@libp2p/plaintext 1.0.25 → 1.1.0-3b9cbf7d8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -1
- package/dist/src/index.js.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +7 -1
- 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 Ft=Object.defineProperty;var lr=Object.getOwnPropertyDescriptor;var dr=Object.getOwnPropertyNames;var pr=Object.prototype.hasOwnProperty;var y=(r,t)=>{for(var e in t)Ft(r,e,{get:t[e],enumerable:!0})},mr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of dr(t))!pr.call(r,i)&&i!==e&&Ft(r,i,{get:()=>t[i],enumerable:!(n=lr(t,i))||n.enumerable});return r};var wr=r=>mr(Ft({},"__esModule",{value:!0}),r);var qn={};y(qn,{plaintext:()=>Gn});var Se=Symbol.for("@libp2p/peer-id");var pt=class r extends Error{code;constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError",this.code=r.code}static code="ERR_UNEXPECTED_PEER"},mt=class r extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError",this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var kt={};y(kt,{base58btc:()=>E,base58flickr:()=>Ar});var Xn=new Uint8Array(0);function Le(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 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")}function De(r){return new TextEncoder().encode(r)}function Ie(r){return new TextDecoder().decode(r)}function gr(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 s=r.charAt(i),o=s.charCodeAt(0);if(e[o]!==255)throw new TypeError(s+" is ambiguous");e[o]=i}var a=r.length,h=r.charAt(0),d=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function u(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var b=0,P=0,L=0,R=f.length;L!==R&&f[L]===0;)L++,b++;for(var U=(R-L)*l+1>>>0,S=new Uint8Array(U);L!==R;){for(var F=f[L],V=0,D=U-1;(F!==0||V<P)&&D!==-1;D--,V++)F+=256*S[D]>>>0,S[D]=F%a>>>0,F=F/a>>>0;if(F!==0)throw new Error("Non-zero carry");P=V,L++}for(var C=U-P;C!==U&&S[C]===0;)C++;for(var dt=h.repeat(b);C<U;++C)dt+=r.charAt(S[C]);return dt}function g(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var b=0;if(f[b]!==" "){for(var P=0,L=0;f[b]===h;)P++,b++;for(var R=(f.length-b)*d+1>>>0,U=new Uint8Array(R);f[b];){var S=e[f.charCodeAt(b)];if(S===255)return;for(var F=0,V=R-1;(S!==0||F<L)&&V!==-1;V--,F++)S+=a*U[V]>>>0,U[V]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");L=F,b++}if(f[b]!==" "){for(var D=R-L;D!==R&&U[D]===0;)D++;for(var C=new Uint8Array(P+(R-D)),dt=P;D!==R;)C[dt++]=U[D++];return C}}}function lt(f){var b=g(f);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:g,decode:lt}}var br=gr,xr=br,Re=xr;var Bt=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")}},Ct=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 Ue(this,t)}},vt=class{decoders;constructor(t){this.decoders=t}or(t){return Ue(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 Ue(r,t){return new vt({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Tt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new Bt(t,e,n),this.decoder=new Ct(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function $({name:r,prefix:t,encode:e,decode:n}){return new Tt(r,t,e,n)}function _({name:r,prefix:t,alphabet:e}){let{encode:n,decode:i}=Re(e,r);return $({prefix:t,name:r,encode:n,decode:s=>v(i(s))})}function yr(r,t,e,n){let i={};for(let l=0;l<t.length;++l)i[t[l]]=l;let s=r.length;for(;r[s-1]==="=";)--s;let o=new Uint8Array(s*e/8|0),a=0,h=0,d=0;for(let l=0;l<s;++l){let u=i[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<e|u,a+=e,a>=8&&(a-=8,o[d++]=255&h>>a)}if(a>=e||255&h<<8-a)throw new SyntaxError("Unexpected end of data");return o}function Er(r,t,e){let n=t[t.length-1]==="=",i=(1<<e)-1,s="",o=0,a=0;for(let h=0;h<r.length;++h)for(a=a<<8|r[h],o+=8;o>e;)o-=e,s+=t[i&a>>o];if(o!==0&&(s+=t[i&a<<e-o]),n)for(;s.length*e&7;)s+="=";return s}function p({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return $({prefix:t,name:r,encode(i){return Er(i,n,e)},decode(i){return yr(i,n,e,r)}})}var E=_({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ar=_({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Mt={};y(Mt,{base10:()=>Sr});var Sr=_({prefix:"9",name:"base10",alphabet:"0123456789"});var Vt={};y(Vt,{base16:()=>Lr,base16upper:()=>Dr});var Lr=p({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Dr=p({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var _t={};y(_t,{base2:()=>Ir});var Ir=p({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ot={};y(Ot,{base256emoji:()=>Br});var Fe=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}"),Nr=Fe.reduce((r,t,e)=>(r[e]=t,r),[]),Rr=Fe.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Ur(r){return r.reduce((t,e)=>(t+=Nr[e],t),"")}function Fr(r){let t=[];for(let e of r){let n=Rr[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Br=$({prefix:"\u{1F680}",name:"base256emoji",encode:Ur,decode:Fr});var Pt={};y(Pt,{base32:()=>j,base32hex:()=>kr,base32hexpad:()=>Vr,base32hexpadupper:()=>_r,base32hexupper:()=>Mr,base32pad:()=>vr,base32padupper:()=>Tr,base32upper:()=>Cr,base32z:()=>Or});var j=p({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Cr=p({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vr=p({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Tr=p({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),kr=p({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Mr=p({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Vr=p({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),_r=p({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Or=p({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var zt={};y(zt,{base36:()=>Pr,base36upper:()=>zr});var Pr=_({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zr=_({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Gt={};y(Gt,{base64:()=>Gr,base64pad:()=>qr,base64url:()=>$r,base64urlpad:()=>jr});var Gr=p({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),qr=p({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),$r=p({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),jr=p({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var qt={};y(qt,{base8:()=>Wr});var Wr=p({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $t={};y($t,{identity:()=>Xr});var Xr=$({prefix:"\0",name:"identity",encode:r=>Ie(r),decode:r=>De(r)});var ci=new TextEncoder,ui=new TextDecoder;var Wt={};y(Wt,{identity:()=>K});var Kr=ve,Be=128,Qr=127,Zr=~Qr,Yr=Math.pow(2,31);function ve(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Yr;)t[e++]=r&255|Be,r/=128;for(;r&Zr;)t[e++]=r&255|Be,r>>>=7;return t[e]=r|0,ve.bytes=e-n+1,t}var tn=jt,en=128,Ce=127;function jt(r,n){var e=0,n=n||0,i=0,s=n,o,a=r.length;do{if(s>=a)throw jt.bytes=0,new RangeError("Could not decode varint");o=r[s++],e+=i<28?(o&Ce)<<i:(o&Ce)*Math.pow(2,i),i+=7}while(o>=en);return jt.bytes=s-n,e}var rn=Math.pow(2,7),nn=Math.pow(2,14),sn=Math.pow(2,21),on=Math.pow(2,28),an=Math.pow(2,35),hn=Math.pow(2,42),cn=Math.pow(2,49),un=Math.pow(2,56),fn=Math.pow(2,63),ln=function(r){return r<rn?1:r<nn?2:r<sn?3:r<on?4:r<an?5:r<hn?6:r<cn?7:r<un?8:r<fn?9:10},dn={encode:Kr,decode:tn,encodingLength:ln},pn=dn,nt=pn;function it(r,t=0){return[nt.decode(r,t),nt.decode.bytes]}function W(r,t,e=0){return nt.encode(r,t,e),t}function X(r){return nt.encodingLength(r)}function B(r,t){let e=t.byteLength,n=X(r),i=n+X(e),s=new Uint8Array(i+e);return W(r,s,0),W(e,s,n),s.set(t,i),new H(r,e,t,s)}function st(r){let t=v(r),[e,n]=it(t),[i,s]=it(t.subarray(n)),o=t.subarray(n+s);if(o.byteLength!==i)throw new Error("Incorrect length");return new H(e,i,o,t)}function Te(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Le(r.bytes,e.bytes)}}var H=class{code;size;digest;bytes;constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};var ke=0,mn="identity",Me=v;function wn(r){return B(ke,Me(r))}var K={code:ke,name:mn,encode:Me,digest:wn};var Jt={};y(Jt,{sha256:()=>ot,sha512:()=>gn});function Ht({name:r,code:t,encode:e}){return new Xt(r,t,e)}var Xt=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?B(this.code,e):e.then(n=>B(this.code,n))}else throw Error("Unknown type, must be binary type")}};function _e(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ot=Ht({name:"sha2-256",code:18,encode:_e("SHA-256")}),gn=Ht({name:"sha2-512",code:19,encode:_e("SHA-512")});function Oe(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return xn(e,Kt(r),t??E.encoder);default:return yn(e,Kt(r),t??j.encoder)}}var Pe=new WeakMap;function Kt(r){let t=Pe.get(r);if(t==null){let e=new Map;return Pe.set(r,e),e}return t}var z=class r{code;version;multihash;bytes;"/";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!==at)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==En)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!=null&&t.code===n.code&&t.version===n.version&&Te(t.multihash,n.multihash)}toString(t){return Oe(this,t)}toJSON(){return{"/":Oe(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:i,multihash:s,bytes:o}=e;return new r(n,i,s,o??ze(n,i,s.bytes))}else if(e[An]===!0){let{version:n,multihash:i,code:s}=e,o=st(i);return r.create(n,s,o)}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!==at)throw new Error(`Version 0 CID must use dag-pb (code: ${at}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=ze(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,at,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,i=v(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=i.subarray(e.multihashSize-e.digestSize),o=new H(e.multihashCode,e.digestSize,s,i);return[e.version===0?r.createV0(o):r.createV1(e.codec,o),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,g]=it(t.subarray(e));return e+=g,u},i=n(),s=at;if(i===18?(i=0,e=0):s=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let o=e,a=n(),h=n(),d=e+h,l=d-o;return{version:i,codec:s,multihashCode:a,digestSize:h,multihashSize:l,size:d}}static parse(t,e){let[n,i]=bn(t,e),s=r.decode(i);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Kt(s).set(n,t),s}};function bn(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)]}}}function xn(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 s=e.encode(r).slice(1);return t.set(n,s),s}else return i}function yn(r,t,e){let{prefix:n}=e,i=t.get(n);if(i==null){let s=e.encode(r);return t.set(n,s),s}else return i}var at=112,En=18;function ze(r,t,e){let n=X(r),i=n+X(t),s=new Uint8Array(i+e.byteLength);return W(r,s,0),W(t,s,n),s.set(e,i),s}var An=Symbol.for("@ipld/js-cid/CID");var Q={...$t,..._t,...qt,...Mt,...Vt,...Pt,...zt,...kt,...Gt,...Ot},Bi={...Jt,...Wt};function ht(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 Sn=Symbol.for("nodejs.util.inspect.custom"),Ge=Object.values(Q).map(r=>r.decoder).reduce((r,t)=>r.or(t),Q.identity.decoder),qe=114,Qt=36,Zt=37,ct=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()})`}[Se]=!0;toString(){return this.string==null&&(this.string=E.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return z.createV1(qe,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ht(this.multihash.bytes,t);if(typeof t=="string")return Ln(t).equals(this);if(t?.multihash?.bytes!=null)return ht(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[Sn](){return`PeerId(${this.toString()})`}},Z=class extends ct{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Y=class extends ct{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},tt=class extends ct{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function Ln(r,t){if(t=t??Ge,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=st(E.decode(`z${r}`));return r.startsWith("12D")?new Y({multihash:e}):r.startsWith("16U")?new tt({multihash:e}):new Z({multihash:e})}return Yt(Ge.decode(r))}function Yt(r){try{let t=st(r);if(t.code===K.code){if(t.digest.length===Qt)return new Y({multihash:t});if(t.digest.length===Zt)return new tt({multihash:t})}if(t.code===ot.code)return new Z({multihash:t})}catch{return Dn(z.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Dn(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==qe)throw new Error("Supplied PeerID CID is invalid");let t=r.multihash;if(t.code===ot.code)return new Z({multihash:r.multihash});if(t.code===K.code){if(t.digest.length===Qt)return new Y({multihash:r.multihash});if(t.digest.length===Zt)return new tt({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function $e(r,t){return r.length===Qt?new Y({multihash:B(K.code,r),privateKey:t}):r.length===Zt?new tt({multihash:B(K.code,r),privateKey:t}):new Z({multihash:await ot.digest(r),publicKey:r,privateKey:t})}function et(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var gt=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 je(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new gt(e?.errorMessage,e?.errorCode));let n,i=new gt(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((s,o)=>{n=()=>{o(i)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var te=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=et(),this.haveNext=et()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=et(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),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");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=et(),await je(this.readNext.promise,e?.signal,e)}};function We(){return new te}function T(r=0){return new Uint8Array(r)}function x(r=0){return new Uint8Array(r)}function ee(r,t){t==null&&(t=r.reduce((i,s)=>i+s.length,0));let e=x(t),n=0;for(let i of r)e.set(i,n),n+=i.length;return e}var He=Symbol.for("@achingbrain/uint8arraylist");function Xe(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 bt(r){return!!r?.[He]}var k=class r{bufs;length;[He]=!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(bt(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(bt(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=Xe(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Xe(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(bt(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 ee(n,i)}subarray(t,e){let{bufs:n,length:i}=this._subList(t,e);return n.length===1?n[0]:ee(n,i)}sublist(t,e){let{bufs:n,length:i}=this._subList(t,e),s=new r;return s.length=i,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],i=0;for(let s=0;s<this.bufs.length;s++){let o=this.bufs[s],a=i,h=a+o.byteLength;if(i=h,t>=h)continue;let d=t>=a&&t<h,l=e>a&&e<=h;if(d&&l){if(t===a&&e===h){n.push(o);break}let u=t-a;n.push(o.subarray(u,u+(e-t)));break}if(d){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(l){if(e===h){n.push(o);break}n.push(o.subarray(0,e-a));break}n.push(o)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!bt(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 s=256,o=new Int32Array(s);for(let u=0;u<s;u++)o[u]=-1;for(let u=0;u<i;u++)o[n[u]]=u;let a=o,h=this.byteLength-n.byteLength,d=n.byteLength-1,l;for(let u=e;u<=h;u+=l){l=0;for(let g=d;g>=0;g--){let lt=this.get(u+g);if(n[g]!==lt){l=Math.max(1,g-a[lt]);break}}if(l===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=x(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=T(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=T(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=T(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=x(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=T(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=T(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=T(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=T(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=T(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(!ht(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,s)=>i+s.byteLength,0)),n.length=e,n}};var xt=class extends Error{code;constructor(t,e){super(t),this.code=e}},re=class extends xt{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function Je(r,t){let e=We();r.sink(e).catch(async o=>{await e.end(o)}),r.sink=async o=>{for await(let a of o)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 k;return{read:async(o,a)=>{a?.signal?.throwIfAborted();let h,d=new Promise((l,u)=>{h=()=>{u(new re("Read aborted"))},a?.signal?.addEventListener("abort",h)});try{if(o==null){let{done:u,value:g}=await Promise.race([n.next(),d]);return u===!0?new k:g}for(;i.byteLength<o;){let{value:u,done:g}=await Promise.race([n.next(),d]);if(g===!0)throw new xt("unexpected end of input","ERR_UNEXPECTED_EOF");i.append(u)}let l=i.sublist(0,o);return i.consume(o),l}finally{h!=null&&a?.signal?.removeEventListener("abort",h)}},write:async(o,a)=>{a?.signal?.throwIfAborted(),o instanceof Uint8Array?await e.push(o,a):await e.push(o.subarray(),a)},unwrap:()=>{if(i.byteLength>0){let o=r.source;r.source=async function*(){t?.yieldBytes===!1?yield i:yield*i,yield*o}()}return r}}}var In=Math.pow(2,7),Nn=Math.pow(2,14),Rn=Math.pow(2,21),ne=Math.pow(2,28),ie=Math.pow(2,35),se=Math.pow(2,42),oe=Math.pow(2,49),c=128,m=127;function M(r){if(r<In)return 1;if(r<Nn)return 2;if(r<Rn)return 3;if(r<ne)return 4;if(r<ie)return 5;if(r<se)return 6;if(r<oe)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ae(r,t,e=0){switch(M(r)){case 8:t[e++]=r&255|c,r/=128;case 7:t[e++]=r&255|c,r/=128;case 6:t[e++]=r&255|c,r/=128;case 5:t[e++]=r&255|c,r/=128;case 4:t[e++]=r&255|c,r>>>=7;case 3:t[e++]=r&255|c,r>>>=7;case 2:t[e++]=r&255|c,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Un(r,t,e=0){switch(M(r)){case 8:t.set(e++,r&255|c),r/=128;case 7:t.set(e++,r&255|c),r/=128;case 6:t.set(e++,r&255|c),r/=128;case 5:t.set(e++,r&255|c),r/=128;case 4:t.set(e++,r&255|c),r>>>=7;case 3:t.set(e++,r&255|c),r>>>=7;case 2:t.set(e++,r&255|c),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function he(r,t){let e=r[t],n=0;if(n+=e&m,e<c||(e=r[t+1],n+=(e&m)<<7,e<c)||(e=r[t+2],n+=(e&m)<<14,e<c)||(e=r[t+3],n+=(e&m)<<21,e<c)||(e=r[t+4],n+=(e&m)*ne,e<c)||(e=r[t+5],n+=(e&m)*ie,e<c)||(e=r[t+6],n+=(e&m)*se,e<c)||(e=r[t+7],n+=(e&m)*oe,e<c))return n;throw new RangeError("Could not decode varint")}function Fn(r,t){let e=r.get(t),n=0;if(n+=e&m,e<c||(e=r.get(t+1),n+=(e&m)<<7,e<c)||(e=r.get(t+2),n+=(e&m)<<14,e<c)||(e=r.get(t+3),n+=(e&m)<<21,e<c)||(e=r.get(t+4),n+=(e&m)*ne,e<c)||(e=r.get(t+5),n+=(e&m)*ie,e<c)||(e=r.get(t+6),n+=(e&m)*se,e<c)||(e=r.get(t+7),n+=(e&m)*oe,e<c))return n;throw new RangeError("Could not decode varint")}function Ke(r,t,e=0){return t==null&&(t=x(M(r))),t instanceof Uint8Array?ae(r,t,e):Un(r,t,e)}function Qe(r,t=0){return r instanceof Uint8Array?he(r,t):Fn(r,t)}var yt=class extends Error{code;constructor(t,e){super(t),this.code=e}};function Ze(r,t={}){let e=Je(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=M(t.maxDataLength));let n=t?.lengthDecoder??Qe,i=t?.lengthEncoder??Ke;return{read:async o=>{let a=-1,h=new k;for(;;){h.append(await e.read(1,o));try{a=n(h)}catch(d){if(d instanceof RangeError)continue;throw d}if(t?.maxLengthLength!=null&&h.byteLength>t.maxLengthLength)throw new yt("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new yt("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(a,o)},write:async(o,a)=>{await e.write(new k(i(o.byteLength),o),a)},writeV:async(o,a)=>{let h=new k(...o.flatMap(d=>[i(d.byteLength),d]));await e.write(h,a)},unwrap:()=>e.unwrap()}}function Ye(r,t){let e=Ze(r,t),n={read:async(i,s)=>{let o=await e.read(s);return i.decode(o)},write:async(i,s,o)=>{await e.write(s.encode(i),o)},writeV:async(i,s,o)=>{await e.writeV(i.map(a=>s.encode(a)),o)},pb:i=>({read:async s=>n.read(i,s),write:async(s,o)=>n.write(s,i,o),writeV:async(s,o)=>n.writeV(s,i,o),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var ce=new Float32Array([-0]),O=new Uint8Array(ce.buffer);function tr(r,t,e){ce[0]=r,t[e]=O[0],t[e+1]=O[1],t[e+2]=O[2],t[e+3]=O[3]}function er(r,t){return O[0]=r[t],O[1]=r[t+1],O[2]=r[t+2],O[3]=r[t+3],ce[0]}var ue=new Float64Array([-0]),w=new Uint8Array(ue.buffer);function rr(r,t,e){ue[0]=r,t[e]=w[0],t[e+1]=w[1],t[e+2]=w[2],t[e+3]=w[3],t[e+4]=w[4],t[e+5]=w[5],t[e+6]=w[6],t[e+7]=w[7]}function nr(r,t){return w[0]=r[t],w[1]=r[t+1],w[2]=r[t+2],w[3]=r[t+3],w[4]=r[t+4],w[5]=r[t+5],w[6]=r[t+6],w[7]=r[t+7],ue[0]}var Cn=BigInt(Number.MAX_SAFE_INTEGER),vn=BigInt(Number.MIN_SAFE_INTEGER),A=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 G;if(t<Cn&&t>vn)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>ir&&(i=0n,++n>ir&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(t){if(t===0)return G;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):G}},G=new A(0,0);G.toBigInt=function(){return 0n};G.zzEncode=G.zzDecode=function(){return this};G.length=function(){return 1};var ir=4294967296n;function sr(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 or(r,t,e){if(e-t<1)return"";let i,s=[],o=0,a;for(;t<e;)a=r[t++],a<128?s[o++]=a:a>191&&a<224?s[o++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[o++]=55296+(a>>10),s[o++]=56320+(a&1023)):s[o++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,o>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,s)),o=0);return i!=null?(o>0&&i.push(String.fromCharCode.apply(String,s.slice(0,o))),i.join("")):String.fromCharCode.apply(String,s.slice(0,o))}function fe(r,t,e){let n=e,i,s;for(let o=0;o<r.length;++o)i=r.charCodeAt(o),i<128?t[e++]=i:i<2048?(t[e++]=i>>6|192,t[e++]=i&63|128):(i&64512)===55296&&((s=r.charCodeAt(o+1))&64512)===56320?(i=65536+((i&1023)<<10)+(s&1023),++o,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 I(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Et(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,I(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 I(this,4);return Et(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw I(this,4);return Et(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw I(this,4);let t=er(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw I(this,4);let t=nr(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 I(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return or(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw I(this,t);this.pos+=t}else do if(this.pos>=this.len)throw I(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 A(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 I(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 I(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 I(this,8);let t=Et(this.buf,this.pos+=4),e=Et(this.buf,this.pos+=4);return new A(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=he(this.buf,this.pos);return this.pos+=M(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function de(r){return new le(r instanceof Uint8Array?r:r.subarray())}function At(r,t,e){let n=de(r);return t.decode(n,void 0,e)}function cr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var hr=cr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),pe=cr("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=x(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Tn={utf8:hr,"utf-8":hr,hex:Q.base16,latin1:pe,ascii:pe,binary:pe,...Q},ur=Tn;function fr(r,t="utf8"){let e=ur[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function me(r){let t=r??8192,e=t>>>1,n,i=t;return function(o){if(o<1||o>e)return x(o);i+o>t&&(n=x(t),i=0);let a=n.subarray(i,i+=o);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 we(){}var be=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},kn=me();function Mn(r){return globalThis.Buffer!=null?x(r):kn(r)}var ft=class{len;head;tail;states;constructor(){this.len=0,this.head=new q(we,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 xe((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(St,10,A.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=A.fromBigInt(t);return this._push(St,e.length(),e)}uint64Number(t){return this._push(ae,M(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=A.fromBigInt(t).zzEncode();return this._push(St,e.length(),e)}sint64Number(t){let e=A.fromNumber(t).zzEncode();return this._push(St,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ge,1,t?1:0)}fixed32(t){return this._push(ut,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=A.fromBigInt(t);return this._push(ut,4,e.lo)._push(ut,4,e.hi)}fixed64Number(t){let e=A.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(tr,4,t)}double(t){return this._push(rr,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ge,1,0):this.uint32(e)._push(_n,e,t)}string(t){let e=sr(t);return e!==0?this.uint32(e)._push(fe,e,t):this._push(ge,1,0)}fork(){return this.states=new be(this),this.head=this.tail=new q(we,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(we,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=Mn(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ge(r,t,e){t[e]=r&255}function Vn(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var xe=class extends q{next;constructor(t,e){super(Vn,t,e),this.next=void 0}};function St(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 _n(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(ft.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(On,t,r),this},ft.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Pn,t,r),this});function On(r,t,e){t.set(r,e)}function Pn(r,t,e){r.length<40?fe(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(fr(r),e)}function ye(){return new ft}function Lt(r,t){let e=ye();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var rt;(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"})(rt||(rt={}));function Dt(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ee(r){function t(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let e=function(s,o){let a=t(s);o.int32(a)},n=function(s){let o=s.int32();return t(o)};return Dt("enum",rt.VARINT,e,n)}function It(r,t){return Dt("message",rt.LENGTH_DELIMITED,r,t)}var Nt;(function(r){let t;r.codec=()=>(t==null&&(t=It((e,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),e.id!=null&&(n.uint32(10),n.bytes(e.id)),e.pubkey!=null&&(n.uint32(18),Ut.codec().encode(e.pubkey,n)),i.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let i={},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let o=e.uint32();switch(o>>>3){case 1:i.id=e.bytes();break;case 2:i.pubkey=Ut.codec().decode(e,e.uint32());break;default:e.skipType(o&7);break}}return i})),t),r.encode=e=>Lt(e,r.codec()),r.decode=e=>At(e,r.codec())})(Nt||(Nt={}));var N;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1",r.ECDSA="ECDSA"})(N||(N={}));var Rt;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1",r[r.ECDSA=3]="ECDSA"})(Rt||(Rt={}));(function(r){r.codec=()=>Ee(Rt)})(N||(N={}));var Ut;(function(r){let t;r.codec=()=>(t==null&&(t=It((e,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),e.Type!=null&&Rt[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)},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let o=e.uint32();switch(o>>>3){case 1:i.Type=N.codec().decode(e);break;case 2:i.Data=e.bytes();break;default:e.skipType(o&7);break}}return i})),t),r.encode=e=>Lt(e,r.codec()),r.decode=e=>At(e,r.codec())})(Ut||(Ut={}));var zn="/plaintext/2.0.0",Ae=class{protocol=zn;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),s=Ye(e).pb(Nt),o=N.RSA;t.type==="Ed25519"?o=N.Ed25519:t.type==="secp256k1"&&(o=N.Secp256k1),this.log("write pubkey exchange to peer %p",n);let[,a]=await Promise.all([s.write({id:t.toBytes(),pubkey:{Type:o,Data:t.publicKey??new Uint8Array(0)}},{signal:i}),s.read({signal:i})]),h;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(h=await $e(a.pubkey.Data),!h.equals(Yt(a.id)))throw new Error("Public key did not match id")}catch(d){throw this.log.error(d),new mt("Remote did not provide its public key")}if(n!=null&&!h.equals(n))throw new pt;return this.log("plaintext key exchange completed successfully with peer %p",h),{conn:s.unwrap().unwrap(),remotePeer:h}}};function Gn(r){return t=>new Ae(t,r)}return wr(qn);})();
|
|
2
|
+
"use strict";var Libp2PPlaintext=(()=>{var Ft=Object.defineProperty;var dr=Object.getOwnPropertyDescriptor;var pr=Object.getOwnPropertyNames;var mr=Object.prototype.hasOwnProperty;var y=(r,t)=>{for(var e in t)Ft(r,e,{get:t[e],enumerable:!0})},wr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of pr(t))!mr.call(r,i)&&i!==e&&Ft(r,i,{get:()=>t[i],enumerable:!(n=dr(t,i))||n.enumerable});return r};var gr=r=>wr(Ft({},"__esModule",{value:!0}),r);var $n={};y($n,{plaintext:()=>qn});var Se=Symbol.for("@libp2p/peer-id");var pt=class r extends Error{code;constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError",this.code=r.code}static code="ERR_UNEXPECTED_PEER"},mt=class r extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError",this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Le=Symbol.for("@libp2p/service-capabilities"),Hn=Symbol.for("@libp2p/service-dependencies");var kt={};y(kt,{base58btc:()=>E,base58flickr:()=>Sr});var bi=new Uint8Array(0);function De(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 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")}function Ie(r){return new TextEncoder().encode(r)}function Ne(r){return new TextDecoder().decode(r)}function br(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),d=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function u(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var b=0,P=0,L=0,R=f.length;L!==R&&f[L]===0;)L++,b++;for(var U=(R-L)*l+1>>>0,S=new Uint8Array(U);L!==R;){for(var F=f[L],V=0,D=U-1;(F!==0||V<P)&&D!==-1;D--,V++)F+=256*S[D]>>>0,S[D]=F%a>>>0,F=F/a>>>0;if(F!==0)throw new Error("Non-zero carry");P=V,L++}for(var C=U-P;C!==U&&S[C]===0;)C++;for(var dt=c.repeat(b);C<U;++C)dt+=r.charAt(S[C]);return dt}function g(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var b=0;if(f[b]!==" "){for(var P=0,L=0;f[b]===c;)P++,b++;for(var R=(f.length-b)*d+1>>>0,U=new Uint8Array(R);f[b];){var S=e[f.charCodeAt(b)];if(S===255)return;for(var F=0,V=R-1;(S!==0||F<L)&&V!==-1;V--,F++)S+=a*U[V]>>>0,U[V]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");L=F,b++}if(f[b]!==" "){for(var D=R-L;D!==R&&U[D]===0;)D++;for(var C=new Uint8Array(P+(R-D)),dt=P;D!==R;)C[dt++]=U[D++];return C}}}function lt(f){var b=g(f);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:g,decode:lt}}var xr=br,yr=xr,Ue=yr;var Bt=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")}},Ct=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 Fe(this,t)}},vt=class{decoders;constructor(t){this.decoders=t}or(t){return Fe(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 Fe(r,t){return new vt({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Tt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new Bt(t,e,n),this.decoder=new Ct(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function $({name:r,prefix:t,encode:e,decode:n}){return new Tt(r,t,e,n)}function _({name:r,prefix:t,alphabet:e}){let{encode:n,decode:i}=Ue(e,r);return $({prefix:t,name:r,encode:n,decode:o=>v(i(o))})}function Er(r,t,e,n){let i={};for(let l=0;l<t.length;++l)i[t[l]]=l;let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),a=0,c=0,d=0;for(let l=0;l<o;++l){let u=i[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,a+=e,a>=8&&(a-=8,s[d++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s}function Ar(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!==0&&(o+=t[i&a<<e-s]),n)for(;o.length*e&7;)o+="=";return o}function p({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return $({prefix:t,name:r,encode(i){return Ar(i,n,e)},decode(i){return Er(i,n,e,r)}})}var E=_({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Sr=_({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Mt={};y(Mt,{base10:()=>Lr});var Lr=_({prefix:"9",name:"base10",alphabet:"0123456789"});var Vt={};y(Vt,{base16:()=>Dr,base16upper:()=>Ir});var Dr=p({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ir=p({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var _t={};y(_t,{base2:()=>Nr});var Nr=p({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ot={};y(Ot,{base256emoji:()=>Cr});var Be=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}"),Rr=Be.reduce((r,t,e)=>(r[e]=t,r),[]),Ur=Be.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Fr(r){return r.reduce((t,e)=>(t+=Rr[e],t),"")}function Br(r){let t=[];for(let e of r){let n=Ur[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var Cr=$({prefix:"\u{1F680}",name:"base256emoji",encode:Fr,decode:Br});var Pt={};y(Pt,{base32:()=>j,base32hex:()=>Mr,base32hexpad:()=>_r,base32hexpadupper:()=>Or,base32hexupper:()=>Vr,base32pad:()=>Tr,base32padupper:()=>kr,base32upper:()=>vr,base32z:()=>Pr});var j=p({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),vr=p({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Tr=p({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kr=p({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Mr=p({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Vr=p({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),_r=p({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Or=p({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Pr=p({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var zt={};y(zt,{base36:()=>zr,base36upper:()=>Gr});var zr=_({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Gr=_({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Gt={};y(Gt,{base64:()=>qr,base64pad:()=>$r,base64url:()=>jr,base64urlpad:()=>Wr});var qr=p({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),$r=p({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),jr=p({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Wr=p({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var qt={};y(qt,{base8:()=>Xr});var Xr=p({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $t={};y($t,{identity:()=>Hr});var Hr=$({prefix:"\0",name:"identity",encode:r=>Ne(r),decode:r=>Ie(r)});var Ti=new TextEncoder,ki=new TextDecoder;var Wt={};y(Wt,{identity:()=>K});var Qr=Te,Ce=128,Zr=127,Yr=~Zr,tn=Math.pow(2,31);function Te(r,t,e){t=t||[],e=e||0;for(var n=e;r>=tn;)t[e++]=r&255|Ce,r/=128;for(;r&Yr;)t[e++]=r&255|Ce,r>>>=7;return t[e]=r|0,Te.bytes=e-n+1,t}var en=jt,rn=128,ve=127;function jt(r,n){var e=0,n=n||0,i=0,o=n,s,a=r.length;do{if(o>=a)throw jt.bytes=0,new RangeError("Could not decode varint");s=r[o++],e+=i<28?(s&ve)<<i:(s&ve)*Math.pow(2,i),i+=7}while(s>=rn);return jt.bytes=o-n,e}var nn=Math.pow(2,7),on=Math.pow(2,14),sn=Math.pow(2,21),an=Math.pow(2,28),cn=Math.pow(2,35),hn=Math.pow(2,42),un=Math.pow(2,49),fn=Math.pow(2,56),ln=Math.pow(2,63),dn=function(r){return r<nn?1:r<on?2:r<sn?3:r<an?4:r<cn?5:r<hn?6:r<un?7:r<fn?8:r<ln?9:10},pn={encode:Qr,decode:en,encodingLength:dn},mn=pn,nt=mn;function it(r,t=0){return[nt.decode(r,t),nt.decode.bytes]}function W(r,t,e=0){return nt.encode(r,t,e),t}function X(r){return nt.encodingLength(r)}function B(r,t){let e=t.byteLength,n=X(r),i=n+X(e),o=new Uint8Array(i+e);return W(r,o,0),W(e,o,n),o.set(t,i),new H(r,e,t,o)}function ot(r){let t=v(r),[e,n]=it(t),[i,o]=it(t.subarray(n)),s=t.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new H(e,i,s,t)}function ke(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&De(r.bytes,e.bytes)}}var H=class{code;size;digest;bytes;constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};var Me=0,wn="identity",Ve=v;function gn(r){return B(Me,Ve(r))}var K={code:Me,name:wn,encode:Ve,digest:gn};var Jt={};y(Jt,{sha256:()=>st,sha512:()=>bn});function Ht({name:r,code:t,encode:e}){return new Xt(r,t,e)}var Xt=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?B(this.code,e):e.then(n=>B(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Oe(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var st=Ht({name:"sha2-256",code:18,encode:Oe("SHA-256")}),bn=Ht({name:"sha2-512",code:19,encode:Oe("SHA-512")});function Pe(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return yn(e,Kt(r),t??E.encoder);default:return En(e,Kt(r),t??j.encoder)}}var ze=new WeakMap;function Kt(r){let t=ze.get(r);if(t==null){let e=new Map;return ze.set(r,e),e}return t}var z=class r{code;version;multihash;bytes;"/";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!==at)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==An)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!=null&&t.code===n.code&&t.version===n.version&&ke(t.multihash,n.multihash)}toString(t){return Pe(this,t)}toJSON(){return{"/":Pe(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:i,multihash:o,bytes:s}=e;return new r(n,i,o,s??Ge(n,i,o.bytes))}else if(e[Sn]===!0){let{version:n,multihash:i,code:o}=e,s=ot(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!==at)throw new Error(`Version 0 CID must use dag-pb (code: ${at}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=Ge(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,at,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,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 H(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,g]=it(t.subarray(e));return e+=g,u},i=n(),o=at;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(),d=e+c,l=d-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:d}}static parse(t,e){let[n,i]=xn(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 Kt(o).set(n,t),o}};function xn(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)]}}}function yn(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}function En(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}var at=112,An=18;function Ge(r,t,e){let n=X(r),i=n+X(t),o=new Uint8Array(i+e.byteLength);return W(r,o,0),W(t,o,n),o.set(e,i),o}var Sn=Symbol.for("@ipld/js-cid/CID");var Q={...$t,..._t,...qt,...Mt,...Vt,...Pt,...zt,...kt,...Gt,...Ot},ro={...Jt,...Wt};function ct(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 Ln=Symbol.for("nodejs.util.inspect.custom"),qe=Object.values(Q).map(r=>r.decoder).reduce((r,t)=>r.or(t),Q.identity.decoder),$e=114,Qt=36,Zt=37,ht=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()})`}[Se]=!0;toString(){return this.string==null&&(this.string=E.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return z.createV1($e,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ct(this.multihash.bytes,t);if(typeof t=="string")return Dn(t).equals(this);if(t?.multihash?.bytes!=null)return ct(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[Ln](){return`PeerId(${this.toString()})`}},Z=class extends ht{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Y=class extends ht{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},tt=class extends ht{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function Dn(r,t){if(t=t??qe,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=ot(E.decode(`z${r}`));return r.startsWith("12D")?new Y({multihash:e}):r.startsWith("16U")?new tt({multihash:e}):new Z({multihash:e})}return Yt(qe.decode(r))}function Yt(r){try{let t=ot(r);if(t.code===K.code){if(t.digest.length===Qt)return new Y({multihash:t});if(t.digest.length===Zt)return new tt({multihash:t})}if(t.code===st.code)return new Z({multihash:t})}catch{return In(z.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function In(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==$e)throw new Error("Supplied PeerID CID is invalid");let t=r.multihash;if(t.code===st.code)return new Z({multihash:r.multihash});if(t.code===K.code){if(t.digest.length===Qt)return new Y({multihash:r.multihash});if(t.digest.length===Zt)return new tt({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function je(r,t){return r.length===Qt?new Y({multihash:B(K.code,r),privateKey:t}):r.length===Zt?new tt({multihash:B(K.code,r),privateKey:t}):new Z({multihash:await st.digest(r),publicKey:r,privateKey:t})}function et(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var gt=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 We(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new gt(e?.errorMessage,e?.errorCode));let n,i=new gt(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 te=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=et(),this.haveNext=et()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=et(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),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");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=et(),await We(this.readNext.promise,e?.signal,e)}};function Xe(){return new te}function T(r=0){return new Uint8Array(r)}function x(r=0){return new Uint8Array(r)}function ee(r,t){t==null&&(t=r.reduce((i,o)=>i+o.length,0));let e=x(t),n=0;for(let i of r)e.set(i,n),n+=i.length;return e}var Je=Symbol.for("@achingbrain/uint8arraylist");function He(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 bt(r){return!!r?.[Je]}var k=class r{bufs;length;[Je]=!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(bt(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(bt(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=He(this.bufs,t);return e.buf[e.index]}set(t,e){let n=He(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(bt(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 ee(n,i)}subarray(t,e){let{bufs:n,length:i}=this._subList(t,e);return n.length===1?n[0]:ee(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 d=t>=a&&t<c,l=e>a&&e<=c;if(d&&l){if(t===a&&e===c){n.push(s);break}let u=t-a;n.push(s.subarray(u,u+(e-t)));break}if(d){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(l){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(!bt(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,d=n.byteLength-1,l;for(let u=e;u<=c;u+=l){l=0;for(let g=d;g>=0;g--){let lt=this.get(u+g);if(n[g]!==lt){l=Math.max(1,g-a[lt]);break}}if(l===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=x(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=T(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=T(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=T(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=x(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=T(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=T(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=T(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=T(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=T(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(!ct(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}};var xt=class extends Error{code;constructor(t,e){super(t),this.code=e}},re=class extends xt{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function Ke(r,t){let e=Xe();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 k;return{read:async(s,a)=>{a?.signal?.throwIfAborted();let c,d=new Promise((l,u)=>{c=()=>{u(new re("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(s==null){let{done:u,value:g}=await Promise.race([n.next(),d]);return u===!0?new k:g}for(;i.byteLength<s;){let{value:u,done:g}=await Promise.race([n.next(),d]);if(g===!0)throw new xt("unexpected end of input","ERR_UNEXPECTED_EOF");i.append(u)}let l=i.sublist(0,s);return i.consume(s),l}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}}}var Nn=Math.pow(2,7),Rn=Math.pow(2,14),Un=Math.pow(2,21),ne=Math.pow(2,28),ie=Math.pow(2,35),oe=Math.pow(2,42),se=Math.pow(2,49),h=128,m=127;function M(r){if(r<Nn)return 1;if(r<Rn)return 2;if(r<Un)return 3;if(r<ne)return 4;if(r<ie)return 5;if(r<oe)return 6;if(r<se)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ae(r,t,e=0){switch(M(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 Fn(r,t,e=0){switch(M(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 ce(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)*ne,e<h)||(e=r[t+5],n+=(e&m)*ie,e<h)||(e=r[t+6],n+=(e&m)*oe,e<h)||(e=r[t+7],n+=(e&m)*se,e<h))return n;throw new RangeError("Could not decode varint")}function Bn(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)*ne,e<h)||(e=r.get(t+5),n+=(e&m)*ie,e<h)||(e=r.get(t+6),n+=(e&m)*oe,e<h)||(e=r.get(t+7),n+=(e&m)*se,e<h))return n;throw new RangeError("Could not decode varint")}function Qe(r,t,e=0){return t==null&&(t=x(M(r))),t instanceof Uint8Array?ae(r,t,e):Fn(r,t,e)}function Ze(r,t=0){return r instanceof Uint8Array?ce(r,t):Bn(r,t)}var yt=class extends Error{code;constructor(t,e){super(t),this.code=e}};function Ye(r,t={}){let e=Ke(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=M(t.maxDataLength));let n=t?.lengthDecoder??Ze,i=t?.lengthEncoder??Qe;return{read:async s=>{let a=-1,c=new k;for(;;){c.append(await e.read(1,s));try{a=n(c)}catch(d){if(d instanceof RangeError)continue;throw d}if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new yt("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new yt("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(a,s)},write:async(s,a)=>{await e.write(new k(i(s.byteLength),s),a)},writeV:async(s,a)=>{let c=new k(...s.flatMap(d=>[i(d.byteLength),d]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function tr(r,t){let e=Ye(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 he=new Float32Array([-0]),O=new Uint8Array(he.buffer);function er(r,t,e){he[0]=r,t[e]=O[0],t[e+1]=O[1],t[e+2]=O[2],t[e+3]=O[3]}function rr(r,t){return O[0]=r[t],O[1]=r[t+1],O[2]=r[t+2],O[3]=r[t+3],he[0]}var ue=new Float64Array([-0]),w=new Uint8Array(ue.buffer);function nr(r,t,e){ue[0]=r,t[e]=w[0],t[e+1]=w[1],t[e+2]=w[2],t[e+3]=w[3],t[e+4]=w[4],t[e+5]=w[5],t[e+6]=w[6],t[e+7]=w[7]}function ir(r,t){return w[0]=r[t],w[1]=r[t+1],w[2]=r[t+2],w[3]=r[t+3],w[4]=r[t+4],w[5]=r[t+5],w[6]=r[t+6],w[7]=r[t+7],ue[0]}var vn=BigInt(Number.MAX_SAFE_INTEGER),Tn=BigInt(Number.MIN_SAFE_INTEGER),A=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 G;if(t<vn&&t>Tn)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>or&&(i=0n,++n>or&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(t){if(t===0)return G;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):G}},G=new A(0,0);G.toBigInt=function(){return 0n};G.zzEncode=G.zzDecode=function(){return this};G.length=function(){return 1};var or=4294967296n;function sr(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 ar(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 fe(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 I(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Et(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,I(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 I(this,4);return Et(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw I(this,4);return Et(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw I(this,4);let t=rr(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw I(this,4);let t=ir(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 I(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ar(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw I(this,t);this.pos+=t}else do if(this.pos>=this.len)throw I(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 A(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 I(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 I(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 I(this,8);let t=Et(this.buf,this.pos+=4),e=Et(this.buf,this.pos+=4);return new A(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ce(this.buf,this.pos);return this.pos+=M(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function de(r){return new le(r instanceof Uint8Array?r:r.subarray())}function At(r,t,e){let n=de(r);return t.decode(n,void 0,e)}function ur(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var hr=ur("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),pe=ur("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=x(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),kn={utf8:hr,"utf-8":hr,hex:Q.base16,latin1:pe,ascii:pe,binary:pe,...Q},fr=kn;function lr(r,t="utf8"){let e=fr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function me(r){let t=r??8192,e=t>>>1,n,i=t;return function(s){if(s<1||s>e)return x(s);i+s>t&&(n=x(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 we(){}var be=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Mn=me();function Vn(r){return globalThis.Buffer!=null?x(r):Mn(r)}var ft=class{len;head;tail;states;constructor(){this.len=0,this.head=new q(we,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 xe((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(St,10,A.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=A.fromBigInt(t);return this._push(St,e.length(),e)}uint64Number(t){return this._push(ae,M(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=A.fromBigInt(t).zzEncode();return this._push(St,e.length(),e)}sint64Number(t){let e=A.fromNumber(t).zzEncode();return this._push(St,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ge,1,t?1:0)}fixed32(t){return this._push(ut,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=A.fromBigInt(t);return this._push(ut,4,e.lo)._push(ut,4,e.hi)}fixed64Number(t){let e=A.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(er,4,t)}double(t){return this._push(nr,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ge,1,0):this.uint32(e)._push(On,e,t)}string(t){let e=sr(t);return e!==0?this.uint32(e)._push(fe,e,t):this._push(ge,1,0)}fork(){return this.states=new be(this),this.head=this.tail=new q(we,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(we,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=Vn(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ge(r,t,e){t[e]=r&255}function _n(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var xe=class extends q{next;constructor(t,e){super(_n,t,e),this.next=void 0}};function St(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 On(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(ft.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Pn,t,r),this},ft.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(zn,t,r),this});function Pn(r,t,e){t.set(r,e)}function zn(r,t,e){r.length<40?fe(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(lr(r),e)}function ye(){return new ft}function Lt(r,t){let e=ye();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var rt;(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"})(rt||(rt={}));function Dt(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ee(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 Dt("enum",rt.VARINT,e,n)}function It(r,t){return Dt("message",rt.LENGTH_DELIMITED,r,t)}var Nt;(function(r){let t;r.codec=()=>(t==null&&(t=It((e,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),e.id!=null&&(n.uint32(10),n.bytes(e.id)),e.pubkey!=null&&(n.uint32(18),Ut.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=Ut.codec().decode(e,e.uint32());break;default:e.skipType(s&7);break}}return i})),t),r.encode=e=>Lt(e,r.codec()),r.decode=e=>At(e,r.codec())})(Nt||(Nt={}));var N;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1",r.ECDSA="ECDSA"})(N||(N={}));var Rt;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1",r[r.ECDSA=3]="ECDSA"})(Rt||(Rt={}));(function(r){r.codec=()=>Ee(Rt)})(N||(N={}));var Ut;(function(r){let t;r.codec=()=>(t==null&&(t=It((e,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),e.Type!=null&&Rt[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=>Lt(e,r.codec()),r.decode=e=>At(e,r.codec())})(Ut||(Ut={}));var Gn="/plaintext/2.0.0",Ae=class{protocol=Gn;log;timeout;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:plaintext"),this.timeout=e.timeout??1e3}[Symbol.toStringTag]="@libp2p/plaintext";[Le]=["@libp2p/connection-encryption"];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=tr(e).pb(Nt),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 je(a.pubkey.Data),!c.equals(Yt(a.id)))throw new Error("Public key did not match id")}catch(d){throw this.log.error(d),new mt("Remote did not provide its public key")}if(n!=null&&!c.equals(n))throw new pt;return this.log("plaintext key exchange completed successfully with peer %p",c),{conn:o.unwrap().unwrap(),remotePeer:c}}};function qn(r){return t=>new Ae(t,r)}return gr($n);})();
|
|
3
3
|
return Libp2PPlaintext}));
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,OAAO,KAAK,EAAE,eAAe,EAA+B,mBAAmB,EAA6B,MAAM,mBAAmB,CAAA;AAMrI,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,OAAO,KAAK,EAAE,eAAe,EAA+B,mBAAmB,EAA6B,MAAM,mBAAmB,CAAA;AAMrI,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAmGD,wBAAgB,SAAS,CAAE,IAAI,CAAC,EAAE,aAAa,GAAG,CAAC,UAAU,EAAE,mBAAmB,KAAK,mBAAmB,CAEzG"}
|
package/dist/src/index.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* })
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
import { UnexpectedPeerError, InvalidCryptoExchangeError } from '@libp2p/interface';
|
|
22
|
+
import { UnexpectedPeerError, InvalidCryptoExchangeError, serviceCapabilities } from '@libp2p/interface';
|
|
23
23
|
import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id';
|
|
24
24
|
import { pbStream } from 'it-protobuf-stream';
|
|
25
25
|
import { Exchange, KeyType } from './pb/proto.js';
|
|
@@ -32,6 +32,10 @@ class Plaintext {
|
|
|
32
32
|
this.log = components.logger.forComponent('libp2p:plaintext');
|
|
33
33
|
this.timeout = init.timeout ?? 1000;
|
|
34
34
|
}
|
|
35
|
+
[Symbol.toStringTag] = '@libp2p/plaintext';
|
|
36
|
+
[serviceCapabilities] = [
|
|
37
|
+
'@libp2p/connection-encryption'
|
|
38
|
+
];
|
|
35
39
|
async secureInbound(localId, conn, remoteId) {
|
|
36
40
|
return this._encrypt(localId, conn, remoteId);
|
|
37
41
|
}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACxG,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAKjD,MAAM,QAAQ,GAAG,kBAAkB,CAAA;AAcnC,MAAM,SAAS;IACN,QAAQ,GAAW,QAAQ,CAAA;IACjB,GAAG,CAAQ;IACX,OAAO,CAAQ;IAEhC,YAAa,UAA+B,EAAE,OAAsB,EAAE;QACpE,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAA;QAC7D,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAA;IACrC,CAAC;IAEQ,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,mBAAmB,CAAA;IAE1C,CAAC,mBAAmB,CAAC,GAAa;QACzC,+BAA+B;KAChC,CAAA;IAED,KAAK,CAAC,aAAa,CAA6F,OAAe,EAAE,IAAY,EAAE,QAAiB;QAC9J,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;IAC/C,CAAC;IAED,KAAK,CAAC,cAAc,CAA6F,OAAe,EAAE,IAAY,EAAE,QAAiB;QAC/J,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;IAC/C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CAA6F,OAAe,EAAE,IAAY,EAAE,QAAiB;QACzJ,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAChD,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAA;QAEtC,IAAI,IAAI,GAAG,OAAO,CAAC,GAAG,CAAA;QAEtB,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,GAAG,OAAO,CAAC,OAAO,CAAA;QACxB,CAAC;aAAM,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACxC,IAAI,GAAG,OAAO,CAAC,SAAS,CAAA;QAC1B,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,kCAAkC,EAAE,QAAQ,CAAC,CAAA;QAEtD,MAAM,CACJ,AADK,EACH,QAAQ,CACX,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACpB,wDAAwD;YACxD,EAAE,CAAC,KAAK,CAAC;gBACP,EAAE,EAAE,OAAO,CAAC,OAAO,EAAE;gBACrB,MAAM,EAAE;oBACN,IAAI,EAAE,IAAI;oBACV,IAAI,EAAE,OAAO,CAAC,SAAS,IAAI,IAAI,UAAU,CAAC,CAAC,CAAC;iBAC7C;aACF,EAAE;gBACD,MAAM;aACP,CAAC;YACF,2BAA2B;YAC3B,EAAE,CAAC,IAAI,CAAC;gBACN,MAAM;aACP,CAAC;SACH,CAAC,CAAA;QAEF,IAAI,MAAM,CAAA;QACV,IAAI,CAAC;YACH,IAAI,QAAQ,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;YACvC,CAAC;YAED,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACtC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;YAC9C,CAAC;YAED,IAAI,QAAQ,CAAC,EAAE,IAAI,IAAI,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;YACtC,CAAC;YAED,MAAM,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAEnD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;gBACjD,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;YAChD,CAAC;QACH,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACnB,MAAM,IAAI,0BAA0B,CAAC,uCAAuC,CAAC,CAAA;QAC/E,CAAC;QAED,IAAI,QAAQ,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YACjD,MAAM,IAAI,mBAAmB,EAAE,CAAA;QACjC,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,4DAA4D,EAAE,MAAM,CAAC,CAAA;QAE9E,OAAO;YACL,IAAI,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE;YAC1B,UAAU,EAAE,MAAM;SACnB,CAAA;IACH,CAAC;CACF;AAED,MAAM,UAAU,SAAS,CAAE,IAAoB;IAC7C,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACxD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/plaintext",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0-3b9cbf7d8",
|
|
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",
|
|
@@ -52,17 +52,17 @@
|
|
|
52
52
|
"doc-check": "aegir doc-check"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@libp2p/interface": "
|
|
56
|
-
"@libp2p/peer-id": "
|
|
55
|
+
"@libp2p/interface": "1.5.0-3b9cbf7d8",
|
|
56
|
+
"@libp2p/peer-id": "4.1.4-3b9cbf7d8",
|
|
57
57
|
"it-protobuf-stream": "^1.1.3",
|
|
58
58
|
"it-stream-types": "^2.0.1",
|
|
59
59
|
"protons-runtime": "^5.4.0",
|
|
60
60
|
"uint8arraylist": "^2.4.8"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@libp2p/interface-compliance-tests": "
|
|
64
|
-
"@libp2p/logger": "
|
|
65
|
-
"@libp2p/peer-id-factory": "
|
|
63
|
+
"@libp2p/interface-compliance-tests": "5.4.7-3b9cbf7d8",
|
|
64
|
+
"@libp2p/logger": "4.0.15-3b9cbf7d8",
|
|
65
|
+
"@libp2p/peer-id-factory": "4.1.4-3b9cbf7d8",
|
|
66
66
|
"@multiformats/multiaddr": "^12.2.3",
|
|
67
67
|
"aegir": "^43.0.1",
|
|
68
68
|
"protons": "^7.5.0",
|
package/src/index.ts
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
import { UnexpectedPeerError, InvalidCryptoExchangeError } from '@libp2p/interface'
|
|
23
|
+
import { UnexpectedPeerError, InvalidCryptoExchangeError, serviceCapabilities } from '@libp2p/interface'
|
|
24
24
|
import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id'
|
|
25
25
|
import { pbStream } from 'it-protobuf-stream'
|
|
26
26
|
import { Exchange, KeyType } from './pb/proto.js'
|
|
@@ -52,6 +52,12 @@ class Plaintext implements ConnectionEncrypter {
|
|
|
52
52
|
this.timeout = init.timeout ?? 1000
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
readonly [Symbol.toStringTag] = '@libp2p/plaintext'
|
|
56
|
+
|
|
57
|
+
readonly [serviceCapabilities]: string[] = [
|
|
58
|
+
'@libp2p/connection-encryption'
|
|
59
|
+
]
|
|
60
|
+
|
|
55
61
|
async secureInbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (localId: PeerId, conn: Stream, remoteId?: PeerId): Promise<SecuredConnection<Stream>> {
|
|
56
62
|
return this._encrypt(localId, conn, remoteId)
|
|
57
63
|
}
|
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
|
-
}
|