libp2p
Version:
JavaScript implementation of libp2p, a modular peer to peer network stack
2 lines • 299 kB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2P = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var Libp2P=(()=>{var Np=Object.create;var Po=Object.defineProperty;var Mp=Object.getOwnPropertyDescriptor;var Bp=Object.getOwnPropertyNames;var Fp=Object.getPrototypeOf,Up=Object.prototype.hasOwnProperty;var aa=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Me=(r,e)=>{for(var t in e)Po(r,t,{get:e[t],enumerable:!0})},Nu=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Bp(e))!Up.call(r,o)&&o!==t&&Po(r,o,{get:()=>e[o],enumerable:!(n=Mp(e,o))||n.enumerable});return r};var ca=(r,e,t)=>(t=r!=null?Np(Fp(r)):{},Nu(e||!r||!r.__esModule?Po(t,"default",{value:r,enumerable:!0}):t,r)),Kp=r=>Nu(Po({},"__esModule",{value:!0}),r);var ch=aa(io=>{(function(){var r,e,t,n,o,s,i,a;a=function(c){var l,f,u,d;return l=(c&255<<24)>>>24,f=(c&255<<16)>>>16,u=(c&65280)>>>8,d=c&255,[l,f,u,d].join(".")},i=function(c){var l,f,u,d,h,p;for(l=[],u=d=0;d<=3&&c.length!==0;u=++d){if(u>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}p=e(c),h=p[0],f=p[1],c=c.substring(f),l.push(h)}if(c.length!==0)throw new Error("Invalid IP");switch(l.length){case 1:if(l[0]>4294967295)throw new Error("Invalid IP");return l[0]>>>0;case 2:if(l[0]>255||l[1]>16777215)throw new Error("Invalid IP");return(l[0]<<24|l[1])>>>0;case 3:if(l[0]>255||l[1]>255||l[2]>65535)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2])>>>0;case 4:if(l[0]>255||l[1]>255||l[2]>255||l[3]>255)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2]<<8|l[3])>>>0;default:throw new Error("Invalid IP")}},t=function(c){return c.charCodeAt(0)},n=t("0"),s=t("a"),o=t("A"),e=function(c){var l,f,u,d,h;for(d=0,l=10,f="9",u=0,c.length>1&&c[u]==="0"&&(c[u+1]==="x"||c[u+1]==="X"?(u+=2,l=16):"0"<=c[u+1]&&c[u+1]<="9"&&(u++,l=8,f="7")),h=u;u<c.length;){if("0"<=c[u]&&c[u]<=f)d=d*l+(t(c[u])-n)>>>0;else if(l===16)if("a"<=c[u]&&c[u]<="f")d=d*l+(10+t(c[u])-s)>>>0;else if("A"<=c[u]&&c[u]<="F")d=d*l+(10+t(c[u])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");u++}if(u===h)throw new Error("empty octet");return[d,u]},r=(function(){function c(l,f){var u,d,h,p;if(typeof l!="string")throw new Error("Missing `net' parameter");if(f||(p=l.split("/",2),l=p[0],f=p[1]),f||(f=32),typeof f=="string"&&f.indexOf(".")>-1){try{this.maskLong=i(f)}catch(E){throw u=E,new Error("Invalid mask: "+f)}for(d=h=32;h>=0;d=--h)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;break}}else if(f||f===0)this.bitmask=parseInt(f,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(l)&this.maskLong)>>>0}catch(E){throw u=E,new Error("Invalid net address: "+l)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+f);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(l){return typeof l=="string"&&(l.indexOf("/")>0||l.split(".").length!==4)&&(l=new c(l)),l instanceof c?this.contains(l.base)&&this.contains(l.broadcast||l.last):(i(l)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(l){return l==null&&(l=1),new c(a(this.netLong+this.size*l),this.mask)},c.prototype.forEach=function(l){var f,u,d;for(d=i(this.first),u=i(this.last),f=0;d<=u;)l(a(d),d,f),f++,d++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c})(),io.ip2long=i,io.long2ip=a,io.Netmask=r}).call(io)});var yp=aa((BT,uu)=>{"use strict";var Lb=Object.prototype.hasOwnProperty,Ne="~";function So(){}Object.create&&(So.prototype=Object.create(null),new So().__proto__||(Ne=!1));function Pb(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function gp(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new Pb(t,n||r,o),i=Ne?Ne+e:e;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function Vi(r,e){--r._eventsCount===0?r._events=new So:delete r._events[e]}function Te(){this._events=new So,this._eventsCount=0}Te.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Lb.call(t,n)&&e.push(Ne?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};Te.prototype.listeners=function(e){var t=Ne?Ne+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};Te.prototype.listenerCount=function(e){var t=Ne?Ne+e:e,n=this._events[t];return n?n.fn?1:n.length:0};Te.prototype.emit=function(e,t,n,o,s,i){var a=Ne?Ne+e:e;if(!this._events[a])return!1;var c=this._events[a],l=arguments.length,f,u;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,o),!0;case 5:return c.fn.call(c.context,t,n,o,s),!0;case 6:return c.fn.call(c.context,t,n,o,s,i),!0}for(u=1,f=new Array(l-1);u<l;u++)f[u-1]=arguments[u];c.fn.apply(c.context,f)}else{var d=c.length,h;for(u=0;u<d;u++)switch(c[u].once&&this.removeListener(e,c[u].fn,void 0,!0),l){case 1:c[u].fn.call(c[u].context);break;case 2:c[u].fn.call(c[u].context,t);break;case 3:c[u].fn.call(c[u].context,t,n);break;case 4:c[u].fn.call(c[u].context,t,n,o);break;default:if(!f)for(h=1,f=new Array(l-1);h<l;h++)f[h-1]=arguments[h];c[u].fn.apply(c[u].context,f)}}return!0};Te.prototype.on=function(e,t,n){return gp(this,e,t,n,!1)};Te.prototype.once=function(e,t,n){return gp(this,e,t,n,!0)};Te.prototype.removeListener=function(e,t,n,o){var s=Ne?Ne+e:e;if(!this._events[s])return this;if(!t)return Vi(this,s),this;var i=this._events[s];if(i.fn)i.fn===t&&(!o||i.once)&&(!n||i.context===n)&&Vi(this,s);else{for(var a=0,c=[],l=i.length;a<l;a++)(i[a].fn!==t||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:Vi(this,s)}return this};Te.prototype.removeAllListeners=function(e){var t;return e?(t=Ne?Ne+e:e,this._events[t]&&Vi(this,t)):(this._events=new So,this._eventsCount=0),this};Te.prototype.off=Te.prototype.removeListener;Te.prototype.addListener=Te.prototype.on;Te.prefixed=Ne;Te.EventEmitter=Te;typeof uu<"u"&&(uu.exports=Te)});var Ep=aa((i4,xp)=>{xp.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function o(s,i){t[s]=i,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(s){return t[s]!==void 0||n[s]!==void 0},remove:function(s){t[s]!==void 0&&(t[s]=void 0),n[s]!==void 0&&(n[s]=void 0)},get:function(s){var i=t[s];if(i!==void 0)return i;if((i=n[s])!==void 0)return o(s,i),i},set:function(s,i){t[s]!==void 0?t[s]=i:o(s,i)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var tw={};Me(tw,{createLibp2p:()=>Qb,dnsaddrResolver:()=>Ar,isLibp2p:()=>ew});var Mu=Symbol.for("@libp2p/connection");var la=Symbol.for("@libp2p/content-routing");var Ge=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var C=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},_r=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}},yn=class extends Error{static name="InvalidPrivateKeyError";constructor(e="Invalid private key"){super(e),this.name="InvalidPrivateKeyError"}};var zt=class extends Error{static name="ConnectionClosedError";constructor(e="The connection is closed"){super(e),this.name="ConnectionClosedError"}};var Ht=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}},Ir=class extends Error{static name="InvalidPeerIdError";constructor(e="Invalid PeerID"){super(e),this.name="InvalidPeerIdError"}},Ct=class extends Error{static name="InvalidMultiaddrError";constructor(e="Invalid multiaddr"){super(e),this.name="InvalidMultiaddrError"}},Do=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Ro=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}},ko=class extends Error{static name="UnsupportedProtocolError";constructor(e="Unsupported protocol error"){super(e),this.name="UnsupportedProtocolError"}},Oo=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var No=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},ut=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var Cr=class extends Error{static name="DialError";constructor(e="Dial error"){super(e),this.name="DialError"}};var bn=class extends Error{static name="LimitedConnectionError";constructor(e="Limited connection"){super(e),this.name="LimitedConnectionError"}},Mo=class extends Error{static name="TooManyInboundProtocolStreamsError";constructor(e="Too many inbound protocol streams"){super(e),this.name="TooManyInboundProtocolStreamsError"}},Bo=class extends Error{static name="TooManyOutboundProtocolStreamsError";constructor(e="Too many outbound protocol streams"){super(e),this.name="TooManyOutboundProtocolStreamsError"}},Tt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Fo=class extends Event{error;local;constructor(e,t,n){super("close",n),this.error=t,this.local=e}};var ua=Symbol.for("@libp2p/peer-discovery");var Uo=Symbol.for("@libp2p/peer-id");function Lt(r){return!!r?.[Uo]}var fa=Symbol.for("@libp2p/peer-routing");var da="keep-alive";function Ko(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function Bu(...r){let e=[];for(let t of r)Ko(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function Fu(...r){let e=[];for(let t of r)Ko(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var dw=Symbol.for("@libp2p/transport");var wn;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(wn||(wn={}));var Le=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var xn=Symbol.for("@libp2p/service-capabilities"),ha=Symbol.for("@libp2p/service-dependencies");var ba={};Me(ba,{base58btc:()=>J,base58flickr:()=>Gp});var Kw=new Uint8Array(0);function Uu(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function ft(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 Ku(r){return new TextEncoder().encode(r)}function qu(r){return new TextDecoder().decode(r)}function qp(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function u(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var E=0,m=0,g=0,A=p.length;g!==A&&p[g]===0;)g++,E++;for(var x=(A-g)*f+1>>>0,I=new Uint8Array(x);g!==A;){for(var O=p[g],$=0,q=x-1;(O!==0||$<m)&&q!==-1;q--,$++)O+=256*I[q]>>>0,I[q]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");m=$,g++}for(var S=x-m;S!==x&&I[S]===0;)S++;for(var v=c.repeat(E);S<x;++S)v+=r.charAt(I[S]);return v}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var E=0;if(p[E]!==" "){for(var m=0,g=0;p[E]===c;)m++,E++;for(var A=(p.length-E)*l+1>>>0,x=new Uint8Array(A);p[E];){var I=t[p.charCodeAt(E)];if(I===255)return;for(var O=0,$=A-1;(I!==0||O<g)&&$!==-1;$--,O++)I+=a*x[$]>>>0,x[$]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");g=O,E++}if(p[E]!==" "){for(var q=A-g;q!==A&&x[q]===0;)q++;for(var S=new Uint8Array(m+(A-q)),v=m;q!==A;)S[v++]=x[q++];return S}}}function h(p){var E=d(p);if(E)return E;throw new Error(`Non-${e} character`)}return{encode:u,decodeUnsafe:d,decode:h}}var $p=qp,Vp=$p,Vu=Vp;var pa=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},ma=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return zu(this,e)}},ga=class{decoders;constructor(e){this.decoders=e}or(e){return zu(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function zu(r,e){return new ga({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var ya=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new pa(e,t,n),this.decoder=new ma(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Tr({name:r,prefix:e,encode:t,decode:n}){return new ya(r,e,t,n)}function Pt({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Vu(t,r);return Tr({prefix:e,name:r,encode:n,decode:s=>ft(o(s))})}function zp(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let f=e[r[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|f,i+=t,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Hp(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function Wp(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function ae({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Wp(n);return Tr({prefix:e,name:r,encode(s){return Hp(s,n,t)},decode(s){return zp(s,o,t,r)}})}var J=Pt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Gp=Pt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var wa={};Me(wa,{base32:()=>ze,base32hex:()=>jp,base32hexpad:()=>Jp,base32hexpadupper:()=>em,base32hexupper:()=>Qp,base32pad:()=>Xp,base32padupper:()=>Zp,base32upper:()=>Yp,base32z:()=>tm});var ze=ae({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Yp=ae({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xp=ae({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Zp=ae({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),jp=ae({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qp=ae({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Jp=ae({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),em=ae({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),tm=ae({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xa={};Me(xa,{base36:()=>En,base36upper:()=>rm});var En=Pt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),rm=Pt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var nm=Gu,Hu=128,om=127,sm=~om,im=Math.pow(2,31);function Gu(r,e,t){e=e||[],t=t||0;for(var n=t;r>=im;)e[t++]=r&255|Hu,r/=128;for(;r&sm;)e[t++]=r&255|Hu,r>>>=7;return e[t]=r|0,Gu.bytes=t-n+1,e}var am=Ea,cm=128,Wu=127;function Ea(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Ea.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Wu)<<o:(i&Wu)*Math.pow(2,o),o+=7}while(i>=cm);return Ea.bytes=s-n,t}var lm=Math.pow(2,7),um=Math.pow(2,14),fm=Math.pow(2,21),dm=Math.pow(2,28),hm=Math.pow(2,35),pm=Math.pow(2,42),mm=Math.pow(2,49),gm=Math.pow(2,56),ym=Math.pow(2,63),bm=function(r){return r<lm?1:r<um?2:r<fm?3:r<dm?4:r<hm?5:r<pm?6:r<mm?7:r<gm?8:r<ym?9:10},wm={encode:nm,decode:am,encodingLength:bm},xm=wm,vn=xm;function Sn(r,e=0){return[vn.decode(r,e),vn.decode.bytes]}function Lr(r,e,t=0){return vn.encode(r,e,t),e}function Pr(r){return vn.encodingLength(r)}function ot(r,e){let t=e.byteLength,n=Pr(r),o=n+Pr(t),s=new Uint8Array(o+t);return Lr(r,s,0),Lr(t,s,n),s.set(e,o),new Dr(r,t,e,s)}function dt(r){let e=ft(r),[t,n]=Sn(e),[o,s]=Sn(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Dr(t,o,i,e)}function Yu(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Uu(r.bytes,t.bytes)}}var Dr=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Xu(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return vm(t,va(r),e??J.encoder);default:return Sm(t,va(r),e??ze.encoder)}}var Zu=new WeakMap;function va(r){let e=Zu.get(r);if(e==null){let t=new Map;return Zu.set(r,t),t}return e}var le=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==An)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Am)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=ot(e,t);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(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Yu(e.multihash,n.multihash)}toString(e){return Xu(this,e)}toJSON(){return{"/":Xu(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??ju(n,o,s.bytes))}else if(t[_m]===!0){let{version:n,multihash:o,code:s}=t,i=dt(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==An)throw new Error(`Version 0 CID must use dag-pb (code: ${An}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=ju(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,An,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=ft(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new Dr(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[u,d]=Sn(e.subarray(t));return t+=d,u},o=n(),s=An;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),c=n(),l=t+c,f=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:l}}static parse(e,t){let[n,o]=Em(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return va(s).set(n,e),s}};function Em(r,e){switch(r[0]){case"Q":{let t=e??J;return[J.prefix,t.decode(`${J.prefix}${r}`)]}case J.prefix:{let t=e??J;return[J.prefix,t.decode(r)]}case ze.prefix:{let t=e??ze;return[ze.prefix,t.decode(r)]}case En.prefix:{let t=e??En;return[En.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function vm(r,e,t){let{prefix:n}=t;if(n!==J.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Sm(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var An=112,Am=18;function ju(r,e,t){let n=Pr(r),o=n+Pr(e),s=new Uint8Array(o+t.byteLength);return Lr(r,s,0),Lr(e,s,n),s.set(t,o),s}var _m=Symbol.for("@ipld/js-cid/CID");var Sa={};Me(Sa,{identity:()=>Ye});var Qu=0,Im="identity",Ju=ft;function Cm(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return ot(Qu,Ju(r))}var Ye={code:Qu,name:Im,encode:Ju,digest:Cm};function j(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function ce(r=0){return new Uint8Array(r)}function Se(r=0){return new Uint8Array(r)}function Xe(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=Se(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var tf=Symbol.for("@achingbrain/uint8arraylist");function ef(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function $o(r){return!!r?.[tf]}var Q=class r{bufs;length;[tf]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if($o(n))t+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if($o(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=ef(this.bufs,e);return t.buf[t.index]}set(e,t){let n=ef(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if($o(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return Xe(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Xe(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=[...n],s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===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,e>=c)continue;let l=e>=a&&e<c,f=t>a&&t<=c;if(l&&f){if(e===a&&t===c){n.push(i);break}let u=e-a;n.push(i.subarray(u,u+(t-e)));break}if(l){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(t===c){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!$o(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let u=0;u<s;u++)i[u]=-1;for(let u=0;u<o;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,f;for(let u=t;u<=c;u+=f){f=0;for(let d=l;d>=0;d--){let h=this.get(u+d);if(n[d]!==h){f=Math.max(1,d-a[h]);break}}if(f===0)return u}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=ce(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=ce(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=ce(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=ce(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=ce(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=ce(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=ce(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=ce(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!j(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};var Aa={};Me(Aa,{base10:()=>Tm});var Tm=Pt({prefix:"9",name:"base10",alphabet:"0123456789"});var _a={};Me(_a,{base16:()=>Lm,base16upper:()=>Pm});var Lm=ae({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Pm=ae({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ia={};Me(Ia,{base2:()=>Dm});var Dm=ae({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ca={};Me(Ca,{base256emoji:()=>Mm});var rf=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}"),Rm=rf.reduce((r,e,t)=>(r[t]=e,r),[]),km=rf.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Om(r){return r.reduce((e,t)=>(e+=Rm[t],e),"")}function Nm(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=km[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Mm=Tr({prefix:"\u{1F680}",name:"base256emoji",encode:Om,decode:Nm});var Pa={};Me(Pa,{base64:()=>Ta,base64pad:()=>Bm,base64url:()=>La,base64urlpad:()=>Fm});var Ta=ae({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Bm=ae({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),La=ae({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Fm=ae({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Da={};Me(Da,{base8:()=>Um});var Um=ae({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ra={};Me(Ra,{identity:()=>Km});var Km=Tr({prefix:"\0",name:"identity",encode:r=>qu(r),decode:r=>Ku(r)});var Sx=new TextEncoder,Ax=new TextDecoder;var Na={};Me(Na,{sha256:()=>Rr,sha512:()=>zm});var Vm=20;function Oa({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new ka(r,e,t,n,o)}var ka=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Vm,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?nf(n,this.code,t?.truncate):n.then(o=>nf(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function nf(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return ot(e,r)}function sf(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Rr=Oa({name:"sha2-256",code:18,encode:sf("SHA-256")}),zm=Oa({name:"sha2-512",code:19,encode:sf("SHA-512")});var _n={...Ra,...Ia,...Da,...Aa,..._a,...wa,...xa,...ba,...Pa,...Ca},Mx={...Na,...Sa};function cf(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var af=cf("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ma=cf("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Se(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Hm={utf8:af,"utf-8":af,hex:_n.base16,latin1:Ma,ascii:Ma,binary:Ma,..._n},Vo=Hm;function L(r,e="utf8"){let t=Vo[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function U(r,e="utf8"){let t=Vo[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Wm=parseInt("11111",2),Ba=parseInt("10000000",2),Gm=parseInt("01111111",2),lf={0:In,1:In,2:Ym,3:jm,4:Qm,5:Zm,6:Xm,16:In,22:In,48:In};function ht(r,e={offset:0}){let t=r[e.offset]&Wm;if(e.offset++,lf[t]!=null)return lf[t](r,e);throw new Error("No decoder for tag "+t)}function Cn(r,e){let t=0;if((r[e.offset]&Ba)===Ba){let n=r[e.offset]&Gm,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)o+=r[e.offset].toString(16).padStart(2,"0");t=parseInt(o,16)}else t=r[e.offset],e.offset++;return t}function In(r,e){Cn(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=ht(r,e);if(n===null)break;t.push(n)}return t}function Ym(r,e){let t=Cn(r,e),n=e.offset,o=e.offset+t,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return e.offset+=t,Uint8Array.from(s)}function Xm(r,e){let t=Cn(r,e),n=e.offset+t,o=r[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;e.offset<n;){let l=r[e.offset];if(e.offset++,c.push(l&127),l<128){c.reverse();let f=0;for(let u=0;u<c.length;u++)f+=c[u]<<u*7;a+=`.${f}`,c=[]}}return a}function Zm(r,e){return e.offset++,null}function jm(r,e){let t=Cn(r,e),n=r[e.offset];e.offset++;let o=r.subarray(e.offset,e.offset+t-1);if(e.offset+=t,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Qm(r,e){let t=Cn(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function Jm(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new Q;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function zo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=Jm(r.byteLength);return new Q(Uint8Array.from([e.byteLength|Ba]),e)}function Pe(r){let e=new Q,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new Q(Uint8Array.from([2]),zo(e),e)}function Tn(r){let e=Uint8Array.from([0]),t=new Q(e,r);return new Q(Uint8Array.from([3]),zo(t),t)}function uf(r){return new Q(Uint8Array.from([4]),zo(r),r)}function Ze(r,e=48){let t=new Q;for(let n of r)t.append(n);return new Q(Uint8Array.from([e]),zo(t),t)}async function ff(r="P-256"){let e=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:r},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",e.publicKey),privateKey:await crypto.subtle.exportKey("jwk",e.privateKey)}}async function df(r,e,t){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["sign"]);t?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,e.subarray());return t?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function hf(r,e,t,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,e,t.subarray());return n?.signal?.throwIfAborted(),s}var eg=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),tg=Uint8Array.from([6,5,43,129,4,0,34]),rg=Uint8Array.from([6,5,43,129,4,0,35]),ng={ext:!0,kty:"EC",crv:"P-256"},og={ext:!0,kty:"EC",crv:"P-384"},sg={ext:!0,kty:"EC",crv:"P-521"},Fa=32,Ua=48,Ka=66;function qa(r){let e=ht(r);return pf(e)}function pf(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===Fa*2+1)return n=U(e.subarray(t,t+Fa),"base64url"),o=U(e.subarray(t+Fa),"base64url"),new Wt({...ng,key_ops:["verify"],x:n,y:o});if(e.byteLength===Ua*2+1)return n=U(e.subarray(t,t+Ua),"base64url"),o=U(e.subarray(t+Ua),"base64url"),new Wt({...og,key_ops:["verify"],x:n,y:o});if(e.byteLength===Ka*2+1)return n=U(e.subarray(t,t+Ka),"base64url"),o=U(e.subarray(t+Ka),"base64url"),new Wt({...sg,key_ops:["verify"],x:n,y:o});throw new C(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function mf(r){return Ze([Pe(Uint8Array.from([1])),uf(L(r.d??"","base64url")),Ze([yf(r.crv)],160),Ze([Tn(new Q(Uint8Array.from([4]),L(r.x??"","base64url"),L(r.y??"","base64url")))],161)]).subarray()}function gf(r){return Ze([Pe(Uint8Array.from([1])),Ze([yf(r.crv)],160),Ze([Tn(new Q(Uint8Array.from([4]),L(r.x??"","base64url"),L(r.y??"","base64url")))],161)]).subarray()}function yf(r){if(r==="P-256")return eg;if(r==="P-384")return tg;if(r==="P-521")return rg;throw new C(`Invalid curve ${r}`)}async function bf(r="P-256"){let e=await ff(r);return new Ho(e.privateKey)}var Wt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=gf(this.jwk)),this._raw}toMultihash(){return Ye.digest(He(this))}toCID(){return le.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:j(this.raw,e.raw)}async verify(e,t,n){return hf(this.jwk,t,e,n)}},Ho=class{type="ECDSA";jwk;publicKey;_raw;constructor(e){this.jwk=e,this.publicKey=new Wt({crv:e.crv,ext:e.ext,key_ops:["verify"],kty:"EC",x:e.x,y:e.y})}get raw(){return this._raw==null&&(this._raw=mf(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:j(this.raw,e.raw)}async sign(e,t){return df(this.jwk,e,t)}};function Gt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function st(r,e=""){if(!Number.isSafeInteger(r)||r<0){let t=e&&`"${e}" `;throw new Error(`${t}expected integer >= 0, got ${r}`)}}function V(r,e,t=""){let n=Gt(r),o=r?.length,s=e!==void 0;if(!n||s&&o!==e){let i=t&&`"${t}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return r}function Wo(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");st(r.outputLen),st(r.blockLen)}function kr(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function xf(r,e){V(r,void 0,"digestInto() output");let t=e.outputLen;if(r.length<t)throw new Error('"digestInto() output" expected to be of length >='+t)}function mt(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function Go(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function je(r,e){return r<<32-e|r>>>e}var Ef=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ig=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function gt(r){if(V(r),Ef)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=ig[r[t]];return e}var pt={_0:48,_9:57,A:65,F:70,a:97,f:102};function wf(r){if(r>=pt._0&&r<=pt._9)return r-pt._0;if(r>=pt.A&&r<=pt.F)return r-(pt.A-10);if(r>=pt.a&&r<=pt.f)return r-(pt.a-10)}function yt(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Ef)return Uint8Array.fromHex(r);let e=r.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,s=0;o<t;o++,s+=2){let i=wf(r.charCodeAt(s)),a=wf(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 Be(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];V(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let s=r[n];t.set(s,o),o+=s.length}return t}function $a(r,e={}){let t=(o,s)=>r(s).update(o).digest(),n=r(void 0);return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=o=>r(o),Object.assign(t,e),Object.freeze(t)}function Rt(r=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(r))}var Va=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function vf(r,e,t){return r&e^~r&t}function Sf(r,e,t){return r&e^r&t^e&t}var Ln=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,o){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Go(this.buffer)}update(e){kr(this),V(e);let{view:t,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Go(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){kr(this),xf(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;t[i++]=128,mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let u=i;u<o;u++)t[u]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Go(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let l=c/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)a.setUint32(4*u,f[u],s)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},bt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var we=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Yo=BigInt(4294967295),Af=BigInt(32);function ag(r,e=!1){return e?{h:Number(r&Yo),l:Number(r>>Af&Yo)}:{h:Number(r>>Af&Yo)|0,l:Number(r&Yo)|0}}function _f(r,e=!1){let t=r.length,n=new Uint32Array(t),o=new Uint32Array(t);for(let s=0;s<t;s++){let{h:i,l:a}=ag(r[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var za=(r,e,t)=>r>>>t,Ha=(r,e,t)=>r<<32-t|e>>>t,Yt=(r,e,t)=>r>>>t|e<<32-t,Xt=(r,e,t)=>r<<32-t|e>>>t,Pn=(r,e,t)=>r<<64-t|e>>>t-32,Dn=(r,e,t)=>r>>>t-32|e<<64-t;function it(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var If=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),Cf=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Tf=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Lf=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,Pf=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),Df=(r,e,t,n,o,s)=>e+t+n+o+s+(r/2**32|0)|0;var lg=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),kt=new Uint32Array(64),Wa=class extends Ln{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:t,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,t,n,o,s,i,a,c]}set(e,t,n,o,s,i,a,c){this.A=e|0,this.B=t|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(e,t){for(let u=0;u<16;u++,t+=4)kt[u]=e.getUint32(t,!1);for(let u=16;u<64;u++){let d=kt[u-15],h=kt[u-2],p=je(d,7)^je(d,18)^d>>>3,E=je(h,17)^je(h,19)^h>>>10;kt[u]=E+kt[u-7]+p+kt[u-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:f}=this;for(let u=0;u<64;u++){let d=je(a,6)^je(a,11)^je(a,25),h=f+d+vf(a,c,l)+lg[u]+kt[u]|0,E=(je(n,2)^je(n,13)^je(n,22))+Sf(n,o,s)|0;f=l,l=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,l,f)}roundClean(){mt(kt)}destroy(){this.set(0,0,0,0,0,0,0,0),mt(this.buffer)}},Ga=class extends Wa{A=bt[0]|0;B=bt[1]|0;C=bt[2]|0;D=bt[3]|0;E=bt[4]|0;F=bt[5]|0;G=bt[6]|0;H=bt[7]|0;constructor(){super(32)}};var Rf=_f(["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))),ug=Rf[0],fg=Rf[1],Ot=new Uint32Array(80),Nt=new Uint32Array(80),Ya=class extends Ln{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:s,