@libp2p/identify 3.0.33-ae595d8db → 3.0.34-7eed3b40d

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 Ec=Object.create;var Fr=Object.defineProperty;var Sc=Object.getOwnPropertyDescriptor;var vc=Object.getOwnPropertyNames;var Ac=Object.getPrototypeOf,Ic=Object.prototype.hasOwnProperty;var Bc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),gt=(e,t)=>{for(var r in t)Fr(e,r,{get:t[r],enumerable:!0})},Ms=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of vc(t))!Ic.call(e,o)&&o!==r&&Fr(e,o,{get:()=>t[o],enumerable:!(n=Sc(t,o))||n.enumerable});return e};var _c=(e,t,r)=>(r=e!=null?Ec(Ac(e)):{},Ms(t||!e||!e.__esModule?Fr(r,"default",{value:e,enumerable:!0}):r,e)),Pc=e=>Ms(Fr({},"__esModule",{value:!0}),e);var cc=Bc(Or=>{(function(){var e,t,r,n,o,s,i,a;a=function(c){var u,f,l,d;return u=(c&255<<24)>>>24,f=(c&255<<16)>>>16,l=(c&65280)>>>8,d=c&255,[u,f,l,d].join(".")},i=function(c){var u,f,l,d,h,m;for(u=[],l=d=0;d<=3&&c.length!==0;l=++d){if(l>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}m=t(c),h=m[0],f=m[1],c=c.substring(f),u.push(h)}if(c.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(c){return c.charCodeAt(0)},n=r("0"),s=r("a"),o=r("A"),t=function(c){var u,f,l,d,h;for(d=0,u=10,f="9",l=0,c.length>1&&c[l]==="0"&&(c[l+1]==="x"||c[l+1]==="X"?(l+=2,u=16):"0"<=c[l+1]&&c[l+1]<="9"&&(l++,u=8,f="7")),h=l;l<c.length;){if("0"<=c[l]&&c[l]<=f)d=d*u+(r(c[l])-n)>>>0;else if(u===16)if("a"<=c[l]&&c[l]<="f")d=d*u+(10+r(c[l])-s)>>>0;else if("A"<=c[l]&&c[l]<="F")d=d*u+(10+r(c[l])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");l++}if(l===h)throw new Error("empty octet");return[d,l]},e=function(){function c(u,f){var l,d,h,m;if(typeof u!="string")throw new Error("Missing `net' parameter");if(f||(m=u.split("/",2),u=m[0],f=m[1]),f||(f=32),typeof f=="string"&&f.indexOf(".")>-1){try{this.maskLong=i(f)}catch(w){throw l=w,new Error("Invalid mask: "+f)}for(d=h=32;h>=0;d=--h)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;break}}else if(f||f===0)this.bitmask=parseInt(f,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(w){throw l=w,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+f);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var f,l,d;for(d=i(this.first),l=i(this.last),f=0;d<=l;)u(a(d),d,f),f++,d++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),Or.ip2long=i,Or.long2ip=a,Or.Netmask=e}).call(Or)});var Xl={};gt(Xl,{identify:()=>Wl,identifyPush:()=>Yl});var Hn=Symbol.for("@libp2p/peer-id");var nt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ce=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Vr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},qr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}},Hr=class extends Error{static name="UnsupportedProtocolError";constructor(t="Unsupported protocol error"){super(t),this.name="UnsupportedProtocolError"}},_t=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var de=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var zr=Symbol.for("@libp2p/service-capabilities"),ed=Symbol.for("@libp2p/service-dependencies");var Zn={};gt(Zn,{base58btc:()=>G,base58flickr:()=>Uc});var vd=new Uint8Array(0);function Fs(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 Gt(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 Vs(e){return new TextEncoder().encode(e)}function qs(e){return new TextDecoder().decode(e)}function Tc(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,c=e.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var w=0,g=0,v=0,T=m.length;v!==T&&m[v]===0;)v++,w++;for(var I=(T-v)*f+1>>>0,D=new Uint8Array(I);v!==T;){for(var b=m[v],L=0,C=I-1;(b!==0||L<g)&&C!==-1;C--,L++)b+=256*D[C]>>>0,D[C]=b%a>>>0,b=b/a>>>0;if(b!==0)throw new Error("Non-zero carry");g=L,v++}for(var B=I-g;B!==I&&D[B]===0;)B++;for(var p=c.repeat(w);B<I;++B)p+=e.charAt(D[B]);return p}function d(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var w=0;if(m[w]!==" "){for(var g=0,v=0;m[w]===c;)g++,w++;for(var T=(m.length-w)*u+1>>>0,I=new Uint8Array(T);m[w];){var D=r[m.charCodeAt(w)];if(D===255)return;for(var b=0,L=T-1;(D!==0||b<v)&&L!==-1;L--,b++)D+=a*I[L]>>>0,I[L]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");v=b,w++}if(m[w]!==" "){for(var C=T-v;C!==T&&I[C]===0;)C++;for(var B=new Uint8Array(g+(T-C)),p=g;C!==T;)B[p++]=I[C++];return B}}}function h(m){var w=d(m);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:h}}var Cc=Tc,Lc=Cc,zs=Lc;var zn=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")}},Gn=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 Gs(this,t)}},$n=class{decoders;constructor(t){this.decoders=t}or(t){return Gs(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 Gs(e,t){return new $n({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var jn=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 zn(t,r,n),this.decoder=new Gn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Le({name:e,prefix:t,encode:r,decode:n}){return new jn(e,t,r,n)}function ee({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=zs(r,e);return Le({prefix:t,name:e,encode:n,decode:s=>Gt(o(s))})}function Dc(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Rc(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Nc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function X({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Nc(n);return Le({prefix:t,name:e,encode(s){return Rc(s,n,r)},decode(s){return Dc(s,o,r,e)}})}var G=ee({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Uc=ee({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Wn={};gt(Wn,{base32:()=>$t,base32hex:()=>Mc,base32hexpad:()=>Vc,base32hexpadupper:()=>qc,base32hexupper:()=>Fc,base32pad:()=>Oc,base32padupper:()=>kc,base32upper:()=>Kc,base32z:()=>Hc});var $t=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Kc=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Oc=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kc=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Mc=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Fc=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Vc=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qc=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hc=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Yn={};gt(Yn,{base36:()=>sr,base36upper:()=>zc});var sr=ee({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zc=ee({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Gc=Zs,$s=128,$c=127,jc=~$c,Zc=Math.pow(2,31);function Zs(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Zc;)t[r++]=e&255|$s,e/=128;for(;e&jc;)t[r++]=e&255|$s,e>>>=7;return t[r]=e|0,Zs.bytes=r-n+1,t}var Wc=Xn,Yc=128,js=127;function Xn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw Xn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&js)<<o:(i&js)*Math.pow(2,o),o+=7}while(i>=Yc);return Xn.bytes=s-n,r}var Xc=Math.pow(2,7),Jc=Math.pow(2,14),Qc=Math.pow(2,21),tf=Math.pow(2,28),ef=Math.pow(2,35),rf=Math.pow(2,42),nf=Math.pow(2,49),of=Math.pow(2,56),sf=Math.pow(2,63),af=function(e){return e<Xc?1:e<Jc?2:e<Qc?3:e<tf?4:e<ef?5:e<rf?6:e<nf?7:e<of?8:e<sf?9:10},cf={encode:Gc,decode:Wc,encodingLength:af},ff=cf,ir=ff;function ar(e,t=0){return[ir.decode(e,t),ir.decode.bytes]}function De(e,t,r=0){return ir.encode(e,t,r),t}function Re(e){return ir.encodingLength(e)}function Pt(e,t){let r=t.byteLength,n=Re(e),o=n+Re(r),s=new Uint8Array(o+r);return De(e,s,0),De(r,s,n),s.set(t,o),new Ne(e,r,t,s)}function he(e){let t=Gt(e),[r,n]=ar(t),[o,s]=ar(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ne(r,o,i,t)}function Ws(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Fs(e.bytes,r.bytes)}}var Ne=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Ys(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return lf(r,Jn(e),t??G.encoder);default:return df(r,Jn(e),t??$t.encoder)}}var Xs=new WeakMap;function Jn(e){let t=Xs.get(e);if(t==null){let r=new Map;return Xs.set(e,r),r}return t}var rt=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!==cr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==hf)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=Pt(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&&Ws(t.multihash,n.multihash)}toString(t){return Ys(this,t)}toJSON(){return{"/":Ys(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??Js(n,o,s.bytes))}else if(r[pf]===!0){let{version:n,multihash:o,code:s}=r,i=he(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!==cr)throw new Error(`Version 0 CID must use dag-pb (code: ${cr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Js(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,cr,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=Gt(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 Ne(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,d]=ar(t.subarray(r));return r+=d,l},o=n(),s=cr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=uf(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 Jn(s).set(n,t),s}};function uf(e,t){switch(e[0]){case"Q":{let r=t??G;return[G.prefix,r.decode(`${G.prefix}${e}`)]}case G.prefix:{let r=t??G;return[G.prefix,r.decode(e)]}case $t.prefix:{let r=t??$t;return[$t.prefix,r.decode(e)]}case sr.prefix:{let r=t??sr;return[sr.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 lf(e,t,r){let{prefix:n}=r;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function df(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 cr=112,hf=18;function Js(e,t,r){let n=Re(e),o=n+Re(t),s=new Uint8Array(o+r.byteLength);return De(e,s,0),De(t,s,n),s.set(r,o),s}var pf=Symbol.for("@ipld/js-cid/CID");var Qn={};gt(Qn,{identity:()=>Tt});var Qs=0,mf="identity",ti=Gt;function yf(e){return Pt(Qs,ti(e))}var Tt={code:Qs,name:mf,encode:ti,digest:yf};function st(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 at(e=0){return new Uint8Array(e)}function xt(e=0){return new Uint8Array(e)}function St(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=xt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var ri=Symbol.for("@achingbrain/uint8arraylist");function ei(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 $r(e){return!!e?.[ri]}var Q=class e{bufs;length;[ri]=!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($r(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($r(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=ei(this.bufs,t);return r.buf[r.index]}set(t,r){let n=ei(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($r(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return St(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:St(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!$r(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let h=this.get(l+d);if(n[d]!==h){f=Math.max(1,d-a[h]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=xt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=at(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=at(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=at(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=xt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=at(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=at(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=at(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=at(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=at(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(!st(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 to={};gt(to,{base10:()=>bf});var bf=ee({prefix:"9",name:"base10",alphabet:"0123456789"});var eo={};gt(eo,{base16:()=>gf,base16upper:()=>xf});var gf=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),xf=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ro={};gt(ro,{base2:()=>wf});var wf=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var no={};gt(no,{base256emoji:()=>If});var ni=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}"),Ef=ni.reduce((e,t,r)=>(e[r]=t,e),[]),Sf=ni.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function vf(e){return e.reduce((t,r)=>(t+=Ef[r],t),"")}function Af(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Sf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var If=Le({prefix:"\u{1F680}",name:"base256emoji",encode:vf,decode:Af});var so={};gt(so,{base64:()=>Bf,base64pad:()=>_f,base64url:()=>oo,base64urlpad:()=>Pf});var Bf=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),_f=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),oo=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Pf=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var io={};gt(io,{base8:()=>Tf});var Tf=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ao={};gt(ao,{identity:()=>Cf});var Cf=Le({prefix:"\0",name:"identity",encode:e=>qs(e),decode:e=>Vs(e)});var ih=new TextEncoder,ah=new TextDecoder;var uo={};gt(uo,{sha256:()=>fr,sha512:()=>Rf});function fo({name:e,code:t,encode:r}){return new co(e,t,r)}var co=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?Pt(this.code,r):r.then(n=>Pt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function si(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var fr=fo({name:"sha2-256",code:18,encode:si("SHA-256")}),Rf=fo({name:"sha2-512",code:19,encode:si("SHA-512")});var ur={...ao,...ro,...io,...to,...eo,...Wn,...Yn,...Zn,...so,...no},xh={...uo,...Qn};function ai(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ii=ai("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),lo=ai("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=xt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Nf={utf8:ii,"utf-8":ii,hex:ur.base16,latin1:lo,ascii:lo,binary:lo,...ur},jr=Nf;function k(e,t="utf8"){let r=jr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function K(e,t="utf8"){let r=jr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Uf=parseInt("11111",2),ho=parseInt("10000000",2),Kf=parseInt("01111111",2),ci={0:lr,1:lr,2:Of,3:Ff,4:Vf,5:Mf,6:kf,16:lr,22:lr,48:lr};function jt(e,t={offset:0}){let r=e[t.offset]&Uf;if(t.offset++,ci[r]!=null)return ci[r](e,t);throw new Error("No decoder for tag "+r)}function dr(e,t){let r=0;if((e[t.offset]&ho)===ho){let n=e[t.offset]&Kf,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 lr(e,t){dr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=jt(e,t);if(n===null)break;r.push(n)}return r}function Of(e,t){let r=dr(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=dr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Mf(e,t){return t.offset++,null}function Ff(e,t){let r=dr(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=dr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function qf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Q;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function po(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=qf(e.byteLength);return new Q(Uint8Array.from([t.byteLength|ho]),t)}function wt(e){let t=new Q,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Q(Uint8Array.from([2]),po(t),t)}function Zr(e){let t=Uint8Array.from([0]),r=new Q(t,e);return new Q(Uint8Array.from([3]),po(r),r)}function ne(e,t=48){let r=new Q;for(let n of e)r.append(n);return new Q(Uint8Array.from([t]),po(r),r)}async function fi(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]),zf=Uint8Array.from([6,5,43,129,4,0,34]),Gf=Uint8Array.from([6,5,43,129,4,0,35]),$f={ext:!0,kty:"EC",crv:"P-256"},jf={ext:!0,kty:"EC",crv:"P-384"},Zf={ext:!0,kty:"EC",crv:"P-521"},mo=32,yo=48,bo=66;function go(e){let t=jt(e);return ui(t)}function ui(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===mo*2+1)return n=K(t.subarray(r,r+mo),"base64url"),o=K(t.subarray(r+mo),"base64url"),new Ue({...$f,key_ops:["verify"],x:n,y:o});if(t.byteLength===yo*2+1)return n=K(t.subarray(r,r+yo),"base64url"),o=K(t.subarray(r+yo),"base64url"),new Ue({...jf,key_ops:["verify"],x:n,y:o});if(t.byteLength===bo*2+1)return n=K(t.subarray(r,r+bo),"base64url"),o=K(t.subarray(r+bo),"base64url"),new Ue({...Zf,key_ops:["verify"],x:n,y:o});throw new nt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function li(e){return ne([wt(Uint8Array.from([1])),ne([Wf(e.crv)],160),ne([Zr(new Q(Uint8Array.from([4]),k(e.x??"","base64url"),k(e.y??"","base64url")))],161)]).subarray()}function Wf(e){if(e==="P-256")return Hf;if(e==="P-384")return zf;if(e==="P-521")return Gf;throw new nt(`Invalid curve ${e}`)}var Ue=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=li(this.jwk)),this._raw}toMultihash(){return Tt.digest(kt(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:st(this.raw,t.raw)}async verify(t,r,n){return fi(this.jwk,r,t,n)}};var pe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Oe(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function hr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ut(e,...t){if(!Oe(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 hi(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");hr(e.outputLen),hr(e.blockLen)}function ke(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 pi(e,t){ut(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Wt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Wr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ct(e,t){return e<<32-t|e>>>t}var mi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Yf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Mt(e){if(ut(e),mi)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Yf[e[r]];return t}var Zt={_0:48,_9:57,A:65,F:70,a:97,f:102};function di(e){if(e>=Zt._0&&e<=Zt._9)return e-Zt._0;if(e>=Zt.A&&e<=Zt.F)return e-(Zt.A-10);if(e>=Zt.a&&e<=Zt.f)return e-(Zt.a-10)}function Me(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(mi)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=di(e.charCodeAt(s)),a=di(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function yi(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function pr(e){return typeof e=="string"&&(e=yi(e)),ut(e),e}function vt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];ut(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 Ke=class{};function xo(e){let t=n=>e().update(pr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function mr(e=32){if(pe&&typeof pe.getRandomValues=="function")return pe.getRandomValues(new Uint8Array(e));if(pe&&typeof pe.randomBytes=="function")return Uint8Array.from(pe.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Xf(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?4:0,u=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+u,a,n)}function bi(e,t,r){return e&t^~e&r}function gi(e,t,r){return e&t^e&r^t&r}var yr=class extends Ke{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=Wr(this.buffer)}update(t){ke(this),t=pr(t),ut(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Wr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ke(this),pi(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Wt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;Xf(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Wr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Yt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ct=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Yr=BigInt(4294967295),xi=BigInt(32);function Jf(e,t=!1){return t?{h:Number(e&Yr),l:Number(e>>xi&Yr)}:{h:Number(e>>xi&Yr)|0,l:Number(e&Yr)|0}}function wi(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Jf(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var wo=(e,t,r)=>e>>>r,Eo=(e,t,r)=>e<<32-r|t>>>r,me=(e,t,r)=>e>>>r|t<<32-r,ye=(e,t,r)=>e<<32-r|t>>>r,br=(e,t,r)=>e<<64-r|t>>>r-32,gr=(e,t,r)=>e>>>r-32|t<<64-r;function Ft(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ei=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Si=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,vi=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ai=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ii=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Bi=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var tu=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),oe=new Uint32Array(64),Xr=class extends yr{constructor(t=32){super(64,t,8,!1),this.A=Yt[0]|0,this.B=Yt[1]|0,this.C=Yt[2]|0,this.D=Yt[3]|0,this.E=Yt[4]|0,this.F=Yt[5]|0,this.G=Yt[6]|0,this.H=Yt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)oe[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=oe[l-15],h=oe[l-2],m=Ct(d,7)^Ct(d,18)^d>>>3,w=Ct(h,17)^Ct(h,19)^h>>>10;oe[l]=w+oe[l-7]+m+oe[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Ct(a,6)^Ct(a,11)^Ct(a,25),h=f+d+bi(a,c,u)+tu[l]+oe[l]|0,w=(Ct(n,2)^Ct(n,13)^Ct(n,22))+gi(n,o,s)|0;f=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+w|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Wt(oe)}destroy(){this.set(0,0,0,0,0,0,0,0),Wt(this.buffer)}};var _i=wi(["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))),eu=_i[0],ru=_i[1],se=new Uint32Array(80),ie=new Uint32Array(80),So=class extends yr{constructor(t=64){super(128,t,16,!1),this.Ah=ct[0]|0,this.Al=ct[1]|0,this.Bh=ct[2]|0,this.Bl=ct[3]|0,this.Ch=ct[4]|0,this.Cl=ct[5]|0,this.Dh=ct[6]|0,this.Dl=ct[7]|0,this.Eh=ct[8]|0,this.El=ct[9]|0,this.Fh=ct[10]|0,this.Fl=ct[11]|0,this.Gh=ct[12]|0,this.Gl=ct[13]|0,this.Hh=ct[14]|0,this.Hl=ct[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:h,Gl:m,Hh:w,Hl:g}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,h,m,w,g]}set(t,r,n,o,s,i,a,c,u,f,l,d,h,m,w,g){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=m|0,this.Hh=w|0,this.Hl=g|0}process(t,r){for(let I=0;I<16;I++,r+=4)se[I]=t.getUint32(r),ie[I]=t.getUint32(r+=4);for(let I=16;I<80;I++){let D=se[I-15]|0,b=ie[I-15]|0,L=me(D,b,1)^me(D,b,8)^wo(D,b,7),C=ye(D,b,1)^ye(D,b,8)^Eo(D,b,7),B=se[I-2]|0,p=ie[I-2]|0,E=me(B,p,19)^br(B,p,61)^wo(B,p,6),y=ye(B,p,19)^gr(B,p,61)^Eo(B,p,6),x=vi(C,y,ie[I-7],ie[I-16]),S=Ai(x,L,E,se[I-7],se[I-16]);se[I]=S|0,ie[I]=x|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:h,Fl:m,Gh:w,Gl:g,Hh:v,Hl:T}=this;for(let I=0;I<80;I++){let D=me(l,d,14)^me(l,d,18)^br(l,d,41),b=ye(l,d,14)^ye(l,d,18)^gr(l,d,41),L=l&h^~l&w,C=d&m^~d&g,B=Ii(T,b,C,ru[I],ie[I]),p=Bi(B,v,D,L,eu[I],se[I]),E=B|0,y=me(n,o,28)^br(n,o,34)^br(n,o,39),x=ye(n,o,28)^gr(n,o,34)^gr(n,o,39),S=n&s^n&a^s&a,_=o&i^o&c^i&c;v=w|0,T=g|0,w=h|0,g=m|0,h=l|0,m=d|0,{h:l,l:d}=Ft(u|0,f|0,p|0,E|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let A=Ei(E,x,_);n=Si(A,p,y,S),o=A|0}({h:n,l:o}=Ft(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ft(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ft(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Ft(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Ft(this.Eh|0,this.El|0,l|0,d|0),{h,l:m}=Ft(this.Fh|0,this.Fl|0,h|0,m|0),{h:w,l:g}=Ft(this.Gh|0,this.Gl|0,w|0,g|0),{h:v,l:T}=Ft(this.Hh|0,this.Hl|0,v|0,T|0),this.set(n,o,s,i,a,c,u,f,l,d,h,m,w,g,v,T)}roundClean(){Wt(se,ie)}destroy(){Wt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Jr=xo(()=>new Xr);var Pi=xo(()=>new So);var Io=BigInt(0),Ao=BigInt(1);function Xt(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function xr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Ti(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Io:BigInt("0x"+e)}function Fe(e){return Ti(Mt(e))}function be(e){return ut(e),Ti(Mt(Uint8Array.from(e).reverse()))}function Qr(e,t){return Me(e.toString(16).padStart(t*2,"0"))}function Ve(e,t){return Qr(e,t).reverse()}function j(e,t,r){let n;if(typeof t=="string")try{n=Me(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Oe(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}var vo=e=>typeof e=="bigint"&&Io<=e;function Ci(e,t,r){return vo(e)&&vo(t)&&vo(r)&&t<=e&&e<r}function ae(e,t,r,n){if(!Ci(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Li(e){let t;for(t=0;e>Io;e>>=Ao,t+=1);return t}var ge=e=>(Ao<<BigInt(e))-Ao;function Di(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),a=0,c=()=>{s.fill(1),i.fill(0),a=0},u=(...h)=>r(i,s,...h),f=(h=n(0))=>{i=u(o(0),h),s=u(),h.length!==0&&(i=u(o(1),h),s=u())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,m=[];for(;h<t;){s=u();let w=s.slice();m.push(w),h+=s.length}return vt(...m)};return(h,m)=>{c(),f(h);let w;for(;!(w=m(l()));)f();return c(),w}}function ce(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let a=e[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}function 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 yt=BigInt(0),it=BigInt(1),xe=BigInt(2),nu=BigInt(3),Ui=BigInt(4),Ki=BigInt(5),Oi=BigInt(8);function Y(e,t){let r=e%t;return r>=yt?r:t+r}function Z(e,t,r){let n=e;for(;t-- >yt;)n*=n,n%=r;return n}function Ri(e,t){if(e===yt)throw new Error("invert: expected non-zero number");if(t<=yt)throw new Error("invert: expected positive modulus, got "+t);let r=Y(e,t),n=t,o=yt,s=it,i=it,a=yt;for(;r!==yt;){let u=n/r,f=n%r,l=o-i*u,d=s-a*u;n=r,r=f,o=i,s=a,i=l,a=d}if(n!==it)throw new Error("invert: does not exist");return Y(o,t)}function ki(e,t){let r=(e.ORDER+it)/Ui,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function ou(e,t){let r=(e.ORDER-Ki)/Oi,n=e.mul(t,xe),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,xe),o),a=e.mul(s,e.sub(i,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}function su(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-it,r=0;for(;t%xe===yt;)t/=xe,r++;let n=xe,o=Lt(e);for(;Ni(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ki;let s=o.pow(n,t),i=(t+it)/xe;return function(c,u){if(c.is0(u))return u;if(Ni(c,u)!==1)throw new Error("Cannot find square root");let f=r,l=c.mul(c.ONE,s),d=c.pow(u,t),h=c.pow(u,i);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let m=1,w=c.sqr(d);for(;!c.eql(w,c.ONE);)if(m++,w=c.sqr(w),m===f)throw new Error("Cannot find square root");let g=it<<BigInt(f-m-1),v=c.pow(l,g);f=m,l=c.sqr(v),d=c.mul(d,l),h=c.mul(h,v)}return h}}function iu(e){return e%Ui===nu?ki:e%Oi===Ki?ou:su(e)}var Mi=(e,t)=>(Y(e,t)&it)===it,au=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Bo(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=au.reduce((n,o)=>(n[o]="function",n),t);return ce(e,r),e}function cu(e,t,r){if(r<yt)throw new Error("invalid exponent, negatives unsupported");if(r===yt)return e.ONE;if(r===it)return t;let n=e.ONE,o=t;for(;r>yt;)r&it&&(n=e.mul(n,o)),o=e.sqr(o),r>>=it;return n}function wr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function Ni(e,t){let r=(e.ORDER-it)/xe,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 Fi(e,t){t!==void 0&&hr(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Lt(e,t,r=!1,n={}){if(e<=yt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=Fi(e,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,u=Object.freeze({ORDER:e,isLE:r,BITS:i,BYTES:a,MASK:ge(i),ZERO:yt,ONE:it,create:f=>Y(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return yt<=f&&f<e},is0:f=>f===yt,isValidNot0:f=>!u.is0(f)&&u.isValid(f),isOdd:f=>(f&it)===it,neg:f=>Y(-f,e),eql:(f,l)=>f===l,sqr:f=>Y(f*f,e),add:(f,l)=>Y(f+l,e),sub:(f,l)=>Y(f-l,e),mul:(f,l)=>Y(f*l,e),pow:(f,l)=>cu(u,f,l),div:(f,l)=>Y(f*Ri(l,e),e),sqrN:f=>f*f,addN:(f,l)=>f+l,subN:(f,l)=>f-l,mulN:(f,l)=>f*l,inv:f=>Ri(f,e),sqrt:s||(f=>(c||(c=iu(e)),c(u,f))),toBytes:f=>r?Ve(f,a):Qr(f,a),fromBytes:f=>{if(f.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);return r?be(f):Fe(f)},invertBatch:f=>wr(u,f),cmov:(f,l,d)=>d?l:f});return Object.freeze(u)}function Vi(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 _o(e){let t=Vi(e);return t+Math.ceil(t/2)}function qi(e,t,r=!1){let n=e.length,o=Vi(t),s=_o(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?be(e):Fe(e),a=Y(i,t-it)+it;return r?Ve(a,o):Qr(a,o)}var ze=BigInt(0),we=BigInt(1);function He(e,t){let r=t.negate();return e?r:t}function tn(e,t,r){let n=t==="pz"?i=>i.pz:i=>i.ez,o=wr(e.Fp,r.map(n));return r.map((i,a)=>i.toAffine(o[a])).map(e.fromAffine)}function $i(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Po(e,t){$i(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=ge(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Hi(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=we);let u=t*n,f=u+Math.abs(a)-1,l=a===0,d=a<0,h=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:d,isNegF:h,offsetF:u}}function fu(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 uu(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 To=new WeakMap,ji=new WeakMap;function Co(e){return ji.get(e)||1}function zi(e){if(e!==ze)throw new Error("invalid wNAF")}function en(e,t){return{constTimeNegate:He,hasPrecomputes(r){return Co(r)!==1},unsafeLadder(r,n,o=e.ZERO){let s=r;for(;n>ze;)n&we&&(o=o.add(s)),s=s.double(),n>>=we;return o},precomputeWindow(r,n){let{windows:o,windowSize:s}=Po(n,t),i=[],a=r,c=a;for(let u=0;u<o;u++){c=a,i.push(c);for(let f=1;f<s;f++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(r,n,o){let s=e.ZERO,i=e.BASE,a=Po(r,t);for(let c=0;c<a.windows;c++){let{nextN:u,offset:f,isZero:l,isNeg:d,isNegF:h,offsetF:m}=Hi(o,c,a);o=u,l?i=i.add(He(h,n[m])):s=s.add(He(d,n[f]))}return zi(o),{p:s,f:i}},wNAFUnsafe(r,n,o,s=e.ZERO){let i=Po(r,t);for(let a=0;a<i.windows&&o!==ze;a++){let{nextN:c,offset:u,isZero:f,isNeg:l}=Hi(o,a,i);if(o=c,!f){let d=n[u];s=s.add(l?d.negate():d)}}return zi(o),s},getPrecomputes(r,n,o){let s=To.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&(typeof o=="function"&&(s=o(s)),To.set(n,s))),s},wNAFCached(r,n,o){let s=Co(r);return this.wNAF(s,this.getPrecomputes(s,r,o),n)},wNAFCachedUnsafe(r,n,o,s){let i=Co(r);return i===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,r,o),n,s)},setWindowSize(r,n){$i(n,t),ji.set(r,n),To.delete(r)}}}function Zi(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>ze||n>ze;)r&we&&(s=s.add(o)),n&we&&(i=i.add(o)),o=o.double(),r>>=we,n>>=we;return{p1:s,p2:i}}function rn(e,t,r,n){fu(r,e),uu(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,a=Li(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=ge(c),f=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,d=i;for(let h=l;h>=0;h-=c){f.fill(i);for(let w=0;w<s;w++){let g=n[w],v=Number(g>>BigInt(h)&u);f[v]=f[v].add(r[w])}let m=i;for(let w=f.length-1,g=i;w>0;w--)g=g.add(f[w]),m=m.add(g);if(d=d.add(m),h!==0)for(let w=0;w<c;w++)d=d.double()}return d}function Gi(e,t){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Bo(t),t}else return Lt(e)}function nn(e,t,r={}){if(!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>ze))throw new Error(`CURVE.${a} must be positive bigint`)}let n=Gi(t.p,r.Fp),o=Gi(t.n,r.Fn),i=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Vt=BigInt(0),bt=BigInt(1),Lo=BigInt(2),lu=BigInt(8),du={zip215:!0};function hu(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function pu(e,t={}){let{Fp:r,Fn:n}=nn("edwards",e,t),{h:o,n:s}=e;ce(t,{},{uvRatio:"function"});let i=Lo<<BigInt(n.BYTES*8)-bt,a=w=>r.create(w),c=t.uvRatio||((w,g)=>{try{return{isValid:!0,value:r.sqrt(r.div(w,g))}}catch{return{isValid:!1,value:Vt}}});if(!hu(r,e,e.Gx,e.Gy))throw new Error("bad curve params: generator point");function u(w,g,v=!1){let T=v?bt:Vt;return ae("coordinate "+w,g,T,i),g}function f(w){if(!(w instanceof h))throw new Error("ExtendedPoint expected")}let l=qe((w,g)=>{let{ex:v,ey:T,ez:I}=w,D=w.is0();g==null&&(g=D?lu:r.inv(I));let b=a(v*g),L=a(T*g),C=a(I*g);if(D)return{x:Vt,y:bt};if(C!==bt)throw new Error("invZ was invalid");return{x:b,y:L}}),d=qe(w=>{let{a:g,d:v}=e;if(w.is0())throw new Error("bad point: ZERO");let{ex:T,ey:I,ez:D,et:b}=w,L=a(T*T),C=a(I*I),B=a(D*D),p=a(B*B),E=a(L*g),y=a(B*a(E+C)),x=a(p+a(v*a(L*C)));if(y!==x)throw new Error("bad point: equation left != right (1)");let S=a(T*I),_=a(D*b);if(S!==_)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(g,v,T,I){this.ex=u("x",g),this.ey=u("y",v),this.ez=u("z",T,!0),this.et=u("t",I),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(g){if(g instanceof h)throw new Error("extended point not allowed");let{x:v,y:T}=g||{};return u("x",v),u("y",T),new h(v,T,bt,a(v*T))}static normalizeZ(g){return tn(h,"ez",g)}static msm(g,v){return rn(h,n,g,v)}_setWindowSize(g){this.precompute(g)}precompute(g=8,v=!0){return m.setWindowSize(this,g),v||this.multiply(Lo),this}assertValidity(){d(this)}equals(g){f(g);let{ex:v,ey:T,ez:I}=this,{ex:D,ey:b,ez:L}=g,C=a(v*L),B=a(D*I),p=a(T*L),E=a(b*I);return C===B&&p===E}is0(){return this.equals(h.ZERO)}negate(){return new h(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:g}=e,{ex:v,ey:T,ez:I}=this,D=a(v*v),b=a(T*T),L=a(Lo*a(I*I)),C=a(g*D),B=v+T,p=a(a(B*B)-D-b),E=C+b,y=E-L,x=C-b,S=a(p*y),_=a(E*x),A=a(p*x),P=a(y*E);return new h(S,_,P,A)}add(g){f(g);let{a:v,d:T}=e,{ex:I,ey:D,ez:b,et:L}=this,{ex:C,ey:B,ez:p,et:E}=g,y=a(I*C),x=a(D*B),S=a(L*T*E),_=a(b*p),A=a((I+D)*(C+B)-y-x),P=_-S,N=_+S,R=a(x-v*y),J=a(A*P),H=a(N*R),U=a(A*R),et=a(P*N);return new h(J,H,et,U)}subtract(g){return this.add(g.negate())}multiply(g){let v=g;ae("scalar",v,bt,s);let{p:T,f:I}=m.wNAFCached(this,v,h.normalizeZ);return h.normalizeZ([T,I])[0]}multiplyUnsafe(g,v=h.ZERO){let T=g;return ae("scalar",T,Vt,s),T===Vt?h.ZERO:this.is0()||T===bt?this:m.wNAFCachedUnsafe(this,T,h.normalizeZ,v)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return m.wNAFCachedUnsafe(this,s).is0()}toAffine(g){return l(this,g)}clearCofactor(){return o===bt?this:this.multiplyUnsafe(o)}static fromBytes(g,v=!1){return ut(g),this.fromHex(g,v)}static fromHex(g,v=!1){let{d:T,a:I}=e,D=r.BYTES;g=j("pointHex",g,D),Xt("zip215",v);let b=g.slice(),L=g[D-1];b[D-1]=L&-129;let C=be(b),B=v?i:r.ORDER;ae("pointHex.y",C,Vt,B);let p=a(C*C),E=a(p-bt),y=a(T*p-I),{isValid:x,value:S}=c(E,y);if(!x)throw new Error("Point.fromHex: invalid y coordinate");let _=(S&bt)===bt,A=(L&128)!==0;if(!v&&S===Vt&&A)throw new Error("Point.fromHex: x=0 and x_0=1");return A!==_&&(S=a(-S)),h.fromAffine({x:S,y:C})}static fromPrivateScalar(g){return h.BASE.multiply(g)}toBytes(){let{x:g,y:v}=this.toAffine(),T=Ve(v,r.BYTES);return T[T.length-1]|=g&bt?128:0,T}toRawBytes(){return this.toBytes()}toHex(){return Mt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}h.BASE=new h(e.Gx,e.Gy,bt,a(e.Gx*e.Gy)),h.ZERO=new h(Vt,bt,bt,Vt),h.Fp=r,h.Fn=n;let m=en(h,n.BYTES*8);return h}function mu(e,t){ce(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:r,hash:n}=t,{BASE:o,Fp:s,Fn:i}=e,a=i.ORDER,c=t.randomBytes||mr,u=t.adjustScalarBytes||(b=>b),f=t.domain||((b,L,C)=>{if(Xt("phflag",C),L.length||C)throw new Error("Contexts/pre-hash are not supported");return b});function l(b){return i.create(b)}function d(b){return l(be(b))}function h(b){let L=s.BYTES;b=j("private key",b,L);let C=j("hashed private key",n(b),2*L),B=u(C.slice(0,L)),p=C.slice(L,2*L),E=d(B);return{head:B,prefix:p,scalar:E}}function m(b){let{head:L,prefix:C,scalar:B}=h(b),p=o.multiply(B),E=p.toBytes();return{head:L,prefix:C,scalar:B,point:p,pointBytes:E}}function w(b){return m(b).pointBytes}function g(b=Uint8Array.of(),...L){let C=vt(...L);return d(n(f(C,j("context",b),!!r)))}function v(b,L,C={}){b=j("message",b),r&&(b=r(b));let{prefix:B,scalar:p,pointBytes:E}=m(L),y=g(C.context,B,b),x=o.multiply(y).toBytes(),S=g(C.context,x,E,b),_=l(y+S*p);ae("signature.s",_,Vt,a);let A=s.BYTES,P=vt(x,Ve(_,A));return j("result",P,A*2)}let T=du;function I(b,L,C,B=T){let{context:p,zip215:E}=B,y=s.BYTES;b=j("signature",b,2*y),L=j("message",L),C=j("publicKey",C,y),E!==void 0&&Xt("zip215",E),r&&(L=r(L));let x=be(b.slice(y,2*y)),S,_,A;try{S=e.fromHex(C,E),_=e.fromHex(b.slice(0,y),E),A=o.multiplyUnsafe(x)}catch{return!1}if(!E&&S.isSmallOrder())return!1;let P=g(p,_.toBytes(),S.toBytes(),L);return _.add(S.multiplyUnsafe(P)).subtract(A).clearCofactor().is0()}return o.precompute(8),{getPublicKey:w,sign:v,verify:I,utils:{getExtendedPublicKey:m,randomPrivateKey:()=>c(s.BYTES),precompute(b=8,L=e.BASE){return L.precompute(b,!1)}},Point:e}}function yu(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=Lt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={hash:e.hash,randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function bu(e,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:e})}function Wi(e){let{CURVE:t,curveOpts:r,eddsaOpts:n}=yu(e),o=pu(t,r),s=mu(o,n);return bu(e,s)}var Ap=BigInt(0),gu=BigInt(1),Yi=BigInt(2),Ip=BigInt(3),xu=BigInt(5),wu=BigInt(8),on={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:wu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Eu(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=on.p,a=e*e%s*e%s,c=Z(a,Yi,s)*a%s,u=Z(c,gu,s)*e%s,f=Z(u,xu,s)*u%s,l=Z(f,t,s)*f%s,d=Z(l,r,s)*l%s,h=Z(d,n,s)*d%s,m=Z(h,o,s)*h%s,w=Z(m,o,s)*h%s,g=Z(w,t,s)*f%s;return{pow_p_5_8:Z(g,Yi,s)*e%s,b2:a}}function Su(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Xi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function vu(e,t){let r=on.p,n=Y(t*t*t,r),o=Y(n*n*t,r),s=Eu(e*o).pow_p_5_8,i=Y(e*n*s,r),a=Y(t*i*i,r),c=i,u=Y(i*Xi,r),f=a===e,l=a===Y(-e,r),d=a===Y(-e*Xi,r);return f&&(i=c),(l||d)&&(i=u),Mi(i,r)&&(i=Y(-i,r)),{isValid:f||l,value:i}}var Au=Lt(on.p,void 0,!0),Iu={...on,Fp:Au,hash:Pi,adjustScalarBytes:Su,uvRatio:vu},Ji=Wi(Iu);var Er=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},sn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Qi={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new sn("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 It=Qi;var an=32;var Do,Bu=(async()=>{try{return await It.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function _u(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await It.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await It.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 Pu(e,t,r){return Ji.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ta(e,t,r){return Do==null&&(Do=await Bu),Do?_u(e,t,r):Pu(e,t,r)}function cn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var fn=class{type="Ed25519";raw;constructor(t){this.raw=Ro(t,an)}toMultihash(){return Tt.digest(kt(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:st(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=ta(this.raw,r,t);return cn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function No(e){return e=Ro(e,an),new fn(e)}function Ro(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new nt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Cu=Math.pow(2,7),Lu=Math.pow(2,14),Du=Math.pow(2,21),Uo=Math.pow(2,28),Ko=Math.pow(2,35),Oo=Math.pow(2,42),ko=Math.pow(2,49),q=128,lt=127;function dt(e){if(e<Cu)return 1;if(e<Lu)return 2;if(e<Du)return 3;if(e<Uo)return 4;if(e<Ko)return 5;if(e<Oo)return 6;if(e<ko)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Mo(e,t,r=0){switch(dt(e)){case 8:t[r++]=e&255|q,e/=128;case 7:t[r++]=e&255|q,e/=128;case 6:t[r++]=e&255|q,e/=128;case 5:t[r++]=e&255|q,e/=128;case 4:t[r++]=e&255|q,e>>>=7;case 3:t[r++]=e&255|q,e>>>=7;case 2:t[r++]=e&255|q,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Ru(e,t,r=0){switch(dt(e)){case 8:t.set(r++,e&255|q),e/=128;case 7:t.set(r++,e&255|q),e/=128;case 6:t.set(r++,e&255|q),e/=128;case 5:t.set(r++,e&255|q),e/=128;case 4:t.set(r++,e&255|q),e>>>=7;case 3:t.set(r++,e&255|q),e>>>=7;case 2:t.set(r++,e&255|q),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Fo(e,t){let r=e[t],n=0;if(n+=r&lt,r<q||(r=e[t+1],n+=(r&lt)<<7,r<q)||(r=e[t+2],n+=(r&lt)<<14,r<q)||(r=e[t+3],n+=(r&lt)<<21,r<q)||(r=e[t+4],n+=(r&lt)*Uo,r<q)||(r=e[t+5],n+=(r&lt)*Ko,r<q)||(r=e[t+6],n+=(r&lt)*Oo,r<q)||(r=e[t+7],n+=(r&lt)*ko,r<q))return n;throw new RangeError("Could not decode varint")}function Nu(e,t){let r=e.get(t),n=0;if(n+=r&lt,r<q||(r=e.get(t+1),n+=(r&lt)<<7,r<q)||(r=e.get(t+2),n+=(r&lt)<<14,r<q)||(r=e.get(t+3),n+=(r&lt)<<21,r<q)||(r=e.get(t+4),n+=(r&lt)*Uo,r<q)||(r=e.get(t+5),n+=(r&lt)*Ko,r<q)||(r=e.get(t+6),n+=(r&lt)*Oo,r<q)||(r=e.get(t+7),n+=(r&lt)*ko,r<q))return n;throw new RangeError("Could not decode varint")}function Bt(e,t,r=0){return t==null&&(t=xt(dt(e))),t instanceof Uint8Array?Mo(e,t,r):Ru(e,t,r)}function Jt(e,t=0){return e instanceof Uint8Array?Fo(e,t):Nu(e,t)}var Vo=new Float32Array([-0]),fe=new Uint8Array(Vo.buffer);function ra(e,t,r){Vo[0]=e,t[r]=fe[0],t[r+1]=fe[1],t[r+2]=fe[2],t[r+3]=fe[3]}function na(e,t){return fe[0]=e[t],fe[1]=e[t+1],fe[2]=e[t+2],fe[3]=e[t+3],Vo[0]}var qo=new Float64Array([-0]),ht=new Uint8Array(qo.buffer);function oa(e,t,r){qo[0]=e,t[r]=ht[0],t[r+1]=ht[1],t[r+2]=ht[2],t[r+3]=ht[3],t[r+4]=ht[4],t[r+5]=ht[5],t[r+6]=ht[6],t[r+7]=ht[7]}function sa(e,t){return ht[0]=e[t],ht[1]=e[t+1],ht[2]=e[t+2],ht[3]=e[t+3],ht[4]=e[t+4],ht[5]=e[t+5],ht[6]=e[t+6],ht[7]=e[t+7],qo[0]}var Uu=BigInt(Number.MAX_SAFE_INTEGER),Ku=BigInt(Number.MIN_SAFE_INTEGER),At=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ee;if(t<Uu&&t>Ku)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>ia&&(o=0n,++n>ia&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ee;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):Ee}},Ee=new At(0,0);Ee.toBigInt=function(){return 0n};Ee.zzEncode=Ee.zzDecode=function(){return this};Ee.length=function(){return 1};var ia=4294967296n;function aa(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 ca(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Ho(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 Dt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function ln(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var zo=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,Dt(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 Dt(this,4);return ln(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Dt(this,4);return ln(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Dt(this,4);let t=na(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Dt(this,4);let t=sa(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 Dt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return ca(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Dt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Dt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new At(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Dt(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 Dt(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 Dt(this,8);let t=ln(this.buf,this.pos+=4),r=ln(this.buf,this.pos+=4);return new At(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Fo(this.buf,this.pos);return this.pos+=dt(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 Go(e){return new zo(e instanceof Uint8Array?e:e.subarray())}function Rt(e,t,r){let n=Go(e);return t.decode(n,void 0,r)}function $o(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return xt(i);o+i>t&&(n=xt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Se=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function jo(){}var Wo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ou=$o();function ku(e){return globalThis.Buffer!=null?xt(e):Ou(e)}var vr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Se(jo,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Se(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Yo((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,At.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=At.fromBigInt(t);return this._push(dn,r.length(),r)}uint64Number(t){return this._push(Mo,dt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=At.fromBigInt(t).zzEncode();return this._push(dn,r.length(),r)}sint64Number(t){let r=At.fromNumber(t).zzEncode();return this._push(dn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Zo,1,t?1:0)}fixed32(t){return this._push(Sr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=At.fromBigInt(t);return this._push(Sr,4,r.lo)._push(Sr,4,r.hi)}fixed64Number(t){let r=At.fromNumber(t);return this._push(Sr,4,r.lo)._push(Sr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(ra,4,t)}double(t){return this._push(oa,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Zo,1,0):this.uint32(r)._push(Fu,r,t)}string(t){let r=aa(t);return r!==0?this.uint32(r)._push(Ho,r,t):this._push(Zo,1,0)}fork(){return this.states=new Wo(this),this.head=this.tail=new Se(jo,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 Se(jo,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=ku(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Zo(e,t,r){t[r]=e&255}function Mu(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Yo=class extends Se{next;constructor(t,r){super(Mu,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 Sr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Fu(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(vr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Vu,t,e),this},vr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(qu,t,e),this});function Vu(e,t,r){t.set(e,r)}function qu(e,t,r){e.length<40?Ho(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(k(e),r)}function Xo(){return new vr}function Nt(e,t){let r=Xo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Ge;(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"})(Ge||(Ge={}));function hn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Jo(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return hn("enum",Ge.VARINT,r,n)}function Ut(e,t){return hn("message",Ge.LENGTH_DELIMITED,e,t)}var ve=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var tt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(tt||(tt={}));var Qo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Qo||(Qo={}));(function(e){e.codec=()=>Jo(Qo)})(tt||(tt={}));var qt;(function(e){let t;e.codec=()=>(t==null&&(t=Ut((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),tt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=tt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Nt(r,e.codec()),e.decode=(r,n)=>Rt(r,e.codec(),n)})(qt||(qt={}));var ts;(function(e){let t;e.codec=()=>(t==null&&(t=Ut((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),tt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=tt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Nt(r,e.codec()),e.decode=(r,n)=>Rt(r,e.codec(),n)})(ts||(ts={}));var Ir={};gt(Ir,{MAX_RSA_KEY_SIZE:()=>es,generateRSAKeyPair:()=>pa,jwkToJWKKeyPair:()=>ma,jwkToPkcs1:()=>$u,jwkToPkix:()=>ss,jwkToRSAPrivateKey:()=>fs,pkcs1MessageToJwk:()=>ns,pkcs1MessageToRSAPrivateKey:()=>is,pkcs1ToJwk:()=>Gu,pkcs1ToRSAPrivateKey:()=>ha,pkixMessageToJwk:()=>os,pkixMessageToRSAPublicKey:()=>cs,pkixToJwk:()=>ju,pkixToRSAPublicKey:()=>as});var pn=Jr;var $e=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Ir.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return rt.createV1(114,this._multihash)}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:st(this.raw,t.raw)}verify(t,r,n){return da(this.jwk,r,t,n)}},Ar=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Ir.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:st(this.raw,t.raw)}sign(t,r){return la(this.jwk,t,r)}};var es=8192,rs=18,Hu=1062,zu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Gu(e){let t=jt(e);return ns(t)}function ns(e){return{n:K(e[1],"base64url"),e:K(e[2],"base64url"),d:K(e[3],"base64url"),p:K(e[4],"base64url"),q:K(e[5],"base64url"),dp:K(e[6],"base64url"),dq:K(e[7],"base64url"),qi:K(e[8],"base64url"),kty:"RSA"}}function $u(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 nt("JWK was missing components");return ne([wt(Uint8Array.from([0])),wt(k(e.n,"base64url")),wt(k(e.e,"base64url")),wt(k(e.d,"base64url")),wt(k(e.p,"base64url")),wt(k(e.q,"base64url")),wt(k(e.dp,"base64url")),wt(k(e.dq,"base64url")),wt(k(e.qi,"base64url"))]).subarray()}function ju(e){let t=jt(e,{offset:0});return os(t)}function os(e){let t=jt(e[1],{offset:0});return{kty:"RSA",n:K(t[0],"base64url"),e:K(t[1],"base64url")}}function ss(e){if(e.n==null||e.e==null)throw new nt("JWK was missing components");return ne([zu,Zr(ne([wt(k(e.n,"base64url")),wt(k(e.e,"base64url"))]))]).subarray()}function ha(e){let t=jt(e);return is(t)}function is(e){let t=ns(e);return fs(t)}function as(e,t){if(e.byteLength>=Hu)throw new Ce("Key size is too large");let r=jt(e,{offset:0});return cs(r,e,t)}function cs(e,t,r){let n=os(e);if(r==null){let o=pn(qt.encode({Type:tt.RSA,Data:t}));r=Pt(rs,o)}return new $e(n,r)}function fs(e){if(ba(e)>es)throw new nt("Key size is too large");let t=ma(e),r=pn(qt.encode({Type:tt.RSA,Data:ss(t.publicKey)})),n=Pt(rs,r);return new Ar(t.privateKey,new $e(t.publicKey,n))}async function pa(e){if(e>es)throw new nt("Key size is too large");let t=await ya(e),r=pn(qt.encode({Type:tt.RSA,Data:ss(t.publicKey)})),n=Pt(rs,r);return new Ar(t.privateKey,new $e(t.publicKey,n))}function ma(e){if(e==null)throw new nt("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function ya(e,t){let r=await It.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 Zu(r,t);return{privateKey:n[0],publicKey:n[1]}}async function la(e,t,r){let n=await It.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await It.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 da(e,t,r,n){let o=await It.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await It.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Zu(e,t){if(e.privateKey==null||e.publicKey==null)throw new nt("Private and public key are required");let r=await Promise.all([It.get().subtle.exportKey("jwk",e.privateKey),It.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function ba(e){if(e.kty!=="RSA")throw new nt("invalid key type");if(e.n==null)throw new nt("invalid key modulus");return k(e.n,"base64url").length*8}var mn=class extends Ke{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,hi(t);let n=pr(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),Wt(s)}update(t){return ke(this),this.iHash.update(t),this}digestInto(t){ke(this),ut(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},us=(e,t,r)=>new mn(e,t).update(r).digest();us.create=(e,t)=>new mn(e,t);function ga(e){e.lowS!==void 0&&Xt("lowS",e.lowS),e.prehash!==void 0&&Xt("prehash",e.prehash)}var ls=class extends Error{constructor(t=""){super(t)}},Qt={Err:ls,_tlv:{encode:(e,t)=>{let{Err:r}=Qt;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=xr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?xr(o.length/2|128):"";return xr(e)+s+o+t},decode(e,t){let{Err:r}=Qt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Qt;if(e<Br)throw new t("integer: negative integers are not allowed");let r=xr(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}=Qt;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 Fe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Qt,o=j("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Qt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Br=BigInt(0),_r=BigInt(1),Wu=BigInt(2),yn=BigInt(3),Yu=BigInt(4);function Xu(e,t,r){function n(o){let s=e.sqr(o),i=e.mul(s,o);return e.add(e.add(i,e.mul(o,t)),r)}return n}function xa(e,t,r){let{BYTES:n}=e;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=j("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{i=e.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(r&&(i=e.create(i)),!e.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function Ju(e,t={}){let{Fp:r,Fn:n}=nn("weierstrass",e,t),{h:o,n:s}=e;ce(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!r.is0(e.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(B,p,E){let{x:y,y:x}=p.toAffine(),S=r.toBytes(y);if(Xt("isCompressed",E),E){a();let _=!r.isOdd(x);return vt(wa(_),S)}else return vt(Uint8Array.of(4),S,r.toBytes(x))}function u(B){ut(B);let p=r.BYTES,E=p+1,y=2*p+1,x=B.length,S=B[0],_=B.subarray(1);if(x===E&&(S===2||S===3)){let A=r.fromBytes(_);if(!r.isValid(A))throw new Error("bad point: is not on curve, wrong x");let P=d(A),N;try{N=r.sqrt(P)}catch(H){let U=H instanceof Error?": "+H.message:"";throw new Error("bad point: is not on curve, sqrt error"+U)}a();let R=r.isOdd(N);return(S&1)===1!==R&&(N=r.neg(N)),{x:A,y:N}}else if(x===y&&S===4){let A=r.fromBytes(_.subarray(p*0,p*1)),P=r.fromBytes(_.subarray(p*1,p*2));if(!h(A,P))throw new Error("bad point: is not on curve");return{x:A,y:P}}else throw new Error(`bad point: got length ${x}, expected compressed=${E} or uncompressed=${y}`)}let f=t.toBytes||c,l=t.fromBytes||u,d=Xu(r,e.a,e.b);function h(B,p){let E=r.sqr(p),y=d(B);return r.eql(E,y)}if(!h(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let m=r.mul(r.pow(e.a,yn),Yu),w=r.mul(r.sqr(e.b),BigInt(27));if(r.is0(r.add(m,w)))throw new Error("bad curve params: a or b");function g(B,p,E=!1){if(!r.isValid(p)||E&&r.is0(p))throw new Error(`bad point coordinate ${B}`);return p}function v(B){if(!(B instanceof b))throw new Error("ProjectivePoint expected")}let T=qe((B,p)=>{let{px:E,py:y,pz:x}=B;if(r.eql(x,r.ONE))return{x:E,y};let S=B.is0();p==null&&(p=S?r.ONE:r.inv(x));let _=r.mul(E,p),A=r.mul(y,p),P=r.mul(x,p);if(S)return{x:r.ZERO,y:r.ZERO};if(!r.eql(P,r.ONE))throw new Error("invZ was invalid");return{x:_,y:A}}),I=qe(B=>{if(B.is0()){if(t.allowInfinityPoint&&!r.is0(B.py))return;throw new Error("bad point: ZERO")}let{x:p,y:E}=B.toAffine();if(!r.isValid(p)||!r.isValid(E))throw new Error("bad point: x or y not field elements");if(!h(p,E))throw new Error("bad point: equation left != right");if(!B.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function D(B,p,E,y,x){return E=new b(r.mul(E.px,B),E.py,E.pz),p=He(y,p),E=He(x,E),p.add(E)}class b{constructor(p,E,y){this.px=g("x",p),this.py=g("y",E,!0),this.pz=g("z",y),Object.freeze(this)}static fromAffine(p){let{x:E,y}=p||{};if(!p||!r.isValid(E)||!r.isValid(y))throw new Error("invalid affine point");if(p instanceof b)throw new Error("projective point not allowed");return r.is0(E)&&r.is0(y)?b.ZERO:new b(E,y,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(p){return tn(b,"pz",p)}static fromBytes(p){return ut(p),b.fromHex(p)}static fromHex(p){let E=b.fromAffine(l(j("pointHex",p)));return E.assertValidity(),E}static fromPrivateKey(p){let E=xa(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return b.BASE.multiply(E(p))}static msm(p,E){return rn(b,n,p,E)}precompute(p=8,E=!0){return C.setWindowSize(this,p),E||this.multiply(yn),this}_setWindowSize(p){this.precompute(p)}assertValidity(){I(this)}hasEvenY(){let{y:p}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(p)}equals(p){v(p);let{px:E,py:y,pz:x}=this,{px:S,py:_,pz:A}=p,P=r.eql(r.mul(E,A),r.mul(S,x)),N=r.eql(r.mul(y,A),r.mul(_,x));return P&&N}negate(){return new b(this.px,r.neg(this.py),this.pz)}double(){let{a:p,b:E}=e,y=r.mul(E,yn),{px:x,py:S,pz:_}=this,A=r.ZERO,P=r.ZERO,N=r.ZERO,R=r.mul(x,x),J=r.mul(S,S),H=r.mul(_,_),U=r.mul(x,S);return U=r.add(U,U),N=r.mul(x,_),N=r.add(N,N),A=r.mul(p,N),P=r.mul(y,H),P=r.add(A,P),A=r.sub(J,P),P=r.add(J,P),P=r.mul(A,P),A=r.mul(U,A),N=r.mul(y,N),H=r.mul(p,H),U=r.sub(R,H),U=r.mul(p,U),U=r.add(U,N),N=r.add(R,R),R=r.add(N,R),R=r.add(R,H),R=r.mul(R,U),P=r.add(P,R),H=r.mul(S,_),H=r.add(H,H),R=r.mul(H,U),A=r.sub(A,R),N=r.mul(H,J),N=r.add(N,N),N=r.add(N,N),new b(A,P,N)}add(p){v(p);let{px:E,py:y,pz:x}=this,{px:S,py:_,pz:A}=p,P=r.ZERO,N=r.ZERO,R=r.ZERO,J=e.a,H=r.mul(e.b,yn),U=r.mul(E,S),et=r.mul(y,_),ot=r.mul(x,A),ft=r.add(E,y),$=r.add(S,_);ft=r.mul(ft,$),$=r.add(U,et),ft=r.sub(ft,$),$=r.add(E,x);let mt=r.add(S,A);return $=r.mul($,mt),mt=r.add(U,ot),$=r.sub($,mt),mt=r.add(y,x),P=r.add(_,A),mt=r.mul(mt,P),P=r.add(et,ot),mt=r.sub(mt,P),R=r.mul(J,$),P=r.mul(H,ot),R=r.add(P,R),P=r.sub(et,R),R=r.add(et,R),N=r.mul(P,R),et=r.add(U,U),et=r.add(et,U),ot=r.mul(J,ot),$=r.mul(H,$),et=r.add(et,ot),ot=r.sub(U,ot),ot=r.mul(J,ot),$=r.add($,ot),U=r.mul(et,$),N=r.add(N,U),U=r.mul(mt,$),P=r.mul(ft,P),P=r.sub(P,U),U=r.mul(ft,et),R=r.mul(mt,R),R=r.add(R,U),new b(P,N,R)}subtract(p){return this.add(p.negate())}is0(){return this.equals(b.ZERO)}multiply(p){let{endo:E}=t;if(!n.isValidNot0(p))throw new Error("invalid scalar: out of range");let y,x,S=_=>C.wNAFCached(this,_,b.normalizeZ);if(E){let{k1neg:_,k1:A,k2neg:P,k2:N}=E.splitScalar(p),{p:R,f:J}=S(A),{p:H,f:U}=S(N);x=J.add(U),y=D(E.beta,R,H,_,P)}else{let{p:_,f:A}=S(p);y=_,x=A}return b.normalizeZ([y,x])[0]}multiplyUnsafe(p){let{endo:E}=t,y=this;if(!n.isValid(p))throw new Error("invalid scalar: out of range");if(p===Br||y.is0())return b.ZERO;if(p===_r)return y;if(C.hasPrecomputes(this))return this.multiply(p);if(E){let{k1neg:x,k1:S,k2neg:_,k2:A}=E.splitScalar(p),{p1:P,p2:N}=Zi(b,y,S,A);return D(E.beta,P,N,x,_)}else return C.wNAFCachedUnsafe(y,p)}multiplyAndAddUnsafe(p,E,y){let x=this.multiplyUnsafe(E).add(p.multiplyUnsafe(y));return x.is0()?void 0:x}toAffine(p){return T(this,p)}isTorsionFree(){let{isTorsionFree:p}=t;return o===_r?!0:p?p(b,this):C.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:p}=t;return o===_r?this:p?p(b,this):this.multiplyUnsafe(o)}toBytes(p=!0){return Xt("isCompressed",p),this.assertValidity(),f(b,this,p)}toRawBytes(p=!0){return this.toBytes(p)}toHex(p=!0){return Mt(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}b.BASE=new b(e.Gx,e.Gy,r.ONE),b.ZERO=new b(r.ZERO,r.ONE,r.ZERO),b.Fp=r,b.Fn=n;let L=n.BITS,C=en(b,t.endo?Math.ceil(L/2):L);return b}function wa(e){return Uint8Array.of(e?2:3)}function Qu(e,t,r={}){ce(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||mr,o=t.hmac||((y,...x)=>us(t.hash,y,vt(...x))),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i;function u(y){let x=a>>_r;return y>x}function f(y){return u(y)?i.neg(y):y}function l(y,x){if(!i.isValidNot0(x))throw new Error(`invalid signature ${y}: out of range 1..CURVE.n`)}class d{constructor(x,S,_){l("r",x),l("s",S),this.r=x,this.s=S,_!=null&&(this.recovery=_),Object.freeze(this)}static fromCompact(x){let S=i.BYTES,_=j("compactSignature",x,S*2);return new d(i.fromBytes(_.subarray(0,S)),i.fromBytes(_.subarray(S,S*2)))}static fromDER(x){let{r:S,s:_}=Qt.toSig(j("DER",x));return new d(S,_)}assertValidity(){}addRecoveryBit(x){return new d(this.r,this.s,x)}recoverPublicKey(x){let S=s.ORDER,{r:_,s:A,recovery:P}=this;if(P==null||![0,1,2,3].includes(P))throw new Error("recovery id invalid");if(a*Wu<S&&P>1)throw new Error("recovery id is ambiguous for h>1 curve");let R=P===2||P===3?_+a:_;if(!s.isValid(R))throw new Error("recovery id 2 or 3 invalid");let J=s.toBytes(R),H=e.fromHex(vt(wa((P&1)===0),J)),U=i.inv(R),et=I(j("msgHash",x)),ot=i.create(-et*U),ft=i.create(A*U),$=e.BASE.multiplyUnsafe(ot).add(H.multiplyUnsafe(ft));if($.is0())throw new Error("point at infinify");return $.assertValidity(),$}hasHighS(){return u(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i.neg(this.s),this.recovery):this}toBytes(x){if(x==="compact")return vt(i.toBytes(this.r),i.toBytes(this.s));if(x==="der")return Me(Qt.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Mt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Mt(this.toBytes("compact"))}}let h=xa(i,r.allowedPrivateKeyLengths,r.wrapPrivateKey),m={isValidPrivateKey(y){try{return h(y),!0}catch{return!1}},normPrivateKeyToScalar:h,randomPrivateKey:()=>{let y=a;return qi(n(_o(y)),y)},precompute(y=8,x=e.BASE){return x.precompute(y,!1)}};function w(y,x=!0){return e.fromPrivateKey(y).toBytes(x)}function g(y){if(typeof y=="bigint")return!1;if(y instanceof e)return!0;let S=j("key",y).length,_=s.BYTES,A=_+1,P=2*_+1;if(!(r.allowedPrivateKeyLengths||i.BYTES===A))return S===A||S===P}function v(y,x,S=!0){if(g(y)===!0)throw new Error("first arg must be private key");if(g(x)===!1)throw new Error("second arg must be public key");return e.fromHex(x).multiply(h(y)).toBytes(S)}let T=t.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let x=Fe(y),S=y.length*8-c;return S>0?x>>BigInt(S):x},I=t.bits2int_modN||function(y){return i.create(T(y))},D=ge(c);function b(y){return ae("num < 2^"+c,y,Br,D),i.toBytes(y)}function L(y,x,S=C){if(["recovered","canonical"].some(ft=>ft in S))throw new Error("sign() legacy options not supported");let{hash:_}=t,{lowS:A,prehash:P,extraEntropy:N}=S;A==null&&(A=!0),y=j("msgHash",y),ga(S),P&&(y=j("prehashed msgHash",_(y)));let R=I(y),J=h(x),H=[b(J),b(R)];if(N!=null&&N!==!1){let ft=N===!0?n(s.BYTES):N;H.push(j("extraEntropy",ft))}let U=vt(...H),et=R;function ot(ft){let $=T(ft);if(!i.isValidNot0($))return;let mt=i.inv($),or=e.BASE.multiply($).toAffine(),Pe=i.create(or.x);if(Pe===Br)return;let le=i.create(mt*i.create(et+Pe*J));if(le===Br)return;let qn=(or.x===Pe?0:2)|Number(or.y&_r),Te=le;return A&&u(le)&&(Te=f(le),qn^=1),new d(Pe,Te,qn)}return{seed:U,k2sig:ot}}let C={lowS:t.lowS,prehash:!1},B={lowS:t.lowS,prehash:!1};function p(y,x,S=C){let{seed:_,k2sig:A}=L(y,x,S);return Di(t.hash.outputLen,i.BYTES,o)(_,A)}e.BASE.precompute(8);function E(y,x,S,_=B){let A=y;x=j("msgHash",x),S=j("publicKey",S),ga(_);let{lowS:P,prehash:N,format:R}=_;if("strict"in _)throw new Error("options.strict was renamed to lowS");if(R!==void 0&&!["compact","der","js"].includes(R))throw new Error('format must be "compact", "der" or "js"');let J=typeof A=="string"||Oe(A),H=!J&&!R&&typeof A=="object"&&A!==null&&typeof A.r=="bigint"&&typeof A.s=="bigint";if(!J&&!H)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let U,et;try{if(H)if(R===void 0||R==="js")U=new d(A.r,A.s);else throw new Error("invalid format");if(J){try{R!=="compact"&&(U=d.fromDER(A))}catch(Te){if(!(Te instanceof Qt.Err))throw Te}!U&&R!=="der"&&(U=d.fromCompact(A))}et=e.fromHex(S)}catch{return!1}if(!U||P&&U.hasHighS())return!1;N&&(x=t.hash(x));let{r:ot,s:ft}=U,$=I(x),mt=i.inv(ft),or=i.create($*mt),Pe=i.create(ot*mt),le=e.BASE.multiplyUnsafe(or).add(et.multiplyUnsafe(Pe));return le.is0()?!1:i.create(le.x)===ot}return Object.freeze({getPublicKey:w,getSharedSecret:v,sign:p,verify:E,utils:m,Point:e,Signature:d})}function tl(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=Lt(t.n,e.nBitLength),o={Fp:r,Fn:n,allowedPrivateKeyLengths:e.allowedPrivateKeyLengths,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,wrapPrivateKey:e.wrapPrivateKey,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:o}}function el(e){let{CURVE:t,curveOpts:r}=tl(e),n={hash:e.hash,hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,ecdsaOpts:n}}function rl(e,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:e})}function Ea(e){let{CURVE:t,curveOpts:r,ecdsaOpts:n}=el(e),o=Ju(t,r),s=Qu(o,n,r);return rl(e,s)}function Sa(e,t){let r=n=>Ea({...e,hash:n});return{...r(t),create:r}}var bn={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},lm=BigInt(0),nl=BigInt(1),ds=BigInt(2),va=(e,t)=>(e+t/ds)/t;function ol(e){let t=bn.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=Z(f,r,t)*f%t,d=Z(l,r,t)*f%t,h=Z(d,ds,t)*u%t,m=Z(h,o,t)*h%t,w=Z(m,s,t)*m%t,g=Z(w,a,t)*w%t,v=Z(g,c,t)*g%t,T=Z(v,a,t)*w%t,I=Z(T,r,t)*f%t,D=Z(I,i,t)*m%t,b=Z(D,n,t)*u%t,L=Z(b,ds,t);if(!hs.eql(hs.sqr(L),e))throw new Error("Cannot find square root");return L}var hs=Lt(bn.p,void 0,void 0,{sqrt:ol}),je=Sa({...bn,Fp:hs,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=bn.n,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-nl*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,i=BigInt("0x100000000000000000000000000000000"),a=va(s*e,t),c=va(-n*e,t),u=Y(e-a*r-c*o,t),f=Y(-a*n-c*s,t),l=u>i,d=f>i;if(l&&(u=t-u),d&&(f=t-f),u>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:u,k2neg:d,k2:f}}}},Jr);function Aa(e,t,r,n){let o=fr.digest(r instanceof Uint8Array?r:r.subarray());if(cn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),je.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new Er(String(s))});try{return n?.signal?.throwIfAborted(),je.verify(t,o.digest,e)}catch(s){throw new Er(String(s))}}var gn=class{type="secp256k1";raw;_key;constructor(t){this._key=Ba(t),this.raw=Ia(this._key)}toMultihash(){return Tt.digest(kt(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:st(this.raw,t.raw)}verify(t,r,n){return Aa(this._key,r,t,n)}};function ps(e){return new gn(e)}function Ia(e){return je.ProjectivePoint.fromHex(e).toRawBytes(!0)}function Ba(e){try{return je.ProjectivePoint.fromHex(e),e}catch(t){throw new Ce(String(t))}}function Ze(e,t){let{Type:r,Data:n}=qt.decode(e),o=n??new Uint8Array;switch(r){case tt.RSA:return as(o,t);case tt.Ed25519:return No(o);case tt.secp256k1:return ps(o);case tt.ECDSA:return go(o);default:throw new de}}function _a(e){let{Type:t,Data:r}=qt.decode(e.digest),n=r??new Uint8Array;switch(t){case tt.Ed25519:return No(n);case tt.secp256k1:return ps(n);case tt.ECDSA:return go(n);default:throw new de}}function kt(e){return qt.encode({Type:tt[e.type],Data:e.raw})}var Pr;(function(e){let t;e.codec=()=>(t==null&&(t=Ut((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:at(0),payloadType:at(0),payload:at(0),signature:at(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>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(a&7);break}}}return s})),t),e.encode=r=>Nt(r,e.codec()),e.decode=(r,n)=>Rt(r,e.codec(),n)})(Pr||(Pr={}));var xn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Ht=class e{static createFromProtobuf=t=>{let r=Pr.decode(t),n=Ze(r.publicKey);return new e({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(t,r,n)=>{if(r==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=Pa(o,s,i),c=await r.sign(a.subarray(),n);return new e({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,r,n)=>{let o=e.createFromProtobuf(t);if(!await o.validate(r,n))throw new xn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:r,payloadType:n,payload:o,signature:s}=t;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Pr.encode({publicKey:kt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:st(this.marshal(),t.marshal())}async validate(t,r){let n=Pa(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Pa=(e,t,r)=>{let n=k(e),o=Bt(n.byteLength),s=Bt(t.length),i=Bt(r.length);return new Q(o,n,s,t,i,r)};var Ta=Symbol.for("nodejs.util.inspect.custom"),sl=114,Tr=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()})`}[Hn]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return rt.createV1(sl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return st(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return st(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ta](){return`PeerId(${this.toString()})`}},Cr=class extends Tr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Lr=class extends Tr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Dr=class extends Tr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},il=2336,Rr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Tt.digest(k(this.url))}[Ta](){return`PeerId(${this.url})`}[Hn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return rt.createV1(il,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=K(t)),t.toString()===this.toString())}};var al=114,Ca=2336;function La(e){if(e.type==="Ed25519")return new Lr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Dr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Cr({multihash:e.toCID().multihash,publicKey:e});throw new de}function ms(e){if(fl(e))return new Cr({multihash:e});if(cl(e))try{let t=_a(e);if(t.type==="Ed25519")return new Lr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Dr({multihash:e,publicKey:t})}catch{let r=K(e.digest);return new Rr(new URL(r))}throw new qr("Supplied PeerID Multihash is invalid")}function wn(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==al&&e.code!==Ca)throw new Vr("Supplied PeerID CID is invalid");if(e.code===Ca){let t=K(e.multihash.digest);return new Rr(new URL(t))}return ms(e.multihash)}function cl(e){return e.code===Tt.code}function fl(e){return e.code===fr.code}function Da(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 En=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(f===void 0)break;if(s*=t,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ra=45,ul=15,We=new En;function Sn(e){if(!(e.length>ul))return We.new(e).parseWith(()=>We.readIPv4Addr())}function vn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Ra))return We.new(e).parseWith(()=>We.readIPv6Addr())}function Ae(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>Ra)return;let r=We.new(e).parseWith(()=>We.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 Na(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 Ua(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 ys(e){switch(e.length){case Ie:return e.join(".");case Be:{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 Ka(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 Oa(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var Ie=4,Be=16,Dy=parseInt("0xFFFF",16),ll=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Nr(e,t){t.length===Be&&e.length===Ie&&Na(t,0,11)&&(t=t.slice(12)),t.length===Ie&&e.length===Be&&Ua(e,ll,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 ka(e,t){if(typeof t=="string"&&(t=Ae(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 bs(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=Ie,o=Sn(t);if(o==null&&(n=Be,o=vn(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=gs(s,8*n);return{network:Nr(o,i),mask:i}}function gs(e,t){if(t!==8*Ie&&t!==8*Be)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 Ye=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=bs(t));else{let n=Ae(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=Ae(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=gs(o,8*n.length);this.network=Nr(n,this.mask)}}contains(t){return ka({network:this.network,mask:this.mask},t)}toString(){let t=Ka(this.mask),r=t!==-1?String(t):Oa(this.mask);return ys(this.network)+"/"+r}};function Ma(e,t){return new Ye(e).contains(t)}function Xe(e){return!!Sn(e)}function Je(e){return!!vn(e)}function An(e){return!!Ae(e)}var Fa=Xe,dl=Je,xs=function(e){let t=0;if(e=e.toString().trim(),Fa(e)){let r=new Uint8Array(t+4);return e.split(/\./g).forEach(n=>{r[t++]=parseInt(n,10)&255}),r}if(dl(e)){let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=Fa(r[n]),i;s&&(i=xs(r[n]),r[n]=K(i.slice(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,K(i.slice(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++){let s=parseInt(r[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},Va=function(e,t=0,r){t=~~t,r=r??e.length-t;let n=new DataView(e.buffer);if(r===4){let o=[];for(let s=0;s<r;s++)o.push(e[t+s]);return o.join(".")}if(r===16){let o=[];for(let s=0;s<r;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Qe={},ws={},pl=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];pl.forEach(e=>{let t=ml(...e);ws[t.code]=t,Qe[t.name]=t});function ml(e,t,r,n,o){return{code:e,size:t,name:r,resolvable:!!n,path:!!o}}function F(e){if(typeof e=="number"){if(ws[e]!=null)return ws[e];throw new Error(`no protocol with code: ${e}`)}else if(typeof e=="string"){if(Qe[e]!=null)return Qe[e];throw new Error(`no protocol with name: ${e}`)}throw new Error(`invalid protocol id type: ${typeof e}`)}var lb=F("ip4"),db=F("ip6"),hb=F("ipcidr");function As(e,t){switch(F(e).code){case 4:case 41:return bl(t);case 42:return vs(t);case 43:return K(t,"base10");case 6:case 273:case 33:case 132:return za(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return vs(t);case 421:return El(t);case 444:return Ha(t);case 445:return Ha(t);case 466:return wl(t);case 481:return globalThis.encodeURIComponent(vs(t));default:return K(t,"base16")}}function Is(e,t){switch(F(e).code){case 4:return qa(t);case 41:return qa(t);case 42:return Ss(t);case 43:return k(t,"base10");case 6:case 273:case 33:case 132:return Bs(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ss(t);case 421:return gl(t);case 444:return Sl(t);case 445:return vl(t);case 466:return xl(t);case 481:return Ss(globalThis.decodeURIComponent(t));default:return k(t,"base16")}}var Es=Object.values(ur).map(e=>e.decoder),yl=function(){let e=Es[0].or(Es[1]);return Es.slice(2).forEach(t=>e=e.or(t)),e}();function qa(e){if(!An(e))throw new Error("invalid ip address");return xs(e)}function bl(e){let t=Va(e,0,e.length);if(t==null)throw new Error("ipBuff is required");if(!An(t))throw new Error("invalid ip address");return t}function Bs(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,e),new Uint8Array(t)}function za(e){return new DataView(e.buffer).getUint16(e.byteOffset)}function Ss(e){let t=k(e),r=Uint8Array.from(Bt(t.length));return St([r,t],r.length+t.length)}function vs(e){let t=Jt(e);if(e=e.slice(dt(t)),e.length!==t)throw new Error("inconsistent lengths");return K(e)}function gl(e){let t;e[0]==="Q"||e[0]==="1"?t=he(G.decode(`z${e}`)).bytes:t=rt.parse(e).multihash.bytes;let r=Uint8Array.from(Bt(t.length));return St([r,t],r.length+t.length)}function xl(e){let t=yl.decode(e),r=Uint8Array.from(Bt(t.length));return St([r,t],r.length+t.length)}function wl(e){let t=Jt(e),r=e.slice(dt(t));if(r.length!==t)throw new Error("inconsistent lengths");return"u"+K(r,"base64url")}function El(e){let t=Jt(e),r=e.slice(dt(t));if(r.length!==t)throw new Error("inconsistent lengths");return K(r,"base58btc")}function Sl(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=$t.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=Bs(n);return St([r,o],r.length+o.length)}function vl(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=$t.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=Bs(n);return St([r,o],r.length+o.length)}function Ha(e){let t=e.slice(0,e.length-2),r=e.slice(e.length-2),n=K(t,"base32"),o=za(r);return`${n}:${o}`}function Ga(e){e=_s(e);let t=[],r=[],n=null,o=e.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=F(i);if(a.size===0){t.push([a.code]),r.push([a.code]);continue}if(s++,s>=o.length)throw new In("invalid address: "+e);if(a.path===!0){n=_s(o.slice(s).join("/")),t.push([a.code,Is(a.code,n)]),r.push([a.code,n]);break}let c=Is(a.code,o[s]);t.push([a.code,c]),r.push([a.code,As(a.code,c)])}return{string:$a(r),bytes:Bn(t),tuples:t,stringTuples:r,path:n}}function Ps(e){let t=[],r=[],n=null,o=0;for(;o<e.length;){let s=Jt(e,o),i=dt(s),a=F(s),c=Al(a,e.slice(o+i));if(c===0){t.push([s]),r.push([s]),o+=i;continue}let u=e.slice(o+i,o+i+c);if(o+=c+i,o>e.length)throw new In("Invalid address Uint8Array: "+K(e,"base16"));t.push([s,u]);let f=As(s,u);if(r.push([s,f]),a.path===!0){n=f;break}}return{bytes:Uint8Array.from(e),string:$a(r),tuples:t,stringTuples:r,path:n}}function $a(e){let t=[];return e.map(r=>{let n=F(r[0]);return t.push(n.name),r.length>1&&r[1]!=null&&t.push(r[1]),null}),_s(t.join("/"))}function Bn(e){return St(e.map(t=>{let r=F(t[0]),n=Uint8Array.from(Bt(r.code));return t.length>1&&t[1]!=null&&(n=St([n,t[1]])),n}))}function Al(e,t){if(e.size>0)return e.size/8;if(e.size===0)return 0;{let r=Jt(t instanceof Uint8Array?t:Uint8Array.from(t));return r+dt(r)}}function _s(e){return"/"+e.trim().split("/").filter(t=>t).join("/")}var In=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var Il=Symbol.for("nodejs.util.inspect.custom"),Cs=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Bl=[F("dns").code,F("dns4").code,F("dns6").code,F("dnsaddr").code],Ts=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},_n=class e{bytes;#e;#t;#r;#n;[Cs]=!0;constructor(t){t==null&&(t="");let r;if(t instanceof Uint8Array)r=Ps(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);r=Ga(t)}else if(Za(t))r=Ps(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=r.bytes,this.#e=r.string,this.#t=r.tuples,this.#r=r.stringTuples,this.#n=r.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,r,n,o,s="",i=F("tcp"),a=F("udp"),c=F("ip4"),u=F("ip6"),f=F("dns6"),l=F("ip6zone");for(let[h,m]of this.stringTuples())h===l.code&&(s=`%${m??""}`),Bl.includes(h)&&(r=i.name==="tcp"?"tcp":"udp",o=443,n=`${m??""}${s}`,t=h===f.code?6:4),(h===i.code||h===a.code)&&(r=F(h).name==="tcp"?"tcp":"udp",o=parseInt(m??"")),(h===c.code||h===u.code)&&(r=F(h).name==="tcp"?"tcp":"udp",n=`${m??""}${s}`,t=h===u.code?6:4);if(t==null||r==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:r,port:o}}protos(){return this.#t.map(([t])=>Object.assign({},F(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>F(t).name)}tuples(){return this.#t.map(([t,r])=>r==null?[t]:[t,r])}stringTuples(){return this.#r.map(([t,r])=>r==null?[t]:[t,r])}encapsulate(t){return t=new e(t),new e(this.toString()+t.toString())}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new e(n.slice(0,o))}decapsulateCode(t){let r=this.tuples();for(let n=r.length-1;n>=0;n--)if(r[n][0]===t)return new e(Bn(r.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Qe.p2p.code&&t.push([n,o]),n===Qe["p2p-circuit"].code&&(t=[])});let r=t.pop();if(r?.[1]!=null){let n=r[1];return n[0]==="Q"||n[0]==="1"?K(G.decode(`z${n}`),"base58btc"):K(rt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return st(this.bytes,t.bytes)}async resolve(t){let r=this.protos().find(s=>s.resolvable);if(r==null)return[this];let n=ja.get(r.name);if(n==null)throw new Ts(`no available resolver for ${r.name}`);return(await n(this,t)).map(s=>zt(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let r=(t??this).protos();return!(r.length!==2||r[0].code!==4&&r[0].code!==41||r[1].code!==6&&r[1].code!==273)}[Il](){return`Multiaddr(${this.#e})`}};var ja=new Map;function Za(e){return!!e?.[Cs]}function zt(e){return new _n(e)}var Wa="libp2p-peer-record",Ya=Uint8Array.from([3,1]);var Ur;(function(e){let t;(function(n){let o;n.codec=()=>(o==null&&(o=Ut((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:at(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.multiaddr=s.bytes();break}default:{s.skipType(f&7);break}}}return c})),o),n.encode=s=>Nt(s,n.codec()),n.decode=(s,i)=>Rt(s,n.codec(),i)})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=Ut((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:at(0),seq:0n,addresses:[]},a=o==null?n.len:n.pos+o;for(;n.pos<a;){let c=n.uint32();switch(c>>>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 ve('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(c&7);break}}}return i})),r),e.encode=n=>Nt(n,e.codec()),e.decode=(n,o)=>Rt(n,e.codec(),o)})(Ur||(Ur={}));var Kt=class e{static createFromProtobuf=t=>{let r=Ur.decode(t),n=ms(he(r.peerId)),o=(r.addresses??[]).map(i=>zt(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Wa;static CODEC=Ya;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=Ur.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||!Da(this.multiaddrs,t.multiaddrs))}};function _l(e){return e[Symbol.asyncIterator]!=null}function Pl(e){if(_l(e))return(async()=>{for await(let t of e);})();for(let t of e);}var Xa=Pl;function Ot(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Pn=globalThis.CustomEvent??Event;async function*Ls(e,t={}){let r=t.concurrency??1/0;r<1&&(r=1/0);let n=t.ordered??!1,o=new EventTarget,s=[],i=Ot(),a=Ot(),c=!1,u,f=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of e){if(s.length===r&&(i=Ot(),await i.promise),f)break;let w={done:!1};s.push(w),m().then(g=>{w.done=!0,w.ok=!0,w.value=g,o.dispatchEvent(new Pn("task-complete"))},g=>{w.done=!0,w.err=g,o.dispatchEvent(new Pn("task-complete"))})}c=!0,o.dispatchEvent(new Pn("task-complete"))}catch(m){u=m,o.dispatchEvent(new Pn("task-complete"))}});function l(){return n?s[0]?.done:!!s.find(m=>m.done)}function*d(){for(;s.length>0&&s[0].done;){let m=s[0];if(s.shift(),m.ok)yield m.value;else throw f=!0,i.resolve(),m.err;i.resolve()}}function*h(){for(;l();)for(let m=0;m<s.length;m++)if(s[m].done){let w=s[m];if(s.splice(m,1),m--,w.ok)yield w.value;else throw f=!0,i.resolve(),w.err;i.resolve()}}for(;;){if(l()||(a=Ot(),await a.promise),u!=null||(n?yield*d():yield*h(),u!=null))throw u;if(c&&s.length===0)break}}var Tn=class extends Error{type;code;constructor(t,r,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function Kr(e,t,r){if(t==null)return e;if(t.aborted)return e.catch(()=>{}),Promise.reject(new Tn(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new Tn(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([e,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Ds=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ot(),this.haveNext=Ot()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Ot(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,r){await this._push(t,r)}async end(t,r){t!=null?await this.throw(t):await this._push(void 0,r)}async _push(t,r){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Ot(),await Kr(this.readNext.promise,r?.signal,r)}};function Ja(){return new Ds}var Cn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Qa(e,t){let r=Ja();e.sink(r).catch(async i=>{await r.end(i)}),e.sink=async i=>{for await(let a of i)await r.push(a);await r.end()};let n=e.source;e.source[Symbol.iterator]!=null?n=e.source[Symbol.iterator]():e.source[Symbol.asyncIterator]!=null&&(n=e.source[Symbol.asyncIterator]());let o=new Q;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:c,value:u}=await Kr(n.next(),i?.signal);return c===!0?null:u}for(;o.byteLength<i.bytes;){let{value:c,done:u}=await Kr(n.next(),i?.signal);if(u===!0)throw new Cn("unexpected end of input");o.append(c)}let a=o.sublist(0,i.bytes);return o.consume(i.bytes),a},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await r.push(i,a):await r.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=e.source;e.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return e}}}var Ln=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Dn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Rn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function tc(e,t={}){let r=Qa(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=dt(t.maxDataLength));let n=t?.lengthDecoder??Jt,o=t?.lengthEncoder??Bt;return{read:async i=>{let a=-1,c=new Q;for(;;){c.append(await r.read({...i,bytes:1}));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new Ln("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Rn("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Dn("message length too long");return r.read({...i,bytes:a})},write:async(i,a)=>{await r.write(new Q(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new Q(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap:()=>r.unwrap()}}function tr(e,t){let r=tc(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(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var ec="0.1.0",rc="id",nc="id/push",oc="1.0.0",sc="1.0.0";var ue;(function(e){let t;e.codec=()=>(t==null&&(t=Ut((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 a=r.uint32();switch(a>>>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 ve('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 ve('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(a&7);break}}}return s})),t),e.encode=r=>Nt(r,e.codec()),e.decode=(r,n)=>Rt(r,e.codec(),n)})(ue||(ue={}));var Et={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function ic(e){if(e!=null&&e.length>0)try{return zt(e)}catch{}}function Ll(e,t){return t??e.userAgent}async function Nn(e,t,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new _t("message was null or undefined");let s={};if(o.listenAddrs.length>0&&(s.addresses=o.listenAddrs.map(c=>({isCertified:!1,multiaddr:zt(c)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let c=Ze(o.publicKey);if(!La(c).equals(n.remotePeer))throw new _t("public key did not match remote PeerId");s.publicKey=c}let i;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let c=o.signedPeerRecord,u=await Ht.openAndCertify(c,Kt.DOMAIN),f=Kt.createFromProtobuf(u.payload),l=wn(u.publicKey.toCID());if(!f.peerId.equals(l))throw new _t("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(f.peerId))throw new _t("signing key does not match remote PeerId");let d;try{d=await e.get(f.peerId)}catch(h){if(h.name!=="NotFoundError")throw h}if(d!=null&&(s.metadata=d.metadata,d.peerRecordEnvelope!=null)){let h=Ht.createFromProtobuf(d.peerRecordEnvelope),m=Kt.createFromProtobuf(h.payload);m.seqNumber>=f.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",m.seqNumber,f.seqNumber),f=m,c=d.peerRecordEnvelope)}s.peerRecordEnvelope=c,s.addresses=f.multiaddrs.map(h=>({isCertified:!0,multiaddr:h})),i={seq:f.seqNumber,addresses:f.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 c={};o.agentVersion!=null&&(c.AgentVersion=k(o.agentVersion)),o.protocolVersion!=null&&(c.ProtocolVersion=k(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,c),await e.merge(n.remotePeer,{metadata:c})}let a={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:o.listenAddrs.map(c=>zt(c)),observedAddr:o.observedAddr==null?void 0:zt(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:a}),a}var er=class{host;protocol;started;timeout;peerId;privateKey;peerStore;registrar;addressManager;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;events;runOnLimitedConnection;log;constructor(t,r){this.protocol=r.protocol,this.started=!1,this.peerId=t.peerId,this.privateKey=t.privateKey,this.peerStore=t.peerStore,this.registrar=t.registrar,this.addressManager=t.addressManager,this.events=t.events,this.log=r.log,this.timeout=r.timeout??Et.timeout,this.maxInboundStreams=r.maxInboundStreams??Et.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Et.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Et.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Et.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Et.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Et.protocolPrefix}/${ec}`,agentVersion:Ll(t.nodeInfo,r.agentVersion)}}isStarted(){return this.started}async start(){this.started||(await this.peerStore.merge(this.peerId,{metadata:{AgentVersion:k(this.host.agentVersion),ProtocolVersion:k(this.host.protocolVersion)}}),await this.registrar.handle(this.protocol,t=>{this.handleProtocol(t).catch(r=>{this.log.error(r)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.registrar.unhandle(this.protocol),this.started=!1}};var Un=class extends er{connectionManager;concurrency;constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??Et.protocolPrefix}/${nc}/${sc}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=r.concurrency??Et.concurrency,(r.runOnSelfUpdate??Et.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error(o)})})}[zr]=["@libp2p/identify-push"];async push(){if(!this.isStarted())return;let t=this.addressManager.getAddresses().map(f=>f.decapsulateCode(F("p2p").code)),r=new Kt({peerId:this.peerId,multiaddrs:t}),n=await Ht.seal(r,this.privateKey),o=this.registrar.getProtocols(),s=await this.peerStore.get(this.peerId),i=K(s.metadata.get("AgentVersion")??k(this.host.agentVersion)),a=K(s.metadata.get("ProtocolVersion")??k(this.host.protocolVersion)),c=this;async function*u(){for(let f of c.connectionManager.getConnections())(await c.peerStore.get(f.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let d,h=AbortSignal.timeout(c.timeout);try{d=await f.newStream(c.protocol,{signal:h,runOnLimitedConnection:c.runOnLimitedConnection}),await tr(d,{maxDataLength:c.maxMessageSize}).pb(ue).write({listenAddrs:t.map(w=>w.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:h}),await d.close({signal:h})}catch(m){c.log.error("could not push identify update to peer",m),d?.abort(m)}})}await Xa(Ls(u(),{concurrency:this.concurrency}))}async handleProtocol(t){let{connection:r,stream:n}=t;try{if(this.peerId.equals(r.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},i=await tr(n,{maxDataLength:this.maxMessageSize}).pb(ue).read(o);await n.close(o),await Nn(this.peerStore,this.events,this.log,r,i)}catch(o){this.log.error("received invalid message",o),n.abort(o);return}this.log.trace("handled push from %p",r.remotePeer)}};var Dl=41;function ac(e){try{let[[t,r]]=e.stringTuples();if(r==null)return!1;if(t===Dl)return Ma("2000::/3",r)}catch{}return!1}var fc=_c(cc(),1),Rl=["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"],Nl=Rl.map(e=>new fc.Netmask(e));function Rs(e){for(let t of Nl)if(t.contains(e))return!0;return!1}function Ul(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function Kl(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 Rs(o)}function Ol(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function kl(e){let t=e.split(":"),r=t[t.length-1];return Rs(r)}function Ml(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 uc(e){return Xe(e)?Rs(e):Ul(e)?Kl(e):Ol(e)?kl(e):Je(e)?Ml(e):void 0}function lc(e){try{let[[t]]=e.stringTuples();return t===4||t===41}catch{}return!1}function dc(e){try{if(!lc(e))return!1;let[[,t]]=e.stringTuples();return t==null?!1:uc(t)??!1}catch{}return!0}var Fl=e=>e.toString().split("/").slice(1),rr=e=>({match:t=>t.length<1?!1:e(t[0])?t.slice(1):!1,pattern:"fn"}),O=e=>({match:t=>rr(r=>r===e).match(t),pattern:e}),_e=()=>({match:e=>rr(t=>typeof t=="string").match(e),pattern:"{string}"}),nr=()=>({match:e=>rr(t=>!isNaN(parseInt(t))).match(e),pattern:"{number}"}),z=()=>({match:e=>{if(e.length<2||e[0]!=="p2p"&&e[0]!=="ipfs")return!1;if(e[1].startsWith("Q")||e[1].startsWith("1"))try{G.decode(`z${e[1]}`)}catch{return!1}else return!1;return e.slice(2)},pattern:"/p2p/{peerid}"}),kr=()=>({match:e=>{if(e.length<2||e[0]!=="certhash")return!1;try{oo.decode(e[1])}catch{return!1}return e.slice(2)},pattern:"/certhash/{certhash}"}),V=e=>({match:t=>{let r=e.match(t);return r===!1?t:r},pattern:`optional(${e.pattern})`}),pt=(...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},pattern:`or(${e.map(t=>t.pattern).join(", ")})`}),M=(...e)=>({match:t=>{for(let r of e){let n=r.match(t);if(n===!1)return!1;t=n}return t},pattern:`and(${e.map(t=>t.pattern).join(", ")})`});function W(...e){function t(o){let s=Fl(o);for(let i of e){let a=i.match(s);if(a===!1)return!1;s=a}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 Vl=z(),rx=W(Vl),On=M(O("dns4"),_e()),kn=M(O("dns6"),_e()),Mn=M(O("dnsaddr"),_e()),Us=M(O("dns"),_e()),nx=W(On,V(z())),ox=W(kn,V(z())),sx=W(Mn,V(z())),ix=W(pt(Us,Mn,On,kn),V(z())),hc=M(O("ip4"),rr(Xe)),pc=M(O("ip6"),rr(Je)),Ks=pt(hc,pc),te=pt(Ks,Us,On,kn,Mn),mc=W(pt(Ks,M(pt(Us,Mn,On,kn),V(z())))),ax=W(hc),cx=W(pc),fx=W(Ks),Os=M(te,O("tcp"),nr()),Mr=M(te,O("udp"),nr()),yc=W(M(Os,V(z()))),ux=W(Mr),ks=M(Mr,O("quic"),V(z())),Fn=M(Mr,O("quic-v1"),V(z())),ql=pt(ks,Fn),lx=W(ks),dx=W(Fn),Ns=pt(te,Os,Mr,ks,Fn),bc=pt(M(Ns,O("ws"),V(z()))),hx=W(bc),gc=pt(M(Ns,O("wss"),V(z())),M(Ns,O("tls"),V(M(O("sni"),_e())),O("ws"),V(z()))),px=W(gc),xc=M(Mr,O("webrtc-direct"),V(kr()),V(kr()),V(z())),mx=W(xc),wc=M(Fn,O("webtransport"),V(kr()),V(kr()),V(z())),yx=W(wc),Kn=pt(bc,gc,M(Os,V(z())),M(ql,V(z())),M(te,V(z())),xc,wc,z()),bx=W(Kn),Hl=M(Kn,O("p2p-circuit"),z()),gx=W(Hl),zl=pt(M(Kn,O("p2p-circuit"),O("webrtc"),V(z())),M(Kn,O("webrtc"),V(z())),M(O("webrtc"),V(z()))),xx=W(zl),Gl=pt(M(te,O("tcp"),nr(),O("http"),V(z())),M(te,O("http"),V(z()))),wx=W(Gl),$l=pt(M(te,O("tcp"),pt(M(O("443"),O("http")),M(nr(),O("https")),M(nr(),O("tls"),O("http"))),V(z())),M(te,O("tls"),O("http"),V(z())),M(te,O("https"),V(z()))),Ex=W($l),jl=pt(M(O("memory"),_e(),V(z()))),Sx=W(jl);var Zl=41,Vn=class extends er{constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??Et.protocolPrefix}/${rc}/${oc}`,log:t.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Et.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(s=>{s.name!==Hr.name&&this.log.error("error during identify trigged by connection:open",s)})})}[zr]=["@libp2p/identify"];async _identify(t,r={}){let n;if(r.signal==null){let o=AbortSignal.timeout(this.timeout);r={...r,signal:o}}try{n=await t.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection});let s=await tr(n,{maxDataLength:this.maxMessageSize}).pb(ue).read(r);return await n.close(r),s}catch(o){throw n?.abort(o),o}}async identify(t,r={}){let n=await this._identify(t,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new _t("public key was missing from identify message");let a=Ze(o),c=wn(a.toCID());if(!t.remotePeer.equals(c))throw new _t("identified peer does not match the expected peer");if(this.peerId.equals(c))throw new _t("identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("identify completed for peer %p and protocols %o",c,s),Nn(this.peerStore,this.events,this.log,t,n)}maybeAddObservedAddress(t){let r=ic(t);if(r==null)return;if(this.log.trace("our observed address was %a",r),dc(r)){this.log.trace("our observed address was private");return}if(r.stringTuples()[0][0]===Zl&&!ac(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}yc.exactMatch(r)||(this.log.trace("storing the observed address"),this.addressManager.addObservedAddr(r))}async handleProtocol(t){let{connection:r,stream:n}=t,o=AbortSignal.timeout(this.timeout);try{let s=await this.peerStore.get(this.peerId),i=this.addressManager.getAddresses().map(f=>f.decapsulateCode(F("p2p").code)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let f=new Kt({peerId:this.peerId,multiaddrs:i});a=(await Ht.seal(f,this.privateKey)).marshal().subarray()}let c=r.remoteAddr.bytes;mc.matches(r.remoteAddr)||(c=void 0),await tr(n).pb(ue).write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:kt(this.privateKey.publicKey),listenAddrs:i.map(f=>f.bytes),signedPeerRecord:a,observedAddr:c,protocols:s.protocols},{signal:o}),await n.close({signal:o})}catch(s){this.log.error("could not respond to identify request",s),n.abort(s)}}};function Wl(e={}){return t=>new Vn(t,e)}function Yl(e={}){return t=>new Un(t,e)}return Pc(Xl);})();
2
+ "use strict";var Libp2PIdentify=(()=>{var kc=Object.create;var Xr=Object.defineProperty;var Mc=Object.getOwnPropertyDescriptor;var Fc=Object.getOwnPropertyNames;var Vc=Object.getPrototypeOf,Hc=Object.prototype.hasOwnProperty;var qc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),gt=(e,t)=>{for(var r in t)Xr(e,r,{get:t[r],enumerable:!0})},Xs=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Fc(t))!Hc.call(e,o)&&o!==r&&Xr(e,o,{get:()=>t[o],enumerable:!(n=Mc(t,o))||n.enumerable});return e};var zc=(e,t,r)=>(r=e!=null?kc(Vc(e)):{},Xs(t||!e||!e.__esModule?Xr(r,"default",{value:e,enumerable:!0}):r,e)),Gc=e=>Xs(Xr({},"__esModule",{value:!0}),e);var Ic=qc(jr=>{(function(){var e,t,r,n,o,s,i,a;a=function(c){var u,f,l,d;return u=(c&255<<24)>>>24,f=(c&255<<16)>>>16,l=(c&65280)>>>8,d=c&255,[u,f,l,d].join(".")},i=function(c){var u,f,l,d,p,m;for(u=[],l=d=0;d<=3&&c.length!==0;l=++d){if(l>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}m=t(c),p=m[0],f=m[1],c=c.substring(f),u.push(p)}if(c.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(c){return c.charCodeAt(0)},n=r("0"),s=r("a"),o=r("A"),t=function(c){var u,f,l,d,p;for(d=0,u=10,f="9",l=0,c.length>1&&c[l]==="0"&&(c[l+1]==="x"||c[l+1]==="X"?(l+=2,u=16):"0"<=c[l+1]&&c[l+1]<="9"&&(l++,u=8,f="7")),p=l;l<c.length;){if("0"<=c[l]&&c[l]<=f)d=d*u+(r(c[l])-n)>>>0;else if(u===16)if("a"<=c[l]&&c[l]<="f")d=d*u+(10+r(c[l])-s)>>>0;else if("A"<=c[l]&&c[l]<="F")d=d*u+(10+r(c[l])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");l++}if(l===p)throw new Error("empty octet");return[d,l]},e=function(){function c(u,f){var l,d,p,m;if(typeof u!="string")throw new Error("Missing `net' parameter");if(f||(m=u.split("/",2),u=m[0],f=m[1]),f||(f=32),typeof f=="string"&&f.indexOf(".")>-1){try{this.maskLong=i(f)}catch(w){throw l=w,new Error("Invalid mask: "+f)}for(d=p=32;p>=0;d=--p)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;break}}else if(f||f===0)this.bitmask=parseInt(f,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(w){throw l=w,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+f);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var f,l,d;for(d=i(this.first),l=i(this.last),f=0;d<=l;)u(a(d),d,f),f++,d++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),jr.ip2long=i,jr.long2ip=a,jr.Netmask=e}).call(jr)});var Kd={};gt(Kd,{identify:()=>Nd,identifyPush:()=>Ud});var eo=Symbol.for("@libp2p/peer-id");var rt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Le=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Qr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Jr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}},tn=class extends Error{static name="UnsupportedProtocolError";constructor(t="Unsupported protocol error"){super(t),this.name="UnsupportedProtocolError"}},Bt=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var pe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var en=Symbol.for("@libp2p/service-capabilities"),Vd=Symbol.for("@libp2p/service-dependencies");var io={};gt(io,{base58btc:()=>G,base58flickr:()=>Qc});var fh=new Uint8Array(0);function Qs(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 $t(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 Js(e){return new TextEncoder().encode(e)}function ti(e){return new TextDecoder().decode(e)}function $c(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,c=e.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var w=0,g=0,v=0,P=m.length;v!==P&&m[v]===0;)v++,w++;for(var I=(P-v)*f+1>>>0,O=new Uint8Array(I);v!==P;){for(var b=m[v],D=0,T=I-1;(b!==0||D<g)&&T!==-1;T--,D++)b+=256*O[T]>>>0,O[T]=b%a>>>0,b=b/a>>>0;if(b!==0)throw new Error("Non-zero carry");g=D,v++}for(var _=I-g;_!==I&&O[_]===0;)_++;for(var h=c.repeat(w);_<I;++_)h+=e.charAt(O[_]);return h}function d(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var w=0;if(m[w]!==" "){for(var g=0,v=0;m[w]===c;)g++,w++;for(var P=(m.length-w)*u+1>>>0,I=new Uint8Array(P);m[w];){var O=r[m.charCodeAt(w)];if(O===255)return;for(var b=0,D=P-1;(O!==0||b<v)&&D!==-1;D--,b++)O+=a*I[D]>>>0,I[D]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");v=b,w++}if(m[w]!==" "){for(var T=P-v;T!==P&&I[T]===0;)T++;for(var _=new Uint8Array(g+(P-T)),h=g;T!==P;)_[h++]=I[T++];return _}}}function p(m){var w=d(m);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:p}}var Wc=$c,jc=Wc,ri=jc;var ro=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")}},no=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 ni(this,t)}},oo=class{decoders;constructor(t){this.decoders=t}or(t){return ni(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 ni(e,t){return new oo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var so=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 ro(t,r,n),this.decoder=new no(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Re({name:e,prefix:t,encode:r,decode:n}){return new so(e,t,r,n)}function re({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=ri(r,e);return Re({prefix:t,name:e,encode:n,decode:s=>$t(o(s))})}function Zc(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Yc(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Xc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Y({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Xc(n);return Re({prefix:t,name:e,encode(s){return Yc(s,n,r)},decode(s){return Zc(s,o,r,e)}})}var G=re({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Qc=re({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ao={};gt(ao,{base32:()=>ne,base32hex:()=>rf,base32hexpad:()=>of,base32hexpadupper:()=>sf,base32hexupper:()=>nf,base32pad:()=>tf,base32padupper:()=>ef,base32upper:()=>Jc,base32z:()=>af});var ne=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Jc=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),tf=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ef=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),rf=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),nf=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),of=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),sf=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),af=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var co={};gt(co,{base36:()=>lr,base36upper:()=>cf});var lr=re({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),cf=re({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ff=ii,oi=128,uf=127,lf=~uf,df=Math.pow(2,31);function ii(e,t,r){t=t||[],r=r||0;for(var n=r;e>=df;)t[r++]=e&255|oi,e/=128;for(;e&lf;)t[r++]=e&255|oi,e>>>=7;return t[r]=e|0,ii.bytes=r-n+1,t}var hf=fo,pf=128,si=127;function fo(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw fo.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&si)<<o:(i&si)*Math.pow(2,o),o+=7}while(i>=pf);return fo.bytes=s-n,r}var mf=Math.pow(2,7),yf=Math.pow(2,14),bf=Math.pow(2,21),gf=Math.pow(2,28),xf=Math.pow(2,35),wf=Math.pow(2,42),Ef=Math.pow(2,49),Sf=Math.pow(2,56),vf=Math.pow(2,63),Af=function(e){return e<mf?1:e<yf?2:e<bf?3:e<gf?4:e<xf?5:e<wf?6:e<Ef?7:e<Sf?8:e<vf?9:10},If={encode:ff,decode:hf,encodingLength:Af},_f=If,dr=_f;function hr(e,t=0){return[dr.decode(e,t),dr.decode.bytes]}function Ne(e,t,r=0){return dr.encode(e,t,r),t}function Ue(e){return dr.encodingLength(e)}function Pt(e,t){let r=t.byteLength,n=Ue(e),o=n+Ue(r),s=new Uint8Array(o+r);return Ne(e,s,0),Ne(r,s,n),s.set(t,o),new Ke(e,r,t,s)}function pr(e){let t=$t(e),[r,n]=hr(t),[o,s]=hr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ke(r,o,i,t)}function ai(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Qs(e.bytes,r.bytes)}}var Ke=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function ci(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Bf(r,uo(e),t??G.encoder);default:return Pf(r,uo(e),t??ne.encoder)}}var fi=new WeakMap;function uo(e){let t=fi.get(e);if(t==null){let r=new Map;return fi.set(e,r),r}return t}var et=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=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!==mr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Tf)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=Pt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&ai(t.multihash,n.multihash)}toString(t){return ci(this,t)}toJSON(){return{"/":ci(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??ui(n,o,s.bytes))}else if(r[Df]===!0){let{version:n,multihash:o,code:s}=r,i=pr(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!==mr)throw new Error(`Version 0 CID must use dag-pb (code: ${mr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ui(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,mr,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=$t(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Ke(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,d]=hr(t.subarray(r));return r+=d,l},o=n(),s=mr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,o]=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 uo(s).set(n,t),s}};function Cf(e,t){switch(e[0]){case"Q":{let r=t??G;return[G.prefix,r.decode(`${G.prefix}${e}`)]}case G.prefix:{let r=t??G;return[G.prefix,r.decode(e)]}case ne.prefix:{let r=t??ne;return[ne.prefix,r.decode(e)]}case lr.prefix:{let r=t??lr;return[lr.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 Bf(e,t,r){let{prefix:n}=r;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Pf(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 mr=112,Tf=18;function ui(e,t,r){let n=Ue(e),o=n+Ue(t),s=new Uint8Array(o+r.byteLength);return Ne(e,s,0),Ne(t,s,n),s.set(r,o),s}var Df=Symbol.for("@ipld/js-cid/CID");var lo={};gt(lo,{identity:()=>Tt});var li=0,Of="identity",di=$t;function Lf(e){return Pt(li,di(e))}var Tt={code:li,name:Of,encode:di,digest:Lf};function ot(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 it(e=0){return new Uint8Array(e)}function xt(e=0){return new Uint8Array(e)}function Wt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=xt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var pi=Symbol.for("@achingbrain/uint8arraylist");function hi(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 nn(e){return!!e?.[pi]}var Q=class e{bufs;length;[pi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(nn(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(nn(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=hi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=hi(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(nn(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 Wt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Wt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!nn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let d=u;d>=0;d--){let p=this.get(l+d);if(n[d]!==p){f=Math.max(1,d-a[p]);break}}if(f===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=xt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=it(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=it(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=it(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=xt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=it(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=it(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=it(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=it(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=it(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(!ot(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 ho={};gt(ho,{base10:()=>Rf});var Rf=re({prefix:"9",name:"base10",alphabet:"0123456789"});var po={};gt(po,{base16:()=>Nf,base16upper:()=>Uf});var Nf=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Uf=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var mo={};gt(mo,{base2:()=>Kf});var Kf=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var yo={};gt(yo,{base256emoji:()=>Hf});var mi=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),kf=mi.reduce((e,t,r)=>(e[r]=t,e),[]),Mf=mi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Ff(e){return e.reduce((t,r)=>(t+=kf[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=Mf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Hf=Re({prefix:"\u{1F680}",name:"base256emoji",encode:Ff,decode:Vf});var bo={};gt(bo,{base64:()=>qf,base64pad:()=>zf,base64url:()=>yr,base64urlpad:()=>Gf});var qf=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),zf=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),yr=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Gf=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var go={};gt(go,{base8:()=>$f});var $f=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var xo={};gt(xo,{identity:()=>Wf});var Wf=Re({prefix:"\0",name:"identity",encode:e=>ti(e),decode:e=>Js(e)});var $h=new TextEncoder,Wh=new TextDecoder;var So={};gt(So,{sha256:()=>br,sha512:()=>Yf});function Eo({name:e,code:t,encode:r}){return new wo(e,t,r)}var wo=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?Pt(this.code,r):r.then(n=>Pt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function bi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var br=Eo({name:"sha2-256",code:18,encode:bi("SHA-256")}),Yf=Eo({name:"sha2-512",code:19,encode:bi("SHA-512")});var gr={...xo,...mo,...go,...ho,...po,...ao,...co,...io,...bo,...yo},sp={...So,...lo};function xi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var gi=xi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),vo=xi("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=xt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Xf={utf8:gi,"utf-8":gi,hex:gr.base16,latin1:vo,ascii:vo,binary:vo,...gr},on=Xf;function U(e,t="utf8"){let r=on[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function K(e,t="utf8"){let r=on[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Qf=parseInt("11111",2),Ao=parseInt("10000000",2),Jf=parseInt("01111111",2),wi={0:xr,1:xr,2:tu,3:nu,4:ou,5:ru,6:eu,16:xr,22:xr,48:xr};function jt(e,t={offset:0}){let r=e[t.offset]&Qf;if(t.offset++,wi[r]!=null)return wi[r](e,t);throw new Error("No decoder for tag "+r)}function wr(e,t){let r=0;if((e[t.offset]&Ao)===Ao){let n=e[t.offset]&Jf,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 xr(e,t){wr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=jt(e,t);if(n===null)break;r.push(n)}return r}function tu(e,t){let r=wr(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 eu(e,t){let r=wr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function ru(e,t){return t.offset++,null}function nu(e,t){let r=wr(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 ou(e,t){let r=wr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function su(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Q;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Io(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=su(e.byteLength);return new Q(Uint8Array.from([t.byteLength|Ao]),t)}function wt(e){let t=new Q,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Q(Uint8Array.from([2]),Io(t),t)}function sn(e){let t=Uint8Array.from([0]),r=new Q(t,e);return new Q(Uint8Array.from([3]),Io(r),r)}function oe(e,t=48){let r=new Q;for(let n of e)r.append(n);return new Q(Uint8Array.from([t]),Io(r),r)}async function Ei(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 iu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),au=Uint8Array.from([6,5,43,129,4,0,34]),cu=Uint8Array.from([6,5,43,129,4,0,35]),fu={ext:!0,kty:"EC",crv:"P-256"},uu={ext:!0,kty:"EC",crv:"P-384"},lu={ext:!0,kty:"EC",crv:"P-521"},_o=32,Co=48,Bo=66;function Po(e){let t=jt(e);return Si(t)}function Si(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===_o*2+1)return n=K(t.subarray(r,r+_o),"base64url"),o=K(t.subarray(r+_o),"base64url"),new ke({...fu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Co*2+1)return n=K(t.subarray(r,r+Co),"base64url"),o=K(t.subarray(r+Co),"base64url"),new ke({...uu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Bo*2+1)return n=K(t.subarray(r,r+Bo),"base64url"),o=K(t.subarray(r+Bo),"base64url"),new ke({...lu,key_ops:["verify"],x:n,y:o});throw new rt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function vi(e){return oe([wt(Uint8Array.from([1])),oe([du(e.crv)],160),oe([sn(new Q(Uint8Array.from([4]),U(e.x??"","base64url"),U(e.y??"","base64url")))],161)]).subarray()}function du(e){if(e==="P-256")return iu;if(e==="P-384")return au;if(e==="P-521")return cu;throw new rt(`Invalid curve ${e}`)}var ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=vi(this.jwk)),this._raw}toMultihash(){return Tt.digest(Mt(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}async verify(t,r,n){return Ei(this.jwk,r,t,n)}};var ye=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Fe(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Er(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function lt(e,...t){if(!Fe(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 Ii(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Er(e.outputLen),Er(e.blockLen)}function Ve(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 _i(e,t){lt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Yt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function an(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Dt(e,t){return e<<32-t|e>>>t}var Ci=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",hu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ft(e){if(lt(e),Ci)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=hu[e[r]];return t}var Zt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ai(e){if(e>=Zt._0&&e<=Zt._9)return e-Zt._0;if(e>=Zt.A&&e<=Zt.F)return e-(Zt.A-10);if(e>=Zt.a&&e<=Zt.f)return e-(Zt.a-10)}function He(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ci)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=Ai(e.charCodeAt(s)),a=Ai(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Bi(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Sr(e){return typeof e=="string"&&(e=Bi(e)),lt(e),e}function At(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];lt(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 Me=class{};function To(e){let t=n=>e().update(Sr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function vr(e=32){if(ye&&typeof ye.getRandomValues=="function")return ye.getRandomValues(new Uint8Array(e));if(ye&&typeof ye.randomBytes=="function")return Uint8Array.from(ye.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function pu(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?4:0,u=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+u,a,n)}function Pi(e,t,r){return e&t^~e&r}function Ti(e,t,r){return e&t^e&r^t&r}var Ar=class extends Me{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=an(this.buffer)}update(t){Ve(this),t=Sr(t),lt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=an(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ve(this),_i(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Yt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;pu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=an(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Xt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var at=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var cn=BigInt(4294967295),Di=BigInt(32);function mu(e,t=!1){return t?{h:Number(e&cn),l:Number(e>>Di&cn)}:{h:Number(e>>Di&cn)|0,l:Number(e&cn)|0}}function Oi(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=mu(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Do=(e,t,r)=>e>>>r,Oo=(e,t,r)=>e<<32-r|t>>>r,be=(e,t,r)=>e>>>r|t<<32-r,ge=(e,t,r)=>e<<32-r|t>>>r,Ir=(e,t,r)=>e<<64-r|t>>>r-32,_r=(e,t,r)=>e>>>r-32|t<<64-r;function Vt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Li=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ri=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Ni=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ui=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ki=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ki=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var bu=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),se=new Uint32Array(64),fn=class extends Ar{constructor(t=32){super(64,t,8,!1),this.A=Xt[0]|0,this.B=Xt[1]|0,this.C=Xt[2]|0,this.D=Xt[3]|0,this.E=Xt[4]|0,this.F=Xt[5]|0,this.G=Xt[6]|0,this.H=Xt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)se[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=se[l-15],p=se[l-2],m=Dt(d,7)^Dt(d,18)^d>>>3,w=Dt(p,17)^Dt(p,19)^p>>>10;se[l]=w+se[l-7]+m+se[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Dt(a,6)^Dt(a,11)^Dt(a,25),p=f+d+Pi(a,c,u)+bu[l]+se[l]|0,w=(Dt(n,2)^Dt(n,13)^Dt(n,22))+Ti(n,o,s)|0;f=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+w|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Yt(se)}destroy(){this.set(0,0,0,0,0,0,0,0),Yt(this.buffer)}};var Mi=Oi(["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))),gu=Mi[0],xu=Mi[1],ie=new Uint32Array(80),ae=new Uint32Array(80),Lo=class extends Ar{constructor(t=64){super(128,t,16,!1),this.Ah=at[0]|0,this.Al=at[1]|0,this.Bh=at[2]|0,this.Bl=at[3]|0,this.Ch=at[4]|0,this.Cl=at[5]|0,this.Dh=at[6]|0,this.Dl=at[7]|0,this.Eh=at[8]|0,this.El=at[9]|0,this.Fh=at[10]|0,this.Fl=at[11]|0,this.Gh=at[12]|0,this.Gl=at[13]|0,this.Hh=at[14]|0,this.Hl=at[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:p,Gl:m,Hh:w,Hl:g}=this;return[t,r,n,o,s,i,a,c,u,f,l,d,p,m,w,g]}set(t,r,n,o,s,i,a,c,u,f,l,d,p,m,w,g){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=p|0,this.Gl=m|0,this.Hh=w|0,this.Hl=g|0}process(t,r){for(let I=0;I<16;I++,r+=4)ie[I]=t.getUint32(r),ae[I]=t.getUint32(r+=4);for(let I=16;I<80;I++){let O=ie[I-15]|0,b=ae[I-15]|0,D=be(O,b,1)^be(O,b,8)^Do(O,b,7),T=ge(O,b,1)^ge(O,b,8)^Oo(O,b,7),_=ie[I-2]|0,h=ae[I-2]|0,E=be(_,h,19)^Ir(_,h,61)^Do(_,h,6),y=ge(_,h,19)^_r(_,h,61)^Oo(_,h,6),x=Ni(T,y,ae[I-7],ae[I-16]),S=Ui(x,D,E,ie[I-7],ie[I-16]);ie[I]=S|0,ae[I]=x|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:p,Fl:m,Gh:w,Gl:g,Hh:v,Hl:P}=this;for(let I=0;I<80;I++){let O=be(l,d,14)^be(l,d,18)^Ir(l,d,41),b=ge(l,d,14)^ge(l,d,18)^_r(l,d,41),D=l&p^~l&w,T=d&m^~d&g,_=Ki(P,b,T,xu[I],ae[I]),h=ki(_,v,O,D,gu[I],ie[I]),E=_|0,y=be(n,o,28)^Ir(n,o,34)^Ir(n,o,39),x=ge(n,o,28)^_r(n,o,34)^_r(n,o,39),S=n&s^n&a^s&a,C=o&i^o&c^i&c;v=w|0,P=g|0,w=p|0,g=m|0,p=l|0,m=d|0,{h:l,l:d}=Vt(u|0,f|0,h|0,E|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let A=Li(E,x,C);n=Ri(A,h,y,S),o=A|0}({h:n,l:o}=Vt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Vt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Vt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Vt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Vt(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:m}=Vt(this.Fh|0,this.Fl|0,p|0,m|0),{h:w,l:g}=Vt(this.Gh|0,this.Gl|0,w|0,g|0),{h:v,l:P}=Vt(this.Hh|0,this.Hl|0,v|0,P|0),this.set(n,o,s,i,a,c,u,f,l,d,p,m,w,g,v,P)}roundClean(){Yt(ie,ae)}destroy(){Yt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var un=To(()=>new fn);var Fi=To(()=>new Lo);var Uo=BigInt(0),No=BigInt(1);function Qt(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function Cr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Vi(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Uo:BigInt("0x"+e)}function qe(e){return Vi(Ft(e))}function xe(e){return lt(e),Vi(Ft(Uint8Array.from(e).reverse()))}function ln(e,t){return He(e.toString(16).padStart(t*2,"0"))}function ze(e,t){return ln(e,t).reverse()}function $(e,t,r){let n;if(typeof t=="string")try{n=He(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Fe(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}var Ro=e=>typeof e=="bigint"&&Uo<=e;function Hi(e,t,r){return Ro(e)&&Ro(t)&&Ro(r)&&t<=e&&e<r}function ce(e,t,r,n){if(!Hi(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function qi(e){let t;for(t=0;e>Uo;e>>=No,t+=1);return t}var we=e=>(No<<BigInt(e))-No;function zi(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=p=>new Uint8Array(p),o=p=>Uint8Array.of(p),s=n(e),i=n(e),a=0,c=()=>{s.fill(1),i.fill(0),a=0},u=(...p)=>r(i,s,...p),f=(p=n(0))=>{i=u(o(0),p),s=u(),p.length!==0&&(i=u(o(1),p),s=u())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,m=[];for(;p<t;){s=u();let w=s.slice();m.push(w),p+=s.length}return At(...m)};return(p,m)=>{c(),f(p);let w;for(;!(w=m(l()));)f();return c(),w}}function fe(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let a=e[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}function Ge(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 yt=BigInt(0),st=BigInt(1),Ee=BigInt(2),wu=BigInt(3),Wi=BigInt(4),ji=BigInt(5),Zi=BigInt(8);function Z(e,t){let r=e%t;return r>=yt?r:t+r}function W(e,t,r){let n=e;for(;t-- >yt;)n*=n,n%=r;return n}function Gi(e,t){if(e===yt)throw new Error("invert: expected non-zero number");if(t<=yt)throw new Error("invert: expected positive modulus, got "+t);let r=Z(e,t),n=t,o=yt,s=st,i=st,a=yt;for(;r!==yt;){let u=n/r,f=n%r,l=o-i*u,d=s-a*u;n=r,r=f,o=i,s=a,i=l,a=d}if(n!==st)throw new Error("invert: does not exist");return Z(o,t)}function Yi(e,t){let r=(e.ORDER+st)/Wi,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function Eu(e,t){let r=(e.ORDER-ji)/Zi,n=e.mul(t,Ee),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Ee),o),a=e.mul(s,e.sub(i,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}function Su(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-st,r=0;for(;t%Ee===yt;)t/=Ee,r++;let n=Ee,o=Ot(e);for(;$i(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Yi;let s=o.pow(n,t),i=(t+st)/Ee;return function(c,u){if(c.is0(u))return u;if($i(c,u)!==1)throw new Error("Cannot find square root");let f=r,l=c.mul(c.ONE,s),d=c.pow(u,t),p=c.pow(u,i);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let m=1,w=c.sqr(d);for(;!c.eql(w,c.ONE);)if(m++,w=c.sqr(w),m===f)throw new Error("Cannot find square root");let g=st<<BigInt(f-m-1),v=c.pow(l,g);f=m,l=c.sqr(v),d=c.mul(d,l),p=c.mul(p,v)}return p}}function vu(e){return e%Wi===wu?Yi:e%Zi===ji?Eu:Su(e)}var Xi=(e,t)=>(Z(e,t)&st)===st,Au=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ko(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Au.reduce((n,o)=>(n[o]="function",n),t);return fe(e,r),e}function Iu(e,t,r){if(r<yt)throw new Error("invalid exponent, negatives unsupported");if(r===yt)return e.ONE;if(r===st)return t;let n=e.ONE,o=t;for(;r>yt;)r&st&&(n=e.mul(n,o)),o=e.sqr(o),r>>=st;return n}function Br(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function $i(e,t){let r=(e.ORDER-st)/Ee,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 Qi(e,t){t!==void 0&&Er(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Ot(e,t,r=!1,n={}){if(e<=yt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=Qi(e,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,u=Object.freeze({ORDER:e,isLE:r,BITS:i,BYTES:a,MASK:we(i),ZERO:yt,ONE:st,create:f=>Z(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return yt<=f&&f<e},is0:f=>f===yt,isValidNot0:f=>!u.is0(f)&&u.isValid(f),isOdd:f=>(f&st)===st,neg:f=>Z(-f,e),eql:(f,l)=>f===l,sqr:f=>Z(f*f,e),add:(f,l)=>Z(f+l,e),sub:(f,l)=>Z(f-l,e),mul:(f,l)=>Z(f*l,e),pow:(f,l)=>Iu(u,f,l),div:(f,l)=>Z(f*Gi(l,e),e),sqrN:f=>f*f,addN:(f,l)=>f+l,subN:(f,l)=>f-l,mulN:(f,l)=>f*l,inv:f=>Gi(f,e),sqrt:s||(f=>(c||(c=vu(e)),c(u,f))),toBytes:f=>r?ze(f,a):ln(f,a),fromBytes:f=>{if(f.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);return r?xe(f):qe(f)},invertBatch:f=>Br(u,f),cmov:(f,l,d)=>d?l:f});return Object.freeze(u)}function Ji(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 ko(e){let t=Ji(e);return t+Math.ceil(t/2)}function ta(e,t,r=!1){let n=e.length,o=Ji(t),s=ko(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?xe(e):qe(e),a=Z(i,t-st)+st;return r?ze(a,o):ln(a,o)}var We=BigInt(0),Se=BigInt(1);function $e(e,t){let r=t.negate();return e?r:t}function dn(e,t,r){let n=t==="pz"?i=>i.pz:i=>i.ez,o=Br(e.Fp,r.map(n));return r.map((i,a)=>i.toAffine(o[a])).map(e.fromAffine)}function oa(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Mo(e,t){oa(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=we(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ea(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=Se);let u=t*n,f=u+Math.abs(a)-1,l=a===0,d=a<0,p=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:d,isNegF:p,offsetF:u}}function _u(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 Cu(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 Fo=new WeakMap,sa=new WeakMap;function Vo(e){return sa.get(e)||1}function ra(e){if(e!==We)throw new Error("invalid wNAF")}function hn(e,t){return{constTimeNegate:$e,hasPrecomputes(r){return Vo(r)!==1},unsafeLadder(r,n,o=e.ZERO){let s=r;for(;n>We;)n&Se&&(o=o.add(s)),s=s.double(),n>>=Se;return o},precomputeWindow(r,n){let{windows:o,windowSize:s}=Mo(n,t),i=[],a=r,c=a;for(let u=0;u<o;u++){c=a,i.push(c);for(let f=1;f<s;f++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(r,n,o){let s=e.ZERO,i=e.BASE,a=Mo(r,t);for(let c=0;c<a.windows;c++){let{nextN:u,offset:f,isZero:l,isNeg:d,isNegF:p,offsetF:m}=ea(o,c,a);o=u,l?i=i.add($e(p,n[m])):s=s.add($e(d,n[f]))}return ra(o),{p:s,f:i}},wNAFUnsafe(r,n,o,s=e.ZERO){let i=Mo(r,t);for(let a=0;a<i.windows&&o!==We;a++){let{nextN:c,offset:u,isZero:f,isNeg:l}=ea(o,a,i);if(o=c,!f){let d=n[u];s=s.add(l?d.negate():d)}}return ra(o),s},getPrecomputes(r,n,o){let s=Fo.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&(typeof o=="function"&&(s=o(s)),Fo.set(n,s))),s},wNAFCached(r,n,o){let s=Vo(r);return this.wNAF(s,this.getPrecomputes(s,r,o),n)},wNAFCachedUnsafe(r,n,o,s){let i=Vo(r);return i===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,r,o),n,s)},setWindowSize(r,n){oa(n,t),sa.set(r,n),Fo.delete(r)}}}function ia(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>We||n>We;)r&Se&&(s=s.add(o)),n&Se&&(i=i.add(o)),o=o.double(),r>>=Se,n>>=Se;return{p1:s,p2:i}}function pn(e,t,r,n){_u(r,e),Cu(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,a=qi(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=we(c),f=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,d=i;for(let p=l;p>=0;p-=c){f.fill(i);for(let w=0;w<s;w++){let g=n[w],v=Number(g>>BigInt(p)&u);f[v]=f[v].add(r[w])}let m=i;for(let w=f.length-1,g=i;w>0;w--)g=g.add(f[w]),m=m.add(g);if(d=d.add(m),p!==0)for(let w=0;w<c;w++)d=d.double()}return d}function na(e,t){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ko(t),t}else return Ot(e)}function mn(e,t,r={}){if(!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>We))throw new Error(`CURVE.${a} must be positive bigint`)}let n=na(t.p,r.Fp),o=na(t.n,r.Fn),i=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Ht=BigInt(0),bt=BigInt(1),Ho=BigInt(2),Bu=BigInt(8),Pu={zip215:!0};function Tu(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function Du(e,t={}){let{Fp:r,Fn:n}=mn("edwards",e,t),{h:o,n:s}=e;fe(t,{},{uvRatio:"function"});let i=Ho<<BigInt(n.BYTES*8)-bt,a=w=>r.create(w),c=t.uvRatio||((w,g)=>{try{return{isValid:!0,value:r.sqrt(r.div(w,g))}}catch{return{isValid:!1,value:Ht}}});if(!Tu(r,e,e.Gx,e.Gy))throw new Error("bad curve params: generator point");function u(w,g,v=!1){let P=v?bt:Ht;return ce("coordinate "+w,g,P,i),g}function f(w){if(!(w instanceof p))throw new Error("ExtendedPoint expected")}let l=Ge((w,g)=>{let{ex:v,ey:P,ez:I}=w,O=w.is0();g==null&&(g=O?Bu:r.inv(I));let b=a(v*g),D=a(P*g),T=a(I*g);if(O)return{x:Ht,y:bt};if(T!==bt)throw new Error("invZ was invalid");return{x:b,y:D}}),d=Ge(w=>{let{a:g,d:v}=e;if(w.is0())throw new Error("bad point: ZERO");let{ex:P,ey:I,ez:O,et:b}=w,D=a(P*P),T=a(I*I),_=a(O*O),h=a(_*_),E=a(D*g),y=a(_*a(E+T)),x=a(h+a(v*a(D*T)));if(y!==x)throw new Error("bad point: equation left != right (1)");let S=a(P*I),C=a(O*b);if(S!==C)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(g,v,P,I){this.ex=u("x",g),this.ey=u("y",v),this.ez=u("z",P,!0),this.et=u("t",I),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(g){if(g instanceof p)throw new Error("extended point not allowed");let{x:v,y:P}=g||{};return u("x",v),u("y",P),new p(v,P,bt,a(v*P))}static normalizeZ(g){return dn(p,"ez",g)}static msm(g,v){return pn(p,n,g,v)}_setWindowSize(g){this.precompute(g)}precompute(g=8,v=!0){return m.setWindowSize(this,g),v||this.multiply(Ho),this}assertValidity(){d(this)}equals(g){f(g);let{ex:v,ey:P,ez:I}=this,{ex:O,ey:b,ez:D}=g,T=a(v*D),_=a(O*I),h=a(P*D),E=a(b*I);return T===_&&h===E}is0(){return this.equals(p.ZERO)}negate(){return new p(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:g}=e,{ex:v,ey:P,ez:I}=this,O=a(v*v),b=a(P*P),D=a(Ho*a(I*I)),T=a(g*O),_=v+P,h=a(a(_*_)-O-b),E=T+b,y=E-D,x=T-b,S=a(h*y),C=a(E*x),A=a(h*x),B=a(y*E);return new p(S,C,B,A)}add(g){f(g);let{a:v,d:P}=e,{ex:I,ey:O,ez:b,et:D}=this,{ex:T,ey:_,ez:h,et:E}=g,y=a(I*T),x=a(O*_),S=a(D*P*E),C=a(b*h),A=a((I+O)*(T+_)-y-x),B=C-S,R=C+S,L=a(x-v*y),X=a(A*B),H=a(R*L),N=a(A*L),tt=a(B*R);return new p(X,H,tt,N)}subtract(g){return this.add(g.negate())}multiply(g){let v=g;ce("scalar",v,bt,s);let{p:P,f:I}=m.wNAFCached(this,v,p.normalizeZ);return p.normalizeZ([P,I])[0]}multiplyUnsafe(g,v=p.ZERO){let P=g;return ce("scalar",P,Ht,s),P===Ht?p.ZERO:this.is0()||P===bt?this:m.wNAFCachedUnsafe(this,P,p.normalizeZ,v)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return m.wNAFCachedUnsafe(this,s).is0()}toAffine(g){return l(this,g)}clearCofactor(){return o===bt?this:this.multiplyUnsafe(o)}static fromBytes(g,v=!1){return lt(g),this.fromHex(g,v)}static fromHex(g,v=!1){let{d:P,a:I}=e,O=r.BYTES;g=$("pointHex",g,O),Qt("zip215",v);let b=g.slice(),D=g[O-1];b[O-1]=D&-129;let T=xe(b),_=v?i:r.ORDER;ce("pointHex.y",T,Ht,_);let h=a(T*T),E=a(h-bt),y=a(P*h-I),{isValid:x,value:S}=c(E,y);if(!x)throw new Error("Point.fromHex: invalid y coordinate");let C=(S&bt)===bt,A=(D&128)!==0;if(!v&&S===Ht&&A)throw new Error("Point.fromHex: x=0 and x_0=1");return A!==C&&(S=a(-S)),p.fromAffine({x:S,y:T})}static fromPrivateScalar(g){return p.BASE.multiply(g)}toBytes(){let{x:g,y:v}=this.toAffine(),P=ze(v,r.BYTES);return P[P.length-1]|=g&bt?128:0,P}toRawBytes(){return this.toBytes()}toHex(){return Ft(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}p.BASE=new p(e.Gx,e.Gy,bt,a(e.Gx*e.Gy)),p.ZERO=new p(Ht,bt,bt,Ht),p.Fp=r,p.Fn=n;let m=hn(p,n.BYTES*8);return p}function Ou(e,t){fe(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:r,hash:n}=t,{BASE:o,Fp:s,Fn:i}=e,a=i.ORDER,c=t.randomBytes||vr,u=t.adjustScalarBytes||(b=>b),f=t.domain||((b,D,T)=>{if(Qt("phflag",T),D.length||T)throw new Error("Contexts/pre-hash are not supported");return b});function l(b){return i.create(b)}function d(b){return l(xe(b))}function p(b){let D=s.BYTES;b=$("private key",b,D);let T=$("hashed private key",n(b),2*D),_=u(T.slice(0,D)),h=T.slice(D,2*D),E=d(_);return{head:_,prefix:h,scalar:E}}function m(b){let{head:D,prefix:T,scalar:_}=p(b),h=o.multiply(_),E=h.toBytes();return{head:D,prefix:T,scalar:_,point:h,pointBytes:E}}function w(b){return m(b).pointBytes}function g(b=Uint8Array.of(),...D){let T=At(...D);return d(n(f(T,$("context",b),!!r)))}function v(b,D,T={}){b=$("message",b),r&&(b=r(b));let{prefix:_,scalar:h,pointBytes:E}=m(D),y=g(T.context,_,b),x=o.multiply(y).toBytes(),S=g(T.context,x,E,b),C=l(y+S*h);ce("signature.s",C,Ht,a);let A=s.BYTES,B=At(x,ze(C,A));return $("result",B,A*2)}let P=Pu;function I(b,D,T,_=P){let{context:h,zip215:E}=_,y=s.BYTES;b=$("signature",b,2*y),D=$("message",D),T=$("publicKey",T,y),E!==void 0&&Qt("zip215",E),r&&(D=r(D));let x=xe(b.slice(y,2*y)),S,C,A;try{S=e.fromHex(T,E),C=e.fromHex(b.slice(0,y),E),A=o.multiplyUnsafe(x)}catch{return!1}if(!E&&S.isSmallOrder())return!1;let B=g(h,C.toBytes(),S.toBytes(),D);return C.add(S.multiplyUnsafe(B)).subtract(A).clearCofactor().is0()}return o.precompute(8),{getPublicKey:w,sign:v,verify:I,utils:{getExtendedPublicKey:m,randomPrivateKey:()=>c(s.BYTES),precompute(b=8,D=e.BASE){return D.precompute(b,!1)}},Point:e}}function Lu(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=Ot(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={hash:e.hash,randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function Ru(e,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:e})}function aa(e){let{CURVE:t,curveOpts:r,eddsaOpts:n}=Lu(e),o=Du(t,r),s=Ou(o,n);return Ru(e,s)}var u0=BigInt(0),Nu=BigInt(1),ca=BigInt(2),l0=BigInt(3),Uu=BigInt(5),Ku=BigInt(8),yn={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Ku,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ku(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=yn.p,a=e*e%s*e%s,c=W(a,ca,s)*a%s,u=W(c,Nu,s)*e%s,f=W(u,Uu,s)*u%s,l=W(f,t,s)*f%s,d=W(l,r,s)*l%s,p=W(d,n,s)*d%s,m=W(p,o,s)*p%s,w=W(m,o,s)*p%s,g=W(w,t,s)*f%s;return{pow_p_5_8:W(g,ca,s)*e%s,b2:a}}function Mu(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var fa=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Fu(e,t){let r=yn.p,n=Z(t*t*t,r),o=Z(n*n*t,r),s=ku(e*o).pow_p_5_8,i=Z(e*n*s,r),a=Z(t*i*i,r),c=i,u=Z(i*fa,r),f=a===e,l=a===Z(-e,r),d=a===Z(-e*fa,r);return f&&(i=c),(l||d)&&(i=u),Xi(i,r)&&(i=Z(-i,r)),{isValid:f||l,value:i}}var Vu=Ot(yn.p,void 0,!0),Hu={...yn,Fp:Vu,hash:Fi,adjustScalarBytes:Mu,uvRatio:Fu},ua=aa(Hu);var Pr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},bn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var la={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new bn("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 _t=la;var gn=32;var qo,qu=(async()=>{try{return await _t.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function zu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await _t.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await _t.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 Gu(e,t,r){return ua.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function da(e,t,r){return qo==null&&(qo=await qu),qo?zu(e,t,r):Gu(e,t,r)}function xn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var wn=class{type="Ed25519";raw;constructor(t){this.raw=zo(t,gn)}toMultihash(){return Tt.digest(Mt(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=da(this.raw,r,t);return xn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Go(e){return e=zo(e,gn),new wn(e)}function zo(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new rt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Wu=Math.pow(2,7),ju=Math.pow(2,14),Zu=Math.pow(2,21),$o=Math.pow(2,28),Wo=Math.pow(2,35),jo=Math.pow(2,42),Zo=Math.pow(2,49),V=128,dt=127;function Et(e){if(e<Wu)return 1;if(e<ju)return 2;if(e<Zu)return 3;if(e<$o)return 4;if(e<Wo)return 5;if(e<jo)return 6;if(e<Zo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function je(e,t,r=0){switch(Et(e)){case 8:t[r++]=e&255|V,e/=128;case 7:t[r++]=e&255|V,e/=128;case 6:t[r++]=e&255|V,e/=128;case 5:t[r++]=e&255|V,e/=128;case 4:t[r++]=e&255|V,e>>>=7;case 3:t[r++]=e&255|V,e>>>=7;case 2:t[r++]=e&255|V,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Yu(e,t,r=0){switch(Et(e)){case 8:t.set(r++,e&255|V),e/=128;case 7:t.set(r++,e&255|V),e/=128;case 6:t.set(r++,e&255|V),e/=128;case 5:t.set(r++,e&255|V),e/=128;case 4:t.set(r++,e&255|V),e>>>=7;case 3:t.set(r++,e&255|V),e>>>=7;case 2:t.set(r++,e&255|V),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Yo(e,t){let r=e[t],n=0;if(n+=r&dt,r<V||(r=e[t+1],n+=(r&dt)<<7,r<V)||(r=e[t+2],n+=(r&dt)<<14,r<V)||(r=e[t+3],n+=(r&dt)<<21,r<V)||(r=e[t+4],n+=(r&dt)*$o,r<V)||(r=e[t+5],n+=(r&dt)*Wo,r<V)||(r=e[t+6],n+=(r&dt)*jo,r<V)||(r=e[t+7],n+=(r&dt)*Zo,r<V))return n;throw new RangeError("Could not decode varint")}function Xu(e,t){let r=e.get(t),n=0;if(n+=r&dt,r<V||(r=e.get(t+1),n+=(r&dt)<<7,r<V)||(r=e.get(t+2),n+=(r&dt)<<14,r<V)||(r=e.get(t+3),n+=(r&dt)<<21,r<V)||(r=e.get(t+4),n+=(r&dt)*$o,r<V)||(r=e.get(t+5),n+=(r&dt)*Wo,r<V)||(r=e.get(t+6),n+=(r&dt)*jo,r<V)||(r=e.get(t+7),n+=(r&dt)*Zo,r<V))return n;throw new RangeError("Could not decode varint")}function Ze(e,t,r=0){return t==null&&(t=xt(Et(e))),t instanceof Uint8Array?je(e,t,r):Yu(e,t,r)}function Tr(e,t=0){return e instanceof Uint8Array?Yo(e,t):Xu(e,t)}var Qo=new Float32Array([-0]),ue=new Uint8Array(Qo.buffer);function pa(e,t,r){Qo[0]=e,t[r]=ue[0],t[r+1]=ue[1],t[r+2]=ue[2],t[r+3]=ue[3]}function ma(e,t){return ue[0]=e[t],ue[1]=e[t+1],ue[2]=e[t+2],ue[3]=e[t+3],Qo[0]}var Jo=new Float64Array([-0]),ht=new Uint8Array(Jo.buffer);function ya(e,t,r){Jo[0]=e,t[r]=ht[0],t[r+1]=ht[1],t[r+2]=ht[2],t[r+3]=ht[3],t[r+4]=ht[4],t[r+5]=ht[5],t[r+6]=ht[6],t[r+7]=ht[7]}function ba(e,t){return ht[0]=e[t],ht[1]=e[t+1],ht[2]=e[t+2],ht[3]=e[t+3],ht[4]=e[t+4],ht[5]=e[t+5],ht[6]=e[t+6],ht[7]=e[t+7],Jo[0]}var Qu=BigInt(Number.MAX_SAFE_INTEGER),Ju=BigInt(Number.MIN_SAFE_INTEGER),It=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 ve;if(t<Qu&&t>Ju)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>ga&&(o=0n,++n>ga&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ve;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):ve}},ve=new It(0,0);ve.toBigInt=function(){return 0n};ve.zzEncode=ve.zzDecode=function(){return this};ve.length=function(){return 1};var ga=4294967296n;function xa(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 wa(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function ts(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 Lt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function En(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var es=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Lt(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 Lt(this,4);return En(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Lt(this,4);return En(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Lt(this,4);let t=ma(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Lt(this,4);let t=ba(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 Lt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return wa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Lt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Lt(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 It(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 Lt(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 Lt(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 Lt(this,8);let t=En(this.buf,this.pos+=4),r=En(this.buf,this.pos+=4);return new It(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=Yo(this.buf,this.pos);return this.pos+=Et(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 rs(e){return new es(e instanceof Uint8Array?e:e.subarray())}function Rt(e,t,r){let n=rs(e);return t.decode(n,void 0,r)}function ns(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return xt(i);o+i>t&&(n=xt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ae=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function os(){}var is=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},tl=ns();function el(e){return globalThis.Buffer!=null?xt(e):tl(e)}var Or=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ae(os,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Ae(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new as((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(Sn,10,It.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=It.fromBigInt(t);return this._push(Sn,r.length(),r)}uint64Number(t){return this._push(je,Et(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=It.fromBigInt(t).zzEncode();return this._push(Sn,r.length(),r)}sint64Number(t){let r=It.fromNumber(t).zzEncode();return this._push(Sn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ss,1,t?1:0)}fixed32(t){return this._push(Dr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=It.fromBigInt(t);return this._push(Dr,4,r.lo)._push(Dr,4,r.hi)}fixed64Number(t){let r=It.fromNumber(t);return this._push(Dr,4,r.lo)._push(Dr,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(pa,4,t)}double(t){return this._push(ya,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ss,1,0):this.uint32(r)._push(nl,r,t)}string(t){let r=xa(t);return r!==0?this.uint32(r)._push(ts,r,t):this._push(ss,1,0)}fork(){return this.states=new is(this),this.head=this.tail=new Ae(os,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Ae(os,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=el(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ss(e,t,r){t[r]=e&255}function rl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var as=class extends Ae{next;constructor(t,r){super(rl,t,r),this.next=void 0}};function Sn(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 Dr(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 nl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Or.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(ol,t,e),this},Or.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(sl,t,e),this});function ol(e,t,r){t.set(e,r)}function sl(e,t,r){e.length<40?ts(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(U(e),r)}function cs(){return new Or}function Nt(e,t){let r=cs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Ye;(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"})(Ye||(Ye={}));function vn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function fs(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return vn("enum",Ye.VARINT,r,n)}function Ut(e,t){return vn("message",Ye.LENGTH_DELIMITED,e,t)}var Ie=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var J;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(J||(J={}));var us;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(us||(us={}));(function(e){e.codec=()=>fs(us)})(J||(J={}));var qt;(function(e){let t;e.codec=()=>(t==null&&(t=Ut((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),J.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=J.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Nt(r,e.codec()),e.decode=(r,n)=>Rt(r,e.codec(),n)})(qt||(qt={}));var ls;(function(e){let t;e.codec=()=>(t==null&&(t=Ut((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),J.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=J.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),t),e.encode=r=>Nt(r,e.codec()),e.decode=(r,n)=>Rt(r,e.codec(),n)})(ls||(ls={}));var Rr={};gt(Rr,{MAX_RSA_KEY_SIZE:()=>ds,generateRSAKeyPair:()=>_a,jwkToJWKKeyPair:()=>Ca,jwkToPkcs1:()=>fl,jwkToPkix:()=>ys,jwkToRSAPrivateKey:()=>ws,pkcs1MessageToJwk:()=>ps,pkcs1MessageToRSAPrivateKey:()=>bs,pkcs1ToJwk:()=>cl,pkcs1ToRSAPrivateKey:()=>Ia,pkixMessageToJwk:()=>ms,pkixMessageToRSAPublicKey:()=>xs,pkixToJwk:()=>ul,pkixToRSAPublicKey:()=>gs});var An=un;var Xe=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return et.createV1(114,this._multihash)}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r,n){return Aa(this.jwk,r,t,n)}},Lr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}sign(t,r){return va(this.jwk,t,r)}};var ds=8192,hs=18,il=1062,al=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function cl(e){let t=jt(e);return ps(t)}function ps(e){return{n:K(e[1],"base64url"),e:K(e[2],"base64url"),d:K(e[3],"base64url"),p:K(e[4],"base64url"),q:K(e[5],"base64url"),dp:K(e[6],"base64url"),dq:K(e[7],"base64url"),qi:K(e[8],"base64url"),kty:"RSA"}}function fl(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 rt("JWK was missing components");return oe([wt(Uint8Array.from([0])),wt(U(e.n,"base64url")),wt(U(e.e,"base64url")),wt(U(e.d,"base64url")),wt(U(e.p,"base64url")),wt(U(e.q,"base64url")),wt(U(e.dp,"base64url")),wt(U(e.dq,"base64url")),wt(U(e.qi,"base64url"))]).subarray()}function ul(e){let t=jt(e,{offset:0});return ms(t)}function ms(e){let t=jt(e[1],{offset:0});return{kty:"RSA",n:K(t[0],"base64url"),e:K(t[1],"base64url")}}function ys(e){if(e.n==null||e.e==null)throw new rt("JWK was missing components");return oe([al,sn(oe([wt(U(e.n,"base64url")),wt(U(e.e,"base64url"))]))]).subarray()}function Ia(e){let t=jt(e);return bs(t)}function bs(e){let t=ps(e);return ws(t)}function gs(e,t){if(e.byteLength>=il)throw new Le("Key size is too large");let r=jt(e,{offset:0});return xs(r,e,t)}function xs(e,t,r){let n=ms(e);if(r==null){let o=An(qt.encode({Type:J.RSA,Data:t}));r=Pt(hs,o)}return new Xe(n,r)}function ws(e){if(Pa(e)>ds)throw new rt("Key size is too large");let t=Ca(e),r=An(qt.encode({Type:J.RSA,Data:ys(t.publicKey)})),n=Pt(hs,r);return new Lr(t.privateKey,new Xe(t.publicKey,n))}async function _a(e){if(e>ds)throw new rt("Key size is too large");let t=await Ba(e),r=An(qt.encode({Type:J.RSA,Data:ys(t.publicKey)})),n=Pt(hs,r);return new Lr(t.privateKey,new Xe(t.publicKey,n))}function Ca(e){if(e==null)throw new rt("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Ba(e,t){let r=await _t.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 ll(r,t);return{privateKey:n[0],publicKey:n[1]}}async function va(e,t,r){let n=await _t.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await _t.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 Aa(e,t,r,n){let o=await _t.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await _t.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function ll(e,t){if(e.privateKey==null||e.publicKey==null)throw new rt("Private and public key are required");let r=await Promise.all([_t.get().subtle.exportKey("jwk",e.privateKey),_t.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Pa(e){if(e.kty!=="RSA")throw new rt("invalid key type");if(e.n==null)throw new rt("invalid key modulus");return U(e.n,"base64url").length*8}var In=class extends Me{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Ii(t);let n=Sr(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),Yt(s)}update(t){return Ve(this),this.iHash.update(t),this}digestInto(t){Ve(this),lt(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Es=(e,t,r)=>new In(e,t).update(r).digest();Es.create=(e,t)=>new In(e,t);function Ta(e){e.lowS!==void 0&&Qt("lowS",e.lowS),e.prehash!==void 0&&Qt("prehash",e.prehash)}var Ss=class extends Error{constructor(t=""){super(t)}},Jt={Err:Ss,_tlv:{encode:(e,t)=>{let{Err:r}=Jt;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=Cr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Cr(o.length/2|128):"";return Cr(e)+s+o+t},decode(e,t){let{Err:r}=Jt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Jt;if(e<Nr)throw new t("integer: negative integers are not allowed");let r=Cr(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}=Jt;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 qe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Jt,o=$("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Jt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Nr=BigInt(0),Ur=BigInt(1),dl=BigInt(2),_n=BigInt(3),hl=BigInt(4);function pl(e,t,r){function n(o){let s=e.sqr(o),i=e.mul(s,o);return e.add(e.add(i,e.mul(o,t)),r)}return n}function Da(e,t,r){let{BYTES:n}=e;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=$("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{i=e.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(r&&(i=e.create(i)),!e.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function ml(e,t={}){let{Fp:r,Fn:n}=mn("weierstrass",e,t),{h:o,n:s}=e;fe(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!r.is0(e.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(_,h,E){let{x:y,y:x}=h.toAffine(),S=r.toBytes(y);if(Qt("isCompressed",E),E){a();let C=!r.isOdd(x);return At(Oa(C),S)}else return At(Uint8Array.of(4),S,r.toBytes(x))}function u(_){lt(_);let h=r.BYTES,E=h+1,y=2*h+1,x=_.length,S=_[0],C=_.subarray(1);if(x===E&&(S===2||S===3)){let A=r.fromBytes(C);if(!r.isValid(A))throw new Error("bad point: is not on curve, wrong x");let B=d(A),R;try{R=r.sqrt(B)}catch(H){let N=H instanceof Error?": "+H.message:"";throw new Error("bad point: is not on curve, sqrt error"+N)}a();let L=r.isOdd(R);return(S&1)===1!==L&&(R=r.neg(R)),{x:A,y:R}}else if(x===y&&S===4){let A=r.fromBytes(C.subarray(h*0,h*1)),B=r.fromBytes(C.subarray(h*1,h*2));if(!p(A,B))throw new Error("bad point: is not on curve");return{x:A,y:B}}else throw new Error(`bad point: got length ${x}, expected compressed=${E} or uncompressed=${y}`)}let f=t.toBytes||c,l=t.fromBytes||u,d=pl(r,e.a,e.b);function p(_,h){let E=r.sqr(h),y=d(_);return r.eql(E,y)}if(!p(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let m=r.mul(r.pow(e.a,_n),hl),w=r.mul(r.sqr(e.b),BigInt(27));if(r.is0(r.add(m,w)))throw new Error("bad curve params: a or b");function g(_,h,E=!1){if(!r.isValid(h)||E&&r.is0(h))throw new Error(`bad point coordinate ${_}`);return h}function v(_){if(!(_ instanceof b))throw new Error("ProjectivePoint expected")}let P=Ge((_,h)=>{let{px:E,py:y,pz:x}=_;if(r.eql(x,r.ONE))return{x:E,y};let S=_.is0();h==null&&(h=S?r.ONE:r.inv(x));let C=r.mul(E,h),A=r.mul(y,h),B=r.mul(x,h);if(S)return{x:r.ZERO,y:r.ZERO};if(!r.eql(B,r.ONE))throw new Error("invZ was invalid");return{x:C,y:A}}),I=Ge(_=>{if(_.is0()){if(t.allowInfinityPoint&&!r.is0(_.py))return;throw new Error("bad point: ZERO")}let{x:h,y:E}=_.toAffine();if(!r.isValid(h)||!r.isValid(E))throw new Error("bad point: x or y not field elements");if(!p(h,E))throw new Error("bad point: equation left != right");if(!_.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function O(_,h,E,y,x){return E=new b(r.mul(E.px,_),E.py,E.pz),h=$e(y,h),E=$e(x,E),h.add(E)}class b{constructor(h,E,y){this.px=g("x",h),this.py=g("y",E,!0),this.pz=g("z",y),Object.freeze(this)}static fromAffine(h){let{x:E,y}=h||{};if(!h||!r.isValid(E)||!r.isValid(y))throw new Error("invalid affine point");if(h instanceof b)throw new Error("projective point not allowed");return r.is0(E)&&r.is0(y)?b.ZERO:new b(E,y,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){return dn(b,"pz",h)}static fromBytes(h){return lt(h),b.fromHex(h)}static fromHex(h){let E=b.fromAffine(l($("pointHex",h)));return E.assertValidity(),E}static fromPrivateKey(h){let E=Da(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return b.BASE.multiply(E(h))}static msm(h,E){return pn(b,n,h,E)}precompute(h=8,E=!0){return T.setWindowSize(this,h),E||this.multiply(_n),this}_setWindowSize(h){this.precompute(h)}assertValidity(){I(this)}hasEvenY(){let{y:h}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(h)}equals(h){v(h);let{px:E,py:y,pz:x}=this,{px:S,py:C,pz:A}=h,B=r.eql(r.mul(E,A),r.mul(S,x)),R=r.eql(r.mul(y,A),r.mul(C,x));return B&&R}negate(){return new b(this.px,r.neg(this.py),this.pz)}double(){let{a:h,b:E}=e,y=r.mul(E,_n),{px:x,py:S,pz:C}=this,A=r.ZERO,B=r.ZERO,R=r.ZERO,L=r.mul(x,x),X=r.mul(S,S),H=r.mul(C,C),N=r.mul(x,S);return N=r.add(N,N),R=r.mul(x,C),R=r.add(R,R),A=r.mul(h,R),B=r.mul(y,H),B=r.add(A,B),A=r.sub(X,B),B=r.add(X,B),B=r.mul(A,B),A=r.mul(N,A),R=r.mul(y,R),H=r.mul(h,H),N=r.sub(L,H),N=r.mul(h,N),N=r.add(N,R),R=r.add(L,L),L=r.add(R,L),L=r.add(L,H),L=r.mul(L,N),B=r.add(B,L),H=r.mul(S,C),H=r.add(H,H),L=r.mul(H,N),A=r.sub(A,L),R=r.mul(H,X),R=r.add(R,R),R=r.add(R,R),new b(A,B,R)}add(h){v(h);let{px:E,py:y,pz:x}=this,{px:S,py:C,pz:A}=h,B=r.ZERO,R=r.ZERO,L=r.ZERO,X=e.a,H=r.mul(e.b,_n),N=r.mul(E,S),tt=r.mul(y,C),nt=r.mul(x,A),ut=r.add(E,y),z=r.add(S,C);ut=r.mul(ut,z),z=r.add(N,tt),ut=r.sub(ut,z),z=r.add(E,x);let mt=r.add(S,A);return z=r.mul(z,mt),mt=r.add(N,nt),z=r.sub(z,mt),mt=r.add(y,x),B=r.add(C,A),mt=r.mul(mt,B),B=r.add(tt,nt),mt=r.sub(mt,B),L=r.mul(X,z),B=r.mul(H,nt),L=r.add(B,L),B=r.sub(tt,L),L=r.add(tt,L),R=r.mul(B,L),tt=r.add(N,N),tt=r.add(tt,N),nt=r.mul(X,nt),z=r.mul(H,z),tt=r.add(tt,nt),nt=r.sub(N,nt),nt=r.mul(X,nt),z=r.add(z,nt),N=r.mul(tt,z),R=r.add(R,N),N=r.mul(mt,z),B=r.mul(ut,B),B=r.sub(B,N),N=r.mul(ut,tt),L=r.mul(mt,L),L=r.add(L,N),new b(B,R,L)}subtract(h){return this.add(h.negate())}is0(){return this.equals(b.ZERO)}multiply(h){let{endo:E}=t;if(!n.isValidNot0(h))throw new Error("invalid scalar: out of range");let y,x,S=C=>T.wNAFCached(this,C,b.normalizeZ);if(E){let{k1neg:C,k1:A,k2neg:B,k2:R}=E.splitScalar(h),{p:L,f:X}=S(A),{p:H,f:N}=S(R);x=X.add(N),y=O(E.beta,L,H,C,B)}else{let{p:C,f:A}=S(h);y=C,x=A}return b.normalizeZ([y,x])[0]}multiplyUnsafe(h){let{endo:E}=t,y=this;if(!n.isValid(h))throw new Error("invalid scalar: out of range");if(h===Nr||y.is0())return b.ZERO;if(h===Ur)return y;if(T.hasPrecomputes(this))return this.multiply(h);if(E){let{k1neg:x,k1:S,k2neg:C,k2:A}=E.splitScalar(h),{p1:B,p2:R}=ia(b,y,S,A);return O(E.beta,B,R,x,C)}else return T.wNAFCachedUnsafe(y,h)}multiplyAndAddUnsafe(h,E,y){let x=this.multiplyUnsafe(E).add(h.multiplyUnsafe(y));return x.is0()?void 0:x}toAffine(h){return P(this,h)}isTorsionFree(){let{isTorsionFree:h}=t;return o===Ur?!0:h?h(b,this):T.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:h}=t;return o===Ur?this:h?h(b,this):this.multiplyUnsafe(o)}toBytes(h=!0){return Qt("isCompressed",h),this.assertValidity(),f(b,this,h)}toRawBytes(h=!0){return this.toBytes(h)}toHex(h=!0){return Ft(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}b.BASE=new b(e.Gx,e.Gy,r.ONE),b.ZERO=new b(r.ZERO,r.ONE,r.ZERO),b.Fp=r,b.Fn=n;let D=n.BITS,T=hn(b,t.endo?Math.ceil(D/2):D);return b}function Oa(e){return Uint8Array.of(e?2:3)}function yl(e,t,r={}){fe(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||vr,o=t.hmac||((y,...x)=>Es(t.hash,y,At(...x))),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i;function u(y){let x=a>>Ur;return y>x}function f(y){return u(y)?i.neg(y):y}function l(y,x){if(!i.isValidNot0(x))throw new Error(`invalid signature ${y}: out of range 1..CURVE.n`)}class d{constructor(x,S,C){l("r",x),l("s",S),this.r=x,this.s=S,C!=null&&(this.recovery=C),Object.freeze(this)}static fromCompact(x){let S=i.BYTES,C=$("compactSignature",x,S*2);return new d(i.fromBytes(C.subarray(0,S)),i.fromBytes(C.subarray(S,S*2)))}static fromDER(x){let{r:S,s:C}=Jt.toSig($("DER",x));return new d(S,C)}assertValidity(){}addRecoveryBit(x){return new d(this.r,this.s,x)}recoverPublicKey(x){let S=s.ORDER,{r:C,s:A,recovery:B}=this;if(B==null||![0,1,2,3].includes(B))throw new Error("recovery id invalid");if(a*dl<S&&B>1)throw new Error("recovery id is ambiguous for h>1 curve");let L=B===2||B===3?C+a:C;if(!s.isValid(L))throw new Error("recovery id 2 or 3 invalid");let X=s.toBytes(L),H=e.fromHex(At(Oa((B&1)===0),X)),N=i.inv(L),tt=I($("msgHash",x)),nt=i.create(-tt*N),ut=i.create(A*N),z=e.BASE.multiplyUnsafe(nt).add(H.multiplyUnsafe(ut));if(z.is0())throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return u(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i.neg(this.s),this.recovery):this}toBytes(x){if(x==="compact")return At(i.toBytes(this.r),i.toBytes(this.s));if(x==="der")return He(Jt.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Ft(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Ft(this.toBytes("compact"))}}let p=Da(i,r.allowedPrivateKeyLengths,r.wrapPrivateKey),m={isValidPrivateKey(y){try{return p(y),!0}catch{return!1}},normPrivateKeyToScalar:p,randomPrivateKey:()=>{let y=a;return ta(n(ko(y)),y)},precompute(y=8,x=e.BASE){return x.precompute(y,!1)}};function w(y,x=!0){return e.fromPrivateKey(y).toBytes(x)}function g(y){if(typeof y=="bigint")return!1;if(y instanceof e)return!0;let S=$("key",y).length,C=s.BYTES,A=C+1,B=2*C+1;if(!(r.allowedPrivateKeyLengths||i.BYTES===A))return S===A||S===B}function v(y,x,S=!0){if(g(y)===!0)throw new Error("first arg must be private key");if(g(x)===!1)throw new Error("second arg must be public key");return e.fromHex(x).multiply(p(y)).toBytes(S)}let P=t.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let x=qe(y),S=y.length*8-c;return S>0?x>>BigInt(S):x},I=t.bits2int_modN||function(y){return i.create(P(y))},O=we(c);function b(y){return ce("num < 2^"+c,y,Nr,O),i.toBytes(y)}function D(y,x,S=T){if(["recovered","canonical"].some(ut=>ut in S))throw new Error("sign() legacy options not supported");let{hash:C}=t,{lowS:A,prehash:B,extraEntropy:R}=S;A==null&&(A=!0),y=$("msgHash",y),Ta(S),B&&(y=$("prehashed msgHash",C(y)));let L=I(y),X=p(x),H=[b(X),b(L)];if(R!=null&&R!==!1){let ut=R===!0?n(s.BYTES):R;H.push($("extraEntropy",ut))}let N=At(...H),tt=L;function nt(ut){let z=P(ut);if(!i.isValidNot0(z))return;let mt=i.inv(z),ur=e.BASE.multiply(z).toAffine(),De=i.create(ur.x);if(De===Nr)return;let he=i.create(mt*i.create(tt+De*X));if(he===Nr)return;let to=(ur.x===De?0:2)|Number(ur.y&Ur),Oe=he;return A&&u(he)&&(Oe=f(he),to^=1),new d(De,Oe,to)}return{seed:N,k2sig:nt}}let T={lowS:t.lowS,prehash:!1},_={lowS:t.lowS,prehash:!1};function h(y,x,S=T){let{seed:C,k2sig:A}=D(y,x,S);return zi(t.hash.outputLen,i.BYTES,o)(C,A)}e.BASE.precompute(8);function E(y,x,S,C=_){let A=y;x=$("msgHash",x),S=$("publicKey",S),Ta(C);let{lowS:B,prehash:R,format:L}=C;if("strict"in C)throw new Error("options.strict was renamed to lowS");if(L!==void 0&&!["compact","der","js"].includes(L))throw new Error('format must be "compact", "der" or "js"');let X=typeof A=="string"||Fe(A),H=!X&&!L&&typeof A=="object"&&A!==null&&typeof A.r=="bigint"&&typeof A.s=="bigint";if(!X&&!H)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let N,tt;try{if(H)if(L===void 0||L==="js")N=new d(A.r,A.s);else throw new Error("invalid format");if(X){try{L!=="compact"&&(N=d.fromDER(A))}catch(Oe){if(!(Oe instanceof Jt.Err))throw Oe}!N&&L!=="der"&&(N=d.fromCompact(A))}tt=e.fromHex(S)}catch{return!1}if(!N||B&&N.hasHighS())return!1;R&&(x=t.hash(x));let{r:nt,s:ut}=N,z=I(x),mt=i.inv(ut),ur=i.create(z*mt),De=i.create(nt*mt),he=e.BASE.multiplyUnsafe(ur).add(tt.multiplyUnsafe(De));return he.is0()?!1:i.create(he.x)===nt}return Object.freeze({getPublicKey:w,getSharedSecret:v,sign:h,verify:E,utils:m,Point:e,Signature:d})}function bl(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=Ot(t.n,e.nBitLength),o={Fp:r,Fn:n,allowedPrivateKeyLengths:e.allowedPrivateKeyLengths,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,wrapPrivateKey:e.wrapPrivateKey,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:o}}function gl(e){let{CURVE:t,curveOpts:r}=bl(e),n={hash:e.hash,hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,ecdsaOpts:n}}function xl(e,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:e})}function La(e){let{CURVE:t,curveOpts:r,ecdsaOpts:n}=gl(e),o=ml(t,r),s=yl(o,n,r);return xl(e,s)}function Ra(e,t){let r=n=>La({...e,hash:n});return{...r(t),create:r}}var Cn={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Xm=BigInt(0),wl=BigInt(1),vs=BigInt(2),Na=(e,t)=>(e+t/vs)/t;function El(e){let t=Cn.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=W(f,r,t)*f%t,d=W(l,r,t)*f%t,p=W(d,vs,t)*u%t,m=W(p,o,t)*p%t,w=W(m,s,t)*m%t,g=W(w,a,t)*w%t,v=W(g,c,t)*g%t,P=W(v,a,t)*w%t,I=W(P,r,t)*f%t,O=W(I,i,t)*m%t,b=W(O,n,t)*u%t,D=W(b,vs,t);if(!As.eql(As.sqr(D),e))throw new Error("Cannot find square root");return D}var As=Ot(Cn.p,void 0,void 0,{sqrt:El}),Qe=Ra({...Cn,Fp:As,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=Cn.n,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-wl*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,i=BigInt("0x100000000000000000000000000000000"),a=Na(s*e,t),c=Na(-n*e,t),u=Z(e-a*r-c*o,t),f=Z(-a*n-c*s,t),l=u>i,d=f>i;if(l&&(u=t-u),d&&(f=t-f),u>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:u,k2neg:d,k2:f}}}},un);function Ua(e,t,r,n){let o=br.digest(r instanceof Uint8Array?r:r.subarray());if(xn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Qe.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new Pr(String(s))});try{return n?.signal?.throwIfAborted(),Qe.verify(t,o.digest,e)}catch(s){throw new Pr(String(s))}}var Bn=class{type="secp256k1";raw;_key;constructor(t){this._key=ka(t),this.raw=Ka(this._key)}toMultihash(){return Tt.digest(Mt(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r,n){return Ua(this._key,r,t,n)}};function Is(e){return new Bn(e)}function Ka(e){return Qe.ProjectivePoint.fromHex(e).toRawBytes(!0)}function ka(e){try{return Qe.ProjectivePoint.fromHex(e),e}catch(t){throw new Le(String(t))}}function Je(e,t){let{Type:r,Data:n}=qt.decode(e),o=n??new Uint8Array;switch(r){case J.RSA:return gs(o,t);case J.Ed25519:return Go(o);case J.secp256k1:return Is(o);case J.ECDSA:return Po(o);default:throw new pe}}function Ma(e){let{Type:t,Data:r}=qt.decode(e.digest),n=r??new Uint8Array;switch(t){case J.Ed25519:return Go(n);case J.secp256k1:return Is(n);case J.ECDSA:return Po(n);default:throw new pe}}function Mt(e){return qt.encode({Type:J[e.type],Data:e.raw})}var Kr;(function(e){let t;e.codec=()=>(t==null&&(t=Ut((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:it(0),payloadType:it(0),payload:it(0),signature:it(0)},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>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(a&7);break}}}return s})),t),e.encode=r=>Nt(r,e.codec()),e.decode=(r,n)=>Rt(r,e.codec(),n)})(Kr||(Kr={}));var Pn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var zt=class e{static createFromProtobuf=t=>{let r=Kr.decode(t),n=Je(r.publicKey);return new e({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(t,r,n)=>{if(r==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),a=Fa(o,s,i),c=await r.sign(a.subarray(),n);return new e({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(t,r,n)=>{let o=e.createFromProtobuf(t);if(!await o.validate(r,n))throw new Pn("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=Kr.encode({publicKey:Mt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:ot(this.marshal(),t.marshal())}async validate(t,r){let n=Fa(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Fa=(e,t,r)=>{let n=U(e),o=Ze(n.byteLength),s=Ze(t.length),i=Ze(r.length);return new Q(o,n,s,t,i,r)};var Va=Symbol.for("nodejs.util.inspect.custom"),Sl=114,kr=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()})`}[eo]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return et.createV1(Sl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ot(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ot(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Va](){return`PeerId(${this.toString()})`}},Mr=class extends kr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Fr=class extends kr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Vr=class extends kr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},vl=2336,Hr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Tt.digest(U(this.url))}[Va](){return`PeerId(${this.url})`}[eo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return et.createV1(vl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=K(t)),t.toString()===this.toString())}};var Al=114,Ha=2336;function qa(e){if(e.type==="Ed25519")return new Fr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Vr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Mr({multihash:e.toCID().multihash,publicKey:e});throw new pe}function _s(e){if(_l(e))return new Mr({multihash:e});if(Il(e))try{let t=Ma(e);if(t.type==="Ed25519")return new Fr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Vr({multihash:e,publicKey:t})}catch{let r=K(e.digest);return new Hr(new URL(r))}throw new Jr("Supplied PeerID Multihash is invalid")}function Tn(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Al&&e.code!==Ha)throw new Qr("Supplied PeerID CID is invalid");if(e.code===Ha){let t=K(e.multihash.digest);return new Hr(new URL(t))}return _s(e.multihash)}function Il(e){return e.code===Tt.code}function _l(e){return e.code===br.code}function za(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 ct=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},te=class extends Error{static name="ValidationError";name="ValidationError"},qr=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Dn=class extends Error{static name="InvalidProtocolError";name="InvalidProtocolError"};var On=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(f===void 0)break;if(s*=t,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ga=45,Cl=15,tr=new On;function Ln(e){if(!(e.length>Cl))return tr.new(e).parseWith(()=>tr.readIPv4Addr())}function Rn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Ga))return tr.new(e).parseWith(()=>tr.readIPv6Addr())}function er(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>Ga)return;let r=tr.new(e).parseWith(()=>tr.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 le(e){return!!Ln(e)}function rr(e){return!!Rn(e)}function Bs(e){return t=>K(t,e)}function Ps(e){return t=>U(t,e)}function nr(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function _e(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function $a(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=U(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=_e(n);return Wt([r,o],r.length+o.length)}function Wa(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=ne.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=_e(n);return Wt([r,o],r.length+o.length)}function Ts(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=K(t,"base32"),o=nr(r);return`${n}:${o}`}var Ds=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 ct("Invalid byte value in IP address");t[n]=o}),t},ja=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=le(r[n]),i;s&&(i=Ds(r[n]),r[n]=K(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,K(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 ct("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Za=function(e){if(e.byteLength!==4)throw new ct("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Ya=function(e){if(e.byteLength!==16)throw new ct("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 ct(`Invalid IPv6 address "${r}"`)}};function Xa(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ct(`Invalid IPv6 address "${e}"`)}}var Cs=Object.values(gr).map(e=>e.decoder),Bl=function(){let e=Cs[0].or(Cs[1]);return Cs.slice(2).forEach(t=>e=e.or(t)),e}();function Qa(e){return Bl.decode(e)}function Ja(e){return t=>e.encoder.encode(t)}function Pl(e){if(parseInt(e).toString()!==e)throw new te("Value must be an integer")}function Tl(e){if(e<0)throw new te("Value must be a positive integer, or zero")}function Dl(e){return t=>{if(t>e)throw new te(`Value must be smaller than or equal to ${e}`)}}function Ol(...e){return t=>{for(let r of e)r(t)}}var zr=Ol(Pl,Tl,Dl(65535));var ft=-1,Os=class{protocolsByCode=new Map;protocolsByName=new Map;getCodec(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Dn(`Protocol ${t} was unknown`);return r}addCodec(t,r,n){this.protocolsByCode.set(t,r),this.protocolsByName.set(r.name,r),n?.forEach(o=>{this.protocolsByName.set(o,r)})}deleteCodec(t){let r=this.getCodec(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},St=new Os,cd=[{code:4,name:"ip4",size:32,valueToBytes:Ds,bytesToValue:Za,validate:e=>{if(!le(e))throw new te(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:_e,bytesToValue:nr,validate:zr},{code:273,name:"udp",size:16,valueToBytes:_e,bytesToValue:nr,validate:zr},{code:33,name:"dccp",size:16,valueToBytes:_e,bytesToValue:nr,validate:zr},{code:41,name:"ip6",size:128,valueToBytes:ja,bytesToValue:Ya,stringToValue:Xa,validate:e=>{if(!rr(e))throw new te(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ft},{code:43,name:"ipcidr",size:8,bytesToValue:Bs("base10"),valueToBytes:Ps("base10")},{code:53,name:"dns",size:ft,resolvable:!0},{code:54,name:"dns4",size:ft,resolvable:!0},{code:55,name:"dns6",size:ft,resolvable:!0},{code:56,name:"dnsaddr",size:ft,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:_e,bytesToValue:nr,validate:zr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ft,path:!0,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ft,bytesToValue:Bs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Ps("base58btc")(e):et.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ts,valueToBytes:$a},{code:445,name:"onion3",size:296,bytesToValue:Ts,valueToBytes:Wa},{code:446,name:"garlic64",size:ft},{code:447,name:"garlic32",size:ft},{code:448,name:"tls"},{code:449,name:"sni",size:ft},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ft,bytesToValue:Ja(yr),valueToBytes:Qa},{code:480,name:"http"},{code:481,name:"http-path",size:ft,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:ft}];cd.forEach(e=>{St.addCodec(e.code,e,e.aliases)});function tc(e){let t=[],r=0;for(;r<e.length;){let n=Tr(e,r),o=St.getCodec(n),s=Et(n),i=fd(o,e,r+s),a=0;i>0&&o.size===ft&&(a=Et(i));let c=s+a+i,u={code:n,name:o.name,bytes:e.subarray(r,r+c)};if(i>0){let f=r+s+a,l=e.subarray(f,f+i);u.value=o.bytesToValue?.(l)??K(l)}t.push(u),r+=c}return t}function ec(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=St.getCodec(n.code),s=Et(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??U(n.value),a=i.byteLength,o.size===ft&&(c=Et(a)));let u=new Uint8Array(s+c+a),f=0;je(n.code,u,f),f+=s,i!=null&&(o.size===ft&&(je(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),t+=n.bytes.byteLength}return Wt(r,t)}function rc(e){if(e.charAt(0)!=="/")throw new ct('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=St.getCodec(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ct(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ct(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}t.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ct("Incomplete multiaddr");return t}function nc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=St.getCodec(t.code);if(r==null)throw new ct(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function fd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Tr(t,r)}var ud=Symbol.for("nodejs.util.inspect.custom"),Ms=Symbol.for("@multiformats/multiaddr"),ld=[53,54,55,56],ks=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}};function dd(e){if(e==null&&(e="/"),sc(e))return e.getComponents();if(e instanceof Uint8Array)return tc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),rc(e);if(Array.isArray(e))return e;throw new ct("Must be a string, Uint8Array, Component[], or another Multiaddr")}var kn=class e{[Ms]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=dd(t),r.validate!==!1&&hd(this)}get bytes(){return this.#r==null&&(this.#r=ec(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=nc(this.#t)),this.#e}toJSON(){return this.toString()}toOptions(){let t,r,n,o,s="";for(let{code:a,name:c,value:u}of this.#t)a===42&&(s=`%${u??""}`),ld.includes(a)&&(r="tcp",o=443,n=`${u??""}${s}`,t=a===55?6:4),(a===6||a===273)&&(r=c==="tcp"?"tcp":"udp",o=parseInt(u??"")),(a===4||a===41)&&(r="tcp",n=`${u??""}${s}`,t=a===41?6:4);if(t==null||r==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:r,port:o}}getComponents(){return[...this.#t]}protos(){return this.#t.map(({code:t,value:r})=>{let n=St.getCodec(t);return{code:t,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#t.map(({code:t})=>t)}protoNames(){return this.#t.map(({name:t})=>t)}tuples(){return this.#t.map(({code:t,value:r})=>{if(r==null)return[t];let n=St.getCodec(t),o=[t];return r!=null&&o.push(n.valueToBytes?.(r)??U(r)),o})}stringTuples(){return this.#t.map(({code:t,value:r})=>r==null?[t]:[t,r])}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 qr(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);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})}getPeerId(){try{let t=[];this.#t.forEach(({code:n,value:o})=>{n===421&&t.push([n,o]),n===290&&(t=[])});let r=t.pop();if(r?.[1]!=null){let n=r[1];return n[0]==="Q"||n[0]==="1"?K(G.decode(`z${n}`),"base58btc"):K(et.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let t of this.#t)if(St.getCodec(t.code).path)return t.value??null;return null}equals(t){return ot(this.bytes,t.bytes)}async resolve(t){let r=this.protos().find(s=>s.resolvable);if(r==null)return[this];let n=oc.get(r.name);if(n==null)throw new ks(`no available resolver for ${r.name}`);return(await n(this,t)).map(s=>Gt(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(){return!(this.#t.length!==2||this.#t[0].code!==4&&this.#t[0].code!==41||this.#t[1].code!==6&&this.#t[1].code!==273)}[ud](){return`Multiaddr(${this.toString()})`}};function hd(e){e.getComponents().forEach(t=>{let r=St.getCodec(t.code);t.value!=null&&r.validate?.(t.value)})}function ic(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 ac(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 Fs(e){switch(e.length){case Be:return e.join(".");case Pe:{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 cc(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 fc(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var Be=4,Pe=16,ng=parseInt("0xFFFF",16),pd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Gr(e,t){t.length===Pe&&e.length===Be&&ic(t,0,11)&&(t=t.slice(12)),t.length===Be&&e.length===Pe&&ac(e,pd,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 uc(e,t){if(typeof t=="string"&&(t=er(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 Vs(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=Be,o=Ln(t);if(o==null&&(n=Pe,o=Rn(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=Hs(s,8*n);return{network:Gr(o,i),mask:i}}function Hs(e,t){if(t!==8*Be&&t!==8*Pe)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 sr=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=Vs(t));else{let n=er(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=er(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Hs(o,8*n.length);this.network=Gr(n,this.mask)}}contains(t){return uc({network:this.network,mask:this.mask},t)}toString(){let t=cc(this.mask),r=t!==-1?String(t):fc(this.mask);return Fs(this.network)+"/"+r}};function lc(e,t){return new sr(e).contains(t)}var oc=new Map;function sc(e){return!!e?.[Ms]}function Gt(e){return new kn(e)}function Mn(e){let t=St.getCodec(e);return{code:t.code,size:t.size??0,name:t.name,resolvable:!!t.resolvable,path:!!t.path}}var dc="libp2p-peer-record",hc=Uint8Array.from([3,1]);var $r;(function(e){let t;(function(n){let o;n.codec=()=>(o==null&&(o=Ut((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={multiaddr:it(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.multiaddr=s.bytes();break}default:{s.skipType(f&7);break}}}return c})),o),n.encode=s=>Nt(s,n.codec()),n.decode=(s,i)=>Rt(s,n.codec(),i)})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=Ut((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:it(0),seq:0n,addresses:[]},a=o==null?n.len:n.pos+o;for(;n.pos<a;){let c=n.uint32();switch(c>>>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 Ie('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(c&7);break}}}return i})),r),e.encode=n=>Nt(n,e.codec()),e.decode=(n,o)=>Rt(n,e.codec(),o)})($r||($r={}));var Kt=class e{static createFromProtobuf=t=>{let r=$r.decode(t),n=_s(pr(r.peerId)),o=(r.addresses??[]).map(i=>Gt(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=dc;static CODEC=hc;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=$r.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||!za(this.multiaddrs,t.multiaddrs))}};function md(e){return e[Symbol.asyncIterator]!=null}function yd(e){if(md(e))return(async()=>{for await(let t of e);})();for(let t of e);}var pc=yd;function kt(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Fn=globalThis.CustomEvent??Event;async function*qs(e,t={}){let r=t.concurrency??1/0;r<1&&(r=1/0);let n=t.ordered??!1,o=new EventTarget,s=[],i=kt(),a=kt(),c=!1,u,f=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of e){if(s.length===r&&(i=kt(),await i.promise),f)break;let w={done:!1};s.push(w),m().then(g=>{w.done=!0,w.ok=!0,w.value=g,o.dispatchEvent(new Fn("task-complete"))},g=>{w.done=!0,w.err=g,o.dispatchEvent(new Fn("task-complete"))})}c=!0,o.dispatchEvent(new Fn("task-complete"))}catch(m){u=m,o.dispatchEvent(new Fn("task-complete"))}});function l(){return n?s[0]?.done:!!s.find(m=>m.done)}function*d(){for(;s.length>0&&s[0].done;){let m=s[0];if(s.shift(),m.ok)yield m.value;else throw f=!0,i.resolve(),m.err;i.resolve()}}function*p(){for(;l();)for(let m=0;m<s.length;m++)if(s[m].done){let w=s[m];if(s.splice(m,1),m--,w.ok)yield w.value;else throw f=!0,i.resolve(),w.err;i.resolve()}}for(;;){if(l()||(a=kt(),await a.promise),u!=null||(n?yield*d():yield*p(),u!=null))throw u;if(c&&s.length===0)break}}var Vn=class extends Error{type;code;constructor(t,r,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function Wr(e,t,r){if(t==null)return e;if(t.aborted)return e.catch(()=>{}),Promise.reject(new Vn(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new Vn(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([e,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var zs=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=kt(),this.haveNext=kt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=kt(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,r){await this._push(t,r)}async end(t,r){t!=null?await this.throw(t):await this._push(void 0,r)}async _push(t,r){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=kt(),await Wr(this.readNext.promise,r?.signal,r)}};function mc(){return new zs}var Hn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function yc(e,t){let r=mc();e.sink(r).catch(async i=>{await r.end(i)}),e.sink=async i=>{for await(let a of i)await r.push(a);await r.end()};let n=e.source;e.source[Symbol.iterator]!=null?n=e.source[Symbol.iterator]():e.source[Symbol.asyncIterator]!=null&&(n=e.source[Symbol.asyncIterator]());let o=new Q;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:c,value:u}=await Wr(n.next(),i?.signal);return c===!0?null:u}for(;o.byteLength<i.bytes;){let{value:c,done:u}=await Wr(n.next(),i?.signal);if(u===!0)throw new Hn("unexpected end of input");o.append(c)}let a=o.sublist(0,i.bytes);return o.consume(i.bytes),a},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await r.push(i,a):await r.push(i.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let i=e.source;e.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return e}}}var qn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},zn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Gn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function bc(e,t={}){let r=yc(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Et(t.maxDataLength));let n=t?.lengthDecoder??Tr,o=t?.lengthEncoder??Ze;return{read:async i=>{let a=-1,c=new Q;for(;;){c.append(await r.read({...i,bytes:1}));try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new qn("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Gn("message length length too long");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new zn("message length too long");return r.read({...i,bytes:a})},write:async(i,a)=>{await r.write(new Q(o(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new Q(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap:()=>r.unwrap()}}function ir(e,t){let r=bc(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(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var gc="0.1.0",xc="id",wc="id/push",Ec="1.0.0",Sc="1.0.0";var de;(function(e){let t;e.codec=()=>(t==null&&(t=Ut((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 a=r.uint32();switch(a>>>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 Ie('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 Ie('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(a&7);break}}}return s})),t),e.encode=r=>Nt(r,e.codec()),e.decode=(r,n)=>Rt(r,e.codec(),n)})(de||(de={}));var vt={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function vc(e){if(e!=null&&e.length>0)try{return Gt(e)}catch{}}function xd(e,t){return t??e.userAgent}async function $n(e,t,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new Bt("message was null or undefined");let s={};if(o.listenAddrs.length>0&&(s.addresses=o.listenAddrs.map(c=>({isCertified:!1,multiaddr:Gt(c)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let c=Je(o.publicKey);if(!qa(c).equals(n.remotePeer))throw new Bt("public key did not match remote PeerId");s.publicKey=c}let i;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let c=o.signedPeerRecord,u=await zt.openAndCertify(c,Kt.DOMAIN),f=Kt.createFromProtobuf(u.payload),l=Tn(u.publicKey.toCID());if(!f.peerId.equals(l))throw new Bt("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(f.peerId))throw new Bt("signing key does not match remote PeerId");let d;try{d=await e.get(f.peerId)}catch(p){if(p.name!=="NotFoundError")throw p}if(d!=null&&(s.metadata=d.metadata,d.peerRecordEnvelope!=null)){let p=zt.createFromProtobuf(d.peerRecordEnvelope),m=Kt.createFromProtobuf(p.payload);m.seqNumber>=f.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",m.seqNumber,f.seqNumber),f=m,c=d.peerRecordEnvelope)}s.peerRecordEnvelope=c,s.addresses=f.multiaddrs.map(p=>({isCertified:!0,multiaddr:p})),i={seq:f.seqNumber,addresses:f.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 c={};o.agentVersion!=null&&(c.AgentVersion=U(o.agentVersion)),o.protocolVersion!=null&&(c.ProtocolVersion=U(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,c),await e.merge(n.remotePeer,{metadata:c})}let a={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:o.listenAddrs.map(c=>Gt(c)),observedAddr:o.observedAddr==null?void 0:Gt(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:a}),a}var ar=class{host;protocol;started;timeout;peerId;privateKey;peerStore;registrar;addressManager;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;events;runOnLimitedConnection;log;constructor(t,r){this.protocol=r.protocol,this.started=!1,this.peerId=t.peerId,this.privateKey=t.privateKey,this.peerStore=t.peerStore,this.registrar=t.registrar,this.addressManager=t.addressManager,this.events=t.events,this.log=r.log,this.timeout=r.timeout??vt.timeout,this.maxInboundStreams=r.maxInboundStreams??vt.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??vt.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??vt.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??vt.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??vt.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??vt.protocolPrefix}/${gc}`,agentVersion:xd(t.nodeInfo,r.agentVersion)}}isStarted(){return this.started}async start(){this.started||(await this.peerStore.merge(this.peerId,{metadata:{AgentVersion:U(this.host.agentVersion),ProtocolVersion:U(this.host.protocolVersion)}}),await this.registrar.handle(this.protocol,t=>{this.handleProtocol(t).catch(r=>{this.log.error(r)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.registrar.unhandle(this.protocol),this.started=!1}};var Wn=class extends ar{connectionManager;concurrency;constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??vt.protocolPrefix}/${wc}/${Sc}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=r.concurrency??vt.concurrency,(r.runOnSelfUpdate??vt.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error(o)})})}[en]=["@libp2p/identify-push"];async push(){if(!this.isStarted())return;let t=this.addressManager.getAddresses().map(f=>f.decapsulateCode(Mn("p2p").code)),r=new Kt({peerId:this.peerId,multiaddrs:t}),n=await zt.seal(r,this.privateKey),o=this.registrar.getProtocols(),s=await this.peerStore.get(this.peerId),i=K(s.metadata.get("AgentVersion")??U(this.host.agentVersion)),a=K(s.metadata.get("ProtocolVersion")??U(this.host.protocolVersion)),c=this;async function*u(){for(let f of c.connectionManager.getConnections())(await c.peerStore.get(f.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let d,p=AbortSignal.timeout(c.timeout);try{d=await f.newStream(c.protocol,{signal:p,runOnLimitedConnection:c.runOnLimitedConnection}),await ir(d,{maxDataLength:c.maxMessageSize}).pb(de).write({listenAddrs:t.map(w=>w.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:p}),await d.close({signal:p})}catch(m){c.log.error("could not push identify update to peer",m),d?.abort(m)}})}await pc(qs(u(),{concurrency:this.concurrency}))}async handleProtocol(t){let{connection:r,stream:n}=t;try{if(this.peerId.equals(r.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},i=await ir(n,{maxDataLength:this.maxMessageSize}).pb(de).read(o);await n.close(o),await $n(this.peerStore,this.events,this.log,r,i)}catch(o){this.log.error("received invalid message",o),n.abort(o);return}this.log.trace("handled push from %p",r.remotePeer)}};function Ac(e){try{for(let{code:t,value:r}of e.getComponents())if(r!=null&&t===41)return lc("2000::/3",r)}catch{}return!1}var _c=zc(Ic(),1),wd=["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"],Ed=wd.map(e=>new _c.Netmask(e));function Gs(e){for(let t of Ed)if(t.contains(e))return!0;return!1}function Sd(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function vd(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 Gs(o)}function Ad(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function Id(e){let t=e.split(":"),r=t[t.length-1];return Gs(r)}function _d(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 Cc(e){if(le(e))return Gs(e);if(Sd(e))return vd(e);if(Ad(e))return Id(e);if(rr(e))return _d(e)}function Bc(e){try{for(let{code:t}of e.getComponents())if(t!==42)return t===4||t===41}catch{}return!1}function Pc(e){try{if(!Bc(e))return!1;let[[,t]]=e.stringTuples();return t==null?!1:Cc(t)??!1}catch{}return!0}var Cd=e=>e.toString().split("/").slice(1),cr=e=>({match:t=>t.length<1?!1:e(t[0])?t.slice(1):!1,pattern:"fn"}),k=e=>({match:t=>cr(r=>r===e).match(t),pattern:e}),Te=()=>({match:e=>cr(t=>typeof t=="string").match(e),pattern:"{string}"}),fr=()=>({match:e=>cr(t=>!isNaN(parseInt(t))).match(e),pattern:"{number}"}),q=()=>({match:e=>{if(e.length<2||e[0]!=="p2p"&&e[0]!=="ipfs")return!1;if(e[1].startsWith("Q")||e[1].startsWith("1"))try{G.decode(`z${e[1]}`)}catch{return!1}else return!1;return e.slice(2)},pattern:"/p2p/{peerid}"}),Zr=()=>({match:e=>{if(e.length<2||e[0]!=="certhash")return!1;try{yr.decode(e[1])}catch{return!1}return e.slice(2)},pattern:"/certhash/{certhash}"}),F=e=>({match:t=>{let r=e.match(t);return r===!1?t:r},pattern:`optional(${e.pattern})`}),pt=(...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},pattern:`or(${e.map(t=>t.pattern).join(", ")})`}),M=(...e)=>({match:t=>{for(let r of e){let n=r.match(t);if(n===!1)return!1;t=n}return t},pattern:`and(${e.map(t=>t.pattern).join(", ")})`});function j(...e){function t(o){let s=Cd(o);for(let i of e){let a=i.match(s);if(a===!1)return!1;s=a}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 Bd=q(),nw=j(Bd),Zn=M(k("dns4"),Te()),Yn=M(k("dns6"),Te()),Xn=M(k("dnsaddr"),Te()),Ws=M(k("dns"),Te()),ow=j(Zn,F(q())),sw=j(Yn,F(q())),iw=j(Xn,F(q())),aw=j(pt(Ws,Xn,Zn,Yn),F(q())),Tc=M(k("ip4"),cr(le)),Dc=M(k("ip6"),cr(rr)),js=pt(Tc,Dc),ee=pt(js,Ws,Zn,Yn,Xn),Oc=j(pt(js,M(pt(Ws,Xn,Zn,Yn),F(q())))),cw=j(Tc),fw=j(Dc),uw=j(js),Zs=M(ee,k("tcp"),fr()),Yr=M(ee,k("udp"),fr()),Lc=j(M(Zs,F(q()))),lw=j(Yr),Ys=M(Yr,k("quic"),F(q())),Qn=M(Yr,k("quic-v1"),F(q())),Pd=pt(Ys,Qn),dw=j(Ys),hw=j(Qn),$s=pt(ee,Zs,Yr,Ys,Qn),Rc=pt(M($s,k("ws"),F(q()))),pw=j(Rc),Nc=pt(M($s,k("wss"),F(q())),M($s,k("tls"),F(M(k("sni"),Te())),k("ws"),F(q()))),mw=j(Nc),Uc=M(Yr,k("webrtc-direct"),F(Zr()),F(Zr()),F(q())),yw=j(Uc),Kc=M(Qn,k("webtransport"),F(Zr()),F(Zr()),F(q())),bw=j(Kc),jn=pt(Rc,Nc,M(Zs,F(q())),M(Pd,F(q())),M(ee,F(q())),Uc,Kc,q()),gw=j(jn),Td=M(jn,k("p2p-circuit"),q()),xw=j(Td),Dd=pt(M(jn,k("p2p-circuit"),k("webrtc"),F(q())),M(jn,k("webrtc"),F(q())),M(k("webrtc"),F(q()))),ww=j(Dd),Od=pt(M(ee,k("tcp"),fr(),k("http"),F(q())),M(ee,k("http"),F(q()))),Ew=j(Od),Ld=pt(M(ee,k("tcp"),pt(M(k("443"),k("http")),M(fr(),k("https")),M(fr(),k("tls"),k("http"))),F(q())),M(ee,k("tls"),k("http"),F(q())),M(ee,k("https"),F(q()))),Sw=j(Ld),Rd=pt(M(k("memory"),Te(),F(q()))),vw=j(Rd);var Jn=class extends ar{constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??vt.protocolPrefix}/${xc}/${Ec}`,log:t.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??vt.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(s=>{s.name!==tn.name&&this.log.error("error during identify trigged by connection:open",s)})})}[en]=["@libp2p/identify"];async _identify(t,r={}){let n;if(r.signal==null){let o=AbortSignal.timeout(this.timeout);r={...r,signal:o}}try{n=await t.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection});let s=await ir(n,{maxDataLength:this.maxMessageSize}).pb(de).read(r);return await n.close(r),s}catch(o){throw n?.abort(o),o}}async identify(t,r={}){let n=await this._identify(t,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Bt("public key was missing from identify message");let a=Je(o),c=Tn(a.toCID());if(!t.remotePeer.equals(c))throw new Bt("identified peer does not match the expected peer");if(this.peerId.equals(c))throw new Bt("identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("identify completed for peer %p and protocols %o",c,s),$n(this.peerStore,this.events,this.log,t,n)}maybeAddObservedAddress(t){let r=vc(t);if(r==null)return;if(this.log.trace("our observed address was %a",r),Pc(r)){this.log.trace("our observed address was private");return}let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Ac(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Lc.exactMatch(r)||(this.log.trace("storing the observed address"),this.addressManager.addObservedAddr(r))}async handleProtocol(t){let{connection:r,stream:n}=t,o=AbortSignal.timeout(this.timeout);try{let s=await this.peerStore.get(this.peerId),i=this.addressManager.getAddresses().map(f=>f.decapsulateCode(Mn("p2p").code)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let f=new Kt({peerId:this.peerId,multiaddrs:i});a=(await zt.seal(f,this.privateKey)).marshal().subarray()}let c=r.remoteAddr.bytes;Oc.matches(r.remoteAddr)||(c=void 0),await ir(n).pb(de).write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Mt(this.privateKey.publicKey),listenAddrs:i.map(f=>f.bytes),signedPeerRecord:a,observedAddr:c,protocols:s.protocols},{signal:o}),await n.close({signal:o})}catch(s){this.log.error("could not respond to identify request",s),n.abort(s)}}};function Nd(e={}){return t=>new Jn(t,e)}function Ud(e={}){return t=>new Wn(t,e)}return Gc(Kd);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js: