@libp2p/plaintext 1.0.7 → 1.0.8-4e0135c7d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/package.json +6 -6
- package/dist/typedoc-urls.json +0 -8
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPlaintext = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PPlaintext=(()=>{var Cr=Object.create;var yt=Object.defineProperty;var _r=Object.getOwnPropertyDescriptor;var kr=Object.getOwnPropertyNames;var Or=Object.getPrototypeOf,Mr=Object.prototype.hasOwnProperty;var Vr=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),x=(r,t)=>{for(var e in t)yt(r,e,{get:t[e],enumerable:!0})},Ce=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of kr(t))!Mr.call(r,i)&&i!==e&&yt(r,i,{get:()=>t[i],enumerable:!(n=_r(t,i))||n.enumerable});return r};var Pr=(r,t,e)=>(e=r!=null?Cr(Or(r)):{},Ce(t||!r||!r.__esModule?yt(e,"default",{value:r,enumerable:!0}):e,r)),Gr=r=>Ce(yt({},"__esModule",{value:!0}),r);var wr=Vr((Os,br)=>{"use strict";function gr(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function ii(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return gr(r,e)}catch{e.message=r.message,e.stack=r.stack;let i=function(){};return i.prototype=Object.create(Object.getPrototypeOf(r)),gr(new i,e)}}br.exports=ii});var yi={};x(yi,{plaintext:()=>wi});var Ei=Symbol.for("@libp2p/connection");var Li=Symbol.for("@libp2p/content-routing");var Ui=Symbol.for("@libp2p/peer-discovery");var _e=Symbol.for("@libp2p/peer-id");var Ri=Symbol.for("@libp2p/peer-routing");var ke;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(ke||(ke={}));var vi=Symbol.for("@libp2p/transport");var Oe;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Oe||(Oe={}));var xt=class r extends Error{code;constructor(t="Unexpected Peer"){super(t),this.code=r.code}static code="ERR_UNEXPECTED_PEER"},Et=class r extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Vt=class extends Event{detail;constructor(t,e){super(t,e),this.detail=e?.detail}},ki=globalThis.CustomEvent??Vt;var qt={};x(qt,{base58btc:()=>E,base58flickr:()=>Xr});function zr(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 i=0;i<r.length;i++){var o=r.charAt(i),s=o.charCodeAt(0);if(e[s]!==255)throw new TypeError(o+" is ambiguous");e[s]=i}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function u(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var w=0,V=0,S=0,I=l.length;S!==I&&l[S]===0;)S++,w++;for(var R=(I-S)*p+1>>>0,A=new Uint8Array(R);S!==I;){for(var T=l[S],k=0,D=R-1;(T!==0||k<V)&&D!==-1;D--,k++)T+=256*A[D]>>>0,A[D]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");V=k,S++}for(var F=R-V;F!==R&&A[F]===0;)F++;for(var wt=c.repeat(w);F<R;++F)wt+=r.charAt(A[F]);return wt}function b(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var w=0;if(l[w]!==" "){for(var V=0,S=0;l[w]===c;)V++,w++;for(var I=(l.length-w)*f+1>>>0,R=new Uint8Array(I);l[w];){var A=e[l.charCodeAt(w)];if(A===255)return;for(var T=0,k=I-1;(A!==0||T<S)&&k!==-1;k--,T++)A+=a*R[k]>>>0,R[k]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");S=T,w++}if(l[w]!==" "){for(var D=I-S;D!==I&&R[D]===0;)D++;for(var F=new Uint8Array(V+(I-D)),wt=V;D!==I;)F[wt++]=R[D++];return F}}}function bt(l){var w=b(l);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:b,decode:bt}}var $r=zr,qr=$r,Me=qr;var po=new Uint8Array(0);var Ve=(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},v=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")};var Pe=r=>new TextEncoder().encode(r),Ge=r=>new TextDecoder().decode(r);var Pt=class{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")}},Gt=class{constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),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 $e(this,t)}},zt=class{constructor(t){this.decoders=t}or(t){return $e(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},$e=(r,t)=>new zt({...r.decoders||{[r.prefix]:r},...t.decoders||{[t.prefix]:t}}),$t=class{constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new Pt(t,e,n),this.decoder=new Gt(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},H=({name:r,prefix:t,encode:e,decode:n})=>new $t(r,t,e,n),O=({prefix:r,name:t,alphabet:e})=>{let{encode:n,decode:i}=Me(e,t);return H({prefix:r,name:t,encode:n,decode:o=>v(i(o))})},Hr=(r,t,e,n)=>{let i={};for(let p=0;p<t.length;++p)i[t[p]]=p;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),a=0,c=0,f=0;for(let p=0;p<o;++p){let u=i[r[p]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,a+=e,a>=8&&(a-=8,s[f++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s},jr=(r,t,e)=>{let n=t[t.length-1]==="=",i=(1<<e)-1,o="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>e;)s-=e,o+=t[i&a>>s];if(s&&(o+=t[i&a<<e-s]),n)for(;o.length*e&7;)o+="=";return o},d=({name:r,prefix:t,bitsPerChar:e,alphabet:n})=>H({prefix:t,name:r,encode(i){return jr(i,n,e)},decode(i){return Hr(i,n,e,r)}});var E=O({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xr=O({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ht={};x(Ht,{base10:()=>Wr});var Wr=O({prefix:"9",name:"base10",alphabet:"0123456789"});var jt={};x(jt,{base16:()=>Jr,base16upper:()=>Kr});var Jr=d({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Kr=d({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Xt={};x(Xt,{base2:()=>Qr});var Qr=d({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Wt={};x(Wt,{base256emoji:()=>rn});var qe=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}"),Zr=qe.reduce((r,t,e)=>(r[e]=t,r),[]),Yr=qe.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function tn(r){return r.reduce((t,e)=>(t+=Zr[e],t),"")}function en(r){let t=[];for(let e of r){let n=Yr[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var rn=H({prefix:"\u{1F680}",name:"base256emoji",encode:tn,decode:en});var Jt={};x(Jt,{base32:()=>j,base32hex:()=>an,base32hexpad:()=>hn,base32hexpadupper:()=>un,base32hexupper:()=>cn,base32pad:()=>on,base32padupper:()=>sn,base32upper:()=>nn,base32z:()=>fn});var j=d({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),nn=d({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),on=d({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),sn=d({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),an=d({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),cn=d({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),hn=d({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),un=d({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),fn=d({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Kt={};x(Kt,{base36:()=>ln,base36upper:()=>pn});var ln=O({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),pn=O({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Qt={};x(Qt,{base64:()=>dn,base64pad:()=>mn,base64url:()=>gn,base64urlpad:()=>bn});var dn=d({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),mn=d({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),gn=d({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),bn=d({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Zt={};x(Zt,{base8:()=>wn});var wn=d({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Yt={};x(Yt,{identity:()=>yn});var yn=H({prefix:"\0",name:"identity",encode:r=>Ge(r),decode:r=>Pe(r)});var Ro=new TextEncoder,To=new TextDecoder;var ee={};x(ee,{identity:()=>Q});var An=Xe,He=128,Ln=127,Sn=~Ln,Dn=Math.pow(2,31);function Xe(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Dn;)t[e++]=r&255|He,r/=128;for(;r&Sn;)t[e++]=r&255|He,r>>>=7;return t[e]=r|0,Xe.bytes=e-n+1,t}var Un=te,Nn=128,je=127;function te(r,n){var e=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a)throw te.bytes=0,new RangeError("Could not decode varint");s=r[o++],e+=i<28?(s&je)<<i:(s&je)*Math.pow(2,i),i+=7}while(s>=Nn);return te.bytes=o-n,e}var In=Math.pow(2,7),Rn=Math.pow(2,14),Tn=Math.pow(2,21),Bn=Math.pow(2,28),Fn=Math.pow(2,35),vn=Math.pow(2,42),Cn=Math.pow(2,49),_n=Math.pow(2,56),kn=Math.pow(2,63),On=function(r){return r<In?1:r<Rn?2:r<Tn?3:r<Bn?4:r<Fn?5:r<vn?6:r<Cn?7:r<_n?8:r<kn?9:10},Mn={encode:An,decode:Un,encodingLength:On},Vn=Mn,ot=Vn;var st=(r,t=0)=>[ot.decode(r,t),ot.decode.bytes],X=(r,t,e=0)=>(ot.encode(r,t,e),t),W=r=>ot.encodingLength(r);var B=(r,t)=>{let e=t.byteLength,n=W(r),i=n+W(e),o=new Uint8Array(i+e);return X(r,o,0),X(e,o,n),o.set(t,i),new J(r,e,t,o)},at=r=>{let t=v(r),[e,n]=st(t),[i,o]=st(t.subarray(n)),s=t.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new J(e,i,s,t)},We=(r,t)=>{if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ve(r.bytes,e.bytes)}},J=class{constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};var Je=0,Pn="identity",Ke=v,Gn=r=>B(Je,Ke(r)),Q={code:Je,name:Pn,encode:Ke,digest:Gn};var ie={};x(ie,{sha256:()=>ct,sha512:()=>zn});var ne=({name:r,code:t,encode:e})=>new re(r,t,e),re=class{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?B(this.code,e):e.then(n=>B(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Ze=r=>async t=>new Uint8Array(await crypto.subtle.digest(r,t)),ct=ne({name:"sha2-256",code:18,encode:Ze("SHA-256")}),zn=ne({name:"sha2-512",code:19,encode:Ze("SHA-512")});var Ye=(r,t)=>{let{bytes:e,version:n}=r;switch(n){case 0:return qn(e,oe(r),t||E.encoder);default:return Hn(e,oe(r),t||j.encoder)}};var tr=new WeakMap,oe=r=>{let t=tr.get(r);if(t==null){let e=new Map;return tr.set(r,e),e}return t},P=class r{constructor(t,e,n,i){this.code=e,this.version=t,this.multihash=n,this.bytes=i,this["/"]=i}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!==ht)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==jn)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=B(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&&t.code===n.code&&t.version===n.version&&We(t.multihash,n.multihash)}toString(t){return Ye(this,t)}toJSON(){return{"/":Ye(this)}}link(){return this}get[Symbol.toStringTag](){return"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:i,multihash:o,bytes:s}=e;return new r(n,i,o,s||er(n,i,o.bytes))}else if(e[Xn]===!0){let{version:n,multihash:i,code:o}=e,s=at(i);return r.create(n,o,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!==ht)throw new Error(`Version 0 CID must use dag-pb (code: ${ht}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=er(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,ht,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,i=v(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=i.subarray(e.multihashSize-e.digestSize),s=new J(e.multihashCode,e.digestSize,o,i);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,b]=st(t.subarray(e));return e+=b,u},i=n(),o=ht;if(i===18?(i=0,e=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=e,a=n(),c=n(),f=e+c,p=f-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:p,size:f}}static parse(t,e){let[n,i]=$n(t,e),o=r.decode(i);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return oe(o).set(n,t),o}},$n=(r,t)=>{switch(r[0]){case"Q":{let e=t||E;return[E.prefix,e.decode(`${E.prefix}${r}`)]}case E.prefix:{let e=t||E;return[E.prefix,e.decode(r)]}case j.prefix:{let e=t||j;return[j.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}},qn=(r,t,e)=>{let{prefix:n}=e;if(n!==E.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let i=t.get(n);if(i==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return i},Hn=(r,t,e)=>{let{prefix:n}=e,i=t.get(n);if(i==null){let o=e.encode(r);return t.set(n,o),o}else return i},ht=112,jn=18,er=(r,t,e)=>{let n=W(r),i=n+W(t),o=new Uint8Array(i+e.byteLength);return X(r,o,0),X(t,o,n),o.set(e,i),o},Xn=Symbol.for("@ipld/js-cid/CID");var Z={...Yt,...Xt,...Zt,...Ht,...jt,...Jt,...Kt,...qt,...Qt,...Wt},jo={...ie,...ee};function se(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}var Wn=Symbol.for("nodejs.util.inspect.custom"),rr=Object.values(Z).map(r=>r.decoder).reduce((r,t)=>r.or(t),Z.identity.decoder),nr=114,ae=36,ce=37,ut=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[_e]=!0;toString(){return this.string==null&&(this.string=E.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return P.createV1(nr,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t instanceof Uint8Array)return se(this.multihash.bytes,t);if(typeof t=="string")return Jn(t).equals(this);if(t?.multihash?.bytes!=null)return se(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[Wn](){return`PeerId(${this.toString()})`}},Y=class extends ut{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},tt=class extends ut{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},et=class extends ut{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function Jn(r,t){if(t=t??rr,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=at(E.decode(`z${r}`));return r.startsWith("12D")?new tt({multihash:e}):r.startsWith("16U")?new et({multihash:e}):new Y({multihash:e})}return he(rr.decode(r))}function he(r){try{let t=at(r);if(t.code===Q.code){if(t.digest.length===ae)return new tt({multihash:t});if(t.digest.length===ce)return new et({multihash:t})}if(t.code===ct.code)return new Y({multihash:t})}catch{return Kn(P.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Kn(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==nr)throw new Error("Supplied PeerID CID is invalid");let t=r.multihash;if(t.code===ct.code)return new Y({multihash:r.multihash});if(t.code===Q.code){if(t.digest.length===ae)return new tt({multihash:r.multihash});if(t.digest.length===ce)return new et({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function ir(r,t){return r.length===ae?new tt({multihash:B(Q.code,r),privateKey:t}):r.length===ce?new et({multihash:B(Q.code,r),privateKey:t}):new Y({multihash:await ct.digest(r),publicKey:r,privateKey:t})}function ft(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function C(r=0){return globalThis.Buffer?.alloc!=null?ft(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function lt(r=0){return globalThis.Buffer?.allocUnsafe!=null?ft(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function ue(r,t){t==null&&(t=r.reduce((i,o)=>i+o.length,0));let e=lt(t),n=0;for(let i of r)e.set(i,n),n+=i.length;return ft(e)}function or(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}var ar=Symbol.for("@achingbrain/uint8arraylist");function sr(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let i=e+n.byteLength;if(t<i)return{buf:n,index:t-e};e=i}throw new RangeError("index is out of bounds")}function Lt(r){return!!r?.[ar]}var L=class r{bufs;length;[ar]=!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(Lt(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(Lt(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=sr(this.bufs,t);return e.buf[e.index]}set(t,e){let n=sr(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(Lt(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:i}=this._subList(t,e);return ue(n,i)}subarray(t,e){let{bufs:n,length:i}=this._subList(t,e);return n.length===1?n[0]:ue(n,i)}sublist(t,e){let{bufs:n,length:i}=this._subList(t,e),o=new r;return o.length=i,o.bufs=[...n],o}_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=[],i=0;for(let o=0;o<this.bufs.length;o++){let s=this.bufs[o],a=i,c=a+s.byteLength;if(i=c,t>=c)continue;let f=t>=a&&t<c,p=e>a&&e<=c;if(f&&p){if(t===a&&e===c){n.push(s);break}let u=t-a;n.push(s.subarray(u,u+(e-t)));break}if(f){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(p){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(!Lt(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 i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,s=new Int32Array(o);for(let u=0;u<o;u++)s[u]=-1;for(let u=0;u<i;u++)s[n[u]]=u;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,p;for(let u=e;u<=c;u+=p){p=0;for(let b=f;b>=0;b--){let bt=this.get(u+b);if(n[b]!==bt){p=Math.max(1,b-a[bt]);break}}if(p===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=lt(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 i=C(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,e,n),this.write(i,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 i=C(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,e,n),this.write(i,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 i=C(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,e,n),this.write(i,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=lt(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 i=C(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,e,n),this.write(i,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 i=C(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,e,n),this.write(i,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 i=C(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,e,n),this.write(i,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 i=C(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,e,n),this.write(i,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 i=C(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,e,n),this.write(i,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(!or(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((i,o)=>i+o.byteLength,0)),n.length=e,n}};function rt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var St=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function cr(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new St(e?.errorMessage,e?.errorCode));let n,i=new St(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((o,s)=>{n=()=>{s(i)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var fe=class{needNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.needNext=rt(),this.haveNext=rt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("Have next but next was undefined");let t=this.nextResult;return this.nextResult=void 0,this.needNext.resolve(),this.needNext=rt(),t}async throw(t){return this.ended=!0,t!=null&&this.haveNext.reject(t),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");this.nextResult!=null&&await this.needNext.promise,t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=rt(),await cr(this.needNext.promise,e?.signal,e)}};function hr(){return new fe}var Dt=class extends Error{code;constructor(t,e){super(t),this.code=e}},le=class extends Dt{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function ur(r,t){let e=hr();r.sink(e).catch(async s=>{await e.end(s)}),r.sink=async s=>{for await(let a of s)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let i=new L;return{read:async(s,a)=>{a?.signal?.throwIfAborted();let c,f=new Promise((p,u)=>{c=()=>{u(new le("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(s==null){let{done:u,value:b}=await Promise.race([n.next(),f]);return u===!0?new L:b}for(;i.byteLength<s;){let{value:u,done:b}=await Promise.race([n.next(),f]);if(b===!0)throw new Dt("unexpected end of input","ERR_UNEXPECTED_EOF");i.append(u)}let p=i.sublist(0,s);return i.consume(s),p}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(s,a)=>{a?.signal?.throwIfAborted(),s instanceof Uint8Array?await e.push(s,a):await e.push(s.subarray(),a)},unwrap:()=>{if(i.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield i:yield*i,yield*s}()}return r}}}function fr(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function lr(r=0){return globalThis.Buffer?.allocUnsafe!=null?fr(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var Qn=Math.pow(2,7),Zn=Math.pow(2,14),Yn=Math.pow(2,21),pe=Math.pow(2,28),de=Math.pow(2,35),me=Math.pow(2,42),ge=Math.pow(2,49),h=128,m=127;function _(r){if(r<Qn)return 1;if(r<Zn)return 2;if(r<Yn)return 3;if(r<pe)return 4;if(r<de)return 5;if(r<me)return 6;if(r<ge)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ti(r,t,e=0){switch(_(r)){case 8:t[e++]=r&255|h,r/=128;case 7:t[e++]=r&255|h,r/=128;case 6:t[e++]=r&255|h,r/=128;case 5:t[e++]=r&255|h,r/=128;case 4:t[e++]=r&255|h,r>>>=7;case 3:t[e++]=r&255|h,r>>>=7;case 2:t[e++]=r&255|h,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function ei(r,t,e=0){switch(_(r)){case 8:t.set(e++,r&255|h),r/=128;case 7:t.set(e++,r&255|h),r/=128;case 6:t.set(e++,r&255|h),r/=128;case 5:t.set(e++,r&255|h),r/=128;case 4:t.set(e++,r&255|h),r>>>=7;case 3:t.set(e++,r&255|h),r>>>=7;case 2:t.set(e++,r&255|h),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function ri(r,t){let e=r[t],n=0;if(n+=e&m,e<h||(e=r[t+1],n+=(e&m)<<7,e<h)||(e=r[t+2],n+=(e&m)<<14,e<h)||(e=r[t+3],n+=(e&m)<<21,e<h)||(e=r[t+4],n+=(e&m)*pe,e<h)||(e=r[t+5],n+=(e&m)*de,e<h)||(e=r[t+6],n+=(e&m)*me,e<h)||(e=r[t+7],n+=(e&m)*ge,e<h))return n;throw new RangeError("Could not decode varint")}function ni(r,t){let e=r.get(t),n=0;if(n+=e&m,e<h||(e=r.get(t+1),n+=(e&m)<<7,e<h)||(e=r.get(t+2),n+=(e&m)<<14,e<h)||(e=r.get(t+3),n+=(e&m)<<21,e<h)||(e=r.get(t+4),n+=(e&m)*pe,e<h)||(e=r.get(t+5),n+=(e&m)*de,e<h)||(e=r.get(t+6),n+=(e&m)*me,e<h)||(e=r.get(t+7),n+=(e&m)*ge,e<h))return n;throw new RangeError("Could not decode varint")}function pr(r,t,e=0){return t==null&&(t=lr(_(r))),t instanceof Uint8Array?ti(r,t,e):ei(r,t,e)}function Ut(r,t=0){return r instanceof Uint8Array?ri(r,t):ni(r,t)}function dr(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function mr(r=0){return globalThis.Buffer?.allocUnsafe!=null?dr(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Nt(r){return r[Symbol.asyncIterator]!=null}var It=r=>{let t=_(r),e=mr(t);return pr(r,e),It.bytes=t,e};It.bytes=0;function pt(r,t){t=t??{};let e=t.lengthEncoder??It;function*n(i){let o=e(i.byteLength);o instanceof Uint8Array?yield o:yield*o,i instanceof Uint8Array?yield i:yield*i}return Nt(r)?async function*(){for await(let i of r)yield*n(i)}():function*(){for(let i of r)yield*n(i)}()}pt.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??It;return new L(e(r.byteLength),r)};var nt=Pr(wr(),1);var oi=8,si=1024*1024*4,G;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(G||(G={}));var ye=r=>{let t=Ut(r);return ye.bytes=_(t),t};ye.bytes=0;function we(r,t){let e=new L,n=G.LENGTH,i=-1,o=t?.lengthDecoder??ye,s=t?.maxLengthLength??oi,a=t?.maxDataLength??si;function*c(){for(;e.byteLength>0;){if(n===G.LENGTH)try{if(i=o(e),i<0)throw(0,nt.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(i>a)throw(0,nt.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let f=o.bytes;e.consume(f),t?.onLength!=null&&t.onLength(i),n=G.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>s)throw(0,nt.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw f}if(n===G.DATA){if(e.byteLength<i)break;let f=e.sublist(0,i);e.consume(i),t?.onData!=null&&t.onData(f),yield f,n=G.LENGTH}}}return Nt(r)?async function*(){for await(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw(0,nt.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw(0,nt.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}we.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:o,value:s}=await r.next(e);if(o===!0)return;s!=null&&(yield s)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{e=1}}();return we(n,{...t??{},onLength:o=>{e=o}})};var Rt=class extends Error{code;constructor(t,e){super(t),this.code=e}},yr=r=>Ut(r);yr.bytes=0;function xr(r,t={}){let e=ur(r,t);return t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=_(t.maxDataLength)),{read:async i=>{let o=-1,s=new L,a=t?.lengthDecoder??yr;for(;;){s.append(await e.read(1,i));try{o=a(s)}catch(c){if(c instanceof RangeError)continue;throw c}if(t?.maxLengthLength!=null&&s.byteLength>t.maxLengthLength)throw new Rt("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(o>-1)break}if(t?.maxDataLength!=null&&o>t.maxDataLength)throw new Rt("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(o,i)},write:async(i,o)=>{await e.write(pt.single(i,t),o)},writeV:async(i,o)=>{let s=new L(...i.map(a=>pt.single(a,t)));await e.write(s,o)},unwrap:()=>e.unwrap()}}function Er(r,t){let e=xr(r,t),n={read:async(i,o)=>{let s=await e.read(o);return i.decode(s)},write:async(i,o,s)=>{await e.write(o.encode(i),s)},writeV:async(i,o,s)=>{await e.writeV(i.map(a=>o.encode(a)),s)},pb:i=>({read:async o=>n.read(i,o),write:async(o,s)=>n.write(o,i,s),writeV:async(o,s)=>n.writeV(o,i,s),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var xe=new Float32Array([-0]),M=new Uint8Array(xe.buffer);function Ar(r,t,e){xe[0]=r,t[e]=M[0],t[e+1]=M[1],t[e+2]=M[2],t[e+3]=M[3]}function Lr(r,t){return M[0]=r[t],M[1]=r[t+1],M[2]=r[t+2],M[3]=r[t+3],xe[0]}var Ee=new Float64Array([-0]),g=new Uint8Array(Ee.buffer);function Sr(r,t,e){Ee[0]=r,t[e]=g[0],t[e+1]=g[1],t[e+2]=g[2],t[e+3]=g[3],t[e+4]=g[4],t[e+5]=g[5],t[e+6]=g[6],t[e+7]=g[7]}function Dr(r,t){return g[0]=r[t],g[1]=r[t+1],g[2]=r[t+2],g[3]=r[t+3],g[4]=r[t+4],g[5]=r[t+5],g[6]=r[t+6],g[7]=r[t+7],Ee[0]}var ci=BigInt(Number.MAX_SAFE_INTEGER),hi=BigInt(Number.MIN_SAFE_INTEGER),y=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return z;if(t<ci&&t>hi)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,i=t-(n<<32n);return e&&(n=~n|0n,i=~i|0n,++i>Ur&&(i=0n,++n>Ur&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(t){if(t===0)return z;let e=t<0;e&&(t=-t);let n=t>>>0,i=(t-n)/4294967296>>>0;return e&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):z}},z=new y(0,0);z.toBigInt=function(){return 0n};z.zzEncode=z.zzDecode=function(){return this};z.length=function(){return 1};var Ur=4294967296n;function Nr(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ir(r,t,e){if(e-t<1)return"";let i,o=[],s=0,a;for(;t<e;)a=r[t++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function Ae(r,t,e){let n=e,i,o;for(let s=0;s<r.length;++s)i=r.charCodeAt(s),i<128?t[e++]=i:i<2048?(t[e++]=i>>6|192,t[e++]=i&63|128):(i&64512)===55296&&((o=r.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,t[e++]=i>>18|240,t[e++]=i>>12&63|128,t[e++]=i>>6&63|128,t[e++]=i&63|128):(t[e++]=i>>12|224,t[e++]=i>>6&63|128,t[e++]=i&63|128);return e-n}function U(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Tt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Le=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,U(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw U(this,4);return Tt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw U(this,4);return Tt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw U(this,4);let t=Lr(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw U(this,4);let t=Dr(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw U(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ir(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw U(this,t);this.pos+=t}else do if(this.pos>=this.len)throw U(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new y(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw U(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw U(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw U(this,8);let t=Tt(this.buf,this.pos+=4),e=Tt(this.buf,this.pos+=4);return new y(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Se(r){return new Le(r instanceof Uint8Array?r:r.subarray())}function Bt(r,t){let e=Se(r);return t.decode(e)}function Ft(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function $(r=0){return globalThis.Buffer?.allocUnsafe!=null?Ft(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Br(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Tr=Br("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),De=Br("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=$(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ui={utf8:Tr,"utf-8":Tr,hex:Z.base16,latin1:De,ascii:De,binary:De,...Z},Fr=ui;function vr(r,t="utf8"){let e=Fr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Ft(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Ue(r){let t=r??8192,e=t>>>1,n,i=t;return function(s){if(s<1||s>e)return $(s);i+s>t&&(n=$(t),i=0);let a=n.subarray(i,i+=s);return i&7&&(i=(i|7)+1),a}}var q=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Ne(){}var Re=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},fi=Ue();function li(r){return globalThis.Buffer!=null?$(r):fi(r)}var gt=class{len;head;tail;states;constructor(){this.len=0,this.head=new q(Ne,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new q(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Te((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(dt,10,y.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=y.fromBigInt(t);return this._push(dt,e.length(),e)}uint64Number(t){let e=y.fromNumber(t);return this._push(dt,e.length(),e)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=y.fromBigInt(t).zzEncode();return this._push(dt,e.length(),e)}sint64Number(t){let e=y.fromNumber(t).zzEncode();return this._push(dt,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ie,1,t?1:0)}fixed32(t){return this._push(mt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=y.fromBigInt(t);return this._push(mt,4,e.lo)._push(mt,4,e.hi)}fixed64Number(t){let e=y.fromNumber(t);return this._push(mt,4,e.lo)._push(mt,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ar,4,t)}double(t){return this._push(Sr,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Ie,1,0):this.uint32(e)._push(di,e,t)}string(t){let e=Nr(t);return e!==0?this.uint32(e)._push(Ae,e,t):this._push(Ie,1,0)}fork(){return this.states=new Re(this),this.head=this.tail=new q(Ne,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new q(Ne,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=li(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Ie(r,t,e){t[e]=r&255}function pi(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Te=class extends q{next;constructor(t,e){super(pi,t,e),this.next=void 0}};function dt(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function mt(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function di(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(gt.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(mi,t,r),this},gt.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(gi,t,r),this});function mi(r,t,e){t.set(r,e)}function gi(r,t,e){r.length<40?Ae(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(vr(r),e)}function Be(){return new gt}function vt(r,t){let e=Be();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var it;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(it||(it={}));function Ct(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Fe(r){function t(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let e=function(o,s){let a=t(o);s.int32(a)},n=function(o){let s=o.int32();return t(s)};return Ct("enum",it.VARINT,e,n)}function _t(r,t){return Ct("message",it.LENGTH_DELIMITED,r,t)}var kt;(function(r){let t;r.codec=()=>(t==null&&(t=_t((e,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),e.id!=null&&(n.uint32(10),n.bytes(e.id)),e.pubkey!=null&&(n.uint32(18),Mt.codec().encode(e.pubkey,n)),i.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let i={},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let s=e.uint32();switch(s>>>3){case 1:i.id=e.bytes();break;case 2:i.pubkey=Mt.codec().decode(e,e.uint32());break;default:e.skipType(s&7);break}}return i})),t),r.encode=e=>vt(e,r.codec()),r.decode=e=>Bt(e,r.codec())})(kt||(kt={}));var N;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1",r.ECDSA="ECDSA"})(N||(N={}));var Ot;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1",r[r.ECDSA=3]="ECDSA"})(Ot||(Ot={}));(function(r){r.codec=()=>Fe(Ot)})(N||(N={}));var Mt;(function(r){let t;r.codec=()=>(t==null&&(t=_t((e,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),e.Type!=null&&Ot[e.Type]!==0&&(n.uint32(8),N.codec().encode(e.Type,n)),e.Data!=null&&e.Data.byteLength>0&&(n.uint32(18),n.bytes(e.Data)),i.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let i={Type:N.RSA,Data:new Uint8Array(0)},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let s=e.uint32();switch(s>>>3){case 1:i.Type=N.codec().decode(e);break;case 2:i.Data=e.bytes();break;default:e.skipType(s&7);break}}return i})),t),r.encode=e=>vt(e,r.codec()),r.decode=e=>Bt(e,r.codec())})(Mt||(Mt={}));var bi="/plaintext/2.0.0",ve=class{protocol=bi;log;timeout;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:plaintext"),this.timeout=e.timeout??1e3}async secureInbound(t,e,n){return this._encrypt(t,e,n)}async secureOutbound(t,e,n){return this._encrypt(t,e,n)}async _encrypt(t,e,n){let i=AbortSignal.timeout(this.timeout),o=Er(e).pb(kt),s=N.RSA;t.type==="Ed25519"?s=N.Ed25519:t.type==="secp256k1"&&(s=N.Secp256k1),this.log("write pubkey exchange to peer %p",n);let[,a]=await Promise.all([o.write({id:t.toBytes(),pubkey:{Type:s,Data:t.publicKey??new Uint8Array(0)}},{signal:i}),o.read({signal:i})]),c;try{if(a.pubkey==null)throw new Error("Public key missing");if(a.pubkey.Data.length===0)throw new Error("Public key data too short");if(a.id==null)throw new Error("Remote id missing");if(c=await ir(a.pubkey.Data),!c.equals(he(a.id)))throw new Error("Public key did not match id")}catch(f){throw this.log.error(f),new Et("Remote did not provide its public key")}if(n!=null&&!c.equals(n))throw new xt;return this.log("plaintext key exchange completed successfully with peer %p",c),{conn:o.unwrap().unwrap(),remotePeer:c}}};function wi(r){return t=>new ve(t,r)}return Gr(yi);})();
|
|
2
|
+
"use strict";var Libp2PPlaintext=(()=>{var Rn=Object.create;var Rt=Object.defineProperty;var Tn=Object.getOwnPropertyDescriptor;var Bn=Object.getOwnPropertyNames;var Fn=Object.getPrototypeOf,Mn=Object.prototype.hasOwnProperty;var On=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),b=(r,t)=>{for(var e in t)Rt(r,e,{get:t[e],enumerable:!0})},mr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Bn(t))!Mn.call(r,o)&&o!==e&&Rt(r,o,{get:()=>t[o],enumerable:!(n=Tn(t,o))||n.enumerable});return r};var kn=(r,t,e)=>(e=r!=null?Rn(Fn(r)):{},mr(t||!r||!r.__esModule?Rt(e,"default",{value:r,enumerable:!0}):e,r)),Vn=r=>mr(Rt({},"__esModule",{value:!0}),r);var Wr=On((_c,Jr)=>{"use strict";function Xr(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function ei(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return Xr(r,e)}catch{e.message=r.message,e.stack=r.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(r)),Xr(new o,e)}}Jr.exports=ei});var Ss={};b(Ss,{plaintext:()=>As});var Ds=Symbol.for("@libp2p/connection");var Ns=Symbol.for("@libp2p/content-routing");var Cs=Symbol.for("@libp2p/peer-discovery");var br=Symbol.for("@libp2p/peer-id");var Bs=Symbol.for("@libp2p/peer-routing");var gr;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(gr||(gr={}));var ks=Symbol.for("@libp2p/transport");var wr;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(wr||(wr={}));var Tt=class r extends Error{code;constructor(t="Unexpected Peer"){super(t),this.code=r.code}static code="ERR_UNEXPECTED_PEER"},Bt=class r extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Zt=class extends Event{detail;constructor(t,e){super(t,e),this.detail=e?.detail}},zs=globalThis.CustomEvent??Zt;var ne={};b(ne,{base58btc:()=>T,base58flickr:()=>qn});var ba=new Uint8Array(0);function xr(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 _(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 yr(r){return new TextEncoder().encode(r)}function Er(r){return new TextDecoder().decode(r)}function _n(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),l=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function u(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var p=0,C=0,g=0,E=h.length;g!==E&&h[g]===0;)g++,p++;for(var A=(E-g)*f+1>>>0,m=new Uint8Array(A);g!==E;){for(var S=h[g],v=0,w=A-1;(S!==0||v<C)&&w!==-1;w--,v++)S+=256*m[w]>>>0,m[w]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");C=v,g++}for(var D=A-C;D!==A&&m[D]===0;)D++;for(var V=c.repeat(p);D<A;++D)V+=r.charAt(m[D]);return V}function L(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var p=0;if(h[p]!==" "){for(var C=0,g=0;h[p]===c;)C++,p++;for(var E=(h.length-p)*l+1>>>0,A=new Uint8Array(E);h[p];){var m=e[h.charCodeAt(p)];if(m===255)return;for(var S=0,v=E-1;(m!==0||S<g)&&v!==-1;v--,S++)m+=a*A[v]>>>0,A[v]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");g=S,p++}if(h[p]!==" "){for(var w=E-g;w!==E&&A[w]===0;)w++;for(var D=new Uint8Array(C+(E-w)),V=C;w!==E;)D[V++]=A[w++];return D}}}function Z(h){var p=L(h);if(p)return p;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:L,decode:Z}}var zn=_n,Pn=zn,Sr=Pn;var Yt=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")}},te=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),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 Lr(this,t)}},ee=class{decoders;constructor(t){this.decoders=t}or(t){return Lr(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 Lr(r,t){return new ee({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var re=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 Yt(t,e,n),this.decoder=new te(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Y({name:r,prefix:t,encode:e,decode:n}){return new re(r,t,e,n)}function $({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Sr(e,r);return Y({prefix:t,name:r,encode:n,decode:i=>_(o(i))})}function Gn(r,t,e,n){let o={};for(let f=0;f<t.length;++f)o[t[f]]=f;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),a=0,c=0,l=0;for(let f=0;f<i;++f){let u=o[r[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,a+=e,a>=8&&(a-=8,s[l++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s}function $n(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;)i+="=";return i}function x({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Y({prefix:t,name:r,encode(o){return $n(o,n,e)},decode(o){return Gn(o,n,e,r)}})}var T=$({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),qn=$({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var oe={};b(oe,{base10:()=>jn});var jn=$({prefix:"9",name:"base10",alphabet:"0123456789"});var ie={};b(ie,{base16:()=>Hn,base16upper:()=>Xn});var Hn=x({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Xn=x({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var se={};b(se,{base2:()=>Jn});var Jn=x({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ae={};b(ae,{base256emoji:()=>Yn});var Dr=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}"),Wn=Dr.reduce((r,t,e)=>(r[e]=t,r),[]),Kn=Dr.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Qn(r){return r.reduce((t,e)=>(t+=Wn[e],t),"")}function Zn(r){let t=[];for(let e of r){let n=Kn[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Yn=Y({prefix:"\u{1F680}",name:"base256emoji",encode:Qn,decode:Zn});var ce={};b(ce,{base32:()=>tt,base32hex:()=>no,base32hexpad:()=>io,base32hexpadupper:()=>so,base32hexupper:()=>oo,base32pad:()=>eo,base32padupper:()=>ro,base32upper:()=>to,base32z:()=>ao});var tt=x({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),to=x({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),eo=x({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ro=x({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),no=x({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),oo=x({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),io=x({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),so=x({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ao=x({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var he={};b(he,{base36:()=>co,base36upper:()=>ho});var co=$({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ho=$({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var fe={};b(fe,{base64:()=>fo,base64pad:()=>uo,base64url:()=>lo,base64urlpad:()=>po});var fo=x({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),uo=x({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),lo=x({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),po=x({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ue={};b(ue,{base8:()=>mo});var mo=x({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var le={};b(le,{identity:()=>bo});var bo=Y({prefix:"\0",name:"identity",encode:r=>Er(r),decode:r=>yr(r)});var Ta=new TextEncoder,Ba=new TextDecoder;var pe={};b(pe,{identity:()=>it});var xo=Ir,vr=128,yo=127,Eo=~yo,Ao=Math.pow(2,31);function Ir(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ao;)t[e++]=r&255|vr,r/=128;for(;r&Eo;)t[e++]=r&255|vr,r>>>=7;return t[e]=r|0,Ir.bytes=e-n+1,t}var So=de,Lo=128,Nr=127;function de(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw de.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&Nr)<<o:(s&Nr)*Math.pow(2,o),o+=7}while(s>=Lo);return de.bytes=i-n,e}var Do=Math.pow(2,7),vo=Math.pow(2,14),No=Math.pow(2,21),Io=Math.pow(2,28),Uo=Math.pow(2,35),Co=Math.pow(2,42),Ro=Math.pow(2,49),To=Math.pow(2,56),Bo=Math.pow(2,63),Fo=function(r){return r<Do?1:r<vo?2:r<No?3:r<Io?4:r<Uo?5:r<Co?6:r<Ro?7:r<To?8:r<Bo?9:10},Mo={encode:xo,decode:So,encodingLength:Fo},Oo=Mo,gt=Oo;function wt(r,t=0){return[gt.decode(r,t),gt.decode.bytes]}function et(r,t,e=0){return gt.encode(r,t,e),t}function rt(r){return gt.encodingLength(r)}function O(r,t){let e=t.byteLength,n=rt(r),o=n+rt(e),i=new Uint8Array(o+e);return et(r,i,0),et(e,i,n),i.set(t,o),new nt(r,e,t,i)}function xt(r){let t=_(r),[e,n]=wt(t),[o,i]=wt(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new nt(e,o,s,t)}function Ur(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&xr(r.bytes,e.bytes)}}var nt=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var Cr=0,ko="identity",Rr=_;function Vo(r){return O(Cr,Rr(r))}var it={code:Cr,name:ko,encode:Rr,digest:Vo};var ge={};b(ge,{sha256:()=>yt,sha512:()=>_o});function be({name:r,code:t,encode:e}){return new me(r,t,e)}var me=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?O(this.code,e):e.then(n=>O(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Br(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var yt=be({name:"sha2-256",code:18,encode:Br("SHA-256")}),_o=be({name:"sha2-512",code:19,encode:Br("SHA-512")});function Fr(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Po(e,we(r),t??T.encoder);default:return Go(e,we(r),t??tt.encoder)}}var Mr=new WeakMap;function we(r){let t=Mr.get(r);if(t==null){let e=new Map;return Mr.set(r,e),e}return t}var H=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!==Et)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==$o)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=O(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&&Ur(t.multihash,n.multihash)}toString(t){return Fr(this,t)}toJSON(){return{"/":Fr(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??Or(n,o,i.bytes))}else if(e[qo]===!0){let{version:n,multihash:o,code:i}=e,s=xt(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!==Et)throw new Error(`Version 0 CID must use dag-pb (code: ${Et}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Or(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Et,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=_(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 nt(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[u,L]=wt(t.subarray(e));return e+=L,u},o=n(),i=Et;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(),l=e+c,f=l-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:l}}static parse(t,e){let[n,o]=zo(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 we(i).set(n,t),i}};function zo(r,t){switch(r[0]){case"Q":{let e=t??T;return[T.prefix,e.decode(`${T.prefix}${r}`)]}case T.prefix:{let e=t??T;return[T.prefix,e.decode(r)]}case tt.prefix:{let e=t??tt;return[tt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Po(r,t,e){let{prefix:n}=e;if(n!==T.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 Go(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 Et=112,$o=18;function Or(r,t,e){let n=rt(r),o=n+rt(t),i=new Uint8Array(o+e.byteLength);return et(r,i,0),et(t,i,n),i.set(e,o),i}var qo=Symbol.for("@ipld/js-cid/CID");var xe={...le,...se,...ue,...oe,...ie,...ce,...he,...ne,...fe,...ae},tc={...ge,...pe};function ye(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}var jo=Symbol.for("nodejs.util.inspect.custom"),kr=Object.values(xe).map(r=>r.decoder).reduce((r,t)=>r.or(t),xe.identity.decoder),Vr=114,Ee=36,Ae=37,At=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[br]=!0;toString(){return this.string==null&&(this.string=T.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return H.createV1(Vr,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t instanceof Uint8Array)return ye(this.multihash.bytes,t);if(typeof t=="string")return Ho(t).equals(this);if(t?.multihash?.bytes!=null)return ye(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[jo](){return`PeerId(${this.toString()})`}},st=class extends At{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},at=class extends At{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},ct=class extends At{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function Ho(r,t){if(t=t??kr,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=xt(T.decode(`z${r}`));return r.startsWith("12D")?new at({multihash:e}):r.startsWith("16U")?new ct({multihash:e}):new st({multihash:e})}return Se(kr.decode(r))}function Se(r){try{let t=xt(r);if(t.code===it.code){if(t.digest.length===Ee)return new at({multihash:t});if(t.digest.length===Ae)return new ct({multihash:t})}if(t.code===yt.code)return new st({multihash:t})}catch{return Xo(H.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Xo(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Vr)throw new Error("Supplied PeerID CID is invalid");let t=r.multihash;if(t.code===yt.code)return new st({multihash:r.multihash});if(t.code===it.code){if(t.digest.length===Ee)return new at({multihash:r.multihash});if(t.digest.length===Ae)return new ct({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function _r(r,t){return r.length===Ee?new at({multihash:O(it.code,r),privateKey:t}):r.length===Ae?new ct({multihash:O(it.code,r),privateKey:t}):new st({multihash:await yt.digest(r),publicKey:r,privateKey:t})}function X(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function z(r=0){return globalThis.Buffer?.alloc!=null?X(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function N(r=0){return globalThis.Buffer?.allocUnsafe!=null?X(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function Le(r,t){t==null&&(t=r.reduce((o,i)=>o+i.length,0));let e=N(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return X(e)}function zr(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}var Gr=Symbol.for("@achingbrain/uint8arraylist");function Pr(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 Mt(r){return!!r?.[Gr]}var B=class r{bufs;length;[Gr]=!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(Mt(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(Mt(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=Pr(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Pr(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(Mt(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 Le(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Le(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 l=t>=a&&t<c,f=e>a&&e<=c;if(l&&f){if(t===a&&e===c){n.push(s);break}let u=t-a;n.push(s.subarray(u,u+(e-t)));break}if(l){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(f){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(!Mt(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 u=0;u<i;u++)s[u]=-1;for(let u=0;u<o;u++)s[n[u]]=u;let a=s,c=this.byteLength-n.byteLength,l=n.byteLength-1,f;for(let u=e;u<=c;u+=f){f=0;for(let L=l;L>=0;L--){let Z=this.get(u+L);if(n[L]!==Z){f=Math.max(1,L-a[Z]);break}}if(f===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=N(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=z(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=z(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=z(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=N(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=z(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=z(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=z(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=z(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=z(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(!zr(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}};function ht(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Ot=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function $r(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new Ot(e?.errorMessage,e?.errorCode));let n,o=new Ot(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((i,s)=>{n=()=>{s(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var De=class{needNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.needNext=ht(),this.haveNext=ht()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("Have next but next was undefined");let t=this.nextResult;return this.nextResult=void 0,this.needNext.resolve(),this.needNext=ht(),t}async throw(t){return this.ended=!0,t!=null&&this.haveNext.reject(t),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");this.nextResult!=null&&await this.needNext.promise,t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=ht(),await $r(this.needNext.promise,e?.signal,e)}};function qr(){return new De}var kt=class extends Error{code;constructor(t,e){super(t),this.code=e}},ve=class extends kt{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function jr(r,t){let e=qr();r.sink(e).catch(async s=>{await e.end(s)}),r.sink=async s=>{for await(let a of s)await e.push(a);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new B;return{read:async(s,a)=>{a?.signal?.throwIfAborted();let c,l=new Promise((f,u)=>{c=()=>{u(new ve("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(s==null){let{done:u,value:L}=await Promise.race([n.next(),l]);return u===!0?new B:L}for(;o.byteLength<s;){let{value:u,done:L}=await Promise.race([n.next(),l]);if(L===!0)throw new kt("unexpected end of input","ERR_UNEXPECTED_EOF");o.append(u)}let f=o.sublist(0,s);return o.consume(s),f}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(s,a)=>{a?.signal?.throwIfAborted(),s instanceof Uint8Array?await e.push(s,a):await e.push(s.subarray(),a)},unwrap:()=>{if(o.byteLength>0){let s=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*s}()}return r}}}var Jo=Math.pow(2,7),Wo=Math.pow(2,14),Ko=Math.pow(2,21),Ne=Math.pow(2,28),Ie=Math.pow(2,35),Ue=Math.pow(2,42),Ce=Math.pow(2,49),d=128,I=127;function P(r){if(r<Jo)return 1;if(r<Wo)return 2;if(r<Ko)return 3;if(r<Ne)return 4;if(r<Ie)return 5;if(r<Ue)return 6;if(r<Ce)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Qo(r,t,e=0){switch(P(r)){case 8:t[e++]=r&255|d,r/=128;case 7:t[e++]=r&255|d,r/=128;case 6:t[e++]=r&255|d,r/=128;case 5:t[e++]=r&255|d,r/=128;case 4:t[e++]=r&255|d,r>>>=7;case 3:t[e++]=r&255|d,r>>>=7;case 2:t[e++]=r&255|d,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Zo(r,t,e=0){switch(P(r)){case 8:t.set(e++,r&255|d),r/=128;case 7:t.set(e++,r&255|d),r/=128;case 6:t.set(e++,r&255|d),r/=128;case 5:t.set(e++,r&255|d),r/=128;case 4:t.set(e++,r&255|d),r>>>=7;case 3:t.set(e++,r&255|d),r>>>=7;case 2:t.set(e++,r&255|d),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Yo(r,t){let e=r[t],n=0;if(n+=e&I,e<d||(e=r[t+1],n+=(e&I)<<7,e<d)||(e=r[t+2],n+=(e&I)<<14,e<d)||(e=r[t+3],n+=(e&I)<<21,e<d)||(e=r[t+4],n+=(e&I)*Ne,e<d)||(e=r[t+5],n+=(e&I)*Ie,e<d)||(e=r[t+6],n+=(e&I)*Ue,e<d)||(e=r[t+7],n+=(e&I)*Ce,e<d))return n;throw new RangeError("Could not decode varint")}function ti(r,t){let e=r.get(t),n=0;if(n+=e&I,e<d||(e=r.get(t+1),n+=(e&I)<<7,e<d)||(e=r.get(t+2),n+=(e&I)<<14,e<d)||(e=r.get(t+3),n+=(e&I)<<21,e<d)||(e=r.get(t+4),n+=(e&I)*Ne,e<d)||(e=r.get(t+5),n+=(e&I)*Ie,e<d)||(e=r.get(t+6),n+=(e&I)*Ue,e<d)||(e=r.get(t+7),n+=(e&I)*Ce,e<d))return n;throw new RangeError("Could not decode varint")}function Hr(r,t,e=0){return t==null&&(t=N(P(r))),t instanceof Uint8Array?Qo(r,t,e):Zo(r,t,e)}function Vt(r,t=0){return r instanceof Uint8Array?Yo(r,t):ti(r,t)}function _t(r){return r[Symbol.asyncIterator]!=null}var zt=r=>{let t=P(r),e=N(t);return Hr(r,e),zt.bytes=t,e};zt.bytes=0;function St(r,t){t=t??{};let e=t.lengthEncoder??zt;function*n(o){let i=e(o.byteLength);i instanceof Uint8Array?yield i:yield*i,o instanceof Uint8Array?yield o:yield*o}return _t(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}St.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??zt;return new B(e(r.byteLength),r)};var ft=kn(Wr(),1);var ri=8,ni=1024*1024*4,J;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(J||(J={}));var Be=r=>{let t=Vt(r);return Be.bytes=P(t),t};Be.bytes=0;function Te(r,t){let e=new B,n=J.LENGTH,o=-1,i=t?.lengthDecoder??Be,s=t?.maxLengthLength??ri,a=t?.maxDataLength??ni;function*c(){for(;e.byteLength>0;){if(n===J.LENGTH)try{if(o=i(e),o<0)throw(0,ft.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(o>a)throw(0,ft.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let l=i.bytes;e.consume(l),t?.onLength!=null&&t.onLength(o),n=J.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>s)throw(0,ft.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw l}if(n===J.DATA){if(e.byteLength<o)break;let l=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(l),yield l,n=J.LENGTH}}}return _t(r)?async function*(){for await(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,ft.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,ft.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Te.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:i,value:s}=await r.next(e);if(i===!0)return;s!=null&&(yield s)}catch(i){if(i.code==="ERR_UNDER_READ")return{done:!0,value:null};throw i}finally{e=1}}();return Te(n,{...t??{},onLength:i=>{e=i}})};var Pt=class extends Error{code;constructor(t,e){super(t),this.code=e}},Kr=r=>Vt(r);Kr.bytes=0;function Qr(r,t={}){let e=jr(r,t);return t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=P(t.maxDataLength)),{read:async o=>{let i=-1,s=new B,a=t?.lengthDecoder??Kr;for(;;){s.append(await e.read(1,o));try{i=a(s)}catch(c){if(c instanceof RangeError)continue;throw c}if(t?.maxLengthLength!=null&&s.byteLength>t.maxLengthLength)throw new Pt("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(i>-1)break}if(t?.maxDataLength!=null&&i>t.maxDataLength)throw new Pt("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(i,o)},write:async(o,i)=>{await e.write(St.single(o,t),i)},writeV:async(o,i)=>{let s=new B(...o.map(a=>St.single(a,t)));await e.write(s,i)},unwrap:()=>e.unwrap()}}function Zr(r,t){let e=Qr(r,t),n={read:async(o,i)=>{let s=await e.read(i);return o.decode(s)},write:async(o,i,s)=>{await e.write(i.encode(o),s)},writeV:async(o,i,s)=>{await e.writeV(o.map(a=>i.encode(a)),s)},pb:o=>({read:async i=>n.read(o,i),write:async(i,s)=>n.write(i,o,s),writeV:async(i,s)=>n.writeV(i,o,s),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Fe=new Float32Array([-0]),q=new Uint8Array(Fe.buffer);function Yr(r,t,e){Fe[0]=r,t[e]=q[0],t[e+1]=q[1],t[e+2]=q[2],t[e+3]=q[3]}function tn(r,t){return q[0]=r[t],q[1]=r[t+1],q[2]=r[t+2],q[3]=r[t+3],Fe[0]}var Me=new Float64Array([-0]),U=new Uint8Array(Me.buffer);function en(r,t,e){Me[0]=r,t[e]=U[0],t[e+1]=U[1],t[e+2]=U[2],t[e+3]=U[3],t[e+4]=U[4],t[e+5]=U[5],t[e+6]=U[6],t[e+7]=U[7]}function rn(r,t){return U[0]=r[t],U[1]=r[t+1],U[2]=r[t+2],U[3]=r[t+3],U[4]=r[t+4],U[5]=r[t+5],U[6]=r[t+6],U[7]=r[t+7],Me[0]}var ii=BigInt(Number.MAX_SAFE_INTEGER),si=BigInt(Number.MIN_SAFE_INTEGER),R=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return W;if(t<ii&&t>si)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>nn&&(o=0n,++n>nn&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return W;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):W}},W=new R(0,0);W.toBigInt=function(){return 0n};W.zzEncode=W.zzDecode=function(){return this};W.length=function(){return 1};var nn=4294967296n;function on(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function sn(r,t,e){if(e-t<1)return"";let o,i=[],s=0,a;for(;t<e;)a=r[t++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Oe(r,t,e){let n=e,o,i;for(let s=0;s<r.length;++s)o=r.charCodeAt(s),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((i=r.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function F(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Gt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var ke=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,F(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw F(this,4);return Gt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw F(this,4);return Gt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw F(this,4);let t=tn(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw F(this,4);let t=rn(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw F(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return sn(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw F(this,t);this.pos+=t}else do if(this.pos>=this.len)throw F(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new R(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw F(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw F(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw F(this,8);let t=Gt(this.buf,this.pos+=4),e=Gt(this.buf,this.pos+=4);return new R(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ve(r){return new ke(r instanceof Uint8Array?r:r.subarray())}function $t(r,t){let e=Ve(r);return t.decode(e)}var $e={};b($e,{base10:()=>li});function ai(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var 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),l=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function u(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var p=0,C=0,g=0,E=h.length;g!==E&&h[g]===0;)g++,p++;for(var A=(E-g)*f+1>>>0,m=new Uint8Array(A);g!==E;){for(var S=h[g],v=0,w=A-1;(S!==0||v<C)&&w!==-1;w--,v++)S+=256*m[w]>>>0,m[w]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");C=v,g++}for(var D=A-C;D!==A&&m[D]===0;)D++;for(var V=c.repeat(p);D<A;++D)V+=r.charAt(m[D]);return V}function L(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var p=0;if(h[p]!==" "){for(var C=0,g=0;h[p]===c;)C++,p++;for(var E=(h.length-p)*l+1>>>0,A=new Uint8Array(E);h[p];){var m=e[h.charCodeAt(p)];if(m===255)return;for(var S=0,v=E-1;(m!==0||S<g)&&v!==-1;v--,S++)m+=a*A[v]>>>0,A[v]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");g=S,p++}if(h[p]!==" "){for(var w=E-g;w!==E&&A[w]===0;)w++;for(var D=new Uint8Array(C+(E-w)),V=C;w!==E;)D[V++]=A[w++];return D}}}function Z(h){var p=L(h);if(p)return p;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:L,decode:Z}}var ci=ai,hi=ci,cn=hi;var oh=new Uint8Array(0);var hn=(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},G=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")};var fn=r=>new TextEncoder().encode(r),un=r=>new TextDecoder().decode(r);var _e=class{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")}},ze=class{constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),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 dn(this,t)}},Pe=class{constructor(t){this.decoders=t}or(t){return dn(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},dn=(r,t)=>new Pe({...r.decoders||{[r.prefix]:r},...t.decoders||{[t.prefix]:t}}),Ge=class{constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new _e(t,e,n),this.decoder=new ze(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},ut=({name:r,prefix:t,encode:e,decode:n})=>new Ge(r,t,e,n),j=({prefix:r,name:t,alphabet:e})=>{let{encode:n,decode:o}=cn(e,t);return ut({prefix:r,name:t,encode:n,decode:i=>G(o(i))})},fi=(r,t,e,n)=>{let o={};for(let f=0;f<t.length;++f)o[t[f]]=f;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),a=0,c=0,l=0;for(let f=0;f<i;++f){let u=o[r[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,a+=e,a>=8&&(a-=8,s[l++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s},ui=(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&&(i+=t[o&a<<e-s]),n)for(;i.length*e&7;)i+="=";return i},y=({name:r,prefix:t,bitsPerChar:e,alphabet:n})=>ut({prefix:t,name:r,encode(o){return ui(o,n,e)},decode(o){return fi(o,n,e,r)}});var li=j({prefix:"9",name:"base10",alphabet:"0123456789"});var qe={};b(qe,{base16:()=>di,base16upper:()=>pi});var di=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),pi=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var je={};b(je,{base2:()=>mi});var mi=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var He={};b(He,{base256emoji:()=>yi});var pn=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}"),bi=pn.reduce((r,t,e)=>(r[e]=t,r),[]),gi=pn.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function wi(r){return r.reduce((t,e)=>(t+=bi[e],t),"")}function xi(r){let t=[];for(let e of r){let n=gi[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var yi=ut({prefix:"\u{1F680}",name:"base256emoji",encode:wi,decode:xi});var Xe={};b(Xe,{base32:()=>lt,base32hex:()=>Li,base32hexpad:()=>vi,base32hexpadupper:()=>Ni,base32hexupper:()=>Di,base32pad:()=>Ai,base32padupper:()=>Si,base32upper:()=>Ei,base32z:()=>Ii});var lt=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ei=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ai=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Si=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Li=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Di=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),vi=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ni=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ii=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Je={};b(Je,{base36:()=>Ui,base36upper:()=>Ci});var Ui=j({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ci=j({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var We={};b(We,{base58btc:()=>k,base58flickr:()=>Ri});var k=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ri=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ke={};b(Ke,{base64:()=>Ti,base64pad:()=>Bi,base64url:()=>Fi,base64urlpad:()=>Mi});var Ti=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Bi=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Fi=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Mi=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Qe={};b(Qe,{base8:()=>Oi});var Oi=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ze={};b(Ze,{identity:()=>ki});var ki=ut({prefix:"\0",name:"identity",encode:r=>un(r),decode:r=>fn(r)});var xh=new TextEncoder,yh=new TextDecoder;var tr={};b(tr,{identity:()=>ss});var zi=gn,mn=128,Pi=127,Gi=~Pi,$i=Math.pow(2,31);function gn(r,t,e){t=t||[],e=e||0;for(var n=e;r>=$i;)t[e++]=r&255|mn,r/=128;for(;r&Gi;)t[e++]=r&255|mn,r>>>=7;return t[e]=r|0,gn.bytes=e-n+1,t}var qi=Ye,ji=128,bn=127;function Ye(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Ye.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&bn)<<o:(s&bn)*Math.pow(2,o),o+=7}while(s>=ji);return Ye.bytes=i-n,e}var Hi=Math.pow(2,7),Xi=Math.pow(2,14),Ji=Math.pow(2,21),Wi=Math.pow(2,28),Ki=Math.pow(2,35),Qi=Math.pow(2,42),Zi=Math.pow(2,49),Yi=Math.pow(2,56),ts=Math.pow(2,63),es=function(r){return r<Hi?1:r<Xi?2:r<Ji?3:r<Wi?4:r<Ki?5:r<Qi?6:r<Zi?7:r<Yi?8:r<ts?9:10},rs={encode:zi,decode:qi,encodingLength:es},ns=rs,Lt=ns;var Dt=(r,t=0)=>[Lt.decode(r,t),Lt.decode.bytes],dt=(r,t,e=0)=>(Lt.encode(r,t,e),t),pt=r=>Lt.encodingLength(r);var K=(r,t)=>{let e=t.byteLength,n=pt(r),o=n+pt(e),i=new Uint8Array(o+e);return dt(r,i,0),dt(e,i,n),i.set(t,o),new mt(r,e,t,i)},wn=r=>{let t=G(r),[e,n]=Dt(t),[o,i]=Dt(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new mt(e,o,s,t)},xn=(r,t)=>{if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&hn(r.bytes,e.bytes)}},mt=class{constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var yn=0,os="identity",En=G,is=r=>K(yn,En(r)),ss={code:yn,name:os,encode:En,digest:is};var nr={};b(nr,{sha256:()=>as,sha512:()=>cs});var rr=({name:r,code:t,encode:e})=>new er(r,t,e),er=class{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?K(this.code,e):e.then(n=>K(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Sn=r=>async t=>new Uint8Array(await crypto.subtle.digest(r,t)),as=rr({name:"sha2-256",code:18,encode:Sn("SHA-256")}),cs=rr({name:"sha2-512",code:19,encode:Sn("SHA-512")});var Ln=(r,t)=>{let{bytes:e,version:n}=r;switch(n){case 0:return fs(e,or(r),t||k.encoder);default:return us(e,or(r),t||lt.encoder)}};var Dn=new WeakMap,or=r=>{let t=Dn.get(r);if(t==null){let e=new Map;return Dn.set(r,e),e}return t},jt=class r{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!==Nt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ls)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=K(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&&t.code===n.code&&t.version===n.version&&xn(t.multihash,n.multihash)}toString(t){return Ln(this,t)}toJSON(){return{"/":Ln(this)}}link(){return this}get[Symbol.toStringTag](){return"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||vn(n,o,i.bytes))}else if(e[ds]===!0){let{version:n,multihash:o,code:i}=e,s=wn(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!==Nt)throw new Error(`Version 0 CID must use dag-pb (code: ${Nt}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=vn(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Nt,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=G(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 mt(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[u,L]=Dt(t.subarray(e));return e+=L,u},o=n(),i=Nt;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(),l=e+c,f=l-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:l}}static parse(t,e){let[n,o]=hs(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 or(i).set(n,t),i}},hs=(r,t)=>{switch(r[0]){case"Q":{let e=t||k;return[k.prefix,e.decode(`${k.prefix}${r}`)]}case k.prefix:{let e=t||k;return[k.prefix,e.decode(r)]}case lt.prefix:{let e=t||lt;return[lt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}},fs=(r,t,e)=>{let{prefix:n}=e;if(n!==k.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},us=(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},Nt=112,ls=18,vn=(r,t,e)=>{let n=pt(r),o=n+pt(t),i=new Uint8Array(o+e.byteLength);return dt(r,i,0),dt(t,i,n),i.set(e,o),i},ds=Symbol.for("@ipld/js-cid/CID");var ir={...Ze,...je,...Qe,...$e,...qe,...Xe,...Je,...We,...Ke,...He},Oh={...nr,...tr};function In(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Nn=In("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),sr=In("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=N(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ps={utf8:Nn,"utf-8":Nn,hex:ir.base16,latin1:sr,ascii:sr,binary:sr,...ir},Un=ps;function Cn(r,t="utf8"){let e=Un[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?X(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function ar(r){let t=r??8192,e=t>>>1,n,o=t;return function(s){if(s<1||s>e)return N(s);o+s>t&&(n=N(t),o=0);let a=n.subarray(o,o+=s);return o&7&&(o=(o|7)+1),a}}var Q=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function cr(){}var fr=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ms=ar();function bs(r){return globalThis.Buffer!=null?N(r):ms(r)}var Ct=class{len;head;tail;states;constructor(){this.len=0,this.head=new Q(cr,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Q(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ur((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(It,10,R.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=R.fromBigInt(t);return this._push(It,e.length(),e)}uint64Number(t){let e=R.fromNumber(t);return this._push(It,e.length(),e)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=R.fromBigInt(t).zzEncode();return this._push(It,e.length(),e)}sint64Number(t){let e=R.fromNumber(t).zzEncode();return this._push(It,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(hr,1,t?1:0)}fixed32(t){return this._push(Ut,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=R.fromBigInt(t);return this._push(Ut,4,e.lo)._push(Ut,4,e.hi)}fixed64Number(t){let e=R.fromNumber(t);return this._push(Ut,4,e.lo)._push(Ut,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Yr,4,t)}double(t){return this._push(en,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(hr,1,0):this.uint32(e)._push(ws,e,t)}string(t){let e=on(t);return e!==0?this.uint32(e)._push(Oe,e,t):this._push(hr,1,0)}fork(){return this.states=new fr(this),this.head=this.tail=new Q(cr,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Q(cr,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=bs(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function hr(r,t,e){t[e]=r&255}function gs(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ur=class extends Q{next;constructor(t,e){super(gs,t,e),this.next=void 0}};function It(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Ut(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function ws(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ct.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(xs,t,r),this},Ct.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ys,t,r),this});function xs(r,t,e){t.set(r,e)}function ys(r,t,e){r.length<40?Oe(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Cn(r),e)}function lr(){return new Ct}function Ht(r,t){let e=lr();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var bt;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(bt||(bt={}));function Xt(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function dr(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(i,s){let a=t(i);s.int32(a)},n=function(i){let s=i.int32();return t(s)};return Xt("enum",bt.VARINT,e,n)}function Jt(r,t){return Xt("message",bt.LENGTH_DELIMITED,r,t)}var Wt;(function(r){let t;r.codec=()=>(t==null&&(t=Jt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.id!=null&&(n.uint32(10),n.bytes(e.id)),e.pubkey!=null&&(n.uint32(18),Qt.codec().encode(e.pubkey,n)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.id=e.bytes();break;case 2:o.pubkey=Qt.codec().decode(e,e.uint32());break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>Ht(e,r.codec()),r.decode=e=>$t(e,r.codec())})(Wt||(Wt={}));var M;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1",r.ECDSA="ECDSA"})(M||(M={}));var Kt;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1",r[r.ECDSA=3]="ECDSA"})(Kt||(Kt={}));(function(r){r.codec=()=>dr(Kt)})(M||(M={}));var Qt;(function(r){let t;r.codec=()=>(t==null&&(t=Jt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&Kt[e.Type]!==0&&(n.uint32(8),M.codec().encode(e.Type,n)),e.Data!=null&&e.Data.byteLength>0&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let o={Type:M.RSA,Data:new Uint8Array(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let s=e.uint32();switch(s>>>3){case 1:o.Type=M.codec().decode(e);break;case 2:o.Data=e.bytes();break;default:e.skipType(s&7);break}}return o})),t),r.encode=e=>Ht(e,r.codec()),r.decode=e=>$t(e,r.codec())})(Qt||(Qt={}));var Es="/plaintext/2.0.0",pr=class{protocol=Es;log;timeout;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:plaintext"),this.timeout=e.timeout??1e3}async secureInbound(t,e,n){return this._encrypt(t,e,n)}async secureOutbound(t,e,n){return this._encrypt(t,e,n)}async _encrypt(t,e,n){let o=AbortSignal.timeout(this.timeout),i=Zr(e).pb(Wt),s=M.RSA;t.type==="Ed25519"?s=M.Ed25519:t.type==="secp256k1"&&(s=M.Secp256k1),this.log("write pubkey exchange to peer %p",n);let[,a]=await Promise.all([i.write({id:t.toBytes(),pubkey:{Type:s,Data:t.publicKey??new Uint8Array(0)}},{signal:o}),i.read({signal:o})]),c;try{if(a.pubkey==null)throw new Error("Public key missing");if(a.pubkey.Data.length===0)throw new Error("Public key data too short");if(a.id==null)throw new Error("Remote id missing");if(c=await _r(a.pubkey.Data),!c.equals(Se(a.id)))throw new Error("Public key did not match id")}catch(l){throw this.log.error(l),new Bt("Remote did not provide its public key")}if(n!=null&&!c.equals(n))throw new Tt;return this.log("plaintext key exchange completed successfully with peer %p",c),{conn:i.unwrap().unwrap(),remotePeer:c}}};function As(r){return t=>new pr(t,r)}return Vn(Ss);})();
|
|
3
3
|
return Libp2PPlaintext}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/plaintext",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8-4e0135c7d",
|
|
4
4
|
"description": "An insecure connection encrypter",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext#readme",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"dep-check": "aegir dep-check"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@libp2p/interface": "
|
|
55
|
-
"@libp2p/peer-id": "
|
|
54
|
+
"@libp2p/interface": "1.0.2-4e0135c7d",
|
|
55
|
+
"@libp2p/peer-id": "4.0.2-4e0135c7d",
|
|
56
56
|
"@multiformats/multiaddr": "^12.1.10",
|
|
57
57
|
"it-protobuf-stream": "^1.1.1",
|
|
58
58
|
"it-stream-types": "^2.0.1",
|
|
@@ -60,9 +60,9 @@
|
|
|
60
60
|
"uint8arraylist": "^2.4.3"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@libp2p/interface-compliance-tests": "
|
|
64
|
-
"@libp2p/logger": "
|
|
65
|
-
"@libp2p/peer-id-factory": "
|
|
63
|
+
"@libp2p/interface-compliance-tests": "5.0.8-4e0135c7d",
|
|
64
|
+
"@libp2p/logger": "4.0.2-4e0135c7d",
|
|
65
|
+
"@libp2p/peer-id-factory": "4.0.1-4e0135c7d",
|
|
66
66
|
"aegir": "^41.0.2",
|
|
67
67
|
"protons": "^7.3.0",
|
|
68
68
|
"sinon": "^17.0.0"
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"PlaintextComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_plaintext.PlaintextComponents.html",
|
|
3
|
-
".:PlaintextComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_plaintext.PlaintextComponents.html",
|
|
4
|
-
"PlaintextInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_plaintext.PlaintextInit.html",
|
|
5
|
-
".:PlaintextInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_plaintext.PlaintextInit.html",
|
|
6
|
-
"plaintext": "https://libp2p.github.io/js-libp2p/functions/_libp2p_plaintext.plaintext.html",
|
|
7
|
-
".:plaintext": "https://libp2p.github.io/js-libp2p/functions/_libp2p_plaintext.plaintext.html"
|
|
8
|
-
}
|