@libp2p/identify 3.0.39-da78fa851 → 3.0.39-e8398d97e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,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 xu=Object.create;var cn=Object.defineProperty;var wu=Object.getOwnPropertyDescriptor;var Eu=Object.getOwnPropertyNames;var vu=Object.getPrototypeOf,Su=Object.prototype.hasOwnProperty;var Iu=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),St=(e,t)=>{for(var r in t)cn(e,r,{get:t[r],enumerable:!0})},Li=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Eu(t))!Su.call(e,o)&&o!==r&&cn(e,o,{get:()=>t[o],enumerable:!(n=wu(t,o))||n.enumerable});return e};var Au=(e,t,r)=>(r=e!=null?xu(vu(e)):{},Li(t||!e||!e.__esModule?cn(r,"default",{value:e,enumerable:!0}):r,e)),_u=e=>Li(cn({},"__esModule",{value:!0}),e);var Wc=Iu(on=>{(function(){var e,t,r,n,o,s,i,c;c=function(a){var u,l,d,f;return u=(a&255<<24)>>>24,l=(a&255<<16)>>>16,d=(a&65280)>>>8,f=a&255,[u,l,d,f].join(".")},i=function(a){var u,l,d,f,h,p;for(u=[],d=f=0;f<=3&&a.length!==0;d=++f){if(d>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}p=t(a),h=p[0],l=p[1],a=a.substring(l),u.push(h)}if(a.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},r=function(a){return a.charCodeAt(0)},n=r("0"),s=r("a"),o=r("A"),t=function(a){var u,l,d,f,h;for(f=0,u=10,l="9",d=0,a.length>1&&a[d]==="0"&&(a[d+1]==="x"||a[d+1]==="X"?(d+=2,u=16):"0"<=a[d+1]&&a[d+1]<="9"&&(d++,u=8,l="7")),h=d;d<a.length;){if("0"<=a[d]&&a[d]<=l)f=f*u+(r(a[d])-n)>>>0;else if(u===16)if("a"<=a[d]&&a[d]<="f")f=f*u+(10+r(a[d])-s)>>>0;else if("A"<=a[d]&&a[d]<="F")f=f*u+(10+r(a[d])-o)>>>0;else break;else break;if(f>4294967295)throw new Error("too large");d++}if(d===h)throw new Error("empty octet");return[f,d]},e=(function(){function a(u,l){var d,f,h,p;if(typeof u!="string")throw new Error("Missing `net' parameter");if(l||(p=u.split("/",2),u=p[0],l=p[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(g){throw d=g,new Error("Invalid mask: "+l)}for(f=h=32;h>=0;f=--h)if(this.maskLong===4294967295<<32-f>>>0){this.bitmask=f;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(u)&this.maskLong)>>>0}catch(g){throw d=g,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new a(u)),u instanceof a?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(u){return u==null&&(u=1),new a(c(this.netLong+this.size*u),this.mask)},a.prototype.forEach=function(u){var l,d,f;for(f=i(this.first),d=i(this.last),l=0;f<=d;)u(c(f),f,l),l++,f++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a})(),on.ip2long=i,on.long2ip=c,on.Netmask=e}).call(on)});var wh={};St(wh,{identify:()=>gh,identifyPush:()=>xh});var Q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},He=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var un=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},fn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Rt=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Se=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ao=Symbol.for("@libp2p/peer-id");var ln=Symbol.for("@libp2p/service-capabilities"),Ih=Symbol.for("@libp2p/service-dependencies");var ho={};St(ho,{base58btc:()=>ot,base58flickr:()=>Ou});var Xh=new Uint8Array(0);function Oi(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Zt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Ri(e){return new TextEncoder().encode(e)}function Ni(e){return new TextDecoder().decode(e)}function Cu(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),u=Math.log(c)/Math.log(256),l=Math.log(256)/Math.log(c);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,S=0,x=0,I=p.length;x!==I&&p[x]===0;)x++,g++;for(var E=(I-x)*l+1>>>0,T=new Uint8Array(E);x!==I;){for(var R=p[x],M=0,k=E-1;(R!==0||M<S)&&k!==-1;k--,M++)R+=256*T[k]>>>0,T[k]=R%c>>>0,R=R/c>>>0;if(R!==0)throw new Error("Non-zero carry");S=M,x++}for(var N=E-S;N!==E&&T[N]===0;)N++;for(var w=a.repeat(g);N<E;++N)w+=e.charAt(T[N]);return w}function f(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var S=0,x=0;p[g]===a;)S++,g++;for(var I=(p.length-g)*u+1>>>0,E=new Uint8Array(I);p[g];){var T=r[p.charCodeAt(g)];if(T===255)return;for(var R=0,M=I-1;(T!==0||R<x)&&M!==-1;M--,R++)T+=c*E[M]>>>0,E[M]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");x=R,g++}if(p[g]!==" "){for(var k=I-x;k!==I&&E[k]===0;)k++;for(var N=new Uint8Array(S+(I-k)),w=S;k!==I;)N[w++]=E[k++];return N}}}function h(p){var g=f(p);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:d,decodeUnsafe:f,decode:h}}var Bu=Cu,Pu=Bu,Ki=Pu;var co=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},uo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ki(this,t)}},fo=class{decoders;constructor(t){this.decoders=t}or(t){return ki(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ki(e,t){return new fo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var lo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new co(t,r,n),this.decoder=new uo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function qe({name:e,prefix:t,encode:r,decode:n}){return new lo(e,t,r,n)}function le({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ki(r,e);return qe({prefix:t,name:e,encode:n,decode:s=>Zt(o(s))})}function Tu(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let l=t[e[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|l,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Du(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Lu(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function rt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Lu(n);return qe({prefix:t,name:e,encode(s){return Du(s,n,r)},decode(s){return Tu(s,o,r,e)}})}var ot=le({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ou=le({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var po={};St(po,{base32:()=>de,base32hex:()=>Ku,base32hexpad:()=>Mu,base32hexpadupper:()=>Vu,base32hexupper:()=>ku,base32pad:()=>Nu,base32padupper:()=>Uu,base32upper:()=>Ru,base32z:()=>Fu});var de=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ru=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Nu=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Uu=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ku=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ku=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Mu=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Vu=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Fu=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var mo={};St(mo,{base36:()=>vr,base36upper:()=>Hu});var vr=le({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Hu=le({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var qu=Fi,Mi=128,zu=127,$u=~zu,Gu=Math.pow(2,31);function Fi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Gu;)t[r++]=e&255|Mi,e/=128;for(;e&$u;)t[r++]=e&255|Mi,e>>>=7;return t[r]=e|0,Fi.bytes=r-n+1,t}var Zu=yo,Yu=128,Vi=127;function yo(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw yo.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Vi)<<o:(i&Vi)*Math.pow(2,o),o+=7}while(i>=Yu);return yo.bytes=s-n,r}var Wu=Math.pow(2,7),ju=Math.pow(2,14),Xu=Math.pow(2,21),Qu=Math.pow(2,28),Ju=Math.pow(2,35),tf=Math.pow(2,42),ef=Math.pow(2,49),rf=Math.pow(2,56),nf=Math.pow(2,63),of=function(e){return e<Wu?1:e<ju?2:e<Xu?3:e<Qu?4:e<Ju?5:e<tf?6:e<ef?7:e<rf?8:e<nf?9:10},sf={encode:qu,decode:Zu,encodingLength:of},af=sf,Sr=af;function Ir(e,t=0){return[Sr.decode(e,t),Sr.decode.bytes]}function ze(e,t,r=0){return Sr.encode(e,t,r),t}function $e(e){return Sr.encodingLength(e)}function Ht(e,t){let r=t.byteLength,n=$e(e),o=n+$e(r),s=new Uint8Array(o+r);return ze(e,s,0),ze(r,s,n),s.set(t,o),new Ge(e,r,t,s)}function Ar(e){let t=Zt(e),[r,n]=Ir(t),[o,s]=Ir(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ge(r,o,i,t)}function Hi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Oi(e.bytes,r.bytes)}}var Ge=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function qi(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return uf(r,bo(e),t??ot.encoder);default:return ff(r,bo(e),t??de.encoder)}}var zi=new WeakMap;function bo(e){let t=zi.get(e);if(t==null){let r=new Map;return zi.set(e,r),r}return t}var ct=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==_r)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==lf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Ht(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Hi(t.multihash,n.multihash)}toString(t){return qi(this,t)}toJSON(){return{"/":qi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??$i(n,o,s.bytes))}else if(r[df]===!0){let{version:n,multihash:o,code:s}=r,i=Ar(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==_r)throw new Error(`Version 0 CID must use dag-pb (code: ${_r}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=$i(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,_r,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Zt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Ge(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[d,f]=Ir(t.subarray(r));return r+=f,d},o=n(),s=_r;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),u=r+a,l=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:l,size:u}}static parse(t,r){let[n,o]=cf(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return bo(s).set(n,t),s}};function cf(e,t){switch(e[0]){case"Q":{let r=t??ot;return[ot.prefix,r.decode(`${ot.prefix}${e}`)]}case ot.prefix:{let r=t??ot;return[ot.prefix,r.decode(e)]}case de.prefix:{let r=t??de;return[de.prefix,r.decode(e)]}case vr.prefix:{let r=t??vr;return[vr.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function uf(e,t,r){let{prefix:n}=r;if(n!==ot.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function ff(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var _r=112,lf=18;function $i(e,t,r){let n=$e(e),o=n+$e(t),s=new Uint8Array(o+r.byteLength);return ze(e,s,0),ze(t,s,n),s.set(r,o),s}var df=Symbol.for("@ipld/js-cid/CID");var go={};St(go,{identity:()=>Nt});var Gi=0,hf="identity",Zi=Zt;function pf(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Ht(Gi,Zi(e))}var Nt={code:Gi,name:hf,encode:Zi,digest:pf};function ut(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ht(e=0){return new Uint8Array(e)}function It(e=0){return new Uint8Array(e)}function Yt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=It(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Wi=Symbol.for("@achingbrain/uint8arraylist");function Yi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function hn(e){return!!e?.[Wi]}var it=class e{bufs;length;[Wi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(hn(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(hn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Yi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Yi(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(hn(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Yt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Yt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,l=r>c&&r<=a;if(u&&l){if(t===c&&r===a){n.push(i);break}let d=t-c;n.push(i.subarray(d,d+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(l){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!hn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let d=r;d<=a;d+=l){l=0;for(let f=u;f>=0;f--){let h=this.get(d+f);if(n[f]!==h){l=Math.max(1,f-c[h]);break}}if(l===0)return d}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=It(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=It(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ut(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var xo={};St(xo,{base10:()=>mf});var mf=le({prefix:"9",name:"base10",alphabet:"0123456789"});var wo={};St(wo,{base16:()=>yf,base16upper:()=>bf});var yf=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),bf=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Eo={};St(Eo,{base2:()=>gf});var gf=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var vo={};St(vo,{base256emoji:()=>Sf});var ji=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}"),xf=ji.reduce((e,t,r)=>(e[r]=t,e),[]),wf=ji.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Ef(e){return e.reduce((t,r)=>(t+=xf[r],t),"")}function vf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=wf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Sf=qe({prefix:"\u{1F680}",name:"base256emoji",encode:Ef,decode:vf});var Io={};St(Io,{base64:()=>If,base64pad:()=>Af,base64url:()=>So,base64urlpad:()=>_f});var If=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Af=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),So=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),_f=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ao={};St(Ao,{base8:()=>Cf});var Cf=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var _o={};St(_o,{identity:()=>Bf});var Bf=qe({prefix:"\0",name:"identity",encode:e=>Ni(e),decode:e=>Ri(e)});var Rp=new TextEncoder,Np=new TextDecoder;var Po={};St(Po,{sha256:()=>Cr,sha512:()=>Lf});var Df=20;function Bo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Co(e,t,r,n,o)}var Co=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Df,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Xi(n,this.code,r?.truncate):n.then(o=>Xi(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Xi(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Ht(t,e)}function Ji(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Cr=Bo({name:"sha2-256",code:18,encode:Ji("SHA-256")}),Lf=Bo({name:"sha2-512",code:19,encode:Ji("SHA-512")});var Br={..._o,...Eo,...Ao,...xo,...wo,...po,...mo,...ho,...Io,...vo},Zp={...Po,...go};function ea(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ta=ea("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),To=ea("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=It(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Of={utf8:ta,"utf-8":ta,hex:Br.base16,latin1:To,ascii:To,binary:To,...Br},pn=Of;function V(e,t="utf8"){let r=pn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function H(e,t="utf8"){let r=pn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Rf=parseInt("11111",2),Do=parseInt("10000000",2),Nf=parseInt("01111111",2),ra={0:Pr,1:Pr,2:Uf,3:Mf,4:Vf,5:kf,6:Kf,16:Pr,22:Pr,48:Pr};function Wt(e,t={offset:0}){let r=e[t.offset]&Rf;if(t.offset++,ra[r]!=null)return ra[r](e,t);throw new Error("No decoder for tag "+r)}function Tr(e,t){let r=0;if((e[t.offset]&Do)===Do){let n=e[t.offset]&Nf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Pr(e,t){Tr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Wt(e,t);if(n===null)break;r.push(n)}return r}function Uf(e,t){let r=Tr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Kf(e,t){let r=Tr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let l=0;for(let d=0;d<a.length;d++)l+=a[d]<<d*7;c+=`.${l}`,a=[]}}return c}function kf(e,t){return t.offset++,null}function Mf(e,t){let r=Tr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Vf(e,t){let r=Tr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Ff(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new it;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Lo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Ff(e.byteLength);return new it(Uint8Array.from([t.byteLength|Do]),t)}function At(e){let t=new it,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new it(Uint8Array.from([2]),Lo(t),t)}function mn(e){let t=Uint8Array.from([0]),r=new it(t,e);return new it(Uint8Array.from([3]),Lo(r),r)}function he(e,t=48){let r=new it;for(let n of e)r.append(n);return new it(Uint8Array.from([t]),Lo(r),r)}async function na(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var Hf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),qf=Uint8Array.from([6,5,43,129,4,0,34]),zf=Uint8Array.from([6,5,43,129,4,0,35]),$f={ext:!0,kty:"EC",crv:"P-256"},Gf={ext:!0,kty:"EC",crv:"P-384"},Zf={ext:!0,kty:"EC",crv:"P-521"},Oo=32,Ro=48,No=66;function Uo(e){let t=Wt(e);return oa(t)}function oa(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Oo*2+1)return n=H(t.subarray(r,r+Oo),"base64url"),o=H(t.subarray(r+Oo),"base64url"),new Ze({...$f,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ro*2+1)return n=H(t.subarray(r,r+Ro),"base64url"),o=H(t.subarray(r+Ro),"base64url"),new Ze({...Gf,key_ops:["verify"],x:n,y:o});if(t.byteLength===No*2+1)return n=H(t.subarray(r,r+No),"base64url"),o=H(t.subarray(r+No),"base64url"),new Ze({...Zf,key_ops:["verify"],x:n,y:o});throw new Q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function sa(e){return he([At(Uint8Array.from([1])),he([Yf(e.crv)],160),he([mn(new it(Uint8Array.from([4]),V(e.x??"","base64url"),V(e.y??"","base64url")))],161)]).subarray()}function Yf(e){if(e==="P-256")return Hf;if(e==="P-384")return qf;if(e==="P-521")return zf;throw new Q(`Invalid curve ${e}`)}var Ze=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=sa(this.jwk)),this._raw}toMultihash(){return Nt.digest(qt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}async verify(t,r,n){return na(this.jwk,r,t,n)}};var Ae=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Xt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Dr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function _t(e,...t){if(!Xt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function yn(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Dr(e.outputLen),Dr(e.blockLen)}function We(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function aa(e,t){_t(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Qt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function bn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ut(e,t){return e<<32-t|e>>>t}var ca=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Wf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Lt(e){if(_t(e),ca)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Wf[e[r]];return t}var jt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ia(e){if(e>=jt._0&&e<=jt._9)return e-jt._0;if(e>=jt.A&&e<=jt.F)return e-(jt.A-10);if(e>=jt.a&&e<=jt.f)return e-(jt.a-10)}function _e(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ca)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=ia(e.charCodeAt(s)),c=ia(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Ko(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Lr(e){return typeof e=="string"&&(e=Ko(e)),_t(e),e}function wt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];_t(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var Ye=class{};function ko(e){let t=n=>e().update(Lr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function je(e=32){if(Ae&&typeof Ae.getRandomValues=="function")return Ae.getRandomValues(new Uint8Array(e));if(Ae&&typeof Ae.randomBytes=="function")return Uint8Array.from(Ae.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function jf(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,u=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+u,c,n)}function ua(e,t,r){return e&t^~e&r}function fa(e,t,r){return e&t^e&r^t&r}var Or=class extends Ye{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=bn(this.buffer)}update(t){We(this),t=Lr(t),_t(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=bn(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){We(this),aa(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Qt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let d=i;d<o;d++)r[d]=0;jf(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=bn(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)c.setUint32(4*d,l[d],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Jt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var pt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var gn=BigInt(4294967295),la=BigInt(32);function Xf(e,t=!1){return t?{h:Number(e&gn),l:Number(e>>la&gn)}:{h:Number(e>>la&gn)|0,l:Number(e&gn)|0}}function da(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=Xf(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Mo=(e,t,r)=>e>>>r,Vo=(e,t,r)=>e<<32-r|t>>>r,Ce=(e,t,r)=>e>>>r|t<<32-r,Be=(e,t,r)=>e<<32-r|t>>>r,Rr=(e,t,r)=>e<<64-r|t>>>r-32,Nr=(e,t,r)=>e>>>r-32|t<<64-r;function zt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ha=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),pa=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ma=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ya=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ba=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ga=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Jf=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]),pe=new Uint32Array(64),xn=class extends Or{constructor(t=32){super(64,t,8,!1),this.A=Jt[0]|0,this.B=Jt[1]|0,this.C=Jt[2]|0,this.D=Jt[3]|0,this.E=Jt[4]|0,this.F=Jt[5]|0,this.G=Jt[6]|0,this.H=Jt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let d=0;d<16;d++,r+=4)pe[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let f=pe[d-15],h=pe[d-2],p=Ut(f,7)^Ut(f,18)^f>>>3,g=Ut(h,17)^Ut(h,19)^h>>>10;pe[d]=g+pe[d-7]+p+pe[d-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:l}=this;for(let d=0;d<64;d++){let f=Ut(c,6)^Ut(c,11)^Ut(c,25),h=l+f+ua(c,a,u)+Jf[d]+pe[d]|0,g=(Ut(n,2)^Ut(n,13)^Ut(n,22))+fa(n,o,s)|0;l=u,u=a,a=c,c=i+h|0,i=s,s=o,o=n,n=h+g|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,c,a,u,l)}roundClean(){Qt(pe)}destroy(){this.set(0,0,0,0,0,0,0,0),Qt(this.buffer)}};var xa=da(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),tl=xa[0],el=xa[1],me=new Uint32Array(80),ye=new Uint32Array(80),Fo=class extends Or{constructor(t=64){super(128,t,16,!1),this.Ah=pt[0]|0,this.Al=pt[1]|0,this.Bh=pt[2]|0,this.Bl=pt[3]|0,this.Ch=pt[4]|0,this.Cl=pt[5]|0,this.Dh=pt[6]|0,this.Dl=pt[7]|0,this.Eh=pt[8]|0,this.El=pt[9]|0,this.Fh=pt[10]|0,this.Fl=pt[11]|0,this.Gh=pt[12]|0,this.Gl=pt[13]|0,this.Hh=pt[14]|0,this.Hl=pt[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:l,Fh:d,Fl:f,Gh:h,Gl:p,Hh:g,Hl:S}=this;return[t,r,n,o,s,i,c,a,u,l,d,f,h,p,g,S]}set(t,r,n,o,s,i,c,a,u,l,d,f,h,p,g,S){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=l|0,this.Fh=d|0,this.Fl=f|0,this.Gh=h|0,this.Gl=p|0,this.Hh=g|0,this.Hl=S|0}process(t,r){for(let E=0;E<16;E++,r+=4)me[E]=t.getUint32(r),ye[E]=t.getUint32(r+=4);for(let E=16;E<80;E++){let T=me[E-15]|0,R=ye[E-15]|0,M=Ce(T,R,1)^Ce(T,R,8)^Mo(T,R,7),k=Be(T,R,1)^Be(T,R,8)^Vo(T,R,7),N=me[E-2]|0,w=ye[E-2]|0,B=Ce(N,w,19)^Rr(N,w,61)^Mo(N,w,6),U=Be(N,w,19)^Nr(N,w,61)^Vo(N,w,6),P=ma(k,U,ye[E-7],ye[E-16]),b=ya(P,M,B,me[E-7],me[E-16]);me[E]=b|0,ye[E]=P|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:l,Eh:d,El:f,Fh:h,Fl:p,Gh:g,Gl:S,Hh:x,Hl:I}=this;for(let E=0;E<80;E++){let T=Ce(d,f,14)^Ce(d,f,18)^Rr(d,f,41),R=Be(d,f,14)^Be(d,f,18)^Nr(d,f,41),M=d&h^~d&g,k=f&p^~f&S,N=ba(I,R,k,el[E],ye[E]),w=ga(N,x,T,M,tl[E],me[E]),B=N|0,U=Ce(n,o,28)^Rr(n,o,34)^Rr(n,o,39),P=Be(n,o,28)^Nr(n,o,34)^Nr(n,o,39),b=n&s^n&c^s&c,m=o&i^o&a^i&a;x=g|0,I=S|0,g=h|0,S=p|0,h=d|0,p=f|0,{h:d,l:f}=zt(u|0,l|0,w|0,B|0),u=c|0,l=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let y=ha(B,P,m);n=pa(y,w,U,b),o=y|0}({h:n,l:o}=zt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=zt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=zt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l}=zt(this.Dh|0,this.Dl|0,u|0,l|0),{h:d,l:f}=zt(this.Eh|0,this.El|0,d|0,f|0),{h,l:p}=zt(this.Fh|0,this.Fl|0,h|0,p|0),{h:g,l:S}=zt(this.Gh|0,this.Gl|0,g|0,S|0),{h:x,l:I}=zt(this.Hh|0,this.Hl|0,x|0,I|0),this.set(n,o,s,i,c,a,u,l,d,f,h,p,g,S,x,I)}roundClean(){Qt(me,ye)}destroy(){Qt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var wn=ko(()=>new xn);var wa=ko(()=>new Fo);var zo=BigInt(0),qo=BigInt(1);function te(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Pt(e,t,r=""){let n=Xt(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function Ur(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Ea(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?zo:BigInt("0x"+e)}function Xe(e){return Ea(Lt(e))}function ee(e){return _t(e),Ea(Lt(Uint8Array.from(e).reverse()))}function En(e,t){return _e(e.toString(16).padStart(t*2,"0"))}function $o(e,t){return En(e,t).reverse()}function Z(e,t,r){let n;if(typeof t=="string")try{n=_e(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Xt(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function va(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function Go(e){return Uint8Array.from(e)}var Ho=e=>typeof e=="bigint"&&zo<=e;function Sa(e,t,r){return Ho(e)&&Ho(t)&&Ho(r)&&t<=e&&e<r}function Kr(e,t,r,n){if(!Sa(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function vn(e){let t;for(t=0;e>zo;e>>=qo,t+=1);return t}var be=e=>(qo<<BigInt(e))-qo;function Ia(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},u=(...h)=>r(i,s,...h),l=(h=n(0))=>{i=u(o(0),h),s=u(),h.length!==0&&(i=u(o(1),h),s=u())},d=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,p=[];for(;h<t;){s=u();let g=s.slice();p.push(g),h+=s.length}return wt(...p)};return(h,p)=>{a(),l(h);let g;for(;!(g=p(d()));)l();return a(),g}}function ge(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var Zo=()=>{throw new Error("not implemented")};function Qe(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var Et=BigInt(0),ft=BigInt(1),Pe=BigInt(2),Ca=BigInt(3),Ba=BigInt(4),Pa=BigInt(5),rl=BigInt(7),Ta=BigInt(8),nl=BigInt(9),Da=BigInt(16);function nt(e,t){let r=e%t;return r>=Et?r:t+r}function X(e,t,r){let n=e;for(;t-- >Et;)n*=n,n%=r;return n}function Aa(e,t){if(e===Et)throw new Error("invert: expected non-zero number");if(t<=Et)throw new Error("invert: expected positive modulus, got "+t);let r=nt(e,t),n=t,o=Et,s=ft,i=ft,c=Et;for(;r!==Et;){let u=n/r,l=n%r,d=o-i*u,f=s-c*u;n=r,r=l,o=i,s=c,i=d,c=f}if(n!==ft)throw new Error("invert: does not exist");return nt(o,t)}function Yo(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function La(e,t){let r=(e.ORDER+ft)/Ba,n=e.pow(t,r);return Yo(e,n,t),n}function ol(e,t){let r=(e.ORDER-Pa)/Ta,n=e.mul(t,Pe),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Pe),o),c=e.mul(s,e.sub(i,e.ONE));return Yo(e,c,t),c}function sl(e){let t=Tt(e),r=Oa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+rl)/Da;return(c,a)=>{let u=c.pow(a,i),l=c.mul(u,n),d=c.mul(u,o),f=c.mul(u,s),h=c.eql(c.sqr(l),a),p=c.eql(c.sqr(d),a);u=c.cmov(u,l,h),l=c.cmov(f,d,p);let g=c.eql(c.sqr(l),a),S=c.cmov(u,l,g);return Yo(c,S,a),S}}function Oa(e){if(e<Ca)throw new Error("sqrt is not defined for small field");let t=e-ft,r=0;for(;t%Pe===Et;)t/=Pe,r++;let n=Pe,o=Tt(e);for(;_a(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return La;let s=o.pow(n,t),i=(t+ft)/Pe;return function(a,u){if(a.is0(u))return u;if(_a(a,u)!==1)throw new Error("Cannot find square root");let l=r,d=a.mul(a.ONE,s),f=a.pow(u,t),h=a.pow(u,i);for(;!a.eql(f,a.ONE);){if(a.is0(f))return a.ZERO;let p=1,g=a.sqr(f);for(;!a.eql(g,a.ONE);)if(p++,g=a.sqr(g),p===l)throw new Error("Cannot find square root");let S=ft<<BigInt(l-p-1),x=a.pow(d,S);l=p,d=a.sqr(x),f=a.mul(f,d),h=a.mul(h,x)}return h}}function il(e){return e%Ba===Ca?La:e%Ta===Pa?ol:e%Da===nl?sl(e):Oa(e)}var re=(e,t)=>(nt(e,t)&ft)===ft,al=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wo(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=al.reduce((n,o)=>(n[o]="function",n),t);return ge(e,r),e}function cl(e,t,r){if(r<Et)throw new Error("invalid exponent, negatives unsupported");if(r===Et)return e.ONE;if(r===ft)return t;let n=e.ONE,o=t;for(;r>Et;)r&ft&&(n=e.mul(n,o)),o=e.sqr(o),r>>=ft;return n}function kr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function _a(e,t){let r=(e.ORDER-ft)/Pe,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Sn(e,t){t!==void 0&&Dr(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Tt(e,t,r=!1,n={}){if(e<=Et)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE),typeof f.modFromBytes=="boolean"&&(i=f.modFromBytes),c=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:u}=Sn(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l,d=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:u,MASK:be(a),ZERO:Et,ONE:ft,allowedLengths:c,create:f=>nt(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return Et<=f&&f<e},is0:f=>f===Et,isValidNot0:f=>!d.is0(f)&&d.isValid(f),isOdd:f=>(f&ft)===ft,neg:f=>nt(-f,e),eql:(f,h)=>f===h,sqr:f=>nt(f*f,e),add:(f,h)=>nt(f+h,e),sub:(f,h)=>nt(f-h,e),mul:(f,h)=>nt(f*h,e),pow:(f,h)=>cl(d,f,h),div:(f,h)=>nt(f*Aa(h,e),e),sqrN:f=>f*f,addN:(f,h)=>f+h,subN:(f,h)=>f-h,mulN:(f,h)=>f*h,inv:f=>Aa(f,e),sqrt:s||(f=>(l||(l=il(e)),l(d,f))),toBytes:f=>r?$o(f,u):En(f,u),fromBytes:(f,h=!0)=>{if(c){if(!c.includes(f.length)||f.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+f.length);let g=new Uint8Array(u);g.set(f,r?0:g.length-f.length),f=g}if(f.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+f.length);let p=r?ee(f):Xe(f);if(i&&(p=nt(p,e)),!h&&!d.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:f=>kr(d,f),cmov:(f,h,p)=>p?h:f});return Object.freeze(d)}function Ra(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function jo(e){let t=Ra(e);return t+Math.ceil(t/2)}function Xo(e,t,r=!1){let n=e.length,o=Ra(t),s=jo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?ee(e):Xe(e),c=nt(i,t-ft)+ft;return r?$o(c,o):En(c,o)}var Je=BigInt(0),Te=BigInt(1);function Mr(e,t){let r=t.negate();return e?r:t}function ne(e,t){let r=kr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function ka(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Qo(e,t){ka(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=be(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Na(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=Te);let u=t*n,l=u+Math.abs(c)-1,d=c===0,f=c<0,h=t%2!==0;return{nextN:a,offset:l,isZero:d,isNeg:f,isNegF:h,offsetF:u}}function ul(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function fl(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Jo=new WeakMap,Ma=new WeakMap;function ts(e){return Ma.get(e)||1}function Ua(e){if(e!==Je)throw new Error("invalid wNAF")}var tr=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Je;)r&Te&&(n=n.add(o)),o=o.double(),r>>=Te;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Qo(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Qo(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:l,isNeg:d,isNegF:f,offsetF:h}=Na(n,c,i);n=a,l?s=s.add(Mr(f,r[h])):o=o.add(Mr(d,r[u]))}return Ua(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Qo(t,this.bits);for(let i=0;i<s.windows&&n!==Je;i++){let{nextN:c,offset:a,isZero:u,isNeg:l}=Na(n,i,s);if(n=c,!u){let d=r[a];o=o.add(l?d.negate():d)}}return Ua(n),o}getPrecomputes(t,r,n){let o=Jo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Jo.set(r,o))),o}cached(t,r,n){let o=ts(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=ts(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){ka(r,this.bits),Ma.set(t,r),Jo.delete(t)}hasCache(t){return ts(t)!==1}};function Va(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Je||n>Je;)r&Te&&(s=s.add(o)),n&Te&&(i=i.add(o)),o=o.double(),r>>=Te,n>>=Te;return{p1:s,p2:i}}function er(e,t,r,n){ul(r,e),fl(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=vn(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=be(a),l=new Array(Number(u)+1).fill(i),d=Math.floor((t.BITS-1)/a)*a,f=i;for(let h=d;h>=0;h-=a){l.fill(i);for(let g=0;g<s;g++){let S=n[g],x=Number(S>>BigInt(h)&u);l[x]=l[x].add(r[g])}let p=i;for(let g=l.length-1,S=i;g>0;g--)S=S.add(l[g]),p=p.add(S);if(f=f.add(p),h!==0)for(let g=0;g<a;g++)f=f.double()}return f}function Ka(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Wo(t),t}else return Tt(e,{isLE:r})}function In(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>Je))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Ka(t.p,r.Fp,n),s=Ka(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var xe=BigInt(0),lt=BigInt(1),es=BigInt(2),ll=BigInt(8);function dl(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function hl(e,t={}){let r=In("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;ge(t,{},{uvRatio:"function"});let c=es<<BigInt(o.BYTES*8)-lt,a=S=>n.create(S),u=t.uvRatio||((S,x)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,x))}}catch{return{isValid:!1,value:xe}}});if(!dl(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(S,x,I=!1){let E=I?lt:xe;return Kr("coordinate "+S,x,E,c),x}function d(S){if(!(S instanceof p))throw new Error("ExtendedPoint expected")}let f=Qe((S,x)=>{let{X:I,Y:E,Z:T}=S,R=S.is0();x==null&&(x=R?ll:n.inv(T));let M=a(I*x),k=a(E*x),N=n.mul(T,x);if(R)return{x:xe,y:lt};if(N!==lt)throw new Error("invZ was invalid");return{x:M,y:k}}),h=Qe(S=>{let{a:x,d:I}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:E,Y:T,Z:R,T:M}=S,k=a(E*E),N=a(T*T),w=a(R*R),B=a(w*w),U=a(k*x),P=a(w*a(U+N)),b=a(B+a(I*a(k*N)));if(P!==b)throw new Error("bad point: equation left != right (1)");let m=a(E*T),y=a(R*M);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(x,I,E,T){this.X=l("x",x),this.Y=l("y",I),this.Z=l("z",E,!0),this.T=l("t",T),Object.freeze(this)}static CURVE(){return s}static fromAffine(x){if(x instanceof p)throw new Error("extended point not allowed");let{x:I,y:E}=x||{};return l("x",I),l("y",E),new p(I,E,lt,a(I*E))}static fromBytes(x,I=!1){let E=n.BYTES,{a:T,d:R}=s;x=Go(Pt(x,E,"point")),te(I,"zip215");let M=Go(x),k=x[E-1];M[E-1]=k&-129;let N=ee(M),w=I?c:n.ORDER;Kr("point.y",N,xe,w);let B=a(N*N),U=a(B-lt),P=a(R*B-T),{isValid:b,value:m}=u(U,P);if(!b)throw new Error("bad point: invalid y coordinate");let y=(m&lt)===lt,v=(k&128)!==0;if(!I&&m===xe&&v)throw new Error("bad point: x=0 and x_0=1");return v!==y&&(m=a(-m)),p.fromAffine({x:m,y:N})}static fromHex(x,I=!1){return p.fromBytes(Z("point",x),I)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,I=!0){return g.createCache(this,x),I||this.multiply(es),this}assertValidity(){h(this)}equals(x){d(x);let{X:I,Y:E,Z:T}=this,{X:R,Y:M,Z:k}=x,N=a(I*k),w=a(R*T),B=a(E*k),U=a(M*T);return N===w&&B===U}is0(){return this.equals(p.ZERO)}negate(){return new p(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:x}=s,{X:I,Y:E,Z:T}=this,R=a(I*I),M=a(E*E),k=a(es*a(T*T)),N=a(x*R),w=I+E,B=a(a(w*w)-R-M),U=N+M,P=U-k,b=N-M,m=a(B*P),y=a(U*b),v=a(B*b),A=a(P*U);return new p(m,y,A,v)}add(x){d(x);let{a:I,d:E}=s,{X:T,Y:R,Z:M,T:k}=this,{X:N,Y:w,Z:B,T:U}=x,P=a(T*N),b=a(R*w),m=a(k*E*U),y=a(M*B),v=a((T+R)*(N+w)-P-b),A=y-m,D=y+m,_=a(b-I*P),C=a(v*A),O=a(D*_),K=a(v*_),J=a(A*D);return new p(C,O,J,K)}subtract(x){return this.add(x.negate())}multiply(x){if(!o.isValidNot0(x))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:I,f:E}=g.cached(this,x,T=>ne(p,T));return ne(p,[I,E])[0]}multiplyUnsafe(x,I=p.ZERO){if(!o.isValid(x))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return x===xe?p.ZERO:this.is0()||x===lt?this:g.unsafe(this,x,E=>ne(p,E),I)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return g.unsafe(this,s.n).is0()}toAffine(x){return f(this,x)}clearCofactor(){return i===lt?this:this.multiplyUnsafe(i)}toBytes(){let{x,y:I}=this.toAffine(),E=n.toBytes(I);return E[E.length-1]|=x&lt?128:0,E}toHex(){return Lt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(x){return ne(p,x)}static msm(x,I){return er(p,o,x,I)}_setWindowSize(x){this.precompute(x)}toRawBytes(){return this.toBytes()}}p.BASE=new p(s.Gx,s.Gy,lt,a(s.Gx*s.Gy)),p.ZERO=new p(xe,lt,lt,xe),p.Fp=n,p.Fn=o;let g=new tr(p,o.BITS);return p.BASE.precompute(8),p}var An=class{constructor(t){this.ep=t}static fromBytes(t){Zo()}static fromHex(t){Zo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Lt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function pl(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');ge(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||je,a=r.adjustScalarBytes||(w=>w),u=r.domain||((w,B,U)=>{if(te(U,"phflag"),B.length||U)throw new Error("Contexts/pre-hash are not supported");return w});function l(w){return i.create(ee(w))}function d(w){let B=E.secretKey;w=Z("private key",w,B);let U=Z("hashed private key",t(w),2*B),P=a(U.slice(0,B)),b=U.slice(B,2*B),m=l(P);return{head:P,prefix:b,scalar:m}}function f(w){let{head:B,prefix:U,scalar:P}=d(w),b=o.multiply(P),m=b.toBytes();return{head:B,prefix:U,scalar:P,point:b,pointBytes:m}}function h(w){return f(w).pointBytes}function p(w=Uint8Array.of(),...B){let U=wt(...B);return l(t(u(U,Z("context",w),!!n)))}function g(w,B,U={}){w=Z("message",w),n&&(w=n(w));let{prefix:P,scalar:b,pointBytes:m}=f(B),y=p(U.context,P,w),v=o.multiply(y).toBytes(),A=p(U.context,v,m,w),D=i.create(y+A*b);if(!i.isValid(D))throw new Error("sign failed: invalid s");let _=wt(v,i.toBytes(D));return Pt(_,E.signature,"result")}let S={zip215:!0};function x(w,B,U,P=S){let{context:b,zip215:m}=P,y=E.signature;w=Z("signature",w,y),B=Z("message",B),U=Z("publicKey",U,E.publicKey),m!==void 0&&te(m,"zip215"),n&&(B=n(B));let v=y/2,A=w.subarray(0,v),D=ee(w.subarray(v,y)),_,C,O;try{_=e.fromBytes(U,m),C=e.fromBytes(A,m),O=o.multiplyUnsafe(D)}catch{return!1}if(!m&&_.isSmallOrder())return!1;let K=p(b,C.toBytes(),_.toBytes(),B);return C.add(_.multiplyUnsafe(K)).subtract(O).clearCofactor().is0()}let I=s.BYTES,E={secretKey:I,publicKey:I,signature:2*I,seed:I};function T(w=c(E.seed)){return Pt(w,E.seed,"seed")}function R(w){let B=N.randomSecretKey(w);return{secretKey:B,publicKey:h(B)}}function M(w){return Xt(w)&&w.length===i.BYTES}function k(w,B){try{return!!e.fromBytes(w,B)}catch{return!1}}let N={getExtendedPublicKey:f,randomSecretKey:T,isValidSecretKey:M,isValidPublicKey:k,toMontgomery(w){let{y:B}=e.fromBytes(w),U=E.publicKey,P=U===32;if(!P&&U!==57)throw new Error("only defined for 25519 and 448");let b=P?s.div(lt+B,lt-B):s.div(B-lt,B+lt);return s.toBytes(b)},toMontgomerySecret(w){let B=E.secretKey;Pt(w,B);let U=t(w.subarray(0,B));return a(U).subarray(0,B)},randomPrivateKey:T,precompute(w=8,B=e.BASE){return B.precompute(w,!1)}};return Object.freeze({keygen:R,getPublicKey:h,sign:g,verify:x,utils:N,Point:e,lengths:E})}function ml(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=Tt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function yl(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Fa(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=ml(e),s=hl(t,r),i=pl(s,n,o);return yl(e,i)}var bl=BigInt(0),oe=BigInt(1),Ha=BigInt(2),em=BigInt(3),gl=BigInt(5),xl=BigInt(8),rr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Vr={p:rr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:xl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function wl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=rr,c=e*e%s*e%s,a=X(c,Ha,s)*c%s,u=X(a,oe,s)*e%s,l=X(u,gl,s)*u%s,d=X(l,t,s)*l%s,f=X(d,r,s)*d%s,h=X(f,n,s)*f%s,p=X(h,o,s)*h%s,g=X(p,o,s)*h%s,S=X(g,t,s)*l%s;return{pow_p_5_8:X(S,Ha,s)*e%s,b2:c}}function El(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var rs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ss(e,t){let r=rr,n=nt(t*t*t,r),o=nt(n*n*t,r),s=wl(e*o).pow_p_5_8,i=nt(e*n*s,r),c=nt(t*i*i,r),a=i,u=nt(i*rs,r),l=c===e,d=c===nt(-e,r),f=c===nt(-e*rs,r);return l&&(i=a),(d||f)&&(i=u),re(i,r)&&(i=nt(-i,r)),{isValid:l||d,value:i}}var we=Tt(Vr.p,{isLE:!0}),vl=Tt(Vr.n,{isLE:!0}),Sl={...Vr,Fp:we,hash:wa,adjustScalarBytes:El,uvRatio:ss},se=Fa(Sl);var ns=rs,Il=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Al=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),_l=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Cl=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),qa=e=>ss(oe,e),Bl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),os=e=>se.Point.Fp.create(ee(e)&Bl);function za(e){let{d:t}=Vr,r=rr,n=x=>we.create(x),o=n(ns*e*e),s=n((o+oe)*_l),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:u}=ss(s,c),l=n(u*e);re(l,r)||(l=n(-l)),a||(u=l),a||(i=o);let d=n(i*(o-oe)*Cl-c),f=u*u,h=n((u+u)*c),p=n(d*Il),g=n(oe-f),S=n(oe+f);return new se.Point(n(h*S),n(g*p),n(p*S),n(h*g))}function Pl(e){_t(e,64);let t=os(e.subarray(0,32)),r=za(t),n=os(e.subarray(32,64)),o=za(n);return new ie(r.add(o))}var ie=class e extends An{constructor(t){super(t)}static fromAffine(t){return new e(se.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return Pl(Z("ristrettoHash",t,64))}static fromBytes(t){_t(t,32);let{a:r,d:n}=Vr,o=rr,s=T=>we.create(T),i=os(t);if(!va(we.toBytes(i),t)||re(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(oe+r*c),u=s(oe-r*c),l=s(a*a),d=s(u*u),f=s(r*n*l-d),{isValid:h,value:p}=qa(s(f*d)),g=s(p*u),S=s(p*g*f),x=s((i+i)*g);re(x,o)&&(x=s(-x));let I=s(a*S),E=s(x*I);if(!h||re(E,o)||I===bl)throw new Error("invalid ristretto255 encoding 2");return new e(new se.Point(x,I,oe,E))}static fromHex(t){return e.fromBytes(Z("ristrettoHex",t,32))}static msm(t,r){return er(e,se.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=rr,i=S=>we.create(S),c=i(i(n+r)*i(n-r)),a=i(t*r),u=i(a*a),{value:l}=qa(i(c*u)),d=i(l*c),f=i(l*a),h=i(d*f*o),p;if(re(o*h,s)){let S=i(r*ns),x=i(t*ns);t=S,r=x,p=i(d*Al)}else p=f;re(t*h,s)&&(r=i(-r));let g=i((n-r)*p);return re(g,s)&&(g=i(-g)),we.toBytes(g)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>we.create(u),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};ie.BASE=new ie(se.Point.BASE);ie.ZERO=new ie(se.Point.ZERO);ie.Fp=we;ie.Fn=vl;var Fr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},_n=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var $a={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new _n("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Ot=$a;var Cn=32;var is,Tl=(async()=>{try{return await Ot.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Dl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Ot.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Ot.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ll(e,t,r){return se.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ga(e,t,r){return is==null&&(is=await Tl),is?Dl(e,t,r):Ll(e,t,r)}function Bn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Pn=class{type="Ed25519";raw;constructor(t){this.raw=as(t,Cn)}toMultihash(){return Nt.digest(qt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ga(this.raw,r,t);return Bn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function cs(e){return e=as(e,Cn),new Pn(e)}function as(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new Q(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Rl=Math.pow(2,7),Nl=Math.pow(2,14),Ul=Math.pow(2,21),us=Math.pow(2,28),fs=Math.pow(2,35),ls=Math.pow(2,42),ds=Math.pow(2,49),$=128,bt=127;function Ct(e){if(e<Rl)return 1;if(e<Nl)return 2;if(e<Ul)return 3;if(e<us)return 4;if(e<fs)return 5;if(e<ls)return 6;if(e<ds)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function nr(e,t,r=0){switch(Ct(e)){case 8:t[r++]=e&255|$,e/=128;case 7:t[r++]=e&255|$,e/=128;case 6:t[r++]=e&255|$,e/=128;case 5:t[r++]=e&255|$,e/=128;case 4:t[r++]=e&255|$,e>>>=7;case 3:t[r++]=e&255|$,e>>>=7;case 2:t[r++]=e&255|$,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Kl(e,t,r=0){switch(Ct(e)){case 8:t.set(r++,e&255|$),e/=128;case 7:t.set(r++,e&255|$),e/=128;case 6:t.set(r++,e&255|$),e/=128;case 5:t.set(r++,e&255|$),e/=128;case 4:t.set(r++,e&255|$),e>>>=7;case 3:t.set(r++,e&255|$),e>>>=7;case 2:t.set(r++,e&255|$),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function hs(e,t){let r=e[t],n=0;if(n+=r&bt,r<$||(r=e[t+1],n+=(r&bt)<<7,r<$)||(r=e[t+2],n+=(r&bt)<<14,r<$)||(r=e[t+3],n+=(r&bt)<<21,r<$)||(r=e[t+4],n+=(r&bt)*us,r<$)||(r=e[t+5],n+=(r&bt)*fs,r<$)||(r=e[t+6],n+=(r&bt)*ls,r<$)||(r=e[t+7],n+=(r&bt)*ds,r<$))return n;throw new RangeError("Could not decode varint")}function kl(e,t){let r=e.get(t),n=0;if(n+=r&bt,r<$||(r=e.get(t+1),n+=(r&bt)<<7,r<$)||(r=e.get(t+2),n+=(r&bt)<<14,r<$)||(r=e.get(t+3),n+=(r&bt)<<21,r<$)||(r=e.get(t+4),n+=(r&bt)*us,r<$)||(r=e.get(t+5),n+=(r&bt)*fs,r<$)||(r=e.get(t+6),n+=(r&bt)*ls,r<$)||(r=e.get(t+7),n+=(r&bt)*ds,r<$))return n;throw new RangeError("Could not decode varint")}function or(e,t,r=0){return t==null&&(t=It(Ct(e))),t instanceof Uint8Array?nr(e,t,r):Kl(e,t,r)}function Hr(e,t=0){return e instanceof Uint8Array?hs(e,t):kl(e,t)}var ms=new Float32Array([-0]),Ee=new Uint8Array(ms.buffer);function Ya(e,t,r){ms[0]=e,t[r]=Ee[0],t[r+1]=Ee[1],t[r+2]=Ee[2],t[r+3]=Ee[3]}function Wa(e,t){return Ee[0]=e[t],Ee[1]=e[t+1],Ee[2]=e[t+2],Ee[3]=e[t+3],ms[0]}var ys=new Float64Array([-0]),gt=new Uint8Array(ys.buffer);function ja(e,t,r){ys[0]=e,t[r]=gt[0],t[r+1]=gt[1],t[r+2]=gt[2],t[r+3]=gt[3],t[r+4]=gt[4],t[r+5]=gt[5],t[r+6]=gt[6],t[r+7]=gt[7]}function Xa(e,t){return gt[0]=e[t],gt[1]=e[t+1],gt[2]=e[t+2],gt[3]=e[t+3],gt[4]=e[t+4],gt[5]=e[t+5],gt[6]=e[t+6],gt[7]=e[t+7],ys[0]}var Ml=BigInt(Number.MAX_SAFE_INTEGER),Vl=BigInt(Number.MIN_SAFE_INTEGER),Dt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return De;if(t<Ml&&t>Vl)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Qa&&(o=0n,++n>Qa&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return De;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):De}},De=new Dt(0,0);De.toBigInt=function(){return 0n};De.zzEncode=De.zzDecode=function(){return this};De.length=function(){return 1};var Qa=4294967296n;function Ja(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function tc(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function bs(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Tn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var gs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Kt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Kt(this,4);return Tn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return Tn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=Wa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=Xa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return tc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Kt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Dt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Kt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Kt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Kt(this,8);let t=Tn(this.buf,this.pos+=4),r=Tn(this.buf,this.pos+=4);return new Dt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=hs(this.buf,this.pos);return this.pos+=Ct(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function xs(e){return new gs(e instanceof Uint8Array?e:e.subarray())}function kt(e,t,r){let n=xs(e);return t.decode(n,void 0,r)}function ws(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return It(i);o+i>t&&(n=It(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var Le=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Es(){}var Ss=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Fl=ws();function Hl(e){return globalThis.Buffer!=null?It(e):Fl(e)}var zr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Le(Es,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Le(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Is((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Dn,10,Dt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Dt.fromBigInt(t);return this._push(Dn,r.length(),r)}uint64Number(t){return this._push(nr,Ct(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Dt.fromBigInt(t).zzEncode();return this._push(Dn,r.length(),r)}sint64Number(t){let r=Dt.fromNumber(t).zzEncode();return this._push(Dn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(vs,1,t?1:0)}fixed32(t){return this._push(qr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Dt.fromBigInt(t);return this._push(qr,4,r.lo)._push(qr,4,r.hi)}fixed64Number(t){let r=Dt.fromNumber(t);return this._push(qr,4,r.lo)._push(qr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ya,4,t)}double(t){return this._push(ja,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(vs,1,0):this.uint32(r)._push(zl,r,t)}string(t){let r=Ja(t);return r!==0?this.uint32(r)._push(bs,r,t):this._push(vs,1,0)}fork(){return this.states=new Ss(this),this.head=this.tail=new Le(Es,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 Le(Es,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Hl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function vs(e,t,r){t[r]=e&255}function ql(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Is=class extends Le{next;constructor(t,r){super(ql,t,r),this.next=void 0}};function Dn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function qr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function zl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(zr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push($l,t,e),this},zr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Gl,t,e),this});function $l(e,t,r){t.set(e,r)}function Gl(e,t,r){e.length<40?bs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(V(e),r)}function As(){return new zr}function Mt(e,t){let r=As();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var sr;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(sr||(sr={}));function Ln(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function _s(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return Ln("enum",sr.VARINT,r,n)}function Vt(e,t){return Ln("message",sr.LENGTH_DELIMITED,e,t)}var Oe=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var st;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(st||(st={}));var Cs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Cs||(Cs={}));(function(e){e.codec=()=>_s(Cs)})(st||(st={}));var $t;(function(e){let t;e.codec=()=>(t==null&&(t=Vt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=st.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Mt(r,e.codec()),e.decode=(r,n)=>kt(r,e.codec(),n)})($t||($t={}));var Bs;(function(e){let t;e.codec=()=>(t==null&&(t=Vt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=st.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Mt(r,e.codec()),e.decode=(r,n)=>kt(r,e.codec(),n)})(Bs||(Bs={}));var Gr={};St(Gr,{MAX_RSA_KEY_SIZE:()=>Ps,generateRSAKeyPair:()=>ic,jwkToJWKKeyPair:()=>ac,jwkToPkcs1:()=>jl,jwkToPkix:()=>Os,jwkToRSAPrivateKey:()=>Ks,pkcs1MessageToJwk:()=>Ds,pkcs1MessageToRSAPrivateKey:()=>Rs,pkcs1ToJwk:()=>Wl,pkcs1ToRSAPrivateKey:()=>sc,pkixMessageToJwk:()=>Ls,pkixMessageToRSAPublicKey:()=>Us,pkixToJwk:()=>Xl,pkixToRSAPublicKey:()=>Ns});var On=wn;var ir=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Gr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ct.createV1(114,this._multihash)}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,r,n){return oc(this.jwk,r,t,n)}},$r=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Gr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}sign(t,r){return nc(this.jwk,t,r)}};var Ps=8192,Ts=18,Zl=1062,Yl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Wl(e){let t=Wt(e);return Ds(t)}function Ds(e){return{n:H(e[1],"base64url"),e:H(e[2],"base64url"),d:H(e[3],"base64url"),p:H(e[4],"base64url"),q:H(e[5],"base64url"),dp:H(e[6],"base64url"),dq:H(e[7],"base64url"),qi:H(e[8],"base64url"),kty:"RSA"}}function jl(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new Q("JWK was missing components");return he([At(Uint8Array.from([0])),At(V(e.n,"base64url")),At(V(e.e,"base64url")),At(V(e.d,"base64url")),At(V(e.p,"base64url")),At(V(e.q,"base64url")),At(V(e.dp,"base64url")),At(V(e.dq,"base64url")),At(V(e.qi,"base64url"))]).subarray()}function Xl(e){let t=Wt(e,{offset:0});return Ls(t)}function Ls(e){let t=Wt(e[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function Os(e){if(e.n==null||e.e==null)throw new Q("JWK was missing components");return he([Yl,mn(he([At(V(e.n,"base64url")),At(V(e.e,"base64url"))]))]).subarray()}function sc(e){let t=Wt(e);return Rs(t)}function Rs(e){let t=Ds(e);return Ks(t)}function Ns(e,t){if(e.byteLength>=Zl)throw new He("Key size is too large");let r=Wt(e,{offset:0});return Us(r,e,t)}function Us(e,t,r){let n=Ls(e);if(r==null){let o=On($t.encode({Type:st.RSA,Data:t}));r=Ht(Ts,o)}return new ir(n,r)}function Ks(e){if(uc(e)>Ps)throw new Q("Key size is too large");let t=ac(e),r=On($t.encode({Type:st.RSA,Data:Os(t.publicKey)})),n=Ht(Ts,r);return new $r(t.privateKey,new ir(t.publicKey,n))}async function ic(e){if(e>Ps)throw new Q("Key size is too large");let t=await cc(e),r=On($t.encode({Type:st.RSA,Data:Os(t.publicKey)})),n=Ht(Ts,r);return new $r(t.privateKey,new ir(t.publicKey,n))}function ac(e){if(e==null)throw new Q("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function cc(e,t){let r=await Ot.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Ql(r,t);return{privateKey:n[0],publicKey:n[1]}}async function nc(e,t,r){let n=await Ot.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ot.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function oc(e,t,r,n){let o=await Ot.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Ot.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Ql(e,t){if(e.privateKey==null||e.publicKey==null)throw new Q("Private and public key are required");let r=await Promise.all([Ot.get().subtle.exportKey("jwk",e.privateKey),Ot.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function uc(e){if(e.kty!=="RSA")throw new Q("invalid key type");if(e.n==null)throw new Q("invalid key modulus");return V(e.n,"base64url").length*8}var Rn=class extends Ye{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,yn(t);let n=Lr(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Qt(s)}update(t){return We(this),this.iHash.update(t),this}digestInto(t){We(this),_t(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ks=(e,t,r)=>new Rn(e,t).update(r).digest();ks.create=(e,t)=>new Rn(e,t);var fc=(e,t)=>(e+(e>=0?t:-t)/lc)/t;function Jl(e,t,r){let[[n,o],[s,i]]=t,c=fc(i*e,r),a=fc(-o*e,r),u=e-c*n-a*s,l=-c*o-a*i,d=u<ce,f=l<ce;d&&(u=-u),f&&(l=-l);let h=be(Math.ceil(vn(r)/2))+cr;if(u<ce||u>=h||l<ce||l>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:d,k1:u,k2neg:f,k2:l}}function Vs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ms(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return te(r.lowS,"lowS"),te(r.prehash,"prehash"),r.format!==void 0&&Vs(r.format),r}var Fs=class extends Error{constructor(t=""){super(t)}},ae={Err:Fs,_tlv:{encode:(e,t)=>{let{Err:r}=ae;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Ur(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Ur(o.length/2|128):"";return Ur(e)+s+o+t},decode(e,t){let{Err:r}=ae,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=ae;if(e<ce)throw new t("integer: negative integers are not allowed");let r=Ur(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=ae;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Xe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=ae,o=Z("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l}=n.decode(2,a);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=ae,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},ce=BigInt(0),cr=BigInt(1),lc=BigInt(2),Nn=BigInt(3),td=BigInt(4);function ar(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=Z("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function ed(e,t={}){let r=In("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;ge(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=hc(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(P,b,m){let{x:y,y:v}=b.toAffine(),A=n.toBytes(y);if(te(m,"isCompressed"),m){l();let D=!n.isOdd(v);return wt(dc(D),A)}else return wt(Uint8Array.of(4),A,n.toBytes(v))}function f(P){Pt(P,void 0,"Point");let{publicKey:b,publicKeyUncompressed:m}=u,y=P.length,v=P[0],A=P.subarray(1);if(y===b&&(v===2||v===3)){let D=n.fromBytes(A);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let _=g(D),C;try{C=n.sqrt(_)}catch(J){let Y=J instanceof Error?": "+J.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}l();let O=n.isOdd(C);return(v&1)===1!==O&&(C=n.neg(C)),{x:D,y:C}}else if(y===m&&v===4){let D=n.BYTES,_=n.fromBytes(A.subarray(0,D)),C=n.fromBytes(A.subarray(D,D*2));if(!S(_,C))throw new Error("bad point: is not on curve");return{x:_,y:C}}else throw new Error(`bad point: got length ${y}, expected compressed=${b} or uncompressed=${m}`)}let h=t.toBytes||d,p=t.fromBytes||f;function g(P){let b=n.sqr(P),m=n.mul(b,P);return n.add(n.add(m,n.mul(P,s.a)),s.b)}function S(P,b){let m=n.sqr(b),y=g(P);return n.eql(m,y)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(s.a,Nn),td),I=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(x,I)))throw new Error("bad curve params: a or b");function E(P,b,m=!1){if(!n.isValid(b)||m&&n.is0(b))throw new Error(`bad point coordinate ${P}`);return b}function T(P){if(!(P instanceof w))throw new Error("ProjectivePoint expected")}function R(P){if(!a||!a.basises)throw new Error("no endo");return Jl(P,a.basises,o.ORDER)}let M=Qe((P,b)=>{let{X:m,Y:y,Z:v}=P;if(n.eql(v,n.ONE))return{x:m,y};let A=P.is0();b==null&&(b=A?n.ONE:n.inv(v));let D=n.mul(m,b),_=n.mul(y,b),C=n.mul(v,b);if(A)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:D,y:_}}),k=Qe(P=>{if(P.is0()){if(t.allowInfinityPoint&&!n.is0(P.Y))return;throw new Error("bad point: ZERO")}let{x:b,y:m}=P.toAffine();if(!n.isValid(b)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!S(b,m))throw new Error("bad point: equation left != right");if(!P.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function N(P,b,m,y,v){return m=new w(n.mul(m.X,P),m.Y,m.Z),b=Mr(y,b),m=Mr(v,m),b.add(m)}class w{constructor(b,m,y){this.X=E("x",b),this.Y=E("y",m,!0),this.Z=E("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){let{x:m,y}=b||{};if(!b||!n.isValid(m)||!n.isValid(y))throw new Error("invalid affine point");if(b instanceof w)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(y)?w.ZERO:new w(m,y,n.ONE)}static fromBytes(b){let m=w.fromAffine(p(Pt(b,void 0,"point")));return m.assertValidity(),m}static fromHex(b){return w.fromBytes(Z("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,m=!0){return U.createCache(this,b),m||this.multiply(Nn),this}assertValidity(){k(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){T(b);let{X:m,Y:y,Z:v}=this,{X:A,Y:D,Z:_}=b,C=n.eql(n.mul(m,_),n.mul(A,v)),O=n.eql(n.mul(y,_),n.mul(D,v));return C&&O}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:m}=s,y=n.mul(m,Nn),{X:v,Y:A,Z:D}=this,_=n.ZERO,C=n.ZERO,O=n.ZERO,K=n.mul(v,v),J=n.mul(A,A),Y=n.mul(D,D),z=n.mul(v,A);return z=n.add(z,z),O=n.mul(v,D),O=n.add(O,O),_=n.mul(b,O),C=n.mul(y,Y),C=n.add(_,C),_=n.sub(J,C),C=n.add(J,C),C=n.mul(_,C),_=n.mul(z,_),O=n.mul(y,O),Y=n.mul(b,Y),z=n.sub(K,Y),z=n.mul(b,z),z=n.add(z,O),O=n.add(K,K),K=n.add(O,K),K=n.add(K,Y),K=n.mul(K,z),C=n.add(C,K),Y=n.mul(A,D),Y=n.add(Y,Y),K=n.mul(Y,z),_=n.sub(_,K),O=n.mul(Y,J),O=n.add(O,O),O=n.add(O,O),new w(_,C,O)}add(b){T(b);let{X:m,Y:y,Z:v}=this,{X:A,Y:D,Z:_}=b,C=n.ZERO,O=n.ZERO,K=n.ZERO,J=s.a,Y=n.mul(s.b,Nn),z=n.mul(m,A),tt=n.mul(y,D),at=n.mul(v,_),vt=n.add(m,y),et=n.add(A,D);vt=n.mul(vt,et),et=n.add(z,tt),vt=n.sub(vt,et),et=n.add(m,v);let yt=n.add(A,_);return et=n.mul(et,yt),yt=n.add(z,at),et=n.sub(et,yt),yt=n.add(y,v),C=n.add(D,_),yt=n.mul(yt,C),C=n.add(tt,at),yt=n.sub(yt,C),K=n.mul(J,et),C=n.mul(Y,at),K=n.add(C,K),C=n.sub(tt,K),K=n.add(tt,K),O=n.mul(C,K),tt=n.add(z,z),tt=n.add(tt,z),at=n.mul(J,at),et=n.mul(Y,et),tt=n.add(tt,at),at=n.sub(z,at),at=n.mul(J,at),et=n.add(et,at),z=n.mul(tt,et),O=n.add(O,z),z=n.mul(yt,et),C=n.mul(vt,C),C=n.sub(C,z),z=n.mul(vt,tt),K=n.mul(yt,K),K=n.add(K,z),new w(C,O,K)}subtract(b){return this.add(b.negate())}is0(){return this.equals(w.ZERO)}multiply(b){let{endo:m}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let y,v,A=D=>U.cached(this,D,_=>ne(w,_));if(m){let{k1neg:D,k1:_,k2neg:C,k2:O}=R(b),{p:K,f:J}=A(_),{p:Y,f:z}=A(O);v=J.add(z),y=N(m.beta,K,Y,D,C)}else{let{p:D,f:_}=A(b);y=D,v=_}return ne(w,[y,v])[0]}multiplyUnsafe(b){let{endo:m}=t,y=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===ce||y.is0())return w.ZERO;if(b===cr)return y;if(U.hasCache(this))return this.multiply(b);if(m){let{k1neg:v,k1:A,k2neg:D,k2:_}=R(b),{p1:C,p2:O}=Va(w,y,A,_);return N(m.beta,C,O,v,D)}else return U.unsafe(y,b)}multiplyAndAddUnsafe(b,m,y){let v=this.multiplyUnsafe(m).add(b.multiplyUnsafe(y));return v.is0()?void 0:v}toAffine(b){return M(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return i===cr?!0:b?b(w,this):U.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:b}=t;return i===cr?this:b?b(w,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return te(b,"isCompressed"),this.assertValidity(),h(w,this,b)}toHex(b=!0){return Lt(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(b=!0){return this.toBytes(b)}_setWindowSize(b){this.precompute(b)}static normalizeZ(b){return ne(w,b)}static msm(b,m){return er(w,o,b,m)}static fromPrivateKey(b){return w.BASE.multiply(ar(o,b))}}w.BASE=new w(s.Gx,s.Gy,n.ONE),w.ZERO=new w(n.ZERO,n.ONE,n.ZERO),w.Fp=n,w.Fn=o;let B=o.BITS,U=new tr(w,t.endo?Math.ceil(B/2):B);return w.BASE.precompute(8),w}function dc(e){return Uint8Array.of(e?2:3)}function hc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function rd(e,t={}){let{Fn:r}=e,n=t.randomBytes||je,o=Object.assign(hc(e.Fp,r),{seed:jo(r.ORDER)});function s(h){try{return!!ar(r,h)}catch{return!1}}function i(h,p){let{publicKey:g,publicKeyUncompressed:S}=o;try{let x=h.length;return p===!0&&x!==g||p===!1&&x!==S?!1:!!e.fromBytes(h)}catch{return!1}}function c(h=n(o.seed)){return Xo(Pt(h,o.seed,"seed"),r.ORDER)}function a(h,p=!0){return e.BASE.multiply(ar(r,h)).toBytes(p)}function u(h){let p=c(h);return{secretKey:p,publicKey:a(p)}}function l(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;let{secretKey:p,publicKey:g,publicKeyUncompressed:S}=o;if(r.allowedLengths||p===g)return;let x=Z("key",h).length;return x===g||x===S}function d(h,p,g=!0){if(l(h)===!0)throw new Error("first arg must be private key");if(l(p)===!1)throw new Error("second arg must be public key");let S=ar(r,h);return e.fromHex(p).multiply(S).toBytes(g)}return Object.freeze({getPublicKey:a,getSharedSecret:d,keygen:u,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:h=>ar(r,h),precompute(h=8,p=e.BASE){return p.precompute(h,!1)}},lengths:o})}function nd(e,t,r={}){yn(t),ge(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||je,o=r.hmac||((m,...y)=>ks(t,m,wt(...y))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:l,getSharedSecret:d,utils:f,lengths:h}=rd(e,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},g="compact";function S(m){let y=c>>cr;return m>y}function x(m,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function I(m,y){Vs(y);let v=h.signature,A=y==="compact"?v:y==="recovered"?v+1:void 0;return Pt(m,A,`${y} signature`)}class E{constructor(y,v,A){this.r=x("r",y),this.s=x("s",v),A!=null&&(this.recovery=A),Object.freeze(this)}static fromBytes(y,v=g){I(y,v);let A;if(v==="der"){let{r:O,s:K}=ae.toSig(Pt(y));return new E(O,K)}v==="recovered"&&(A=y[0],v="compact",y=y.subarray(1));let D=i.BYTES,_=y.subarray(0,D),C=y.subarray(D,D*2);return new E(i.fromBytes(_),i.fromBytes(C),A)}static fromHex(y,v){return this.fromBytes(_e(y),v)}addRecoveryBit(y){return new E(this.r,this.s,y)}recoverPublicKey(y){let v=s.ORDER,{r:A,s:D,recovery:_}=this;if(_==null||![0,1,2,3].includes(_))throw new Error("recovery id invalid");if(c*lc<v&&_>1)throw new Error("recovery id is ambiguous for h>1 curve");let O=_===2||_===3?A+c:A;if(!s.isValid(O))throw new Error("recovery id 2 or 3 invalid");let K=s.toBytes(O),J=e.fromBytes(wt(dc((_&1)===0),K)),Y=i.inv(O),z=R(Z("msgHash",y)),tt=i.create(-z*Y),at=i.create(D*Y),vt=e.BASE.multiplyUnsafe(tt).add(J.multiplyUnsafe(at));if(vt.is0())throw new Error("point at infinify");return vt.assertValidity(),vt}hasHighS(){return S(this.s)}toBytes(y=g){if(Vs(y),y==="der")return _e(ae.hexFromSig(this));let v=i.toBytes(this.r),A=i.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return wt(Uint8Array.of(this.recovery),v,A)}return wt(v,A)}toHex(y){return Lt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return E.fromBytes(Z("sig",y),"compact")}static fromDER(y){return E.fromBytes(Z("sig",y),"der")}normalizeS(){return this.hasHighS()?new E(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Lt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Lt(this.toBytes("compact"))}}let T=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let v=Xe(y),A=y.length*8-a;return A>0?v>>BigInt(A):v},R=r.bits2int_modN||function(y){return i.create(T(y))},M=be(a);function k(m){return Kr("num < 2^"+a,m,ce,M),i.toBytes(m)}function N(m,y){return Pt(m,void 0,"message"),y?Pt(t(m),void 0,"prehashed message"):m}function w(m,y,v){if(["recovered","canonical"].some(tt=>tt in v))throw new Error("sign() legacy options not supported");let{lowS:A,prehash:D,extraEntropy:_}=Ms(v,p);m=N(m,D);let C=R(m),O=ar(i,y),K=[k(O),k(C)];if(_!=null&&_!==!1){let tt=_===!0?n(h.secretKey):_;K.push(Z("extraEntropy",tt))}let J=wt(...K),Y=C;function z(tt){let at=T(tt);if(!i.isValidNot0(at))return;let vt=i.inv(at),et=e.BASE.multiply(at).toAffine(),yt=i.create(et.x);if(yt===ce)return;let an=i.create(vt*i.create(Y+yt*O));if(an===ce)return;let Ti=(et.x===yt?0:2)|Number(et.y&cr),Di=an;return A&&S(an)&&(Di=i.neg(an),Ti^=1),new E(yt,Di,Ti)}return{seed:J,k2sig:z}}function B(m,y,v={}){m=Z("message",m);let{seed:A,k2sig:D}=w(m,y,v);return Ia(t.outputLen,i.BYTES,o)(A,D)}function U(m){let y,v=typeof m=="string"||Xt(m),A=!v&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!v&&!A)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(A)y=new E(m.r,m.s);else if(v){try{y=E.fromBytes(Z("sig",m),"der")}catch(D){if(!(D instanceof ae.Err))throw D}if(!y)try{y=E.fromBytes(Z("sig",m),"compact")}catch{return!1}}return y||!1}function P(m,y,v,A={}){let{lowS:D,prehash:_,format:C}=Ms(A,p);if(v=Z("publicKey",v),y=N(Z("message",y),_),"strict"in A)throw new Error("options.strict was renamed to lowS");let O=C===void 0?U(m):E.fromBytes(Z("sig",m),C);if(O===!1)return!1;try{let K=e.fromBytes(v);if(D&&O.hasHighS())return!1;let{r:J,s:Y}=O,z=R(y),tt=i.inv(Y),at=i.create(z*tt),vt=i.create(J*tt),et=e.BASE.multiplyUnsafe(at).add(K.multiplyUnsafe(vt));return et.is0()?!1:i.create(et.x)===J}catch{return!1}}function b(m,y,v={}){let{prehash:A}=Ms(v,p);return y=N(y,A),E.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:d,utils:f,lengths:h,Point:e,sign:B,verify:P,recoverPublicKey:b,Signature:E,hash:t})}function od(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=Tt(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function sd(e){let{CURVE:t,curveOpts:r}=od(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function id(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Sn(r.Fn.ORDER,r.Fn.BITS))})}function pc(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=sd(e),s=ed(t,r),i=nd(s,n,o);return id(e,i)}function mc(e,t){let r=n=>pc({...e,hash:n});return{...r(t),create:r}}var qs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ad={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var yc=BigInt(2);function cd(e){let t=qs.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,l=u*u*e%t,d=X(l,r,t)*l%t,f=X(d,r,t)*l%t,h=X(f,yc,t)*u%t,p=X(h,o,t)*h%t,g=X(p,s,t)*p%t,S=X(g,c,t)*g%t,x=X(S,a,t)*S%t,I=X(x,c,t)*g%t,E=X(I,r,t)*l%t,T=X(E,i,t)*p%t,R=X(T,n,t)*u%t,M=X(R,yc,t);if(!Hs.eql(Hs.sqr(M),e))throw new Error("Cannot find square root");return M}var Hs=Tt(qs.p,{sqrt:cd}),ur=mc({...qs,Fp:Hs,lowS:!0,endo:ad},wn);function bc(e,t,r,n){let o=Cr.digest(r instanceof Uint8Array?r:r.subarray());if(Bn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ur.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new Fr(String(s))});try{return n?.signal?.throwIfAborted(),ur.verify(t,o.digest,e)}catch(s){throw new Fr(String(s))}}var Un=class{type="secp256k1";raw;_key;constructor(t){this._key=xc(t),this.raw=gc(this._key)}toMultihash(){return Nt.digest(qt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,r,n){return bc(this._key,r,t,n)}};function zs(e){return new Un(e)}function gc(e){return ur.ProjectivePoint.fromHex(e).toRawBytes(!0)}function xc(e){try{return ur.ProjectivePoint.fromHex(e),e}catch(t){throw new He(String(t))}}function fr(e,t){let{Type:r,Data:n}=$t.decode(e),o=n??new Uint8Array;switch(r){case st.RSA:return Ns(o,t);case st.Ed25519:return cs(o);case st.secp256k1:return zs(o);case st.ECDSA:return Uo(o);default:throw new Se}}function wc(e){let{Type:t,Data:r}=$t.decode(e.digest),n=r??new Uint8Array;switch(t){case st.Ed25519:return cs(n);case st.secp256k1:return zs(n);case st.ECDSA:return Uo(n);default:throw new Se}}function qt(e){return $t.encode({Type:st[e.type],Data:e.raw})}var Zr;(function(e){let t;e.codec=()=>(t==null&&(t=Vt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.publicKey!=null&&r.publicKey.byteLength>0&&(n.uint32(10),n.bytes(r.publicKey)),r.payloadType!=null&&r.payloadType.byteLength>0&&(n.uint32(18),n.bytes(r.payloadType)),r.payload!=null&&r.payload.byteLength>0&&(n.uint32(26),n.bytes(r.payload)),r.signature!=null&&r.signature.byteLength>0&&(n.uint32(42),n.bytes(r.signature)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={publicKey:ht(0),payloadType:ht(0),payload:ht(0),signature:ht(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.publicKey=r.bytes();break}case 2:{s.payloadType=r.bytes();break}case 3:{s.payload=r.bytes();break}case 5:{s.signature=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Mt(r,e.codec()),e.decode=(r,n)=>kt(r,e.codec(),n)})(Zr||(Zr={}));var Kn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Gt=class e{static createFromProtobuf=t=>{let r=Zr.decode(t),n=fr(r.publicKey);return new e({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(t,r,n)=>{if(r==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),c=Ec(o,s,i),a=await r.sign(c.subarray(),n);return new e({publicKey:r.publicKey,payloadType:s,payload:i,signature:a})};static openAndCertify=async(t,r,n)=>{let o=e.createFromProtobuf(t);if(!await o.validate(r,n))throw new Kn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:r,payloadType:n,payload:o,signature:s}=t;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Zr.encode({publicKey:qt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:ut(this.marshal(),t.marshal())}async validate(t,r){let n=Ec(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Ec=(e,t,r)=>{let n=V(e),o=or(n.byteLength),s=or(t.length),i=or(r.length);return new it(o,n,s,t,i,r)};var vc=Symbol.for("nodejs.util.inspect.custom"),ud=114,Yr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[ao]=!0;toString(){return this.string==null&&(this.string=ot.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ct.createV1(ud,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ut(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ut(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[vc](){return`PeerId(${this.toString()})`}},Wr=class extends Yr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},jr=class extends Yr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Xr=class extends Yr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},fd=2336,Qr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Nt.digest(V(this.url))}[vc](){return`PeerId(${this.url})`}[ao]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(fd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};var ld=114,Sc=2336;function Ic(e){if(e.type==="Ed25519")return new jr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Xr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Wr({multihash:e.toCID().multihash,publicKey:e});throw new Se}function $s(e){if(hd(e))return new Wr({multihash:e});if(dd(e))try{let t=wc(e);if(t.type==="Ed25519")return new jr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Xr({multihash:e,publicKey:t})}catch{let r=H(e.digest);return new Qr(new URL(r))}throw new fn("Supplied PeerID Multihash is invalid")}function kn(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==ld&&e.code!==Sc)throw new un("Supplied PeerID CID is invalid");if(e.code===Sc){let t=H(e.multihash.digest);return new Qr(new URL(t))}return $s(e.multihash)}function dd(e){return e.code===Nt.code}function hd(e){return e.code===Cr.code}var mt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ue=class extends Error{static name="ValidationError";name="ValidationError"},Mn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Vn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Fn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let f=Number.parseInt(d,t);if(!Number.isNaN(f))return f});if(l===void 0)break;if(s*=t,s+=l,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&a&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[c]=t(s.subarray(0,i));return r.set(s.subarray(0,c),16-c),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ac=45,pd=15,lr=new Fn;function Hn(e){if(!(e.length>pd))return lr.new(e).parseWith(()=>lr.readIPv4Addr())}function qn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Ac))return lr.new(e).parseWith(()=>lr.readIPv6Addr())}function dr(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>Ac)return;let r=lr.new(e).parseWith(()=>lr.readIPAddr());if(r)return t&&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 hr(e){return!!Hn(e)}function zn(e){return!!qn(e)}function Zs(e){return t=>H(t,e)}function Ys(e){return t=>V(t,e)}function pr(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Re(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function _c(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=V(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Re(n);return Yt([r,o],r.length+o.length)}function Cc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=de.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Re(n);return Yt([r,o],r.length+o.length)}function Ws(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=H(t,"base32"),o=pr(r);return`${n}:${o}`}var js=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new mt("Invalid byte value in IP address");t[n]=o}),t},Bc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=hr(r[n]),i;s&&(i=js(r[n]),r[n]=H(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,H(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new mt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Pc=function(e){if(e.byteLength!==4)throw new mt("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Tc=function(e){if(e.byteLength!==16)throw new mt("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new mt(`Invalid IPv6 address "${r}"`)}};function Dc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new mt(`Invalid IPv6 address "${e}"`)}}var Gs=Object.values(Br).map(e=>e.decoder),md=(function(){let e=Gs[0].or(Gs[1]);return Gs.slice(2).forEach(t=>e=e.or(t)),e})();function Lc(e){return md.decode(e)}function Oc(e){return t=>e.encoder.encode(t)}function yd(e){if(parseInt(e).toString()!==e)throw new ue("Value must be an integer")}function bd(e){if(e<0)throw new ue("Value must be a positive integer, or zero")}function gd(e){return t=>{if(t>e)throw new ue(`Value must be smaller than or equal to ${e}`)}}function xd(...e){return t=>{for(let r of e)r(t)}}var Jr=xd(yd,bd,gd(65535));var dt=-1,Xs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Vn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},fe=new Xs,Rd=[{code:4,name:"ip4",size:32,valueToBytes:js,bytesToValue:Pc,validate:e=>{if(!hr(e))throw new ue(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Re,bytesToValue:pr,validate:Jr},{code:273,name:"udp",size:16,valueToBytes:Re,bytesToValue:pr,validate:Jr},{code:33,name:"dccp",size:16,valueToBytes:Re,bytesToValue:pr,validate:Jr},{code:41,name:"ip6",size:128,valueToBytes:Bc,bytesToValue:Tc,stringToValue:Dc,validate:e=>{if(!zn(e))throw new ue(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:dt},{code:43,name:"ipcidr",size:8,bytesToValue:Zs("base10"),valueToBytes:Ys("base10")},{code:53,name:"dns",size:dt},{code:54,name:"dns4",size:dt},{code:55,name:"dns6",size:dt},{code:56,name:"dnsaddr",size:dt},{code:132,name:"sctp",size:16,valueToBytes:Re,bytesToValue:pr,validate:Jr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:dt,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:dt,bytesToValue:Zs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Ys("base58btc")(e):ct.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ws,valueToBytes:_c},{code:445,name:"onion3",size:296,bytesToValue:Ws,valueToBytes:Cc},{code:446,name:"garlic64",size:dt},{code:447,name:"garlic32",size:dt},{code:448,name:"tls"},{code:449,name:"sni",size:dt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:dt,bytesToValue:Oc(So),valueToBytes:Lc},{code:480,name:"http"},{code:481,name:"http-path",size:dt,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:dt}];Rd.forEach(e=>{fe.addProtocol(e)});function Rc(e){let t=[],r=0;for(;r<e.length;){let n=Hr(e,r),o=fe.getProtocol(n),s=Ct(n),i=Nd(o,e,r+s),c=0;i>0&&o.size===dt&&(c=Ct(i));let a=s+c+i,u={code:n,name:o.name,bytes:e.subarray(r,r+a)};if(i>0){let l=r+s+c,d=e.subarray(l,l+i);u.value=o.bytesToValue?.(d)??H(d)}t.push(u),r+=a}return t}function Nc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=fe.getProtocol(n.code),s=Ct(n.code),i,c=0,a=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),c=i.byteLength,o.size===dt&&(a=Ct(c)));let u=new Uint8Array(s+a+c),l=0;nr(n.code,u,l),l+=s,i!=null&&(o.size===dt&&(nr(c,u,l),l+=a),u.set(i,l)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Yt(r,t)}function Uc(e){if(e.charAt(0)!=="/")throw new mt('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let c=s===e.length-1;if(i==="/"||c){let a=fe.getProtocol(o);if(r==="protocol"){if(a.size==null||a.size===0){t.push({code:a.code,name:a.name}),n="",o="",r="protocol";continue}else if(c)throw new mt(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new mt(`Component ${o} was missing value`);u.value=a.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new mt("Incomplete multiaddr");return t}function Kc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=fe.getProtocol(t.code);if(r==null)throw new mt(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Nd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Hr(t,r)}var Ud=Symbol.for("nodejs.util.inspect.custom"),di=Symbol.for("@multiformats/multiaddr");function Kd(e){if(e==null&&(e="/"),kc(e))return e.getComponents();if(e instanceof Uint8Array)return Rc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Uc(e);if(Array.isArray(e))return e;throw new mt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Wn=class e{[di]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Kd(t),r.validate!==!1&&kd(this)}get bytes(){return this.#r==null&&(this.#r=Nc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Kc(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Mn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return ut(this.bytes,t.bytes)}[Ud](){return`Multiaddr(${this.toString()})`}};function kd(e){e.getComponents().forEach(t=>{let r=fe.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function kc(e){return!!e?.[di]}function Ke(e){return new Wn(e)}var Mc="libp2p-peer-record",Vc=Uint8Array.from([3,1]);var en;(function(e){let t;(function(n){let o;n.codec=()=>(o==null&&(o=Vt((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={multiaddr:ht(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{a.multiaddr=s.bytes();break}default:{s.skipType(l&7);break}}}return a})),o),n.encode=s=>Mt(s,n.codec()),n.decode=(s,i)=>kt(s,n.codec(),i)})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=Vt((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(o.uint32(10),o.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(o.uint32(16),o.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)o.uint32(26),e.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId:ht(0),seq:0n,addresses:[]},c=o==null?n.len:n.pos+o;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new Oe('Decode error - map field "addresses" had too many elements');i.addresses.push(e.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(a&7);break}}}return i})),r),e.encode=n=>Mt(n,e.codec()),e.decode=(n,o)=>kt(n,e.codec(),o)})(en||(en={}));function Fc(e,t){let r=(n,o)=>n.toString().localeCompare(o.toString());return e.length!==t.length?!1:(t.sort(r),e.sort(r).every((n,o)=>t[o].equals(n)))}var Ft=class e{static createFromProtobuf=t=>{let r=en.decode(t),n=$s(Ar(r.peerId)),o=(r.addresses??[]).map(i=>Ke(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Mc;static CODEC=Vc;peerId;multiaddrs;seqNumber;domain=e.DOMAIN;codec=e.CODEC;marshaled;constructor(t){let{peerId:r,multiaddrs:n,seqNumber:o}=t;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=en.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof e)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!Fc(this.multiaddrs,t.multiaddrs))}};function jn(e){let t=e.getComponents(),r={},n=0;if(t[n]?.name==="ip6zone"&&(r.zone=`${t[n].value}`,n++),t[n].name==="ip4"||t[n].name==="ip6"||t[n].name==="dns"||t[n].name==="dns4"||t[n].name==="dns6"?(r.type=t[n].name,r.host=t[n].value,n++):t[n].name==="dnsaddr"&&(r.type=t[n].name,r.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(r.protocol=t[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${t[n].value}`):r.type==="ip6"&&(r.cidr=`${t[n].value}`),n++),r.type==null||r.host==null)throw new Q(`Multiaddr ${e} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(r.sni=t[n+1].value,n+=2),r}function Hc(e,t,r){let n=0;for(let o of e)if(!(n<t)){if(n>r)break;if(o!==255)return!1;n++}return!0}function qc(e,t,r,n){let o=0;for(let s of e)if(!(o<r)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function hi(e){switch(e.length){case ke:return e.join(".");case Me:{let t=[];for(let r=0;r<e.length;r++)r%2===0&&t.push(e[r].toString(16).padStart(2,"0")+e[r+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function zc(e){let t=0;for(let[r,n]of e.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<e.length;o++)if(e[o]!=0)return-1;break}return t}function $c(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var ke=4,Me=16,ax=parseInt("0xFFFF",16),Md=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function rn(e,t){t.length===Me&&e.length===ke&&Hc(t,0,11)&&(t=t.slice(12)),t.length===ke&&e.length===Me&&qc(e,Md,0,11)&&(e=e.slice(12));let r=e.length;if(r!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=e[o]&t[o];return n}function Gc(e,t){if(typeof t=="string"&&(t=dr(t)),t==null)throw new Error("Invalid ip");if(t.length!==e.network.length)return!1;for(let r=0;r<t.length;r++)if((e.network[r]&e.mask[r])!==(t[r]&e.mask[r]))return!1;return!0}function pi(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=ke,o=Hn(t);if(o==null&&(n=Me,o=qn(t),o==null))throw new Error("Failed to parse given CIDR: "+e);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: "+e);let i=mi(s,8*n);return{network:rn(o,i),mask:i}}function mi(e,t){if(t!==8*ke&&t!==8*Me)throw new Error("Invalid CIDR mask");if(e<0||e>t)throw new Error("Invalid CIDR mask");let r=t/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(e>=8){n[o]=255,e-=8;continue}n[o]=255-(255>>e),e=0}return n}var nn=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=pi(t));else{let n=dr(t);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=dr(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=mi(o,8*n.length);this.network=rn(n,this.mask)}}contains(t){return Gc({network:this.network,mask:this.mask},t)}toString(){let t=zc(this.mask),r=t!==-1?String(t):$c(this.mask);return hi(this.network)+"/"+r}};function Zc(e,t){return new nn(e).contains(t)}function Yc(e){try{let t=jn(e);switch(t.type){case"ip6":return Zc("2000::/3",t.host);default:return!1}}catch{return!1}}var jc=Au(Wc(),1),Vd=["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"],Fd=Vd.map(e=>new jc.Netmask(e));function yi(e){for(let t of Fd)if(t.contains(e))return!0;return!1}function Hd(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function qd(e){let t=e.split(":");if(t.length<2)return!1;let r=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return yi(o)}function zd(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function $d(e){let t=e.split(":"),r=t[t.length-1];return yi(r)}function Gd(e){return/^::$/.test(e)||/^::1$/.test(e)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(e)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(e)||/^ff([0-9a-fA-F]{2,2}):/i.test(e)}function Xc(e){if(hr(e))return yi(e);if(Hd(e))return qd(e);if(zd(e))return $d(e);if(zn(e))return Gd(e)}function Qc(e){try{let t=jn(e);switch(t.type){case"ip4":case"ip6":return Xc(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function xr(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var bi=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},gi=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Jc=e=>globalThis.DOMException===void 0?new gi(e):new DOMException(e),tu=e=>{let t=e.reason===void 0?Jc("This operation was aborted."):e.reason;return t instanceof Error?t:Jc(t)};function xi(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,u=new Promise((l,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:h}=t;h.aborted&&d(tu(h)),c=()=>{d(tu(h))},h.addEventListener("abort",c,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(l,d);return}let f=new bi;i=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(h){d(h)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?d(o):(f.message=o??`Promise timed out after ${r} milliseconds`,d(f))},r),(async()=>{try{l(await e)}catch(h){d(h)}})()}).finally(()=>{u.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return u.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},u}var Zd=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function Yd(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let c=[t].flat(),a=[],{addListener:u,removeListener:l}=Zd(e),d=(...h)=>{let p=r.multiArgs?h:h[0];r.filter&&!r.filter(p)||(a.push(p),r.count===a.length&&(n(),s(a)))},f=h=>{n(),i(h)};n=()=>{for(let h of c)l(h,d);for(let h of r.rejectionEvents)l(h,f)};for(let h of c)u(h,d);for(let h of r.rejectionEvents)u(h,f);r.signal&&r.signal.addEventListener("abort",()=>{f(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(a)});if(o.cancel=n,typeof r.timeout=="number"){let s=xi(o,{milliseconds:r.timeout});return s.cancel=n,s}return o}function eu(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Yd(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function ru(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Ve=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Wd(e){return e.reason}async function nu(e,t,r){if(t==null)return e;let n=r?.translateError??Wd;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var Xd=4194304,Xn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ei=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},vi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Si=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Qd(e){return typeof e?.closeRead=="function"}function Jd(e){return typeof e?.close=="function"}function wi(e){return Qd(e)?e.readStatus==="closing"||e.readStatus==="closed":Jd(e)?e.status!=="open":!1}function th(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function eh(e,t){let r=t?.maxBufferSize??Xd,n=new it,o=Promise.withResolvers(),s=!1;if(!th(e))throw new Q("Argument should be a Stream or a Multiaddr");let i=l=>{if(n.append(l.data),n.byteLength>r){let d=n.byteLength;n.consume(n.byteLength),o.reject(new Error(`Read buffer overflow - ${d} > ${r}`))}o.resolve()};e.addEventListener("message",i);let c=l=>{l.error!=null?o.reject(l.error):o.resolve()};e.addEventListener("close",c);let a=()=>{o.resolve()};e.addEventListener("remoteCloseWrite",a);let u={readBuffer:n,async read(l){if(s===!0)throw new Xn("Stream was unwrapped");if(wi(e)){if(l?.bytes==null)return null;if(n.byteLength<l.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new Ve(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let d=l?.bytes??1;for(;;){if(n.byteLength>=d){o.resolve();break}if(await nu(o.promise,l?.signal),wi(e)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let f=l?.bytes??n.byteLength;if(n.byteLength<f){if(wi(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,f),new Ve(`Unexpected EOF - stream closed while reading ${n.byteLength}/${f} bytes`);return u.read(l)}let h=n.sublist(0,f);return n.consume(f),h},async write(l,d){if(s===!0)throw new Xn("Stream was unwrapped");e.send(l)||await eu(e,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",a),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return u}function rh(e,t={}){let r=eh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Ct(t.maxDataLength));let n=t?.lengthDecoder??Hr,o=t?.lengthEncoder??or;return{async read(i){let c=-1,a=new it;for(;;){let l=await r.read({...i,bytes:1});if(l==null)break;a.append(l);try{c=n(a)}catch(d){if(d instanceof RangeError)continue;throw d}if(c<0)throw new Ei("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new Si(`Message length length too long - ${a.byteLength} > ${t.maxLengthLength}`);if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new vi(`Message length too long - ${c} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:c});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",c),new Ve(`Unexpected EOF - tried to read ${c} bytes but the stream closed`);if(u.byteLength!==c)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,c),new Ve(`Unexpected EOF - read ${u.byteLength}/${c} bytes before the stream closed`);return u},async write(i,c){await r.write(new it(o(i.byteLength),i),c)},async writeV(i,c){let a=new it(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(a,c)},unwrap(){return r.unwrap()}}}function wr(e,t){let r=rh(e,t),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(c=>s.encode(c)),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 nh(e){return e[Symbol.asyncIterator]!=null}function oh(e){if(nh(e))return(async()=>{for await(let t of e);})();for(let t of e);}var ou=oh;var Qn=globalThis.CustomEvent??Event;async function*Ii(e,t={}){let r=t.concurrency??1/0;r<1&&(r=1/0);let n=t.ordered??!1,o=new EventTarget,s=[],i=xr(),c=xr(),a=!1,u,l=!1;o.addEventListener("task-complete",()=>{c.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of e){if(s.length===r&&(i=xr(),await i.promise),l)break;let g={done:!1};s.push(g),p().then(S=>{g.done=!0,g.ok=!0,g.value=S,o.dispatchEvent(new Qn("task-complete"))},S=>{g.done=!0,g.err=S,o.dispatchEvent(new Qn("task-complete"))})}a=!0,o.dispatchEvent(new Qn("task-complete"))}catch(p){u=p,o.dispatchEvent(new Qn("task-complete"))}});function d(){return n?s[0]?.done:!!s.find(p=>p.done)}function*f(){for(;s.length>0&&s[0].done;){let p=s[0];if(s.shift(),p.ok)yield p.value;else throw l=!0,i.resolve(),p.err;i.resolve()}}function*h(){for(;d();)for(let p=0;p<s.length;p++)if(s[p].done){let g=s[p];if(s.splice(p,1),p--,g.ok)yield g.value;else throw l=!0,i.resolve(),g.err;i.resolve()}}for(;;){if(d()||(c=xr(),await c.promise),u!=null||(n?yield*f():yield*h(),u!=null))throw u;if(a&&s.length===0)break}}var su="0.1.0";var iu="id/push",au="1.0.0",cu="1.0.0";var ve;(function(e){let t;e.codec=()=>(t==null&&(t=Vt((r,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),r.protocolVersion!=null&&(n.uint32(42),n.string(r.protocolVersion)),r.agentVersion!=null&&(n.uint32(50),n.string(r.agentVersion)),r.publicKey!=null&&(n.uint32(10),n.bytes(r.publicKey)),r.listenAddrs!=null)for(let s of r.listenAddrs)n.uint32(18),n.bytes(s);if(r.observedAddr!=null&&(n.uint32(34),n.bytes(r.observedAddr)),r.protocols!=null)for(let s of r.protocols)n.uint32(26),n.string(s);r.signedPeerRecord!=null&&(n.uint32(66),n.bytes(r.signedPeerRecord)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={listenAddrs:[],protocols:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 5:{s.protocolVersion=r.string();break}case 6:{s.agentVersion=r.string();break}case 1:{s.publicKey=r.bytes();break}case 2:{if(o.limits?.listenAddrs!=null&&s.listenAddrs.length===o.limits.listenAddrs)throw new Oe('Decode error - map field "listenAddrs" had too many elements');s.listenAddrs.push(r.bytes());break}case 4:{s.observedAddr=r.bytes();break}case 3:{if(o.limits?.protocols!=null&&s.protocols.length===o.limits.protocols)throw new Oe('Decode error - map field "protocols" had too many elements');s.protocols.push(r.string());break}case 8:{s.signedPeerRecord=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Mt(r,e.codec()),e.decode=(r,n)=>kt(r,e.codec(),n)})(ve||(ve={}));var Bt={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function uu(e){if(e!=null&&e.length>0)try{return Ke(e)}catch{}}function ah(e,t){return t??e.userAgent}async function Jn(e,t,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new Rt("message was null or undefined");let s={};if(o.listenAddrs.length>0&&(s.addresses=o.listenAddrs.map(a=>({isCertified:!1,multiaddr:Ke(a)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let a=fr(o.publicKey);if(!Ic(a).equals(n.remotePeer))throw new Rt("public key did not match remote PeerId");s.publicKey=a}let i;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let a=o.signedPeerRecord,u=await Gt.openAndCertify(a,Ft.DOMAIN),l=Ft.createFromProtobuf(u.payload),d=kn(u.publicKey.toCID());if(!l.peerId.equals(d))throw new Rt("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(l.peerId))throw new Rt("signing key does not match remote PeerId");let f;try{f=await e.get(l.peerId)}catch(h){if(h.name!=="NotFoundError")throw h}if(f!=null&&(s.metadata=f.metadata,f.peerRecordEnvelope!=null)){let h=Gt.createFromProtobuf(f.peerRecordEnvelope),p=Ft.createFromProtobuf(h.payload);p.seqNumber>=l.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",p.seqNumber,l.seqNumber),l=p,a=f.peerRecordEnvelope)}s.peerRecordEnvelope=a,s.addresses=l.multiaddrs.map(h=>({isCertified:!0,multiaddr:h})),i={seq:l.seqNumber,addresses:l.multiaddrs}}else r("%p did not send a signed peer record",n.remotePeer);if(r.trace("patching %p with",n.remotePeer,s),await e.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let a={};o.agentVersion!=null&&(a.AgentVersion=V(o.agentVersion)),o.protocolVersion!=null&&(a.ProtocolVersion=V(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,a),await e.merge(n.remotePeer,{metadata:a})}let c={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:o.listenAddrs.map(a=>Ke(a)),observedAddr:o.observedAddr==null?void 0:Ke(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:c}),c}var Er=class{host;components;protocol;started;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;runOnLimitedConnection;log;constructor(t,r){this.protocol=r.protocol,this.started=!1,this.components=t,this.log=r.log,this.timeout=r.timeout??Bt.timeout,this.maxInboundStreams=r.maxInboundStreams??Bt.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Bt.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Bt.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Bt.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Bt.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Bt.protocolPrefix}/${su}`,agentVersion:ah(t.nodeInfo,r.agentVersion)},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 to=class extends Er{connectionManager;concurrency;_push;constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??Bt.protocolPrefix}/${iu}/${cu}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=r.concurrency??Bt.concurrency,this._push=ru(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Bt.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[ln]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let t=this.components.addressManager.getAddresses().map(l=>l.decapsulateCode(421)),r=new Ft({peerId:this.components.peerId,multiaddrs:t}),n=await Gt.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=H(s.metadata.get("AgentVersion")??V(this.host.agentVersion)),c=H(s.metadata.get("ProtocolVersion")??V(this.host.protocolVersion)),a=this;async function*u(){for(let l of a.connectionManager.getConnections())(await a.components.peerStore.get(l.remotePeer)).protocols.includes(a.protocol)&&(yield async()=>{let f,h=AbortSignal.timeout(a.timeout);try{f=await l.newStream(a.protocol,{signal:h,runOnLimitedConnection:a.runOnLimitedConnection}),await wr(f,{maxDataLength:a.maxMessageSize}).pb(ve).write({listenAddrs:t.map(g=>g.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:c},{signal:h}),await f.close({signal:h})}catch(p){f?.log.newScope("identify-push")?.error("could not push identify update to peer",p),f?.abort(p)}})}await ou(Ii(u(),{concurrency:this.concurrency}))}catch(t){this.log.error("error pushing updates to peers - %e",t)}}async handleProtocol(t,r){let n=t.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)},i=await wr(t,{maxDataLength:this.maxMessageSize}).pb(ve).read(o);await t.close(o),await Jn(this.components.peerStore,this.components.events,n,r,i),n.trace("handled push from %p",r.remotePeer)}};var W=e=>({match:t=>{let r=t[0];return r==null||r.code!==e||r.value!=null?!1:t.slice(1)}}),L=(e,t)=>({match:r=>{let n=r[0];return n?.code!==e||n.value==null||t!=null&&n.value!==t?!1:r.slice(1)}}),fu=e=>({match:t=>e.match(t)===!1?t:!1}),F=e=>({match:t=>{let r=e.match(t);return r===!1?t:r}}),xt=(...e)=>({match:t=>{let r;for(let n of e){let o=n.match(t);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),G=(...e)=>({match:t=>{for(let r of e){let n=r.match(t);if(n===!1)return!1;t=n}return t}});function j(...e){function t(o){if(o==null)return!1;let s=o.getComponents();for(let i of e){let c=i.match(s);if(c===!1)return!1;s=c}return s}function r(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:e,matches:r,exactMatch:n}}var uh=L(421),Hw=j(uh),ro=L(54),no=L(55),oo=L(56),_i=L(53),qw=j(ro,F(L(421))),zw=j(no,F(L(421))),$w=j(oo,F(L(421))),Gw=j(xt(_i,oo,ro,no),F(L(421))),lu=G(L(4),F(L(43))),du=G(F(L(42)),L(41),F(L(43))),Ci=xt(lu,du),Fe=xt(Ci,_i,ro,no,oo),hu=j(xt(Ci,G(xt(_i,oo,ro,no),F(L(421))))),Zw=j(lu),Yw=j(du),Ww=j(Ci),Bi=G(Fe,L(6)),sn=G(Fe,L(273)),pu=j(G(Bi,F(L(421)))),jw=j(sn),Pi=G(sn,W(460),F(L(421))),so=G(sn,W(461),F(L(421))),fh=xt(Pi,so),Xw=j(Pi),Qw=j(so),Ai=xt(Fe,Bi,sn,Pi,so),mu=xt(G(Ai,W(477),F(L(421)))),Jw=j(mu),yu=xt(G(Ai,W(478),F(L(421))),G(Ai,W(448),F(L(449)),W(477),F(L(421)))),t2=j(yu),bu=G(sn,W(280),F(L(466)),F(L(466)),F(L(421))),e2=j(bu),gu=G(so,W(465),F(L(466)),F(L(466)),F(L(421))),r2=j(gu),eo=xt(mu,yu,G(Bi,F(L(421))),G(fh,F(L(421))),G(Fe,F(L(421))),bu,gu,L(421)),n2=j(eo),lh=G(F(eo),W(290),fu(W(281)),F(L(421))),o2=j(lh),dh=xt(G(eo,W(290),W(281),F(L(421))),G(eo,W(281),F(L(421))),G(W(281),F(L(421)))),s2=j(dh),hh=xt(G(Fe,L(6),W(480),F(L(421))),G(Fe,W(480),F(L(421)))),i2=j(hh),ph=G(Fe,xt(G(L(6,"443"),W(480)),G(L(6),W(443)),G(L(6),W(448),W(480)),G(W(448),W(480)),W(448),W(443)),F(L(421))),a2=j(ph),mh=xt(G(L(777),F(L(421)))),c2=j(mh),yh=xt(G(L(400),F(L(421)))),u2=j(yh);var io=class extends Er{constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??Bt.protocolPrefix}/${"id"}/${au}`,log:t.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Bt.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[ln]=["@libp2p/identify"];async _identify(t,r={}){let n,o;if(r.signal==null){let s=AbortSignal.timeout(this.timeout);r={...r,signal:s}}try{n=await t.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),o=n.log.newScope("identify");let s=wr(n,{maxDataLength:this.maxMessageSize}).pb(ve);o("read response");let i=await s.read(r);return o("close write"),await s.unwrap().unwrap().close(r),i}catch(s){throw o?.error("identify failed - %e",s),n?.abort(s),s}}async identify(t,r={}){let n=await this._identify(t,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Rt("Public key was missing from identify message");let c=fr(o),a=kn(c.toCID());if(!t.remotePeer.equals(a))throw new Rt("Identified peer does not match the expected peer");if(this.components.peerId.equals(a))throw new Rt("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",a,s),Jn(this.components.peerStore,this.components.events,this.log,t,n)}maybeAddObservedAddress(t){let r=uu(t);if(r==null||(this.log.trace("our observed address was %a",r),Qc(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Yc(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}pu.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(t,r){let n=t.log.newScope("identify"),o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(l=>l.decapsulateCode(421)),c=s.peerRecordEnvelope;if(i.length>0&&c==null){let l=new Ft({peerId:this.components.peerId,multiaddrs:i});c=(await Gt.seal(l,this.components.privateKey,{signal:o})).marshal().subarray()}let a=r.remoteAddr.bytes;hu.matches(r.remoteAddr)||(a=void 0);let u=wr(t).pb(ve);n("send response"),await u.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:qt(this.components.privateKey.publicKey),listenAddrs:i.map(l=>l.bytes),signedPeerRecord:c,observedAddr:a,protocols:s.protocols},{signal:o}),n("close write"),await u.unwrap().unwrap().close({signal:o})}};function gh(e={}){return t=>new io(t,e)}function xh(e={}){return t=>new to(t,e)}return _u(wh);})();
2
+ "use strict";var Libp2PIdentify=(()=>{var xu=Object.create;var cn=Object.defineProperty;var wu=Object.getOwnPropertyDescriptor;var Eu=Object.getOwnPropertyNames;var vu=Object.getPrototypeOf,Su=Object.prototype.hasOwnProperty;var Iu=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),St=(e,t)=>{for(var r in t)cn(e,r,{get:t[r],enumerable:!0})},Li=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Eu(t))!Su.call(e,o)&&o!==r&&cn(e,o,{get:()=>t[o],enumerable:!(n=wu(t,o))||n.enumerable});return e};var Au=(e,t,r)=>(r=e!=null?xu(vu(e)):{},Li(t||!e||!e.__esModule?cn(r,"default",{value:e,enumerable:!0}):r,e)),_u=e=>Li(cn({},"__esModule",{value:!0}),e);var Wc=Iu(on=>{(function(){var e,t,r,n,o,s,i,c;c=function(a){var u,l,d,f;return u=(a&255<<24)>>>24,l=(a&255<<16)>>>16,d=(a&65280)>>>8,f=a&255,[u,l,d,f].join(".")},i=function(a){var u,l,d,f,h,p;for(u=[],d=f=0;f<=3&&a.length!==0;d=++f){if(d>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}p=t(a),h=p[0],l=p[1],a=a.substring(l),u.push(h)}if(a.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},r=function(a){return a.charCodeAt(0)},n=r("0"),s=r("a"),o=r("A"),t=function(a){var u,l,d,f,h;for(f=0,u=10,l="9",d=0,a.length>1&&a[d]==="0"&&(a[d+1]==="x"||a[d+1]==="X"?(d+=2,u=16):"0"<=a[d+1]&&a[d+1]<="9"&&(d++,u=8,l="7")),h=d;d<a.length;){if("0"<=a[d]&&a[d]<=l)f=f*u+(r(a[d])-n)>>>0;else if(u===16)if("a"<=a[d]&&a[d]<="f")f=f*u+(10+r(a[d])-s)>>>0;else if("A"<=a[d]&&a[d]<="F")f=f*u+(10+r(a[d])-o)>>>0;else break;else break;if(f>4294967295)throw new Error("too large");d++}if(d===h)throw new Error("empty octet");return[f,d]},e=(function(){function a(u,l){var d,f,h,p;if(typeof u!="string")throw new Error("Missing `net' parameter");if(l||(p=u.split("/",2),u=p[0],l=p[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(g){throw d=g,new Error("Invalid mask: "+l)}for(f=h=32;h>=0;f=--h)if(this.maskLong===4294967295<<32-f>>>0){this.bitmask=f;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(u)&this.maskLong)>>>0}catch(g){throw d=g,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new a(u)),u instanceof a?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(u){return u==null&&(u=1),new a(c(this.netLong+this.size*u),this.mask)},a.prototype.forEach=function(u){var l,d,f;for(f=i(this.first),d=i(this.last),l=0;f<=d;)u(c(f),f,l),l++,f++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a})(),on.ip2long=i,on.long2ip=c,on.Netmask=e}).call(on)});var xh={};St(xh,{identify:()=>bh,identifyPush:()=>gh});var Q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},He=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var un=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},fn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Rt=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Se=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ao=Symbol.for("@libp2p/peer-id");var ln=Symbol.for("@libp2p/service-capabilities"),Sh=Symbol.for("@libp2p/service-dependencies");var ho={};St(ho,{base58btc:()=>ot,base58flickr:()=>Ou});var Wh=new Uint8Array(0);function Oi(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Zt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Ri(e){return new TextEncoder().encode(e)}function Ni(e){return new TextDecoder().decode(e)}function Cu(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),u=Math.log(c)/Math.log(256),l=Math.log(256)/Math.log(c);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,S=0,x=0,I=p.length;x!==I&&p[x]===0;)x++,g++;for(var E=(I-x)*l+1>>>0,T=new Uint8Array(E);x!==I;){for(var R=p[x],M=0,k=E-1;(R!==0||M<S)&&k!==-1;k--,M++)R+=256*T[k]>>>0,T[k]=R%c>>>0,R=R/c>>>0;if(R!==0)throw new Error("Non-zero carry");S=M,x++}for(var N=E-S;N!==E&&T[N]===0;)N++;for(var w=a.repeat(g);N<E;++N)w+=e.charAt(T[N]);return w}function f(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var S=0,x=0;p[g]===a;)S++,g++;for(var I=(p.length-g)*u+1>>>0,E=new Uint8Array(I);p[g];){var T=r[p.charCodeAt(g)];if(T===255)return;for(var R=0,M=I-1;(T!==0||R<x)&&M!==-1;M--,R++)T+=c*E[M]>>>0,E[M]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");x=R,g++}if(p[g]!==" "){for(var k=I-x;k!==I&&E[k]===0;)k++;for(var N=new Uint8Array(S+(I-k)),w=S;k!==I;)N[w++]=E[k++];return N}}}function h(p){var g=f(p);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:d,decodeUnsafe:f,decode:h}}var Bu=Cu,Pu=Bu,Ki=Pu;var co=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},uo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ki(this,t)}},fo=class{decoders;constructor(t){this.decoders=t}or(t){return ki(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ki(e,t){return new fo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var lo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new co(t,r,n),this.decoder=new uo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function qe({name:e,prefix:t,encode:r,decode:n}){return new lo(e,t,r,n)}function le({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ki(r,e);return qe({prefix:t,name:e,encode:n,decode:s=>Zt(o(s))})}function Tu(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let l=t[e[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|l,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Du(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Lu(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function rt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Lu(n);return qe({prefix:t,name:e,encode(s){return Du(s,n,r)},decode(s){return Tu(s,o,r,e)}})}var ot=le({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ou=le({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var po={};St(po,{base32:()=>de,base32hex:()=>Ku,base32hexpad:()=>Mu,base32hexpadupper:()=>Vu,base32hexupper:()=>ku,base32pad:()=>Nu,base32padupper:()=>Uu,base32upper:()=>Ru,base32z:()=>Fu});var de=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ru=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Nu=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Uu=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ku=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ku=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Mu=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Vu=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Fu=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var mo={};St(mo,{base36:()=>vr,base36upper:()=>Hu});var vr=le({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Hu=le({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var qu=Fi,Mi=128,zu=127,$u=~zu,Gu=Math.pow(2,31);function Fi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Gu;)t[r++]=e&255|Mi,e/=128;for(;e&$u;)t[r++]=e&255|Mi,e>>>=7;return t[r]=e|0,Fi.bytes=r-n+1,t}var Zu=yo,Yu=128,Vi=127;function yo(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw yo.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Vi)<<o:(i&Vi)*Math.pow(2,o),o+=7}while(i>=Yu);return yo.bytes=s-n,r}var Wu=Math.pow(2,7),ju=Math.pow(2,14),Xu=Math.pow(2,21),Qu=Math.pow(2,28),Ju=Math.pow(2,35),tf=Math.pow(2,42),ef=Math.pow(2,49),rf=Math.pow(2,56),nf=Math.pow(2,63),of=function(e){return e<Wu?1:e<ju?2:e<Xu?3:e<Qu?4:e<Ju?5:e<tf?6:e<ef?7:e<rf?8:e<nf?9:10},sf={encode:qu,decode:Zu,encodingLength:of},af=sf,Sr=af;function Ir(e,t=0){return[Sr.decode(e,t),Sr.decode.bytes]}function ze(e,t,r=0){return Sr.encode(e,t,r),t}function $e(e){return Sr.encodingLength(e)}function Ht(e,t){let r=t.byteLength,n=$e(e),o=n+$e(r),s=new Uint8Array(o+r);return ze(e,s,0),ze(r,s,n),s.set(t,o),new Ge(e,r,t,s)}function Ar(e){let t=Zt(e),[r,n]=Ir(t),[o,s]=Ir(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ge(r,o,i,t)}function Hi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Oi(e.bytes,r.bytes)}}var Ge=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function qi(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return uf(r,bo(e),t??ot.encoder);default:return ff(r,bo(e),t??de.encoder)}}var zi=new WeakMap;function bo(e){let t=zi.get(e);if(t==null){let r=new Map;return zi.set(e,r),r}return t}var ct=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==_r)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==lf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Ht(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Hi(t.multihash,n.multihash)}toString(t){return qi(this,t)}toJSON(){return{"/":qi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??$i(n,o,s.bytes))}else if(r[df]===!0){let{version:n,multihash:o,code:s}=r,i=Ar(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==_r)throw new Error(`Version 0 CID must use dag-pb (code: ${_r}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=$i(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,_r,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Zt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Ge(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[d,f]=Ir(t.subarray(r));return r+=f,d},o=n(),s=_r;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),u=r+a,l=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:l,size:u}}static parse(t,r){let[n,o]=cf(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return bo(s).set(n,t),s}};function cf(e,t){switch(e[0]){case"Q":{let r=t??ot;return[ot.prefix,r.decode(`${ot.prefix}${e}`)]}case ot.prefix:{let r=t??ot;return[ot.prefix,r.decode(e)]}case de.prefix:{let r=t??de;return[de.prefix,r.decode(e)]}case vr.prefix:{let r=t??vr;return[vr.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function uf(e,t,r){let{prefix:n}=r;if(n!==ot.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function ff(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var _r=112,lf=18;function $i(e,t,r){let n=$e(e),o=n+$e(t),s=new Uint8Array(o+r.byteLength);return ze(e,s,0),ze(t,s,n),s.set(r,o),s}var df=Symbol.for("@ipld/js-cid/CID");var go={};St(go,{identity:()=>Nt});var Gi=0,hf="identity",Zi=Zt;function pf(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Ht(Gi,Zi(e))}var Nt={code:Gi,name:hf,encode:Zi,digest:pf};function ut(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ht(e=0){return new Uint8Array(e)}function It(e=0){return new Uint8Array(e)}function Yt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=It(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Wi=Symbol.for("@achingbrain/uint8arraylist");function Yi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function hn(e){return!!e?.[Wi]}var it=class e{bufs;length;[Wi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(hn(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(hn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Yi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Yi(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(hn(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Yt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Yt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,l=r>c&&r<=a;if(u&&l){if(t===c&&r===a){n.push(i);break}let d=t-c;n.push(i.subarray(d,d+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(l){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!hn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let d=r;d<=a;d+=l){l=0;for(let f=u;f>=0;f--){let h=this.get(d+f);if(n[f]!==h){l=Math.max(1,f-c[h]);break}}if(l===0)return d}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=It(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=It(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ut(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var xo={};St(xo,{base10:()=>mf});var mf=le({prefix:"9",name:"base10",alphabet:"0123456789"});var wo={};St(wo,{base16:()=>yf,base16upper:()=>bf});var yf=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),bf=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Eo={};St(Eo,{base2:()=>gf});var gf=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var vo={};St(vo,{base256emoji:()=>Sf});var ji=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}"),xf=ji.reduce((e,t,r)=>(e[r]=t,e),[]),wf=ji.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Ef(e){return e.reduce((t,r)=>(t+=xf[r],t),"")}function vf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=wf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Sf=qe({prefix:"\u{1F680}",name:"base256emoji",encode:Ef,decode:vf});var Io={};St(Io,{base64:()=>If,base64pad:()=>Af,base64url:()=>So,base64urlpad:()=>_f});var If=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Af=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),So=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),_f=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ao={};St(Ao,{base8:()=>Cf});var Cf=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var _o={};St(_o,{identity:()=>Bf});var Bf=qe({prefix:"\0",name:"identity",encode:e=>Ni(e),decode:e=>Ri(e)});var Lp=new TextEncoder,Op=new TextDecoder;var Po={};St(Po,{sha256:()=>Cr,sha512:()=>Lf});var Df=20;function Bo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Co(e,t,r,n,o)}var Co=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Df,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Xi(n,this.code,r?.truncate):n.then(o=>Xi(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Xi(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Ht(t,e)}function Ji(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Cr=Bo({name:"sha2-256",code:18,encode:Ji("SHA-256")}),Lf=Bo({name:"sha2-512",code:19,encode:Ji("SHA-512")});var Br={..._o,...Eo,...Ao,...xo,...wo,...po,...mo,...ho,...Io,...vo},$p={...Po,...go};function ea(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ta=ea("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),To=ea("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=It(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Of={utf8:ta,"utf-8":ta,hex:Br.base16,latin1:To,ascii:To,binary:To,...Br},pn=Of;function V(e,t="utf8"){let r=pn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function H(e,t="utf8"){let r=pn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Rf=parseInt("11111",2),Do=parseInt("10000000",2),Nf=parseInt("01111111",2),ra={0:Pr,1:Pr,2:Uf,3:Mf,4:Vf,5:kf,6:Kf,16:Pr,22:Pr,48:Pr};function Wt(e,t={offset:0}){let r=e[t.offset]&Rf;if(t.offset++,ra[r]!=null)return ra[r](e,t);throw new Error("No decoder for tag "+r)}function Tr(e,t){let r=0;if((e[t.offset]&Do)===Do){let n=e[t.offset]&Nf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Pr(e,t){Tr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Wt(e,t);if(n===null)break;r.push(n)}return r}function Uf(e,t){let r=Tr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Kf(e,t){let r=Tr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let l=0;for(let d=0;d<a.length;d++)l+=a[d]<<d*7;c+=`.${l}`,a=[]}}return c}function kf(e,t){return t.offset++,null}function Mf(e,t){let r=Tr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Vf(e,t){let r=Tr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Ff(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new it;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Lo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Ff(e.byteLength);return new it(Uint8Array.from([t.byteLength|Do]),t)}function At(e){let t=new it,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new it(Uint8Array.from([2]),Lo(t),t)}function mn(e){let t=Uint8Array.from([0]),r=new it(t,e);return new it(Uint8Array.from([3]),Lo(r),r)}function he(e,t=48){let r=new it;for(let n of e)r.append(n);return new it(Uint8Array.from([t]),Lo(r),r)}async function na(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var Hf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),qf=Uint8Array.from([6,5,43,129,4,0,34]),zf=Uint8Array.from([6,5,43,129,4,0,35]),$f={ext:!0,kty:"EC",crv:"P-256"},Gf={ext:!0,kty:"EC",crv:"P-384"},Zf={ext:!0,kty:"EC",crv:"P-521"},Oo=32,Ro=48,No=66;function Uo(e){let t=Wt(e);return oa(t)}function oa(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Oo*2+1)return n=H(t.subarray(r,r+Oo),"base64url"),o=H(t.subarray(r+Oo),"base64url"),new Ze({...$f,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ro*2+1)return n=H(t.subarray(r,r+Ro),"base64url"),o=H(t.subarray(r+Ro),"base64url"),new Ze({...Gf,key_ops:["verify"],x:n,y:o});if(t.byteLength===No*2+1)return n=H(t.subarray(r,r+No),"base64url"),o=H(t.subarray(r+No),"base64url"),new Ze({...Zf,key_ops:["verify"],x:n,y:o});throw new Q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function sa(e){return he([At(Uint8Array.from([1])),he([Yf(e.crv)],160),he([mn(new it(Uint8Array.from([4]),V(e.x??"","base64url"),V(e.y??"","base64url")))],161)]).subarray()}function Yf(e){if(e==="P-256")return Hf;if(e==="P-384")return qf;if(e==="P-521")return zf;throw new Q(`Invalid curve ${e}`)}var Ze=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=sa(this.jwk)),this._raw}toMultihash(){return Nt.digest(qt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}async verify(t,r,n){return na(this.jwk,r,t,n)}};var Ae=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Xt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Dr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function _t(e,...t){if(!Xt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function yn(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Dr(e.outputLen),Dr(e.blockLen)}function We(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function aa(e,t){_t(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Qt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function bn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ut(e,t){return e<<32-t|e>>>t}var ca=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Wf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Lt(e){if(_t(e),ca)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Wf[e[r]];return t}var jt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ia(e){if(e>=jt._0&&e<=jt._9)return e-jt._0;if(e>=jt.A&&e<=jt.F)return e-(jt.A-10);if(e>=jt.a&&e<=jt.f)return e-(jt.a-10)}function _e(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ca)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=ia(e.charCodeAt(s)),c=ia(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Ko(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Lr(e){return typeof e=="string"&&(e=Ko(e)),_t(e),e}function wt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];_t(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var Ye=class{};function ko(e){let t=n=>e().update(Lr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function je(e=32){if(Ae&&typeof Ae.getRandomValues=="function")return Ae.getRandomValues(new Uint8Array(e));if(Ae&&typeof Ae.randomBytes=="function")return Uint8Array.from(Ae.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function jf(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,u=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+u,c,n)}function ua(e,t,r){return e&t^~e&r}function fa(e,t,r){return e&t^e&r^t&r}var Or=class extends Ye{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=bn(this.buffer)}update(t){We(this),t=Lr(t),_t(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=bn(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){We(this),aa(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Qt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let d=i;d<o;d++)r[d]=0;jf(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=bn(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<u;d++)c.setUint32(4*d,l[d],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Jt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var pt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var gn=BigInt(4294967295),la=BigInt(32);function Xf(e,t=!1){return t?{h:Number(e&gn),l:Number(e>>la&gn)}:{h:Number(e>>la&gn)|0,l:Number(e&gn)|0}}function da(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=Xf(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Mo=(e,t,r)=>e>>>r,Vo=(e,t,r)=>e<<32-r|t>>>r,Ce=(e,t,r)=>e>>>r|t<<32-r,Be=(e,t,r)=>e<<32-r|t>>>r,Rr=(e,t,r)=>e<<64-r|t>>>r-32,Nr=(e,t,r)=>e>>>r-32|t<<64-r;function zt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ha=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),pa=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ma=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ya=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ba=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ga=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Jf=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]),pe=new Uint32Array(64),xn=class extends Or{constructor(t=32){super(64,t,8,!1),this.A=Jt[0]|0,this.B=Jt[1]|0,this.C=Jt[2]|0,this.D=Jt[3]|0,this.E=Jt[4]|0,this.F=Jt[5]|0,this.G=Jt[6]|0,this.H=Jt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let d=0;d<16;d++,r+=4)pe[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let f=pe[d-15],h=pe[d-2],p=Ut(f,7)^Ut(f,18)^f>>>3,g=Ut(h,17)^Ut(h,19)^h>>>10;pe[d]=g+pe[d-7]+p+pe[d-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:l}=this;for(let d=0;d<64;d++){let f=Ut(c,6)^Ut(c,11)^Ut(c,25),h=l+f+ua(c,a,u)+Jf[d]+pe[d]|0,g=(Ut(n,2)^Ut(n,13)^Ut(n,22))+fa(n,o,s)|0;l=u,u=a,a=c,c=i+h|0,i=s,s=o,o=n,n=h+g|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,c,a,u,l)}roundClean(){Qt(pe)}destroy(){this.set(0,0,0,0,0,0,0,0),Qt(this.buffer)}};var xa=da(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),tl=xa[0],el=xa[1],me=new Uint32Array(80),ye=new Uint32Array(80),Fo=class extends Or{constructor(t=64){super(128,t,16,!1),this.Ah=pt[0]|0,this.Al=pt[1]|0,this.Bh=pt[2]|0,this.Bl=pt[3]|0,this.Ch=pt[4]|0,this.Cl=pt[5]|0,this.Dh=pt[6]|0,this.Dl=pt[7]|0,this.Eh=pt[8]|0,this.El=pt[9]|0,this.Fh=pt[10]|0,this.Fl=pt[11]|0,this.Gh=pt[12]|0,this.Gl=pt[13]|0,this.Hh=pt[14]|0,this.Hl=pt[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:l,Fh:d,Fl:f,Gh:h,Gl:p,Hh:g,Hl:S}=this;return[t,r,n,o,s,i,c,a,u,l,d,f,h,p,g,S]}set(t,r,n,o,s,i,c,a,u,l,d,f,h,p,g,S){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=l|0,this.Fh=d|0,this.Fl=f|0,this.Gh=h|0,this.Gl=p|0,this.Hh=g|0,this.Hl=S|0}process(t,r){for(let E=0;E<16;E++,r+=4)me[E]=t.getUint32(r),ye[E]=t.getUint32(r+=4);for(let E=16;E<80;E++){let T=me[E-15]|0,R=ye[E-15]|0,M=Ce(T,R,1)^Ce(T,R,8)^Mo(T,R,7),k=Be(T,R,1)^Be(T,R,8)^Vo(T,R,7),N=me[E-2]|0,w=ye[E-2]|0,B=Ce(N,w,19)^Rr(N,w,61)^Mo(N,w,6),U=Be(N,w,19)^Nr(N,w,61)^Vo(N,w,6),P=ma(k,U,ye[E-7],ye[E-16]),b=ya(P,M,B,me[E-7],me[E-16]);me[E]=b|0,ye[E]=P|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:l,Eh:d,El:f,Fh:h,Fl:p,Gh:g,Gl:S,Hh:x,Hl:I}=this;for(let E=0;E<80;E++){let T=Ce(d,f,14)^Ce(d,f,18)^Rr(d,f,41),R=Be(d,f,14)^Be(d,f,18)^Nr(d,f,41),M=d&h^~d&g,k=f&p^~f&S,N=ba(I,R,k,el[E],ye[E]),w=ga(N,x,T,M,tl[E],me[E]),B=N|0,U=Ce(n,o,28)^Rr(n,o,34)^Rr(n,o,39),P=Be(n,o,28)^Nr(n,o,34)^Nr(n,o,39),b=n&s^n&c^s&c,m=o&i^o&a^i&a;x=g|0,I=S|0,g=h|0,S=p|0,h=d|0,p=f|0,{h:d,l:f}=zt(u|0,l|0,w|0,B|0),u=c|0,l=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let y=ha(B,P,m);n=pa(y,w,U,b),o=y|0}({h:n,l:o}=zt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=zt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=zt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l}=zt(this.Dh|0,this.Dl|0,u|0,l|0),{h:d,l:f}=zt(this.Eh|0,this.El|0,d|0,f|0),{h,l:p}=zt(this.Fh|0,this.Fl|0,h|0,p|0),{h:g,l:S}=zt(this.Gh|0,this.Gl|0,g|0,S|0),{h:x,l:I}=zt(this.Hh|0,this.Hl|0,x|0,I|0),this.set(n,o,s,i,c,a,u,l,d,f,h,p,g,S,x,I)}roundClean(){Qt(me,ye)}destroy(){Qt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var wn=ko(()=>new xn);var wa=ko(()=>new Fo);var zo=BigInt(0),qo=BigInt(1);function te(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Pt(e,t,r=""){let n=Xt(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function Ur(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Ea(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?zo:BigInt("0x"+e)}function Xe(e){return Ea(Lt(e))}function ee(e){return _t(e),Ea(Lt(Uint8Array.from(e).reverse()))}function En(e,t){return _e(e.toString(16).padStart(t*2,"0"))}function $o(e,t){return En(e,t).reverse()}function Z(e,t,r){let n;if(typeof t=="string")try{n=_e(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Xt(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function va(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function Go(e){return Uint8Array.from(e)}var Ho=e=>typeof e=="bigint"&&zo<=e;function Sa(e,t,r){return Ho(e)&&Ho(t)&&Ho(r)&&t<=e&&e<r}function Kr(e,t,r,n){if(!Sa(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function vn(e){let t;for(t=0;e>zo;e>>=qo,t+=1);return t}var be=e=>(qo<<BigInt(e))-qo;function Ia(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},u=(...h)=>r(i,s,...h),l=(h=n(0))=>{i=u(o(0),h),s=u(),h.length!==0&&(i=u(o(1),h),s=u())},d=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,p=[];for(;h<t;){s=u();let g=s.slice();p.push(g),h+=s.length}return wt(...p)};return(h,p)=>{a(),l(h);let g;for(;!(g=p(d()));)l();return a(),g}}function ge(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var Zo=()=>{throw new Error("not implemented")};function Qe(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var Et=BigInt(0),ft=BigInt(1),Pe=BigInt(2),Ca=BigInt(3),Ba=BigInt(4),Pa=BigInt(5),rl=BigInt(7),Ta=BigInt(8),nl=BigInt(9),Da=BigInt(16);function nt(e,t){let r=e%t;return r>=Et?r:t+r}function X(e,t,r){let n=e;for(;t-- >Et;)n*=n,n%=r;return n}function Aa(e,t){if(e===Et)throw new Error("invert: expected non-zero number");if(t<=Et)throw new Error("invert: expected positive modulus, got "+t);let r=nt(e,t),n=t,o=Et,s=ft,i=ft,c=Et;for(;r!==Et;){let u=n/r,l=n%r,d=o-i*u,f=s-c*u;n=r,r=l,o=i,s=c,i=d,c=f}if(n!==ft)throw new Error("invert: does not exist");return nt(o,t)}function Yo(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function La(e,t){let r=(e.ORDER+ft)/Ba,n=e.pow(t,r);return Yo(e,n,t),n}function ol(e,t){let r=(e.ORDER-Pa)/Ta,n=e.mul(t,Pe),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Pe),o),c=e.mul(s,e.sub(i,e.ONE));return Yo(e,c,t),c}function sl(e){let t=Tt(e),r=Oa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+rl)/Da;return(c,a)=>{let u=c.pow(a,i),l=c.mul(u,n),d=c.mul(u,o),f=c.mul(u,s),h=c.eql(c.sqr(l),a),p=c.eql(c.sqr(d),a);u=c.cmov(u,l,h),l=c.cmov(f,d,p);let g=c.eql(c.sqr(l),a),S=c.cmov(u,l,g);return Yo(c,S,a),S}}function Oa(e){if(e<Ca)throw new Error("sqrt is not defined for small field");let t=e-ft,r=0;for(;t%Pe===Et;)t/=Pe,r++;let n=Pe,o=Tt(e);for(;_a(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return La;let s=o.pow(n,t),i=(t+ft)/Pe;return function(a,u){if(a.is0(u))return u;if(_a(a,u)!==1)throw new Error("Cannot find square root");let l=r,d=a.mul(a.ONE,s),f=a.pow(u,t),h=a.pow(u,i);for(;!a.eql(f,a.ONE);){if(a.is0(f))return a.ZERO;let p=1,g=a.sqr(f);for(;!a.eql(g,a.ONE);)if(p++,g=a.sqr(g),p===l)throw new Error("Cannot find square root");let S=ft<<BigInt(l-p-1),x=a.pow(d,S);l=p,d=a.sqr(x),f=a.mul(f,d),h=a.mul(h,x)}return h}}function il(e){return e%Ba===Ca?La:e%Ta===Pa?ol:e%Da===nl?sl(e):Oa(e)}var re=(e,t)=>(nt(e,t)&ft)===ft,al=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wo(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=al.reduce((n,o)=>(n[o]="function",n),t);return ge(e,r),e}function cl(e,t,r){if(r<Et)throw new Error("invalid exponent, negatives unsupported");if(r===Et)return e.ONE;if(r===ft)return t;let n=e.ONE,o=t;for(;r>Et;)r&ft&&(n=e.mul(n,o)),o=e.sqr(o),r>>=ft;return n}function kr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function _a(e,t){let r=(e.ORDER-ft)/Pe,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Sn(e,t){t!==void 0&&Dr(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Tt(e,t,r=!1,n={}){if(e<=Et)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE),typeof f.modFromBytes=="boolean"&&(i=f.modFromBytes),c=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:u}=Sn(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l,d=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:u,MASK:be(a),ZERO:Et,ONE:ft,allowedLengths:c,create:f=>nt(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return Et<=f&&f<e},is0:f=>f===Et,isValidNot0:f=>!d.is0(f)&&d.isValid(f),isOdd:f=>(f&ft)===ft,neg:f=>nt(-f,e),eql:(f,h)=>f===h,sqr:f=>nt(f*f,e),add:(f,h)=>nt(f+h,e),sub:(f,h)=>nt(f-h,e),mul:(f,h)=>nt(f*h,e),pow:(f,h)=>cl(d,f,h),div:(f,h)=>nt(f*Aa(h,e),e),sqrN:f=>f*f,addN:(f,h)=>f+h,subN:(f,h)=>f-h,mulN:(f,h)=>f*h,inv:f=>Aa(f,e),sqrt:s||(f=>(l||(l=il(e)),l(d,f))),toBytes:f=>r?$o(f,u):En(f,u),fromBytes:(f,h=!0)=>{if(c){if(!c.includes(f.length)||f.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+f.length);let g=new Uint8Array(u);g.set(f,r?0:g.length-f.length),f=g}if(f.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+f.length);let p=r?ee(f):Xe(f);if(i&&(p=nt(p,e)),!h&&!d.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:f=>kr(d,f),cmov:(f,h,p)=>p?h:f});return Object.freeze(d)}function Ra(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function jo(e){let t=Ra(e);return t+Math.ceil(t/2)}function Xo(e,t,r=!1){let n=e.length,o=Ra(t),s=jo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?ee(e):Xe(e),c=nt(i,t-ft)+ft;return r?$o(c,o):En(c,o)}var Je=BigInt(0),Te=BigInt(1);function Mr(e,t){let r=t.negate();return e?r:t}function ne(e,t){let r=kr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function ka(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Qo(e,t){ka(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=be(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Na(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=Te);let u=t*n,l=u+Math.abs(c)-1,d=c===0,f=c<0,h=t%2!==0;return{nextN:a,offset:l,isZero:d,isNeg:f,isNegF:h,offsetF:u}}function ul(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function fl(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Jo=new WeakMap,Ma=new WeakMap;function ts(e){return Ma.get(e)||1}function Ua(e){if(e!==Je)throw new Error("invalid wNAF")}var tr=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Je;)r&Te&&(n=n.add(o)),o=o.double(),r>>=Te;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Qo(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Qo(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:l,isNeg:d,isNegF:f,offsetF:h}=Na(n,c,i);n=a,l?s=s.add(Mr(f,r[h])):o=o.add(Mr(d,r[u]))}return Ua(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Qo(t,this.bits);for(let i=0;i<s.windows&&n!==Je;i++){let{nextN:c,offset:a,isZero:u,isNeg:l}=Na(n,i,s);if(n=c,!u){let d=r[a];o=o.add(l?d.negate():d)}}return Ua(n),o}getPrecomputes(t,r,n){let o=Jo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Jo.set(r,o))),o}cached(t,r,n){let o=ts(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=ts(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){ka(r,this.bits),Ma.set(t,r),Jo.delete(t)}hasCache(t){return ts(t)!==1}};function Va(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Je||n>Je;)r&Te&&(s=s.add(o)),n&Te&&(i=i.add(o)),o=o.double(),r>>=Te,n>>=Te;return{p1:s,p2:i}}function er(e,t,r,n){ul(r,e),fl(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=vn(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=be(a),l=new Array(Number(u)+1).fill(i),d=Math.floor((t.BITS-1)/a)*a,f=i;for(let h=d;h>=0;h-=a){l.fill(i);for(let g=0;g<s;g++){let S=n[g],x=Number(S>>BigInt(h)&u);l[x]=l[x].add(r[g])}let p=i;for(let g=l.length-1,S=i;g>0;g--)S=S.add(l[g]),p=p.add(S);if(f=f.add(p),h!==0)for(let g=0;g<a;g++)f=f.double()}return f}function Ka(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Wo(t),t}else return Tt(e,{isLE:r})}function In(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>Je))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Ka(t.p,r.Fp,n),s=Ka(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var xe=BigInt(0),lt=BigInt(1),es=BigInt(2),ll=BigInt(8);function dl(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function hl(e,t={}){let r=In("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;ge(t,{},{uvRatio:"function"});let c=es<<BigInt(o.BYTES*8)-lt,a=S=>n.create(S),u=t.uvRatio||((S,x)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,x))}}catch{return{isValid:!1,value:xe}}});if(!dl(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(S,x,I=!1){let E=I?lt:xe;return Kr("coordinate "+S,x,E,c),x}function d(S){if(!(S instanceof p))throw new Error("ExtendedPoint expected")}let f=Qe((S,x)=>{let{X:I,Y:E,Z:T}=S,R=S.is0();x==null&&(x=R?ll:n.inv(T));let M=a(I*x),k=a(E*x),N=n.mul(T,x);if(R)return{x:xe,y:lt};if(N!==lt)throw new Error("invZ was invalid");return{x:M,y:k}}),h=Qe(S=>{let{a:x,d:I}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:E,Y:T,Z:R,T:M}=S,k=a(E*E),N=a(T*T),w=a(R*R),B=a(w*w),U=a(k*x),P=a(w*a(U+N)),b=a(B+a(I*a(k*N)));if(P!==b)throw new Error("bad point: equation left != right (1)");let m=a(E*T),y=a(R*M);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(x,I,E,T){this.X=l("x",x),this.Y=l("y",I),this.Z=l("z",E,!0),this.T=l("t",T),Object.freeze(this)}static CURVE(){return s}static fromAffine(x){if(x instanceof p)throw new Error("extended point not allowed");let{x:I,y:E}=x||{};return l("x",I),l("y",E),new p(I,E,lt,a(I*E))}static fromBytes(x,I=!1){let E=n.BYTES,{a:T,d:R}=s;x=Go(Pt(x,E,"point")),te(I,"zip215");let M=Go(x),k=x[E-1];M[E-1]=k&-129;let N=ee(M),w=I?c:n.ORDER;Kr("point.y",N,xe,w);let B=a(N*N),U=a(B-lt),P=a(R*B-T),{isValid:b,value:m}=u(U,P);if(!b)throw new Error("bad point: invalid y coordinate");let y=(m&lt)===lt,v=(k&128)!==0;if(!I&&m===xe&&v)throw new Error("bad point: x=0 and x_0=1");return v!==y&&(m=a(-m)),p.fromAffine({x:m,y:N})}static fromHex(x,I=!1){return p.fromBytes(Z("point",x),I)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,I=!0){return g.createCache(this,x),I||this.multiply(es),this}assertValidity(){h(this)}equals(x){d(x);let{X:I,Y:E,Z:T}=this,{X:R,Y:M,Z:k}=x,N=a(I*k),w=a(R*T),B=a(E*k),U=a(M*T);return N===w&&B===U}is0(){return this.equals(p.ZERO)}negate(){return new p(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:x}=s,{X:I,Y:E,Z:T}=this,R=a(I*I),M=a(E*E),k=a(es*a(T*T)),N=a(x*R),w=I+E,B=a(a(w*w)-R-M),U=N+M,P=U-k,b=N-M,m=a(B*P),y=a(U*b),v=a(B*b),A=a(P*U);return new p(m,y,A,v)}add(x){d(x);let{a:I,d:E}=s,{X:T,Y:R,Z:M,T:k}=this,{X:N,Y:w,Z:B,T:U}=x,P=a(T*N),b=a(R*w),m=a(k*E*U),y=a(M*B),v=a((T+R)*(N+w)-P-b),A=y-m,D=y+m,_=a(b-I*P),C=a(v*A),O=a(D*_),K=a(v*_),J=a(A*D);return new p(C,O,J,K)}subtract(x){return this.add(x.negate())}multiply(x){if(!o.isValidNot0(x))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:I,f:E}=g.cached(this,x,T=>ne(p,T));return ne(p,[I,E])[0]}multiplyUnsafe(x,I=p.ZERO){if(!o.isValid(x))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return x===xe?p.ZERO:this.is0()||x===lt?this:g.unsafe(this,x,E=>ne(p,E),I)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return g.unsafe(this,s.n).is0()}toAffine(x){return f(this,x)}clearCofactor(){return i===lt?this:this.multiplyUnsafe(i)}toBytes(){let{x,y:I}=this.toAffine(),E=n.toBytes(I);return E[E.length-1]|=x&lt?128:0,E}toHex(){return Lt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(x){return ne(p,x)}static msm(x,I){return er(p,o,x,I)}_setWindowSize(x){this.precompute(x)}toRawBytes(){return this.toBytes()}}p.BASE=new p(s.Gx,s.Gy,lt,a(s.Gx*s.Gy)),p.ZERO=new p(xe,lt,lt,xe),p.Fp=n,p.Fn=o;let g=new tr(p,o.BITS);return p.BASE.precompute(8),p}var An=class{constructor(t){this.ep=t}static fromBytes(t){Zo()}static fromHex(t){Zo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Lt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function pl(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');ge(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||je,a=r.adjustScalarBytes||(w=>w),u=r.domain||((w,B,U)=>{if(te(U,"phflag"),B.length||U)throw new Error("Contexts/pre-hash are not supported");return w});function l(w){return i.create(ee(w))}function d(w){let B=E.secretKey;w=Z("private key",w,B);let U=Z("hashed private key",t(w),2*B),P=a(U.slice(0,B)),b=U.slice(B,2*B),m=l(P);return{head:P,prefix:b,scalar:m}}function f(w){let{head:B,prefix:U,scalar:P}=d(w),b=o.multiply(P),m=b.toBytes();return{head:B,prefix:U,scalar:P,point:b,pointBytes:m}}function h(w){return f(w).pointBytes}function p(w=Uint8Array.of(),...B){let U=wt(...B);return l(t(u(U,Z("context",w),!!n)))}function g(w,B,U={}){w=Z("message",w),n&&(w=n(w));let{prefix:P,scalar:b,pointBytes:m}=f(B),y=p(U.context,P,w),v=o.multiply(y).toBytes(),A=p(U.context,v,m,w),D=i.create(y+A*b);if(!i.isValid(D))throw new Error("sign failed: invalid s");let _=wt(v,i.toBytes(D));return Pt(_,E.signature,"result")}let S={zip215:!0};function x(w,B,U,P=S){let{context:b,zip215:m}=P,y=E.signature;w=Z("signature",w,y),B=Z("message",B),U=Z("publicKey",U,E.publicKey),m!==void 0&&te(m,"zip215"),n&&(B=n(B));let v=y/2,A=w.subarray(0,v),D=ee(w.subarray(v,y)),_,C,O;try{_=e.fromBytes(U,m),C=e.fromBytes(A,m),O=o.multiplyUnsafe(D)}catch{return!1}if(!m&&_.isSmallOrder())return!1;let K=p(b,C.toBytes(),_.toBytes(),B);return C.add(_.multiplyUnsafe(K)).subtract(O).clearCofactor().is0()}let I=s.BYTES,E={secretKey:I,publicKey:I,signature:2*I,seed:I};function T(w=c(E.seed)){return Pt(w,E.seed,"seed")}function R(w){let B=N.randomSecretKey(w);return{secretKey:B,publicKey:h(B)}}function M(w){return Xt(w)&&w.length===i.BYTES}function k(w,B){try{return!!e.fromBytes(w,B)}catch{return!1}}let N={getExtendedPublicKey:f,randomSecretKey:T,isValidSecretKey:M,isValidPublicKey:k,toMontgomery(w){let{y:B}=e.fromBytes(w),U=E.publicKey,P=U===32;if(!P&&U!==57)throw new Error("only defined for 25519 and 448");let b=P?s.div(lt+B,lt-B):s.div(B-lt,B+lt);return s.toBytes(b)},toMontgomerySecret(w){let B=E.secretKey;Pt(w,B);let U=t(w.subarray(0,B));return a(U).subarray(0,B)},randomPrivateKey:T,precompute(w=8,B=e.BASE){return B.precompute(w,!1)}};return Object.freeze({keygen:R,getPublicKey:h,sign:g,verify:x,utils:N,Point:e,lengths:E})}function ml(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=Tt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function yl(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Fa(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=ml(e),s=hl(t,r),i=pl(s,n,o);return yl(e,i)}var bl=BigInt(0),oe=BigInt(1),Ha=BigInt(2),J0=BigInt(3),gl=BigInt(5),xl=BigInt(8),rr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Vr={p:rr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:xl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function wl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=rr,c=e*e%s*e%s,a=X(c,Ha,s)*c%s,u=X(a,oe,s)*e%s,l=X(u,gl,s)*u%s,d=X(l,t,s)*l%s,f=X(d,r,s)*d%s,h=X(f,n,s)*f%s,p=X(h,o,s)*h%s,g=X(p,o,s)*h%s,S=X(g,t,s)*l%s;return{pow_p_5_8:X(S,Ha,s)*e%s,b2:c}}function El(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var rs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ss(e,t){let r=rr,n=nt(t*t*t,r),o=nt(n*n*t,r),s=wl(e*o).pow_p_5_8,i=nt(e*n*s,r),c=nt(t*i*i,r),a=i,u=nt(i*rs,r),l=c===e,d=c===nt(-e,r),f=c===nt(-e*rs,r);return l&&(i=a),(d||f)&&(i=u),re(i,r)&&(i=nt(-i,r)),{isValid:l||d,value:i}}var we=Tt(Vr.p,{isLE:!0}),vl=Tt(Vr.n,{isLE:!0}),Sl={...Vr,Fp:we,hash:wa,adjustScalarBytes:El,uvRatio:ss},se=Fa(Sl);var ns=rs,Il=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Al=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),_l=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Cl=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),qa=e=>ss(oe,e),Bl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),os=e=>se.Point.Fp.create(ee(e)&Bl);function za(e){let{d:t}=Vr,r=rr,n=x=>we.create(x),o=n(ns*e*e),s=n((o+oe)*_l),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:u}=ss(s,c),l=n(u*e);re(l,r)||(l=n(-l)),a||(u=l),a||(i=o);let d=n(i*(o-oe)*Cl-c),f=u*u,h=n((u+u)*c),p=n(d*Il),g=n(oe-f),S=n(oe+f);return new se.Point(n(h*S),n(g*p),n(p*S),n(h*g))}function Pl(e){_t(e,64);let t=os(e.subarray(0,32)),r=za(t),n=os(e.subarray(32,64)),o=za(n);return new ie(r.add(o))}var ie=class e extends An{constructor(t){super(t)}static fromAffine(t){return new e(se.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return Pl(Z("ristrettoHash",t,64))}static fromBytes(t){_t(t,32);let{a:r,d:n}=Vr,o=rr,s=T=>we.create(T),i=os(t);if(!va(we.toBytes(i),t)||re(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(oe+r*c),u=s(oe-r*c),l=s(a*a),d=s(u*u),f=s(r*n*l-d),{isValid:h,value:p}=qa(s(f*d)),g=s(p*u),S=s(p*g*f),x=s((i+i)*g);re(x,o)&&(x=s(-x));let I=s(a*S),E=s(x*I);if(!h||re(E,o)||I===bl)throw new Error("invalid ristretto255 encoding 2");return new e(new se.Point(x,I,oe,E))}static fromHex(t){return e.fromBytes(Z("ristrettoHex",t,32))}static msm(t,r){return er(e,se.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=rr,i=S=>we.create(S),c=i(i(n+r)*i(n-r)),a=i(t*r),u=i(a*a),{value:l}=qa(i(c*u)),d=i(l*c),f=i(l*a),h=i(d*f*o),p;if(re(o*h,s)){let S=i(r*ns),x=i(t*ns);t=S,r=x,p=i(d*Al)}else p=f;re(t*h,s)&&(r=i(-r));let g=i((n-r)*p);return re(g,s)&&(g=i(-g)),we.toBytes(g)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>we.create(u),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};ie.BASE=new ie(se.Point.BASE);ie.ZERO=new ie(se.Point.ZERO);ie.Fp=we;ie.Fn=vl;var Fr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},_n=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var $a={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new _n("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Ot=$a;var Cn=32;var is,Tl=(async()=>{try{return await Ot.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Dl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Ot.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Ot.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ll(e,t,r){return se.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ga(e,t,r){return is==null&&(is=await Tl),is?Dl(e,t,r):Ll(e,t,r)}function Bn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Pn=class{type="Ed25519";raw;constructor(t){this.raw=as(t,Cn)}toMultihash(){return Nt.digest(qt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ga(this.raw,r,t);return Bn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function cs(e){return e=as(e,Cn),new Pn(e)}function as(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new Q(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Rl=Math.pow(2,7),Nl=Math.pow(2,14),Ul=Math.pow(2,21),us=Math.pow(2,28),fs=Math.pow(2,35),ls=Math.pow(2,42),ds=Math.pow(2,49),$=128,bt=127;function Ct(e){if(e<Rl)return 1;if(e<Nl)return 2;if(e<Ul)return 3;if(e<us)return 4;if(e<fs)return 5;if(e<ls)return 6;if(e<ds)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function nr(e,t,r=0){switch(Ct(e)){case 8:t[r++]=e&255|$,e/=128;case 7:t[r++]=e&255|$,e/=128;case 6:t[r++]=e&255|$,e/=128;case 5:t[r++]=e&255|$,e/=128;case 4:t[r++]=e&255|$,e>>>=7;case 3:t[r++]=e&255|$,e>>>=7;case 2:t[r++]=e&255|$,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Kl(e,t,r=0){switch(Ct(e)){case 8:t.set(r++,e&255|$),e/=128;case 7:t.set(r++,e&255|$),e/=128;case 6:t.set(r++,e&255|$),e/=128;case 5:t.set(r++,e&255|$),e/=128;case 4:t.set(r++,e&255|$),e>>>=7;case 3:t.set(r++,e&255|$),e>>>=7;case 2:t.set(r++,e&255|$),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function hs(e,t){let r=e[t],n=0;if(n+=r&bt,r<$||(r=e[t+1],n+=(r&bt)<<7,r<$)||(r=e[t+2],n+=(r&bt)<<14,r<$)||(r=e[t+3],n+=(r&bt)<<21,r<$)||(r=e[t+4],n+=(r&bt)*us,r<$)||(r=e[t+5],n+=(r&bt)*fs,r<$)||(r=e[t+6],n+=(r&bt)*ls,r<$)||(r=e[t+7],n+=(r&bt)*ds,r<$))return n;throw new RangeError("Could not decode varint")}function kl(e,t){let r=e.get(t),n=0;if(n+=r&bt,r<$||(r=e.get(t+1),n+=(r&bt)<<7,r<$)||(r=e.get(t+2),n+=(r&bt)<<14,r<$)||(r=e.get(t+3),n+=(r&bt)<<21,r<$)||(r=e.get(t+4),n+=(r&bt)*us,r<$)||(r=e.get(t+5),n+=(r&bt)*fs,r<$)||(r=e.get(t+6),n+=(r&bt)*ls,r<$)||(r=e.get(t+7),n+=(r&bt)*ds,r<$))return n;throw new RangeError("Could not decode varint")}function or(e,t,r=0){return t==null&&(t=It(Ct(e))),t instanceof Uint8Array?nr(e,t,r):Kl(e,t,r)}function Hr(e,t=0){return e instanceof Uint8Array?hs(e,t):kl(e,t)}var ms=new Float32Array([-0]),Ee=new Uint8Array(ms.buffer);function Ya(e,t,r){ms[0]=e,t[r]=Ee[0],t[r+1]=Ee[1],t[r+2]=Ee[2],t[r+3]=Ee[3]}function Wa(e,t){return Ee[0]=e[t],Ee[1]=e[t+1],Ee[2]=e[t+2],Ee[3]=e[t+3],ms[0]}var ys=new Float64Array([-0]),gt=new Uint8Array(ys.buffer);function ja(e,t,r){ys[0]=e,t[r]=gt[0],t[r+1]=gt[1],t[r+2]=gt[2],t[r+3]=gt[3],t[r+4]=gt[4],t[r+5]=gt[5],t[r+6]=gt[6],t[r+7]=gt[7]}function Xa(e,t){return gt[0]=e[t],gt[1]=e[t+1],gt[2]=e[t+2],gt[3]=e[t+3],gt[4]=e[t+4],gt[5]=e[t+5],gt[6]=e[t+6],gt[7]=e[t+7],ys[0]}var Ml=BigInt(Number.MAX_SAFE_INTEGER),Vl=BigInt(Number.MIN_SAFE_INTEGER),Dt=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return De;if(t<Ml&&t>Vl)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Qa&&(o=0n,++n>Qa&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return De;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):De}},De=new Dt(0,0);De.toBigInt=function(){return 0n};De.zzEncode=De.zzDecode=function(){return this};De.length=function(){return 1};var Qa=4294967296n;function Ja(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function tc(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function bs(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Tn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var gs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Kt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Kt(this,4);return Tn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return Tn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=Wa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=Xa(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return tc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Kt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Dt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Kt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Kt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Kt(this,8);let t=Tn(this.buf,this.pos+=4),r=Tn(this.buf,this.pos+=4);return new Dt(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=hs(this.buf,this.pos);return this.pos+=Ct(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function xs(e){return new gs(e instanceof Uint8Array?e:e.subarray())}function kt(e,t,r){let n=xs(e);return t.decode(n,void 0,r)}function ws(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return It(i);o+i>t&&(n=It(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var Le=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Es(){}var Ss=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Fl=ws();function Hl(e){return globalThis.Buffer!=null?It(e):Fl(e)}var zr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Le(Es,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Le(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Is((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Dn,10,Dt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Dt.fromBigInt(t);return this._push(Dn,r.length(),r)}uint64Number(t){return this._push(nr,Ct(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Dt.fromBigInt(t).zzEncode();return this._push(Dn,r.length(),r)}sint64Number(t){let r=Dt.fromNumber(t).zzEncode();return this._push(Dn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(vs,1,t?1:0)}fixed32(t){return this._push(qr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Dt.fromBigInt(t);return this._push(qr,4,r.lo)._push(qr,4,r.hi)}fixed64Number(t){let r=Dt.fromNumber(t);return this._push(qr,4,r.lo)._push(qr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ya,4,t)}double(t){return this._push(ja,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(vs,1,0):this.uint32(r)._push(zl,r,t)}string(t){let r=Ja(t);return r!==0?this.uint32(r)._push(bs,r,t):this._push(vs,1,0)}fork(){return this.states=new Ss(this),this.head=this.tail=new Le(Es,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 Le(Es,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Hl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function vs(e,t,r){t[r]=e&255}function ql(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Is=class extends Le{next;constructor(t,r){super(ql,t,r),this.next=void 0}};function Dn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function qr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function zl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(zr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push($l,t,e),this},zr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Gl,t,e),this});function $l(e,t,r){t.set(e,r)}function Gl(e,t,r){e.length<40?bs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(V(e),r)}function As(){return new zr}function Mt(e,t){let r=As();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var sr;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(sr||(sr={}));function Ln(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function _s(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return Ln("enum",sr.VARINT,r,n)}function Vt(e,t){return Ln("message",sr.LENGTH_DELIMITED,e,t)}var Oe=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var st;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(st||(st={}));var Cs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Cs||(Cs={}));(function(e){e.codec=()=>_s(Cs)})(st||(st={}));var $t;(function(e){let t;e.codec=()=>(t==null&&(t=Vt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=st.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Mt(r,e.codec()),e.decode=(r,n)=>kt(r,e.codec(),n)})($t||($t={}));var Bs;(function(e){let t;e.codec=()=>(t==null&&(t=Vt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=st.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Mt(r,e.codec()),e.decode=(r,n)=>kt(r,e.codec(),n)})(Bs||(Bs={}));var Gr={};St(Gr,{MAX_RSA_KEY_SIZE:()=>Ps,generateRSAKeyPair:()=>ic,jwkToJWKKeyPair:()=>ac,jwkToPkcs1:()=>jl,jwkToPkix:()=>Os,jwkToRSAPrivateKey:()=>Ks,pkcs1MessageToJwk:()=>Ds,pkcs1MessageToRSAPrivateKey:()=>Rs,pkcs1ToJwk:()=>Wl,pkcs1ToRSAPrivateKey:()=>sc,pkixMessageToJwk:()=>Ls,pkixMessageToRSAPublicKey:()=>Us,pkixToJwk:()=>Xl,pkixToRSAPublicKey:()=>Ns});var On=wn;var ir=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Gr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ct.createV1(114,this._multihash)}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,r,n){return oc(this.jwk,r,t,n)}},$r=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Gr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}sign(t,r){return nc(this.jwk,t,r)}};var Ps=8192,Ts=18,Zl=1062,Yl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Wl(e){let t=Wt(e);return Ds(t)}function Ds(e){return{n:H(e[1],"base64url"),e:H(e[2],"base64url"),d:H(e[3],"base64url"),p:H(e[4],"base64url"),q:H(e[5],"base64url"),dp:H(e[6],"base64url"),dq:H(e[7],"base64url"),qi:H(e[8],"base64url"),kty:"RSA"}}function jl(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new Q("JWK was missing components");return he([At(Uint8Array.from([0])),At(V(e.n,"base64url")),At(V(e.e,"base64url")),At(V(e.d,"base64url")),At(V(e.p,"base64url")),At(V(e.q,"base64url")),At(V(e.dp,"base64url")),At(V(e.dq,"base64url")),At(V(e.qi,"base64url"))]).subarray()}function Xl(e){let t=Wt(e,{offset:0});return Ls(t)}function Ls(e){let t=Wt(e[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function Os(e){if(e.n==null||e.e==null)throw new Q("JWK was missing components");return he([Yl,mn(he([At(V(e.n,"base64url")),At(V(e.e,"base64url"))]))]).subarray()}function sc(e){let t=Wt(e);return Rs(t)}function Rs(e){let t=Ds(e);return Ks(t)}function Ns(e,t){if(e.byteLength>=Zl)throw new He("Key size is too large");let r=Wt(e,{offset:0});return Us(r,e,t)}function Us(e,t,r){let n=Ls(e);if(r==null){let o=On($t.encode({Type:st.RSA,Data:t}));r=Ht(Ts,o)}return new ir(n,r)}function Ks(e){if(uc(e)>Ps)throw new Q("Key size is too large");let t=ac(e),r=On($t.encode({Type:st.RSA,Data:Os(t.publicKey)})),n=Ht(Ts,r);return new $r(t.privateKey,new ir(t.publicKey,n))}async function ic(e){if(e>Ps)throw new Q("Key size is too large");let t=await cc(e),r=On($t.encode({Type:st.RSA,Data:Os(t.publicKey)})),n=Ht(Ts,r);return new $r(t.privateKey,new ir(t.publicKey,n))}function ac(e){if(e==null)throw new Q("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function cc(e,t){let r=await Ot.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Ql(r,t);return{privateKey:n[0],publicKey:n[1]}}async function nc(e,t,r){let n=await Ot.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ot.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function oc(e,t,r,n){let o=await Ot.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Ot.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Ql(e,t){if(e.privateKey==null||e.publicKey==null)throw new Q("Private and public key are required");let r=await Promise.all([Ot.get().subtle.exportKey("jwk",e.privateKey),Ot.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function uc(e){if(e.kty!=="RSA")throw new Q("invalid key type");if(e.n==null)throw new Q("invalid key modulus");return V(e.n,"base64url").length*8}var Rn=class extends Ye{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,yn(t);let n=Lr(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Qt(s)}update(t){return We(this),this.iHash.update(t),this}digestInto(t){We(this),_t(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ks=(e,t,r)=>new Rn(e,t).update(r).digest();ks.create=(e,t)=>new Rn(e,t);var fc=(e,t)=>(e+(e>=0?t:-t)/lc)/t;function Jl(e,t,r){let[[n,o],[s,i]]=t,c=fc(i*e,r),a=fc(-o*e,r),u=e-c*n-a*s,l=-c*o-a*i,d=u<ce,f=l<ce;d&&(u=-u),f&&(l=-l);let h=be(Math.ceil(vn(r)/2))+cr;if(u<ce||u>=h||l<ce||l>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:d,k1:u,k2neg:f,k2:l}}function Vs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ms(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return te(r.lowS,"lowS"),te(r.prehash,"prehash"),r.format!==void 0&&Vs(r.format),r}var Fs=class extends Error{constructor(t=""){super(t)}},ae={Err:Fs,_tlv:{encode:(e,t)=>{let{Err:r}=ae;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Ur(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Ur(o.length/2|128):"";return Ur(e)+s+o+t},decode(e,t){let{Err:r}=ae,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=ae;if(e<ce)throw new t("integer: negative integers are not allowed");let r=Ur(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=ae;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Xe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=ae,o=Z("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l}=n.decode(2,a);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=ae,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},ce=BigInt(0),cr=BigInt(1),lc=BigInt(2),Nn=BigInt(3),td=BigInt(4);function ar(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=Z("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function ed(e,t={}){let r=In("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;ge(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=hc(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(P,b,m){let{x:y,y:v}=b.toAffine(),A=n.toBytes(y);if(te(m,"isCompressed"),m){l();let D=!n.isOdd(v);return wt(dc(D),A)}else return wt(Uint8Array.of(4),A,n.toBytes(v))}function f(P){Pt(P,void 0,"Point");let{publicKey:b,publicKeyUncompressed:m}=u,y=P.length,v=P[0],A=P.subarray(1);if(y===b&&(v===2||v===3)){let D=n.fromBytes(A);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let _=g(D),C;try{C=n.sqrt(_)}catch(J){let Y=J instanceof Error?": "+J.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}l();let O=n.isOdd(C);return(v&1)===1!==O&&(C=n.neg(C)),{x:D,y:C}}else if(y===m&&v===4){let D=n.BYTES,_=n.fromBytes(A.subarray(0,D)),C=n.fromBytes(A.subarray(D,D*2));if(!S(_,C))throw new Error("bad point: is not on curve");return{x:_,y:C}}else throw new Error(`bad point: got length ${y}, expected compressed=${b} or uncompressed=${m}`)}let h=t.toBytes||d,p=t.fromBytes||f;function g(P){let b=n.sqr(P),m=n.mul(b,P);return n.add(n.add(m,n.mul(P,s.a)),s.b)}function S(P,b){let m=n.sqr(b),y=g(P);return n.eql(m,y)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(s.a,Nn),td),I=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(x,I)))throw new Error("bad curve params: a or b");function E(P,b,m=!1){if(!n.isValid(b)||m&&n.is0(b))throw new Error(`bad point coordinate ${P}`);return b}function T(P){if(!(P instanceof w))throw new Error("ProjectivePoint expected")}function R(P){if(!a||!a.basises)throw new Error("no endo");return Jl(P,a.basises,o.ORDER)}let M=Qe((P,b)=>{let{X:m,Y:y,Z:v}=P;if(n.eql(v,n.ONE))return{x:m,y};let A=P.is0();b==null&&(b=A?n.ONE:n.inv(v));let D=n.mul(m,b),_=n.mul(y,b),C=n.mul(v,b);if(A)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:D,y:_}}),k=Qe(P=>{if(P.is0()){if(t.allowInfinityPoint&&!n.is0(P.Y))return;throw new Error("bad point: ZERO")}let{x:b,y:m}=P.toAffine();if(!n.isValid(b)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!S(b,m))throw new Error("bad point: equation left != right");if(!P.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function N(P,b,m,y,v){return m=new w(n.mul(m.X,P),m.Y,m.Z),b=Mr(y,b),m=Mr(v,m),b.add(m)}class w{constructor(b,m,y){this.X=E("x",b),this.Y=E("y",m,!0),this.Z=E("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){let{x:m,y}=b||{};if(!b||!n.isValid(m)||!n.isValid(y))throw new Error("invalid affine point");if(b instanceof w)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(y)?w.ZERO:new w(m,y,n.ONE)}static fromBytes(b){let m=w.fromAffine(p(Pt(b,void 0,"point")));return m.assertValidity(),m}static fromHex(b){return w.fromBytes(Z("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,m=!0){return U.createCache(this,b),m||this.multiply(Nn),this}assertValidity(){k(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){T(b);let{X:m,Y:y,Z:v}=this,{X:A,Y:D,Z:_}=b,C=n.eql(n.mul(m,_),n.mul(A,v)),O=n.eql(n.mul(y,_),n.mul(D,v));return C&&O}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:m}=s,y=n.mul(m,Nn),{X:v,Y:A,Z:D}=this,_=n.ZERO,C=n.ZERO,O=n.ZERO,K=n.mul(v,v),J=n.mul(A,A),Y=n.mul(D,D),z=n.mul(v,A);return z=n.add(z,z),O=n.mul(v,D),O=n.add(O,O),_=n.mul(b,O),C=n.mul(y,Y),C=n.add(_,C),_=n.sub(J,C),C=n.add(J,C),C=n.mul(_,C),_=n.mul(z,_),O=n.mul(y,O),Y=n.mul(b,Y),z=n.sub(K,Y),z=n.mul(b,z),z=n.add(z,O),O=n.add(K,K),K=n.add(O,K),K=n.add(K,Y),K=n.mul(K,z),C=n.add(C,K),Y=n.mul(A,D),Y=n.add(Y,Y),K=n.mul(Y,z),_=n.sub(_,K),O=n.mul(Y,J),O=n.add(O,O),O=n.add(O,O),new w(_,C,O)}add(b){T(b);let{X:m,Y:y,Z:v}=this,{X:A,Y:D,Z:_}=b,C=n.ZERO,O=n.ZERO,K=n.ZERO,J=s.a,Y=n.mul(s.b,Nn),z=n.mul(m,A),tt=n.mul(y,D),at=n.mul(v,_),vt=n.add(m,y),et=n.add(A,D);vt=n.mul(vt,et),et=n.add(z,tt),vt=n.sub(vt,et),et=n.add(m,v);let yt=n.add(A,_);return et=n.mul(et,yt),yt=n.add(z,at),et=n.sub(et,yt),yt=n.add(y,v),C=n.add(D,_),yt=n.mul(yt,C),C=n.add(tt,at),yt=n.sub(yt,C),K=n.mul(J,et),C=n.mul(Y,at),K=n.add(C,K),C=n.sub(tt,K),K=n.add(tt,K),O=n.mul(C,K),tt=n.add(z,z),tt=n.add(tt,z),at=n.mul(J,at),et=n.mul(Y,et),tt=n.add(tt,at),at=n.sub(z,at),at=n.mul(J,at),et=n.add(et,at),z=n.mul(tt,et),O=n.add(O,z),z=n.mul(yt,et),C=n.mul(vt,C),C=n.sub(C,z),z=n.mul(vt,tt),K=n.mul(yt,K),K=n.add(K,z),new w(C,O,K)}subtract(b){return this.add(b.negate())}is0(){return this.equals(w.ZERO)}multiply(b){let{endo:m}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let y,v,A=D=>U.cached(this,D,_=>ne(w,_));if(m){let{k1neg:D,k1:_,k2neg:C,k2:O}=R(b),{p:K,f:J}=A(_),{p:Y,f:z}=A(O);v=J.add(z),y=N(m.beta,K,Y,D,C)}else{let{p:D,f:_}=A(b);y=D,v=_}return ne(w,[y,v])[0]}multiplyUnsafe(b){let{endo:m}=t,y=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===ce||y.is0())return w.ZERO;if(b===cr)return y;if(U.hasCache(this))return this.multiply(b);if(m){let{k1neg:v,k1:A,k2neg:D,k2:_}=R(b),{p1:C,p2:O}=Va(w,y,A,_);return N(m.beta,C,O,v,D)}else return U.unsafe(y,b)}multiplyAndAddUnsafe(b,m,y){let v=this.multiplyUnsafe(m).add(b.multiplyUnsafe(y));return v.is0()?void 0:v}toAffine(b){return M(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return i===cr?!0:b?b(w,this):U.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:b}=t;return i===cr?this:b?b(w,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return te(b,"isCompressed"),this.assertValidity(),h(w,this,b)}toHex(b=!0){return Lt(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(b=!0){return this.toBytes(b)}_setWindowSize(b){this.precompute(b)}static normalizeZ(b){return ne(w,b)}static msm(b,m){return er(w,o,b,m)}static fromPrivateKey(b){return w.BASE.multiply(ar(o,b))}}w.BASE=new w(s.Gx,s.Gy,n.ONE),w.ZERO=new w(n.ZERO,n.ONE,n.ZERO),w.Fp=n,w.Fn=o;let B=o.BITS,U=new tr(w,t.endo?Math.ceil(B/2):B);return w.BASE.precompute(8),w}function dc(e){return Uint8Array.of(e?2:3)}function hc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function rd(e,t={}){let{Fn:r}=e,n=t.randomBytes||je,o=Object.assign(hc(e.Fp,r),{seed:jo(r.ORDER)});function s(h){try{return!!ar(r,h)}catch{return!1}}function i(h,p){let{publicKey:g,publicKeyUncompressed:S}=o;try{let x=h.length;return p===!0&&x!==g||p===!1&&x!==S?!1:!!e.fromBytes(h)}catch{return!1}}function c(h=n(o.seed)){return Xo(Pt(h,o.seed,"seed"),r.ORDER)}function a(h,p=!0){return e.BASE.multiply(ar(r,h)).toBytes(p)}function u(h){let p=c(h);return{secretKey:p,publicKey:a(p)}}function l(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;let{secretKey:p,publicKey:g,publicKeyUncompressed:S}=o;if(r.allowedLengths||p===g)return;let x=Z("key",h).length;return x===g||x===S}function d(h,p,g=!0){if(l(h)===!0)throw new Error("first arg must be private key");if(l(p)===!1)throw new Error("second arg must be public key");let S=ar(r,h);return e.fromHex(p).multiply(S).toBytes(g)}return Object.freeze({getPublicKey:a,getSharedSecret:d,keygen:u,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:h=>ar(r,h),precompute(h=8,p=e.BASE){return p.precompute(h,!1)}},lengths:o})}function nd(e,t,r={}){yn(t),ge(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||je,o=r.hmac||((m,...y)=>ks(t,m,wt(...y))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:l,getSharedSecret:d,utils:f,lengths:h}=rd(e,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},g="compact";function S(m){let y=c>>cr;return m>y}function x(m,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function I(m,y){Vs(y);let v=h.signature,A=y==="compact"?v:y==="recovered"?v+1:void 0;return Pt(m,A,`${y} signature`)}class E{constructor(y,v,A){this.r=x("r",y),this.s=x("s",v),A!=null&&(this.recovery=A),Object.freeze(this)}static fromBytes(y,v=g){I(y,v);let A;if(v==="der"){let{r:O,s:K}=ae.toSig(Pt(y));return new E(O,K)}v==="recovered"&&(A=y[0],v="compact",y=y.subarray(1));let D=i.BYTES,_=y.subarray(0,D),C=y.subarray(D,D*2);return new E(i.fromBytes(_),i.fromBytes(C),A)}static fromHex(y,v){return this.fromBytes(_e(y),v)}addRecoveryBit(y){return new E(this.r,this.s,y)}recoverPublicKey(y){let v=s.ORDER,{r:A,s:D,recovery:_}=this;if(_==null||![0,1,2,3].includes(_))throw new Error("recovery id invalid");if(c*lc<v&&_>1)throw new Error("recovery id is ambiguous for h>1 curve");let O=_===2||_===3?A+c:A;if(!s.isValid(O))throw new Error("recovery id 2 or 3 invalid");let K=s.toBytes(O),J=e.fromBytes(wt(dc((_&1)===0),K)),Y=i.inv(O),z=R(Z("msgHash",y)),tt=i.create(-z*Y),at=i.create(D*Y),vt=e.BASE.multiplyUnsafe(tt).add(J.multiplyUnsafe(at));if(vt.is0())throw new Error("point at infinify");return vt.assertValidity(),vt}hasHighS(){return S(this.s)}toBytes(y=g){if(Vs(y),y==="der")return _e(ae.hexFromSig(this));let v=i.toBytes(this.r),A=i.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return wt(Uint8Array.of(this.recovery),v,A)}return wt(v,A)}toHex(y){return Lt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return E.fromBytes(Z("sig",y),"compact")}static fromDER(y){return E.fromBytes(Z("sig",y),"der")}normalizeS(){return this.hasHighS()?new E(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Lt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Lt(this.toBytes("compact"))}}let T=r.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let v=Xe(y),A=y.length*8-a;return A>0?v>>BigInt(A):v},R=r.bits2int_modN||function(y){return i.create(T(y))},M=be(a);function k(m){return Kr("num < 2^"+a,m,ce,M),i.toBytes(m)}function N(m,y){return Pt(m,void 0,"message"),y?Pt(t(m),void 0,"prehashed message"):m}function w(m,y,v){if(["recovered","canonical"].some(tt=>tt in v))throw new Error("sign() legacy options not supported");let{lowS:A,prehash:D,extraEntropy:_}=Ms(v,p);m=N(m,D);let C=R(m),O=ar(i,y),K=[k(O),k(C)];if(_!=null&&_!==!1){let tt=_===!0?n(h.secretKey):_;K.push(Z("extraEntropy",tt))}let J=wt(...K),Y=C;function z(tt){let at=T(tt);if(!i.isValidNot0(at))return;let vt=i.inv(at),et=e.BASE.multiply(at).toAffine(),yt=i.create(et.x);if(yt===ce)return;let an=i.create(vt*i.create(Y+yt*O));if(an===ce)return;let Ti=(et.x===yt?0:2)|Number(et.y&cr),Di=an;return A&&S(an)&&(Di=i.neg(an),Ti^=1),new E(yt,Di,Ti)}return{seed:J,k2sig:z}}function B(m,y,v={}){m=Z("message",m);let{seed:A,k2sig:D}=w(m,y,v);return Ia(t.outputLen,i.BYTES,o)(A,D)}function U(m){let y,v=typeof m=="string"||Xt(m),A=!v&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!v&&!A)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(A)y=new E(m.r,m.s);else if(v){try{y=E.fromBytes(Z("sig",m),"der")}catch(D){if(!(D instanceof ae.Err))throw D}if(!y)try{y=E.fromBytes(Z("sig",m),"compact")}catch{return!1}}return y||!1}function P(m,y,v,A={}){let{lowS:D,prehash:_,format:C}=Ms(A,p);if(v=Z("publicKey",v),y=N(Z("message",y),_),"strict"in A)throw new Error("options.strict was renamed to lowS");let O=C===void 0?U(m):E.fromBytes(Z("sig",m),C);if(O===!1)return!1;try{let K=e.fromBytes(v);if(D&&O.hasHighS())return!1;let{r:J,s:Y}=O,z=R(y),tt=i.inv(Y),at=i.create(z*tt),vt=i.create(J*tt),et=e.BASE.multiplyUnsafe(at).add(K.multiplyUnsafe(vt));return et.is0()?!1:i.create(et.x)===J}catch{return!1}}function b(m,y,v={}){let{prehash:A}=Ms(v,p);return y=N(y,A),E.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:d,utils:f,lengths:h,Point:e,sign:B,verify:P,recoverPublicKey:b,Signature:E,hash:t})}function od(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=Tt(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function sd(e){let{CURVE:t,curveOpts:r}=od(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function id(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Sn(r.Fn.ORDER,r.Fn.BITS))})}function pc(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=sd(e),s=ed(t,r),i=nd(s,n,o);return id(e,i)}function mc(e,t){let r=n=>pc({...e,hash:n});return{...r(t),create:r}}var qs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ad={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var yc=BigInt(2);function cd(e){let t=qs.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,l=u*u*e%t,d=X(l,r,t)*l%t,f=X(d,r,t)*l%t,h=X(f,yc,t)*u%t,p=X(h,o,t)*h%t,g=X(p,s,t)*p%t,S=X(g,c,t)*g%t,x=X(S,a,t)*S%t,I=X(x,c,t)*g%t,E=X(I,r,t)*l%t,T=X(E,i,t)*p%t,R=X(T,n,t)*u%t,M=X(R,yc,t);if(!Hs.eql(Hs.sqr(M),e))throw new Error("Cannot find square root");return M}var Hs=Tt(qs.p,{sqrt:cd}),ur=mc({...qs,Fp:Hs,lowS:!0,endo:ad},wn);function bc(e,t,r,n){let o=Cr.digest(r instanceof Uint8Array?r:r.subarray());if(Bn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ur.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new Fr(String(s))});try{return n?.signal?.throwIfAborted(),ur.verify(t,o.digest,e)}catch(s){throw new Fr(String(s))}}var Un=class{type="secp256k1";raw;_key;constructor(t){this._key=xc(t),this.raw=gc(this._key)}toMultihash(){return Nt.digest(qt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ut(this.raw,t.raw)}verify(t,r,n){return bc(this._key,r,t,n)}};function zs(e){return new Un(e)}function gc(e){return ur.ProjectivePoint.fromHex(e).toRawBytes(!0)}function xc(e){try{return ur.ProjectivePoint.fromHex(e),e}catch(t){throw new He(String(t))}}function fr(e,t){let{Type:r,Data:n}=$t.decode(e),o=n??new Uint8Array;switch(r){case st.RSA:return Ns(o,t);case st.Ed25519:return cs(o);case st.secp256k1:return zs(o);case st.ECDSA:return Uo(o);default:throw new Se}}function wc(e){let{Type:t,Data:r}=$t.decode(e.digest),n=r??new Uint8Array;switch(t){case st.Ed25519:return cs(n);case st.secp256k1:return zs(n);case st.ECDSA:return Uo(n);default:throw new Se}}function qt(e){return $t.encode({Type:st[e.type],Data:e.raw})}var Zr;(function(e){let t;e.codec=()=>(t==null&&(t=Vt((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.publicKey!=null&&r.publicKey.byteLength>0&&(n.uint32(10),n.bytes(r.publicKey)),r.payloadType!=null&&r.payloadType.byteLength>0&&(n.uint32(18),n.bytes(r.payloadType)),r.payload!=null&&r.payload.byteLength>0&&(n.uint32(26),n.bytes(r.payload)),r.signature!=null&&r.signature.byteLength>0&&(n.uint32(42),n.bytes(r.signature)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={publicKey:ht(0),payloadType:ht(0),payload:ht(0),signature:ht(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.publicKey=r.bytes();break}case 2:{s.payloadType=r.bytes();break}case 3:{s.payload=r.bytes();break}case 5:{s.signature=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Mt(r,e.codec()),e.decode=(r,n)=>kt(r,e.codec(),n)})(Zr||(Zr={}));var Kn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Gt=class e{static createFromProtobuf=t=>{let r=Zr.decode(t),n=fr(r.publicKey);return new e({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(t,r,n)=>{if(r==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),c=Ec(o,s,i),a=await r.sign(c.subarray(),n);return new e({publicKey:r.publicKey,payloadType:s,payload:i,signature:a})};static openAndCertify=async(t,r,n)=>{let o=e.createFromProtobuf(t);if(!await o.validate(r,n))throw new Kn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:r,payloadType:n,payload:o,signature:s}=t;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Zr.encode({publicKey:qt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:ut(this.marshal(),t.marshal())}async validate(t,r){let n=Ec(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Ec=(e,t,r)=>{let n=V(e),o=or(n.byteLength),s=or(t.length),i=or(r.length);return new it(o,n,s,t,i,r)};var vc=Symbol.for("nodejs.util.inspect.custom"),ud=114,Yr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[ao]=!0;toString(){return this.string==null&&(this.string=ot.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ct.createV1(ud,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ut(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ut(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[vc](){return`PeerId(${this.toString()})`}},Wr=class extends Yr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},jr=class extends Yr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Xr=class extends Yr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},fd=2336,Qr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Nt.digest(V(this.url))}[vc](){return`PeerId(${this.url})`}[ao]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(fd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};var ld=114,Sc=2336;function Ic(e){if(e.type==="Ed25519")return new jr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Xr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Wr({multihash:e.toCID().multihash,publicKey:e});throw new Se}function $s(e){if(hd(e))return new Wr({multihash:e});if(dd(e))try{let t=wc(e);if(t.type==="Ed25519")return new jr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Xr({multihash:e,publicKey:t})}catch{let r=H(e.digest);return new Qr(new URL(r))}throw new fn("Supplied PeerID Multihash is invalid")}function kn(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==ld&&e.code!==Sc)throw new un("Supplied PeerID CID is invalid");if(e.code===Sc){let t=H(e.multihash.digest);return new Qr(new URL(t))}return $s(e.multihash)}function dd(e){return e.code===Nt.code}function hd(e){return e.code===Cr.code}var mt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ue=class extends Error{static name="ValidationError";name="ValidationError"},Mn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Vn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Fn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let f=Number.parseInt(d,t);if(!Number.isNaN(f))return f});if(l===void 0)break;if(s*=t,s+=l,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&a&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[c]=t(s.subarray(0,i));return r.set(s.subarray(0,c),16-c),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ac=45,pd=15,lr=new Fn;function Hn(e){if(!(e.length>pd))return lr.new(e).parseWith(()=>lr.readIPv4Addr())}function qn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Ac))return lr.new(e).parseWith(()=>lr.readIPv6Addr())}function dr(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>Ac)return;let r=lr.new(e).parseWith(()=>lr.readIPAddr());if(r)return t&&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 hr(e){return!!Hn(e)}function zn(e){return!!qn(e)}function Zs(e){return t=>H(t,e)}function Ys(e){return t=>V(t,e)}function pr(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Re(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function _c(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=V(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Re(n);return Yt([r,o],r.length+o.length)}function Cc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=de.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Re(n);return Yt([r,o],r.length+o.length)}function Ws(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=H(t,"base32"),o=pr(r);return`${n}:${o}`}var js=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new mt("Invalid byte value in IP address");t[n]=o}),t},Bc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=hr(r[n]),i;s&&(i=js(r[n]),r[n]=H(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,H(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new mt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Pc=function(e){if(e.byteLength!==4)throw new mt("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Tc=function(e){if(e.byteLength!==16)throw new mt("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new mt(`Invalid IPv6 address "${r}"`)}};function Dc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new mt(`Invalid IPv6 address "${e}"`)}}var Gs=Object.values(Br).map(e=>e.decoder),md=(function(){let e=Gs[0].or(Gs[1]);return Gs.slice(2).forEach(t=>e=e.or(t)),e})();function Lc(e){return md.decode(e)}function Oc(e){return t=>e.encoder.encode(t)}function yd(e){if(parseInt(e).toString()!==e)throw new ue("Value must be an integer")}function bd(e){if(e<0)throw new ue("Value must be a positive integer, or zero")}function gd(e){return t=>{if(t>e)throw new ue(`Value must be smaller than or equal to ${e}`)}}function xd(...e){return t=>{for(let r of e)r(t)}}var Jr=xd(yd,bd,gd(65535));var dt=-1,Xs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Vn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},fe=new Xs,Rd=[{code:4,name:"ip4",size:32,valueToBytes:js,bytesToValue:Pc,validate:e=>{if(!hr(e))throw new ue(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Re,bytesToValue:pr,validate:Jr},{code:273,name:"udp",size:16,valueToBytes:Re,bytesToValue:pr,validate:Jr},{code:33,name:"dccp",size:16,valueToBytes:Re,bytesToValue:pr,validate:Jr},{code:41,name:"ip6",size:128,valueToBytes:Bc,bytesToValue:Tc,stringToValue:Dc,validate:e=>{if(!zn(e))throw new ue(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:dt},{code:43,name:"ipcidr",size:8,bytesToValue:Zs("base10"),valueToBytes:Ys("base10")},{code:53,name:"dns",size:dt},{code:54,name:"dns4",size:dt},{code:55,name:"dns6",size:dt},{code:56,name:"dnsaddr",size:dt},{code:132,name:"sctp",size:16,valueToBytes:Re,bytesToValue:pr,validate:Jr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:dt,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:dt,bytesToValue:Zs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Ys("base58btc")(e):ct.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ws,valueToBytes:_c},{code:445,name:"onion3",size:296,bytesToValue:Ws,valueToBytes:Cc},{code:446,name:"garlic64",size:dt},{code:447,name:"garlic32",size:dt},{code:448,name:"tls"},{code:449,name:"sni",size:dt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:dt,bytesToValue:Oc(So),valueToBytes:Lc},{code:480,name:"http"},{code:481,name:"http-path",size:dt,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:dt}];Rd.forEach(e=>{fe.addProtocol(e)});function Rc(e){let t=[],r=0;for(;r<e.length;){let n=Hr(e,r),o=fe.getProtocol(n),s=Ct(n),i=Nd(o,e,r+s),c=0;i>0&&o.size===dt&&(c=Ct(i));let a=s+c+i,u={code:n,name:o.name,bytes:e.subarray(r,r+a)};if(i>0){let l=r+s+c,d=e.subarray(l,l+i);u.value=o.bytesToValue?.(d)??H(d)}t.push(u),r+=a}return t}function Nc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=fe.getProtocol(n.code),s=Ct(n.code),i,c=0,a=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),c=i.byteLength,o.size===dt&&(a=Ct(c)));let u=new Uint8Array(s+a+c),l=0;nr(n.code,u,l),l+=s,i!=null&&(o.size===dt&&(nr(c,u,l),l+=a),u.set(i,l)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Yt(r,t)}function Uc(e){if(e.charAt(0)!=="/")throw new mt('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let c=s===e.length-1;if(i==="/"||c){let a=fe.getProtocol(o);if(r==="protocol"){if(a.size==null||a.size===0){t.push({code:a.code,name:a.name}),n="",o="",r="protocol";continue}else if(c)throw new mt(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new mt(`Component ${o} was missing value`);u.value=a.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new mt("Incomplete multiaddr");return t}function Kc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=fe.getProtocol(t.code);if(r==null)throw new mt(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Nd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Hr(t,r)}var Ud=Symbol.for("nodejs.util.inspect.custom"),di=Symbol.for("@multiformats/multiaddr");function Kd(e){if(e==null&&(e="/"),kc(e))return e.getComponents();if(e instanceof Uint8Array)return Rc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Uc(e);if(Array.isArray(e))return e;throw new mt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Wn=class e{[di]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Kd(t),r.validate!==!1&&kd(this)}get bytes(){return this.#r==null&&(this.#r=Nc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Kc(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Mn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return ut(this.bytes,t.bytes)}[Ud](){return`Multiaddr(${this.toString()})`}};function kd(e){e.getComponents().forEach(t=>{let r=fe.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function kc(e){return!!e?.[di]}function Ke(e){return new Wn(e)}var Mc="libp2p-peer-record",Vc=Uint8Array.from([3,1]);var en;(function(e){let t;(function(n){let o;n.codec=()=>(o==null&&(o=Vt((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={multiaddr:ht(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:{a.multiaddr=s.bytes();break}default:{s.skipType(l&7);break}}}return a})),o),n.encode=s=>Mt(s,n.codec()),n.decode=(s,i)=>kt(s,n.codec(),i)})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=Vt((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(o.uint32(10),o.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(o.uint32(16),o.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)o.uint32(26),e.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId:ht(0),seq:0n,addresses:[]},c=o==null?n.len:n.pos+o;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new Oe('Decode error - map field "addresses" had too many elements');i.addresses.push(e.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(a&7);break}}}return i})),r),e.encode=n=>Mt(n,e.codec()),e.decode=(n,o)=>kt(n,e.codec(),o)})(en||(en={}));function Fc(e,t){let r=(n,o)=>n.toString().localeCompare(o.toString());return e.length!==t.length?!1:(t.sort(r),e.sort(r).every((n,o)=>t[o].equals(n)))}var Ft=class e{static createFromProtobuf=t=>{let r=en.decode(t),n=$s(Ar(r.peerId)),o=(r.addresses??[]).map(i=>Ke(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Mc;static CODEC=Vc;peerId;multiaddrs;seqNumber;domain=e.DOMAIN;codec=e.CODEC;marshaled;constructor(t){let{peerId:r,multiaddrs:n,seqNumber:o}=t;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=en.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof e)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!Fc(this.multiaddrs,t.multiaddrs))}};function jn(e){let t=e.getComponents(),r={},n=0;if(t[n]?.name==="ip6zone"&&(r.zone=`${t[n].value}`,n++),t[n].name==="ip4"||t[n].name==="ip6"||t[n].name==="dns"||t[n].name==="dns4"||t[n].name==="dns6"?(r.type=t[n].name,r.host=t[n].value,n++):t[n].name==="dnsaddr"&&(r.type=t[n].name,r.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(r.protocol=t[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${t[n].value}`):r.type==="ip6"&&(r.cidr=`${t[n].value}`),n++),r.type==null||r.host==null)throw new Q(`Multiaddr ${e} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(r.sni=t[n+1].value,n+=2),r}function Hc(e,t,r){let n=0;for(let o of e)if(!(n<t)){if(n>r)break;if(o!==255)return!1;n++}return!0}function qc(e,t,r,n){let o=0;for(let s of e)if(!(o<r)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function hi(e){switch(e.length){case ke:return e.join(".");case Me:{let t=[];for(let r=0;r<e.length;r++)r%2===0&&t.push(e[r].toString(16).padStart(2,"0")+e[r+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function zc(e){let t=0;for(let[r,n]of e.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<e.length;o++)if(e[o]!=0)return-1;break}return t}function $c(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var ke=4,Me=16,sx=parseInt("0xFFFF",16),Md=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function rn(e,t){t.length===Me&&e.length===ke&&Hc(t,0,11)&&(t=t.slice(12)),t.length===ke&&e.length===Me&&qc(e,Md,0,11)&&(e=e.slice(12));let r=e.length;if(r!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=e[o]&t[o];return n}function Gc(e,t){if(typeof t=="string"&&(t=dr(t)),t==null)throw new Error("Invalid ip");if(t.length!==e.network.length)return!1;for(let r=0;r<t.length;r++)if((e.network[r]&e.mask[r])!==(t[r]&e.mask[r]))return!1;return!0}function pi(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=ke,o=Hn(t);if(o==null&&(n=Me,o=qn(t),o==null))throw new Error("Failed to parse given CIDR: "+e);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: "+e);let i=mi(s,8*n);return{network:rn(o,i),mask:i}}function mi(e,t){if(t!==8*ke&&t!==8*Me)throw new Error("Invalid CIDR mask");if(e<0||e>t)throw new Error("Invalid CIDR mask");let r=t/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(e>=8){n[o]=255,e-=8;continue}n[o]=255-(255>>e),e=0}return n}var nn=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=pi(t));else{let n=dr(t);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=dr(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=mi(o,8*n.length);this.network=rn(n,this.mask)}}contains(t){return Gc({network:this.network,mask:this.mask},t)}toString(){let t=zc(this.mask),r=t!==-1?String(t):$c(this.mask);return hi(this.network)+"/"+r}};function Zc(e,t){return new nn(e).contains(t)}function Yc(e){try{let t=jn(e);switch(t.type){case"ip6":return Zc("2000::/3",t.host);default:return!1}}catch{return!1}}var jc=Au(Wc(),1),Vd=["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"],Fd=Vd.map(e=>new jc.Netmask(e));function yi(e){for(let t of Fd)if(t.contains(e))return!0;return!1}function Hd(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function qd(e){let t=e.split(":");if(t.length<2)return!1;let r=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return yi(o)}function zd(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function $d(e){let t=e.split(":"),r=t[t.length-1];return yi(r)}function Gd(e){return/^::$/.test(e)||/^::1$/.test(e)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(e)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(e)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(e)||/^ff([0-9a-fA-F]{2,2}):/i.test(e)}function Xc(e){if(hr(e))return yi(e);if(Hd(e))return qd(e);if(zd(e))return $d(e);if(zn(e))return Gd(e)}function Qc(e){try{let t=jn(e);switch(t.type){case"ip4":case"ip6":return Xc(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function xr(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var bi=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},gi=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Jc=e=>globalThis.DOMException===void 0?new gi(e):new DOMException(e),tu=e=>{let t=e.reason===void 0?Jc("This operation was aborted."):e.reason;return t instanceof Error?t:Jc(t)};function xi(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,u=new Promise((l,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:h}=t;h.aborted&&d(tu(h)),c=()=>{d(tu(h))},h.addEventListener("abort",c,{once:!0})}if(r===Number.POSITIVE_INFINITY){e.then(l,d);return}let f=new bi;i=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(h){d(h)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?d(o):(f.message=o??`Promise timed out after ${r} milliseconds`,d(f))},r),(async()=>{try{l(await e)}catch(h){d(h)}})()}).finally(()=>{u.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return u.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},u}var Zd=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function Yd(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let c=[t].flat(),a=[],{addListener:u,removeListener:l}=Zd(e),d=(...h)=>{let p=r.multiArgs?h:h[0];r.filter&&!r.filter(p)||(a.push(p),r.count===a.length&&(n(),s(a)))},f=h=>{n(),i(h)};n=()=>{for(let h of c)l(h,d);for(let h of r.rejectionEvents)l(h,f)};for(let h of c)u(h,d);for(let h of r.rejectionEvents)u(h,f);r.signal&&r.signal.addEventListener("abort",()=>{f(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(a)});if(o.cancel=n,typeof r.timeout=="number"){let s=xi(o,{milliseconds:r.timeout});return s.cancel=n,s}return o}function eu(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Yd(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function ru(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Ve=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Wd(e){return e.reason}async function nu(e,t,r){if(t==null)return e;let n=r?.translateError??Wd;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var Xd=4194304,Xn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ei=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},vi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Si=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Qd(e){return typeof e?.closeRead=="function"}function Jd(e){return typeof e?.close=="function"}function wi(e){return Qd(e)?e.readStatus==="closing"||e.readStatus==="closed":Jd(e)?e.status!=="open":!1}function th(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function eh(e,t){let r=t?.maxBufferSize??Xd,n=new it,o=Promise.withResolvers(),s=!1;if(!th(e))throw new Q("Argument should be a Stream or a Multiaddr");let i=l=>{if(n.append(l.data),n.byteLength>r){let d=n.byteLength;n.consume(n.byteLength),o.reject(new Error(`Read buffer overflow - ${d} > ${r}`))}o.resolve()};e.addEventListener("message",i);let c=l=>{l.error!=null?o.reject(l.error):o.resolve()};e.addEventListener("close",c);let a=()=>{o.resolve()};e.addEventListener("remoteCloseWrite",a);let u={readBuffer:n,async read(l){if(s===!0)throw new Xn("Stream was unwrapped");if(wi(e)){if(l?.bytes==null)return null;if(n.byteLength<l.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new Ve(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let d=l?.bytes??1;for(;;){if(n.byteLength>=d){o.resolve();break}if(await nu(o.promise,l?.signal),wi(e)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let f=l?.bytes??n.byteLength;if(n.byteLength<f){if(wi(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,f),new Ve(`Unexpected EOF - stream closed while reading ${n.byteLength}/${f} bytes`);return u.read(l)}let h=n.sublist(0,f);return n.consume(f),h},async write(l,d){if(s===!0)throw new Xn("Stream was unwrapped");e.send(l)||await eu(e,"drain",{signal:d?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",a),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return u}function rh(e,t={}){let r=eh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Ct(t.maxDataLength));let n=t?.lengthDecoder??Hr,o=t?.lengthEncoder??or;return{async read(i){let c=-1,a=new it;for(;;){let l=await r.read({...i,bytes:1});if(l==null)break;a.append(l);try{c=n(a)}catch(d){if(d instanceof RangeError)continue;throw d}if(c<0)throw new Ei("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new Si(`Message length length too long - ${a.byteLength} > ${t.maxLengthLength}`);if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new vi(`Message length too long - ${c} > ${t.maxDataLength}`);let u=await r.read({...i,bytes:c});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",c),new Ve(`Unexpected EOF - tried to read ${c} bytes but the stream closed`);if(u.byteLength!==c)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,c),new Ve(`Unexpected EOF - read ${u.byteLength}/${c} bytes before the stream closed`);return u},async write(i,c){await r.write(new it(o(i.byteLength),i),c)},async writeV(i,c){let a=new it(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(a,c)},unwrap(){return r.unwrap()}}}function wr(e,t){let r=rh(e,t),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(c=>s.encode(c)),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 nh(e){return e[Symbol.asyncIterator]!=null}function oh(e){if(nh(e))return(async()=>{for await(let t of e);})();for(let t of e);}var ou=oh;var Qn=globalThis.CustomEvent??Event;async function*Ii(e,t={}){let r=t.concurrency??1/0;r<1&&(r=1/0);let n=t.ordered??!1,o=new EventTarget,s=[],i=xr(),c=xr(),a=!1,u,l=!1;o.addEventListener("task-complete",()=>{c.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of e){if(s.length===r&&(i=xr(),await i.promise),l)break;let g={done:!1};s.push(g),p().then(S=>{g.done=!0,g.ok=!0,g.value=S,o.dispatchEvent(new Qn("task-complete"))},S=>{g.done=!0,g.err=S,o.dispatchEvent(new Qn("task-complete"))})}a=!0,o.dispatchEvent(new Qn("task-complete"))}catch(p){u=p,o.dispatchEvent(new Qn("task-complete"))}});function d(){return n?s[0]?.done:!!s.find(p=>p.done)}function*f(){for(;s.length>0&&s[0].done;){let p=s[0];if(s.shift(),p.ok)yield p.value;else throw l=!0,i.resolve(),p.err;i.resolve()}}function*h(){for(;d();)for(let p=0;p<s.length;p++)if(s[p].done){let g=s[p];if(s.splice(p,1),p--,g.ok)yield g.value;else throw l=!0,i.resolve(),g.err;i.resolve()}}for(;;){if(d()||(c=xr(),await c.promise),u!=null||(n?yield*f():yield*h(),u!=null))throw u;if(a&&s.length===0)break}}var su="0.1.0";var iu="id/push",au="1.0.0",cu="1.0.0";var ve;(function(e){let t;e.codec=()=>(t==null&&(t=Vt((r,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),r.protocolVersion!=null&&(n.uint32(42),n.string(r.protocolVersion)),r.agentVersion!=null&&(n.uint32(50),n.string(r.agentVersion)),r.publicKey!=null&&(n.uint32(10),n.bytes(r.publicKey)),r.listenAddrs!=null)for(let s of r.listenAddrs)n.uint32(18),n.bytes(s);if(r.observedAddr!=null&&(n.uint32(34),n.bytes(r.observedAddr)),r.protocols!=null)for(let s of r.protocols)n.uint32(26),n.string(s);r.signedPeerRecord!=null&&(n.uint32(66),n.bytes(r.signedPeerRecord)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={listenAddrs:[],protocols:[]},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 5:{s.protocolVersion=r.string();break}case 6:{s.agentVersion=r.string();break}case 1:{s.publicKey=r.bytes();break}case 2:{if(o.limits?.listenAddrs!=null&&s.listenAddrs.length===o.limits.listenAddrs)throw new Oe('Decode error - map field "listenAddrs" had too many elements');s.listenAddrs.push(r.bytes());break}case 4:{s.observedAddr=r.bytes();break}case 3:{if(o.limits?.protocols!=null&&s.protocols.length===o.limits.protocols)throw new Oe('Decode error - map field "protocols" had too many elements');s.protocols.push(r.string());break}case 8:{s.signedPeerRecord=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Mt(r,e.codec()),e.decode=(r,n)=>kt(r,e.codec(),n)})(ve||(ve={}));var Bt={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function uu(e){if(e!=null&&e.length>0)try{return Ke(e)}catch{}}async function Jn(e,t,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new Rt("message was null or undefined");let s={};if(o.listenAddrs.length>0&&(s.addresses=o.listenAddrs.map(a=>({isCertified:!1,multiaddr:Ke(a)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let a=fr(o.publicKey);if(!Ic(a).equals(n.remotePeer))throw new Rt("public key did not match remote PeerId");s.publicKey=a}let i;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let a=o.signedPeerRecord,u=await Gt.openAndCertify(a,Ft.DOMAIN),l=Ft.createFromProtobuf(u.payload),d=kn(u.publicKey.toCID());if(!l.peerId.equals(d))throw new Rt("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(l.peerId))throw new Rt("signing key does not match remote PeerId");let f;try{f=await e.get(l.peerId)}catch(h){if(h.name!=="NotFoundError")throw h}if(f!=null&&(s.metadata=f.metadata,f.peerRecordEnvelope!=null)){let h=Gt.createFromProtobuf(f.peerRecordEnvelope),p=Ft.createFromProtobuf(h.payload);p.seqNumber>=l.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",p.seqNumber,l.seqNumber),l=p,a=f.peerRecordEnvelope)}s.peerRecordEnvelope=a,s.addresses=l.multiaddrs.map(h=>({isCertified:!0,multiaddr:h})),i={seq:l.seqNumber,addresses:l.multiaddrs}}else r("%p did not send a signed peer record",n.remotePeer);if(r.trace("patching %p with",n.remotePeer,s),await e.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let a={};o.agentVersion!=null&&(a.AgentVersion=V(o.agentVersion)),o.protocolVersion!=null&&(a.ProtocolVersion=V(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,a),await e.merge(n.remotePeer,{metadata:a})}let c={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:o.listenAddrs.map(a=>Ke(a)),observedAddr:o.observedAddr==null?void 0:Ke(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:c}),c}var Er=class{host;components;protocol;started;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;runOnLimitedConnection;log;constructor(t,r){this.protocol=r.protocol,this.started=!1,this.components=t,this.log=r.log,this.timeout=r.timeout??Bt.timeout,this.maxInboundStreams=r.maxInboundStreams??Bt.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Bt.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Bt.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Bt.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Bt.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Bt.protocolPrefix}/${su}`,agentVersion:t.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 to=class extends Er{connectionManager;concurrency;_push;constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??Bt.protocolPrefix}/${iu}/${cu}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=r.concurrency??Bt.concurrency,this._push=ru(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Bt.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[ln]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let t=this.components.addressManager.getAddresses().map(l=>l.decapsulateCode(421)),r=new Ft({peerId:this.components.peerId,multiaddrs:t}),n=await Gt.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=H(s.metadata.get("AgentVersion")??V(this.host.agentVersion)),c=H(s.metadata.get("ProtocolVersion")??V(this.host.protocolVersion)),a=this;async function*u(){for(let l of a.connectionManager.getConnections())(await a.components.peerStore.get(l.remotePeer)).protocols.includes(a.protocol)&&(yield async()=>{let f,h=AbortSignal.timeout(a.timeout);try{f=await l.newStream(a.protocol,{signal:h,runOnLimitedConnection:a.runOnLimitedConnection}),await wr(f,{maxDataLength:a.maxMessageSize}).pb(ve).write({listenAddrs:t.map(g=>g.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:c},{signal:h}),await f.close({signal:h})}catch(p){f?.log.newScope("identify-push")?.error("could not push identify update to peer",p),f?.abort(p)}})}await ou(Ii(u(),{concurrency:this.concurrency}))}catch(t){this.log.error("error pushing updates to peers - %e",t)}}async handleProtocol(t,r){let n=t.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)},i=await wr(t,{maxDataLength:this.maxMessageSize}).pb(ve).read(o);await t.close(o),await Jn(this.components.peerStore,this.components.events,n,r,i),n.trace("handled push from %p",r.remotePeer)}};var W=e=>({match:t=>{let r=t[0];return r==null||r.code!==e||r.value!=null?!1:t.slice(1)}}),L=(e,t)=>({match:r=>{let n=r[0];return n?.code!==e||n.value==null||t!=null&&n.value!==t?!1:r.slice(1)}}),fu=e=>({match:t=>e.match(t)===!1?t:!1}),F=e=>({match:t=>{let r=e.match(t);return r===!1?t:r}}),xt=(...e)=>({match:t=>{let r;for(let n of e){let o=n.match(t);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),G=(...e)=>({match:t=>{for(let r of e){let n=r.match(t);if(n===!1)return!1;t=n}return t}});function j(...e){function t(o){if(o==null)return!1;let s=o.getComponents();for(let i of e){let c=i.match(s);if(c===!1)return!1;s=c}return s}function r(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:e,matches:r,exactMatch:n}}var ch=L(421),Vw=j(ch),ro=L(54),no=L(55),oo=L(56),_i=L(53),Fw=j(ro,F(L(421))),Hw=j(no,F(L(421))),qw=j(oo,F(L(421))),zw=j(xt(_i,oo,ro,no),F(L(421))),lu=G(L(4),F(L(43))),du=G(F(L(42)),L(41),F(L(43))),Ci=xt(lu,du),Fe=xt(Ci,_i,ro,no,oo),hu=j(xt(Ci,G(xt(_i,oo,ro,no),F(L(421))))),$w=j(lu),Gw=j(du),Zw=j(Ci),Bi=G(Fe,L(6)),sn=G(Fe,L(273)),pu=j(G(Bi,F(L(421)))),Yw=j(sn),Pi=G(sn,W(460),F(L(421))),so=G(sn,W(461),F(L(421))),uh=xt(Pi,so),Ww=j(Pi),jw=j(so),Ai=xt(Fe,Bi,sn,Pi,so),mu=xt(G(Ai,W(477),F(L(421)))),Xw=j(mu),yu=xt(G(Ai,W(478),F(L(421))),G(Ai,W(448),F(L(449)),W(477),F(L(421)))),Qw=j(yu),bu=G(sn,W(280),F(L(466)),F(L(466)),F(L(421))),Jw=j(bu),gu=G(so,W(465),F(L(466)),F(L(466)),F(L(421))),t2=j(gu),eo=xt(mu,yu,G(Bi,F(L(421))),G(uh,F(L(421))),G(Fe,F(L(421))),bu,gu,L(421)),e2=j(eo),fh=G(F(eo),W(290),fu(W(281)),F(L(421))),r2=j(fh),lh=xt(G(eo,W(290),W(281),F(L(421))),G(eo,W(281),F(L(421))),G(W(281),F(L(421)))),n2=j(lh),dh=xt(G(Fe,L(6),W(480),F(L(421))),G(Fe,W(480),F(L(421)))),o2=j(dh),hh=G(Fe,xt(G(L(6,"443"),W(480)),G(L(6),W(443)),G(L(6),W(448),W(480)),G(W(448),W(480)),W(448),W(443)),F(L(421))),s2=j(hh),ph=xt(G(L(777),F(L(421)))),i2=j(ph),mh=xt(G(L(400),F(L(421)))),a2=j(mh);var io=class extends Er{constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??Bt.protocolPrefix}/${"id"}/${au}`,log:t.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Bt.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[ln]=["@libp2p/identify"];async _identify(t,r={}){let n,o;if(r.signal==null){let s=AbortSignal.timeout(this.timeout);r={...r,signal:s}}try{n=await t.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),o=n.log.newScope("identify");let s=wr(n,{maxDataLength:this.maxMessageSize}).pb(ve);o("read response");let i=await s.read(r);return o("close write"),await s.unwrap().unwrap().close(r),i}catch(s){throw o?.error("identify failed - %e",s),n?.abort(s),s}}async identify(t,r={}){let n=await this._identify(t,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Rt("Public key was missing from identify message");let c=fr(o),a=kn(c.toCID());if(!t.remotePeer.equals(a))throw new Rt("Identified peer does not match the expected peer");if(this.components.peerId.equals(a))throw new Rt("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",a,s),Jn(this.components.peerStore,this.components.events,this.log,t,n)}maybeAddObservedAddress(t){let r=uu(t);if(r==null||(this.log.trace("our observed address was %a",r),Qc(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Yc(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}pu.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(t,r){let n=t.log.newScope("identify"),o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(l=>l.decapsulateCode(421)),c=s.peerRecordEnvelope;if(i.length>0&&c==null){let l=new Ft({peerId:this.components.peerId,multiaddrs:i});c=(await Gt.seal(l,this.components.privateKey,{signal:o})).marshal().subarray()}let a=r.remoteAddr.bytes;hu.matches(r.remoteAddr)||(a=void 0);let u=wr(t).pb(ve);n("send response"),await u.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:qt(this.components.privateKey.publicKey),listenAddrs:i.map(l=>l.bytes),signedPeerRecord:c,observedAddr:a,protocols:s.protocols},{signal:o}),n("close write"),await u.unwrap().unwrap().close({signal:o})}};function bh(e={}){return t=>new io(t,e)}function gh(e={}){return t=>new to(t,e)}return _u(xh);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js: