@libp2p/peer-store
Version:
Stores information about peers libp2p knows on the network
2 lines • 143 kB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPeerStore = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var Libp2PPeerStore=(()=>{var Wa=Object.create;var Ar=Object.defineProperty;var $a=Object.getOwnPropertyDescriptor;var Za=Object.getOwnPropertyNames;var Ya=Object.getPrototypeOf,ja=Object.prototype.hasOwnProperty;var Xa=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),vt=(r,t)=>{for(var e in t)Ar(r,e,{get:t[e],enumerable:!0})},Ai=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Za(t))!ja.call(r,o)&&o!==e&&Ar(r,o,{get:()=>t[o],enumerable:!(n=$a(t,o))||n.enumerable});return r};var Qa=(r,t,e)=>(e=r!=null?Wa(Ya(r)):{},Ai(t||!r||!r.__esModule?Ar(e,"default",{value:r,enumerable:!0}):e,r)),Ja=r=>Ai(Ar({},"__esModule",{value:!0}),r);var Ia=Xa((Cg,ai)=>{"use strict";var yf=Object.prototype.hasOwnProperty,xt="~";function wr(){}Object.create&&(wr.prototype=Object.create(null),new wr().__proto__||(xt=!1));function gf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Aa(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var i=new gf(e,n||r,o),s=xt?xt+t:t;return r._events[s]?r._events[s].fn?r._events[s]=[r._events[s],i]:r._events[s].push(i):(r._events[s]=i,r._eventsCount++),r}function on(r,t){--r._eventsCount===0?r._events=new wr:delete r._events[t]}function pt(){this._events=new wr,this._eventsCount=0}pt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)yf.call(e,n)&&t.push(xt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};pt.prototype.listeners=function(t){var e=xt?xt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s};pt.prototype.listenerCount=function(t){var e=xt?xt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};pt.prototype.emit=function(t,e,n,o,i,s){var a=xt?xt+t:t;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,u,l;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,o),!0;case 5:return c.fn.call(c.context,e,n,o,i),!0;case 6:return c.fn.call(c.context,e,n,o,i,s),!0}for(l=1,u=new Array(f-1);l<f;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var d=c.length,y;for(l=0;l<d;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),f){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,e);break;case 3:c[l].fn.call(c[l].context,e,n);break;case 4:c[l].fn.call(c[l].context,e,n,o);break;default:if(!u)for(y=1,u=new Array(f-1);y<f;y++)u[y-1]=arguments[y];c[l].fn.apply(c[l].context,u)}}return!0};pt.prototype.on=function(t,e,n){return Aa(this,t,e,n,!1)};pt.prototype.once=function(t,e,n){return Aa(this,t,e,n,!0)};pt.prototype.removeListener=function(t,e,n,o){var i=xt?xt+t:t;if(!this._events[i])return this;if(!e)return on(this,i),this;var s=this._events[i];if(s.fn)s.fn===e&&(!o||s.once)&&(!n||s.context===n)&&on(this,i);else{for(var a=0,c=[],f=s.length;a<f;a++)(s[a].fn!==e||o&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[i]=c.length===1?c[0]:c:on(this,i)}return this};pt.prototype.removeAllListeners=function(t){var e;return t?(e=xt?xt+t:t,this._events[e]&&on(this,e)):(this._events=new wr,this._eventsCount=0),this};pt.prototype.off=pt.prototype.removeListener;pt.prototype.addListener=pt.prototype.on;pt.prefixed=xt;pt.EventEmitter=pt;typeof ai<"u"&&(ai.exports=pt)});var Df={};vt(Df,{persistentPeerStore:()=>kf});var Ir=Symbol.for("@libp2p/peer-id");function Ii(r){return!!r?.[Ir]}var q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Te=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var $e=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Br=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Tr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var de=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var wn={};vt(wn,{base58btc:()=>$,base58flickr:()=>ic});var Nf=new Uint8Array(0);function Bi(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 Ht(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 Ti(r){return new TextEncoder().encode(r)}function Pi(r){return new TextDecoder().decode(r)}function tc(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 i=r.charAt(o),s=i.charCodeAt(0);if(e[s]!==255)throw new TypeError(i+" is ambiguous");e[s]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var g=0,h=0,x=0,A=w.length;x!==A&&w[x]===0;)x++,g++;for(var m=(A-x)*u+1>>>0,I=new Uint8Array(m);x!==A;){for(var k=w[x],C=0,T=m-1;(k!==0||C<h)&&T!==-1;T--,C++)k+=256*I[T]>>>0,I[T]=k%a>>>0,k=k/a>>>0;if(k!==0)throw new Error("Non-zero carry");h=C,x++}for(var P=m-h;P!==m&&I[P]===0;)P++;for(var L=c.repeat(g);P<m;++P)L+=r.charAt(I[P]);return L}function d(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var g=0;if(w[g]!==" "){for(var h=0,x=0;w[g]===c;)h++,g++;for(var A=(w.length-g)*f+1>>>0,m=new Uint8Array(A);w[g];){var I=e[w.charCodeAt(g)];if(I===255)return;for(var k=0,C=A-1;(I!==0||k<x)&&C!==-1;C--,k++)I+=a*m[C]>>>0,m[C]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");x=k,g++}if(w[g]!==" "){for(var T=A-x;T!==A&&m[T]===0;)T++;for(var P=new Uint8Array(h+(A-T)),L=h;T!==A;)P[L++]=m[T++];return P}}}function y(w){var g=d(w);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:y}}var ec=tc,rc=ec,_i=rc;var mn=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")}},yn=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 Ci(this,t)}},gn=class{decoders;constructor(t){this.decoders=t}or(t){return Ci(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 Ci(r,t){return new gn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var bn=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 mn(t,e,n),this.decoder=new yn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Pe({name:r,prefix:t,encode:e,decode:n}){return new bn(r,t,e,n)}function Jt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=_i(e,r);return Pe({prefix:t,name:r,encode:n,decode:i=>Ht(o(i))})}function nc(r,t,e,n){let o={};for(let u=0;u<t.length;++u)o[t[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),a=0,c=0,f=0;for(let u=0;u<i;++u){let l=o[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|l,a+=e,a>=8&&(a-=8,s[f++]=255&c>>a)}if(a>=e||(255&c<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return s}function oc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>e;)s-=e,i+=t[o&a>>s];if(s!==0&&(i+=t[o&a<<e-s]),n)for(;(i.length*e&7)!==0;)i+="=";return i}function tt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Pe({prefix:t,name:r,encode(o){return oc(o,n,e)},decode(o){return nc(o,n,e,r)}})}var $=Jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ic=Jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xn={};vt(xn,{base32:()=>kt,base32hex:()=>uc,base32hexpad:()=>fc,base32hexpadupper:()=>dc,base32hexupper:()=>lc,base32pad:()=>ac,base32padupper:()=>cc,base32upper:()=>sc,base32z:()=>hc});var kt=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),sc=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ac=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),cc=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),uc=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),lc=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),fc=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),dc=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),hc=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var En={};vt(En,{base36:()=>Ze,base36upper:()=>pc});var Ze=Jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),pc=Jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var mc=Ki,ki=128,yc=127,gc=~yc,bc=Math.pow(2,31);function Ki(r,t,e){t=t||[],e=e||0;for(var n=e;r>=bc;)t[e++]=r&255|ki,r/=128;for(;r&gc;)t[e++]=r&255|ki,r>>>=7;return t[e]=r|0,Ki.bytes=e-n+1,t}var wc=vn,xc=128,Di=127;function vn(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw vn.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&Di)<<o:(s&Di)*Math.pow(2,o),o+=7}while(s>=xc);return vn.bytes=i-n,e}var Ec=Math.pow(2,7),vc=Math.pow(2,14),Sc=Math.pow(2,21),Ac=Math.pow(2,28),Ic=Math.pow(2,35),Bc=Math.pow(2,42),Tc=Math.pow(2,49),Pc=Math.pow(2,56),Lc=Math.pow(2,63),_c=function(r){return r<Ec?1:r<vc?2:r<Sc?3:r<Ac?4:r<Ic?5:r<Bc?6:r<Tc?7:r<Pc?8:r<Lc?9:10},Cc={encode:mc,decode:wc,encodingLength:_c},kc=Cc,Ye=kc;function je(r,t=0){return[Ye.decode(r,t),Ye.decode.bytes]}function Le(r,t,e=0){return Ye.encode(r,t,e),t}function _e(r){return Ye.encodingLength(r)}function Dt(r,t){let e=t.byteLength,n=_e(r),o=n+_e(e),i=new Uint8Array(o+e);return Le(r,i,0),Le(e,i,n),i.set(t,o),new Ce(r,e,t,i)}function Ft(r){let t=Ht(r),[e,n]=je(t),[o,i]=je(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ce(e,o,s,t)}function Ri(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Bi(r.bytes,e.bytes)}}var Ce=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Ui(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Kc(e,Sn(r),t??$.encoder);default:return Rc(e,Sn(r),t??kt.encoder)}}var Ni=new WeakMap;function Sn(r){let t=Ni.get(r);if(t==null){let e=new Map;return Ni.set(r,e),e}return t}var et=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!==Xe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Uc)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=Dt(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&&Ri(t.multihash,n.multihash)}toString(t){return Ui(this,t)}toJSON(){return{"/":Ui(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:i,bytes:s}=e;return new r(n,o,i,s??Oi(n,o,i.bytes))}else if(e[Nc]===!0){let{version:n,multihash:o,code:i}=e,s=Ft(o);return r.create(n,i,s)}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!==Xe)throw new Error(`Version 0 CID must use dag-pb (code: ${Xe}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Oi(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Xe,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=Ht(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),s=new Ce(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,d]=je(t.subarray(e));return e+=d,l},o=n(),i=Xe;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,a=n(),c=n(),f=e+c,u=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,e){let[n,o]=Dc(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Sn(i).set(n,t),i}};function Dc(r,t){switch(r[0]){case"Q":{let e=t??$;return[$.prefix,e.decode(`${$.prefix}${r}`)]}case $.prefix:{let e=t??$;return[$.prefix,e.decode(r)]}case kt.prefix:{let e=t??kt;return[kt.prefix,e.decode(r)]}case Ze.prefix:{let e=t??Ze;return[Ze.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 Kc(r,t,e){let{prefix:n}=e;if(n!==$.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o}function Rc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o}var Xe=112,Uc=18;function Oi(r,t,e){let n=_e(r),o=n+_e(t),i=new Uint8Array(o+e.byteLength);return Le(r,i,0),Le(t,i,n),i.set(e,o),i}var Nc=Symbol.for("@ipld/js-cid/CID");var An={};vt(An,{identity:()=>Kt});var Mi=0,Oc="identity",qi=Ht;function Mc(r){return Dt(Mi,qi(r))}var Kt={code:Mi,name:Oc,encode:qi,digest:Mc};function j(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 it(r=0){return new Uint8Array(r)}function St(r=0){return new Uint8Array(r)}function Tt(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=St(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Fi=Symbol.for("@achingbrain/uint8arraylist");function Hi(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 Lr(r){return!!r?.[Fi]}var mt=class r{bufs;length;[Fi]=!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(Lr(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(Lr(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=Hi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Hi(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(Lr(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 Tt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Tt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),i=new r;return i.length=o,i.bufs=[...n],i}_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 i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=e>a&&e<=c;if(f&&u){if(t===a&&e===c){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(e-t)));break}if(f){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(u){if(e===c){n.push(s);break}n.push(s.subarray(0,e-a));break}n.push(s)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Lr(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 i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=e;l<=c;l+=u){u=0;for(let d=f;d>=0;d--){let y=this.get(l+d);if(n[d]!==y){u=Math.max(1,d-a[y]);break}}if(u===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=St(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=it(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=it(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=it(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=St(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=it(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=it(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=it(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=it(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=it(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(!j(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,i)=>o+i.byteLength,0)),n.length=e,n}};var In={};vt(In,{base10:()=>qc});var qc=Jt({prefix:"9",name:"base10",alphabet:"0123456789"});var Bn={};vt(Bn,{base16:()=>Hc,base16upper:()=>Fc});var Hc=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Fc=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Tn={};vt(Tn,{base2:()=>Vc});var Vc=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Pn={};vt(Pn,{base256emoji:()=>Zc});var Vi=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}"),zc=Vi.reduce((r,t,e)=>(r[e]=t,r),[]),Gc=Vi.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Wc(r){return r.reduce((t,e)=>(t+=zc[e],t),"")}function $c(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Gc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Zc=Pe({prefix:"\u{1F680}",name:"base256emoji",encode:Wc,decode:$c});var Ln={};vt(Ln,{base64:()=>Yc,base64pad:()=>jc,base64url:()=>Xc,base64urlpad:()=>Qc});var Yc=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jc=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Xc=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Qc=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var _n={};vt(_n,{base8:()=>Jc});var Jc=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Cn={};vt(Cn,{identity:()=>tu});var tu=Pe({prefix:"\0",name:"identity",encode:r=>Pi(r),decode:r=>Ti(r)});var xd=new TextEncoder,Ed=new TextDecoder;var Kn={};vt(Kn,{sha256:()=>Qe,sha512:()=>nu});function Dn({name:r,code:t,encode:e}){return new kn(r,t,e)}var kn=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?Dt(this.code,e):e.then(n=>Dt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Gi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Qe=Dn({name:"sha2-256",code:18,encode:Gi("SHA-256")}),nu=Dn({name:"sha2-512",code:19,encode:Gi("SHA-512")});var Je={...Cn,...Tn,..._n,...In,...Bn,...xn,...En,...wn,...Ln,...Pn},Dd={...Kn,...An};function $i(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Wi=$i("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Rn=$i("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=St(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ou={utf8:Wi,"utf-8":Wi,hex:Je.base16,latin1:Rn,ascii:Rn,binary:Rn,...Je},_r=ou;function G(r,t="utf8"){let e=_r[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function U(r,t="utf8"){let e=_r[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var iu=parseInt("11111",2),Un=parseInt("10000000",2),su=parseInt("01111111",2),Zi={0:tr,1:tr,2:au,3:lu,4:fu,5:uu,6:cu,16:tr,22:tr,48:tr};function zt(r,t={offset:0}){let e=r[t.offset]&iu;if(t.offset++,Zi[e]!=null)return Zi[e](r,t);throw new Error("No decoder for tag "+e)}function er(r,t){let e=0;if((r[t.offset]&Un)===Un){let n=r[t.offset]&su,o="0x";t.offset++;for(let i=0;i<n;i++,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 tr(r,t){er(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=zt(r,t);if(n===null)break;e.push(n)}return e}function au(r,t){let e=er(r,t),n=t.offset,o=t.offset+e,i=[];for(let s=n;s<o;s++)s===n&&r[s]===0||i.push(r[s]);return t.offset+=e,Uint8Array.from(i)}function cu(r,t){let e=er(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function uu(r,t){return t.offset++,null}function lu(r,t){let e=er(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 fu(r,t){let e=er(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function du(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new mt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Nn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=du(r.byteLength);return new mt(Uint8Array.from([t.byteLength|Un]),t)}function At(r){let t=new mt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new mt(Uint8Array.from([2]),Nn(t),t)}function Cr(r){let t=Uint8Array.from([0]),e=new mt(t,r);return new mt(Uint8Array.from([3]),Nn(e),e)}function te(r,t=48){let e=new mt;for(let n of r)e.append(n);return new mt(Uint8Array.from([t]),Nn(e),e)}async function Yi(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var hu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),pu=Uint8Array.from([6,5,43,129,4,0,34]),mu=Uint8Array.from([6,5,43,129,4,0,35]),yu={ext:!0,kty:"EC",crv:"P-256"},gu={ext:!0,kty:"EC",crv:"P-384"},bu={ext:!0,kty:"EC",crv:"P-521"},On=32,Mn=48,qn=66;function Hn(r){let t=zt(r);return ji(t)}function ji(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===On*2+1)return n=U(t.subarray(e,e+On),"base64url"),o=U(t.subarray(e+On),"base64url"),new ke({...yu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Mn*2+1)return n=U(t.subarray(e,e+Mn),"base64url"),o=U(t.subarray(e+Mn),"base64url"),new ke({...gu,key_ops:["verify"],x:n,y:o});if(t.byteLength===qn*2+1)return n=U(t.subarray(e,e+qn),"base64url"),o=U(t.subarray(e+qn),"base64url"),new ke({...bu,key_ops:["verify"],x:n,y:o});throw new q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Xi(r){return te([At(Uint8Array.from([1])),te([wu(r.crv)],160),te([Cr(new mt(Uint8Array.from([4]),G(r.x??"","base64url"),G(r.y??"","base64url")))],161)]).subarray()}function wu(r){if(r==="P-256")return hu;if(r==="P-384")return pu;if(r==="P-521")return mu;throw new q(`Invalid curve ${r}`)}var ke=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Xi(this.jwk)),this._raw}toMultihash(){return Kt.digest(_t(this))}toCID(){return et.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:j(this.raw,t.raw)}async verify(t,e){return Yi(this.jwk,e,t)}};function Qi(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function xu(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function De(r,...t){if(!xu(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 Ji(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Qi(r.outputLen),Qi(r.blockLen)}function Ke(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 ts(r,t){De(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function kr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Rt(r,t){return r<<32-t|r>>>t}var ph=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function";function es(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function rr(r){return typeof r=="string"&&(r=es(r)),De(r),r}function Fn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];De(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let i=r[n];e.set(i,o),o+=i.length}return e}var Re=class{clone(){return this._cloneInto()}};function Dr(r){let t=n=>r().update(rr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Kr(r=32){if(he&&typeof he.getRandomValues=="function")return he.getRandomValues(new Uint8Array(r));if(he&&typeof he.randomBytes=="function")return Uint8Array.from(he.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Eu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(e>>o&i),a=Number(e&i),c=n?4:0,f=n?0:4;r.setUint32(t+c,s,n),r.setUint32(t+f,a,n)}function rs(r,t,e){return r&t^~r&e}function ns(r,t,e){return r&t^r&e^t&e}var Ue=class extends Re{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=kr(this.buffer)}update(t){Ke(this);let{view:e,buffer:n,blockLen:o}=this;t=rr(t);let i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=kr(t);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ke(this),ts(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;e[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)e[l]=0;Eu(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=kr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],i)}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:i,destroyed:s,pos:a}=this;return t.length=o,t.pos=a,t.finished=i,t.destroyed=s,o%e&&t.buffer.set(n),t}};var vu=new Uint32Array([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]),ee=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),re=new Uint32Array(64),Vn=class extends Ue{constructor(t=32){super(64,t,8,!1),this.A=ee[0]|0,this.B=ee[1]|0,this.C=ee[2]|0,this.D=ee[3]|0,this.E=ee[4]|0,this.F=ee[5]|0,this.G=ee[6]|0,this.H=ee[7]|0}get(){let{A:t,B:e,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[t,e,n,o,i,s,a,c]}set(t,e,n,o,i,s,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,e){for(let l=0;l<16;l++,e+=4)re[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let d=re[l-15],y=re[l-2],w=Rt(d,7)^Rt(d,18)^d>>>3,g=Rt(y,17)^Rt(y,19)^y>>>10;re[l]=g+re[l-7]+w+re[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let d=Rt(a,6)^Rt(a,11)^Rt(a,25),y=u+d+rs(a,c,f)+vu[l]+re[l]|0,g=(Rt(n,2)^Rt(n,13)^Rt(n,22))+ns(n,o,i)|0;u=f,f=c,c=a,a=s+y|0,s=i,i=o,o=n,n=y+g|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,f,u)}roundClean(){re.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var pe=Dr(()=>new Vn);var Rr=BigInt(4294967295),zn=BigInt(32);function os(r,t=!1){return t?{h:Number(r&Rr),l:Number(r>>zn&Rr)}:{h:Number(r>>zn&Rr)|0,l:Number(r&Rr)|0}}function Su(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:i,l:s}=os(r[o],t);[e[o],n[o]]=[i,s]}return[e,n]}var Au=(r,t)=>BigInt(r>>>0)<<zn|BigInt(t>>>0),Iu=(r,t,e)=>r>>>e,Bu=(r,t,e)=>r<<32-e|t>>>e,Tu=(r,t,e)=>r>>>e|t<<32-e,Pu=(r,t,e)=>r<<32-e|t>>>e,Lu=(r,t,e)=>r<<64-e|t>>>e-32,_u=(r,t,e)=>r>>>e-32|t<<64-e,Cu=(r,t)=>t,ku=(r,t)=>r,Du=(r,t,e)=>r<<e|t>>>32-e,Ku=(r,t,e)=>t<<e|r>>>32-e,Ru=(r,t,e)=>t<<e-32|r>>>64-e,Uu=(r,t,e)=>r<<e-32|t>>>64-e;function Nu(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ou=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Mu=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,qu=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Hu=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Fu=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Vu=(r,t,e,n,o,i)=>t+e+n+o+i+(r/2**32|0)|0;var zu={fromBig:os,split:Su,toBig:Au,shrSH:Iu,shrSL:Bu,rotrSH:Tu,rotrSL:Pu,rotrBH:Lu,rotrBL:_u,rotr32H:Cu,rotr32L:ku,rotlSH:Du,rotlSL:Ku,rotlBH:Ru,rotlBL:Uu,add:Nu,add3L:Ou,add3H:Mu,add4L:qu,add4H:Hu,add5H:Vu,add5L:Fu},K=zu;var[Gu,Wu]=K.split(["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))),ne=new Uint32Array(80),oe=new Uint32Array(80),Gn=class extends Ue{constructor(t=64){super(128,t,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:d,Gh:y,Gl:w,Hh:g,Hl:h}=this;return[t,e,n,o,i,s,a,c,f,u,l,d,y,w,g,h]}set(t,e,n,o,i,s,a,c,f,u,l,d,y,w,g,h){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=d|0,this.Gh=y|0,this.Gl=w|0,this.Hh=g|0,this.Hl=h|0}process(t,e){for(let m=0;m<16;m++,e+=4)ne[m]=t.getUint32(e),oe[m]=t.getUint32(e+=4);for(let m=16;m<80;m++){let I=ne[m-15]|0,k=oe[m-15]|0,C=K.rotrSH(I,k,1)^K.rotrSH(I,k,8)^K.shrSH(I,k,7),T=K.rotrSL(I,k,1)^K.rotrSL(I,k,8)^K.shrSL(I,k,7),P=ne[m-2]|0,L=oe[m-2]|0,Y=K.rotrSH(P,L,19)^K.rotrBH(P,L,61)^K.shrSH(P,L,6),F=K.rotrSL(P,L,19)^K.rotrBL(P,L,61)^K.shrSL(P,L,6),N=K.add4L(T,F,oe[m-7],oe[m-16]),st=K.add4H(N,C,Y,ne[m-7],ne[m-16]);ne[m]=st|0,oe[m]=N|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:d,Fh:y,Fl:w,Gh:g,Gl:h,Hh:x,Hl:A}=this;for(let m=0;m<80;m++){let I=K.rotrSH(l,d,14)^K.rotrSH(l,d,18)^K.rotrBH(l,d,41),k=K.rotrSL(l,d,14)^K.rotrSL(l,d,18)^K.rotrBL(l,d,41),C=l&y^~l&g,T=d&w^~d&h,P=K.add5L(A,k,T,Wu[m],oe[m]),L=K.add5H(P,x,I,C,Gu[m],ne[m]),Y=P|0,F=K.rotrSH(n,o,28)^K.rotrBH(n,o,34)^K.rotrBH(n,o,39),N=K.rotrSL(n,o,28)^K.rotrBL(n,o,34)^K.rotrBL(n,o,39),st=n&i^n&a^i&a,v=o&s^o&c^s&c;x=g|0,A=h|0,g=y|0,h=w|0,y=l|0,w=d|0,{h:l,l:d}=K.add(f|0,u|0,L|0,Y|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let B=K.add3L(Y,N,v);n=K.add3H(B,L,F,st),o=B|0}({h:n,l:o}=K.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=K.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=K.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=K.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:d}=K.add(this.Eh|0,this.El|0,l|0,d|0),{h:y,l:w}=K.add(this.Fh|0,this.Fl|0,y|0,w|0),{h:g,l:h}=K.add(this.Gh|0,this.Gl|0,g|0,h|0),{h:x,l:A}=K.add(this.Hh|0,this.Hl|0,x|0,A|0),this.set(n,o,i,s,a,c,f,u,l,d,y,w,g,h,x,A)}roundClean(){ne.fill(0),oe.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Wn=Dr(()=>new Gn);var jn=BigInt(0),Yn=BigInt(1);function me(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Xn(r){if(!me(r))throw new Error("Uint8Array expected")}function Nt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function nr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function as(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?jn:BigInt("0x"+r)}var cs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",$u=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ie(r){if(Xn(r),cs)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=$u[r[e]];return t}var Gt={_0:48,_9:57,A:65,F:70,a:97,f:102};function is(r){if(r>=Gt._0&&r<=Gt._9)return r-Gt._0;if(r>=Gt.A&&r<=Gt.F)return r-(Gt.A-10);if(r>=Gt.a&&r<=Gt.f)return r-(Gt.a-10)}function or(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(cs)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,i=0;o<e;o++,i+=2){let s=is(r.charCodeAt(i)),a=is(r.charCodeAt(i+1));if(s===void 0||a===void 0){let c=r[i]+r[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function Wt(r){return as(ie(r))}function ye(r){return Xn(r),as(ie(Uint8Array.from(r).reverse()))}function ge(r,t){return or(r.toString(16).padStart(t*2,"0"))}function Ne(r,t){return ge(r,t).reverse()}function J(r,t,e){let n;if(typeof t=="string")try{n=or(t)}catch(i){throw new Error(r+" must be hex string or Uint8Array, cause: "+i)}else if(me(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 se(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Xn(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let i=r[n];e.set(i,o),o+=i.length}return e}var $n=r=>typeof r=="bigint"&&jn<=r;function Ur(r,t,e){return $n(r)&&$n(t)&&$n(e)&&t<=r&&r<e}function Pt(r,t,e,n){if(!Ur(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function us(r){let t;for(t=0;r>jn;r>>=Yn,t+=1);return t}var be=r=>(Yn<<BigInt(r))-Yn,Zn=r=>new Uint8Array(r),ss=r=>Uint8Array.from(r);function ls(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=Zn(r),o=Zn(r),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...l)=>e(o,n,...l),c=(l=Zn(0))=>{o=a(ss([0]),l),n=a(),l.length!==0&&(o=a(ss([1]),l),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,d=[];for(;l<t;){n=a();let y=n.slice();d.push(y),l+=n.length}return se(...d)};return(l,d)=>{s(),c(l);let y;for(;!(y=d(f()));)c();return s(),y}}var Zu={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||me(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function $t(r,t,e={}){let n=(o,i,s)=>{let a=Zu[i];if(typeof a!="function")throw new Error("invalid validator function");let c=r[o];if(!(s&&c===void 0)&&!a(c,r))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+c)};for(let[o,i]of Object.entries(t))n(o,i,!1);for(let[o,i]of Object.entries(e))n(o,i,!0);return r}function Oe(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let i=r(e,...n);return t.set(e,i),i}}var at=BigInt(0),X=BigInt(1),we=BigInt(2),Yu=BigInt(3),Qn=BigInt(4),fs=BigInt(5),ds=BigInt(8),ju=BigInt(9),Xu=BigInt(16);function W(r,t){let e=r%t;return e>=at?e:t+e}function Qu(r,t,e){if(t<at)throw new Error("invalid exponent, negatives unsupported");if(e<=at)throw new Error("invalid modulus");if(e===X)return at;let n=X;for(;t>at;)t&X&&(n=n*r%e),r=r*r%e,t>>=X;return n}function Q(r,t,e){let n=r;for(;t-- >at;)n*=n,n%=e;return n}function Nr(r,t){if(r===at)throw new Error("invert: expected non-zero number");if(t<=at)throw new Error("invert: expected positive modulus, got "+t);let e=W(r,t),n=t,o=at,i=X,s=X,a=at;for(;e!==at;){let f=n/e,u=n%e,l=o-s*f,d=i-a*f;n=e,e=u,o=s,i=a,s=l,a=d}if(n!==X)throw new Error("invert: does not exist");return W(o,t)}function Ju(r){let t=(r-X)/we,e,n,o;for(e=r-X,n=0;e%we===at;e/=we,n++);for(o=we;o<r&&Qu(o,t,r)!==r-X;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let s=(r+X)/Qn;return function(c,f){let u=c.pow(f,s);if(!c.eql(c.sqr(u),f))throw new Error("Cannot find square root");return u}}let i=(e+X)/we;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,u=a.pow(a.mul(a.ONE,o),e),l=a.pow(c,i),d=a.pow(c,e);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let y=1;for(let g=a.sqr(d);y<f&&!a.eql(g,a.ONE);y++)g=a.sqr(g);let w=a.pow(u,X<<BigInt(f-y-1));u=a.sqr(w),l=a.mul(l,w),d=a.mul(d,u),f=y}return l}}function tl(r){if(r%Qn===Yu){let t=(r+X)/Qn;return function(n,o){let i=n.pow(o,t);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(r%ds===fs){let t=(r-fs)/ds;return function(n,o){let i=n.mul(o,we),s=n.pow(i,t),a=n.mul(o,s),c=n.mul(n.mul(a,we),s),f=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return r%Xu,Ju(r)}var hs=(r,t)=>(W(r,t)&X)===X,el=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Jn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=el.reduce((n,o)=>(n[o]="function",n),t);return $t(r,e)}function rl(r,t,e){if(e<at)throw new Error("invalid exponent, negatives unsupported");if(e===at)return r.ONE;if(e===X)return t;let n=r.ONE,o=t;for(;e>at;)e&X&&(n=r.mul(n,o)),o=r.sqr(o),e>>=X;return n}function nl(r,t){let e=new Array(t.length),n=t.reduce((i,s,a)=>r.is0(s)?i:(e[a]=i,r.mul(i,s)),r.ONE),o=r.inv(n);return t.reduceRight((i,s,a)=>r.is0(s)?i:(e[a]=r.mul(i,e[a]),r.mul(i,s)),o),e}function to(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function ae(r,t,e=!1,n={}){if(r<=at)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:i}=to(r,t);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,a=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:i,MASK:be(o),ZERO:at,ONE:X,create:c=>W(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return at<=c&&c<r},is0:c=>c===at,isOdd:c=>(c&X)===X,neg:c=>W(-c,r),eql:(c,f)=>c===f,sqr:c=>W(c*c,r),add:(c,f)=>W(c+f,r),sub:(c,f)=>W(c-f,r),mul:(c,f)=>W(c*f,r),pow:(c,f)=>rl(a,c,f),div:(c,f)=>W(c*Nr(f,r),r),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Nr(c,r),sqrt:n.sqrt||(c=>(s||(s=tl(r)),s(a,c))),invertBatch:c=>nl(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>e?Ne(c,i):ge(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return e?ye(c):Wt(c)}});return Object.freeze(a)}function ps(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=