@libp2p/peer-store 12.0.20 → 12.0.21-404c7824a
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 +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/utils/bytes-to-peer.d.ts +1 -1
- package/dist/src/utils/bytes-to-peer.js +1 -1
- package/dist/src/utils/dedupe-addresses.d.ts +2 -2
- package/dist/src/utils/peer-equals.d.ts +1 -1
- package/dist/src/utils/to-peer-pb.d.ts +3 -3
- package/package.json +16 -16
- package/src/utils/bytes-to-peer.ts +1 -1
- package/src/utils/dedupe-addresses.ts +2 -2
- package/src/utils/peer-equals.ts +1 -1
- package/src/utils/to-peer-pb.ts +3 -3
- package/dist/typedoc-urls.json +0 -10
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPeerStore = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PPeerStore=(()=>{var so=Object.defineProperty;var Gc=Object.getOwnPropertyDescriptor;var Xc=Object.getOwnPropertyNames;var Qc=Object.prototype.hasOwnProperty;var wt=(e,t)=>{for(var r in t)so(e,r,{get:t[r],enumerable:!0})},Jc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xc(t))!Qc.call(e,o)&&o!==r&&so(e,o,{get:()=>t[o],enumerable:!(n=Gc(t,o))||n.enumerable});return e};var tu=e=>Jc(so({},"__esModule",{value:!0}),e);var Qd={};wt(Qd,{persistentPeerStore:()=>Xd});var F=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Re=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var er=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Vr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Hr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var he=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var $r=Symbol.for("@libp2p/peer-id");function Be(e){return!!e?.[$r]}function eu(e){return typeof e?.handleEvent=="function"}function ru(e){return(e!==!0&&e!==!1&&e?.once)??!1}var Ce=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){let o=ru(n);super.addEventListener(t,i=>{if(o){let a=this.#t.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#t.set(i.type,a))}eu(r)?r.handleEvent(i):r(i)},n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:r,once:o})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var fo={};wt(fo,{base58btc:()=>G,base58flickr:()=>uu});var nh=new Uint8Array(0);function mi(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 zt(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 yi(e){return new TextEncoder().encode(e)}function bi(e){return new TextDecoder().decode(e)}function nu(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),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var g=0,p=0,b=0,v=y.length;b!==v&&y[b]===0;)b++,g++;for(var A=(v-b)*f+1>>>0,D=new Uint8Array(A);b!==v;){for(var B=y[b],k=0,L=A-1;(B!==0||k<p)&&L!==-1;L--,k++)B+=256*D[L]>>>0,D[L]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");p=k,b++}for(var I=A-p;I!==A&&D[I]===0;)I++;for(var P=c.repeat(g);I<A;++I)P+=e.charAt(D[I]);return P}function d(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var g=0;if(y[g]!==" "){for(var p=0,b=0;y[g]===c;)p++,g++;for(var v=(y.length-g)*u+1>>>0,A=new Uint8Array(v);y[g];){var D=r[y.charCodeAt(g)];if(D===255)return;for(var B=0,k=v-1;(D!==0||B<b)&&k!==-1;k--,B++)D+=a*A[k]>>>0,A[k]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");b=B,g++}if(y[g]!==" "){for(var L=v-b;L!==v&&A[L]===0;)L++;for(var I=new Uint8Array(p+(v-L)),P=p;L!==v;)I[P++]=A[L++];return I}}}function h(y){var g=d(y);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:h}}var ou=nu,su=ou,wi=su;var io=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")}},ao=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 xi(this,t)}},co=class{decoders;constructor(t){this.decoders=t}or(t){return xi(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 xi(e,t){return new co({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var uo=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 io(t,r,n),this.decoder=new ao(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function De({name:e,prefix:t,encode:r,decode:n}){return new uo(e,t,r,n)}function te({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=wi(r,e);return De({prefix:t,name:e,encode:n,decode:s=>zt(o(s))})}function iu(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 u=0;u<o;++u){let f=t[e[u]];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 au(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 cu(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Y({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=cu(n);return De({prefix:t,name:e,encode(s){return au(s,n,r)},decode(s){return iu(s,o,r,e)}})}var G=te({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),uu=te({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var lo={};wt(lo,{base32:()=>Kt,base32hex:()=>hu,base32hexpad:()=>mu,base32hexpadupper:()=>yu,base32hexupper:()=>pu,base32pad:()=>lu,base32padupper:()=>du,base32upper:()=>fu,base32z:()=>bu});var Kt=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),fu=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),lu=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),du=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),hu=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),pu=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),mu=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),yu=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),bu=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ho={};wt(ho,{base36:()=>rr,base36upper:()=>gu});var rr=te({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),gu=te({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var wu=Si,Ei=128,xu=127,Eu=~xu,vu=Math.pow(2,31);function Si(e,t,r){t=t||[],r=r||0;for(var n=r;e>=vu;)t[r++]=e&255|Ei,e/=128;for(;e&Eu;)t[r++]=e&255|Ei,e>>>=7;return t[r]=e|0,Si.bytes=r-n+1,t}var Su=po,Au=128,vi=127;function po(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw po.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&vi)<<o:(i&vi)*Math.pow(2,o),o+=7}while(i>=Au);return po.bytes=s-n,r}var _u=Math.pow(2,7),Tu=Math.pow(2,14),Iu=Math.pow(2,21),Ru=Math.pow(2,28),Bu=Math.pow(2,35),Cu=Math.pow(2,42),Du=Math.pow(2,49),Lu=Math.pow(2,56),Ou=Math.pow(2,63),ku=function(e){return e<_u?1:e<Tu?2:e<Iu?3:e<Ru?4:e<Bu?5:e<Cu?6:e<Du?7:e<Lu?8:e<Ou?9:10},Pu={encode:wu,decode:Su,encodingLength:ku},Ku=Pu,nr=Ku;function or(e,t=0){return[nr.decode(e,t),nr.decode.bytes]}function Le(e,t,r=0){return nr.encode(e,t,r),t}function Oe(e){return nr.encodingLength(e)}function Nt(e,t){let r=t.byteLength,n=Oe(e),o=n+Oe(r),s=new Uint8Array(o+r);return Le(e,s,0),Le(r,s,n),s.set(t,o),new ke(e,r,t,s)}function Pe(e){let t=zt(e),[r,n]=or(t),[o,s]=or(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ke(r,o,i,t)}function Ai(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&mi(e.bytes,r.bytes)}}var ke=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function _i(e,t){let{bytes:r,version:n}=e;return n===0?Uu(r,mo(e),t??G.encoder):Fu(r,mo(e),t??Kt.encoder)}var Ti=new WeakMap;function mo(e){let t=Ti.get(e);if(t==null){let r=new Map;return Ti.set(e,r),r}return t}var tt=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!==sr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Mu)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=Nt(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&&Ai(t.multihash,n.multihash)}toString(t){return _i(this,t)}toJSON(){return{"/":_i(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??Ii(n,o,s.bytes))}else if(r[qu]===!0){let{version:n,multihash:o,code:s}=r,i=Pe(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!==sr)throw new Error(`Version 0 CID must use dag-pb (code: ${sr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ii(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,sr,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=zt(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 ke(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,d]=or(t.subarray(r));return r+=d,l},o=n(),s=sr;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(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=Nu(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 mo(s).set(n,t),s}};function Nu(e,t){switch(e[0]){case"Q":{let r=t??G;return[G.prefix,r.decode(`${G.prefix}${e}`)]}case G.prefix:{let r=t??G;return[G.prefix,r.decode(e)]}case Kt.prefix:{let r=t??Kt;return[Kt.prefix,r.decode(e)]}case rr.prefix:{let r=t??rr;return[rr.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 Uu(e,t,r){let{prefix:n}=r;if(n!==G.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 Fu(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 sr=112,Mu=18;function Ii(e,t,r){let n=Oe(e),o=n+Oe(t),s=new Uint8Array(o+r.byteLength);return Le(e,s,0),Le(t,s,n),s.set(r,o),s}var qu=Symbol.for("@ipld/js-cid/CID");var yo={};wt(yo,{identity:()=>Bt});var Ri=0,zu="identity",Bi=zt;function Vu(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Nt(Ri,Bi(e))}var Bt={code:Ri,name:zu,encode:Bi,digest:Vu};function W(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}async function Ci(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}function et(e=0){return new Uint8Array(e)}function xt(e=0){return new Uint8Array(e)}function Vt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=xt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Li=Symbol.for("@achingbrain/uint8arraylist");function Di(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 jr(e){return!!e?.[Li]}var ht=class e{bufs;length;[Li]=!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(jr(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}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(jr(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=Di(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Di(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(jr(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 Vt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Vt(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 u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){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(!jr(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 a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let h=this.get(l+d);if(n[d]!==h){f=Math.max(1,d-a[h]);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=xt(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=et(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=et(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=et(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=xt(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=et(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=et(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=et(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=et(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=et(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(!W(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 bo={};wt(bo,{base10:()=>Hu});var Hu=te({prefix:"9",name:"base10",alphabet:"0123456789"});var go={};wt(go,{base16:()=>$u,base16upper:()=>Wu});var $u=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Wu=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var wo={};wt(wo,{base2:()=>ju});var ju=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var xo={};wt(xo,{base256emoji:()=>Qu});var Oi=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}"),Zu=Oi.reduce((e,t,r)=>(e[r]=t,e),[]),Yu=Oi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Gu(e){return e.reduce((t,r)=>(t+=Zu[r],t),"")}function Xu(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Yu[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Qu=De({prefix:"\u{1F680}",name:"base256emoji",encode:Gu,decode:Xu});var vo={};wt(vo,{base64:()=>Ju,base64pad:()=>tf,base64url:()=>Eo,base64urlpad:()=>ef});var Ju=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),tf=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Eo=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ef=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var So={};wt(So,{base8:()=>rf});var rf=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ao={};wt(Ao,{identity:()=>nf});var nf=De({prefix:"\0",name:"identity",encode:e=>bi(e),decode:e=>yi(e)});var qh=new TextEncoder,zh=new TextDecoder;var Io={};wt(Io,{sha256:()=>ir,sha512:()=>cf});var af=20;function To({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new _o(e,t,r,n,o)}var _o=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??af,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?ki(n,this.code,r?.truncate):n.then(o=>ki(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ki(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Nt(t,e)}function Ki(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var ir=To({name:"sha2-256",code:18,encode:Ki("SHA-256")}),cf=To({name:"sha2-512",code:19,encode:Ki("SHA-512")});var ar={...Ao,...wo,...So,...bo,...go,...lo,...ho,...fo,...vo,...xo},tp={...Io,...yo};function Ui(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ni=Ui("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Ro=Ui("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=xt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),uf={utf8:Ni,"utf-8":Ni,hex:ar.base16,latin1:Ro,ascii:Ro,binary:Ro,...ar},Zr=uf;function V(e,t="utf8"){let r=Zr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function q(e,t="utf8"){let r=Zr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var ff=parseInt("11111",2),Bo=parseInt("10000000",2),lf=parseInt("01111111",2),Fi={0:cr,1:cr,2:df,3:mf,4:yf,5:pf,6:hf,16:cr,22:cr,48:cr};function Ht(e,t={offset:0}){let r=e[t.offset]&ff;if(t.offset++,Fi[r]!=null)return Fi[r](e,t);throw new Error("No decoder for tag "+r)}function ur(e,t){let r=0;if((e[t.offset]&Bo)===Bo){let n=e[t.offset]&lf,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 cr(e,t){ur(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Ht(e,t);if(n===null)break;r.push(n)}return r}function df(e,t){let r=ur(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 hf(e,t){let r=ur(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 u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function pf(e,t){return t.offset++,null}function mf(e,t){let r=ur(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 yf(e,t){let r=ur(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function bf(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 Co(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=bf(e.byteLength);return new ht(Uint8Array.from([t.byteLength|Bo]),t)}function Et(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]),Co(t),t)}function Yr(e){let t=Uint8Array.from([0]),r=new ht(t,e);return new ht(Uint8Array.from([3]),Co(r),r)}function re(e,t=48){let r=new ht;for(let n of e)r.append(n);return new ht(Uint8Array.from([t]),Co(r),r)}var gf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),wf=Uint8Array.from([6,5,43,129,4,0,34]),xf=Uint8Array.from([6,5,43,129,4,0,35]),Ef={ext:!0,kty:"EC",crv:"P-256"},vf={ext:!0,kty:"EC",crv:"P-384"},Sf={ext:!0,kty:"EC",crv:"P-521"},Do=32,Lo=48,Oo=66;function ko(e){let t=Ht(e);return Mi(t)}function Mi(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Do*2+1)return n=q(t.subarray(r,r+Do),"base64url"),o=q(t.subarray(r+Do),"base64url"),new Ke({...Ef,key_ops:["verify"],x:n,y:o});if(t.byteLength===Lo*2+1)return n=q(t.subarray(r,r+Lo),"base64url"),o=q(t.subarray(r+Lo),"base64url"),new Ke({...vf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Oo*2+1)return n=q(t.subarray(r,r+Oo),"base64url"),o=q(t.subarray(r+Oo),"base64url"),new Ke({...Sf,key_ops:["verify"],x:n,y:o});throw new F(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function qi(e){return re([Et(Uint8Array.from([1])),re([Af(e.crv)],160),re([Yr(new ht(Uint8Array.from([4]),V(e.x??"","base64url"),V(e.y??"","base64url")))],161)]).subarray()}function Af(e){if(e==="P-256")return gf;if(e==="P-384")return wf;if(e==="P-521")return xf;throw new F(`Invalid curve ${e}`)}var Ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=qi(this.jwk)),this._raw}toMultihash(){return Bt.digest(_t(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}async verify(t,r,n){return Ci(this.jwk,r,t,n)}};function Po(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function ne(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function vt(e,t,r=""){let n=Po(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return e}function Gr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(ne(e.outputLen),ne(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Ne(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 Xr(e,t){vt(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function Wt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Qr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ct(e,t){return e<<32-t|e>>>t}var Vi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",_f=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Jr(e){if(vt(e),Vi)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=_f[e[r]];return t}var $t={_0:48,_9:57,A:65,F:70,a:97,f:102};function zi(e){if(e>=$t._0&&e<=$t._9)return e-$t._0;if(e>=$t.A&&e<=$t.F)return e-($t.A-10);if(e>=$t.a&&e<=$t.f)return e-($t.a-10)}function fr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(Vi)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,r=t/2;if(t%2)throw new RangeError("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=zi(e.charCodeAt(s)),a=zi(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Ko(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];vt(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 No(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Hi(e=32){ne(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Uo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function $i(e,t,r){return e&t^~e&r}function Wi(e,t,r){return e&t^e&r^t&r}var lr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Qr(this.buffer)}update(t){Ne(this),vt(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=Qr(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){Ne(this),Xr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Wt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Qr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.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||=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()}},jt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var tn=BigInt(4294967295),ji=BigInt(32);function Tf(e,t=!1){return t?{h:Number(e&tn),l:Number(e>>ji&tn)}:{h:Number(e>>ji&tn)|0,l:Number(e&tn)|0}}function Zi(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}=Tf(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Fo=(e,t,r)=>e>>>r,Mo=(e,t,r)=>e<<32-r|t>>>r,pe=(e,t,r)=>e>>>r|t<<32-r,me=(e,t,r)=>e<<32-r|t>>>r,dr=(e,t,r)=>e<<64-r|t>>>r-32,hr=(e,t,r)=>e>>>r-32|t<<64-r;function Ut(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Yi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Gi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Xi=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Qi=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ji=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ta=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Rf=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]),oe=new Uint32Array(64),qo=class extends lr{constructor(t){super(64,t,8,!1)}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 l=0;l<16;l++,r+=4)oe[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=oe[l-15],h=oe[l-2],y=Ct(d,7)^Ct(d,18)^d>>>3,g=Ct(h,17)^Ct(h,19)^h>>>10;oe[l]=g+oe[l-7]+y+oe[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Ct(a,6)^Ct(a,11)^Ct(a,25),h=f+d+$i(a,c,u)+Rf[l]+oe[l]|0,g=(Ct(n,2)^Ct(n,13)^Ct(n,22))+Wi(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+g|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,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Wt(oe)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Wt(this.buffer)}},zo=class extends qo{A=jt[0]|0;B=jt[1]|0;C=jt[2]|0;D=jt[3]|0;E=jt[4]|0;F=jt[5]|0;G=jt[6]|0;H=jt[7]|0;constructor(){super(32)}};var ea=Zi(["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))),Bf=ea[0],Cf=ea[1],se=new Uint32Array(80),ie=new Uint32Array(80),Vo=class extends lr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:h,Gl:y,Hh:g,Hl:p}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,h,y,g,p]}set(t,r,n,o,s,i,a,c,u,f,l,d,h,y,g,p){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=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=y|0,this.Hh=g|0,this.Hl=p|0}process(t,r){for(let A=0;A<16;A++,r+=4)se[A]=t.getUint32(r),ie[A]=t.getUint32(r+=4);for(let A=16;A<80;A++){let D=se[A-15]|0,B=ie[A-15]|0,k=pe(D,B,1)^pe(D,B,8)^Fo(D,B,7),L=me(D,B,1)^me(D,B,8)^Mo(D,B,7),I=se[A-2]|0,P=ie[A-2]|0,$=pe(I,P,19)^dr(I,P,61)^Fo(I,P,6),K=me(I,P,19)^hr(I,P,61)^Mo(I,P,6),m=Xi(L,K,ie[A-7],ie[A-16]),w=Qi(m,k,$,se[A-7],se[A-16]);se[A]=w|0,ie[A]=m|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:h,Fl:y,Gh:g,Gl:p,Hh:b,Hl:v}=this;for(let A=0;A<80;A++){let D=pe(l,d,14)^pe(l,d,18)^dr(l,d,41),B=me(l,d,14)^me(l,d,18)^hr(l,d,41),k=l&h^~l&g,L=d&y^~d&p,I=Ji(v,B,L,Cf[A],ie[A]),P=ta(I,b,D,k,Bf[A],se[A]),$=I|0,K=pe(n,o,28)^dr(n,o,34)^dr(n,o,39),m=me(n,o,28)^hr(n,o,34)^hr(n,o,39),w=n&s^n&a^s&a,S=o&i^o&c^i&c;b=g|0,v=p|0,g=h|0,p=y|0,h=l|0,y=d|0,{h:l,l:d}=Ut(u|0,f|0,P|0,$|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let E=Yi($,m,S);n=Gi(E,P,K,w),o=E|0}({h:n,l:o}=Ut(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ut(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ut(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Ut(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Ut(this.Eh|0,this.El|0,l|0,d|0),{h,l:y}=Ut(this.Fh|0,this.Fl|0,h|0,y|0),{h:g,l:p}=Ut(this.Gh|0,this.Gl|0,g|0,p|0),{h:b,l:v}=Ut(this.Hh|0,this.Hl|0,b|0,v|0),this.set(n,o,s,i,a,c,u,f,l,d,h,y,g,p,b,v)}roundClean(){Wt(se,ie)}destroy(){this.destroyed=!0,Wt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ho=class extends Vo{Ah=ct[0]|0;Al=ct[1]|0;Bh=ct[2]|0;Bl=ct[3]|0;Ch=ct[4]|0;Cl=ct[5]|0;Dh=ct[6]|0;Dl=ct[7]|0;Eh=ct[8]|0;El=ct[9]|0;Fh=ct[10]|0;Fl=ct[11]|0;Gh=ct[12]|0;Gl=ct[13]|0;Hh=ct[14]|0;Hl=ct[15]|0;constructor(){super(64)}};var Ue=No(()=>new zo,Uo(1));var en=No(()=>new Ho,Uo(3));var M=(e,t,r)=>vt(e,t,r),Wo=ne,Fe=Jr,nt=(...e)=>Ko(...e),Me=e=>fr(e),ye=Po,pr=e=>Hi(e),nn=BigInt(0),$o=BigInt(1);function Dt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function on(e){if(typeof e=="bigint"){if(!rn(e))throw new RangeError("positive bigint expected, got "+e)}else Wo(e);return e}function Lt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function mr(e){let t=on(e).toString(16);return t.length&1?"0"+t:t}function ra(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?nn:BigInt("0x"+e)}function be(e){return ra(Jr(e))}function Ft(e){return ra(Jr(yr(vt(e)).reverse()))}function sn(e,t){if(ne(t),t===0)throw new RangeError("zero length");e=on(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return fr(r.padStart(t*2,"0"))}function jo(e,t){return sn(e,t).reverse()}function na(e,t){if(e=M(e),t=M(t),e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function yr(e){return Uint8Array.from(M(e))}function an(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var rn=e=>typeof e=="bigint"&&nn<=e;function Df(e,t,r){return rn(e)&&rn(t)&&rn(r)&&t<=e&&e<r}function qe(e,t,r,n){if(!Df(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function ze(e){if(e<nn)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>nn;e>>=$o,t+=1);return t}var br=e=>($o<<BigInt(e))-$o;function oa(e,t,r){if(ne(e,"hashLen"),ne(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=p=>new Uint8Array(p),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...p)=>r(u,nt(c,...p)),h=(p=o)=>{u=d(s,p),c=d(),p.length!==0&&(u=d(i,p),c=d())},y=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let p=0,b=[];for(;p<t;){c=d();let v=c.slice();b.push(v),p+=c.length}return nt(...b)};return(p,b)=>{l(),h(p);let v;for(;(v=b(y()))===void 0;)h();return l(),v}}function Ot(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(e,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=e[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(r,!0)}var Zo=()=>{throw new Error("not implemented")};var ut=BigInt(0),X=BigInt(1),ge=BigInt(2),ca=BigInt(3),ua=BigInt(4),fa=BigInt(5),Lf=BigInt(7),la=BigInt(8),Of=BigInt(9),da=BigInt(16);function J(e,t){if(t<=ut)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=ut?r:t+r}function j(e,t,r){if(t<ut)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >ut;)n*=n,n%=r;return n}function sa(e,t){if(e===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let r=J(e,t),n=t,o=ut,s=X,i=X,a=ut;for(;r!==ut;){let u=n/r,f=n-r*u,l=o-i*u,d=s-a*u;n=r,r=f,o=i,s=a,i=l,a=d}if(n!==X)throw new Error("invert: does not exist");return J(o,t)}function Yo(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function ha(e,t){let r=e,n=(r.ORDER+X)/ua,o=r.pow(t,n);return Yo(r,o,t),o}function kf(e,t){let r=e,n=(r.ORDER-fa)/la,o=r.mul(t,ge),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,ge),s),c=r.mul(i,r.sub(a,r.ONE));return Yo(r,c,t),c}function Pf(e){let t=Ve(e),r=pa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Lf)/da;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,o),h=u.mul(f,s),y=u.eql(u.sqr(l),c),g=u.eql(u.sqr(d),c);f=u.cmov(f,l,y),l=u.cmov(h,d,g);let p=u.eql(u.sqr(l),c),b=u.cmov(f,l,p);return Yo(u,b,c),b})}function pa(e){if(e<ca)throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%ge===ut;)t/=ge,r++;let n=ge,o=Ve(e);for(;ia(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ha;let s=o.pow(n,t),i=(t+X)/ge;return function(c,u){let f=c;if(f.is0(u))return u;if(ia(f,u)!==1)throw new Error("Cannot find square root");let l=r,d=f.mul(f.ONE,s),h=f.pow(u,t),y=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))return f.ZERO;let g=1,p=f.sqr(h);for(;!f.eql(p,f.ONE);)if(g++,p=f.sqr(p),g===l)throw new Error("Cannot find square root");let b=X<<BigInt(l-g-1),v=f.pow(d,b);l=g,d=f.sqr(v),h=f.mul(h,d),y=f.mul(y,v)}return y}}function Kf(e){return e%ua===ca?ha:e%la===fa?kf:e%da===Of?Pf(e):pa(e)}var Zt=(e,t)=>(J(e,t)&X)===X,Nf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Go(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Nf.reduce((n,o)=>(n[o]="function",n),t);if(Ot(e,r),Lt(e.BYTES,"BYTES"),Lt(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function Uf(e,t,r){let n=e;if(r<ut)throw new Error("invalid exponent, negatives unsupported");if(r===ut)return n.ONE;if(r===X)return t;let o=n.ONE,s=t;for(;r>ut;)r&X&&(o=n.mul(o,s)),s=n.sqr(s),r>>=X;return o}function gr(e,t,r=!1){let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function ia(e,t){let r=e,n=(r.ORDER-X)/ge,o=r.pow(t,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Ff(e,t){if(t!==void 0&&Wo(t),e<=ut)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=ze(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var aa=new WeakMap,cn=class{ORDER;BITS;BYTES;isLE;ZERO=ut;ONE=X;_lengths;_mod;constructor(t,r={}){if(t<=X)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=Ff(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return J(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return ut<=t&&t<this.ORDER}is0(t){return t===ut}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&X)===X}neg(t){return J(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return J(t*t,this.ORDER)}add(t,r){return J(t+r,this.ORDER)}sub(t,r){return J(t-r,this.ORDER)}mul(t,r){return J(t*r,this.ORDER)}pow(t,r){return Uf(this,t,r)}div(t,r){return J(t*sa(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return sa(t,this.ORDER)}sqrt(t){let r=aa.get(this);return r||aa.set(this,r=Kf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?jo(t,this.BYTES):sn(t,this.BYTES)}fromBytes(t,r=!1){M(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?Ft(t):be(t);if(a&&(c=J(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return gr(this,t)}cmov(t,r,n){return Dt(n,"condition"),n?r:t}};Object.freeze(cn.prototype);function Ve(e,t={}){return new cn(e,t)}function ma(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=X)throw new Error("field order must be greater than 1");let t=ze(e-X);return Math.ceil(t/8)}function Xo(e){let t=ma(e);return t+Math.ceil(t/2)}function Qo(e,t,r=!1){M(e);let n=e.length,o=ma(t),s=Math.max(Xo(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ft(e):be(e),a=J(i,t-X)+X;return r?jo(a,o):sn(a,o)}var He=BigInt(0),we=BigInt(1);function wr(e,t){let r=t.negate();return e?r:t}function xe(e,t){let r=gr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function wa(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Jo(e,t){wa(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=br(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ya(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+=we);let u=t*n,f=u+Math.abs(a)-1,l=a===0,d=a<0,h=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:d,isNegF:h,offsetF:u}}var ts=new WeakMap,xa=new WeakMap;function es(e){return xa.get(e)||1}function ba(e){if(e!==He)throw new Error("invalid wNAF")}var $e=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>He;)r&we&&(n=n.add(o)),o=o.double(),r>>=we;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Jo(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Jo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:d,offsetF:h}=ya(n,a,i);n=c,f?s=s.add(wr(d,r[h])):o=o.add(wr(l,r[u]))}return ba(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Jo(t,this.bits);for(let i=0;i<s.windows&&n!==He;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=ya(n,i,s);if(n=a,!u){let l=r[c];o=o.add(f?l.negate():l)}}return ba(n),o}getPrecomputes(t,r,n){let o=ts.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ts.set(r,o))),o}cached(t,r,n){let o=es(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=es(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){wa(r,this.bits),xa.set(t,r),ts.delete(t)}hasCache(t){return es(t)!==1}};function Ea(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>He||n>He;)r&we&&(s=s.add(o)),n&we&&(i=i.add(o)),o=o.double(),r>>=we,n>>=we;return{p1:s,p2:i}}function ga(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Go(t),t}else return Ve(e,{isLE:r})}function un(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>He))throw new Error(`CURVE.${c} must be positive bigint`)}let o=ga(t.p,r.Fp,n),s=ga(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function fn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var ae=BigInt(0),it=BigInt(1),rs=BigInt(2),Mf=BigInt(8);function qf(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 va(e,t={}){let r=t,n=un("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Ot(r,{},{uvRatio:"function"});let c=rs<<BigInt(s.BYTES*8)-it,u=g=>o.create(g),f=r.uvRatio===void 0?(g,p)=>{try{return{isValid:!0,value:o.sqrt(o.div(g,p))}}catch{return{isValid:!1,value:ae}}}:r.uvRatio;if(!qf(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(g,p,b=!1){let v=b?it:ae;return qe("coordinate "+g,p,v,c),p}function d(g){if(!(g instanceof h))throw new Error("EdwardsPoint expected")}class h{static BASE=new h(i.Gx,i.Gy,it,u(i.Gx*i.Gy));static ZERO=new h(ae,it,it,ae);static Fp=o;static Fn=s;X;Y;Z;T;constructor(p,b,v,A){this.X=l("x",p),this.Y=l("y",b),this.Z=l("z",v,!0),this.T=l("t",A),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){if(p instanceof h)throw new Error("extended point not allowed");let{x:b,y:v}=p||{};return l("x",b),l("y",v),new h(b,v,it,u(b*v))}static fromBytes(p,b=!1){let v=o.BYTES,{a:A,d:D}=i;p=yr(M(p,v,"point")),Dt(b,"zip215");let B=yr(p),k=p[v-1];B[v-1]=k&-129;let L=Ft(B),I=b?c:o.ORDER;qe("point.y",L,ae,I);let P=u(L*L),$=u(P-it),K=u(D*P-A),{isValid:m,value:w}=f($,K);if(!m)throw new Error("bad point: invalid y coordinate");let S=(w&it)===it,E=(k&128)!==0;if(!b&&w===ae&&E)throw new Error("bad point: x=0 and x_0=1");return E!==S&&(w=u(-w)),h.fromAffine({x:w,y:L})}static fromHex(p,b=!1){return h.fromBytes(Me(p),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,b=!0){return y.createCache(this,p),b||this.multiply(rs),this}assertValidity(){let p=this,{a:b,d:v}=i;if(p.is0())throw new Error("bad point: ZERO");let{X:A,Y:D,Z:B,T:k}=p,L=u(A*A),I=u(D*D),P=u(B*B),$=u(P*P),K=u(L*b),m=u(P*u(K+I)),w=u($+u(v*u(L*I)));if(m!==w)throw new Error("bad point: equation left != right (1)");let S=u(A*D),E=u(B*k);if(S!==E)throw new Error("bad point: equation left != right (2)")}equals(p){d(p);let{X:b,Y:v,Z:A}=this,{X:D,Y:B,Z:k}=p,L=u(b*k),I=u(D*A),P=u(v*k),$=u(B*A);return L===I&&P===$}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:p}=i,{X:b,Y:v,Z:A}=this,D=u(b*b),B=u(v*v),k=u(rs*u(A*A)),L=u(p*D),I=b+v,P=u(u(I*I)-D-B),$=L+B,K=$-k,m=L-B,w=u(P*K),S=u($*m),E=u(P*m),x=u(K*$);return new h(w,S,x,E)}add(p){d(p);let{a:b,d:v}=i,{X:A,Y:D,Z:B,T:k}=this,{X:L,Y:I,Z:P,T:$}=p,K=u(A*L),m=u(D*I),w=u(k*v*$),S=u(B*P),E=u((A+D)*(L+I)-K-m),x=S-w,_=S+w,R=u(m-b*K),T=u(E*x),C=u(_*R),O=u(E*R),U=u(x*_);return new h(T,C,U,O)}subtract(p){return d(p),this.add(p.negate())}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:b,f:v}=y.cached(this,p,A=>xe(h,A));return xe(h,[b,v])[0]}multiplyUnsafe(p){if(!s.isValid(p))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return p===ae?h.ZERO:this.is0()||p===it?this:y.unsafe(this,p,b=>xe(h,b))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return y.unsafe(this,i.n).is0()}toAffine(p){let b=this,v=p,{X:A,Y:D,Z:B}=b,k=b.is0();v==null&&(v=k?Mf:o.inv(B));let L=u(A*v),I=u(D*v),P=o.mul(B,v);if(k)return{x:ae,y:it};if(P!==it)throw new Error("invZ was invalid");return{x:L,y:I}}clearCofactor(){return a===it?this:this.multiplyUnsafe(a)}toBytes(){let{x:p,y:b}=this.toAffine(),v=o.toBytes(b);return v[v.length-1]|=p&it?128:0,v}toHex(){return Fe(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=new $e(h,s.BITS);return s.BITS>=8&&h.BASE.precompute(8),Object.freeze(h.prototype),Object.freeze(h),h}var ln=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Zo()}static fromHex(t){Zo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Fe(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.ep.precompute(t,r),this}};function Sa(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;Ot(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Lt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?pr:o.randomBytes,d=o.adjustScalarBytes===void 0?m=>m:o.adjustScalarBytes,h=o.domain===void 0?(m,w,S)=>{if(Dt(S,"phflag"),w.length||S)throw new Error("Contexts/pre-hash are not supported");return m}:o.domain;function y(m){return c.create(Ft(m))}function g(m){let w=L.secretKey;M(m,L.secretKey,"secretKey");let S=M(n(m),2*w,"hashedSecretKey"),E=d(S.slice(0,w)),x=S.slice(w,2*w),_=y(E);return{head:E,prefix:x,scalar:_}}function p(m){let{head:w,prefix:S,scalar:E}=g(m),x=i.multiply(E),_=x.toBytes();return{head:w,prefix:S,scalar:E,point:x,pointBytes:_}}function b(m){return p(m).pointBytes}function v(m=Uint8Array.of(),...w){let S=nt(...w);return y(n(h(S,M(m,void 0,"context"),!!s)))}function A(m,w,S={}){m=M(m,void 0,"message"),s&&(m=s(m));let{prefix:E,scalar:x,pointBytes:_}=p(w),R=v(S.context,E,m),T=i.multiply(R).toBytes(),C=v(S.context,T,_,m),O=c.create(R+C*x);if(!c.isValid(O))throw new Error("sign failed: invalid s");let U=nt(T,c.toBytes(O));return M(U,L.signature,"result")}let D={zip215:o.zip215};function B(m,w,S,E=D){let{context:x}=E,_=E.zip215===void 0?!!D.zip215:E.zip215,R=L.signature;m=M(m,R,"signature"),w=M(w,void 0,"message"),S=M(S,L.publicKey,"publicKey"),_!==void 0&&Dt(_,"zip215"),s&&(w=s(w));let T=R/2,C=m.subarray(0,T),O=Ft(m.subarray(T,R)),U,z,N;try{U=e.fromBytes(S,_),z=e.fromBytes(C,_),N=i.multiplyUnsafe(O)}catch{return!1}if(!_&&U.isSmallOrder())return!1;let rt=v(x,C,S,w);return z.add(U.multiplyUnsafe(rt)).subtract(N).clearCofactor().is0()}let k=a.BYTES,L={secretKey:k,publicKey:k,signature:2*k,seed:k};function I(m){return m=m===void 0?l(L.seed):m,M(m,L.seed,"seed")}function P(m){return ye(m)&&m.length===L.secretKey}function $(m,w){try{return!!e.fromBytes(m,w===void 0?D.zip215:w)}catch{return!1}}let K={getExtendedPublicKey:p,randomSecretKey:I,isValidSecretKey:P,isValidPublicKey:$,toMontgomery(m){let{y:w}=e.fromBytes(m),S=L.publicKey,E=S===32;if(!E&&S!==57)throw new Error("only defined for 25519 and 448");let x=E?a.div(it+w,it-w):a.div(w-it,w+it);return a.toBytes(x)},toMontgomerySecret(m){let w=L.secretKey;M(m,w);let S=n(m.subarray(0,w));return d(S).subarray(0,w)}};return Object.freeze(L),Object.freeze(K),Object.freeze({keygen:fn(I,b),getPublicKey:b,sign:A,verify:B,utils:K,Point:e,lengths:L})}function xr(e,t){if(Lt(e),Lt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function zf(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function Vf(e){if(!ye(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?an(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function ns(e,t,r,n){M(e),Lt(r),t=Vf(t),t.length>255&&(t=n(nt(an("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=nt(t,xr(t.length,1)),c=new Uint8Array(s),u=xr(r,2),f=new Array(i),l=n(nt(c,e,u,xr(0,1),a));f[0]=n(nt(l,xr(1,1),a));for(let h=1;h<i;h++){let y=[zf(l,f[h-1]),xr(h+1,1),a];f[h]=n(nt(...y))}return nt(...f).slice(0,r)}var Aa="HashToScalar-";var Hf=BigInt(0),Yt=BigInt(1),_a=BigInt(2);var $f=BigInt(5),Wf=BigInt(8),We=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),as={p:We,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Wf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function jf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=We,a=e*e%s*e%s,c=j(a,_a,s)*a%s,u=j(c,Yt,s)*e%s,f=j(u,$f,s)*u%s,l=j(f,t,s)*f%s,d=j(l,r,s)*l%s,h=j(d,n,s)*d%s,y=j(h,o,s)*h%s,g=j(y,o,s)*h%s,p=j(g,t,s)*f%s;return{pow_p_5_8:j(p,_a,s)*e%s,b2:a}}function Zf(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var os=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function cs(e,t){let r=We,n=J(t*t*t,r),o=J(n*n*t,r),s=jf(e*o).pow_p_5_8,i=J(e*n*s,r),a=J(t*i*i,r),c=i,u=J(i*os,r),f=a===e,l=a===J(-e,r),d=a===J(-e*os,r);return f&&(i=c),(l||d)&&(i=u),Zt(i,r)&&(i=J(-i,r)),{isValid:f||l,value:i}}var ue=va(as,{uvRatio:cs}),ce=ue.Fp,Ra=ue.Fn;function Yf(e){return Sa(ue,en,Object.assign({adjustScalarBytes:Zf,zip215:!0},e))}var Ba=Yf({});var ss=os,Gf=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Xf=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Qf=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Jf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ta=e=>cs(Yt,e),tl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),is=e=>ce.create(Ft(e)&tl);function Ia(e){let{d:t}=as,r=We,n=b=>ce.create(b),o=n(ss*e*e),s=n((o+Yt)*Qf),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=cs(s,a),f=n(u*e);Zt(f,r)||(f=n(-f)),c||(u=f),c||(i=o);let l=n(i*(o-Yt)*Jf-a),d=u*u,h=n((u+u)*a),y=n(l*Gf),g=n(Yt-d),p=n(Yt+d);return new ue(n(h*p),n(g*y),n(y*p),n(h*g))}var fe=class e extends ln{static BASE=new e(ue.BASE);static ZERO=new e(ue.ZERO);static Fp=ce;static Fn=Ra;constructor(t){super(t)}static fromAffine(t){return new e(ue.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){vt(t,32);let{a:r,d:n}=as,o=We,s=D=>ce.create(D),i=is(t);if(!na(ce.toBytes(i),t)||Zt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Yt+r*a),u=s(Yt-r*a),f=s(c*c),l=s(u*u),d=s(r*n*f-l),{isValid:h,value:y}=Ta(s(d*l)),g=s(y*u),p=s(y*g*d),b=s((i+i)*g);Zt(b,o)&&(b=s(-b));let v=s(c*p),A=s(b*v);if(!h||Zt(A,o)||v===Hf)throw new Error("invalid ristretto255 encoding 2");return new e(new ue(b,v,Yt,A))}static fromHex(t){return e.fromBytes(fr(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=We,i=p=>ce.create(p),a=i(i(n+r)*i(n-r)),c=i(t*r),u=i(c*c),{value:f}=Ta(i(a*u)),l=i(f*a),d=i(f*c),h=i(l*d*o),y;if(Zt(o*h,s)){let p=i(r*ss),b=i(t*ss);t=p,r=b,y=i(l*Xf)}else y=d;Zt(t*h,s)&&(r=i(-r));let g=i((n-r)*y);return Zt(g,s)&&(g=i(-g)),ce.toBytes(g)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>ce.create(u),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(e.ZERO)}};Object.freeze(fe.BASE);Object.freeze(fe.ZERO);Object.freeze(fe.prototype);Object.freeze(fe);var el=Object.freeze({Point:fe,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=ns(e,r,64,en);return el.deriveToCurve(n)},hashToScalar(e,t={DST:Aa}){let r=ns(e,t.DST,64,en);return Ra.create(Ft(r))},deriveToCurve(e){vt(e,64);let t=is(e.subarray(0,32)),r=Ia(t),n=is(e.subarray(32,64)),o=Ia(n);return new fe(r.add(o))}});var Er=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},dn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ca={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new dn("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 Tt=Ca;var hn=32;var us,rl=(async()=>{try{return await Tt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function nl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Tt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Tt.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 ol(e,t,r){return Ba.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Da(e,t,r){return us==null&&(us=await rl),us?nl(e,t,r):ol(e,t,r)}function pn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var mn=class{type="Ed25519";raw;constructor(t){this.raw=fs(t,hn)}toMultihash(){return Bt.digest(_t(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Da(this.raw,r,t);return pn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ls(e){return e=fs(e,hn),new mn(e)}function fs(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new F(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var il=Math.pow(2,7),al=Math.pow(2,14),cl=Math.pow(2,21),ds=Math.pow(2,28),hs=Math.pow(2,35),ps=Math.pow(2,42),ms=Math.pow(2,49),H=128,lt=127;function It(e){if(e<il)return 1;if(e<al)return 2;if(e<cl)return 3;if(e<ds)return 4;if(e<hs)return 5;if(e<ps)return 6;if(e<ms)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function je(e,t,r=0){switch(It(e)){case 8:t[r++]=e&255|H,e/=128;case 7:t[r++]=e&255|H,e/=128;case 6:t[r++]=e&255|H,e/=128;case 5:t[r++]=e&255|H,e/=128;case 4:t[r++]=e&255|H,e>>>=7;case 3:t[r++]=e&255|H,e>>>=7;case 2:t[r++]=e&255|H,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function ul(e,t,r=0){switch(It(e)){case 8:t.set(r++,e&255|H),e/=128;case 7:t.set(r++,e&255|H),e/=128;case 6:t.set(r++,e&255|H),e/=128;case 5:t.set(r++,e&255|H),e/=128;case 4:t.set(r++,e&255|H),e>>>=7;case 3:t.set(r++,e&255|H),e>>>=7;case 2:t.set(r++,e&255|H),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function ys(e,t){let r=e[t],n=0;if(n+=r<,r<H||(r=e[t+1],n+=(r<)<<7,r<H)||(r=e[t+2],n+=(r<)<<14,r<H)||(r=e[t+3],n+=(r<)<<21,r<H)||(r=e[t+4],n+=(r<)*ds,r<H)||(r=e[t+5],n+=(r<)*hs,r<H)||(r=e[t+6],n+=(r<)*ps,r<H)||(r=e[t+7],n+=(r<)*ms,r<H))return n;throw new RangeError("Could not decode varint")}function fl(e,t){let r=e.get(t),n=0;if(n+=r<,r<H||(r=e.get(t+1),n+=(r<)<<7,r<H)||(r=e.get(t+2),n+=(r<)<<14,r<H)||(r=e.get(t+3),n+=(r<)<<21,r<H)||(r=e.get(t+4),n+=(r<)*ds,r<H)||(r=e.get(t+5),n+=(r<)*hs,r<H)||(r=e.get(t+6),n+=(r<)*ps,r<H)||(r=e.get(t+7),n+=(r<)*ms,r<H))return n;throw new RangeError("Could not decode varint")}function yn(e,t,r=0){return t==null&&(t=xt(It(e))),t instanceof Uint8Array?je(e,t,r):ul(e,t,r)}function bs(e,t=0){return e instanceof Uint8Array?ys(e,t):fl(e,t)}var gs=new Float32Array([-0]),le=new Uint8Array(gs.buffer);function ka(e,t,r){gs[0]=e,t[r]=le[0],t[r+1]=le[1],t[r+2]=le[2],t[r+3]=le[3]}function Pa(e,t){return le[0]=e[t],le[1]=e[t+1],le[2]=e[t+2],le[3]=e[t+3],gs[0]}var ws=new Float64Array([-0]),dt=new Uint8Array(ws.buffer);function Ka(e,t,r){ws[0]=e,t[r]=dt[0],t[r+1]=dt[1],t[r+2]=dt[2],t[r+3]=dt[3],t[r+4]=dt[4],t[r+5]=dt[5],t[r+6]=dt[6],t[r+7]=dt[7]}function Na(e,t){return dt[0]=e[t],dt[1]=e[t+1],dt[2]=e[t+2],dt[3]=e[t+3],dt[4]=e[t+4],dt[5]=e[t+5],dt[6]=e[t+6],dt[7]=e[t+7],ws[0]}var ll=BigInt(Number.MAX_SAFE_INTEGER),dl=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 Ee;if(t<ll&&t>dl)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>Ua&&(o=0n,++n>Ua&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ee;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):Ee}},Ee=new St(0,0);Ee.toBigInt=function(){return 0n};Ee.zzEncode=Ee.zzDecode=function(){return this};Ee.length=function(){return 1};var Ua=4294967296n;function Fa(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 Ma(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 xs(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 kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function bn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Es=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,kt(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 kt(this,4);return bn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw kt(this,4);return bn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw kt(this,4);let t=Pa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw kt(this,4);let t=Na(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 kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ma(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw kt(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 kt(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 kt(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 kt(this,8);let t=bn(this.buf,this.pos+=4),r=bn(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=ys(this.buf,this.pos);return this.pos+=It(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 vr(e){return new Es(e instanceof Uint8Array?e:e.subarray())}function pt(e,t,r){let n=vr(e);return t.decode(n,void 0,r)}function vs(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return xt(i);o+i>t&&(n=xt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ve=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ss(){}var _s=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},hl=vs();function pl(e){return globalThis.Buffer!=null?xt(e):hl(e)}var Ar=class{len;head;tail;states;constructor(){this.len=0,this.head=new ve(Ss,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ve(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ts((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(gn,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(gn,r.length(),r)}uint64Number(t){return this._push(je,It(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(gn,r.length(),r)}sint64Number(t){let r=St.fromNumber(t).zzEncode();return this._push(gn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(As,1,t?1:0)}fixed32(t){return this._push(Sr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=St.fromBigInt(t);return this._push(Sr,4,r.lo)._push(Sr,4,r.hi)}fixed64Number(t){let r=St.fromNumber(t);return this._push(Sr,4,r.lo)._push(Sr,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(ka,4,t)}double(t){return this._push(Ka,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(As,1,0):this.uint32(r)._push(yl,r,t)}string(t){let r=Fa(t);return r!==0?this.uint32(r)._push(xs,r,t):this._push(As,1,0)}fork(){return this.states=new _s(this),this.head=this.tail=new ve(Ss,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 ve(Ss,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=pl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function As(e,t,r){t[r]=e&255}function ml(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ts=class extends ve{next;constructor(t,r){super(ml,t,r),this.next=void 0}};function gn(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 Sr(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 yl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Ar.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(bl,t,e),this},Ar.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(gl,t,e),this});function bl(e,t,r){t.set(e,r)}function gl(e,t,r){e.length<40?xs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(V(e),r)}function Is(){return new Ar}function mt(e,t){let r=Is();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*yt(e,t,r){let n=vr(e);yield*t.stream(n,void 0,"$",r)}var wn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function xn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Rs(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return xn("enum",wn.VARINT,r,n,o)}function bt(e,t,r){return xn("message",wn.LENGTH_DELIMITED,e,t,r)}var Rt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},_r=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var Z;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(Z||(Z={}));var Bs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Bs||(Bs={}));(function(e){e.codec=()=>Rs(Bs)})(Z||(Z={}));var Mt;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Z.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Z.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Z.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(Mt||(Mt={}));var Cs;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Z.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Z.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Z.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(Cs||(Cs={}));var Ir={};wt(Ir,{MAX_RSA_KEY_SIZE:()=>Ds,generateRSAKeyPair:()=>Wa,jwkToJWKKeyPair:()=>ja,jwkToPkcs1:()=>vl,jwkToPkix:()=>Ps,jwkToRSAPrivateKey:()=>Fs,pkcs1MessageToJwk:()=>Os,pkcs1MessageToRSAPrivateKey:()=>Ks,pkcs1ToJwk:()=>El,pkcs1ToRSAPrivateKey:()=>$a,pkixMessageToJwk:()=>ks,pkixMessageToRSAPublicKey:()=>Us,pkixToJwk:()=>Sl,pkixToRSAPublicKey:()=>Ns});var Ze=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Ir.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return tt.createV1(114,this._multihash)}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return Ha(this.jwk,r,t,n)}},Tr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Ir.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}sign(t,r){return Va(this.jwk,t,r)}};var Ds=8192,Ls=18,wl=1062,xl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function El(e){let t=Ht(e);return Os(t)}function Os(e){return{n:q(e[1],"base64url"),e:q(e[2],"base64url"),d:q(e[3],"base64url"),p:q(e[4],"base64url"),q:q(e[5],"base64url"),dp:q(e[6],"base64url"),dq:q(e[7],"base64url"),qi:q(e[8],"base64url"),kty:"RSA"}}function vl(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 F("JWK was missing components");return re([Et(Uint8Array.from([0])),Et(V(e.n,"base64url")),Et(V(e.e,"base64url")),Et(V(e.d,"base64url")),Et(V(e.p,"base64url")),Et(V(e.q,"base64url")),Et(V(e.dp,"base64url")),Et(V(e.dq,"base64url")),Et(V(e.qi,"base64url"))]).subarray()}function Sl(e){let t=Ht(e,{offset:0});return ks(t)}function ks(e){let t=Ht(e[1],{offset:0});return{kty:"RSA",n:q(t[0],"base64url"),e:q(t[1],"base64url")}}function Ps(e){if(e.n==null||e.e==null)throw new F("JWK was missing components");return re([xl,Yr(re([Et(V(e.n,"base64url")),Et(V(e.e,"base64url"))]))]).subarray()}function $a(e){let t=Ht(e);return Ks(t)}function Ks(e){let t=Os(e);return Fs(t)}function Ns(e,t){if(e.byteLength>=wl)throw new Re("Key size is too large");let r=Ht(e,{offset:0});return Us(r,e,t)}function Us(e,t,r){let n=ks(e);if(r==null){let o=Ue(Mt.encode({Type:Z.RSA,Data:t}));r=Nt(Ls,o)}return new Ze(n,r)}function Fs(e){if(Ya(e)>Ds)throw new F("Key size is too large");let t=ja(e),r=Ue(Mt.encode({Type:Z.RSA,Data:Ps(t.publicKey)})),n=Nt(Ls,r);return new Tr(t.privateKey,new Ze(t.publicKey,n))}async function Wa(e){if(e>Ds)throw new F("Key size is too large");let t=await Za(e),r=Ue(Mt.encode({Type:Z.RSA,Data:Ps(t.publicKey)})),n=Nt(Ls,r);return new Tr(t.privateKey,new Ze(t.publicKey,n))}function ja(e){if(e==null)throw new F("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Za(e,t){let r=await Tt.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 Al(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Va(e,t,r){let n=await Tt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Tt.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 Ha(e,t,r,n){let o=await Tt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Tt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Al(e,t){if(e.privateKey==null||e.publicKey==null)throw new F("Private and public key are required");let r=await Promise.all([Tt.get().subtle.exportKey("jwk",e.privateKey),Tt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Ya(e){if(e.kty!=="RSA")throw new F("invalid key type");if(e.n==null)throw new F("invalid key modulus");return V(e.n,"base64url").length*8}var En=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Gr(t),vt(r,void 0,"key"),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 n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Wt(o)}update(t){return Ne(this),this.iHash.update(t),this}digestInto(t){Ne(this),Xr(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(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()}},Ga=(()=>{let e=((t,r,n)=>new En(t,r).update(n).digest());return e.create=(t,r)=>new En(t,r),e})();var Xa=(e,t)=>(e+(e>=0?t:-t)/Qa)/t;function _l(e,t,r){qe("scalar",e,qt,r);let[[n,o],[s,i]]=t,a=Xa(i*e,r),c=Xa(-o*e,r),u=e-a*n-c*s,f=-a*o-c*i,l=u<qt,d=f<qt;l&&(u=-u),d&&(f=-f);let h=br(Math.ceil(ze(r)/2))+de;if(u<qt||u>=h||f<qt||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function qs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ms(e,t){Ot(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Dt(r.lowS,"lowS"),Dt(r.prehash,"prehash"),r.format!==void 0&&qs(r.format),r}var zs=class extends Error{constructor(t=""){super(t)}},Pt={Err:zs,_tlv:{encode:(e,t)=>{let{Err:r}=Pt;if(Lt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=mr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?mr(o.length/2|128):"";return mr(e)+s+o+t},decode(e,t){let{Err:r}=Pt;t=M(t,void 0,"DER data");let n=0;if(e<0||e>255)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 u=t.subarray(n,n+c);if(u.length!==c)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+=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}=Pt;if(on(e),e<qt)throw new t("integer: negative integers are not allowed");let r=mr(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}=Pt;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return be(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Pt,o=M(e,void 0,"signature"),{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:u,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(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Pt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Pt._tlv);Object.freeze(Pt._int);Object.freeze(Pt);var qt=BigInt(0),de=BigInt(1),Qa=BigInt(2),vn=BigInt(3),Tl=BigInt(4);function Ja(e,t={}){let r=un("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Ot(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=ec(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(K,m,w){if(u&&m.is0())return Uint8Array.of(0);let{x:S,y:E}=m.toAffine(),x=n.toBytes(S);if(Dt(w,"isCompressed"),w){l();let _=!n.isOdd(E);return nt(tc(_),x)}else return nt(Uint8Array.of(4),x,n.toBytes(E))}function h(K){M(K,void 0,"Point");let{publicKey:m,publicKeyUncompressed:w}=f,S=K.length,E=K[0],x=K.subarray(1);if(u&&S===1&&E===0)return{x:n.ZERO,y:n.ZERO};if(S===m&&(E===2||E===3)){let _=n.fromBytes(x);if(!n.isValid(_))throw new Error("bad point: is not on curve, wrong x");let R=p(_),T;try{T=n.sqrt(R)}catch(U){let z=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}l();let C=n.isOdd(T);return(E&1)===1!==C&&(T=n.neg(T)),{x:_,y:T}}else if(S===w&&E===4){let _=n.BYTES,R=n.fromBytes(x.subarray(0,_)),T=n.fromBytes(x.subarray(_,_*2));if(!b(R,T))throw new Error("bad point: is not on curve");return{x:R,y:T}}else throw new Error(`bad point: got length ${S}, expected compressed=${m} or uncompressed=${w}`)}let y=t.toBytes===void 0?d:t.toBytes,g=t.fromBytes===void 0?h:t.fromBytes;function p(K){let m=n.sqr(K),w=n.mul(m,K);return n.add(n.add(w,n.mul(K,s.a)),s.b)}function b(K,m){let w=n.sqr(m),S=p(K);return n.eql(w,S)}if(!b(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,vn),Tl),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,A)))throw new Error("bad curve params: a or b");function D(K,m,w=!1){if(!n.isValid(m)||w&&n.is0(m))throw new Error(`bad point coordinate ${K}`);return m}function B(K){if(!(K instanceof I))throw new Error("Weierstrass Point expected")}function k(K){if(!c||!c.basises)throw new Error("no endo");return _l(K,c.basises,o.ORDER)}function L(K,m,w,S,E){return w=new I(n.mul(w.X,K),w.Y,w.Z),m=wr(S,m),w=wr(E,w),m.add(w)}class I{static BASE=new I(s.Gx,s.Gy,n.ONE);static ZERO=new I(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,w,S){this.X=D("x",m),this.Y=D("y",w,!0),this.Z=D("z",S),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){let{x:w,y:S}=m||{};if(!m||!n.isValid(w)||!n.isValid(S))throw new Error("invalid affine point");if(m instanceof I)throw new Error("projective point not allowed");return n.is0(w)&&n.is0(S)?I.ZERO:new I(w,S,n.ONE)}static fromBytes(m){let w=I.fromAffine(g(M(m,void 0,"point")));return w.assertValidity(),w}static fromHex(m){return I.fromBytes(Me(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,w=!0){return $.createCache(this,m),w||this.multiply(vn),this}assertValidity(){let m=this;if(m.is0()){if(t.allowInfinityPoint&&n.is0(m.X)&&n.eql(m.Y,n.ONE)&&n.is0(m.Z))return;throw new Error("bad point: ZERO")}let{x:w,y:S}=m.toAffine();if(!n.isValid(w)||!n.isValid(S))throw new Error("bad point: x or y not field elements");if(!b(w,S))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){B(m);let{X:w,Y:S,Z:E}=this,{X:x,Y:_,Z:R}=m,T=n.eql(n.mul(w,R),n.mul(x,E)),C=n.eql(n.mul(S,R),n.mul(_,E));return T&&C}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:w}=s,S=n.mul(w,vn),{X:E,Y:x,Z:_}=this,R=n.ZERO,T=n.ZERO,C=n.ZERO,O=n.mul(E,E),U=n.mul(x,x),z=n.mul(_,_),N=n.mul(E,x);return N=n.add(N,N),C=n.mul(E,_),C=n.add(C,C),R=n.mul(m,C),T=n.mul(S,z),T=n.add(R,T),R=n.sub(U,T),T=n.add(U,T),T=n.mul(R,T),R=n.mul(N,R),C=n.mul(S,C),z=n.mul(m,z),N=n.sub(O,z),N=n.mul(m,N),N=n.add(N,C),C=n.add(O,O),O=n.add(C,O),O=n.add(O,z),O=n.mul(O,N),T=n.add(T,O),z=n.mul(x,_),z=n.add(z,z),O=n.mul(z,N),R=n.sub(R,O),C=n.mul(z,U),C=n.add(C,C),C=n.add(C,C),new I(R,T,C)}add(m){B(m);let{X:w,Y:S,Z:E}=this,{X:x,Y:_,Z:R}=m,T=n.ZERO,C=n.ZERO,O=n.ZERO,U=s.a,z=n.mul(s.b,vn),N=n.mul(w,x),rt=n.mul(S,_),ot=n.mul(E,R),st=n.add(w,S),Q=n.add(x,_);st=n.mul(st,Q),Q=n.add(N,rt),st=n.sub(st,Q),Q=n.add(w,E);let gt=n.add(x,R);return Q=n.mul(Q,gt),gt=n.add(N,ot),Q=n.sub(Q,gt),gt=n.add(S,E),T=n.add(_,R),gt=n.mul(gt,T),T=n.add(rt,ot),gt=n.sub(gt,T),O=n.mul(U,Q),T=n.mul(z,ot),O=n.add(T,O),T=n.sub(rt,O),O=n.add(rt,O),C=n.mul(T,O),rt=n.add(N,N),rt=n.add(rt,N),ot=n.mul(U,ot),Q=n.mul(z,Q),rt=n.add(rt,ot),ot=n.sub(N,ot),ot=n.mul(U,ot),Q=n.add(Q,ot),N=n.mul(rt,Q),C=n.add(C,N),N=n.mul(gt,Q),T=n.mul(st,T),T=n.sub(T,N),N=n.mul(st,rt),O=n.mul(gt,O),O=n.add(O,N),new I(T,C,O)}subtract(m){return B(m),this.add(m.negate())}is0(){return this.equals(I.ZERO)}multiply(m){let{endo:w}=t;if(!o.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let S,E,x=_=>$.cached(this,_,R=>xe(I,R));if(w){let{k1neg:_,k1:R,k2neg:T,k2:C}=k(m),{p:O,f:U}=x(R),{p:z,f:N}=x(C);E=U.add(N),S=L(w.beta,O,z,_,T)}else{let{p:_,f:R}=x(m);S=_,E=R}return xe(I,[S,E])[0]}multiplyUnsafe(m){let{endo:w}=t,S=this,E=m;if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(E===qt||S.is0())return I.ZERO;if(E===de)return S;if($.hasCache(this))return this.multiply(E);if(w){let{k1neg:x,k1:_,k2neg:R,k2:T}=k(E),{p1:C,p2:O}=Ea(I,S,_,T);return L(w.beta,C,O,x,R)}else return $.unsafe(S,E)}toAffine(m){let w=this,S=m,{X:E,Y:x,Z:_}=w;if(n.eql(_,n.ONE))return{x:E,y:x};let R=w.is0();S==null&&(S=R?n.ONE:n.inv(_));let T=n.mul(E,S),C=n.mul(x,S),O=n.mul(_,S);if(R)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:T,y:C}}isTorsionFree(){let{isTorsionFree:m}=t;return i===de?!0:m?m(I,this):$.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return i===de?this:m?m(I,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===de?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return Dt(m,"isCompressed"),this.assertValidity(),y(I,this,m)}toHex(m=!0){return Fe(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=o.BITS,$=new $e(I,t.endo?Math.ceil(P/2):P);return P>=8&&I.BASE.precompute(8),Object.freeze(I.prototype),Object.freeze(I),I}function tc(e){return Uint8Array.of(e?2:3)}function ec(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Il(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?pr:t.randomBytes,o=Object.assign(ec(e.Fp,r),{seed:Math.max(Xo(r.ORDER),16)});function s(h){try{let y=r.fromBytes(h);return r.isValidNot0(y)}catch{return!1}}function i(h,y){let{publicKey:g,publicKeyUncompressed:p}=o;try{let b=h.length;return y===!0&&b!==g||y===!1&&b!==p?!1:!!e.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,Qo(M(h,o.seed,"seed"),r.ORDER)}function c(h,y=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(y)}function u(h){let{secretKey:y,publicKey:g,publicKeyUncompressed:p}=o,b=r._lengths;if(!ye(h))return;let v=M(h,void 0,"key").length,A=v===g||v===p,D=v===y||!!b?.includes(v);if(!(A&&D))return A}function f(h,y,g=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(y)===!1)throw new Error("second arg must be public key");let p=r.fromBytes(h);return e.fromBytes(y).multiply(p).toBytes(g)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=fn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:e,utils:l,lengths:o})}function rc(e,t,r={}){let n=t;Gr(n),Ot(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?pr:r.randomBytes,s=r.hmac===void 0?(E,x)=>Ga(n,E,x):r.hmac,{Fp:i,Fn:a}=e,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:d,utils:h,lengths:y}=Il(e,r),g={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},p=c*Qa+de<i.ORDER;function b(E){let x=c>>de;return E>x}function v(E,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return x}function A(){if(p)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function D(E,x){qs(x);let _=y.signature,R=x==="compact"?_:x==="recovered"?_+1:void 0;return M(E,R)}class B{r;s;recovery;constructor(x,_,R){if(this.r=v("r",x),this.s=v("s",_),R!=null){if(A(),![0,1,2,3].includes(R))throw new Error("invalid recovery id");this.recovery=R}Object.freeze(this)}static fromBytes(x,_=g.format){D(x,_);let R;if(_==="der"){let{r:U,s:z}=Pt.toSig(M(x));return new B(U,z)}_==="recovered"&&(R=x[0],_="compact",x=x.subarray(1));let T=y.signature/2,C=x.subarray(0,T),O=x.subarray(T,T*2);return new B(a.fromBytes(C),a.fromBytes(O),R)}static fromHex(x,_){return this.fromBytes(Me(x),_)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new B(this.r,this.s,x)}recoverPublicKey(x){let{r:_,s:R}=this,T=this.assertRecovery(),C=T===2||T===3?_+c:_;if(!i.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let O=i.toBytes(C),U=e.fromBytes(nt(tc((T&1)===0),O)),z=a.inv(C),N=L(M(x,void 0,"msgHash")),rt=a.create(-N*z),ot=a.create(R*z),st=e.BASE.multiplyUnsafe(rt).add(U.multiplyUnsafe(ot));if(st.is0())throw new Error("invalid recovery: point at infinify");return st.assertValidity(),st}hasHighS(){return b(this.s)}toBytes(x=g.format){if(qs(x),x==="der")return Me(Pt.hexFromSig(this));let{r:_,s:R}=this,T=a.toBytes(_),C=a.toBytes(R);return x==="recovered"?(A(),nt(Uint8Array.of(this.assertRecovery()),T,C)):nt(T,C)}toHex(x){return Fe(this.toBytes(x))}}Object.freeze(B.prototype),Object.freeze(B);let k=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let _=be(x),R=x.length*8-u;return R>0?_>>BigInt(R):_}:r.bits2int,L=r.bits2int_modN===void 0?function(x){return a.create(k(x))}:r.bits2int_modN,I=br(u);function P(E){return qe("num < 2^"+u,E,qt,I),a.toBytes(E)}function $(E,x){return M(E,void 0,"message"),x?M(n(E),void 0,"prehashed message"):E}function K(E,x,_){let{lowS:R,prehash:T,extraEntropy:C}=Ms(_,g);E=$(E,T);let O=L(E),U=a.fromBytes(x);if(!a.isValidNot0(U))throw new Error("invalid private key");let z=[P(U),P(O)];if(C!=null&&C!==!1){let st=C===!0?o(y.secretKey):C;z.push(M(st,void 0,"extraEntropy"))}let N=nt(...z),rt=O;function ot(st){let Q=k(st);if(!a.isValidNot0(Q))return;let gt=a.inv(Q),Ie=e.BASE.multiply(Q).toAffine(),tr=a.create(Ie.x);if(tr===qt)return;let zr=a.create(gt*a.create(rt+tr*U));if(zr===qt)return;let hi=(Ie.x===tr?0:2)|Number(Ie.y&de),pi=zr;return R&&b(zr)&&(pi=a.neg(zr),hi^=1),new B(tr,pi,p?void 0:hi)}return{seed:N,k2sig:ot}}function m(E,x,_={}){let{seed:R,k2sig:T}=K(E,x,_);return oa(n.outputLen,a.BYTES,s)(R,T).toBytes(_.format)}function w(E,x,_,R={}){let{lowS:T,prehash:C,format:O}=Ms(R,g);if(_=M(_,void 0,"publicKey"),x=$(x,C),!ye(E)){let U=E instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}D(E,O);try{let U=B.fromBytes(E,O),z=e.fromBytes(_);if(T&&U.hasHighS())return!1;let{r:N,s:rt}=U,ot=L(x),st=a.inv(rt),Q=a.create(ot*st),gt=a.create(N*st),Ie=e.BASE.multiplyUnsafe(Q).add(z.multiplyUnsafe(gt));return Ie.is0()?!1:a.create(Ie.x)===N}catch{return!1}}function S(E,x,_={}){let{prehash:R}=Ms(_,g);return x=$(x,R),B.fromBytes(E,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:d,utils:h,lengths:y,Point:e,sign:m,verify:w,recoverPublicKey:S,Signature:B,hash:n})}var Hs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Rl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var nc=BigInt(2);function Bl(e){let t=Hs.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=j(f,r,t)*f%t,d=j(l,r,t)*f%t,h=j(d,nc,t)*u%t,y=j(h,o,t)*h%t,g=j(y,s,t)*y%t,p=j(g,a,t)*g%t,b=j(p,c,t)*p%t,v=j(b,a,t)*g%t,A=j(v,r,t)*f%t,D=j(A,i,t)*y%t,B=j(D,n,t)*u%t,k=j(B,nc,t);if(!Vs.eql(Vs.sqr(k),e))throw new Error("Cannot find square root");return k}var Vs=Ve(Hs.p,{sqrt:Bl}),Cl=Ja(Hs,{Fp:Vs,endo:Rl}),Ye=rc(Cl,Ue);function oc(e,t,r,n){let o=ir.digest(r instanceof Uint8Array?r:r.subarray());if(pn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ye.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Er(String(s))});try{return n?.signal?.throwIfAborted(),Ye.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Er(String(s))}}var Sn=class{type="secp256k1";raw;_key;constructor(t){this._key=ic(t),this.raw=sc(this._key)}toMultihash(){return Bt.digest(_t(this))}toCID(){return tt.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return oc(this._key,r,t,n)}};function $s(e){return new Sn(e)}function sc(e){return Ye.Point.fromBytes(e).toBytes()}function ic(e){try{return Ye.Point.fromBytes(e),e}catch(t){throw new Re(String(t))}}function An(e,t){let{Type:r,Data:n}=Mt.decode(e),o=n??new Uint8Array;switch(r){case Z.RSA:return Ns(o,t);case Z.Ed25519:return ls(o);case Z.secp256k1:return $s(o);case Z.ECDSA:return ko(o);default:throw new he}}function ac(e){let{Type:t,Data:r}=Mt.decode(e.digest),n=r??new Uint8Array;switch(t){case Z.Ed25519:return ls(n);case Z.secp256k1:return $s(n);case Z.ECDSA:return ko(n);default:throw new he}}function _t(e){return Mt.encode({Type:Z[e.type],Data:e.raw})}var cc=Symbol.for("nodejs.util.inspect.custom"),Dl=114,Rr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[$r]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return tt.createV1(Dl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return W(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return W(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[cc](){return`PeerId(${this.toString()})`}},Br=class extends Rr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Cr=class extends Rr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Dr=class extends Rr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ll=2336,Lr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Bt.digest(V(this.url))}[cc](){return`PeerId(${this.url})`}[$r]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return tt.createV1(Ll,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=q(t)),t.toString()===this.toString())}};var Ol=114,uc=2336;function fc(e){if(e.type==="Ed25519")return new Cr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Dr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Br({multihash:e.toCID().multihash,publicKey:e});throw new he}function Ws(e){if(Pl(e))return new Br({multihash:e});if(kl(e))try{let t=ac(e);if(t.type==="Ed25519")return new Cr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Dr({multihash:e,publicKey:t})}catch{let r=q(e.digest);return new Lr(new URL(r))}throw new Hr("Supplied PeerID Multihash is invalid")}function _n(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Ol&&e.code!==uc)throw new Vr("Supplied PeerID CID is invalid");if(e.code===uc){let t=q(e.multihash.digest);return new Lr(new URL(t))}return Ws(e.multihash)}function kl(e){return e.code===Bt.code}function Pl(e){return e.code===ir.code}var Or;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:et(0),payloadType:et(0),payload:et(0),signature:et(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(Or||(Or={}));var Tn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Ge=class e{static createFromProtobuf=t=>{let r=Or.decode(t),n=An(r.publicKey);return new e({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(t,r,n)=>{if(r==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=lc(o,s,i),c=await r.sign(a.subarray(),n);return new e({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,r,n)=>{let o=e.createFromProtobuf(t);if(!await o.validate(r,n))throw new Tn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:r,payloadType:n,payload:o,signature:s}=t;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Or.encode({publicKey:_t(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:W(this.marshal(),t.marshal())}async validate(t,r){let n=lc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},lc=(e,t,r)=>{let n=V(e),o=yn(n.byteLength),s=yn(t.length),i=yn(r.length);return new ht(o,n,s,t,i,r)};var ft=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Gt=class extends Error{static name="ValidationError";name="ValidationError"},In=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Rn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Bn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(f===void 0)break;if(s*=t,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Kl=45,Nl=15,Cn=new Bn;function dc(e){if(!(e.length>Nl))return Cn.new(e).parseWith(()=>Cn.readIPv4Addr())}function hc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Kl))return Cn.new(e).parseWith(()=>Cn.readIPv6Addr())}function Dn(e){return!!dc(e)}function pc(e){return!!hc(e)}function Zs(e){return t=>q(t,e)}function Ys(e){return t=>V(t,e)}function Xe(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Se(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function mc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=V(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Se(n);return Vt([r,o],r.length+o.length)}function yc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=Kt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Se(n);return Vt([r,o],r.length+o.length)}function Gs(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=q(t,"base32"),o=Xe(r);return`${n}:${o}`}var Xs=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new ft("Invalid byte value in IP address");t[n]=o}),t},bc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=Dn(r[n]),i;s&&(i=Xs(r[n]),r[n]=q(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,q(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new ft("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},gc=function(e){if(e.byteLength!==4)throw new ft("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},wc=function(e){if(e.byteLength!==16)throw new ft("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${r}"`)}};function xc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${e}"`)}}var js=Object.values(ar).map(e=>e.decoder),Ul=(function(){let e=js[0].or(js[1]);return js.slice(2).forEach(t=>e=e.or(t)),e})();function Ec(e){return Ul.decode(e)}function vc(e){return t=>e.encoder.encode(t)}function Fl(e){if(parseInt(e).toString()!==e)throw new Gt("Value must be an integer")}function Ml(e){if(e<0)throw new Gt("Value must be a positive integer, or zero")}function ql(e){return t=>{if(t>e)throw new Gt(`Value must be smaller than or equal to ${e}`)}}function zl(...e){return t=>{for(let r of e)r(t)}}var kr=zl(Fl,Ml,ql(65535));var at=-1,Qs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Rn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Xt=new Qs,Rd=[{code:4,name:"ip4",size:32,valueToBytes:Xs,bytesToValue:gc,validate:e=>{if(!Dn(e))throw new Gt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Se,bytesToValue:Xe,validate:kr},{code:273,name:"udp",size:16,valueToBytes:Se,bytesToValue:Xe,validate:kr},{code:33,name:"dccp",size:16,valueToBytes:Se,bytesToValue:Xe,validate:kr},{code:41,name:"ip6",size:128,valueToBytes:bc,bytesToValue:wc,stringToValue:xc,validate:e=>{if(!pc(e))throw new Gt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:at},{code:43,name:"ipcidr",size:8,bytesToValue:Zs("base10"),valueToBytes:Ys("base10")},{code:53,name:"dns",size:at},{code:54,name:"dns4",size:at},{code:55,name:"dns6",size:at},{code:56,name:"dnsaddr",size:at},{code:132,name:"sctp",size:16,valueToBytes:Se,bytesToValue:Xe,validate:kr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:at,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:at,bytesToValue:Zs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Ys("base58btc")(e):tt.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Gs,valueToBytes:mc},{code:445,name:"onion3",size:296,bytesToValue:Gs,valueToBytes:yc},{code:446,name:"garlic64",size:at},{code:447,name:"garlic32",size:at},{code:448,name:"tls"},{code:449,name:"sni",size:at},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:at,bytesToValue:vc(Eo),valueToBytes:Ec},{code:480,name:"http"},{code:481,name:"http-path",size:at,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:at}];Rd.forEach(e=>{Xt.addProtocol(e)});function Sc(e){let t=[],r=0;for(;r<e.length;){let n=bs(e,r),o=Xt.getProtocol(n),s=It(n),i=Bd(o,e,r+s),a=0;i>0&&o.size===at&&(a=It(i));let c=s+a+i,u={code:n,name:o.name,bytes:e.subarray(r,r+c)};if(i>0){let f=r+s+a,l=e.subarray(f,f+i);u.value=o.bytesToValue?.(l)??q(l)}t.push(u),r+=c}return t}function Ac(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Xt.getProtocol(n.code),s=It(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===at&&(c=It(a)));let u=new Uint8Array(s+c+a),f=0;je(n.code,u,f),f+=s,i!=null&&(o.size===at&&(je(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Vt(r,t)}function _c(e){if(e.charAt(0)!=="/")throw new ft('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=Xt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ft(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ft(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ft("Incomplete multiaddr");return t}function Tc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Xt.getProtocol(t.code);if(r==null)throw new ft(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Bd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:bs(t,r)}var Cd=Symbol.for("nodejs.util.inspect.custom"),ti=Symbol.for("@multiformats/multiaddr");function Dd(e){if(e==null&&(e="/"),On(e))return e.getComponents();if(e instanceof Uint8Array)return Sc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),_c(e);if(Array.isArray(e))return e;throw new ft("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Ln=class e{[ti]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Dd(t),r.validate!==!1&&Ld(this)}get bytes(){return this.#r==null&&(this.#r=Ac(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Tc(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new In(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return W(this.bytes,t.bytes)}[Cd](){return`Multiaddr(${this.toString()})`}};function Ld(e){e.getComponents().forEach(t=>{let r=Xt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function On(e){return!!e?.[ti]}function Ae(e){return new Ln(e)}var Ic="libp2p-peer-record",Rc=Uint8Array.from([3,1]);var Pr;(function(e){let t;(function(i){let a;i.codec=()=>(a==null&&(a=bt((l,d,h={})=>{h.lengthDelimited!==!1&&d.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(d.uint32(10),d.bytes(l.multiaddr)),h.lengthDelimited!==!1&&d.ldelim()},(l,d,h={})=>{let y={multiaddr:et(0)},g=d==null?l.len:l.pos+d;for(;l.pos<g;){let p=l.uint32();p>>>3===1?y.multiaddr=l.bytes():l.skipType(p&7)}return y},function*(l,d,h,y={}){let g=d==null?l.len:l.pos+d;for(;l.pos<g;){let p=l.uint32();p>>>3===1?yield{field:`${h}.multiaddr`,value:l.bytes()}:l.skipType(p&7)}})),a);function c(l){return mt(l,i.codec())}i.encode=c;function u(l,d){return pt(l,i.codec(),d)}i.decode=u;function f(l,d){return yt(l,i.codec(),d)}i.stream=f})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=bt((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let u of i.addresses)a.uint32(26),e.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:et(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Rt('Decode error - repeated field "addresses" had too many elements');u.addresses.push(e.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Rt('Streaming decode error - repeated field "addresses" had too many elements');for(let h of e.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...h,index:f.addresses};f.addresses++;break}default:{i.skipType(d&7);break}}}})),r);function n(i){return mt(i,e.codec())}e.encode=n;function o(i,a){return pt(i,e.codec(),a)}e.decode=o;function s(i,a){return yt(i,e.codec(),a)}e.stream=s})(Pr||(Pr={}));function Bc(e,t){let r=(n,o)=>n.toString().localeCompare(o.toString());return e.length!==t.length?!1:(t.sort(r),e.sort(r).every((n,o)=>t[o].equals(n)))}var _e=class e{static createFromProtobuf=t=>{let r=Pr.decode(t),n=Ws(Pe(r.peerId)),o=(r.addresses??[]).map(i=>Ae(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Ic;static CODEC=Rc;peerId;multiaddrs;seqNumber;domain=e.DOMAIN;codec=e.CODEC;marshaled;constructor(t){let{peerId:r,multiaddrs:n,seqNumber:o}=t;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Pr.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof e)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!Bc(this.multiaddrs,t.multiaddrs))}};function Od(e){return e[Symbol.asyncIterator]!=null}function kd(e){if(Od(e))return(async()=>{let r=[];for await(let n of e)r.push(n);return r})();let t=[];for(let r of e)t.push(r);return t}var Cc=kd;function kn(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}var Kr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[r,n]of t.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return kn(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((r,n)=>{t(r.value,r.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,r){this.map.set(t.toString(),{key:t,value:r})}keys(){return kn(this.map.values(),t=>t.key)}values(){return kn(this.map.values(),t=>t.value)}get size(){return this.map.size}};function Pn(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Kn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Qe=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Kn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new Kn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var ei=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Dc(e={}){return Pd(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function Pd(e,t){t=t??{};let r=t.onEnd,n=new Qe,o,s,i,a=Pn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,b)=>{s=v=>{s=null,n.push(v);try{p(e(n))}catch(A){b(A)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Pn()})}},u=p=>s!=null?s(p):(n.push(p),o),f=p=>(n=new Qe,s!=null?s({error:p}):(n.push({error:p}),o)),l=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:p})},d=p=>i?o:(i=!0,p!=null?f(p):u({done:!0})),h=()=>(n=new Qe,d(),{done:!0}),y=p=>(d(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:y,push:l,end:d,get readableLength(){return n.size},onEmpty:async p=>{let b=p?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let v,A;b!=null&&(v=new Promise((D,B)=>{A=()=>{B(new ei)},b.addEventListener("abort",A)}));try{await Promise.race([a.promise,v])}finally{A!=null&&b!=null&&b?.removeEventListener("abort",A)}}},r==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(p){return g.throw(p),r!=null&&(r(p),r=void 0),{done:!0}},return(){return g.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(p){return g.end(p),r!=null&&(r(p),r=void 0),o},get readableLength(){return g.readableLength},onEmpty:p=>g.onEmpty(p)},o}function Kd(e){return e.reason}async function Lc(e,t,r){if(t==null)return e;let n=r?.translateError??Kd;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var ri=class extends Kr{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(t,r){return super.set(t,r),this.updateComponentMetric(),this}delete(t){let r=super.delete(t);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ni(e){let{name:t,metrics:r}=e,n;return r!=null?n=new ri({name:t,metrics:r}):n=new Kr,n}var At=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...r){super(t,...r)}};async function Nn(e,t,r,n){let o=new At(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let s=n?.errorEvent??"error";return r?.aborted===!0?Promise.reject(o):new Promise((i,a)=>{function c(){si(r,"abort",l),si(e,t,u),si(e,s,f)}let u=d=>{try{if(n?.filter?.(d)===!1)return}catch(h){c(),a(h);return}c(),i(d)},f=d=>{if(c(),d instanceof Error){a(d);return}a(d.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},l=()=>{c(),a(o)};oi(r,"abort",l),oi(e,t,u),oi(e,s,f)})}function oi(e,t,r){e!=null&&(Oc(e)?e.addEventListener(t,r):e.addListener(t,r))}function si(e,t,r){e!=null&&(Oc(e)?e.removeEventListener(t,r):e.removeListener(t,r))}function Oc(e){return typeof e.addEventListener=="function"&&typeof e.removeEventListener=="function"}var Un=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var Fn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new At)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Nd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Mn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,r){this.id=Nd(),this.status="queued",this.fn=t,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new At),this.cleanup())}async join(t={}){let r=new Fn(t.signal);return this.recipients.push(r),t.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Lc(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};function ii(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Nr=class extends Ce{concurrency;maxSize;queue;pending;sort;autoStart;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=t.autoStart??!0,this.sort=t.sort,this.queue=[],this.emitEmpty=ii(this.emitEmpty.bind(this),1),this.emitIdle=ii(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(t,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Un;let n=new Mn(t,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new At)}),this.clear()}async onEmpty(t){this.size!==0&&await Nn(this,"empty",t?.signal)}async onSizeLessThan(t,r){this.size<t||await Nn(this,"next",r?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Nn(this,"idle",t?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let r=Dc({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail.result)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new At("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var qn="lock:worker:request-read",zn="lock:worker:abort-read-request",Vn="lock:worker:release-read",Hn="lock:master:grant-read",$n="lock:master:error-read",Wn="lock:worker:request-write",jn="lock:worker:abort-write-request",Zn="lock:worker:release-write",Yn="lock:master:grant-write",Gn="lock:master:error-write",Xn="lock:worker:finalize",Qn="mortice",kc={singleProcess:!1};var ai=(e,t,r,n,o,s,i,a,c)=>u=>{if(u.data==null)return;let f={type:u.data.type,name:u.data.name,identifier:u.data.identifier};f.type===o&&e.safeDispatchEvent(r,{detail:{name:f.name,identifier:f.identifier,handler:async()=>{t.postMessage({type:c,name:f.name,identifier:f.identifier}),await new Promise(l=>{let d=h=>{if(h?.data==null)return;let y={type:h.data.type,name:h.data.name,identifier:h.data.identifier};y.type===a&&y.identifier===f.identifier&&(t.removeEventListener("message",d),l())};t.addEventListener("message",d)})},onError:l=>{t.postMessage({type:i,name:f.name,identifier:f.identifier,error:{message:l.message,name:l.name,stack:l.stack}})}}}),f.type===s&&e.safeDispatchEvent(n,{detail:{name:f.name,identifier:f.identifier}}),f.type===Xn&&e.safeDispatchEvent("finalizeRequest",{detail:{name:f.name}})};var Pc=(e=10)=>Math.random().toString().substring(2,e+2);var Jn=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(Qn)}readLock(t){return this.sendRequest(qn,zn,Hn,$n,Vn,t)}writeLock(t){return this.sendRequest(Wn,jn,Yn,Gn,Zn,t)}finalize(){this.channel.postMessage({type:Xn,name:this.name}),this.channel.close()}async sendRequest(t,r,n,o,s,i){i?.signal?.throwIfAborted();let a=Pc();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,u)=>{let f=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",f,{once:!0});let l=d=>{if(d.data?.identifier===a&&(d.data?.type===n&&(this.channel.removeEventListener("message",l),i?.signal?.removeEventListener("abort",f),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),d.data.type===o)){this.channel.removeEventListener("message",l),i?.signal?.removeEventListener("abort",f);let h=new Error;d.data.error!=null&&(h.message=d.data.error.message,h.name=d.data.error.name,h.stack=d.data.error.stack),u(h)}};this.channel.addEventListener("message",l)})}};var Kc=e=>{if(e=Object.assign({},kc,e),!!globalThis.document||e.singleProcess){let r=new BroadcastChannel(Qn),n=new Ce;return r.addEventListener("message",ai(n,r,"requestReadLock","abortReadLockRequest",qn,zn,$n,Vn,Hn)),r.addEventListener("message",ai(n,r,"requestWriteLock","abortWriteLockRequest",Wn,jn,Gn,Zn,Yn)),n}return new Jn(e.name)};var Te=new Map,Ur;function Nc(e){return typeof e?.readLock=="function"&&typeof e?.writeLock=="function"}function Ud(e){if(Ur==null&&(Ur=Kc(e),!Nc(Ur))){let t=Ur;t.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Te.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};t.addEventListener("abortReadLockRequest",a),s.readLock({signal:i.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{t.removeEventListener("abortReadLockRequest",a)})}),t.addEventListener("requestWriteLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Te.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};t.addEventListener("abortWriteLockRequest",a),s.writeLock({signal:i.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{t.removeEventListener("abortWriteLockRequest",a)})}),t.addEventListener("finalizeRequest",r=>{let n=r.detail.name,o=Te.get(n);o?.finalize()})}return Ur}async function ci(e,t){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new At)};return t?.signal?.addEventListener("abort",s,{once:!0}),e.add(async()=>{await new Promise(i=>{r(()=>{t?.signal?.removeEventListener("abort",s),i()})})},{signal:t?.signal}).catch(i=>{n(i)}),o}var Uc=(e,t)=>{let r=Te.get(e);if(r!=null)return r;let n=Ud(t);if(Nc(n))return r=n,Te.set(e,r),r;let o=new Nr({concurrency:1}),s;return r={async readLock(i){if(s!=null)return ci(s,i);s=new Nr({concurrency:t.concurrency,autoStart:!1});let a=s,c=ci(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,ci(o,i)},finalize:()=>{Te.delete(e)},queue:o},Te.set(e,r),t.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var Fd={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function ui(e){let t=Object.assign({},Fd,e);return Uc(t.name,t)}var Qt;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=bt((d,h,y={})=>{y.lengthDelimited!==!1&&h.fork(),d.key!=null&&d.key!==""&&(h.uint32(10),h.string(d.key)),d.value!=null&&d.value.byteLength>0&&(h.uint32(18),h.bytes(d.value)),y.lengthDelimited!==!1&&h.ldelim()},(d,h,y={})=>{let g={key:"",value:et(0)},p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{g.key=d.string();break}case 2:{g.value=d.bytes();break}default:{d.skipType(b&7);break}}}return g},function*(d,h,y,g={}){let p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{yield{field:`${y}.key`,value:d.string()};break}case 2:{yield{field:`${y}.value`,value:d.bytes()};break}default:{d.skipType(b&7);break}}}})),c);function u(d){return mt(d,a.codec())}a.encode=u;function f(d,h){return pt(d,a.codec(),h)}a.decode=f;function l(d,h){return yt(d,a.codec(),h)}a.stream=l})(t=e.Peer$metadataEntry||(e.Peer$metadataEntry={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=bt((d,h,y={})=>{y.lengthDelimited!==!1&&h.fork(),d.key!=null&&d.key!==""&&(h.uint32(10),h.string(d.key)),d.value!=null&&(h.uint32(18),Mr.codec().encode(d.value,h)),y.lengthDelimited!==!1&&h.ldelim()},(d,h,y={})=>{let g={key:""},p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{g.key=d.string();break}case 2:{g.value=Mr.codec().decode(d,d.uint32(),{limits:y.limits?.value});break}default:{d.skipType(b&7);break}}}return g},function*(d,h,y,g={}){let p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{yield{field:`${y}.key`,value:d.string()};break}case 2:{yield*Mr.codec().stream(d,d.uint32(),`${y}.value`,{limits:g.limits?.value});break}default:{d.skipType(b&7);break}}}})),c);function u(d){return mt(d,a.codec())}a.encode=u;function f(d,h){return pt(d,a.codec(),h)}a.decode=f;function l(d,h){return yt(d,a.codec(),h)}a.stream=l})(r=e.Peer$tagsEntry||(e.Peer$tagsEntry={}));let n;e.codec=()=>(n==null&&(n=bt((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.addresses!=null&&a.addresses.length>0)for(let f of a.addresses)c.uint32(10),Fr.codec().encode(f,c);if(a.protocols!=null&&a.protocols.length>0)for(let f of a.protocols)c.uint32(18),c.string(f);if(a.publicKey!=null&&(c.uint32(34),c.bytes(a.publicKey)),a.peerRecordEnvelope!=null&&(c.uint32(42),c.bytes(a.peerRecordEnvelope)),a.metadata!=null&&a.metadata.size>0)for(let[f,l]of a.metadata.entries())c.uint32(50),e.Peer$metadataEntry.codec().encode({key:f,value:l},c);if(a.tags!=null&&a.tags.size>0)for(let[f,l]of a.tags.entries())c.uint32(58),e.Peer$tagsEntry.codec().encode({key:f,value:l},c);a.updated!=null&&(c.uint32(64),c.uint64Number(a.updated)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={addresses:[],protocols:[],metadata:new Map,tags:new Map},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{if(u.limits?.addresses!=null&&f.addresses.length===u.limits.addresses)throw new Rt('Decode error - repeated field "addresses" had too many elements');f.addresses.push(Fr.codec().decode(a,a.uint32(),{limits:u.limits?.addresses$}));break}case 2:{if(u.limits?.protocols!=null&&f.protocols.length===u.limits.protocols)throw new Rt('Decode error - repeated field "protocols" had too many elements');f.protocols.push(a.string());break}case 4:{f.publicKey=a.bytes();break}case 5:{f.peerRecordEnvelope=a.bytes();break}case 6:{if(u.limits?.metadata!=null&&f.metadata.size===u.limits.metadata)throw new _r('Decode error - map field "metadata" had too many elements');let h=e.Peer$metadataEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.metadata$value}});f.metadata.set(h.key,h.value);break}case 7:{if(u.limits?.tags!=null&&f.tags.size===u.limits.tags)throw new _r('Decode error - map field "tags" had too many elements');let h=e.Peer$tagsEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.tags$value}});f.tags.set(h.key,h.value);break}case 8:{f.updated=a.uint64Number();break}default:{a.skipType(d&7);break}}}return f},function*(a,c,u,f={}){let l={addresses:0,protocols:0,metadata:0,tags:0},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let h=a.uint32();switch(h>>>3){case 1:{if(f.limits?.addresses!=null&&l.addresses===f.limits.addresses)throw new Rt('Streaming decode error - repeated field "addresses" had too many elements');for(let y of Fr.codec().stream(a,a.uint32(),`${u}.addresses[]`,{limits:f.limits?.addresses$}))yield{...y,index:l.addresses};l.addresses++;break}case 2:{if(f.limits?.protocols!=null&&l.protocols===f.limits.protocols)throw new Rt('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${u}.protocols[]`,index:l.protocols,value:a.string()},l.protocols++;break}case 4:{yield{field:`${u}.publicKey`,value:a.bytes()};break}case 5:{yield{field:`${u}.peerRecordEnvelope`,value:a.bytes()};break}case 6:{if(f.limits?.metadata!=null&&l.metadata===f.limits.metadata)throw new Rt('Decode error - map field "metadata" had too many elements');yield*e.Peer$metadataEntry.codec().stream(a,a.uint32(),`${u}.metadata{}`,{limits:{value:f.limits?.metadata$value}}),l.metadata++;break}case 7:{if(f.limits?.tags!=null&&l.tags===f.limits.tags)throw new Rt('Decode error - map field "tags" had too many elements');yield*e.Peer$tagsEntry.codec().stream(a,a.uint32(),`${u}.tags{}`,{limits:{value:f.limits?.tags$value}}),l.tags++;break}case 8:{yield{field:`${u}.updated`,value:a.uint64Number()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return mt(a,e.codec())}e.encode=o;function s(a,c){return pt(a,e.codec(),c)}e.decode=s;function i(a,c){return yt(a,e.codec(),c)}e.stream=i})(Qt||(Qt={}));var Fr;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),s.isCertified!=null&&(i.uint32(16),i.bool(s.isCertified)),s.observed!=null&&(i.uint32(24),i.uint64Number(s.observed)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:et(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.multiaddr=s.bytes();break}case 2:{c.isCertified=s.bool();break}case 3:{c.observed=s.uint64Number();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.multiaddr`,value:s.bytes()};break}case 2:{yield{field:`${a}.isCertified`,value:s.bool()};break}case 3:{yield{field:`${a}.observed`,value:s.uint64Number()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(Fr||(Fr={}));var Mr;(function(e){let t;e.codec=()=>(t==null&&(t=bt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.value!=null&&s.value!==0&&(i.uint32(8),i.uint32(s.value)),s.expiry!=null&&(i.uint32(16),i.uint64(s.expiry)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={value:0},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.value=s.uint32();break}case 2:{c.expiry=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.value`,value:s.uint32()};break}case 2:{yield{field:`${a}.expiry`,value:s.uint64()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return mt(s,e.codec())}e.encode=r;function n(s,i){return pt(s,e.codec(),i)}e.decode=n;function o(s,i){return yt(s,e.codec(),i)}e.stream=o})(Mr||(Mr={}));function Md(e,t){if(e.publicKey!=null||t.publicKey==null)return e;let r;e.type==="RSA"&&(r=e.toMultihash());let n=An(t.publicKey,r);return fc(n)}function Fc(e,t,r){let n=Qt.decode(t);return Je(e,n,r)}function Je(e,t,r){let n=new Map,o=BigInt(Date.now());for(let[s,i]of t.tags.entries())i.expiry!=null&&i.expiry<o||n.set(s,i);return{...t,id:Md(e,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-r).map(({multiaddr:s,isCertified:i})=>({multiaddr:Ae(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function Mc(e,t){return qd(e.addresses,t.addresses)&&zd(e.protocols,t.protocols)&&Vd(e.publicKey,t.publicKey)&&Hd(e.peerRecordEnvelope,t.peerRecordEnvelope)&&$d(e.metadata,t.metadata)&&Wd(e.tags,t.tags)}function qd(e,t){return zc(e,t,(r,n)=>!(r.isCertified!==n.isCertified||!W(r.multiaddr,n.multiaddr)))}function zd(e,t){return zc(e,t,(r,n)=>r===n)}function Vd(e,t){return qc(e,t)}function Hd(e,t){return qc(e,t)}function $d(e,t){return Vc(e,t,(r,n)=>W(r,n))}function Wd(e,t){return Vc(e,t,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function qc(e,t){return e==null&&t==null?!0:e!=null&&t!=null?W(e,t):!1}function zc(e,t,r){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n]))return!1;return!0}function Vc(e,t,r){if(e.size!==t.size)return!1;for(let[n,o]of e.entries()){let s=t.get(n);if(s==null||!r(o,s))return!1}return!0}var Jt="/",Hc=new TextEncoder().encode(Jt),to=Hc[0],eo=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=V(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==to)throw new Error("Invalid key")}toString(t="utf8"){return q(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(Jt))}static random(){return new e(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new e(t):typeof t.uint8Array=="function"?new e(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Hc),this._buf[0]!==to){let t=new Uint8Array(this._buf.byteLength+1);t.fill(to,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===to;)this._buf=this._buf.subarray(0,-1)}less(t){let r=this.list(),n=t.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let s=r[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return r.length<n.length}reverse(){return e.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(Jt).slice(1)}type(){return jd(this.baseNamespace())}name(){return Zd(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(Jt)||(t+=Jt),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(Jt):new e(t.slice(0,-1).join(Jt))}child(t){return this.toString()===Jt?t:t.toString()===Jt?this:new e(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return e.withNamespaces([...this.namespaces(),...Yd(t.map(r=>r.namespaces()))])}};function jd(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Zd(e){let t=e.split(":");return t[t.length-1]}function Yd(e){return[].concat(...e)}var fi="/peers/";function qr(e){if(!Be(e)||e.type==null)throw new F("Invalid PeerId");let t=e.toCID().toString();return new eo(`${fi}${t}`)}async function $c(e,t,r,n,o){let s=new Map;for(let i of r){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=Ae(i.multiaddr)),!On(i.multiaddr))throw new F("Multiaddr was invalid");if(!await t(e,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),u=s.get(c);u!=null?i.isCertified=u.isCertified||a:s.set(c,{multiaddr:i.multiaddr,isCertified:a})}return[...s.values()].sort((i,a)=>i.multiaddr.toString().localeCompare(a.multiaddr.toString())).map(({isCertified:i,multiaddr:a})=>{let c=a.getComponents().find(u=>u.code===421)?.value;return e.equals(c)&&(a=a.decapsulate(Ae(`/p2p/${e}`))),{isCertified:i,multiaddr:a.bytes}})}async function no(e,t,r,n){if(t==null)throw new F("Invalid PeerData");if(t.publicKey!=null&&e.publicKey!=null&&!t.publicKey.equals(e.publicKey))throw new F("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!e.equals(o.id))throw new F("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,u=o?.peerRecordEnvelope;if(r==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=ro(d,{validate:Wc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=ro(d,{validate:jc,map:Zc})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}if(r==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[h,y]of d)y==null?a.delete(h):a.set(h,y);a=ro([...a.entries()],{validate:Wc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),h=new Map(c);for(let[y,g]of d)g==null?h.delete(y):h.set(y,g);c=ro([...h.entries()],{validate:jc,map:Zc})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}let f;o?.id.publicKey!=null?f=_t(o.id.publicKey):t.publicKey!=null?f=_t(t.publicKey):e.publicKey!=null&&(f=_t(e.publicKey));let l={addresses:await $c(e,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((d,h)=>d.localeCompare(h)),metadata:a,tags:c,publicKey:f,peerRecordEnvelope:u};return l.addresses.forEach(d=>{d.observed=n.existingPeer?.peerPB.addresses?.find(h=>W(h.multiaddr,h.multiaddr))?.observed??Date.now()}),e.type!=="RSA"&&delete l.publicKey,l}function ro(e,t){let r=new Map;for(let[n,o]of e)o!=null&&t.validate(n,o);for(let[n,o]of e.sort(([s],[i])=>s.localeCompare(i)))o!=null&&r.set(n,t.map?.(n,o)??o);return r}function Wc(e,t){if(typeof e!="string")throw new F("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new F("Metadata value must be a Uint8Array")}function jc(e,t){if(typeof e!="string")throw new F("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new F("Tag value must be an integer");if(t.value<0||t.value>100)throw new F("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new F("Tag ttl must be an integer");if(t.ttl<0)throw new F("Tag ttl must be between greater than 0")}}function Zc(e,t){let r;t.expiry!=null&&(r=t.expiry),t.ttl!=null&&(r=BigInt(Date.now()+Number(t.ttl)));let n={value:t.value??0};return r!=null&&(n.expiry=r),n}function Yc(e){let t=e.toString().split("/")[2],r=tt.parse(t,Kt);return _n(r)}function li(e,t,r){let n=Yc(e);return Fc(n,t,r)}function Gd(e,t){return{prefix:fi,filters:(e.filters??[]).map(r=>({key:n,value:o})=>r(li(n,o,t))),orders:(e.orders??[]).map(r=>(n,o)=>r(li(n.key,n.value,t),li(o.key,o.value,t)))}}var oo=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(t,r={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.peerId=t.peerId,this.datastore=t.datastore,this.addressFilter=r.addressFilter,this.locks=ni({name:"libp2p_peer_store_locks",metrics:t.metrics}),this.maxAddressAge=r.maxAddressAge??36e5,this.maxPeerAge=r.maxPeerAge??216e5}getLock(t){let r=this.locks.get(t);return r==null&&(r={refs:0,lock:ui({name:t.toString(),singleProcess:!0})},this.locks.set(t,r)),r.refs++,r}maybeRemoveLock(t,r){r.refs--,r.refs===0&&(r.lock.finalize(),this.locks.delete(t))}async getReadLock(t,r){let n=this.getLock(t);try{let o=await n.lock.readLock(r);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async getWriteLock(t,r){let n=this.getLock(t);try{let o=await n.lock.writeLock(r);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async has(t,r){try{return await this.load(t,r),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(t,r){this.peerId.equals(t)||await this.datastore.delete(qr(t),r)}async load(t,r){let n=qr(t),o=await this.datastore.get(n,r),s=Qt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new er;return Je(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,r,n){let o=await this.#t(t,n),s=await no(t,r,"patch",{...n,addressFilter:this.addressFilter});return this.#e(t,s,o)}async patch(t,r,n){let o=await this.#t(t,n),s=await no(t,r,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async merge(t,r,n){let o=await this.#t(t,n),s=await no(t,r,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async*all(t){for await(let{key:r,value:n}of this.datastore.query(Gd(t??{},this.maxAddressAge),t)){let o=Yc(r);if(o.equals(this.peerId))continue;let s=Qt.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,t);continue}yield Je(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,r){try{let n=qr(t),o=await this.datastore.get(n,r),s=Qt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new er;return{peerPB:s,peer:Je(t,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#e(t,r,n,o){r.updated=Date.now();let s=Qt.encode(r);return await this.datastore.put(qr(t),s,o),{peer:Je(t,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!Mc(r,n.peerPB)}}#r(t,r){if(r.updated==null)return!0;if(this.peerId.equals(t))return!1;let n=r.updated<Date.now()-this.maxPeerAge,o=Date.now()-this.maxAddressAge,s=r.addresses.filter(i=>i.observed!=null&&i.observed>o);return n&&s.length===0}};var di=class{store;events;peerId;log;constructor(t,r={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.events=t.events,this.peerId=t.peerId,this.store=new oo(t,r)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,r){for await(let n of this.store.all(r))t(n)}async all(t){return Cc(this.store.all(t))}async delete(t,r){let n=await this.store.getReadLock(t,r);try{await this.store.delete(t,r)}finally{n()}}async has(t,r){let n=await this.store.getReadLock(t,r);try{return await this.store.has(t,r)}finally{this.log.trace("has release read lock"),n?.()}}async get(t,r){let n=await this.store.getReadLock(t,r);try{return await this.store.load(t,r)}finally{n?.()}}async getInfo(t,r){let n=await this.get(t,r);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.save(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async patch(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.patch(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async merge(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.merge(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async consumePeerRecord(t,r,n){let o=Be(r)?r:Be(r?.expectedPeer)?r.expectedPeer:void 0,s=Be(r)||r===void 0?n:r,i=await Ge.openAndCertify(t,_e.DOMAIN,s),a=_n(i.publicKey.toCID());if(o?.equals(a)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",o,a),!1;let c=_e.createFromProtobuf(i.payload),u;try{u=await this.get(a,s)}catch(f){if(f.name!=="NotFoundError")throw f}if(u?.peerRecordEnvelope!=null){let f=Ge.createFromProtobuf(u.peerRecordEnvelope),l=_e.createFromProtobuf(f.payload);if(l.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",l.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(f=>({isCertified:!0,multiaddr:f}))},s),!0}#t(t,r){r.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:r}):this.events.safeDispatchEvent("peer:update",{detail:r}))}};function Xd(e,t={}){return new di(e,t)}return tu(Qd);})();
|
|
2
|
+
"use strict";var Libp2PPeerStore=(()=>{var ao=Object.defineProperty;var Qc=Object.getOwnPropertyDescriptor;var Jc=Object.getOwnPropertyNames;var tu=Object.prototype.hasOwnProperty;var Et=(e,t)=>{for(var r in t)ao(e,r,{get:t[r],enumerable:!0})},eu=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Jc(t))!tu.call(e,o)&&o!==r&&ao(e,o,{get:()=>t[o],enumerable:!(n=Qc(t,o))||n.enumerable});return e};var ru=e=>eu(ao({},"__esModule",{value:!0}),e);var nh={};Et(nh,{persistentPeerStore:()=>rh});var F=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ce=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var nr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var $r=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Wr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var pe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var jr=Symbol.for("@libp2p/peer-id");function Le(e){return!!e?.[jr]}function nu(e){return typeof e?.handleEvent=="function"}function ou(e){return(e!==!0&&e!==!1&&e?.once)??!1}var De=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){let o=ou(n);super.addEventListener(t,i=>{if(o){let a=this.#t.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#t.set(i.type,a))}nu(r)?r.handleEvent(i):r(i)},n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:r,once:o})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var ho={};Et(ho,{base58btc:()=>G,base58flickr:()=>du});var ch=new Uint8Array(0);function gi(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 Ht(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return me(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return me(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function wi(e){return new TextEncoder().encode(e)}function xi(e){return new TextDecoder().decode(e)}function su(e){return e?.buffer instanceof ArrayBuffer}function me(e){return su(e)?e:e.slice()}function iu(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),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var g=0,p=0,b=0,v=y.length;b!==v&&y[b]===0;)b++,g++;for(var A=(v-b)*f+1>>>0,L=new Uint8Array(A);b!==v;){for(var R=y[b],k=0,D=A-1;(R!==0||k<p)&&D!==-1;D--,k++)R+=256*L[D]>>>0,L[D]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");p=k,b++}for(var B=A-p;B!==A&&L[B]===0;)B++;for(var P=c.repeat(g);B<A;++B)P+=e.charAt(L[B]);return P}function d(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var g=0;if(y[g]!==" "){for(var p=0,b=0;y[g]===c;)p++,g++;for(var v=(y.length-g)*u+1>>>0,A=new Uint8Array(v);y[g];){var L=r[y.charCodeAt(g)];if(L===255)return;for(var R=0,k=v-1;(L!==0||R<b)&&k!==-1;k--,R++)L+=a*A[k]>>>0,A[k]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");b=R,g++}if(y[g]!==" "){for(var D=v-b;D!==v&&A[D]===0;)D++;for(var B=new Uint8Array(p+(v-D)),P=p;D!==v;)B[P++]=A[D++];return B}}}function h(y){var g=d(y);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:h}}var au=iu,cu=au,vi=cu;var co=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")}},uo=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 Si(this,t)}},fo=class{decoders;constructor(t){this.decoders=t}or(t){return Si(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 Si(e,t){return new fo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var lo=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 co(t,r,n),this.decoder=new uo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Oe({name:e,prefix:t,encode:r,decode:n}){return new lo(e,t,r,n)}function ee({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=vi(r,e);return Oe({prefix:t,name:e,encode:n,decode:s=>Ht(o(s))})}function uu(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 u=0;u<o;++u){let f=t[e[u]];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 fu(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 lu(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Y({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=lu(n);return Oe({prefix:t,name:e,encode(s){return fu(s,n,r)},decode(s){return uu(s,o,r,e)}})}var G=ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),du=ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var po={};Et(po,{base32:()=>Nt,base32hex:()=>yu,base32hexpad:()=>gu,base32hexpadupper:()=>wu,base32hexupper:()=>bu,base32pad:()=>pu,base32padupper:()=>mu,base32upper:()=>hu,base32z:()=>xu});var Nt=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),hu=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),pu=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),mu=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),yu=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),bu=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),gu=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),wu=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),xu=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var mo={};Et(mo,{base36:()=>or,base36upper:()=>Eu});var or=ee({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Eu=ee({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var vu=Ti,Ai=128,Su=127,Au=~Su,_u=Math.pow(2,31);function Ti(e,t,r){t=t||[],r=r||0;for(var n=r;e>=_u;)t[r++]=e&255|Ai,e/=128;for(;e&Au;)t[r++]=e&255|Ai,e>>>=7;return t[r]=e|0,Ti.bytes=r-n+1,t}var Tu=yo,Bu=128,_i=127;function yo(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw yo.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&_i)<<o:(i&_i)*Math.pow(2,o),o+=7}while(i>=Bu);return yo.bytes=s-n,r}var Iu=Math.pow(2,7),Ru=Math.pow(2,14),Cu=Math.pow(2,21),Lu=Math.pow(2,28),Du=Math.pow(2,35),Ou=Math.pow(2,42),ku=Math.pow(2,49),Pu=Math.pow(2,56),Ku=Math.pow(2,63),Nu=function(e){return e<Iu?1:e<Ru?2:e<Cu?3:e<Lu?4:e<Du?5:e<Ou?6:e<ku?7:e<Pu?8:e<Ku?9:10},Uu={encode:vu,decode:Tu,encodingLength:Nu},Fu=Uu,sr=Fu;function ir(e,t=0){return[sr.decode(e,t),sr.decode.bytes]}function ke(e,t,r=0){return sr.encode(e,t,r),t}function Pe(e){return sr.encodingLength(e)}function Ut(e,t){let r=t.byteLength,n=Pe(e),o=n+Pe(r),s=new Uint8Array(o+r);return ke(e,s,0),ke(r,s,n),s.set(t,o),new Ke(e,r,t,s)}function Ne(e){let t=Ht(e),[r,n]=ir(t),[o,s]=ir(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ke(r,o,i,t)}function Bi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&gi(e.bytes,r.bytes)}}var Ke=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=me(n),this.bytes=me(o)}};function Ii(e,t){let{bytes:r,version:n}=e;return n===0?qu(r,bo(e),t??G.encoder):zu(r,bo(e),t??Nt.encoder)}var Ri=new WeakMap;function bo(e){let t=Ri.get(e);if(t==null){let r=new Map;return Ri.set(e,r),r}return t}var et=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=me(o),this["/"]=this.bytes}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!==ar)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Vu)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=Ut(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&&Bi(t.multihash,n.multihash)}toString(t){return Ii(this,t)}toJSON(){return{"/":Ii(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??Ci(n,o,s.bytes))}else if(r[Hu]===!0){let{version:n,multihash:o,code:s}=r,i=Ne(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!==ar)throw new Error(`Version 0 CID must use dag-pb (code: ${ar}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ci(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,ar,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=Ht(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 Ke(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,d]=ir(t.subarray(r));return r+=d,l},o=n(),s=ar;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(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=Mu(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 bo(s).set(n,t),s}};function Mu(e,t){switch(e[0]){case"Q":{let r=t??G;return[G.prefix,r.decode(`${G.prefix}${e}`)]}case G.prefix:{let r=t??G;return[G.prefix,r.decode(e)]}case Nt.prefix:{let r=t??Nt;return[Nt.prefix,r.decode(e)]}case or.prefix:{let r=t??or;return[or.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 qu(e,t,r){let{prefix:n}=r;if(n!==G.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 zu(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 ar=112,Vu=18;function Ci(e,t,r){let n=Pe(e),o=n+Pe(t),s=new Uint8Array(o+r.byteLength);return ke(e,s,0),ke(t,s,n),s.set(r,o),s}var Hu=Symbol.for("@ipld/js-cid/CID");var go={};Et(go,{identity:()=>Ct});var Li=0,$u="identity",Di=Ht;function Wu(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Ut(Li,Di(e))}var Ct={code:Li,name:$u,encode:Di,digest:Wu};function W(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 ju(e){return e.buffer instanceof ArrayBuffer}function pt(e){return ju(e)?e:e.slice()}async function Oi(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,pt(t),pt(r.subarray()));return n?.signal?.throwIfAborted(),s}function J(e=0){return new Uint8Array(e)}function lt(e=0){return new Uint8Array(e)}function Zu(e){return e?.buffer instanceof ArrayBuffer}function wo(e){if(Zu(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Ft(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=lt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return wo(r)}var Pi=Symbol.for("@achingbrain/uint8arraylist");function ki(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 Yr(e){return!!e?.[Pi]}var mt=class e{bufs;length;[Pi]=!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(Yr(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}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(Yr(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=ki(this.bufs,t);return r.buf[r.index]}set(t,r){let n=ki(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(Yr(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 Ft(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ft(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 u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){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(!Yr(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 a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let h=this.get(l+d);if(n[d]!==h){f=Math.max(1,d-a[h]);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=lt(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=J(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=J(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=J(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=lt(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=J(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=J(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=J(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=J(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=J(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(!W(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 xo={};Et(xo,{base10:()=>Yu});var Yu=ee({prefix:"9",name:"base10",alphabet:"0123456789"});var Eo={};Et(Eo,{base16:()=>Gu,base16upper:()=>Xu});var Gu=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Xu=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var vo={};Et(vo,{base2:()=>Qu});var Qu=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var So={};Et(So,{base256emoji:()=>nf});var Ki=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}"),Ju=Ki.reduce((e,t,r)=>(e[r]=t,e),[]),tf=Ki.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function ef(e){return e.reduce((t,r)=>(t+=Ju[r],t),"")}function rf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=tf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var nf=Oe({prefix:"\u{1F680}",name:"base256emoji",encode:ef,decode:rf});var _o={};Et(_o,{base64:()=>of,base64pad:()=>sf,base64url:()=>Ao,base64urlpad:()=>af});var of=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),sf=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ao=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),af=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var To={};Et(To,{base8:()=>cf});var cf=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Bo={};Et(Bo,{identity:()=>uf});var uf=Oe({prefix:"\0",name:"identity",encode:e=>xi(e),decode:e=>wi(e)});var jh=new TextEncoder,Zh=new TextDecoder;var Co={};Et(Co,{sha256:()=>cr,sha512:()=>hf});var df=20;function Ro({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Io(e,t,r,n,o)}var Io=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??df,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Ni(n,this.code,r?.truncate):n.then(o=>Ni(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ni(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Ut(t,e)}function Fi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var cr=Ro({name:"sha2-256",code:18,encode:Fi("SHA-256")}),hf=Ro({name:"sha2-512",code:19,encode:Fi("SHA-512")});var ur={...Bo,...vo,...To,...xo,...Eo,...po,...mo,...ho,..._o,...So},ip={...Co,...go};function qi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Mi=qi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Lo=qi("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=lt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),pf={utf8:Mi,"utf-8":Mi,hex:ur.base16,latin1:Lo,ascii:Lo,binary:Lo,...ur},Gr=pf;function V(e,t="utf8"){let r=Gr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function M(e,t="utf8"){let r=Gr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var mf=parseInt("11111",2),Do=parseInt("10000000",2),yf=parseInt("01111111",2),zi={0:fr,1:fr,2:bf,3:xf,4:Ef,5:wf,6:gf,16:fr,22:fr,48:fr};function $t(e,t={offset:0}){let r=e[t.offset]&mf;if(t.offset++,zi[r]!=null)return zi[r](e,t);throw new Error("No decoder for tag "+r)}function lr(e,t){let r=0;if((e[t.offset]&Do)===Do){let n=e[t.offset]&yf,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 fr(e,t){lr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=$t(e,t);if(n===null)break;r.push(n)}return r}function bf(e,t){let r=lr(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 gf(e,t){let r=lr(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 u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function wf(e,t){return t.offset++,null}function xf(e,t){let r=lr(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 Ef(e,t){let r=lr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function vf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new mt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Oo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=vf(e.byteLength);return new mt(Uint8Array.from([t.byteLength|Do]),t)}function vt(e){let t=new mt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new mt(Uint8Array.from([2]),Oo(t),t)}function Xr(e){let t=Uint8Array.from([0]),r=new mt(t,e);return new mt(Uint8Array.from([3]),Oo(r),r)}function ne(e,t=48){let r=new mt;for(let n of e)r.append(n);return new mt(Uint8Array.from([t]),Oo(r),r)}var Sf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Af=Uint8Array.from([6,5,43,129,4,0,34]),_f=Uint8Array.from([6,5,43,129,4,0,35]),Tf={ext:!0,kty:"EC",crv:"P-256"},Bf={ext:!0,kty:"EC",crv:"P-384"},If={ext:!0,kty:"EC",crv:"P-521"},ko=32,Po=48,Ko=66;function No(e){let t=$t(e);return Vi(t)}function Vi(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===ko*2+1)return n=M(t.subarray(r,r+ko),"base64url"),o=M(t.subarray(r+ko),"base64url"),new Ue({...Tf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Po*2+1)return n=M(t.subarray(r,r+Po),"base64url"),o=M(t.subarray(r+Po),"base64url"),new Ue({...Bf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ko*2+1)return n=M(t.subarray(r,r+Ko),"base64url"),o=M(t.subarray(r+Ko),"base64url"),new Ue({...If,key_ops:["verify"],x:n,y:o});throw new F(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Hi(e){return ne([vt(Uint8Array.from([1])),ne([Rf(e.crv)],160),ne([Xr(new mt(Uint8Array.from([4]),V(e.x??"","base64url"),V(e.y??"","base64url")))],161)]).subarray()}function Rf(e){if(e==="P-256")return Sf;if(e==="P-384")return Af;if(e==="P-521")return _f;throw new F(`Invalid curve ${e}`)}var Ue=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Hi(this.jwk)),this._raw}toMultihash(){return Ct.digest(Tt(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}async verify(t,r,n){return Oi(this.jwk,r,t,n)}};function Uo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function oe(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function St(e,t,r=""){let n=Uo(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return e}function Qr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(oe(e.outputLen),oe(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Fe(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 Jr(e,t){St(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function jt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function tn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Lt(e,t){return e<<32-t|e>>>t}var Wi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Cf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function en(e){if(St(e),Wi)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Cf[e[r]];return t}var Wt={_0:48,_9:57,A:65,F:70,a:97,f:102};function $i(e){if(e>=Wt._0&&e<=Wt._9)return e-Wt._0;if(e>=Wt.A&&e<=Wt.F)return e-(Wt.A-10);if(e>=Wt.a&&e<=Wt.f)return e-(Wt.a-10)}function dr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(Wi)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=e.length,r=t/2;if(t%2)throw new RangeError("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=$i(e.charCodeAt(s)),a=$i(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Fo(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];St(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 Mo(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function ji(e=32){oe(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var qo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Zi(e,t,r){return e&t^~e&r}function Yi(e,t,r){return e&t^e&r^t&r}var hr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=tn(this.buffer)}update(t){Fe(this),St(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=tn(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){Fe(this),Jr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,jt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=tn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.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||=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()}},Zt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var rn=BigInt(4294967295),Gi=BigInt(32);function Lf(e,t=!1){return t?{h:Number(e&rn),l:Number(e>>Gi&rn)}:{h:Number(e>>Gi&rn)|0,l:Number(e&rn)|0}}function Xi(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}=Lf(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var zo=(e,t,r)=>e>>>r,Vo=(e,t,r)=>e<<32-r|t>>>r,ye=(e,t,r)=>e>>>r|t<<32-r,be=(e,t,r)=>e<<32-r|t>>>r,pr=(e,t,r)=>e<<64-r|t>>>r-32,mr=(e,t,r)=>e>>>r-32|t<<64-r;function Mt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Qi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ji=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ta=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ea=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ra=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),na=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Of=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]),se=new Uint32Array(64),Ho=class extends hr{constructor(t){super(64,t,8,!1)}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 l=0;l<16;l++,r+=4)se[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=se[l-15],h=se[l-2],y=Lt(d,7)^Lt(d,18)^d>>>3,g=Lt(h,17)^Lt(h,19)^h>>>10;se[l]=g+se[l-7]+y+se[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Lt(a,6)^Lt(a,11)^Lt(a,25),h=f+d+Zi(a,c,u)+Of[l]+se[l]|0,g=(Lt(n,2)^Lt(n,13)^Lt(n,22))+Yi(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+g|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,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){jt(se)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),jt(this.buffer)}},$o=class extends Ho{A=Zt[0]|0;B=Zt[1]|0;C=Zt[2]|0;D=Zt[3]|0;E=Zt[4]|0;F=Zt[5]|0;G=Zt[6]|0;H=Zt[7]|0;constructor(){super(32)}};var oa=Xi(["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))),kf=oa[0],Pf=oa[1],ie=new Uint32Array(80),ae=new Uint32Array(80),Wo=class extends hr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:h,Gl:y,Hh:g,Hl:p}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,h,y,g,p]}set(t,r,n,o,s,i,a,c,u,f,l,d,h,y,g,p){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=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=y|0,this.Hh=g|0,this.Hl=p|0}process(t,r){for(let A=0;A<16;A++,r+=4)ie[A]=t.getUint32(r),ae[A]=t.getUint32(r+=4);for(let A=16;A<80;A++){let L=ie[A-15]|0,R=ae[A-15]|0,k=ye(L,R,1)^ye(L,R,8)^zo(L,R,7),D=be(L,R,1)^be(L,R,8)^Vo(L,R,7),B=ie[A-2]|0,P=ae[A-2]|0,$=ye(B,P,19)^pr(B,P,61)^zo(B,P,6),K=be(B,P,19)^mr(B,P,61)^Vo(B,P,6),m=ta(D,K,ae[A-7],ae[A-16]),w=ea(m,k,$,ie[A-7],ie[A-16]);ie[A]=w|0,ae[A]=m|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:h,Fl:y,Gh:g,Gl:p,Hh:b,Hl:v}=this;for(let A=0;A<80;A++){let L=ye(l,d,14)^ye(l,d,18)^pr(l,d,41),R=be(l,d,14)^be(l,d,18)^mr(l,d,41),k=l&h^~l&g,D=d&y^~d&p,B=ra(v,R,D,Pf[A],ae[A]),P=na(B,b,L,k,kf[A],ie[A]),$=B|0,K=ye(n,o,28)^pr(n,o,34)^pr(n,o,39),m=be(n,o,28)^mr(n,o,34)^mr(n,o,39),w=n&s^n&a^s&a,S=o&i^o&c^i&c;b=g|0,v=p|0,g=h|0,p=y|0,h=l|0,y=d|0,{h:l,l:d}=Mt(u|0,f|0,P|0,$|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let E=Qi($,m,S);n=Ji(E,P,K,w),o=E|0}({h:n,l:o}=Mt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Mt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Mt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Mt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Mt(this.Eh|0,this.El|0,l|0,d|0),{h,l:y}=Mt(this.Fh|0,this.Fl|0,h|0,y|0),{h:g,l:p}=Mt(this.Gh|0,this.Gl|0,g|0,p|0),{h:b,l:v}=Mt(this.Hh|0,this.Hl|0,b|0,v|0),this.set(n,o,s,i,a,c,u,f,l,d,h,y,g,p,b,v)}roundClean(){jt(ie,ae)}destroy(){this.destroyed=!0,jt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},jo=class extends Wo{Ah=ct[0]|0;Al=ct[1]|0;Bh=ct[2]|0;Bl=ct[3]|0;Ch=ct[4]|0;Cl=ct[5]|0;Dh=ct[6]|0;Dl=ct[7]|0;Eh=ct[8]|0;El=ct[9]|0;Fh=ct[10]|0;Fl=ct[11]|0;Gh=ct[12]|0;Gl=ct[13]|0;Hh=ct[14]|0;Hl=ct[15]|0;constructor(){super(64)}};var Me=Mo(()=>new $o,qo(1));var nn=Mo(()=>new jo,qo(3));var q=(e,t,r)=>St(e,t,r),Yo=oe,qe=en,nt=(...e)=>Fo(...e),ze=e=>dr(e),ge=Uo,yr=e=>ji(e),sn=BigInt(0),Zo=BigInt(1);function Dt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function an(e){if(typeof e=="bigint"){if(!on(e))throw new RangeError("positive bigint expected, got "+e)}else Yo(e);return e}function Ot(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function br(e){let t=an(e).toString(16);return t.length&1?"0"+t:t}function sa(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?sn:BigInt("0x"+e)}function we(e){return sa(en(e))}function qt(e){return sa(en(gr(St(e)).reverse()))}function cn(e,t){if(oe(t),t===0)throw new RangeError("zero length");e=an(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return dr(r.padStart(t*2,"0"))}function Go(e,t){return cn(e,t).reverse()}function ia(e,t){if(e=q(e),t=q(t),e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function gr(e){return Uint8Array.from(q(e))}function un(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var on=e=>typeof e=="bigint"&&sn<=e;function Kf(e,t,r){return on(e)&&on(t)&&on(r)&&t<=e&&e<r}function Ve(e,t,r,n){if(!Kf(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function He(e){if(e<sn)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>sn;e>>=Zo,t+=1);return t}var wr=e=>(Zo<<BigInt(e))-Zo;function aa(e,t,r){if(oe(e,"hashLen"),oe(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=p=>new Uint8Array(p),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},d=(...p)=>r(u,nt(c,...p)),h=(p=o)=>{u=d(s,p),c=d(),p.length!==0&&(u=d(i,p),c=d())},y=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let p=0,b=[];for(;p<t;){c=d();let v=c.slice();b.push(v),p+=c.length}return nt(...b)};return(p,b)=>{l(),h(p);let v;for(;(v=b(y()))===void 0;)h();return l(),v}}function kt(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(e,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=e[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(r,!0)}var Xo=()=>{throw new Error("not implemented")};var ut=BigInt(0),X=BigInt(1),xe=BigInt(2),la=BigInt(3),da=BigInt(4),ha=BigInt(5),Nf=BigInt(7),pa=BigInt(8),Uf=BigInt(9),ma=BigInt(16);function tt(e,t){if(t<=ut)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=ut?r:t+r}function j(e,t,r){if(t<ut)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >ut;)n*=n,n%=r;return n}function ca(e,t){if(e===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let r=tt(e,t),n=t,o=ut,s=X,i=X,a=ut;for(;r!==ut;){let u=n/r,f=n-r*u,l=o-i*u,d=s-a*u;n=r,r=f,o=i,s=a,i=l,a=d}if(n!==X)throw new Error("invert: does not exist");return tt(o,t)}function Qo(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function ya(e,t){let r=e,n=(r.ORDER+X)/da,o=r.pow(t,n);return Qo(r,o,t),o}function Ff(e,t){let r=e,n=(r.ORDER-ha)/pa,o=r.mul(t,xe),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,xe),s),c=r.mul(i,r.sub(a,r.ONE));return Qo(r,c,t),c}function Mf(e){let t=$e(e),r=ba(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Nf)/ma;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),d=u.mul(f,o),h=u.mul(f,s),y=u.eql(u.sqr(l),c),g=u.eql(u.sqr(d),c);f=u.cmov(f,l,y),l=u.cmov(h,d,g);let p=u.eql(u.sqr(l),c),b=u.cmov(f,l,p);return Qo(u,b,c),b})}function ba(e){if(e<la)throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%xe===ut;)t/=xe,r++;let n=xe,o=$e(e);for(;ua(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ya;let s=o.pow(n,t),i=(t+X)/xe;return function(c,u){let f=c;if(f.is0(u))return u;if(ua(f,u)!==1)throw new Error("Cannot find square root");let l=r,d=f.mul(f.ONE,s),h=f.pow(u,t),y=f.pow(u,i);for(;!f.eql(h,f.ONE);){if(f.is0(h))return f.ZERO;let g=1,p=f.sqr(h);for(;!f.eql(p,f.ONE);)if(g++,p=f.sqr(p),g===l)throw new Error("Cannot find square root");let b=X<<BigInt(l-g-1),v=f.pow(d,b);l=g,d=f.sqr(v),h=f.mul(h,d),y=f.mul(y,v)}return y}}function qf(e){return e%da===la?ya:e%pa===ha?Ff:e%ma===Uf?Mf(e):ba(e)}var Yt=(e,t)=>(tt(e,t)&X)===X,zf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Jo(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=zf.reduce((n,o)=>(n[o]="function",n),t);if(kt(e,r),Ot(e.BYTES,"BYTES"),Ot(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function Vf(e,t,r){let n=e;if(r<ut)throw new Error("invalid exponent, negatives unsupported");if(r===ut)return n.ONE;if(r===X)return t;let o=n.ONE,s=t;for(;r>ut;)r&X&&(o=n.mul(o,s)),s=n.sqr(s),r>>=X;return o}function xr(e,t,r=!1){let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return t.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function ua(e,t){let r=e,n=(r.ORDER-X)/xe,o=r.pow(t,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Hf(e,t){if(t!==void 0&&Yo(t),e<=ut)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=He(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var fa=new WeakMap,fn=class{ORDER;BITS;BYTES;isLE;ZERO=ut;ONE=X;_lengths;_mod;constructor(t,r={}){if(t<=X)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=Hf(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return tt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return ut<=t&&t<this.ORDER}is0(t){return t===ut}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&X)===X}neg(t){return tt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return tt(t*t,this.ORDER)}add(t,r){return tt(t+r,this.ORDER)}sub(t,r){return tt(t-r,this.ORDER)}mul(t,r){return tt(t*r,this.ORDER)}pow(t,r){return Vf(this,t,r)}div(t,r){return tt(t*ca(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return ca(t,this.ORDER)}sqrt(t){let r=fa.get(this);return r||fa.set(this,r=qf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?Go(t,this.BYTES):cn(t,this.BYTES)}fromBytes(t,r=!1){q(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(o);u.set(t,s?0:u.length-t.length),t=u}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?qt(t):we(t);if(a&&(c=tt(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return xr(this,t)}cmov(t,r,n){return Dt(n,"condition"),n?r:t}};Object.freeze(fn.prototype);function $e(e,t={}){return new fn(e,t)}function ga(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=X)throw new Error("field order must be greater than 1");let t=He(e-X);return Math.ceil(t/8)}function ts(e){let t=ga(e);return t+Math.ceil(t/2)}function es(e,t,r=!1){q(e);let n=e.length,o=ga(t),s=Math.max(ts(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?qt(e):we(e),a=tt(i,t-X)+X;return r?Go(a,o):cn(a,o)}var We=BigInt(0),Ee=BigInt(1);function Er(e,t){let r=t.negate();return e?r:t}function ve(e,t){let r=xr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function va(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function rs(e,t){va(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=wr(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function wa(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+=Ee);let u=t*n,f=u+Math.abs(a)-1,l=a===0,d=a<0,h=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:d,isNegF:h,offsetF:u}}var ns=new WeakMap,Sa=new WeakMap;function os(e){return Sa.get(e)||1}function xa(e){if(e!==We)throw new Error("invalid wNAF")}var je=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>We;)r&Ee&&(n=n.add(o)),o=o.double(),r>>=Ee;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=rs(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=rs(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:d,offsetF:h}=wa(n,a,i);n=c,f?s=s.add(Er(d,r[h])):o=o.add(Er(l,r[u]))}return xa(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=rs(t,this.bits);for(let i=0;i<s.windows&&n!==We;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=wa(n,i,s);if(n=a,!u){let l=r[c];o=o.add(f?l.negate():l)}}return xa(n),o}getPrecomputes(t,r,n){let o=ns.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ns.set(r,o))),o}cached(t,r,n){let o=os(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=os(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){va(r,this.bits),Sa.set(t,r),ns.delete(t)}hasCache(t){return os(t)!==1}};function Aa(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>We||n>We;)r&Ee&&(s=s.add(o)),n&Ee&&(i=i.add(o)),o=o.double(),r>>=Ee,n>>=Ee;return{p1:s,p2:i}}function Ea(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Jo(t),t}else return $e(e,{isLE:r})}function ln(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>We))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Ea(t.p,r.Fp,n),s=Ea(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function dn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var ce=BigInt(0),it=BigInt(1),ss=BigInt(2),$f=BigInt(8);function Wf(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 _a(e,t={}){let r=t,n=ln("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;kt(r,{},{uvRatio:"function"});let c=ss<<BigInt(s.BYTES*8)-it,u=g=>o.create(g),f=r.uvRatio===void 0?(g,p)=>{try{return{isValid:!0,value:o.sqrt(o.div(g,p))}}catch{return{isValid:!1,value:ce}}}:r.uvRatio;if(!Wf(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(g,p,b=!1){let v=b?it:ce;return Ve("coordinate "+g,p,v,c),p}function d(g){if(!(g instanceof h))throw new Error("EdwardsPoint expected")}class h{static BASE=new h(i.Gx,i.Gy,it,u(i.Gx*i.Gy));static ZERO=new h(ce,it,it,ce);static Fp=o;static Fn=s;X;Y;Z;T;constructor(p,b,v,A){this.X=l("x",p),this.Y=l("y",b),this.Z=l("z",v,!0),this.T=l("t",A),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){if(p instanceof h)throw new Error("extended point not allowed");let{x:b,y:v}=p||{};return l("x",b),l("y",v),new h(b,v,it,u(b*v))}static fromBytes(p,b=!1){let v=o.BYTES,{a:A,d:L}=i;p=gr(q(p,v,"point")),Dt(b,"zip215");let R=gr(p),k=p[v-1];R[v-1]=k&-129;let D=qt(R),B=b?c:o.ORDER;Ve("point.y",D,ce,B);let P=u(D*D),$=u(P-it),K=u(L*P-A),{isValid:m,value:w}=f($,K);if(!m)throw new Error("bad point: invalid y coordinate");let S=(w&it)===it,E=(k&128)!==0;if(!b&&w===ce&&E)throw new Error("bad point: x=0 and x_0=1");return E!==S&&(w=u(-w)),h.fromAffine({x:w,y:D})}static fromHex(p,b=!1){return h.fromBytes(ze(p),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,b=!0){return y.createCache(this,p),b||this.multiply(ss),this}assertValidity(){let p=this,{a:b,d:v}=i;if(p.is0())throw new Error("bad point: ZERO");let{X:A,Y:L,Z:R,T:k}=p,D=u(A*A),B=u(L*L),P=u(R*R),$=u(P*P),K=u(D*b),m=u(P*u(K+B)),w=u($+u(v*u(D*B)));if(m!==w)throw new Error("bad point: equation left != right (1)");let S=u(A*L),E=u(R*k);if(S!==E)throw new Error("bad point: equation left != right (2)")}equals(p){d(p);let{X:b,Y:v,Z:A}=this,{X:L,Y:R,Z:k}=p,D=u(b*k),B=u(L*A),P=u(v*k),$=u(R*A);return D===B&&P===$}is0(){return this.equals(h.ZERO)}negate(){return new h(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:p}=i,{X:b,Y:v,Z:A}=this,L=u(b*b),R=u(v*v),k=u(ss*u(A*A)),D=u(p*L),B=b+v,P=u(u(B*B)-L-R),$=D+R,K=$-k,m=D-R,w=u(P*K),S=u($*m),E=u(P*m),x=u(K*$);return new h(w,S,x,E)}add(p){d(p);let{a:b,d:v}=i,{X:A,Y:L,Z:R,T:k}=this,{X:D,Y:B,Z:P,T:$}=p,K=u(A*D),m=u(L*B),w=u(k*v*$),S=u(R*P),E=u((A+L)*(D+B)-K-m),x=S-w,_=S+w,I=u(m-b*K),T=u(E*x),C=u(_*I),O=u(E*I),U=u(x*_);return new h(T,C,U,O)}subtract(p){return d(p),this.add(p.negate())}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:b,f:v}=y.cached(this,p,A=>ve(h,A));return ve(h,[b,v])[0]}multiplyUnsafe(p){if(!s.isValid(p))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return p===ce?h.ZERO:this.is0()||p===it?this:y.unsafe(this,p,b=>ve(h,b))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return y.unsafe(this,i.n).is0()}toAffine(p){let b=this,v=p,{X:A,Y:L,Z:R}=b,k=b.is0();v==null&&(v=k?$f:o.inv(R));let D=u(A*v),B=u(L*v),P=o.mul(R,v);if(k)return{x:ce,y:it};if(P!==it)throw new Error("invZ was invalid");return{x:D,y:B}}clearCofactor(){return a===it?this:this.multiplyUnsafe(a)}toBytes(){let{x:p,y:b}=this.toAffine(),v=o.toBytes(b);return v[v.length-1]|=p&it?128:0,v}toHex(){return qe(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=new je(h,s.BITS);return s.BITS>=8&&h.BASE.precompute(8),Object.freeze(h.prototype),Object.freeze(h),h}var hn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Xo()}static fromHex(t){Xo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return qe(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.ep.precompute(t,r),this}};function Ta(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;kt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Ot(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?yr:o.randomBytes,d=o.adjustScalarBytes===void 0?m=>m:o.adjustScalarBytes,h=o.domain===void 0?(m,w,S)=>{if(Dt(S,"phflag"),w.length||S)throw new Error("Contexts/pre-hash are not supported");return m}:o.domain;function y(m){return c.create(qt(m))}function g(m){let w=D.secretKey;q(m,D.secretKey,"secretKey");let S=q(n(m),2*w,"hashedSecretKey"),E=d(S.slice(0,w)),x=S.slice(w,2*w),_=y(E);return{head:E,prefix:x,scalar:_}}function p(m){let{head:w,prefix:S,scalar:E}=g(m),x=i.multiply(E),_=x.toBytes();return{head:w,prefix:S,scalar:E,point:x,pointBytes:_}}function b(m){return p(m).pointBytes}function v(m=Uint8Array.of(),...w){let S=nt(...w);return y(n(h(S,q(m,void 0,"context"),!!s)))}function A(m,w,S={}){m=q(m,void 0,"message"),s&&(m=s(m));let{prefix:E,scalar:x,pointBytes:_}=p(w),I=v(S.context,E,m),T=i.multiply(I).toBytes(),C=v(S.context,T,_,m),O=c.create(I+C*x);if(!c.isValid(O))throw new Error("sign failed: invalid s");let U=nt(T,c.toBytes(O));return q(U,D.signature,"result")}let L={zip215:o.zip215};function R(m,w,S,E=L){let{context:x}=E,_=E.zip215===void 0?!!L.zip215:E.zip215,I=D.signature;m=q(m,I,"signature"),w=q(w,void 0,"message"),S=q(S,D.publicKey,"publicKey"),_!==void 0&&Dt(_,"zip215"),s&&(w=s(w));let T=I/2,C=m.subarray(0,T),O=qt(m.subarray(T,I)),U,z,N;try{U=e.fromBytes(S,_),z=e.fromBytes(C,_),N=i.multiplyUnsafe(O)}catch{return!1}if(!_&&U.isSmallOrder())return!1;let rt=v(x,C,S,w);return z.add(U.multiplyUnsafe(rt)).subtract(N).clearCofactor().is0()}let k=a.BYTES,D={secretKey:k,publicKey:k,signature:2*k,seed:k};function B(m){return m=m===void 0?l(D.seed):m,q(m,D.seed,"seed")}function P(m){return ge(m)&&m.length===D.secretKey}function $(m,w){try{return!!e.fromBytes(m,w===void 0?L.zip215:w)}catch{return!1}}let K={getExtendedPublicKey:p,randomSecretKey:B,isValidSecretKey:P,isValidPublicKey:$,toMontgomery(m){let{y:w}=e.fromBytes(m),S=D.publicKey,E=S===32;if(!E&&S!==57)throw new Error("only defined for 25519 and 448");let x=E?a.div(it+w,it-w):a.div(w-it,w+it);return a.toBytes(x)},toMontgomerySecret(m){let w=D.secretKey;q(m,w);let S=n(m.subarray(0,w));return d(S).subarray(0,w)}};return Object.freeze(D),Object.freeze(K),Object.freeze({keygen:dn(B,b),getPublicKey:b,sign:A,verify:R,utils:K,Point:e,lengths:D})}function vr(e,t){if(Ot(e),Ot(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function jf(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function Zf(e){if(!ge(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?un(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function is(e,t,r,n){q(e),Ot(r),t=Zf(t),t.length>255&&(t=n(nt(un("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=nt(t,vr(t.length,1)),c=new Uint8Array(s),u=vr(r,2),f=new Array(i),l=n(nt(c,e,u,vr(0,1),a));f[0]=n(nt(l,vr(1,1),a));for(let h=1;h<i;h++){let y=[jf(l,f[h-1]),vr(h+1,1),a];f[h]=n(nt(...y))}return nt(...f).slice(0,r)}var Ba="HashToScalar-";var Yf=BigInt(0),Gt=BigInt(1),Ia=BigInt(2);var Gf=BigInt(5),Xf=BigInt(8),Ze=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),fs={p:Ze,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Xf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Qf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ze,a=e*e%s*e%s,c=j(a,Ia,s)*a%s,u=j(c,Gt,s)*e%s,f=j(u,Gf,s)*u%s,l=j(f,t,s)*f%s,d=j(l,r,s)*l%s,h=j(d,n,s)*d%s,y=j(h,o,s)*h%s,g=j(y,o,s)*h%s,p=j(g,t,s)*f%s;return{pow_p_5_8:j(p,Ia,s)*e%s,b2:a}}function Jf(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var as=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ls(e,t){let r=Ze,n=tt(t*t*t,r),o=tt(n*n*t,r),s=Qf(e*o).pow_p_5_8,i=tt(e*n*s,r),a=tt(t*i*i,r),c=i,u=tt(i*as,r),f=a===e,l=a===tt(-e,r),d=a===tt(-e*as,r);return f&&(i=c),(l||d)&&(i=u),Yt(i,r)&&(i=tt(-i,r)),{isValid:f||l,value:i}}var fe=_a(fs,{uvRatio:ls}),ue=fe.Fp,La=fe.Fn;function tl(e){return Ta(fe,nn,Object.assign({adjustScalarBytes:Jf,zip215:!0},e))}var Da=tl({});var cs=as,el=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),rl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),nl=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),ol=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ra=e=>ls(Gt,e),sl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),us=e=>ue.create(qt(e)&sl);function Ca(e){let{d:t}=fs,r=Ze,n=b=>ue.create(b),o=n(cs*e*e),s=n((o+Gt)*nl),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=ls(s,a),f=n(u*e);Yt(f,r)||(f=n(-f)),c||(u=f),c||(i=o);let l=n(i*(o-Gt)*ol-a),d=u*u,h=n((u+u)*a),y=n(l*el),g=n(Gt-d),p=n(Gt+d);return new fe(n(h*p),n(g*y),n(y*p),n(h*g))}var le=class e extends hn{static BASE=new e(fe.BASE);static ZERO=new e(fe.ZERO);static Fp=ue;static Fn=La;constructor(t){super(t)}static fromAffine(t){return new e(fe.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){St(t,32);let{a:r,d:n}=fs,o=Ze,s=L=>ue.create(L),i=us(t);if(!ia(ue.toBytes(i),t)||Yt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Gt+r*a),u=s(Gt-r*a),f=s(c*c),l=s(u*u),d=s(r*n*f-l),{isValid:h,value:y}=Ra(s(d*l)),g=s(y*u),p=s(y*g*d),b=s((i+i)*g);Yt(b,o)&&(b=s(-b));let v=s(c*p),A=s(b*v);if(!h||Yt(A,o)||v===Yf)throw new Error("invalid ristretto255 encoding 2");return new e(new fe(b,v,Gt,A))}static fromHex(t){return e.fromBytes(dr(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Ze,i=p=>ue.create(p),a=i(i(n+r)*i(n-r)),c=i(t*r),u=i(c*c),{value:f}=Ra(i(a*u)),l=i(f*a),d=i(f*c),h=i(l*d*o),y;if(Yt(o*h,s)){let p=i(r*cs),b=i(t*cs);t=p,r=b,y=i(l*rl)}else y=d;Yt(t*h,s)&&(r=i(-r));let g=i((n-r)*y);return Yt(g,s)&&(g=i(-g)),ue.toBytes(g)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>ue.create(u),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(e.ZERO)}};Object.freeze(le.BASE);Object.freeze(le.ZERO);Object.freeze(le.prototype);Object.freeze(le);var il=Object.freeze({Point:le,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=is(e,r,64,nn);return il.deriveToCurve(n)},hashToScalar(e,t={DST:Ba}){let r=is(e,t.DST,64,nn);return La.create(qt(r))},deriveToCurve(e){St(e,64);let t=us(e.subarray(0,32)),r=Ca(t),n=us(e.subarray(32,64)),o=Ca(n);return new le(r.add(o))}});var Sr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},pn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Bt={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new pn("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 mn=32;var ds,al=(async()=>{try{return await Bt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function cl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Bt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Bt.get().subtle.verify({name:"Ed25519"},n,pt(t),pt(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ul(e,t,r){return Da.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Oa(e,t,r){return ds==null&&(ds=await al),ds?cl(e,t,r):ul(e,t,r)}function yn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var bn=class{type="Ed25519";raw;constructor(t){this.raw=hs(t,mn)}toMultihash(){return Ct.digest(Tt(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Oa(this.raw,r,t);return yn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ps(e){return e=hs(e,mn),new bn(e)}function hs(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new F(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var ll=Math.pow(2,7),dl=Math.pow(2,14),hl=Math.pow(2,21),ms=Math.pow(2,28),ys=Math.pow(2,35),bs=Math.pow(2,42),gs=Math.pow(2,49),H=128,dt=127;function It(e){if(e<ll)return 1;if(e<dl)return 2;if(e<hl)return 3;if(e<ms)return 4;if(e<ys)return 5;if(e<bs)return 6;if(e<gs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ye(e,t,r=0){switch(It(e)){case 8:t[r++]=e&255|H,e/=128;case 7:t[r++]=e&255|H,e/=128;case 6:t[r++]=e&255|H,e/=128;case 5:t[r++]=e&255|H,e/=128;case 4:t[r++]=e&255|H,e>>>=7;case 3:t[r++]=e&255|H,e>>>=7;case 2:t[r++]=e&255|H,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function pl(e,t,r=0){switch(It(e)){case 8:t.set(r++,e&255|H),e/=128;case 7:t.set(r++,e&255|H),e/=128;case 6:t.set(r++,e&255|H),e/=128;case 5:t.set(r++,e&255|H),e/=128;case 4:t.set(r++,e&255|H),e>>>=7;case 3:t.set(r++,e&255|H),e>>>=7;case 2:t.set(r++,e&255|H),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function ws(e,t){let r=e[t],n=0;if(n+=r&dt,r<H||(r=e[t+1],n+=(r&dt)<<7,r<H)||(r=e[t+2],n+=(r&dt)<<14,r<H)||(r=e[t+3],n+=(r&dt)<<21,r<H)||(r=e[t+4],n+=(r&dt)*ms,r<H)||(r=e[t+5],n+=(r&dt)*ys,r<H)||(r=e[t+6],n+=(r&dt)*bs,r<H)||(r=e[t+7],n+=(r&dt)*gs,r<H))return n;throw new RangeError("Could not decode varint")}function ml(e,t){let r=e.get(t),n=0;if(n+=r&dt,r<H||(r=e.get(t+1),n+=(r&dt)<<7,r<H)||(r=e.get(t+2),n+=(r&dt)<<14,r<H)||(r=e.get(t+3),n+=(r&dt)<<21,r<H)||(r=e.get(t+4),n+=(r&dt)*ms,r<H)||(r=e.get(t+5),n+=(r&dt)*ys,r<H)||(r=e.get(t+6),n+=(r&dt)*bs,r<H)||(r=e.get(t+7),n+=(r&dt)*gs,r<H))return n;throw new RangeError("Could not decode varint")}function gn(e,t,r=0){return t==null&&(t=lt(It(e))),t instanceof Uint8Array?Ye(e,t,r):pl(e,t,r)}function xs(e,t=0){return e instanceof Uint8Array?ws(e,t):ml(e,t)}var Es=new Float32Array([-0]),de=new Uint8Array(Es.buffer);function Ka(e,t,r){Es[0]=e,t[r]=de[0],t[r+1]=de[1],t[r+2]=de[2],t[r+3]=de[3]}function Na(e,t){return de[0]=e[t],de[1]=e[t+1],de[2]=e[t+2],de[3]=e[t+3],Es[0]}var vs=new Float64Array([-0]),ht=new Uint8Array(vs.buffer);function Ua(e,t,r){vs[0]=e,t[r]=ht[0],t[r+1]=ht[1],t[r+2]=ht[2],t[r+3]=ht[3],t[r+4]=ht[4],t[r+5]=ht[5],t[r+6]=ht[6],t[r+7]=ht[7]}function Fa(e,t){return ht[0]=e[t],ht[1]=e[t+1],ht[2]=e[t+2],ht[3]=e[t+3],ht[4]=e[t+4],ht[5]=e[t+5],ht[6]=e[t+6],ht[7]=e[t+7],vs[0]}var yl=BigInt(Number.MAX_SAFE_INTEGER),bl=BigInt(Number.MIN_SAFE_INTEGER),At=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 Se;if(t<yl&&t>bl)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>Ma&&(o=0n,++n>Ma&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Se;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):Se}},Se=new At(0,0);Se.toBigInt=function(){return 0n};Se.zzEncode=Se.zzDecode=function(){return this};Se.length=function(){return 1};var Ma=4294967296n;function qa(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 za(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 Ss(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 Pt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function wn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var As=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=pt(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,Pt(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 Pt(this,4);return wn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pt(this,4);return wn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pt(this,4);let t=Na(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Pt(this,4);let t=Fa(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 Pt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return za(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Pt(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 At(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 Pt(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 Pt(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 Pt(this,8);let t=wn(this.buf,this.pos+=4),r=wn(this.buf,this.pos+=4);return new At(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=ws(this.buf,this.pos);return this.pos+=It(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 Ar(e){return new As(e instanceof Uint8Array?e:e.subarray())}function yt(e,t,r){let n=Ar(e);return t.decode(n,void 0,r)}function _s(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return lt(i);o+i>t&&(n=lt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ae=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ts(){}var Is=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},gl=_s();function wl(e){return globalThis.Buffer!=null?lt(e):gl(e)}var Tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ae(Ts,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Ae(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Rs((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(xn,10,At.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=At.fromBigInt(t);return this._push(xn,r.length(),r)}uint64Number(t){return this._push(Ye,It(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=At.fromBigInt(t).zzEncode();return this._push(xn,r.length(),r)}sint64Number(t){let r=At.fromNumber(t).zzEncode();return this._push(xn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Bs,1,t?1:0)}fixed32(t){return this._push(_r,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=At.fromBigInt(t);return this._push(_r,4,r.lo)._push(_r,4,r.hi)}fixed64Number(t){let r=At.fromNumber(t);return this._push(_r,4,r.lo)._push(_r,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(Ka,4,t)}double(t){return this._push(Ua,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Bs,1,0):this.uint32(r)._push(El,r,t)}string(t){let r=qa(t);return r!==0?this.uint32(r)._push(Ss,r,t):this._push(Bs,1,0)}fork(){return this.states=new Is(this),this.head=this.tail=new Ae(Ts,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 Ae(Ts,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=wl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Bs(e,t,r){t[r]=e&255}function xl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Rs=class extends Ae{next;constructor(t,r){super(xl,t,r),this.next=void 0}};function xn(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 _r(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 El(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Tr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(vl,t,e),this},Tr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Sl,t,e),this});function vl(e,t,r){t.set(e,r)}function Sl(e,t,r){e.length<40?Ss(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(V(e),r)}function Cs(){return new Tr}function bt(e,t){let r=Cs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*gt(e,t,r){let n=Ar(e);yield*t.stream(n,void 0,"$",r)}var En={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function vn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Ls(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return vn("enum",En.VARINT,r,n,o)}function wt(e,t,r){return vn("message",En.LENGTH_DELIMITED,e,t,r)}var Rt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"},Br=class extends Error{code="ERR_MAX_SIZE";name="MaxSizeError"};var Z;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(Z||(Z={}));var Ds;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Ds||(Ds={}));(function(e){e.codec=()=>Ls(Ds)})(Z||(Z={}));var zt;(function(e){let t;e.codec=()=>(t==null&&(t=wt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Z.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Z.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Z.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(zt||(zt={}));var Os;(function(e){let t;e.codec=()=>(t==null&&(t=wt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),Z.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Z.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Z.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(Os||(Os={}));var Rr={};Et(Rr,{MAX_RSA_KEY_SIZE:()=>ks,generateRSAKeyPair:()=>Za,jwkToJWKKeyPair:()=>Ya,jwkToPkcs1:()=>Bl,jwkToPkix:()=>Us,jwkToRSAPrivateKey:()=>zs,pkcs1MessageToJwk:()=>Ks,pkcs1MessageToRSAPrivateKey:()=>Fs,pkcs1ToJwk:()=>Tl,pkcs1ToRSAPrivateKey:()=>ja,pkixMessageToJwk:()=>Ns,pkixMessageToRSAPublicKey:()=>qs,pkixToJwk:()=>Il,pkixToRSAPublicKey:()=>Ms});var Ge=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return et.createV1(114,this._multihash)}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return Wa(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=Rr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}sign(t,r){return $a(this.jwk,t,r)}};var ks=8192,Ps=18,Al=1062,_l=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Tl(e){let t=$t(e);return Ks(t)}function Ks(e){return{n:M(e[1],"base64url"),e:M(e[2],"base64url"),d:M(e[3],"base64url"),p:M(e[4],"base64url"),q:M(e[5],"base64url"),dp:M(e[6],"base64url"),dq:M(e[7],"base64url"),qi:M(e[8],"base64url"),kty:"RSA"}}function Bl(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 F("JWK was missing components");return ne([vt(Uint8Array.from([0])),vt(V(e.n,"base64url")),vt(V(e.e,"base64url")),vt(V(e.d,"base64url")),vt(V(e.p,"base64url")),vt(V(e.q,"base64url")),vt(V(e.dp,"base64url")),vt(V(e.dq,"base64url")),vt(V(e.qi,"base64url"))]).subarray()}function Il(e){let t=$t(e,{offset:0});return Ns(t)}function Ns(e){let t=$t(e[1],{offset:0});return{kty:"RSA",n:M(t[0],"base64url"),e:M(t[1],"base64url")}}function Us(e){if(e.n==null||e.e==null)throw new F("JWK was missing components");return ne([_l,Xr(ne([vt(V(e.n,"base64url")),vt(V(e.e,"base64url"))]))]).subarray()}function ja(e){let t=$t(e);return Fs(t)}function Fs(e){let t=Ks(e);return zs(t)}function Ms(e,t){if(e.byteLength>=Al)throw new Ce("Key size is too large");let r=$t(e,{offset:0});return qs(r,e,t)}function qs(e,t,r){let n=Ns(e);if(r==null){let o=Me(zt.encode({Type:Z.RSA,Data:t}));r=Ut(Ps,o)}return new Ge(n,r)}function zs(e){if(Xa(e)>ks)throw new F("Key size is too large");let t=Ya(e),r=Me(zt.encode({Type:Z.RSA,Data:Us(t.publicKey)})),n=Ut(Ps,r);return new Ir(t.privateKey,new Ge(t.publicKey,n))}async function Za(e){if(e>ks)throw new F("Key size is too large");let t=await Ga(e),r=Me(zt.encode({Type:Z.RSA,Data:Us(t.publicKey)})),n=Ut(Ps,r);return new Ir(t.privateKey,new Ge(t.publicKey,n))}function Ya(e){if(e==null)throw new F("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Ga(e,t){let r=await Bt.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 Rl(r,t);return{privateKey:n[0],publicKey:n[1]}}async function $a(e,t,r){let n=await Bt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Bt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,pt(t instanceof Uint8Array?t:t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Wa(e,t,r,n){let o=await Bt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Bt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,pt(t),pt(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function Rl(e,t){if(e.privateKey==null||e.publicKey==null)throw new F("Private and public key are required");let r=await Promise.all([Bt.get().subtle.exportKey("jwk",e.privateKey),Bt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Xa(e){if(e.kty!=="RSA")throw new F("invalid key type");if(e.n==null)throw new F("invalid key modulus");return V(e.n,"base64url").length*8}var Sn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Qr(t),St(r,void 0,"key"),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 n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),jt(o)}update(t){return Fe(this),this.iHash.update(t),this}digestInto(t){Fe(this),Jr(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(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()}},Qa=(()=>{let e=((t,r,n)=>new Sn(t,r).update(n).digest());return e.create=(t,r)=>new Sn(t,r),e})();var Ja=(e,t)=>(e+(e>=0?t:-t)/tc)/t;function Cl(e,t,r){Ve("scalar",e,Vt,r);let[[n,o],[s,i]]=t,a=Ja(i*e,r),c=Ja(-o*e,r),u=e-a*n-c*s,f=-a*o-c*i,l=u<Vt,d=f<Vt;l&&(u=-u),d&&(f=-f);let h=wr(Math.ceil(He(r)/2))+he;if(u<Vt||u>=h||f<Vt||f>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:d,k2:f}}function Hs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Vs(e,t){kt(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Dt(r.lowS,"lowS"),Dt(r.prehash,"prehash"),r.format!==void 0&&Hs(r.format),r}var $s=class extends Error{constructor(t=""){super(t)}},Kt={Err:$s,_tlv:{encode:(e,t)=>{let{Err:r}=Kt;if(Ot(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=br(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?br(o.length/2|128):"";return br(e)+s+o+t},decode(e,t){let{Err:r}=Kt;t=q(t,void 0,"DER data");let n=0;if(e<0||e>255)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 u=t.subarray(n,n+c);if(u.length!==c)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+=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}=Kt;if(an(e),e<Vt)throw new t("integer: negative integers are not allowed");let r=br(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}=Kt;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return we(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Kt,o=q(e,void 0,"signature"),{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:u,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(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Kt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Kt._tlv);Object.freeze(Kt._int);Object.freeze(Kt);var Vt=BigInt(0),he=BigInt(1),tc=BigInt(2),An=BigInt(3),Ll=BigInt(4);function ec(e,t={}){let r=ln("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;kt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=nc(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(K,m,w){if(u&&m.is0())return Uint8Array.of(0);let{x:S,y:E}=m.toAffine(),x=n.toBytes(S);if(Dt(w,"isCompressed"),w){l();let _=!n.isOdd(E);return nt(rc(_),x)}else return nt(Uint8Array.of(4),x,n.toBytes(E))}function h(K){q(K,void 0,"Point");let{publicKey:m,publicKeyUncompressed:w}=f,S=K.length,E=K[0],x=K.subarray(1);if(u&&S===1&&E===0)return{x:n.ZERO,y:n.ZERO};if(S===m&&(E===2||E===3)){let _=n.fromBytes(x);if(!n.isValid(_))throw new Error("bad point: is not on curve, wrong x");let I=p(_),T;try{T=n.sqrt(I)}catch(U){let z=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}l();let C=n.isOdd(T);return(E&1)===1!==C&&(T=n.neg(T)),{x:_,y:T}}else if(S===w&&E===4){let _=n.BYTES,I=n.fromBytes(x.subarray(0,_)),T=n.fromBytes(x.subarray(_,_*2));if(!b(I,T))throw new Error("bad point: is not on curve");return{x:I,y:T}}else throw new Error(`bad point: got length ${S}, expected compressed=${m} or uncompressed=${w}`)}let y=t.toBytes===void 0?d:t.toBytes,g=t.fromBytes===void 0?h:t.fromBytes;function p(K){let m=n.sqr(K),w=n.mul(m,K);return n.add(n.add(w,n.mul(K,s.a)),s.b)}function b(K,m){let w=n.sqr(m),S=p(K);return n.eql(w,S)}if(!b(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,An),Ll),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,A)))throw new Error("bad curve params: a or b");function L(K,m,w=!1){if(!n.isValid(m)||w&&n.is0(m))throw new Error(`bad point coordinate ${K}`);return m}function R(K){if(!(K instanceof B))throw new Error("Weierstrass Point expected")}function k(K){if(!c||!c.basises)throw new Error("no endo");return Cl(K,c.basises,o.ORDER)}function D(K,m,w,S,E){return w=new B(n.mul(w.X,K),w.Y,w.Z),m=Er(S,m),w=Er(E,w),m.add(w)}class B{static BASE=new B(s.Gx,s.Gy,n.ONE);static ZERO=new B(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,w,S){this.X=L("x",m),this.Y=L("y",w,!0),this.Z=L("z",S),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){let{x:w,y:S}=m||{};if(!m||!n.isValid(w)||!n.isValid(S))throw new Error("invalid affine point");if(m instanceof B)throw new Error("projective point not allowed");return n.is0(w)&&n.is0(S)?B.ZERO:new B(w,S,n.ONE)}static fromBytes(m){let w=B.fromAffine(g(q(m,void 0,"point")));return w.assertValidity(),w}static fromHex(m){return B.fromBytes(ze(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,w=!0){return $.createCache(this,m),w||this.multiply(An),this}assertValidity(){let m=this;if(m.is0()){if(t.allowInfinityPoint&&n.is0(m.X)&&n.eql(m.Y,n.ONE)&&n.is0(m.Z))return;throw new Error("bad point: ZERO")}let{x:w,y:S}=m.toAffine();if(!n.isValid(w)||!n.isValid(S))throw new Error("bad point: x or y not field elements");if(!b(w,S))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){R(m);let{X:w,Y:S,Z:E}=this,{X:x,Y:_,Z:I}=m,T=n.eql(n.mul(w,I),n.mul(x,E)),C=n.eql(n.mul(S,I),n.mul(_,E));return T&&C}negate(){return new B(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:w}=s,S=n.mul(w,An),{X:E,Y:x,Z:_}=this,I=n.ZERO,T=n.ZERO,C=n.ZERO,O=n.mul(E,E),U=n.mul(x,x),z=n.mul(_,_),N=n.mul(E,x);return N=n.add(N,N),C=n.mul(E,_),C=n.add(C,C),I=n.mul(m,C),T=n.mul(S,z),T=n.add(I,T),I=n.sub(U,T),T=n.add(U,T),T=n.mul(I,T),I=n.mul(N,I),C=n.mul(S,C),z=n.mul(m,z),N=n.sub(O,z),N=n.mul(m,N),N=n.add(N,C),C=n.add(O,O),O=n.add(C,O),O=n.add(O,z),O=n.mul(O,N),T=n.add(T,O),z=n.mul(x,_),z=n.add(z,z),O=n.mul(z,N),I=n.sub(I,O),C=n.mul(z,U),C=n.add(C,C),C=n.add(C,C),new B(I,T,C)}add(m){R(m);let{X:w,Y:S,Z:E}=this,{X:x,Y:_,Z:I}=m,T=n.ZERO,C=n.ZERO,O=n.ZERO,U=s.a,z=n.mul(s.b,An),N=n.mul(w,x),rt=n.mul(S,_),ot=n.mul(E,I),st=n.add(w,S),Q=n.add(x,_);st=n.mul(st,Q),Q=n.add(N,rt),st=n.sub(st,Q),Q=n.add(w,E);let xt=n.add(x,I);return Q=n.mul(Q,xt),xt=n.add(N,ot),Q=n.sub(Q,xt),xt=n.add(S,E),T=n.add(_,I),xt=n.mul(xt,T),T=n.add(rt,ot),xt=n.sub(xt,T),O=n.mul(U,Q),T=n.mul(z,ot),O=n.add(T,O),T=n.sub(rt,O),O=n.add(rt,O),C=n.mul(T,O),rt=n.add(N,N),rt=n.add(rt,N),ot=n.mul(U,ot),Q=n.mul(z,Q),rt=n.add(rt,ot),ot=n.sub(N,ot),ot=n.mul(U,ot),Q=n.add(Q,ot),N=n.mul(rt,Q),C=n.add(C,N),N=n.mul(xt,Q),T=n.mul(st,T),T=n.sub(T,N),N=n.mul(st,rt),O=n.mul(xt,O),O=n.add(O,N),new B(T,C,O)}subtract(m){return R(m),this.add(m.negate())}is0(){return this.equals(B.ZERO)}multiply(m){let{endo:w}=t;if(!o.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let S,E,x=_=>$.cached(this,_,I=>ve(B,I));if(w){let{k1neg:_,k1:I,k2neg:T,k2:C}=k(m),{p:O,f:U}=x(I),{p:z,f:N}=x(C);E=U.add(N),S=D(w.beta,O,z,_,T)}else{let{p:_,f:I}=x(m);S=_,E=I}return ve(B,[S,E])[0]}multiplyUnsafe(m){let{endo:w}=t,S=this,E=m;if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(E===Vt||S.is0())return B.ZERO;if(E===he)return S;if($.hasCache(this))return this.multiply(E);if(w){let{k1neg:x,k1:_,k2neg:I,k2:T}=k(E),{p1:C,p2:O}=Aa(B,S,_,T);return D(w.beta,C,O,x,I)}else return $.unsafe(S,E)}toAffine(m){let w=this,S=m,{X:E,Y:x,Z:_}=w;if(n.eql(_,n.ONE))return{x:E,y:x};let I=w.is0();S==null&&(S=I?n.ONE:n.inv(_));let T=n.mul(E,S),C=n.mul(x,S),O=n.mul(_,S);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:T,y:C}}isTorsionFree(){let{isTorsionFree:m}=t;return i===he?!0:m?m(B,this):$.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return i===he?this:m?m(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===he?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return Dt(m,"isCompressed"),this.assertValidity(),y(B,this,m)}toHex(m=!0){return qe(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let P=o.BITS,$=new je(B,t.endo?Math.ceil(P/2):P);return P>=8&&B.BASE.precompute(8),Object.freeze(B.prototype),Object.freeze(B),B}function rc(e){return Uint8Array.of(e?2:3)}function nc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Dl(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?yr:t.randomBytes,o=Object.assign(nc(e.Fp,r),{seed:Math.max(ts(r.ORDER),16)});function s(h){try{let y=r.fromBytes(h);return r.isValidNot0(y)}catch{return!1}}function i(h,y){let{publicKey:g,publicKeyUncompressed:p}=o;try{let b=h.length;return y===!0&&b!==g||y===!1&&b!==p?!1:!!e.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,es(q(h,o.seed,"seed"),r.ORDER)}function c(h,y=!0){return e.BASE.multiply(r.fromBytes(h)).toBytes(y)}function u(h){let{secretKey:y,publicKey:g,publicKeyUncompressed:p}=o,b=r._lengths;if(!ge(h))return;let v=q(h,void 0,"key").length,A=v===g||v===p,L=v===y||!!b?.includes(v);if(!(A&&L))return A}function f(h,y,g=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(y)===!1)throw new Error("second arg must be public key");let p=r.fromBytes(h);return e.fromBytes(y).multiply(p).toBytes(g)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},d=dn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:d,Point:e,utils:l,lengths:o})}function oc(e,t,r={}){let n=t;Qr(n),kt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?yr:r.randomBytes,s=r.hmac===void 0?(E,x)=>Qa(n,E,x):r.hmac,{Fp:i,Fn:a}=e,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:d,utils:h,lengths:y}=Dl(e,r),g={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},p=c*tc+he<i.ORDER;function b(E){let x=c>>he;return E>x}function v(E,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return x}function A(){if(p)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function L(E,x){Hs(x);let _=y.signature,I=x==="compact"?_:x==="recovered"?_+1:void 0;return q(E,I)}class R{r;s;recovery;constructor(x,_,I){if(this.r=v("r",x),this.s=v("s",_),I!=null){if(A(),![0,1,2,3].includes(I))throw new Error("invalid recovery id");this.recovery=I}Object.freeze(this)}static fromBytes(x,_=g.format){L(x,_);let I;if(_==="der"){let{r:U,s:z}=Kt.toSig(q(x));return new R(U,z)}_==="recovered"&&(I=x[0],_="compact",x=x.subarray(1));let T=y.signature/2,C=x.subarray(0,T),O=x.subarray(T,T*2);return new R(a.fromBytes(C),a.fromBytes(O),I)}static fromHex(x,_){return this.fromBytes(ze(x),_)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new R(this.r,this.s,x)}recoverPublicKey(x){let{r:_,s:I}=this,T=this.assertRecovery(),C=T===2||T===3?_+c:_;if(!i.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let O=i.toBytes(C),U=e.fromBytes(nt(rc((T&1)===0),O)),z=a.inv(C),N=D(q(x,void 0,"msgHash")),rt=a.create(-N*z),ot=a.create(I*z),st=e.BASE.multiplyUnsafe(rt).add(U.multiplyUnsafe(ot));if(st.is0())throw new Error("invalid recovery: point at infinify");return st.assertValidity(),st}hasHighS(){return b(this.s)}toBytes(x=g.format){if(Hs(x),x==="der")return ze(Kt.hexFromSig(this));let{r:_,s:I}=this,T=a.toBytes(_),C=a.toBytes(I);return x==="recovered"?(A(),nt(Uint8Array.of(this.assertRecovery()),T,C)):nt(T,C)}toHex(x){return qe(this.toBytes(x))}}Object.freeze(R.prototype),Object.freeze(R);let k=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let _=we(x),I=x.length*8-u;return I>0?_>>BigInt(I):_}:r.bits2int,D=r.bits2int_modN===void 0?function(x){return a.create(k(x))}:r.bits2int_modN,B=wr(u);function P(E){return Ve("num < 2^"+u,E,Vt,B),a.toBytes(E)}function $(E,x){return q(E,void 0,"message"),x?q(n(E),void 0,"prehashed message"):E}function K(E,x,_){let{lowS:I,prehash:T,extraEntropy:C}=Vs(_,g);E=$(E,T);let O=D(E),U=a.fromBytes(x);if(!a.isValidNot0(U))throw new Error("invalid private key");let z=[P(U),P(O)];if(C!=null&&C!==!1){let st=C===!0?o(y.secretKey):C;z.push(q(st,void 0,"extraEntropy"))}let N=nt(...z),rt=O;function ot(st){let Q=k(st);if(!a.isValidNot0(Q))return;let xt=a.inv(Q),Re=e.BASE.multiply(Q).toAffine(),rr=a.create(Re.x);if(rr===Vt)return;let Hr=a.create(xt*a.create(rt+rr*U));if(Hr===Vt)return;let yi=(Re.x===rr?0:2)|Number(Re.y&he),bi=Hr;return I&&b(Hr)&&(bi=a.neg(Hr),yi^=1),new R(rr,bi,p?void 0:yi)}return{seed:N,k2sig:ot}}function m(E,x,_={}){let{seed:I,k2sig:T}=K(E,x,_);return aa(n.outputLen,a.BYTES,s)(I,T).toBytes(_.format)}function w(E,x,_,I={}){let{lowS:T,prehash:C,format:O}=Vs(I,g);if(_=q(_,void 0,"publicKey"),x=$(x,C),!ge(E)){let U=E instanceof R?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}L(E,O);try{let U=R.fromBytes(E,O),z=e.fromBytes(_);if(T&&U.hasHighS())return!1;let{r:N,s:rt}=U,ot=D(x),st=a.inv(rt),Q=a.create(ot*st),xt=a.create(N*st),Re=e.BASE.multiplyUnsafe(Q).add(z.multiplyUnsafe(xt));return Re.is0()?!1:a.create(Re.x)===N}catch{return!1}}function S(E,x,_={}){let{prehash:I}=Vs(_,g);return x=$(x,I),R.fromBytes(E,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:d,utils:h,lengths:y,Point:e,sign:m,verify:w,recoverPublicKey:S,Signature:R,hash:n})}var js={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ol={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var sc=BigInt(2);function kl(e){let t=js.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=j(f,r,t)*f%t,d=j(l,r,t)*f%t,h=j(d,sc,t)*u%t,y=j(h,o,t)*h%t,g=j(y,s,t)*y%t,p=j(g,a,t)*g%t,b=j(p,c,t)*p%t,v=j(b,a,t)*g%t,A=j(v,r,t)*f%t,L=j(A,i,t)*y%t,R=j(L,n,t)*u%t,k=j(R,sc,t);if(!Ws.eql(Ws.sqr(k),e))throw new Error("Cannot find square root");return k}var Ws=$e(js.p,{sqrt:kl}),Pl=ec(js,{Fp:Ws,endo:Ol}),Xe=oc(Pl,Me);function ic(e,t,r,n){let o=cr.digest(r instanceof Uint8Array?r:r.subarray());if(yn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Xe.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Sr(String(s))});try{return n?.signal?.throwIfAborted(),Xe.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Sr(String(s))}}var _n=class{type="secp256k1";raw;_key;constructor(t){this._key=cc(t),this.raw=ac(this._key)}toMultihash(){return Ct.digest(Tt(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:W(this.raw,t.raw)}verify(t,r,n){return ic(this._key,r,t,n)}};function Zs(e){return new _n(e)}function ac(e){return Xe.Point.fromBytes(e).toBytes()}function cc(e){try{return Xe.Point.fromBytes(e),e}catch(t){throw new Ce(String(t))}}function Tn(e,t){let{Type:r,Data:n}=zt.decode(e),o=n??new Uint8Array;switch(r){case Z.RSA:return Ms(o,t);case Z.Ed25519:return ps(o);case Z.secp256k1:return Zs(o);case Z.ECDSA:return No(o);default:throw new pe}}function uc(e){let{Type:t,Data:r}=zt.decode(e.digest),n=r??new Uint8Array;switch(t){case Z.Ed25519:return ps(n);case Z.secp256k1:return Zs(n);case Z.ECDSA:return No(n);default:throw new pe}}function Tt(e){return zt.encode({Type:Z[e.type],Data:e.raw})}var fc=Symbol.for("nodejs.util.inspect.custom"),Kl=114,Cr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[jr]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return et.createV1(Kl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return W(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return W(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[fc](){return`PeerId(${this.toString()})`}},Lr=class extends Cr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Dr=class extends Cr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Or=class extends Cr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Nl=2336,kr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ct.digest(V(this.url))}[fc](){return`PeerId(${this.url})`}[jr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return et.createV1(Nl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=M(t)),t.toString()===this.toString())}};var Ul=114,lc=2336;function dc(e){if(e.type==="Ed25519")return new Dr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Or({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Lr({multihash:e.toCID().multihash,publicKey:e});throw new pe}function Ys(e){if(Ml(e))return new Lr({multihash:e});if(Fl(e))try{let t=uc(e);if(t.type==="Ed25519")return new Dr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Or({multihash:e,publicKey:t})}catch{let r=M(e.digest);return new kr(new URL(r))}throw new Wr("Supplied PeerID Multihash is invalid")}function Bn(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Ul&&e.code!==lc)throw new $r("Supplied PeerID CID is invalid");if(e.code===lc){let t=M(e.multihash.digest);return new kr(new URL(t))}return Ys(e.multihash)}function Fl(e){return e.code===Ct.code}function Ml(e){return e.code===cr.code}var Pr;(function(e){let t;e.codec=()=>(t==null&&(t=wt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:J(0),payloadType:J(0),payload:J(0),signature:J(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(Pr||(Pr={}));var In=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Qe=class e{static createFromProtobuf=t=>{let r=Pr.decode(t),n=Tn(r.publicKey);return new e({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(t,r,n)=>{if(r==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=hc(o,s,i),c=await r.sign(a.subarray(),n);return new e({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,r,n)=>{let o=e.createFromProtobuf(t);if(!await o.validate(r,n))throw new In("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:r,payloadType:n,payload:o,signature:s}=t;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Pr.encode({publicKey:Tt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:W(this.marshal(),t.marshal())}async validate(t,r){let n=hc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},hc=(e,t,r)=>{let n=V(e),o=gn(n.byteLength),s=gn(t.length),i=gn(r.length);return new mt(o,n,s,t,i,r)};var ft=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Xt=class extends Error{static name="ValidationError";name="ValidationError"},Rn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Cn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Ln=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(f===void 0)break;if(s*=t,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ql=45,zl=15,Dn=new Ln;function pc(e){if(!(e.length>zl))return Dn.new(e).parseWith(()=>Dn.readIPv4Addr())}function mc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>ql))return Dn.new(e).parseWith(()=>Dn.readIPv6Addr())}function On(e){return!!pc(e)}function yc(e){return!!mc(e)}function Xs(e){return t=>M(t,e)}function Qs(e){return t=>V(t,e)}function Je(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function _e(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function bc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=V(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=_e(n);return Ft([r,o],r.length+o.length)}function gc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=Nt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=_e(n);return Ft([r,o],r.length+o.length)}function Js(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=M(t,"base32"),o=Je(r);return`${n}:${o}`}var ti=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new ft("Invalid byte value in IP address");t[n]=o}),t},wc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=On(r[n]),i;s&&(i=ti(r[n]),r[n]=M(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,M(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new ft("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},xc=function(e){if(e.byteLength!==4)throw new ft("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Ec=function(e){if(e.byteLength!==16)throw new ft("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${r}"`)}};function vc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ft(`Invalid IPv6 address "${e}"`)}}var Gs=Object.values(ur).map(e=>e.decoder),Vl=(function(){let e=Gs[0].or(Gs[1]);return Gs.slice(2).forEach(t=>e=e.or(t)),e})();function Sc(e){return Vl.decode(e)}function Ac(e){return t=>e.encoder.encode(t)}function Hl(e){if(parseInt(e).toString()!==e)throw new Xt("Value must be an integer")}function $l(e){if(e<0)throw new Xt("Value must be a positive integer, or zero")}function Wl(e){return t=>{if(t>e)throw new Xt(`Value must be smaller than or equal to ${e}`)}}function jl(...e){return t=>{for(let r of e)r(t)}}var Kr=jl(Hl,$l,Wl(65535));var at=-1,ei=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Cn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Qt=new ei,Od=[{code:4,name:"ip4",size:32,valueToBytes:ti,bytesToValue:xc,validate:e=>{if(!On(e))throw new Xt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:_e,bytesToValue:Je,validate:Kr},{code:273,name:"udp",size:16,valueToBytes:_e,bytesToValue:Je,validate:Kr},{code:33,name:"dccp",size:16,valueToBytes:_e,bytesToValue:Je,validate:Kr},{code:41,name:"ip6",size:128,valueToBytes:wc,bytesToValue:Ec,stringToValue:vc,validate:e=>{if(!yc(e))throw new Xt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:at},{code:43,name:"ipcidr",size:8,bytesToValue:Xs("base10"),valueToBytes:Qs("base10")},{code:53,name:"dns",size:at},{code:54,name:"dns4",size:at},{code:55,name:"dns6",size:at},{code:56,name:"dnsaddr",size:at},{code:132,name:"sctp",size:16,valueToBytes:_e,bytesToValue:Je,validate:Kr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:at,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:at,bytesToValue:Xs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Qs("base58btc")(e):et.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Js,valueToBytes:bc},{code:445,name:"onion3",size:296,bytesToValue:Js,valueToBytes:gc},{code:446,name:"garlic64",size:at},{code:447,name:"garlic32",size:at},{code:448,name:"tls"},{code:449,name:"sni",size:at},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:at,bytesToValue:Ac(Ao),valueToBytes:Sc},{code:480,name:"http"},{code:481,name:"http-path",size:at,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:at}];Od.forEach(e=>{Qt.addProtocol(e)});function _c(e){let t=[],r=0;for(;r<e.length;){let n=xs(e,r),o=Qt.getProtocol(n),s=It(n),i=kd(o,e,r+s),a=0;i>0&&o.size===at&&(a=It(i));let c=s+a+i,u={code:n,name:o.name,bytes:pt(e.subarray(r,r+c))};if(i>0){let f=r+s+a,l=e.subarray(f,f+i);u.value=o.bytesToValue?.(l)??M(l)}t.push(u),r+=c}return t}function Tc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Qt.getProtocol(n.code),s=It(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===at&&(c=It(a)));let u=new Uint8Array(s+c+a),f=0;Ye(n.code,u,f),f+=s,i!=null&&(o.size===at&&(Ye(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Ft(r,t)}function Bc(e){if(e.charAt(0)!=="/")throw new ft('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=Qt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ft(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ft(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ft("Incomplete multiaddr");return t}function Ic(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Qt.getProtocol(t.code);if(r==null)throw new ft(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function kd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:xs(t,r)}var Pd=Symbol.for("nodejs.util.inspect.custom"),ni=Symbol.for("@multiformats/multiaddr");function Kd(e){if(e==null&&(e="/"),Pn(e))return e.getComponents();if(e instanceof Uint8Array)return _c(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Bc(e);if(Array.isArray(e))return e;throw new ft("Must be a string, Uint8Array, Component[], or another Multiaddr")}var kn=class e{[ni]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Kd(t),r.validate!==!1&&Nd(this)}get bytes(){return this.#r==null&&(this.#r=Tc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Ic(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Rn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return W(this.bytes,t.bytes)}[Pd](){return`Multiaddr(${this.toString()})`}};function Nd(e){e.getComponents().forEach(t=>{let r=Qt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Pn(e){return!!e?.[ni]}function Te(e){return new kn(e)}var Rc="libp2p-peer-record",Cc=Uint8Array.from([3,1]);var Nr;(function(e){let t;(function(i){let a;i.codec=()=>(a==null&&(a=wt((l,d,h={})=>{h.lengthDelimited!==!1&&d.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(d.uint32(10),d.bytes(l.multiaddr)),h.lengthDelimited!==!1&&d.ldelim()},(l,d,h={})=>{let y={multiaddr:J(0)},g=d==null?l.len:l.pos+d;for(;l.pos<g;){let p=l.uint32();p>>>3===1?y.multiaddr=l.bytes():l.skipType(p&7)}return y},function*(l,d,h,y={}){let g=d==null?l.len:l.pos+d;for(;l.pos<g;){let p=l.uint32();p>>>3===1?yield{field:`${h}.multiaddr`,value:l.bytes()}:l.skipType(p&7)}})),a);function c(l){return bt(l,i.codec())}i.encode=c;function u(l,d){return yt(l,i.codec(),d)}i.decode=u;function f(l,d){return gt(l,i.codec(),d)}i.stream=f})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=wt((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let u of i.addresses)a.uint32(26),e.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:J(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Rt('Decode error - repeated field "addresses" had too many elements');u.addresses.push(e.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Rt('Streaming decode error - repeated field "addresses" had too many elements');for(let h of e.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...h,index:f.addresses};f.addresses++;break}default:{i.skipType(d&7);break}}}})),r);function n(i){return bt(i,e.codec())}e.encode=n;function o(i,a){return yt(i,e.codec(),a)}e.decode=o;function s(i,a){return gt(i,e.codec(),a)}e.stream=s})(Nr||(Nr={}));function Lc(e,t){let r=(n,o)=>n.toString().localeCompare(o.toString());return e.length!==t.length?!1:(t.sort(r),e.sort(r).every((n,o)=>t[o].equals(n)))}var Be=class e{static createFromProtobuf=t=>{let r=Nr.decode(t),n=Ys(Ne(r.peerId)),o=(r.addresses??[]).map(i=>Te(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Rc;static CODEC=Cc;peerId;multiaddrs;seqNumber;domain=e.DOMAIN;codec=e.CODEC;marshaled;constructor(t){let{peerId:r,multiaddrs:n,seqNumber:o}=t;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Nr.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof e)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!Lc(this.multiaddrs,t.multiaddrs))}};function Ud(e){return e[Symbol.asyncIterator]!=null}function Fd(e){if(Ud(e))return(async()=>{let r=[];for await(let n of e)r.push(n);return r})();let t=[];for(let r of e)t.push(r);return t}var Dc=Fd;function Kn(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}var Ur=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[r,n]of t.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return Kn(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((r,n)=>{t(r.value,r.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,r){this.map.set(t.toString(),{key:t,value:r})}keys(){return Kn(this.map.values(),t=>t.key)}values(){return Kn(this.map.values(),t=>t.value)}get size(){return this.map.size}};function Nn(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Un=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},tr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Un(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new Un(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var oi=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Oc(e={}){return Md(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function Md(e,t){t=t??{};let r=t.onEnd,n=new tr,o,s,i,a=Nn(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,b)=>{s=v=>{s=null,n.push(v);try{p(e(n))}catch(A){b(A)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Nn()})}},u=p=>s!=null?s(p):(n.push(p),o),f=p=>(n=new tr,s!=null?s({error:p}):(n.push({error:p}),o)),l=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:p})},d=p=>i?o:(i=!0,p!=null?f(p):u({done:!0})),h=()=>(n=new tr,d(),{done:!0}),y=p=>(d(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:y,push:l,end:d,get readableLength(){return n.size},onEmpty:async p=>{let b=p?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let v,A;b!=null&&(v=new Promise((L,R)=>{A=()=>{R(new oi)},b.addEventListener("abort",A)}));try{await Promise.race([a.promise,v])}finally{A!=null&&b!=null&&b?.removeEventListener("abort",A)}}},r==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(p){return g.throw(p),r!=null&&(r(p),r=void 0),{done:!0}},return(){return g.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(p){return g.end(p),r!=null&&(r(p),r=void 0),o},get readableLength(){return g.readableLength},onEmpty:p=>g.onEmpty(p)},o}function qd(e){return e.reason}async function kc(e,t,r){if(t==null)return e;let n=r?.translateError??qd;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var si=class extends Ur{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(t,r){return super.set(t,r),this.updateComponentMetric(),this}delete(t){let r=super.delete(t);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ii(e){let{name:t,metrics:r}=e,n;return r!=null?n=new si({name:t,metrics:r}):n=new Ur,n}var _t=class extends Error{static name="AbortError";name="AbortError";constructor(t="The operation was aborted",...r){super(t,...r)}};async function Fn(e,t,r,n){let o=new _t(n?.errorMessage);n?.errorCode!=null&&(o.code=n.errorCode);let s=n?.errorEvent??"error";return r?.aborted===!0?Promise.reject(o):new Promise((i,a)=>{function c(){ci(r,"abort",l),ci(e,t,u),ci(e,s,f)}let u=d=>{try{if(n?.filter?.(d)===!1)return}catch(h){c(),a(h);return}c(),i(d)},f=d=>{if(c(),d instanceof Error){a(d);return}a(d.detail??n?.error??new Error(`The "${n?.errorEvent}" event was emitted but the event had no '.detail' field. Pass an 'error' option to race-event to change this message.`))},l=()=>{c(),a(o)};ai(r,"abort",l),ai(e,t,u),ai(e,s,f)})}function ai(e,t,r){e!=null&&(Pc(e)?e.addEventListener(t,r):e.addListener(t,r))}function ci(e,t,r){e!=null&&(Pc(e)?e.removeEventListener(t,r):e.removeListener(t,r))}function Pc(e){return typeof e.addEventListener=="function"&&typeof e.removeEventListener=="function"}var Mn=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var qn=class{deferred;signal;constructor(t){this.signal=t,this.deferred=Promise.withResolvers(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new _t)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function zd(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var zn=class{id;fn;options;recipients;status;timeline;controller;constructor(t,r){this.id=zd(),this.status="queued",this.fn=t,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new _t),this.cleanup())}async join(t={}){let r=new qn(t.signal);return this.recipients.push(r),t.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await kc(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(r=>{r.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};function ui(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Fr=class extends De{concurrency;maxSize;queue;pending;sort;autoStart;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.autoStart=t.autoStart??!0,this.sort=t.sort,this.queue=[],this.emitEmpty=ui(this.emitEmpty.bind(this),1),this.emitIdle=ui(this.emitIdle.bind(this),1)}[Symbol.asyncIterator](){return this.toGenerator()}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}tryToStartAnother(){if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let t;for(let r of this.queue)if(r.status==="queued"){t=r;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===t){this.queue.splice(r,1);break}this.pending--,this.safeDispatchEvent("next"),this.autoStart&&this.tryToStartAnother()}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}start(){this.autoStart===!1&&(this.autoStart=!0,this.tryToStartAnother())}pause(){this.autoStart=!1}async add(t,r){if(r?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Mn;let n=new zn(t,r);return this.enqueue(n),this.safeDispatchEvent("add"),this.autoStart&&this.tryToStartAnother(),n.join(r).then(o=>(this.safeDispatchEvent("success",{detail:{job:n,result:o}}),o)).catch(o=>{if(n.status==="queued"){for(let s=0;s<this.queue.length;s++)if(this.queue[s]===n){this.queue.splice(s,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:o}}),o})}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(t=>{t.abort(new _t)}),this.clear()}async onEmpty(t){this.size!==0&&await Fn(this,"empty",t?.signal)}async onSizeLessThan(t,r){this.size<t||await Fn(this,"next",r?.signal,{filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Fn(this,"idle",t?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let r=Oc({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},o=c=>{c.detail!=null&&r.push(c.detail.result)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new _t("Queue aborted"))};this.addEventListener("success",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("success",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var Vn="lock:worker:request-read",Hn="lock:worker:abort-read-request",$n="lock:worker:release-read",Wn="lock:master:grant-read",jn="lock:master:error-read",Zn="lock:worker:request-write",Yn="lock:worker:abort-write-request",Gn="lock:worker:release-write",Xn="lock:master:grant-write",Qn="lock:master:error-write",Jn="lock:worker:finalize",to="mortice",Kc={singleProcess:!1};var fi=(e,t,r,n,o,s,i,a,c)=>u=>{if(u.data==null)return;let f={type:u.data.type,name:u.data.name,identifier:u.data.identifier};f.type===o&&e.safeDispatchEvent(r,{detail:{name:f.name,identifier:f.identifier,handler:async()=>{t.postMessage({type:c,name:f.name,identifier:f.identifier}),await new Promise(l=>{let d=h=>{if(h?.data==null)return;let y={type:h.data.type,name:h.data.name,identifier:h.data.identifier};y.type===a&&y.identifier===f.identifier&&(t.removeEventListener("message",d),l())};t.addEventListener("message",d)})},onError:l=>{t.postMessage({type:i,name:f.name,identifier:f.identifier,error:{message:l.message,name:l.name,stack:l.stack}})}}}),f.type===s&&e.safeDispatchEvent(n,{detail:{name:f.name,identifier:f.identifier}}),f.type===Jn&&e.safeDispatchEvent("finalizeRequest",{detail:{name:f.name}})};var Nc=(e=10)=>Math.random().toString().substring(2,e+2);var eo=class{name;channel;constructor(t){this.name=t,this.channel=new BroadcastChannel(to)}readLock(t){return this.sendRequest(Vn,Hn,Wn,jn,$n,t)}writeLock(t){return this.sendRequest(Zn,Yn,Xn,Qn,Gn,t)}finalize(){this.channel.postMessage({type:Jn,name:this.name}),this.channel.close()}async sendRequest(t,r,n,o,s,i){i?.signal?.throwIfAborted();let a=Nc();return this.channel.postMessage({type:t,identifier:a,name:this.name}),new Promise((c,u)=>{let f=()=>{this.channel.postMessage({type:r,identifier:a,name:this.name})};i?.signal?.addEventListener("abort",f,{once:!0});let l=d=>{if(d.data?.identifier===a&&(d.data?.type===n&&(this.channel.removeEventListener("message",l),i?.signal?.removeEventListener("abort",f),c(()=>{this.channel.postMessage({type:s,identifier:a,name:this.name})})),d.data.type===o)){this.channel.removeEventListener("message",l),i?.signal?.removeEventListener("abort",f);let h=new Error;d.data.error!=null&&(h.message=d.data.error.message,h.name=d.data.error.name,h.stack=d.data.error.stack),u(h)}};this.channel.addEventListener("message",l)})}};var Uc=e=>{if(e=Object.assign({},Kc,e),!!globalThis.document||e.singleProcess){let r=new BroadcastChannel(to),n=new De;return r.addEventListener("message",fi(n,r,"requestReadLock","abortReadLockRequest",Vn,Hn,jn,$n,Wn)),r.addEventListener("message",fi(n,r,"requestWriteLock","abortWriteLockRequest",Zn,Yn,Qn,Gn,Xn)),n}return new eo(e.name)};var Ie=new Map,Mr;function Fc(e){return typeof e?.readLock=="function"&&typeof e?.writeLock=="function"}function Vd(e){if(Mr==null&&(Mr=Uc(e),!Fc(Mr))){let t=Mr;t.addEventListener("requestReadLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Ie.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};t.addEventListener("abortReadLockRequest",a),s.readLock({signal:i.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{t.removeEventListener("abortReadLockRequest",a)})}),t.addEventListener("requestWriteLock",r=>{let n=r.detail.name,o=r.detail.identifier,s=Ie.get(n);if(s==null)return;let i=new AbortController,a=c=>{c.detail.name!==n||c.detail.identifier!==o||i.abort()};t.addEventListener("abortWriteLockRequest",a),s.writeLock({signal:i.signal}).then(async c=>{await r.detail.handler().finally(()=>{c()})}).catch(c=>{r.detail.onError(c)}).finally(()=>{t.removeEventListener("abortWriteLockRequest",a)})}),t.addEventListener("finalizeRequest",r=>{let n=r.detail.name,o=Ie.get(n);o?.finalize()})}return Mr}async function li(e,t){let r,n,o=new Promise((i,a)=>{r=i,n=a}),s=()=>{n(new _t)};return t?.signal?.addEventListener("abort",s,{once:!0}),e.add(async()=>{await new Promise(i=>{r(()=>{t?.signal?.removeEventListener("abort",s),i()})})},{signal:t?.signal}).catch(i=>{n(i)}),o}var Mc=(e,t)=>{let r=Ie.get(e);if(r!=null)return r;let n=Vd(t);if(Fc(n))return r=n,Ie.set(e,r),r;let o=new Fr({concurrency:1}),s;return r={async readLock(i){if(s!=null)return li(s,i);s=new Fr({concurrency:t.concurrency,autoStart:!1});let a=s,c=li(s,i);return o.add(async()=>{a.start(),await a.onIdle().then(()=>{s===a&&(s=null)})}),c},async writeLock(i){return s=null,li(o,i)},finalize:()=>{Ie.delete(e)},queue:o},Ie.set(e,r),t.autoFinalize===!0&&o.addEventListener("idle",()=>{r.finalize()},{once:!0}),r};var Hd={name:"lock",concurrency:1/0,singleProcess:!1,autoFinalize:!1};function di(e){let t=Object.assign({},Hd,e);return Mc(t.name,t)}var Jt;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=wt((d,h,y={})=>{y.lengthDelimited!==!1&&h.fork(),d.key!=null&&d.key!==""&&(h.uint32(10),h.string(d.key)),d.value!=null&&d.value.byteLength>0&&(h.uint32(18),h.bytes(d.value)),y.lengthDelimited!==!1&&h.ldelim()},(d,h,y={})=>{let g={key:"",value:J(0)},p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{g.key=d.string();break}case 2:{g.value=d.bytes();break}default:{d.skipType(b&7);break}}}return g},function*(d,h,y,g={}){let p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{yield{field:`${y}.key`,value:d.string()};break}case 2:{yield{field:`${y}.value`,value:d.bytes()};break}default:{d.skipType(b&7);break}}}})),c);function u(d){return bt(d,a.codec())}a.encode=u;function f(d,h){return yt(d,a.codec(),h)}a.decode=f;function l(d,h){return gt(d,a.codec(),h)}a.stream=l})(t=e.Peer$metadataEntry||(e.Peer$metadataEntry={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=wt((d,h,y={})=>{y.lengthDelimited!==!1&&h.fork(),d.key!=null&&d.key!==""&&(h.uint32(10),h.string(d.key)),d.value!=null&&(h.uint32(18),zr.codec().encode(d.value,h)),y.lengthDelimited!==!1&&h.ldelim()},(d,h,y={})=>{let g={key:""},p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{g.key=d.string();break}case 2:{g.value=zr.codec().decode(d,d.uint32(),{limits:y.limits?.value});break}default:{d.skipType(b&7);break}}}return g},function*(d,h,y,g={}){let p=h==null?d.len:d.pos+h;for(;d.pos<p;){let b=d.uint32();switch(b>>>3){case 1:{yield{field:`${y}.key`,value:d.string()};break}case 2:{yield*zr.codec().stream(d,d.uint32(),`${y}.value`,{limits:g.limits?.value});break}default:{d.skipType(b&7);break}}}})),c);function u(d){return bt(d,a.codec())}a.encode=u;function f(d,h){return yt(d,a.codec(),h)}a.decode=f;function l(d,h){return gt(d,a.codec(),h)}a.stream=l})(r=e.Peer$tagsEntry||(e.Peer$tagsEntry={}));let n;e.codec=()=>(n==null&&(n=wt((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.addresses!=null&&a.addresses.length>0)for(let f of a.addresses)c.uint32(10),qr.codec().encode(f,c);if(a.protocols!=null&&a.protocols.length>0)for(let f of a.protocols)c.uint32(18),c.string(f);if(a.publicKey!=null&&(c.uint32(34),c.bytes(a.publicKey)),a.peerRecordEnvelope!=null&&(c.uint32(42),c.bytes(a.peerRecordEnvelope)),a.metadata!=null&&a.metadata.size>0)for(let[f,l]of a.metadata.entries())c.uint32(50),e.Peer$metadataEntry.codec().encode({key:f,value:l},c);if(a.tags!=null&&a.tags.size>0)for(let[f,l]of a.tags.entries())c.uint32(58),e.Peer$tagsEntry.codec().encode({key:f,value:l},c);a.updated!=null&&(c.uint32(64),c.uint64Number(a.updated)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={addresses:[],protocols:[],metadata:new Map,tags:new Map},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{if(u.limits?.addresses!=null&&f.addresses.length===u.limits.addresses)throw new Rt('Decode error - repeated field "addresses" had too many elements');f.addresses.push(qr.codec().decode(a,a.uint32(),{limits:u.limits?.addresses$}));break}case 2:{if(u.limits?.protocols!=null&&f.protocols.length===u.limits.protocols)throw new Rt('Decode error - repeated field "protocols" had too many elements');f.protocols.push(a.string());break}case 4:{f.publicKey=a.bytes();break}case 5:{f.peerRecordEnvelope=a.bytes();break}case 6:{if(u.limits?.metadata!=null&&f.metadata.size===u.limits.metadata)throw new Br('Decode error - map field "metadata" had too many elements');let h=e.Peer$metadataEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.metadata$value}});f.metadata.set(h.key,h.value);break}case 7:{if(u.limits?.tags!=null&&f.tags.size===u.limits.tags)throw new Br('Decode error - map field "tags" had too many elements');let h=e.Peer$tagsEntry.codec().decode(a,a.uint32(),{limits:{value:u.limits?.tags$value}});f.tags.set(h.key,h.value);break}case 8:{f.updated=a.uint64Number();break}default:{a.skipType(d&7);break}}}return f},function*(a,c,u,f={}){let l={addresses:0,protocols:0,metadata:0,tags:0},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let h=a.uint32();switch(h>>>3){case 1:{if(f.limits?.addresses!=null&&l.addresses===f.limits.addresses)throw new Rt('Streaming decode error - repeated field "addresses" had too many elements');for(let y of qr.codec().stream(a,a.uint32(),`${u}.addresses[]`,{limits:f.limits?.addresses$}))yield{...y,index:l.addresses};l.addresses++;break}case 2:{if(f.limits?.protocols!=null&&l.protocols===f.limits.protocols)throw new Rt('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${u}.protocols[]`,index:l.protocols,value:a.string()},l.protocols++;break}case 4:{yield{field:`${u}.publicKey`,value:a.bytes()};break}case 5:{yield{field:`${u}.peerRecordEnvelope`,value:a.bytes()};break}case 6:{if(f.limits?.metadata!=null&&l.metadata===f.limits.metadata)throw new Rt('Decode error - map field "metadata" had too many elements');yield*e.Peer$metadataEntry.codec().stream(a,a.uint32(),`${u}.metadata{}`,{limits:{value:f.limits?.metadata$value}}),l.metadata++;break}case 7:{if(f.limits?.tags!=null&&l.tags===f.limits.tags)throw new Rt('Decode error - map field "tags" had too many elements');yield*e.Peer$tagsEntry.codec().stream(a,a.uint32(),`${u}.tags{}`,{limits:{value:f.limits?.tags$value}}),l.tags++;break}case 8:{yield{field:`${u}.updated`,value:a.uint64Number()};break}default:{a.skipType(h&7);break}}}})),n);function o(a){return bt(a,e.codec())}e.encode=o;function s(a,c){return yt(a,e.codec(),c)}e.decode=s;function i(a,c){return gt(a,e.codec(),c)}e.stream=i})(Jt||(Jt={}));var qr;(function(e){let t;e.codec=()=>(t==null&&(t=wt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),s.isCertified!=null&&(i.uint32(16),i.bool(s.isCertified)),s.observed!=null&&(i.uint32(24),i.uint64Number(s.observed)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:J(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.multiaddr=s.bytes();break}case 2:{c.isCertified=s.bool();break}case 3:{c.observed=s.uint64Number();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.multiaddr`,value:s.bytes()};break}case 2:{yield{field:`${a}.isCertified`,value:s.bool()};break}case 3:{yield{field:`${a}.observed`,value:s.uint64Number()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(qr||(qr={}));var zr;(function(e){let t;e.codec=()=>(t==null&&(t=wt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.value!=null&&s.value!==0&&(i.uint32(8),i.uint32(s.value)),s.expiry!=null&&(i.uint32(16),i.uint64(s.expiry)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={value:0},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.value=s.uint32();break}case 2:{c.expiry=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.value`,value:s.uint32()};break}case 2:{yield{field:`${a}.expiry`,value:s.uint64()};break}default:{s.skipType(f&7);break}}}})),t);function r(s){return bt(s,e.codec())}e.encode=r;function n(s,i){return yt(s,e.codec(),i)}e.decode=n;function o(s,i){return gt(s,e.codec(),i)}e.stream=o})(zr||(zr={}));function $d(e,t){if(e.publicKey!=null||t.publicKey==null)return e;let r;e.type==="RSA"&&(r=e.toMultihash());let n=Tn(t.publicKey,r);return dc(n)}function qc(e,t,r){let n=Jt.decode(t);return er(e,n,r)}function er(e,t,r){let n=new Map,o=BigInt(Date.now());for(let[s,i]of t.tags.entries())i.expiry!=null&&i.expiry<o||n.set(s,i);return{...t,id:$d(e,t),addresses:t.addresses.filter(({observed:s})=>s!=null&&s>Date.now()-r).map(({multiaddr:s,isCertified:i})=>({multiaddr:Te(s),isCertified:i??!1})),metadata:t.metadata,peerRecordEnvelope:t.peerRecordEnvelope??void 0,tags:n}}function zc(e,t){return Wd(e.addresses,t.addresses)&&jd(e.protocols,t.protocols)&&Zd(e.publicKey,t.publicKey)&&Yd(e.peerRecordEnvelope,t.peerRecordEnvelope)&&Gd(e.metadata,t.metadata)&&Xd(e.tags,t.tags)}function Wd(e,t){return Hc(e,t,(r,n)=>!(r.isCertified!==n.isCertified||!W(r.multiaddr,n.multiaddr)))}function jd(e,t){return Hc(e,t,(r,n)=>r===n)}function Zd(e,t){return Vc(e,t)}function Yd(e,t){return Vc(e,t)}function Gd(e,t){return $c(e,t,(r,n)=>W(r,n))}function Xd(e,t){return $c(e,t,(r,n)=>r.value===n.value&&r.expiry===n.expiry)}function Vc(e,t){return e==null&&t==null?!0:e!=null&&t!=null?W(e,t):!1}function Hc(e,t,r){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n]))return!1;return!0}function $c(e,t,r){if(e.size!==t.size)return!1;for(let[n,o]of e.entries()){let s=t.get(n);if(s==null||!r(o,s))return!1}return!0}var te="/",Wc=new TextEncoder().encode(te),ro=Wc[0],no=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=V(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==ro)throw new Error("Invalid key")}toString(t="utf8"){return M(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(te))}static random(){return new e(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new e(t):typeof t.uint8Array=="function"?new e(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Wc),this._buf[0]!==ro){let t=new Uint8Array(this._buf.byteLength+1);t.fill(ro,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===ro;)this._buf=this._buf.subarray(0,-1)}less(t){let r=this.list(),n=t.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let s=r[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return r.length<n.length}reverse(){return e.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(te).slice(1)}type(){return Qd(this.baseNamespace())}name(){return Jd(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(te)||(t+=te),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(te):new e(t.slice(0,-1).join(te))}child(t){return this.toString()===te?t:t.toString()===te?this:new e(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return e.withNamespaces([...this.namespaces(),...th(t.map(r=>r.namespaces()))])}};function Qd(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Jd(e){let t=e.split(":");return t[t.length-1]}function th(e){return[].concat(...e)}var hi="/peers/";function Vr(e){if(!Le(e)||e.type==null)throw new F("Invalid PeerId");let t=e.toCID().toString();return new no(`${hi}${t}`)}async function jc(e,t,r,n,o){let s=new Map;for(let i of r){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=Te(i.multiaddr)),!Pn(i.multiaddr))throw new F("Multiaddr was invalid");if(!await t(e,i.multiaddr,o))continue;let a=i.isCertified??!1,c=i.multiaddr.toString(),u=s.get(c);u!=null?i.isCertified=u.isCertified||a:s.set(c,{multiaddr:i.multiaddr,isCertified:a})}return[...s.values()].sort((i,a)=>i.multiaddr.toString().localeCompare(a.multiaddr.toString())).map(({isCertified:i,multiaddr:a})=>{let c=a.getComponents().find(u=>u.code===421)?.value;return e.equals(c)&&(a=a.decapsulate(Te(`/p2p/${e}`))),{isCertified:i,multiaddr:a.bytes}})}async function so(e,t,r,n){if(t==null)throw new F("Invalid PeerData");if(t.publicKey!=null&&e.publicKey!=null&&!t.publicKey.equals(e.publicKey))throw new F("publicKey bytes do not match peer id publicKey bytes");let o=n.existingPeer?.peer;if(o!=null&&!e.equals(o.id))throw new F("peer id did not match existing peer id");let s=o?.addresses??[],i=new Set(o?.protocols??[]),a=o?.metadata??new Map,c=o?.tags??new Map,u=o?.peerRecordEnvelope;if(r==="patch"){if((t.multiaddrs!=null||t.addresses!=null)&&(s=[],t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses)),t.protocols!=null&&(i=new Set(t.protocols)),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);a=oo(d,{validate:Zc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags);c=oo(d,{validate:Yc,map:Gc})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}if(r==="merge"){if(t.multiaddrs!=null&&s.push(...t.multiaddrs.map(d=>({isCertified:!1,multiaddr:d}))),t.addresses!=null&&s.push(...t.addresses),t.protocols!=null&&(i=new Set([...i,...t.protocols])),t.metadata!=null){let d=t.metadata instanceof Map?[...t.metadata.entries()]:Object.entries(t.metadata);for(let[h,y]of d)y==null?a.delete(h):a.set(h,y);a=oo([...a.entries()],{validate:Zc})}if(t.tags!=null){let d=t.tags instanceof Map?[...t.tags.entries()]:Object.entries(t.tags),h=new Map(c);for(let[y,g]of d)g==null?h.delete(y):h.set(y,g);c=oo([...h.entries()],{validate:Yc,map:Gc})}t.peerRecordEnvelope!=null&&(u=t.peerRecordEnvelope)}let f;o?.id.publicKey!=null?f=Tt(o.id.publicKey):t.publicKey!=null?f=Tt(t.publicKey):e.publicKey!=null&&(f=Tt(e.publicKey));let l={addresses:await jc(e,n.addressFilter??(async()=>!0),s,n.existingPeer?.peerPB.addresses,n),protocols:[...i.values()].sort((d,h)=>d.localeCompare(h)),metadata:a,tags:c,publicKey:f,peerRecordEnvelope:u};return l.addresses.forEach(d=>{d.observed=n.existingPeer?.peerPB.addresses?.find(h=>W(h.multiaddr,h.multiaddr))?.observed??Date.now()}),e.type!=="RSA"&&delete l.publicKey,l}function oo(e,t){let r=new Map;for(let[n,o]of e)o!=null&&t.validate(n,o);for(let[n,o]of e.sort(([s],[i])=>s.localeCompare(i)))o!=null&&r.set(n,t.map?.(n,o)??o);return r}function Zc(e,t){if(typeof e!="string")throw new F("Metadata key must be a string");if(!(t instanceof Uint8Array))throw new F("Metadata value must be a Uint8Array")}function Yc(e,t){if(typeof e!="string")throw new F("Tag name must be a string");if(t.value!=null){if(parseInt(`${t.value}`,10)!==t.value)throw new F("Tag value must be an integer");if(t.value<0||t.value>100)throw new F("Tag value must be between 0-100")}if(t.ttl!=null){if(parseInt(`${t.ttl}`,10)!==t.ttl)throw new F("Tag ttl must be an integer");if(t.ttl<0)throw new F("Tag ttl must be between greater than 0")}}function Gc(e,t){let r;t.expiry!=null&&(r=t.expiry),t.ttl!=null&&(r=BigInt(Date.now()+Number(t.ttl)));let n={value:t.value??0};return r!=null&&(n.expiry=r),n}function Xc(e){let t=e.toString().split("/")[2],r=et.parse(t,Nt);return Bn(r)}function pi(e,t,r){let n=Xc(e);return qc(n,t,r)}function eh(e,t){return{prefix:hi,filters:(e.filters??[]).map(r=>({key:n,value:o})=>r(pi(n,o,t))),orders:(e.orders??[]).map(r=>(n,o)=>r(pi(n.key,n.value,t),pi(o.key,o.value,t)))}}var io=class{peerId;datastore;locks;addressFilter;log;maxAddressAge;maxPeerAge;constructor(t,r={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.peerId=t.peerId,this.datastore=t.datastore,this.addressFilter=r.addressFilter,this.locks=ii({name:"libp2p_peer_store_locks",metrics:t.metrics}),this.maxAddressAge=r.maxAddressAge??36e5,this.maxPeerAge=r.maxPeerAge??216e5}getLock(t){let r=this.locks.get(t);return r==null&&(r={refs:0,lock:di({name:t.toString(),singleProcess:!0})},this.locks.set(t,r)),r.refs++,r}maybeRemoveLock(t,r){r.refs--,r.refs===0&&(r.lock.finalize(),this.locks.delete(t))}async getReadLock(t,r){let n=this.getLock(t);try{let o=await n.lock.readLock(r);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async getWriteLock(t,r){let n=this.getLock(t);try{let o=await n.lock.writeLock(r);return()=>{o(),this.maybeRemoveLock(t,n)}}catch(o){throw this.maybeRemoveLock(t,n),o}}async has(t,r){try{return await this.load(t,r),!0}catch(n){if(n.name!=="NotFoundError")throw n}return!1}async delete(t,r){this.peerId.equals(t)||await this.datastore.delete(Vr(t),r)}async load(t,r){let n=Vr(t),o=await this.datastore.get(n,r),s=Jt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new nr;return er(t,s,this.peerId.equals(t)?1/0:this.maxAddressAge)}async save(t,r,n){let o=await this.#t(t,n),s=await so(t,r,"patch",{...n,addressFilter:this.addressFilter});return this.#e(t,s,o)}async patch(t,r,n){let o=await this.#t(t,n),s=await so(t,r,"patch",{...n,addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async merge(t,r,n){let o=await this.#t(t,n),s=await so(t,r,"merge",{addressFilter:this.addressFilter,existingPeer:o});return this.#e(t,s,o)}async*all(t){for await(let{key:r,value:n}of this.datastore.query(eh(t??{},this.maxAddressAge),t)){let o=Xc(r);if(o.equals(this.peerId))continue;let s=Jt.decode(n);if(this.#r(o,s)){await this.datastore.delete(r,t);continue}yield er(o,s,this.peerId.equals(o)?1/0:this.maxAddressAge)}}async#t(t,r){try{let n=Vr(t),o=await this.datastore.get(n,r),s=Jt.decode(o);if(this.#r(t,s))throw await this.datastore.delete(n,r),new nr;return{peerPB:s,peer:er(t,s,this.maxAddressAge)}}catch(n){n.name!=="NotFoundError"&&this.log.error("invalid peer data found in peer store - %e",n)}}async#e(t,r,n,o){r.updated=Date.now();let s=Jt.encode(r);return await this.datastore.put(Vr(t),s,o),{peer:er(t,r,this.maxAddressAge),previous:n?.peer,updated:n==null||!zc(r,n.peerPB)}}#r(t,r){if(r.updated==null)return!0;if(this.peerId.equals(t))return!1;let n=r.updated<Date.now()-this.maxPeerAge,o=Date.now()-this.maxAddressAge,s=r.addresses.filter(i=>i.observed!=null&&i.observed>o);return n&&s.length===0}};var mi=class{store;events;peerId;log;constructor(t,r={}){this.log=t.logger.forComponent("libp2p:peer-store"),this.events=t.events,this.peerId=t.peerId,this.store=new io(t,r)}[Symbol.toStringTag]="@libp2p/peer-store";async forEach(t,r){for await(let n of this.store.all(r))t(n)}async all(t){return Dc(this.store.all(t))}async delete(t,r){let n=await this.store.getReadLock(t,r);try{await this.store.delete(t,r)}finally{n()}}async has(t,r){let n=await this.store.getReadLock(t,r);try{return await this.store.has(t,r)}finally{this.log.trace("has release read lock"),n?.()}}async get(t,r){let n=await this.store.getReadLock(t,r);try{return await this.store.load(t,r)}finally{n?.()}}async getInfo(t,r){let n=await this.get(t,r);return{id:n.id,multiaddrs:n.addresses.map(({multiaddr:o})=>o)}}async save(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.save(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async patch(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.patch(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async merge(t,r,n){let o=await this.store.getWriteLock(t,n);try{let s=await this.store.merge(t,r,n);return this.#t(t,s),s.peer}finally{o?.()}}async consumePeerRecord(t,r,n){let o=Le(r)?r:Le(r?.expectedPeer)?r.expectedPeer:void 0,s=Le(r)||r===void 0?n:r,i=await Qe.openAndCertify(t,Be.DOMAIN,s),a=Bn(i.publicKey.toCID());if(o?.equals(a)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",o,a),!1;let c=Be.createFromProtobuf(i.payload),u;try{u=await this.get(a,s)}catch(f){if(f.name!=="NotFoundError")throw f}if(u?.peerRecordEnvelope!=null){let f=Qe.createFromProtobuf(u.peerRecordEnvelope),l=Be.createFromProtobuf(f.payload);if(l.seqNumber>=c.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",l.seqNumber,c.seqNumber),!1}return await this.patch(c.peerId,{peerRecordEnvelope:t,addresses:c.multiaddrs.map(f=>({isCertified:!0,multiaddr:f}))},s),!0}#t(t,r){r.updated&&(this.peerId.equals(t)?this.events.safeDispatchEvent("self:peer:update",{detail:r}):this.events.safeDispatchEvent("peer:update",{detail:r}))}};function rh(e,t={}){return new mi(e,t)}return ru(nh);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|