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