@libp2p/identify 4.1.19 → 4.1.20-dac3122db
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 +2 -2
- package/package.json +8 -8
- package/dist/typedoc-urls.json +0 -18
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PIdentify = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PIdentify=(()=>{var xo=Object.defineProperty;var Ku=Object.getOwnPropertyDescriptor;var Fu=Object.getOwnPropertyNames;var qu=Object.prototype.hasOwnProperty;var Ce=(t,e)=>{for(var r in e)xo(t,r,{get:e[r],enumerable:!0})},Vu=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Fu(e))!qu.call(t,o)&&o!==r&&xo(t,o,{get:()=>e[o],enumerable:!(n=Ku(e,o))||n.enumerable});return t};var Hu=t=>Vu(xo({},"__esModule",{value:!0}),t);var Vh={};Ce(Vh,{identify:()=>Fh,identifyPush:()=>qh});var ae=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},At=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var rn=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var nn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Ke=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var It=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var wo=Symbol.for("@libp2p/peer-id");var on=Symbol.for("@libp2p/service-capabilities");function pe(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var Io={};Ce(Io,{base58btc:()=>he,base58flickr:()=>Xu});var gp=new Uint8Array(0);function Yi(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ne(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Tt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Tt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function ji(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var $i=4096;function Wi(t){let e=t.length;if(e<=$i)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=$i));return r}function zu(t){return t?.buffer instanceof ArrayBuffer}function Tt(t){return zu(t)?t:t.slice()}function $u(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<t.length;s++){var i=t.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=t.length,l=t.charAt(0),h=Math.log(f)/Math.log(256),p=Math.log(256)/Math.log(f);function x(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var I=0,b=0,S=0,A=w.length;S!==A&&w[S]===0;)S++,I++;for(var R=(A-S)*p+1>>>0,K=new Uint8Array(R);S!==A;){for(var P=w[S],O=0,N=R-1;(P!==0||O<b)&&N!==-1;N--,O++)P+=256*K[N]>>>0,K[N]=P%f>>>0,P=P/f>>>0;if(P!==0)throw new Error("Non-zero carry");b=O,S++}for(var F=R-b;F!==R&&K[F]===0;)F++;for(var H=l.repeat(I);F<R;++F)H+=t.charAt(K[F]);return H}function m(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var I=0;if(w[I]!==" "){for(var b=0,S=0;w[I]===l;)b++,I++;for(var A=(w.length-I)*h+1>>>0,R=new Uint8Array(A);w[I];){var K=w.charCodeAt(I);if(K>255)return;var P=n[K];if(P===255)return;for(var O=0,N=A-1;(P!==0||O<S)&&N!==-1;N--,O++)P+=f*R[N]>>>0,R[N]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");S=O,I++}if(w[I]!==" "){for(var F=A-S;F!==A&&R[F]===0;)F++;for(var H=new Uint8Array(b+(A-F)),J=b;F!==A;)H[J++]=R[F++];return H}}}function g(w){var I=m(w);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:x,decodeUnsafe:m,decode:g}}var Yu=$u,ju=Yu,Gi=ju;var Eo=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},So=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,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(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Xi(this,e)}},vo=class{decoders;constructor(e){this.decoders=e}or(e){return Xi(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Xi(t,e){return new vo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Ao=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Eo(e,r,n),this.decoder=new So(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ht({name:t,prefix:e,encode:r,decode:n}){return new Ao(t,e,r,n)}function ft({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Gi(r,t,n);return Ht({prefix:e,name:t,encode:o,decode:i=>Ne(s(i))})}function Wu(t,e,r,n){let o=t.length;for(;t[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=e[t[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 Zu(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Gu(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let o=t[n].toLowerCase(),s=t[n].toUpperCase();o!==t[n]&&(r[o]=n),s!==t[n]&&(r[s]=n)}return r}function fe({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=Gu(n,o);return Ht({prefix:e,name:t,encode(i){return Zu(i,n,r)},decode(i){return Wu(i,s,r,t)}})}var he=ft({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xu=ft({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var To={};Ce(To,{base32:()=>lt,base32hex:()=>tf,base32hexpad:()=>nf,base32hexpadupper:()=>of,base32hexupper:()=>rf,base32pad:()=>Ju,base32padupper:()=>ef,base32upper:()=>Qu,base32z:()=>sf});var lt=fe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Qu=fe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Ju=fe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),ef=fe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),tf=fe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),rf=fe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),nf=fe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),of=fe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),sf=fe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var _o={};Ce(_o,{base36:()=>xr,base36upper:()=>af});var xr=ft({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),af=ft({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var cf=ea,Qi=128,uf=127,ff=~uf,lf=Math.pow(2,31);function ea(t,e,r){e=e||[],r=r||0;for(var n=r;t>=lf;)e[r++]=t&255|Qi,t/=128;for(;t&ff;)e[r++]=t&255|Qi,t>>>=7;return e[r]=t|0,ea.bytes=r-n+1,e}var df=Co,hf=128,Ji=127;function Co(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Co.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Ji)<<o:(i&Ji)*Math.pow(2,o),o+=7}while(i>=hf);return Co.bytes=s-n,r}var pf=Math.pow(2,7),mf=Math.pow(2,14),yf=Math.pow(2,21),bf=Math.pow(2,28),gf=Math.pow(2,35),xf=Math.pow(2,42),wf=Math.pow(2,49),Ef=Math.pow(2,56),Sf=Math.pow(2,63),vf=function(t){return t<pf?1:t<mf?2:t<yf?3:t<bf?4:t<gf?5:t<xf?6:t<wf?7:t<Ef?8:t<Sf?9:10},Af={encode:cf,decode:df,encodingLength:vf},If=Af,wr=If;function Er(t,e=0){let r=wr.decode(t,e),n=wr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function zt(t,e,r=0){return wr.encode(t,e,r),e}function $t(t){return wr.encodingLength(t)}function We(t,e){let r=e.byteLength,n=$t(t),o=n+$t(r),s=new Uint8Array(o+r);return zt(t,s,0),zt(r,s,n),s.set(e,o),new Yt(t,r,e,s)}function Sr(t){let e=Ne(t),[r,n]=Er(e),[o,s]=Er(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Yt(r,o,i,e)}function ta(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Yi(t.bytes,r.bytes)}}var Yt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Tt(n),this.bytes=Tt(o)}};function ra(t,e){let{bytes:r,version:n}=t;return n===0?_f(r,Bo(t),e??he.encoder):Cf(r,Bo(t),e??lt.encoder)}var na=new WeakMap;function Bo(t){let e=na.get(t);if(e==null){let r=new Map;return na.set(t,r),r}return e}var ge=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Tt(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:e,multihash:r}=this;if(e!==vr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Bf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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:e,digest:r}=this.multihash,n=We(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&ta(e.multihash,n.multihash)}toString(e){return ra(this,e)}toJSON(){return{"/":ra(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??oa(n,o,s.bytes))}else if(r[Df]===!0){let{version:n,multihash:o,code:s}=r,i=Sr(o);return t.create(n,s,i)}else return null}static create(e,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(e){case 0:{if(r!==vr)throw new Error(`Version 0 CID must use dag-pb (code: ${vr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=oa(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,vr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Ne(e.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 Yt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=Er(e.subarray(r));return r+=h,l},o=n(),s=vr;if(o===18)o=0,r=0;else if(o===1)s=n();else throw o===0?new RangeError("Invalid CID version, v0 is always implicit"):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(e,r){let[n,o]=Tf(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Bo(s).set(n,e),s}};function Tf(t,e){switch(t[0]){case"Q":{let r=e??he;return[he.prefix,r.decode(`${he.prefix}${t}`)]}case he.prefix:{let r=e??he;return[he.prefix,r.decode(t)]}case lt.prefix:{let r=e??lt;return[lt.prefix,r.decode(t)]}case xr.prefix:{let r=e??xr;return[xr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function _f(t,e,r){let{prefix:n}=r;if(n!==he.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Cf(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var vr=112,Bf=18;function oa(t,e,r){let n=$t(t),o=n+$t(e),s=new Uint8Array(o+r.byteLength);return zt(t,s,0),zt(e,s,n),s.set(r,o),s}var Df=Symbol.for("@ipld/js-cid/CID");var Do={};Ce(Do,{identity:()=>Fe});var sa=0,Of="identity",ia=Ne;function Pf(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return We(sa,ia(t))}var Fe={code:sa,name:Of,encode:ia,digest:Pf};function Lf(t){return t.buffer instanceof ArrayBuffer}function _e(t){return Lf(t)?t:t.slice()}async function aa(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,_e(e),_e(r.subarray()));return n?.signal?.throwIfAborted(),s}function xe(t=0){return new Uint8Array(t)}function Se(t=0){return new Uint8Array(t)}function Rf(t){return t?.buffer instanceof ArrayBuffer}function Oo(t){if(Rf(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ze(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Se(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Oo(r)}var ua=Symbol.for("@achingbrain/uint8arraylist");function ca(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function an(t){return!!t?.[ua]}var me=class t{bufs;length;[ua]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(an(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(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(an(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(e){let r=ca(this.bufs,e);return r.buf[r.index]}set(e,r){let n=ca(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(an(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return Ze(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Ze(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===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,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-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-e}}indexOf(e,r=0){if(!an(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.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 h=u;h>=0;h--){let p=this.get(l+h);if(n[h]!==p){f=Math.max(1,h-a[p]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=xe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=xe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=xe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=xe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=xe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=xe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=xe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=xe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!pe(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Po={};Ce(Po,{base10:()=>Nf});var Nf=ft({prefix:"9",name:"base10",alphabet:"0123456789"});var Lo={};Ce(Lo,{base16:()=>Uf,base16upper:()=>kf});var Uf=fe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),kf=fe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Ro={};Ce(Ro,{base2:()=>Mf});var Mf=fe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var No={};Ce(No,{base256emoji:()=>Hf});var fa=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}"),Kf=fa.reduce((t,e,r)=>(t[r]=e,t),[]),Ff=fa.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function qf(t){return t.reduce((e,r)=>(e+=Kf[r],e),"")}function Vf(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ff[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Hf=Ht({prefix:"\u{1F680}",name:"base256emoji",encode:qf,decode:Vf});var ko={};Ce(ko,{base64:()=>zf,base64pad:()=>$f,base64url:()=>Uo,base64urlpad:()=>Yf});var zf=fe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),$f=fe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Uo=fe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yf=fe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mo={};Ce(Mo,{base8:()=>jf});var jf=fe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ko={};Ce(Ko,{identity:()=>Wf});var Wf=Ht({prefix:"\0",name:"identity",encode:t=>Wi(Ne(t)),decode:t=>Ne(ji(t))});var rm=new TextEncoder,nm=new TextDecoder;var Vo={};Ce(Vo,{sha256:()=>Ar,sha512:()=>Qf});var Xf=20;function qo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Fo(t,e,r,n,o)}var Fo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Xf,this.maxDigestLength=s}digest(e,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(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?la(n,this.code,r?.truncate):n.then(o=>la(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function la(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return We(e,t)}function ha(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Ar=qo({name:"sha2-256",code:18,encode:ha("SHA-256")}),Qf=qo({name:"sha2-512",code:19,encode:ha("SHA-512")});var Ir={...Ko,...Ro,...Mo,...Po,...Lo,...To,..._o,...Io,...ko,...No},mm={...Vo,...Do};function ma(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var pa=ma("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Ho=ma("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Se(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Jf={utf8:pa,"utf-8":pa,hex:Ir.base16,latin1:Ho,ascii:Ho,binary:Ho,...Ir},cn=Jf;function V(t,e="utf8"){let r=cn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Y(t,e="utf8"){let r=cn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var el=parseInt("11111",2),zo=parseInt("10000000",2),tl=parseInt("01111111",2),ya={0:Tr,1:Tr,2:rl,3:sl,4:il,5:ol,6:nl,16:Tr,22:Tr,48:Tr};function rt(t,e={offset:0}){let r=t[e.offset]⪙if(e.offset++,ya[r]!=null)return ya[r](t,e);throw new Error("No decoder for tag "+r)}function _r(t,e){let r=0;if((t[e.offset]&zo)===zo){let n=t[e.offset]&tl,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");o+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function Tr(t,e){_r(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=rt(t,e);if(n===null)break;r.push(n)}return r}function rl(t,e){let r=_r(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function nl(t,e){let r=_r(t,e),n=e.offset+r,o=t[e.offset];e.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(;e.offset<n;){let u=t[e.offset];if(e.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 ol(t,e){return e.offset++,null}function sl(t,e){let r=_r(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function il(t,e){let r=_r(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function al(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new me;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function $o(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=al(t.byteLength);return new me(Uint8Array.from([e.byteLength|zo]),e)}function Be(t){let e=new me,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new me(Uint8Array.from([2]),$o(e),e)}function un(t){let e=Uint8Array.from([0]),r=new me(e,t);return new me(Uint8Array.from([3]),$o(r),r)}function dt(t,e=48){let r=new me;for(let n of t)r.append(n);return new me(Uint8Array.from([e]),$o(r),r)}var cl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ul=Uint8Array.from([6,5,43,129,4,0,34]),fl=Uint8Array.from([6,5,43,129,4,0,35]),ll={ext:!0,kty:"EC",crv:"P-256"},dl={ext:!0,kty:"EC",crv:"P-384"},hl={ext:!0,kty:"EC",crv:"P-521"},Yo=32,jo=48,Wo=66;function Zo(t){let e=rt(t);return ba(e)}function ba(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Yo*2+1)return n=Y(e.subarray(r,r+Yo),"base64url"),o=Y(e.subarray(r+Yo),"base64url"),new jt({...ll,key_ops:["verify"],x:n,y:o});if(e.byteLength===jo*2+1)return n=Y(e.subarray(r,r+jo),"base64url"),o=Y(e.subarray(r+jo),"base64url"),new jt({...dl,key_ops:["verify"],x:n,y:o});if(e.byteLength===Wo*2+1)return n=Y(e.subarray(r,r+Wo),"base64url"),o=Y(e.subarray(r+Wo),"base64url"),new jt({...hl,key_ops:["verify"],x:n,y:o});throw new ae(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function ga(t){return dt([Be(Uint8Array.from([1])),dt([pl(t.crv)],160),dt([un(new me(Uint8Array.from([4]),V(t.x??"","base64url"),V(t.y??"","base64url")))],161)]).subarray()}function pl(t){if(t==="P-256")return cl;if(t==="P-384")return ul;if(t==="P-521")return fl;throw new ae(`Invalid curve ${t}`)}var jt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=ga(this.jwk)),this._raw}toMultihash(){return Fe.digest(Ge(this))}toCID(){return ge.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}async verify(e,r,n){return aa(this.jwk,r,e,n)}};var fn=BigInt(4294967295),xa=BigInt(32);function ml(t,e=!1){return e?{h:Number(t&fn),l:Number(t>>xa&fn)}:{h:Number(t>>xa&fn)|0,l:Number(t&fn)|0}}function wa(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=ml(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var yl=t=>t/2**32|0,bl=t=>t>>>0;function Ea(t,e,r,n){let o=yl(r),s=bl(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}var Go=(t,e,r)=>t>>>r,Xo=(t,e,r)=>t<<32-r|e>>>r,Ct=(t,e,r)=>t>>>r|e<<32-r,Bt=(t,e,r)=>t<<32-r|e>>>r,Cr=(t,e,r)=>t<<64-r|e>>>r-32,Br=(t,e,r)=>t>>>r-32|e<<64-r;function Xe(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Sa=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),va=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Aa=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ia=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Ta=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),_a=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;function ln(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Qo=t=>t?`"${t}" `:"";function nt(t,e=""){if(typeof t!="number")throw new TypeError(Qo(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Qo(e)+"expected integer >= 0, got "+t);return t}function Ue(t,e,r=""){if(ln(t)&&(e===void 0||t.length===e))return t;e!==void 0&&nt(e,"length");let n=ln(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=Qo(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function dn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(nt(t.outputLen),nt(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var xl=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},Ca=(t,e)=>{xl(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function Wt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function hn(t,e){Ue(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Dt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function pn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function qe(t,e){return t<<32-e|t>>>e}var Da=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",wl=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function mn(t){if(Ue(t),Da)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=wl[t[r]];return e}function Ba(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function yn(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Da)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Ba(t.charCodeAt(s)),a=Ba(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Jo(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ue(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function El(t,e,r="opts"){return Ca(t,"defaults"),e!==void 0&&Ca(e,r),Object.assign(Object.create(null),t,e)}function es(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=El({},e,"info");let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Oa(t=32){nt(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var ts=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Pa(t,e,r){return t&e^~t&r}function La(t,e,r){return t&e^t&r^e&r}var Dr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=pn(this.buffer)}update(e){Wt(this),Ue(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let u=pn(e);for(;o<=s-a;a+=o)this.process(u,a);i=!0;continue}n.set(a===0&&c===s?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Wt(this),hn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),Ea(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===r?n:pn(e),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Ra=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Na=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Sl=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ht=new Uint32Array(64),rs=class extends Dr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|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}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let l=0;l<16;l++,r+=4)ht[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=ht[l-15],p=ht[l-2],x=qe(h,7)^qe(h,18)^h>>>3,m=qe(p,17)^qe(p,19)^p>>>10;ht[l]=m+ht[l-7]+x+ht[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 h=qe(a,6)^qe(a,11)^qe(a,25),p=f+h+Pa(a,c,u)+Sl[l]+ht[l]|0,m=(qe(n,2)^qe(n,13)^qe(n,22))+La(n,o,s)|0;f=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+m|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(){Dt(ht)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Dt(this.buffer)}},ns=class extends rs{constructor(){super(32,Ra)}};var Ua=wa(["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(t=>BigInt(t))),vl=Ua[0],Al=Ua[1],pt=new Uint32Array(80),mt=new Uint32Array(80),os=class extends Dr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:p,Gl:x,Hh:m,Hl:g}=this;return[e,r,n,o,s,i,a,c,u,f,l,h,p,x,m,g]}set(e,r,n,o,s,i,a,c,u,f,l,h,p,x,m,g){this.Ah=e|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=h|0,this.Gh=p|0,this.Gl=x|0,this.Hh=m|0,this.Hl=g|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let b=0;b<16;b++,r+=4)pt[b]=e.getUint32(r),mt[b]=e.getUint32(r+=4);for(let b=16;b<80;b++){let S=pt[b-15]|0,A=mt[b-15]|0,R=Ct(S,A,1)^Ct(S,A,8)^Go(S,A,7),K=Bt(S,A,1)^Bt(S,A,8)^Xo(S,A,7),P=pt[b-2]|0,O=mt[b-2]|0,N=Ct(P,O,19)^Cr(P,O,61)^Go(P,O,6),F=Bt(P,O,19)^Br(P,O,61)^Xo(P,O,6),H=Aa(K,F,mt[b-7],mt[b-16]),J=Ia(H,R,N,pt[b-7],pt[b-16]);pt[b]=J|0,mt[b]=H|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:p,Fl:x,Gh:m,Gl:g,Hh:w,Hl:I}=this;for(let b=0;b<80;b++){let S=Ct(l,h,14)^Ct(l,h,18)^Cr(l,h,41),A=Bt(l,h,14)^Bt(l,h,18)^Br(l,h,41),R=l&p^~l&m,K=h&x^~h&g,P=Ta(I,A,K,Al[b],mt[b]),O=_a(P,w,S,R,vl[b],pt[b]),N=P|0,F=Ct(n,o,28)^Cr(n,o,34)^Cr(n,o,39),H=Bt(n,o,28)^Br(n,o,34)^Br(n,o,39),J=n&s^n&a^s&a,_=o&i^o&c^i&c;w=m|0,I=g|0,m=p|0,g=x|0,p=l|0,x=h|0,{h:l,l:h}=Xe(u|0,f|0,O|0,N|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let M=Sa(N,H,_);n=va(M,O,F,J),o=M|0}({h:n,l:o}=Xe(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Xe(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Xe(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Xe(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=Xe(this.Eh|0,this.El|0,l|0,h|0),{h:p,l:x}=Xe(this.Fh|0,this.Fl|0,p|0,x|0),{h:m,l:g}=Xe(this.Gh|0,this.Gl|0,m|0,g|0),{h:w,l:I}=Xe(this.Hh|0,this.Hl|0,w|0,I|0),this.set(n,o,s,i,a,c,u,f,l,h,p,x,m,g,w,I)}roundClean(){Dt(pt,mt)}destroy(){this.destroyed=!0,Dt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ss=class extends os{constructor(){super(64,Na)}};var Zt=es(()=>new ns,ts(1));var is=es(()=>new ss,ts(3));function gn(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var G=(t,e,r)=>Ue(t,e,r),as=nt;function Ma(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function yt(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Ot(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var Or=mn,ke=(...t)=>Jo(...t),Gt=t=>yn(t),gt=ln,Pt=t=>Oa(t),bn=BigInt(0),ka=BigInt(1),Il=t=>t?`"${t}" `:"";function De(t,e=""){if(typeof t!="boolean")throw new TypeError(Il(e)+"expected boolean, got type="+typeof t);return t}function xn(t){if(typeof t=="bigint"){if(!bt(t))throw new RangeError("positive bigint expected, got "+t)}else as(t);return t}function ot(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Pr(t){let e=xn(t).toString(16);return e.length&1?"0"+e:e}function Ka(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?bn:BigInt("0x"+t)}function Qe(t){return Ka(mn(t))}function Lt(t){return Ka(mn(Lr(Ue(t)).reverse()))}function wn(t,e){if(nt(e),e===0)throw new Error("zero output length is invalid");t=xn(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return yn(n.padStart(r,"0"))}function cs(t,e){return wn(t,e).reverse()}function Lr(t){return Uint8Array.from(G(t))}function bt(t){return typeof t=="bigint"&&bn<=t}function us(t,e,r){return bt(t)&&bt(e)&&bt(r)&&e<=t&&t<r}function Xt(t,e,r,n){if(!us(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Qt(t){if(t<bn)throw new Error("expected non-negative bigint, got "+t);return t===bn?0:t.toString(2).length}var Rr=t=>(ot(t,"n"),(ka<<BigInt(t))-ka);function Fa(t,e,r){if(nt(t,"hashLen"),nt(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=g=>new Uint8Array(g),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...g)=>r(u,ke(c,...g)),p=(g=o)=>{u=h(s,g),c=h(),g.length!==0&&(u=h(i,g),c=h())},x=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let g=0,w=[];for(;g<e;){c=h();let I=c.slice();w.push(I),g+=c.length}return ke(...w)};return(g,w)=>{l(),p(g);let I;for(;(I=w(x()))===void 0;)p();return l(),I}}function Oe(t,e={},r={},n="object"){yt(t,n),yt(e,"fields"),yt(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=t[i];if(!Object.hasOwn(t,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(e,!1),s(r,!0)}var ye=BigInt(0),X=BigInt(1),xt=BigInt(2),Ha=BigInt(3),fs=BigInt(4),za=BigInt(5),Tl=BigInt(7),$a=BigInt(8),_l=BigInt(9),Cl=BigInt(15),Ya=BigInt(16),Bl=BigInt("0x10000000000000000");function ce(t,e){if(e<=ye)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ye?r:e+r}function ja(t,e,r){if(r<=X)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<ye)throw new Error("invalid exponent, negatives unsupported");if(e===ye)return X;if(e===X)return t;let n=t%r;if(n<ye&&(n+=r),e<Bl){let a=X;for(;e>ye;)e&X&&(a=a*n%r),n=n*n%r,e>>=X;return a}let o=[];for(;e>ye;)o.push(Number(e&Cl)),e>>=fs;let s=new Array(16);s[0]=X,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function se(t,e,r){if(r<=X)throw new Error("pow2: expected modulus > 1, got "+r);if(e<ye)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ye;)n*=n,n%=r;return n}function qa(t,e){if(t===ye)throw new Error("invert: expected non-zero number");if(e<=X)throw new Error("invert: expected modulus > 1, got "+e);let r=ce(t,e),n=e,o=ye,s=X;for(;r!==ye;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==X)throw new Error("invert: does not exist");return ce(o,e)}function Wa(t,e){if(e<=X)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ce(t,e);if(r===ye)throw new Error("invertCt: expected non-zero number");let n=ja(r,e-xt,e);if(ce(r*n,e)!==X)throw new Error("invertCt: does not exist");return n}function ls(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function ds(t,e){if((t&X)===ye)throw new Error(e+": expected odd modulus, got "+t)}function Za(t,e){let r=t,n=(r.ORDER+X)/fs,o=r.pow(e,n);return ls(r,o,e),o}function Dl(t,e){let r=t,n=(r.ORDER-za)/$a,o=r.mul(e,xt),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,xt),s),c=r.mul(i,r.sub(a,r.ONE));return ls(r,c,e),c}function Ol(t){let e=er(t),r=Ga(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+Tl)/Ya;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),h=u.mul(f,o),p=u.mul(f,s),x=u.eql(u.sqr(l),c),m=u.eql(u.sqr(h),c);f=u.cmov(f,l,x),l=u.cmov(p,h,m);let g=u.eql(u.sqr(l),c),w=u.cmov(f,l,g);return ls(u,w,c),w})}function Ga(t){if(t<Ha)throw new Error("sqrt is not defined for small field");ds(t,"tonelliShanks");let e=t-X,r=0;for(;e%xt===ye;)e/=xt,r++;let n=xt,o=er(t);for(;Nr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Za;let s=o.pow(n,e),i=(e+X)/xt;return function(c,u){let f=c;if(f.is0(u))return u;if(Nr(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,s),p=f.pow(u,e),x=f.pow(u,i);for(;!f.eql(p,f.ONE);){if(f.is0(p))throw new Error("Cannot find square root: probably non-prime P");let m=1,g=f.sqr(p);for(;!f.eql(g,f.ONE);)if(m++,g=f.sqr(g),m===l)throw new Error("Cannot find square root");let w=X<<BigInt(l-m-1),I=f.pow(h,w);l=m,h=f.sqr(I),p=f.mul(p,h),x=f.mul(x,I)}return x}}function Pl(t){return ds(t,"Fp.sqrt"),t%fs===Ha?Za:t%$a===za?Dl:t%Ya===_l?Ol(t):Ga(t)}var Xa=(t,e)=>(ce(t,e)&X)===X,Ll=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Jt(t){if(yt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);ot(t.BYTES,"BYTES"),ot(t.BITS,"BITS");for(let e of Ll)Ot(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Sn(t,e,r=!1){Jt(t),gn(e,"nums"),De(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function Nr(t,e){Jt(t);let r=t;ds(r.ORDER,"FpLegendre");let n=(r.ORDER-X)/xt,o=r.pow(e,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 Rl(t,e){if(e!==void 0&&as(e),t<=ye)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Qt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Va=new WeakMap,En=class{ORDER;BITS;BYTES;isLE;ZERO=ye;ONE=X;_lengths;_mod;constructor(e,r={}){if(e<=X)throw new Error("invalid field: expected ORDER > 1, got "+e);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}=Rl(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return ce(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ye<=e&&e<this.ORDER}is0(e){return e===ye}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&X)===X}neg(e){return ce(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ce(e*e,this.ORDER)}add(e,r){return ce(e+r,this.ORDER)}sub(e,r){return ce(e-r,this.ORDER)}mul(e,r){return ce(e*r,this.ORDER)}pow(e,r){return ja(e,r,this.ORDER)}div(e,r){return ce(e*qa(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return qa(e,this.ORDER)}sqrt(e){let r=Va.get(this);return r||Va.set(this,r=Pl(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?cs(e,this.BYTES):wn(e,this.BYTES)}fromBytes(e,r=!1){G(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?Lt(e):Qe(e);if(a&&(c=ce(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Sn(this,e,!0)}cmov(e,r,n){return De(n,"condition"),n?r:e}};function er(t,e={}){return Object.freeze(En.prototype),new En(t,e)}function Qa(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=X)throw new Error("field order must be greater than 1");let e=Qt(t-X);return Math.ceil(e/8)}function vn(t){let e=Qa(t);return e+Math.ceil(e/2)}function An(t,e,r=!1){G(t);let n=t.length,o=Qa(e),s=Math.max(vn(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Lt(t):Qe(t),a=ce(i,e-X)+X;return r?cs(a,o):wn(a,o)}var ms=BigInt(0),Ur=BigInt(1),Nl=BigInt(4),hs=16,Ja=128,Ul=5,ec=2**31;function wt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Ot(e.fromAffine,"Point.fromAffine"),Ot(e.fromBytes,"Point.fromBytes"),Ot(e.fromHex,"Point.fromHex"),yt(e.BASE,"Point.BASE"),yt(e.ZERO,"Point.ZERO"),Jt(e.Fp),Jt(e.Fn)}function In(t,e){wt(t),rc(e,t);let r=Sn(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function kl(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function Ml(t,e){let r=t*(4*e+128);if(r>ec)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+ec/2**20+" MiB")}function ys(t,e){if(t!==void 0){Ot(t,"randomBytes");try{let r=t(e);if(!gt(r)||r.length!==e)return}catch{return}return t}}function rc(t,e){gn(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Kl(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):bt(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var nc=new WeakMap;function ps(t){return nc.get(t)||1}function Fl(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function ql(t,e){let r=2**e,n=r/2,o=BigInt(r-1),s=[];for(;t>ms;){let i=0;t&Ur&&(i=Number(t&o),i>=n&&(i-=r),t-=BigInt(i)),s.push(i),t>>=Ur}return s}function Vl(t,e,r){let n=2**e,o=n/2,s=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let u=Number(t&s);t>>=i,u>o&&(u-=n,t+=Ur),a.push(u)}if(t!==ms)throw new Error("invalid wnaf");return a}function Hl(t,e,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=t;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=e[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var tr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){wt(e),this.randomBytes=ys(r,hs),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=e;for(let c=0;c<o;c++){let u=a;for(let f=0;f<s;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(e,r){let{W:n,windows:o,comp:s}=e,i=2**(n-1),a=Vl(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],h=f*i,p=Math.abs(l)-1,x=s[h];for(let g=1;g<i;g++)x=g===p?s[h+g]:x;let m=x.negate();l===0?u=u.add(s[h]):c=c.add(l<0?m:x)}return{p:c,f:u}}getWnafPrecomputes(e,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!us(r,Ur,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let s=ps(e);return s===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Ja,s=this.randomBytes(hs);if(!gt(s)||s.length!==hs)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Qe(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,r,n){let o=Ul,s=1<<o,i=Rr(o),a=new Array(s);a[0]=this.ZERO;for(let f=1;f<s;f++)a[f]=a[f-1].add(e);let c=Math.ceil(n/o),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let p=0;p<o;p++)u=u.double();let l=Number(r>>BigInt(f*o)&i),h=a[0];for(let p=1;p<s;p++)h=p===l?a[p]:h;u=u.add(h)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Ur?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!bt(r))throw new Error("invalid scalar");let o=ps(e);if(o===1||r>=this.Point.Fn.ORDER)return Tn(this.Point,[e],[r],!0);let s=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(e,r){this.assertPoint(e),kl(r,this.bits);let n=Math.ceil((this.bits+Ja)/r)+1;Ml(n*2**(r-1),this.Point.Fp.BYTES),nc.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return ps(e)!==1}};function Tn(t,e,r,n=!1){if(wt(t),rc(e,t),De(n,"allowOversized"),Kl(r,t.Fn,n?t.Fn.ORDER**Nl:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>Fl(i,4)),s=r.map(i=>ql(i,4));return Hl(t.ZERO,o,s)}function tc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Jt(e),e}else return er(t,{isLE:r})}function _n(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Oe(r);for(let c of["p","n","h"]){let u=e[c];if(!(bt(u)&&u!==ms))throw new Error(`CURVE.${c} must be positive bigint`)}let o=tc(e.p,r.Fp,n),s=tc(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function Cn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var Bn=BigInt(0),Dn=BigInt(1),On=BigInt(2),zl=BigInt(4),oc=BigInt(8);function $l(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function sc(t,e={}){Oe(e,{},{},"extraOpts");let r=e,n=_n("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(Nr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Nr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Oe(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?Pt:r.randomBytes,u=On<<BigInt(o.BYTES*8)-Dn;function f(I){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(I)}let l=r.uvRatio===void 0?(I,b)=>{try{return{isValid:!0,value:o.sqrt(o.div(I,b))}}catch{return{isValid:!1,value:Bn}}}:r.uvRatio;if(!$l(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let h=o.eql(i.a,o.neg(o.ONE))?I=>o.neg(I):o.eql(i.a,o.ONE)?I=>I:I=>o.mul(i.a,I);function p(I,b,S=!1){let A=S?Dn:Bn;return Xt("coordinate "+I,b,A,u),b}function x(I){if(!(I instanceof m))throw new Error("EdwardsPoint expected")}class m{static BASE=new m(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new m(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(b,S,A,R){this.X=p("x",b),this.Y=p("y",S),this.Z=p("z",A,!0),this.T=p("t",R),Object.freeze(this)}static CURVE(){return i}static fromAffine(b){if(b instanceof m)throw new Error("extended point not allowed");let{x:S,y:A}=b||{};return p("x",S),p("y",A),new m(S,A,o.ONE,o.mul(S,A))}static fromBytes(b,S=!1){let A=o.BYTES,{a:R,d:K}=i;b=Lr(G(b,A,"point")),De(S,"zip215");let P=Lr(b),O=b[A-1];P[A-1]=O&-129;let N=Lt(P),F=S?u:o.ORDER;Xt("point.y",N,Bn,F);let H=o.sqr(N),J=o.sub(H,o.ONE),_=o.sub(o.mulN(K,H),R),{isValid:M,value:q}=l(J,_);if(!M)throw new Error("bad point: invalid y coordinate");let L=f(q),re=(O&128)!==0;if(!S&&o.is0(q)&&re)throw new Error("bad point: x=0 and x_0=1");return re!==L&&(q=o.neg(q)),m.fromAffine({x:q,y:N})}static fromHex(b,S=!1){return m.fromBytes(Gt(b),S)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=6,S=!0){return w.setWindowSize(this,b),S||this.multiply(On),this}assertValidity(){let b=this,{a:S,d:A}=i;if(b.is0())throw new Error("bad point: ZERO");let{X:R,Y:K,Z:P,T:O}=b,N=o.sqr(R),F=o.sqr(K),H=o.sqr(P),J=o.sqr(H),_=o.mul(N,S),M=o.mul(o.add(_,F),H),q=o.add(J,o.mul(A,o.mul(N,F)));if(!o.eql(M,q))throw new Error("bad point: equation left != right (1)");let L=o.mul(R,K),re=o.mul(P,O);if(!o.eql(L,re))throw new Error("bad point: equation left != right (2)")}equals(b){x(b);let{X:S,Y:A,Z:R}=this,{X:K,Y:P,Z:O}=b,N=o.mul(S,O),F=o.mul(K,R),H=o.mul(A,O),J=o.mul(P,R);return o.eql(N,F)&&o.eql(H,J)}is0(){return this.equals(m.ZERO)}negate(){return new m(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:b,Y:S,Z:A}=this,R=o.sqr(b),K=o.sqr(S),P=o.mul(o.sqr(A),On),O=h(R),N=o.addN(b,S),F=o.sub(o.subN(o.sqr(N),R),K),H=o.addN(O,K),J=o.subN(H,P),_=o.subN(O,K),M=o.mul(F,J),q=o.mul(H,_),L=o.mul(F,_),re=o.mul(J,H);return new m(M,q,re,L)}add(b){x(b);let{d:S}=i,{X:A,Y:R,Z:K,T:P}=this,{X:O,Y:N,Z:F,T:H}=b,J=o.mul(A,O),_=o.mul(R,N),M=o.mul(o.mulN(P,S),H),q=o.mul(K,F),L=o.sub(o.subN(o.mulN(o.addN(A,R),o.addN(O,N)),J),_),re=o.subN(q,M),ie=o.addN(q,M),v=o.sub(_,h(J)),d=o.mul(L,re),y=o.mul(ie,v),E=o.mul(L,v),T=o.mul(re,ie);return new m(d,y,T,E)}subtract(b){return x(b),this.add(b.negate())}multiply(b){if(!s.isValidNot0(b))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:S,f:A}=w.mulSecret(this,b,a,g);return g([S,A])[0]}multiplyUnsafe(b){if(!s.isValid(b))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return b===Bn?m.ZERO:this.is0()||b===Dn?this:w.mulUnsafe(this,b,g)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return w.mulUnsafe(this,i.n).is0()}toAffine(b){let S=this,A=b;if(A!=null&&typeof A!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof A);let{X:R,Y:K,Z:P}=S,O=S.is0();A==null&&(A=O?o.create(oc):o.inv(P));let N=o.mul(R,A),F=o.mul(K,A),H=o.mul(P,A);if(O)return{x:o.ZERO,y:o.ONE};if(!o.eql(H,o.ONE))throw new Error("invZ was invalid");return{x:N,y:F}}clearCofactor(){return a===Dn?this:a===On?this.double():a===zl?this.double().double():a===oc?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:b,y:S}=this.toAffine(),A=o.toBytes(S);return A[A.length-1]|=f(b)?128:0,A}toHex(){return Or(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let g=I=>In(m,I),w=new tr(m,c);return w.bits>=6&&m.BASE.precompute(6),Object.freeze(m.prototype),Object.freeze(m),m}function ic(t,e,r={}){if(wt(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Oe(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=t,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?Pt:o.randomBytes,h=o.toMontgomery,p=o.toMontgomerySecret,x=o.adjustScalarBytes===void 0?_=>_:o.adjustScalarBytes,m=o.domain===void 0?(_,M,q)=>{if(De(q,"phflag"),M.length||q)throw new Error("Contexts/pre-hash are not supported");return _}:o.domain;function g(_){return c.create(Lt(_))}function w(_){let M=O.secretKey;G(_,O.secretKey,"secretKey");let q=G(n(_),2*M,"hashedSecretKey"),L=x(q.slice(0,M)),re=q.slice(M,2*M),ie=g(L);return{head:L,prefix:re,scalar:ie}}function I(_){let{head:M,prefix:q,scalar:L}=w(_),re=i.multiply(L),ie=re.toBytes();return{head:M,prefix:q,scalar:L,point:re,pointBytes:ie}}function b(_){return I(_).pointBytes}function S(_=Uint8Array.of(),...M){let q=ke(...M);return g(n(m(q,G(_,void 0,"context"),!!s)))}function A(_,M,q={}){Oe(q,{},{},"options"),_=Lr(G(_,void 0,"message")),s&&(_=s(_));let{prefix:L,scalar:re,pointBytes:ie}=I(M),v=S(q.context,L,_),d=i.multiply(v).toBytes(),y=S(q.context,d,ie,_),E=c.create(v+y*re);if(!c.isValid(E))throw new Error("sign failed: invalid s");let T=ke(d,c.toBytes(E));return G(T,O.signature,"result")}let R={zip215:o.zip215};function K(_,M,q,L=R){Oe(L);let{context:re}=L,ie=L.zip215===void 0?!!R.zip215:L.zip215,v=O.signature;_=G(_,v,"signature"),M=G(M,void 0,"message"),q=G(q,O.publicKey,"publicKey"),ie!==void 0&&De(ie,"zip215"),s&&(M=s(M));let d=v/2,y=_.subarray(0,d),E=Lt(_.subarray(d,v)),T,C,B;try{T=t.fromBytes(q,ie),C=t.fromBytes(y,ie),B=i.multiplyUnsafe(E)}catch{return!1}if(!ie&&T.isSmallOrder())return!1;let U=S(re,y,q,M);return C.add(T.multiplyUnsafe(U)).subtract(B).clearCofactor().is0()}let P=a.BYTES,O={secretKey:P,publicKey:P,signature:2*P,seed:P};function N(_){return _=_===void 0?l(O.seed):_,G(_,O.seed,"seed")}function F(_){return gt(_)&&_.length===O.secretKey}function H(_,M){try{return!!t.fromBytes(_,M===void 0?R.zip215:M)}catch{return!1}}let J={getExtendedPublicKey:I,randomSecretKey:N,isValidSecretKey:F,isValidPublicKey:H,toMontgomery(_){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(t.fromBytes(_))},toMontgomerySecret(_){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(_)}};return Object.freeze(O),Object.freeze(J),Object.freeze({keygen:Cn(N,b),getPublicKey:b,sign:A,verify:K,utils:J,Point:t,lengths:O})}var bs=BigInt(1),ac=BigInt(2);var Yl=BigInt(5),jl=BigInt(8),gs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Wl={p:gs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:jl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Zl(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=gs,a=t*t%s*t%s,c=se(a,ac,s)*a%s,u=se(c,bs,s)*t%s,f=se(u,Yl,s)*u%s,l=se(f,e,s)*f%s,h=se(l,r,s)*l%s,p=se(h,n,s)*h%s,x=se(p,o,s)*p%s,m=se(x,o,s)*p%s,g=se(m,e,s)*f%s;return{pow_p_5_8:se(g,ac,s)*t%s,b2:a}}function fc(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var cc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Gl(t,e){let r=gs,n=ce(e*e*e,r),o=ce(n*n*e,r),s=Zl(t*o).pow_p_5_8,i=ce(t*n*s,r),a=ce(e*i*i,r),c=i,u=ce(i*cc,r),f=a===t,l=a===ce(-t,r),h=a===ce(-t*cc,r);return f&&(i=c),(l||h)&&(i=u),Xa(i,r)&&(i=ce(-i,r)),{isValid:f||l,value:i}}var xs=sc(Wl,{uvRatio:Gl}),uc=xs.Fp;function Xl(t){let{y:e}=t;return uc.toBytes(uc.div(bs+e,bs-e))}function Ql(t){let e=xs.Fp.BYTES;return Ue(t,e),fc(is(t.subarray(0,e))).subarray(0,e)}function Jl(t){return ic(xs,is,Object.assign({adjustScalarBytes:fc,toMontgomery:Xl,toMontgomerySecret:Ql,zip215:!0},t))}var lc=Jl({});var kr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Pn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Me={get(t=globalThis){let e=t.crypto;if(e?.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 e}};var Ln=32;var ws,ed=(async()=>{try{return await Me.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function td(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Me.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Me.get().subtle.verify({name:"Ed25519"},n,_e(e),_e(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function rd(t,e,r){return lc.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function dc(t,e,r){return ws==null&&(ws=await ed),ws?td(t,e,r):rd(t,e,r)}function Rn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Nn=class{type="Ed25519";raw;constructor(e){this.raw=Es(e,Ln)}toMultihash(){return Fe.digest(Ge(this))}toCID(){return ge.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=dc(this.raw,r,e);return Rn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Ss(t){return t=Es(t,Ln),new Nn(t)}function Es(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new ae(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var od=Math.pow(2,7),sd=Math.pow(2,14),id=Math.pow(2,21),vs=Math.pow(2,28),As=Math.pow(2,35),Is=Math.pow(2,42),Ts=Math.pow(2,49),Q=128,ve=127;function Pe(t){if(t<od)return 1;if(t<sd)return 2;if(t<id)return 3;if(t<vs)return 4;if(t<As)return 5;if(t<Is)return 6;if(t<Ts)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function rr(t,e,r=0){switch(Pe(t)){case 8:e[r++]=t&255|Q,t/=128;case 7:e[r++]=t&255|Q,t/=128;case 6:e[r++]=t&255|Q,t/=128;case 5:e[r++]=t&255|Q,t/=128;case 4:e[r++]=t&255|Q,t>>>=7;case 3:e[r++]=t&255|Q,t>>>=7;case 2:e[r++]=t&255|Q,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function ad(t,e,r=0){switch(Pe(t)){case 8:e.set(r++,t&255|Q),t/=128;case 7:e.set(r++,t&255|Q),t/=128;case 6:e.set(r++,t&255|Q),t/=128;case 5:e.set(r++,t&255|Q),t/=128;case 4:e.set(r++,t&255|Q),t>>>=7;case 3:e.set(r++,t&255|Q),t>>>=7;case 2:e.set(r++,t&255|Q),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function _s(t,e){let r=t[e],n=0;if(n+=r&ve,r<Q||(r=t[e+1],n+=(r&ve)<<7,r<Q)||(r=t[e+2],n+=(r&ve)<<14,r<Q)||(r=t[e+3],n+=(r&ve)<<21,r<Q)||(r=t[e+4],n+=(r&ve)*vs,r<Q)||(r=t[e+5],n+=(r&ve)*As,r<Q)||(r=t[e+6],n+=(r&ve)*Is,r<Q)||(r=t[e+7],n+=(r&ve)*Ts,r<Q))return n;throw new RangeError("Could not decode varint")}function cd(t,e){let r=t.get(e),n=0;if(n+=r&ve,r<Q||(r=t.get(e+1),n+=(r&ve)<<7,r<Q)||(r=t.get(e+2),n+=(r&ve)<<14,r<Q)||(r=t.get(e+3),n+=(r&ve)<<21,r<Q)||(r=t.get(e+4),n+=(r&ve)*vs,r<Q)||(r=t.get(e+5),n+=(r&ve)*As,r<Q)||(r=t.get(e+6),n+=(r&ve)*Is,r<Q)||(r=t.get(e+7),n+=(r&ve)*Ts,r<Q))return n;throw new RangeError("Could not decode varint")}function nr(t,e,r=0){return e==null&&(e=Se(Pe(t))),e instanceof Uint8Array?rr(t,e,r):ad(t,e,r)}function Mr(t,e=0){return t instanceof Uint8Array?_s(t,e):cd(t,e)}var Bs=new Float32Array([-0]),Et=new Uint8Array(Bs.buffer);function pc(t,e,r){Bs[0]=t,e[r]=Et[0],e[r+1]=Et[1],e[r+2]=Et[2],e[r+3]=Et[3]}function mc(t,e){return Et[0]=t[e],Et[1]=t[e+1],Et[2]=t[e+2],Et[3]=t[e+3],Bs[0]}var Ds=new Float64Array([-0]),Ae=new Uint8Array(Ds.buffer);function yc(t,e,r){Ds[0]=t,e[r]=Ae[0],e[r+1]=Ae[1],e[r+2]=Ae[2],e[r+3]=Ae[3],e[r+4]=Ae[4],e[r+5]=Ae[5],e[r+6]=Ae[6],e[r+7]=Ae[7]}function bc(t,e){return Ae[0]=t[e],Ae[1]=t[e+1],Ae[2]=t[e+2],Ae[3]=t[e+3],Ae[4]=t[e+4],Ae[5]=t[e+5],Ae[6]=t[e+6],Ae[7]=t[e+7],Ds[0]}var ud=BigInt(Number.MAX_SAFE_INTEGER),fd=BigInt(Number.MIN_SAFE_INTEGER),Le=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&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(e=!1){if(e)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(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Rt;if(e<ud&&e>fd)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>gc&&(o=0n,++n>gc&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Rt;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Rt}},Rt=new Le(0,0);Rt.toBigInt=function(){return 0n};Rt.zzEncode=Rt.zzDecode=function(){return this};Rt.length=function(){return 1};var gc=4294967296n;function xc(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function wc(t,e,r){if(r-e<1)return"";let o,s=[],i=0,a;for(;e<r;)a=t[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&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 Os(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Ve(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Un(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Ps=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=_e(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ve(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ve(this,4);return Un(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ve(this,4);return Un(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ve(this,4);let e=mc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ve(this,4);let e=bc(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ve(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return wc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ve(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ve(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Le(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ve(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ve(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ve(this,8);let e=Un(this.buf,this.pos+=4),r=Un(this.buf,this.pos+=4);return new Le(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=_s(this.buf,this.pos);return this.pos+=Pe(e),e}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 Kr(t){return new Ps(t instanceof Uint8Array?t:t.subarray())}function He(t,e,r){let n=Kr(t);return e.decode(n,void 0,r)}function Ls(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return Se(i);o+i>e&&(n=Se(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Nt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Rs(){}var Us=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},ld=Ls();function dd(t){return globalThis.Buffer!=null?Se(t):ld(t)}var qr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Nt(Rs,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Nt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ks((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(kn,10,Le.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Le.fromBigInt(e);return this._push(kn,r.length(),r)}uint64Number(e){return this._push(rr,Pe(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Le.fromBigInt(e).zzEncode();return this._push(kn,r.length(),r)}sint64Number(e){let r=Le.fromNumber(e).zzEncode();return this._push(kn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ns,1,e?1:0)}fixed32(e){return this._push(Fr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Le.fromBigInt(e);return this._push(Fr,4,r.lo)._push(Fr,4,r.hi)}fixed64Number(e){let r=Le.fromNumber(e);return this._push(Fr,4,r.lo)._push(Fr,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(pc,4,e)}double(e){return this._push(yc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Ns,1,0):this.uint32(r)._push(pd,r,e)}string(e){let r=xc(e);return r!==0?this.uint32(r)._push(Os,r,e):this._push(Ns,1,0)}fork(){return this.states=new Us(this),this.head=this.tail=new Nt(Rs,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 Nt(Rs,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=dd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Ns(t,e,r){e[r]=t&255}function hd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var ks=class extends Nt{next;constructor(e,r){super(hd,e,r),this.next=void 0}};function kn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Fr(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function pd(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(qr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(md,e,t),this},qr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(yd,e,t),this});function md(t,e,r){e.set(t,r)}function yd(t,e,r){t.length<40?Os(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(V(t),r)}function Ms(){return new qr}function ze(t,e){let r=Ms();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*$e(t,e,r){let n=Kr(t);yield*e.stream(n,void 0,".",r)}var Mn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Kn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Ks(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i,a){};return Kn("enum",Mn.VARINT,r,n,o)}function Ye(t,e,r){return Kn("message",Mn.LENGTH_DELIMITED,t,e,r)}var Je=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ue;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(ue||(ue={}));var Fs;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Fs||(Fs={}));(function(t){t.codec=()=>Ks(Fs)})(ue||(ue={}));var et;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ue.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=ue.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:ue.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ze(s,t.codec())}t.encode=r;function n(s,i){return He(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(et||(et={}));var qs;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ue.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=ue.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:ue.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ze(s,t.codec())}t.encode=r;function n(s,i){return He(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(qs||(qs={}));var Hr={};Ce(Hr,{MAX_RSA_KEY_SIZE:()=>Vs,generateRSAKeyPair:()=>Tc,jwkToJWKKeyPair:()=>_c,jwkToPkcs1:()=>wd,jwkToPkix:()=>Ys,jwkToRSAPrivateKey:()=>Gs,pkcs1MessageToJwk:()=>zs,pkcs1MessageToRSAPrivateKey:()=>js,pkcs1ToJwk:()=>xd,pkcs1ToRSAPrivateKey:()=>Ic,pkixMessageToJwk:()=>$s,pkixMessageToRSAPublicKey:()=>Zs,pkixToJwk:()=>Ed,pkixToRSAPublicKey:()=>Ws});var or=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Hr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ge.createV1(114,this._multihash)}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}verify(e,r,n){return Ac(this.jwk,r,e,n)}},Vr=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Hr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}sign(e,r){return vc(this.jwk,e,r)}};var Vs=8192,Hs=18,bd=1062,gd=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function xd(t){let e=rt(t);return zs(e)}function zs(t){return{n:Y(t[1],"base64url"),e:Y(t[2],"base64url"),d:Y(t[3],"base64url"),p:Y(t[4],"base64url"),q:Y(t[5],"base64url"),dp:Y(t[6],"base64url"),dq:Y(t[7],"base64url"),qi:Y(t[8],"base64url"),kty:"RSA"}}function wd(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new ae("JWK was missing components");return dt([Be(Uint8Array.from([0])),Be(V(t.n,"base64url")),Be(V(t.e,"base64url")),Be(V(t.d,"base64url")),Be(V(t.p,"base64url")),Be(V(t.q,"base64url")),Be(V(t.dp,"base64url")),Be(V(t.dq,"base64url")),Be(V(t.qi,"base64url"))]).subarray()}function Ed(t){let e=rt(t,{offset:0});return $s(e)}function $s(t){let e=rt(t[1],{offset:0});return{kty:"RSA",n:Y(e[0],"base64url"),e:Y(e[1],"base64url")}}function Ys(t){if(t.n==null||t.e==null)throw new ae("JWK was missing components");return dt([gd,un(dt([Be(V(t.n,"base64url")),Be(V(t.e,"base64url"))]))]).subarray()}function Ic(t){let e=rt(t);return js(e)}function js(t){let e=zs(t);return Gs(e)}function Ws(t,e){if(t.byteLength>=bd)throw new At("Key size is too large");let r=rt(t,{offset:0});return Zs(r,t,e)}function Zs(t,e,r){let n=$s(t);if(r==null){let o=Zt(et.encode({Type:ue.RSA,Data:e}));r=We(Hs,o)}return new or(n,r)}function Gs(t){if(Bc(t)>Vs)throw new ae("Key size is too large");let e=_c(t),r=Zt(et.encode({Type:ue.RSA,Data:Ys(e.publicKey)})),n=We(Hs,r);return new Vr(e.privateKey,new or(e.publicKey,n))}async function Tc(t){if(t>Vs)throw new ae("Key size is too large");let e=await Cc(t),r=Zt(et.encode({Type:ue.RSA,Data:Ys(e.publicKey)})),n=We(Hs,r);return new Vr(e.privateKey,new or(e.publicKey,n))}function _c(t){if(t==null)throw new ae("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Cc(t,e){let r=await Me.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await Sd(r,e);return{privateKey:n[0],publicKey:n[1]}}async function vc(t,e,r){let n=await Me.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Me.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,_e(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ac(t,e,r,n){let o=await Me.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Me.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,_e(e),_e(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function Sd(t,e){if(t.privateKey==null||t.publicKey==null)throw new ae("Private and public key are required");let r=await Promise.all([Me.get().subtle.exportKey("jwk",t.privateKey),Me.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Bc(t){if(t.kty!=="RSA")throw new ae("invalid key type");if(t.n==null)throw new ae("invalid key modulus");return V(t.n,"base64url").length*8}var Fn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(dn(e),Ue(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Dt(o)}update(e){return Wt(this),this.iHash.update(e),this}digestInto(e){Wt(this),hn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Dc=(()=>{let t=((e,r,n)=>new Fn(e,r).update(n).digest());return t.create=(e,r)=>new Fn(e,r),t})();var vd=BigInt(0),Xs=class extends Error{constructor(e=""){super(e)}},st={Err:Xs,_tlv:{encode:(t,e)=>{let{Err:r}=st;if(ot(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Ma(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Pr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Pr(o.length/2|128):"";return Pr(t)+s+o+e},decode(t,e){let{Err:r}=st;e=G(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[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=e.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=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=st;if(xn(t),t<vd)throw new e("integer: negative integers are not allowed");let r=Pr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=st;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Qe(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:o}=st;if(e!==void 0&&(ot(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let s=G(t,void 0,"signature"),{v:i,l:a}=o.decode(48,s);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=o.decode(2,i),{v:f,l}=o.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||f.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=st;Oe(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}},qn=(Object.freeze(st._tlv),Object.freeze(st._int),Object.freeze(st));var Oc=(t,e)=>(t+(t>=0?e:-e)/Pc)/e;function Ad(t,e,r){Xt("scalar",t,it,r);let[[n,o],[s,i]]=e,a=Oc(i*t,r),c=Oc(-o*t,r),u=t-a*n-c*s,f=-a*o-c*i,l=u<it,h=f<it;l&&(u=-u),h&&(f=-f);let p=Rr(Math.ceil(Qt(r)/2))+Ut;if(u<it||u>=p||f<it||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:h,k2:f}}function ei(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Qs(t,e){Oe(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return De(r.lowS,"lowS"),De(r.prehash,"prehash"),r.format!==void 0&&ei(r.format),r}var it=BigInt(0),Ut=BigInt(1),Pc=BigInt(2),Js=BigInt(3),Id=BigInt(4);function Lc(t,e={}){let r=_n("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Oe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:h,toBytes:p}=e,x=e.randomBytes===void 0?Pt:e.randomBytes;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 m=c?{beta:c.beta,basises:c.basises.map(v=>[...v])}:void 0,g=Nc(n,o);function w(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function I(v,d,y){if(d.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:E,y:T}=d.toAffine(),C=n.toBytes(E);if(De(y,"isCompressed"),y){w();let B=!n.isOdd(T);return ke(Rc(B),C)}else return ke(Uint8Array.of(4),C,n.toBytes(T))}function b(v){G(v,void 0,"Point");let{publicKey:d,publicKeyUncompressed:y}=g,E=v.length,T=v[0],C=v.subarray(1);if(u&&E===1&&T===0)return{x:n.ZERO,y:n.ZERO};if(E===d&&(T===2||T===3)){let B=n.fromBytes(C);if(!n.isValid(B))throw new Error("bad point: is not on curve, wrong x");let U=P(B),k;try{k=n.sqrt(U)}catch(le){let ne=le instanceof Error?": "+le.message:"";throw new Error("bad point: is not on curve, sqrt error"+ne)}w();let Z=n.isOdd(k);return(T&1)===1!==Z&&(k=n.neg(k)),{x:B,y:k}}else if(E===y&&T===4){let B=n.BYTES,U=n.fromBytes(C.subarray(0,B)),k=n.fromBytes(C.subarray(B,B*2));if(!O(U,k))throw new Error("bad point: is not on curve");return{x:U,y:k}}else throw new Error(`bad point: got length ${E}, expected compressed=${d} or uncompressed=${y}`)}let S=p===void 0?I:p,A=h===void 0?b:h,R=n.mul(s.b,Js),K=n.is0(s.a)?v=>n.ZERO:v=>n.mul(s.a,v);function P(v){let d=n.sqr(v),y=n.mul(d,v);return n.add(n.add(y,n.mul(v,s.a)),s.b)}function O(v,d){let y=n.sqr(d),E=P(v);return n.eql(y,E)}if(!O(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let N=n.mul(n.pow(s.a,Js),Id),F=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(N,F)))throw new Error("bad curve params: a or b");function H(v,d,y=!1){if(!n.isValid(d)||y&&n.is0(d))throw new Error(`bad point coordinate ${v}`);return typeof d=="object"&&d!==null?n.create(d):d}function J(v){if(!(v instanceof L))throw new Error("Weierstrass Point expected")}function _(v){if(!m||!m.basises)throw new Error("no endo");return Ad(v,m.basises,o.ORDER)}function M(v,d,y,E){if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(m){let{k1neg:T,k1:C,k2neg:B,k2:U}=_(E),k=new L(n.mul(y.X,m.beta),y.Y,y.Z);v.push(T?y.negate():y,B?k.negate():k),d.push(C,U)}else v.push(y),d.push(E)}let q=new WeakSet;class L{static BASE=new L(s.Gx,s.Gy,n.ONE);static ZERO=new L(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,y,E){this.X=H("x",d),this.Y=H("y",y,!0),this.Z=H("z",E),Object.freeze(this)}static CURVE(){return s}static fromAffine(d){let{x:y,y:E}=d||{};if(!d||!n.isValid(y)||!n.isValid(E))throw new Error("invalid affine point");if(d instanceof L)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(E)?L.ZERO:new L(y,E,n.ONE)}static fromBytes(d){let y=L.fromAffine(A(G(d,void 0,"point")));return y.assertValidity(),y}static fromHex(d){return L.fromBytes(Gt(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=6,y=!0){return ie.setWindowSize(this,d),y||this.multiply(Js),this}assertValidity(){let d=this;if(d.is0()){if(u&&n.is0(d.X)&&n.eql(d.Y,n.ONE)&&n.is0(d.Z))return;throw new Error("bad point: ZERO")}if(q.has(d))return;let{x:y,y:E}=d.toAffine();if(!n.isValid(y)||!n.isValid(E))throw new Error("bad point: x or y not field elements");if(!O(y,E))throw new Error("bad point: equation left != right");if(!d.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");q.add(d)}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){J(d);let{X:y,Y:E,Z:T}=this,{X:C,Y:B,Z:U}=d,k=n.eql(n.mul(y,U),n.mul(C,T)),Z=n.eql(n.mul(E,U),n.mul(B,T));return k&&Z}negate(){return new L(this.X,n.neg(this.Y),this.Z)}double(){let{X:d,Y:y,Z:E}=this,T=n.ZERO,C=n.ZERO,B=n.ZERO,U=n.mul(d,d),k=n.mul(y,y),Z=n.mul(E,E),$=n.mul(d,y);return $=n.add($,$),B=n.mul(d,E),B=n.add(B,B),T=K(B),C=n.mul(R,Z),C=n.add(T,C),T=n.sub(k,C),C=n.add(k,C),C=n.mul(T,C),T=n.mul($,T),B=n.mul(R,B),Z=K(Z),$=n.sub(U,Z),$=K($),$=n.add($,B),B=n.add(U,U),U=n.add(B,U),U=n.add(U,Z),U=n.mul(U,$),C=n.add(C,U),Z=n.mul(y,E),Z=n.add(Z,Z),U=n.mul(Z,$),T=n.sub(T,U),B=n.mul(Z,k),B=n.add(B,B),B=n.add(B,B),new L(T,C,B)}add(d){J(d);let{X:y,Y:E,Z:T}=this,{X:C,Y:B,Z:U}=d,k=n.ZERO,Z=n.ZERO,$=n.ZERO,le=n.mul(y,C),ne=n.mul(E,B),be=n.mul(T,U),Re=n.add(y,E),oe=n.add(C,B);Re=n.mul(Re,oe),oe=n.add(le,ne),Re=n.sub(Re,oe),oe=n.add(y,T);let de=n.add(C,U);return oe=n.mul(oe,de),de=n.add(le,be),oe=n.sub(oe,de),de=n.add(E,T),k=n.add(B,U),de=n.mul(de,k),k=n.add(ne,be),de=n.sub(de,k),$=K(oe),k=n.mul(R,be),$=n.add(k,$),k=n.sub(ne,$),$=n.add(ne,$),Z=n.mul(k,$),ne=n.add(le,le),ne=n.add(ne,le),be=K(be),oe=n.mul(R,oe),ne=n.add(ne,be),be=n.sub(le,be),be=K(be),oe=n.add(oe,be),le=n.mul(ne,oe),Z=n.add(Z,le),le=n.mul(de,oe),k=n.mul(Re,k),k=n.sub(k,le),le=n.mul(Re,ne),$=n.mul(de,$),$=n.add($,le),new L(k,Z,$)}subtract(d){return J(d),this.add(d.negate())}is0(){return this.equals(L.ZERO)}multiply(d){if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let{p:y,f:E}=ie.mulSecret(this,d,i,re);return re([y,E])[0]}multiplyUnsafe(d){let y=this,E=d;if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(E===it||y.is0())return L.ZERO;if(E===Ut)return y;if(ie.hasWindowSize(this))return ie.mulUnsafe(y,E,re);let T=[],C=[];return M(T,C,y,E),Tn(L,T,C)}mulAddUnsafe(d,y,E){J(y);let T=[],C=[];return M(T,C,this,d),M(T,C,y,E),Tn(L,T,C)}toAffine(d){let y=this,E=d;if(E!=null&&!n.isValid(E))throw new RangeError('"invertedZ" expected valid field element');let{X:T,Y:C,Z:B}=y;if(n.eql(B,n.ONE))return{x:T,y:C};let U=y.is0();E==null&&(E=U?n.ONE:n.inv(B));let k=n.mul(T,E),Z=n.mul(C,E),$=n.mul(B,E);if(U)return{x:n.ZERO,y:n.ZERO};if(!n.eql($,n.ONE))throw new Error("invZ was invalid");return{x:k,y:Z}}isTorsionFree(){return i===Ut?!0:l?l(L,this):ie.mulUnsafe(this,a).is0()}clearCofactor(){return i===Ut?this:f?f(L,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Ut?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return De(d,"isCompressed"),this.assertValidity(),S(L,this,d)}toHex(d=!0){return Or(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let re=v=>In(L,v),ie=new tr(L,x);return ie.bits>=6&&L.BASE.precompute(6),Object.freeze(L.prototype),Object.freeze(L),L}function Rc(t){return Uint8Array.of(t?2:3)}function Nc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Td(t,e={}){wt(t);let{Fn:r}=t,n=e.randomBytes===void 0?Pt:e.randomBytes,o=Object.assign(Nc(t.Fp,r),{seed:Math.max(vn(r.ORDER),16)});function s(p){try{let x=r.fromBytes(p);return r.isValidNot0(x)}catch{return!1}}function i(p,x){let{publicKey:m,publicKeyUncompressed:g}=o;try{let w=p.length;return x===!0&&w!==m||x===!1&&w!==g?!1:!t.fromBytes(p).is0()}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,An(G(p,o.seed,"seed"),r.ORDER)}function c(p,x=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(x)}function u(p){let{secretKey:x,publicKey:m,publicKeyUncompressed:g}=o,w=r._lengths;if(!gt(p))return;let I=G(p,void 0,"key").length,b=I===m||I===g,S=I===x||!!w?.includes(I);if(!(b&&S))return b}function f(p,x,m=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(x)===!1)throw new Error("second arg must be public key");let g=r.fromBytes(p),w=t.fromBytes(x);if(w.is0())throw new Error("invalid public key: point at infinity");return w.multiply(g).toBytes(m)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},h=Cn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:h,Point:t,utils:l,lengths:o})}function Uc(t,e,r={}){wt(t);let n=e;dn(n),Oe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?Pt:o.randomBytes,i=o.hmac===void 0?(v,d)=>Dc(n,v,d):o.hmac,{Fp:a,Fn:c}=t,{ORDER:u,BITS:f}=c,l=vn(u),h=ys(s,l),{keygen:p,getPublicKey:x,getSharedSecret:m,utils:g,lengths:w}=Td(t,o),I={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},b=u*Pc+Ut<a.ORDER;function S(v){let d=u>>Ut;return v>d}function A(v,d){if(!c.isValidNot0(d))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return d}function R(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function K(v,d,y){return R(),(v===y?0:2)|Number(a.isOdd(d))}function P(){if(b)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(v,d){ei(d);let y=w.signature,E=d==="compact"?y:d==="recovered"?y+1:void 0;return G(v,E)}class N{r;s;recovery;constructor(d,y,E){if(this.r=A("r",d),this.s=A("s",y),E!=null){if(P(),![0,1,2,3].includes(E))throw new Error("invalid recovery id");this.recovery=E}Object.freeze(this)}static fromBytes(d,y=I.format){O(d,y);let E;if(y==="der"){if(d.length>2*c.BYTES+16)throw new qn.Err("invalid signature: DER signature too long");let{r:U,s:k}=qn.toSig(G(d),c.BYTES+1);return new N(U,k)}y==="recovered"&&(E=d[0],y="compact",d=d.subarray(1));let T=w.signature/2,C=d.subarray(0,T),B=d.subarray(T,T*2);return new N(c.fromBytes(C),c.fromBytes(B),E)}static fromHex(d,y){return this.fromBytes(Gt(d),y)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new N(this.r,this.s,d)}recoverPublicKey(d){let{r:y,s:E}=this,T=this.assertRecovery(),C=T===2||T===3?y+u:y;if(!a.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let B=a.toBytes(C),U=t.fromBytes(ke(Rc((T&1)===0),B)),k=c.inv(C),Z=H(G(d,void 0,"msgHash")),$=c.create(-Z*k),le=c.create(E*k),ne=t.BASE.mulAddUnsafe($,U,le);if(ne.is0())throw new Error("invalid recovery: point at infinify");return ne.assertValidity(),ne}hasHighS(){return S(this.s)}toBytes(d=I.format){if(ei(d),d==="der")return Gt(qn.hexFromSig(this));let{r:y,s:E}=this,T=c.toBytes(y),C=c.toBytes(E);return d==="recovered"?(P(),ke(Uint8Array.of(this.assertRecovery()),T,C)):ke(T,C)}toHex(d){return Or(this.toBytes(d))}}Object.freeze(N.prototype),Object.freeze(N);let F=o.bits2int===void 0?function(d){if(d.length>8192)throw new Error("input is too large");let y=Qe(d),E=d.length*8-f;return E>0?y>>BigInt(E):y}:o.bits2int,H=o.bits2int_modN===void 0?function(d){return c.create(F(d))}:o.bits2int_modN,J=Rr(f);function _(v){return Xt("num < 2^"+f,v,it,J),c.toBytes(v)}function M(v,d){return G(v,void 0,"message"),d?G(n(v),void 0,"prehashed message"):v}function q(v,d,y){let{lowS:E,prehash:T,extraEntropy:C}=Qs(y,I);v=M(v,T);let B=H(v),U=c.fromBytes(d);if(!c.isValidNot0(U))throw new Error("invalid private key");let k=[_(U),_(B)];if(C!=null&&C!==!1){let ne=C===!0?s(w.secretKey):C;k.push(G(ne,void 0,"extraEntropy"))}let Z=ke(...k),$=B;function le(ne){let be=F(ne);if(!c.isValidNot0(be))return;let Re=t.BASE.multiply(be).toAffine(),oe=c.create(Re.x);if(oe===it)return;let de;if(h!==void 0){let gr=Qe(An(h(l),u)),Uu=c.inv(c.mul(gr,be)),ku=c.mul(gr,$),Mu=c.mul(gr,U);de=c.create(Uu*c.create(ku+Mu*oe))}else{let gr=Wa(be,u);de=c.create(gr*c.create($+oe*U))}if(de===it)return;let go=K(Re.x,Re.y,oe),zi=de;return E&&S(de)&&(zi=c.neg(de),go^=1),new N(oe,zi,b?void 0:go)}return{seed:Z,k2sig:le}}function L(v,d,y={}){let{seed:E,k2sig:T}=q(v,d,y);return Fa(n.outputLen,c.BYTES,i)(E,T).toBytes(y.format)}function re(v,d,y,E={}){let{lowS:T,prehash:C,format:B}=Qs(E,I);if(y=G(y,void 0,"publicKey"),d=M(d,C),!gt(v)){let U=v instanceof N?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}O(v,B);try{let U=N.fromBytes(v,B),k=t.fromBytes(y);if(k.is0()||T&&U.hasHighS())return!1;let{r:Z,s:$}=U,le=H(d),ne=c.inv($),be=c.create(le*ne),Re=c.create(Z*ne),oe=t.BASE.mulAddUnsafe(be,k,Re);if(oe.is0())return!1;let de=oe.toAffine();return!(c.create(de.x)!==Z||B==="recovered"&&U.recovery!==K(de.x,de.y,Z))}catch{return!1}}function ie(v,d,y={}){let{prehash:E}=Qs(y,I);return d=M(d,E),N.fromBytes(v,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:p,getPublicKey:x,getSharedSecret:m,utils:g,lengths:w,Point:t,sign:L,verify:re,recoverPublicKey:ie,Signature:N,hash:n})}var ri={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},_d={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var kc=BigInt(2);function Cd(t){let e=ri.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=se(f,r,e)*f%e,h=se(l,r,e)*f%e,p=se(h,kc,e)*u%e,x=se(p,o,e)*p%e,m=se(x,s,e)*x%e,g=se(m,a,e)*m%e,w=se(g,c,e)*g%e,I=se(w,a,e)*m%e,b=se(I,r,e)*f%e,S=se(b,i,e)*x%e,A=se(S,n,e)*u%e,R=se(A,kc,e);if(!ti.eql(ti.sqr(R),t))throw new Error("Cannot find square root");return R}var ti=er(ri.p,{sqrt:Cd}),Bd=Lc(ri,{Fp:ti,endo:_d}),sr=Uc(Bd,Zt);function Mc(t,e,r,n){let o=Ar.digest(r instanceof Uint8Array?r:r.subarray());if(Rn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),sr.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new kr(String(s))});try{return n?.signal?.throwIfAborted(),sr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new kr(String(s))}}var Vn=class{type="secp256k1";raw;_key;constructor(e){this._key=Fc(e),this.raw=Kc(this._key)}toMultihash(){return Fe.digest(Ge(this))}toCID(){return ge.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}verify(e,r,n){return Mc(this._key,r,e,n)}};function ni(t){return new Vn(t)}function Kc(t){return sr.Point.fromBytes(t).toBytes()}function Fc(t){try{return sr.Point.fromBytes(t),t}catch(e){throw new At(String(e))}}function ir(t,e){let{Type:r,Data:n}=et.decode(t),o=n??new Uint8Array;switch(r){case ue.RSA:return Ws(o,e);case ue.Ed25519:return Ss(o);case ue.secp256k1:return ni(o);case ue.ECDSA:return Zo(o);default:throw new It}}function qc(t){let{Type:e,Data:r}=et.decode(t.digest),n=r??new Uint8Array;switch(e){case ue.Ed25519:return Ss(n);case ue.secp256k1:return ni(n);case ue.ECDSA:return Zo(n);default:throw new It}}function Ge(t){return et.encode({Type:ue[t.type],Data:t.raw})}var zr;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((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:xe(0),payloadType:xe(0),payload:xe(0),signature:xe(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}}}})),e);function r(s){return ze(s,t.codec())}t.encode=r;function n(s,i){return He(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(zr||(zr={}));var Hn=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var tt=class t{static createFromProtobuf=e=>{let r=zr.decode(e),n=ir(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),a=Vc(o,s,i),c=await r.sign(a.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,r,n)=>{let o=t.createFromProtobuf(e);if(!await o.validate(r,n))throw new Hn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:r,payloadType:n,payload:o,signature:s}=e;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=zr.encode({publicKey:Ge(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:pe(this.marshal(),e.marshal())}async validate(e,r){let n=Vc(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Vc=(t,e,r)=>{let n=V(t),o=nr(n.byteLength),s=nr(e.length),i=nr(r.length);return new me(o,n,s,e,i,r)};var Hc=Symbol.for("nodejs.util.inspect.custom"),Dd=114,$r=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[wo]=!0;toString(){return this.string==null&&(this.string=he.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ge.createV1(Dd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return pe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return pe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Hc](){return`PeerId(${this.toString()})`}},Yr=class extends $r{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},jr=class extends $r{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Wr=class extends $r{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Od=2336,zn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Fe.digest(V(this.url))}[Hc](){return`PeerId(${this.url})`}[wo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ge.createV1(Od,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=Y(e)),e.toString()===this.toString())}};function Zr(t){if(t.type==="Ed25519")return new jr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Wr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Yr({multihash:t.toCID().multihash,publicKey:t});throw new It}function zc(t){if(Ld(t))return new Yr({multihash:t});if(Pd(t))try{let e=qc(t);if(e.type==="Ed25519")return new jr({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Wr({multihash:t,publicKey:e})}catch{let r=Y(t.digest);return new zn(new URL(r))}throw new nn("Supplied PeerID Multihash is invalid")}function Pd(t){return t.code===Fe.code}function Ld(t){return t.code===Ar.code}var Ee=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},at=class extends Error{static name="ValidationError";name="ValidationError"},$n=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Yn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var jn=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();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(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,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 h=Number.parseInt(l,e);if(!Number.isNaN(h))return h});if(f===void 0)break;if(s*=e,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 e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=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]=e(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]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var $c=45,Rd=15,ar=new jn;function Wn(t){if(!(t.length>Rd))return ar.new(t).parseWith(()=>ar.readIPv4Addr())}function Zn(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>$c))return ar.new(t).parseWith(()=>ar.readIPv6Addr())}function St(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>$c)return;let r=ar.new(t).parseWith(()=>ar.readIPAddr());if(r)return e&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function cr(t){return!!Wn(t)}function Gn(t){return!!Zn(t)}function si(t){return e=>Y(e,t)}function ii(t){return e=>V(e,t)}function ur(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function kt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Yc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=V(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=kt(n);return Ze([r,o],r.length+o.length)}function jc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=lt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=kt(n);return Ze([r,o],r.length+o.length)}function ai(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=Y(e,"base32"),o=ur(r);return`${n}:${o}`}var ci=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new Ee("Invalid byte value in IP address");e[n]=o}),e},Wc=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=cr(r[n]),i;s&&(i=ci(r[n]),r[n]=Y(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,Y(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(e+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 Ee("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Zc=function(t){if(t.byteLength!==4)throw new Ee("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Gc=function(t){if(t.byteLength!==16)throw new Ee("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new Ee(`Invalid IPv6 address "${r}"`)}};function Xc(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new Ee(`Invalid IPv6 address "${t}"`)}}var oi=Object.values(Ir).map(t=>t.decoder),Nd=(function(){let t=oi[0].or(oi[1]);return oi.slice(2).forEach(e=>t=t.or(e)),t})();function Qc(t){return Nd.decode(t)}function Jc(t){return e=>t.encoder.encode(e)}function Ud(t){if(parseInt(t).toString()!==t)throw new at("Value must be an integer")}function kd(t){if(t<0)throw new at("Value must be a positive integer, or zero")}function Md(t){return e=>{if(e>t)throw new at(`Value must be smaller than or equal to ${t}`)}}function Kd(...t){return e=>{for(let r of t)r(e)}}var Gr=Kd(Ud,kd,Md(65535));var we=-1,ui=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Yn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ut=new ui,Jd=[{code:4,name:"ip4",size:32,valueToBytes:ci,bytesToValue:Zc,validate:t=>{if(!cr(t))throw new at(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:kt,bytesToValue:ur,validate:Gr},{code:273,name:"udp",size:16,valueToBytes:kt,bytesToValue:ur,validate:Gr},{code:33,name:"dccp",size:16,valueToBytes:kt,bytesToValue:ur,validate:Gr},{code:41,name:"ip6",size:128,valueToBytes:Wc,bytesToValue:Gc,stringToValue:Xc,validate:t=>{if(!Gn(t))throw new at(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:we},{code:43,name:"ipcidr",size:8,bytesToValue:si("base10"),valueToBytes:ii("base10")},{code:53,name:"dns",size:we},{code:54,name:"dns4",size:we},{code:55,name:"dns6",size:we},{code:56,name:"dnsaddr",size:we},{code:132,name:"sctp",size:16,valueToBytes:kt,bytesToValue:ur,validate:Gr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:we,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:we,bytesToValue:si("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?ii("base58btc")(t):ge.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ai,valueToBytes:Yc},{code:445,name:"onion3",size:296,bytesToValue:ai,valueToBytes:jc},{code:446,name:"garlic64",size:we},{code:447,name:"garlic32",size:we},{code:448,name:"tls"},{code:449,name:"sni",size:we},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:we,bytesToValue:Jc(Uo),valueToBytes:Qc},{code:480,name:"http"},{code:481,name:"http-path",size:we,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.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:we}];Jd.forEach(t=>{ut.addProtocol(t)});function eu(t){let e=[],r=0;for(;r<t.length;){let n=Mr(t,r),o=ut.getProtocol(n),s=Pe(n),i=eh(o,t,r+s),a=0;i>0&&o.size===we&&(a=Pe(i));let c=s+a+i,u={code:n,name:o.name,bytes:_e(t.subarray(r,r+c))};if(i>0){let f=r+s+a,l=t.subarray(f,f+i);u.value=o.bytesToValue?.(l)??Y(l)}e.push(u),r+=c}return e}function tu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=ut.getProtocol(n.code),s=Pe(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===we&&(c=Pe(a)));let u=new Uint8Array(s+c+a),f=0;rr(n.code,u,f),f+=s,i!=null&&(o.size===we&&(rr(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Ze(r,e)}function ru(t){if(t.charAt(0)!=="/")throw new Ee('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=ut.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new Ee(`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 Ee(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new Ee("Incomplete multiaddr");return e}function nu(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ut.getProtocol(e.code);if(r==null)throw new Ee(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function eh(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:Mr(e,r)}var th=Symbol.for("nodejs.util.inspect.custom"),Ai=Symbol.for("@multiformats/multiaddr");function rh(t){if(t==null&&(t="/"),ou(t))return t.getComponents();if(t instanceof Uint8Array)return eu(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),ru(t);if(Array.isArray(t))return t;throw new Ee("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ro=class t{[Ai]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=rh(e),r.validate!==!1&&nh(this)}get bytes(){return this.#r==null&&(this.#r=tu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=nu(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new $n(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return pe(this.bytes,e.bytes)}[th](){return`Multiaddr(${this.toString()})`}};function nh(t){t.getComponents().forEach(e=>{let r=ut.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function ou(t){return!!t?.[Ai]}function Qr(t){return new ro(t)}var su="libp2p-peer-record",iu=Uint8Array.from([3,1]);var Jr;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=Ye((l,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(h.uint32(10),h.bytes(l.multiaddr)),p.lengthDelimited!==!1&&h.ldelim()},(l,h,p={})=>{let x={multiaddr:xe(0)},m=h==null?l.len:l.pos+h;for(;l.pos<m;){let g=l.uint32();g>>>3===1?x.multiaddr=l.bytes():l.skipType(g&7)}return x},function*(l,h,p,x={}){let m=h==null?l.len:l.pos+h;for(;l.pos<m;){let g=l.uint32();g>>>3===1?yield{field:`${p}.multiaddr`,value:l.bytes()}:l.skipType(g&7)}})),a);function c(l){return ze(l,i.codec())}i.encode=c;function u(l,h){return He(l,i.codec(),h)}i.decode=u;function f(l,h){return $e(l,i.codec(),h)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=Ye((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),t.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:xe(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 Je('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.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 h=i.uint32();switch(h>>>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 Je('Streaming decode error - repeated field "addresses" had too many elements');for(let p of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...p,index:f.addresses};f.addresses++;break}default:{i.skipType(h&7);break}}}})),r);function n(i){return ze(i,t.codec())}t.encode=n;function o(i,a){return He(i,t.codec(),a)}t.decode=o;function s(i,a){return $e(i,t.codec(),a)}t.stream=s})(Jr||(Jr={}));function au(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var je=class t{static createFromProtobuf=e=>{let r=Jr.decode(e),n=zc(Sr(r.peerId)),o=(r.addresses??[]).map(i=>Qr(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=su;static CODEC=iu;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:o}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Jr.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!au(this.multiaddrs,e.multiaddrs))}};function oh(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function no(t){let e=oh(t);if(e==null)throw new ae(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function cu(t,e,r){let n=0;for(let o of t)if(!(n<e)){if(n>r)break;if(o!==255)return!1;n++}return!0}function Ii(t,e,r,n){let o=0;for(let s of t)if(!(o<r)){if(o>n)break;if(s!==e[o])return!1;o++}return!0}function Ti(t){switch(t.length){case Kt:return t.join(".");case Ft:{let e=[];for(let r=0;r<t.length;r++)r%2===0&&e.push(t[r].toString(16).padStart(2,"0")+t[r+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function uu(t){let e=0;for(let[r,n]of t.entries()){if(n===255){e+=8;continue}for(;(n&128)!=0;)e++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<t.length;o++)if(t[o]!=0)return-1;break}return e}function fu(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Kt=4,Ft=16,$x=parseInt("0xFFFF",16),lu=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function en(t,e){e.length===Ft&&t.length===Kt&&cu(e,0,11)&&(e=e.slice(12)),e.length===Kt&&t.length===Ft&&Ii(t,lu,0,11)&&(t=t.slice(12));let r=t.length;if(r!=e.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=t[o]&e[o];return n}function du(t,e){if(typeof e=="string"&&(e=St(e)),e==null)throw new Error("Invalid ip");if(e.length!==t.network.length)return!1;for(let r=0;r<e.length;r++)if((t.network[r]&t.mask[r])!==(e[r]&t.mask[r]))return!1;return!0}function _i(t){if(!oo(t))throw new Error("Must have 0xffff prefix");return t.slice(12)}function oo(t){return Ii(t,lu,0,11)}function Ci(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Kt,o=Wn(e);if(o==null&&(n=Ft,o=Zn(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+t);let i=Bi(s,8*n);return{network:en(o,i),mask:i}}function Bi(t,e){if(e!==8*Kt&&e!==8*Ft)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var qt=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Ci(e));else{let n=St(e);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=St(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Bi(o,8*n.length);this.network=en(n,this.mask)}}contains(e){return du({network:this.network,mask:this.mask},e)}toString(){let e=uu(this.mask),r=e!==-1?String(e):fu(this.mask);return Ti(this.network)+"/"+r}};function hu(t,e){return new qt(t).contains(e)}function pu(t){try{let e=no(t);return e.type==="ip6"?hu("2000::/3",e.host):!1}catch{return!1}}var sh=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32","::/128","::1/128","64:ff9b::/96","100::/64","2001::/32","2001:20::/28","2001:db8::/32","2002::/16","fc00::/7","fe80::/10","ff00::/8"].map(t=>new qt(t));function mu(t){if(!cr(t)&&!Gn(t))return;let e=St(t);if(e==null)return;let r=e.length===16&&oo(e)?_i(e):e;return sh.some(n=>n.contains(r))}function yu(t){try{let e=no(t);switch(e.type){case"ip4":case"ip6":return mu(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var ee=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),D=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),bu=t=>({match:e=>t.match(e)===!1?e:!1}),z=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),Ie=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),W=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function te(...t){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of t){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:t,matches:r,exactMatch:n}}var ih=D(421),ww=te(ih),io=D(54),ao=D(55),co=D(56),Oi=D(53),Ew=te(io,z(D(421))),Sw=te(ao,z(D(421))),vw=te(co,z(D(421))),Aw=te(Ie(Oi,co,io,ao),z(D(421))),gu=W(D(4),z(D(43))),xu=W(z(D(42)),D(41),z(D(43))),Pi=Ie(gu,xu),pr=Ie(Pi,Oi,io,ao,co),wu=te(Ie(Pi,W(Ie(Oi,co,io,ao),z(D(421))))),Iw=te(gu),Tw=te(xu),_w=te(Pi),Li=W(pr,D(6)),tn=W(pr,D(273)),Eu=te(W(Li,z(D(421)))),Cw=te(tn),Ri=W(tn,ee(460),z(D(421))),uo=W(tn,ee(461),z(D(421))),ah=Ie(Ri,uo),Bw=te(Ri),Dw=te(uo),Di=Ie(pr,Li,tn,Ri,uo),Su=Ie(W(Di,ee(477),z(D(421)))),Ow=te(Su),vu=Ie(W(Di,ee(478),z(D(421))),W(Di,ee(448),z(D(449)),ee(477),z(D(421)))),Pw=te(vu),Au=W(tn,ee(280),z(D(466)),z(D(466)),z(D(421))),Lw=te(Au),Iu=W(uo,ee(465),z(D(466)),z(D(466)),z(D(421))),Rw=te(Iu),so=Ie(Su,vu,W(Li,z(D(421))),W(ah,z(D(421))),W(pr,z(D(421))),Au,Iu,D(421)),Nw=te(so),ch=W(z(so),ee(290),bu(ee(281)),z(D(421))),Uw=te(ch),uh=Ie(W(so,ee(290),ee(281),z(D(421))),W(so,ee(281),z(D(421))),W(ee(281),z(D(421)))),kw=te(uh),fh=W(pr,Ie(W(D(6,"80")),W(D(6),ee(480)),ee(480)),z(D(481)),z(D(421))),Mw=te(fh),lh=W(pr,Ie(W(D(6,"443")),W(D(6,"443"),ee(480)),W(D(6),ee(443)),W(D(6),ee(448),ee(480)),W(ee(448),ee(480)),ee(448),ee(443)),z(D(481)),z(D(421))),Kw=te(lh),dh=Ie(W(D(777),z(D(421)))),Fw=te(dh),hh=Ie(W(D(400),z(D(421)))),qw=te(hh);function mr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Ni=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},ph=t=>"reason"in t?t.reason:new DOMException("This operation was aborted.","AbortError"),mh=2**31-1,yh=(t,e)=>{if(typeof t!="number"||Math.sign(t)!==1)return new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(typeof e?.setTimeout!="function"||typeof e?.clearTimeout!="function")return new TypeError("Expected `customTimers` to have a `setTimeout` and a `clearTimeout` function")};function Ui(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,u=()=>{try{t.cancel?.()}catch{}},l=new Promise((h,p)=>{let x=()=>{p(ph(i)),u()},m=yh(r,s);try{m?p(m):i?.aborted?x():i&&(c=x,i.addEventListener("abort",c,{once:!0}))}finally{t.then(h,p)}if(m||i?.aborted||r>mh)return;let g=n||o===!1||o instanceof Error?void 0:new Ni(o??`Promise timed out after ${r} milliseconds`);a=s.setTimeout.call(void 0,()=>{if(n)try{h(n())}catch(w){p(w)}else o===!1?h():p(o instanceof Error?o:g);u()},r)}).finally(()=>{try{l.clear()}catch{}try{c&&i.removeEventListener("abort",c)}catch{}});return l.clear=()=>{a!==void 0&&(s.clearTimeout.call(void 0,a),a=void 0)},l}var Tu=t=>typeof t=="function"?{filter:t}:{...t},bh=t=>t===1/0||Number.isSafeInteger(t)&&t>=0,gh=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],xh=t=>{for(let[e,r]of gh){let n=t?.[e],o=t?.[r];if(typeof n=="function"&&typeof o=="function")return{addListener:n.bind(t),removeListener:o.bind(t)}}throw new TypeError("Emitter is not compatible")},wh=t=>{let e=new Map;for(let[r,n]of t)for(let o of Array.isArray(r)?r:[r])e.has(o)||e.set(o,n);return e},Eh=({addListener:t,removeListener:e,handlers:r,signal:n,abortHandler:o,isDone:s})=>{n?.addEventListener("abort",o,{once:!0});for(let[i,a]of r)if(t(i,a),s()){e(i,a);return}},Sh=({removeListener:t,handlers:e,signal:r,abortHandler:n})=>{for(let[o,s]of e)t(o,s);r?.removeEventListener("abort",n)},vh=(t,e,r)=>{let n=Promise.resolve();return(o,s)=>{n=n.then(async()=>{if(e())return;let i;try{i=t?await t(o):!0}catch(a){e()||r(a);return}e()||s(i)})}};function Ah(t,e,r){let n=()=>{},o=!1,s,i=new Promise((a,c)=>{r=Tu(r);let{filter:u}=r;if(!bh(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:f,removeListener:l}=xh(t);if(r.count===0){a([]);return}let h=[],p=S=>{n(),c(S)},x=vh(u,()=>o,p),m=S=>{h.push(S),r.count===h.length&&(n(),a(h))},g=(...S)=>{if(o)return;let A=r.multiArgs?S:S[0];if(!u){m(A);return}x(A,R=>{R&&m(A)})},w=(...S)=>{p(r.rejectionMultiArgs?S:S[0])},I=()=>{p(r.signal.reason)},b={addListener:f,removeListener:l,handlers:wh([[e,g],[r.rejectionEvents??["error"],w]]),signal:r.signal,abortHandler:I,isDone:()=>o};n=()=>{o=!0,clearTimeout(s),Sh(b)},Eh(b),!(o||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&r.timeout<=2**31-1&&(s=setTimeout(n,r.timeout)),a(h))});if(i.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let a=Ui(i,{milliseconds:r.timeout});return a.cancel=()=>{n(),a.clear()},a}return i}function _u(t,e,r){let n=Ah(t,e,{...Tu(r),count:1,resolveImmediately:!1}),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Cu(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Vt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Ih(t){return t.reason}function ki(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??Ih;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var _h=4194304,fo=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ki=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Fi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},qi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ch(t){return typeof t?.closeRead=="function"}function Bh(t){return typeof t?.close=="function"}function Mi(t){return Ch(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Bh(t)?t.status!=="open":!1}function Dh(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Oh(t,e){let r=e?.maxBufferSize??_h,n=new me,o,s=!1,i;if(!Dh(t))throw new ae("Argument should be a Stream or a Multiaddr");let a=l=>{if(!s&&i==null){if(n.append(l.data),n.byteLength>r){let h=n.byteLength;n.consume(h);let p=new rn(`Read buffer overflow - ${h} > ${r}`);i=p,o?.reject(p),queueMicrotask(()=>{t.abort(p)});return}o?.resolve()}};t.addEventListener("message",a);let c=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};t.addEventListener("close",c);let u=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(s===!0)throw new fo("Stream was unwrapped");if(i!=null)throw i;if(Mi(t)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new Vt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let h=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await ki(o.promise,l?.signal),Mi(t)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let p=l?.bytes??n.byteLength;if(n.byteLength<p){if(Mi(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Vt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return f.read(l)}let x=n.sublist(0,p);return n.consume(p),x},async write(l,h){if(s===!0)throw new fo("Stream was unwrapped");t.send(l)||await _u(t,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",a),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n),n.consume(n.byteLength))),t}};return f}function Ph(t,e={}){let r=Oh(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Pe(e.maxDataLength));let n=e?.lengthDecoder??Mr,o=e?.lengthEncoder??nr;return{async read(i){let a=-1,c=new me;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Ki("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new qi(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Fi(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new Vt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Vt(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new me(o(i.byteLength),i),a)},async writeV(i,a){let c=new me(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function yr(t,e){let r=Ph(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i,s)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}function Lh(t){return t[Symbol.asyncIterator]!=null}function Rh(t){if(Lh(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Bu=Rh;var lo=globalThis.CustomEvent??Event;async function*Vi(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,s=[],i=mr(),a=mr(),c=!1,u,f=!1,l=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of t){if(s.length===r&&(i=mr(),await i.promise),f||l)break;let g={done:!1};s.push(g),m().then(w=>{g.done=!0,g.ok=!0,g.value=w,o.dispatchEvent(new lo("task-complete"))},w=>{g.done=!0,g.err=w,o.dispatchEvent(new lo("task-complete"))})}c=!0,o.dispatchEvent(new lo("task-complete"))}catch(m){u=m,o.dispatchEvent(new lo("task-complete"))}});function h(){return n?s[0]?.done:!!s.find(m=>m.done)}function*p(){for(;s.length>0&&s[0].done;){let m=s[0];if(s.shift(),m.ok)yield m.value;else throw f=!0,i.resolve(),m.err;i.resolve()}}function*x(){for(;h();)for(let m=0;m<s.length;m++)if(s[m].done){let g=s[m];if(s.splice(m,1),m--,g.ok)yield g.value;else throw f=!0,i.resolve(),g.err;i.resolve()}}try{for(;;){if(h()||(a=mr(),await a.promise),u!=null||(n?yield*p():yield*x(),u!=null))throw u;if(c&&s.length===0)break}}finally{l=!0,i.resolve()}}var Du="0.1.0";var Ou="id/push",Pu="1.0.0",Lu="1.0.0";var vt;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((s,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),s.protocolVersion!=null&&(i.uint32(42),i.string(s.protocolVersion)),s.agentVersion!=null&&(i.uint32(50),i.string(s.agentVersion)),s.publicKey!=null&&(i.uint32(10),i.bytes(s.publicKey)),s.listenAddrs!=null&&s.listenAddrs.length>0)for(let c of s.listenAddrs)i.uint32(18),i.bytes(c);if(s.observedAddr!=null&&(i.uint32(34),i.bytes(s.observedAddr)),s.protocols!=null&&s.protocols.length>0)for(let c of s.protocols)i.uint32(26),i.string(c);s.signedPeerRecord!=null&&(i.uint32(66),i.bytes(s.signedPeerRecord)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={listenAddrs:[],protocols:[]},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 5:{c.protocolVersion=s.string();break}case 6:{c.agentVersion=s.string();break}case 1:{c.publicKey=s.bytes();break}case 2:{if(a.limits?.listenAddrs!=null&&c.listenAddrs.length===a.limits.listenAddrs)throw new Je('Decode error - repeated field "listenAddrs" had too many elements');c.listenAddrs.push(s.bytes());break}case 4:{c.observedAddr=s.bytes();break}case 3:{if(a.limits?.protocols!=null&&c.protocols.length===a.limits.protocols)throw new Je('Decode error - repeated field "protocols" had too many elements');c.protocols.push(s.string());break}case 8:{c.signedPeerRecord=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u={listenAddrs:0,protocols:0},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 5:{yield{field:`${a}.protocolVersion`,value:s.string()};break}case 6:{yield{field:`${a}.agentVersion`,value:s.string()};break}case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{if(c.limits?.listenAddrs!=null&&u.listenAddrs===c.limits.listenAddrs)throw new Je('Streaming decode error - repeated field "listenAddrs" had too many elements');yield{field:`${a}.listenAddrs[]`,index:u.listenAddrs,value:s.bytes()},u.listenAddrs++;break}case 4:{yield{field:`${a}.observedAddr`,value:s.bytes()};break}case 3:{if(c.limits?.protocols!=null&&u.protocols===c.limits.protocols)throw new Je('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${a}.protocols[]`,index:u.protocols,value:s.string()},u.protocols++;break}case 8:{yield{field:`${a}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function r(s){return ze(s,t.codec())}t.encode=r;function n(s,i){return He(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(vt||(vt={}));var Te={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxListenAddresses:100,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Nu(t){return t.bytes.length===0}function Hi(t){if(t!=null&&t.length>0)try{let e=Qr(t);if(!Nu(e))return e}catch{}}async function ho(t,e,r,n,o,s=Te.maxListenAddresses){if(r("received identify from %p",n.remotePeer),o==null)throw new Ke("message was null or undefined");let i={};o.listenAddrs.length>s&&r("%p sent %d listen addresses, ignoring all but the first %d",n.remotePeer,o.listenAddrs.length,s);let a=o.listenAddrs.slice(0,s).map(Hi).filter(f=>f!=null);if(o.listenAddrs.length>0&&(i.addresses=a.map(f=>({isCertified:!1,multiaddr:f}))),o.protocols.length>0&&(i.protocols=o.protocols),o.publicKey!=null){let f=ir(o.publicKey);if(!Zr(f).equals(n.remotePeer))throw new Ke("public key did not match remote PeerId");i.publicKey=f}let c;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let f=o.signedPeerRecord,l=await tt.openAndCertify(f,je.DOMAIN),h=je.createFromProtobuf(l.payload),p=Zr(l.publicKey);if(!h.peerId.equals(p))throw new Ke("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(h.peerId))throw new Ke("signing key does not match remote PeerId");let x;try{x=await t.get(h.peerId)}catch(g){if(g.name!=="NotFoundError")throw g}if(x!=null&&(i.metadata=x.metadata,x.peerRecordEnvelope!=null)){let g=tt.createFromProtobuf(x.peerRecordEnvelope),w=je.createFromProtobuf(g.payload);w.seqNumber>=h.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",w.seqNumber,h.seqNumber),h=w,f=x.peerRecordEnvelope)}i.peerRecordEnvelope=f;let m=h.multiaddrs.filter(g=>!Nu(g)).slice(0,s);i.addresses=m.map(g=>({isCertified:!0,multiaddr:g})),c={seq:h.seqNumber,addresses:m}}else r("%p did not send a signed peer record",n.remotePeer);if(r.trace("patching %p with",n.remotePeer,i),await t.patch(n.remotePeer,i),o.agentVersion!=null||o.protocolVersion!=null){let f={};o.agentVersion!=null&&(f.AgentVersion=V(o.agentVersion)),o.protocolVersion!=null&&(f.ProtocolVersion=V(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,f),await t.merge(n.remotePeer,{metadata:f})}let u={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:a,observedAddr:o.observedAddr==null?void 0:Qr(o.observedAddr),protocols:o.protocols,signedPeerRecord:c,connection:n};return e.safeDispatchEvent("peer:identify",{detail:u}),u}function po(t){let e={...t[0]};for(let r of t.slice(1))r.protocolVersion!=null&&(e.protocolVersion=r.protocolVersion),r.agentVersion!=null&&(e.agentVersion=r.agentVersion),r.publicKey!=null&&(e.publicKey=r.publicKey),r.observedAddr!=null&&(e.observedAddr=r.observedAddr),r.signedPeerRecord!=null&&(e.signedPeerRecord=r.signedPeerRecord),e.listenAddrs=[...e.listenAddrs,...r.listenAddrs],e.protocols=[...new Set([...e.protocols,...r.protocols])];return e}async function mo(t,e,r,n){let o=yr(t,{maxDataLength:e}).pb(vt),s=[];for(let i=0;i<10;i++)try{s.push(await o.read(r))}catch(a){if(s.length===0)throw a;n.trace("stopped reading identify - %e",a);break}s.length>=10&&n("reached MAX_IDENTIFY_MESSAGES, returning truncated identify");try{await t.close(r)}catch(i){n.trace("error closing identify stream after read - %e",i),t.abort(i)}return s}var br=class{host;components;protocol;started;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;maxListenAddresses;runOnLimitedConnection;log;constructor(e,r){this.protocol=r.protocol,this.started=!1,this.components=e,this.log=r.log,this.timeout=r.timeout??Te.timeout,this.maxInboundStreams=r.maxInboundStreams??Te.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Te.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Te.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Te.maxObservedAddresses,this.maxListenAddresses=r.maxListenAddresses??Te.maxListenAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Te.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Te.protocolPrefix}/${Du}`,agentVersion:e.nodeInfo.userAgent},this.handleProtocol=this.handleProtocol.bind(this)}isStarted(){return this.started}async start(){this.started||(await this.components.peerStore.merge(this.components.peerId,{metadata:{AgentVersion:V(this.host.agentVersion),ProtocolVersion:V(this.host.protocolVersion)}}),await this.components.registrar.handle(this.protocol,this.handleProtocol,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}};var yo=class extends br{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Te.protocolPrefix}/${Ou}/${Lu}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??Te.concurrency,this._push=Cu(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Te.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[on]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let e=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),r=new je({peerId:this.components.peerId,multiaddrs:e}),n=await tt.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=Y(s.metadata.get("AgentVersion")??V(this.host.agentVersion)),a=Y(s.metadata.get("ProtocolVersion")??V(this.host.protocolVersion)),c=this;async function*u(){for(let f of c.connectionManager.getConnections())(await c.components.peerStore.get(f.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let h,p=AbortSignal.timeout(c.timeout);try{h=await f.newStream(c.protocol,{signal:p,runOnLimitedConnection:c.runOnLimitedConnection}),await yr(h,{maxDataLength:c.maxMessageSize}).pb(vt).write({listenAddrs:e.map(m=>m.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:p}),await h.close({signal:p})}catch(x){h?.log.newScope("identify-push")?.error("could not push identify update to peer",x),h?.abort(x)}})}await Bu(Vi(u(),{concurrency:this.concurrency}))}catch(e){this.log.error("error pushing updates to peers - %e",e)}}async handleProtocol(e,r){let n=e.log.newScope("identify-push");if(this.components.peerId.equals(r.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},s=await mo(e,this.maxMessageSize,o,n);await ho(this.components.peerStore,this.components.events,n,r,po(s),this.maxListenAddresses),n.trace("handled push from %p",r.remotePeer)}};var bo=class extends br{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Te.protocolPrefix}/${"id"}/${Pu}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Te.runOnConnectionOpen)&&e.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[on]=["@libp2p/identify"];async _identify(e,r={}){let n,o;if(r.signal==null){let s=AbortSignal.timeout(this.timeout);r={...r,signal:s}}this.log("run identify on new connection %a",e.remoteAddr);try{n=await e.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),o=n.log.newScope("identify");let s=await mo(n,this.maxMessageSize,r,o);return po(s)}catch(s){throw o?.error("identify failed - %e",s),n?.abort(s),s}}async identify(e,r={}){let n=await this._identify(e,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Ke("Public key was missing from identify message");let a=ir(o),c=Zr(a);if(!e.remotePeer.equals(c))throw new Ke("Identified peer does not match the expected peer");if(this.components.peerId.equals(c))throw new Ke("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",c,s),ho(this.components.peerStore,this.components.events,this.log,e,n,this.maxListenAddresses)}maybeAddObservedAddress(e){let r=Hi(e);if(r==null||(this.log.trace("our observed address was %a",r),yu(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!pu(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Eu.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(e,r){let n=e.log.newScope("identify");n("responding to identify");let o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let f=new je({peerId:this.components.peerId,multiaddrs:i});a=(await tt.seal(f,this.components.privateKey,{signal:o})).marshal().subarray()}let c=r.remoteAddr.bytes;wu.matches(r.remoteAddr)||(c=void 0);let u=yr(e).pb(vt);n("send response"),await u.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ge(this.components.privateKey.publicKey),listenAddrs:i.map(f=>f.bytes),signedPeerRecord:a,observedAddr:c,protocols:s.protocols},{signal:o}),n("close write"),await u.unwrap().unwrap().close({signal:o})}};function Fh(t={}){return e=>new bo(e,t)}function qh(t={}){return e=>new yo(e,t)}return Hu(Vh);})();
|
|
2
|
+
"use strict";var Libp2PIdentify=(()=>{var xo=Object.defineProperty;var Ku=Object.getOwnPropertyDescriptor;var Fu=Object.getOwnPropertyNames;var qu=Object.prototype.hasOwnProperty;var Ce=(t,e)=>{for(var r in e)xo(t,r,{get:e[r],enumerable:!0})},Vu=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Fu(e))!qu.call(t,o)&&o!==r&&xo(t,o,{get:()=>e[o],enumerable:!(n=Ku(e,o))||n.enumerable});return t};var Hu=t=>Vu(xo({},"__esModule",{value:!0}),t);var Vh={};Ce(Vh,{identify:()=>Fh,identifyPush:()=>qh});var ae=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},At=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var rn=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var nn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Ke=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var It=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var wo=Symbol.for("@libp2p/peer-id");var on=Symbol.for("@libp2p/service-capabilities");function pe(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var Io={};Ce(Io,{base58btc:()=>he,base58flickr:()=>Xu});var gp=new Uint8Array(0);function Yi(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ne(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Tt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Tt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function ji(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var $i=4096;function Wi(t){let e=t.length;if(e<=$i)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=$i));return r}function zu(t){return t?.buffer instanceof ArrayBuffer}function Tt(t){return zu(t)?t:t.slice()}function $u(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<t.length;s++){var i=t.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=t.length,l=t.charAt(0),h=Math.log(f)/Math.log(256),p=Math.log(256)/Math.log(f);function x(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var I=0,b=0,S=0,A=w.length;S!==A&&w[S]===0;)S++,I++;for(var R=(A-S)*p+1>>>0,K=new Uint8Array(R);S!==A;){for(var P=w[S],O=0,N=R-1;(P!==0||O<b)&&N!==-1;N--,O++)P+=256*K[N]>>>0,K[N]=P%f>>>0,P=P/f>>>0;if(P!==0)throw new Error("Non-zero carry");b=O,S++}for(var F=R-b;F!==R&&K[F]===0;)F++;for(var H=l.repeat(I);F<R;++F)H+=t.charAt(K[F]);return H}function m(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var I=0;if(w[I]!==" "){for(var b=0,S=0;w[I]===l;)b++,I++;for(var A=(w.length-I)*h+1>>>0,R=new Uint8Array(A);w[I];){var K=w.charCodeAt(I);if(K>255)return;var P=n[K];if(P===255)return;for(var O=0,N=A-1;(P!==0||O<S)&&N!==-1;N--,O++)P+=f*R[N]>>>0,R[N]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");S=O,I++}if(w[I]!==" "){for(var F=A-S;F!==A&&R[F]===0;)F++;for(var H=new Uint8Array(b+(A-F)),J=b;F!==A;)H[J++]=R[F++];return H}}}function g(w){var I=m(w);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:x,decodeUnsafe:m,decode:g}}var Yu=$u,ju=Yu,Gi=ju;var Eo=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},So=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,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(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Xi(this,e)}},vo=class{decoders;constructor(e){this.decoders=e}or(e){return Xi(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Xi(t,e){return new vo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Ao=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Eo(e,r,n),this.decoder=new So(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ht({name:t,prefix:e,encode:r,decode:n}){return new Ao(t,e,r,n)}function ft({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Gi(r,t,n);return Ht({prefix:e,name:t,encode:o,decode:i=>Ne(s(i))})}function Wu(t,e,r,n){let o=t.length;for(;t[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=e[t[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 Zu(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Gu(t,e){let r={};for(let n=0;n<t.length;++n)if(t[n]!=="="&&(r[t[n]]=n,e)){let o=t[n].toLowerCase(),s=t[n].toUpperCase();o!==t[n]&&(r[o]=n),s!==t[n]&&(r[s]=n)}return r}function fe({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=Gu(n,o);return Ht({prefix:e,name:t,encode(i){return Zu(i,n,r)},decode(i){return Wu(i,s,r,t)}})}var he=ft({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xu=ft({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var To={};Ce(To,{base32:()=>lt,base32hex:()=>tf,base32hexpad:()=>nf,base32hexpadupper:()=>of,base32hexupper:()=>rf,base32pad:()=>Ju,base32padupper:()=>ef,base32upper:()=>Qu,base32z:()=>sf});var lt=fe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Qu=fe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Ju=fe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),ef=fe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),tf=fe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),rf=fe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),nf=fe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),of=fe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),sf=fe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var _o={};Ce(_o,{base36:()=>xr,base36upper:()=>af});var xr=ft({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),af=ft({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var cf=ea,Qi=128,uf=127,ff=~uf,lf=Math.pow(2,31);function ea(t,e,r){e=e||[],r=r||0;for(var n=r;t>=lf;)e[r++]=t&255|Qi,t/=128;for(;t&ff;)e[r++]=t&255|Qi,t>>>=7;return e[r]=t|0,ea.bytes=r-n+1,e}var df=Co,hf=128,Ji=127;function Co(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Co.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Ji)<<o:(i&Ji)*Math.pow(2,o),o+=7}while(i>=hf);return Co.bytes=s-n,r}var pf=Math.pow(2,7),mf=Math.pow(2,14),yf=Math.pow(2,21),bf=Math.pow(2,28),gf=Math.pow(2,35),xf=Math.pow(2,42),wf=Math.pow(2,49),Ef=Math.pow(2,56),Sf=Math.pow(2,63),vf=function(t){return t<pf?1:t<mf?2:t<yf?3:t<bf?4:t<gf?5:t<xf?6:t<wf?7:t<Ef?8:t<Sf?9:10},Af={encode:cf,decode:df,encodingLength:vf},If=Af,wr=If;function Er(t,e=0){let r=wr.decode(t,e),n=wr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function zt(t,e,r=0){return wr.encode(t,e,r),e}function $t(t){return wr.encodingLength(t)}function We(t,e){let r=e.byteLength,n=$t(t),o=n+$t(r),s=new Uint8Array(o+r);return zt(t,s,0),zt(r,s,n),s.set(e,o),new Yt(t,r,e,s)}function Sr(t){let e=Ne(t),[r,n]=Er(e),[o,s]=Er(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Yt(r,o,i,e)}function ta(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Yi(t.bytes,r.bytes)}}var Yt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Tt(n),this.bytes=Tt(o)}};function ra(t,e){let{bytes:r,version:n}=t;return n===0?_f(r,Bo(t),e??he.encoder):Cf(r,Bo(t),e??lt.encoder)}var na=new WeakMap;function Bo(t){let e=na.get(t);if(e==null){let r=new Map;return na.set(t,r),r}return e}var ge=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Tt(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:e,multihash:r}=this;if(e!==vr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Bf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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:e,digest:r}=this.multihash,n=We(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&ta(e.multihash,n.multihash)}toString(e){return ra(this,e)}toJSON(){return{"/":ra(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??oa(n,o,s.bytes))}else if(r[Df]===!0){let{version:n,multihash:o,code:s}=r,i=Sr(o);return t.create(n,s,i)}else return null}static create(e,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(e){case 0:{if(r!==vr)throw new Error(`Version 0 CID must use dag-pb (code: ${vr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=oa(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,vr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Ne(e.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 Yt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=Er(e.subarray(r));return r+=h,l},o=n(),s=vr;if(o===18)o=0,r=0;else if(o===1)s=n();else throw o===0?new RangeError("Invalid CID version, v0 is always implicit"):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(e,r){let[n,o]=Tf(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Bo(s).set(n,e),s}};function Tf(t,e){switch(t[0]){case"Q":{let r=e??he;return[he.prefix,r.decode(`${he.prefix}${t}`)]}case he.prefix:{let r=e??he;return[he.prefix,r.decode(t)]}case lt.prefix:{let r=e??lt;return[lt.prefix,r.decode(t)]}case xr.prefix:{let r=e??xr;return[xr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function _f(t,e,r){let{prefix:n}=r;if(n!==he.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Cf(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var vr=112,Bf=18;function oa(t,e,r){let n=$t(t),o=n+$t(e),s=new Uint8Array(o+r.byteLength);return zt(t,s,0),zt(e,s,n),s.set(r,o),s}var Df=Symbol.for("@ipld/js-cid/CID");var Do={};Ce(Do,{identity:()=>Fe});var sa=0,Of="identity",ia=Ne;function Pf(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return We(sa,ia(t))}var Fe={code:sa,name:Of,encode:ia,digest:Pf};function Lf(t){return t.buffer instanceof ArrayBuffer}function _e(t){return Lf(t)?t:t.slice()}async function aa(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,_e(e),_e(r.subarray()));return n?.signal?.throwIfAborted(),s}function xe(t=0){return new Uint8Array(t)}function Se(t=0){return new Uint8Array(t)}function Rf(t){return t?.buffer instanceof ArrayBuffer}function Oo(t){if(Rf(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ze(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Se(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Oo(r)}var ua=Symbol.for("@achingbrain/uint8arraylist");function ca(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function an(t){return!!t?.[ua]}var me=class t{bufs;length;[ua]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(an(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(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(an(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(e){let r=ca(this.bufs,e);return r.buf[r.index]}set(e,r){let n=ca(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(an(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return Ze(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Ze(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===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,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-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-e}}indexOf(e,r=0){if(!an(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.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 h=u;h>=0;h--){let p=this.get(l+h);if(n[h]!==p){f=Math.max(1,h-a[p]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=xe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=xe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=xe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=xe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=xe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=xe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=xe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=xe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!pe(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Po={};Ce(Po,{base10:()=>Nf});var Nf=ft({prefix:"9",name:"base10",alphabet:"0123456789"});var Lo={};Ce(Lo,{base16:()=>Uf,base16upper:()=>kf});var Uf=fe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),kf=fe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Ro={};Ce(Ro,{base2:()=>Mf});var Mf=fe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var No={};Ce(No,{base256emoji:()=>Hf});var fa=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}"),Kf=fa.reduce((t,e,r)=>(t[r]=e,t),[]),Ff=fa.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function qf(t){return t.reduce((e,r)=>(e+=Kf[r],e),"")}function Vf(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ff[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Hf=Ht({prefix:"\u{1F680}",name:"base256emoji",encode:qf,decode:Vf});var ko={};Ce(ko,{base64:()=>zf,base64pad:()=>$f,base64url:()=>Uo,base64urlpad:()=>Yf});var zf=fe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),$f=fe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Uo=fe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yf=fe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mo={};Ce(Mo,{base8:()=>jf});var jf=fe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ko={};Ce(Ko,{identity:()=>Wf});var Wf=Ht({prefix:"\0",name:"identity",encode:t=>Wi(Ne(t)),decode:t=>Ne(ji(t))});var rm=new TextEncoder,nm=new TextDecoder;var Vo={};Ce(Vo,{sha256:()=>Ar,sha512:()=>Qf});var Xf=20;function qo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Fo(t,e,r,n,o)}var Fo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Xf,this.maxDigestLength=s}digest(e,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(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?la(n,this.code,r?.truncate):n.then(o=>la(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function la(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return We(e,t)}function ha(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Ar=qo({name:"sha2-256",code:18,encode:ha("SHA-256")}),Qf=qo({name:"sha2-512",code:19,encode:ha("SHA-512")});var Ir={...Ko,...Ro,...Mo,...Po,...Lo,...To,..._o,...Io,...ko,...No},mm={...Vo,...Do};function ma(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var pa=ma("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Ho=ma("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Se(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Jf={utf8:pa,"utf-8":pa,hex:Ir.base16,latin1:Ho,ascii:Ho,binary:Ho,...Ir},cn=Jf;function V(t,e="utf8"){let r=cn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Y(t,e="utf8"){let r=cn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var el=parseInt("11111",2),zo=parseInt("10000000",2),tl=parseInt("01111111",2),ya={0:Tr,1:Tr,2:rl,3:sl,4:il,5:ol,6:nl,16:Tr,22:Tr,48:Tr};function rt(t,e={offset:0}){let r=t[e.offset]⪙if(e.offset++,ya[r]!=null)return ya[r](t,e);throw new Error("No decoder for tag "+r)}function _r(t,e){let r=0;if((t[e.offset]&zo)===zo){let n=t[e.offset]&tl,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");o+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function Tr(t,e){_r(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=rt(t,e);if(n===null)break;r.push(n)}return r}function rl(t,e){let r=_r(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function nl(t,e){let r=_r(t,e),n=e.offset+r,o=t[e.offset];e.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(;e.offset<n;){let u=t[e.offset];if(e.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 ol(t,e){return e.offset++,null}function sl(t,e){let r=_r(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function il(t,e){let r=_r(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function al(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new me;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function $o(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=al(t.byteLength);return new me(Uint8Array.from([e.byteLength|zo]),e)}function Be(t){let e=new me,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new me(Uint8Array.from([2]),$o(e),e)}function un(t){let e=Uint8Array.from([0]),r=new me(e,t);return new me(Uint8Array.from([3]),$o(r),r)}function dt(t,e=48){let r=new me;for(let n of t)r.append(n);return new me(Uint8Array.from([e]),$o(r),r)}var cl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ul=Uint8Array.from([6,5,43,129,4,0,34]),fl=Uint8Array.from([6,5,43,129,4,0,35]),ll={ext:!0,kty:"EC",crv:"P-256"},dl={ext:!0,kty:"EC",crv:"P-384"},hl={ext:!0,kty:"EC",crv:"P-521"},Yo=32,jo=48,Wo=66;function Zo(t){let e=rt(t);return ba(e)}function ba(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Yo*2+1)return n=Y(e.subarray(r,r+Yo),"base64url"),o=Y(e.subarray(r+Yo),"base64url"),new jt({...ll,key_ops:["verify"],x:n,y:o});if(e.byteLength===jo*2+1)return n=Y(e.subarray(r,r+jo),"base64url"),o=Y(e.subarray(r+jo),"base64url"),new jt({...dl,key_ops:["verify"],x:n,y:o});if(e.byteLength===Wo*2+1)return n=Y(e.subarray(r,r+Wo),"base64url"),o=Y(e.subarray(r+Wo),"base64url"),new jt({...hl,key_ops:["verify"],x:n,y:o});throw new ae(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function ga(t){return dt([Be(Uint8Array.from([1])),dt([pl(t.crv)],160),dt([un(new me(Uint8Array.from([4]),V(t.x??"","base64url"),V(t.y??"","base64url")))],161)]).subarray()}function pl(t){if(t==="P-256")return cl;if(t==="P-384")return ul;if(t==="P-521")return fl;throw new ae(`Invalid curve ${t}`)}var jt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=ga(this.jwk)),this._raw}toMultihash(){return Fe.digest(Ge(this))}toCID(){return ge.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}async verify(e,r,n){return aa(this.jwk,r,e,n)}};var fn=BigInt(4294967295),xa=BigInt(32);function ml(t,e=!1){return e?{h:Number(t&fn),l:Number(t>>xa&fn)}:{h:Number(t>>xa&fn)|0,l:Number(t&fn)|0}}function wa(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=ml(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var yl=t=>t/2**32|0,bl=t=>t>>>0;function Ea(t,e,r,n){let o=yl(r),s=bl(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}var Go=(t,e,r)=>t>>>r,Xo=(t,e,r)=>t<<32-r|e>>>r,Ct=(t,e,r)=>t>>>r|e<<32-r,Bt=(t,e,r)=>t<<32-r|e>>>r,Cr=(t,e,r)=>t<<64-r|e>>>r-32,Br=(t,e,r)=>t>>>r-32|e<<64-r;function Xe(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Sa=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),va=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Aa=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ia=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Ta=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),_a=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;function ln(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Qo=t=>t?`"${t}" `:"";function nt(t,e=""){if(typeof t!="number")throw new TypeError(Qo(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Qo(e)+"expected integer >= 0, got "+t);return t}function Ue(t,e,r=""){if(ln(t)&&(e===void 0||t.length===e))return t;e!==void 0&&nt(e,"length");let n=ln(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=Qo(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function dn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(nt(t.outputLen),nt(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var xl=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},Ca=(t,e)=>{xl(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function Wt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function hn(t,e){Ue(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Dt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function pn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function qe(t,e){return t<<32-e|t>>>e}var Da=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",wl=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function mn(t){if(Ue(t),Da)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=wl[t[r]];return e}function Ba(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function yn(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Da)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Ba(t.charCodeAt(s)),a=Ba(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Jo(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ue(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function El(t,e,r="opts"){return Ca(t,"defaults"),e!==void 0&&Ca(e,r),Object.assign(Object.create(null),t,e)}function es(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=El({},e,"info");let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Oa(t=32){nt(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var ts=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Pa(t,e,r){return t&e^~t&r}function La(t,e,r){return t&e^t&r^e&r}var Dr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=pn(this.buffer)}update(e){Wt(this),Ue(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let u=pn(e);for(;o<=s-a;a+=o)this.process(u,a);i=!0;continue}n.set(a===0&&c===s?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Wt(this),hn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),Ea(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===r?n:pn(e),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Ra=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Na=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Sl=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ht=new Uint32Array(64),rs=class extends Dr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|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}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let l=0;l<16;l++,r+=4)ht[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=ht[l-15],p=ht[l-2],x=qe(h,7)^qe(h,18)^h>>>3,m=qe(p,17)^qe(p,19)^p>>>10;ht[l]=m+ht[l-7]+x+ht[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 h=qe(a,6)^qe(a,11)^qe(a,25),p=f+h+Pa(a,c,u)+Sl[l]+ht[l]|0,m=(qe(n,2)^qe(n,13)^qe(n,22))+La(n,o,s)|0;f=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+m|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(){Dt(ht)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Dt(this.buffer)}},ns=class extends rs{constructor(){super(32,Ra)}};var Ua=wa(["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(t=>BigInt(t))),vl=Ua[0],Al=Ua[1],pt=new Uint32Array(80),mt=new Uint32Array(80),os=class extends Dr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:p,Gl:x,Hh:m,Hl:g}=this;return[e,r,n,o,s,i,a,c,u,f,l,h,p,x,m,g]}set(e,r,n,o,s,i,a,c,u,f,l,h,p,x,m,g){this.Ah=e|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=h|0,this.Gh=p|0,this.Gl=x|0,this.Hh=m|0,this.Hl=g|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let b=0;b<16;b++,r+=4)pt[b]=e.getUint32(r),mt[b]=e.getUint32(r+=4);for(let b=16;b<80;b++){let S=pt[b-15]|0,A=mt[b-15]|0,R=Ct(S,A,1)^Ct(S,A,8)^Go(S,A,7),K=Bt(S,A,1)^Bt(S,A,8)^Xo(S,A,7),P=pt[b-2]|0,O=mt[b-2]|0,N=Ct(P,O,19)^Cr(P,O,61)^Go(P,O,6),F=Bt(P,O,19)^Br(P,O,61)^Xo(P,O,6),H=Aa(K,F,mt[b-7],mt[b-16]),J=Ia(H,R,N,pt[b-7],pt[b-16]);pt[b]=J|0,mt[b]=H|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:p,Fl:x,Gh:m,Gl:g,Hh:w,Hl:I}=this;for(let b=0;b<80;b++){let S=Ct(l,h,14)^Ct(l,h,18)^Cr(l,h,41),A=Bt(l,h,14)^Bt(l,h,18)^Br(l,h,41),R=l&p^~l&m,K=h&x^~h&g,P=Ta(I,A,K,Al[b],mt[b]),O=_a(P,w,S,R,vl[b],pt[b]),N=P|0,F=Ct(n,o,28)^Cr(n,o,34)^Cr(n,o,39),H=Bt(n,o,28)^Br(n,o,34)^Br(n,o,39),J=n&s^n&a^s&a,_=o&i^o&c^i&c;w=m|0,I=g|0,m=p|0,g=x|0,p=l|0,x=h|0,{h:l,l:h}=Xe(u|0,f|0,O|0,N|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let M=Sa(N,H,_);n=va(M,O,F,J),o=M|0}({h:n,l:o}=Xe(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Xe(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Xe(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Xe(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=Xe(this.Eh|0,this.El|0,l|0,h|0),{h:p,l:x}=Xe(this.Fh|0,this.Fl|0,p|0,x|0),{h:m,l:g}=Xe(this.Gh|0,this.Gl|0,m|0,g|0),{h:w,l:I}=Xe(this.Hh|0,this.Hl|0,w|0,I|0),this.set(n,o,s,i,a,c,u,f,l,h,p,x,m,g,w,I)}roundClean(){Dt(pt,mt)}destroy(){this.destroyed=!0,Dt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ss=class extends os{constructor(){super(64,Na)}};var Zt=es(()=>new ns,ts(1));var is=es(()=>new ss,ts(3));function gn(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var G=(t,e,r)=>Ue(t,e,r),as=nt;function Ma(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function yt(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Ot(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var Or=mn,ke=(...t)=>Jo(...t),Gt=t=>yn(t),gt=ln,Pt=t=>Oa(t),bn=BigInt(0),ka=BigInt(1),Il=t=>t?`"${t}" `:"";function De(t,e=""){if(typeof t!="boolean")throw new TypeError(Il(e)+"expected boolean, got type="+typeof t);return t}function xn(t){if(typeof t=="bigint"){if(!bt(t))throw new RangeError("positive bigint expected, got "+t)}else as(t);return t}function ot(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Pr(t){let e=xn(t).toString(16);return e.length&1?"0"+e:e}function Ka(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?bn:BigInt("0x"+t)}function Qe(t){return Ka(mn(t))}function Lt(t){return Ka(mn(Lr(Ue(t)).reverse()))}function wn(t,e){if(nt(e),e===0)throw new Error("zero output length is invalid");t=xn(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return yn(n.padStart(r,"0"))}function cs(t,e){return wn(t,e).reverse()}function Lr(t){return Uint8Array.from(G(t))}function bt(t){return typeof t=="bigint"&&bn<=t}function us(t,e,r){return bt(t)&&bt(e)&&bt(r)&&e<=t&&t<r}function Xt(t,e,r,n){if(!us(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Qt(t){if(t<bn)throw new Error("expected non-negative bigint, got "+t);return t===bn?0:t.toString(2).length}var Rr=t=>(ot(t,"n"),(ka<<BigInt(t))-ka);function Fa(t,e,r){if(nt(t,"hashLen"),nt(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=g=>new Uint8Array(g),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...g)=>r(u,ke(c,...g)),p=(g=o)=>{u=h(s,g),c=h(),g.length!==0&&(u=h(i,g),c=h())},x=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let g=0,w=[];for(;g<e;){c=h();let I=c.slice();w.push(I),g+=c.length}return ke(...w)};return(g,w)=>{l(),p(g);let I;for(;(I=w(x()))===void 0;)p();return l(),I}}function Oe(t,e={},r={},n="object"){yt(t,n),yt(e,"fields"),yt(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=t[i];if(!Object.hasOwn(t,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(e,!1),s(r,!0)}var ye=BigInt(0),X=BigInt(1),xt=BigInt(2),Ha=BigInt(3),fs=BigInt(4),za=BigInt(5),Tl=BigInt(7),$a=BigInt(8),_l=BigInt(9),Cl=BigInt(15),Ya=BigInt(16),Bl=BigInt("0x10000000000000000");function ce(t,e){if(e<=ye)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ye?r:e+r}function ja(t,e,r){if(r<=X)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<ye)throw new Error("invalid exponent, negatives unsupported");if(e===ye)return X;if(e===X)return t;let n=t%r;if(n<ye&&(n+=r),e<Bl){let a=X;for(;e>ye;)e&X&&(a=a*n%r),n=n*n%r,e>>=X;return a}let o=[];for(;e>ye;)o.push(Number(e&Cl)),e>>=fs;let s=new Array(16);s[0]=X,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function se(t,e,r){if(r<=X)throw new Error("pow2: expected modulus > 1, got "+r);if(e<ye)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ye;)n*=n,n%=r;return n}function qa(t,e){if(t===ye)throw new Error("invert: expected non-zero number");if(e<=X)throw new Error("invert: expected modulus > 1, got "+e);let r=ce(t,e),n=e,o=ye,s=X;for(;r!==ye;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==X)throw new Error("invert: does not exist");return ce(o,e)}function Wa(t,e){if(e<=X)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ce(t,e);if(r===ye)throw new Error("invertCt: expected non-zero number");let n=ja(r,e-xt,e);if(ce(r*n,e)!==X)throw new Error("invertCt: does not exist");return n}function ls(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function ds(t,e){if((t&X)===ye)throw new Error(e+": expected odd modulus, got "+t)}function Za(t,e){let r=t,n=(r.ORDER+X)/fs,o=r.pow(e,n);return ls(r,o,e),o}function Dl(t,e){let r=t,n=(r.ORDER-za)/$a,o=r.mul(e,xt),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,xt),s),c=r.mul(i,r.sub(a,r.ONE));return ls(r,c,e),c}function Ol(t){let e=er(t),r=Ga(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+Tl)/Ya;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),h=u.mul(f,o),p=u.mul(f,s),x=u.eql(u.sqr(l),c),m=u.eql(u.sqr(h),c);f=u.cmov(f,l,x),l=u.cmov(p,h,m);let g=u.eql(u.sqr(l),c),w=u.cmov(f,l,g);return ls(u,w,c),w})}function Ga(t){if(t<Ha)throw new Error("sqrt is not defined for small field");ds(t,"tonelliShanks");let e=t-X,r=0;for(;e%xt===ye;)e/=xt,r++;let n=xt,o=er(t);for(;Nr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Za;let s=o.pow(n,e),i=(e+X)/xt;return function(c,u){let f=c;if(f.is0(u))return u;if(Nr(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,s),p=f.pow(u,e),x=f.pow(u,i);for(;!f.eql(p,f.ONE);){if(f.is0(p))throw new Error("Cannot find square root: probably non-prime P");let m=1,g=f.sqr(p);for(;!f.eql(g,f.ONE);)if(m++,g=f.sqr(g),m===l)throw new Error("Cannot find square root");let w=X<<BigInt(l-m-1),I=f.pow(h,w);l=m,h=f.sqr(I),p=f.mul(p,h),x=f.mul(x,I)}return x}}function Pl(t){return ds(t,"Fp.sqrt"),t%fs===Ha?Za:t%$a===za?Dl:t%Ya===_l?Ol(t):Ga(t)}var Xa=(t,e)=>(ce(t,e)&X)===X,Ll=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Jt(t){if(yt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);ot(t.BYTES,"BYTES"),ot(t.BITS,"BITS");for(let e of Ll)Ot(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Sn(t,e,r=!1){Jt(t),gn(e,"nums"),De(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function Nr(t,e){Jt(t);let r=t;ds(r.ORDER,"FpLegendre");let n=(r.ORDER-X)/xt,o=r.pow(e,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 Rl(t,e){if(e!==void 0&&as(e),t<=ye)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Qt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Va=new WeakMap,En=class{ORDER;BITS;BYTES;isLE;ZERO=ye;ONE=X;_lengths;_mod;constructor(e,r={}){if(e<=X)throw new Error("invalid field: expected ORDER > 1, got "+e);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}=Rl(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return ce(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ye<=e&&e<this.ORDER}is0(e){return e===ye}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&X)===X}neg(e){return ce(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ce(e*e,this.ORDER)}add(e,r){return ce(e+r,this.ORDER)}sub(e,r){return ce(e-r,this.ORDER)}mul(e,r){return ce(e*r,this.ORDER)}pow(e,r){return ja(e,r,this.ORDER)}div(e,r){return ce(e*qa(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return qa(e,this.ORDER)}sqrt(e){let r=Va.get(this);return r||Va.set(this,r=Pl(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?cs(e,this.BYTES):wn(e,this.BYTES)}fromBytes(e,r=!1){G(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?Lt(e):Qe(e);if(a&&(c=ce(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Sn(this,e,!0)}cmov(e,r,n){return De(n,"condition"),n?r:e}};function er(t,e={}){return Object.freeze(En.prototype),new En(t,e)}function Qa(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=X)throw new Error("field order must be greater than 1");let e=Qt(t-X);return Math.ceil(e/8)}function vn(t){let e=Qa(t);return e+Math.ceil(e/2)}function An(t,e,r=!1){G(t);let n=t.length,o=Qa(e),s=Math.max(vn(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Lt(t):Qe(t),a=ce(i,e-X)+X;return r?cs(a,o):wn(a,o)}var ms=BigInt(0),Ur=BigInt(1),Nl=BigInt(4),hs=16,Ja=128,Ul=5,ec=2**31;function wt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Ot(e.fromAffine,"Point.fromAffine"),Ot(e.fromBytes,"Point.fromBytes"),Ot(e.fromHex,"Point.fromHex"),yt(e.BASE,"Point.BASE"),yt(e.ZERO,"Point.ZERO"),Jt(e.Fp),Jt(e.Fn)}function In(t,e){wt(t),rc(e,t);let r=Sn(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function kl(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function Ml(t,e){let r=t*(4*e+128);if(r>ec)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+ec/2**20+" MiB")}function ys(t,e){if(t!==void 0){Ot(t,"randomBytes");try{let r=t(e);if(!gt(r)||r.length!==e)return}catch{return}return t}}function rc(t,e){gn(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Kl(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):bt(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var nc=new WeakMap;function ps(t){return nc.get(t)||1}function Fl(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function ql(t,e){let r=2**e,n=r/2,o=BigInt(r-1),s=[];for(;t>ms;){let i=0;t&Ur&&(i=Number(t&o),i>=n&&(i-=r),t-=BigInt(i)),s.push(i),t>>=Ur}return s}function Vl(t,e,r){let n=2**e,o=n/2,s=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let u=Number(t&s);t>>=i,u>o&&(u-=n,t+=Ur),a.push(u)}if(t!==ms)throw new Error("invalid wnaf");return a}function Hl(t,e,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=t;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=e[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var tr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){wt(e),this.randomBytes=ys(r,hs),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=e;for(let c=0;c<o;c++){let u=a;for(let f=0;f<s;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(e,r){let{W:n,windows:o,comp:s}=e,i=2**(n-1),a=Vl(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],h=f*i,p=Math.abs(l)-1,x=s[h];for(let g=1;g<i;g++)x=g===p?s[h+g]:x;let m=x.negate();l===0?u=u.add(s[h]):c=c.add(l<0?m:x)}return{p:c,f:u}}getWnafPrecomputes(e,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!us(r,Ur,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let s=ps(e);return s===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Ja,s=this.randomBytes(hs);if(!gt(s)||s.length!==hs)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Qe(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,r,n){let o=Ul,s=1<<o,i=Rr(o),a=new Array(s);a[0]=this.ZERO;for(let f=1;f<s;f++)a[f]=a[f-1].add(e);let c=Math.ceil(n/o),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let p=0;p<o;p++)u=u.double();let l=Number(r>>BigInt(f*o)&i),h=a[0];for(let p=1;p<s;p++)h=p===l?a[p]:h;u=u.add(h)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Ur?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!bt(r))throw new Error("invalid scalar");let o=ps(e);if(o===1||r>=this.Point.Fn.ORDER)return Tn(this.Point,[e],[r],!0);let s=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(e,r){this.assertPoint(e),kl(r,this.bits);let n=Math.ceil((this.bits+Ja)/r)+1;Ml(n*2**(r-1),this.Point.Fp.BYTES),nc.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return ps(e)!==1}};function Tn(t,e,r,n=!1){if(wt(t),rc(e,t),De(n,"allowOversized"),Kl(r,t.Fn,n?t.Fn.ORDER**Nl:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>Fl(i,4)),s=r.map(i=>ql(i,4));return Hl(t.ZERO,o,s)}function tc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Jt(e),e}else return er(t,{isLE:r})}function _n(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Oe(r);for(let c of["p","n","h"]){let u=e[c];if(!(bt(u)&&u!==ms))throw new Error(`CURVE.${c} must be positive bigint`)}let o=tc(e.p,r.Fp,n),s=tc(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function Cn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var Bn=BigInt(0),Dn=BigInt(1),On=BigInt(2),zl=BigInt(4),oc=BigInt(8);function $l(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function sc(t,e={}){Oe(e,{},{},"extraOpts");let r=e,n=_n("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(Nr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Nr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Oe(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?Pt:r.randomBytes,u=On<<BigInt(o.BYTES*8)-Dn;function f(I){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(I)}let l=r.uvRatio===void 0?(I,b)=>{try{return{isValid:!0,value:o.sqrt(o.div(I,b))}}catch{return{isValid:!1,value:Bn}}}:r.uvRatio;if(!$l(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let h=o.eql(i.a,o.neg(o.ONE))?I=>o.neg(I):o.eql(i.a,o.ONE)?I=>I:I=>o.mul(i.a,I);function p(I,b,S=!1){let A=S?Dn:Bn;return Xt("coordinate "+I,b,A,u),b}function x(I){if(!(I instanceof m))throw new Error("EdwardsPoint expected")}class m{static BASE=new m(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new m(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(b,S,A,R){this.X=p("x",b),this.Y=p("y",S),this.Z=p("z",A,!0),this.T=p("t",R),Object.freeze(this)}static CURVE(){return i}static fromAffine(b){if(b instanceof m)throw new Error("extended point not allowed");let{x:S,y:A}=b||{};return p("x",S),p("y",A),new m(S,A,o.ONE,o.mul(S,A))}static fromBytes(b,S=!1){let A=o.BYTES,{a:R,d:K}=i;b=Lr(G(b,A,"point")),De(S,"zip215");let P=Lr(b),O=b[A-1];P[A-1]=O&-129;let N=Lt(P),F=S?u:o.ORDER;Xt("point.y",N,Bn,F);let H=o.sqr(N),J=o.sub(H,o.ONE),_=o.sub(o.mulN(K,H),R),{isValid:M,value:q}=l(J,_);if(!M)throw new Error("bad point: invalid y coordinate");let L=f(q),re=(O&128)!==0;if(!S&&o.is0(q)&&re)throw new Error("bad point: x=0 and x_0=1");return re!==L&&(q=o.neg(q)),m.fromAffine({x:q,y:N})}static fromHex(b,S=!1){return m.fromBytes(Gt(b),S)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=6,S=!0){return w.setWindowSize(this,b),S||this.multiply(On),this}assertValidity(){let b=this,{a:S,d:A}=i;if(b.is0())throw new Error("bad point: ZERO");let{X:R,Y:K,Z:P,T:O}=b,N=o.sqr(R),F=o.sqr(K),H=o.sqr(P),J=o.sqr(H),_=o.mul(N,S),M=o.mul(o.add(_,F),H),q=o.add(J,o.mul(A,o.mul(N,F)));if(!o.eql(M,q))throw new Error("bad point: equation left != right (1)");let L=o.mul(R,K),re=o.mul(P,O);if(!o.eql(L,re))throw new Error("bad point: equation left != right (2)")}equals(b){x(b);let{X:S,Y:A,Z:R}=this,{X:K,Y:P,Z:O}=b,N=o.mul(S,O),F=o.mul(K,R),H=o.mul(A,O),J=o.mul(P,R);return o.eql(N,F)&&o.eql(H,J)}is0(){return this.equals(m.ZERO)}negate(){return new m(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:b,Y:S,Z:A}=this,R=o.sqr(b),K=o.sqr(S),P=o.mul(o.sqr(A),On),O=h(R),N=o.addN(b,S),F=o.sub(o.subN(o.sqr(N),R),K),H=o.addN(O,K),J=o.subN(H,P),_=o.subN(O,K),M=o.mul(F,J),q=o.mul(H,_),L=o.mul(F,_),re=o.mul(J,H);return new m(M,q,re,L)}add(b){x(b);let{d:S}=i,{X:A,Y:R,Z:K,T:P}=this,{X:O,Y:N,Z:F,T:H}=b,J=o.mul(A,O),_=o.mul(R,N),M=o.mul(o.mulN(P,S),H),q=o.mul(K,F),L=o.sub(o.subN(o.mulN(o.addN(A,R),o.addN(O,N)),J),_),re=o.subN(q,M),ie=o.addN(q,M),v=o.sub(_,h(J)),d=o.mul(L,re),y=o.mul(ie,v),E=o.mul(L,v),T=o.mul(re,ie);return new m(d,y,T,E)}subtract(b){return x(b),this.add(b.negate())}multiply(b){if(!s.isValidNot0(b))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:S,f:A}=w.mulSecret(this,b,a,g);return g([S,A])[0]}multiplyUnsafe(b){if(!s.isValid(b))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return b===Bn?m.ZERO:this.is0()||b===Dn?this:w.mulUnsafe(this,b,g)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return w.mulUnsafe(this,i.n).is0()}toAffine(b){let S=this,A=b;if(A!=null&&typeof A!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof A);let{X:R,Y:K,Z:P}=S,O=S.is0();A==null&&(A=O?o.create(oc):o.inv(P));let N=o.mul(R,A),F=o.mul(K,A),H=o.mul(P,A);if(O)return{x:o.ZERO,y:o.ONE};if(!o.eql(H,o.ONE))throw new Error("invZ was invalid");return{x:N,y:F}}clearCofactor(){return a===Dn?this:a===On?this.double():a===zl?this.double().double():a===oc?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:b,y:S}=this.toAffine(),A=o.toBytes(S);return A[A.length-1]|=f(b)?128:0,A}toHex(){return Or(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let g=I=>In(m,I),w=new tr(m,c);return w.bits>=6&&m.BASE.precompute(6),Object.freeze(m.prototype),Object.freeze(m),m}function ic(t,e,r={}){if(wt(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Oe(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=t,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?Pt:o.randomBytes,h=o.toMontgomery,p=o.toMontgomerySecret,x=o.adjustScalarBytes===void 0?_=>_:o.adjustScalarBytes,m=o.domain===void 0?(_,M,q)=>{if(De(q,"phflag"),M.length||q)throw new Error("Contexts/pre-hash are not supported");return _}:o.domain;function g(_){return c.create(Lt(_))}function w(_){let M=O.secretKey;G(_,O.secretKey,"secretKey");let q=G(n(_),2*M,"hashedSecretKey"),L=x(q.slice(0,M)),re=q.slice(M,2*M),ie=g(L);return{head:L,prefix:re,scalar:ie}}function I(_){let{head:M,prefix:q,scalar:L}=w(_),re=i.multiply(L),ie=re.toBytes();return{head:M,prefix:q,scalar:L,point:re,pointBytes:ie}}function b(_){return I(_).pointBytes}function S(_=Uint8Array.of(),...M){let q=ke(...M);return g(n(m(q,G(_,void 0,"context"),!!s)))}function A(_,M,q={}){Oe(q,{},{},"options"),_=Lr(G(_,void 0,"message")),s&&(_=s(_));let{prefix:L,scalar:re,pointBytes:ie}=I(M),v=S(q.context,L,_),d=i.multiply(v).toBytes(),y=S(q.context,d,ie,_),E=c.create(v+y*re);if(!c.isValid(E))throw new Error("sign failed: invalid s");let T=ke(d,c.toBytes(E));return G(T,O.signature,"result")}let R={zip215:o.zip215};function K(_,M,q,L=R){Oe(L);let{context:re}=L,ie=L.zip215===void 0?!!R.zip215:L.zip215,v=O.signature;_=G(_,v,"signature"),M=G(M,void 0,"message"),q=G(q,O.publicKey,"publicKey"),ie!==void 0&&De(ie,"zip215"),s&&(M=s(M));let d=v/2,y=_.subarray(0,d),E=Lt(_.subarray(d,v)),T,C,B;try{T=t.fromBytes(q,ie),C=t.fromBytes(y,ie),B=i.multiplyUnsafe(E)}catch{return!1}if(!ie&&T.isSmallOrder())return!1;let U=S(re,y,q,M);return C.add(T.multiplyUnsafe(U)).subtract(B).clearCofactor().is0()}let P=a.BYTES,O={secretKey:P,publicKey:P,signature:2*P,seed:P};function N(_){return _=_===void 0?l(O.seed):_,G(_,O.seed,"seed")}function F(_){return gt(_)&&_.length===O.secretKey}function H(_,M){try{return!!t.fromBytes(_,M===void 0?R.zip215:M)}catch{return!1}}let J={getExtendedPublicKey:I,randomSecretKey:N,isValidSecretKey:F,isValidPublicKey:H,toMontgomery(_){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(t.fromBytes(_))},toMontgomerySecret(_){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(_)}};return Object.freeze(O),Object.freeze(J),Object.freeze({keygen:Cn(N,b),getPublicKey:b,sign:A,verify:K,utils:J,Point:t,lengths:O})}var bs=BigInt(1),ac=BigInt(2);var Yl=BigInt(5),jl=BigInt(8),gs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Wl={p:gs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:jl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Zl(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=gs,a=t*t%s*t%s,c=se(a,ac,s)*a%s,u=se(c,bs,s)*t%s,f=se(u,Yl,s)*u%s,l=se(f,e,s)*f%s,h=se(l,r,s)*l%s,p=se(h,n,s)*h%s,x=se(p,o,s)*p%s,m=se(x,o,s)*p%s,g=se(m,e,s)*f%s;return{pow_p_5_8:se(g,ac,s)*t%s,b2:a}}function fc(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var cc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Gl(t,e){let r=gs,n=ce(e*e*e,r),o=ce(n*n*e,r),s=Zl(t*o).pow_p_5_8,i=ce(t*n*s,r),a=ce(e*i*i,r),c=i,u=ce(i*cc,r),f=a===t,l=a===ce(-t,r),h=a===ce(-t*cc,r);return f&&(i=c),(l||h)&&(i=u),Xa(i,r)&&(i=ce(-i,r)),{isValid:f||l,value:i}}var xs=sc(Wl,{uvRatio:Gl}),uc=xs.Fp;function Xl(t){let{y:e}=t;return uc.toBytes(uc.div(bs+e,bs-e))}function Ql(t){let e=xs.Fp.BYTES;return Ue(t,e),fc(is(t.subarray(0,e))).subarray(0,e)}function Jl(t){return ic(xs,is,Object.assign({adjustScalarBytes:fc,toMontgomery:Xl,toMontgomerySecret:Ql,zip215:!0},t))}var lc=Jl({});var kr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Pn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Me={get(t=globalThis){let e=t.crypto;if(e?.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 e}};var Ln=32;var ws,ed=(async()=>{try{return await Me.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function td(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Me.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Me.get().subtle.verify({name:"Ed25519"},n,_e(e),_e(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function rd(t,e,r){return lc.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function dc(t,e,r){return ws==null&&(ws=await ed),ws?td(t,e,r):rd(t,e,r)}function Rn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Nn=class{type="Ed25519";raw;constructor(e){this.raw=Es(e,Ln)}toMultihash(){return Fe.digest(Ge(this))}toCID(){return ge.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=dc(this.raw,r,e);return Rn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Ss(t){return t=Es(t,Ln),new Nn(t)}function Es(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new ae(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var od=Math.pow(2,7),sd=Math.pow(2,14),id=Math.pow(2,21),vs=Math.pow(2,28),As=Math.pow(2,35),Is=Math.pow(2,42),Ts=Math.pow(2,49),Q=128,ve=127;function Pe(t){if(t<od)return 1;if(t<sd)return 2;if(t<id)return 3;if(t<vs)return 4;if(t<As)return 5;if(t<Is)return 6;if(t<Ts)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function rr(t,e,r=0){switch(Pe(t)){case 8:e[r++]=t&255|Q,t/=128;case 7:e[r++]=t&255|Q,t/=128;case 6:e[r++]=t&255|Q,t/=128;case 5:e[r++]=t&255|Q,t/=128;case 4:e[r++]=t&255|Q,t>>>=7;case 3:e[r++]=t&255|Q,t>>>=7;case 2:e[r++]=t&255|Q,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function ad(t,e,r=0){switch(Pe(t)){case 8:e.set(r++,t&255|Q),t/=128;case 7:e.set(r++,t&255|Q),t/=128;case 6:e.set(r++,t&255|Q),t/=128;case 5:e.set(r++,t&255|Q),t/=128;case 4:e.set(r++,t&255|Q),t>>>=7;case 3:e.set(r++,t&255|Q),t>>>=7;case 2:e.set(r++,t&255|Q),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function _s(t,e){let r=t[e],n=0;if(n+=r&ve,r<Q||(r=t[e+1],n+=(r&ve)<<7,r<Q)||(r=t[e+2],n+=(r&ve)<<14,r<Q)||(r=t[e+3],n+=(r&ve)<<21,r<Q)||(r=t[e+4],n+=(r&ve)*vs,r<Q)||(r=t[e+5],n+=(r&ve)*As,r<Q)||(r=t[e+6],n+=(r&ve)*Is,r<Q)||(r=t[e+7],n+=(r&ve)*Ts,r<Q))return n;throw new RangeError("Could not decode varint")}function cd(t,e){let r=t.get(e),n=0;if(n+=r&ve,r<Q||(r=t.get(e+1),n+=(r&ve)<<7,r<Q)||(r=t.get(e+2),n+=(r&ve)<<14,r<Q)||(r=t.get(e+3),n+=(r&ve)<<21,r<Q)||(r=t.get(e+4),n+=(r&ve)*vs,r<Q)||(r=t.get(e+5),n+=(r&ve)*As,r<Q)||(r=t.get(e+6),n+=(r&ve)*Is,r<Q)||(r=t.get(e+7),n+=(r&ve)*Ts,r<Q))return n;throw new RangeError("Could not decode varint")}function nr(t,e,r=0){return e==null&&(e=Se(Pe(t))),e instanceof Uint8Array?rr(t,e,r):ad(t,e,r)}function Mr(t,e=0){return t instanceof Uint8Array?_s(t,e):cd(t,e)}var Bs=new Float32Array([-0]),Et=new Uint8Array(Bs.buffer);function pc(t,e,r){Bs[0]=t,e[r]=Et[0],e[r+1]=Et[1],e[r+2]=Et[2],e[r+3]=Et[3]}function mc(t,e){return Et[0]=t[e],Et[1]=t[e+1],Et[2]=t[e+2],Et[3]=t[e+3],Bs[0]}var Ds=new Float64Array([-0]),Ae=new Uint8Array(Ds.buffer);function yc(t,e,r){Ds[0]=t,e[r]=Ae[0],e[r+1]=Ae[1],e[r+2]=Ae[2],e[r+3]=Ae[3],e[r+4]=Ae[4],e[r+5]=Ae[5],e[r+6]=Ae[6],e[r+7]=Ae[7]}function bc(t,e){return Ae[0]=t[e],Ae[1]=t[e+1],Ae[2]=t[e+2],Ae[3]=t[e+3],Ae[4]=t[e+4],Ae[5]=t[e+5],Ae[6]=t[e+6],Ae[7]=t[e+7],Ds[0]}var ud=BigInt(Number.MAX_SAFE_INTEGER),fd=BigInt(Number.MIN_SAFE_INTEGER),Le=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&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(e=!1){if(e)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(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Rt;if(e<ud&&e>fd)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>gc&&(o=0n,++n>gc&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Rt;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Rt}},Rt=new Le(0,0);Rt.toBigInt=function(){return 0n};Rt.zzEncode=Rt.zzDecode=function(){return this};Rt.length=function(){return 1};var gc=4294967296n;function xc(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function wc(t,e,r){if(r-e<1)return"";let o,s=[],i=0,a;for(;e<r;)a=t[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&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 Os(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Ve(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Un(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Ps=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=_e(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ve(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ve(this,4);return Un(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ve(this,4);return Un(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ve(this,4);let e=mc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ve(this,4);let e=bc(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ve(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return wc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ve(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ve(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Le(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ve(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ve(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ve(this,8);let e=Un(this.buf,this.pos+=4),r=Un(this.buf,this.pos+=4);return new Le(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=_s(this.buf,this.pos);return this.pos+=Pe(e),e}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 Kr(t){return new Ps(t instanceof Uint8Array?t:t.subarray())}function He(t,e,r){let n=Kr(t);return e.decode(n,void 0,r)}function Ls(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return Se(i);o+i>e&&(n=Se(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Nt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Rs(){}var Us=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},ld=Ls();function dd(t){return globalThis.Buffer!=null?Se(t):ld(t)}var qr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Nt(Rs,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Nt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ks((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(kn,10,Le.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Le.fromBigInt(e);return this._push(kn,r.length(),r)}uint64Number(e){return this._push(rr,Pe(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Le.fromBigInt(e).zzEncode();return this._push(kn,r.length(),r)}sint64Number(e){let r=Le.fromNumber(e).zzEncode();return this._push(kn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ns,1,e?1:0)}fixed32(e){return this._push(Fr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Le.fromBigInt(e);return this._push(Fr,4,r.lo)._push(Fr,4,r.hi)}fixed64Number(e){let r=Le.fromNumber(e);return this._push(Fr,4,r.lo)._push(Fr,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(pc,4,e)}double(e){return this._push(yc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Ns,1,0):this.uint32(r)._push(pd,r,e)}string(e){let r=xc(e);return r!==0?this.uint32(r)._push(Os,r,e):this._push(Ns,1,0)}fork(){return this.states=new Us(this),this.head=this.tail=new Nt(Rs,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 Nt(Rs,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=dd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Ns(t,e,r){e[r]=t&255}function hd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var ks=class extends Nt{next;constructor(e,r){super(hd,e,r),this.next=void 0}};function kn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Fr(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function pd(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(qr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(md,e,t),this},qr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(yd,e,t),this});function md(t,e,r){e.set(t,r)}function yd(t,e,r){t.length<40?Os(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(V(t),r)}function Ms(){return new qr}function ze(t,e){let r=Ms();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*$e(t,e,r){let n=Kr(t);yield*e.stream(n,void 0,".",r)}var Mn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Kn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Ks(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i,a){};return Kn("enum",Mn.VARINT,r,n,o)}function Ye(t,e,r){return Kn("message",Mn.LENGTH_DELIMITED,t,e,r)}var Je=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ue;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(ue||(ue={}));var Fs;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Fs||(Fs={}));(function(t){t.codec=()=>Ks(Fs)})(ue||(ue={}));var et;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ue.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=ue.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:ue.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ze(s,t.codec())}t.encode=r;function n(s,i){return He(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(et||(et={}));var qs;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ue.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=ue.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:ue.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ze(s,t.codec())}t.encode=r;function n(s,i){return He(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(qs||(qs={}));var Hr={};Ce(Hr,{MAX_RSA_KEY_SIZE:()=>Vs,generateRSAKeyPair:()=>Tc,jwkToJWKKeyPair:()=>_c,jwkToPkcs1:()=>wd,jwkToPkix:()=>Ys,jwkToRSAPrivateKey:()=>Gs,pkcs1MessageToJwk:()=>zs,pkcs1MessageToRSAPrivateKey:()=>js,pkcs1ToJwk:()=>xd,pkcs1ToRSAPrivateKey:()=>Ic,pkixMessageToJwk:()=>$s,pkixMessageToRSAPublicKey:()=>Zs,pkixToJwk:()=>Ed,pkixToRSAPublicKey:()=>Ws});var or=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Hr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ge.createV1(114,this._multihash)}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}verify(e,r,n){return Ac(this.jwk,r,e,n)}},Vr=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Hr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}sign(e,r){return vc(this.jwk,e,r)}};var Vs=8192,Hs=18,bd=1062,gd=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function xd(t){let e=rt(t);return zs(e)}function zs(t){return{n:Y(t[1],"base64url"),e:Y(t[2],"base64url"),d:Y(t[3],"base64url"),p:Y(t[4],"base64url"),q:Y(t[5],"base64url"),dp:Y(t[6],"base64url"),dq:Y(t[7],"base64url"),qi:Y(t[8],"base64url"),kty:"RSA"}}function wd(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new ae("JWK was missing components");return dt([Be(Uint8Array.from([0])),Be(V(t.n,"base64url")),Be(V(t.e,"base64url")),Be(V(t.d,"base64url")),Be(V(t.p,"base64url")),Be(V(t.q,"base64url")),Be(V(t.dp,"base64url")),Be(V(t.dq,"base64url")),Be(V(t.qi,"base64url"))]).subarray()}function Ed(t){let e=rt(t,{offset:0});return $s(e)}function $s(t){let e=rt(t[1],{offset:0});return{kty:"RSA",n:Y(e[0],"base64url"),e:Y(e[1],"base64url")}}function Ys(t){if(t.n==null||t.e==null)throw new ae("JWK was missing components");return dt([gd,un(dt([Be(V(t.n,"base64url")),Be(V(t.e,"base64url"))]))]).subarray()}function Ic(t){let e=rt(t);return js(e)}function js(t){let e=zs(t);return Gs(e)}function Ws(t,e){if(t.byteLength>=bd)throw new At("Key size is too large");let r=rt(t,{offset:0});return Zs(r,t,e)}function Zs(t,e,r){let n=$s(t);if(r==null){let o=Zt(et.encode({Type:ue.RSA,Data:e}));r=We(Hs,o)}return new or(n,r)}function Gs(t){if(Bc(t)>Vs)throw new ae("Key size is too large");let e=_c(t),r=Zt(et.encode({Type:ue.RSA,Data:Ys(e.publicKey)})),n=We(Hs,r);return new Vr(e.privateKey,new or(e.publicKey,n))}async function Tc(t){if(t>Vs)throw new ae("Key size is too large");let e=await Cc(t),r=Zt(et.encode({Type:ue.RSA,Data:Ys(e.publicKey)})),n=We(Hs,r);return new Vr(e.privateKey,new or(e.publicKey,n))}function _c(t){if(t==null)throw new ae("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Cc(t,e){let r=await Me.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await Sd(r,e);return{privateKey:n[0],publicKey:n[1]}}async function vc(t,e,r){let n=await Me.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Me.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,_e(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ac(t,e,r,n){let o=await Me.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Me.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,_e(e),_e(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function Sd(t,e){if(t.privateKey==null||t.publicKey==null)throw new ae("Private and public key are required");let r=await Promise.all([Me.get().subtle.exportKey("jwk",t.privateKey),Me.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Bc(t){if(t.kty!=="RSA")throw new ae("invalid key type");if(t.n==null)throw new ae("invalid key modulus");return V(t.n,"base64url").length*8}var Fn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(dn(e),Ue(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Dt(o)}update(e){return Wt(this),this.iHash.update(e),this}digestInto(e){Wt(this),hn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Dc=(()=>{let t=((e,r,n)=>new Fn(e,r).update(n).digest());return t.create=(e,r)=>new Fn(e,r),t})();var vd=BigInt(0),Xs=class extends Error{constructor(e=""){super(e)}},st={Err:Xs,_tlv:{encode:(t,e)=>{let{Err:r}=st;if(ot(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Ma(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Pr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Pr(o.length/2|128):"";return Pr(t)+s+o+e},decode(t,e){let{Err:r}=st;e=G(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[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=e.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=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=st;if(xn(t),t<vd)throw new e("integer: negative integers are not allowed");let r=Pr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=st;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Qe(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:o}=st;if(e!==void 0&&(ot(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let s=G(t,void 0,"signature"),{v:i,l:a}=o.decode(48,s);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=o.decode(2,i),{v:f,l}=o.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||f.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=st;Oe(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}},qn=(Object.freeze(st._tlv),Object.freeze(st._int),Object.freeze(st));var Oc=(t,e)=>(t+(t>=0?e:-e)/Pc)/e;function Ad(t,e,r){Xt("scalar",t,it,r);let[[n,o],[s,i]]=e,a=Oc(i*t,r),c=Oc(-o*t,r),u=t-a*n-c*s,f=-a*o-c*i,l=u<it,h=f<it;l&&(u=-u),h&&(f=-f);let p=Rr(Math.ceil(Qt(r)/2))+Ut;if(u<it||u>=p||f<it||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:h,k2:f}}function ei(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Qs(t,e){Oe(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return De(r.lowS,"lowS"),De(r.prehash,"prehash"),r.format!==void 0&&ei(r.format),r}var it=BigInt(0),Ut=BigInt(1),Pc=BigInt(2),Js=BigInt(3),Id=BigInt(4);function Lc(t,e={}){let r=_n("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Oe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:h,toBytes:p}=e,x=e.randomBytes===void 0?Pt:e.randomBytes;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 m=c?{beta:c.beta,basises:c.basises.map(v=>[...v])}:void 0,g=Nc(n,o);function w(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function I(v,d,y){if(d.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:E,y:T}=d.toAffine(),C=n.toBytes(E);if(De(y,"isCompressed"),y){w();let B=!n.isOdd(T);return ke(Rc(B),C)}else return ke(Uint8Array.of(4),C,n.toBytes(T))}function b(v){G(v,void 0,"Point");let{publicKey:d,publicKeyUncompressed:y}=g,E=v.length,T=v[0],C=v.subarray(1);if(u&&E===1&&T===0)return{x:n.ZERO,y:n.ZERO};if(E===d&&(T===2||T===3)){let B=n.fromBytes(C);if(!n.isValid(B))throw new Error("bad point: is not on curve, wrong x");let U=P(B),k;try{k=n.sqrt(U)}catch(le){let ne=le instanceof Error?": "+le.message:"";throw new Error("bad point: is not on curve, sqrt error"+ne)}w();let Z=n.isOdd(k);return(T&1)===1!==Z&&(k=n.neg(k)),{x:B,y:k}}else if(E===y&&T===4){let B=n.BYTES,U=n.fromBytes(C.subarray(0,B)),k=n.fromBytes(C.subarray(B,B*2));if(!O(U,k))throw new Error("bad point: is not on curve");return{x:U,y:k}}else throw new Error(`bad point: got length ${E}, expected compressed=${d} or uncompressed=${y}`)}let S=p===void 0?I:p,A=h===void 0?b:h,R=n.mul(s.b,Js),K=n.is0(s.a)?v=>n.ZERO:v=>n.mul(s.a,v);function P(v){let d=n.sqr(v),y=n.mul(d,v);return n.add(n.add(y,n.mul(v,s.a)),s.b)}function O(v,d){let y=n.sqr(d),E=P(v);return n.eql(y,E)}if(!O(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let N=n.mul(n.pow(s.a,Js),Id),F=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(N,F)))throw new Error("bad curve params: a or b");function H(v,d,y=!1){if(!n.isValid(d)||y&&n.is0(d))throw new Error(`bad point coordinate ${v}`);return typeof d=="object"&&d!==null?n.create(d):d}function J(v){if(!(v instanceof L))throw new Error("Weierstrass Point expected")}function _(v){if(!m||!m.basises)throw new Error("no endo");return Ad(v,m.basises,o.ORDER)}function M(v,d,y,E){if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(m){let{k1neg:T,k1:C,k2neg:B,k2:U}=_(E),k=new L(n.mul(y.X,m.beta),y.Y,y.Z);v.push(T?y.negate():y,B?k.negate():k),d.push(C,U)}else v.push(y),d.push(E)}let q=new WeakSet;class L{static BASE=new L(s.Gx,s.Gy,n.ONE);static ZERO=new L(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,y,E){this.X=H("x",d),this.Y=H("y",y,!0),this.Z=H("z",E),Object.freeze(this)}static CURVE(){return s}static fromAffine(d){let{x:y,y:E}=d||{};if(!d||!n.isValid(y)||!n.isValid(E))throw new Error("invalid affine point");if(d instanceof L)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(E)?L.ZERO:new L(y,E,n.ONE)}static fromBytes(d){let y=L.fromAffine(A(G(d,void 0,"point")));return y.assertValidity(),y}static fromHex(d){return L.fromBytes(Gt(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=6,y=!0){return ie.setWindowSize(this,d),y||this.multiply(Js),this}assertValidity(){let d=this;if(d.is0()){if(u&&n.is0(d.X)&&n.eql(d.Y,n.ONE)&&n.is0(d.Z))return;throw new Error("bad point: ZERO")}if(q.has(d))return;let{x:y,y:E}=d.toAffine();if(!n.isValid(y)||!n.isValid(E))throw new Error("bad point: x or y not field elements");if(!O(y,E))throw new Error("bad point: equation left != right");if(!d.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");q.add(d)}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){J(d);let{X:y,Y:E,Z:T}=this,{X:C,Y:B,Z:U}=d,k=n.eql(n.mul(y,U),n.mul(C,T)),Z=n.eql(n.mul(E,U),n.mul(B,T));return k&&Z}negate(){return new L(this.X,n.neg(this.Y),this.Z)}double(){let{X:d,Y:y,Z:E}=this,T=n.ZERO,C=n.ZERO,B=n.ZERO,U=n.mul(d,d),k=n.mul(y,y),Z=n.mul(E,E),$=n.mul(d,y);return $=n.add($,$),B=n.mul(d,E),B=n.add(B,B),T=K(B),C=n.mul(R,Z),C=n.add(T,C),T=n.sub(k,C),C=n.add(k,C),C=n.mul(T,C),T=n.mul($,T),B=n.mul(R,B),Z=K(Z),$=n.sub(U,Z),$=K($),$=n.add($,B),B=n.add(U,U),U=n.add(B,U),U=n.add(U,Z),U=n.mul(U,$),C=n.add(C,U),Z=n.mul(y,E),Z=n.add(Z,Z),U=n.mul(Z,$),T=n.sub(T,U),B=n.mul(Z,k),B=n.add(B,B),B=n.add(B,B),new L(T,C,B)}add(d){J(d);let{X:y,Y:E,Z:T}=this,{X:C,Y:B,Z:U}=d,k=n.ZERO,Z=n.ZERO,$=n.ZERO,le=n.mul(y,C),ne=n.mul(E,B),be=n.mul(T,U),Re=n.add(y,E),oe=n.add(C,B);Re=n.mul(Re,oe),oe=n.add(le,ne),Re=n.sub(Re,oe),oe=n.add(y,T);let de=n.add(C,U);return oe=n.mul(oe,de),de=n.add(le,be),oe=n.sub(oe,de),de=n.add(E,T),k=n.add(B,U),de=n.mul(de,k),k=n.add(ne,be),de=n.sub(de,k),$=K(oe),k=n.mul(R,be),$=n.add(k,$),k=n.sub(ne,$),$=n.add(ne,$),Z=n.mul(k,$),ne=n.add(le,le),ne=n.add(ne,le),be=K(be),oe=n.mul(R,oe),ne=n.add(ne,be),be=n.sub(le,be),be=K(be),oe=n.add(oe,be),le=n.mul(ne,oe),Z=n.add(Z,le),le=n.mul(de,oe),k=n.mul(Re,k),k=n.sub(k,le),le=n.mul(Re,ne),$=n.mul(de,$),$=n.add($,le),new L(k,Z,$)}subtract(d){return J(d),this.add(d.negate())}is0(){return this.equals(L.ZERO)}multiply(d){if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let{p:y,f:E}=ie.mulSecret(this,d,i,re);return re([y,E])[0]}multiplyUnsafe(d){let y=this,E=d;if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(E===it||y.is0())return L.ZERO;if(E===Ut)return y;if(ie.hasWindowSize(this))return ie.mulUnsafe(y,E,re);let T=[],C=[];return M(T,C,y,E),Tn(L,T,C)}mulAddUnsafe(d,y,E){J(y);let T=[],C=[];return M(T,C,this,d),M(T,C,y,E),Tn(L,T,C)}toAffine(d){let y=this,E=d;if(E!=null&&!n.isValid(E))throw new RangeError('"invertedZ" expected valid field element');let{X:T,Y:C,Z:B}=y;if(n.eql(B,n.ONE))return{x:T,y:C};let U=y.is0();E==null&&(E=U?n.ONE:n.inv(B));let k=n.mul(T,E),Z=n.mul(C,E),$=n.mul(B,E);if(U)return{x:n.ZERO,y:n.ZERO};if(!n.eql($,n.ONE))throw new Error("invZ was invalid");return{x:k,y:Z}}isTorsionFree(){return i===Ut?!0:l?l(L,this):ie.mulUnsafe(this,a).is0()}clearCofactor(){return i===Ut?this:f?f(L,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Ut?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return De(d,"isCompressed"),this.assertValidity(),S(L,this,d)}toHex(d=!0){return Or(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let re=v=>In(L,v),ie=new tr(L,x);return ie.bits>=6&&L.BASE.precompute(6),Object.freeze(L.prototype),Object.freeze(L),L}function Rc(t){return Uint8Array.of(t?2:3)}function Nc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Td(t,e={}){wt(t);let{Fn:r}=t,n=e.randomBytes===void 0?Pt:e.randomBytes,o=Object.assign(Nc(t.Fp,r),{seed:Math.max(vn(r.ORDER),16)});function s(p){try{let x=r.fromBytes(p);return r.isValidNot0(x)}catch{return!1}}function i(p,x){let{publicKey:m,publicKeyUncompressed:g}=o;try{let w=p.length;return x===!0&&w!==m||x===!1&&w!==g?!1:!t.fromBytes(p).is0()}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,An(G(p,o.seed,"seed"),r.ORDER)}function c(p,x=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(x)}function u(p){let{secretKey:x,publicKey:m,publicKeyUncompressed:g}=o,w=r._lengths;if(!gt(p))return;let I=G(p,void 0,"key").length,b=I===m||I===g,S=I===x||!!w?.includes(I);if(!(b&&S))return b}function f(p,x,m=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(x)===!1)throw new Error("second arg must be public key");let g=r.fromBytes(p),w=t.fromBytes(x);if(w.is0())throw new Error("invalid public key: point at infinity");return w.multiply(g).toBytes(m)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},h=Cn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:h,Point:t,utils:l,lengths:o})}function Uc(t,e,r={}){wt(t);let n=e;dn(n),Oe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?Pt:o.randomBytes,i=o.hmac===void 0?(v,d)=>Dc(n,v,d):o.hmac,{Fp:a,Fn:c}=t,{ORDER:u,BITS:f}=c,l=vn(u),h=ys(s,l),{keygen:p,getPublicKey:x,getSharedSecret:m,utils:g,lengths:w}=Td(t,o),I={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},b=u*Pc+Ut<a.ORDER;function S(v){let d=u>>Ut;return v>d}function A(v,d){if(!c.isValidNot0(d))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return d}function R(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function K(v,d,y){return R(),(v===y?0:2)|Number(a.isOdd(d))}function P(){if(b)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(v,d){ei(d);let y=w.signature,E=d==="compact"?y:d==="recovered"?y+1:void 0;return G(v,E)}class N{r;s;recovery;constructor(d,y,E){if(this.r=A("r",d),this.s=A("s",y),E!=null){if(P(),![0,1,2,3].includes(E))throw new Error("invalid recovery id");this.recovery=E}Object.freeze(this)}static fromBytes(d,y=I.format){O(d,y);let E;if(y==="der"){if(d.length>2*c.BYTES+16)throw new qn.Err("invalid signature: DER signature too long");let{r:U,s:k}=qn.toSig(G(d),c.BYTES+1);return new N(U,k)}y==="recovered"&&(E=d[0],y="compact",d=d.subarray(1));let T=w.signature/2,C=d.subarray(0,T),B=d.subarray(T,T*2);return new N(c.fromBytes(C),c.fromBytes(B),E)}static fromHex(d,y){return this.fromBytes(Gt(d),y)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new N(this.r,this.s,d)}recoverPublicKey(d){let{r:y,s:E}=this,T=this.assertRecovery(),C=T===2||T===3?y+u:y;if(!a.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let B=a.toBytes(C),U=t.fromBytes(ke(Rc((T&1)===0),B)),k=c.inv(C),Z=H(G(d,void 0,"msgHash")),$=c.create(-Z*k),le=c.create(E*k),ne=t.BASE.mulAddUnsafe($,U,le);if(ne.is0())throw new Error("invalid recovery: point at infinify");return ne.assertValidity(),ne}hasHighS(){return S(this.s)}toBytes(d=I.format){if(ei(d),d==="der")return Gt(qn.hexFromSig(this));let{r:y,s:E}=this,T=c.toBytes(y),C=c.toBytes(E);return d==="recovered"?(P(),ke(Uint8Array.of(this.assertRecovery()),T,C)):ke(T,C)}toHex(d){return Or(this.toBytes(d))}}Object.freeze(N.prototype),Object.freeze(N);let F=o.bits2int===void 0?function(d){if(d.length>8192)throw new Error("input is too large");let y=Qe(d),E=d.length*8-f;return E>0?y>>BigInt(E):y}:o.bits2int,H=o.bits2int_modN===void 0?function(d){return c.create(F(d))}:o.bits2int_modN,J=Rr(f);function _(v){return Xt("num < 2^"+f,v,it,J),c.toBytes(v)}function M(v,d){return G(v,void 0,"message"),d?G(n(v),void 0,"prehashed message"):v}function q(v,d,y){let{lowS:E,prehash:T,extraEntropy:C}=Qs(y,I);v=M(v,T);let B=H(v),U=c.fromBytes(d);if(!c.isValidNot0(U))throw new Error("invalid private key");let k=[_(U),_(B)];if(C!=null&&C!==!1){let ne=C===!0?s(w.secretKey):C;k.push(G(ne,void 0,"extraEntropy"))}let Z=ke(...k),$=B;function le(ne){let be=F(ne);if(!c.isValidNot0(be))return;let Re=t.BASE.multiply(be).toAffine(),oe=c.create(Re.x);if(oe===it)return;let de;if(h!==void 0){let gr=Qe(An(h(l),u)),Uu=c.inv(c.mul(gr,be)),ku=c.mul(gr,$),Mu=c.mul(gr,U);de=c.create(Uu*c.create(ku+Mu*oe))}else{let gr=Wa(be,u);de=c.create(gr*c.create($+oe*U))}if(de===it)return;let go=K(Re.x,Re.y,oe),zi=de;return E&&S(de)&&(zi=c.neg(de),go^=1),new N(oe,zi,b?void 0:go)}return{seed:Z,k2sig:le}}function L(v,d,y={}){let{seed:E,k2sig:T}=q(v,d,y);return Fa(n.outputLen,c.BYTES,i)(E,T).toBytes(y.format)}function re(v,d,y,E={}){let{lowS:T,prehash:C,format:B}=Qs(E,I);if(y=G(y,void 0,"publicKey"),d=M(d,C),!gt(v)){let U=v instanceof N?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}O(v,B);try{let U=N.fromBytes(v,B),k=t.fromBytes(y);if(k.is0()||T&&U.hasHighS())return!1;let{r:Z,s:$}=U,le=H(d),ne=c.inv($),be=c.create(le*ne),Re=c.create(Z*ne),oe=t.BASE.mulAddUnsafe(be,k,Re);if(oe.is0())return!1;let de=oe.toAffine();return!(c.create(de.x)!==Z||B==="recovered"&&U.recovery!==K(de.x,de.y,Z))}catch{return!1}}function ie(v,d,y={}){let{prehash:E}=Qs(y,I);return d=M(d,E),N.fromBytes(v,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:p,getPublicKey:x,getSharedSecret:m,utils:g,lengths:w,Point:t,sign:L,verify:re,recoverPublicKey:ie,Signature:N,hash:n})}var ri={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},_d={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var kc=BigInt(2);function Cd(t){let e=ri.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=se(f,r,e)*f%e,h=se(l,r,e)*f%e,p=se(h,kc,e)*u%e,x=se(p,o,e)*p%e,m=se(x,s,e)*x%e,g=se(m,a,e)*m%e,w=se(g,c,e)*g%e,I=se(w,a,e)*m%e,b=se(I,r,e)*f%e,S=se(b,i,e)*x%e,A=se(S,n,e)*u%e,R=se(A,kc,e);if(!ti.eql(ti.sqr(R),t))throw new Error("Cannot find square root");return R}var ti=er(ri.p,{sqrt:Cd}),Bd=Lc(ri,{Fp:ti,endo:_d}),sr=Uc(Bd,Zt);function Mc(t,e,r,n){let o=Ar.digest(r instanceof Uint8Array?r:r.subarray());if(Rn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),sr.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new kr(String(s))});try{return n?.signal?.throwIfAborted(),sr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new kr(String(s))}}var Vn=class{type="secp256k1";raw;_key;constructor(e){this._key=Fc(e),this.raw=Kc(this._key)}toMultihash(){return Fe.digest(Ge(this))}toCID(){return ge.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}verify(e,r,n){return Mc(this._key,r,e,n)}};function ni(t){return new Vn(t)}function Kc(t){return sr.Point.fromBytes(t).toBytes()}function Fc(t){try{return sr.Point.fromBytes(t),t}catch(e){throw new At(String(e))}}function ir(t,e){let{Type:r,Data:n}=et.decode(t),o=n??new Uint8Array;switch(r){case ue.RSA:return Ws(o,e);case ue.Ed25519:return Ss(o);case ue.secp256k1:return ni(o);case ue.ECDSA:return Zo(o);default:throw new It}}function qc(t){let{Type:e,Data:r}=et.decode(t.digest),n=r??new Uint8Array;switch(e){case ue.Ed25519:return Ss(n);case ue.secp256k1:return ni(n);case ue.ECDSA:return Zo(n);default:throw new It}}function Ge(t){return et.encode({Type:ue[t.type],Data:t.raw})}var zr;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((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:xe(0),payloadType:xe(0),payload:xe(0),signature:xe(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}}}})),e);function r(s){return ze(s,t.codec())}t.encode=r;function n(s,i){return He(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(zr||(zr={}));var Hn=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var tt=class t{static createFromProtobuf=e=>{let r=zr.decode(e),n=ir(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),a=Vc(o,s,i),c=await r.sign(a.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,r,n)=>{let o=t.createFromProtobuf(e);if(!await o.validate(r,n))throw new Hn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:r,payloadType:n,payload:o,signature:s}=e;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=zr.encode({publicKey:Ge(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:pe(this.marshal(),e.marshal())}async validate(e,r){let n=Vc(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Vc=(t,e,r)=>{let n=V(t),o=nr(n.byteLength),s=nr(e.length),i=nr(r.length);return new me(o,n,s,e,i,r)};var Hc=Symbol.for("nodejs.util.inspect.custom"),Dd=114,$r=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[wo]=!0;toString(){return this.string==null&&(this.string=he.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ge.createV1(Dd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return pe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return pe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Hc](){return`PeerId(${this.toString()})`}},Yr=class extends $r{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},jr=class extends $r{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Wr=class extends $r{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Od=2336,zn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Fe.digest(V(this.url))}[Hc](){return`PeerId(${this.url})`}[wo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ge.createV1(Od,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=Y(e)),e.toString()===this.toString())}};function Zr(t){if(t.type==="Ed25519")return new jr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Wr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Yr({multihash:t.toCID().multihash,publicKey:t});throw new It}function zc(t){if(Ld(t))return new Yr({multihash:t});if(Pd(t))try{let e=qc(t);if(e.type==="Ed25519")return new jr({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Wr({multihash:t,publicKey:e})}catch{let r=Y(t.digest);return new zn(new URL(r))}throw new nn("Supplied PeerID Multihash is invalid")}function Pd(t){return t.code===Fe.code}function Ld(t){return t.code===Ar.code}var Ee=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},at=class extends Error{static name="ValidationError";name="ValidationError"},$n=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Yn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var jn=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();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(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,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 h=Number.parseInt(l,e);if(!Number.isNaN(h))return h});if(f===void 0)break;if(s*=e,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 e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=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]=e(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]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var $c=45,Rd=15,ar=new jn;function Wn(t){if(!(t.length>Rd))return ar.new(t).parseWith(()=>ar.readIPv4Addr())}function Zn(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>$c))return ar.new(t).parseWith(()=>ar.readIPv6Addr())}function St(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>$c)return;let r=ar.new(t).parseWith(()=>ar.readIPAddr());if(r)return e&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function cr(t){return!!Wn(t)}function Gn(t){return!!Zn(t)}function si(t){return e=>Y(e,t)}function ii(t){return e=>V(e,t)}function ur(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function kt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Yc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=V(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=kt(n);return Ze([r,o],r.length+o.length)}function jc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=lt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=kt(n);return Ze([r,o],r.length+o.length)}function ai(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=Y(e,"base32"),o=ur(r);return`${n}:${o}`}var ci=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new Ee("Invalid byte value in IP address");e[n]=o}),e},Wc=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=cr(r[n]),i;s&&(i=ci(r[n]),r[n]=Y(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,Y(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(e+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 Ee("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Zc=function(t){if(t.byteLength!==4)throw new Ee("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Gc=function(t){if(t.byteLength!==16)throw new Ee("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new Ee(`Invalid IPv6 address "${r}"`)}};function Xc(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new Ee(`Invalid IPv6 address "${t}"`)}}var oi=Object.values(Ir).map(t=>t.decoder),Nd=(function(){let t=oi[0].or(oi[1]);return oi.slice(2).forEach(e=>t=t.or(e)),t})();function Qc(t){return Nd.decode(t)}function Jc(t){return e=>t.encoder.encode(e)}function Ud(t){if(parseInt(t).toString()!==t)throw new at("Value must be an integer")}function kd(t){if(t<0)throw new at("Value must be a positive integer, or zero")}function Md(t){return e=>{if(e>t)throw new at(`Value must be smaller than or equal to ${t}`)}}function Kd(...t){return e=>{for(let r of t)r(e)}}var Gr=Kd(Ud,kd,Md(65535));var we=-1,ui=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Yn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ut=new ui,Jd=[{code:4,name:"ip4",size:32,valueToBytes:ci,bytesToValue:Zc,validate:t=>{if(!cr(t))throw new at(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:kt,bytesToValue:ur,validate:Gr},{code:273,name:"udp",size:16,valueToBytes:kt,bytesToValue:ur,validate:Gr},{code:33,name:"dccp",size:16,valueToBytes:kt,bytesToValue:ur,validate:Gr},{code:41,name:"ip6",size:128,valueToBytes:Wc,bytesToValue:Gc,stringToValue:Xc,validate:t=>{if(!Gn(t))throw new at(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:we},{code:43,name:"ipcidr",size:8,bytesToValue:si("base10"),valueToBytes:ii("base10")},{code:53,name:"dns",size:we},{code:54,name:"dns4",size:we},{code:55,name:"dns6",size:we},{code:56,name:"dnsaddr",size:we},{code:132,name:"sctp",size:16,valueToBytes:kt,bytesToValue:ur,validate:Gr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:we,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:we,bytesToValue:si("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?ii("base58btc")(t):ge.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ai,valueToBytes:Yc},{code:445,name:"onion3",size:296,bytesToValue:ai,valueToBytes:jc},{code:446,name:"garlic64",size:we},{code:447,name:"garlic32",size:we},{code:448,name:"tls"},{code:449,name:"sni",size:we},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:we,bytesToValue:Jc(Uo),valueToBytes:Qc},{code:480,name:"http"},{code:481,name:"http-path",size:we,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.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:we}];Jd.forEach(t=>{ut.addProtocol(t)});function eu(t){let e=[],r=0;for(;r<t.length;){let n=Mr(t,r),o=ut.getProtocol(n),s=Pe(n),i=eh(o,t,r+s),a=0;i>0&&o.size===we&&(a=Pe(i));let c=s+a+i,u={code:n,name:o.name,bytes:_e(t.subarray(r,r+c))};if(i>0){let f=r+s+a,l=t.subarray(f,f+i);u.value=o.bytesToValue?.(l)??Y(l)}e.push(u),r+=c}return e}function tu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=ut.getProtocol(n.code),s=Pe(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===we&&(c=Pe(a)));let u=new Uint8Array(s+c+a),f=0;rr(n.code,u,f),f+=s,i!=null&&(o.size===we&&(rr(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Ze(r,e)}function ru(t){if(t.charAt(0)!=="/")throw new Ee('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=ut.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new Ee(`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 Ee(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new Ee("Incomplete multiaddr");return e}function nu(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ut.getProtocol(e.code);if(r==null)throw new Ee(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function eh(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:Mr(e,r)}var th=Symbol.for("nodejs.util.inspect.custom"),Ai=Symbol.for("@multiformats/multiaddr");function rh(t){if(t==null&&(t="/"),ou(t))return t.getComponents();if(t instanceof Uint8Array)return eu(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),ru(t);if(Array.isArray(t))return t;throw new Ee("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ro=class t{[Ai]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=rh(e),r.validate!==!1&&nh(this)}get bytes(){return this.#r==null&&(this.#r=tu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=nu(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new $n(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return pe(this.bytes,e.bytes)}[th](){return`Multiaddr(${this.toString()})`}};function nh(t){t.getComponents().forEach(e=>{let r=ut.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function ou(t){return!!t?.[Ai]}function Qr(t){return new ro(t)}var su="libp2p-peer-record",iu=Uint8Array.from([3,1]);var Jr;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=Ye((l,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(h.uint32(10),h.bytes(l.multiaddr)),p.lengthDelimited!==!1&&h.ldelim()},(l,h,p={})=>{let x={multiaddr:xe(0)},m=h==null?l.len:l.pos+h;for(;l.pos<m;){let g=l.uint32();g>>>3===1?x.multiaddr=l.bytes():l.skipType(g&7)}return x},function*(l,h,p,x={}){let m=h==null?l.len:l.pos+h;for(;l.pos<m;){let g=l.uint32();g>>>3===1?yield{field:`${p}.multiaddr`,value:l.bytes()}:l.skipType(g&7)}})),a);function c(l){return ze(l,i.codec())}i.encode=c;function u(l,h){return He(l,i.codec(),h)}i.decode=u;function f(l,h){return $e(l,i.codec(),h)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=Ye((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),t.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:xe(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 Je('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.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 h=i.uint32();switch(h>>>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 Je('Streaming decode error - repeated field "addresses" had too many elements');for(let p of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...p,index:f.addresses};f.addresses++;break}default:{i.skipType(h&7);break}}}})),r);function n(i){return ze(i,t.codec())}t.encode=n;function o(i,a){return He(i,t.codec(),a)}t.decode=o;function s(i,a){return $e(i,t.codec(),a)}t.stream=s})(Jr||(Jr={}));function au(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var je=class t{static createFromProtobuf=e=>{let r=Jr.decode(e),n=zc(Sr(r.peerId)),o=(r.addresses??[]).map(i=>Qr(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=su;static CODEC=iu;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:o}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Jr.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!au(this.multiaddrs,e.multiaddrs))}};function oh(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function no(t){let e=oh(t);if(e==null)throw new ae(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function cu(t,e,r){let n=0;for(let o of t)if(!(n<e)){if(n>r)break;if(o!==255)return!1;n++}return!0}function Ii(t,e,r,n){let o=0;for(let s of t)if(!(o<r)){if(o>n)break;if(s!==e[o])return!1;o++}return!0}function Ti(t){switch(t.length){case Kt:return t.join(".");case Ft:{let e=[];for(let r=0;r<t.length;r++)r%2===0&&e.push(t[r].toString(16).padStart(2,"0")+t[r+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function uu(t){let e=0;for(let[r,n]of t.entries()){if(n===255){e+=8;continue}for(;(n&128)!=0;)e++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<t.length;o++)if(t[o]!=0)return-1;break}return e}function fu(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Kt=4,Ft=16,$x=parseInt("0xFFFF",16),lu=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function en(t,e){e.length===Ft&&t.length===Kt&&cu(e,0,11)&&(e=e.slice(12)),e.length===Kt&&t.length===Ft&&Ii(t,lu,0,11)&&(t=t.slice(12));let r=t.length;if(r!=e.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=t[o]&e[o];return n}function du(t,e){if(typeof e=="string"&&(e=St(e)),e==null)throw new Error("Invalid ip");if(e.length!==t.network.length)return!1;for(let r=0;r<e.length;r++)if((t.network[r]&t.mask[r])!==(e[r]&t.mask[r]))return!1;return!0}function _i(t){if(!oo(t))throw new Error("Must have 0xffff prefix");return t.slice(12)}function oo(t){return Ii(t,lu,0,11)}function Ci(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Kt,o=Wn(e);if(o==null&&(n=Ft,o=Zn(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+t);let i=Bi(s,8*n);return{network:en(o,i),mask:i}}function Bi(t,e){if(e!==8*Kt&&e!==8*Ft)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var qt=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Ci(e));else{let n=St(e);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=St(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Bi(o,8*n.length);this.network=en(n,this.mask)}}contains(e){return du({network:this.network,mask:this.mask},e)}toString(){let e=uu(this.mask),r=e!==-1?String(e):fu(this.mask);return Ti(this.network)+"/"+r}};function hu(t,e){return new qt(t).contains(e)}function pu(t){try{let e=no(t);return e.type==="ip6"?hu("2000::/3",e.host):!1}catch{return!1}}var sh=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32","::/128","::1/128","64:ff9b::/96","100::/64","2001::/32","2001:20::/28","2001:db8::/32","2002::/16","fc00::/7","fe80::/10","ff00::/8"].map(t=>new qt(t));function mu(t){if(!cr(t)&&!Gn(t))return;let e=St(t);if(e==null)return;let r=e.length===16&&oo(e)?_i(e):e;return sh.some(n=>n.contains(r))}function yu(t){try{let e=no(t);switch(e.type){case"ip4":case"ip6":return mu(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var ee=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),D=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),bu=t=>({match:e=>t.match(e)===!1?e:!1}),z=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),Ie=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),W=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function te(...t){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of t){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:t,matches:r,exactMatch:n}}var ih=D(421),ww=te(ih),io=D(54),ao=D(55),co=D(56),Oi=D(53),Ew=te(io,z(D(421))),Sw=te(ao,z(D(421))),vw=te(co,z(D(421))),Aw=te(Ie(Oi,co,io,ao),z(D(421))),gu=W(D(4),z(D(43))),xu=W(z(D(42)),D(41),z(D(43))),Pi=Ie(gu,xu),pr=Ie(Pi,Oi,io,ao,co),wu=te(Ie(Pi,W(Ie(Oi,co,io,ao),z(D(421))))),Iw=te(gu),Tw=te(xu),_w=te(Pi),Li=W(pr,D(6)),tn=W(pr,D(273)),Eu=te(W(Li,z(D(421)))),Cw=te(tn),Ri=W(tn,ee(460),z(D(421))),uo=W(tn,ee(461),z(D(421))),ah=Ie(Ri,uo),Bw=te(Ri),Dw=te(uo),Di=Ie(pr,Li,tn,Ri,uo),Su=Ie(W(Di,ee(477),z(D(421)))),Ow=te(Su),vu=Ie(W(Di,ee(478),z(D(421))),W(Di,ee(448),z(D(449)),ee(477),z(D(421)))),Pw=te(vu),Au=W(tn,ee(280),z(D(466)),z(D(466)),z(D(421))),Lw=te(Au),Iu=W(uo,ee(465),z(D(466)),z(D(466)),z(D(421))),Rw=te(Iu),so=Ie(Su,vu,W(Li,z(D(421))),W(ah,z(D(421))),W(pr,z(D(421))),Au,Iu,D(421)),Nw=te(so),ch=W(z(so),ee(290),bu(ee(281)),z(D(421))),Uw=te(ch),uh=Ie(W(so,ee(290),ee(281),z(D(421))),W(so,ee(281),z(D(421))),W(ee(281),z(D(421)))),kw=te(uh),fh=W(pr,Ie(W(D(6,"80")),W(D(6),ee(480)),ee(480)),z(D(481)),z(D(421))),Mw=te(fh),lh=W(pr,Ie(W(D(6,"443")),W(D(6,"443"),ee(480)),W(D(6),ee(443)),W(D(6),ee(448),ee(480)),W(ee(448),ee(480)),ee(448),ee(443)),z(D(481)),z(D(421))),Kw=te(lh),dh=Ie(W(D(777),z(D(421)))),Fw=te(dh),hh=Ie(W(D(400),z(D(421)))),qw=te(hh);function mr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Ni=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},ph=t=>"reason"in t?t.reason:new DOMException("This operation was aborted.","AbortError"),mh=2**31-1,yh=(t,e)=>{if(typeof t!="number"||Math.sign(t)!==1)return new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(typeof e?.setTimeout!="function"||typeof e?.clearTimeout!="function")return new TypeError("Expected `customTimers` to have a `setTimeout` and a `clearTimeout` function")};function Ui(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,u=()=>{try{t.cancel?.()}catch{}},l=new Promise((h,p)=>{let x=()=>{p(ph(i)),u()},m=yh(r,s);try{m?p(m):i?.aborted?x():i&&(c=x,i.addEventListener("abort",c,{once:!0}))}finally{t.then(h,p)}if(m||i?.aborted||r>mh)return;let g=n||o===!1||o instanceof Error?void 0:new Ni(o??`Promise timed out after ${r} milliseconds`);a=s.setTimeout.call(void 0,()=>{if(n)try{h(n())}catch(w){p(w)}else o===!1?h():p(o instanceof Error?o:g);u()},r)}).finally(()=>{try{l.clear()}catch{}try{c&&i.removeEventListener("abort",c)}catch{}});return l.clear=()=>{a!==void 0&&(s.clearTimeout.call(void 0,a),a=void 0)},l}var Tu=t=>typeof t=="function"?{filter:t}:{...t},bh=t=>t===1/0||Number.isSafeInteger(t)&&t>=0,gh=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],xh=t=>{for(let[e,r]of gh){let n=t?.[e],o=t?.[r];if(typeof n=="function"&&typeof o=="function")return{addListener:n.bind(t),removeListener:o.bind(t)}}throw new TypeError("Emitter is not compatible")},wh=t=>{let e=new Map;for(let[r,n]of t)for(let o of Array.isArray(r)?r:[r])e.has(o)||e.set(o,n);return e},Eh=({addListener:t,removeListener:e,handlers:r,signal:n,abortHandler:o,isDone:s})=>{n?.addEventListener("abort",o,{once:!0});for(let[i,a]of r)if(t(i,a),s()){e(i,a);return}},Sh=({removeListener:t,handlers:e,signal:r,abortHandler:n})=>{for(let[o,s]of e)t(o,s);r?.removeEventListener("abort",n)},vh=(t,e,r)=>{let n=Promise.resolve();return(o,s)=>{n=n.then(async()=>{if(e())return;let i;try{i=t?await t(o):!0}catch(a){e()||r(a);return}e()||s(i)})}};function Ah(t,e,r){let n=()=>{},o=!1,s,i=new Promise((a,c)=>{r=Tu(r);let{filter:u}=r;if(!bh(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:f,removeListener:l}=xh(t);if(r.count===0){a([]);return}let h=[],p=S=>{n(),c(S)},x=vh(u,()=>o,p),m=S=>{h.push(S),r.count===h.length&&(n(),a(h))},g=(...S)=>{if(o)return;let A=r.multiArgs?S:S[0];if(!u){m(A);return}x(A,R=>{R&&m(A)})},w=(...S)=>{p(r.rejectionMultiArgs?S:S[0])},I=()=>{p(r.signal.reason)},b={addListener:f,removeListener:l,handlers:wh([[e,g],[r.rejectionEvents??["error"],w]]),signal:r.signal,abortHandler:I,isDone:()=>o};n=()=>{o=!0,clearTimeout(s),Sh(b)},Eh(b),!(o||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&r.timeout<=2**31-1&&(s=setTimeout(n,r.timeout)),a(h))});if(i.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let a=Ui(i,{milliseconds:r.timeout});return a.cancel=()=>{n(),a.clear()},a}return i}function _u(t,e,r){let n=Ah(t,e,{...Tu(r),count:1,resolveImmediately:!1}),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Cu(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Vt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Ih(t){return t.reason}function ki(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??Ih;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var _h=4194304,fo=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ki=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Fi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},qi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ch(t){return typeof t?.closeRead=="function"}function Bh(t){return typeof t?.close=="function"}function Mi(t){return Ch(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Bh(t)?t.status!=="open":!1}function Dh(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Oh(t,e){let r=e?.maxBufferSize??_h,n=new me,o,s=!1,i;if(!Dh(t))throw new ae("Argument should be a Stream or a Multiaddr");let a=l=>{if(!s&&i==null){if(n.append(l.data),n.byteLength>r){let h=n.byteLength;n.consume(h);let p=new rn(`Read buffer overflow - ${h} > ${r}`);i=p,o?.reject(p),queueMicrotask(()=>{t.abort(p)});return}o?.resolve()}};t.addEventListener("message",a);let c=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};t.addEventListener("close",c);let u=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(s===!0)throw new fo("Stream was unwrapped");if(i!=null)throw i;if(Mi(t)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new Vt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let h=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await ki(o.promise,l?.signal),Mi(t)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let p=l?.bytes??n.byteLength;if(n.byteLength<p){if(Mi(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Vt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return f.read(l)}let x=n.sublist(0,p);return n.consume(p),x},async write(l,h){if(s===!0)throw new fo("Stream was unwrapped");t.send(l)||await _u(t,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",a),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n),n.consume(n.byteLength))),t}};return f}function Ph(t,e={}){let r=Oh(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Pe(e.maxDataLength));let n=e?.lengthDecoder??Mr,o=e?.lengthEncoder??nr;return{async read(i){let a=-1,c=new me;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Ki("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new qi(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Fi(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new Vt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Vt(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new me(o(i.byteLength),i),a)},async writeV(i,a){let c=new me(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function yr(t,e){let r=Ph(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i,s)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}function Lh(t){return t[Symbol.asyncIterator]!=null}function Rh(t){if(Lh(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Bu=Rh;var lo=globalThis.CustomEvent??Event;async function*Vi(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,s=[],i=mr(),a=mr(),c=!1,u,f=!1,l=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of t){if(s.length===r&&(i=mr(),await i.promise),f||l)break;let g={done:!1};s.push(g),m().then(w=>{g.done=!0,g.ok=!0,g.value=w,o.dispatchEvent(new lo("task-complete"))},w=>{g.done=!0,g.err=w,o.dispatchEvent(new lo("task-complete"))})}c=!0,o.dispatchEvent(new lo("task-complete"))}catch(m){u=m,o.dispatchEvent(new lo("task-complete"))}});function h(){return n?s[0]?.done:!!s.find(m=>m.done)}function*p(){for(;s.length>0&&s[0].done;){let m=s[0];if(s.shift(),m.ok)yield m.value;else throw f=!0,i.resolve(),m.err;i.resolve()}}function*x(){for(;h();)for(let m=0;m<s.length;m++)if(s[m].done){let g=s[m];if(s.splice(m,1),m--,g.ok)yield g.value;else throw f=!0,i.resolve(),g.err;i.resolve()}}try{for(;;){if(h()||(a=mr(),await a.promise),u!=null||(n?yield*p():yield*x(),u!=null))throw u;if(c&&s.length===0)break}}finally{l=!0,i.resolve()}}var Du="0.1.0";var Ou="id/push",Pu="1.0.0",Lu="1.0.0";var vt;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((s,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),s.protocolVersion!=null&&(i.uint32(42),i.string(s.protocolVersion)),s.agentVersion!=null&&(i.uint32(50),i.string(s.agentVersion)),s.publicKey!=null&&(i.uint32(10),i.bytes(s.publicKey)),s.listenAddrs!=null&&s.listenAddrs.length>0)for(let c of s.listenAddrs)i.uint32(18),i.bytes(c);if(s.observedAddr!=null&&(i.uint32(34),i.bytes(s.observedAddr)),s.protocols!=null&&s.protocols.length>0)for(let c of s.protocols)i.uint32(26),i.string(c);s.signedPeerRecord!=null&&(i.uint32(66),i.bytes(s.signedPeerRecord)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={listenAddrs:[],protocols:[]},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 5:{c.protocolVersion=s.string();break}case 6:{c.agentVersion=s.string();break}case 1:{c.publicKey=s.bytes();break}case 2:{if(a.limits?.listenAddrs!=null&&c.listenAddrs.length===a.limits.listenAddrs)throw new Je('Decode error - repeated field "listenAddrs" had too many elements');c.listenAddrs.push(s.bytes());break}case 4:{c.observedAddr=s.bytes();break}case 3:{if(a.limits?.protocols!=null&&c.protocols.length===a.limits.protocols)throw new Je('Decode error - repeated field "protocols" had too many elements');c.protocols.push(s.string());break}case 8:{c.signedPeerRecord=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u={listenAddrs:0,protocols:0},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 5:{yield{field:`${a}.protocolVersion`,value:s.string()};break}case 6:{yield{field:`${a}.agentVersion`,value:s.string()};break}case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{if(c.limits?.listenAddrs!=null&&u.listenAddrs===c.limits.listenAddrs)throw new Je('Streaming decode error - repeated field "listenAddrs" had too many elements');yield{field:`${a}.listenAddrs[]`,index:u.listenAddrs,value:s.bytes()},u.listenAddrs++;break}case 4:{yield{field:`${a}.observedAddr`,value:s.bytes()};break}case 3:{if(c.limits?.protocols!=null&&u.protocols===c.limits.protocols)throw new Je('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${a}.protocols[]`,index:u.protocols,value:s.string()},u.protocols++;break}case 8:{yield{field:`${a}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function r(s){return ze(s,t.codec())}t.encode=r;function n(s,i){return He(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(vt||(vt={}));var Te={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxListenAddresses:100,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Nu(t){return t.bytes.length===0}function Hi(t){if(t!=null&&t.length>0)try{let e=Qr(t);if(!Nu(e))return e}catch{}}async function ho(t,e,r,n,o,s=Te.maxListenAddresses){if(r("received identify from %p",n.remotePeer),o==null)throw new Ke("message was null or undefined");let i={};o.listenAddrs.length>s&&r("%p sent %d listen addresses, ignoring all but the first %d",n.remotePeer,o.listenAddrs.length,s);let a=o.listenAddrs.slice(0,s).map(Hi).filter(f=>f!=null);if(o.listenAddrs.length>0&&(i.addresses=a.map(f=>({isCertified:!1,multiaddr:f}))),o.protocols.length>0&&(i.protocols=o.protocols),o.publicKey!=null){let f=ir(o.publicKey);if(!Zr(f).equals(n.remotePeer))throw new Ke("public key did not match remote PeerId");i.publicKey=f}let c;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let f=o.signedPeerRecord,l=await tt.openAndCertify(f,je.DOMAIN),h=je.createFromProtobuf(l.payload),p=Zr(l.publicKey);if(!h.peerId.equals(p))throw new Ke("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(h.peerId))throw new Ke("signing key does not match remote PeerId");let x;try{x=await t.get(h.peerId)}catch(g){if(g.name!=="NotFoundError")throw g}if(x!=null&&(i.metadata=x.metadata,x.peerRecordEnvelope!=null)){let g=tt.createFromProtobuf(x.peerRecordEnvelope),w=je.createFromProtobuf(g.payload);w.seqNumber>=h.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",w.seqNumber,h.seqNumber),h=w,f=x.peerRecordEnvelope)}i.peerRecordEnvelope=f;let m=h.multiaddrs.filter(g=>!Nu(g)).slice(0,s);i.addresses=m.map(g=>({isCertified:!0,multiaddr:g})),c={seq:h.seqNumber,addresses:m}}else r("%p did not send a signed peer record",n.remotePeer);if(r.trace("patching %p with",n.remotePeer,i),await t.patch(n.remotePeer,i),o.agentVersion!=null||o.protocolVersion!=null){let f={};o.agentVersion!=null&&(f.AgentVersion=V(o.agentVersion)),o.protocolVersion!=null&&(f.ProtocolVersion=V(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,f),await t.merge(n.remotePeer,{metadata:f})}let u={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:a,observedAddr:o.observedAddr==null?void 0:Qr(o.observedAddr),protocols:o.protocols,signedPeerRecord:c,connection:n};return e.safeDispatchEvent("peer:identify",{detail:u}),u}function po(t){let e={...t[0]};for(let r of t.slice(1))r.protocolVersion!=null&&(e.protocolVersion=r.protocolVersion),r.agentVersion!=null&&(e.agentVersion=r.agentVersion),r.publicKey!=null&&(e.publicKey=r.publicKey),r.observedAddr!=null&&(e.observedAddr=r.observedAddr),r.signedPeerRecord!=null&&(e.signedPeerRecord=r.signedPeerRecord),e.listenAddrs=[...e.listenAddrs,...r.listenAddrs],e.protocols=[...new Set([...e.protocols,...r.protocols])];return e}async function mo(t,e,r,n){let o=yr(t,{maxDataLength:e}).pb(vt),s=[];for(let i=0;i<10;i++)try{s.push(await o.read(r))}catch(a){if(s.length===0)throw a;n.trace("stopped reading identify - %e",a);break}s.length>=10&&n("reached MAX_IDENTIFY_MESSAGES, returning truncated identify");try{await t.close(r)}catch(i){n.trace("error closing identify stream after read - %e",i),t.abort(i)}return s}var br=class{host;components;protocol;started;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;maxListenAddresses;runOnLimitedConnection;log;constructor(e,r){this.protocol=r.protocol,this.started=!1,this.components=e,this.log=r.log,this.timeout=r.timeout??Te.timeout,this.maxInboundStreams=r.maxInboundStreams??Te.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Te.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Te.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Te.maxObservedAddresses,this.maxListenAddresses=r.maxListenAddresses??Te.maxListenAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Te.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Te.protocolPrefix}/${Du}`,agentVersion:e.nodeInfo.userAgent},this.handleProtocol=this.handleProtocol.bind(this)}isStarted(){return this.started}async start(){this.started||(await this.components.peerStore.merge(this.components.peerId,{metadata:{AgentVersion:V(this.host.agentVersion),ProtocolVersion:V(this.host.protocolVersion)}}),await this.components.registrar.handle(this.protocol,this.handleProtocol,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}};var yo=class extends br{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Te.protocolPrefix}/${Ou}/${Lu}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??Te.concurrency,this._push=Cu(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Te.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[on]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let e=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),r=new je({peerId:this.components.peerId,multiaddrs:e}),n=await tt.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=Y(s.metadata.get("AgentVersion")??V(this.host.agentVersion)),a=Y(s.metadata.get("ProtocolVersion")??V(this.host.protocolVersion)),c=this;async function*u(){for(let f of c.connectionManager.getConnections())(await c.components.peerStore.get(f.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let h,p=AbortSignal.timeout(c.timeout);try{h=await f.newStream(c.protocol,{signal:p,runOnLimitedConnection:c.runOnLimitedConnection}),await yr(h,{maxDataLength:c.maxMessageSize}).pb(vt).write({listenAddrs:e.map(m=>m.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:p}),await h.close({signal:p})}catch(x){h?.log.newScope("identify-push")?.error("could not push identify update to peer",x),h?.abort(x)}})}await Bu(Vi(u(),{concurrency:this.concurrency}))}catch(e){this.log.error("error pushing updates to peers - %e",e)}}async handleProtocol(e,r){let n=e.log.newScope("identify-push");if(this.components.peerId.equals(r.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},s=await mo(e,this.maxMessageSize,o,n);await ho(this.components.peerStore,this.components.events,n,r,po(s),this.maxListenAddresses),n.trace("handled push from %p",r.remotePeer)}};var bo=class extends br{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Te.protocolPrefix}/${"id"}/${Pu}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Te.runOnConnectionOpen)&&e.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[on]=["@libp2p/identify"];async _identify(e,r={}){let n,o;if(r.signal==null){let s=AbortSignal.timeout(this.timeout);r={...r,signal:s}}this.log("run identify on new connection %a",e.remoteAddr);try{n=await e.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),o=n.log.newScope("identify");let s=await mo(n,this.maxMessageSize,r,o);return po(s)}catch(s){throw o?.error("identify failed - %e",s),n?.abort(s),s}}async identify(e,r={}){let n=await this._identify(e,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Ke("Public key was missing from identify message");let a=ir(o),c=Zr(a);if(!e.remotePeer.equals(c))throw new Ke("Identified peer does not match the expected peer");if(this.components.peerId.equals(c))throw new Ke("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",c,s),ho(this.components.peerStore,this.components.events,this.log,e,n,this.maxListenAddresses)}maybeAddObservedAddress(e){let r=Hi(e);if(r==null||(this.log.trace("our observed address was %a",r),yu(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!pu(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Eu.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(e,r){let n=e.log.newScope("identify");n("responding to identify");let o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let f=new je({peerId:this.components.peerId,multiaddrs:i});a=(await tt.seal(f,this.components.privateKey,{signal:o})).marshal().subarray()}let c=r.remoteAddr.bytes;wu.matches(r.remoteAddr)||(c=void 0);let u=yr(e).pb(vt);n("send response"),await u.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ge(this.components.privateKey.publicKey),listenAddrs:i.map(f=>f.bytes),signedPeerRecord:a,observedAddr:c,protocols:s.protocols},{signal:o}),n("close write"),await u.unwrap().unwrap().close({signal:o})}};function Fh(t={}){return e=>new bo(e,t)}function qh(t={}){return e=>new yo(e,t)}return Hu(Vh);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|