@libp2p/peer-collections 6.0.35 → 7.0.0-55b7e5fea
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 +9 -10
- package/dist/index.min.js.map +4 -4
- package/dist/src/filter.js +1 -1
- package/dist/src/filter.js.map +1 -1
- package/package.json +8 -8
- package/src/filter.ts +2 -2
- package/dist/typedoc-urls.json +0 -16
package/dist/index.min.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPeerCollections = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PPeerCollections=(()=>{var qr=Object.defineProperty;var Bi=Object.getOwnPropertyDescriptor;var vi=Object.getOwnPropertyNames;var Ai=Object.prototype.hasOwnProperty;var at=(e,t)=>{for(var r in t)qr(e,r,{get:t[r],enumerable:!0})},Ii=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of vi(t))!Ai.call(e,o)&&o!==r&&qr(e,o,{get:()=>t[o],enumerable:!(n=Bi(t,o))||n.enumerable});return e};var Li=e=>Ii(qr({},"__esModule",{value:!0}),e);var mf={};at(mf,{PeerFilter:()=>or,PeerList:()=>Jt,PeerMap:()=>$t,PeerSet:()=>Wt,peerFilter:()=>wi,peerList:()=>yi,peerMap:()=>pi,peerSet:()=>mi,trackedPeerList:()=>Si,trackedPeerMap:()=>Ei,trackedPeerSet:()=>_i});var Vr=Symbol.for("@libp2p/peer-id");var vt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ir=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var cr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Ue=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Gr={};at(Gr,{base58btc:()=>Y,base58flickr:()=>ki});var xf=new Uint8Array(0);function wo(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function At(e){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 Eo(e){return new TextEncoder().encode(e)}function _o(e){return new TextDecoder().decode(e)}function Ci(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),u=Math.log(c)/Math.log(256),y=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,B=h.length;g!==B&&h[g]===0;)g++,E++;for(var w=(B-g)*y+1>>>0,T=new Uint8Array(w);g!==B;){for(var K=h[g],M=0,P=w-1;(K!==0||M<S)&&P!==-1;P--,M++)K+=256*T[P]>>>0,T[P]=K%c>>>0,K=K/c>>>0;if(K!==0)throw new Error("Non-zero carry");S=M,g++}for(var R=w-S;R!==w&&T[R]===0;)R++;for(var x=a.repeat(E);R<w;++R)x+=e.charAt(T[R]);return x}function f(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 B=(h.length-E)*u+1>>>0,w=new Uint8Array(B);h[E];){var T=r[h.charCodeAt(E)];if(T===255)return;for(var K=0,M=B-1;(T!==0||K<g)&&M!==-1;M--,K++)T+=c*w[M]>>>0,w[M]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");g=K,E++}if(h[E]!==" "){for(var P=B-g;P!==B&&w[P]===0;)P++;for(var R=new Uint8Array(S+(B-P)),x=S;P!==B;)R[x++]=w[P++];return R}}}function d(h){var E=f(h);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:f,decode:d}}var Ti=Ci,Ui=Ti,Bo=Ui;var zr=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")}},Fr=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 vo(this,t)}},jr=class{decoders;constructor(t){this.decoders=t}or(t){return vo(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 vo(e,t){return new jr({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Zr=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 zr(t,r,n),this.decoder=new Fr(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ue({name:e,prefix:t,encode:r,decode:n}){return new Zr(e,t,r,n)}function Ht({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Bo(r,e);return ue({prefix:t,name:e,encode:n,decode:s=>At(o(s))})}function Di(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let y=t[e[u]];if(y===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|y,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 Ki(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Ri(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Z({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Ri(n);return ue({prefix:t,name:e,encode(s){return Ki(s,n,r)},decode(s){return Di(s,o,r,e)}})}var Y=Ht({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ki=Ht({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Yr={};at(Yr,{base32:()=>he,base32hex:()=>Oi,base32hexpad:()=>qi,base32hexpadupper:()=>Vi,base32hexupper:()=>Hi,base32pad:()=>Pi,base32padupper:()=>Mi,base32upper:()=>Ni,base32z:()=>zi});var he=Z({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ni=Z({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Pi=Z({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Mi=Z({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Oi=Z({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Hi=Z({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),qi=Z({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Vi=Z({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),zi=Z({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Xr={};at(Xr,{base36:()=>De,base36upper:()=>Fi});var De=Ht({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Fi=Ht({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ji=Lo,Ao=128,Zi=127,Gi=~Zi,Yi=Math.pow(2,31);function Lo(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Yi;)t[r++]=e&255|Ao,e/=128;for(;e&Gi;)t[r++]=e&255|Ao,e>>>=7;return t[r]=e|0,Lo.bytes=r-n+1,t}var Xi=$r,$i=128,Io=127;function $r(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw $r.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Io)<<o:(i&Io)*Math.pow(2,o),o+=7}while(i>=$i);return $r.bytes=s-n,r}var Wi=Math.pow(2,7),Ji=Math.pow(2,14),Qi=Math.pow(2,21),tc=Math.pow(2,28),ec=Math.pow(2,35),rc=Math.pow(2,42),nc=Math.pow(2,49),oc=Math.pow(2,56),sc=Math.pow(2,63),ic=function(e){return e<Wi?1:e<Ji?2:e<Qi?3:e<tc?4:e<ec?5:e<rc?6:e<nc?7:e<oc?8:e<sc?9:10},cc={encode:ji,decode:Xi,encodingLength:ic},ac=cc,Ke=ac;function Re(e,t=0){return[Ke.decode(e,t),Ke.decode.bytes]}function le(e,t,r=0){return Ke.encode(e,t,r),t}function de(e){return Ke.encodingLength(e)}function me(e,t){let r=t.byteLength,n=de(e),o=n+de(r),s=new Uint8Array(o+r);return le(e,s,0),le(r,s,n),s.set(t,o),new pe(e,r,t,s)}function ke(e){let t=At(e),[r,n]=Re(t),[o,s]=Re(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new pe(r,o,i,t)}function Co(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&wo(e.bytes,r.bytes)}}var pe=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function To(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return uc(r,Wr(e),t??Y.encoder);default:return hc(r,Wr(e),t??he.encoder)}}var Uo=new WeakMap;function Wr(e){let t=Uo.get(e);if(t==null){let r=new Map;return Uo.set(e,r),r}return t}var it=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!==Ne)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==lc)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=me(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&&Co(t.multihash,n.multihash)}toString(t){return To(this,t)}toJSON(){return{"/":To(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??Do(n,o,s.bytes))}else if(r[dc]===!0){let{version:n,multihash:o,code:s}=r,i=ke(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!==Ne)throw new Error(`Version 0 CID must use dag-pb (code: ${Ne}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Do(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ne,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=At(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 pe(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,f]=Re(t.subarray(r));return r+=f,l},o=n(),s=Ne;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,y=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:y,size:u}}static parse(t,r){let[n,o]=fc(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 Wr(s).set(n,t),s}};function fc(e,t){switch(e[0]){case"Q":{let r=t??Y;return[Y.prefix,r.decode(`${Y.prefix}${e}`)]}case Y.prefix:{let r=t??Y;return[Y.prefix,r.decode(e)]}case he.prefix:{let r=t??he;return[he.prefix,r.decode(e)]}case De.prefix:{let r=t??De;return[De.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 uc(e,t,r){let{prefix:n}=r;if(n!==Y.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 hc(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 Ne=112,lc=18;function Do(e,t,r){let n=de(e),o=n+de(t),s=new Uint8Array(o+r.byteLength);return le(e,s,0),le(t,s,n),s.set(r,o),s}var dc=Symbol.for("@ipld/js-cid/CID");var Jr={};at(Jr,{identity:()=>gt});var Ko=0,pc="identity",Ro=At;function mc(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 me(Ko,Ro(e))}var gt={code:Ko,name:pc,encode:Ro,digest:mc};function ft(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 xt(e=0){return new Uint8Array(e)}function ut(e=0){return new Uint8Array(e)}function fr(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ut(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var No=Symbol.for("@achingbrain/uint8arraylist");function ko(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 ur(e){return!!e?.[No]}var ht=class e{bufs;length;[No]=!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(ur(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(ur(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=ko(this.bufs,t);return r.buf[r.index]}set(t,r){let n=ko(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(ur(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 fr(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:fr(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,y=r>c&&r<=a;if(u&&y){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(y){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!ur(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 c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,y;for(let l=r;l<=a;l+=y){y=0;for(let f=u;f>=0;f--){let d=this.get(l+f);if(n[f]!==d){y=Math.max(1,f-c[d]);break}}if(y===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=ut(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=xt(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=xt(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=xt(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=ut(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=xt(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=xt(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=xt(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=xt(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=xt(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(!ft(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 Qr={};at(Qr,{base10:()=>yc});var yc=Ht({prefix:"9",name:"base10",alphabet:"0123456789"});var tn={};at(tn,{base16:()=>bc,base16upper:()=>gc});var bc=Z({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),gc=Z({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var en={};at(en,{base2:()=>xc});var xc=Z({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var rn={};at(rn,{base256emoji:()=>Bc});var Po=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}"),wc=Po.reduce((e,t,r)=>(e[r]=t,e),[]),Ec=Po.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function _c(e){return e.reduce((t,r)=>(t+=wc[r],t),"")}function Sc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ec[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Bc=ue({prefix:"\u{1F680}",name:"base256emoji",encode:_c,decode:Sc});var nn={};at(nn,{base64:()=>vc,base64pad:()=>Ac,base64url:()=>Ic,base64urlpad:()=>Lc});var vc=Z({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ac=Z({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ic=Z({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Lc=Z({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var on={};at(on,{base8:()=>Cc});var Cc=Z({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var sn={};at(sn,{identity:()=>Tc});var Tc=ue({prefix:"\0",name:"identity",encode:e=>_o(e),decode:e=>Eo(e)});var ru=new TextEncoder,nu=new TextDecoder;var fn={};at(fn,{sha256:()=>Pe,sha512:()=>Rc});var Kc=20;function an({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new cn(e,t,r,n,o)}var cn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Kc,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?Mo(n,this.code,r?.truncate):n.then(o=>Mo(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Mo(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 me(t,e)}function Ho(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Pe=an({name:"sha2-256",code:18,encode:Ho("SHA-256")}),Rc=an({name:"sha2-512",code:19,encode:Ho("SHA-512")});var un={...sn,...en,...on,...Qr,...tn,...Yr,...Xr,...Gr,...nn,...rn},mu={...fn,...Jr};function Vo(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var qo=Vo("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),hn=Vo("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=ut(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),kc={utf8:qo,"utf-8":qo,hex:un.base16,latin1:hn,ascii:hn,binary:hn,...un},hr=kc;function $(e,t="utf8"){let r=hr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function yt(e,t="utf8"){let r=hr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Nc=parseInt("11111",2),ln=parseInt("10000000",2),Pc=parseInt("01111111",2),zo={0:Me,1:Me,2:Mc,3:qc,4:Vc,5:Hc,6:Oc,16:Me,22:Me,48:Me};function dn(e,t={offset:0}){let r=e[t.offset]&Nc;if(t.offset++,zo[r]!=null)return zo[r](e,t);throw new Error("No decoder for tag "+r)}function Oe(e,t){let r=0;if((e[t.offset]&ln)===ln){let n=e[t.offset]&Pc,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 Me(e,t){Oe(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=dn(e,t);if(n===null)break;r.push(n)}return r}function Mc(e,t){let r=Oe(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 Oc(e,t){let r=Oe(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let y=0;for(let l=0;l<a.length;l++)y+=a[l]<<l*7;c+=`.${y}`,a=[]}}return c}function Hc(e,t){return t.offset++,null}function qc(e,t){let r=Oe(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 Vc(e,t){let r=Oe(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function zc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new ht;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function pn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=zc(e.byteLength);return new ht(Uint8Array.from([t.byteLength|ln]),t)}function Fo(e){let t=new ht,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new ht(Uint8Array.from([2]),pn(t),t)}function jo(e){let t=Uint8Array.from([0]),r=new ht(t,e);return new ht(Uint8Array.from([3]),pn(r),r)}function lr(e,t=48){let r=new ht;for(let n of e)r.append(n);return new ht(Uint8Array.from([t]),pn(r),r)}async function Zo(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 Fc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),jc=Uint8Array.from([6,5,43,129,4,0,34]),Zc=Uint8Array.from([6,5,43,129,4,0,35]),Gc={ext:!0,kty:"EC",crv:"P-256"},Yc={ext:!0,kty:"EC",crv:"P-384"},Xc={ext:!0,kty:"EC",crv:"P-521"},mn=32,yn=48,bn=66;function Go(e){let t=dn(e);return Yo(t)}function Yo(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===mn*2+1)return n=yt(t.subarray(r,r+mn),"base64url"),o=yt(t.subarray(r+mn),"base64url"),new ye({...Gc,key_ops:["verify"],x:n,y:o});if(t.byteLength===yn*2+1)return n=yt(t.subarray(r,r+yn),"base64url"),o=yt(t.subarray(r+yn),"base64url"),new ye({...Yc,key_ops:["verify"],x:n,y:o});if(t.byteLength===bn*2+1)return n=yt(t.subarray(r,r+bn),"base64url"),o=yt(t.subarray(r+bn),"base64url"),new ye({...Xc,key_ops:["verify"],x:n,y:o});throw new vt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Xo(e){return lr([Fo(Uint8Array.from([1])),lr([$c(e.crv)],160),lr([jo(new ht(Uint8Array.from([4]),$(e.x??"","base64url"),$(e.y??"","base64url")))],161)]).subarray()}function $c(e){if(e==="P-256")return Fc;if(e==="P-384")return jc;if(e==="P-521")return Zc;throw new vt(`Invalid curve ${e}`)}var ye=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Xo(this.jwk)),this._raw}toMultihash(){return gt.digest(be(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}async verify(t,r,n){return Zo(this.jwk,r,t,n)}};var te=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Lt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function He(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ct(e,...t){if(!Lt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function dr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");He(e.outputLen),He(e.blockLen)}function xe(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 Wo(e,t){ct(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Ct(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function pr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function wt(e,t){return e<<32-t|e>>>t}var Jo=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Wc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function bt(e){if(ct(e),Jo)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Wc[e[r]];return t}var It={_0:48,_9:57,A:65,F:70,a:97,f:102};function $o(e){if(e>=It._0&&e<=It._9)return e-It._0;if(e>=It.A&&e<=It.F)return e-(It.A-10);if(e>=It.a&&e<=It.f)return e-(It.a-10)}function ee(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Jo)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=$o(e.charCodeAt(s)),c=$o(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function gn(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function qe(e){return typeof e=="string"&&(e=gn(e)),ct(e),e}function rt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];ct(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var ge=class{};function xn(e){let t=n=>e().update(qe(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function we(e=32){if(te&&typeof te.getRandomValues=="function")return te.getRandomValues(new Uint8Array(e));if(te&&typeof te.randomBytes=="function")return Uint8Array.from(te.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Jc(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),c=Number(r&s),a=n?4:0,u=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+u,c,n)}function Qo(e,t,r){return e&t^~e&r}function ts(e,t,r){return e&t^e&r^t&r}var Ve=class extends ge{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=pr(this.buffer)}update(t){xe(this),t=qe(t),ct(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=pr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){xe(this),Wo(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Ct(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;Jc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=pr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,y=this.get();if(u>y.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,y[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Tt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Q=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var mr=BigInt(4294967295),es=BigInt(32);function Qc(e,t=!1){return t?{h:Number(e&mr),l:Number(e>>es&mr)}:{h:Number(e>>es&mr)|0,l:Number(e&mr)|0}}function rs(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=Qc(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var wn=(e,t,r)=>e>>>r,En=(e,t,r)=>e<<32-r|t>>>r,re=(e,t,r)=>e>>>r|t<<32-r,ne=(e,t,r)=>e<<32-r|t>>>r,ze=(e,t,r)=>e<<64-r|t>>>r-32,Fe=(e,t,r)=>e>>>r-32|t<<64-r;function St(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ns=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),os=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ss=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),is=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,cs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),as=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var ea=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]),qt=new Uint32Array(64),_n=class extends Ve{constructor(t=32){super(64,t,8,!1),this.A=Tt[0]|0,this.B=Tt[1]|0,this.C=Tt[2]|0,this.D=Tt[3]|0,this.E=Tt[4]|0,this.F=Tt[5]|0,this.G=Tt[6]|0,this.H=Tt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)qt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let f=qt[l-15],d=qt[l-2],h=wt(f,7)^wt(f,18)^f>>>3,E=wt(d,17)^wt(d,19)^d>>>10;qt[l]=E+qt[l-7]+h+qt[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:y}=this;for(let l=0;l<64;l++){let f=wt(c,6)^wt(c,11)^wt(c,25),d=y+f+Qo(c,a,u)+ea[l]+qt[l]|0,E=(wt(n,2)^wt(n,13)^wt(n,22))+ts(n,o,s)|0;y=u,u=a,a=c,c=i+d|0,i=s,s=o,o=n,n=d+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,y=y+this.H|0,this.set(n,o,s,i,c,a,u,y)}roundClean(){Ct(qt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ct(this.buffer)}};var fs=rs(["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))),ra=fs[0],na=fs[1],Vt=new Uint32Array(80),zt=new Uint32Array(80),Sn=class extends Ve{constructor(t=64){super(128,t,16,!1),this.Ah=Q[0]|0,this.Al=Q[1]|0,this.Bh=Q[2]|0,this.Bl=Q[3]|0,this.Ch=Q[4]|0,this.Cl=Q[5]|0,this.Dh=Q[6]|0,this.Dl=Q[7]|0,this.Eh=Q[8]|0,this.El=Q[9]|0,this.Fh=Q[10]|0,this.Fl=Q[11]|0,this.Gh=Q[12]|0,this.Gl=Q[13]|0,this.Hh=Q[14]|0,this.Hl=Q[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:y,Fh:l,Fl:f,Gh:d,Gl:h,Hh:E,Hl:S}=this;return[t,r,n,o,s,i,c,a,u,y,l,f,d,h,E,S]}set(t,r,n,o,s,i,c,a,u,y,l,f,d,h,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=c|0,this.Dl=a|0,this.Eh=u|0,this.El=y|0,this.Fh=l|0,this.Fl=f|0,this.Gh=d|0,this.Gl=h|0,this.Hh=E|0,this.Hl=S|0}process(t,r){for(let w=0;w<16;w++,r+=4)Vt[w]=t.getUint32(r),zt[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let T=Vt[w-15]|0,K=zt[w-15]|0,M=re(T,K,1)^re(T,K,8)^wn(T,K,7),P=ne(T,K,1)^ne(T,K,8)^En(T,K,7),R=Vt[w-2]|0,x=zt[w-2]|0,L=re(R,x,19)^ze(R,x,61)^wn(R,x,6),k=ne(R,x,19)^Fe(R,x,61)^En(R,x,6),C=ss(P,k,zt[w-7],zt[w-16]),b=is(C,M,L,Vt[w-7],Vt[w-16]);Vt[w]=b|0,zt[w]=C|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:y,Eh:l,El:f,Fh:d,Fl:h,Gh:E,Gl:S,Hh:g,Hl:B}=this;for(let w=0;w<80;w++){let T=re(l,f,14)^re(l,f,18)^ze(l,f,41),K=ne(l,f,14)^ne(l,f,18)^Fe(l,f,41),M=l&d^~l&E,P=f&h^~f&S,R=cs(B,K,P,na[w],zt[w]),x=as(R,g,T,M,ra[w],Vt[w]),L=R|0,k=re(n,o,28)^ze(n,o,34)^ze(n,o,39),C=ne(n,o,28)^Fe(n,o,34)^Fe(n,o,39),b=n&s^n&c^s&c,p=o&i^o&a^i&a;g=E|0,B=S|0,E=d|0,S=h|0,d=l|0,h=f|0,{h:l,l:f}=St(u|0,y|0,x|0,L|0),u=c|0,y=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let m=ns(L,C,p);n=os(m,x,k,b),o=m|0}({h:n,l:o}=St(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=St(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=St(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:y}=St(this.Dh|0,this.Dl|0,u|0,y|0),{h:l,l:f}=St(this.Eh|0,this.El|0,l|0,f|0),{h:d,l:h}=St(this.Fh|0,this.Fl|0,d|0,h|0),{h:E,l:S}=St(this.Gh|0,this.Gl|0,E|0,S|0),{h:g,l:B}=St(this.Hh|0,this.Hl|0,g|0,B|0),this.set(n,o,s,i,c,a,u,y,l,f,d,h,E,S,g,B)}roundClean(){Ct(Vt,zt)}destroy(){Ct(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var us=xn(()=>new _n);var hs=xn(()=>new Sn);var An=BigInt(0),vn=BigInt(1);function Ut(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function lt(e,t,r=""){let n=Lt(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function je(e){let t=e.toString(16);return t.length&1?"0"+t:t}function ls(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?An:BigInt("0x"+e)}function Ee(e){return ls(bt(e))}function Dt(e){return ct(e),ls(bt(Uint8Array.from(e).reverse()))}function yr(e,t){return ee(e.toString(16).padStart(t*2,"0"))}function In(e,t){return yr(e,t).reverse()}function H(e,t,r){let n;if(typeof t=="string")try{n=ee(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Lt(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function ds(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function Ln(e){return Uint8Array.from(e)}var Bn=e=>typeof e=="bigint"&&An<=e;function ps(e,t,r){return Bn(e)&&Bn(t)&&Bn(r)&&t<=e&&e<r}function Ze(e,t,r,n){if(!ps(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function br(e){let t;for(t=0;e>An;e>>=vn,t+=1);return t}var Ft=e=>(vn<<BigInt(e))-vn;function ms(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=d=>new Uint8Array(d),o=d=>Uint8Array.of(d),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},u=(...d)=>r(i,s,...d),y=(d=n(0))=>{i=u(o(0),d),s=u(),d.length!==0&&(i=u(o(1),d),s=u())},l=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let d=0,h=[];for(;d<t;){s=u();let E=s.slice();h.push(E),d+=s.length}return rt(...h)};return(d,h)=>{a(),y(d);let E;for(;!(E=h(l()));)y();return a(),E}}function jt(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var Cn=()=>{throw new Error("not implemented")};function _e(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 nt=BigInt(0),W=BigInt(1),oe=BigInt(2),gs=BigInt(3),xs=BigInt(4),ws=BigInt(5),oa=BigInt(7),Es=BigInt(8),sa=BigInt(9),_s=BigInt(16);function G(e,t){let r=e%t;return r>=nt?r:t+r}function V(e,t,r){let n=e;for(;t-- >nt;)n*=n,n%=r;return n}function ys(e,t){if(e===nt)throw new Error("invert: expected non-zero number");if(t<=nt)throw new Error("invert: expected positive modulus, got "+t);let r=G(e,t),n=t,o=nt,s=W,i=W,c=nt;for(;r!==nt;){let u=n/r,y=n%r,l=o-i*u,f=s-c*u;n=r,r=y,o=i,s=c,i=l,c=f}if(n!==W)throw new Error("invert: does not exist");return G(o,t)}function Tn(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Ss(e,t){let r=(e.ORDER+W)/xs,n=e.pow(t,r);return Tn(e,n,t),n}function ia(e,t){let r=(e.ORDER-ws)/Es,n=e.mul(t,oe),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,oe),o),c=e.mul(s,e.sub(i,e.ONE));return Tn(e,c,t),c}function ca(e){let t=dt(e),r=Bs(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+oa)/_s;return(c,a)=>{let u=c.pow(a,i),y=c.mul(u,n),l=c.mul(u,o),f=c.mul(u,s),d=c.eql(c.sqr(y),a),h=c.eql(c.sqr(l),a);u=c.cmov(u,y,d),y=c.cmov(f,l,h);let E=c.eql(c.sqr(y),a),S=c.cmov(u,y,E);return Tn(c,S,a),S}}function Bs(e){if(e<gs)throw new Error("sqrt is not defined for small field");let t=e-W,r=0;for(;t%oe===nt;)t/=oe,r++;let n=oe,o=dt(e);for(;bs(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ss;let s=o.pow(n,t),i=(t+W)/oe;return function(a,u){if(a.is0(u))return u;if(bs(a,u)!==1)throw new Error("Cannot find square root");let y=r,l=a.mul(a.ONE,s),f=a.pow(u,t),d=a.pow(u,i);for(;!a.eql(f,a.ONE);){if(a.is0(f))return a.ZERO;let h=1,E=a.sqr(f);for(;!a.eql(E,a.ONE);)if(h++,E=a.sqr(E),h===y)throw new Error("Cannot find square root");let S=W<<BigInt(y-h-1),g=a.pow(l,S);y=h,l=a.sqr(g),f=a.mul(f,l),d=a.mul(d,g)}return d}}function aa(e){return e%xs===gs?Ss:e%Es===ws?ia:e%_s===sa?ca(e):Bs(e)}var Kt=(e,t)=>(G(e,t)&W)===W,fa=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Un(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=fa.reduce((n,o)=>(n[o]="function",n),t);return jt(e,r),e}function ua(e,t,r){if(r<nt)throw new Error("invalid exponent, negatives unsupported");if(r===nt)return e.ONE;if(r===W)return t;let n=e.ONE,o=t;for(;r>nt;)r&W&&(n=e.mul(n,o)),o=e.sqr(o),r>>=W;return n}function Ge(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function bs(e,t){let r=(e.ORDER-W)/oe,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 gr(e,t){t!==void 0&&He(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function dt(e,t,r=!1,n={}){if(e<=nt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s,i=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE),typeof f.modFromBytes=="boolean"&&(i=f.modFromBytes),c=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:a,nByteLength:u}=gr(e,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let y,l=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:u,MASK:Ft(a),ZERO:nt,ONE:W,allowedLengths:c,create:f=>G(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return nt<=f&&f<e},is0:f=>f===nt,isValidNot0:f=>!l.is0(f)&&l.isValid(f),isOdd:f=>(f&W)===W,neg:f=>G(-f,e),eql:(f,d)=>f===d,sqr:f=>G(f*f,e),add:(f,d)=>G(f+d,e),sub:(f,d)=>G(f-d,e),mul:(f,d)=>G(f*d,e),pow:(f,d)=>ua(l,f,d),div:(f,d)=>G(f*ys(d,e),e),sqrN:f=>f*f,addN:(f,d)=>f+d,subN:(f,d)=>f-d,mulN:(f,d)=>f*d,inv:f=>ys(f,e),sqrt:s||(f=>(y||(y=aa(e)),y(l,f))),toBytes:f=>r?In(f,u):yr(f,u),fromBytes:(f,d=!0)=>{if(c){if(!c.includes(f.length)||f.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+f.length);let E=new Uint8Array(u);E.set(f,r?0:E.length-f.length),f=E}if(f.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+f.length);let h=r?Dt(f):Ee(f);if(i&&(h=G(h,e)),!d&&!l.isValid(h))throw new Error("invalid field element: outside of range 0..ORDER");return h},invertBatch:f=>Ge(l,f),cmov:(f,d,h)=>h?d:f});return Object.freeze(l)}function vs(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 Dn(e){let t=vs(e);return t+Math.ceil(t/2)}function Kn(e,t,r=!1){let n=e.length,o=vs(t),s=Dn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Dt(e):Ee(e),c=G(i,t-W)+W;return r?In(c,o):yr(c,o)}var Se=BigInt(0),se=BigInt(1);function Ye(e,t){let r=t.negate();return e?r:t}function Rt(e,t){let r=Ge(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Cs(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Rn(e,t){Cs(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Ft(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function As(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=se);let u=t*n,y=u+Math.abs(c)-1,l=c===0,f=c<0,d=t%2!==0;return{nextN:a,offset:y,isZero:l,isNeg:f,isNegF:d,offsetF:u}}function ha(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function la(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var kn=new WeakMap,Ts=new WeakMap;function Nn(e){return Ts.get(e)||1}function Is(e){if(e!==Se)throw new Error("invalid wNAF")}var Be=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Se;)r&se&&(n=n.add(o)),o=o.double(),r>>=se;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Rn(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let u=1;u<o;u++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Rn(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:u,isZero:y,isNeg:l,isNegF:f,offsetF:d}=As(n,c,i);n=a,y?s=s.add(Ye(f,r[d])):o=o.add(Ye(l,r[u]))}return Is(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Rn(t,this.bits);for(let i=0;i<s.windows&&n!==Se;i++){let{nextN:c,offset:a,isZero:u,isNeg:y}=As(n,i,s);if(n=c,!u){let l=r[a];o=o.add(y?l.negate():l)}}return Is(n),o}getPrecomputes(t,r,n){let o=kn.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),kn.set(r,o))),o}cached(t,r,n){let o=Nn(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Nn(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Cs(r,this.bits),Ts.set(t,r),kn.delete(t)}hasCache(t){return Nn(t)!==1}};function Us(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Se||n>Se;)r&se&&(s=s.add(o)),n&se&&(i=i.add(o)),o=o.double(),r>>=se,n>>=se;return{p1:s,p2:i}}function ve(e,t,r,n){ha(r,e),la(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,c=br(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let u=Ft(a),y=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/a)*a,f=i;for(let d=l;d>=0;d-=a){y.fill(i);for(let E=0;E<s;E++){let S=n[E],g=Number(S>>BigInt(d)&u);y[g]=y[g].add(r[E])}let h=i;for(let E=y.length-1,S=i;E>0;E--)S=S.add(y[E]),h=h.add(S);if(f=f.add(h),d!==0)for(let E=0;E<a;E++)f=f.double()}return f}function Ls(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Un(t),t}else return dt(e,{isLE:r})}function xr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>Se))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Ls(t.p,r.Fp,n),s=Ls(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var Zt=BigInt(0),J=BigInt(1),Pn=BigInt(2),da=BigInt(8);function pa(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function ma(e,t={}){let r=xr("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;jt(t,{},{uvRatio:"function"});let c=Pn<<BigInt(o.BYTES*8)-J,a=S=>n.create(S),u=t.uvRatio||((S,g)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,g))}}catch{return{isValid:!1,value:Zt}}});if(!pa(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function y(S,g,B=!1){let w=B?J:Zt;return Ze("coordinate "+S,g,w,c),g}function l(S){if(!(S instanceof h))throw new Error("ExtendedPoint expected")}let f=_e((S,g)=>{let{X:B,Y:w,Z:T}=S,K=S.is0();g==null&&(g=K?da:n.inv(T));let M=a(B*g),P=a(w*g),R=n.mul(T,g);if(K)return{x:Zt,y:J};if(R!==J)throw new Error("invZ was invalid");return{x:M,y:P}}),d=_e(S=>{let{a:g,d:B}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:w,Y:T,Z:K,T:M}=S,P=a(w*w),R=a(T*T),x=a(K*K),L=a(x*x),k=a(P*g),C=a(x*a(k+R)),b=a(L+a(B*a(P*R)));if(C!==b)throw new Error("bad point: equation left != right (1)");let p=a(w*T),m=a(K*M);if(p!==m)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(g,B,w,T){this.X=y("x",g),this.Y=y("y",B),this.Z=y("z",w,!0),this.T=y("t",T),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){if(g instanceof h)throw new Error("extended point not allowed");let{x:B,y:w}=g||{};return y("x",B),y("y",w),new h(B,w,J,a(B*w))}static fromBytes(g,B=!1){let w=n.BYTES,{a:T,d:K}=s;g=Ln(lt(g,w,"point")),Ut(B,"zip215");let M=Ln(g),P=g[w-1];M[w-1]=P&-129;let R=Dt(M),x=B?c:n.ORDER;Ze("point.y",R,Zt,x);let L=a(R*R),k=a(L-J),C=a(K*L-T),{isValid:b,value:p}=u(k,C);if(!b)throw new Error("bad point: invalid y coordinate");let m=(p&J)===J,_=(P&128)!==0;if(!B&&p===Zt&&_)throw new Error("bad point: x=0 and x_0=1");return _!==m&&(p=a(-p)),h.fromAffine({x:p,y:R})}static fromHex(g,B=!1){return h.fromBytes(H("point",g),B)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,B=!0){return E.createCache(this,g),B||this.multiply(Pn),this}assertValidity(){d(this)}equals(g){l(g);let{X:B,Y:w,Z:T}=this,{X:K,Y:M,Z:P}=g,R=a(B*P),x=a(K*T),L=a(w*P),k=a(M*T);return R===x&&L===k}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:B,Y:w,Z:T}=this,K=a(B*B),M=a(w*w),P=a(Pn*a(T*T)),R=a(g*K),x=B+w,L=a(a(x*x)-K-M),k=R+M,C=k-P,b=R-M,p=a(L*C),m=a(k*b),_=a(L*b),v=a(C*k);return new h(p,m,v,_)}add(g){l(g);let{a:B,d:w}=s,{X:T,Y:K,Z:M,T:P}=this,{X:R,Y:x,Z:L,T:k}=g,C=a(T*R),b=a(K*x),p=a(P*w*k),m=a(M*L),_=a((T+K)*(R+x)-C-b),v=m-p,U=m+p,A=a(b-B*C),I=a(_*v),D=a(U*A),N=a(_*A),z=a(v*U);return new h(I,D,z,N)}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:B,f:w}=E.cached(this,g,T=>Rt(h,T));return Rt(h,[B,w])[0]}multiplyUnsafe(g,B=h.ZERO){if(!o.isValid(g))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return g===Zt?h.ZERO:this.is0()||g===J?this:E.unsafe(this,g,w=>Rt(h,w),B)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(g){return f(this,g)}clearCofactor(){return i===J?this:this.multiplyUnsafe(i)}toBytes(){let{x:g,y:B}=this.toAffine(),w=n.toBytes(B);return w[w.length-1]|=g&J?128:0,w}toHex(){return bt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(g){return Rt(h,g)}static msm(g,B){return ve(h,o,g,B)}_setWindowSize(g){this.precompute(g)}toRawBytes(){return this.toBytes()}}h.BASE=new h(s.Gx,s.Gy,J,a(s.Gx*s.Gy)),h.ZERO=new h(Zt,J,J,Zt),h.Fp=n,h.Fn=o;let E=new Be(h,o.BITS);return h.BASE.precompute(8),h}var wr=class{constructor(t){this.ep=t}static fromBytes(t){Cn()}static fromHex(t){Cn()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return bt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function ya(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');jt(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||we,a=r.adjustScalarBytes||(x=>x),u=r.domain||((x,L,k)=>{if(Ut(k,"phflag"),L.length||k)throw new Error("Contexts/pre-hash are not supported");return x});function y(x){return i.create(Dt(x))}function l(x){let L=w.secretKey;x=H("private key",x,L);let k=H("hashed private key",t(x),2*L),C=a(k.slice(0,L)),b=k.slice(L,2*L),p=y(C);return{head:C,prefix:b,scalar:p}}function f(x){let{head:L,prefix:k,scalar:C}=l(x),b=o.multiply(C),p=b.toBytes();return{head:L,prefix:k,scalar:C,point:b,pointBytes:p}}function d(x){return f(x).pointBytes}function h(x=Uint8Array.of(),...L){let k=rt(...L);return y(t(u(k,H("context",x),!!n)))}function E(x,L,k={}){x=H("message",x),n&&(x=n(x));let{prefix:C,scalar:b,pointBytes:p}=f(L),m=h(k.context,C,x),_=o.multiply(m).toBytes(),v=h(k.context,_,p,x),U=i.create(m+v*b);if(!i.isValid(U))throw new Error("sign failed: invalid s");let A=rt(_,i.toBytes(U));return lt(A,w.signature,"result")}let S={zip215:!0};function g(x,L,k,C=S){let{context:b,zip215:p}=C,m=w.signature;x=H("signature",x,m),L=H("message",L),k=H("publicKey",k,w.publicKey),p!==void 0&&Ut(p,"zip215"),n&&(L=n(L));let _=m/2,v=x.subarray(0,_),U=Dt(x.subarray(_,m)),A,I,D;try{A=e.fromBytes(k,p),I=e.fromBytes(v,p),D=o.multiplyUnsafe(U)}catch{return!1}if(!p&&A.isSmallOrder())return!1;let N=h(b,I.toBytes(),A.toBytes(),L);return I.add(A.multiplyUnsafe(N)).subtract(D).clearCofactor().is0()}let B=s.BYTES,w={secretKey:B,publicKey:B,signature:2*B,seed:B};function T(x=c(w.seed)){return lt(x,w.seed,"seed")}function K(x){let L=R.randomSecretKey(x);return{secretKey:L,publicKey:d(L)}}function M(x){return Lt(x)&&x.length===i.BYTES}function P(x,L){try{return!!e.fromBytes(x,L)}catch{return!1}}let R={getExtendedPublicKey:f,randomSecretKey:T,isValidSecretKey:M,isValidPublicKey:P,toMontgomery(x){let{y:L}=e.fromBytes(x),k=w.publicKey,C=k===32;if(!C&&k!==57)throw new Error("only defined for 25519 and 448");let b=C?s.div(J+L,J-L):s.div(L-J,L+J);return s.toBytes(b)},toMontgomerySecret(x){let L=w.secretKey;lt(x,L);let k=t(x.subarray(0,L));return a(k).subarray(0,L)},randomPrivateKey:T,precompute(x=8,L=e.BASE){return L.precompute(x,!1)}};return Object.freeze({keygen:K,getPublicKey:d,sign:E,verify:g,utils:R,Point:e,lengths:w})}function ba(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=dt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},s={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:s}}function ga(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Ds(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=ba(e),s=ma(t,r),i=ya(s,n,o);return ga(e,i)}var xa=BigInt(0),kt=BigInt(1),Ks=BigInt(2),Sh=BigInt(3),wa=BigInt(5),Ea=BigInt(8),Ae=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Xe={p:Ae,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Ea,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function _a(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ae,c=e*e%s*e%s,a=V(c,Ks,s)*c%s,u=V(a,kt,s)*e%s,y=V(u,wa,s)*u%s,l=V(y,t,s)*y%s,f=V(l,r,s)*l%s,d=V(f,n,s)*f%s,h=V(d,o,s)*d%s,E=V(h,o,s)*d%s,S=V(E,t,s)*y%s;return{pow_p_5_8:V(S,Ks,s)*e%s,b2:c}}function Sa(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Mn=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function qn(e,t){let r=Ae,n=G(t*t*t,r),o=G(n*n*t,r),s=_a(e*o).pow_p_5_8,i=G(e*n*s,r),c=G(t*i*i,r),a=i,u=G(i*Mn,r),y=c===e,l=c===G(-e,r),f=c===G(-e*Mn,r);return y&&(i=a),(l||f)&&(i=u),Kt(i,r)&&(i=G(-i,r)),{isValid:y||l,value:i}}var Gt=dt(Xe.p,{isLE:!0}),Ba=dt(Xe.n,{isLE:!0}),va={...Xe,Fp:Gt,hash:hs,adjustScalarBytes:Sa,uvRatio:qn},Nt=Ds(va);var On=Mn,Aa=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Ia=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),La=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Ca=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Rs=e=>qn(kt,e),Ta=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Hn=e=>Nt.Point.Fp.create(Dt(e)&Ta);function ks(e){let{d:t}=Xe,r=Ae,n=g=>Gt.create(g),o=n(On*e*e),s=n((o+kt)*La),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:a,value:u}=qn(s,c),y=n(u*e);Kt(y,r)||(y=n(-y)),a||(u=y),a||(i=o);let l=n(i*(o-kt)*Ca-c),f=u*u,d=n((u+u)*c),h=n(l*Aa),E=n(kt-f),S=n(kt+f);return new Nt.Point(n(d*S),n(E*h),n(h*S),n(d*E))}function Ua(e){ct(e,64);let t=Hn(e.subarray(0,32)),r=ks(t),n=Hn(e.subarray(32,64)),o=ks(n);return new Pt(r.add(o))}var Pt=class e extends wr{constructor(t){super(t)}static fromAffine(t){return new e(Nt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return Ua(H("ristrettoHash",t,64))}static fromBytes(t){ct(t,32);let{a:r,d:n}=Xe,o=Ae,s=T=>Gt.create(T),i=Hn(t);if(!ds(Gt.toBytes(i),t)||Kt(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),a=s(kt+r*c),u=s(kt-r*c),y=s(a*a),l=s(u*u),f=s(r*n*y-l),{isValid:d,value:h}=Rs(s(f*l)),E=s(h*u),S=s(h*E*f),g=s((i+i)*E);Kt(g,o)&&(g=s(-g));let B=s(a*S),w=s(g*B);if(!d||Kt(w,o)||B===xa)throw new Error("invalid ristretto255 encoding 2");return new e(new Nt.Point(g,B,kt,w))}static fromHex(t){return e.fromBytes(H("ristrettoHex",t,32))}static msm(t,r){return ve(e,Nt.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Ae,i=S=>Gt.create(S),c=i(i(n+r)*i(n-r)),a=i(t*r),u=i(a*a),{value:y}=Rs(i(c*u)),l=i(y*c),f=i(y*a),d=i(l*f*o),h;if(Kt(o*d,s)){let S=i(r*On),g=i(t*On);t=S,r=g,h=i(l*Ia)}else h=f;Kt(t*d,s)&&(r=i(-r));let E=i((n-r)*h);return Kt(E,s)&&(E=i(-E)),Gt.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>Gt.create(u),c=i(r*s)===i(n*o),a=i(n*s)===i(r*o);return c||a}is0(){return this.equals(e.ZERO)}};Pt.BASE=new Pt(Nt.Point.BASE);Pt.ZERO=new Pt(Nt.Point.ZERO);Pt.Fp=Gt;Pt.Fn=Ba;var $e=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Er=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ns={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Er("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 _r=Ns;var Sr=32;var Vn,Da=(async()=>{try{return await _r.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Ka(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await _r.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await _r.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 Ra(e,t,r){return Nt.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Ps(e,t,r){return Vn==null&&(Vn=await Da),Vn?Ka(e,t,r):Ra(e,t,r)}function Br(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var vr=class{type="Ed25519";raw;constructor(t){this.raw=zn(t,Sr)}toMultihash(){return gt.digest(be(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Ps(this.raw,r,t);return Br(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Os(e){return e=zn(e,Sr),new vr(e)}function zn(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new vt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Na=Math.pow(2,7),Pa=Math.pow(2,14),Ma=Math.pow(2,21),Hs=Math.pow(2,28),qs=Math.pow(2,35),Vs=Math.pow(2,42),zs=Math.pow(2,49),ot=128,Yt=127;function We(e){if(e<Na)return 1;if(e<Pa)return 2;if(e<Ma)return 3;if(e<Hs)return 4;if(e<qs)return 5;if(e<Vs)return 6;if(e<zs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Fs(e,t,r=0){switch(We(e)){case 8:t[r++]=e&255|ot,e/=128;case 7:t[r++]=e&255|ot,e/=128;case 6:t[r++]=e&255|ot,e/=128;case 5:t[r++]=e&255|ot,e/=128;case 4:t[r++]=e&255|ot,e>>>=7;case 3:t[r++]=e&255|ot,e>>>=7;case 2:t[r++]=e&255|ot,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function js(e,t){let r=e[t],n=0;if(n+=r&Yt,r<ot||(r=e[t+1],n+=(r&Yt)<<7,r<ot)||(r=e[t+2],n+=(r&Yt)<<14,r<ot)||(r=e[t+3],n+=(r&Yt)<<21,r<ot)||(r=e[t+4],n+=(r&Yt)*Hs,r<ot)||(r=e[t+5],n+=(r&Yt)*qs,r<ot)||(r=e[t+6],n+=(r&Yt)*Vs,r<ot)||(r=e[t+7],n+=(r&Yt)*zs,r<ot))return n;throw new RangeError("Could not decode varint")}var Fn=new Float32Array([-0]),Xt=new Uint8Array(Fn.buffer);function Zs(e,t,r){Fn[0]=e,t[r]=Xt[0],t[r+1]=Xt[1],t[r+2]=Xt[2],t[r+3]=Xt[3]}function Gs(e,t){return Xt[0]=e[t],Xt[1]=e[t+1],Xt[2]=e[t+2],Xt[3]=e[t+3],Fn[0]}var jn=new Float64Array([-0]),et=new Uint8Array(jn.buffer);function Ys(e,t,r){jn[0]=e,t[r]=et[0],t[r+1]=et[1],t[r+2]=et[2],t[r+3]=et[3],t[r+4]=et[4],t[r+5]=et[5],t[r+6]=et[6],t[r+7]=et[7]}function Xs(e,t){return et[0]=e[t],et[1]=e[t+1],et[2]=e[t+2],et[3]=e[t+3],et[4]=e[t+4],et[5]=e[t+5],et[6]=e[t+6],et[7]=e[t+7],jn[0]}var Oa=BigInt(Number.MAX_SAFE_INTEGER),Ha=BigInt(Number.MIN_SAFE_INTEGER),pt=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 ie;if(t<Oa&&t>Ha)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>$s&&(o=0n,++n>$s&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ie;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):ie}},ie=new pt(0,0);ie.toBigInt=function(){return 0n};ie.zzEncode=ie.zzDecode=function(){return this};ie.length=function(){return 1};var $s=4294967296n;function Ws(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 Js(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Zn(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 Et(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Ar(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Gn=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,Et(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 Et(this,4);return Ar(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Et(this,4);return Ar(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Et(this,4);let t=Gs(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Et(this,4);let t=Xs(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 Et(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Js(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Et(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Et(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 pt(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 Et(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 Et(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 Et(this,8);let t=Ar(this.buf,this.pos+=4),r=Ar(this.buf,this.pos+=4);return new pt(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=js(this.buf,this.pos);return this.pos+=We(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 Yn(e){return new Gn(e instanceof Uint8Array?e:e.subarray())}function Ir(e,t,r){let n=Yn(e);return t.decode(n,void 0,r)}function Xn(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return ut(i);o+i>t&&(n=ut(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var ce=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function $n(){}var Jn=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},qa=Xn();function Va(e){return globalThis.Buffer!=null?ut(e):qa(e)}var Qe=class{len;head;tail;states;constructor(){this.len=0,this.head=new ce($n,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ce(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Qn((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(Lr,10,pt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=pt.fromBigInt(t);return this._push(Lr,r.length(),r)}uint64Number(t){return this._push(Fs,We(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=pt.fromBigInt(t).zzEncode();return this._push(Lr,r.length(),r)}sint64Number(t){let r=pt.fromNumber(t).zzEncode();return this._push(Lr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Wn,1,t?1:0)}fixed32(t){return this._push(Je,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=pt.fromBigInt(t);return this._push(Je,4,r.lo)._push(Je,4,r.hi)}fixed64Number(t){let r=pt.fromNumber(t);return this._push(Je,4,r.lo)._push(Je,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(Zs,4,t)}double(t){return this._push(Ys,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Wn,1,0):this.uint32(r)._push(Fa,r,t)}string(t){let r=Ws(t);return r!==0?this.uint32(r)._push(Zn,r,t):this._push(Wn,1,0)}fork(){return this.states=new Jn(this),this.head=this.tail=new ce($n,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 ce($n,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=Va(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Wn(e,t,r){t[r]=e&255}function za(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Qn=class extends ce{next;constructor(t,r){super(za,t,r),this.next=void 0}};function Lr(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 Je(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 Fa(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Qe.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(ja,t,e),this},Qe.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Za,t,e),this});function ja(e,t,r){t.set(e,r)}function Za(e,t,r){e.length<40?Zn(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set($(e),r)}function to(){return new Qe}function Cr(e,t){let r=to();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var Ie;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(Ie||(Ie={}));function Tr(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function eo(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return Tr("enum",Ie.VARINT,r,n)}function Ur(e,t){return Tr("message",Ie.LENGTH_DELIMITED,e,t)}var mt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(mt||(mt={}));var ro;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(ro||(ro={}));(function(e){e.codec=()=>eo(ro)})(mt||(mt={}));var tr;(function(e){let t;e.codec=()=>(t==null&&(t=Ur((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),mt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=mt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Cr(r,e.codec()),e.decode=(r,n)=>Ir(r,e.codec(),n)})(tr||(tr={}));var no;(function(e){let t;e.codec=()=>(t==null&&(t=Ur((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),mt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let c=r.uint32();switch(c>>>3){case 1:{s.Type=mt.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(c&7);break}}}return s})),t),e.encode=r=>Cr(r,e.codec()),e.decode=(r,n)=>Ir(r,e.codec(),n)})(no||(no={}));var Dr=class extends ge{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,dr(t);let n=qe(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Ct(s)}update(t){return xe(this),this.iHash.update(t),this}digestInto(t){xe(this),ct(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},oo=(e,t,r)=>new Dr(e,t).update(r).digest();oo.create=(e,t)=>new Dr(e,t);var ti=(e,t)=>(e+(e>=0?t:-t)/ei)/t;function Ya(e,t,r){let[[n,o],[s,i]]=t,c=ti(i*e,r),a=ti(-o*e,r),u=e-c*n-a*s,y=-c*o-a*i,l=u<Ot,f=y<Ot;l&&(u=-u),f&&(y=-y);let d=Ft(Math.ceil(br(r)/2))+Ce;if(u<Ot||u>=d||y<Ot||y>=d)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:f,k2:y}}function io(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function so(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Ut(r.lowS,"lowS"),Ut(r.prehash,"prehash"),r.format!==void 0&&io(r.format),r}var co=class extends Error{constructor(t=""){super(t)}},Mt={Err:co,_tlv:{encode:(e,t)=>{let{Err:r}=Mt;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=je(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?je(o.length/2|128):"";return je(e)+s+o+t},decode(e,t){let{Err:r}=Mt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let y of u)i=i<<8|y;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Mt;if(e<Ot)throw new t("integer: negative integers are not allowed");let r=je(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}=Mt;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 Ee(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Mt,o=H("signature",e),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l:y}=n.decode(2,a);if(y.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(u)}},hexFromSig(e){let{_tlv:t,_int:r}=Mt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},Ot=BigInt(0),Ce=BigInt(1),ei=BigInt(2),Kr=BigInt(3),Xa=BigInt(4);function Le(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=H("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function $a(e,t={}){let r=xr("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;jt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=ni(n,o);function y(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(C,b,p){let{x:m,y:_}=b.toAffine(),v=n.toBytes(m);if(Ut(p,"isCompressed"),p){y();let U=!n.isOdd(_);return rt(ri(U),v)}else return rt(Uint8Array.of(4),v,n.toBytes(_))}function f(C){lt(C,void 0,"Point");let{publicKey:b,publicKeyUncompressed:p}=u,m=C.length,_=C[0],v=C.subarray(1);if(m===b&&(_===2||_===3)){let U=n.fromBytes(v);if(!n.isValid(U))throw new Error("bad point: is not on curve, wrong x");let A=E(U),I;try{I=n.sqrt(A)}catch(z){let q=z instanceof Error?": "+z.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}y();let D=n.isOdd(I);return(_&1)===1!==D&&(I=n.neg(I)),{x:U,y:I}}else if(m===p&&_===4){let U=n.BYTES,A=n.fromBytes(v.subarray(0,U)),I=n.fromBytes(v.subarray(U,U*2));if(!S(A,I))throw new Error("bad point: is not on curve");return{x:A,y:I}}else throw new Error(`bad point: got length ${m}, expected compressed=${b} or uncompressed=${p}`)}let d=t.toBytes||l,h=t.fromBytes||f;function E(C){let b=n.sqr(C),p=n.mul(b,C);return n.add(n.add(p,n.mul(C,s.a)),s.b)}function S(C,b){let p=n.sqr(b),m=E(C);return n.eql(p,m)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let g=n.mul(n.pow(s.a,Kr),Xa),B=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(g,B)))throw new Error("bad curve params: a or b");function w(C,b,p=!1){if(!n.isValid(b)||p&&n.is0(b))throw new Error(`bad point coordinate ${C}`);return b}function T(C){if(!(C instanceof x))throw new Error("ProjectivePoint expected")}function K(C){if(!a||!a.basises)throw new Error("no endo");return Ya(C,a.basises,o.ORDER)}let M=_e((C,b)=>{let{X:p,Y:m,Z:_}=C;if(n.eql(_,n.ONE))return{x:p,y:m};let v=C.is0();b==null&&(b=v?n.ONE:n.inv(_));let U=n.mul(p,b),A=n.mul(m,b),I=n.mul(_,b);if(v)return{x:n.ZERO,y:n.ZERO};if(!n.eql(I,n.ONE))throw new Error("invZ was invalid");return{x:U,y:A}}),P=_e(C=>{if(C.is0()){if(t.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:b,y:p}=C.toAffine();if(!n.isValid(b)||!n.isValid(p))throw new Error("bad point: x or y not field elements");if(!S(b,p))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function R(C,b,p,m,_){return p=new x(n.mul(p.X,C),p.Y,p.Z),b=Ye(m,b),p=Ye(_,p),b.add(p)}class x{constructor(b,p,m){this.X=w("x",b),this.Y=w("y",p,!0),this.Z=w("z",m),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){let{x:p,y:m}=b||{};if(!b||!n.isValid(p)||!n.isValid(m))throw new Error("invalid affine point");if(b instanceof x)throw new Error("projective point not allowed");return n.is0(p)&&n.is0(m)?x.ZERO:new x(p,m,n.ONE)}static fromBytes(b){let p=x.fromAffine(h(lt(b,void 0,"point")));return p.assertValidity(),p}static fromHex(b){return x.fromBytes(H("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,p=!0){return k.createCache(this,b),p||this.multiply(Kr),this}assertValidity(){P(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){T(b);let{X:p,Y:m,Z:_}=this,{X:v,Y:U,Z:A}=b,I=n.eql(n.mul(p,A),n.mul(v,_)),D=n.eql(n.mul(m,A),n.mul(U,_));return I&&D}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:p}=s,m=n.mul(p,Kr),{X:_,Y:v,Z:U}=this,A=n.ZERO,I=n.ZERO,D=n.ZERO,N=n.mul(_,_),z=n.mul(v,v),q=n.mul(U,U),O=n.mul(_,v);return O=n.add(O,O),D=n.mul(_,U),D=n.add(D,D),A=n.mul(b,D),I=n.mul(m,q),I=n.add(A,I),A=n.sub(z,I),I=n.add(z,I),I=n.mul(A,I),A=n.mul(O,A),D=n.mul(m,D),q=n.mul(b,q),O=n.sub(N,q),O=n.mul(b,O),O=n.add(O,D),D=n.add(N,N),N=n.add(D,N),N=n.add(N,q),N=n.mul(N,O),I=n.add(I,N),q=n.mul(v,U),q=n.add(q,q),N=n.mul(q,O),A=n.sub(A,N),D=n.mul(q,z),D=n.add(D,D),D=n.add(D,D),new x(A,I,D)}add(b){T(b);let{X:p,Y:m,Z:_}=this,{X:v,Y:U,Z:A}=b,I=n.ZERO,D=n.ZERO,N=n.ZERO,z=s.a,q=n.mul(s.b,Kr),O=n.mul(p,v),F=n.mul(m,U),X=n.mul(_,A),st=n.add(p,m),j=n.add(v,U);st=n.mul(st,j),j=n.add(O,F),st=n.sub(st,j),j=n.add(p,_);let tt=n.add(v,A);return j=n.mul(j,tt),tt=n.add(O,X),j=n.sub(j,tt),tt=n.add(m,_),I=n.add(U,A),tt=n.mul(tt,I),I=n.add(F,X),tt=n.sub(tt,I),N=n.mul(z,j),I=n.mul(q,X),N=n.add(I,N),I=n.sub(F,N),N=n.add(F,N),D=n.mul(I,N),F=n.add(O,O),F=n.add(F,O),X=n.mul(z,X),j=n.mul(q,j),F=n.add(F,X),X=n.sub(O,X),X=n.mul(z,X),j=n.add(j,X),O=n.mul(F,j),D=n.add(D,O),O=n.mul(tt,j),I=n.mul(st,I),I=n.sub(I,O),O=n.mul(st,F),N=n.mul(tt,N),N=n.add(N,O),new x(I,D,N)}subtract(b){return this.add(b.negate())}is0(){return this.equals(x.ZERO)}multiply(b){let{endo:p}=t;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let m,_,v=U=>k.cached(this,U,A=>Rt(x,A));if(p){let{k1neg:U,k1:A,k2neg:I,k2:D}=K(b),{p:N,f:z}=v(A),{p:q,f:O}=v(D);_=z.add(O),m=R(p.beta,N,q,U,I)}else{let{p:U,f:A}=v(b);m=U,_=A}return Rt(x,[m,_])[0]}multiplyUnsafe(b){let{endo:p}=t,m=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===Ot||m.is0())return x.ZERO;if(b===Ce)return m;if(k.hasCache(this))return this.multiply(b);if(p){let{k1neg:_,k1:v,k2neg:U,k2:A}=K(b),{p1:I,p2:D}=Us(x,m,v,A);return R(p.beta,I,D,_,U)}else return k.unsafe(m,b)}multiplyAndAddUnsafe(b,p,m){let _=this.multiplyUnsafe(p).add(b.multiplyUnsafe(m));return _.is0()?void 0:_}toAffine(b){return M(this,b)}isTorsionFree(){let{isTorsionFree:b}=t;return i===Ce?!0:b?b(x,this):k.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:b}=t;return i===Ce?this:b?b(x,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return Ut(b,"isCompressed"),this.assertValidity(),d(x,this,b)}toHex(b=!0){return bt(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(b=!0){return this.toBytes(b)}_setWindowSize(b){this.precompute(b)}static normalizeZ(b){return Rt(x,b)}static msm(b,p){return ve(x,o,b,p)}static fromPrivateKey(b){return x.BASE.multiply(Le(o,b))}}x.BASE=new x(s.Gx,s.Gy,n.ONE),x.ZERO=new x(n.ZERO,n.ONE,n.ZERO),x.Fp=n,x.Fn=o;let L=o.BITS,k=new Be(x,t.endo?Math.ceil(L/2):L);return x.BASE.precompute(8),x}function ri(e){return Uint8Array.of(e?2:3)}function ni(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Wa(e,t={}){let{Fn:r}=e,n=t.randomBytes||we,o=Object.assign(ni(e.Fp,r),{seed:Dn(r.ORDER)});function s(d){try{return!!Le(r,d)}catch{return!1}}function i(d,h){let{publicKey:E,publicKeyUncompressed:S}=o;try{let g=d.length;return h===!0&&g!==E||h===!1&&g!==S?!1:!!e.fromBytes(d)}catch{return!1}}function c(d=n(o.seed)){return Kn(lt(d,o.seed,"seed"),r.ORDER)}function a(d,h=!0){return e.BASE.multiply(Le(r,d)).toBytes(h)}function u(d){let h=c(d);return{secretKey:h,publicKey:a(h)}}function y(d){if(typeof d=="bigint")return!1;if(d instanceof e)return!0;let{secretKey:h,publicKey:E,publicKeyUncompressed:S}=o;if(r.allowedLengths||h===E)return;let g=H("key",d).length;return g===E||g===S}function l(d,h,E=!0){if(y(d)===!0)throw new Error("first arg must be private key");if(y(h)===!1)throw new Error("second arg must be public key");let S=Le(r,d);return e.fromHex(h).multiply(S).toBytes(E)}return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:u,Point:e,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c,isValidPrivateKey:s,randomPrivateKey:c,normPrivateKeyToScalar:d=>Le(r,d),precompute(d=8,h=e.BASE){return h.precompute(d,!1)}},lengths:o})}function Ja(e,t,r={}){dr(t),jt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||we,o=r.hmac||((p,...m)=>oo(t,p,rt(...m))),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:u,getPublicKey:y,getSharedSecret:l,utils:f,lengths:d}=Wa(e,r),h={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},E="compact";function S(p){let m=c>>Ce;return p>m}function g(p,m){if(!i.isValidNot0(m))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return m}function B(p,m){io(m);let _=d.signature,v=m==="compact"?_:m==="recovered"?_+1:void 0;return lt(p,v,`${m} signature`)}class w{constructor(m,_,v){this.r=g("r",m),this.s=g("s",_),v!=null&&(this.recovery=v),Object.freeze(this)}static fromBytes(m,_=E){B(m,_);let v;if(_==="der"){let{r:D,s:N}=Mt.toSig(lt(m));return new w(D,N)}_==="recovered"&&(v=m[0],_="compact",m=m.subarray(1));let U=i.BYTES,A=m.subarray(0,U),I=m.subarray(U,U*2);return new w(i.fromBytes(A),i.fromBytes(I),v)}static fromHex(m,_){return this.fromBytes(ee(m),_)}addRecoveryBit(m){return new w(this.r,this.s,m)}recoverPublicKey(m){let _=s.ORDER,{r:v,s:U,recovery:A}=this;if(A==null||![0,1,2,3].includes(A))throw new Error("recovery id invalid");if(c*ei<_&&A>1)throw new Error("recovery id is ambiguous for h>1 curve");let D=A===2||A===3?v+c:v;if(!s.isValid(D))throw new Error("recovery id 2 or 3 invalid");let N=s.toBytes(D),z=e.fromBytes(rt(ri((A&1)===0),N)),q=i.inv(D),O=K(H("msgHash",m)),F=i.create(-O*q),X=i.create(U*q),st=e.BASE.multiplyUnsafe(F).add(z.multiplyUnsafe(X));if(st.is0())throw new Error("point at infinify");return st.assertValidity(),st}hasHighS(){return S(this.s)}toBytes(m=E){if(io(m),m==="der")return ee(Mt.hexFromSig(this));let _=i.toBytes(this.r),v=i.toBytes(this.s);if(m==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return rt(Uint8Array.of(this.recovery),_,v)}return rt(_,v)}toHex(m){return bt(this.toBytes(m))}assertValidity(){}static fromCompact(m){return w.fromBytes(H("sig",m),"compact")}static fromDER(m){return w.fromBytes(H("sig",m),"der")}normalizeS(){return this.hasHighS()?new w(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return bt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return bt(this.toBytes("compact"))}}let T=r.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let _=Ee(m),v=m.length*8-a;return v>0?_>>BigInt(v):_},K=r.bits2int_modN||function(m){return i.create(T(m))},M=Ft(a);function P(p){return Ze("num < 2^"+a,p,Ot,M),i.toBytes(p)}function R(p,m){return lt(p,void 0,"message"),m?lt(t(p),void 0,"prehashed message"):p}function x(p,m,_){if(["recovered","canonical"].some(F=>F in _))throw new Error("sign() legacy options not supported");let{lowS:v,prehash:U,extraEntropy:A}=so(_,h);p=R(p,U);let I=K(p),D=Le(i,m),N=[P(D),P(I)];if(A!=null&&A!==!1){let F=A===!0?n(d.secretKey):A;N.push(H("extraEntropy",F))}let z=rt(...N),q=I;function O(F){let X=T(F);if(!i.isValidNot0(X))return;let st=i.inv(X),j=e.BASE.multiply(X).toAffine(),tt=i.create(j.x);if(tt===Ot)return;let sr=i.create(st*i.create(q+tt*D));if(sr===Ot)return;let go=(j.x===tt?0:2)|Number(j.y&Ce),xo=sr;return v&&S(sr)&&(xo=i.neg(sr),go^=1),new w(tt,xo,go)}return{seed:z,k2sig:O}}function L(p,m,_={}){p=H("message",p);let{seed:v,k2sig:U}=x(p,m,_);return ms(t.outputLen,i.BYTES,o)(v,U)}function k(p){let m,_=typeof p=="string"||Lt(p),v=!_&&p!==null&&typeof p=="object"&&typeof p.r=="bigint"&&typeof p.s=="bigint";if(!_&&!v)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(v)m=new w(p.r,p.s);else if(_){try{m=w.fromBytes(H("sig",p),"der")}catch(U){if(!(U instanceof Mt.Err))throw U}if(!m)try{m=w.fromBytes(H("sig",p),"compact")}catch{return!1}}return m||!1}function C(p,m,_,v={}){let{lowS:U,prehash:A,format:I}=so(v,h);if(_=H("publicKey",_),m=R(H("message",m),A),"strict"in v)throw new Error("options.strict was renamed to lowS");let D=I===void 0?k(p):w.fromBytes(H("sig",p),I);if(D===!1)return!1;try{let N=e.fromBytes(_);if(U&&D.hasHighS())return!1;let{r:z,s:q}=D,O=K(m),F=i.inv(q),X=i.create(O*F),st=i.create(z*F),j=e.BASE.multiplyUnsafe(X).add(N.multiplyUnsafe(st));return j.is0()?!1:i.create(j.x)===z}catch{return!1}}function b(p,m,_={}){let{prehash:v}=so(_,h);return m=R(m,v),w.fromBytes(p,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:u,getPublicKey:y,getSharedSecret:l,utils:f,lengths:d,Point:e,sign:L,verify:C,recoverPublicKey:b,Signature:w,hash:t})}function Qa(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=dt(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),s={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:s}}function tf(e){let{CURVE:t,curveOpts:r}=Qa(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function ef(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,gr(r.Fn.ORDER,r.Fn.BITS))})}function oi(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=tf(e),s=$a(t,r),i=Ja(s,n,o);return ef(e,i)}function si(e,t){let r=n=>oi({...e,hash:n});return{...r(t),create:r}}var fo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},rf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ii=BigInt(2);function nf(e){let t=fo.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=e*e*e%t,y=u*u*e%t,l=V(y,r,t)*y%t,f=V(l,r,t)*y%t,d=V(f,ii,t)*u%t,h=V(d,o,t)*d%t,E=V(h,s,t)*h%t,S=V(E,c,t)*E%t,g=V(S,a,t)*S%t,B=V(g,c,t)*E%t,w=V(B,r,t)*y%t,T=V(w,i,t)*h%t,K=V(T,n,t)*u%t,M=V(K,ii,t);if(!ao.eql(ao.sqr(M),e))throw new Error("Cannot find square root");return M}var ao=dt(fo.p,{sqrt:nf}),Te=si({...fo,Fp:ao,lowS:!0,endo:rf},us);function ci(e,t,r,n){let o=Pe.digest(r instanceof Uint8Array?r:r.subarray());if(Br(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Te.verify(t,s,e))).catch(s=>{throw s.name==="AbortError"?s:new $e(String(s))});try{return n?.signal?.throwIfAborted(),Te.verify(t,o.digest,e)}catch(s){throw new $e(String(s))}}var Rr=class{type="secp256k1";raw;_key;constructor(t){this._key=fi(t),this.raw=ai(this._key)}toMultihash(){return gt.digest(be(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ft(this.raw,t.raw)}verify(t,r,n){return ci(this._key,r,t,n)}};function ui(e){return new Rr(e)}function ai(e){return Te.ProjectivePoint.fromHex(e).toRawBytes(!0)}function fi(e){try{return Te.ProjectivePoint.fromHex(e),e}catch(t){throw new ir(String(t))}}function hi(e){let{Type:t,Data:r}=tr.decode(e.digest),n=r??new Uint8Array;switch(t){case mt.Ed25519:return Os(n);case mt.secp256k1:return ui(n);case mt.ECDSA:return Go(n);default:throw new Ue}}function be(e){return tr.encode({Type:mt[e.type],Data:e.raw})}var li=Symbol.for("nodejs.util.inspect.custom"),of=114,er=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()})`}[Vr]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return it.createV1(of,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ft(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ft(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[li](){return`PeerId(${this.toString()})`}},kr=class extends er{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Nr=class extends er{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Pr=class extends er{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},sf=2336,Mr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=gt.digest($(this.url))}[li](){return`PeerId(${this.url})`}[Vr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return it.createV1(sf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=yt(t)),t.toString()===this.toString())}};function di(e){if(af(e))return new kr({multihash:e});if(cf(e))try{let t=hi(e);if(t.type==="Ed25519")return new Nr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Pr({multihash:e,publicKey:t})}catch{let r=yt(e.digest);return new Mr(new URL(r))}throw new cr("Supplied PeerID Multihash is invalid")}function cf(e){return e.code===gt.code}function af(e){return e.code===Pe.code}function Bt(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return r}function Or(e){let t=ke(Y.decode(`z${e}`));return di(t)}var $t=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[r,n]of t.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return Bt(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((r,n)=>{t(r.value,r.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,r){this.map.set(t.toString(),{key:t,value:r})}keys(){return Bt(this.map.values(),t=>t.key)}values(){return Bt(this.map.values(),t=>t.value)}get size(){return this.map.size}};function pi(){return new $t}var Wt=class e{set;constructor(t){if(this.set=new Set,t!=null)for(let r of t)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Bt(this.set.entries(),t=>{let r=Or(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=Or(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Bt(this.set.values(),t=>Or(t))}intersection(t){let r=new e;for(let n of t)this.has(n)&&r.add(n);return r}difference(t){let r=new e;for(let n of this)t.has(n)||r.add(n);return r}union(t){let r=new e;for(let n of t)r.add(n);for(let n of this)r.add(n);return r}};function mi(){return new Wt}var Jt=class e{list;constructor(t){if(this.list=[],t!=null)for(let r of t)this.list.push(r)}[Symbol.iterator](){return Bt(this.list.entries(),t=>t[1])}concat(t){let r=new e(this);for(let n of t)r.push(n);return r}entries(){return Bt(this.list.entries(),t=>[t[0],t[1]])}every(t){return this.list.every((r,n)=>t(r,n,this))}filter(t){let r=new e;return this.list.forEach((n,o)=>{t(n,o,this)&&r.push(n)}),r}find(t){let r=this.list.find((n,o)=>t(n,o,this));if(r!=null)return r}findIndex(t){return this.list.findIndex((r,n)=>t(r,n,this))}forEach(t){this.list.forEach((r,n)=>{t(r,n,this)})}includes(t){return this.includes(t)}indexOf(t){return this.list.findIndex(r=>r.equals(t))}pop(){let t=this.list.pop();if(t!=null)return t}push(...t){for(let r of t)this.list.push(r)}shift(){let t=this.list.shift();if(t!=null)return t}unshift(...t){let r=this.list.length;for(let n=t.length-1;n>-1;n--)r=this.list.unshift(t[n]);return r}clear(){this.list=[]}get length(){return this.list.length}};function yi(){return new Jt}var uo={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},bi={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},gi=new globalThis.TextEncoder;function ff(e,t){let r=uo[t],n=bi[t];for(let o=0;o<e.length;o++)n^=BigInt(e[o]),n=BigInt.asUintN(t,n*r);return n}function uf(e,t,r){if(r.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=uo[t],o=bi[t],s=e;for(;s.length>0;){let i=gi.encodeInto(s,r);s=s.slice(i.read);for(let c=0;c<i.written;c++)o^=BigInt(r[c]),o=BigInt.asUintN(t,o*n)}return o}function ho(e,{size:t=32,utf8Buffer:r}={}){if(!uo[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof e=="string"){if(r)return uf(e,t,r);e=gi.encode(e)}return ff(e,t)}var rr={hash:e=>Number(ho(e,{size:32})),hashV:(e,t)=>hf(rr.hash(e,t))};function hf(e){let t=e.toString(16);return t.length%2===1&&(t=`0${t}`),$(t,"base16")}var lo=64,_t=class{fp;h;seed;constructor(t,r,n,o=2){if(o>lo)throw new TypeError("Invalid Fingerprint Size");let s=r.hashV(t,n),i=xt(o);for(let c=0;c<i.length;c++)i[c]=s[c];i.length===0&&(i[0]=7),this.fp=i,this.h=r,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?ft(this.fp,t.fp):!1}};function ae(e,t){return Math.floor(Math.random()*(t-e))+e}var fe=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof _t))throw new TypeError("Invalid Fingerprint");return this.contents.some(r=>t.equals(r))}add(t){if(!(t instanceof _t))throw new TypeError("Invalid Fingerprint");for(let r=0;r<this.contents.length;r++)if(this.contents[r]==null)return this.contents[r]=t,!0;return!0}swap(t){if(!(t instanceof _t))throw new TypeError("Invalid Fingerprint");let r=ae(0,this.contents.length-1),n=this.contents[r];return this.contents[r]=t,n}remove(t){if(!(t instanceof _t))throw new TypeError("Invalid Fingerprint");let r=this.contents.findIndex(n=>t.equals(n));return r>-1?(this.contents[r]=null,!0):!1}};var lf=500,nr=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??rr,this.seed=t.seed??ae(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=$(t));let r=new _t(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^r.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new fe(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new fe(this.bucketSize)),this.buckets[n].add(r)||this.buckets[o].add(r))return this.count++,!0;let s=[n,o],i=s[ae(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new fe(this.bucketSize));for(let c=0;c<lf;c++){let a=this.buckets[i].swap(r);if(a!=null&&(i=(i^a.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new fe(this.bucketSize)),this.buckets[i].add(a)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=$(t));let r=new _t(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(r)??!1;if(o)return o;let s=(n^r.hash())%this.filterSize;return this.buckets[s]?.has(r)??!1}remove(t){typeof t=="string"&&(t=$(t));let r=new _t(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(r)??!1;if(o)return this.count--,o;let s=(n^r.hash())%this.filterSize,i=this.buckets[s]?.remove(r)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},df={1:.5,2:.84,4:.95,8:.98};function pf(e=.001){return e>.002?2:e>1e-5?4:8}function xi(e,t=.001){let r=pf(t),n=df[r],o=Math.round(e/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*r)),lo);return{filterSize:o,bucketSize:r,fingerprintSize:s}}var Hr=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(t){this.bucketSize=t.bucketSize??4,this.filterSize=t.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=t.fingerprintSize??2,this.scale=t.scale??2,this.hash=t.hash??rr,this.seed=t.seed??ae(0,Math.pow(2,10)),this.filterSeries=[new nr({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=$(t)),this.has(t))return!0;let r=this.filterSeries.find(n=>n.reliable);if(r==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);r=new nr({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(r)}return r.add(t)}has(t){typeof t=="string"&&(t=$(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=$(t));for(let r=0;r<this.filterSeries.length;r++)if(this.filterSeries[r].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,r)=>t+r.count,0)}};function po(e,t=.001,r){return new Hr({...xi(e,t),...r??{}})}var or=class{filter;constructor(t,r){this.filter=po(t,r)}has(t){return this.filter.has(t.toMultihash().bytes)}add(t){this.filter.add(t.toMultihash().bytes)}remove(t){this.filter.remove?.(t.toMultihash().bytes)}};function wi(e,t=.001){return new or(e,t)}var mo=class extends $t{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(t,r){return super.set(t,r),this.updateComponentMetric(),this}delete(t){let r=super.delete(t);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Ei(e){let{name:t,metrics:r}=e,n;return r!=null?n=new mo({name:t,metrics:r}):n=new $t,n}var yo=class extends Wt{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}add(t){super.add(t),this.updateComponentMetric()}delete(t){super.delete(t),this.updateComponentMetric()}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function _i(e){let{name:t,metrics:r}=e,n;return r!=null?n=new yo({name:t,metrics:r}):n=new Wt,n}var bo=class extends Jt{metric;constructor(t){super();let{name:r,metrics:n}=t;this.metric=n.registerMetric(r),this.updateComponentMetric()}pop(){let t=super.pop();return this.updateComponentMetric(),t}push(...t){super.push(...t),this.updateComponentMetric()}shift(){let t=super.shift();return this.updateComponentMetric(),t}unshift(...t){let r=super.unshift(...t);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.length)}};function Si(e){let{name:t,metrics:r}=e,n;return r!=null?n=new bo({name:t,metrics:r}):n=new Jt,n}return Li(mf);})();
|
|
2
|
+
"use strict";var Libp2PPeerCollections=(()=>{var Ir=Object.defineProperty;var fi=Object.getOwnPropertyDescriptor;var ui=Object.getOwnPropertyNames;var hi=Object.prototype.hasOwnProperty;var it=(r,t)=>{for(var e in t)Ir(r,e,{get:t[e],enumerable:!0})},li=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ui(t))!hi.call(r,o)&&o!==e&&Ir(r,o,{get:()=>t[o],enumerable:!(n=fi(t,o))||n.enumerable});return r};var di=r=>li(Ir({},"__esModule",{value:!0}),r);var qa={};it(qa,{PeerFilter:()=>Fe,PeerList:()=>Vt,PeerMap:()=>qt,PeerSet:()=>Ht,peerFilter:()=>si,peerList:()=>ei,peerMap:()=>Qs,peerSet:()=>ti,trackedPeerList:()=>ai,trackedPeerMap:()=>ii,trackedPeerSet:()=>ci});var _t=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},je=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ge=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var xe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Lr=Symbol.for("@libp2p/peer-id");var Ur={};it(Ur,{base58btc:()=>G,base58flickr:()=>wi});var Fa=new Uint8Array(0);function no(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function St(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function oo(r){return new TextEncoder().encode(r)}function so(r){return new TextDecoder().decode(r)}function pi(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),m=Math.log(256)/Math.log(a);function u(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var v=0,S=0,b=0,A=p.length;b!==A&&p[b]===0;)b++,v++;for(var y=(A-b)*m+1>>>0,B=new Uint8Array(y);b!==A;){for(var U=p[b],O=0,M=y-1;(U!==0||O<S)&&M!==-1;M--,O++)U+=256*B[M]>>>0,B[M]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");S=O,b++}for(var x=y-S;x!==y&&B[x]===0;)x++;for(var g=c.repeat(v);x<y;++x)g+=r.charAt(B[x]);return g}function w(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var v=0;if(p[v]!==" "){for(var S=0,b=0;p[v]===c;)S++,v++;for(var A=(p.length-v)*f+1>>>0,y=new Uint8Array(A);p[v];){var B=e[p.charCodeAt(v)];if(B===255)return;for(var U=0,O=A-1;(B!==0||U<b)&&O!==-1;O--,U++)B+=a*y[O]>>>0,y[O]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");b=U,v++}if(p[v]!==" "){for(var M=A-b;M!==A&&y[M]===0;)M++;for(var x=new Uint8Array(S+(A-M)),g=S;M!==A;)x[g++]=y[M++];return x}}}function _(p){var v=w(p);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:w,decode:_}}var mi=pi,bi=mi,co=bi;var Dr=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Cr=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.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 ao(this,t)}},Tr=class{decoders;constructor(t){this.decoders=t}or(t){return ao(this,t)}decode(t){let e=t[0],n=this.decoders[e];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 ao(r,t){return new Tr({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Rr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Dr(t,e,n),this.decoder=new Cr(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ee({name:r,prefix:t,encode:e,decode:n}){return new Rr(r,t,e,n)}function Tt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=co(e,r);return ee({prefix:t,name:r,encode:n,decode:s=>St(o(s))})}function yi(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let m=t[r[f]];if(m===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|m,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function gi(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function xi(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function j({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=xi(n);return ee({prefix:t,name:r,encode(s){return gi(s,n,e)},decode(s){return yi(s,o,e,r)}})}var G=Tt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),wi=Tt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Kr={};it(Kr,{base32:()=>re,base32hex:()=>Ai,base32hexpad:()=>Bi,base32hexpadupper:()=>Ii,base32hexupper:()=>vi,base32pad:()=>_i,base32padupper:()=>Si,base32upper:()=>Ei,base32z:()=>Li});var re=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ei=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),_i=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Si=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ai=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),vi=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Bi=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ii=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Li=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var kr={};it(kr,{base36:()=>we,base36upper:()=>Di});var we=Tt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Di=Tt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ci=ho,fo=128,Ti=127,Ri=~Ti,Ui=Math.pow(2,31);function ho(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ui;)t[e++]=r&255|fo,r/=128;for(;r&Ri;)t[e++]=r&255|fo,r>>>=7;return t[e]=r|0,ho.bytes=e-n+1,t}var Ki=Nr,ki=128,uo=127;function Nr(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Nr.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&uo)<<o:(i&uo)*Math.pow(2,o),o+=7}while(i>=ki);return Nr.bytes=s-n,e}var Ni=Math.pow(2,7),Oi=Math.pow(2,14),Mi=Math.pow(2,21),Pi=Math.pow(2,28),qi=Math.pow(2,35),Hi=Math.pow(2,42),Vi=Math.pow(2,49),zi=Math.pow(2,56),Fi=Math.pow(2,63),Zi=function(r){return r<Ni?1:r<Oi?2:r<Mi?3:r<Pi?4:r<qi?5:r<Hi?6:r<Vi?7:r<zi?8:r<Fi?9:10},ji={encode:Ci,decode:Ki,encodingLength:Zi},Gi=ji,Ee=Gi;function _e(r,t=0){return[Ee.decode(r,t),Ee.decode.bytes]}function ne(r,t,e=0){return Ee.encode(r,t,e),t}function oe(r){return Ee.encodingLength(r)}function ie(r,t){let e=t.byteLength,n=oe(r),o=n+oe(e),s=new Uint8Array(o+e);return ne(r,s,0),ne(e,s,n),s.set(t,o),new se(r,e,t,s)}function Se(r){let t=St(r),[e,n]=_e(t),[o,s]=_e(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new se(e,o,i,t)}function lo(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&no(r.bytes,e.bytes)}}var se=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function po(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Xi(e,Or(r),t??G.encoder);default:return $i(e,Or(r),t??re.encoder)}}var mo=new WeakMap;function Or(r){let t=mo.get(r);if(t==null){let e=new Map;return mo.set(r,e),e}return t}var ot=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,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:e}=this;if(t!==Ae)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Wi)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:e}=this.multihash,n=ie(t,e);return r.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 r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&lo(t.multihash,n.multihash)}toString(t){return po(this,t)}toJSON(){return{"/":po(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 e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??bo(n,o,s.bytes))}else if(e[Ji]===!0){let{version:n,multihash:o,code:s}=e,i=Se(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="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(e!==Ae)throw new Error(`Version 0 CID must use dag-pb (code: ${Ae}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=bo(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ae,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=St(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new se(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,w]=_e(t.subarray(e));return e+=w,u},o=n(),s=Ae;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,m=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:m,size:f}}static parse(t,e){let[n,o]=Yi(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Or(s).set(n,t),s}};function Yi(r,t){switch(r[0]){case"Q":{let e=t??G;return[G.prefix,e.decode(`${G.prefix}${r}`)]}case G.prefix:{let e=t??G;return[G.prefix,e.decode(r)]}case re.prefix:{let e=t??re;return[re.prefix,e.decode(r)]}case we.prefix:{let e=t??we;return[we.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Xi(r,t,e){let{prefix:n}=e;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function $i(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Ae=112,Wi=18;function bo(r,t,e){let n=oe(r),o=n+oe(t),s=new Uint8Array(o+e.byteLength);return ne(r,s,0),ne(t,s,n),s.set(e,o),s}var Ji=Symbol.for("@ipld/js-cid/CID");var Mr={};it(Mr,{identity:()=>dt});var yo=0,Qi="identity",go=St;function tc(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return ie(yo,go(r))}var dt={code:yo,name:Qi,encode:go,digest:tc};function ct(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function pt(r=0){return new Uint8Array(r)}function at(r=0){return new Uint8Array(r)}function Xe(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=at(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var wo=Symbol.for("@achingbrain/uint8arraylist");function xo(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function $e(r){return!!r?.[wo]}var ft=class r{bufs;length;[wo]=!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 e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if($e(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if($e(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=xo(this.bufs,t);return e.buf[e.index]}set(t,e){let n=xo(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if($e(t))for(let n=0;n<t.length;n++)this.set(e+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,e){let{bufs:n,length:o}=this._subList(t,e);return Xe(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Xe(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===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,m=e>a&&e<=c;if(f&&m){if(t===a&&e===c){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(m){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!$e(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(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;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 u=0;u<s;u++)i[u]=-1;for(let u=0;u<o;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,m;for(let u=e;u<=c;u+=m){m=0;for(let w=f;w>=0;w--){let _=this.get(u+w);if(n[w]!==_){m=Math.max(1,w-a[_]);break}}if(m===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=at(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=pt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=at(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=pt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!ct(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Pr={};it(Pr,{base10:()=>ec});var ec=Tt({prefix:"9",name:"base10",alphabet:"0123456789"});var qr={};it(qr,{base16:()=>rc,base16upper:()=>nc});var rc=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),nc=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Hr={};it(Hr,{base2:()=>oc});var oc=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Vr={};it(Vr,{base256emoji:()=>fc});var Eo=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}"),sc=Eo.reduce((r,t,e)=>(r[e]=t,r),[]),ic=Eo.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function cc(r){return r.reduce((t,e)=>(t+=sc[e],t),"")}function ac(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=ic[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var fc=ee({prefix:"\u{1F680}",name:"base256emoji",encode:cc,decode:ac});var zr={};it(zr,{base64:()=>uc,base64pad:()=>hc,base64url:()=>lc,base64urlpad:()=>dc});var uc=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),hc=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),lc=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),dc=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Fr={};it(Fr,{base8:()=>pc});var pc=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Zr={};it(Zr,{identity:()=>mc});var mc=ee({prefix:"\0",name:"identity",encode:r=>so(r),decode:r=>oo(r)});var Lf=new TextEncoder,Df=new TextDecoder;var Yr={};it(Yr,{sha256:()=>ve,sha512:()=>xc});var gc=20;function Gr({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new jr(r,t,e,n,o)}var jr=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??gc,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.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?_o(n,this.code,e?.truncate):n.then(o=>_o(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function _o(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return ie(t,r)}function Ao(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ve=Gr({name:"sha2-256",code:18,encode:Ao("SHA-256")}),xc=Gr({name:"sha2-512",code:19,encode:Ao("SHA-512")});var Xr={...Zr,...Hr,...Fr,...Pr,...qr,...Kr,...kr,...Ur,...zr,...Vr},Hf={...Yr,...Mr};function Bo(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var vo=Bo("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),$r=Bo("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=at(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),wc={utf8:vo,"utf-8":vo,hex:Xr.base16,latin1:$r,ascii:$r,binary:$r,...Xr},We=wc;function X(r,t="utf8"){let e=We[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function lt(r,t="utf8"){let e=We[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Ec=parseInt("11111",2),Wr=parseInt("10000000",2),_c=parseInt("01111111",2),Io={0:Be,1:Be,2:Sc,3:Bc,4:Ic,5:vc,6:Ac,16:Be,22:Be,48:Be};function Jr(r,t={offset:0}){let e=r[t.offset]&Ec;if(t.offset++,Io[e]!=null)return Io[e](r,t);throw new Error("No decoder for tag "+e)}function Ie(r,t){let e=0;if((r[t.offset]&Wr)===Wr){let n=r[t.offset]&_c,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Be(r,t){Ie(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Jr(r,t);if(n===null)break;e.push(n)}return e}function Sc(r,t){let e=Ie(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Ac(r,t){let e=Ie(r,t),n=t.offset+e,o=r[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=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let m=0;for(let u=0;u<c.length;u++)m+=c[u]<<u*7;a+=`.${m}`,c=[]}}return a}function vc(r,t){return t.offset++,null}function Bc(r,t){let e=Ie(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Ic(r,t){let e=Ie(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Lc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new ft;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Qr(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Lc(r.byteLength);return new ft(Uint8Array.from([t.byteLength|Wr]),t)}function Lo(r){let t=new ft,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new ft(Uint8Array.from([2]),Qr(t),t)}function Do(r){let t=Uint8Array.from([0]),e=new ft(t,r);return new ft(Uint8Array.from([3]),Qr(e),e)}function Je(r,t=48){let e=new ft;for(let n of r)e.append(n);return new ft(Uint8Array.from([t]),Qr(e),e)}async function Co(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Dc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Cc=Uint8Array.from([6,5,43,129,4,0,34]),Tc=Uint8Array.from([6,5,43,129,4,0,35]),Rc={ext:!0,kty:"EC",crv:"P-256"},Uc={ext:!0,kty:"EC",crv:"P-384"},Kc={ext:!0,kty:"EC",crv:"P-521"},tn=32,en=48,rn=66;function To(r){let t=Jr(r);return Ro(t)}function Ro(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===tn*2+1)return n=lt(t.subarray(e,e+tn),"base64url"),o=lt(t.subarray(e+tn),"base64url"),new ce({...Rc,key_ops:["verify"],x:n,y:o});if(t.byteLength===en*2+1)return n=lt(t.subarray(e,e+en),"base64url"),o=lt(t.subarray(e+en),"base64url"),new ce({...Uc,key_ops:["verify"],x:n,y:o});if(t.byteLength===rn*2+1)return n=lt(t.subarray(e,e+rn),"base64url"),o=lt(t.subarray(e+rn),"base64url"),new ce({...Kc,key_ops:["verify"],x:n,y:o});throw new _t(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Uo(r){return Je([Lo(Uint8Array.from([1])),Je([kc(r.crv)],160),Je([Do(new ft(Uint8Array.from([4]),X(r.x??"","base64url"),X(r.y??"","base64url")))],161)]).subarray()}function kc(r){if(r==="P-256")return Dc;if(r==="P-384")return Cc;if(r==="P-521")return Tc;throw new _t(`Invalid curve ${r}`)}var ce=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Uo(this.jwk)),this._raw}toMultihash(){return dt.digest(ae(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async verify(t,e,n){return Co(this.jwk,e,t,n)}};function Ft(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function xt(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function N(r,t,e=""){let n=Ft(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return r}function Qe(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");xt(r.outputLen),xt(r.blockLen)}function fe(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function ko(r,t){N(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new Error('"digestInto() output" expected to be of length >='+e)}function vt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function tr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function mt(r,t){return r<<32-t|r>>>t}var No=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Nc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Bt(r){if(N(r),No)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Nc[r[e]];return t}var At={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ko(r){if(r>=At._0&&r<=At._9)return r-At._0;if(r>=At.A&&r<=At.F)return r-(At.A-10);if(r>=At.a&&r<=At.f)return r-(At.a-10)}function It(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(No)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Ko(r.charCodeAt(s)),a=Ko(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function st(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];N(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function nn(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function ue(r=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(r))}var on=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function Oo(r,t,e){return r&t^~r&e}function Mo(r,t,e){return r&t^r&e^t&e}var Le=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=tr(this.buffer)}update(t){fe(this),N(t);let{view:e,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=tr(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(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){fe(this),ko(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,vt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let u=i;u<o;u++)e[u]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=tr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,m=this.get();if(f>m.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<f;u++)a.setUint32(4*u,m[u],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,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%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Lt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Q=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var er=BigInt(4294967295),Po=BigInt(32);function Oc(r,t=!1){return t?{h:Number(r&er),l:Number(r>>Po&er)}:{h:Number(r>>Po&er)|0,l:Number(r&er)|0}}function qo(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=Oc(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var sn=(r,t,e)=>r>>>e,cn=(r,t,e)=>r<<32-e|t>>>e,Zt=(r,t,e)=>r>>>e|t<<32-e,jt=(r,t,e)=>r<<32-e|t>>>e,De=(r,t,e)=>r<<64-e|t>>>e-32,Ce=(r,t,e)=>r>>>e-32|t<<64-e;function wt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ho=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Vo=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,zo=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Fo=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Zo=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),jo=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Pc=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]),Rt=new Uint32Array(64),an=class extends Le{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|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,e){for(let u=0;u<16;u++,e+=4)Rt[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let w=Rt[u-15],_=Rt[u-2],p=mt(w,7)^mt(w,18)^w>>>3,v=mt(_,17)^mt(_,19)^_>>>10;Rt[u]=v+Rt[u-7]+p+Rt[u-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:m}=this;for(let u=0;u<64;u++){let w=mt(a,6)^mt(a,11)^mt(a,25),_=m+w+Oo(a,c,f)+Pc[u]+Rt[u]|0,v=(mt(n,2)^mt(n,13)^mt(n,22))+Mo(n,o,s)|0;m=f,f=c,c=a,a=i+_|0,i=s,s=o,o=n,n=_+v|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,m=m+this.H|0,this.set(n,o,s,i,a,c,f,m)}roundClean(){vt(Rt)}destroy(){this.set(0,0,0,0,0,0,0,0),vt(this.buffer)}},fn=class extends an{A=Lt[0]|0;B=Lt[1]|0;C=Lt[2]|0;D=Lt[3]|0;E=Lt[4]|0;F=Lt[5]|0;G=Lt[6]|0;H=Lt[7]|0;constructor(){super(32)}};var Go=qo(["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(r=>BigInt(r))),qc=Go[0],Hc=Go[1],Ut=new Uint32Array(80),Kt=new Uint32Array(80),un=class extends Le{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:m,Fh:u,Fl:w,Gh:_,Gl:p,Hh:v,Hl:S}=this;return[t,e,n,o,s,i,a,c,f,m,u,w,_,p,v,S]}set(t,e,n,o,s,i,a,c,f,m,u,w,_,p,v,S){this.Ah=t|0,this.Al=e|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=m|0,this.Fh=u|0,this.Fl=w|0,this.Gh=_|0,this.Gl=p|0,this.Hh=v|0,this.Hl=S|0}process(t,e){for(let y=0;y<16;y++,e+=4)Ut[y]=t.getUint32(e),Kt[y]=t.getUint32(e+=4);for(let y=16;y<80;y++){let B=Ut[y-15]|0,U=Kt[y-15]|0,O=Zt(B,U,1)^Zt(B,U,8)^sn(B,U,7),M=jt(B,U,1)^jt(B,U,8)^cn(B,U,7),x=Ut[y-2]|0,g=Kt[y-2]|0,K=Zt(x,g,19)^De(x,g,61)^sn(x,g,6),P=jt(x,g,19)^Ce(x,g,61)^cn(x,g,6),C=zo(M,P,Kt[y-7],Kt[y-16]),l=Fo(C,O,K,Ut[y-7],Ut[y-16]);Ut[y]=l|0,Kt[y]=C|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:m,Eh:u,El:w,Fh:_,Fl:p,Gh:v,Gl:S,Hh:b,Hl:A}=this;for(let y=0;y<80;y++){let B=Zt(u,w,14)^Zt(u,w,18)^De(u,w,41),U=jt(u,w,14)^jt(u,w,18)^Ce(u,w,41),O=u&_^~u&v,M=w&p^~w&S,x=Zo(A,U,M,Hc[y],Kt[y]),g=jo(x,b,B,O,qc[y],Ut[y]),K=x|0,P=Zt(n,o,28)^De(n,o,34)^De(n,o,39),C=jt(n,o,28)^Ce(n,o,34)^Ce(n,o,39),l=n&s^n&a^s&a,d=o&i^o&c^i&c;b=v|0,A=S|0,v=_|0,S=p|0,_=u|0,p=w|0,{h:u,l:w}=wt(f|0,m|0,g|0,K|0),f=a|0,m=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let h=Ho(K,C,d);n=Vo(h,g,P,l),o=h|0}({h:n,l:o}=wt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=wt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=wt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:m}=wt(this.Dh|0,this.Dl|0,f|0,m|0),{h:u,l:w}=wt(this.Eh|0,this.El|0,u|0,w|0),{h:_,l:p}=wt(this.Fh|0,this.Fl|0,_|0,p|0),{h:v,l:S}=wt(this.Gh|0,this.Gl|0,v|0,S|0),{h:b,l:A}=wt(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,a,c,f,m,u,w,_,p,v,S,b,A)}roundClean(){vt(Ut,Kt)}destroy(){vt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},hn=class extends un{Ah=Q[0]|0;Al=Q[1]|0;Bh=Q[2]|0;Bl=Q[3]|0;Ch=Q[4]|0;Cl=Q[5]|0;Dh=Q[6]|0;Dl=Q[7]|0;Eh=Q[8]|0;El=Q[9]|0;Fh=Q[10]|0;Fl=Q[11]|0;Gh=Q[12]|0;Gl=Q[13]|0;Hh=Q[14]|0;Hl=Q[15]|0;constructor(){super(64)}};var Yo=nn(()=>new fn,on(1));var Xo=nn(()=>new hn,on(3));var dn=BigInt(0),ln=BigInt(1);function Dt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function $o(r){if(typeof r=="bigint"){if(!rr(r))throw new Error("positive bigint expected, got "+r)}else xt(r);return r}function Te(r){let t=$o(r).toString(16);return t.length&1?"0"+t:t}function Wo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?dn:BigInt("0x"+r)}function he(r){return Wo(Bt(r))}function Gt(r){return Wo(Bt(or(N(r)).reverse()))}function nr(r,t){xt(t),r=$o(r);let e=It(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function pn(r,t){return nr(r,t).reverse()}function or(r){return Uint8Array.from(r)}var rr=r=>typeof r=="bigint"&&dn<=r;function Vc(r,t,e){return rr(r)&&rr(t)&&rr(e)&&t<=r&&r<e}function Re(r,t,e,n){if(!Vc(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function mn(r){let t;for(t=0;r>dn;r>>=ln,t+=1);return t}var Ue=r=>(ln<<BigInt(r))-ln;function Jo(r,t,e){if(xt(r,"hashLen"),xt(t,"qByteLen"),typeof e!="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(r),f=n(r),m=0,u=()=>{c.fill(1),f.fill(0),m=0},w=(...S)=>e(f,st(c,...S)),_=(S=o)=>{f=w(s,S),c=w(),S.length!==0&&(f=w(i,S),c=w())},p=()=>{if(m++>=a)throw new Error("drbg: tried max amount of iterations");let S=0,b=[];for(;S<t;){c=w();let A=c.slice();b.push(A),S+=c.length}return st(...b)};return(S,b)=>{u(),_(S);let A;for(;!(A=b(p()));)_();return u(),A}}function kt(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(s,i,a){let c=r[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(e,!0)}function le(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var rt=BigInt(0),$=BigInt(1),Yt=BigInt(2),es=BigInt(3),rs=BigInt(4),ns=BigInt(5),zc=BigInt(7),os=BigInt(8),Fc=BigInt(9),ss=BigInt(16);function Y(r,t){let e=r%t;return e>=rt?e:t+e}function V(r,t,e){let n=r;for(;t-- >rt;)n*=n,n%=e;return n}function Qo(r,t){if(r===rt)throw new Error("invert: expected non-zero number");if(t<=rt)throw new Error("invert: expected positive modulus, got "+t);let e=Y(r,t),n=t,o=rt,s=$,i=$,a=rt;for(;e!==rt;){let f=n/e,m=n%e,u=o-i*f,w=s-a*f;n=e,e=m,o=i,s=a,i=u,a=w}if(n!==$)throw new Error("invert: does not exist");return Y(o,t)}function yn(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function is(r,t){let e=(r.ORDER+$)/rs,n=r.pow(t,e);return yn(r,n,t),n}function Zc(r,t){let e=(r.ORDER-ns)/os,n=r.mul(t,Yt),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,Yt),o),a=r.mul(s,r.sub(i,r.ONE));return yn(r,a,t),a}function jc(r){let t=de(r),e=cs(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+zc)/ss;return(a,c)=>{let f=a.pow(c,i),m=a.mul(f,n),u=a.mul(f,o),w=a.mul(f,s),_=a.eql(a.sqr(m),c),p=a.eql(a.sqr(u),c);f=a.cmov(f,m,_),m=a.cmov(w,u,p);let v=a.eql(a.sqr(m),c),S=a.cmov(f,m,v);return yn(a,S,c),S}}function cs(r){if(r<es)throw new Error("sqrt is not defined for small field");let t=r-$,e=0;for(;t%Yt===rt;)t/=Yt,e++;let n=Yt,o=de(r);for(;ts(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return is;let s=o.pow(n,t),i=(t+$)/Yt;return function(c,f){if(c.is0(f))return f;if(ts(c,f)!==1)throw new Error("Cannot find square root");let m=e,u=c.mul(c.ONE,s),w=c.pow(f,t),_=c.pow(f,i);for(;!c.eql(w,c.ONE);){if(c.is0(w))return c.ZERO;let p=1,v=c.sqr(w);for(;!c.eql(v,c.ONE);)if(p++,v=c.sqr(v),p===m)throw new Error("Cannot find square root");let S=$<<BigInt(m-p-1),b=c.pow(u,S);m=p,u=c.sqr(b),w=c.mul(w,u),_=c.mul(_,b)}return _}}function Gc(r){return r%rs===es?is:r%os===ns?Zc:r%ss===Fc?jc(r):cs(r)}var as=(r,t)=>(Y(r,t)&$)===$,Yc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function gn(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=Yc.reduce((n,o)=>(n[o]="function",n),t);return kt(r,e),r}function Xc(r,t,e){if(e<rt)throw new Error("invalid exponent, negatives unsupported");if(e===rt)return r.ONE;if(e===$)return t;let n=r.ONE,o=t;for(;e>rt;)e&$&&(n=r.mul(n,o)),o=r.sqr(o),e>>=$;return n}function Ke(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function ts(r,t){let e=(r.ORDER-$)/Yt,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function $c(r,t){t!==void 0&&xt(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var bn=class{ORDER;BITS;BYTES;isLE;ZERO=rt;ONE=$;_lengths;_sqrt;_mod;constructor(t,e={}){if(t<=rt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&(this.sqrt=e.sqrt),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=e.allowedLengths?.slice()),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=$c(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 Y(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return rt<=t&&t<this.ORDER}is0(t){return t===rt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&$)===$}neg(t){return Y(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Y(t*t,this.ORDER)}add(t,e){return Y(t+e,this.ORDER)}sub(t,e){return Y(t-e,this.ORDER)}mul(t,e){return Y(t*e,this.ORDER)}pow(t,e){return Xc(this,t,e)}div(t,e){return Y(t*Qo(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return Qo(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Gc(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?pn(t,this.BYTES):nr(t,this.BYTES)}fromBytes(t,e=!1){N(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?Gt(t):he(t);if(a&&(c=Y(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Ke(this,t)}cmov(t,e,n){return n?e:t}};function de(r,t={}){return new bn(r,t)}function fs(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function xn(r){let t=fs(r);return t+Math.ceil(t/2)}function wn(r,t,e=!1){N(r);let n=r.length,o=fs(t),s=xn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Gt(r):he(r),a=Y(i,t-$)+$;return e?pn(a,o):nr(a,o)}var pe=BigInt(0),Xt=BigInt(1);function ke(r,t){let e=t.negate();return r?e:t}function $t(r,t){let e=Ke(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function ds(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function En(r,t){ds(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=Ue(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function us(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=Xt);let f=t*n,m=f+Math.abs(a)-1,u=a===0,w=a<0,_=t%2!==0;return{nextN:c,offset:m,isZero:u,isNeg:w,isNegF:_,offsetF:f}}var _n=new WeakMap,ps=new WeakMap;function Sn(r){return ps.get(r)||1}function hs(r){if(r!==pe)throw new Error("invalid wNAF")}var me=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>pe;)e&Xt&&(n=n.add(o)),o=o.double(),e>>=Xt;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=En(e,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,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=En(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:m,isNeg:u,isNegF:w,offsetF:_}=us(n,a,i);n=c,m?s=s.add(ke(w,e[_])):o=o.add(ke(u,e[f]))}return hs(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=En(t,this.bits);for(let i=0;i<s.windows&&n!==pe;i++){let{nextN:a,offset:c,isZero:f,isNeg:m}=us(n,i,s);if(n=a,!f){let u=e[c];o=o.add(m?u.negate():u)}}return hs(n),o}getPrecomputes(t,e,n){let o=_n.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),_n.set(e,o))),o}cached(t,e,n){let o=Sn(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=Sn(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){ds(e,this.bits),ps.set(t,e),_n.delete(t)}hasCache(t){return Sn(t)!==1}};function ms(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>pe||n>pe;)e&Xt&&(s=s.add(o)),n&Xt&&(i=i.add(o)),o=o.double(),e>>=Xt,n>>=Xt;return{p1:s,p2:i}}function ls(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return gn(t),t}else return de(r,{isLE:e})}function sr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>pe))throw new Error(`CURVE.${c} must be positive bigint`)}let o=ls(t.p,e.Fp,n),s=ls(t.n,e.Fn,n),a=["Gx","Gy","a",r==="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 ir(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var Nt=BigInt(0),W=BigInt(1),An=BigInt(2),Wc=BigInt(8);function Jc(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function bs(r,t={}){let e=sr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i}=s;kt(t,{},{uvRatio:"function"});let a=An<<BigInt(o.BYTES*8)-W,c=S=>n.create(S),f=t.uvRatio||((S,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,b))}}catch{return{isValid:!1,value:Nt}}});if(!Jc(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function m(S,b,A=!1){let y=A?W:Nt;return Re("coordinate "+S,b,y,a),b}function u(S){if(!(S instanceof p))throw new Error("EdwardsPoint expected")}let w=le((S,b)=>{let{X:A,Y:y,Z:B}=S,U=S.is0();b==null&&(b=U?Wc:n.inv(B));let O=c(A*b),M=c(y*b),x=n.mul(B,b);if(U)return{x:Nt,y:W};if(x!==W)throw new Error("invZ was invalid");return{x:O,y:M}}),_=le(S=>{let{a:b,d:A}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:y,Y:B,Z:U,T:O}=S,M=c(y*y),x=c(B*B),g=c(U*U),K=c(g*g),P=c(M*b),C=c(g*c(P+x)),l=c(K+c(A*c(M*x)));if(C!==l)throw new Error("bad point: equation left != right (1)");let d=c(y*B),h=c(U*O);if(d!==h)throw new Error("bad point: equation left != right (2)");return!0});class p{static BASE=new p(s.Gx,s.Gy,W,c(s.Gx*s.Gy));static ZERO=new p(Nt,W,W,Nt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(b,A,y,B){this.X=m("x",b),this.Y=m("y",A),this.Z=m("z",y,!0),this.T=m("t",B),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof p)throw new Error("extended point not allowed");let{x:A,y}=b||{};return m("x",A),m("y",y),new p(A,y,W,c(A*y))}static fromBytes(b,A=!1){let y=n.BYTES,{a:B,d:U}=s;b=or(N(b,y,"point")),Dt(A,"zip215");let O=or(b),M=b[y-1];O[y-1]=M&-129;let x=Gt(O),g=A?a:n.ORDER;Re("point.y",x,Nt,g);let K=c(x*x),P=c(K-W),C=c(U*K-B),{isValid:l,value:d}=f(P,C);if(!l)throw new Error("bad point: invalid y coordinate");let h=(d&W)===W,E=(M&128)!==0;if(!A&&d===Nt&&E)throw new Error("bad point: x=0 and x_0=1");return E!==h&&(d=c(-d)),p.fromAffine({x:d,y:x})}static fromHex(b,A=!1){return p.fromBytes(It(b),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,A=!0){return v.createCache(this,b),A||this.multiply(An),this}assertValidity(){_(this)}equals(b){u(b);let{X:A,Y:y,Z:B}=this,{X:U,Y:O,Z:M}=b,x=c(A*M),g=c(U*B),K=c(y*M),P=c(O*B);return x===g&&K===P}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:b}=s,{X:A,Y:y,Z:B}=this,U=c(A*A),O=c(y*y),M=c(An*c(B*B)),x=c(b*U),g=A+y,K=c(c(g*g)-U-O),P=x+O,C=P-M,l=x-O,d=c(K*C),h=c(P*l),E=c(K*l),I=c(C*P);return new p(d,h,I,E)}add(b){u(b);let{a:A,d:y}=s,{X:B,Y:U,Z:O,T:M}=this,{X:x,Y:g,Z:K,T:P}=b,C=c(B*x),l=c(U*g),d=c(M*y*P),h=c(O*K),E=c((B+U)*(x+g)-C-l),I=h-d,D=h+d,T=c(l-A*C),L=c(E*I),R=c(D*T),k=c(E*T),z=c(I*D);return new p(L,R,z,k)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:y}=v.cached(this,b,B=>$t(p,B));return $t(p,[A,y])[0]}multiplyUnsafe(b,A=p.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===Nt?p.ZERO:this.is0()||b===W?this:v.unsafe(this,b,y=>$t(p,y),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return v.unsafe(this,s.n).is0()}toAffine(b){return w(this,b)}clearCofactor(){return i===W?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:A}=this.toAffine(),y=n.toBytes(A);return y[y.length-1]|=b&W?128:0,y}toHex(){return Bt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let v=new me(p,o.BITS);return p.BASE.precompute(8),p}function ys(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');kt(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,a=e.randomBytes||ue,c=e.adjustScalarBytes||(x=>x),f=e.domain||((x,g,K)=>{if(Dt(K,"phflag"),g.length||K)throw new Error("Contexts/pre-hash are not supported");return x});function m(x){return i.create(Gt(x))}function u(x){let g=y.secretKey;N(x,y.secretKey,"secretKey");let K=N(t(x),2*g,"hashedSecretKey"),P=c(K.slice(0,g)),C=K.slice(g,2*g),l=m(P);return{head:P,prefix:C,scalar:l}}function w(x){let{head:g,prefix:K,scalar:P}=u(x),C=o.multiply(P),l=C.toBytes();return{head:g,prefix:K,scalar:P,point:C,pointBytes:l}}function _(x){return w(x).pointBytes}function p(x=Uint8Array.of(),...g){let K=st(...g);return m(t(f(K,N(x,void 0,"context"),!!n)))}function v(x,g,K={}){x=N(x,void 0,"message"),n&&(x=n(x));let{prefix:P,scalar:C,pointBytes:l}=w(g),d=p(K.context,P,x),h=o.multiply(d).toBytes(),E=p(K.context,h,l,x),I=i.create(d+E*C);if(!i.isValid(I))throw new Error("sign failed: invalid s");let D=st(h,i.toBytes(I));return N(D,y.signature,"result")}let S={zip215:!0};function b(x,g,K,P=S){let{context:C,zip215:l}=P,d=y.signature;x=N(x,d,"signature"),g=N(g,void 0,"message"),K=N(K,y.publicKey,"publicKey"),l!==void 0&&Dt(l,"zip215"),n&&(g=n(g));let h=d/2,E=x.subarray(0,h),I=Gt(x.subarray(h,d)),D,T,L;try{D=r.fromBytes(K,l),T=r.fromBytes(E,l),L=o.multiplyUnsafe(I)}catch{return!1}if(!l&&D.isSmallOrder())return!1;let R=p(C,T.toBytes(),D.toBytes(),g);return T.add(D.multiplyUnsafe(R)).subtract(L).clearCofactor().is0()}let A=s.BYTES,y={secretKey:A,publicKey:A,signature:2*A,seed:A};function B(x=a(y.seed)){return N(x,y.seed,"seed")}function U(x){return Ft(x)&&x.length===i.BYTES}function O(x,g){try{return!!r.fromBytes(x,g)}catch{return!1}}let M={getExtendedPublicKey:w,randomSecretKey:B,isValidSecretKey:U,isValidPublicKey:O,toMontgomery(x){let{y:g}=r.fromBytes(x),K=y.publicKey,P=K===32;if(!P&&K!==57)throw new Error("only defined for 25519 and 448");let C=P?s.div(W+g,W-g):s.div(g-W,g+W);return s.toBytes(C)},toMontgomerySecret(x){let g=y.secretKey;N(x,g);let K=t(x.subarray(0,g));return c(K).subarray(0,g)}};return Object.freeze({keygen:ir(B,_),getPublicKey:_,sign:v,verify:b,utils:M,Point:r,lengths:y})}var Qc=BigInt(1),gs=BigInt(2);var ta=BigInt(5),ea=BigInt(8),vn=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ra={p:vn,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:ea,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function na(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=vn,a=r*r%s*r%s,c=V(a,gs,s)*a%s,f=V(c,Qc,s)*r%s,m=V(f,ta,s)*f%s,u=V(m,t,s)*m%s,w=V(u,e,s)*u%s,_=V(w,n,s)*w%s,p=V(_,o,s)*_%s,v=V(p,o,s)*_%s,S=V(v,t,s)*m%s;return{pow_p_5_8:V(S,gs,s)*r%s,b2:a}}function oa(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var xs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function sa(r,t){let e=vn,n=Y(t*t*t,e),o=Y(n*n*t,e),s=na(r*o).pow_p_5_8,i=Y(r*n*s,e),a=Y(t*i*i,e),c=i,f=Y(i*xs,e),m=a===r,u=a===Y(-r,e),w=a===Y(-r*xs,e);return m&&(i=c),(u||w)&&(i=f),as(i,e)&&(i=Y(-i,e)),{isValid:m||u,value:i}}var ia=bs(ra,{uvRatio:sa});function ca(r){return ys(ia,Xo,Object.assign({adjustScalarBytes:oa},r))}var ws=ca({});var Ne=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},cr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Es={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new cr("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 ar=Es;var fr=32;var Bn,aa=(async()=>{try{return await ar.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function fa(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await ar.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await ar.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ua(r,t,e){return ws.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function _s(r,t,e){return Bn==null&&(Bn=await aa),Bn?fa(r,t,e):ua(r,t,e)}function ur(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var hr=class{type="Ed25519";raw;constructor(t){this.raw=In(t,fr)}toMultihash(){return dt.digest(ae(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=_s(this.raw,e,t);return ur(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function As(r){return r=In(r,fr),new hr(r)}function In(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new _t(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var la=Math.pow(2,7),da=Math.pow(2,14),pa=Math.pow(2,21),vs=Math.pow(2,28),Bs=Math.pow(2,35),Is=Math.pow(2,42),Ls=Math.pow(2,49),nt=128,Ot=127;function Oe(r){if(r<la)return 1;if(r<da)return 2;if(r<pa)return 3;if(r<vs)return 4;if(r<Bs)return 5;if(r<Is)return 6;if(r<Ls)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ds(r,t,e=0){switch(Oe(r)){case 8:t[e++]=r&255|nt,r/=128;case 7:t[e++]=r&255|nt,r/=128;case 6:t[e++]=r&255|nt,r/=128;case 5:t[e++]=r&255|nt,r/=128;case 4:t[e++]=r&255|nt,r>>>=7;case 3:t[e++]=r&255|nt,r>>>=7;case 2:t[e++]=r&255|nt,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Cs(r,t){let e=r[t],n=0;if(n+=e&Ot,e<nt||(e=r[t+1],n+=(e&Ot)<<7,e<nt)||(e=r[t+2],n+=(e&Ot)<<14,e<nt)||(e=r[t+3],n+=(e&Ot)<<21,e<nt)||(e=r[t+4],n+=(e&Ot)*vs,e<nt)||(e=r[t+5],n+=(e&Ot)*Bs,e<nt)||(e=r[t+6],n+=(e&Ot)*Is,e<nt)||(e=r[t+7],n+=(e&Ot)*Ls,e<nt))return n;throw new RangeError("Could not decode varint")}var Ln=new Float32Array([-0]),Mt=new Uint8Array(Ln.buffer);function Ts(r,t,e){Ln[0]=r,t[e]=Mt[0],t[e+1]=Mt[1],t[e+2]=Mt[2],t[e+3]=Mt[3]}function Rs(r,t){return Mt[0]=r[t],Mt[1]=r[t+1],Mt[2]=r[t+2],Mt[3]=r[t+3],Ln[0]}var Dn=new Float64Array([-0]),et=new Uint8Array(Dn.buffer);function Us(r,t,e){Dn[0]=r,t[e]=et[0],t[e+1]=et[1],t[e+2]=et[2],t[e+3]=et[3],t[e+4]=et[4],t[e+5]=et[5],t[e+6]=et[6],t[e+7]=et[7]}function Ks(r,t){return et[0]=r[t],et[1]=r[t+1],et[2]=r[t+2],et[3]=r[t+3],et[4]=r[t+4],et[5]=r[t+5],et[6]=r[t+6],et[7]=r[t+7],Dn[0]}var ma=BigInt(Number.MAX_SAFE_INTEGER),ba=BigInt(Number.MIN_SAFE_INTEGER),ut=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+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 e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(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,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Wt;if(t<ma&&t>ba)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>ks&&(o=0n,++n>ks&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Wt;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):Wt}},Wt=new ut(0,0);Wt.toBigInt=function(){return 0n};Wt.zzEncode=Wt.zzDecode=function(){return this};Wt.length=function(){return 1};var ks=4294967296n;function Ns(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Os(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[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 Cn(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function bt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function lr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Tn=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,bt(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 bt(this,4);return lr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw bt(this,4);return lr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw bt(this,4);let t=Rs(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw bt(this,4);let t=Ks(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw bt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Os(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw bt(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 ut(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*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;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw bt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw bt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw bt(this,8);let t=lr(this.buf,this.pos+=4),e=lr(this.buf,this.pos+=4);return new ut(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Cs(this.buf,this.pos);return this.pos+=Oe(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 Rn(r){return new Tn(r instanceof Uint8Array?r:r.subarray())}function dr(r,t,e){let n=Rn(r);return t.decode(n,void 0,e)}function Un(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return at(i);o+i>t&&(n=at(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Jt=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Kn(){}var Nn=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ya=Un();function ga(r){return globalThis.Buffer!=null?at(r):ya(r)}var Pe=class{len;head;tail;states;constructor(){this.len=0,this.head=new Jt(Kn,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Jt(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new On((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(pr,10,ut.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=ut.fromBigInt(t);return this._push(pr,e.length(),e)}uint64Number(t){return this._push(Ds,Oe(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 e=ut.fromBigInt(t).zzEncode();return this._push(pr,e.length(),e)}sint64Number(t){let e=ut.fromNumber(t).zzEncode();return this._push(pr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(kn,1,t?1:0)}fixed32(t){return this._push(Me,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=ut.fromBigInt(t);return this._push(Me,4,e.lo)._push(Me,4,e.hi)}fixed64Number(t){let e=ut.fromNumber(t);return this._push(Me,4,e.lo)._push(Me,4,e.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(Ts,4,t)}double(t){return this._push(Us,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(kn,1,0):this.uint32(e)._push(wa,e,t)}string(t){let e=Ns(t);return e!==0?this.uint32(e)._push(Cn,e,t):this._push(kn,1,0)}fork(){return this.states=new Nn(this),this.head=this.tail=new Jt(Kn,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 Jt(Kn,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=ga(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function kn(r,t,e){t[e]=r&255}function xa(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var On=class extends Jt{next;constructor(t,e){super(xa,t,e),this.next=void 0}};function pr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Me(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function wa(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Pe.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ea,t,r),this},Pe.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(_a,t,r),this});function Ea(r,t,e){t.set(r,e)}function _a(r,t,e){r.length<40?Cn(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(X(r),e)}function Mn(){return new Pe}function mr(r,t){let e=Mn();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var be;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(be||(be={}));function br(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Pn(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return br("enum",be.VARINT,e,n)}function yr(r,t){return br("message",be.LENGTH_DELIMITED,r,t)}var ht;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ht||(ht={}));var qn;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(qn||(qn={}));(function(r){r.codec=()=>Pn(qn)})(ht||(ht={}));var qe;(function(r){let t;r.codec=()=>(t==null&&(t=yr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ht.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=ht.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>mr(e,r.codec()),r.decode=(e,n)=>dr(e,r.codec(),n)})(qe||(qe={}));var Hn;(function(r){let t;r.codec=()=>(t==null&&(t=yr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ht.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=ht.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>mr(e,r.codec()),r.decode=(e,n)=>dr(e,r.codec(),n)})(Hn||(Hn={}));var gr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Qe(t),N(e,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(e.length>n?t.create().update(e).digest():e);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),vt(o)}update(t){return fe(this),this.iHash.update(t),this}digestInto(t){fe(this),N(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:e,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=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Vn=(r,t,e)=>new gr(r,t).update(e).digest();Vn.create=(r,t)=>new gr(r,t);var Ps=(r,t)=>(r+(r>=0?t:-t)/qs)/t;function Aa(r,t,e){let[[n,o],[s,i]]=t,a=Ps(i*r,e),c=Ps(-o*r,e),f=r-a*n-c*s,m=-a*o-c*i,u=f<Ct,w=m<Ct;u&&(f=-f),w&&(m=-m);let _=Ue(Math.ceil(mn(e)/2))+ye;if(f<Ct||f>=_||m<Ct||m>=_)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:u,k1:f,k2neg:w,k2:m}}function Fn(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function zn(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Dt(e.lowS,"lowS"),Dt(e.prehash,"prehash"),e.format!==void 0&&Fn(e.format),e}var Zn=class extends Error{constructor(t=""){super(t)}},Pt={Err:Zn,_tlv:{encode:(r,t)=>{let{Err:e}=Pt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Te(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Te(o.length/2|128):"";return Te(r)+s+o+t},decode(r,t){let{Err:e}=Pt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("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 e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let m of f)i=i<<8|m;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Pt;if(r<Ct)throw new t("integer: negative integers are not allowed");let e=Te(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Pt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return he(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Pt,o=N(r,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:m}=n.decode(2,c);if(m.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=Pt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Ct=BigInt(0),ye=BigInt(1),qs=BigInt(2),xr=BigInt(3),va=BigInt(4);function Hs(r,t={}){let e=sr("weierstrass",r,t),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i,n:a}=s;kt(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=zs(n,o);function m(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(C,l,d){let{x:h,y:E}=l.toAffine(),I=n.toBytes(h);if(Dt(d,"isCompressed"),d){m();let D=!n.isOdd(E);return st(Vs(D),I)}else return st(Uint8Array.of(4),I,n.toBytes(E))}function w(C){N(C,void 0,"Point");let{publicKey:l,publicKeyUncompressed:d}=f,h=C.length,E=C[0],I=C.subarray(1);if(h===l&&(E===2||E===3)){let D=n.fromBytes(I);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let T=v(D),L;try{L=n.sqrt(T)}catch(z){let H=z instanceof Error?": "+z.message:"";throw new Error("bad point: is not on curve, sqrt error"+H)}m();let R=n.isOdd(L);return(E&1)===1!==R&&(L=n.neg(L)),{x:D,y:L}}else if(h===d&&E===4){let D=n.BYTES,T=n.fromBytes(I.subarray(0,D)),L=n.fromBytes(I.subarray(D,D*2));if(!S(T,L))throw new Error("bad point: is not on curve");return{x:T,y:L}}else throw new Error(`bad point: got length ${h}, expected compressed=${l} or uncompressed=${d}`)}let _=t.toBytes||u,p=t.fromBytes||w;function v(C){let l=n.sqr(C),d=n.mul(l,C);return n.add(n.add(d,n.mul(C,s.a)),s.b)}function S(C,l){let d=n.sqr(l),h=v(C);return n.eql(d,h)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,xr),va),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,A)))throw new Error("bad curve params: a or b");function y(C,l,d=!1){if(!n.isValid(l)||d&&n.is0(l))throw new Error(`bad point coordinate ${C}`);return l}function B(C){if(!(C instanceof g))throw new Error("Weierstrass Point expected")}function U(C){if(!c||!c.basises)throw new Error("no endo");return Aa(C,c.basises,o.ORDER)}let O=le((C,l)=>{let{X:d,Y:h,Z:E}=C;if(n.eql(E,n.ONE))return{x:d,y:h};let I=C.is0();l==null&&(l=I?n.ONE:n.inv(E));let D=n.mul(d,l),T=n.mul(h,l),L=n.mul(E,l);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(L,n.ONE))throw new Error("invZ was invalid");return{x:D,y:T}}),M=le(C=>{if(C.is0()){if(t.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:l,y:d}=C.toAffine();if(!n.isValid(l)||!n.isValid(d))throw new Error("bad point: x or y not field elements");if(!S(l,d))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function x(C,l,d,h,E){return d=new g(n.mul(d.X,C),d.Y,d.Z),l=ke(h,l),d=ke(E,d),l.add(d)}class g{static BASE=new g(s.Gx,s.Gy,n.ONE);static ZERO=new g(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(l,d,h){this.X=y("x",l),this.Y=y("y",d,!0),this.Z=y("z",h),Object.freeze(this)}static CURVE(){return s}static fromAffine(l){let{x:d,y:h}=l||{};if(!l||!n.isValid(d)||!n.isValid(h))throw new Error("invalid affine point");if(l instanceof g)throw new Error("projective point not allowed");return n.is0(d)&&n.is0(h)?g.ZERO:new g(d,h,n.ONE)}static fromBytes(l){let d=g.fromAffine(p(N(l,void 0,"point")));return d.assertValidity(),d}static fromHex(l){return g.fromBytes(It(l))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(l=8,d=!0){return P.createCache(this,l),d||this.multiply(xr),this}assertValidity(){M(this)}hasEvenY(){let{y:l}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(l)}equals(l){B(l);let{X:d,Y:h,Z:E}=this,{X:I,Y:D,Z:T}=l,L=n.eql(n.mul(d,T),n.mul(I,E)),R=n.eql(n.mul(h,T),n.mul(D,E));return L&&R}negate(){return new g(this.X,n.neg(this.Y),this.Z)}double(){let{a:l,b:d}=s,h=n.mul(d,xr),{X:E,Y:I,Z:D}=this,T=n.ZERO,L=n.ZERO,R=n.ZERO,k=n.mul(E,E),z=n.mul(I,I),H=n.mul(D,D),q=n.mul(E,I);return q=n.add(q,q),R=n.mul(E,D),R=n.add(R,R),T=n.mul(l,R),L=n.mul(h,H),L=n.add(T,L),T=n.sub(z,L),L=n.add(z,L),L=n.mul(T,L),T=n.mul(q,T),R=n.mul(h,R),H=n.mul(l,H),q=n.sub(k,H),q=n.mul(l,q),q=n.add(q,R),R=n.add(k,k),k=n.add(R,k),k=n.add(k,H),k=n.mul(k,q),L=n.add(L,k),H=n.mul(I,D),H=n.add(H,H),k=n.mul(H,q),T=n.sub(T,k),R=n.mul(H,z),R=n.add(R,R),R=n.add(R,R),new g(T,L,R)}add(l){B(l);let{X:d,Y:h,Z:E}=this,{X:I,Y:D,Z:T}=l,L=n.ZERO,R=n.ZERO,k=n.ZERO,z=s.a,H=n.mul(s.b,xr),q=n.mul(d,I),F=n.mul(h,D),J=n.mul(E,T),gt=n.add(d,h),Z=n.add(I,D);gt=n.mul(gt,Z),Z=n.add(q,F),gt=n.sub(gt,Z),Z=n.add(d,E);let tt=n.add(I,T);return Z=n.mul(Z,tt),tt=n.add(q,J),Z=n.sub(Z,tt),tt=n.add(h,E),L=n.add(D,T),tt=n.mul(tt,L),L=n.add(F,J),tt=n.sub(tt,L),k=n.mul(z,Z),L=n.mul(H,J),k=n.add(L,k),L=n.sub(F,k),k=n.add(F,k),R=n.mul(L,k),F=n.add(q,q),F=n.add(F,q),J=n.mul(z,J),Z=n.mul(H,Z),F=n.add(F,J),J=n.sub(q,J),J=n.mul(z,J),Z=n.add(Z,J),q=n.mul(F,Z),R=n.add(R,q),q=n.mul(tt,Z),L=n.mul(gt,L),L=n.sub(L,q),q=n.mul(gt,F),k=n.mul(tt,k),k=n.add(k,q),new g(L,R,k)}subtract(l){return this.add(l.negate())}is0(){return this.equals(g.ZERO)}multiply(l){let{endo:d}=t;if(!o.isValidNot0(l))throw new Error("invalid scalar: out of range");let h,E,I=D=>P.cached(this,D,T=>$t(g,T));if(d){let{k1neg:D,k1:T,k2neg:L,k2:R}=U(l),{p:k,f:z}=I(T),{p:H,f:q}=I(R);E=z.add(q),h=x(d.beta,k,H,D,L)}else{let{p:D,f:T}=I(l);h=D,E=T}return $t(g,[h,E])[0]}multiplyUnsafe(l){let{endo:d}=t,h=this;if(!o.isValid(l))throw new Error("invalid scalar: out of range");if(l===Ct||h.is0())return g.ZERO;if(l===ye)return h;if(P.hasCache(this))return this.multiply(l);if(d){let{k1neg:E,k1:I,k2neg:D,k2:T}=U(l),{p1:L,p2:R}=ms(g,h,I,T);return x(d.beta,L,R,E,D)}else return P.unsafe(h,l)}toAffine(l){return O(this,l)}isTorsionFree(){let{isTorsionFree:l}=t;return i===ye?!0:l?l(g,this):P.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:l}=t;return i===ye?this:l?l(g,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(l=!0){return Dt(l,"isCompressed"),this.assertValidity(),_(g,this,l)}toHex(l=!0){return Bt(this.toBytes(l))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let K=o.BITS,P=new me(g,t.endo?Math.ceil(K/2):K);return g.BASE.precompute(8),g}function Vs(r){return Uint8Array.of(r?2:3)}function zs(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ba(r,t={}){let{Fn:e}=r,n=t.randomBytes||ue,o=Object.assign(zs(r.Fp,e),{seed:xn(e.ORDER)});function s(_){try{let p=e.fromBytes(_);return e.isValidNot0(p)}catch{return!1}}function i(_,p){let{publicKey:v,publicKeyUncompressed:S}=o;try{let b=_.length;return p===!0&&b!==v||p===!1&&b!==S?!1:!!r.fromBytes(_)}catch{return!1}}function a(_=n(o.seed)){return wn(N(_,o.seed,"seed"),e.ORDER)}function c(_,p=!0){return r.BASE.multiply(e.fromBytes(_)).toBytes(p)}function f(_){let{secretKey:p,publicKey:v,publicKeyUncompressed:S}=o;if(!Ft(_)||"_lengths"in e&&e._lengths||p===v)return;let b=N(_,void 0,"key").length;return b===v||b===S}function m(_,p,v=!0){if(f(_)===!0)throw new Error("first arg must be private key");if(f(p)===!1)throw new Error("second arg must be public key");let S=e.fromBytes(_);return r.fromBytes(p).multiply(S).toBytes(v)}let u={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},w=ir(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:m,keygen:w,Point:r,utils:u,lengths:o})}function Fs(r,t,e={}){Qe(t),kt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||ue,o=e.hmac||((d,h)=>Vn(t,d,h)),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,{keygen:f,getPublicKey:m,getSharedSecret:u,utils:w,lengths:_}=Ba(r,e),p={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},v=a*qs<s.ORDER;function S(d){let h=a>>ye;return d>h}function b(d,h){if(!i.isValidNot0(h))throw new Error(`invalid signature ${d}: out of range 1..Point.Fn.ORDER`);return h}function A(){if(v)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function y(d,h){Fn(h);let E=_.signature,I=h==="compact"?E:h==="recovered"?E+1:void 0;return N(d,I)}class B{r;s;recovery;constructor(h,E,I){if(this.r=b("r",h),this.s=b("s",E),I!=null){if(A(),![0,1,2,3].includes(I))throw new Error("invalid recovery id");this.recovery=I}Object.freeze(this)}static fromBytes(h,E=p.format){y(h,E);let I;if(E==="der"){let{r:R,s:k}=Pt.toSig(N(h));return new B(R,k)}E==="recovered"&&(I=h[0],E="compact",h=h.subarray(1));let D=_.signature/2,T=h.subarray(0,D),L=h.subarray(D,D*2);return new B(i.fromBytes(T),i.fromBytes(L),I)}static fromHex(h,E){return this.fromBytes(It(h),E)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new B(this.r,this.s,h)}recoverPublicKey(h){let{r:E,s:I}=this,D=this.assertRecovery(),T=D===2||D===3?E+a:E;if(!s.isValid(T))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let L=s.toBytes(T),R=r.fromBytes(st(Vs((D&1)===0),L)),k=i.inv(T),z=O(N(h,void 0,"msgHash")),H=i.create(-z*k),q=i.create(I*k),F=r.BASE.multiplyUnsafe(H).add(R.multiplyUnsafe(q));if(F.is0())throw new Error("invalid recovery: point at infinify");return F.assertValidity(),F}hasHighS(){return S(this.s)}toBytes(h=p.format){if(Fn(h),h==="der")return It(Pt.hexFromSig(this));let{r:E,s:I}=this,D=i.toBytes(E),T=i.toBytes(I);return h==="recovered"?(A(),st(Uint8Array.of(this.assertRecovery()),D,T)):st(D,T)}toHex(h){return Bt(this.toBytes(h))}}let U=e.bits2int||function(h){if(h.length>8192)throw new Error("input is too large");let E=he(h),I=h.length*8-c;return I>0?E>>BigInt(I):E},O=e.bits2int_modN||function(h){return i.create(U(h))},M=Ue(c);function x(d){return Re("num < 2^"+c,d,Ct,M),i.toBytes(d)}function g(d,h){return N(d,void 0,"message"),h?N(t(d),void 0,"prehashed message"):d}function K(d,h,E){let{lowS:I,prehash:D,extraEntropy:T}=zn(E,p);d=g(d,D);let L=O(d),R=i.fromBytes(h);if(!i.isValidNot0(R))throw new Error("invalid private key");let k=[x(R),x(L)];if(T!=null&&T!==!1){let F=T===!0?n(_.secretKey):T;k.push(N(F,void 0,"extraEntropy"))}let z=st(...k),H=L;function q(F){let J=U(F);if(!i.isValidNot0(J))return;let gt=i.inv(J),Z=r.BASE.multiply(J).toAffine(),tt=i.create(Z.x);if(tt===Ct)return;let Ze=i.create(gt*i.create(H+tt*R));if(Ze===Ct)return;let eo=(Z.x===tt?0:2)|Number(Z.y&ye),ro=Ze;return I&&S(Ze)&&(ro=i.neg(Ze),eo^=1),new B(tt,ro,v?void 0:eo)}return{seed:z,k2sig:q}}function P(d,h,E={}){let{seed:I,k2sig:D}=K(d,h,E);return Jo(t.outputLen,i.BYTES,o)(I,D).toBytes(E.format)}function C(d,h,E,I={}){let{lowS:D,prehash:T,format:L}=zn(I,p);if(E=N(E,void 0,"publicKey"),h=g(h,T),!Ft(d)){let R=d instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+R)}y(d,L);try{let R=B.fromBytes(d,L),k=r.fromBytes(E);if(D&&R.hasHighS())return!1;let{r:z,s:H}=R,q=O(h),F=i.inv(H),J=i.create(q*F),gt=i.create(z*F),Z=r.BASE.multiplyUnsafe(J).add(k.multiplyUnsafe(gt));return Z.is0()?!1:i.create(Z.x)===z}catch{return!1}}function l(d,h,E={}){let{prehash:I}=zn(E,p);return h=g(h,I),B.fromBytes(d,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:f,getPublicKey:m,getSharedSecret:u,utils:w,lengths:_,Point:r,sign:P,verify:C,recoverPublicKey:l,Signature:B,hash:t})}var Gn={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ia={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Zs=BigInt(2);function La(r){let t=Gn.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,m=f*f*r%t,u=V(m,e,t)*m%t,w=V(u,e,t)*m%t,_=V(w,Zs,t)*f%t,p=V(_,o,t)*_%t,v=V(p,s,t)*p%t,S=V(v,a,t)*v%t,b=V(S,c,t)*S%t,A=V(b,a,t)*v%t,y=V(A,e,t)*m%t,B=V(y,i,t)*p%t,U=V(B,n,t)*f%t,O=V(U,Zs,t);if(!jn.eql(jn.sqr(O),r))throw new Error("Cannot find square root");return O}var jn=de(Gn.p,{sqrt:La}),Da=Hs(Gn,{Fp:jn,endo:Ia}),ge=Fs(Da,Yo);function js(r,t,e,n){let o=ve.digest(e instanceof Uint8Array?e:e.subarray());if(ur(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ge.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Ne(String(s))});try{return n?.signal?.throwIfAborted(),ge.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new Ne(String(s))}}var wr=class{type="secp256k1";raw;_key;constructor(t){this._key=Ys(t),this.raw=Gs(this._key)}toMultihash(){return dt.digest(ae(this))}toCID(){return ot.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,e,n){return js(this._key,e,t,n)}};function Xs(r){return new wr(r)}function Gs(r){return ge.Point.fromBytes(r).toBytes()}function Ys(r){try{return ge.Point.fromBytes(r),r}catch(t){throw new je(String(t))}}function $s(r){let{Type:t,Data:e}=qe.decode(r.digest),n=e??new Uint8Array;switch(t){case ht.Ed25519:return As(n);case ht.secp256k1:return Xs(n);case ht.ECDSA:return To(n);default:throw new xe}}function ae(r){return qe.encode({Type:ht[r.type],Data:r.raw})}var Ws=Symbol.for("nodejs.util.inspect.custom"),Ca=114,He=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()})`}[Lr]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ot.createV1(Ca,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")}[Ws](){return`PeerId(${this.toString()})`}},Er=class extends He{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},_r=class extends He{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Sr=class extends He{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ta=2336,Ar=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=dt.digest(X(this.url))}[Ws](){return`PeerId(${this.url})`}[Lr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ot.createV1(Ta,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=lt(t)),t.toString()===this.toString())}};function Js(r){if(Ua(r))return new Er({multihash:r});if(Ra(r))try{let t=$s(r);if(t.type==="Ed25519")return new _r({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Sr({multihash:r,publicKey:t})}catch{let e=lt(r.digest);return new Ar(new URL(e))}throw new Ge("Supplied PeerID Multihash is invalid")}function Ra(r){return r.code===dt.code}function Ua(r){return r.code===ve.code}function Et(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function vr(r){let t=Se(G.decode(`z${r}`));return Js(t)}var qt=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return Et(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return Et(this.map.values(),t=>t.key)}values(){return Et(this.map.values(),t=>t.value)}get size(){return this.map.size}};function Qs(){return new qt}var Ht=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Et(this.set.entries(),t=>{let e=vr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=vr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Et(this.set.values(),t=>vr(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function ti(){return new Ht}var Vt=class r{list;constructor(t){if(this.list=[],t!=null)for(let e of t)this.list.push(e)}[Symbol.iterator](){return Et(this.list.entries(),t=>t[1])}concat(t){let e=new r(this);for(let n of t)e.push(n);return e}entries(){return Et(this.list.entries(),t=>[t[0],t[1]])}every(t){return this.list.every((e,n)=>t(e,n,this))}filter(t){let e=new r;return this.list.forEach((n,o)=>{t(n,o,this)&&e.push(n)}),e}find(t){let e=this.list.find((n,o)=>t(n,o,this));if(e!=null)return e}findIndex(t){return this.list.findIndex((e,n)=>t(e,n,this))}forEach(t){this.list.forEach((e,n)=>{t(e,n,this)})}includes(t){return this.includes(t)}indexOf(t){return this.list.findIndex(e=>e.equals(t))}pop(){let t=this.list.pop();if(t!=null)return t}push(...t){for(let e of t)this.list.push(e)}shift(){let t=this.list.shift();if(t!=null)return t}unshift(...t){let e=this.list.length;for(let n=t.length-1;n>-1;n--)e=this.list.unshift(t[n]);return e}clear(){this.list=[]}get length(){return this.list.length}};function ei(){return new Vt}var Yn={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},ri={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},ni=new globalThis.TextEncoder;function Ka(r,t){let e=Yn[t],n=ri[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function ka(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Yn[t],o=ri[t],s=r;for(;s.length>0;){let i=ni.encodeInto(s,e);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(e[a]),o=BigInt.asUintN(t,o*n)}return o}function Xn(r,{size:t=32,utf8Buffer:e}={}){if(!Yn[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(e)return ka(r,t,e);r=ni.encode(r)}return Ka(r,t)}var Ve={hash:r=>Number(Xn(r,{size:32})),hashV:(r,t)=>Na(Ve.hash(r,t))};function Na(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),X(t,"base16")}var $n=64,yt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>$n)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=pt(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?ct(this.fp,t.fp):!1}};function Qt(r,t){return Math.floor(Math.random()*(t-r))+r}var te=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof yt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof yt))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof yt))throw new TypeError("Invalid Fingerprint");let e=Qt(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof yt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Oa=500,ze=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??Ve,this.seed=t.seed??Qt(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=X(t));let e=new yt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new te(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new te(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[Qt(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new te(this.bucketSize));for(let a=0;a<Oa;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new te(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=X(t));let e=new yt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=X(t));let e=new yt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Ma={1:.5,2:.84,4:.95,8:.98};function Pa(r=.001){return r>.002?2:r>1e-5?4:8}function oi(r,t=.001){let e=Pa(t),n=Ma[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),$n);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Br=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(t){this.bucketSize=t.bucketSize??4,this.filterSize=t.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=t.fingerprintSize??2,this.scale=t.scale??2,this.hash=t.hash??Ve,this.seed=t.seed??Qt(0,Math.pow(2,10)),this.filterSeries=[new ze({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=X(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new ze({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=X(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=X(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function Wn(r,t=.001,e){return new Br({...oi(r,t),...e??{}})}var Fe=class{filter;constructor(t,e){this.filter=Wn(t,e)}has(t){return this.filter.has(t.toMultihash().bytes)}add(t){this.filter.add(t.toMultihash().bytes)}remove(t){this.filter.remove?.(t.toMultihash().bytes)}};function si(r,t=.001){return new Fe(r,t)}var Jn=class extends qt{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ii(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Jn({name:t,metrics:e}):n=new qt,n}var Qn=class extends Ht{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}add(t){super.add(t),this.updateComponentMetric()}delete(t){super.delete(t),this.updateComponentMetric()}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ci(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Qn({name:t,metrics:e}):n=new Ht,n}var to=class extends Vt{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}pop(){let t=super.pop();return this.updateComponentMetric(),t}push(...t){super.push(...t),this.updateComponentMetric()}shift(){let t=super.shift();return this.updateComponentMetric(),t}unshift(...t){let e=super.unshift(...t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.length)}};function ai(r){let{name:t,metrics:e}=r,n;return e!=null?n=new to({name:t,metrics:e}):n=new Vt,n}return di(qa);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
|
-
@noble/hashes/
|
|
5
|
+
@noble/hashes/utils.js:
|
|
6
6
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
7
7
|
|
|
8
|
-
@noble/curves/
|
|
9
|
-
@noble/curves/
|
|
10
|
-
@noble/curves/
|
|
11
|
-
@noble/curves/
|
|
12
|
-
@noble/curves/
|
|
13
|
-
@noble/curves/
|
|
14
|
-
@noble/curves/
|
|
15
|
-
@noble/curves/esm/secp256k1.js:
|
|
8
|
+
@noble/curves/utils.js:
|
|
9
|
+
@noble/curves/abstract/modular.js:
|
|
10
|
+
@noble/curves/abstract/curve.js:
|
|
11
|
+
@noble/curves/abstract/edwards.js:
|
|
12
|
+
@noble/curves/ed25519.js:
|
|
13
|
+
@noble/curves/abstract/weierstrass.js:
|
|
14
|
+
@noble/curves/secp256k1.js:
|
|
16
15
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
17
16
|
*/
|
|
18
17
|
return Libp2PPeerCollections}));
|