@libp2p/crypto 5.1.5 → 5.1.6-439d2c9ce

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/index.min.js CHANGED
@@ -1,11 +1,11 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PCrypto = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PCrypto=(()=>{var tn=Object.defineProperty;var ta=Object.getOwnPropertyDescriptor;var ea=Object.getOwnPropertyNames;var ra=Object.prototype.hasOwnProperty;var ct=(e,t)=>{for(var r in t)tn(e,r,{get:t[r],enumerable:!0})},na=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ea(t))!ra.call(e,o)&&o!==r&&tn(e,o,{get:()=>t[o],enumerable:!(n=ta(t,o))||n.enumerable});return e};var oa=e=>na(tn({},"__esModule",{value:!0}),e);var jf={};ct(jf,{hmac:()=>gr,keys:()=>Ko,pbkdf2:()=>Co,randomBytes:()=>po});var gr={};ct(gr,{create:()=>en});var Fe=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},je=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},wr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Do={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new wr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var X=Do;var Po={SHA1:20,SHA256:32,SHA512:64};var sa={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},ia=async(e,t)=>{let r=await X.get().subtle.sign({name:"HMAC"},e,t);return new Uint8Array(r,0,r.byteLength)};async function en(e,t){let r=sa[e],n=await X.get().subtle.importKey("raw",t,{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return ia(n,o)},length:Po[e]}}var Ko={};ct(Ko,{generateEphemeralKeyPair:()=>Vi,generateKeyPair:()=>Cf,generateKeyPairFromSeed:()=>Tf,keyStretcher:()=>Fi,privateKeyFromCryptoKeyPair:()=>Vf,privateKeyFromProtobuf:()=>kf,privateKeyFromRaw:()=>Nf,privateKeyToCryptoKeyPair:()=>qf,privateKeyToProtobuf:()=>Hf,publicKeyFromMultihash:()=>Rf,publicKeyFromProtobuf:()=>Df,publicKeyFromRaw:()=>Pf,publicKeyToProtobuf:()=>ae});var H=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},we=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},Ge=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var Gt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var an={};ct(an,{base58btc:()=>rt,base58flickr:()=>da});var ru=new Uint8Array(0);function Ro(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function kt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function ko(e){return new TextEncoder().encode(e)}function No(e){return new TextDecoder().decode(e)}function aa(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),u=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function l(S){if(S instanceof Uint8Array||(ArrayBuffer.isView(S)?S=new Uint8Array(S.buffer,S.byteOffset,S.byteLength):Array.isArray(S)&&(S=Uint8Array.from(S))),!(S instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(S.length===0)return"";for(var m=0,D=0,U=0,O=S.length;U!==O&&S[U]===0;)U++,m++;for(var g=(O-U)*f+1>>>0,h=new Uint8Array(g);U!==O;){for(var b=S[U],v=0,B=g-1;(b!==0||v<D)&&B!==-1;B--,v++)b+=256*h[B]>>>0,h[B]=b%c>>>0,b=b/c>>>0;if(b!==0)throw new Error("Non-zero carry");D=v,U++}for(var _=g-D;_!==g&&h[_]===0;)_++;for(var P=a.repeat(m);_<g;++_)P+=e.charAt(h[_]);return P}function y(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var m=0;if(S[m]!==" "){for(var D=0,U=0;S[m]===a;)D++,m++;for(var O=(S.length-m)*u+1>>>0,g=new Uint8Array(O);S[m];){var h=r[S.charCodeAt(m)];if(h===255)return;for(var b=0,v=O-1;(h!==0||b<U)&&v!==-1;v--,b++)h+=c*g[v]>>>0,g[v]=h%256>>>0,h=h/256>>>0;if(h!==0)throw new Error("Non-zero carry");U=b,m++}if(S[m]!==" "){for(var B=O-U;B!==O&&g[B]===0;)B++;for(var _=new Uint8Array(D+(O-B)),P=D;B!==O;)_[P++]=g[B++];return _}}}function I(S){var m=y(S);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:y,decode:I}}var ca=aa,fa=ca,Oo=fa;var rn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},nn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,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 Mo(this,t)}},on=class{decoders;constructor(t){this.decoders=t}or(t){return Mo(this,t)}decode(t){let r=t[0],n=this.decoders[r];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 Mo(e,t){return new on({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var sn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new rn(t,r,n),this.decoder=new nn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ge({name:e,prefix:t,encode:r,decode:n}){return new sn(e,t,r,n)}function Zt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Oo(r,e);return ge({prefix:t,name:e,encode:n,decode:s=>kt(o(s))})}function ua(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|f,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ha(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function la(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function $({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=la(n);return ge({prefix:t,name:e,encode(s){return ha(s,n,r)},decode(s){return ua(s,o,r,e)}})}var rt=Zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),da=Zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var cn={};ct(cn,{base32:()=>Ee,base32hex:()=>ba,base32hexpad:()=>wa,base32hexpadupper:()=>ga,base32hexupper:()=>xa,base32pad:()=>ma,base32padupper:()=>ya,base32upper:()=>pa,base32z:()=>Ea});var Ee=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),pa=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ma=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ya=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ba=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),xa=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),wa=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ga=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ea=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var fn={};ct(fn,{base36:()=>Ze,base36upper:()=>Aa});var Ze=Zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Aa=Zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Sa=zo,qo=128,va=127,Ba=~va,Ia=Math.pow(2,31);function zo(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Ia;)t[r++]=e&255|qo,e/=128;for(;e&Ba;)t[r++]=e&255|qo,e>>>=7;return t[r]=e|0,zo.bytes=r-n+1,t}var _a=un,La=128,Vo=127;function un(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw un.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Vo)<<o:(i&Vo)*Math.pow(2,o),o+=7}while(i>=La);return un.bytes=s-n,r}var Ua=Math.pow(2,7),Ka=Math.pow(2,14),Ca=Math.pow(2,21),Ta=Math.pow(2,28),Da=Math.pow(2,35),Pa=Math.pow(2,42),Ra=Math.pow(2,49),ka=Math.pow(2,56),Na=Math.pow(2,63),Ha=function(e){return e<Ua?1:e<Ka?2:e<Ca?3:e<Ta?4:e<Da?5:e<Pa?6:e<Ra?7:e<ka?8:e<Na?9:10},Oa={encode:Sa,decode:_a,encodingLength:Ha},Ma=Oa,Ye=Ma;function We(e,t=0){return[Ye.decode(e,t),Ye.decode.bytes]}function Ae(e,t,r=0){return Ye.encode(e,t,r),t}function Se(e){return Ye.encodingLength(e)}function It(e,t){let r=t.byteLength,n=Se(e),o=n+Se(r),s=new Uint8Array(o+r);return Ae(e,s,0),Ae(r,s,n),s.set(t,o),new ve(e,r,t,s)}function Fo(e){let t=kt(e),[r,n]=We(t),[o,s]=We(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ve(r,o,i,t)}function jo(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ro(e.bytes,r.bytes)}}var ve=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Go(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Va(r,hn(e),t??rt.encoder);default:return za(r,hn(e),t??Ee.encoder)}}var Zo=new WeakMap;function hn(e){let t=Zo.get(e);if(t==null){let r=new Map;return Zo.set(e,r),r}return t}var vt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}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:r}=this;if(t!==$e)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Fa)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}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:r}=this.multihash,n=It(t,r);return e.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 e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&jo(t.multihash,n.multihash)}toString(t){return Go(this,t)}toJSON(){return{"/":Go(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 r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Yo(n,o,s.bytes))}else if(r[ja]===!0){let{version:n,multihash:o,code:s}=r,i=Fo(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="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(r!==$e)throw new Error(`Version 0 CID must use dag-pb (code: ${$e}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Yo(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,$e,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=kt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new ve(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,y]=We(t.subarray(r));return r+=y,l},o=n(),s=$e;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),u=r+a,f=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:f,size:u}}static parse(t,r){let[n,o]=qa(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return hn(s).set(n,t),s}};function qa(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case Ee.prefix:{let r=t??Ee;return[Ee.prefix,r.decode(e)]}case Ze.prefix:{let r=t??Ze;return[Ze.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Va(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function za(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var $e=112,Fa=18;function Yo(e,t,r){let n=Se(e),o=n+Se(t),s=new Uint8Array(o+r.byteLength);return Ae(e,s,0),Ae(t,s,n),s.set(r,o),s}var ja=Symbol.for("@ipld/js-cid/CID");var ln={};ct(ln,{identity:()=>se});var Wo=0,Ga="identity",Xo=kt;function Za(e){return It(Wo,Xo(e))}var se={code:Wo,name:Ga,encode:Xo,digest:Za};function ft(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Nt(e=0){return new Uint8Array(e)}function wt(e=0){return new Uint8Array(e)}function Ct(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=wt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Jo=Symbol.for("@achingbrain/uint8arraylist");function $o(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Ar(e){return!!e?.[Jo]}var ht=class e{bufs;length;[Jo]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Ar(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Ar(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=$o(this.bufs,t);return r.buf[r.index]}set(t,r){let n=$o(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(Ar(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Ct(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ct(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,f=r>c&&r<=a;if(u&&f){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(f){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Ar(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=a;l+=f){f=0;for(let y=u;y>=0;y--){let I=this.get(l+y);if(n[y]!==I){f=Math.max(1,y-c[I]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=wt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Nt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Nt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Nt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=wt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Nt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Nt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Nt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Nt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Nt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ft(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var dn={};ct(dn,{base10:()=>Ya});var Ya=Zt({prefix:"9",name:"base10",alphabet:"0123456789"});var pn={};ct(pn,{base16:()=>Wa,base16upper:()=>Xa});var Wa=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Xa=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var mn={};ct(mn,{base2:()=>$a});var $a=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var yn={};ct(yn,{base256emoji:()=>rc});var Qo=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Ja=Qo.reduce((e,t,r)=>(e[r]=t,e),[]),Qa=Qo.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function tc(e){return e.reduce((t,r)=>(t+=Ja[r],t),"")}function ec(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Qa[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var rc=ge({prefix:"\u{1F680}",name:"base256emoji",encode:tc,decode:ec});var xn={};ct(xn,{base64:()=>bn,base64pad:()=>nc,base64url:()=>oc,base64urlpad:()=>sc});var bn=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),nc=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),oc=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sc=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var wn={};ct(wn,{base8:()=>ic});var ic=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var gn={};ct(gn,{identity:()=>ac});var ac=ge({prefix:"\0",name:"identity",encode:e=>No(e),decode:e=>ko(e)});var Ou=new TextEncoder,Mu=new TextDecoder;var Sn={};ct(Sn,{sha256:()=>Sr,sha512:()=>uc});function An({name:e,code:t,encode:r}){return new En(e,t,r)}var En=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?It(this.code,r):r.then(n=>It(this.code,n))}else throw Error("Unknown type, must be binary type")}};function es(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Sr=An({name:"sha2-256",code:18,encode:es("SHA-256")}),uc=An({name:"sha2-512",code:19,encode:es("SHA-512")});var vn={...gn,...mn,...wn,...dn,...pn,...cn,...fn,...an,...xn,...yn},Ju={...Sn,...ln};function ns(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var rs=ns("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Bn=ns("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=wt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),hc={utf8:rs,"utf-8":rs,hex:vn.base16,latin1:Bn,ascii:Bn,binary:Bn,...vn},vr=hc;function Z(e,t="utf8"){let r=vr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function V(e,t="utf8"){let r=vr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var lc=parseInt("11111",2),In=parseInt("10000000",2),dc=parseInt("01111111",2),os={0:Je,1:Je,2:pc,3:bc,4:xc,5:yc,6:mc,16:Je,22:Je,48:Je};function gt(e,t={offset:0}){let r=e[t.offset]&lc;if(t.offset++,os[r]!=null)return os[r](e,t);throw new Error("No decoder for tag "+r)}function Qe(e,t){let r=0;if((e[t.offset]&In)===In){let n=e[t.offset]&dc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Je(e,t){Qe(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=gt(e,t);if(n===null)break;r.push(n)}return r}function pc(e,t){let r=Qe(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function mc(e,t){let r=Qe(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let f=0;for(let l=0;l<a.length;l++)f+=a[l]<<l*7;c+=`.${f}`,a=[]}}return c}function yc(e,t){return t.offset++,null}function bc(e,t){let r=Qe(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function xc(e,t){let r=Qe(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function wc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ht;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Br(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=wc(e.byteLength);return new ht(Uint8Array.from([t.byteLength|In]),t)}function lt(e){let t=new ht,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ht(Uint8Array.from([2]),Br(t),t)}function tr(e){let t=Uint8Array.from([0]),r=new ht(t,e);return new ht(Uint8Array.from([3]),Br(r),r)}function ss(e){return new ht(Uint8Array.from([4]),Br(e),e)}function _t(e,t=48){let r=new ht;for(let n of e)r.append(n);return new ht(Uint8Array.from([t]),Br(r),r)}var _n="1.2.840.10045.3.1.7",Ln="1.3.132.0.34",Un="1.3.132.0.35";async function is(e="P-256"){let t=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:e},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",t.publicKey),privateKey:await crypto.subtle.exportKey("jwk",t.privateKey)}}async function as(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["sign"]);r?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function cs(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var gc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ec=Uint8Array.from([6,5,43,129,4,0,34]),Ac=Uint8Array.from([6,5,43,129,4,0,35]),fs={ext:!0,kty:"EC",crv:"P-256"},us={ext:!0,kty:"EC",crv:"P-384"},hs={ext:!0,kty:"EC",crv:"P-521"},Be=32,Ie=48,_e=66;function ls(e){let t=gt(e);return Kn(t)}function Kn(e){let t=e[1],r=V(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===Be)return s=V(n.subarray(o,o+Be),"base64url"),i=V(n.subarray(o+Be),"base64url"),new Ht({...fs,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===Ie)return s=V(n.subarray(o,o+Ie),"base64url"),i=V(n.subarray(o+Ie),"base64url"),new Ht({...us,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===_e)return s=V(n.subarray(o,o+_e),"base64url"),i=V(n.subarray(o+_e),"base64url"),new Ht({...hs,key_ops:["sign"],d:r,x:s,y:i});throw new H(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function Cn(e){let t=gt(e);return Tn(t)}function Tn(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Be*2+1)return n=V(t.subarray(r,r+Be),"base64url"),o=V(t.subarray(r+Be),"base64url"),new ie({...fs,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ie*2+1)return n=V(t.subarray(r,r+Ie),"base64url"),o=V(t.subarray(r+Ie),"base64url"),new ie({...us,key_ops:["verify"],x:n,y:o});if(t.byteLength===_e*2+1)return n=V(t.subarray(r,r+_e),"base64url"),o=V(t.subarray(r+_e),"base64url"),new ie({...hs,key_ops:["verify"],x:n,y:o});throw new H(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ds(e){return _t([lt(Uint8Array.from([1])),ss(Z(e.d??"","base64url")),_t([ms(e.crv)],160),_t([tr(new ht(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function ps(e){return _t([lt(Uint8Array.from([1])),_t([ms(e.crv)],160),_t([tr(new ht(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function ms(e){if(e==="P-256")return gc;if(e==="P-384")return Ec;if(e==="P-521")return Ac;throw new H(`Invalid curve ${e}`)}async function ys(e="P-256"){let t=await is(e);return new Ht(t.privateKey)}var ie=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ps(this.jwk)),this._raw}toMultihash(){return se.digest(ae(this))}toCID(){return vt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}async verify(t,r,n){return cs(this.jwk,r,t,n)}},Ht=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new ie({crv:t.crv,ext:t.ext,key_ops:["verify"],kty:"EC",x:t.x,y:t.y})}get raw(){return this._raw==null&&(this._raw=ds(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}async sign(t,r){return as(this.jwk,t,r)}};var ce=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Sc(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Yt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Wt(e,...t){if(!Sc(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Ir(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Yt(e.outputLen),Yt(e.blockLen)}function Ue(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function bs(e,t){Wt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function bt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Ke(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Lt(e,t){return e<<32-t|e>>>t}function _r(e,t){return e<<t|e>>>32-t>>>0}function Dn(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function er(e){return typeof e=="string"&&(e=Dn(e)),Wt(e),e}function Pn(e){return typeof e=="string"&&(e=Dn(e)),Wt(e),e}function Rn(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Wt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function xs(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(e,t)}var Le=class{};function rr(e){let t=n=>e().update(er(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Ce(e=32){if(ce&&typeof ce.getRandomValues=="function")return ce.getRandomValues(new Uint8Array(e));if(ce&&typeof ce.randomBytes=="function")return Uint8Array.from(ce.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function vc(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,u=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+u,c,n)}function Lr(e,t,r){return e&t^~e&r}function Ur(e,t,r){return e&t^e&r^t&r}var fe=class extends Le{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Ke(this.buffer)}update(t){Ue(this),t=er(t),Wt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Ke(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ue(this),bs(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,bt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;vc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Ke(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],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ot=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var it=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Kr=BigInt(4294967295),ws=BigInt(32);function Bc(e,t=!1){return t?{h:Number(e&Kr),l:Number(e>>ws&Kr)}:{h:Number(e>>ws&Kr)|0,l:Number(e&Kr)|0}}function gs(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=Bc(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var kn=(e,t,r)=>e>>>r,Nn=(e,t,r)=>e<<32-r|t>>>r,ue=(e,t,r)=>e>>>r|t<<32-r,he=(e,t,r)=>e<<32-r|t>>>r,nr=(e,t,r)=>e<<64-r|t>>>r-32,or=(e,t,r)=>e>>>r-32|t<<64-r;function Tt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Es=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),As=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ss=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),vs=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Bs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Is=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var _c=Uint32Array.from([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]),Xt=new Uint32Array(64),Cr=class extends fe{constructor(t=32){super(64,t,8,!1),this.A=Ot[0]|0,this.B=Ot[1]|0,this.C=Ot[2]|0,this.D=Ot[3]|0,this.E=Ot[4]|0,this.F=Ot[5]|0,this.G=Ot[6]|0,this.H=Ot[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)Xt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let y=Xt[l-15],I=Xt[l-2],S=Lt(y,7)^Lt(y,18)^y>>>3,m=Lt(I,17)^Lt(I,19)^I>>>10;Xt[l]=m+Xt[l-7]+S+Xt[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){let y=Lt(c,6)^Lt(c,11)^Lt(c,25),I=f+y+Lr(c,a,u)+_c[l]+Xt[l]|0,m=(Lt(n,2)^Lt(n,13)^Lt(n,22))+Ur(n,o,s)|0;f=u,u=a,a=c,c=i+I|0,i=s,s=o,o=n,n=I+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+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,o,s,i,c,a,u,f)}roundClean(){bt(Xt)}destroy(){this.set(0,0,0,0,0,0,0,0),bt(this.buffer)}};var _s=gs(["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(e=>BigInt(e))),Lc=_s[0],Uc=_s[1],$t=new Uint32Array(80),Jt=new Uint32Array(80),Tr=class extends fe{constructor(t=64){super(128,t,16,!1),this.Ah=it[0]|0,this.Al=it[1]|0,this.Bh=it[2]|0,this.Bl=it[3]|0,this.Ch=it[4]|0,this.Cl=it[5]|0,this.Dh=it[6]|0,this.Dl=it[7]|0,this.Eh=it[8]|0,this.El=it[9]|0,this.Fh=it[10]|0,this.Fl=it[11]|0,this.Gh=it[12]|0,this.Gl=it[13]|0,this.Hh=it[14]|0,this.Hl=it[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:f,Fh:l,Fl:y,Gh:I,Gl:S,Hh:m,Hl:D}=this;return[t,r,n,o,s,i,c,a,u,f,l,y,I,S,m,D]}set(t,r,n,o,s,i,c,a,u,f,l,y,I,S,m,D){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|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=I|0,this.Gl=S|0,this.Hh=m|0,this.Hl=D|0}process(t,r){for(let g=0;g<16;g++,r+=4)$t[g]=t.getUint32(r),Jt[g]=t.getUint32(r+=4);for(let g=16;g<80;g++){let h=$t[g-15]|0,b=Jt[g-15]|0,v=ue(h,b,1)^ue(h,b,8)^kn(h,b,7),B=he(h,b,1)^he(h,b,8)^Nn(h,b,7),_=$t[g-2]|0,P=Jt[g-2]|0,N=ue(_,P,19)^nr(_,P,61)^kn(_,P,6),K=he(_,P,19)^or(_,P,61)^Nn(_,P,6),R=Ss(B,K,Jt[g-7],Jt[g-16]),T=vs(R,v,N,$t[g-7],$t[g-16]);$t[g]=T|0,Jt[g]=R|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:f,Eh:l,El:y,Fh:I,Fl:S,Gh:m,Gl:D,Hh:U,Hl:O}=this;for(let g=0;g<80;g++){let h=ue(l,y,14)^ue(l,y,18)^nr(l,y,41),b=he(l,y,14)^he(l,y,18)^or(l,y,41),v=l&I^~l&m,B=y&S^~y&D,_=Bs(O,b,B,Uc[g],Jt[g]),P=Is(_,U,h,v,Lc[g],$t[g]),N=_|0,K=ue(n,o,28)^nr(n,o,34)^nr(n,o,39),R=he(n,o,28)^or(n,o,34)^or(n,o,39),T=n&s^n&c^s&c,Q=o&i^o&a^i&a;U=m|0,O=D|0,m=I|0,D=S|0,I=l|0,S=y|0,{h:l,l:y}=Tt(u|0,f|0,P|0,N|0),u=c|0,f=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let E=Es(N,R,Q);n=As(E,P,K,T),o=E|0}({h:n,l:o}=Tt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Tt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Tt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:f}=Tt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:y}=Tt(this.Eh|0,this.El|0,l|0,y|0),{h:I,l:S}=Tt(this.Fh|0,this.Fl|0,I|0,S|0),{h:m,l:D}=Tt(this.Gh|0,this.Gl|0,m|0,D|0),{h:U,l:O}=Tt(this.Hh|0,this.Hl|0,U|0,O|0),this.set(n,o,s,i,c,a,u,f,l,y,I,S,m,D,U,O)}roundClean(){bt($t,Jt)}destroy(){bt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Dr=rr(()=>new Cr);var Pr=rr(()=>new Tr);var qn=BigInt(0),Mn=BigInt(1);function Te(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Vn(e){if(!Te(e))throw new Error("Uint8Array expected")}function Dt(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function sr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Ks(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?qn:BigInt("0x"+e)}var Cs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Kc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Qt(e){if(Vn(e),Cs)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Kc[e[r]];return t}var Mt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ls(e){if(e>=Mt._0&&e<=Mt._9)return e-Mt._0;if(e>=Mt.A&&e<=Mt.F)return e-(Mt.A-10);if(e>=Mt.a&&e<=Mt.f)return e-(Mt.a-10)}function ir(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Cs)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Ls(e.charCodeAt(s)),c=Ls(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function qt(e){return Ks(Qt(e))}function le(e){return Vn(e),Ks(Qt(Uint8Array.from(e).reverse()))}function de(e,t){return ir(e.toString(16).padStart(t*2,"0"))}function De(e,t){return de(e,t).reverse()}function Y(e,t,r){let n;if(typeof t=="string")try{n=ir(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Te(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function te(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Vn(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var Hn=e=>typeof e=="bigint"&&qn<=e;function Rr(e,t,r){return Hn(e)&&Hn(t)&&Hn(r)&&t<=e&&e<r}function Et(e,t,r,n){if(!Rr(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ts(e){let t;for(t=0;e>qn;e>>=Mn,t+=1);return t}var pe=e=>(Mn<<BigInt(e))-Mn,On=e=>new Uint8Array(e),Us=e=>Uint8Array.from(e);function Ds(e,t,r){if(typeof e!="number"||e<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 r!="function")throw new Error("hmacFn must be a function");let n=On(e),o=On(e),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...l)=>r(o,n,...l),a=(l=On(0))=>{o=c(Us([0]),l),n=c(),l.length!==0&&(o=c(Us([1]),l),n=c())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,y=[];for(;l<t;){n=c();let I=n.slice();y.push(I),l+=n.length}return te(...y)};return(l,y)=>{i(),a(l);let I;for(;!(I=y(u()));)a();return i(),I}}var Cc={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||Te(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function Vt(e,t,r={}){let n=(o,s,i)=>{let c=Cc[s];if(typeof c!="function")throw new Error("invalid validator function");let a=e[o];if(!(i&&a===void 0)&&!c(a,e))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+a)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(r))n(o,s,!0);return e}function Pe(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var dt=BigInt(0),nt=BigInt(1),me=BigInt(2),Tc=BigInt(3),Rs=BigInt(4),ks=BigInt(5),Ns=BigInt(8);function j(e,t){let r=e%t;return r>=dt?r:t+r}function W(e,t,r){let n=e;for(;t-- >dt;)n*=n,n%=r;return n}function kr(e,t){if(e===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let r=j(e,t),n=t,o=dt,s=nt,i=nt,c=dt;for(;r!==dt;){let u=n/r,f=n%r,l=o-i*u,y=s-c*u;n=r,r=f,o=i,s=c,i=l,c=y}if(n!==nt)throw new Error("invert: does not exist");return j(o,t)}function Hs(e,t){let r=(e.ORDER+nt)/Rs,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function Dc(e,t){let r=(e.ORDER-ks)/Ns,n=e.mul(t,me),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,me),o),c=e.mul(s,e.sub(i,e.ONE));if(!e.eql(e.sqr(c),t))throw new Error("Cannot find square root");return c}function Pc(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%me===dt;)t/=me,r++;let n=me,o=zt(e);for(;Ps(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Hs;let s=o.pow(n,t),i=(t+nt)/me;return function(a,u){if(a.is0(u))return u;if(Ps(a,u)!==1)throw new Error("Cannot find square root");let f=r,l=a.mul(a.ONE,s),y=a.pow(u,t),I=a.pow(u,i);for(;!a.eql(y,a.ONE);){if(a.is0(y))return a.ZERO;let S=1,m=a.sqr(y);for(;!a.eql(m,a.ONE);)if(S++,m=a.sqr(m),S===f)throw new Error("Cannot find square root");let D=nt<<BigInt(f-S-1),U=a.pow(l,D);f=S,l=a.sqr(U),y=a.mul(y,l),I=a.mul(I,U)}return I}}function Rc(e){return e%Rs===Tc?Hs:e%Ns===ks?Dc:Pc(e)}var Os=(e,t)=>(j(e,t)&nt)===nt,kc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function zn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=kc.reduce((n,o)=>(n[o]="function",n),t);return Vt(e,r)}function Nc(e,t,r){if(r<dt)throw new Error("invalid exponent, negatives unsupported");if(r===dt)return e.ONE;if(r===nt)return t;let n=e.ONE,o=t;for(;r>dt;)r&nt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=nt;return n}function Re(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function Ps(e,t){let r=(e.ORDER-nt)/me,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Fn(e,t){t!==void 0&&Yt(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function zt(e,t,r=!1,n={}){if(e<=dt)throw new Error("invalid field: expected ORDER > 0, got "+e);let{nBitLength:o,nByteLength:s}=Fn(e,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,c=Object.freeze({ORDER:e,isLE:r,BITS:o,BYTES:s,MASK:pe(o),ZERO:dt,ONE:nt,create:a=>j(a,e),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return dt<=a&&a<e},is0:a=>a===dt,isOdd:a=>(a&nt)===nt,neg:a=>j(-a,e),eql:(a,u)=>a===u,sqr:a=>j(a*a,e),add:(a,u)=>j(a+u,e),sub:(a,u)=>j(a-u,e),mul:(a,u)=>j(a*u,e),pow:(a,u)=>Nc(c,a,u),div:(a,u)=>j(a*kr(u,e),e),sqrN:a=>a*a,addN:(a,u)=>a+u,subN:(a,u)=>a-u,mulN:(a,u)=>a*u,inv:a=>kr(a,e),sqrt:n.sqrt||(a=>(i||(i=Rc(e)),i(c,a))),toBytes:a=>r?De(a,s):de(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return r?le(a):qt(a)},invertBatch:a=>Re(c,a),cmov:(a,u,f)=>f?u:a});return Object.freeze(c)}function Ms(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function jn(e){let t=Ms(e);return t+Math.ceil(t/2)}function qs(e,t,r=!1){let n=e.length,o=Ms(t),s=jn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?le(e):qt(e),c=j(i,t-nt)+nt;return r?De(c,o):de(c,o)}var Vs=BigInt(0),Xn=BigInt(1);function Gn(e,t){let r=t.negate();return e?r:t}function Fs(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Zn(e,t){Fs(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=pe(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function zs(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=Xn);let u=t*n,f=u+Math.abs(c)-1,l=c===0,y=c<0,I=t%2!==0;return{nextN:a,offset:f,isZero:l,isNeg:y,isNegF:I,offsetF:u}}function Hc(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Oc(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Yn=new WeakMap,js=new WeakMap;function Wn(e){return js.get(e)||1}function Nr(e,t){return{constTimeNegate:Gn,hasPrecomputes(r){return Wn(r)!==1},unsafeLadder(r,n,o=e.ZERO){let s=r;for(;n>Vs;)n&Xn&&(o=o.add(s)),s=s.double(),n>>=Xn;return o},precomputeWindow(r,n){let{windows:o,windowSize:s}=Zn(n,t),i=[],c=r,a=c;for(let u=0;u<o;u++){a=c,i.push(a);for(let f=1;f<s;f++)a=a.add(c),i.push(a);c=a.double()}return i},wNAF(r,n,o){let s=e.ZERO,i=e.BASE,c=Zn(r,t);for(let a=0;a<c.windows;a++){let{nextN:u,offset:f,isZero:l,isNeg:y,isNegF:I,offsetF:S}=zs(o,a,c);o=u,l?i=i.add(Gn(I,n[S])):s=s.add(Gn(y,n[f]))}return{p:s,f:i}},wNAFUnsafe(r,n,o,s=e.ZERO){let i=Zn(r,t);for(let c=0;c<i.windows&&o!==Vs;c++){let{nextN:a,offset:u,isZero:f,isNeg:l}=zs(o,c,i);if(o=a,!f){let y=n[u];s=s.add(l?y.negate():y)}}return s},getPrecomputes(r,n,o){let s=Yn.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&Yn.set(n,o(s))),s},wNAFCached(r,n,o){let s=Wn(r);return this.wNAF(s,this.getPrecomputes(s,r,o),n)},wNAFCachedUnsafe(r,n,o,s){let i=Wn(r);return i===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,r,o),n,s)},setWindowSize(r,n){Fs(n,t),js.set(r,n),Yn.delete(r)}}}function Hr(e,t,r,n){Hc(r,e),Oc(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=Ts(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=pe(a),f=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/a)*a,y=i;for(let I=l;I>=0;I-=a){f.fill(i);for(let m=0;m<s;m++){let D=n[m],U=Number(D>>BigInt(I)&u);f[U]=f[U].add(r[m])}let S=i;for(let m=f.length-1,D=i;m>0;m--)D=D.add(f[m]),S=S.add(D);if(y=y.add(S),I!==0)for(let m=0;m<a;m++)y=y.double()}return y}function ar(e){return zn(e.Fp),Vt(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Fn(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}var Pt=BigInt(0),pt=BigInt(1),Gs=BigInt(2),Mc=BigInt(8),qc={zip215:!0};function Vc(e){let t=ar(e);return Vt(e,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Zs(e){let t=Vc(e),{Fp:r,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,u=Gs<<BigInt(c*8)-pt,f=r.create,l=zt(t.n,t.nBitLength);function y(x,d){let p=r.sqr(x),A=r.sqr(d),C=r.add(r.mul(t.a,p),A),k=r.add(r.ONE,r.mul(t.d,r.mul(p,A)));return r.eql(C,k)}if(!y(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let I=t.uvRatio||((x,d)=>{try{return{isValid:!0,value:r.sqrt(x*r.inv(d))}}catch{return{isValid:!1,value:Pt}}}),S=t.adjustScalarBytes||(x=>x),m=t.domain||((x,d,p)=>{if(Dt("phflag",p),d.length||p)throw new Error("Contexts/pre-hash are not supported");return x});function D(x,d,p=!1){let A=p?pt:Pt;Et("coordinate "+x,d,A,u)}function U(x){if(!(x instanceof h))throw new Error("ExtendedPoint expected")}let O=Pe((x,d)=>{let{ex:p,ey:A,ez:C}=x,k=x.is0();d==null&&(d=k?Mc:r.inv(C));let M=f(p*d),q=f(A*d),z=f(C*d);if(k)return{x:Pt,y:pt};if(z!==pt)throw new Error("invZ was invalid");return{x:M,y:q}}),g=Pe(x=>{let{a:d,d:p}=t;if(x.is0())throw new Error("bad point: ZERO");let{ex:A,ey:C,ez:k,et:M}=x,q=f(A*A),z=f(C*C),F=f(k*k),tt=f(F*F),J=f(q*d),st=f(F*f(J+z)),yt=f(tt+f(p*f(q*z)));if(st!==yt)throw new Error("bad point: equation left != right (1)");let et=f(A*C),at=f(k*M);if(et!==at)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(d,p,A,C){D("x",d),D("y",p),D("z",A,!0),D("t",C),this.ex=d,this.ey=p,this.ez=A,this.et=C,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof h)throw new Error("extended point not allowed");let{x:p,y:A}=d||{};return D("x",p),D("y",A),new h(p,A,pt,f(p*A))}static normalizeZ(d){let p=Re(r,d.map(A=>A.ez));return d.map((A,C)=>A.toAffine(p[C])).map(h.fromAffine)}static msm(d,p){return Hr(h,l,d,p)}_setWindowSize(d){B.setWindowSize(this,d)}assertValidity(){g(this)}equals(d){U(d);let{ex:p,ey:A,ez:C}=this,{ex:k,ey:M,ez:q}=d,z=f(p*q),F=f(k*C),tt=f(A*q),J=f(M*C);return z===F&&tt===J}is0(){return this.equals(h.ZERO)}negate(){return new h(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:d}=t,{ex:p,ey:A,ez:C}=this,k=f(p*p),M=f(A*A),q=f(Gs*f(C*C)),z=f(d*k),F=p+A,tt=f(f(F*F)-k-M),J=z+M,st=J-q,yt=z-M,et=f(tt*st),at=f(J*yt),xt=f(tt*yt),Bt=f(st*J);return new h(et,at,Bt,xt)}add(d){U(d);let{a:p,d:A}=t,{ex:C,ey:k,ez:M,et:q}=this,{ex:z,ey:F,ez:tt,et:J}=d,st=f(C*z),yt=f(k*F),et=f(q*A*J),at=f(M*tt),xt=f((C+k)*(z+F)-st-yt),Bt=at-et,ze=at+et,To=f(yt-p*st),Xi=f(xt*Bt),$i=f(ze*To),Ji=f(xt*To),Qi=f(Bt*ze);return new h(Xi,$i,Qi,Ji)}subtract(d){return this.add(d.negate())}wNAF(d){return B.wNAFCached(this,d,h.normalizeZ)}multiply(d){let p=d;Et("scalar",p,pt,n);let{p:A,f:C}=this.wNAF(p);return h.normalizeZ([A,C])[0]}multiplyUnsafe(d,p=h.ZERO){let A=d;return Et("scalar",A,Pt,n),A===Pt?v:this.is0()||A===pt?this:B.wNAFCachedUnsafe(this,A,h.normalizeZ,p)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return B.unsafeLadder(this,n).is0()}toAffine(d){return O(this,d)}clearCofactor(){let{h:d}=t;return d===pt?this:this.multiplyUnsafe(d)}static fromHex(d,p=!1){let{d:A,a:C}=t,k=r.BYTES;d=Y("pointHex",d,k),Dt("zip215",p);let M=d.slice(),q=d[k-1];M[k-1]=q&-129;let z=le(M),F=p?u:r.ORDER;Et("pointHex.y",z,Pt,F);let tt=f(z*z),J=f(tt-pt),st=f(A*tt-C),{isValid:yt,value:et}=I(J,st);if(!yt)throw new Error("Point.fromHex: invalid y coordinate");let at=(et&pt)===pt,xt=(q&128)!==0;if(!p&&et===Pt&&xt)throw new Error("Point.fromHex: x=0 and x_0=1");return xt!==at&&(et=f(-et)),h.fromAffine({x:et,y:z})}static fromPrivateKey(d){let{scalar:p}=N(d);return b.multiply(p)}toRawBytes(){let{x:d,y:p}=this.toAffine(),A=De(p,r.BYTES);return A[A.length-1]|=d&pt?128:0,A}toHex(){return Qt(this.toRawBytes())}}h.BASE=new h(t.Gx,t.Gy,pt,f(t.Gx*t.Gy)),h.ZERO=new h(Pt,pt,pt,Pt);let{BASE:b,ZERO:v}=h,B=Nr(h,c*8);function _(x){return j(x,n)}function P(x){return _(le(x))}function N(x){let d=r.BYTES;x=Y("private key",x,d);let p=Y("hashed private key",s(x),2*d),A=S(p.slice(0,d)),C=p.slice(d,2*d),k=P(A);return{head:A,prefix:C,scalar:k}}function K(x){let{head:d,prefix:p,scalar:A}=N(x),C=b.multiply(A),k=C.toRawBytes();return{head:d,prefix:p,scalar:A,point:C,pointBytes:k}}function R(x){return K(x).pointBytes}function T(x=Uint8Array.of(),...d){let p=te(...d);return P(s(m(p,Y("context",x),!!o)))}function Q(x,d,p={}){x=Y("message",x),o&&(x=o(x));let{prefix:A,scalar:C,pointBytes:k}=K(d),M=T(p.context,A,x),q=b.multiply(M).toRawBytes(),z=T(p.context,q,k,x),F=_(M+z*C);Et("signature.s",F,Pt,n);let tt=te(q,De(F,r.BYTES));return Y("result",tt,r.BYTES*2)}let E=qc;function w(x,d,p,A=E){let{context:C,zip215:k}=A,M=r.BYTES;x=Y("signature",x,2*M),d=Y("message",d),p=Y("publicKey",p,M),k!==void 0&&Dt("zip215",k),o&&(d=o(d));let q=le(x.slice(M,2*M)),z,F,tt;try{z=h.fromHex(p,k),F=h.fromHex(x.slice(0,M),k),tt=b.multiplyUnsafe(q)}catch{return!1}if(!k&&z.isSmallOrder())return!1;let J=T(C,F.toRawBytes(),z.toRawBytes(),d);return F.add(z.multiplyUnsafe(J)).subtract(tt).clearCofactor().equals(h.ZERO)}return b._setWindowSize(8),{CURVE:t,getPublicKey:R,sign:Q,verify:w,ExtendedPoint:h,utils:{getExtendedPublicKey:K,randomPrivateKey:()=>i(r.BYTES),precompute(x=8,d=h.BASE){return d._setWindowSize(x),d.multiply(BigInt(3)),d}}}}var $n=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ys=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Jh=BigInt(0),zc=BigInt(1),Ws=BigInt(2),Qh=BigInt(3),Fc=BigInt(5),jc=BigInt(8);function Gc(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=$n,c=e*e%s*e%s,a=W(c,Ws,s)*c%s,u=W(a,zc,s)*e%s,f=W(u,Fc,s)*u%s,l=W(f,t,s)*f%s,y=W(l,r,s)*l%s,I=W(y,n,s)*y%s,S=W(I,o,s)*I%s,m=W(S,o,s)*I%s,D=W(m,t,s)*f%s;return{pow_p_5_8:W(D,Ws,s)*e%s,b2:c}}function Zc(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}function Yc(e,t){let r=$n,n=j(t*t*t,r),o=j(n*n*t,r),s=Gc(e*o).pow_p_5_8,i=j(e*n*s,r),c=j(t*i*i,r),a=i,u=j(i*Ys,r),f=c===e,l=c===j(-e,r),y=c===j(-e*Ys,r);return f&&(i=a),(l||y)&&(i=u),Os(i,r)&&(i=j(-i,r)),{isValid:f||l,value:i}}var Xs=zt($n,void 0,!0),Wc={a:Xs.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Xs,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:jc,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Pr,randomBytes:Ce,adjustScalarBytes:Zc,uvRatio:Yc},ke=Zs(Wc);var ee=32,At=64,Or=32;var Ne,$s=(async()=>{try{return await X.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function Js(){let e=ke.utils.randomPrivateKey(),t=ke.getPublicKey(e);return{privateKey:ri(e,t),publicKey:t}}function Qs(e){if(e.length!==Or)throw new TypeError('"seed" must be 32 bytes in length.');if(!(e instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let t=e,r=ke.getPublicKey(t);return{privateKey:ri(t,r),publicKey:r}}async function Xc(e,t){let r;e.length===At?r=e.subarray(0,32):r=e;let n={crv:"Ed25519",kty:"OKP",x:V(e.subarray(32),"base64url"),d:V(r,"base64url"),ext:!0,key_ops:["sign"]},o=await X.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),s=await X.get().subtle.sign({name:"Ed25519"},o,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(s,0,s.byteLength)}function $c(e,t){let r=e.subarray(0,Or);return ke.sign(t instanceof Uint8Array?t:t.subarray(),r)}async function ti(e,t){return Ne==null&&(Ne=await $s),Ne?Xc(e,t):$c(e,t)}async function Jc(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await X.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await X.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Qc(e,t,r){return ke.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ei(e,t,r){return Ne==null&&(Ne=await $s),Ne?Jc(e,t,r):Qc(e,t,r)}function ri(e,t){let r=new Uint8Array(At);for(let n=0;n<Or;n++)r[n]=e[n],r[Or+n]=t[n];return r}function Jn(e,t){let r=Z(e,"base64urlpad");if(t!=null){if(r.length>t)throw new Error("byte array longer than desired length");r=Ct([new Uint8Array(t-r.length),r])}return r}function He(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var cr=class{type="Ed25519";raw;constructor(t){this.raw=Oe(t,ee)}toMultihash(){return se.digest(ae(this))}toCID(){return vt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=ei(this.raw,r,t);return He(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}},ye=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=Oe(t,At),this.publicKey=new cr(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}sign(t,r){r?.signal?.throwIfAborted();let n=ti(this.raw,t);return He(n)?n.then(o=>(r?.signal?.throwIfAborted(),o)):(r?.signal?.throwIfAborted(),n)}};function Qn(e){if(e.length>At){e=Oe(e,At+ee);let n=e.subarray(0,At),o=e.subarray(At,e.length);return new ye(n,o)}e=Oe(e,At);let t=e.subarray(0,At),r=e.subarray(ee);return new ye(t,r)}function Mr(e){return e=Oe(e,ee),new cr(e)}async function oi(){let{privateKey:e,publicKey:t}=Js();return new ye(e,t)}async function si(e){let{privateKey:t,publicKey:r}=Qs(e);return new ye(t,r)}function Oe(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new H(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var tf=Math.pow(2,7),ef=Math.pow(2,14),rf=Math.pow(2,21),ii=Math.pow(2,28),ai=Math.pow(2,35),ci=Math.pow(2,42),fi=Math.pow(2,49),mt=128,re=127;function fr(e){if(e<tf)return 1;if(e<ef)return 2;if(e<rf)return 3;if(e<ii)return 4;if(e<ai)return 5;if(e<ci)return 6;if(e<fi)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ui(e,t,r=0){switch(fr(e)){case 8:t[r++]=e&255|mt,e/=128;case 7:t[r++]=e&255|mt,e/=128;case 6:t[r++]=e&255|mt,e/=128;case 5:t[r++]=e&255|mt,e/=128;case 4:t[r++]=e&255|mt,e>>>=7;case 3:t[r++]=e&255|mt,e>>>=7;case 2:t[r++]=e&255|mt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function hi(e,t){let r=e[t],n=0;if(n+=r&re,r<mt||(r=e[t+1],n+=(r&re)<<7,r<mt)||(r=e[t+2],n+=(r&re)<<14,r<mt)||(r=e[t+3],n+=(r&re)<<21,r<mt)||(r=e[t+4],n+=(r&re)*ii,r<mt)||(r=e[t+5],n+=(r&re)*ai,r<mt)||(r=e[t+6],n+=(r&re)*ci,r<mt)||(r=e[t+7],n+=(r&re)*fi,r<mt))return n;throw new RangeError("Could not decode varint")}var to=new Float32Array([-0]),ne=new Uint8Array(to.buffer);function li(e,t,r){to[0]=e,t[r]=ne[0],t[r+1]=ne[1],t[r+2]=ne[2],t[r+3]=ne[3]}function di(e,t){return ne[0]=e[t],ne[1]=e[t+1],ne[2]=e[t+2],ne[3]=e[t+3],to[0]}var eo=new Float64Array([-0]),ut=new Uint8Array(eo.buffer);function pi(e,t,r){eo[0]=e,t[r]=ut[0],t[r+1]=ut[1],t[r+2]=ut[2],t[r+3]=ut[3],t[r+4]=ut[4],t[r+5]=ut[5],t[r+6]=ut[6],t[r+7]=ut[7]}function mi(e,t){return ut[0]=e[t],ut[1]=e[t+1],ut[2]=e[t+2],ut[3]=e[t+3],ut[4]=e[t+4],ut[5]=e[t+5],ut[6]=e[t+6],ut[7]=e[t+7],eo[0]}var nf=BigInt(Number.MAX_SAFE_INTEGER),of=BigInt(Number.MIN_SAFE_INTEGER),St=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return be;if(t<nf&&t>of)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>yi&&(o=0n,++n>yi&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return be;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):be}},be=new St(0,0);be.toBigInt=function(){return 0n};be.zzEncode=be.zzDecode=function(){return this};be.length=function(){return 1};var yi=4294967296n;function bi(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function xi(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function ro(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Ut(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function qr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var no=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Ut(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ut(this,4);return qr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ut(this,4);return qr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ut(this,4);let t=di(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ut(this,4);let t=mi(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Ut(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return xi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ut(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ut(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new St(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ut(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Ut(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ut(this,8);let t=qr(this.buf,this.pos+=4),r=qr(this.buf,this.pos+=4);return new St(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=hi(this.buf,this.pos);return this.pos+=fr(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function oo(e){return new no(e instanceof Uint8Array?e:e.subarray())}function Vr(e,t,r){let n=oo(e);return t.decode(n,void 0,r)}function so(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return wt(i);o+i>t&&(n=wt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var xe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function io(){}var co=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},sf=so();function af(e){return globalThis.Buffer!=null?wt(e):sf(e)}var hr=class{len;head;tail;states;constructor(){this.len=0,this.head=new xe(io,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new xe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new fo((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(zr,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=St.fromBigInt(t);return this._push(zr,r.length(),r)}uint64Number(t){return this._push(ui,fr(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=St.fromBigInt(t).zzEncode();return this._push(zr,r.length(),r)}sint64Number(t){let r=St.fromNumber(t).zzEncode();return this._push(zr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ao,1,t?1:0)}fixed32(t){return this._push(ur,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=St.fromBigInt(t);return this._push(ur,4,r.lo)._push(ur,4,r.hi)}fixed64Number(t){let r=St.fromNumber(t);return this._push(ur,4,r.lo)._push(ur,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(li,4,t)}double(t){return this._push(pi,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ao,1,0):this.uint32(r)._push(ff,r,t)}string(t){let r=bi(t);return r!==0?this.uint32(r)._push(ro,r,t):this._push(ao,1,0)}fork(){return this.states=new co(this),this.head=this.tail=new xe(io,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new xe(io,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=af(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ao(e,t,r){t[r]=e&255}function cf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var fo=class extends xe{next;constructor(t,r){super(cf,t,r),this.next=void 0}};function zr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function ur(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function ff(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(hr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(uf,t,e),this},hr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(hf,t,e),this});function uf(e,t,r){t.set(e,r)}function hf(e,t,r){e.length<40?ro(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Z(e),r)}function uo(){return new hr}function Fr(e,t){let r=uo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Me;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Me||(Me={}));function jr(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function ho(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return jr("enum",Me.VARINT,r,n)}function Gr(e,t){return jr("message",Me.LENGTH_DELIMITED,e,t)}var G;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(G||(G={}));var lo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(lo||(lo={}));(function(e){e.codec=()=>ho(lo)})(G||(G={}));var Rt;(function(e){let t;e.codec=()=>(t==null&&(t=Gr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),G.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=G.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Fr(r,e.codec()),e.decode=(r,n)=>Vr(r,e.codec(),n)})(Rt||(Rt={}));var lr;(function(e){let t;e.codec=()=>(t==null&&(t=Gr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),G.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=G.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Fr(r,e.codec()),e.decode=(r,n)=>Vr(r,e.codec(),n)})(lr||(lr={}));function po(e){if(isNaN(e)||e<=0)throw new H("random bytes length must be a Number bigger than 0");return Ce(e)}var pr={};ct(pr,{MAX_RSA_KEY_SIZE:()=>mo,generateRSAKeyPair:()=>Ao,jwkToJWKKeyPair:()=>Si,jwkToPkcs1:()=>mf,jwkToPkix:()=>wo,jwkToRSAPrivateKey:()=>Wr,pkcs1MessageToJwk:()=>bo,pkcs1MessageToRSAPrivateKey:()=>Zr,pkcs1ToJwk:()=>pf,pkcs1ToRSAPrivateKey:()=>go,pkixMessageToJwk:()=>xo,pkixMessageToRSAPublicKey:()=>Yr,pkixToJwk:()=>yf,pkixToRSAPublicKey:()=>Eo});var qe=Dr;var Ve=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=pr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return vt.createV1(114,this._multihash)}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}verify(t,r,n){return Ai(this.jwk,r,t,n)}},dr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=pr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}sign(t,r){return Ei(this.jwk,t,r)}};var mo=8192,yo=18,lf=1062,df=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function pf(e){let t=gt(e);return bo(t)}function bo(e){return{n:V(e[1],"base64url"),e:V(e[2],"base64url"),d:V(e[3],"base64url"),p:V(e[4],"base64url"),q:V(e[5],"base64url"),dp:V(e[6],"base64url"),dq:V(e[7],"base64url"),qi:V(e[8],"base64url"),kty:"RSA"}}function mf(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new H("JWK was missing components");return _t([lt(Uint8Array.from([0])),lt(Z(e.n,"base64url")),lt(Z(e.e,"base64url")),lt(Z(e.d,"base64url")),lt(Z(e.p,"base64url")),lt(Z(e.q,"base64url")),lt(Z(e.dp,"base64url")),lt(Z(e.dq,"base64url")),lt(Z(e.qi,"base64url"))]).subarray()}function yf(e){let t=gt(e,{offset:0});return xo(t)}function xo(e){let t=gt(e[1],{offset:0});return{kty:"RSA",n:V(t[0],"base64url"),e:V(t[1],"base64url")}}function wo(e){if(e.n==null||e.e==null)throw new H("JWK was missing components");return _t([df,tr(_t([lt(Z(e.n,"base64url")),lt(Z(e.e,"base64url"))]))]).subarray()}function go(e){let t=gt(e);return Zr(t)}function Zr(e){let t=bo(e);return Wr(t)}function Eo(e,t){if(e.byteLength>=lf)throw new we("Key size is too large");let r=gt(e,{offset:0});return Yr(r,e,t)}function Yr(e,t,r){let n=xo(e);if(r==null){let o=qe(Rt.encode({Type:G.RSA,Data:t}));r=It(yo,o)}return new Ve(n,r)}function Wr(e){if(Bi(e)>mo)throw new H("Key size is too large");let t=Si(e),r=qe(Rt.encode({Type:G.RSA,Data:wo(t.publicKey)})),n=It(yo,r);return new dr(t.privateKey,new Ve(t.publicKey,n))}async function Ao(e){if(e>mo)throw new H("Key size is too large");let t=await vi(e),r=qe(Rt.encode({Type:G.RSA,Data:wo(t.publicKey)})),n=It(yo,r);return new dr(t.privateKey,new Ve(t.publicKey,n))}function Si(e){if(e==null)throw new H("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var Ii="1.2.840.113549.1.1.1";async function vi(e,t){let r=await X.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await bf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Ei(e,t,r){let n=await X.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await X.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ai(e,t,r,n){let o=await X.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await X.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function bf(e,t){if(e.privateKey==null||e.publicKey==null)throw new H("Private and public key are required");let r=await Promise.all([X.get().subtle.exportKey("jwk",e.privateKey),X.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Bi(e){if(e.kty!=="RSA")throw new H("invalid key type");if(e.n==null)throw new H("invalid key modulus");return Z(e.n,"base64url").length*8}var Xr=class extends Le{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Ir(t);let n=er(r);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 o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),bt(s)}update(t){return Ue(this),this.iHash.update(t),this}digestInto(t){Ue(this),Wt(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:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},mr=(e,t,r)=>new Xr(e,t).update(r).digest();mr.create=(e,t)=>new Xr(e,t);function _i(e){e.lowS!==void 0&&Dt("lowS",e.lowS),e.prehash!==void 0&&Dt("prehash",e.prehash)}function xf(e){let t=ar(e);Vt(t,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:r,Fp:n,a:o}=t;if(r){if(!n.eql(o,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...t})}var Bo=class extends Error{constructor(t=""){super(t)}},Ft={Err:Bo,_tlv:{encode:(e,t)=>{let{Err:r}=Ft;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=sr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?sr(o.length/2|128):"";return sr(e)+s+o+t},decode(e,t){let{Err:r}=Ft,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Ft;if(e<jt)throw new t("integer: negative integers are not allowed");let r=sr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Ft;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return qt(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Ft,o=Y("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l:f}=n.decode(2,a);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Ft,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}};function So(e,t){return Qt(de(e,t))}var jt=BigInt(0),ot=BigInt(1),_0=BigInt(2),vo=BigInt(3),wf=BigInt(4);function gf(e){let t=xf(e),{Fp:r}=t,n=zt(t.n,t.nBitLength),o=t.toBytes||((g,h,b)=>{let v=h.toAffine();return te(Uint8Array.from([4]),r.toBytes(v.x),r.toBytes(v.y))}),s=t.fromBytes||(g=>{let h=g.subarray(1),b=r.fromBytes(h.subarray(0,r.BYTES)),v=r.fromBytes(h.subarray(r.BYTES,2*r.BYTES));return{x:b,y:v}});function i(g){let{a:h,b}=t,v=r.sqr(g),B=r.mul(v,g);return r.add(r.add(B,r.mul(g,h)),b)}function c(g,h){let b=r.sqr(h),v=i(g);return r.eql(b,v)}if(!c(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let a=r.mul(r.pow(t.a,vo),wf),u=r.mul(r.sqr(t.b),BigInt(27));if(r.is0(r.add(a,u)))throw new Error("bad curve params: a or b");function f(g){return Rr(g,ot,t.n)}function l(g){let{allowedPrivateKeyLengths:h,nByteLength:b,wrapPrivateKey:v,n:B}=t;if(h&&typeof g!="bigint"){if(Te(g)&&(g=Qt(g)),typeof g!="string"||!h.includes(g.length))throw new Error("invalid private key");g=g.padStart(b*2,"0")}let _;try{_=typeof g=="bigint"?g:qt(Y("private key",g,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof g)}return v&&(_=j(_,B)),Et("private key",_,ot,B),_}function y(g){if(!(g instanceof m))throw new Error("ProjectivePoint expected")}let I=Pe((g,h)=>{let{px:b,py:v,pz:B}=g;if(r.eql(B,r.ONE))return{x:b,y:v};let _=g.is0();h==null&&(h=_?r.ONE:r.inv(B));let P=r.mul(b,h),N=r.mul(v,h),K=r.mul(B,h);if(_)return{x:r.ZERO,y:r.ZERO};if(!r.eql(K,r.ONE))throw new Error("invZ was invalid");return{x:P,y:N}}),S=Pe(g=>{if(g.is0()){if(t.allowInfinityPoint&&!r.is0(g.py))return;throw new Error("bad point: ZERO")}let{x:h,y:b}=g.toAffine();if(!r.isValid(h)||!r.isValid(b))throw new Error("bad point: x or y not FE");if(!c(h,b))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class m{constructor(h,b,v){if(h==null||!r.isValid(h))throw new Error("x required");if(b==null||!r.isValid(b)||r.is0(b))throw new Error("y required");if(v==null||!r.isValid(v))throw new Error("z required");this.px=h,this.py=b,this.pz=v,Object.freeze(this)}static fromAffine(h){let{x:b,y:v}=h||{};if(!h||!r.isValid(b)||!r.isValid(v))throw new Error("invalid affine point");if(h instanceof m)throw new Error("projective point not allowed");let B=_=>r.eql(_,r.ZERO);return B(b)&&B(v)?m.ZERO:new m(b,v,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let b=Re(r,h.map(v=>v.pz));return h.map((v,B)=>v.toAffine(b[B])).map(m.fromAffine)}static fromHex(h){let b=m.fromAffine(s(Y("pointHex",h)));return b.assertValidity(),b}static fromPrivateKey(h){return m.BASE.multiply(l(h))}static msm(h,b){return Hr(m,n,h,b)}_setWindowSize(h){O.setWindowSize(this,h)}assertValidity(){S(this)}hasEvenY(){let{y:h}=this.toAffine();if(r.isOdd)return!r.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){y(h);let{px:b,py:v,pz:B}=this,{px:_,py:P,pz:N}=h,K=r.eql(r.mul(b,N),r.mul(_,B)),R=r.eql(r.mul(v,N),r.mul(P,B));return K&&R}negate(){return new m(this.px,r.neg(this.py),this.pz)}double(){let{a:h,b}=t,v=r.mul(b,vo),{px:B,py:_,pz:P}=this,N=r.ZERO,K=r.ZERO,R=r.ZERO,T=r.mul(B,B),Q=r.mul(_,_),E=r.mul(P,P),w=r.mul(B,_);return w=r.add(w,w),R=r.mul(B,P),R=r.add(R,R),N=r.mul(h,R),K=r.mul(v,E),K=r.add(N,K),N=r.sub(Q,K),K=r.add(Q,K),K=r.mul(N,K),N=r.mul(w,N),R=r.mul(v,R),E=r.mul(h,E),w=r.sub(T,E),w=r.mul(h,w),w=r.add(w,R),R=r.add(T,T),T=r.add(R,T),T=r.add(T,E),T=r.mul(T,w),K=r.add(K,T),E=r.mul(_,P),E=r.add(E,E),T=r.mul(E,w),N=r.sub(N,T),R=r.mul(E,Q),R=r.add(R,R),R=r.add(R,R),new m(N,K,R)}add(h){y(h);let{px:b,py:v,pz:B}=this,{px:_,py:P,pz:N}=h,K=r.ZERO,R=r.ZERO,T=r.ZERO,Q=t.a,E=r.mul(t.b,vo),w=r.mul(b,_),L=r.mul(v,P),x=r.mul(B,N),d=r.add(b,v),p=r.add(_,P);d=r.mul(d,p),p=r.add(w,L),d=r.sub(d,p),p=r.add(b,B);let A=r.add(_,N);return p=r.mul(p,A),A=r.add(w,x),p=r.sub(p,A),A=r.add(v,B),K=r.add(P,N),A=r.mul(A,K),K=r.add(L,x),A=r.sub(A,K),T=r.mul(Q,p),K=r.mul(E,x),T=r.add(K,T),K=r.sub(L,T),T=r.add(L,T),R=r.mul(K,T),L=r.add(w,w),L=r.add(L,w),x=r.mul(Q,x),p=r.mul(E,p),L=r.add(L,x),x=r.sub(w,x),x=r.mul(Q,x),p=r.add(p,x),w=r.mul(L,p),R=r.add(R,w),w=r.mul(A,p),K=r.mul(d,K),K=r.sub(K,w),w=r.mul(d,L),T=r.mul(A,T),T=r.add(T,w),new m(K,R,T)}subtract(h){return this.add(h.negate())}is0(){return this.equals(m.ZERO)}wNAF(h){return O.wNAFCached(this,h,m.normalizeZ)}multiplyUnsafe(h){let{endo:b,n:v}=t;Et("scalar",h,jt,v);let B=m.ZERO;if(h===jt)return B;if(this.is0()||h===ot)return this;if(!b||O.hasPrecomputes(this))return O.wNAFCachedUnsafe(this,h,m.normalizeZ);let{k1neg:_,k1:P,k2neg:N,k2:K}=b.splitScalar(h),R=B,T=B,Q=this;for(;P>jt||K>jt;)P&ot&&(R=R.add(Q)),K&ot&&(T=T.add(Q)),Q=Q.double(),P>>=ot,K>>=ot;return _&&(R=R.negate()),N&&(T=T.negate()),T=new m(r.mul(T.px,b.beta),T.py,T.pz),R.add(T)}multiply(h){let{endo:b,n:v}=t;Et("scalar",h,ot,v);let B,_;if(b){let{k1neg:P,k1:N,k2neg:K,k2:R}=b.splitScalar(h),{p:T,f:Q}=this.wNAF(N),{p:E,f:w}=this.wNAF(R);T=O.constTimeNegate(P,T),E=O.constTimeNegate(K,E),E=new m(r.mul(E.px,b.beta),E.py,E.pz),B=T.add(E),_=Q.add(w)}else{let{p:P,f:N}=this.wNAF(h);B=P,_=N}return m.normalizeZ([B,_])[0]}multiplyAndAddUnsafe(h,b,v){let B=m.BASE,_=(N,K)=>K===jt||K===ot||!N.equals(B)?N.multiplyUnsafe(K):N.multiply(K),P=_(this,b).add(_(h,v));return P.is0()?void 0:P}toAffine(h){return I(this,h)}isTorsionFree(){let{h,isTorsionFree:b}=t;if(h===ot)return!0;if(b)return b(m,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:b}=t;return h===ot?this:b?b(m,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Dt("isCompressed",h),this.assertValidity(),o(m,this,h)}toHex(h=!0){return Dt("isCompressed",h),Qt(this.toRawBytes(h))}}m.BASE=new m(t.Gx,t.Gy,r.ONE),m.ZERO=new m(r.ZERO,r.ONE,r.ZERO);let{endo:D,nBitLength:U}=t,O=Nr(m,D?Math.ceil(U/2):U);return{CURVE:t,ProjectivePoint:m,normPrivateKeyToScalar:l,weierstrassEquation:i,isWithinCurveOrder:f}}function Ef(e){let t=ar(e);return Vt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Li(e){let t=Ef(e),{Fp:r,n,nByteLength:o,nBitLength:s}=t,i=r.BYTES+1,c=2*r.BYTES+1;function a(E){return j(E,n)}function u(E){return kr(E,n)}let{ProjectivePoint:f,normPrivateKeyToScalar:l,weierstrassEquation:y,isWithinCurveOrder:I}=gf({...t,toBytes(E,w,L){let x=w.toAffine(),d=r.toBytes(x.x),p=te;return Dt("isCompressed",L),L?p(Uint8Array.from([w.hasEvenY()?2:3]),d):p(Uint8Array.from([4]),d,r.toBytes(x.y))},fromBytes(E){let w=E.length,L=E[0],x=E.subarray(1);if(w===i&&(L===2||L===3)){let d=qt(x);if(!Rr(d,ot,r.ORDER))throw new Error("Point is not on curve");let p=y(d),A;try{A=r.sqrt(p)}catch(M){let q=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+q)}let C=(A&ot)===ot;return(L&1)===1!==C&&(A=r.neg(A)),{x:d,y:A}}else if(w===c&&L===4){let d=r.fromBytes(x.subarray(0,r.BYTES)),p=r.fromBytes(x.subarray(r.BYTES,2*r.BYTES));return{x:d,y:p}}else{let d=i,p=c;throw new Error("invalid Point, expected length of "+d+", or uncompressed "+p+", got "+w)}}});function S(E){let w=n>>ot;return E>w}function m(E){return S(E)?a(-E):E}let D=(E,w,L)=>qt(E.slice(w,L));class U{constructor(w,L,x){Et("r",w,ot,n),Et("s",L,ot,n),this.r=w,this.s=L,x!=null&&(this.recovery=x),Object.freeze(this)}static fromCompact(w){let L=o;return w=Y("compactSignature",w,L*2),new U(D(w,0,L),D(w,L,2*L))}static fromDER(w){let{r:L,s:x}=Ft.toSig(Y("DER",w));return new U(L,x)}assertValidity(){}addRecoveryBit(w){return new U(this.r,this.s,w)}recoverPublicKey(w){let{r:L,s:x,recovery:d}=this,p=B(Y("msgHash",w));if(d==null||![0,1,2,3].includes(d))throw new Error("recovery id invalid");let A=d===2||d===3?L+t.n:L;if(A>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let C=(d&1)===0?"02":"03",k=f.fromHex(C+So(A,r.BYTES)),M=u(A),q=a(-p*M),z=a(x*M),F=f.BASE.multiplyAndAddUnsafe(k,q,z);if(!F)throw new Error("point at infinify");return F.assertValidity(),F}hasHighS(){return S(this.s)}normalizeS(){return this.hasHighS()?new U(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return ir(this.toDERHex())}toDERHex(){return Ft.hexFromSig(this)}toCompactRawBytes(){return ir(this.toCompactHex())}toCompactHex(){let w=o;return So(this.r,w)+So(this.s,w)}}let O={isValidPrivateKey(E){try{return l(E),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let E=jn(t.n);return qs(t.randomBytes(E),t.n)},precompute(E=8,w=f.BASE){return w._setWindowSize(E),w.multiply(BigInt(3)),w}};function g(E,w=!0){return f.fromPrivateKey(E).toRawBytes(w)}function h(E){if(typeof E=="bigint")return!1;if(E instanceof f)return!0;let L=Y("key",E).length,x=r.BYTES,d=x+1,p=2*x+1;if(!(t.allowedPrivateKeyLengths||o===d))return L===d||L===p}function b(E,w,L=!0){if(h(E)===!0)throw new Error("first arg must be private key");if(h(w)===!1)throw new Error("second arg must be public key");return f.fromHex(w).multiply(l(E)).toRawBytes(L)}let v=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let w=qt(E),L=E.length*8-s;return L>0?w>>BigInt(L):w},B=t.bits2int_modN||function(E){return a(v(E))},_=pe(s);function P(E){return Et("num < 2^"+s,E,jt,_),de(E,o)}function N(E,w,L=K){if(["recovered","canonical"].some(J=>J in L))throw new Error("sign() legacy options not supported");let{hash:x,randomBytes:d}=t,{lowS:p,prehash:A,extraEntropy:C}=L;p==null&&(p=!0),E=Y("msgHash",E),_i(L),A&&(E=Y("prehashed msgHash",x(E)));let k=B(E),M=l(w),q=[P(M),P(k)];if(C!=null&&C!==!1){let J=C===!0?d(r.BYTES):C;q.push(Y("extraEntropy",J))}let z=te(...q),F=k;function tt(J){let st=v(J);if(!I(st))return;let yt=u(st),et=f.BASE.multiply(st).toAffine(),at=a(et.x);if(at===jt)return;let xt=a(yt*a(F+at*M));if(xt===jt)return;let Bt=(et.x===at?0:2)|Number(et.y&ot),ze=xt;return p&&S(xt)&&(ze=m(xt),Bt^=1),new U(at,ze,Bt)}return{seed:z,k2sig:tt}}let K={lowS:t.lowS,prehash:!1},R={lowS:t.lowS,prehash:!1};function T(E,w,L=K){let{seed:x,k2sig:d}=N(E,w,L),p=t;return Ds(p.hash.outputLen,p.nByteLength,p.hmac)(x,d)}f.BASE._setWindowSize(8);function Q(E,w,L,x=R){let d=E;w=Y("msgHash",w),L=Y("publicKey",L);let{lowS:p,prehash:A,format:C}=x;if(_i(x),"strict"in x)throw new Error("options.strict was renamed to lowS");if(C!==void 0&&C!=="compact"&&C!=="der")throw new Error("format must be compact or der");let k=typeof d=="string"||Te(d),M=!k&&!C&&typeof d=="object"&&d!==null&&typeof d.r=="bigint"&&typeof d.s=="bigint";if(!k&&!M)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let q,z;try{if(M&&(q=new U(d.r,d.s)),k){try{C!=="compact"&&(q=U.fromDER(d))}catch(Bt){if(!(Bt instanceof Ft.Err))throw Bt}!q&&C!=="der"&&(q=U.fromCompact(d))}z=f.fromHex(L)}catch{return!1}if(!q||p&&q.hasHighS())return!1;A&&(w=t.hash(w));let{r:F,s:tt}=q,J=B(w),st=u(tt),yt=a(J*st),et=a(F*st),at=f.BASE.multiplyAndAddUnsafe(z,yt,et)?.toAffine();return at?a(at.x)===F:!1}return{CURVE:t,getPublicKey:g,getSharedSecret:b,sign:T,verify:Q,ProjectivePoint:f,Signature:U,utils:O}}function Af(e){return{hash:e,hmac:(t,...r)=>mr(e,t,Rn(...r)),randomBytes:Ce}}function Ui(e,t){let r=n=>Li({...e,...Af(n)});return{...r(t),create:r}}var Ti=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ki=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Sf=BigInt(0),vf=BigInt(1),Io=BigInt(2),Ci=(e,t)=>(e+t/Io)/t;function Bf(e){let t=Ti,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=W(f,r,t)*f%t,y=W(l,r,t)*f%t,I=W(y,Io,t)*u%t,S=W(I,o,t)*I%t,m=W(S,s,t)*S%t,D=W(m,c,t)*m%t,U=W(D,a,t)*D%t,O=W(U,c,t)*m%t,g=W(O,r,t)*f%t,h=W(g,i,t)*S%t,b=W(h,n,t)*u%t,v=W(b,Io,t);if(!_o.eql(_o.sqr(v),e))throw new Error("Cannot find square root");return v}var _o=zt(Ti,void 0,void 0,{sqrt:Bf}),Kt=Ui({a:Sf,b:BigInt(7),Fp:_o,n:Ki,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=Ki,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-vf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,i=BigInt("0x100000000000000000000000000000000"),c=Ci(s*e,t),a=Ci(-n*e,t),u=j(e-c*r-a*o,t),f=j(-c*n-a*s,t),l=u>i,y=f>i;if(l&&(u=t-u),y&&(f=t-f),u>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:u,k2neg:y,k2:f}}}},Dr);var Di=33,Pi=32;function Ri(e,t,r){let n=Sr.digest(t instanceof Uint8Array?t:t.subarray());if(He(n))return n.then(({digest:o})=>(r?.signal?.throwIfAborted(),Kt.sign(o,e).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new Fe(String(o))});try{return Kt.sign(n.digest,e).toDERRawBytes()}catch(o){throw new Fe(String(o))}}function ki(e,t,r,n){let o=Sr.digest(r instanceof Uint8Array?r:r.subarray());if(He(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Kt.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new je(String(s))});try{return n?.signal?.throwIfAborted(),Kt.verify(t,o.digest,e)}catch(s){throw new je(String(s))}}var yr=class{type="secp256k1";raw;_key;constructor(t){this._key=Oi(t),this.raw=Ni(this._key)}toMultihash(){return se.digest(ae(this))}toCID(){return vt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}verify(t,r,n){return ki(this._key,r,t,n)}},br=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=Hi(t),this.publicKey=new yr(r??Mi(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}sign(t,r){return Ri(this.raw,t,r)}};function Lo(e){return new br(e)}function $r(e){return new yr(e)}async function qi(){let e=If();return new br(e)}function Ni(e){return Kt.ProjectivePoint.fromHex(e).toRawBytes(!0)}function Hi(e){try{return Kt.getPublicKey(e,!0),e}catch(t){throw new Ge(String(t))}}function Oi(e){try{return Kt.ProjectivePoint.fromHex(e),e}catch(t){throw new we(String(t))}}function Mi(e){try{return Kt.getPublicKey(e,!0)}catch(t){throw new Ge(String(t))}}function If(){return Kt.utils.randomPrivateKey()}var Jr={"P-256":32,"P-384":48,"P-521":66},_f=Object.keys(Jr),Uo=_f.join(" / ");async function Vi(e){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new H(`Unknown curve: ${e}. Must be ${Uo}`);let t=await X.get().subtle.generateKey({name:"ECDH",namedCurve:e},!0,["deriveBits"]),r=async(s,i)=>{let c;i!=null?c=await X.get().subtle.importKey("jwk",Uf(e,i),{name:"ECDH",namedCurve:e},!1,["deriveBits"]):c=t.privateKey;let a=await X.get().subtle.importKey("jwk",zi(e,s),{name:"ECDH",namedCurve:e},!1,[]),u=await X.get().subtle.deriveBits({name:"ECDH",public:a},c,Jr[e]*8);return new Uint8Array(u,0,u.byteLength)},n=await X.get().subtle.exportKey("jwk",t.publicKey);return{key:Lf(n),genSharedKey:r}}function Lf(e){if(e.crv==null||e.x==null||e.y==null)throw new H("JWK was missing components");if(e.crv!=="P-256"&&e.crv!=="P-384"&&e.crv!=="P-521")throw new H(`Unknown curve: ${e.crv}. Must be ${Uo}`);let t=Jr[e.crv];return Ct([Uint8Array.from([4]),Jn(e.x,t),Jn(e.y,t)],1+t*2)}function zi(e,t){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new H(`Unknown curve: ${e}. Must be ${Uo}`);let r=Jr[e];if(!ft(t.subarray(0,1),Uint8Array.from([4])))throw new H("Cannot unmarshal public key - invalid key format");return{kty:"EC",crv:e,x:V(t.subarray(1,r+1),"base64url"),y:V(t.subarray(1+r),"base64url"),ext:!0}}var Uf=(e,t)=>({...zi(e,t.public),d:V(t.private,"base64url")});var Kf={"AES-128":{ivSize:16,keySize:16},"AES-256":{ivSize:16,keySize:32},Blowfish:{ivSize:8,keySize:32}};async function Fi(e,t,r){if(e!=="AES-128"&&e!=="AES-256"&&e!=="Blowfish")throw new H("Cipher type was missing or unsupported");if(t!=="SHA1"&&t!=="SHA256"&&t!=="SHA512")throw new H("Hash type was missing or unsupported");if(r==null||!(r instanceof Uint8Array))throw new H("Secret was missing or an incorrect type");let n=Kf[e],o=n.keySize,s=n.ivSize,i=20,c=Z("key expansion"),a=2*(s+o+i),u=await en(t,r),f=await u.digest(c),l=[],y=0;for(;y<a;){let O=await u.digest(Ct([f,c])),g=O.length;y+g>a&&(g=a-y),l.push(O),y+=g,f=await u.digest(f)}let I=a/2,S=Ct(l),m=S.subarray(0,I),D=S.subarray(I,a),U=O=>({iv:O.subarray(0,s),cipherKey:O.subarray(s,s+o),macKey:O.subarray(s+o)});return{k1:U(m),k2:U(D)}}async function Cf(e,t){if(e==="Ed25519")return oi();if(e==="secp256k1")return qi();if(e==="RSA")return Ao(Of(t));if(e==="ECDSA")return ys(Mf(t));throw new Gt}async function Tf(e,t){if(e!=="Ed25519")throw new Gt("Seed key derivation only supported for Ed25519 keys");return si(t)}function Df(e,t){let{Type:r,Data:n}=Rt.decode(e),o=n??new Uint8Array;switch(r){case G.RSA:return Eo(o,t);case G.Ed25519:return Mr(o);case G.secp256k1:return $r(o);case G.ECDSA:return Cn(o);default:throw new Gt}}function Pf(e){if(e.byteLength===ee)return Mr(e);if(e.byteLength===Di)return $r(e);let t=gt(e),r=t[1]?.[0];if(r===_n||r===Ln||r===Un)return Tn(t);if(t[0]?.[0]===Ii)return Yr(t,e);throw new H("Could not extract public key from raw bytes")}function Rf(e){let{Type:t,Data:r}=Rt.decode(e.digest),n=r??new Uint8Array;switch(t){case G.Ed25519:return Mr(n);case G.secp256k1:return $r(n);case G.ECDSA:return Cn(n);default:throw new Gt}}function ae(e){return Rt.encode({Type:G[e.type],Data:e.raw})}function kf(e){let t=lr.decode(e),r=t.Data??new Uint8Array;switch(t.Type){case G.RSA:return go(r);case G.Ed25519:return Qn(r);case G.secp256k1:return Lo(r);case G.ECDSA:return ls(r);default:throw new Gt}}function Nf(e){if(e.byteLength===At)return Qn(e);if(e.byteLength===Pi)return Lo(e);let t=gt(e),r=t[2]?.[0];if(r===_n||r===Ln||r===Un)return Kn(t);if(t.length>8)return Zr(t);throw new H("Could not extract private key from raw bytes")}function Hf(e){return lr.encode({Type:G[e.type],Data:e.raw})}function Of(e){return e==null?2048:parseInt(e,10)}function Mf(e){if(e==="P-256"||e==null)return"P-256";if(e==="P-384")return"P-384";if(e==="P-521")return"P-521";throw new H("Unsupported curve, should be P-256, P-384 or P-521")}async function qf(e){if(e.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(e.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"ECDSA",namedCurve:e.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"ECDSA",namedCurve:e.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new H("Only RSA and ECDSA keys are supported")}async function Vf(e){if(e.privateKey.algorithm.name==="RSASSA-PKCS1-v1_5"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return Wr(t)}if(e.privateKey.algorithm.name==="ECDSA"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return new Ht(t)}throw new H("Only RSA and ECDSA keys are supported")}function zf(e,t,r,n){Ir(e);let o=xs({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:c}=o;if(Yt(s),Yt(i),Yt(c),s<1)throw new Error("iterations (c) should be >= 1");let a=Pn(t),u=Pn(r),f=new Uint8Array(i),l=mr.create(e,a),y=l._cloneInto().update(u);return{c:s,dkLen:i,asyncTick:c,DK:f,PRF:l,PRFSalt:y}}function Ff(e,t,r,n,o){return e.destroy(),t.destroy(),n&&n.destroy(),bt(o),r}function ji(e,t,r,n){let{c:o,dkLen:s,DK:i,PRF:c,PRFSalt:a}=zf(e,t,r,n),u,f=new Uint8Array(4),l=Ke(f),y=new Uint8Array(c.outputLen);for(let I=1,S=0;S<s;I++,S+=c.outputLen){let m=i.subarray(S,S+c.outputLen);l.setInt32(0,I,!1),(u=a._cloneInto(u)).update(f).digestInto(y),m.set(y.subarray(0,m.length));for(let D=1;D<o;D++){c._cloneInto(u).update(y).digestInto(y);for(let U=0;U<m.length;U++)m[U]^=y[U]}}return Ff(c,a,i,u,y)}var xr=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),oe=new Uint32Array(80),Qr=class extends fe{constructor(){super(64,20,8,!1),this.A=xr[0]|0,this.B=xr[1]|0,this.C=xr[2]|0,this.D=xr[3]|0,this.E=xr[4]|0}get(){let{A:t,B:r,C:n,D:o,E:s}=this;return[t,r,n,o,s]}set(t,r,n,o,s){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0}process(t,r){for(let a=0;a<16;a++,r+=4)oe[a]=t.getUint32(r,!1);for(let a=16;a<80;a++)oe[a]=_r(oe[a-3]^oe[a-8]^oe[a-14]^oe[a-16],1);let{A:n,B:o,C:s,D:i,E:c}=this;for(let a=0;a<80;a++){let u,f;a<20?(u=Lr(o,s,i),f=1518500249):a<40?(u=o^s^i,f=1859775393):a<60?(u=Ur(o,s,i),f=2400959708):(u=o^s^i,f=3395469782);let l=_r(n,5)+u+c+f+oe[a]|0;c=i,i=s,s=_r(o,30),o=n,n=l}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,this.set(n,o,s,i,c)}roundClean(){bt(oe)}destroy(){this.set(0,0,0,0,0),bt(this.buffer)}},Gi=rr(()=>new Qr);var Zi=Gi;var Yi=Pr;var Wi={sha1:Zi,"sha2-256":qe,"sha2-512":Yi};function Co(e,t,r,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let c=Object.keys(Wi).join(" / ");throw new H(`Hash '${o}' is unknown or not supported. Must be ${c}`)}let s=Wi[o],i=ji(s,e,t,{c:r,dkLen:n});return bn.encode(i).substring(1)}return oa(jf);})();
2
+ "use strict";var Libp2PCrypto=(()=>{var tn=Object.defineProperty;var zi=Object.getOwnPropertyDescriptor;var Fi=Object.getOwnPropertyNames;var ji=Object.prototype.hasOwnProperty;var et=(e,t)=>{for(var r in t)tn(e,r,{get:t[r],enumerable:!0})},Gi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Fi(t))!ji.call(e,o)&&o!==r&&tn(e,o,{get:()=>t[o],enumerable:!(n=zi(t,o))||n.enumerable});return e};var Zi=e=>Gi(tn({},"__esModule",{value:!0}),e);var Of={};et(Of,{hmac:()=>mr,keys:()=>Ao,pbkdf2:()=>So,randomBytes:()=>ao});var mr={};et(mr,{create:()=>en});var He=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},Oe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},pr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Bo={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new pr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var F=Bo;var vo={SHA1:20,SHA256:32,SHA512:64};var $i={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},Yi=async(e,t)=>{let r=await F.get().subtle.sign({name:"HMAC"},e,t);return new Uint8Array(r,0,r.byteLength)};async function en(e,t){let r=$i[e],n=await F.get().subtle.importKey("raw",t,{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return Yi(n,o)},length:vo[e]}}var Ao={};et(Ao,{generateEphemeralKeyPair:()=>Ri,generateKeyPair:()=>vf,generateKeyPairFromSeed:()=>If,keyStretcher:()=>ki,privateKeyFromCryptoKeyPair:()=>Nf,privateKeyFromProtobuf:()=>Tf,privateKeyFromRaw:()=>Uf,privateKeyToCryptoKeyPair:()=>Rf,privateKeyToProtobuf:()=>Cf,publicKeyFromMultihash:()=>Lf,publicKeyFromProtobuf:()=>_f,publicKeyFromRaw:()=>Kf,publicKeyToProtobuf:()=>Wt});var N=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},he=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},Me=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var Nt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var an={};et(an,{base58btc:()=>W,base58flickr:()=>ra});var Wf=new Uint8Array(0);function Io(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Kt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function _o(e){return new TextEncoder().encode(e)}function Ko(e){return new TextDecoder().decode(e)}function Wi(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,c=e.charAt(0),h=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function u(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var E=0,y=0,S=0,I=g.length;S!==I&&g[S]===0;)S++,E++;for(var B=(I-S)*f+1>>>0,C=new Uint8Array(B);S!==I;){for(var p=g[S],U=0,T=B-1;(p!==0||U<y)&&T!==-1;T--,U++)p+=256*C[T]>>>0,C[T]=p%a>>>0,p=p/a>>>0;if(p!==0)throw new Error("Non-zero carry");y=U,S++}for(var _=B-y;_!==B&&C[_]===0;)_++;for(var l=c.repeat(E);_<B;++_)l+=e.charAt(C[_]);return l}function m(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var E=0;if(g[E]!==" "){for(var y=0,S=0;g[E]===c;)y++,E++;for(var I=(g.length-E)*h+1>>>0,B=new Uint8Array(I);g[E];){var C=r[g.charCodeAt(E)];if(C===255)return;for(var p=0,U=I-1;(C!==0||p<S)&&U!==-1;U--,p++)C+=a*B[U]>>>0,B[U]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");S=p,E++}if(g[E]!==" "){for(var T=I-S;T!==I&&B[T]===0;)T++;for(var _=new Uint8Array(y+(I-T)),l=y;T!==I;)_[l++]=B[T++];return _}}}function b(g){var E=m(g);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:m,decode:b}}var Xi=Wi,Ji=Xi,To=Ji;var rn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},nn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,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 Uo(this,t)}},on=class{decoders;constructor(t){this.decoders=t}or(t){return Uo(this,t)}decode(t){let r=t[0],n=this.decoders[r];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 Uo(e,t){return new on({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var sn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new rn(t,r,n),this.decoder=new nn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function le({name:e,prefix:t,encode:r,decode:n}){return new sn(e,t,r,n)}function kt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=To(r,e);return le({prefix:t,name:e,encode:n,decode:s=>Kt(o(s))})}function Qi(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let h=0;h<o;++h){let f=t[e[h]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ta(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function ea(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function G({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=ea(n);return le({prefix:t,name:e,encode(s){return ta(s,n,r)},decode(s){return Qi(s,o,r,e)}})}var W=kt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ra=kt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var cn={};et(cn,{base32:()=>de,base32hex:()=>ia,base32hexpad:()=>ca,base32hexpadupper:()=>fa,base32hexupper:()=>aa,base32pad:()=>oa,base32padupper:()=>sa,base32upper:()=>na,base32z:()=>ua});var de=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),na=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),oa=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),sa=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ia=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),aa=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ca=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),fa=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ua=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var fn={};et(fn,{base36:()=>qe,base36upper:()=>ha});var qe=kt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ha=kt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var la=Po,Co=128,da=127,pa=~da,ma=Math.pow(2,31);function Po(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ma;)t[r++]=e&255|Co,e/=128;for(;e&pa;)t[r++]=e&255|Co,e>>>=7;return t[r]=e|0,Po.bytes=r-n+1,t}var ya=un,ba=128,Do=127;function un(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw un.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Do)<<o:(i&Do)*Math.pow(2,o),o+=7}while(i>=ba);return un.bytes=s-n,r}var xa=Math.pow(2,7),wa=Math.pow(2,14),ga=Math.pow(2,21),Ea=Math.pow(2,28),Aa=Math.pow(2,35),Sa=Math.pow(2,42),Ba=Math.pow(2,49),va=Math.pow(2,56),Ia=Math.pow(2,63),_a=function(e){return e<xa?1:e<wa?2:e<ga?3:e<Ea?4:e<Aa?5:e<Sa?6:e<Ba?7:e<va?8:e<Ia?9:10},Ka={encode:la,decode:ya,encodingLength:_a},La=Ka,Ve=La;function ze(e,t=0){return[Ve.decode(e,t),Ve.decode.bytes]}function pe(e,t,r=0){return Ve.encode(e,t,r),t}function me(e){return Ve.encodingLength(e)}function bt(e,t){let r=t.byteLength,n=me(e),o=n+me(r),s=new Uint8Array(o+r);return pe(e,s,0),pe(r,s,n),s.set(t,o),new ye(e,r,t,s)}function Ro(e){let t=Kt(e),[r,n]=ze(t),[o,s]=ze(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ye(r,o,i,t)}function No(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Io(e.bytes,r.bytes)}}var ye=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function ko(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Ua(r,hn(e),t??W.encoder);default:return Ca(r,hn(e),t??de.encoder)}}var Ho=new WeakMap;function hn(e){let t=Ho.get(e);if(t==null){let r=new Map;return Ho.set(e,r),r}return t}var yt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}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:r}=this;if(t!==je)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Da)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}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:r}=this.multihash,n=bt(t,r);return e.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 e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&No(t.multihash,n.multihash)}toString(t){return ko(this,t)}toJSON(){return{"/":ko(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 r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Oo(n,o,s.bytes))}else if(r[Pa]===!0){let{version:n,multihash:o,code:s}=r,i=Ro(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="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(r!==je)throw new Error(`Version 0 CID must use dag-pb (code: ${je}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Oo(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,je,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Kt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new ye(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[u,m]=ze(t.subarray(r));return r+=m,u},o=n(),s=je;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),h=r+c,f=h-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:h}}static parse(t,r){let[n,o]=Ta(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return hn(s).set(n,t),s}};function Ta(e,t){switch(e[0]){case"Q":{let r=t??W;return[W.prefix,r.decode(`${W.prefix}${e}`)]}case W.prefix:{let r=t??W;return[W.prefix,r.decode(e)]}case de.prefix:{let r=t??de;return[de.prefix,r.decode(e)]}case qe.prefix:{let r=t??qe;return[qe.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Ua(e,t,r){let{prefix:n}=r;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Ca(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var je=112,Da=18;function Oo(e,t,r){let n=me(e),o=n+me(t),s=new Uint8Array(o+r.byteLength);return pe(e,s,0),pe(t,s,n),s.set(r,o),s}var Pa=Symbol.for("@ipld/js-cid/CID");var ln={};et(ln,{identity:()=>$t});var Mo=0,Ra="identity",qo=Kt;function Na(e){return bt(Mo,qo(e))}var $t={code:Mo,name:Ra,encode:qo,digest:Na};function rt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Lt(e=0){return new Uint8Array(e)}function ht(e=0){return new Uint8Array(e)}function St(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ht(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var zo=Symbol.for("@achingbrain/uint8arraylist");function Vo(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function br(e){return!!e?.[zo]}var st=class e{bufs;length;[zo]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(br(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(br(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Vo(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Vo(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(br(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return St(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:St(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let h=t>=a&&t<c,f=r>a&&r<=c;if(h&&f){if(t===a&&r===c){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(r-t)));break}if(h){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!br(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let u=0;u<s;u++)i[u]=-1;for(let u=0;u<o;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,h=n.byteLength-1,f;for(let u=r;u<=c;u+=f){f=0;for(let m=h;m>=0;m--){let b=this.get(u+m);if(n[m]!==b){f=Math.max(1,m-a[b]);break}}if(f===0)return u}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ht(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Lt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Lt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Lt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ht(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Lt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Lt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Lt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Lt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Lt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!rt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var dn={};et(dn,{base10:()=>ka});var ka=kt({prefix:"9",name:"base10",alphabet:"0123456789"});var pn={};et(pn,{base16:()=>Ha,base16upper:()=>Oa});var Ha=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Oa=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var mn={};et(mn,{base2:()=>Ma});var Ma=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var yn={};et(yn,{base256emoji:()=>ja});var Fo=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),qa=Fo.reduce((e,t,r)=>(e[r]=t,e),[]),Va=Fo.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function za(e){return e.reduce((t,r)=>(t+=qa[r],t),"")}function Fa(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Va[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var ja=le({prefix:"\u{1F680}",name:"base256emoji",encode:za,decode:Fa});var xn={};et(xn,{base64:()=>bn,base64pad:()=>Ga,base64url:()=>Za,base64urlpad:()=>$a});var bn=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ga=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Za=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),$a=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var wn={};et(wn,{base8:()=>Ya});var Ya=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var gn={};et(gn,{identity:()=>Wa});var Wa=le({prefix:"\0",name:"identity",encode:e=>Ko(e),decode:e=>_o(e)});var Du=new TextEncoder,Pu=new TextDecoder;var Sn={};et(Sn,{sha256:()=>xr,sha512:()=>Qa});function An({name:e,code:t,encode:r}){return new En(e,t,r)}var En=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?bt(this.code,r):r.then(n=>bt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Go(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var xr=An({name:"sha2-256",code:18,encode:Go("SHA-256")}),Qa=An({name:"sha2-512",code:19,encode:Go("SHA-512")});var Bn={...gn,...mn,...wn,...dn,...pn,...cn,...fn,...an,...xn,...yn},Gu={...Sn,...ln};function $o(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Zo=$o("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),vn=$o("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ht(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),tc={utf8:Zo,"utf-8":Zo,hex:Bn.base16,latin1:vn,ascii:vn,binary:vn,...Bn},wr=tc;function q(e,t="utf8"){let r=wr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function k(e,t="utf8"){let r=wr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var ec=parseInt("11111",2),In=parseInt("10000000",2),rc=parseInt("01111111",2),Yo={0:Ge,1:Ge,2:nc,3:ic,4:ac,5:sc,6:oc,16:Ge,22:Ge,48:Ge};function lt(e,t={offset:0}){let r=e[t.offset]&ec;if(t.offset++,Yo[r]!=null)return Yo[r](e,t);throw new Error("No decoder for tag "+r)}function Ze(e,t){let r=0;if((e[t.offset]&In)===In){let n=e[t.offset]&rc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Ge(e,t){Ze(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=lt(e,t);if(n===null)break;r.push(n)}return r}function nc(e,t){let r=Ze(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function oc(e,t){let r=Ze(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let h=e[t.offset];if(t.offset++,c.push(h&127),h<128){c.reverse();let f=0;for(let u=0;u<c.length;u++)f+=c[u]<<u*7;a+=`.${f}`,c=[]}}return a}function sc(e,t){return t.offset++,null}function ic(e,t){let r=Ze(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function ac(e,t){let r=Ze(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function cc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new st;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function gr(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=cc(e.byteLength);return new st(Uint8Array.from([t.byteLength|In]),t)}function it(e){let t=new st,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new st(Uint8Array.from([2]),gr(t),t)}function $e(e){let t=Uint8Array.from([0]),r=new st(t,e);return new st(Uint8Array.from([3]),gr(r),r)}function Wo(e){return new st(Uint8Array.from([4]),gr(e),e)}function xt(e,t=48){let r=new st;for(let n of e)r.append(n);return new st(Uint8Array.from([t]),gr(r),r)}var _n="1.2.840.10045.3.1.7",Kn="1.3.132.0.34",Ln="1.3.132.0.35";async function Xo(e="P-256"){let t=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:e},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",t.publicKey),privateKey:await crypto.subtle.exportKey("jwk",t.privateKey)}}async function Jo(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["sign"]);r?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Qo(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var fc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),uc=Uint8Array.from([6,5,43,129,4,0,34]),hc=Uint8Array.from([6,5,43,129,4,0,35]),ts={ext:!0,kty:"EC",crv:"P-256"},es={ext:!0,kty:"EC",crv:"P-384"},rs={ext:!0,kty:"EC",crv:"P-521"},be=32,xe=48,we=66;function ns(e){let t=lt(e);return Tn(t)}function Tn(e){let t=e[1],r=k(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===be)return s=k(n.subarray(o,o+be),"base64url"),i=k(n.subarray(o+be),"base64url"),new Tt({...ts,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===xe)return s=k(n.subarray(o,o+xe),"base64url"),i=k(n.subarray(o+xe),"base64url"),new Tt({...es,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===we)return s=k(n.subarray(o,o+we),"base64url"),i=k(n.subarray(o+we),"base64url"),new Tt({...rs,key_ops:["sign"],d:r,x:s,y:i});throw new N(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function Un(e){let t=lt(e);return Cn(t)}function Cn(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===be*2+1)return n=k(t.subarray(r,r+be),"base64url"),o=k(t.subarray(r+be),"base64url"),new Yt({...ts,key_ops:["verify"],x:n,y:o});if(t.byteLength===xe*2+1)return n=k(t.subarray(r,r+xe),"base64url"),o=k(t.subarray(r+xe),"base64url"),new Yt({...es,key_ops:["verify"],x:n,y:o});if(t.byteLength===we*2+1)return n=k(t.subarray(r,r+we),"base64url"),o=k(t.subarray(r+we),"base64url"),new Yt({...rs,key_ops:["verify"],x:n,y:o});throw new N(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function os(e){return xt([it(Uint8Array.from([1])),Wo(q(e.d??"","base64url")),xt([is(e.crv)],160),xt([$e(new st(Uint8Array.from([4]),q(e.x??"","base64url"),q(e.y??"","base64url")))],161)]).subarray()}function ss(e){return xt([it(Uint8Array.from([1])),xt([is(e.crv)],160),xt([$e(new st(Uint8Array.from([4]),q(e.x??"","base64url"),q(e.y??"","base64url")))],161)]).subarray()}function is(e){if(e==="P-256")return fc;if(e==="P-384")return uc;if(e==="P-521")return hc;throw new N(`Invalid curve ${e}`)}async function as(e="P-256"){let t=await Xo(e);return new Tt(t.privateKey)}var Yt=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ss(this.jwk)),this._raw}toMultihash(){return $t.digest(Wt(this))}toCID(){return yt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}async verify(t,r,n){return Qo(this.jwk,r,t,n)}},Tt=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new Yt({crv:t.crv,ext:t.ext,key_ops:["verify"],kty:"EC",x:t.x,y:t.y})}get raw(){return this._raw==null&&(this._raw=os(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}async sign(t,r){return Jo(this.jwk,t,r)}};var Xt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ee(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ct(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function J(e,...t){if(!Ee(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Er(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Ct(e.outputLen),Ct(e.blockLen)}function Ae(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function fs(e,t){J(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function ut(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Se(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function wt(e,t){return e<<32-t|e>>>t}function Ar(e,t){return e<<t|e>>>32-t>>>0}var us=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",lc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Bt(e){if(J(e),us)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=lc[e[r]];return t}var Ut={_0:48,_9:57,A:65,F:70,a:97,f:102};function cs(e){if(e>=Ut._0&&e<=Ut._9)return e-Ut._0;if(e>=Ut.A&&e<=Ut.F)return e-(Ut.A-10);if(e>=Ut.a&&e<=Ut.f)return e-(Ut.a-10)}function Be(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(us)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=cs(e.charCodeAt(s)),a=cs(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Dn(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Ye(e){return typeof e=="string"&&(e=Dn(e)),J(e),e}function Pn(e){return typeof e=="string"&&(e=Dn(e)),J(e),e}function dt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];J(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function hs(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(e,t)}var ge=class{};function We(e){let t=n=>e().update(Ye(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Jt(e=32){if(Xt&&typeof Xt.getRandomValues=="function")return Xt.getRandomValues(new Uint8Array(e));if(Xt&&typeof Xt.randomBytes=="function")return Uint8Array.from(Xt.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function dc(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?4:0,h=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+h,a,n)}function Sr(e,t,r){return e&t^~e&r}function Br(e,t,r){return e&t^e&r^t&r}var Qt=class extends ge{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Se(this.buffer)}update(t){Ae(this),t=Ye(t),J(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Se(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ae(this),fs(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,ut(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let u=i;u<o;u++)r[u]=0;dc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Se(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let h=c/4,f=this.get();if(h>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<h;u++)a.setUint32(4*u,f[u],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Dt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Q=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var vr=BigInt(4294967295),ls=BigInt(32);function pc(e,t=!1){return t?{h:Number(e&vr),l:Number(e>>ls&vr)}:{h:Number(e>>ls&vr)|0,l:Number(e&vr)|0}}function ds(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=pc(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Rn=(e,t,r)=>e>>>r,Nn=(e,t,r)=>e<<32-r|t>>>r,te=(e,t,r)=>e>>>r|t<<32-r,ee=(e,t,r)=>e<<32-r|t>>>r,Xe=(e,t,r)=>e<<64-r|t>>>r-32,Je=(e,t,r)=>e>>>r-32|t<<64-r;function vt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ps=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ms=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ys=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),bs=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,xs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ws=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var yc=Uint32Array.from([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]),Ht=new Uint32Array(64),Ir=class extends Qt{constructor(t=32){super(64,t,8,!1),this.A=Dt[0]|0,this.B=Dt[1]|0,this.C=Dt[2]|0,this.D=Dt[3]|0,this.E=Dt[4]|0,this.F=Dt[5]|0,this.G=Dt[6]|0,this.H=Dt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let u=0;u<16;u++,r+=4)Ht[u]=t.getUint32(r,!1);for(let u=16;u<64;u++){let m=Ht[u-15],b=Ht[u-2],g=wt(m,7)^wt(m,18)^m>>>3,E=wt(b,17)^wt(b,19)^b>>>10;Ht[u]=E+Ht[u-7]+g+Ht[u-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:h,H:f}=this;for(let u=0;u<64;u++){let m=wt(a,6)^wt(a,11)^wt(a,25),b=f+m+Sr(a,c,h)+yc[u]+Ht[u]|0,E=(wt(n,2)^wt(n,13)^wt(n,22))+Br(n,o,s)|0;f=h,h=c,c=a,a=i+b|0,i=s,s=o,o=n,n=b+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,h=h+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,h,f)}roundClean(){ut(Ht)}destroy(){this.set(0,0,0,0,0,0,0,0),ut(this.buffer)}};var gs=ds(["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(e=>BigInt(e))),bc=gs[0],xc=gs[1],Ot=new Uint32Array(80),Mt=new Uint32Array(80),_r=class extends Qt{constructor(t=64){super(128,t,16,!1),this.Ah=Q[0]|0,this.Al=Q[1]|0,this.Bh=Q[2]|0,this.Bl=Q[3]|0,this.Ch=Q[4]|0,this.Cl=Q[5]|0,this.Dh=Q[6]|0,this.Dl=Q[7]|0,this.Eh=Q[8]|0,this.El=Q[9]|0,this.Fh=Q[10]|0,this.Fl=Q[11]|0,this.Gh=Q[12]|0,this.Gl=Q[13]|0,this.Hh=Q[14]|0,this.Hl=Q[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:h,El:f,Fh:u,Fl:m,Gh:b,Gl:g,Hh:E,Hl:y}=this;return[t,r,n,o,s,i,a,c,h,f,u,m,b,g,E,y]}set(t,r,n,o,s,i,a,c,h,f,u,m,b,g,E,y){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=h|0,this.El=f|0,this.Fh=u|0,this.Fl=m|0,this.Gh=b|0,this.Gl=g|0,this.Hh=E|0,this.Hl=y|0}process(t,r){for(let B=0;B<16;B++,r+=4)Ot[B]=t.getUint32(r),Mt[B]=t.getUint32(r+=4);for(let B=16;B<80;B++){let C=Ot[B-15]|0,p=Mt[B-15]|0,U=te(C,p,1)^te(C,p,8)^Rn(C,p,7),T=ee(C,p,1)^ee(C,p,8)^Nn(C,p,7),_=Ot[B-2]|0,l=Mt[B-2]|0,w=te(_,l,19)^Xe(_,l,61)^Rn(_,l,6),d=ee(_,l,19)^Je(_,l,61)^Nn(_,l,6),x=ys(T,d,Mt[B-7],Mt[B-16]),A=bs(x,U,w,Ot[B-7],Ot[B-16]);Ot[B]=A|0,Mt[B]=x|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:h,Dl:f,Eh:u,El:m,Fh:b,Fl:g,Gh:E,Gl:y,Hh:S,Hl:I}=this;for(let B=0;B<80;B++){let C=te(u,m,14)^te(u,m,18)^Xe(u,m,41),p=ee(u,m,14)^ee(u,m,18)^Je(u,m,41),U=u&b^~u&E,T=m&g^~m&y,_=xs(I,p,T,xc[B],Mt[B]),l=ws(_,S,C,U,bc[B],Ot[B]),w=_|0,d=te(n,o,28)^Xe(n,o,34)^Xe(n,o,39),x=ee(n,o,28)^Je(n,o,34)^Je(n,o,39),A=n&s^n&a^s&a,K=o&i^o&c^i&c;S=E|0,I=y|0,E=b|0,y=g|0,b=u|0,g=m|0,{h:u,l:m}=vt(h|0,f|0,l|0,w|0),h=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let v=ps(w,x,K);n=ms(v,l,d,A),o=v|0}({h:n,l:o}=vt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=vt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=vt(this.Ch|0,this.Cl|0,a|0,c|0),{h,l:f}=vt(this.Dh|0,this.Dl|0,h|0,f|0),{h:u,l:m}=vt(this.Eh|0,this.El|0,u|0,m|0),{h:b,l:g}=vt(this.Fh|0,this.Fl|0,b|0,g|0),{h:E,l:y}=vt(this.Gh|0,this.Gl|0,E|0,y|0),{h:S,l:I}=vt(this.Hh|0,this.Hl|0,S|0,I|0),this.set(n,o,s,i,a,c,h,f,u,m,b,g,E,y,S,I)}roundClean(){ut(Ot,Mt)}destroy(){ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Kr=We(()=>new Ir);var Lr=We(()=>new _r);var On=BigInt(0),Hn=BigInt(1);function Pt(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function Qe(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Es(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?On:BigInt("0x"+e)}function ve(e){return Es(Bt(e))}function re(e){return J(e),Es(Bt(Uint8Array.from(e).reverse()))}function Tr(e,t){return Be(e.toString(16).padStart(t*2,"0"))}function Ie(e,t){return Tr(e,t).reverse()}function V(e,t,r){let n;if(typeof t=="string")try{n=Be(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ee(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}var kn=e=>typeof e=="bigint"&&On<=e;function As(e,t,r){return kn(e)&&kn(t)&&kn(r)&&t<=e&&e<r}function qt(e,t,r,n){if(!As(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ss(e){let t;for(t=0;e>On;e>>=Hn,t+=1);return t}var ne=e=>(Hn<<BigInt(e))-Hn;function Bs(e,t,r){if(typeof e!="number"||e<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 r!="function")throw new Error("hmacFn must be a function");let n=b=>new Uint8Array(b),o=b=>Uint8Array.of(b),s=n(e),i=n(e),a=0,c=()=>{s.fill(1),i.fill(0),a=0},h=(...b)=>r(i,s,...b),f=(b=n(0))=>{i=h(o(0),b),s=h(),b.length!==0&&(i=h(o(1),b),s=h())},u=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let b=0,g=[];for(;b<t;){s=h();let E=s.slice();g.push(E),b+=s.length}return dt(...g)};return(b,g)=>{c(),f(b);let E;for(;!(E=g(u()));)f();return c(),E}}function Vt(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let a=e[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}function _e(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var at=BigInt(0),X=BigInt(1),oe=BigInt(2),wc=BigInt(3),_s=BigInt(4),Ks=BigInt(5),Ls=BigInt(8);function j(e,t){let r=e%t;return r>=at?r:t+r}function z(e,t,r){let n=e;for(;t-- >at;)n*=n,n%=r;return n}function vs(e,t){if(e===at)throw new Error("invert: expected non-zero number");if(t<=at)throw new Error("invert: expected positive modulus, got "+t);let r=j(e,t),n=t,o=at,s=X,i=X,a=at;for(;r!==at;){let h=n/r,f=n%r,u=o-i*h,m=s-a*h;n=r,r=f,o=i,s=a,i=u,a=m}if(n!==X)throw new Error("invert: does not exist");return j(o,t)}function Ts(e,t){let r=(e.ORDER+X)/_s,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function gc(e,t){let r=(e.ORDER-Ks)/Ls,n=e.mul(t,oe),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,oe),o),a=e.mul(s,e.sub(i,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}function Ec(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%oe===at;)t/=oe,r++;let n=oe,o=gt(e);for(;Is(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ts;let s=o.pow(n,t),i=(t+X)/oe;return function(c,h){if(c.is0(h))return h;if(Is(c,h)!==1)throw new Error("Cannot find square root");let f=r,u=c.mul(c.ONE,s),m=c.pow(h,t),b=c.pow(h,i);for(;!c.eql(m,c.ONE);){if(c.is0(m))return c.ZERO;let g=1,E=c.sqr(m);for(;!c.eql(E,c.ONE);)if(g++,E=c.sqr(E),g===f)throw new Error("Cannot find square root");let y=X<<BigInt(f-g-1),S=c.pow(u,y);f=g,u=c.sqr(S),m=c.mul(m,u),b=c.mul(b,S)}return b}}function Ac(e){return e%_s===wc?Ts:e%Ls===Ks?gc:Ec(e)}var Us=(e,t)=>(j(e,t)&X)===X,Sc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Mn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Sc.reduce((n,o)=>(n[o]="function",n),t);return Vt(e,r),e}function Bc(e,t,r){if(r<at)throw new Error("invalid exponent, negatives unsupported");if(r===at)return e.ONE;if(r===X)return t;let n=e.ONE,o=t;for(;r>at;)r&X&&(n=e.mul(n,o)),o=e.sqr(o),r>>=X;return n}function tr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function Is(e,t){let r=(e.ORDER-X)/oe,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Cs(e,t){t!==void 0&&Ct(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function gt(e,t,r=!1,n={}){if(e<=at)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=Cs(e,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,h=Object.freeze({ORDER:e,isLE:r,BITS:i,BYTES:a,MASK:ne(i),ZERO:at,ONE:X,create:f=>j(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return at<=f&&f<e},is0:f=>f===at,isValidNot0:f=>!h.is0(f)&&h.isValid(f),isOdd:f=>(f&X)===X,neg:f=>j(-f,e),eql:(f,u)=>f===u,sqr:f=>j(f*f,e),add:(f,u)=>j(f+u,e),sub:(f,u)=>j(f-u,e),mul:(f,u)=>j(f*u,e),pow:(f,u)=>Bc(h,f,u),div:(f,u)=>j(f*vs(u,e),e),sqrN:f=>f*f,addN:(f,u)=>f+u,subN:(f,u)=>f-u,mulN:(f,u)=>f*u,inv:f=>vs(f,e),sqrt:s||(f=>(c||(c=Ac(e)),c(h,f))),toBytes:f=>r?Ie(f,a):Tr(f,a),fromBytes:f=>{if(f.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);return r?re(f):ve(f)},invertBatch:f=>tr(h,f),cmov:(f,u,m)=>m?u:f});return Object.freeze(h)}function Ds(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function qn(e){let t=Ds(e);return t+Math.ceil(t/2)}function Ps(e,t,r=!1){let n=e.length,o=Ds(t),s=qn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?re(e):ve(e),a=j(i,t-X)+X;return r?Ie(a,o):Tr(a,o)}var Le=BigInt(0),se=BigInt(1);function Ke(e,t){let r=t.negate();return e?r:t}function Ur(e,t,r){let n=t==="pz"?i=>i.pz:i=>i.ez,o=tr(e.Fp,r.map(n));return r.map((i,a)=>i.toAffine(o[a])).map(e.fromAffine)}function Hs(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Vn(e,t){Hs(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=ne(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Rs(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=se);let h=t*n,f=h+Math.abs(a)-1,u=a===0,m=a<0,b=t%2!==0;return{nextN:c,offset:f,isZero:u,isNeg:m,isNegF:b,offsetF:h}}function vc(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Ic(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var zn=new WeakMap,Os=new WeakMap;function Fn(e){return Os.get(e)||1}function Ns(e){if(e!==Le)throw new Error("invalid wNAF")}function Cr(e,t){return{constTimeNegate:Ke,hasPrecomputes(r){return Fn(r)!==1},unsafeLadder(r,n,o=e.ZERO){let s=r;for(;n>Le;)n&se&&(o=o.add(s)),s=s.double(),n>>=se;return o},precomputeWindow(r,n){let{windows:o,windowSize:s}=Vn(n,t),i=[],a=r,c=a;for(let h=0;h<o;h++){c=a,i.push(c);for(let f=1;f<s;f++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(r,n,o){let s=e.ZERO,i=e.BASE,a=Vn(r,t);for(let c=0;c<a.windows;c++){let{nextN:h,offset:f,isZero:u,isNeg:m,isNegF:b,offsetF:g}=Rs(o,c,a);o=h,u?i=i.add(Ke(b,n[g])):s=s.add(Ke(m,n[f]))}return Ns(o),{p:s,f:i}},wNAFUnsafe(r,n,o,s=e.ZERO){let i=Vn(r,t);for(let a=0;a<i.windows&&o!==Le;a++){let{nextN:c,offset:h,isZero:f,isNeg:u}=Rs(o,a,i);if(o=c,!f){let m=n[h];s=s.add(u?m.negate():m)}}return Ns(o),s},getPrecomputes(r,n,o){let s=zn.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&(typeof o=="function"&&(s=o(s)),zn.set(n,s))),s},wNAFCached(r,n,o){let s=Fn(r);return this.wNAF(s,this.getPrecomputes(s,r,o),n)},wNAFCachedUnsafe(r,n,o,s){let i=Fn(r);return i===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,r,o),n,s)},setWindowSize(r,n){Hs(n,t),Os.set(r,n),zn.delete(r)}}}function Ms(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Le||n>Le;)r&se&&(s=s.add(o)),n&se&&(i=i.add(o)),o=o.double(),r>>=se,n>>=se;return{p1:s,p2:i}}function Dr(e,t,r,n){vc(r,e),Ic(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,a=Ss(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let h=ne(c),f=new Array(Number(h)+1).fill(i),u=Math.floor((t.BITS-1)/c)*c,m=i;for(let b=u;b>=0;b-=c){f.fill(i);for(let E=0;E<s;E++){let y=n[E],S=Number(y>>BigInt(b)&h);f[S]=f[S].add(r[E])}let g=i;for(let E=f.length-1,y=i;E>0;E--)y=y.add(f[E]),g=g.add(y);if(m=m.add(g),b!==0)for(let E=0;E<c;E++)m=m.double()}return m}function ks(e,t){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Mn(t),t}else return gt(e)}function Pr(e,t,r={}){if(!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>Le))throw new Error(`CURVE.${a} must be positive bigint`)}let n=ks(t.p,r.Fp),o=ks(t.n,r.Fn),i=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var It=BigInt(0),ct=BigInt(1),jn=BigInt(2),_c=BigInt(8),Kc={zip215:!0};function Lc(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function Tc(e,t={}){let{Fp:r,Fn:n}=Pr("edwards",e,t),{h:o,n:s}=e;Vt(t,{},{uvRatio:"function"});let i=jn<<BigInt(n.BYTES*8)-ct,a=E=>r.create(E),c=t.uvRatio||((E,y)=>{try{return{isValid:!0,value:r.sqrt(r.div(E,y))}}catch{return{isValid:!1,value:It}}});if(!Lc(r,e,e.Gx,e.Gy))throw new Error("bad curve params: generator point");function h(E,y,S=!1){let I=S?ct:It;return qt("coordinate "+E,y,I,i),y}function f(E){if(!(E instanceof b))throw new Error("ExtendedPoint expected")}let u=_e((E,y)=>{let{ex:S,ey:I,ez:B}=E,C=E.is0();y==null&&(y=C?_c:r.inv(B));let p=a(S*y),U=a(I*y),T=a(B*y);if(C)return{x:It,y:ct};if(T!==ct)throw new Error("invZ was invalid");return{x:p,y:U}}),m=_e(E=>{let{a:y,d:S}=e;if(E.is0())throw new Error("bad point: ZERO");let{ex:I,ey:B,ez:C,et:p}=E,U=a(I*I),T=a(B*B),_=a(C*C),l=a(_*_),w=a(U*y),d=a(_*a(w+T)),x=a(l+a(S*a(U*T)));if(d!==x)throw new Error("bad point: equation left != right (1)");let A=a(I*B),K=a(C*p);if(A!==K)throw new Error("bad point: equation left != right (2)");return!0});class b{constructor(y,S,I,B){this.ex=h("x",y),this.ey=h("y",S),this.ez=h("z",I,!0),this.et=h("t",B),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(y){if(y instanceof b)throw new Error("extended point not allowed");let{x:S,y:I}=y||{};return h("x",S),h("y",I),new b(S,I,ct,a(S*I))}static normalizeZ(y){return Ur(b,"ez",y)}static msm(y,S){return Dr(b,n,y,S)}_setWindowSize(y){this.precompute(y)}precompute(y=8,S=!0){return g.setWindowSize(this,y),S||this.multiply(jn),this}assertValidity(){m(this)}equals(y){f(y);let{ex:S,ey:I,ez:B}=this,{ex:C,ey:p,ez:U}=y,T=a(S*U),_=a(C*B),l=a(I*U),w=a(p*B);return T===_&&l===w}is0(){return this.equals(b.ZERO)}negate(){return new b(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:y}=e,{ex:S,ey:I,ez:B}=this,C=a(S*S),p=a(I*I),U=a(jn*a(B*B)),T=a(y*C),_=S+I,l=a(a(_*_)-C-p),w=T+p,d=w-U,x=T-p,A=a(l*d),K=a(w*x),v=a(l*x),L=a(d*w);return new b(A,K,L,v)}add(y){f(y);let{a:S,d:I}=e,{ex:B,ey:C,ez:p,et:U}=this,{ex:T,ey:_,ez:l,et:w}=y,d=a(B*T),x=a(C*_),A=a(U*I*w),K=a(p*l),v=a((B+C)*(T+_)-d-x),L=K-A,P=K+A,D=a(x-S*d),Z=a(v*L),H=a(P*D),R=a(v*D),$=a(L*P);return new b(Z,H,$,R)}subtract(y){return this.add(y.negate())}multiply(y){let S=y;qt("scalar",S,ct,s);let{p:I,f:B}=g.wNAFCached(this,S,b.normalizeZ);return b.normalizeZ([I,B])[0]}multiplyUnsafe(y,S=b.ZERO){let I=y;return qt("scalar",I,It,s),I===It?b.ZERO:this.is0()||I===ct?this:g.wNAFCachedUnsafe(this,I,b.normalizeZ,S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return g.wNAFCachedUnsafe(this,s).is0()}toAffine(y){return u(this,y)}clearCofactor(){return o===ct?this:this.multiplyUnsafe(o)}static fromBytes(y,S=!1){return J(y),this.fromHex(y,S)}static fromHex(y,S=!1){let{d:I,a:B}=e,C=r.BYTES;y=V("pointHex",y,C),Pt("zip215",S);let p=y.slice(),U=y[C-1];p[C-1]=U&-129;let T=re(p),_=S?i:r.ORDER;qt("pointHex.y",T,It,_);let l=a(T*T),w=a(l-ct),d=a(I*l-B),{isValid:x,value:A}=c(w,d);if(!x)throw new Error("Point.fromHex: invalid y coordinate");let K=(A&ct)===ct,v=(U&128)!==0;if(!S&&A===It&&v)throw new Error("Point.fromHex: x=0 and x_0=1");return v!==K&&(A=a(-A)),b.fromAffine({x:A,y:T})}static fromPrivateScalar(y){return b.BASE.multiply(y)}toBytes(){let{x:y,y:S}=this.toAffine(),I=Ie(S,r.BYTES);return I[I.length-1]|=y&ct?128:0,I}toRawBytes(){return this.toBytes()}toHex(){return Bt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}b.BASE=new b(e.Gx,e.Gy,ct,a(e.Gx*e.Gy)),b.ZERO=new b(It,ct,ct,It),b.Fp=r,b.Fn=n;let g=Cr(b,n.BYTES*8);return b}function Uc(e,t){Vt(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:r,hash:n}=t,{BASE:o,Fp:s,Fn:i}=e,a=i.ORDER,c=t.randomBytes||Jt,h=t.adjustScalarBytes||(p=>p),f=t.domain||((p,U,T)=>{if(Pt("phflag",T),U.length||T)throw new Error("Contexts/pre-hash are not supported");return p});function u(p){return i.create(p)}function m(p){return u(re(p))}function b(p){let U=s.BYTES;p=V("private key",p,U);let T=V("hashed private key",n(p),2*U),_=h(T.slice(0,U)),l=T.slice(U,2*U),w=m(_);return{head:_,prefix:l,scalar:w}}function g(p){let{head:U,prefix:T,scalar:_}=b(p),l=o.multiply(_),w=l.toBytes();return{head:U,prefix:T,scalar:_,point:l,pointBytes:w}}function E(p){return g(p).pointBytes}function y(p=Uint8Array.of(),...U){let T=dt(...U);return m(n(f(T,V("context",p),!!r)))}function S(p,U,T={}){p=V("message",p),r&&(p=r(p));let{prefix:_,scalar:l,pointBytes:w}=g(U),d=y(T.context,_,p),x=o.multiply(d).toBytes(),A=y(T.context,x,w,p),K=u(d+A*l);qt("signature.s",K,It,a);let v=s.BYTES,L=dt(x,Ie(K,v));return V("result",L,v*2)}let I=Kc;function B(p,U,T,_=I){let{context:l,zip215:w}=_,d=s.BYTES;p=V("signature",p,2*d),U=V("message",U),T=V("publicKey",T,d),w!==void 0&&Pt("zip215",w),r&&(U=r(U));let x=re(p.slice(d,2*d)),A,K,v;try{A=e.fromHex(T,w),K=e.fromHex(p.slice(0,d),w),v=o.multiplyUnsafe(x)}catch{return!1}if(!w&&A.isSmallOrder())return!1;let L=y(l,K.toBytes(),A.toBytes(),U);return K.add(A.multiplyUnsafe(L)).subtract(v).clearCofactor().is0()}return o.precompute(8),{getPublicKey:E,sign:S,verify:B,utils:{getExtendedPublicKey:g,randomPrivateKey:()=>c(s.BYTES),precompute(p=8,U=e.BASE){return U.precompute(p,!1)}},Point:e}}function Cc(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=gt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={hash:e.hash,randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function Dc(e,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:e})}function qs(e){let{CURVE:t,curveOpts:r,eddsaOpts:n}=Cc(e),o=Tc(t,r),s=Uc(o,n);return Dc(e,s)}var $h=BigInt(0),Pc=BigInt(1),Vs=BigInt(2),Yh=BigInt(3),Rc=BigInt(5),Nc=BigInt(8),Rr={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Nc,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function kc(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Rr.p,a=e*e%s*e%s,c=z(a,Vs,s)*a%s,h=z(c,Pc,s)*e%s,f=z(h,Rc,s)*h%s,u=z(f,t,s)*f%s,m=z(u,r,s)*u%s,b=z(m,n,s)*m%s,g=z(b,o,s)*b%s,E=z(g,o,s)*b%s,y=z(E,t,s)*f%s;return{pow_p_5_8:z(y,Vs,s)*e%s,b2:a}}function Hc(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var zs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Oc(e,t){let r=Rr.p,n=j(t*t*t,r),o=j(n*n*t,r),s=kc(e*o).pow_p_5_8,i=j(e*n*s,r),a=j(t*i*i,r),c=i,h=j(i*zs,r),f=a===e,u=a===j(-e,r),m=a===j(-e*zs,r);return f&&(i=c),(u||m)&&(i=h),Us(i,r)&&(i=j(-i,r)),{isValid:f||u,value:i}}var Mc=gt(Rr.p,void 0,!0),qc={...Rr,Fp:Mc,hash:Lr,adjustScalarBytes:Hc,uvRatio:Oc},Te=qs(qc);var zt=32,pt=64,Nr=32;var Ue,Fs=(async()=>{try{return await F.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();function js(){let e=Te.utils.randomPrivateKey(),t=Te.getPublicKey(e);return{privateKey:Ys(e,t),publicKey:t}}function Gs(e){if(e.length!==Nr)throw new TypeError('"seed" must be 32 bytes in length.');if(!(e instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let t=e,r=Te.getPublicKey(t);return{privateKey:Ys(t,r),publicKey:r}}async function Vc(e,t){let r;e.length===pt?r=e.subarray(0,32):r=e;let n={crv:"Ed25519",kty:"OKP",x:k(e.subarray(32),"base64url"),d:k(r,"base64url"),ext:!0,key_ops:["sign"]},o=await F.get().subtle.importKey("jwk",n,{name:"Ed25519"},!0,["sign"]),s=await F.get().subtle.sign({name:"Ed25519"},o,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(s,0,s.byteLength)}function zc(e,t){let r=e.subarray(0,Nr);return Te.sign(t instanceof Uint8Array?t:t.subarray(),r)}async function Zs(e,t){return Ue==null&&(Ue=await Fs),Ue?Vc(e,t):zc(e,t)}async function Fc(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await F.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await F.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function jc(e,t,r){return Te.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function $s(e,t,r){return Ue==null&&(Ue=await Fs),Ue?Fc(e,t,r):jc(e,t,r)}function Ys(e,t){let r=new Uint8Array(pt);for(let n=0;n<Nr;n++)r[n]=e[n],r[Nr+n]=t[n];return r}function Gn(e,t){let r=q(e,"base64urlpad");if(t!=null){if(r.length>t)throw new Error("byte array longer than desired length");r=St([new Uint8Array(t-r.length),r])}return r}function Ce(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var er=class{type="Ed25519";raw;constructor(t){this.raw=De(t,zt)}toMultihash(){return $t.digest(Wt(this))}toCID(){return yt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=$s(this.raw,r,t);return Ce(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}},ie=class{type="Ed25519";raw;publicKey;constructor(t,r){this.raw=De(t,pt),this.publicKey=new er(r)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}sign(t,r){r?.signal?.throwIfAborted();let n=Zs(this.raw,t);return Ce(n)?n.then(o=>(r?.signal?.throwIfAborted(),o)):(r?.signal?.throwIfAborted(),n)}};function Zn(e){if(e.length>pt){e=De(e,pt+zt);let n=e.subarray(0,pt),o=e.subarray(pt,e.length);return new ie(n,o)}e=De(e,pt);let t=e.subarray(0,pt),r=e.subarray(zt);return new ie(t,r)}function kr(e){return e=De(e,zt),new er(e)}async function Xs(){let{privateKey:e,publicKey:t}=js();return new ie(e,t)}async function Js(e){let{privateKey:t,publicKey:r}=Gs(e);return new ie(t,r)}function De(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new N(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Gc=Math.pow(2,7),Zc=Math.pow(2,14),$c=Math.pow(2,21),Qs=Math.pow(2,28),ti=Math.pow(2,35),ei=Math.pow(2,42),ri=Math.pow(2,49),ft=128,Ft=127;function rr(e){if(e<Gc)return 1;if(e<Zc)return 2;if(e<$c)return 3;if(e<Qs)return 4;if(e<ti)return 5;if(e<ei)return 6;if(e<ri)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ni(e,t,r=0){switch(rr(e)){case 8:t[r++]=e&255|ft,e/=128;case 7:t[r++]=e&255|ft,e/=128;case 6:t[r++]=e&255|ft,e/=128;case 5:t[r++]=e&255|ft,e/=128;case 4:t[r++]=e&255|ft,e>>>=7;case 3:t[r++]=e&255|ft,e>>>=7;case 2:t[r++]=e&255|ft,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function oi(e,t){let r=e[t],n=0;if(n+=r&Ft,r<ft||(r=e[t+1],n+=(r&Ft)<<7,r<ft)||(r=e[t+2],n+=(r&Ft)<<14,r<ft)||(r=e[t+3],n+=(r&Ft)<<21,r<ft)||(r=e[t+4],n+=(r&Ft)*Qs,r<ft)||(r=e[t+5],n+=(r&Ft)*ti,r<ft)||(r=e[t+6],n+=(r&Ft)*ei,r<ft)||(r=e[t+7],n+=(r&Ft)*ri,r<ft))return n;throw new RangeError("Could not decode varint")}var $n=new Float32Array([-0]),jt=new Uint8Array($n.buffer);function si(e,t,r){$n[0]=e,t[r]=jt[0],t[r+1]=jt[1],t[r+2]=jt[2],t[r+3]=jt[3]}function ii(e,t){return jt[0]=e[t],jt[1]=e[t+1],jt[2]=e[t+2],jt[3]=e[t+3],$n[0]}var Yn=new Float64Array([-0]),nt=new Uint8Array(Yn.buffer);function ai(e,t,r){Yn[0]=e,t[r]=nt[0],t[r+1]=nt[1],t[r+2]=nt[2],t[r+3]=nt[3],t[r+4]=nt[4],t[r+5]=nt[5],t[r+6]=nt[6],t[r+7]=nt[7]}function ci(e,t){return nt[0]=e[t],nt[1]=e[t+1],nt[2]=e[t+2],nt[3]=e[t+3],nt[4]=e[t+4],nt[5]=e[t+5],nt[6]=e[t+6],nt[7]=e[t+7],Yn[0]}var Yc=BigInt(Number.MAX_SAFE_INTEGER),Wc=BigInt(Number.MIN_SAFE_INTEGER),mt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ae;if(t<Yc&&t>Wc)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>fi&&(o=0n,++n>fi&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ae;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ae}},ae=new mt(0,0);ae.toBigInt=function(){return 0n};ae.zzEncode=ae.zzDecode=function(){return this};ae.length=function(){return 1};var fi=4294967296n;function ui(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function hi(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Wn(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Et(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Hr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Xn=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Et(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Et(this,4);return Hr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Et(this,4);return Hr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Et(this,4);let t=ii(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Et(this,4);let t=ci(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Et(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return hi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Et(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Et(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new mt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Et(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Et(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Et(this,8);let t=Hr(this.buf,this.pos+=4),r=Hr(this.buf,this.pos+=4);return new mt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=oi(this.buf,this.pos);return this.pos+=rr(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Jn(e){return new Xn(e instanceof Uint8Array?e:e.subarray())}function Or(e,t,r){let n=Jn(e);return t.decode(n,void 0,r)}function Qn(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return ht(i);o+i>t&&(n=ht(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ce=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function to(){}var ro=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Xc=Qn();function Jc(e){return globalThis.Buffer!=null?ht(e):Xc(e)}var or=class{len;head;tail;states;constructor(){this.len=0,this.head=new ce(to,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ce(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new no((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Mr,10,mt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=mt.fromBigInt(t);return this._push(Mr,r.length(),r)}uint64Number(t){return this._push(ni,rr(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=mt.fromBigInt(t).zzEncode();return this._push(Mr,r.length(),r)}sint64Number(t){let r=mt.fromNumber(t).zzEncode();return this._push(Mr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(eo,1,t?1:0)}fixed32(t){return this._push(nr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=mt.fromBigInt(t);return this._push(nr,4,r.lo)._push(nr,4,r.hi)}fixed64Number(t){let r=mt.fromNumber(t);return this._push(nr,4,r.lo)._push(nr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(si,4,t)}double(t){return this._push(ai,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(eo,1,0):this.uint32(r)._push(tf,r,t)}string(t){let r=ui(t);return r!==0?this.uint32(r)._push(Wn,r,t):this._push(eo,1,0)}fork(){return this.states=new ro(this),this.head=this.tail=new ce(to,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new ce(to,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Jc(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function eo(e,t,r){t[r]=e&255}function Qc(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var no=class extends ce{next;constructor(t,r){super(Qc,t,r),this.next=void 0}};function Mr(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function nr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function tf(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(or.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(ef,t,e),this},or.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(rf,t,e),this});function ef(e,t,r){t.set(e,r)}function rf(e,t,r){e.length<40?Wn(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(q(e),r)}function oo(){return new or}function qr(e,t){let r=oo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Pe;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Pe||(Pe={}));function Vr(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function so(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Vr("enum",Pe.VARINT,r,n)}function zr(e,t){return Vr("message",Pe.LENGTH_DELIMITED,e,t)}var O;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(O||(O={}));var io;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(io||(io={}));(function(e){e.codec=()=>so(io)})(O||(O={}));var _t;(function(e){let t;e.codec=()=>(t==null&&(t=zr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),O.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=O.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>qr(r,e.codec()),e.decode=(r,n)=>Or(r,e.codec(),n)})(_t||(_t={}));var sr;(function(e){let t;e.codec=()=>(t==null&&(t=zr((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),O.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=O.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>qr(r,e.codec()),e.decode=(r,n)=>Or(r,e.codec(),n)})(sr||(sr={}));function ao(e){if(isNaN(e)||e<=0)throw new N("random bytes length must be a Number bigger than 0");return Jt(e)}var ar={};et(ar,{MAX_RSA_KEY_SIZE:()=>co,generateRSAKeyPair:()=>yo,jwkToJWKKeyPair:()=>yi,jwkToPkcs1:()=>af,jwkToPkix:()=>lo,jwkToRSAPrivateKey:()=>Gr,pkcs1MessageToJwk:()=>uo,pkcs1MessageToRSAPrivateKey:()=>Fr,pkcs1ToJwk:()=>sf,pkcs1ToRSAPrivateKey:()=>po,pkixMessageToJwk:()=>ho,pkixMessageToRSAPublicKey:()=>jr,pkixToJwk:()=>cf,pkixToRSAPublicKey:()=>mo});var Re=Kr;var Ne=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=ar.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return yt.createV1(114,this._multihash)}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}verify(t,r,n){return mi(this.jwk,r,t,n)}},ir=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=ar.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}sign(t,r){return pi(this.jwk,t,r)}};var co=8192,fo=18,nf=1062,of=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function sf(e){let t=lt(e);return uo(t)}function uo(e){return{n:k(e[1],"base64url"),e:k(e[2],"base64url"),d:k(e[3],"base64url"),p:k(e[4],"base64url"),q:k(e[5],"base64url"),dp:k(e[6],"base64url"),dq:k(e[7],"base64url"),qi:k(e[8],"base64url"),kty:"RSA"}}function af(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new N("JWK was missing components");return xt([it(Uint8Array.from([0])),it(q(e.n,"base64url")),it(q(e.e,"base64url")),it(q(e.d,"base64url")),it(q(e.p,"base64url")),it(q(e.q,"base64url")),it(q(e.dp,"base64url")),it(q(e.dq,"base64url")),it(q(e.qi,"base64url"))]).subarray()}function cf(e){let t=lt(e,{offset:0});return ho(t)}function ho(e){let t=lt(e[1],{offset:0});return{kty:"RSA",n:k(t[0],"base64url"),e:k(t[1],"base64url")}}function lo(e){if(e.n==null||e.e==null)throw new N("JWK was missing components");return xt([of,$e(xt([it(q(e.n,"base64url")),it(q(e.e,"base64url"))]))]).subarray()}function po(e){let t=lt(e);return Fr(t)}function Fr(e){let t=uo(e);return Gr(t)}function mo(e,t){if(e.byteLength>=nf)throw new he("Key size is too large");let r=lt(e,{offset:0});return jr(r,e,t)}function jr(e,t,r){let n=ho(e);if(r==null){let o=Re(_t.encode({Type:O.RSA,Data:t}));r=bt(fo,o)}return new Ne(n,r)}function Gr(e){if(xi(e)>co)throw new N("Key size is too large");let t=yi(e),r=Re(_t.encode({Type:O.RSA,Data:lo(t.publicKey)})),n=bt(fo,r);return new ir(t.privateKey,new Ne(t.publicKey,n))}async function yo(e){if(e>co)throw new N("Key size is too large");let t=await bi(e),r=Re(_t.encode({Type:O.RSA,Data:lo(t.publicKey)})),n=bt(fo,r);return new ir(t.privateKey,new Ne(t.publicKey,n))}function yi(e){if(e==null)throw new N("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var wi="1.2.840.113549.1.1.1";async function bi(e,t){let r=await F.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await ff(r,t);return{privateKey:n[0],publicKey:n[1]}}async function pi(e,t,r){let n=await F.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await F.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function mi(e,t,r,n){let o=await F.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await F.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function ff(e,t){if(e.privateKey==null||e.publicKey==null)throw new N("Private and public key are required");let r=await Promise.all([F.get().subtle.exportKey("jwk",e.privateKey),F.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function xi(e){if(e.kty!=="RSA")throw new N("invalid key type");if(e.n==null)throw new N("invalid key modulus");return q(e.n,"base64url").length*8}var Zr=class extends ge{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Er(t);let n=Ye(r);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 o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),ut(s)}update(t){return Ae(this),this.iHash.update(t),this}digestInto(t){Ae(this),J(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:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},cr=(e,t,r)=>new Zr(e,t).update(r).digest();cr.create=(e,t)=>new Zr(e,t);function gi(e){e.lowS!==void 0&&Pt("lowS",e.lowS),e.prehash!==void 0&&Pt("prehash",e.prehash)}var bo=class extends Error{constructor(t=""){super(t)}},Rt={Err:bo,_tlv:{encode:(e,t)=>{let{Err:r}=Rt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Qe(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Qe(o.length/2|128):"";return Qe(e)+s+o+t},decode(e,t){let{Err:r}=Rt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let h=t.subarray(n,n+c);if(h.length!==c)throw new r("tlv.decode: length bytes not complete");if(h[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of h)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Rt;if(e<fr)throw new t("integer: negative integers are not allowed");let r=Qe(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Rt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return ve(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Rt,o=V("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:h,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(h)}},hexFromSig(e){let{_tlv:t,_int:r}=Rt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},fr=BigInt(0),ur=BigInt(1),uf=BigInt(2),$r=BigInt(3),hf=BigInt(4);function lf(e,t,r){function n(o){let s=e.sqr(o),i=e.mul(s,o);return e.add(e.add(i,e.mul(o,t)),r)}return n}function Ei(e,t,r){let{BYTES:n}=e;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=V("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{i=e.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(r&&(i=e.create(i)),!e.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function df(e,t={}){let{Fp:r,Fn:n}=Pr("weierstrass",e,t),{h:o,n:s}=e;Vt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!r.is0(e.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(_,l,w){let{x:d,y:x}=l.toAffine(),A=r.toBytes(d);if(Pt("isCompressed",w),w){a();let K=!r.isOdd(x);return dt(Ai(K),A)}else return dt(Uint8Array.of(4),A,r.toBytes(x))}function h(_){J(_);let l=r.BYTES,w=l+1,d=2*l+1,x=_.length,A=_[0],K=_.subarray(1);if(x===w&&(A===2||A===3)){let v=r.fromBytes(K);if(!r.isValid(v))throw new Error("bad point: is not on curve, wrong x");let L=m(v),P;try{P=r.sqrt(L)}catch(H){let R=H instanceof Error?": "+H.message:"";throw new Error("bad point: is not on curve, sqrt error"+R)}a();let D=r.isOdd(P);return(A&1)===1!==D&&(P=r.neg(P)),{x:v,y:P}}else if(x===d&&A===4){let v=r.fromBytes(K.subarray(l*0,l*1)),L=r.fromBytes(K.subarray(l*1,l*2));if(!b(v,L))throw new Error("bad point: is not on curve");return{x:v,y:L}}else throw new Error(`bad point: got length ${x}, expected compressed=${w} or uncompressed=${d}`)}let f=t.toBytes||c,u=t.fromBytes||h,m=lf(r,e.a,e.b);function b(_,l){let w=r.sqr(l),d=m(_);return r.eql(w,d)}if(!b(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let g=r.mul(r.pow(e.a,$r),hf),E=r.mul(r.sqr(e.b),BigInt(27));if(r.is0(r.add(g,E)))throw new Error("bad curve params: a or b");function y(_,l,w=!1){if(!r.isValid(l)||w&&r.is0(l))throw new Error(`bad point coordinate ${_}`);return l}function S(_){if(!(_ instanceof p))throw new Error("ProjectivePoint expected")}let I=_e((_,l)=>{let{px:w,py:d,pz:x}=_;if(r.eql(x,r.ONE))return{x:w,y:d};let A=_.is0();l==null&&(l=A?r.ONE:r.inv(x));let K=r.mul(w,l),v=r.mul(d,l),L=r.mul(x,l);if(A)return{x:r.ZERO,y:r.ZERO};if(!r.eql(L,r.ONE))throw new Error("invZ was invalid");return{x:K,y:v}}),B=_e(_=>{if(_.is0()){if(t.allowInfinityPoint&&!r.is0(_.py))return;throw new Error("bad point: ZERO")}let{x:l,y:w}=_.toAffine();if(!r.isValid(l)||!r.isValid(w))throw new Error("bad point: x or y not field elements");if(!b(l,w))throw new Error("bad point: equation left != right");if(!_.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function C(_,l,w,d,x){return w=new p(r.mul(w.px,_),w.py,w.pz),l=Ke(d,l),w=Ke(x,w),l.add(w)}class p{constructor(l,w,d){this.px=y("x",l),this.py=y("y",w,!0),this.pz=y("z",d),Object.freeze(this)}static fromAffine(l){let{x:w,y:d}=l||{};if(!l||!r.isValid(w)||!r.isValid(d))throw new Error("invalid affine point");if(l instanceof p)throw new Error("projective point not allowed");return r.is0(w)&&r.is0(d)?p.ZERO:new p(w,d,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(l){return Ur(p,"pz",l)}static fromBytes(l){return J(l),p.fromHex(l)}static fromHex(l){let w=p.fromAffine(u(V("pointHex",l)));return w.assertValidity(),w}static fromPrivateKey(l){let w=Ei(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return p.BASE.multiply(w(l))}static msm(l,w){return Dr(p,n,l,w)}precompute(l=8,w=!0){return T.setWindowSize(this,l),w||this.multiply($r),this}_setWindowSize(l){this.precompute(l)}assertValidity(){B(this)}hasEvenY(){let{y:l}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(l)}equals(l){S(l);let{px:w,py:d,pz:x}=this,{px:A,py:K,pz:v}=l,L=r.eql(r.mul(w,v),r.mul(A,x)),P=r.eql(r.mul(d,v),r.mul(K,x));return L&&P}negate(){return new p(this.px,r.neg(this.py),this.pz)}double(){let{a:l,b:w}=e,d=r.mul(w,$r),{px:x,py:A,pz:K}=this,v=r.ZERO,L=r.ZERO,P=r.ZERO,D=r.mul(x,x),Z=r.mul(A,A),H=r.mul(K,K),R=r.mul(x,A);return R=r.add(R,R),P=r.mul(x,K),P=r.add(P,P),v=r.mul(l,P),L=r.mul(d,H),L=r.add(v,L),v=r.sub(Z,L),L=r.add(Z,L),L=r.mul(v,L),v=r.mul(R,v),P=r.mul(d,P),H=r.mul(l,H),R=r.sub(D,H),R=r.mul(l,R),R=r.add(R,P),P=r.add(D,D),D=r.add(P,D),D=r.add(D,H),D=r.mul(D,R),L=r.add(L,D),H=r.mul(A,K),H=r.add(H,H),D=r.mul(H,R),v=r.sub(v,D),P=r.mul(H,Z),P=r.add(P,P),P=r.add(P,P),new p(v,L,P)}add(l){S(l);let{px:w,py:d,pz:x}=this,{px:A,py:K,pz:v}=l,L=r.ZERO,P=r.ZERO,D=r.ZERO,Z=e.a,H=r.mul(e.b,$r),R=r.mul(w,A),$=r.mul(d,K),Y=r.mul(x,v),tt=r.add(w,d),M=r.add(A,K);tt=r.mul(tt,M),M=r.add(R,$),tt=r.sub(tt,M),M=r.add(w,x);let ot=r.add(A,v);return M=r.mul(M,ot),ot=r.add(R,Y),M=r.sub(M,ot),ot=r.add(d,x),L=r.add(K,v),ot=r.mul(ot,L),L=r.add($,Y),ot=r.sub(ot,L),D=r.mul(Z,M),L=r.mul(H,Y),D=r.add(L,D),L=r.sub($,D),D=r.add($,D),P=r.mul(L,D),$=r.add(R,R),$=r.add($,R),Y=r.mul(Z,Y),M=r.mul(H,M),$=r.add($,Y),Y=r.sub(R,Y),Y=r.mul(Z,Y),M=r.add(M,Y),R=r.mul($,M),P=r.add(P,R),R=r.mul(ot,M),L=r.mul(tt,L),L=r.sub(L,R),R=r.mul(tt,$),D=r.mul(ot,D),D=r.add(D,R),new p(L,P,D)}subtract(l){return this.add(l.negate())}is0(){return this.equals(p.ZERO)}multiply(l){let{endo:w}=t;if(!n.isValidNot0(l))throw new Error("invalid scalar: out of range");let d,x,A=K=>T.wNAFCached(this,K,p.normalizeZ);if(w){let{k1neg:K,k1:v,k2neg:L,k2:P}=w.splitScalar(l),{p:D,f:Z}=A(v),{p:H,f:R}=A(P);x=Z.add(R),d=C(w.beta,D,H,K,L)}else{let{p:K,f:v}=A(l);d=K,x=v}return p.normalizeZ([d,x])[0]}multiplyUnsafe(l){let{endo:w}=t,d=this;if(!n.isValid(l))throw new Error("invalid scalar: out of range");if(l===fr||d.is0())return p.ZERO;if(l===ur)return d;if(T.hasPrecomputes(this))return this.multiply(l);if(w){let{k1neg:x,k1:A,k2neg:K,k2:v}=w.splitScalar(l),{p1:L,p2:P}=Ms(p,d,A,v);return C(w.beta,L,P,x,K)}else return T.wNAFCachedUnsafe(d,l)}multiplyAndAddUnsafe(l,w,d){let x=this.multiplyUnsafe(w).add(l.multiplyUnsafe(d));return x.is0()?void 0:x}toAffine(l){return I(this,l)}isTorsionFree(){let{isTorsionFree:l}=t;return o===ur?!0:l?l(p,this):T.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:l}=t;return o===ur?this:l?l(p,this):this.multiplyUnsafe(o)}toBytes(l=!0){return Pt("isCompressed",l),this.assertValidity(),f(p,this,l)}toRawBytes(l=!0){return this.toBytes(l)}toHex(l=!0){return Bt(this.toBytes(l))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}p.BASE=new p(e.Gx,e.Gy,r.ONE),p.ZERO=new p(r.ZERO,r.ONE,r.ZERO),p.Fp=r,p.Fn=n;let U=n.BITS,T=Cr(p,t.endo?Math.ceil(U/2):U);return p}function Ai(e){return Uint8Array.of(e?2:3)}function pf(e,t,r={}){Vt(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||Jt,o=t.hmac||((d,...x)=>cr(t.hash,d,dt(...x))),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i;function h(d){let x=a>>ur;return d>x}function f(d){return h(d)?i.neg(d):d}function u(d,x){if(!i.isValidNot0(x))throw new Error(`invalid signature ${d}: out of range 1..CURVE.n`)}class m{constructor(x,A,K){u("r",x),u("s",A),this.r=x,this.s=A,K!=null&&(this.recovery=K),Object.freeze(this)}static fromCompact(x){let A=i.BYTES,K=V("compactSignature",x,A*2);return new m(i.fromBytes(K.subarray(0,A)),i.fromBytes(K.subarray(A,A*2)))}static fromDER(x){let{r:A,s:K}=Rt.toSig(V("DER",x));return new m(A,K)}assertValidity(){}addRecoveryBit(x){return new m(this.r,this.s,x)}recoverPublicKey(x){let A=s.ORDER,{r:K,s:v,recovery:L}=this;if(L==null||![0,1,2,3].includes(L))throw new Error("recovery id invalid");if(a*uf<A&&L>1)throw new Error("recovery id is ambiguous for h>1 curve");let D=L===2||L===3?K+a:K;if(!s.isValid(D))throw new Error("recovery id 2 or 3 invalid");let Z=s.toBytes(D),H=e.fromHex(dt(Ai((L&1)===0),Z)),R=i.inv(D),$=B(V("msgHash",x)),Y=i.create(-$*R),tt=i.create(v*R),M=e.BASE.multiplyUnsafe(Y).add(H.multiplyUnsafe(tt));if(M.is0())throw new Error("point at infinify");return M.assertValidity(),M}hasHighS(){return h(this.s)}normalizeS(){return this.hasHighS()?new m(this.r,i.neg(this.s),this.recovery):this}toBytes(x){if(x==="compact")return dt(i.toBytes(this.r),i.toBytes(this.s));if(x==="der")return Be(Rt.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Bt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Bt(this.toBytes("compact"))}}let b=Ei(i,r.allowedPrivateKeyLengths,r.wrapPrivateKey),g={isValidPrivateKey(d){try{return b(d),!0}catch{return!1}},normPrivateKeyToScalar:b,randomPrivateKey:()=>{let d=a;return Ps(n(qn(d)),d)},precompute(d=8,x=e.BASE){return x.precompute(d,!1)}};function E(d,x=!0){return e.fromPrivateKey(d).toBytes(x)}function y(d){if(typeof d=="bigint")return!1;if(d instanceof e)return!0;let A=V("key",d).length,K=s.BYTES,v=K+1,L=2*K+1;if(!(r.allowedPrivateKeyLengths||i.BYTES===v))return A===v||A===L}function S(d,x,A=!0){if(y(d)===!0)throw new Error("first arg must be private key");if(y(x)===!1)throw new Error("second arg must be public key");return e.fromHex(x).multiply(b(d)).toBytes(A)}let I=t.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let x=ve(d),A=d.length*8-c;return A>0?x>>BigInt(A):x},B=t.bits2int_modN||function(d){return i.create(I(d))},C=ne(c);function p(d){return qt("num < 2^"+c,d,fr,C),i.toBytes(d)}function U(d,x,A=T){if(["recovered","canonical"].some(tt=>tt in A))throw new Error("sign() legacy options not supported");let{hash:K}=t,{lowS:v,prehash:L,extraEntropy:P}=A;v==null&&(v=!0),d=V("msgHash",d),gi(A),L&&(d=V("prehashed msgHash",K(d)));let D=B(d),Z=b(x),H=[p(Z),p(D)];if(P!=null&&P!==!1){let tt=P===!0?n(s.BYTES):P;H.push(V("extraEntropy",tt))}let R=dt(...H),$=D;function Y(tt){let M=I(tt);if(!i.isValidNot0(M))return;let ot=i.inv(M),ke=e.BASE.multiply(M).toAffine(),fe=i.create(ke.x);if(fe===fr)return;let Zt=i.create(ot*i.create($+fe*Z));if(Zt===fr)return;let Qr=(ke.x===fe?0:2)|Number(ke.y&ur),ue=Zt;return v&&h(Zt)&&(ue=f(Zt),Qr^=1),new m(fe,ue,Qr)}return{seed:R,k2sig:Y}}let T={lowS:t.lowS,prehash:!1},_={lowS:t.lowS,prehash:!1};function l(d,x,A=T){let{seed:K,k2sig:v}=U(d,x,A);return Bs(t.hash.outputLen,i.BYTES,o)(K,v)}e.BASE.precompute(8);function w(d,x,A,K=_){let v=d;x=V("msgHash",x),A=V("publicKey",A),gi(K);let{lowS:L,prehash:P,format:D}=K;if("strict"in K)throw new Error("options.strict was renamed to lowS");if(D!==void 0&&!["compact","der","js"].includes(D))throw new Error('format must be "compact", "der" or "js"');let Z=typeof v=="string"||Ee(v),H=!Z&&!D&&typeof v=="object"&&v!==null&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!Z&&!H)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let R,$;try{if(H)if(D===void 0||D==="js")R=new m(v.r,v.s);else throw new Error("invalid format");if(Z){try{D!=="compact"&&(R=m.fromDER(v))}catch(ue){if(!(ue instanceof Rt.Err))throw ue}!R&&D!=="der"&&(R=m.fromCompact(v))}$=e.fromHex(A)}catch{return!1}if(!R||L&&R.hasHighS())return!1;P&&(x=t.hash(x));let{r:Y,s:tt}=R,M=B(x),ot=i.inv(tt),ke=i.create(M*ot),fe=i.create(Y*ot),Zt=e.BASE.multiplyUnsafe(ke).add($.multiplyUnsafe(fe));return Zt.is0()?!1:i.create(Zt.x)===Y}return Object.freeze({getPublicKey:E,getSharedSecret:S,sign:l,verify:w,utils:g,Point:e,Signature:m})}function mf(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=gt(t.n,e.nBitLength),o={Fp:r,Fn:n,allowedPrivateKeyLengths:e.allowedPrivateKeyLengths,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,wrapPrivateKey:e.wrapPrivateKey,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:o}}function yf(e){let{CURVE:t,curveOpts:r}=mf(e),n={hash:e.hash,hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,ecdsaOpts:n}}function bf(e,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:e})}function Si(e){let{CURVE:t,curveOpts:r,ecdsaOpts:n}=yf(e),o=df(t,r),s=pf(o,n,r);return bf(e,s)}function Bi(e,t){let r=n=>Si({...e,hash:n});return{...r(t),create:r}}var Yr={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},T0=BigInt(0),xf=BigInt(1),xo=BigInt(2),vi=(e,t)=>(e+t/xo)/t;function wf(e){let t=Yr.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),h=e*e*e%t,f=h*h*e%t,u=z(f,r,t)*f%t,m=z(u,r,t)*f%t,b=z(m,xo,t)*h%t,g=z(b,o,t)*b%t,E=z(g,s,t)*g%t,y=z(E,a,t)*E%t,S=z(y,c,t)*y%t,I=z(S,a,t)*E%t,B=z(I,r,t)*f%t,C=z(B,i,t)*g%t,p=z(C,n,t)*h%t,U=z(p,xo,t);if(!wo.eql(wo.sqr(U),e))throw new Error("Cannot find square root");return U}var wo=gt(Yr.p,void 0,void 0,{sqrt:wf}),At=Bi({...Yr,Fp:wo,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=Yr.n,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-xf*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,i=BigInt("0x100000000000000000000000000000000"),a=vi(s*e,t),c=vi(-n*e,t),h=j(e-a*r-c*o,t),f=j(-a*n-c*s,t),u=h>i,m=f>i;if(u&&(h=t-h),m&&(f=t-f),h>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:u,k1:h,k2neg:m,k2:f}}}},Kr);var Ii=33,_i=32;function Ki(e,t,r){let n=xr.digest(t instanceof Uint8Array?t:t.subarray());if(Ce(n))return n.then(({digest:o})=>(r?.signal?.throwIfAborted(),At.sign(o,e).toDERRawBytes())).catch(o=>{throw o.name==="AbortError"?o:new He(String(o))});try{return At.sign(n.digest,e).toDERRawBytes()}catch(o){throw new He(String(o))}}function Li(e,t,r,n){let o=xr.digest(r instanceof Uint8Array?r:r.subarray());if(Ce(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),At.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new Oe(String(s))});try{return n?.signal?.throwIfAborted(),At.verify(t,o.digest,e)}catch(s){throw new Oe(String(s))}}var hr=class{type="secp256k1";raw;_key;constructor(t){this._key=Ci(t),this.raw=Ti(this._key)}toMultihash(){return $t.digest(Wt(this))}toCID(){return yt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}verify(t,r,n){return Li(this._key,r,t,n)}},lr=class{type="secp256k1";raw;publicKey;constructor(t,r){this.raw=Ui(t),this.publicKey=new hr(r??Di(t))}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}sign(t,r){return Ki(this.raw,t,r)}};function go(e){return new lr(e)}function Wr(e){return new hr(e)}async function Pi(){let e=gf();return new lr(e)}function Ti(e){return At.ProjectivePoint.fromHex(e).toRawBytes(!0)}function Ui(e){try{return At.getPublicKey(e,!0),e}catch(t){throw new Me(String(t))}}function Ci(e){try{return At.ProjectivePoint.fromHex(e),e}catch(t){throw new he(String(t))}}function Di(e){try{return At.getPublicKey(e,!0)}catch(t){throw new Me(String(t))}}function gf(){return At.utils.randomPrivateKey()}var Xr={"P-256":32,"P-384":48,"P-521":66},Ef=Object.keys(Xr),Eo=Ef.join(" / ");async function Ri(e){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new N(`Unknown curve: ${e}. Must be ${Eo}`);let t=await F.get().subtle.generateKey({name:"ECDH",namedCurve:e},!0,["deriveBits"]),r=async(s,i)=>{let a;i!=null?a=await F.get().subtle.importKey("jwk",Sf(e,i),{name:"ECDH",namedCurve:e},!1,["deriveBits"]):a=t.privateKey;let c=await F.get().subtle.importKey("jwk",Ni(e,s),{name:"ECDH",namedCurve:e},!1,[]),h=await F.get().subtle.deriveBits({name:"ECDH",public:c},a,Xr[e]*8);return new Uint8Array(h,0,h.byteLength)},n=await F.get().subtle.exportKey("jwk",t.publicKey);return{key:Af(n),genSharedKey:r}}function Af(e){if(e.crv==null||e.x==null||e.y==null)throw new N("JWK was missing components");if(e.crv!=="P-256"&&e.crv!=="P-384"&&e.crv!=="P-521")throw new N(`Unknown curve: ${e.crv}. Must be ${Eo}`);let t=Xr[e.crv];return St([Uint8Array.from([4]),Gn(e.x,t),Gn(e.y,t)],1+t*2)}function Ni(e,t){if(e!=="P-256"&&e!=="P-384"&&e!=="P-521")throw new N(`Unknown curve: ${e}. Must be ${Eo}`);let r=Xr[e];if(!rt(t.subarray(0,1),Uint8Array.from([4])))throw new N("Cannot unmarshal public key - invalid key format");return{kty:"EC",crv:e,x:k(t.subarray(1,r+1),"base64url"),y:k(t.subarray(1+r),"base64url"),ext:!0}}var Sf=(e,t)=>({...Ni(e,t.public),d:k(t.private,"base64url")});var Bf={"AES-128":{ivSize:16,keySize:16},"AES-256":{ivSize:16,keySize:32},Blowfish:{ivSize:8,keySize:32}};async function ki(e,t,r){if(e!=="AES-128"&&e!=="AES-256"&&e!=="Blowfish")throw new N("Cipher type was missing or unsupported");if(t!=="SHA1"&&t!=="SHA256"&&t!=="SHA512")throw new N("Hash type was missing or unsupported");if(r==null||!(r instanceof Uint8Array))throw new N("Secret was missing or an incorrect type");let n=Bf[e],o=n.keySize,s=n.ivSize,i=20,a=q("key expansion"),c=2*(s+o+i),h=await en(t,r),f=await h.digest(a),u=[],m=0;for(;m<c;){let I=await h.digest(St([f,a])),B=I.length;m+B>c&&(B=c-m),u.push(I),m+=B,f=await h.digest(f)}let b=c/2,g=St(u),E=g.subarray(0,b),y=g.subarray(b,c),S=I=>({iv:I.subarray(0,s),cipherKey:I.subarray(s,s+o),macKey:I.subarray(s+o)});return{k1:S(E),k2:S(y)}}async function vf(e,t){if(e==="Ed25519")return Xs();if(e==="secp256k1")return Pi();if(e==="RSA")return yo(Df(t));if(e==="ECDSA")return as(Pf(t));throw new Nt}async function If(e,t){if(e!=="Ed25519")throw new Nt("Seed key derivation only supported for Ed25519 keys");return Js(t)}function _f(e,t){let{Type:r,Data:n}=_t.decode(e),o=n??new Uint8Array;switch(r){case O.RSA:return mo(o,t);case O.Ed25519:return kr(o);case O.secp256k1:return Wr(o);case O.ECDSA:return Un(o);default:throw new Nt}}function Kf(e){if(e.byteLength===zt)return kr(e);if(e.byteLength===Ii)return Wr(e);let t=lt(e),r=t[1]?.[0];if(r===_n||r===Kn||r===Ln)return Cn(t);if(t[0]?.[0]===wi)return jr(t,e);throw new N("Could not extract public key from raw bytes")}function Lf(e){let{Type:t,Data:r}=_t.decode(e.digest),n=r??new Uint8Array;switch(t){case O.Ed25519:return kr(n);case O.secp256k1:return Wr(n);case O.ECDSA:return Un(n);default:throw new Nt}}function Wt(e){return _t.encode({Type:O[e.type],Data:e.raw})}function Tf(e){let t=sr.decode(e),r=t.Data??new Uint8Array;switch(t.Type){case O.RSA:return po(r);case O.Ed25519:return Zn(r);case O.secp256k1:return go(r);case O.ECDSA:return ns(r);default:throw new Nt}}function Uf(e){if(e.byteLength===pt)return Zn(e);if(e.byteLength===_i)return go(e);let t=lt(e),r=t[2]?.[0];if(r===_n||r===Kn||r===Ln)return Tn(t);if(t.length>8)return Fr(t);throw new N("Could not extract private key from raw bytes")}function Cf(e){return sr.encode({Type:O[e.type],Data:e.raw})}function Df(e){return e==null?2048:parseInt(e,10)}function Pf(e){if(e==="P-256"||e==null)return"P-256";if(e==="P-384")return"P-384";if(e==="P-521")return"P-521";throw new N("Unsupported curve, should be P-256, P-384 or P-521")}async function Rf(e){if(e.type==="RSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])};if(e.type==="ECDSA")return{privateKey:await crypto.subtle.importKey("jwk",e.jwk,{name:"ECDSA",namedCurve:e.jwk.crv??"P-256"},!0,["sign"]),publicKey:await crypto.subtle.importKey("jwk",e.publicKey.jwk,{name:"ECDSA",namedCurve:e.publicKey.jwk.crv??"P-256"},!0,["verify"])};throw new N("Only RSA and ECDSA keys are supported")}async function Nf(e){if(e.privateKey.algorithm.name==="RSASSA-PKCS1-v1_5"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return Gr(t)}if(e.privateKey.algorithm.name==="ECDSA"){let t=await crypto.subtle.exportKey("jwk",e.privateKey);return new Tt(t)}throw new N("Only RSA and ECDSA keys are supported")}function kf(e,t,r,n){Er(e);let o=hs({dkLen:32,asyncTick:10},n),{c:s,dkLen:i,asyncTick:a}=o;if(Ct(s),Ct(i),Ct(a),s<1)throw new Error("iterations (c) should be >= 1");let c=Pn(t),h=Pn(r),f=new Uint8Array(i),u=cr.create(e,c),m=u._cloneInto().update(h);return{c:s,dkLen:i,asyncTick:a,DK:f,PRF:u,PRFSalt:m}}function Hf(e,t,r,n,o){return e.destroy(),t.destroy(),n&&n.destroy(),ut(o),r}function Hi(e,t,r,n){let{c:o,dkLen:s,DK:i,PRF:a,PRFSalt:c}=kf(e,t,r,n),h,f=new Uint8Array(4),u=Se(f),m=new Uint8Array(a.outputLen);for(let b=1,g=0;g<s;b++,g+=a.outputLen){let E=i.subarray(g,g+a.outputLen);u.setInt32(0,b,!1),(h=c._cloneInto(h)).update(f).digestInto(m),E.set(m.subarray(0,E.length));for(let y=1;y<o;y++){a._cloneInto(h).update(m).digestInto(m);for(let S=0;S<E.length;S++)E[S]^=m[S]}}return Hf(a,c,i,h,m)}var dr=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),Gt=new Uint32Array(80),Jr=class extends Qt{constructor(){super(64,20,8,!1),this.A=dr[0]|0,this.B=dr[1]|0,this.C=dr[2]|0,this.D=dr[3]|0,this.E=dr[4]|0}get(){let{A:t,B:r,C:n,D:o,E:s}=this;return[t,r,n,o,s]}set(t,r,n,o,s){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0}process(t,r){for(let c=0;c<16;c++,r+=4)Gt[c]=t.getUint32(r,!1);for(let c=16;c<80;c++)Gt[c]=Ar(Gt[c-3]^Gt[c-8]^Gt[c-14]^Gt[c-16],1);let{A:n,B:o,C:s,D:i,E:a}=this;for(let c=0;c<80;c++){let h,f;c<20?(h=Sr(o,s,i),f=1518500249):c<40?(h=o^s^i,f=1859775393):c<60?(h=Br(o,s,i),f=2400959708):(h=o^s^i,f=3395469782);let u=Ar(n,5)+h+a+f+Gt[c]|0;a=i,i=s,s=Ar(o,30),o=n,n=u}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,this.set(n,o,s,i,a)}roundClean(){ut(Gt)}destroy(){this.set(0,0,0,0,0),ut(this.buffer)}},Oi=We(()=>new Jr);var Mi=Oi;var qi=Lr;var Vi={sha1:Mi,"sha2-256":Re,"sha2-512":qi};function So(e,t,r,n,o){if(o!=="sha1"&&o!=="sha2-256"&&o!=="sha2-512"){let a=Object.keys(Vi).join(" / ");throw new N(`Hash '${o}' is unknown or not supported. Must be ${a}`)}let s=Vi[o],i=Hi(s,e,t,{c:r,dkLen:n});return bn.encode(i).substring(1)}return Zi(Of);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js:
6
6
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
7
7
 
8
- @noble/curves/esm/abstract/utils.js:
8
+ @noble/curves/esm/utils.js:
9
9
  @noble/curves/esm/abstract/modular.js:
10
10
  @noble/curves/esm/abstract/curve.js:
11
11
  @noble/curves/esm/abstract/edwards.js: