@libp2p/peer-collections 7.0.22-f144def15 → 7.0.23

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