@libp2p/identify 4.0.14 → 4.1.0-2151144c3

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 ru=Object.create;var Wr=Object.defineProperty;var nu=Object.getOwnPropertyDescriptor;var ou=Object.getOwnPropertyNames;var su=Object.getPrototypeOf,iu=Object.prototype.hasOwnProperty;var au=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ee=(t,e)=>{for(var r in e)Wr(t,r,{get:e[r],enumerable:!0})},yi=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ou(e))!iu.call(t,o)&&o!==r&&Wr(t,o,{get:()=>e[o],enumerable:!(n=nu(e,o))||n.enumerable});return t};var cu=(t,e,r)=>(r=t!=null?ru(su(t)):{},yi(e||!t||!t.__esModule?Wr(r,"default",{value:t,enumerable:!0}):r,t)),uu=t=>yi(Wr({},"__esModule",{value:!0}),t);var Rc=au(Yr=>{(function(){var t,e,r,n,o,s,i,c;c=function(a){var u,f,l,d;return u=(a&255<<24)>>>24,f=(a&255<<16)>>>16,l=(a&65280)>>>8,d=a&255,[u,f,l,d].join(".")},i=function(a){var u,f,l,d,p,h;for(u=[],l=d=0;d<=3&&a.length!==0;l=++d){if(l>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}h=e(a),p=h[0],f=h[1],a=a.substring(f),u.push(p)}if(a.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},r=function(a){return a.charCodeAt(0)},n=r("0"),s=r("a"),o=r("A"),e=function(a){var u,f,l,d,p;for(d=0,u=10,f="9",l=0,a.length>1&&a[l]==="0"&&(a[l+1]==="x"||a[l+1]==="X"?(l+=2,u=16):"0"<=a[l+1]&&a[l+1]<="9"&&(l++,u=8,f="7")),p=l;l<a.length;){if("0"<=a[l]&&a[l]<=f)d=d*u+(r(a[l])-n)>>>0;else if(u===16)if("a"<=a[l]&&a[l]<="f")d=d*u+(10+r(a[l])-s)>>>0;else if("A"<=a[l]&&a[l]<="F")d=d*u+(10+r(a[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]},t=(function(){function a(u,f){var l,d,p,h;if(typeof u!="string")throw new Error("Missing `net' parameter");if(f||(h=u.split("/",2),u=h[0],f=h[1]),f||(f=32),typeof f=="string"&&f.indexOf(".")>-1){try{this.maskLong=i(f)}catch(E){throw l=E,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(E){throw l=E,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=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new a(u)),u instanceof a?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(u){return u==null&&(u=1),new a(c(this.netLong+this.size*u),this.mask)},a.prototype.forEach=function(u){var f,l,d;for(d=i(this.first),l=i(this.last),f=0;d<=l;)u(c(d),d,f),f++,d++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a})(),Yr.ip2long=i,Yr.long2ip=c,Yr.Netmask=t}).call(Yr)});var Hd={};Ee(Hd,{identify:()=>Fd,identifyPush:()=>qd});var Q=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Rt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var jr=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Xr=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Te=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var mt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Zn=Symbol.for("@libp2p/peer-id");var Qr=Symbol.for("@libp2p/service-capabilities"),Zd=Symbol.for("@libp2p/service-dependencies");var Qn={};Ee(Qn,{base58btc:()=>oe,base58flickr:()=>yu});var xh=new Uint8Array(0);function bi(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ye(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function gi(t){return new TextEncoder().encode(t)}function xi(t){return new TextDecoder().decode(t)}function fu(t,e){if(t.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<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=t.length,a=t.charAt(0),u=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function l(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var E=0,S=0,g=0,I=h.length;g!==I&&h[g]===0;)g++,E++;for(var x=(I-g)*f+1>>>0,C=new Uint8Array(x);g!==I;){for(var R=h[g],K=0,M=x-1;(R!==0||K<S)&&M!==-1;M--,K++)R+=256*C[M]>>>0,C[M]=R%c>>>0,R=R/c>>>0;if(R!==0)throw new Error("Non-zero carry");S=K,g++}for(var v=x-S;v!==x&&C[v]===0;)v++;for(var w=a.repeat(E);v<x;++v)w+=t.charAt(C[v]);return w}function d(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var E=0;if(h[E]!==" "){for(var S=0,g=0;h[E]===a;)S++,E++;for(var I=(h.length-E)*u+1>>>0,x=new Uint8Array(I);h[E];){var C=r[h.charCodeAt(E)];if(C===255)return;for(var R=0,K=I-1;(C!==0||R<g)&&K!==-1;K--,R++)C+=c*x[K]>>>0,x[K]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");g=R,E++}if(h[E]!==" "){for(var M=I-g;M!==I&&x[M]===0;)M++;for(var v=new Uint8Array(S+(I-M)),w=S;M!==I;)v[w++]=x[M++];return v}}}function p(h){var E=d(h);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:d,decode:p}}var lu=fu,du=lu,Ei=du;var Gn=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Wn=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return vi(this,e)}},jn=class{decoders;constructor(e){this.decoders=e}or(e){return vi(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function vi(t,e){return new jn({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Xn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Gn(e,r,n),this.decoder=new Wn(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Nt({name:t,prefix:e,encode:r,decode:n}){return new Xn(t,e,r,n)}function ot({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Ei(r,t);return Nt({prefix:e,name:t,encode:n,decode:s=>Ye(o(s))})}function hu(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|f,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function pu(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<t.length;++a)for(c=c<<8|t[a],i+=8;i>r;)i-=r,s+=e[o&c>>i];if(i!==0&&(s+=e[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function mu(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function ne({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=mu(n);return Nt({prefix:e,name:t,encode(s){return pu(s,n,r)},decode(s){return hu(s,o,r,t)}})}var oe=ot({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),yu=ot({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Jn={};Ee(Jn,{base32:()=>st,base32hex:()=>wu,base32hexpad:()=>vu,base32hexpadupper:()=>Su,base32hexupper:()=>Eu,base32pad:()=>gu,base32padupper:()=>xu,base32upper:()=>bu,base32z:()=>Au});var st=ne({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),bu=ne({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),gu=ne({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),xu=ne({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),wu=ne({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Eu=ne({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),vu=ne({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Su=ne({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Au=ne({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var eo={};Ee(eo,{base36:()=>lr,base36upper:()=>Iu});var lr=ot({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Iu=ot({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Cu=Ii,Si=128,_u=127,Du=~_u,Tu=Math.pow(2,31);function Ii(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Tu;)e[r++]=t&255|Si,t/=128;for(;t&Du;)e[r++]=t&255|Si,t>>>=7;return e[r]=t|0,Ii.bytes=r-n+1,e}var Lu=to,Bu=128,Ai=127;function to(t,n){var r=0,n=n||0,o=0,s=n,i,c=t.length;do{if(s>=c)throw to.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Ai)<<o:(i&Ai)*Math.pow(2,o),o+=7}while(i>=Bu);return to.bytes=s-n,r}var Pu=Math.pow(2,7),Ou=Math.pow(2,14),Ru=Math.pow(2,21),Nu=Math.pow(2,28),Uu=Math.pow(2,35),ku=Math.pow(2,42),Ku=Math.pow(2,49),Mu=Math.pow(2,56),Vu=Math.pow(2,63),Fu=function(t){return t<Pu?1:t<Ou?2:t<Ru?3:t<Nu?4:t<Uu?5:t<ku?6:t<Ku?7:t<Mu?8:t<Vu?9:10},qu={encode:Cu,decode:Lu,encodingLength:Fu},Hu=qu,dr=Hu;function hr(t,e=0){return[dr.decode(t,e),dr.decode.bytes]}function Ut(t,e,r=0){return dr.encode(t,e,r),e}function kt(t){return dr.encodingLength(t)}function Me(t,e){let r=e.byteLength,n=kt(t),o=n+kt(r),s=new Uint8Array(o+r);return Ut(t,s,0),Ut(r,s,n),s.set(e,o),new Kt(t,r,e,s)}function pr(t){let e=Ye(t),[r,n]=hr(e),[o,s]=hr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Kt(r,o,i,e)}function Ci(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&bi(t.bytes,r.bytes)}}var Kt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function _i(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return zu(r,ro(t),e??oe.encoder);default:return Yu(r,ro(t),e??st.encoder)}}var Di=new WeakMap;function ro(t){let e=Di.get(t);if(e==null){let r=new Map;return Di.set(t,r),r}return e}var ae=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,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:e,multihash:r}=this;if(e!==mr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Zu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Me(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Ci(e.multihash,n.multihash)}toString(e){return _i(this,e)}toJSON(){return{"/":_i(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??Ti(n,o,s.bytes))}else if(r[Gu]===!0){let{version:n,multihash:o,code:s}=r,i=pr(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==mr)throw new Error(`Version 0 CID must use dag-pb (code: ${mr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Ti(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,mr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Ye(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Kt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,d]=hr(e.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,c=n(),a=n(),u=r+a,f=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:f,size:u}}static parse(e,r){let[n,o]=$u(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ro(s).set(n,e),s}};function $u(t,e){switch(t[0]){case"Q":{let r=e??oe;return[oe.prefix,r.decode(`${oe.prefix}${t}`)]}case oe.prefix:{let r=e??oe;return[oe.prefix,r.decode(t)]}case st.prefix:{let r=e??st;return[st.prefix,r.decode(t)]}case lr.prefix:{let r=e??lr;return[lr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function zu(t,e,r){let{prefix:n}=r;if(n!==oe.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Yu(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var mr=112,Zu=18;function Ti(t,e,r){let n=kt(t),o=n+kt(e),s=new Uint8Array(o+r.byteLength);return Ut(t,s,0),Ut(e,s,n),s.set(r,o),s}var Gu=Symbol.for("@ipld/js-cid/CID");var no={};Ee(no,{identity:()=>Le});var Li=0,Wu="identity",Bi=Ye;function ju(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Me(Li,Bi(t))}var Le={code:Li,name:Wu,encode:Bi,digest:ju};function ce(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function he(t=0){return new Uint8Array(t)}function ve(t=0){return new Uint8Array(t)}function Ze(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=ve(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}var Oi=Symbol.for("@achingbrain/uint8arraylist");function Pi(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function en(t){return!!t?.[Oi]}var ie=class t{bufs;length;[Oi]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(en(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(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(en(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Pi(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Pi(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(en(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return Ze(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Ze(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=[...n],s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,e>=a)continue;let u=e>=c&&e<a,f=r>c&&r<=a;if(u&&f){if(e===c&&r===a){n.push(i);break}let l=e-c;n.push(i.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-c));continue}if(f){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!en(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=a;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-c[p]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=ve(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=he(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=he(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=he(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=ve(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=he(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=he(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=he(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=he(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=he(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ce(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var oo={};Ee(oo,{base10:()=>Xu});var Xu=ot({prefix:"9",name:"base10",alphabet:"0123456789"});var so={};Ee(so,{base16:()=>Qu,base16upper:()=>Ju});var Qu=ne({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ju=ne({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var io={};Ee(io,{base2:()=>ef});var ef=ne({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ao={};Ee(ao,{base256emoji:()=>sf});var Ri=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}"),tf=Ri.reduce((t,e,r)=>(t[r]=e,t),[]),rf=Ri.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function nf(t){return t.reduce((e,r)=>(e+=tf[r],e),"")}function of(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=rf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var sf=Nt({prefix:"\u{1F680}",name:"base256emoji",encode:nf,decode:of});var uo={};Ee(uo,{base64:()=>af,base64pad:()=>cf,base64url:()=>co,base64urlpad:()=>uf});var af=ne({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),cf=ne({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),co=ne({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),uf=ne({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var fo={};Ee(fo,{base8:()=>ff});var ff=ne({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var lo={};Ee(lo,{identity:()=>lf});var lf=Nt({prefix:"\0",name:"identity",encode:t=>xi(t),decode:t=>gi(t)});var rp=new TextEncoder,np=new TextDecoder;var mo={};Ee(mo,{sha256:()=>yr,sha512:()=>mf});var pf=20;function po({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new ho(t,e,r,n,o)}var ho=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??pf,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Ni(n,this.code,r?.truncate):n.then(o=>Ni(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ni(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Me(e,t)}function ki(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var yr=po({name:"sha2-256",code:18,encode:ki("SHA-256")}),mf=po({name:"sha2-512",code:19,encode:ki("SHA-512")});var br={...lo,...io,...fo,...oo,...so,...Jn,...eo,...Qn,...uo,...ao},mp={...mo,...no};function Mi(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ki=Mi("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),yo=Mi("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=ve(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),yf={utf8:Ki,"utf-8":Ki,hex:br.base16,latin1:yo,ascii:yo,binary:yo,...br},tn=yf;function F(t,e="utf8"){let r=tn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function H(t,e="utf8"){let r=tn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var bf=parseInt("11111",2),bo=parseInt("10000000",2),gf=parseInt("01111111",2),Vi={0:gr,1:gr,2:xf,3:vf,4:Sf,5:Ef,6:wf,16:gr,22:gr,48:gr};function Ge(t,e={offset:0}){let r=t[e.offset]&bf;if(e.offset++,Vi[r]!=null)return Vi[r](t,e);throw new Error("No decoder for tag "+r)}function xr(t,e){let r=0;if((t[e.offset]&bo)===bo){let n=t[e.offset]&gf,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)o+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=t[e.offset],e.offset++;return r}function gr(t,e){xr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=Ge(t,e);if(n===null)break;r.push(n)}return r}function xf(t,e){let r=xr(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function wf(t,e){let r=xr(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,a.push(u&127),u<128){a.reverse();let f=0;for(let l=0;l<a.length;l++)f+=a[l]<<l*7;c+=`.${f}`,a=[]}}return c}function Ef(t,e){return e.offset++,null}function vf(t,e){let r=xr(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Sf(t,e){let r=xr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Af(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new ie;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function go(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Af(t.byteLength);return new ie(Uint8Array.from([e.byteLength|bo]),e)}function Se(t){let e=new ie,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ie(Uint8Array.from([2]),go(e),e)}function rn(t){let e=Uint8Array.from([0]),r=new ie(e,t);return new ie(Uint8Array.from([3]),go(r),r)}function it(t,e=48){let r=new ie;for(let n of t)r.append(n);return new ie(Uint8Array.from([e]),go(r),r)}async function Fi(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,e,r.subarray());return n?.signal?.throwIfAborted(),s}var If=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Cf=Uint8Array.from([6,5,43,129,4,0,34]),_f=Uint8Array.from([6,5,43,129,4,0,35]),Df={ext:!0,kty:"EC",crv:"P-256"},Tf={ext:!0,kty:"EC",crv:"P-384"},Lf={ext:!0,kty:"EC",crv:"P-521"},xo=32,wo=48,Eo=66;function vo(t){let e=Ge(t);return qi(e)}function qi(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===xo*2+1)return n=H(e.subarray(r,r+xo),"base64url"),o=H(e.subarray(r+xo),"base64url"),new Mt({...Df,key_ops:["verify"],x:n,y:o});if(e.byteLength===wo*2+1)return n=H(e.subarray(r,r+wo),"base64url"),o=H(e.subarray(r+wo),"base64url"),new Mt({...Tf,key_ops:["verify"],x:n,y:o});if(e.byteLength===Eo*2+1)return n=H(e.subarray(r,r+Eo),"base64url"),o=H(e.subarray(r+Eo),"base64url"),new Mt({...Lf,key_ops:["verify"],x:n,y:o});throw new Q(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Hi(t){return it([Se(Uint8Array.from([1])),it([Bf(t.crv)],160),it([rn(new ie(Uint8Array.from([4]),F(t.x??"","base64url"),F(t.y??"","base64url")))],161)]).subarray()}function Bf(t){if(t==="P-256")return If;if(t==="P-384")return Cf;if(t==="P-521")return _f;throw new Q(`Invalid curve ${t}`)}var Mt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Hi(this.jwk)),this._raw}toMultihash(){return Le.digest(Ve(this))}toCID(){return ae.createV1(114,this.toMultihash())}toString(){return oe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ce(this.raw,e.raw)}async verify(e,r,n){return Fi(this.jwk,r,e,n)}};function bt(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Fe(t,e=""){if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new Error(`${r}expected integer >= 0, got ${t}`)}}function k(t,e,r=""){let n=bt(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,c=s?` of length ${e}`:"",a=n?`length=${o}`:`type=${typeof t}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return t}function nn(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Fe(t.outputLen),Fe(t.blockLen)}function Vt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function zi(t,e){k(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function je(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function on(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Be(t,e){return t<<32-e|t>>>e}var Yi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Pf=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Xe(t){if(k(t),Yi)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Pf[t[r]];return e}var We={_0:48,_9:57,A:65,F:70,a:97,f:102};function $i(t){if(t>=We._0&&t<=We._9)return t-We._0;if(t>=We.A&&t<=We.F)return t-(We.A-10);if(t>=We.a&&t<=We.f)return t-(We.a-10)}function Qe(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Yi)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=$i(t.charCodeAt(s)),c=$i(t.charCodeAt(s+1));if(i===void 0||c===void 0){let a=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Ae(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];k(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function So(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Ft(t=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}var Ao=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Zi(t,e,r){return t&e^~t&r}function Gi(t,e,r){return t&e^t&r^e&r}var wr=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=on(this.buffer)}update(e){Vt(this),k(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=on(e);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(e.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Vt(this),zi(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,je(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let c=on(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,f[l],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=c,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Je=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var pe=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var sn=BigInt(4294967295),Wi=BigInt(32);function Of(t,e=!1){return e?{h:Number(t&sn),l:Number(t>>Wi&sn)}:{h:Number(t>>Wi&sn)|0,l:Number(t&sn)|0}}function ji(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=Of(t[s],e);[n[s],o[s]]=[i,c]}return[n,o]}var Io=(t,e,r)=>t>>>r,Co=(t,e,r)=>t<<32-r|e>>>r,gt=(t,e,r)=>t>>>r|e<<32-r,xt=(t,e,r)=>t<<32-r|e>>>r,Er=(t,e,r)=>t<<64-r|e>>>r-32,vr=(t,e,r)=>t>>>r-32|e<<64-r;function qe(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Xi=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Qi=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Ji=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),ea=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,ta=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ra=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var Nf=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]),at=new Uint32Array(64),_o=class extends wr{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[e,r,n,o,s,i,c,a]}set(e,r,n,o,s,i,c,a){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(e,r){for(let l=0;l<16;l++,r+=4)at[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let d=at[l-15],p=at[l-2],h=Be(d,7)^Be(d,18)^d>>>3,E=Be(p,17)^Be(p,19)^p>>>10;at[l]=E+at[l-7]+h+at[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Be(c,6)^Be(c,11)^Be(c,25),p=f+d+Zi(c,a,u)+Nf[l]+at[l]|0,E=(Be(n,2)^Be(n,13)^Be(n,22))+Gi(n,o,s)|0;f=u,u=a,a=c,c=i+p|0,i=s,s=o,o=n,n=p+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,c,a,u,f)}roundClean(){je(at)}destroy(){this.set(0,0,0,0,0,0,0,0),je(this.buffer)}},Do=class extends _o{A=Je[0]|0;B=Je[1]|0;C=Je[2]|0;D=Je[3]|0;E=Je[4]|0;F=Je[5]|0;G=Je[6]|0;H=Je[7]|0;constructor(){super(32)}};var na=ji(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Uf=na[0],kf=na[1],ct=new Uint32Array(80),ut=new Uint32Array(80),To=class extends wr{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:f,Fh:l,Fl:d,Gh:p,Gl:h,Hh:E,Hl:S}=this;return[e,r,n,o,s,i,c,a,u,f,l,d,p,h,E,S]}set(e,r,n,o,s,i,c,a,u,f,l,d,p,h,E,S){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=p|0,this.Gl=h|0,this.Hh=E|0,this.Hl=S|0}process(e,r){for(let x=0;x<16;x++,r+=4)ct[x]=e.getUint32(r),ut[x]=e.getUint32(r+=4);for(let x=16;x<80;x++){let C=ct[x-15]|0,R=ut[x-15]|0,K=gt(C,R,1)^gt(C,R,8)^Io(C,R,7),M=xt(C,R,1)^xt(C,R,8)^Co(C,R,7),v=ct[x-2]|0,w=ut[x-2]|0,N=gt(v,w,19)^Er(v,w,61)^Io(v,w,6),V=xt(v,w,19)^vr(v,w,61)^Co(v,w,6),L=Ji(M,V,ut[x-7],ut[x-16]),y=ea(L,K,N,ct[x-7],ct[x-16]);ct[x]=y|0,ut[x]=L|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:f,Eh:l,El:d,Fh:p,Fl:h,Gh:E,Gl:S,Hh:g,Hl:I}=this;for(let x=0;x<80;x++){let C=gt(l,d,14)^gt(l,d,18)^Er(l,d,41),R=xt(l,d,14)^xt(l,d,18)^vr(l,d,41),K=l&p^~l&E,M=d&h^~d&S,v=ta(I,R,M,kf[x],ut[x]),w=ra(v,g,C,K,Uf[x],ct[x]),N=v|0,V=gt(n,o,28)^Er(n,o,34)^Er(n,o,39),L=xt(n,o,28)^vr(n,o,34)^vr(n,o,39),y=n&s^n&c^s&c,b=o&i^o&a^i&a;g=E|0,I=S|0,E=p|0,S=h|0,p=l|0,h=d|0,{h:l,l:d}=qe(u|0,f|0,w|0,N|0),u=c|0,f=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let m=Xi(N,L,b);n=Qi(m,w,V,y),o=m|0}({h:n,l:o}=qe(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=qe(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=qe(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:f}=qe(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=qe(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:h}=qe(this.Fh|0,this.Fl|0,p|0,h|0),{h:E,l:S}=qe(this.Gh|0,this.Gl|0,E|0,S|0),{h:g,l:I}=qe(this.Hh|0,this.Hl|0,g|0,I|0),this.set(n,o,s,i,c,a,u,f,l,d,p,h,E,S,g,I)}roundClean(){je(ct,ut)}destroy(){je(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Lo=class extends To{Ah=pe[0]|0;Al=pe[1]|0;Bh=pe[2]|0;Bl=pe[3]|0;Ch=pe[4]|0;Cl=pe[5]|0;Dh=pe[6]|0;Dl=pe[7]|0;Eh=pe[8]|0;El=pe[9]|0;Fh=pe[10]|0;Fl=pe[11]|0;Gh=pe[12]|0;Gl=pe[13]|0;Hh=pe[14]|0;Hl=pe[15]|0;constructor(){super(64)}};var qt=So(()=>new Do,Ao(1));var oa=So(()=>new Lo,Ao(3));var Po=BigInt(0),Bo=BigInt(1);function et(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function sa(t){if(typeof t=="bigint"){if(!an(t))throw new Error("positive bigint expected, got "+t)}else Fe(t);return t}function Sr(t){let e=sa(t).toString(16);return e.length&1?"0"+e:e}function ia(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Po:BigInt("0x"+t)}function Ht(t){return ia(Xe(t))}function wt(t){return ia(Xe(un(k(t)).reverse()))}function cn(t,e){Fe(e),t=sa(t);let r=Qe(t.toString(16).padStart(e*2,"0"));if(r.length!==e)throw new Error("number too large");return r}function Oo(t,e){return cn(t,e).reverse()}function un(t){return Uint8Array.from(t)}var an=t=>typeof t=="bigint"&&Po<=t;function Kf(t,e,r){return an(t)&&an(e)&&an(r)&&e<=t&&t<r}function Ar(t,e,r,n){if(!Kf(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Ro(t){let e;for(e=0;t>Po;t>>=Bo,e+=1);return e}var Ir=t=>(Bo<<BigInt(t))-Bo;function aa(t,e,r){if(Fe(t,"hashLen"),Fe(e,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=S=>new Uint8Array(S),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),c=1e3,a=n(t),u=n(t),f=0,l=()=>{a.fill(1),u.fill(0),f=0},d=(...S)=>r(u,Ae(a,...S)),p=(S=o)=>{u=d(s,S),a=d(),S.length!==0&&(u=d(i,S),a=d())},h=()=>{if(f++>=c)throw new Error("drbg: tried max amount of iterations");let S=0,g=[];for(;S<e;){a=d();let I=a.slice();g.push(I),S+=a.length}return Ae(...g)};return(S,g)=>{l(),p(S);let I;for(;!(I=g(h()));)p();return l(),I}}function ft(t,e={},r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(s,i,c){let a=t[s];if(c&&a===void 0)return;let u=typeof a;if(u!==i||a===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([c,a])=>n(c,a,i));o(e,!1),o(r,!0)}function $t(t){let e=new WeakMap;return(r,...n)=>{let o=e.get(r);if(o!==void 0)return o;let s=t(r,...n);return e.set(r,s),s}}var we=BigInt(0),ue=BigInt(1),Et=BigInt(2),fa=BigInt(3),la=BigInt(4),da=BigInt(5),Mf=BigInt(7),ha=BigInt(8),Vf=BigInt(9),pa=BigInt(16);function se(t,e){let r=t%e;return r>=we?r:e+r}function X(t,e,r){let n=t;for(;e-- >we;)n*=n,n%=r;return n}function ca(t,e){if(t===we)throw new Error("invert: expected non-zero number");if(e<=we)throw new Error("invert: expected positive modulus, got "+e);let r=se(t,e),n=e,o=we,s=ue,i=ue,c=we;for(;r!==we;){let u=n/r,f=n%r,l=o-i*u,d=s-c*u;n=r,r=f,o=i,s=c,i=l,c=d}if(n!==ue)throw new Error("invert: does not exist");return se(o,e)}function Uo(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function ma(t,e){let r=(t.ORDER+ue)/la,n=t.pow(e,r);return Uo(t,n,e),n}function Ff(t,e){let r=(t.ORDER-da)/ha,n=t.mul(e,Et),o=t.pow(n,r),s=t.mul(e,o),i=t.mul(t.mul(s,Et),o),c=t.mul(s,t.sub(i,t.ONE));return Uo(t,c,e),c}function qf(t){let e=zt(t),r=ya(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+Mf)/pa;return(c,a)=>{let u=c.pow(a,i),f=c.mul(u,n),l=c.mul(u,o),d=c.mul(u,s),p=c.eql(c.sqr(f),a),h=c.eql(c.sqr(l),a);u=c.cmov(u,f,p),f=c.cmov(d,l,h);let E=c.eql(c.sqr(f),a),S=c.cmov(u,f,E);return Uo(c,S,a),S}}function ya(t){if(t<fa)throw new Error("sqrt is not defined for small field");let e=t-ue,r=0;for(;e%Et===we;)e/=Et,r++;let n=Et,o=zt(t);for(;ua(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ma;let s=o.pow(n,e),i=(e+ue)/Et;return function(a,u){if(a.is0(u))return u;if(ua(a,u)!==1)throw new Error("Cannot find square root");let f=r,l=a.mul(a.ONE,s),d=a.pow(u,e),p=a.pow(u,i);for(;!a.eql(d,a.ONE);){if(a.is0(d))return a.ZERO;let h=1,E=a.sqr(d);for(;!a.eql(E,a.ONE);)if(h++,E=a.sqr(E),h===f)throw new Error("Cannot find square root");let S=ue<<BigInt(f-h-1),g=a.pow(l,S);f=h,l=a.sqr(g),d=a.mul(d,l),p=a.mul(p,g)}return p}}function Hf(t){return t%la===fa?ma:t%ha===da?Ff:t%pa===Vf?qf(t):ya(t)}var ba=(t,e)=>(se(t,e)&ue)===ue,$f=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ko(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=$f.reduce((n,o)=>(n[o]="function",n),e);return ft(t,r),t}function zf(t,e,r){if(r<we)throw new Error("invalid exponent, negatives unsupported");if(r===we)return t.ONE;if(r===ue)return e;let n=t.ONE,o=e;for(;r>we;)r&ue&&(n=t.mul(n,o)),o=t.sqr(o),r>>=ue;return n}function Cr(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),o=e.reduce((i,c,a)=>t.is0(c)?i:(n[a]=i,t.mul(i,c)),t.ONE),s=t.inv(o);return e.reduceRight((i,c,a)=>t.is0(c)?i:(n[a]=t.mul(i,n[a]),t.mul(i,c)),s),n}function ua(t,e){let r=(t.ORDER-ue)/Et,n=t.pow(e,r),o=t.eql(n,t.ONE),s=t.eql(n,t.ZERO),i=t.eql(n,t.neg(t.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Yf(t,e){e!==void 0&&Fe(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var No=class{ORDER;BITS;BYTES;isLE;ZERO=we;ONE=ue;_lengths;_sqrt;_mod;constructor(e,r={}){if(e<=we)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=Yf(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return se(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return we<=e&&e<this.ORDER}is0(e){return e===we}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&ue)===ue}neg(e){return se(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return se(e*e,this.ORDER)}add(e,r){return se(e+r,this.ORDER)}sub(e,r){return se(e-r,this.ORDER)}mul(e,r){return se(e*r,this.ORDER)}pow(e,r){return zf(this,e,r)}div(e,r){return se(e*ca(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return ca(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=Hf(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?Oo(e,this.BYTES):cn(e,this.BYTES)}fromBytes(e,r=!1){k(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:c}=this;if(n){if(!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let a=s?wt(e):Ht(e);if(c&&(a=se(a,i)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return Cr(this,e)}cmov(e,r,n){return n?r:e}};function zt(t,e={}){return new No(t,e)}function ga(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function Ko(t){let e=ga(t);return e+Math.ceil(e/2)}function Mo(t,e,r=!1){k(t);let n=t.length,o=ga(e),s=Ko(e);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?wt(t):Ht(t),c=se(i,e-ue)+ue;return r?Oo(c,o):cn(c,o)}var Yt=BigInt(0),vt=BigInt(1);function _r(t,e){let r=e.negate();return t?r:e}function St(t,e){let r=Cr(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function va(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Vo(t,e){va(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=Ir(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function xa(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(t&o),a=t>>i;c>n&&(c-=s,a+=vt);let u=e*n,f=u+Math.abs(c)-1,l=c===0,d=c<0,p=e%2!==0;return{nextN:a,offset:f,isZero:l,isNeg:d,isNegF:p,offsetF:u}}var Fo=new WeakMap,Sa=new WeakMap;function qo(t){return Sa.get(t)||1}function wa(t){if(t!==Yt)throw new Error("invalid wNAF")}var Zt=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>Yt;)r&vt&&(n=n.add(o)),o=o.double(),r>>=vt;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=Vo(r,this.bits),s=[],i=e,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Vo(e,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:f,isNeg:l,isNegF:d,offsetF:p}=xa(n,c,i);n=a,f?s=s.add(_r(d,r[p])):o=o.add(_r(l,r[u]))}return wa(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=Vo(e,this.bits);for(let i=0;i<s.windows&&n!==Yt;i++){let{nextN:c,offset:a,isZero:u,isNeg:f}=xa(n,i,s);if(n=c,!u){let l=r[a];o=o.add(f?l.negate():l)}}return wa(n),o}getPrecomputes(e,r,n){let o=Fo.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Fo.set(r,o))),o}cached(e,r,n){let o=qo(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=qo(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){va(r,this.bits),Sa.set(e,r),Fo.delete(e)}hasCache(e){return qo(e)!==1}};function Aa(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>Yt||n>Yt;)r&vt&&(s=s.add(o)),n&vt&&(i=i.add(o)),o=o.double(),r>>=vt,n>>=vt;return{p1:s,p2:i}}function Ea(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ko(e),e}else return zt(t,{isLE:r})}function fn(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let a of["p","n","h"]){let u=e[a];if(!(typeof u=="bigint"&&u>Yt))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Ea(e.p,r.Fp,n),s=Ea(e.n,r.Fn,n),c=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function ln(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var lt=BigInt(0),fe=BigInt(1),Ho=BigInt(2),Zf=BigInt(8);function Gf(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),c=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,c)}function Ia(t,e={}){let r=fn("edwards",t,e,e.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;ft(e,{},{uvRatio:"function"});let c=Ho<<BigInt(o.BYTES*8)-fe,a=S=>n.create(S),u=e.uvRatio||((S,g)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,g))}}catch{return{isValid:!1,value:lt}}});if(!Gf(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function f(S,g,I=!1){let x=I?fe:lt;return Ar("coordinate "+S,g,x,c),g}function l(S){if(!(S instanceof h))throw new Error("EdwardsPoint expected")}let d=$t((S,g)=>{let{X:I,Y:x,Z:C}=S,R=S.is0();g==null&&(g=R?Zf:n.inv(C));let K=a(I*g),M=a(x*g),v=n.mul(C,g);if(R)return{x:lt,y:fe};if(v!==fe)throw new Error("invZ was invalid");return{x:K,y:M}}),p=$t(S=>{let{a:g,d:I}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:x,Y:C,Z:R,T:K}=S,M=a(x*x),v=a(C*C),w=a(R*R),N=a(w*w),V=a(M*g),L=a(w*a(V+v)),y=a(N+a(I*a(M*v)));if(L!==y)throw new Error("bad point: equation left != right (1)");let b=a(x*C),m=a(R*K);if(b!==m)throw new Error("bad point: equation left != right (2)");return!0});class h{static BASE=new h(s.Gx,s.Gy,fe,a(s.Gx*s.Gy));static ZERO=new h(lt,fe,fe,lt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(g,I,x,C){this.X=f("x",g),this.Y=f("y",I),this.Z=f("z",x,!0),this.T=f("t",C),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){if(g instanceof h)throw new Error("extended point not allowed");let{x:I,y:x}=g||{};return f("x",I),f("y",x),new h(I,x,fe,a(I*x))}static fromBytes(g,I=!1){let x=n.BYTES,{a:C,d:R}=s;g=un(k(g,x,"point")),et(I,"zip215");let K=un(g),M=g[x-1];K[x-1]=M&-129;let v=wt(K),w=I?c:n.ORDER;Ar("point.y",v,lt,w);let N=a(v*v),V=a(N-fe),L=a(R*N-C),{isValid:y,value:b}=u(V,L);if(!y)throw new Error("bad point: invalid y coordinate");let m=(b&fe)===fe,A=(M&128)!==0;if(!I&&b===lt&&A)throw new Error("bad point: x=0 and x_0=1");return A!==m&&(b=a(-b)),h.fromAffine({x:b,y:v})}static fromHex(g,I=!1){return h.fromBytes(Qe(g),I)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,I=!0){return E.createCache(this,g),I||this.multiply(Ho),this}assertValidity(){p(this)}equals(g){l(g);let{X:I,Y:x,Z:C}=this,{X:R,Y:K,Z:M}=g,v=a(I*M),w=a(R*C),N=a(x*M),V=a(K*C);return v===w&&N===V}is0(){return this.equals(h.ZERO)}negate(){return new h(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:g}=s,{X:I,Y:x,Z:C}=this,R=a(I*I),K=a(x*x),M=a(Ho*a(C*C)),v=a(g*R),w=I+x,N=a(a(w*w)-R-K),V=v+K,L=V-M,y=v-K,b=a(N*L),m=a(V*y),A=a(N*y),_=a(L*V);return new h(b,m,_,A)}add(g){l(g);let{a:I,d:x}=s,{X:C,Y:R,Z:K,T:M}=this,{X:v,Y:w,Z:N,T:V}=g,L=a(C*v),y=a(R*w),b=a(M*x*V),m=a(K*N),A=a((C+R)*(v+w)-L-y),_=m-b,T=m+b,B=a(y-I*L),D=a(A*_),O=a(T*B),U=a(A*B),ee=a(_*T);return new h(D,O,ee,U)}subtract(g){return this.add(g.negate())}multiply(g){if(!o.isValidNot0(g))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:I,f:x}=E.cached(this,g,C=>St(h,C));return St(h,[I,x])[0]}multiplyUnsafe(g,I=h.ZERO){if(!o.isValid(g))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return g===lt?h.ZERO:this.is0()||g===fe?this:E.unsafe(this,g,x=>St(h,x),I)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(g){return d(this,g)}clearCofactor(){return i===fe?this:this.multiplyUnsafe(i)}toBytes(){let{x:g,y:I}=this.toAffine(),x=n.toBytes(I);return x[x.length-1]|=g&fe?128:0,x}toHex(){return Xe(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let E=new Zt(h,o.BITS);return h.BASE.precompute(8),h}function Ca(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');ft(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=t,c=r.randomBytes||Ft,a=r.adjustScalarBytes||(v=>v),u=r.domain||((v,w,N)=>{if(et(N,"phflag"),w.length||N)throw new Error("Contexts/pre-hash are not supported");return v});function f(v){return i.create(wt(v))}function l(v){let w=x.secretKey;k(v,x.secretKey,"secretKey");let N=k(e(v),2*w,"hashedSecretKey"),V=a(N.slice(0,w)),L=N.slice(w,2*w),y=f(V);return{head:V,prefix:L,scalar:y}}function d(v){let{head:w,prefix:N,scalar:V}=l(v),L=o.multiply(V),y=L.toBytes();return{head:w,prefix:N,scalar:V,point:L,pointBytes:y}}function p(v){return d(v).pointBytes}function h(v=Uint8Array.of(),...w){let N=Ae(...w);return f(e(u(N,k(v,void 0,"context"),!!n)))}function E(v,w,N={}){v=k(v,void 0,"message"),n&&(v=n(v));let{prefix:V,scalar:L,pointBytes:y}=d(w),b=h(N.context,V,v),m=o.multiply(b).toBytes(),A=h(N.context,m,y,v),_=i.create(b+A*L);if(!i.isValid(_))throw new Error("sign failed: invalid s");let T=Ae(m,i.toBytes(_));return k(T,x.signature,"result")}let S={zip215:!0};function g(v,w,N,V=S){let{context:L,zip215:y}=V,b=x.signature;v=k(v,b,"signature"),w=k(w,void 0,"message"),N=k(N,x.publicKey,"publicKey"),y!==void 0&&et(y,"zip215"),n&&(w=n(w));let m=b/2,A=v.subarray(0,m),_=wt(v.subarray(m,b)),T,B,D;try{T=t.fromBytes(N,y),B=t.fromBytes(A,y),D=o.multiplyUnsafe(_)}catch{return!1}if(!y&&T.isSmallOrder())return!1;let O=h(L,B.toBytes(),T.toBytes(),w);return B.add(T.multiplyUnsafe(O)).subtract(D).clearCofactor().is0()}let I=s.BYTES,x={secretKey:I,publicKey:I,signature:2*I,seed:I};function C(v=c(x.seed)){return k(v,x.seed,"seed")}function R(v){return bt(v)&&v.length===i.BYTES}function K(v,w){try{return!!t.fromBytes(v,w)}catch{return!1}}let M={getExtendedPublicKey:d,randomSecretKey:C,isValidSecretKey:R,isValidPublicKey:K,toMontgomery(v){let{y:w}=t.fromBytes(v),N=x.publicKey,V=N===32;if(!V&&N!==57)throw new Error("only defined for 25519 and 448");let L=V?s.div(fe+w,fe-w):s.div(w-fe,w+fe);return s.toBytes(L)},toMontgomerySecret(v){let w=x.secretKey;k(v,w);let N=e(v.subarray(0,w));return a(N).subarray(0,w)}};return Object.freeze({keygen:ln(C,p),getPublicKey:p,sign:E,verify:g,utils:M,Point:t,lengths:x})}var Wf=BigInt(1),_a=BigInt(2);var jf=BigInt(5),Xf=BigInt(8),$o=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Qf={p:$o,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Xf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Jf(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=$o,c=t*t%s*t%s,a=X(c,_a,s)*c%s,u=X(a,Wf,s)*t%s,f=X(u,jf,s)*u%s,l=X(f,e,s)*f%s,d=X(l,r,s)*l%s,p=X(d,n,s)*d%s,h=X(p,o,s)*p%s,E=X(h,o,s)*p%s,S=X(E,e,s)*f%s;return{pow_p_5_8:X(S,_a,s)*t%s,b2:c}}function el(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Da=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function tl(t,e){let r=$o,n=se(e*e*e,r),o=se(n*n*e,r),s=Jf(t*o).pow_p_5_8,i=se(t*n*s,r),c=se(e*i*i,r),a=i,u=se(i*Da,r),f=c===t,l=c===se(-t,r),d=c===se(-t*Da,r);return f&&(i=a),(l||d)&&(i=u),ba(i,r)&&(i=se(-i,r)),{isValid:f||l,value:i}}var rl=Ia(Qf,{uvRatio:tl});function nl(t){return Ca(rl,oa,Object.assign({adjustScalarBytes:el},t))}var Ta=nl({});var Dr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},dn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var La={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new dn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var De=La;var hn=32;var zo,ol=(async()=>{try{return await De.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function sl(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await De.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await De.get().subtle.verify({name:"Ed25519"},n,e,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function il(t,e,r){return Ta.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Ba(t,e,r){return zo==null&&(zo=await ol),zo?sl(t,e,r):il(t,e,r)}function pn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var mn=class{type="Ed25519";raw;constructor(e){this.raw=Yo(e,hn)}toMultihash(){return Le.digest(Ve(this))}toCID(){return ae.createV1(114,this.toMultihash())}toString(){return oe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ce(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=Ba(this.raw,r,e);return pn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Zo(t){return t=Yo(t,hn),new mn(t)}function Yo(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new Q(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var cl=Math.pow(2,7),ul=Math.pow(2,14),fl=Math.pow(2,21),Go=Math.pow(2,28),Wo=Math.pow(2,35),jo=Math.pow(2,42),Xo=Math.pow(2,49),Y=128,be=127;function Ie(t){if(t<cl)return 1;if(t<ul)return 2;if(t<fl)return 3;if(t<Go)return 4;if(t<Wo)return 5;if(t<jo)return 6;if(t<Xo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Gt(t,e,r=0){switch(Ie(t)){case 8:e[r++]=t&255|Y,t/=128;case 7:e[r++]=t&255|Y,t/=128;case 6:e[r++]=t&255|Y,t/=128;case 5:e[r++]=t&255|Y,t/=128;case 4:e[r++]=t&255|Y,t>>>=7;case 3:e[r++]=t&255|Y,t>>>=7;case 2:e[r++]=t&255|Y,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function ll(t,e,r=0){switch(Ie(t)){case 8:e.set(r++,t&255|Y),t/=128;case 7:e.set(r++,t&255|Y),t/=128;case 6:e.set(r++,t&255|Y),t/=128;case 5:e.set(r++,t&255|Y),t/=128;case 4:e.set(r++,t&255|Y),t>>>=7;case 3:e.set(r++,t&255|Y),t>>>=7;case 2:e.set(r++,t&255|Y),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function Qo(t,e){let r=t[e],n=0;if(n+=r&be,r<Y||(r=t[e+1],n+=(r&be)<<7,r<Y)||(r=t[e+2],n+=(r&be)<<14,r<Y)||(r=t[e+3],n+=(r&be)<<21,r<Y)||(r=t[e+4],n+=(r&be)*Go,r<Y)||(r=t[e+5],n+=(r&be)*Wo,r<Y)||(r=t[e+6],n+=(r&be)*jo,r<Y)||(r=t[e+7],n+=(r&be)*Xo,r<Y))return n;throw new RangeError("Could not decode varint")}function dl(t,e){let r=t.get(e),n=0;if(n+=r&be,r<Y||(r=t.get(e+1),n+=(r&be)<<7,r<Y)||(r=t.get(e+2),n+=(r&be)<<14,r<Y)||(r=t.get(e+3),n+=(r&be)<<21,r<Y)||(r=t.get(e+4),n+=(r&be)*Go,r<Y)||(r=t.get(e+5),n+=(r&be)*Wo,r<Y)||(r=t.get(e+6),n+=(r&be)*jo,r<Y)||(r=t.get(e+7),n+=(r&be)*Xo,r<Y))return n;throw new RangeError("Could not decode varint")}function Wt(t,e,r=0){return e==null&&(e=ve(Ie(t))),e instanceof Uint8Array?Gt(t,e,r):ll(t,e,r)}function Tr(t,e=0){return t instanceof Uint8Array?Qo(t,e):dl(t,e)}var es=new Float32Array([-0]),dt=new Uint8Array(es.buffer);function Oa(t,e,r){es[0]=t,e[r]=dt[0],e[r+1]=dt[1],e[r+2]=dt[2],e[r+3]=dt[3]}function Ra(t,e){return dt[0]=t[e],dt[1]=t[e+1],dt[2]=t[e+2],dt[3]=t[e+3],es[0]}var ts=new Float64Array([-0]),ge=new Uint8Array(ts.buffer);function Na(t,e,r){ts[0]=t,e[r]=ge[0],e[r+1]=ge[1],e[r+2]=ge[2],e[r+3]=ge[3],e[r+4]=ge[4],e[r+5]=ge[5],e[r+6]=ge[6],e[r+7]=ge[7]}function Ua(t,e){return ge[0]=t[e],ge[1]=t[e+1],ge[2]=t[e+2],ge[3]=t[e+3],ge[4]=t[e+4],ge[5]=t[e+5],ge[6]=t[e+6],ge[7]=t[e+7],ts[0]}var hl=BigInt(Number.MAX_SAFE_INTEGER),pl=BigInt(Number.MIN_SAFE_INTEGER),_e=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return At;if(e<hl&&e>pl)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>ka&&(o=0n,++n>ka&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return At;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):At}},At=new _e(0,0);At.toBigInt=function(){return 0n};At.zzEncode=At.zzDecode=function(){return this};At.length=function(){return 1};var ka=4294967296n;function Ka(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Ma(t,e,r){if(r-e<1)return"";let o,s=[],i=0,c;for(;e<r;)c=t[e++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|t[e++]&63:c>239&&c<365?(c=((c&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function rs(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Pe(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function yn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var ns=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Pe(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Pe(this,4);return yn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pe(this,4);return yn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pe(this,4);let e=Ra(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Pe(this,4);let e=Ua(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Pe(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Ma(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Pe(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Pe(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new _e(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Pe(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Pe(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Pe(this,8);let e=yn(this.buf,this.pos+=4),r=yn(this.buf,this.pos+=4);return new _e(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Qo(this.buf,this.pos);return this.pos+=Ie(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Lr(t){return new ns(t instanceof Uint8Array?t:t.subarray())}function Oe(t,e,r){let n=Lr(t);return e.decode(n,void 0,r)}function os(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return ve(i);o+i>e&&(n=ve(e),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var It=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function ss(){}var as=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},ml=os();function yl(t){return globalThis.Buffer!=null?ve(t):ml(t)}var Pr=class{len;head;tail;states;constructor(){this.len=0,this.head=new It(ss,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new It(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new cs((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(bn,10,_e.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=_e.fromBigInt(e);return this._push(bn,r.length(),r)}uint64Number(e){return this._push(Gt,Ie(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=_e.fromBigInt(e).zzEncode();return this._push(bn,r.length(),r)}sint64Number(e){let r=_e.fromNumber(e).zzEncode();return this._push(bn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(is,1,e?1:0)}fixed32(e){return this._push(Br,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=_e.fromBigInt(e);return this._push(Br,4,r.lo)._push(Br,4,r.hi)}fixed64Number(e){let r=_e.fromNumber(e);return this._push(Br,4,r.lo)._push(Br,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Oa,4,e)}double(e){return this._push(Na,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(is,1,0):this.uint32(r)._push(gl,r,e)}string(e){let r=Ka(e);return r!==0?this.uint32(r)._push(rs,r,e):this._push(is,1,0)}fork(){return this.states=new as(this),this.head=this.tail=new It(ss,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new It(ss,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=yl(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function is(t,e,r){e[r]=t&255}function bl(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var cs=class extends It{next;constructor(e,r){super(bl,e,r),this.next=void 0}};function bn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Br(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function gl(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Pr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(xl,e,t),this},Pr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(wl,e,t),this});function xl(t,e,r){e.set(t,r)}function wl(t,e,r){t.length<40?rs(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(F(t),r)}function us(){return new Pr}function Re(t,e){let r=us();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Ne(t,e,r){let n=Lr(t);yield*e.stream(n,void 0,"$",r)}var gn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function xn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function fs(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,c){let a=e(i);c.int32(a)},n=function(i){let c=i.int32();return e(c)},o=function*(i){let c=i.int32();yield e(c)};return xn("enum",gn.VARINT,r,n,o)}function Ue(t,e,r){return xn("message",gn.LENGTH_DELIMITED,t,e,r)}var He=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var J;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(J||(J={}));var ls;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(ls||(ls={}));(function(t){t.codec=()=>fs(ls)})(J||(J={}));var $e;(function(t){let e;t.codec=()=>(e==null&&(e=Ue((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),J.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.Type=J.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return a},function*(s,i,c,a={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${c}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return Re(s,t.codec())}t.encode=r;function n(s,i){return Oe(s,t.codec(),i)}t.decode=n;function o(s,i){return Ne(s,t.codec(),i)}t.stream=o})($e||($e={}));var ds;(function(t){let e;t.codec=()=>(e==null&&(e=Ue((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),J.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.Type=J.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return a},function*(s,i,c,a={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${c}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return Re(s,t.codec())}t.encode=r;function n(s,i){return Oe(s,t.codec(),i)}t.decode=n;function o(s,i){return Ne(s,t.codec(),i)}t.stream=o})(ds||(ds={}));var Rr={};Ee(Rr,{MAX_RSA_KEY_SIZE:()=>hs,generateRSAKeyPair:()=>za,jwkToJWKKeyPair:()=>Ya,jwkToPkcs1:()=>Al,jwkToPkix:()=>bs,jwkToRSAPrivateKey:()=>Es,pkcs1MessageToJwk:()=>ms,pkcs1MessageToRSAPrivateKey:()=>gs,pkcs1ToJwk:()=>Sl,pkcs1ToRSAPrivateKey:()=>$a,pkixMessageToJwk:()=>ys,pkixMessageToRSAPublicKey:()=>ws,pkixToJwk:()=>Il,pkixToRSAPublicKey:()=>xs});var jt=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ae.createV1(114,this._multihash)}toString(){return oe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ce(this.raw,e.raw)}verify(e,r,n){return Ha(this.jwk,r,e,n)}},Or=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ce(this.raw,e.raw)}sign(e,r){return qa(this.jwk,e,r)}};var hs=8192,ps=18,El=1062,vl=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Sl(t){let e=Ge(t);return ms(e)}function ms(t){return{n:H(t[1],"base64url"),e:H(t[2],"base64url"),d:H(t[3],"base64url"),p:H(t[4],"base64url"),q:H(t[5],"base64url"),dp:H(t[6],"base64url"),dq:H(t[7],"base64url"),qi:H(t[8],"base64url"),kty:"RSA"}}function Al(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new Q("JWK was missing components");return it([Se(Uint8Array.from([0])),Se(F(t.n,"base64url")),Se(F(t.e,"base64url")),Se(F(t.d,"base64url")),Se(F(t.p,"base64url")),Se(F(t.q,"base64url")),Se(F(t.dp,"base64url")),Se(F(t.dq,"base64url")),Se(F(t.qi,"base64url"))]).subarray()}function Il(t){let e=Ge(t,{offset:0});return ys(e)}function ys(t){let e=Ge(t[1],{offset:0});return{kty:"RSA",n:H(e[0],"base64url"),e:H(e[1],"base64url")}}function bs(t){if(t.n==null||t.e==null)throw new Q("JWK was missing components");return it([vl,rn(it([Se(F(t.n,"base64url")),Se(F(t.e,"base64url"))]))]).subarray()}function $a(t){let e=Ge(t);return gs(e)}function gs(t){let e=ms(t);return Es(e)}function xs(t,e){if(t.byteLength>=El)throw new Rt("Key size is too large");let r=Ge(t,{offset:0});return ws(r,t,e)}function ws(t,e,r){let n=ys(t);if(r==null){let o=qt($e.encode({Type:J.RSA,Data:e}));r=Me(ps,o)}return new jt(n,r)}function Es(t){if(Ga(t)>hs)throw new Q("Key size is too large");let e=Ya(t),r=qt($e.encode({Type:J.RSA,Data:bs(e.publicKey)})),n=Me(ps,r);return new Or(e.privateKey,new jt(e.publicKey,n))}async function za(t){if(t>hs)throw new Q("Key size is too large");let e=await Za(t),r=qt($e.encode({Type:J.RSA,Data:bs(e.publicKey)})),n=Me(ps,r);return new Or(e.privateKey,new jt(e.publicKey,n))}function Ya(t){if(t==null)throw new Q("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Za(t,e){let r=await De.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await Cl(r,e);return{privateKey:n[0],publicKey:n[1]}}async function qa(t,e,r){let n=await De.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await De.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,e instanceof Uint8Array?e:e.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ha(t,e,r,n){let o=await De.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await De.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Cl(t,e){if(t.privateKey==null||t.publicKey==null)throw new Q("Private and public key are required");let r=await Promise.all([De.get().subtle.exportKey("jwk",t.privateKey),De.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Ga(t){if(t.kty!=="RSA")throw new Q("invalid key type");if(t.n==null)throw new Q("invalid key modulus");return F(t.n,"base64url").length*8}var wn=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,r){if(nn(e),k(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),je(o)}update(e){return Vt(this),this.iHash.update(e),this}digestInto(e){Vt(this),k(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},vs=(t,e,r)=>new wn(t,e).update(r).digest();vs.create=(t,e)=>new wn(t,e);var Wa=(t,e)=>(t+(t>=0?e:-e)/ja)/e;function _l(t,e,r){let[[n,o],[s,i]]=e,c=Wa(i*t,r),a=Wa(-o*t,r),u=t-c*n-a*s,f=-c*o-a*i,l=u<tt,d=f<tt;l&&(u=-u),d&&(f=-f);let p=Ir(Math.ceil(Ro(r)/2))+Xt;if(u<tt||u>=p||f<tt||f>=p)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:l,k1:u,k2neg:d,k2:f}}function As(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Ss(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return et(r.lowS,"lowS"),et(r.prehash,"prehash"),r.format!==void 0&&As(r.format),r}var Is=class extends Error{constructor(e=""){super(e)}},ht={Err:Is,_tlv:{encode:(t,e)=>{let{Err:r}=ht;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Sr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Sr(o.length/2|128):"";return Sr(t)+s+o+e},decode(t,e){let{Err:r}=ht,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=e.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=ht;if(t<tt)throw new e("integer: negative integers are not allowed");let r=Sr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=ht;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Ht(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=ht,o=k(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l:f}=n.decode(2,a);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=ht,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}},tt=BigInt(0),Xt=BigInt(1),ja=BigInt(2),En=BigInt(3),Dl=BigInt(4);function Xa(t,e={}){let r=fn("weierstrass",t,e),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;ft(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=e;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Ja(n,o);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(L,y,b){let{x:m,y:A}=y.toAffine(),_=n.toBytes(m);if(et(b,"isCompressed"),b){f();let T=!n.isOdd(A);return Ae(Qa(T),_)}else return Ae(Uint8Array.of(4),_,n.toBytes(A))}function d(L){k(L,void 0,"Point");let{publicKey:y,publicKeyUncompressed:b}=u,m=L.length,A=L[0],_=L.subarray(1);if(m===y&&(A===2||A===3)){let T=n.fromBytes(_);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let B=E(T),D;try{D=n.sqrt(B)}catch(ee){let j=ee instanceof Error?": "+ee.message:"";throw new Error("bad point: is not on curve, sqrt error"+j)}f();let O=n.isOdd(D);return(A&1)===1!==O&&(D=n.neg(D)),{x:T,y:D}}else if(m===b&&A===4){let T=n.BYTES,B=n.fromBytes(_.subarray(0,T)),D=n.fromBytes(_.subarray(T,T*2));if(!S(B,D))throw new Error("bad point: is not on curve");return{x:B,y:D}}else throw new Error(`bad point: got length ${m}, expected compressed=${y} or uncompressed=${b}`)}let p=e.toBytes||l,h=e.fromBytes||d;function E(L){let y=n.sqr(L),b=n.mul(y,L);return n.add(n.add(b,n.mul(L,s.a)),s.b)}function S(L,y){let b=n.sqr(y),m=E(L);return n.eql(b,m)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let g=n.mul(n.pow(s.a,En),Dl),I=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(g,I)))throw new Error("bad curve params: a or b");function x(L,y,b=!1){if(!n.isValid(y)||b&&n.is0(y))throw new Error(`bad point coordinate ${L}`);return y}function C(L){if(!(L instanceof w))throw new Error("Weierstrass Point expected")}function R(L){if(!a||!a.basises)throw new Error("no endo");return _l(L,a.basises,o.ORDER)}let K=$t((L,y)=>{let{X:b,Y:m,Z:A}=L;if(n.eql(A,n.ONE))return{x:b,y:m};let _=L.is0();y==null&&(y=_?n.ONE:n.inv(A));let T=n.mul(b,y),B=n.mul(m,y),D=n.mul(A,y);if(_)return{x:n.ZERO,y:n.ZERO};if(!n.eql(D,n.ONE))throw new Error("invZ was invalid");return{x:T,y:B}}),M=$t(L=>{if(L.is0()){if(e.allowInfinityPoint&&!n.is0(L.Y))return;throw new Error("bad point: ZERO")}let{x:y,y:b}=L.toAffine();if(!n.isValid(y)||!n.isValid(b))throw new Error("bad point: x or y not field elements");if(!S(y,b))throw new Error("bad point: equation left != right");if(!L.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function v(L,y,b,m,A){return b=new w(n.mul(b.X,L),b.Y,b.Z),y=_r(m,y),b=_r(A,b),y.add(b)}class w{static BASE=new w(s.Gx,s.Gy,n.ONE);static ZERO=new w(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(y,b,m){this.X=x("x",y),this.Y=x("y",b,!0),this.Z=x("z",m),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){let{x:b,y:m}=y||{};if(!y||!n.isValid(b)||!n.isValid(m))throw new Error("invalid affine point");if(y instanceof w)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(m)?w.ZERO:new w(b,m,n.ONE)}static fromBytes(y){let b=w.fromAffine(h(k(y,void 0,"point")));return b.assertValidity(),b}static fromHex(y){return w.fromBytes(Qe(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,b=!0){return V.createCache(this,y),b||this.multiply(En),this}assertValidity(){M(this)}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){C(y);let{X:b,Y:m,Z:A}=this,{X:_,Y:T,Z:B}=y,D=n.eql(n.mul(b,B),n.mul(_,A)),O=n.eql(n.mul(m,B),n.mul(T,A));return D&&O}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:y,b}=s,m=n.mul(b,En),{X:A,Y:_,Z:T}=this,B=n.ZERO,D=n.ZERO,O=n.ZERO,U=n.mul(A,A),ee=n.mul(_,_),j=n.mul(T,T),z=n.mul(A,_);return z=n.add(z,z),O=n.mul(A,T),O=n.add(O,O),B=n.mul(y,O),D=n.mul(m,j),D=n.add(B,D),B=n.sub(ee,D),D=n.add(ee,D),D=n.mul(B,D),B=n.mul(z,B),O=n.mul(m,O),j=n.mul(y,j),z=n.sub(U,j),z=n.mul(y,z),z=n.add(z,O),O=n.add(U,U),U=n.add(O,U),U=n.add(U,j),U=n.mul(U,z),D=n.add(D,U),j=n.mul(_,T),j=n.add(j,j),U=n.mul(j,z),B=n.sub(B,U),O=n.mul(j,ee),O=n.add(O,O),O=n.add(O,O),new w(B,D,O)}add(y){C(y);let{X:b,Y:m,Z:A}=this,{X:_,Y:T,Z:B}=y,D=n.ZERO,O=n.ZERO,U=n.ZERO,ee=s.a,j=n.mul(s.b,En),z=n.mul(b,_),te=n.mul(m,T),de=n.mul(A,B),Ke=n.add(b,m),re=n.add(_,T);Ke=n.mul(Ke,re),re=n.add(z,te),Ke=n.sub(Ke,re),re=n.add(b,A);let ye=n.add(_,B);return re=n.mul(re,ye),ye=n.add(z,de),re=n.sub(re,ye),ye=n.add(m,A),D=n.add(T,B),ye=n.mul(ye,D),D=n.add(te,de),ye=n.sub(ye,D),U=n.mul(ee,re),D=n.mul(j,de),U=n.add(D,U),D=n.sub(te,U),U=n.add(te,U),O=n.mul(D,U),te=n.add(z,z),te=n.add(te,z),de=n.mul(ee,de),re=n.mul(j,re),te=n.add(te,de),de=n.sub(z,de),de=n.mul(ee,de),re=n.add(re,de),z=n.mul(te,re),O=n.add(O,z),z=n.mul(ye,re),D=n.mul(Ke,D),D=n.sub(D,z),z=n.mul(Ke,te),U=n.mul(ye,U),U=n.add(U,z),new w(D,O,U)}subtract(y){return this.add(y.negate())}is0(){return this.equals(w.ZERO)}multiply(y){let{endo:b}=e;if(!o.isValidNot0(y))throw new Error("invalid scalar: out of range");let m,A,_=T=>V.cached(this,T,B=>St(w,B));if(b){let{k1neg:T,k1:B,k2neg:D,k2:O}=R(y),{p:U,f:ee}=_(B),{p:j,f:z}=_(O);A=ee.add(z),m=v(b.beta,U,j,T,D)}else{let{p:T,f:B}=_(y);m=T,A=B}return St(w,[m,A])[0]}multiplyUnsafe(y){let{endo:b}=e,m=this;if(!o.isValid(y))throw new Error("invalid scalar: out of range");if(y===tt||m.is0())return w.ZERO;if(y===Xt)return m;if(V.hasCache(this))return this.multiply(y);if(b){let{k1neg:A,k1:_,k2neg:T,k2:B}=R(y),{p1:D,p2:O}=Aa(w,m,_,B);return v(b.beta,D,O,A,T)}else return V.unsafe(m,y)}toAffine(y){return K(this,y)}isTorsionFree(){let{isTorsionFree:y}=e;return i===Xt?!0:y?y(w,this):V.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:y}=e;return i===Xt?this:y?y(w,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(y=!0){return et(y,"isCompressed"),this.assertValidity(),p(w,this,y)}toHex(y=!0){return Xe(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=o.BITS,V=new Zt(w,e.endo?Math.ceil(N/2):N);return w.BASE.precompute(8),w}function Qa(t){return Uint8Array.of(t?2:3)}function Ja(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Tl(t,e={}){let{Fn:r}=t,n=e.randomBytes||Ft,o=Object.assign(Ja(t.Fp,r),{seed:Ko(r.ORDER)});function s(p){try{let h=r.fromBytes(p);return r.isValidNot0(h)}catch{return!1}}function i(p,h){let{publicKey:E,publicKeyUncompressed:S}=o;try{let g=p.length;return h===!0&&g!==E||h===!1&&g!==S?!1:!!t.fromBytes(p)}catch{return!1}}function c(p=n(o.seed)){return Mo(k(p,o.seed,"seed"),r.ORDER)}function a(p,h=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(h)}function u(p){let{secretKey:h,publicKey:E,publicKeyUncompressed:S}=o;if(!bt(p)||"_lengths"in r&&r._lengths||h===E)return;let g=k(p,void 0,"key").length;return g===E||g===S}function f(p,h,E=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(h)===!1)throw new Error("second arg must be public key");let S=r.fromBytes(p);return t.fromBytes(h).multiply(S).toBytes(E)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c},d=ln(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:f,keygen:d,Point:t,utils:l,lengths:o})}function ec(t,e,r={}){nn(e),ft(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||Ft,o=r.hmac||((b,m)=>vs(e,b,m)),{Fp:s,Fn:i}=t,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:f,getSharedSecret:l,utils:d,lengths:p}=Tl(t,r),h={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},E=c*ja<s.ORDER;function S(b){let m=c>>Xt;return b>m}function g(b,m){if(!i.isValidNot0(m))throw new Error(`invalid signature ${b}: out of range 1..Point.Fn.ORDER`);return m}function I(){if(E)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function x(b,m){As(m);let A=p.signature,_=m==="compact"?A:m==="recovered"?A+1:void 0;return k(b,_)}class C{r;s;recovery;constructor(m,A,_){if(this.r=g("r",m),this.s=g("s",A),_!=null){if(I(),![0,1,2,3].includes(_))throw new Error("invalid recovery id");this.recovery=_}Object.freeze(this)}static fromBytes(m,A=h.format){x(m,A);let _;if(A==="der"){let{r:O,s:U}=ht.toSig(k(m));return new C(O,U)}A==="recovered"&&(_=m[0],A="compact",m=m.subarray(1));let T=p.signature/2,B=m.subarray(0,T),D=m.subarray(T,T*2);return new C(i.fromBytes(B),i.fromBytes(D),_)}static fromHex(m,A){return this.fromBytes(Qe(m),A)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new C(this.r,this.s,m)}recoverPublicKey(m){let{r:A,s:_}=this,T=this.assertRecovery(),B=T===2||T===3?A+c:A;if(!s.isValid(B))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let D=s.toBytes(B),O=t.fromBytes(Ae(Qa((T&1)===0),D)),U=i.inv(B),ee=K(k(m,void 0,"msgHash")),j=i.create(-ee*U),z=i.create(_*U),te=t.BASE.multiplyUnsafe(j).add(O.multiplyUnsafe(z));if(te.is0())throw new Error("invalid recovery: point at infinify");return te.assertValidity(),te}hasHighS(){return S(this.s)}toBytes(m=h.format){if(As(m),m==="der")return Qe(ht.hexFromSig(this));let{r:A,s:_}=this,T=i.toBytes(A),B=i.toBytes(_);return m==="recovered"?(I(),Ae(Uint8Array.of(this.assertRecovery()),T,B)):Ae(T,B)}toHex(m){return Xe(this.toBytes(m))}}let R=r.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let A=Ht(m),_=m.length*8-a;return _>0?A>>BigInt(_):A},K=r.bits2int_modN||function(m){return i.create(R(m))},M=Ir(a);function v(b){return Ar("num < 2^"+a,b,tt,M),i.toBytes(b)}function w(b,m){return k(b,void 0,"message"),m?k(e(b),void 0,"prehashed message"):b}function N(b,m,A){let{lowS:_,prehash:T,extraEntropy:B}=Ss(A,h);b=w(b,T);let D=K(b),O=i.fromBytes(m);if(!i.isValidNot0(O))throw new Error("invalid private key");let U=[v(O),v(D)];if(B!=null&&B!==!1){let te=B===!0?n(p.secretKey):B;U.push(k(te,void 0,"extraEntropy"))}let ee=Ae(...U),j=D;function z(te){let de=R(te);if(!i.isValidNot0(de))return;let Ke=i.inv(de),re=t.BASE.multiply(de).toAffine(),ye=i.create(re.x);if(ye===tt)return;let Gr=i.create(Ke*i.create(j+ye*O));if(Gr===tt)return;let pi=(re.x===ye?0:2)|Number(re.y&Xt),mi=Gr;return _&&S(Gr)&&(mi=i.neg(Gr),pi^=1),new C(ye,mi,E?void 0:pi)}return{seed:ee,k2sig:z}}function V(b,m,A={}){let{seed:_,k2sig:T}=N(b,m,A);return aa(e.outputLen,i.BYTES,o)(_,T).toBytes(A.format)}function L(b,m,A,_={}){let{lowS:T,prehash:B,format:D}=Ss(_,h);if(A=k(A,void 0,"publicKey"),m=w(m,B),!bt(b)){let O=b instanceof C?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+O)}x(b,D);try{let O=C.fromBytes(b,D),U=t.fromBytes(A);if(T&&O.hasHighS())return!1;let{r:ee,s:j}=O,z=K(m),te=i.inv(j),de=i.create(z*te),Ke=i.create(ee*te),re=t.BASE.multiplyUnsafe(de).add(U.multiplyUnsafe(Ke));return re.is0()?!1:i.create(re.x)===ee}catch{return!1}}function y(b,m,A={}){let{prehash:_}=Ss(A,h);return m=w(m,_),C.fromBytes(b,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:l,utils:d,lengths:p,Point:t,sign:V,verify:L,recoverPublicKey:y,Signature:C,hash:e})}var _s={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ll={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var tc=BigInt(2);function Bl(t){let e=_s.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=X(f,r,e)*f%e,d=X(l,r,e)*f%e,p=X(d,tc,e)*u%e,h=X(p,o,e)*p%e,E=X(h,s,e)*h%e,S=X(E,c,e)*E%e,g=X(S,a,e)*S%e,I=X(g,c,e)*E%e,x=X(I,r,e)*f%e,C=X(x,i,e)*h%e,R=X(C,n,e)*u%e,K=X(R,tc,e);if(!Cs.eql(Cs.sqr(K),t))throw new Error("Cannot find square root");return K}var Cs=zt(_s.p,{sqrt:Bl}),Pl=Xa(_s,{Fp:Cs,endo:Ll}),Qt=ec(Pl,qt);function rc(t,e,r,n){let o=yr.digest(r instanceof Uint8Array?r:r.subarray());if(pn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Qt.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Dr(String(s))});try{return n?.signal?.throwIfAborted(),Qt.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new Dr(String(s))}}var vn=class{type="secp256k1";raw;_key;constructor(e){this._key=oc(e),this.raw=nc(this._key)}toMultihash(){return Le.digest(Ve(this))}toCID(){return ae.createV1(114,this.toMultihash())}toString(){return oe.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ce(this.raw,e.raw)}verify(e,r,n){return rc(this._key,r,e,n)}};function Ds(t){return new vn(t)}function nc(t){return Qt.Point.fromBytes(t).toBytes()}function oc(t){try{return Qt.Point.fromBytes(t),t}catch(e){throw new Rt(String(e))}}function Jt(t,e){let{Type:r,Data:n}=$e.decode(t),o=n??new Uint8Array;switch(r){case J.RSA:return xs(o,e);case J.Ed25519:return Zo(o);case J.secp256k1:return Ds(o);case J.ECDSA:return vo(o);default:throw new mt}}function sc(t){let{Type:e,Data:r}=$e.decode(t.digest),n=r??new Uint8Array;switch(e){case J.Ed25519:return Zo(n);case J.secp256k1:return Ds(n);case J.ECDSA:return vo(n);default:throw new mt}}function Ve(t){return $e.encode({Type:J[t.type],Data:t.raw})}var Nr;(function(t){let e;t.codec=()=>(e==null&&(e=Ue((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={publicKey:he(0),payloadType:he(0),payload:he(0),signature:he(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.publicKey=s.bytes();break}case 2:{a.payloadType=s.bytes();break}case 3:{a.payload=s.bytes();break}case 5:{a.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return a},function*(s,i,c,a={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${c}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${c}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${c}.payload`,value:s.bytes()};break}case 5:{yield{field:`${c}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return Re(s,t.codec())}t.encode=r;function n(s,i){return Oe(s,t.codec(),i)}t.decode=n;function o(s,i){return Ne(s,t.codec(),i)}t.stream=o})(Nr||(Nr={}));var Sn=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var ze=class t{static createFromProtobuf=e=>{let r=Nr.decode(e),n=Jt(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),c=ic(o,s,i),a=await r.sign(c.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:a})};static openAndCertify=async(e,r,n)=>{let o=t.createFromProtobuf(e);if(!await o.validate(r,n))throw new Sn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:r,payloadType:n,payload:o,signature:s}=e;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Nr.encode({publicKey:Ve(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:ce(this.marshal(),e.marshal())}async validate(e,r){let n=ic(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},ic=(t,e,r)=>{let n=F(t),o=Wt(n.byteLength),s=Wt(e.length),i=Wt(r.length);return new ie(o,n,s,e,i,r)};var ac=Symbol.for("nodejs.util.inspect.custom"),Ol=114,Ur=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Zn]=!0;toString(){return this.string==null&&(this.string=oe.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ae.createV1(Ol,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ce(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return ce(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[ac](){return`PeerId(${this.toString()})`}},kr=class extends Ur{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Kr=class extends Ur{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Mr=class extends Ur{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Rl=2336,Vr=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Le.digest(F(this.url))}[ac](){return`PeerId(${this.url})`}[Zn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ae.createV1(Rl,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=H(e)),e.toString()===this.toString())}};var Nl=114,cc=2336;function uc(t){if(t.type==="Ed25519")return new Kr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Mr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new kr({multihash:t.toCID().multihash,publicKey:t});throw new mt}function Ts(t){if(kl(t))return new kr({multihash:t});if(Ul(t))try{let e=sc(t);if(e.type==="Ed25519")return new Kr({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Mr({multihash:t,publicKey:e})}catch{let r=H(t.digest);return new Vr(new URL(r))}throw new Xr("Supplied PeerID Multihash is invalid")}function An(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Nl&&t.code!==cc)throw new jr("Supplied PeerID CID is invalid");if(t.code===cc){let e=H(t.multihash.digest);return new Vr(new URL(e))}return Ts(t.multihash)}function Ul(t){return t.code===Le.code}function kl(t){return t.code===yr.code}var me=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},rt=class extends Error{static name="ValidationError";name="ValidationError"},In=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Cn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var _n=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="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,e);if(!Number.isNaN(d))return d});if(f===void 0)break;if(s*=e,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&a&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[c]=e(s.subarray(0,i));return r.set(s.subarray(0,c),16-c),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var fc=45,Kl=15,er=new _n;function Dn(t){if(!(t.length>Kl))return er.new(t).parseWith(()=>er.readIPv4Addr())}function Tn(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>fc))return er.new(t).parseWith(()=>er.readIPv6Addr())}function tr(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>fc)return;let r=er.new(t).parseWith(()=>er.readIPAddr());if(r)return e&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function rr(t){return!!Dn(t)}function Ln(t){return!!Tn(t)}function Bs(t){return e=>H(e,t)}function Ps(t){return e=>F(e,t)}function nr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Ct(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function lc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=F(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ct(n);return Ze([r,o],r.length+o.length)}function dc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=st.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ct(n);return Ze([r,o],r.length+o.length)}function Os(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=H(e,"base32"),o=nr(r);return`${n}:${o}`}var Rs=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new me("Invalid byte value in IP address");e[n]=o}),e},hc=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=rr(r[n]),i;s&&(i=Rs(r[n]),r[n]=H(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,H(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new me("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},pc=function(t){if(t.byteLength!==4)throw new me("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},mc=function(t){if(t.byteLength!==16)throw new me("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new me(`Invalid IPv6 address "${r}"`)}};function yc(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new me(`Invalid IPv6 address "${t}"`)}}var Ls=Object.values(br).map(t=>t.decoder),Ml=(function(){let t=Ls[0].or(Ls[1]);return Ls.slice(2).forEach(e=>t=t.or(e)),t})();function bc(t){return Ml.decode(t)}function gc(t){return e=>t.encoder.encode(e)}function Vl(t){if(parseInt(t).toString()!==t)throw new rt("Value must be an integer")}function Fl(t){if(t<0)throw new rt("Value must be a positive integer, or zero")}function ql(t){return e=>{if(e>t)throw new rt(`Value must be smaller than or equal to ${t}`)}}function Hl(...t){return e=>{for(let r of t)r(e)}}var Fr=Hl(Vl,Fl,ql(65535));var le=-1,Ns=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Cn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},nt=new Ns,od=[{code:4,name:"ip4",size:32,valueToBytes:Rs,bytesToValue:pc,validate:t=>{if(!rr(t))throw new rt(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ct,bytesToValue:nr,validate:Fr},{code:273,name:"udp",size:16,valueToBytes:Ct,bytesToValue:nr,validate:Fr},{code:33,name:"dccp",size:16,valueToBytes:Ct,bytesToValue:nr,validate:Fr},{code:41,name:"ip6",size:128,valueToBytes:hc,bytesToValue:mc,stringToValue:yc,validate:t=>{if(!Ln(t))throw new rt(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:le},{code:43,name:"ipcidr",size:8,bytesToValue:Bs("base10"),valueToBytes:Ps("base10")},{code:53,name:"dns",size:le},{code:54,name:"dns4",size:le},{code:55,name:"dns6",size:le},{code:56,name:"dnsaddr",size:le},{code:132,name:"sctp",size:16,valueToBytes:Ct,bytesToValue:nr,validate:Fr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:le,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:le,bytesToValue:Bs("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?Ps("base58btc")(t):ae.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Os,valueToBytes:lc},{code:445,name:"onion3",size:296,bytesToValue:Os,valueToBytes:dc},{code:446,name:"garlic64",size:le},{code:447,name:"garlic32",size:le},{code:448,name:"tls"},{code:449,name:"sni",size:le},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:le,bytesToValue:gc(co),valueToBytes:bc},{code:480,name:"http"},{code:481,name:"http-path",size:le,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:le}];od.forEach(t=>{nt.addProtocol(t)});function xc(t){let e=[],r=0;for(;r<t.length;){let n=Tr(t,r),o=nt.getProtocol(n),s=Ie(n),i=sd(o,t,r+s),c=0;i>0&&o.size===le&&(c=Ie(i));let a=s+c+i,u={code:n,name:o.name,bytes:t.subarray(r,r+a)};if(i>0){let f=r+s+c,l=t.subarray(f,f+i);u.value=o.bytesToValue?.(l)??H(l)}e.push(u),r+=a}return e}function wc(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=nt.getProtocol(n.code),s=Ie(n.code),i,c=0,a=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??F(n.value),c=i.byteLength,o.size===le&&(a=Ie(c)));let u=new Uint8Array(s+a+c),f=0;Gt(n.code,u,f),f+=s,i!=null&&(o.size===le&&(Gt(c,u,f),f+=a),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Ze(r,e)}function Ec(t){if(t.charAt(0)!=="/")throw new me('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let c=s===t.length-1;if(i==="/"||c){let a=nt.getProtocol(o);if(r==="protocol"){if(a.size==null||a.size===0){e.push({code:a.code,name:a.name}),n="",o="",r="protocol";continue}else if(c)throw new me(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new me(`Component ${o} was missing value`);u.value=a.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new me("Incomplete multiaddr");return e}function vc(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=nt.getProtocol(e.code);if(r==null)throw new me(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function sd(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:Tr(e,r)}var id=Symbol.for("nodejs.util.inspect.custom"),js=Symbol.for("@multiformats/multiaddr");function ad(t){if(t==null&&(t="/"),Sc(t))return t.getComponents();if(t instanceof Uint8Array)return xc(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Ec(t);if(Array.isArray(t))return t;throw new me("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Nn=class t{[js]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=ad(e),r.validate!==!1&&cd(this)}get bytes(){return this.#r==null&&(this.#r=wc(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=vc(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new In(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return ce(this.bytes,e.bytes)}[id](){return`Multiaddr(${this.toString()})`}};function cd(t){t.getComponents().forEach(e=>{let r=nt.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function Sc(t){return!!t?.[js]}function Tt(t){return new Nn(t)}var Ac="libp2p-peer-record",Ic=Uint8Array.from([3,1]);var Hr;(function(t){let e;(function(i){let c;i.codec=()=>(c==null&&(c=Ue((l,d,p={})=>{p.lengthDelimited!==!1&&d.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(d.uint32(10),d.bytes(l.multiaddr)),p.lengthDelimited!==!1&&d.ldelim()},(l,d,p={})=>{let h={multiaddr:he(0)},E=d==null?l.len:l.pos+d;for(;l.pos<E;){let S=l.uint32();switch(S>>>3){case 1:{h.multiaddr=l.bytes();break}default:{l.skipType(S&7);break}}}return h},function*(l,d,p,h={}){let E=d==null?l.len:l.pos+d;for(;l.pos<E;){let S=l.uint32();switch(S>>>3){case 1:{yield{field:`${p}.multiaddr`,value:l.bytes()};break}default:{l.skipType(S&7);break}}}})),c);function a(l){return Re(l,i.codec())}i.encode=a;function u(l,d){return Oe(l,i.codec(),d)}i.decode=u;function f(l,d){return Ne(l,i.codec(),d)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=Ue((i,c,a={})=>{if(a.lengthDelimited!==!1&&c.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(c.uint32(10),c.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(c.uint32(16),c.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let u of i.addresses)c.uint32(26),t.AddressInfo.codec().encode(u,c);a.lengthDelimited!==!1&&c.ldelim()},(i,c,a={})=>{let u={peerId:he(0),seq:0n,addresses:[]},f=c==null?i.len:i.pos+c;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(a.limits?.addresses!=null&&u.addresses.length===a.limits.addresses)throw new He('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:a.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return u},function*(i,c,a,u={}){let f={addresses:0},l=c==null?i.len:i.pos+c;for(;i.pos<l;){let d=i.uint32();switch(d>>>3){case 1:{yield{field:`${a}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${a}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new He('Streaming decode error - repeated field "addresses" had too many elements');for(let p of t.AddressInfo.codec().stream(i,i.uint32(),`${a}.addresses[]`,{limits:u.limits?.addresses$}))yield{...p,index:f.addresses};f.addresses++;break}default:{i.skipType(d&7);break}}}})),r);function n(i){return Re(i,t.codec())}t.encode=n;function o(i,c){return Oe(i,t.codec(),c)}t.decode=o;function s(i,c){return Ne(i,t.codec(),c)}t.stream=s})(Hr||(Hr={}));function Cc(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var ke=class t{static createFromProtobuf=e=>{let r=Hr.decode(e),n=Ts(pr(r.peerId)),o=(r.addresses??[]).map(i=>Tt(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Ac;static CODEC=Ic;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:o}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Hr.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!Cc(this.multiaddrs,e.multiaddrs))}};function Un(t){let e=t.getComponents(),r={},n=0;if(e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n].name==="ip4"||e[n].name==="ip6"||e[n].name==="dns"||e[n].name==="dns4"||e[n].name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n].name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null)throw new Q(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r}function _c(t,e,r){let n=0;for(let o of t)if(!(n<e)){if(n>r)break;if(o!==255)return!1;n++}return!0}function Dc(t,e,r,n){let o=0;for(let s of t)if(!(o<r)){if(o>n)break;if(s!==e[o])return!1;o++}return!0}function Xs(t){switch(t.length){case Lt:return t.join(".");case Bt:{let e=[];for(let r=0;r<t.length;r++)r%2===0&&e.push(t[r].toString(16).padStart(2,"0")+t[r+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function Tc(t){let e=0;for(let[r,n]of t.entries()){if(n===255){e+=8;continue}for(;(n&128)!=0;)e++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<t.length;o++)if(t[o]!=0)return-1;break}return e}function Lc(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Lt=4,Bt=16,wg=parseInt("0xFFFF",16),ud=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function $r(t,e){e.length===Bt&&t.length===Lt&&_c(e,0,11)&&(e=e.slice(12)),e.length===Lt&&t.length===Bt&&Dc(t,ud,0,11)&&(t=t.slice(12));let r=t.length;if(r!=e.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=t[o]&e[o];return n}function Bc(t,e){if(typeof e=="string"&&(e=tr(e)),e==null)throw new Error("Invalid ip");if(e.length!==t.network.length)return!1;for(let r=0;r<e.length;r++)if((t.network[r]&t.mask[r])!==(e[r]&t.mask[r]))return!1;return!0}function Qs(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Lt,o=Dn(e);if(o==null&&(n=Bt,o=Tn(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+t);let i=Js(s,8*n);return{network:$r(o,i),mask:i}}function Js(t,e){if(e!==8*Lt&&e!==8*Bt)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var zr=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Qs(e));else{let n=tr(e);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=tr(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Js(o,8*n.length);this.network=$r(n,this.mask)}}contains(e){return Bc({network:this.network,mask:this.mask},e)}toString(){let e=Tc(this.mask),r=e!==-1?String(e):Lc(this.mask);return Xs(this.network)+"/"+r}};function Pc(t,e){return new zr(t).contains(e)}function Oc(t){try{let e=Un(t);switch(e.type){case"ip6":return Pc("2000::/3",e.host);default:return!1}}catch{return!1}}var Nc=cu(Rc(),1),fd=["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"],ld=fd.map(t=>new Nc.Netmask(t));function ei(t){for(let e of ld)if(e.contains(t))return!0;return!1}function dd(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function hd(t){let e=t.split(":");if(e.length<2)return!1;let r=e[e.length-1].padStart(4,"0"),n=e[e.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 ei(o)}function pd(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function md(t){let e=t.split(":"),r=e[e.length-1];return ei(r)}function yd(t){return/^::$/.test(t)||/^::1$/.test(t)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^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(t)||/^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(t)||/^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(t)||/^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(t)||/^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(t)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(t)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(t)||/^ff([0-9a-fA-F]{2,2}):/i.test(t)}function Uc(t){if(rr(t))return ei(t);if(dd(t))return hd(t);if(pd(t))return md(t);if(Ln(t))return yd(t)}function kc(t){try{let e=Un(t);switch(e.type){case"ip4":case"ip6":return Uc(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}function cr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var ti=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Kc=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function ri(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,c,a,f=new Promise((l,d)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){d(Kc(i));return}if(i&&(a=()=>{d(Kc(i))},i.addEventListener("abort",a,{once:!0})),t.then(l,d),r===Number.POSITIVE_INFINITY)return;let p=new ti;c=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(h){d(h)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?d(o):(p.message=o??`Promise timed out after ${r} milliseconds`,d(p))},r)}).finally(()=>{f.clear(),a&&i&&i.removeEventListener("abort",a)});return f.clear=()=>{s.clearTimeout.call(void 0,c),c=void 0},f}var bd=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function gd(t,e,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let c=[e].flat(),a=[],{addListener:u,removeListener:f}=bd(t),l=async(...p)=>{let h=r.multiArgs?p:p[0];if(r.filter)try{if(!await r.filter(h))return}catch(E){n(),i(E);return}a.push(h),r.count===a.length&&(n(),s(a))},d=(...p)=>{n(),i(r.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of c)f(p,l);for(let p of r.rejectionEvents)c.includes(p)||f(p,d)};for(let p of c)u(p,l);for(let p of r.rejectionEvents)c.includes(p)||u(p,d);r.signal&&r.signal.addEventListener("abort",()=>{d(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(a)});if(o.cancel=n,typeof r.timeout=="number"){let s=ri(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Mc(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=gd(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Vc(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Pt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function xd(t){return t.reason}async function ni(t,e,r){if(e==null)return t;let n=r?.translateError??xd;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Ed=4194304,kn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},si=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ii=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ai=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function vd(t){return typeof t?.closeRead=="function"}function Sd(t){return typeof t?.close=="function"}function oi(t){return vd(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Sd(t)?t.status!=="open":!1}function Ad(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Id(t,e){let r=e?.maxBufferSize??Ed,n=new ie,o,s=!1;if(!Ad(t))throw new Q("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}o?.resolve()};t.addEventListener("message",i);let c=f=>{f.error!=null?o?.reject(f.error):o?.resolve()};t.addEventListener("close",c);let a=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",a);let u={readBuffer:n,async read(f){if(s===!0)throw new kn("Stream was unwrapped");if(oi(t)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Pt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let l=f?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await ni(o.promise,f?.signal),oi(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}o=Promise.withResolvers()}let d=f?.bytes??n.byteLength;if(n.byteLength<d){if(oi(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,d),new Pt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return u.read(f)}let p=n.sublist(0,d);return n.consume(d),p},async write(f,l){if(s===!0)throw new kn("Stream was unwrapped");t.send(f)||await Mc(t,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",i),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",a),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.push(n))),t}};return u}function Cd(t,e={}){let r=Id(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ie(e.maxDataLength));let n=e?.lengthDecoder??Tr,o=e?.lengthEncoder??Wt;return{async read(i){let c=-1,a=new ie;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;a.append(f);try{c=n(a)}catch(l){if(l instanceof RangeError)continue;throw l}if(c<0)throw new si("Invalid message length");if(e?.maxLengthLength!=null&&a.byteLength>e.maxLengthLength)throw new ai(`Message length length too long - ${a.byteLength} > ${e.maxLengthLength}`);if(c>-1)break}if(e?.maxDataLength!=null&&c>e.maxDataLength)throw new ii(`Message length too long - ${c} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:c});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",c),new Pt(`Unexpected EOF - tried to read ${c} bytes but the stream closed`);if(u.byteLength!==c)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,c),new Pt(`Unexpected EOF - read ${u.byteLength}/${c} bytes before the stream closed`);return u},async write(i,c){await r.write(new ie(o(i.byteLength),i),c)},async writeV(i,c){let a=new ie(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(a,c)},unwrap(){return r.unwrap()}}}function ur(t,e){let r=Cd(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(c=>s.encode(c)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}function _d(t){return t[Symbol.asyncIterator]!=null}function Dd(t){if(_d(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Fc=Dd;var Kn=globalThis.CustomEvent??Event;async function*ci(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,s=[],i=cr(),c=cr(),a=!1,u,f=!1;o.addEventListener("task-complete",()=>{c.resolve()}),Promise.resolve().then(async()=>{try{for await(let h of t){if(s.length===r&&(i=cr(),await i.promise),f)break;let E={done:!1};s.push(E),h().then(S=>{E.done=!0,E.ok=!0,E.value=S,o.dispatchEvent(new Kn("task-complete"))},S=>{E.done=!0,E.err=S,o.dispatchEvent(new Kn("task-complete"))})}a=!0,o.dispatchEvent(new Kn("task-complete"))}catch(h){u=h,o.dispatchEvent(new Kn("task-complete"))}});function l(){return n?s[0]?.done:!!s.find(h=>h.done)}function*d(){for(;s.length>0&&s[0].done;){let h=s[0];if(s.shift(),h.ok)yield h.value;else throw f=!0,i.resolve(),h.err;i.resolve()}}function*p(){for(;l();)for(let h=0;h<s.length;h++)if(s[h].done){let E=s[h];if(s.splice(h,1),h--,E.ok)yield E.value;else throw f=!0,i.resolve(),E.err;i.resolve()}}for(;;){if(l()||(c=cr(),await c.promise),u!=null||(n?yield*d():yield*p(),u!=null))throw u;if(a&&s.length===0)break}}var qc="0.1.0";var Hc="id/push",$c="1.0.0",zc="1.0.0";var pt;(function(t){let e;t.codec=()=>(e==null&&(e=Ue((s,i,c={})=>{if(c.lengthDelimited!==!1&&i.fork(),s.protocolVersion!=null&&(i.uint32(42),i.string(s.protocolVersion)),s.agentVersion!=null&&(i.uint32(50),i.string(s.agentVersion)),s.publicKey!=null&&(i.uint32(10),i.bytes(s.publicKey)),s.listenAddrs!=null&&s.listenAddrs.length>0)for(let a of s.listenAddrs)i.uint32(18),i.bytes(a);if(s.observedAddr!=null&&(i.uint32(34),i.bytes(s.observedAddr)),s.protocols!=null&&s.protocols.length>0)for(let a of s.protocols)i.uint32(26),i.string(a);s.signedPeerRecord!=null&&(i.uint32(66),i.bytes(s.signedPeerRecord)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={listenAddrs:[],protocols:[]},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 5:{a.protocolVersion=s.string();break}case 6:{a.agentVersion=s.string();break}case 1:{a.publicKey=s.bytes();break}case 2:{if(c.limits?.listenAddrs!=null&&a.listenAddrs.length===c.limits.listenAddrs)throw new He('Decode error - repeated field "listenAddrs" had too many elements');a.listenAddrs.push(s.bytes());break}case 4:{a.observedAddr=s.bytes();break}case 3:{if(c.limits?.protocols!=null&&a.protocols.length===c.limits.protocols)throw new He('Decode error - repeated field "protocols" had too many elements');a.protocols.push(s.string());break}case 8:{a.signedPeerRecord=s.bytes();break}default:{s.skipType(f&7);break}}}return a},function*(s,i,c,a={}){let u={listenAddrs:0,protocols:0},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 5:{yield{field:`${c}.protocolVersion`,value:s.string()};break}case 6:{yield{field:`${c}.agentVersion`,value:s.string()};break}case 1:{yield{field:`${c}.publicKey`,value:s.bytes()};break}case 2:{if(a.limits?.listenAddrs!=null&&u.listenAddrs===a.limits.listenAddrs)throw new He('Streaming decode error - repeated field "listenAddrs" had too many elements');yield{field:`${c}.listenAddrs[]`,index:u.listenAddrs,value:s.bytes()},u.listenAddrs++;break}case 4:{yield{field:`${c}.observedAddr`,value:s.bytes()};break}case 3:{if(a.limits?.protocols!=null&&u.protocols===a.limits.protocols)throw new He('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${c}.protocols[]`,index:u.protocols,value:s.string()},u.protocols++;break}case 8:{yield{field:`${c}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function r(s){return Re(s,t.codec())}t.encode=r;function n(s,i){return Oe(s,t.codec(),i)}t.decode=n;function o(s,i){return Ne(s,t.codec(),i)}t.stream=o})(pt||(pt={}));var Ce={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Yc(t){if(t!=null&&t.length>0)try{return Tt(t)}catch{}}async function Mn(t,e,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new Te("message was null or undefined");let s={};if(o.listenAddrs.length>0&&(s.addresses=o.listenAddrs.map(a=>({isCertified:!1,multiaddr:Tt(a)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let a=Jt(o.publicKey);if(!uc(a).equals(n.remotePeer))throw new Te("public key did not match remote PeerId");s.publicKey=a}let i;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let a=o.signedPeerRecord,u=await ze.openAndCertify(a,ke.DOMAIN),f=ke.createFromProtobuf(u.payload),l=An(u.publicKey.toCID());if(!f.peerId.equals(l))throw new Te("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(f.peerId))throw new Te("signing key does not match remote PeerId");let d;try{d=await t.get(f.peerId)}catch(p){if(p.name!=="NotFoundError")throw p}if(d!=null&&(s.metadata=d.metadata,d.peerRecordEnvelope!=null)){let p=ze.createFromProtobuf(d.peerRecordEnvelope),h=ke.createFromProtobuf(p.payload);h.seqNumber>=f.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",h.seqNumber,f.seqNumber),f=h,a=d.peerRecordEnvelope)}s.peerRecordEnvelope=a,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 t.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let a={};o.agentVersion!=null&&(a.AgentVersion=F(o.agentVersion)),o.protocolVersion!=null&&(a.ProtocolVersion=F(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,a),await t.merge(n.remotePeer,{metadata:a})}let c={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:o.listenAddrs.map(a=>Tt(a)),observedAddr:o.observedAddr==null?void 0:Tt(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return e.safeDispatchEvent("peer:identify",{detail:c}),c}var fr=class{host;components;protocol;started;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;runOnLimitedConnection;log;constructor(e,r){this.protocol=r.protocol,this.started=!1,this.components=e,this.log=r.log,this.timeout=r.timeout??Ce.timeout,this.maxInboundStreams=r.maxInboundStreams??Ce.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Ce.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Ce.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Ce.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Ce.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Ce.protocolPrefix}/${qc}`,agentVersion:e.nodeInfo.userAgent},this.handleProtocol=this.handleProtocol.bind(this)}isStarted(){return this.started}async start(){this.started||(await this.components.peerStore.merge(this.components.peerId,{metadata:{AgentVersion:F(this.host.agentVersion),ProtocolVersion:F(this.host.protocolVersion)}}),await this.components.registrar.handle(this.protocol,this.handleProtocol,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}};var Vn=class extends fr{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Ce.protocolPrefix}/${Hc}/${zc}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??Ce.concurrency,this._push=Vc(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Ce.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[Qr]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let e=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),r=new ke({peerId:this.components.peerId,multiaddrs:e}),n=await ze.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=H(s.metadata.get("AgentVersion")??F(this.host.agentVersion)),c=H(s.metadata.get("ProtocolVersion")??F(this.host.protocolVersion)),a=this;async function*u(){for(let f of a.connectionManager.getConnections())(await a.components.peerStore.get(f.remotePeer)).protocols.includes(a.protocol)&&(yield async()=>{let d,p=AbortSignal.timeout(a.timeout);try{d=await f.newStream(a.protocol,{signal:p,runOnLimitedConnection:a.runOnLimitedConnection}),await ur(d,{maxDataLength:a.maxMessageSize}).pb(pt).write({listenAddrs:e.map(E=>E.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:c},{signal:p}),await d.close({signal:p})}catch(h){d?.log.newScope("identify-push")?.error("could not push identify update to peer",h),d?.abort(h)}})}await Fc(ci(u(),{concurrency:this.concurrency}))}catch(e){this.log.error("error pushing updates to peers - %e",e)}}async handleProtocol(e,r){let n=e.log.newScope("identify-push");if(this.components.peerId.equals(r.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},i=await ur(e,{maxDataLength:this.maxMessageSize}).pb(pt).read(o);await e.close(o),await Mn(this.components.peerStore,this.components.events,n,r,i),n.trace("handled push from %p",r.remotePeer)}};var G=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),P=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),Zc=t=>({match:e=>t.match(e)===!1?e:!1}),q=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),xe=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),Z=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function W(...t){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of t){let c=i.match(s);if(c===!1)return!1;s=c}return s}function r(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:t,matches:r,exactMatch:n}}var Pd=P(421),Jx=W(Pd),qn=P(54),Hn=P(55),$n=P(56),fi=P(53),ew=W(qn,q(P(421))),tw=W(Hn,q(P(421))),rw=W($n,q(P(421))),nw=W(xe(fi,$n,qn,Hn),q(P(421))),Gc=Z(P(4),q(P(43))),Wc=Z(q(P(42)),P(41),q(P(43))),li=xe(Gc,Wc),Ot=xe(li,fi,qn,Hn,$n),jc=W(xe(li,Z(xe(fi,$n,qn,Hn),q(P(421))))),ow=W(Gc),sw=W(Wc),iw=W(li),di=Z(Ot,P(6)),Zr=Z(Ot,P(273)),Xc=W(Z(di,q(P(421)))),aw=W(Zr),hi=Z(Zr,G(460),q(P(421))),zn=Z(Zr,G(461),q(P(421))),Od=xe(hi,zn),cw=W(hi),uw=W(zn),ui=xe(Ot,di,Zr,hi,zn),Qc=xe(Z(ui,G(477),q(P(421)))),fw=W(Qc),Jc=xe(Z(ui,G(478),q(P(421))),Z(ui,G(448),q(P(449)),G(477),q(P(421)))),lw=W(Jc),eu=Z(Zr,G(280),q(P(466)),q(P(466)),q(P(421))),dw=W(eu),tu=Z(zn,G(465),q(P(466)),q(P(466)),q(P(421))),hw=W(tu),Fn=xe(Qc,Jc,Z(di,q(P(421))),Z(Od,q(P(421))),Z(Ot,q(P(421))),eu,tu,P(421)),pw=W(Fn),Rd=Z(q(Fn),G(290),Zc(G(281)),q(P(421))),mw=W(Rd),Nd=xe(Z(Fn,G(290),G(281),q(P(421))),Z(Fn,G(281),q(P(421))),Z(G(281),q(P(421)))),yw=W(Nd),Ud=xe(Z(Ot,P(6),G(480),q(P(421))),Z(Ot,G(480),q(P(421)))),bw=W(Ud),kd=Z(Ot,xe(Z(P(6,"443"),G(480)),Z(P(6),G(443)),Z(P(6),G(448),G(480)),Z(G(448),G(480)),G(448),G(443)),q(P(421))),gw=W(kd),Kd=xe(Z(P(777),q(P(421)))),xw=W(Kd),Md=xe(Z(P(400),q(P(421)))),ww=W(Md);var Yn=class extends fr{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Ce.protocolPrefix}/${"id"}/${$c}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Ce.runOnConnectionOpen)&&e.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[Qr]=["@libp2p/identify"];async _identify(e,r={}){let n,o;if(r.signal==null){let s=AbortSignal.timeout(this.timeout);r={...r,signal:s}}this.log("run identify on new connection %a",e.remoteAddr);try{n=await e.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),o=n.log.newScope("identify");let s=ur(n,{maxDataLength:this.maxMessageSize}).pb(pt),i=await s.read(r);return await s.unwrap().unwrap().close(r),i}catch(s){throw o?.error("identify failed - %e",s),n?.abort(s),s}}async identify(e,r={}){let n=await this._identify(e,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Te("Public key was missing from identify message");let c=Jt(o),a=An(c.toCID());if(!e.remotePeer.equals(a))throw new Te("Identified peer does not match the expected peer");if(this.components.peerId.equals(a))throw new Te("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",a,s),Mn(this.components.peerStore,this.components.events,this.log,e,n)}maybeAddObservedAddress(e){let r=Yc(e);if(r==null||(this.log.trace("our observed address was %a",r),kc(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Oc(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Xc.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(e,r){let n=e.log.newScope("identify");n("responding to identify");let o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),c=s.peerRecordEnvelope;if(i.length>0&&c==null){let f=new ke({peerId:this.components.peerId,multiaddrs:i});c=(await ze.seal(f,this.components.privateKey,{signal:o})).marshal().subarray()}let a=r.remoteAddr.bytes;jc.matches(r.remoteAddr)||(a=void 0);let u=ur(e).pb(pt);n("send response"),await u.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ve(this.components.privateKey.publicKey),listenAddrs:i.map(f=>f.bytes),signedPeerRecord:c,observedAddr:a,protocols:s.protocols},{signal:o}),n("close write"),await u.unwrap().unwrap().close({signal:o})}};function Fd(t={}){return e=>new Yn(e,t)}function qd(t={}){return e=>new Vn(e,t)}return uu(Hd);})();
2
+ "use strict";var Libp2PIdentify=(()=>{var Nf=Object.create;var nn=Object.defineProperty;var kf=Object.getOwnPropertyDescriptor;var Uf=Object.getOwnPropertyNames;var Kf=Object.getPrototypeOf,Mf=Object.prototype.hasOwnProperty;var io=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Et=(e,t)=>{for(var r in t)nn(e,r,{get:t[r],enumerable:!0})},Vi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Uf(t))!Mf.call(e,o)&&o!==r&&nn(e,o,{get:()=>t[o],enumerable:!(n=kf(t,o))||n.enumerable});return e};var Vf=(e,t,r)=>(r=e!=null?Nf(Kf(e)):{},Vi(t||!e||!e.__esModule?nn(r,"default",{value:e,enumerable:!0}):r,e)),Ff=e=>Vi(nn({},"__esModule",{value:!0}),e);var gi=io(hr=>{"use strict";Object.defineProperty(hr,"__esModule",{value:!0});hr.Netmask4Impl=void 0;hr.ip2long=dr;hr.long2ip=Yt;function Yt(e){let t=(e&-16777216)>>>24,r=(e&255<<16)>>>16,n=(e&65280)>>>8,o=e&255;return[t,r,n,o].join(".")}var Hd=48,qd=97,$d=65;function zd(e){let t=0,r=10,n="9",o=0;e.length>1&&e[o]==="0"&&(e[o+1]==="x"||e[o+1]==="X"?(o+=2,r=16):"0"<=e[o+1]&&e[o+1]<="9"&&(o++,r=8,n="7"));let s=o;for(;o<e.length;){if("0"<=e[o]&&e[o]<=n)t=t*r+(e.charCodeAt(o)-Hd)>>>0;else if(r===16)if("a"<=e[o]&&e[o]<="f")t=t*r+(10+e.charCodeAt(o)-qd)>>>0;else if("A"<=e[o]&&e[o]<="F")t=t*r+(10+e.charCodeAt(o)-$d)>>>0;else break;else break;if(t>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[t,o]}function dr(e){let t=[];for(let r=0;r<=3&&e.length!==0;r++){if(r>0){if(e[0]!==".")throw new Error("Invalid IP");e=e.substring(1)}let[n,o]=zd(e);e=e.substring(o),t.push(n)}if(e.length!==0)throw new Error("Invalid IP");switch(t.length){case 1:if(t[0]>4294967295)throw new Error("Invalid IP");return t[0]>>>0;case 2:if(t[0]>255||t[1]>16777215)throw new Error("Invalid IP");return(t[0]<<24|t[1])>>>0;case 3:if(t[0]>255||t[1]>255||t[2]>65535)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2])>>>0;case 4:if(t[0]>255||t[1]>255||t[2]>255||t[3]>255)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0;default:throw new Error("Invalid IP")}}var xi=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=t.split("/",2);t=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=dr(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(dr(t)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+t)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=Yt(this.netLong),this.mask=Yt(this.maskLong),this.hostmask=Yt(~this.maskLong),this.first=this.bitmask<=30?Yt(this.netLong+1):this.base,this.last=this.bitmask<=30?Yt(this.netLong+this.size-2):Yt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Yt(this.netLong+this.size-1):void 0}contains(t){return typeof t=="string"&&(t.indexOf("/")>0||t.split(".").length!==4)&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):(dr(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new e(Yt(this.netLong+this.size*t),this.mask)}forEach(t){let r=dr(this.first),n=dr(this.last),o=0;for(;r<=n;)t(Yt(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};hr.Netmask4Impl=xi});var df=io(pr=>{"use strict";Object.defineProperty(pr,"__esModule",{value:!0});pr.Netmask6Impl=void 0;pr.ip6bigint=Ei;pr.bigint2ip6=Ue;var Gd=gi(),wi=(1n<<128n)-1n;function Ei(e){let t=e.indexOf("%");t!==-1&&(e=e.substring(0,t));let r=e.lastIndexOf(":");if(r!==-1&&e.indexOf(".",r)!==-1){let n=e.substring(r+1),o=(0,Gd.ip2long)(n),s=e.substring(0,r+1)+"0:0";return lf(s)&~0xffffffffn|BigInt(o)}return lf(e)}function lf(e){let t=e.indexOf("::"),r;if(t!==-1){let o=e.substring(0,t),s=e.substring(t+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(c).fill("0"),...a]}else r=e.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let s=r[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Ue(e){if(e<0n||e>wi)throw new Error("Invalid IPv6 address value");let t=[];for(let i=0;i<8;i++)t.unshift(Number(e&0xffffn)),e>>=16n;let r=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)t[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(r=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(r=o,n=s),r!==-1&&r+n===8&&r>0)return t.slice(0,r).map(a=>a.toString(16)).join(":")+"::";if(r===0)return"::"+t.slice(n).map(a=>a.toString(16)).join(":");if(r>0){let i=t.slice(0,r).map(c=>c.toString(16)),a=t.slice(r+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return t.map(i=>i.toString(16)).join(":")}var vi=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=t.indexOf("/");o!==-1?(n=parseInt(t.substring(o+1),10),t=t.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=wi>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Ei(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Ue(this.netBigint),this.mask=Ue(this.maskBigint),this.hostmask=Ue(~this.maskBigint&wi),this.first=this.base,this.last=Ue(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(t){return typeof t=="string"&&t.indexOf("/")>0&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.last):(Ei(t)&this.maskBigint)===this.netBigint}next(t=1){let r=1n<<BigInt(128-this.bitmask);return new e(Ue(this.netBigint+r*BigInt(t)),this.bitmask)}forEach(t){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)t(Ue(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};pr.Netmask6Impl=vi});var hf=io(ge=>{"use strict";Object.defineProperty(ge,"__esModule",{value:!0});ge.long2ip=ge.ip2long=ge.Netmask=void 0;var Wn=gi();Object.defineProperty(ge,"ip2long",{enumerable:!0,get:function(){return Wn.ip2long}});Object.defineProperty(ge,"long2ip",{enumerable:!0,get:function(){return Wn.long2ip}});var Yd=df(),Si=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");(t.indexOf("/")!==-1?t.substring(0,t.indexOf("/")):t).indexOf(":")!==-1?this._impl=new Yd.Netmask6Impl(t,r):this._impl=new Wn.Netmask4Impl(t,r),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof Wn.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(t){return typeof t=="string"&&(t.indexOf("/")>0?t=new e(t):t.indexOf(":")===-1&&t.split(".").length!==4&&(t=new e(t))),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):this._impl.contains(t)}next(t=1){let r=this._impl.next(t);return new e(r.base,r.bitmask)}forEach(t){this._impl.forEach(t)}toString(){return this._impl.toString()}};ge.Netmask=Si});var Ch={};Et(Ch,{identify:()=>Ih,identifyPush:()=>_h});var Q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Me=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var on=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},sn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Bt=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Ee=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ao=Symbol.for("@libp2p/peer-id");var an=Symbol.for("@libp2p/service-capabilities");var ho={};Et(ho,{base58btc:()=>ot,base58flickr:()=>Zf});var r0=new Uint8Array(0);function Fi(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Zt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Hi(e){return new TextEncoder().encode(e)}function qi(e){return new TextDecoder().decode(e)}function Hf(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),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var E=0,S=0,x=0,I=d.length;x!==I&&d[x]===0;)x++,E++;for(var g=(I-x)*u+1>>>0,_=new Uint8Array(g);x!==I;){for(var R=d[x],K=0,M=g-1;(R!==0||K<S)&&M!==-1;M--,K++)R+=256*_[M]>>>0,_[M]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");S=K,x++}for(var v=g-S;v!==g&&_[v]===0;)v++;for(var w=c.repeat(E);v<g;++v)w+=e.charAt(_[v]);return w}function h(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var E=0;if(d[E]!==" "){for(var S=0,x=0;d[E]===c;)S++,E++;for(var I=(d.length-E)*f+1>>>0,g=new Uint8Array(I);d[E];){var _=r[d.charCodeAt(E)];if(_===255)return;for(var R=0,K=I-1;(_!==0||R<x)&&K!==-1;K--,R++)_+=a*g[K]>>>0,g[K]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");x=R,E++}if(d[E]!==" "){for(var M=I-x;M!==I&&g[M]===0;)M++;for(var v=new Uint8Array(S+(I-M)),w=S;M!==I;)v[w++]=g[M++];return v}}}function p(d){var E=h(d);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:h,decode:p}}var qf=Hf,$f=qf,zi=$f;var co=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},fo=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 Gi(this,t)}},uo=class{decoders;constructor(t){this.decoders=t}or(t){return Gi(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 Gi(e,t){return new uo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var lo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new co(t,r,n),this.decoder=new fo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ve({name:e,prefix:t,encode:r,decode:n}){return new lo(e,t,r,n)}function ce({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=zi(r,e);return Ve({prefix:t,name:e,encode:n,decode:s=>Zt(o(s))})}function zf(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 f=0;f<o;++f){let u=t[e[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,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 Gf(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 Yf(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function nt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Yf(n);return Ve({prefix:t,name:e,encode(s){return Gf(s,n,r)},decode(s){return zf(s,o,r,e)}})}var ot=ce({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zf=ce({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var po={};Et(po,{base32:()=>fe,base32hex:()=>Qf,base32hexpad:()=>tu,base32hexpadupper:()=>eu,base32hexupper:()=>Jf,base32pad:()=>jf,base32padupper:()=>Xf,base32upper:()=>Wf,base32z:()=>ru});var fe=nt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Wf=nt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jf=nt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Xf=nt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Qf=nt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Jf=nt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),tu=nt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),eu=nt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ru=nt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var mo={};Et(mo,{base36:()=>gr,base36upper:()=>nu});var gr=ce({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),nu=ce({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ou=Wi,Yi=128,su=127,iu=~su,au=Math.pow(2,31);function Wi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=au;)t[r++]=e&255|Yi,e/=128;for(;e&iu;)t[r++]=e&255|Yi,e>>>=7;return t[r]=e|0,Wi.bytes=r-n+1,t}var cu=bo,fu=128,Zi=127;function bo(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw bo.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Zi)<<o:(i&Zi)*Math.pow(2,o),o+=7}while(i>=fu);return bo.bytes=s-n,r}var uu=Math.pow(2,7),lu=Math.pow(2,14),du=Math.pow(2,21),hu=Math.pow(2,28),pu=Math.pow(2,35),mu=Math.pow(2,42),bu=Math.pow(2,49),yu=Math.pow(2,56),xu=Math.pow(2,63),gu=function(e){return e<uu?1:e<lu?2:e<du?3:e<hu?4:e<pu?5:e<mu?6:e<bu?7:e<yu?8:e<xu?9:10},wu={encode:ou,decode:cu,encodingLength:gu},Eu=wu,wr=Eu;function Er(e,t=0){return[wr.decode(e,t),wr.decode.bytes]}function Fe(e,t,r=0){return wr.encode(e,t,r),t}function He(e){return wr.encodingLength(e)}function Vt(e,t){let r=t.byteLength,n=He(e),o=n+He(r),s=new Uint8Array(o+r);return Fe(e,s,0),Fe(r,s,n),s.set(t,o),new qe(e,r,t,s)}function vr(e){let t=Zt(e),[r,n]=Er(t),[o,s]=Er(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new qe(r,o,i,t)}function ji(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Fi(e.bytes,r.bytes)}}var qe=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Xi(e,t){let{bytes:r,version:n}=e;return n===0?Su(r,yo(e),t??ot.encoder):Au(r,yo(e),t??fe.encoder)}var Qi=new WeakMap;function yo(e){let t=Qi.get(e);if(t==null){let r=new Map;return Qi.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Sr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Iu)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=Vt(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&&ji(t.multihash,n.multihash)}toString(t){return Xi(this,t)}toJSON(){return{"/":Xi(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??Ji(n,o,s.bytes))}else if(r[_u]===!0){let{version:n,multihash:o,code:s}=r,i=vr(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Sr)throw new Error(`Version 0 CID must use dag-pb (code: ${Sr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ji(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Sr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Zt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new qe(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,h]=Er(t.subarray(r));return r+=h,l},o=n(),s=Sr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),f=r+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,r){let[n,o]=vu(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 yo(s).set(n,t),s}};function vu(e,t){switch(e[0]){case"Q":{let r=t??ot;return[ot.prefix,r.decode(`${ot.prefix}${e}`)]}case ot.prefix:{let r=t??ot;return[ot.prefix,r.decode(e)]}case fe.prefix:{let r=t??fe;return[fe.prefix,r.decode(e)]}case gr.prefix:{let r=t??gr;return[gr.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 Su(e,t,r){let{prefix:n}=r;if(n!==ot.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Au(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Sr=112,Iu=18;function Ji(e,t,r){let n=He(e),o=n+He(t),s=new Uint8Array(o+r.byteLength);return Fe(e,s,0),Fe(t,s,n),s.set(r,o),s}var _u=Symbol.for("@ipld/js-cid/CID");var xo={};Et(xo,{identity:()=>Lt});var ta=0,Cu="identity",ea=Zt;function Du(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Vt(ta,ea(e))}var Lt={code:ta,name:Cu,encode:ea,digest:Du};function ct(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ht(e=0){return new Uint8Array(e)}function vt(e=0){return new Uint8Array(e)}function Wt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=vt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var na=Symbol.for("@achingbrain/uint8arraylist");function ra(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 fn(e){return!!e?.[na]}var it=class e{bufs;length;[na]=!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(fn(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(fn(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=ra(this.bufs,t);return r.buf[r.index]}set(t,r){let n=ra(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(fn(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 f=t>=a&&t<c,u=r>a&&r<=c;if(f&&u){if(t===a&&r===c){n.push(i);break}let l=t-a;n.push(i.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){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(!fn(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,f=n.byteLength-1,u;for(let l=r;l<=c;l+=u){u=0;for(let h=f;h>=0;h--){let p=this.get(l+h);if(n[h]!==p){u=Math.max(1,h-a[p]);break}}if(u===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=vt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=vt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ct(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 go={};Et(go,{base10:()=>Bu});var Bu=ce({prefix:"9",name:"base10",alphabet:"0123456789"});var wo={};Et(wo,{base16:()=>Lu,base16upper:()=>Tu});var Lu=nt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Tu=nt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Eo={};Et(Eo,{base2:()=>Pu});var Pu=nt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var vo={};Et(vo,{base256emoji:()=>Uu});var oa=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}"),Ou=oa.reduce((e,t,r)=>(e[r]=t,e),[]),Ru=oa.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Nu(e){return e.reduce((t,r)=>(t+=Ou[r],t),"")}function ku(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ru[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Uu=Ve({prefix:"\u{1F680}",name:"base256emoji",encode:Nu,decode:ku});var Ao={};Et(Ao,{base64:()=>Ku,base64pad:()=>Mu,base64url:()=>So,base64urlpad:()=>Vu});var Ku=nt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Mu=nt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),So=nt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Vu=nt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Io={};Et(Io,{base8:()=>Fu});var Fu=nt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var _o={};Et(_o,{identity:()=>Hu});var Hu=Ve({prefix:"\0",name:"identity",encode:e=>qi(e),decode:e=>Hi(e)});var M0=new TextEncoder,V0=new TextDecoder;var Bo={};Et(Bo,{sha256:()=>Ar,sha512:()=>Gu});var zu=20;function Do({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Co(e,t,r,n,o)}var Co=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??zu,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?sa(n,this.code,r?.truncate):n.then(o=>sa(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function sa(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Vt(t,e)}function aa(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Ar=Do({name:"sha2-256",code:18,encode:aa("SHA-256")}),Gu=Do({name:"sha2-512",code:19,encode:aa("SHA-512")});var Ir={..._o,...Eo,...Io,...go,...wo,...po,...mo,...ho,...Ao,...vo},Q0={...Bo,...xo};function fa(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ca=fa("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Lo=fa("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=vt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Yu={utf8:ca,"utf-8":ca,hex:Ir.base16,latin1:Lo,ascii:Lo,binary:Lo,...Ir},un=Yu;function F(e,t="utf8"){let r=un[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function q(e,t="utf8"){let r=un[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Zu=parseInt("11111",2),To=parseInt("10000000",2),Wu=parseInt("01111111",2),ua={0:_r,1:_r,2:ju,3:Ju,4:tl,5:Qu,6:Xu,16:_r,22:_r,48:_r};function jt(e,t={offset:0}){let r=e[t.offset]&Zu;if(t.offset++,ua[r]!=null)return ua[r](e,t);throw new Error("No decoder for tag "+r)}function Cr(e,t){let r=0;if((e[t.offset]&To)===To){let n=e[t.offset]&Wu,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 _r(e,t){Cr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=jt(e,t);if(n===null)break;r.push(n)}return r}function ju(e,t){let r=Cr(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 Xu(e,t){let r=Cr(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 f=e[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function Qu(e,t){return t.offset++,null}function Ju(e,t){let r=Cr(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 tl(e,t){let r=Cr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function el(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new it;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Po(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=el(e.byteLength);return new it(Uint8Array.from([t.byteLength|To]),t)}function St(e){let t=new it,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new it(Uint8Array.from([2]),Po(t),t)}function ln(e){let t=Uint8Array.from([0]),r=new it(t,e);return new it(Uint8Array.from([3]),Po(r),r)}function ue(e,t=48){let r=new it;for(let n of e)r.append(n);return new it(Uint8Array.from([t]),Po(r),r)}async function la(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 rl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),nl=Uint8Array.from([6,5,43,129,4,0,34]),ol=Uint8Array.from([6,5,43,129,4,0,35]),sl={ext:!0,kty:"EC",crv:"P-256"},il={ext:!0,kty:"EC",crv:"P-384"},al={ext:!0,kty:"EC",crv:"P-521"},Oo=32,Ro=48,No=66;function ko(e){let t=jt(e);return da(t)}function da(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Oo*2+1)return n=q(t.subarray(r,r+Oo),"base64url"),o=q(t.subarray(r+Oo),"base64url"),new $e({...sl,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ro*2+1)return n=q(t.subarray(r,r+Ro),"base64url"),o=q(t.subarray(r+Ro),"base64url"),new $e({...il,key_ops:["verify"],x:n,y:o});if(t.byteLength===No*2+1)return n=q(t.subarray(r,r+No),"base64url"),o=q(t.subarray(r+No),"base64url"),new $e({...al,key_ops:["verify"],x:n,y:o});throw new Q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ha(e){return ue([St(Uint8Array.from([1])),ue([cl(e.crv)],160),ue([ln(new it(Uint8Array.from([4]),F(e.x??"","base64url"),F(e.y??"","base64url")))],161)]).subarray()}function cl(e){if(e==="P-256")return rl;if(e==="P-384")return nl;if(e==="P-521")return ol;throw new Q(`Invalid curve ${e}`)}var $e=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ha(this.jwk)),this._raw}toMultihash(){return Lt.digest(Ft(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async verify(t,r,n){return la(this.jwk,r,t,n)}};function Se(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ht(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function U(e,t,r=""){let n=Se(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function dn(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Ht(e.outputLen),Ht(e.blockLen)}function ze(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 ma(e,t){U(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Qt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function hn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Tt(e,t){return e<<32-t|e>>>t}var ba=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",fl=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Jt(e){if(U(e),ba)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=fl[e[r]];return t}var Xt={_0:48,_9:57,A:65,F:70,a:97,f:102};function pa(e){if(e>=Xt._0&&e<=Xt._9)return e-Xt._0;if(e>=Xt.A&&e<=Xt.F)return e-(Xt.A-10);if(e>=Xt.a&&e<=Xt.f)return e-(Xt.a-10)}function te(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ba)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=pa(e.charCodeAt(s)),a=pa(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 At(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];U(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function Uo(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Ge(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var Ko=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ya(e,t,r){return e&t^~e&r}function xa(e,t,r){return e&t^e&r^t&r}var Dr=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=hn(this.buffer)}update(t){ze(this),U(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=hn(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){ze(this),ma(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Qt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=hn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},ee=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var pt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var pn=BigInt(4294967295),ga=BigInt(32);function ul(e,t=!1){return t?{h:Number(e&pn),l:Number(e>>ga&pn)}:{h:Number(e>>ga&pn)|0,l:Number(e&pn)|0}}function wa(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}=ul(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Mo=(e,t,r)=>e>>>r,Vo=(e,t,r)=>e<<32-r|t>>>r,Ae=(e,t,r)=>e>>>r|t<<32-r,Ie=(e,t,r)=>e<<32-r|t>>>r,Br=(e,t,r)=>e<<64-r|t>>>r-32,Lr=(e,t,r)=>e>>>r-32|t<<64-r;function qt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ea=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),va=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Sa=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Aa=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ia=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),_a=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var dl=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]),le=new Uint32Array(64),Fo=class extends Dr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)le[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let h=le[l-15],p=le[l-2],d=Tt(h,7)^Tt(h,18)^h>>>3,E=Tt(p,17)^Tt(p,19)^p>>>10;le[l]=E+le[l-7]+d+le[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let h=Tt(a,6)^Tt(a,11)^Tt(a,25),p=u+h+ya(a,c,f)+dl[l]+le[l]|0,E=(Tt(n,2)^Tt(n,13)^Tt(n,22))+xa(n,o,s)|0;u=f,f=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,f,u)}roundClean(){Qt(le)}destroy(){this.set(0,0,0,0,0,0,0,0),Qt(this.buffer)}},Ho=class extends Fo{A=ee[0]|0;B=ee[1]|0;C=ee[2]|0;D=ee[3]|0;E=ee[4]|0;F=ee[5]|0;G=ee[6]|0;H=ee[7]|0;constructor(){super(32)}};var Ca=wa(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),hl=Ca[0],pl=Ca[1],de=new Uint32Array(80),he=new Uint32Array(80),qo=class extends Dr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:h,Gh:p,Gl:d,Hh:E,Hl:S}=this;return[t,r,n,o,s,i,a,c,f,u,l,h,p,d,E,S]}set(t,r,n,o,s,i,a,c,f,u,l,h,p,d,E,S){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=h|0,this.Gh=p|0,this.Gl=d|0,this.Hh=E|0,this.Hl=S|0}process(t,r){for(let g=0;g<16;g++,r+=4)de[g]=t.getUint32(r),he[g]=t.getUint32(r+=4);for(let g=16;g<80;g++){let _=de[g-15]|0,R=he[g-15]|0,K=Ae(_,R,1)^Ae(_,R,8)^Mo(_,R,7),M=Ie(_,R,1)^Ie(_,R,8)^Vo(_,R,7),v=de[g-2]|0,w=he[g-2]|0,N=Ae(v,w,19)^Br(v,w,61)^Mo(v,w,6),V=Ie(v,w,19)^Lr(v,w,61)^Vo(v,w,6),L=Sa(M,V,he[g-7],he[g-16]),b=Aa(L,K,N,de[g-7],de[g-16]);de[g]=b|0,he[g]=L|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:h,Fh:p,Fl:d,Gh:E,Gl:S,Hh:x,Hl:I}=this;for(let g=0;g<80;g++){let _=Ae(l,h,14)^Ae(l,h,18)^Br(l,h,41),R=Ie(l,h,14)^Ie(l,h,18)^Lr(l,h,41),K=l&p^~l&E,M=h&d^~h&S,v=Ia(I,R,M,pl[g],he[g]),w=_a(v,x,_,K,hl[g],de[g]),N=v|0,V=Ae(n,o,28)^Br(n,o,34)^Br(n,o,39),L=Ie(n,o,28)^Lr(n,o,34)^Lr(n,o,39),b=n&s^n&a^s&a,y=o&i^o&c^i&c;x=E|0,I=S|0,E=p|0,S=d|0,p=l|0,d=h|0,{h:l,l:h}=qt(f|0,u|0,w|0,N|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let m=Ea(N,L,y);n=va(m,w,V,b),o=m|0}({h:n,l:o}=qt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=qt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=qt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=qt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:h}=qt(this.Eh|0,this.El|0,l|0,h|0),{h:p,l:d}=qt(this.Fh|0,this.Fl|0,p|0,d|0),{h:E,l:S}=qt(this.Gh|0,this.Gl|0,E|0,S|0),{h:x,l:I}=qt(this.Hh|0,this.Hl|0,x|0,I|0),this.set(n,o,s,i,a,c,f,u,l,h,p,d,E,S,x,I)}roundClean(){Qt(de,he)}destroy(){Qt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},$o=class extends qo{Ah=pt[0]|0;Al=pt[1]|0;Bh=pt[2]|0;Bl=pt[3]|0;Ch=pt[4]|0;Cl=pt[5]|0;Dh=pt[6]|0;Dl=pt[7]|0;Eh=pt[8]|0;El=pt[9]|0;Fh=pt[10]|0;Fl=pt[11]|0;Gh=pt[12]|0;Gl=pt[13]|0;Hh=pt[14]|0;Hl=pt[15]|0;constructor(){super(64)}};var Da=Uo(()=>new Ho,Ko(1));var Ba=Uo(()=>new $o,Ko(3));var Go=BigInt(0),zo=BigInt(1);function re(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function La(e){if(typeof e=="bigint"){if(!mn(e))throw new Error("positive bigint expected, got "+e)}else Ht(e);return e}function Tr(e){let t=La(e).toString(16);return t.length&1?"0"+t:t}function Ta(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Go:BigInt("0x"+e)}function Ye(e){return Ta(Jt(e))}function _e(e){return Ta(Jt(yn(U(e)).reverse()))}function bn(e,t){Ht(t),e=La(e);let r=te(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function Yo(e,t){return bn(e,t).reverse()}function yn(e){return Uint8Array.from(e)}var mn=e=>typeof e=="bigint"&&Go<=e;function ml(e,t,r){return mn(e)&&mn(t)&&mn(r)&&t<=e&&e<r}function Pr(e,t,r,n){if(!ml(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Zo(e){let t;for(t=0;e>Go;e>>=zo,t+=1);return t}var Or=e=>(zo<<BigInt(e))-zo;function Pa(e,t,r){if(Ht(e,"hashLen"),Ht(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=S=>new Uint8Array(S),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),f=n(e),u=0,l=()=>{c.fill(1),f.fill(0),u=0},h=(...S)=>r(f,At(c,...S)),p=(S=o)=>{f=h(s,S),c=h(),S.length!==0&&(f=h(i,S),c=h())},d=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let S=0,x=[];for(;S<t;){c=h();let I=c.slice();x.push(I),S+=c.length}return At(...x)};return(S,x)=>{l(),p(S);let I;for(;!(I=x(d()));)p();return l(),I}}function pe(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,i,a){let c=e[s];if(a&&c===void 0)return;let f=typeof c;if(f!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(r,!0)}function Ze(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 wt=BigInt(0),ft=BigInt(1),Ce=BigInt(2),Na=BigInt(3),ka=BigInt(4),Ua=BigInt(5),bl=BigInt(7),Ka=BigInt(8),yl=BigInt(9),Ma=BigInt(16);function st(e,t){let r=e%t;return r>=wt?r:t+r}function X(e,t,r){let n=e;for(;t-- >wt;)n*=n,n%=r;return n}function Oa(e,t){if(e===wt)throw new Error("invert: expected non-zero number");if(t<=wt)throw new Error("invert: expected positive modulus, got "+t);let r=st(e,t),n=t,o=wt,s=ft,i=ft,a=wt;for(;r!==wt;){let f=n/r,u=n%r,l=o-i*f,h=s-a*f;n=r,r=u,o=i,s=a,i=l,a=h}if(n!==ft)throw new Error("invert: does not exist");return st(o,t)}function jo(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Va(e,t){let r=(e.ORDER+ft)/ka,n=e.pow(t,r);return jo(e,n,t),n}function xl(e,t){let r=(e.ORDER-Ua)/Ka,n=e.mul(t,Ce),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Ce),o),a=e.mul(s,e.sub(i,e.ONE));return jo(e,a,t),a}function gl(e){let t=We(e),r=Fa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+bl)/Ma;return(a,c)=>{let f=a.pow(c,i),u=a.mul(f,n),l=a.mul(f,o),h=a.mul(f,s),p=a.eql(a.sqr(u),c),d=a.eql(a.sqr(l),c);f=a.cmov(f,u,p),u=a.cmov(h,l,d);let E=a.eql(a.sqr(u),c),S=a.cmov(f,u,E);return jo(a,S,c),S}}function Fa(e){if(e<Na)throw new Error("sqrt is not defined for small field");let t=e-ft,r=0;for(;t%Ce===wt;)t/=Ce,r++;let n=Ce,o=We(e);for(;Ra(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Va;let s=o.pow(n,t),i=(t+ft)/Ce;return function(c,f){if(c.is0(f))return f;if(Ra(c,f)!==1)throw new Error("Cannot find square root");let u=r,l=c.mul(c.ONE,s),h=c.pow(f,t),p=c.pow(f,i);for(;!c.eql(h,c.ONE);){if(c.is0(h))return c.ZERO;let d=1,E=c.sqr(h);for(;!c.eql(E,c.ONE);)if(d++,E=c.sqr(E),d===u)throw new Error("Cannot find square root");let S=ft<<BigInt(u-d-1),x=c.pow(l,S);u=d,l=c.sqr(x),h=c.mul(h,l),p=c.mul(p,x)}return p}}function wl(e){return e%ka===Na?Va:e%Ka===Ua?xl:e%Ma===yl?gl(e):Fa(e)}var Ha=(e,t)=>(st(e,t)&ft)===ft,El=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Xo(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=El.reduce((n,o)=>(n[o]="function",n),t);return pe(e,r),e}function vl(e,t,r){if(r<wt)throw new Error("invalid exponent, negatives unsupported");if(r===wt)return e.ONE;if(r===ft)return t;let n=e.ONE,o=t;for(;r>wt;)r&ft&&(n=e.mul(n,o)),o=e.sqr(o),r>>=ft;return n}function Rr(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 Ra(e,t){let r=(e.ORDER-ft)/Ce,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 Sl(e,t){t!==void 0&&Ht(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var Wo=class{ORDER;BITS;BYTES;isLE;ZERO=wt;ONE=ft;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=wt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=Sl(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return st(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return wt<=t&&t<this.ORDER}is0(t){return t===wt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&ft)===ft}neg(t){return st(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return st(t*t,this.ORDER)}add(t,r){return st(t+r,this.ORDER)}sub(t,r){return st(t-r,this.ORDER)}mul(t,r){return st(t*r,this.ORDER)}pow(t,r){return vl(this,t,r)}div(t,r){return st(t*Oa(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Oa(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=wl(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Yo(t,this.BYTES):bn(t,this.BYTES)}fromBytes(t,r=!1){U(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?_e(t):Ye(t);if(a&&(c=st(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Rr(this,t)}cmov(t,r,n){return n?r:t}};function We(e,t={}){return new Wo(e,t)}function qa(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 Qo(e){let t=qa(e);return t+Math.ceil(t/2)}function Jo(e,t,r=!1){U(e);let n=e.length,o=qa(t),s=Qo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?_e(e):Ye(e),a=st(i,t-ft)+ft;return r?Yo(a,o):bn(a,o)}var je=BigInt(0),De=BigInt(1);function Nr(e,t){let r=t.negate();return e?r:t}function Be(e,t){let r=Rr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Ya(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function ts(e,t){Ya(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Or(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function $a(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+=De);let f=t*n,u=f+Math.abs(a)-1,l=a===0,h=a<0,p=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:h,isNegF:p,offsetF:f}}var es=new WeakMap,Za=new WeakMap;function rs(e){return Za.get(e)||1}function za(e){if(e!==je)throw new Error("invalid wNAF")}var Xe=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>je;)r&De&&(n=n.add(o)),o=o.double(),r>>=De;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=ts(r,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=ts(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:l,isNegF:h,offsetF:p}=$a(n,a,i);n=c,u?s=s.add(Nr(h,r[p])):o=o.add(Nr(l,r[f]))}return za(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=ts(t,this.bits);for(let i=0;i<s.windows&&n!==je;i++){let{nextN:a,offset:c,isZero:f,isNeg:u}=$a(n,i,s);if(n=a,!f){let l=r[c];o=o.add(u?l.negate():l)}}return za(n),o}getPrecomputes(t,r,n){let o=es.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),es.set(r,o))),o}cached(t,r,n){let o=rs(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=rs(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Ya(r,this.bits),Za.set(t,r),es.delete(t)}hasCache(t){return rs(t)!==1}};function Wa(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>je||n>je;)r&De&&(s=s.add(o)),n&De&&(i=i.add(o)),o=o.double(),r>>=De,n>>=De;return{p1:s,p2:i}}function Ga(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Xo(t),t}else return We(e,{isLE:r})}function xn(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>je))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Ga(t.p,r.Fp,n),s=Ga(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function gn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var me=BigInt(0),ut=BigInt(1),ns=BigInt(2),Al=BigInt(8);function Il(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 ja(e,t={}){let r=xn("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;pe(t,{},{uvRatio:"function"});let a=ns<<BigInt(o.BYTES*8)-ut,c=S=>n.create(S),f=t.uvRatio||((S,x)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,x))}}catch{return{isValid:!1,value:me}}});if(!Il(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function u(S,x,I=!1){let g=I?ut:me;return Pr("coordinate "+S,x,g,a),x}function l(S){if(!(S instanceof d))throw new Error("EdwardsPoint expected")}let h=Ze((S,x)=>{let{X:I,Y:g,Z:_}=S,R=S.is0();x==null&&(x=R?Al:n.inv(_));let K=c(I*x),M=c(g*x),v=n.mul(_,x);if(R)return{x:me,y:ut};if(v!==ut)throw new Error("invZ was invalid");return{x:K,y:M}}),p=Ze(S=>{let{a:x,d:I}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:g,Y:_,Z:R,T:K}=S,M=c(g*g),v=c(_*_),w=c(R*R),N=c(w*w),V=c(M*x),L=c(w*c(V+v)),b=c(N+c(I*c(M*v)));if(L!==b)throw new Error("bad point: equation left != right (1)");let y=c(g*_),m=c(R*K);if(y!==m)throw new Error("bad point: equation left != right (2)");return!0});class d{static BASE=new d(s.Gx,s.Gy,ut,c(s.Gx*s.Gy));static ZERO=new d(me,ut,ut,me);static Fp=n;static Fn=o;X;Y;Z;T;constructor(x,I,g,_){this.X=u("x",x),this.Y=u("y",I),this.Z=u("z",g,!0),this.T=u("t",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(x){if(x instanceof d)throw new Error("extended point not allowed");let{x:I,y:g}=x||{};return u("x",I),u("y",g),new d(I,g,ut,c(I*g))}static fromBytes(x,I=!1){let g=n.BYTES,{a:_,d:R}=s;x=yn(U(x,g,"point")),re(I,"zip215");let K=yn(x),M=x[g-1];K[g-1]=M&-129;let v=_e(K),w=I?a:n.ORDER;Pr("point.y",v,me,w);let N=c(v*v),V=c(N-ut),L=c(R*N-_),{isValid:b,value:y}=f(V,L);if(!b)throw new Error("bad point: invalid y coordinate");let m=(y&ut)===ut,A=(M&128)!==0;if(!I&&y===me&&A)throw new Error("bad point: x=0 and x_0=1");return A!==m&&(y=c(-y)),d.fromAffine({x:y,y:v})}static fromHex(x,I=!1){return d.fromBytes(te(x),I)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,I=!0){return E.createCache(this,x),I||this.multiply(ns),this}assertValidity(){p(this)}equals(x){l(x);let{X:I,Y:g,Z:_}=this,{X:R,Y:K,Z:M}=x,v=c(I*M),w=c(R*_),N=c(g*M),V=c(K*_);return v===w&&N===V}is0(){return this.equals(d.ZERO)}negate(){return new d(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:x}=s,{X:I,Y:g,Z:_}=this,R=c(I*I),K=c(g*g),M=c(ns*c(_*_)),v=c(x*R),w=I+g,N=c(c(w*w)-R-K),V=v+K,L=V-M,b=v-K,y=c(N*L),m=c(V*b),A=c(N*b),C=c(L*V);return new d(y,m,C,A)}add(x){l(x);let{a:I,d:g}=s,{X:_,Y:R,Z:K,T:M}=this,{X:v,Y:w,Z:N,T:V}=x,L=c(_*v),b=c(R*w),y=c(M*g*V),m=c(K*N),A=c((_+R)*(v+w)-L-b),C=m-y,B=m+y,T=c(b-I*L),D=c(A*C),O=c(B*T),k=c(A*T),tt=c(C*B);return new d(D,O,tt,k)}subtract(x){return this.add(x.negate())}multiply(x){if(!o.isValidNot0(x))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:I,f:g}=E.cached(this,x,_=>Be(d,_));return Be(d,[I,g])[0]}multiplyUnsafe(x,I=d.ZERO){if(!o.isValid(x))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return x===me?d.ZERO:this.is0()||x===ut?this:E.unsafe(this,x,g=>Be(d,g),I)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(x){return h(this,x)}clearCofactor(){return i===ut?this:this.multiplyUnsafe(i)}toBytes(){let{x,y:I}=this.toAffine(),g=n.toBytes(I);return g[g.length-1]|=x&ut?128:0,g}toHex(){return Jt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let E=new Xe(d,o.BITS);return d.BASE.precompute(8),d}function Xa(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');pe(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,a=r.randomBytes||Ge,c=r.adjustScalarBytes||(v=>v),f=r.domain||((v,w,N)=>{if(re(N,"phflag"),w.length||N)throw new Error("Contexts/pre-hash are not supported");return v});function u(v){return i.create(_e(v))}function l(v){let w=g.secretKey;U(v,g.secretKey,"secretKey");let N=U(t(v),2*w,"hashedSecretKey"),V=c(N.slice(0,w)),L=N.slice(w,2*w),b=u(V);return{head:V,prefix:L,scalar:b}}function h(v){let{head:w,prefix:N,scalar:V}=l(v),L=o.multiply(V),b=L.toBytes();return{head:w,prefix:N,scalar:V,point:L,pointBytes:b}}function p(v){return h(v).pointBytes}function d(v=Uint8Array.of(),...w){let N=At(...w);return u(t(f(N,U(v,void 0,"context"),!!n)))}function E(v,w,N={}){v=U(v,void 0,"message"),n&&(v=n(v));let{prefix:V,scalar:L,pointBytes:b}=h(w),y=d(N.context,V,v),m=o.multiply(y).toBytes(),A=d(N.context,m,b,v),C=i.create(y+A*L);if(!i.isValid(C))throw new Error("sign failed: invalid s");let B=At(m,i.toBytes(C));return U(B,g.signature,"result")}let S={zip215:!0};function x(v,w,N,V=S){let{context:L,zip215:b}=V,y=g.signature;v=U(v,y,"signature"),w=U(w,void 0,"message"),N=U(N,g.publicKey,"publicKey"),b!==void 0&&re(b,"zip215"),n&&(w=n(w));let m=y/2,A=v.subarray(0,m),C=_e(v.subarray(m,y)),B,T,D;try{B=e.fromBytes(N,b),T=e.fromBytes(A,b),D=o.multiplyUnsafe(C)}catch{return!1}if(!b&&B.isSmallOrder())return!1;let O=d(L,T.toBytes(),B.toBytes(),w);return T.add(B.multiplyUnsafe(O)).subtract(D).clearCofactor().is0()}let I=s.BYTES,g={secretKey:I,publicKey:I,signature:2*I,seed:I};function _(v=a(g.seed)){return U(v,g.seed,"seed")}function R(v){return Se(v)&&v.length===i.BYTES}function K(v,w){try{return!!e.fromBytes(v,w)}catch{return!1}}let M={getExtendedPublicKey:h,randomSecretKey:_,isValidSecretKey:R,isValidPublicKey:K,toMontgomery(v){let{y:w}=e.fromBytes(v),N=g.publicKey,V=N===32;if(!V&&N!==57)throw new Error("only defined for 25519 and 448");let L=V?s.div(ut+w,ut-w):s.div(w-ut,w+ut);return s.toBytes(L)},toMontgomerySecret(v){let w=g.secretKey;U(v,w);let N=t(v.subarray(0,w));return c(N).subarray(0,w)}};return Object.freeze({keygen:gn(_,p),getPublicKey:p,sign:E,verify:x,utils:M,Point:e,lengths:g})}var _l=BigInt(1),Qa=BigInt(2);var Cl=BigInt(5),Dl=BigInt(8),os=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Bl={p:os,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Dl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Ll(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=os,a=e*e%s*e%s,c=X(a,Qa,s)*a%s,f=X(c,_l,s)*e%s,u=X(f,Cl,s)*f%s,l=X(u,t,s)*u%s,h=X(l,r,s)*l%s,p=X(h,n,s)*h%s,d=X(p,o,s)*p%s,E=X(d,o,s)*p%s,S=X(E,t,s)*u%s;return{pow_p_5_8:X(S,Qa,s)*e%s,b2:a}}function Tl(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ja=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Pl(e,t){let r=os,n=st(t*t*t,r),o=st(n*n*t,r),s=Ll(e*o).pow_p_5_8,i=st(e*n*s,r),a=st(t*i*i,r),c=i,f=st(i*Ja,r),u=a===e,l=a===st(-e,r),h=a===st(-e*Ja,r);return u&&(i=c),(l||h)&&(i=f),Ha(i,r)&&(i=st(-i,r)),{isValid:u||l,value:i}}var Ol=ja(Bl,{uvRatio:Pl});function Rl(e){return Xa(Ol,Ba,Object.assign({adjustScalarBytes:Tl},e))}var tc=Rl({});var kr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},wn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ec={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new wn("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 Dt=ec;var En=32;var ss,Nl=(async()=>{try{return await Dt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function kl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Dt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Dt.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 Ul(e,t,r){return tc.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function rc(e,t,r){return ss==null&&(ss=await Nl),ss?kl(e,t,r):Ul(e,t,r)}function vn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Sn=class{type="Ed25519";raw;constructor(t){this.raw=is(t,En)}toMultihash(){return Lt.digest(Ft(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=rc(this.raw,r,t);return vn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function as(e){return e=is(e,En),new Sn(e)}function is(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new Q(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Ml=Math.pow(2,7),Vl=Math.pow(2,14),Fl=Math.pow(2,21),cs=Math.pow(2,28),fs=Math.pow(2,35),us=Math.pow(2,42),ls=Math.pow(2,49),Y=128,yt=127;function It(e){if(e<Ml)return 1;if(e<Vl)return 2;if(e<Fl)return 3;if(e<cs)return 4;if(e<fs)return 5;if(e<us)return 6;if(e<ls)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Qe(e,t,r=0){switch(It(e)){case 8:t[r++]=e&255|Y,e/=128;case 7:t[r++]=e&255|Y,e/=128;case 6:t[r++]=e&255|Y,e/=128;case 5:t[r++]=e&255|Y,e/=128;case 4:t[r++]=e&255|Y,e>>>=7;case 3:t[r++]=e&255|Y,e>>>=7;case 2:t[r++]=e&255|Y,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Hl(e,t,r=0){switch(It(e)){case 8:t.set(r++,e&255|Y),e/=128;case 7:t.set(r++,e&255|Y),e/=128;case 6:t.set(r++,e&255|Y),e/=128;case 5:t.set(r++,e&255|Y),e/=128;case 4:t.set(r++,e&255|Y),e>>>=7;case 3:t.set(r++,e&255|Y),e>>>=7;case 2:t.set(r++,e&255|Y),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function ds(e,t){let r=e[t],n=0;if(n+=r&yt,r<Y||(r=e[t+1],n+=(r&yt)<<7,r<Y)||(r=e[t+2],n+=(r&yt)<<14,r<Y)||(r=e[t+3],n+=(r&yt)<<21,r<Y)||(r=e[t+4],n+=(r&yt)*cs,r<Y)||(r=e[t+5],n+=(r&yt)*fs,r<Y)||(r=e[t+6],n+=(r&yt)*us,r<Y)||(r=e[t+7],n+=(r&yt)*ls,r<Y))return n;throw new RangeError("Could not decode varint")}function ql(e,t){let r=e.get(t),n=0;if(n+=r&yt,r<Y||(r=e.get(t+1),n+=(r&yt)<<7,r<Y)||(r=e.get(t+2),n+=(r&yt)<<14,r<Y)||(r=e.get(t+3),n+=(r&yt)<<21,r<Y)||(r=e.get(t+4),n+=(r&yt)*cs,r<Y)||(r=e.get(t+5),n+=(r&yt)*fs,r<Y)||(r=e.get(t+6),n+=(r&yt)*us,r<Y)||(r=e.get(t+7),n+=(r&yt)*ls,r<Y))return n;throw new RangeError("Could not decode varint")}function Je(e,t,r=0){return t==null&&(t=vt(It(e))),t instanceof Uint8Array?Qe(e,t,r):Hl(e,t,r)}function Ur(e,t=0){return e instanceof Uint8Array?ds(e,t):ql(e,t)}var ps=new Float32Array([-0]),be=new Uint8Array(ps.buffer);function oc(e,t,r){ps[0]=e,t[r]=be[0],t[r+1]=be[1],t[r+2]=be[2],t[r+3]=be[3]}function sc(e,t){return be[0]=e[t],be[1]=e[t+1],be[2]=e[t+2],be[3]=e[t+3],ps[0]}var ms=new Float64Array([-0]),xt=new Uint8Array(ms.buffer);function ic(e,t,r){ms[0]=e,t[r]=xt[0],t[r+1]=xt[1],t[r+2]=xt[2],t[r+3]=xt[3],t[r+4]=xt[4],t[r+5]=xt[5],t[r+6]=xt[6],t[r+7]=xt[7]}function ac(e,t){return xt[0]=e[t],xt[1]=e[t+1],xt[2]=e[t+2],xt[3]=e[t+3],xt[4]=e[t+4],xt[5]=e[t+5],xt[6]=e[t+6],xt[7]=e[t+7],ms[0]}var $l=BigInt(Number.MAX_SAFE_INTEGER),zl=BigInt(Number.MIN_SAFE_INTEGER),Ct=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 Le;if(t<$l&&t>zl)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>cc&&(o=0n,++n>cc&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Le;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):Le}},Le=new Ct(0,0);Le.toBigInt=function(){return 0n};Le.zzEncode=Le.zzDecode=function(){return this};Le.length=function(){return 1};var cc=4294967296n;function fc(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 uc(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 bs(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Pt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function An(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ys=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,Pt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Pt(this,4);return An(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pt(this,4);return An(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pt(this,4);let t=sc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Pt(this,4);let t=ac(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Pt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return uc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Pt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Ct(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Pt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Pt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Pt(this,8);let t=An(this.buf,this.pos+=4),r=An(this.buf,this.pos+=4);return new Ct(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=ds(this.buf,this.pos);return this.pos+=It(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Kr(e){return new ys(e instanceof Uint8Array?e:e.subarray())}function Ot(e,t,r){let n=Kr(e);return t.decode(n,void 0,r)}function xs(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return vt(i);o+i>t&&(n=vt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Te=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function gs(){}var Es=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Gl=xs();function Yl(e){return globalThis.Buffer!=null?vt(e):Gl(e)}var Vr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Te(gs,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Te(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new vs((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(In,10,Ct.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Ct.fromBigInt(t);return this._push(In,r.length(),r)}uint64Number(t){return this._push(Qe,It(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Ct.fromBigInt(t).zzEncode();return this._push(In,r.length(),r)}sint64Number(t){let r=Ct.fromNumber(t).zzEncode();return this._push(In,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ws,1,t?1:0)}fixed32(t){return this._push(Mr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Ct.fromBigInt(t);return this._push(Mr,4,r.lo)._push(Mr,4,r.hi)}fixed64Number(t){let r=Ct.fromNumber(t);return this._push(Mr,4,r.lo)._push(Mr,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(oc,4,t)}double(t){return this._push(ic,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ws,1,0):this.uint32(r)._push(Wl,r,t)}string(t){let r=fc(t);return r!==0?this.uint32(r)._push(bs,r,t):this._push(ws,1,0)}fork(){return this.states=new Es(this),this.head=this.tail=new Te(gs,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 Te(gs,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=Yl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ws(e,t,r){t[r]=e&255}function Zl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var vs=class extends Te{next;constructor(t,r){super(Zl,t,r),this.next=void 0}};function In(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 Mr(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 Wl(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(jl,t,e),this},Vr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Xl,t,e),this});function jl(e,t,r){t.set(e,r)}function Xl(e,t,r){e.length<40?bs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(F(e),r)}function Ss(){return new Vr}function Rt(e,t){let r=Ss();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Nt(e,t,r){let n=Kr(e);yield*t.stream(n,void 0,"$",r)}var _n={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Cn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function As(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return Cn("enum",_n.VARINT,r,n,o)}function kt(e,t,r){return Cn("message",_n.LENGTH_DELIMITED,e,t,r)}var $t=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 Is;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Is||(Is={}));(function(e){e.codec=()=>As(Is)})(J||(J={}));var zt;(function(e){let t;e.codec=()=>(t==null&&(t=kt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),J.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=J.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Rt(s,e.codec())}e.encode=r;function n(s,i){return Ot(s,e.codec(),i)}e.decode=n;function o(s,i){return Nt(s,e.codec(),i)}e.stream=o})(zt||(zt={}));var _s;(function(e){let t;e.codec=()=>(t==null&&(t=kt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),J.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=J.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Rt(s,e.codec())}e.encode=r;function n(s,i){return Ot(s,e.codec(),i)}e.decode=n;function o(s,i){return Nt(s,e.codec(),i)}e.stream=o})(_s||(_s={}));function Ql(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function Cs(e,t,r=""){let n=Ql(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`,f=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(f):new TypeError(f)}return e}function Ds(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 hc(e,t){Cs(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function Fr(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Dn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ut(e,t){return e<<32-t|e>>>t}function pc(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}var mc=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});var qr={};Et(qr,{MAX_RSA_KEY_SIZE:()=>Ts,generateRSAKeyPair:()=>Ec,jwkToJWKKeyPair:()=>vc,jwkToPkcs1:()=>nd,jwkToPkix:()=>Ns,jwkToRSAPrivateKey:()=>Ms,pkcs1MessageToJwk:()=>Os,pkcs1MessageToRSAPrivateKey:()=>ks,pkcs1ToJwk:()=>rd,pkcs1ToRSAPrivateKey:()=>wc,pkixMessageToJwk:()=>Rs,pkixMessageToRSAPublicKey:()=>Ks,pkixToJwk:()=>od,pkixToRSAPublicKey:()=>Us});function bc(e,t,r){return e&t^~e&r}function yc(e,t,r){return e&t^e&r^t&r}var Bn=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Dn(this.buffer)}update(t){Ds(this),Cs(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=Dn(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){Ds(this),hc(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Fr(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Dn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},ne=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Jl=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]),ye=new Uint32Array(64),Bs=class extends Bn{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)ye[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let h=ye[l-15],p=ye[l-2],d=Ut(h,7)^Ut(h,18)^h>>>3,E=Ut(p,17)^Ut(p,19)^p>>>10;ye[l]=E+ye[l-7]+d+ye[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let h=Ut(a,6)^Ut(a,11)^Ut(a,25),p=u+h+bc(a,c,f)+Jl[l]+ye[l]|0,E=(Ut(n,2)^Ut(n,13)^Ut(n,22))+yc(n,o,s)|0;u=f,f=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,f,u)}roundClean(){Fr(ye)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Fr(this.buffer)}},Ls=class extends Bs{A=ne[0]|0;B=ne[1]|0;C=ne[2]|0;D=ne[3]|0;E=ne[4]|0;F=ne[5]|0;G=ne[6]|0;H=ne[7]|0;constructor(){super(32)}};var Ln=pc(()=>new Ls,mc(1));var tr=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=qr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return at.createV1(114,this._multihash)}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){return gc(this.jwk,r,t,n)}},Hr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=qr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t,r){return xc(this.jwk,t,r)}};var Ts=8192,Ps=18,td=1062,ed=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function rd(e){let t=jt(e);return Os(t)}function Os(e){return{n:q(e[1],"base64url"),e:q(e[2],"base64url"),d:q(e[3],"base64url"),p:q(e[4],"base64url"),q:q(e[5],"base64url"),dp:q(e[6],"base64url"),dq:q(e[7],"base64url"),qi:q(e[8],"base64url"),kty:"RSA"}}function nd(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new Q("JWK was missing components");return ue([St(Uint8Array.from([0])),St(F(e.n,"base64url")),St(F(e.e,"base64url")),St(F(e.d,"base64url")),St(F(e.p,"base64url")),St(F(e.q,"base64url")),St(F(e.dp,"base64url")),St(F(e.dq,"base64url")),St(F(e.qi,"base64url"))]).subarray()}function od(e){let t=jt(e,{offset:0});return Rs(t)}function Rs(e){let t=jt(e[1],{offset:0});return{kty:"RSA",n:q(t[0],"base64url"),e:q(t[1],"base64url")}}function Ns(e){if(e.n==null||e.e==null)throw new Q("JWK was missing components");return ue([ed,ln(ue([St(F(e.n,"base64url")),St(F(e.e,"base64url"))]))]).subarray()}function wc(e){let t=jt(e);return ks(t)}function ks(e){let t=Os(e);return Ms(t)}function Us(e,t){if(e.byteLength>=td)throw new Me("Key size is too large");let r=jt(e,{offset:0});return Ks(r,e,t)}function Ks(e,t,r){let n=Rs(e);if(r==null){let o=Ln(zt.encode({Type:J.RSA,Data:t}));r=Vt(Ps,o)}return new tr(n,r)}function Ms(e){if(Ac(e)>Ts)throw new Q("Key size is too large");let t=vc(e),r=Ln(zt.encode({Type:J.RSA,Data:Ns(t.publicKey)})),n=Vt(Ps,r);return new Hr(t.privateKey,new tr(t.publicKey,n))}async function Ec(e){if(e>Ts)throw new Q("Key size is too large");let t=await Sc(e),r=Ln(zt.encode({Type:J.RSA,Data:Ns(t.publicKey)})),n=Vt(Ps,r);return new Hr(t.privateKey,new tr(t.publicKey,n))}function vc(e){if(e==null)throw new Q("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Sc(e,t){let r=await Dt.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 sd(r,t);return{privateKey:n[0],publicKey:n[1]}}async function xc(e,t,r){let n=await Dt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Dt.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 gc(e,t,r,n){let o=await Dt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Dt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function sd(e,t){if(e.privateKey==null||e.publicKey==null)throw new Q("Private and public key are required");let r=await Promise.all([Dt.get().subtle.exportKey("jwk",e.privateKey),Dt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function Ac(e){if(e.kty!=="RSA")throw new Q("invalid key type");if(e.n==null)throw new Q("invalid key modulus");return F(e.n,"base64url").length*8}var Tn=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(dn(t),U(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Qt(o)}update(t){return ze(this),this.iHash.update(t),this}digestInto(t){ze(this),U(t,this.outputLen,"output"),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||=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()}},Vs=(e,t,r)=>new Tn(e,t).update(r).digest();Vs.create=(e,t)=>new Tn(e,t);var Ic=(e,t)=>(e+(e>=0?t:-t)/_c)/t;function id(e,t,r){let[[n,o],[s,i]]=t,a=Ic(i*e,r),c=Ic(-o*e,r),f=e-a*n-c*s,u=-a*o-c*i,l=f<oe,h=u<oe;l&&(f=-f),h&&(u=-u);let p=Or(Math.ceil(Zo(r)/2))+er;if(f<oe||f>=p||u<oe||u>=p)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:h,k2:u}}function Hs(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Fs(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return re(r.lowS,"lowS"),re(r.prehash,"prehash"),r.format!==void 0&&Hs(r.format),r}var qs=class extends Error{constructor(t=""){super(t)}},xe={Err:qs,_tlv:{encode:(e,t)=>{let{Err:r}=xe;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=Tr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Tr(o.length/2|128):"";return Tr(e)+s+o+t},decode(e,t){let{Err:r}=xe,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 f=t.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;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}=xe;if(e<oe)throw new t("integer: negative integers are not allowed");let r=Tr(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}=xe;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 Ye(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=xe,o=U(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=xe,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},oe=BigInt(0),er=BigInt(1),_c=BigInt(2),Pn=BigInt(3),ad=BigInt(4);function Cc(e,t={}){let r=xn("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;pe(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=Bc(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(L,b,y){let{x:m,y:A}=b.toAffine(),C=n.toBytes(m);if(re(y,"isCompressed"),y){u();let B=!n.isOdd(A);return At(Dc(B),C)}else return At(Uint8Array.of(4),C,n.toBytes(A))}function h(L){U(L,void 0,"Point");let{publicKey:b,publicKeyUncompressed:y}=f,m=L.length,A=L[0],C=L.subarray(1);if(m===b&&(A===2||A===3)){let B=n.fromBytes(C);if(!n.isValid(B))throw new Error("bad point: is not on curve, wrong x");let T=E(B),D;try{D=n.sqrt(T)}catch(tt){let j=tt instanceof Error?": "+tt.message:"";throw new Error("bad point: is not on curve, sqrt error"+j)}u();let O=n.isOdd(D);return(A&1)===1!==O&&(D=n.neg(D)),{x:B,y:D}}else if(m===y&&A===4){let B=n.BYTES,T=n.fromBytes(C.subarray(0,B)),D=n.fromBytes(C.subarray(B,B*2));if(!S(T,D))throw new Error("bad point: is not on curve");return{x:T,y:D}}else throw new Error(`bad point: got length ${m}, expected compressed=${b} or uncompressed=${y}`)}let p=t.toBytes||l,d=t.fromBytes||h;function E(L){let b=n.sqr(L),y=n.mul(b,L);return n.add(n.add(y,n.mul(L,s.a)),s.b)}function S(L,b){let y=n.sqr(b),m=E(L);return n.eql(y,m)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(s.a,Pn),ad),I=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(x,I)))throw new Error("bad curve params: a or b");function g(L,b,y=!1){if(!n.isValid(b)||y&&n.is0(b))throw new Error(`bad point coordinate ${L}`);return b}function _(L){if(!(L instanceof w))throw new Error("Weierstrass Point expected")}function R(L){if(!c||!c.basises)throw new Error("no endo");return id(L,c.basises,o.ORDER)}let K=Ze((L,b)=>{let{X:y,Y:m,Z:A}=L;if(n.eql(A,n.ONE))return{x:y,y:m};let C=L.is0();b==null&&(b=C?n.ONE:n.inv(A));let B=n.mul(y,b),T=n.mul(m,b),D=n.mul(A,b);if(C)return{x:n.ZERO,y:n.ZERO};if(!n.eql(D,n.ONE))throw new Error("invZ was invalid");return{x:B,y:T}}),M=Ze(L=>{if(L.is0()){if(t.allowInfinityPoint&&!n.is0(L.Y))return;throw new Error("bad point: ZERO")}let{x:b,y}=L.toAffine();if(!n.isValid(b)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!S(b,y))throw new Error("bad point: equation left != right");if(!L.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function v(L,b,y,m,A){return y=new w(n.mul(y.X,L),y.Y,y.Z),b=Nr(m,b),y=Nr(A,y),b.add(y)}class w{static BASE=new w(s.Gx,s.Gy,n.ONE);static ZERO=new w(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(b,y,m){this.X=g("x",b),this.Y=g("y",y,!0),this.Z=g("z",m),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){let{x:y,y:m}=b||{};if(!b||!n.isValid(y)||!n.isValid(m))throw new Error("invalid affine point");if(b instanceof w)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(m)?w.ZERO:new w(y,m,n.ONE)}static fromBytes(b){let y=w.fromAffine(d(U(b,void 0,"point")));return y.assertValidity(),y}static fromHex(b){return w.fromBytes(te(b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,y=!0){return V.createCache(this,b),y||this.multiply(Pn),this}assertValidity(){M(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){_(b);let{X:y,Y:m,Z:A}=this,{X:C,Y:B,Z:T}=b,D=n.eql(n.mul(y,T),n.mul(C,A)),O=n.eql(n.mul(m,T),n.mul(B,A));return D&&O}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:y}=s,m=n.mul(y,Pn),{X:A,Y:C,Z:B}=this,T=n.ZERO,D=n.ZERO,O=n.ZERO,k=n.mul(A,A),tt=n.mul(C,C),j=n.mul(B,B),$=n.mul(A,C);return $=n.add($,$),O=n.mul(A,B),O=n.add(O,O),T=n.mul(b,O),D=n.mul(m,j),D=n.add(T,D),T=n.sub(tt,D),D=n.add(tt,D),D=n.mul(T,D),T=n.mul($,T),O=n.mul(m,O),j=n.mul(b,j),$=n.sub(k,j),$=n.mul(b,$),$=n.add($,O),O=n.add(k,k),k=n.add(O,k),k=n.add(k,j),k=n.mul(k,$),D=n.add(D,k),j=n.mul(C,B),j=n.add(j,j),k=n.mul(j,$),T=n.sub(T,k),O=n.mul(j,tt),O=n.add(O,O),O=n.add(O,O),new w(T,D,O)}add(b){_(b);let{X:y,Y:m,Z:A}=this,{X:C,Y:B,Z:T}=b,D=n.ZERO,O=n.ZERO,k=n.ZERO,tt=s.a,j=n.mul(s.b,Pn),$=n.mul(y,C),et=n.mul(m,B),dt=n.mul(A,T),Mt=n.add(y,m),rt=n.add(C,B);Mt=n.mul(Mt,rt),rt=n.add($,et),Mt=n.sub(Mt,rt),rt=n.add(y,A);let bt=n.add(C,T);return rt=n.mul(rt,bt),bt=n.add($,dt),rt=n.sub(rt,bt),bt=n.add(m,A),D=n.add(B,T),bt=n.mul(bt,D),D=n.add(et,dt),bt=n.sub(bt,D),k=n.mul(tt,rt),D=n.mul(j,dt),k=n.add(D,k),D=n.sub(et,k),k=n.add(et,k),O=n.mul(D,k),et=n.add($,$),et=n.add(et,$),dt=n.mul(tt,dt),rt=n.mul(j,rt),et=n.add(et,dt),dt=n.sub($,dt),dt=n.mul(tt,dt),rt=n.add(rt,dt),$=n.mul(et,rt),O=n.add(O,$),$=n.mul(bt,rt),D=n.mul(Mt,D),D=n.sub(D,$),$=n.mul(Mt,et),k=n.mul(bt,k),k=n.add(k,$),new w(D,O,k)}subtract(b){return this.add(b.negate())}is0(){return this.equals(w.ZERO)}multiply(b){let{endo:y}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let m,A,C=B=>V.cached(this,B,T=>Be(w,T));if(y){let{k1neg:B,k1:T,k2neg:D,k2:O}=R(b),{p:k,f:tt}=C(T),{p:j,f:$}=C(O);A=tt.add($),m=v(y.beta,k,j,B,D)}else{let{p:B,f:T}=C(b);m=B,A=T}return Be(w,[m,A])[0]}multiplyUnsafe(b){let{endo:y}=t,m=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===oe||m.is0())return w.ZERO;if(b===er)return m;if(V.hasCache(this))return this.multiply(b);if(y){let{k1neg:A,k1:C,k2neg:B,k2:T}=R(b),{p1:D,p2:O}=Wa(w,m,C,T);return v(y.beta,D,O,A,B)}else return V.unsafe(m,b)}toAffine(b){return K(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return i===er?!0:b?b(w,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:b}=t;return i===er?this:b?b(w,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return re(b,"isCompressed"),this.assertValidity(),p(w,this,b)}toHex(b=!0){return Jt(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=o.BITS,V=new Xe(w,t.endo?Math.ceil(N/2):N);return w.BASE.precompute(8),w}function Dc(e){return Uint8Array.of(e?2:3)}function Bc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function cd(e,t={}){let{Fn:r}=e,n=t.randomBytes||Ge,o=Object.assign(Bc(e.Fp,r),{seed:Qo(r.ORDER)});function s(p){try{let d=r.fromBytes(p);return r.isValidNot0(d)}catch{return!1}}function i(p,d){let{publicKey:E,publicKeyUncompressed:S}=o;try{let x=p.length;return d===!0&&x!==E||d===!1&&x!==S?!1:!!e.fromBytes(p)}catch{return!1}}function a(p=n(o.seed)){return Jo(U(p,o.seed,"seed"),r.ORDER)}function c(p,d=!0){return e.BASE.multiply(r.fromBytes(p)).toBytes(d)}function f(p){let{secretKey:d,publicKey:E,publicKeyUncompressed:S}=o;if(!Se(p)||"_lengths"in r&&r._lengths||d===E)return;let x=U(p,void 0,"key").length;return x===E||x===S}function u(p,d,E=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(d)===!1)throw new Error("second arg must be public key");let S=r.fromBytes(p);return e.fromBytes(d).multiply(S).toBytes(E)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},h=gn(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:h,Point:e,utils:l,lengths:o})}function Lc(e,t,r={}){dn(t),pe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||Ge,o=r.hmac||((y,m)=>Vs(t,y,m)),{Fp:s,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:f,getPublicKey:u,getSharedSecret:l,utils:h,lengths:p}=cd(e,r),d={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},E=a*_c<s.ORDER;function S(y){let m=a>>er;return y>m}function x(y,m){if(!i.isValidNot0(m))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return m}function I(){if(E)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function g(y,m){Hs(m);let A=p.signature,C=m==="compact"?A:m==="recovered"?A+1:void 0;return U(y,C)}class _{r;s;recovery;constructor(m,A,C){if(this.r=x("r",m),this.s=x("s",A),C!=null){if(I(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(m,A=d.format){g(m,A);let C;if(A==="der"){let{r:O,s:k}=xe.toSig(U(m));return new _(O,k)}A==="recovered"&&(C=m[0],A="compact",m=m.subarray(1));let B=p.signature/2,T=m.subarray(0,B),D=m.subarray(B,B*2);return new _(i.fromBytes(T),i.fromBytes(D),C)}static fromHex(m,A){return this.fromBytes(te(m),A)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new _(this.r,this.s,m)}recoverPublicKey(m){let{r:A,s:C}=this,B=this.assertRecovery(),T=B===2||B===3?A+a:A;if(!s.isValid(T))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let D=s.toBytes(T),O=e.fromBytes(At(Dc((B&1)===0),D)),k=i.inv(T),tt=K(U(m,void 0,"msgHash")),j=i.create(-tt*k),$=i.create(C*k),et=e.BASE.multiplyUnsafe(j).add(O.multiplyUnsafe($));if(et.is0())throw new Error("invalid recovery: point at infinify");return et.assertValidity(),et}hasHighS(){return S(this.s)}toBytes(m=d.format){if(Hs(m),m==="der")return te(xe.hexFromSig(this));let{r:A,s:C}=this,B=i.toBytes(A),T=i.toBytes(C);return m==="recovered"?(I(),At(Uint8Array.of(this.assertRecovery()),B,T)):At(B,T)}toHex(m){return Jt(this.toBytes(m))}}let R=r.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let A=Ye(m),C=m.length*8-c;return C>0?A>>BigInt(C):A},K=r.bits2int_modN||function(m){return i.create(R(m))},M=Or(c);function v(y){return Pr("num < 2^"+c,y,oe,M),i.toBytes(y)}function w(y,m){return U(y,void 0,"message"),m?U(t(y),void 0,"prehashed message"):y}function N(y,m,A){let{lowS:C,prehash:B,extraEntropy:T}=Fs(A,d);y=w(y,B);let D=K(y),O=i.fromBytes(m);if(!i.isValidNot0(O))throw new Error("invalid private key");let k=[v(O),v(D)];if(T!=null&&T!==!1){let et=T===!0?n(p.secretKey):T;k.push(U(et,void 0,"extraEntropy"))}let tt=At(...k),j=D;function $(et){let dt=R(et);if(!i.isValidNot0(dt))return;let Mt=i.inv(dt),rt=e.BASE.multiply(dt).toAffine(),bt=i.create(rt.x);if(bt===oe)return;let rn=i.create(Mt*i.create(j+bt*O));if(rn===oe)return;let Ki=(rt.x===bt?0:2)|Number(rt.y&er),Mi=rn;return C&&S(rn)&&(Mi=i.neg(rn),Ki^=1),new _(bt,Mi,E?void 0:Ki)}return{seed:tt,k2sig:$}}function V(y,m,A={}){let{seed:C,k2sig:B}=N(y,m,A);return Pa(t.outputLen,i.BYTES,o)(C,B).toBytes(A.format)}function L(y,m,A,C={}){let{lowS:B,prehash:T,format:D}=Fs(C,d);if(A=U(A,void 0,"publicKey"),m=w(m,T),!Se(y)){let O=y instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+O)}g(y,D);try{let O=_.fromBytes(y,D),k=e.fromBytes(A);if(B&&O.hasHighS())return!1;let{r:tt,s:j}=O,$=K(m),et=i.inv(j),dt=i.create($*et),Mt=i.create(tt*et),rt=e.BASE.multiplyUnsafe(dt).add(k.multiplyUnsafe(Mt));return rt.is0()?!1:i.create(rt.x)===tt}catch{return!1}}function b(y,m,A={}){let{prehash:C}=Fs(A,d);return m=w(m,C),_.fromBytes(y,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:l,utils:h,lengths:p,Point:e,sign:V,verify:L,recoverPublicKey:b,Signature:_,hash:t})}var zs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},fd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Tc=BigInt(2);function ud(e){let t=zs.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=e*e*e%t,u=f*f*e%t,l=X(u,r,t)*u%t,h=X(l,r,t)*u%t,p=X(h,Tc,t)*f%t,d=X(p,o,t)*p%t,E=X(d,s,t)*d%t,S=X(E,a,t)*E%t,x=X(S,c,t)*S%t,I=X(x,a,t)*E%t,g=X(I,r,t)*u%t,_=X(g,i,t)*d%t,R=X(_,n,t)*f%t,K=X(R,Tc,t);if(!$s.eql($s.sqr(K),e))throw new Error("Cannot find square root");return K}var $s=We(zs.p,{sqrt:ud}),ld=Cc(zs,{Fp:$s,endo:fd}),rr=Lc(ld,Da);function Pc(e,t,r,n){let o=Ar.digest(r instanceof Uint8Array?r:r.subarray());if(vn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),rr.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new kr(String(s))});try{return n?.signal?.throwIfAborted(),rr.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new kr(String(s))}}var On=class{type="secp256k1";raw;_key;constructor(t){this._key=Rc(t),this.raw=Oc(this._key)}toMultihash(){return Lt.digest(Ft(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){return Pc(this._key,r,t,n)}};function Gs(e){return new On(e)}function Oc(e){return rr.Point.fromBytes(e).toBytes()}function Rc(e){try{return rr.Point.fromBytes(e),e}catch(t){throw new Me(String(t))}}function nr(e,t){let{Type:r,Data:n}=zt.decode(e),o=n??new Uint8Array;switch(r){case J.RSA:return Us(o,t);case J.Ed25519:return as(o);case J.secp256k1:return Gs(o);case J.ECDSA:return ko(o);default:throw new Ee}}function Nc(e){let{Type:t,Data:r}=zt.decode(e.digest),n=r??new Uint8Array;switch(t){case J.Ed25519:return as(n);case J.secp256k1:return Gs(n);case J.ECDSA:return ko(n);default:throw new Ee}}function Ft(e){return zt.encode({Type:J[e.type],Data:e.raw})}var $r;(function(e){let t;e.codec=()=>(t==null&&(t=kt((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:ht(0),payloadType:ht(0),payload:ht(0),signature:ht(0)},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Rt(s,e.codec())}e.encode=r;function n(s,i){return Ot(s,e.codec(),i)}e.decode=n;function o(s,i){return Nt(s,e.codec(),i)}e.stream=o})($r||($r={}));var Rn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Gt=class e{static createFromProtobuf=t=>{let r=$r.decode(t),n=nr(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=kc(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 Rn("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=$r.encode({publicKey:Ft(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:ct(this.marshal(),t.marshal())}async validate(t,r){let n=kc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},kc=(e,t,r)=>{let n=F(e),o=Je(n.byteLength),s=Je(t.length),i=Je(r.length);return new it(o,n,s,t,i,r)};var Uc=Symbol.for("nodejs.util.inspect.custom"),dd=114,zr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[ao]=!0;toString(){return this.string==null&&(this.string=ot.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(dd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ct(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ct(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Uc](){return`PeerId(${this.toString()})`}},Gr=class extends zr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Yr=class extends zr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Zr=class extends zr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},hd=2336,Wr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Lt.digest(F(this.url))}[Uc](){return`PeerId(${this.url})`}[ao]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(hd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=q(t)),t.toString()===this.toString())}};var pd=114,Kc=2336;function Mc(e){if(e.type==="Ed25519")return new Yr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new Zr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Gr({multihash:e.toCID().multihash,publicKey:e});throw new Ee}function Ys(e){if(bd(e))return new Gr({multihash:e});if(md(e))try{let t=Nc(e);if(t.type==="Ed25519")return new Yr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Zr({multihash:e,publicKey:t})}catch{let r=q(e.digest);return new Wr(new URL(r))}throw new sn("Supplied PeerID Multihash is invalid")}function Nn(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==pd&&e.code!==Kc)throw new on("Supplied PeerID CID is invalid");if(e.code===Kc){let t=q(e.multihash.digest);return new Wr(new URL(t))}return Ys(e.multihash)}function md(e){return e.code===Lt.code}function bd(e){return e.code===Ar.code}var mt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},se=class extends Error{static name="ValidationError";name="ValidationError"},kn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Un=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Kn=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",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,t);if(!Number.isNaN(h))return h});if(u===void 0)break;if(s*=t,s+=u,s>f||(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 Vc=45,yd=15,or=new Kn;function Mn(e){if(!(e.length>yd))return or.new(e).parseWith(()=>or.readIPv4Addr())}function Vn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Vc))return or.new(e).parseWith(()=>or.readIPv6Addr())}function sr(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>Vc)return;let r=or.new(e).parseWith(()=>or.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 ir(e){return!!Mn(e)}function Fn(e){return!!Vn(e)}function Ws(e){return t=>q(t,e)}function js(e){return t=>F(t,e)}function ar(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Pe(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Fc(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=F(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=Pe(n);return Wt([r,o],r.length+o.length)}function Hc(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=fe.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=Pe(n);return Wt([r,o],r.length+o.length)}function Xs(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=q(t,"base32"),o=ar(r);return`${n}:${o}`}var Qs=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new mt("Invalid byte value in IP address");t[n]=o}),t},qc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=ir(r[n]),i;s&&(i=Qs(r[n]),r[n]=q(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,q(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new mt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},$c=function(e){if(e.byteLength!==4)throw new mt("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},zc=function(e){if(e.byteLength!==16)throw new mt("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new mt(`Invalid IPv6 address "${r}"`)}};function Gc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new mt(`Invalid IPv6 address "${e}"`)}}var Zs=Object.values(Ir).map(e=>e.decoder),xd=(function(){let e=Zs[0].or(Zs[1]);return Zs.slice(2).forEach(t=>e=e.or(t)),e})();function Yc(e){return xd.decode(e)}function Zc(e){return t=>e.encoder.encode(t)}function gd(e){if(parseInt(e).toString()!==e)throw new se("Value must be an integer")}function wd(e){if(e<0)throw new se("Value must be a positive integer, or zero")}function Ed(e){return t=>{if(t>e)throw new se(`Value must be smaller than or equal to ${e}`)}}function vd(...e){return t=>{for(let r of e)r(t)}}var jr=vd(gd,wd,Ed(65535));var lt=-1,Js=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Un(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ae=new Js,kd=[{code:4,name:"ip4",size:32,valueToBytes:Qs,bytesToValue:$c,validate:e=>{if(!ir(e))throw new se(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Pe,bytesToValue:ar,validate:jr},{code:273,name:"udp",size:16,valueToBytes:Pe,bytesToValue:ar,validate:jr},{code:33,name:"dccp",size:16,valueToBytes:Pe,bytesToValue:ar,validate:jr},{code:41,name:"ip6",size:128,valueToBytes:qc,bytesToValue:zc,stringToValue:Gc,validate:e=>{if(!Fn(e))throw new se(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:lt},{code:43,name:"ipcidr",size:8,bytesToValue:Ws("base10"),valueToBytes:js("base10")},{code:53,name:"dns",size:lt},{code:54,name:"dns4",size:lt},{code:55,name:"dns6",size:lt},{code:56,name:"dnsaddr",size:lt},{code:132,name:"sctp",size:16,valueToBytes:Pe,bytesToValue:ar,validate:jr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:lt,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:lt,bytesToValue:Ws("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?js("base58btc")(e):at.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Xs,valueToBytes:Fc},{code:445,name:"onion3",size:296,bytesToValue:Xs,valueToBytes:Hc},{code:446,name:"garlic64",size:lt},{code:447,name:"garlic32",size:lt},{code:448,name:"tls"},{code:449,name:"sni",size:lt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:lt,bytesToValue:Zc(So),valueToBytes:Yc},{code:480,name:"http"},{code:481,name:"http-path",size:lt,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:lt}];kd.forEach(e=>{ae.addProtocol(e)});function Wc(e){let t=[],r=0;for(;r<e.length;){let n=Ur(e,r),o=ae.getProtocol(n),s=It(n),i=Ud(o,e,r+s),a=0;i>0&&o.size===lt&&(a=It(i));let c=s+a+i,f={code:n,name:o.name,bytes:e.subarray(r,r+c)};if(i>0){let u=r+s+a,l=e.subarray(u,u+i);f.value=o.bytesToValue?.(l)??q(l)}t.push(f),r+=c}return t}function jc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=ae.getProtocol(n.code),s=It(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??F(n.value),a=i.byteLength,o.size===lt&&(c=It(a)));let f=new Uint8Array(s+c+a),u=0;Qe(n.code,f,u),u+=s,i!=null&&(o.size===lt&&(Qe(a,f,u),u+=c),f.set(i,u)),n.bytes=f}r.push(n.bytes),t+=n.bytes.byteLength}return Wt(r,t)}function Xc(e){if(e.charAt(0)!=="/")throw new mt('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let c=ae.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new mt(`Component ${o} was missing value`);r="value"}else if(r==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new mt(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}t.push(f),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new mt("Incomplete multiaddr");return t}function Qc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=ae.getProtocol(t.code);if(r==null)throw new mt(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Ud(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Ur(t,r)}var Kd=Symbol.for("nodejs.util.inspect.custom"),pi=Symbol.for("@multiformats/multiaddr");function Md(e){if(e==null&&(e="/"),Jc(e))return e.getComponents();if(e instanceof Uint8Array)return Wc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Xc(e);if(Array.isArray(e))return e;throw new mt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Yn=class e{[pi]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Md(t),r.validate!==!1&&Vd(this)}get bytes(){return this.#r==null&&(this.#r=jc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Qc(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new kn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return ct(this.bytes,t.bytes)}[Kd](){return`Multiaddr(${this.toString()})`}};function Vd(e){e.getComponents().forEach(t=>{let r=ae.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Jc(e){return!!e?.[pi]}function Re(e){return new Yn(e)}var tf="libp2p-peer-record",ef=Uint8Array.from([3,1]);var Qr;(function(e){let t;(function(i){let a;i.codec=()=>(a==null&&(a=kt((l,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(h.uint32(10),h.bytes(l.multiaddr)),p.lengthDelimited!==!1&&h.ldelim()},(l,h,p={})=>{let d={multiaddr:ht(0)},E=h==null?l.len:l.pos+h;for(;l.pos<E;){let S=l.uint32();S>>>3===1?d.multiaddr=l.bytes():l.skipType(S&7)}return d},function*(l,h,p,d={}){let E=h==null?l.len:l.pos+h;for(;l.pos<E;){let S=l.uint32();S>>>3===1?yield{field:`${p}.multiaddr`,value:l.bytes()}:l.skipType(S&7)}})),a);function c(l){return Rt(l,i.codec())}i.encode=c;function f(l,h){return Ot(l,i.codec(),h)}i.decode=f;function u(l,h){return Nt(l,i.codec(),h)}i.stream=u})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=kt((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let f of i.addresses)a.uint32(26),e.AddressInfo.codec().encode(f,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let f={peerId:ht(0),seq:0n,addresses:[]},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{f.peerId=i.bytes();break}case 2:{f.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&f.addresses.length===c.limits.addresses)throw new $t('Decode error - repeated field "addresses" had too many elements');f.addresses.push(e.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return f},function*(i,a,c,f={}){let u={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let h=i.uint32();switch(h>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(f.limits?.addresses!=null&&u.addresses===f.limits.addresses)throw new $t('Streaming decode error - repeated field "addresses" had too many elements');for(let p of e.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:f.limits?.addresses$}))yield{...p,index:u.addresses};u.addresses++;break}default:{i.skipType(h&7);break}}}})),r);function n(i){return Rt(i,e.codec())}e.encode=n;function o(i,a){return Ot(i,e.codec(),a)}e.decode=o;function s(i,a){return Nt(i,e.codec(),a)}e.stream=s})(Qr||(Qr={}));function rf(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 Kt=class e{static createFromProtobuf=t=>{let r=Qr.decode(t),n=Ys(vr(r.peerId)),o=(r.addresses??[]).map(i=>Re(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=tf;static CODEC=ef;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=Qr.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||!rf(this.multiaddrs,t.multiaddrs))}};function Zn(e){let t=e.getComponents(),r={},n=0;if(t[n]?.name==="ip6zone"&&(r.zone=`${t[n].value}`,n++),t[n].name==="ip4"||t[n].name==="ip6"||t[n].name==="dns"||t[n].name==="dns4"||t[n].name==="dns6"?(r.type=t[n].name,r.host=t[n].value,n++):t[n].name==="dnsaddr"&&(r.type=t[n].name,r.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(r.protocol=t[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${t[n].value}`):r.type==="ip6"&&(r.cidr=`${t[n].value}`),n++),r.type==null||r.host==null)throw new Q(`Multiaddr ${e} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(r.sni=t[n+1].value,n+=2),r}function nf(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 of(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 mi(e){switch(e.length){case Ne:return e.join(".");case ke:{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 sf(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 af(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var Ne=4,ke=16,dg=parseInt("0xFFFF",16),Fd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Jr(e,t){t.length===ke&&e.length===Ne&&nf(t,0,11)&&(t=t.slice(12)),t.length===Ne&&e.length===ke&&of(e,Fd,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 cf(e,t){if(typeof t=="string"&&(t=sr(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 bi(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=Ne,o=Mn(t);if(o==null&&(n=ke,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=yi(s,8*n);return{network:Jr(o,i),mask:i}}function yi(e,t){if(t!==8*Ne&&t!==8*ke)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 tn=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=bi(t));else{let n=sr(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=sr(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=yi(o,8*n.length);this.network=Jr(n,this.mask)}}contains(t){return cf({network:this.network,mask:this.mask},t)}toString(){let t=sf(this.mask),r=t!==-1?String(t):af(this.mask);return mi(this.network)+"/"+r}};function ff(e,t){return new tn(e).contains(t)}function uf(e){try{let t=Zn(e);return t.type==="ip6"?ff("2000::/3",t.host):!1}catch{return!1}}var pf=Vf(hf(),1),Zd=["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"],Wd=Zd.map(e=>new pf.Netmask(e));function Ai(e){for(let t of Wd)if(t.contains(e))return!0;return!1}function jd(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function Xd(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 Ai(o)}function Qd(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function Jd(e){let t=e.split(":"),r=t[t.length-1];return Ai(r)}function th(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 mf(e){if(ir(e))return Ai(e);if(jd(e))return Xd(e);if(Qd(e))return Jd(e);if(Fn(e))return th(e)}function bf(e){try{let t=Zn(e);switch(t.type){case"ip4":case"ip6":return mf(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function mr(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Ii=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},yf=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function _i(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,u=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){h(yf(i));return}if(i&&(c=()=>{h(yf(i))},i.addEventListener("abort",c,{once:!0})),e.then(l,h),r===Number.POSITIVE_INFINITY)return;let p=new Ii;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(d){h(d)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?h(o):(p.message=o??`Promise timed out after ${r} milliseconds`,h(p))},r)}).finally(()=>{u.clear(),c&&i&&i.removeEventListener("abort",c)});return u.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},u}var eh=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function rh(e,t,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:f,removeListener:u}=eh(e),l=async(...p)=>{let d=r.multiArgs?p:p[0];if(r.filter)try{if(!await r.filter(d))return}catch(E){n(),i(E);return}c.push(d),r.count===c.length&&(n(),s(c))},h=(...p)=>{n(),i(r.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of a)u(p,l);for(let p of r.rejectionEvents)a.includes(p)||u(p,h)};for(let p of a)f(p,l);for(let p of r.rejectionEvents)a.includes(p)||f(p,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=_i(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function xf(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=rh(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function gf(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Ke=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function nh(e){return e.reason}async function Ci(e,t,r){if(t==null)return e;let n=r?.translateError??nh;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var sh=4194304,jn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Bi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Li=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ti=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function ih(e){return typeof e?.closeRead=="function"}function ah(e){return typeof e?.close=="function"}function Di(e){return ih(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:ah(e)?e.status!=="open":!1}function ch(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function fh(e,t){let r=t?.maxBufferSize??sh,n=new it,o,s=!1;if(!ch(e))throw new Q("Argument should be a Stream or a Multiaddr");let i=u=>{if(n.append(u.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}o?.resolve()};e.addEventListener("message",i);let a=u=>{u.error!=null?o?.reject(u.error):o?.resolve()};e.addEventListener("close",a);let c=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",c);let f={readBuffer:n,async read(u){if(s===!0)throw new jn("Stream was unwrapped");if(Di(e)){if(n.byteLength===0&&u?.bytes==null)return null;if(u?.bytes!=null&&n.byteLength<u.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new Ke(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let l=u?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await Ci(o.promise,u?.signal),Di(e)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let h=u?.bytes??n.byteLength;if(n.byteLength<h){if(Di(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,h),new Ke(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return f.read(u)}let p=n.sublist(0,h);return n.consume(h),p},async write(u,l){if(s===!0)throw new jn("Stream was unwrapped");e.send(u)||await xf(e,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return f}function uh(e,t={}){let r=fh(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=It(t.maxDataLength));let n=t?.lengthDecoder??Ur,o=t?.lengthEncoder??Je;return{async read(i){let a=-1,c=new it;for(;;){let u=await r.read({...i,bytes:1});if(u==null)break;c.append(u);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Bi("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Ti(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Li(`Message length too long - ${a} > ${t.maxDataLength}`);let f=await r.read({...i,bytes:a});if(f==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new Ke(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new Ke(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await r.write(new it(o(i.byteLength),i),a)},async writeV(i,a){let c=new it(...i.flatMap(f=>[o(f.byteLength),f]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function br(e,t){let r=uh(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}function lh(e){return e[Symbol.asyncIterator]!=null}function dh(e){if(lh(e))return(async()=>{for await(let t of e);})();for(let t of e);}var wf=dh;var Xn=globalThis.CustomEvent??Event;async function*Pi(e,t={}){let r=t.concurrency??1/0;r<1&&(r=1/0);let n=t.ordered??!1,o=new EventTarget,s=[],i=mr(),a=mr(),c=!1,f,u=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let d of e){if(s.length===r&&(i=mr(),await i.promise),u)break;let E={done:!1};s.push(E),d().then(S=>{E.done=!0,E.ok=!0,E.value=S,o.dispatchEvent(new Xn("task-complete"))},S=>{E.done=!0,E.err=S,o.dispatchEvent(new Xn("task-complete"))})}c=!0,o.dispatchEvent(new Xn("task-complete"))}catch(d){f=d,o.dispatchEvent(new Xn("task-complete"))}});function l(){return n?s[0]?.done:!!s.find(d=>d.done)}function*h(){for(;s.length>0&&s[0].done;){let d=s[0];if(s.shift(),d.ok)yield d.value;else throw u=!0,i.resolve(),d.err;i.resolve()}}function*p(){for(;l();)for(let d=0;d<s.length;d++)if(s[d].done){let E=s[d];if(s.splice(d,1),d--,E.ok)yield E.value;else throw u=!0,i.resolve(),E.err;i.resolve()}}for(;;){if(l()||(a=mr(),await a.promise),f!=null||(n?yield*h():yield*p(),f!=null))throw f;if(c&&s.length===0)break}}var Ef="0.1.0";var vf="id/push",Sf="1.0.0",Af="1.0.0";var we;(function(e){let t;e.codec=()=>(t==null&&(t=kt((s,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),s.protocolVersion!=null&&(i.uint32(42),i.string(s.protocolVersion)),s.agentVersion!=null&&(i.uint32(50),i.string(s.agentVersion)),s.publicKey!=null&&(i.uint32(10),i.bytes(s.publicKey)),s.listenAddrs!=null&&s.listenAddrs.length>0)for(let c of s.listenAddrs)i.uint32(18),i.bytes(c);if(s.observedAddr!=null&&(i.uint32(34),i.bytes(s.observedAddr)),s.protocols!=null&&s.protocols.length>0)for(let c of s.protocols)i.uint32(26),i.string(c);s.signedPeerRecord!=null&&(i.uint32(66),i.bytes(s.signedPeerRecord)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={listenAddrs:[],protocols:[]},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 5:{c.protocolVersion=s.string();break}case 6:{c.agentVersion=s.string();break}case 1:{c.publicKey=s.bytes();break}case 2:{if(a.limits?.listenAddrs!=null&&c.listenAddrs.length===a.limits.listenAddrs)throw new $t('Decode error - repeated field "listenAddrs" had too many elements');c.listenAddrs.push(s.bytes());break}case 4:{c.observedAddr=s.bytes();break}case 3:{if(a.limits?.protocols!=null&&c.protocols.length===a.limits.protocols)throw new $t('Decode error - repeated field "protocols" had too many elements');c.protocols.push(s.string());break}case 8:{c.signedPeerRecord=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f={listenAddrs:0,protocols:0},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 5:{yield{field:`${a}.protocolVersion`,value:s.string()};break}case 6:{yield{field:`${a}.agentVersion`,value:s.string()};break}case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{if(c.limits?.listenAddrs!=null&&f.listenAddrs===c.limits.listenAddrs)throw new $t('Streaming decode error - repeated field "listenAddrs" had too many elements');yield{field:`${a}.listenAddrs[]`,index:f.listenAddrs,value:s.bytes()},f.listenAddrs++;break}case 4:{yield{field:`${a}.observedAddr`,value:s.bytes()};break}case 3:{if(c.limits?.protocols!=null&&f.protocols===c.limits.protocols)throw new $t('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${a}.protocols[]`,index:f.protocols,value:s.string()},f.protocols++;break}case 8:{yield{field:`${a}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),t);function r(s){return Rt(s,e.codec())}e.encode=r;function n(s,i){return Ot(s,e.codec(),i)}e.decode=n;function o(s,i){return Nt(s,e.codec(),i)}e.stream=o})(we||(we={}));var _t={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function If(e){if(e!=null&&e.length>0)try{return Re(e)}catch{}}async function Qn(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:Re(c)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let c=nr(o.publicKey);if(!Mc(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,f=await Gt.openAndCertify(c,Kt.DOMAIN),u=Kt.createFromProtobuf(f.payload),l=Nn(f.publicKey.toCID());if(!u.peerId.equals(l))throw new Bt("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(u.peerId))throw new Bt("signing key does not match remote PeerId");let h;try{h=await e.get(u.peerId)}catch(p){if(p.name!=="NotFoundError")throw p}if(h!=null&&(s.metadata=h.metadata,h.peerRecordEnvelope!=null)){let p=Gt.createFromProtobuf(h.peerRecordEnvelope),d=Kt.createFromProtobuf(p.payload);d.seqNumber>=u.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",d.seqNumber,u.seqNumber),u=d,c=h.peerRecordEnvelope)}s.peerRecordEnvelope=c,s.addresses=u.multiaddrs.map(p=>({isCertified:!0,multiaddr:p})),i={seq:u.seqNumber,addresses:u.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=F(o.agentVersion)),o.protocolVersion!=null&&(c.ProtocolVersion=F(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=>Re(c)),observedAddr:o.observedAddr==null?void 0:Re(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:a}),a}var yr=class{host;components;protocol;started;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;runOnLimitedConnection;log;constructor(t,r){this.protocol=r.protocol,this.started=!1,this.components=t,this.log=r.log,this.timeout=r.timeout??_t.timeout,this.maxInboundStreams=r.maxInboundStreams??_t.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??_t.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??_t.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??_t.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??_t.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??_t.protocolPrefix}/${Ef}`,agentVersion:t.nodeInfo.userAgent},this.handleProtocol=this.handleProtocol.bind(this)}isStarted(){return this.started}async start(){this.started||(await this.components.peerStore.merge(this.components.peerId,{metadata:{AgentVersion:F(this.host.agentVersion),ProtocolVersion:F(this.host.protocolVersion)}}),await this.components.registrar.handle(this.protocol,this.handleProtocol,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}};var Jn=class extends yr{connectionManager;concurrency;_push;constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??_t.protocolPrefix}/${vf}/${Af}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=r.concurrency??_t.concurrency,this._push=gf(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??_t.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[an]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let t=this.components.addressManager.getAddresses().map(u=>u.decapsulateCode(421)),r=new Kt({peerId:this.components.peerId,multiaddrs:t}),n=await Gt.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=q(s.metadata.get("AgentVersion")??F(this.host.agentVersion)),a=q(s.metadata.get("ProtocolVersion")??F(this.host.protocolVersion)),c=this;async function*f(){for(let u of c.connectionManager.getConnections())(await c.components.peerStore.get(u.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let h,p=AbortSignal.timeout(c.timeout);try{h=await u.newStream(c.protocol,{signal:p,runOnLimitedConnection:c.runOnLimitedConnection}),await br(h,{maxDataLength:c.maxMessageSize}).pb(we).write({listenAddrs:t.map(E=>E.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:p}),await h.close({signal:p})}catch(d){h?.log.newScope("identify-push")?.error("could not push identify update to peer",d),h?.abort(d)}})}await wf(Pi(f(),{concurrency:this.concurrency}))}catch(t){this.log.error("error pushing updates to peers - %e",t)}}async handleProtocol(t,r){let n=t.log.newScope("identify-push");if(this.components.peerId.equals(r.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},i=await br(t,{maxDataLength:this.maxMessageSize}).pb(we).read(o);await t.close(o),await Qn(this.components.peerStore,this.components.events,n,r,i),n.trace("handled push from %p",r.remotePeer)}};var Z=e=>({match:t=>{let r=t[0];return r==null||r.code!==e||r.value!=null?!1:t.slice(1)}}),P=(e,t)=>({match:r=>{let n=r[0];return n?.code!==e||n.value==null||t!=null&&n.value!==t?!1:r.slice(1)}}),_f=e=>({match:t=>e.match(t)===!1?t:!1}),H=e=>({match:t=>{let r=e.match(t);return r===!1?t:r}}),gt=(...e)=>({match:t=>{let r;for(let n of e){let o=n.match(t);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),G=(...e)=>({match:t=>{for(let r of e){let n=r.match(t);if(n===!1)return!1;t=n}return t}});function W(...e){function t(o){if(o==null)return!1;let s=o.getComponents();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 bh=P(421),Y1=W(bh),eo=P(54),ro=P(55),no=P(56),Ri=P(53),Z1=W(eo,H(P(421))),W1=W(ro,H(P(421))),j1=W(no,H(P(421))),X1=W(gt(Ri,no,eo,ro),H(P(421))),Cf=G(P(4),H(P(43))),Df=G(H(P(42)),P(41),H(P(43))),Ni=gt(Cf,Df),xr=gt(Ni,Ri,eo,ro,no),Bf=W(gt(Ni,G(gt(Ri,no,eo,ro),H(P(421))))),Q1=W(Cf),J1=W(Df),tw=W(Ni),ki=G(xr,P(6)),en=G(xr,P(273)),Lf=W(G(ki,H(P(421)))),ew=W(en),Ui=G(en,Z(460),H(P(421))),oo=G(en,Z(461),H(P(421))),yh=gt(Ui,oo),rw=W(Ui),nw=W(oo),Oi=gt(xr,ki,en,Ui,oo),Tf=gt(G(Oi,Z(477),H(P(421)))),ow=W(Tf),Pf=gt(G(Oi,Z(478),H(P(421))),G(Oi,Z(448),H(P(449)),Z(477),H(P(421)))),sw=W(Pf),Of=G(en,Z(280),H(P(466)),H(P(466)),H(P(421))),iw=W(Of),Rf=G(oo,Z(465),H(P(466)),H(P(466)),H(P(421))),aw=W(Rf),to=gt(Tf,Pf,G(ki,H(P(421))),G(yh,H(P(421))),G(xr,H(P(421))),Of,Rf,P(421)),cw=W(to),xh=G(H(to),Z(290),_f(Z(281)),H(P(421))),fw=W(xh),gh=gt(G(to,Z(290),Z(281),H(P(421))),G(to,Z(281),H(P(421))),G(Z(281),H(P(421)))),uw=W(gh),wh=G(xr,gt(G(P(6,"80")),G(P(6),Z(480)),Z(480)),H(P(481)),H(P(421))),lw=W(wh),Eh=G(xr,gt(G(P(6,"443")),G(P(6,"443"),Z(480)),G(P(6),Z(443)),G(P(6),Z(448),Z(480)),G(Z(448),Z(480)),Z(448),Z(443)),H(P(481)),H(P(421))),dw=W(Eh),vh=gt(G(P(777),H(P(421)))),hw=W(vh),Sh=gt(G(P(400),H(P(421)))),pw=W(Sh);var so=class extends yr{constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??_t.protocolPrefix}/${"id"}/${Sf}`,log:t.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??_t.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[an]=["@libp2p/identify"];async _identify(t,r={}){let n,o;if(r.signal==null){let s=AbortSignal.timeout(this.timeout);r={...r,signal:s}}this.log("run identify on new connection %a",t.remoteAddr);try{n=await t.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),o=n.log.newScope("identify");let s=br(n,{maxDataLength:this.maxMessageSize}).pb(we),i=await s.read(r);return await s.unwrap().unwrap().close(r),i}catch(s){throw o?.error("identify failed - %e",s),n?.abort(s),s}}async identify(t,r={}){let n=await this._identify(t,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Bt("Public key was missing from identify message");let a=nr(o),c=Nn(a.toCID());if(!t.remotePeer.equals(c))throw new Bt("Identified peer does not match the expected peer");if(this.components.peerId.equals(c))throw new Bt("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",c,s),Qn(this.components.peerStore,this.components.events,this.log,t,n)}maybeAddObservedAddress(t){let r=If(t);if(r==null||(this.log.trace("our observed address was %a",r),bf(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!uf(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Lf.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(t,r){let n=t.log.newScope("identify");n("responding to identify");let o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(u=>u.decapsulateCode(421)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let u=new Kt({peerId:this.components.peerId,multiaddrs:i});a=(await Gt.seal(u,this.components.privateKey,{signal:o})).marshal().subarray()}let c=r.remoteAddr.bytes;Bf.matches(r.remoteAddr)||(c=void 0);let f=br(t).pb(we);n("send response"),await f.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ft(this.components.privateKey.publicKey),listenAddrs:i.map(u=>u.bytes),signedPeerRecord:a,observedAddr:c,protocols:s.protocols},{signal:o}),n("close write"),await f.unwrap().unwrap().close({signal:o})}};function Ih(e={}){return t=>new so(t,e)}function _h(e={}){return t=>new Jn(t,e)}return Ff(Ch);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/utils.js: