@libp2p/plaintext 0.0.0-d729d66a5 → 0.0.0-e2267d437
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 +8 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +21 -29
- package/dist/src/index.js.map +1 -1
- package/dist/src/pb/proto.js.map +1 -1
- package/package.json +7 -9
- package/src/index.ts +39 -45
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 Er=Object.create;var Et=Object.defineProperty;var Ar=Object.getOwnPropertyDescriptor;var Lr=Object.getOwnPropertyNames;var Dr=Object.getPrototypeOf,Sr=Object.prototype.hasOwnProperty;var Ir=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),I=(r,t)=>{for(var e in t)Et(r,e,{get:t[e],enumerable:!0})},Ne=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Lr(t))!Sr.call(r,i)&&i!==e&&Et(r,i,{get:()=>t[i],enumerable:!(n=Ar(t,i))||n.enumerable});return r};var Nr=(r,t,e)=>(e=r!=null?Er(Dr(r)):{},Ne(t||!r||!r.__esModule?Et(e,"default",{value:r,enumerable:!0}):e,r)),Ur=r=>Ne(Et({},"__esModule",{value:!0}),r);var or=Ir((Cs,sr)=>{"use strict";function ir(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Hn(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return ir(r,e)}catch{e.message=r.message,e.stack=r.stack;let i=function(){};return i.prototype=Object.create(Object.getPrototypeOf(r)),ir(new i,e)}}sr.exports=Hn});var fi={};I(fi,{plaintext:()=>ui});var At=class r extends Error{code;constructor(t="Unexpected Peer"){super(t),this.code=r.code}static code="ERR_UNEXPECTED_PEER"},Lt=class r extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Ue=Symbol.for("@libp2p/peer-id");var Pt={};I(Pt,{base58btc:()=>N,base58flickr:()=>Cr});function Rr(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),u=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function d(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var b=0,c=0,g=0,A=l.length;g!==A&&l[g]===0;)g++,b++;for(var w=(A-g)*p+1>>>0,S=new Uint8Array(w);g!==A;){for(var U=l[g],M=0,R=w-1;(U!==0||M<c)&&R!==-1;R--,M++)U+=256*S[R]>>>0,S[R]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");c=M,g++}for(var C=w-c;C!==w&&S[C]===0;)C++;for(var xt=h.repeat(b);C<w;++C)xt+=r.charAt(S[C]);return xt}function L(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var b=0;if(l[b]!==" "){for(var c=0,g=0;l[b]===h;)c++,b++;for(var A=(l.length-b)*u+1>>>0,w=new Uint8Array(A);l[b];){var S=e[l.charCodeAt(b)];if(S===255)return;for(var U=0,M=A-1;(S!==0||U<g)&&M!==-1;M--,U++)S+=a*w[M]>>>0,w[M]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");g=U,b++}if(l[b]!==" "){for(var R=A-g;R!==A&&w[R]===0;)R++;for(var C=new Uint8Array(c+(A-R)),xt=c;R!==A;)C[xt++]=w[R++];return C}}}function H(l){var b=L(l);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:d,decodeUnsafe:L,decode:H}}var Br=Rr,Tr=Br,Re=Tr;var bi=new Uint8Array(0);var Be=(r,t)=>{if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0},v=r=>{if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")};var Te=r=>new TextEncoder().encode(r),Fe=r=>new TextDecoder().decode(r);var Mt=class{constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Ot=class{constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ce(this,t)}},Vt=class{constructor(t){this.decoders=t}or(t){return Ce(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Ce=(r,t)=>new Vt({...r.decoders||{[r.prefix]:r},...t.decoders||{[t.prefix]:t}}),zt=class{constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new Mt(t,e,n),this.decoder=new Ot(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},X=({name:r,prefix:t,encode:e,decode:n})=>new zt(r,t,e,n),O=({prefix:r,name:t,alphabet:e})=>{let{encode:n,decode:i}=Re(e,t);return X({prefix:r,name:t,encode:n,decode:s=>v(i(s))})},Fr=(r,t,e,n)=>{let i={};for(let p=0;p<t.length;++p)i[t[p]]=p;let s=r.length;for(;r[s-1]==="=";)--s;let o=new Uint8Array(s*e/8|0),a=0,h=0,u=0;for(let p=0;p<s;++p){let d=i[r[p]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<e|d,a+=e,a>=8&&(a-=8,o[u++]=255&h>>a)}if(a>=e||255&h<<8-a)throw new SyntaxError("Unexpected end of data");return o},kr=(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&&(s+=t[i&a<<e-o]),n)for(;s.length*e&7;)s+="=";return s},m=({name:r,prefix:t,bitsPerChar:e,alphabet:n})=>X({prefix:t,name:r,encode(i){return kr(i,n,e)},decode(i){return Fr(i,n,e,r)}});var N=O({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Cr=O({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Gt={};I(Gt,{base10:()=>vr});var vr=O({prefix:"9",name:"base10",alphabet:"0123456789"});var $t={};I($t,{base16:()=>_r,base16upper:()=>Mr});var _r=m({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Mr=m({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var qt={};I(qt,{base2:()=>Or});var Or=m({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var jt={};I(jt,{base256emoji:()=>$r});var ve=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}"),Vr=ve.reduce((r,t,e)=>(r[e]=t,r),[]),zr=ve.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Pr(r){return r.reduce((t,e)=>(t+=Vr[e],t),"")}function Gr(r){let t=[];for(let e of r){let n=zr[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var $r=X({prefix:"\u{1F680}",name:"base256emoji",encode:Pr,decode:Gr});var Ht={};I(Ht,{base32:()=>J,base32hex:()=>Xr,base32hexpad:()=>Wr,base32hexpadupper:()=>Qr,base32hexupper:()=>Jr,base32pad:()=>jr,base32padupper:()=>Hr,base32upper:()=>qr,base32z:()=>Kr});var J=m({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qr=m({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jr=m({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Hr=m({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Xr=m({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Jr=m({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wr=m({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Qr=m({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Kr=m({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Xt={};I(Xt,{base36:()=>Zr,base36upper:()=>Yr});var Zr=O({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Yr=O({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Jt={};I(Jt,{base64:()=>tn,base64pad:()=>en,base64url:()=>rn,base64urlpad:()=>nn});var tn=m({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),en=m({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),rn=m({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),nn=m({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Wt={};I(Wt,{base8:()=>sn});var sn=m({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Qt={};I(Qt,{identity:()=>on});var on=X({prefix:"\0",name:"identity",encode:r=>Fe(r),decode:r=>Te(r)});var Ti=new TextEncoder,Fi=new TextDecoder;var Zt={};I(Zt,{identity:()=>Y});var cn=Oe,_e=128,un=127,fn=~un,ln=Math.pow(2,31);function Oe(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ln;)t[e++]=r&255|_e,r/=128;for(;r&fn;)t[e++]=r&255|_e,r>>>=7;return t[e]=r|0,Oe.bytes=e-n+1,t}var dn=Kt,pn=128,Me=127;function Kt(r,n){var e=0,n=n||0,i=0,s=n,o,a=r.length;do{if(s>=a)throw Kt.bytes=0,new RangeError("Could not decode varint");o=r[s++],e+=i<28?(o&Me)<<i:(o&Me)*Math.pow(2,i),i+=7}while(o>=pn);return Kt.bytes=s-n,e}var mn=Math.pow(2,7),bn=Math.pow(2,14),gn=Math.pow(2,21),wn=Math.pow(2,28),yn=Math.pow(2,35),xn=Math.pow(2,42),En=Math.pow(2,49),An=Math.pow(2,56),Ln=Math.pow(2,63),Dn=function(r){return r<mn?1:r<bn?2:r<gn?3:r<wn?4:r<yn?5:r<xn?6:r<En?7:r<An?8:r<Ln?9:10},Sn={encode:cn,decode:dn,encodingLength:Dn},In=Sn,ht=In;var ct=(r,t=0)=>[ht.decode(r,t),ht.decode.bytes],W=(r,t,e=0)=>(ht.encode(r,t,e),t),Q=r=>ht.encodingLength(r);var F=(r,t)=>{let e=t.byteLength,n=Q(r),i=n+Q(e),s=new Uint8Array(i+e);return W(r,s,0),W(e,s,n),s.set(t,i),new K(r,e,t,s)},ut=r=>{let t=v(r),[e,n]=ct(t),[i,s]=ct(t.subarray(n)),o=t.subarray(n+s);if(o.byteLength!==i)throw new Error("Incorrect length");return new K(e,i,o,t)},Ve=(r,t)=>{if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Be(r.bytes,e.bytes)}},K=class{constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};var ze=0,Nn="identity",Pe=v,Un=r=>F(ze,Pe(r)),Y={code:ze,name:Nn,encode:Pe,digest:Un};var ee={};I(ee,{sha256:()=>ft,sha512:()=>Rn});var te=({name:r,code:t,encode:e})=>new Yt(r,t,e),Yt=class{constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?F(this.code,e):e.then(n=>F(this.code,n))}else throw Error("Unknown type, must be binary type")}};var $e=r=>async t=>new Uint8Array(await crypto.subtle.digest(r,t)),ft=te({name:"sha2-256",code:18,encode:$e("SHA-256")}),Rn=te({name:"sha2-512",code:19,encode:$e("SHA-512")});var qe=(r,t)=>{let{bytes:e,version:n}=r;switch(n){case 0:return Tn(e,re(r),t||N.encoder);default:return Fn(e,re(r),t||J.encoder)}};var je=new WeakMap,re=r=>{let t=je.get(r);if(t==null){let e=new Map;return je.set(r,e),e}return t},z=class r{constructor(t,e,n,i){this.code=e,this.version=t,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==lt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==kn)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=F(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n&&t.code===n.code&&t.version===n.version&&Ve(t.multihash,n.multihash)}toString(t){return qe(this,t)}toJSON(){return{"/":qe(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:i,multihash:s,bytes:o}=e;return new r(n,i,s,o||He(n,i,s.bytes))}else if(e[Cn]===!0){let{version:n,multihash:i,code:s}=e,o=ut(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!==lt)throw new Error(`Version 0 CID must use dag-pb (code: ${lt}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=He(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,lt,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,i=v(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=i.subarray(e.multihashSize-e.digestSize),o=new K(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[d,L]=ct(t.subarray(e));return e+=L,d},i=n(),s=lt;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(),u=e+h,p=u-o;return{version:i,codec:s,multihashCode:a,digestSize:h,multihashSize:p,size:u}}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 re(s).set(n,t),s}},Bn=(r,t)=>{switch(r[0]){case"Q":{let e=t||N;return[N.prefix,e.decode(`${N.prefix}${r}`)]}case N.prefix:{let e=t||N;return[N.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)]}}},Tn=(r,t,e)=>{let{prefix:n}=e;if(n!==N.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},Fn=(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},lt=112,kn=18,He=(r,t,e)=>{let n=Q(r),i=n+Q(t),s=new Uint8Array(i+e.byteLength);return W(r,s,0),W(t,s,n),s.set(e,i),s},Cn=Symbol.for("@ipld/js-cid/CID");var tt={...Qt,...qt,...Wt,...Gt,...$t,...Ht,...Xt,...Pt,...Jt,...jt},Ji={...ee,...Zt};function dt(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 vn=Symbol.for("nodejs.util.inspect.custom"),Xe=Object.values(tt).map(r=>r.decoder).reduce((r,t)=>r.or(t),tt.identity.decoder),Je=114,ne=36,ie=37,pt=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()})`}[Ue]=!0;toString(){return this.string==null&&(this.string=N.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return z.createV1(Je,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t instanceof Uint8Array)return dt(this.multihash.bytes,t);if(typeof t=="string")return _n(t).equals(this);if(t?.multihash?.bytes!=null)return dt(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[vn](){return`PeerId(${this.toString()})`}},et=class extends pt{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},rt=class extends pt{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},nt=class extends pt{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function _n(r,t){if(t=t??Xe,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=ut(N.decode(`z${r}`));return r.startsWith("12D")?new rt({multihash:e}):r.startsWith("16U")?new nt({multihash:e}):new et({multihash:e})}return se(Xe.decode(r))}function se(r){try{let t=ut(r);if(t.code===Y.code){if(t.digest.length===ne)return new rt({multihash:t});if(t.digest.length===ie)return new nt({multihash:t})}if(t.code===ft.code)return new et({multihash:t})}catch{return Mn(z.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Mn(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Je)throw new Error("Supplied PeerID CID is invalid");let t=r.multihash;if(t.code===ft.code)return new et({multihash:r.multihash});if(t.code===Y.code){if(t.digest.length===ne)return new rt({multihash:r.multihash});if(t.digest.length===ie)return new nt({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function We(r,t){return r.length===ne?new rt({multihash:F(Y.code,r),privateKey:t}):r.length===ie?new nt({multihash:F(Y.code,r),privateKey:t}):new et({multihash:await ft.digest(r),publicKey:r,privateKey:t})}function P(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function _(r=0){return globalThis.Buffer?.alloc!=null?P(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function y(r=0){return globalThis.Buffer?.allocUnsafe!=null?P(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function oe(r,t){t==null&&(t=r.reduce((i,s)=>i+s.length,0));let e=y(t),n=0;for(let i of r)e.set(i,n),n+=i.length;return P(e)}var Ke=Symbol.for("@achingbrain/uint8arraylist");function Qe(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 St(r){return!!r?.[Ke]}var k=class r{constructor(...t){Object.defineProperty(this,Ke,{value:!0}),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(St(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(St(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=Qe(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Qe(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(St(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 oe(n,i)}subarray(t,e){let{bufs:n,length:i}=this._subList(t,e);return n.length===1?n[0]:oe(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 u=t>=a&&t<h,p=e>a&&e<=h;if(u&&p){if(t===a&&e===h){n.push(o);break}let d=t-a;n.push(o.subarray(d,d+(e-t)));break}if(u){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(p){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(!St(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 d=0;d<s;d++)o[d]=-1;for(let d=0;d<i;d++)o[n[d]]=d;let a=o,h=this.byteLength-n.byteLength,u=n.byteLength-1,p;for(let d=e;d<=h;d+=p){p=0;for(let L=u;L>=0;L--){let H=this.get(d+L);if(n[L]!==H){p=Math.max(1,L-a[H]);break}}if(p===0)return d}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=y(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=_(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=_(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=_(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=y(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=_(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=_(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=_(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=_(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=_(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(!dt(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}};function Ze(r){let t=async function*(){let e=yield,n=new k;for await(let i of r){if(e==null){n.append(i),e=yield n,n=new k;continue}for(n.append(i);n.length>=e;){let s=n.sublist(0,e);if(n.consume(e),e=yield s,e==null){n.length>0&&(e=yield n,n=new k);break}}}if(e!=null)throw Object.assign(new Error(`stream ended before ${e} bytes became available`),{code:"ERR_UNDER_READ",buffer:n})}();return t.next(),t}function it(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var It=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},st=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new It(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new It(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var ae=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Ye(r={}){return On(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function On(r,t){t=t??{};let e=t.onEnd,n=new st,i,s,o,a=it(),h=async()=>{try{return n.isEmpty()?o?{done:!0}:await new Promise((c,g)=>{s=A=>{s=null,n.push(A);try{c(r(n))}catch(w){g(w)}return i}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=it()})}},u=c=>s!=null?s(c):(n.push(c),i),p=c=>(n=new st,s!=null?s({error:c}):(n.push({error:c}),i)),d=c=>{if(o)return i;if(t?.objectMode!==!0&&c?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:c})},L=c=>o?i:(o=!0,c!=null?p(c):u({done:!0})),H=()=>(n=new st,L(),{done:!0}),l=c=>(L(c),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:h,return:H,throw:l,push:d,end:L,get readableLength(){return n.size},onEmpty:async c=>{let g=c?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let A,w;g!=null&&(A=new Promise((S,U)=>{w=()=>{U(new ae)},g.addEventListener("abort",w)}));try{await Promise.race([a.promise,A])}finally{w!=null&&g!=null&&g?.removeEventListener("abort",w)}}},e==null)return i;let b=i;return i={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(c){return b.throw(c),e!=null&&(e(c),e=void 0),{done:!0}},return(){return b.return(),e!=null&&(e(),e=void 0),{done:!0}},push:d,end(c){return b.end(c),e!=null&&(e(c),e=void 0),i},get readableLength(){return b.readableLength},onEmpty:c=>b.onEmpty(c)},i}function tr(r){let t=Ye(),e=Ze(r.source),n=it(),i,s=r.sink(async function*(){yield*t,yield*await n.promise}());return s.catch(a=>{i=a}),{reader:e,writer:t,stream:{sink:async a=>{if(i!=null){await Promise.reject(i);return}n.resolve(a),await s},source:e},rest:()=>t.end(),write:t.push,read:async()=>{let a=await e.next();if(a.value!=null)return a.value}}}var Vn=Math.pow(2,7),zn=Math.pow(2,14),Pn=Math.pow(2,21),he=Math.pow(2,28),ce=Math.pow(2,35),ue=Math.pow(2,42),fe=Math.pow(2,49),f=128,x=127;function G(r){if(r<Vn)return 1;if(r<zn)return 2;if(r<Pn)return 3;if(r<he)return 4;if(r<ce)return 5;if(r<ue)return 6;if(r<fe)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Gn(r,t,e=0){switch(G(r)){case 8:t[e++]=r&255|f,r/=128;case 7:t[e++]=r&255|f,r/=128;case 6:t[e++]=r&255|f,r/=128;case 5:t[e++]=r&255|f,r/=128;case 4:t[e++]=r&255|f,r>>>=7;case 3:t[e++]=r&255|f,r>>>=7;case 2:t[e++]=r&255|f,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function $n(r,t,e=0){switch(G(r)){case 8:t.set(e++,r&255|f),r/=128;case 7:t.set(e++,r&255|f),r/=128;case 6:t.set(e++,r&255|f),r/=128;case 5:t.set(e++,r&255|f),r/=128;case 4:t.set(e++,r&255|f),r>>>=7;case 3:t.set(e++,r&255|f),r>>>=7;case 2:t.set(e++,r&255|f),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function qn(r,t){let e=r[t],n=0;if(n+=e&x,e<f||(e=r[t+1],n+=(e&x)<<7,e<f)||(e=r[t+2],n+=(e&x)<<14,e<f)||(e=r[t+3],n+=(e&x)<<21,e<f)||(e=r[t+4],n+=(e&x)*he,e<f)||(e=r[t+5],n+=(e&x)*ce,e<f)||(e=r[t+6],n+=(e&x)*ue,e<f)||(e=r[t+7],n+=(e&x)*fe,e<f))return n;throw new RangeError("Could not decode varint")}function jn(r,t){let e=r.get(t),n=0;if(n+=e&x,e<f||(e=r.get(t+1),n+=(e&x)<<7,e<f)||(e=r.get(t+2),n+=(e&x)<<14,e<f)||(e=r.get(t+3),n+=(e&x)<<21,e<f)||(e=r.get(t+4),n+=(e&x)*he,e<f)||(e=r.get(t+5),n+=(e&x)*ce,e<f)||(e=r.get(t+6),n+=(e&x)*ue,e<f)||(e=r.get(t+7),n+=(e&x)*fe,e<f))return n;throw new RangeError("Could not decode varint")}function er(r,t,e=0){return t==null&&(t=y(G(r))),t instanceof Uint8Array?Gn(r,t,e):$n(r,t,e)}function rr(r,t=0){return r instanceof Uint8Array?qn(r,t):jn(r,t)}function Nt(r){return r[Symbol.asyncIterator]!=null}var Ut=r=>{let t=G(r),e=y(t);return er(r,e),Ut.bytes=t,e};Ut.bytes=0;function Rt(r,t){t=t??{};let e=t.lengthEncoder??Ut;function*n(i){let s=e(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return Nt(r)?async function*(){for await(let i of r)yield*n(i)}():function*(){for(let i of r)yield*n(i)}()}Rt.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Ut;return new k(e(r.byteLength),r)};var ot=Nr(or(),1);var Xn=8,Jn=1024*1024*4,$;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})($||($={}));var le=r=>{let t=rr(r);return le.bytes=G(t),t};le.bytes=0;function mt(r,t){let e=new k,n=$.LENGTH,i=-1,s=t?.lengthDecoder??le,o=t?.maxLengthLength??Xn,a=t?.maxDataLength??Jn;function*h(){for(;e.byteLength>0;){if(n===$.LENGTH)try{if(i=s(e),i<0)throw(0,ot.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(i>a)throw(0,ot.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let u=s.bytes;e.consume(u),t?.onLength!=null&&t.onLength(i),n=$.DATA}catch(u){if(u instanceof RangeError){if(e.byteLength>o)throw(0,ot.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw u}if(n===$.DATA){if(e.byteLength<i)break;let u=e.sublist(0,i);e.consume(i),t?.onData!=null&&t.onData(u),yield u,n=$.LENGTH}}}return Nt(r)?async function*(){for await(let u of r)e.append(u),yield*h();if(e.byteLength>0)throw(0,ot.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let u of r)e.append(u),yield*h();if(e.byteLength>0)throw(0,ot.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}mt.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:o}=await r.next(e);if(s===!0)return;o!=null&&(yield o)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return mt(n,{...t??{},onLength:s=>{e=s}})};function Qn(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var ar=Qn;function Kn(r){return r[Symbol.asyncIterator]!=null}function Zn(r,t){if(Kn(r))return async function*(){for await(let a of r)yield t(a)}();let e=ar(r),{value:n,done:i}=e.next();if(i===!0)return function*(){}();let s=t(n);if(typeof s.then=="function")return async function*(){yield await s;for await(let a of e)yield t(a)}();let o=t;return function*(){yield s;for(let a of e)yield o(a)}()}var hr=Zn;var de=new Float32Array([-0]),V=new Uint8Array(de.buffer);function cr(r,t,e){de[0]=r,t[e]=V[0],t[e+1]=V[1],t[e+2]=V[2],t[e+3]=V[3]}function ur(r,t){return V[0]=r[t],V[1]=r[t+1],V[2]=r[t+2],V[3]=r[t+3],de[0]}var pe=new Float64Array([-0]),E=new Uint8Array(pe.buffer);function fr(r,t,e){pe[0]=r,t[e]=E[0],t[e+1]=E[1],t[e+2]=E[2],t[e+3]=E[3],t[e+4]=E[4],t[e+5]=E[5],t[e+6]=E[6],t[e+7]=E[7]}function lr(r,t){return E[0]=r[t],E[1]=r[t+1],E[2]=r[t+2],E[3]=r[t+3],E[4]=r[t+4],E[5]=r[t+5],E[6]=r[t+6],E[7]=r[t+7],pe[0]}var Yn=BigInt(Number.MAX_SAFE_INTEGER),ti=BigInt(Number.MIN_SAFE_INTEGER),D=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 q;if(t<Yn&&t>ti)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>dr&&(i=0n,++n>dr&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(t){if(t===0)return q;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):q}},q=new D(0,0);q.toBigInt=function(){return 0n};q.zzEncode=q.zzDecode=function(){return this};q.length=function(){return 1};var dr=4294967296n;function pr(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 mr(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 me(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 B(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Bt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var be=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,B(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 B(this,4);return Bt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw B(this,4);return Bt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw B(this,4);let t=ur(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw B(this,4);let t=lr(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 B(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return mr(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw B(this,t);this.pos+=t}else do if(this.pos>=this.len)throw B(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 D(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 B(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 B(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 B(this,8);let t=Bt(this.buf,this.pos+=4),e=Bt(this.buf,this.pos+=4);return new D(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function ge(r){return new be(r instanceof Uint8Array?r:r.subarray())}function Tt(r,t){let e=ge(r);return t.decode(e)}function wr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var gr=wr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),we=wr("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=y(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ei={utf8:gr,"utf-8":gr,hex:tt.base16,latin1:we,ascii:we,binary:we,...tt},yr=ei;function xr(r,t="utf8"){let e=yr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?P(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function ye(r){let t=r??8192,e=t>>>1,n,i=t;return function(o){if(o<1||o>e)return y(o);i+o>t&&(n=y(t),i=0);let a=n.subarray(i,i+=o);return i&7&&(i=(i|7)+1),a}}var j=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function xe(){}var Ae=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ri=ye();function ni(r){return globalThis.Buffer!=null?y(r):ri(r)}var wt=class{len;head;tail;states;constructor(){this.len=0,this.head=new j(xe,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new j(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Le((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(bt,10,D.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=D.fromBigInt(t);return this._push(bt,e.length(),e)}uint64Number(t){let e=D.fromNumber(t);return this._push(bt,e.length(),e)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=D.fromBigInt(t).zzEncode();return this._push(bt,e.length(),e)}sint64Number(t){let e=D.fromNumber(t).zzEncode();return this._push(bt,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ee,1,t?1:0)}fixed32(t){return this._push(gt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=D.fromBigInt(t);return this._push(gt,4,e.lo)._push(gt,4,e.hi)}fixed64Number(t){let e=D.fromNumber(t);return this._push(gt,4,e.lo)._push(gt,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(cr,4,t)}double(t){return this._push(fr,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Ee,1,0):this.uint32(e)._push(si,e,t)}string(t){let e=pr(t);return e!==0?this.uint32(e)._push(me,e,t):this._push(Ee,1,0)}fork(){return this.states=new Ae(this),this.head=this.tail=new j(xe,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 j(xe,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=ni(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Ee(r,t,e){t[e]=r&255}function ii(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Le=class extends j{next;constructor(t,e){super(ii,t,e),this.next=void 0}};function bt(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 gt(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 si(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(wt.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(oi,t,r),this},wt.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ai,t,r),this});function oi(r,t,e){t.set(r,e)}function ai(r,t,e){r.length<40?me(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(xr(r),e)}function De(){return new wt}function Ft(r,t){let e=De();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var at;(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"})(at||(at={}));function kt(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Se(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 kt("enum",at.VARINT,e,n)}function Ct(r,t){return kt("message",at.LENGTH_DELIMITED,r,t)}var yt;(function(r){let t;r.codec=()=>(t==null&&(t=Ct((e,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),e.id!=null&&(n.uint32(10),n.bytes(e.id)),e.pubkey!=null&&(n.uint32(18),_t.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=_t.codec().decode(e,e.uint32());break;default:e.skipType(o&7);break}}return i})),t),r.encode=e=>Ft(e,r.codec()),r.decode=e=>Tt(e,r.codec())})(yt||(yt={}));var T;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1",r.ECDSA="ECDSA"})(T||(T={}));var vt;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1",r[r.ECDSA=3]="ECDSA"})(vt||(vt={}));(function(r){r.codec=()=>Se(vt)})(T||(T={}));var _t;(function(r){let t;r.codec=()=>(t==null&&(t=Ct((e,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),e.Type!=null&&vt[e.Type]!==0&&(n.uint32(8),T.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:T.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=T.codec().decode(e);break;case 2:i.Data=e.bytes();break;default:e.skipType(o&7);break}}return i})),t),r.encode=e=>Ft(e,r.codec()),r.decode=e=>Tt(e,r.codec())})(_t||(_t={}));var hi="/plaintext/2.0.0";function ci(r){let t=yt.encode(r);return Rt.single(t)}var Ie=class{protocol=hi;log;constructor(t){this.log=t.logger.forComponent("libp2p:plaintext")}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=tr(e),s=T.RSA;t.type==="Ed25519"?s=T.Ed25519:t.type==="secp256k1"&&(s=T.Secp256k1),i.write(ci({id:t.toBytes(),pubkey:{Type:s,Data:t.publicKey??new Uint8Array(0)}}).subarray()),this.log("write pubkey exchange to peer %p",n);let o=(await mt.fromReader(i.reader).next()).value;if(o==null)throw new Error("Did not read response");let a=yt.decode(o);this.log("read pubkey exchange from peer %p",n);let 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 We(a.pubkey.Data),!h.equals(se(a.id)))throw new Error("Public key did not match id")}catch(u){throw this.log.error(u),new Lt("Remote did not provide its public key")}if(n!=null&&!h.equals(n))throw new At;return this.log("plaintext key exchange completed successfully with peer %p",h),i.rest(),{conn:{sink:i.stream.sink,source:hr(i.stream.source,u=>u.subarray())},remotePeer:h}}};function ui(){return r=>new Ie(r)}return Ur(fi);})();
|
|
2
|
+
"use strict";var Libp2PPlaintext=(()=>{var Sr=Object.create;var yt=Object.defineProperty;var Dr=Object.getOwnPropertyDescriptor;var Nr=Object.getOwnPropertyNames;var Ir=Object.getPrototypeOf,Rr=Object.prototype.hasOwnProperty;var Ur=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),E=(r,t)=>{for(var e in t)yt(r,e,{get:t[e],enumerable:!0})},Be=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Nr(t))!Rr.call(r,i)&&i!==e&&yt(r,i,{get:()=>t[i],enumerable:!(n=Dr(t,i))||n.enumerable});return r};var Tr=(r,t,e)=>(e=r!=null?Sr(Ir(r)):{},Be(t||!r||!r.__esModule?yt(e,"default",{value:r,enumerable:!0}):e,r)),Br=r=>Be(yt({},"__esModule",{value:!0}),r);var cr=Ur((Ts,ar)=>{"use strict";function or(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function Wn(r,t,e){if(!r||typeof r=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return or(r,e)}catch{e.message=r.message,e.stack=r.stack;let i=function(){};return i.prototype=Object.create(Object.getPrototypeOf(r)),or(new i,e)}}ar.exports=Wn});var hi={};E(hi,{plaintext:()=>ci});var xt=class r extends Error{code;constructor(t="Unexpected Peer"){super(t),this.code=r.code}static code="ERR_UNEXPECTED_PEER"},Et=class r extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var Fe=Symbol.for("@libp2p/peer-id");var Gt={};E(Gt,{base58btc:()=>A,base58flickr:()=>Or});function Fr(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,c=r.charAt(0),f=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function u(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var y=0,z=0,D=0,U=l.length;D!==U&&l[D]===0;)D++,y++;for(var T=(U-D)*d+1>>>0,L=new Uint8Array(T);D!==U;){for(var B=l[D],O=0,N=T-1;(B!==0||O<z)&&N!==-1;N--,O++)B+=256*L[N]>>>0,L[N]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");z=O,D++}for(var C=T-z;C!==T&&L[C]===0;)C++;for(var bt=c.repeat(y);C<T;++C)bt+=r.charAt(L[C]);return bt}function b(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var y=0;if(l[y]!==" "){for(var z=0,D=0;l[y]===c;)z++,y++;for(var U=(l.length-y)*f+1>>>0,T=new Uint8Array(U);l[y];){var L=e[l.charCodeAt(y)];if(L===255)return;for(var B=0,O=U-1;(L!==0||B<D)&&O!==-1;O--,B++)L+=a*T[O]>>>0,T[O]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");D=B,y++}if(l[y]!==" "){for(var N=U-D;N!==U&&T[N]===0;)N++;for(var C=new Uint8Array(z+(U-N)),bt=z;N!==U;)C[bt++]=T[N++];return C}}}function wt(l){var y=b(l);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:b,decode:wt}}var Cr=Fr,vr=Cr,Ce=vr;var pi=new Uint8Array(0);var ve=(r,t)=>{if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0},v=r=>{if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")};var _e=r=>new TextEncoder().encode(r),ke=r=>new TextDecoder().decode(r);var Mt=class{constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Vt=class{constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Me(this,t)}},Pt=class{constructor(t){this.decoders=t}or(t){return Me(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Me=(r,t)=>new Pt({...r.decoders||{[r.prefix]:r},...t.decoders||{[t.prefix]:t}}),zt=class{constructor(t,e,n,i){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=i,this.encoder=new Mt(t,e,n),this.decoder=new Vt(t,e,i)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},j=({name:r,prefix:t,encode:e,decode:n})=>new zt(r,t,e,n),M=({prefix:r,name:t,alphabet:e})=>{let{encode:n,decode:i}=Ce(e,t);return j({prefix:r,name:t,encode:n,decode:s=>v(i(s))})},_r=(r,t,e,n)=>{let i={};for(let d=0;d<t.length;++d)i[t[d]]=d;let s=r.length;for(;r[s-1]==="=";)--s;let o=new Uint8Array(s*e/8|0),a=0,c=0,f=0;for(let d=0;d<s;++d){let u=i[r[d]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,a+=e,a>=8&&(a-=8,o[f++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},kr=(r,t,e)=>{let n=t[t.length-1]==="=",i=(1<<e)-1,s="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>e;)o-=e,s+=t[i&a>>o];if(o&&(s+=t[i&a<<e-o]),n)for(;s.length*e&7;)s+="=";return s},p=({name:r,prefix:t,bitsPerChar:e,alphabet:n})=>j({prefix:t,name:r,encode(i){return kr(i,n,e)},decode(i){return _r(i,n,e,r)}});var A=M({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Or=M({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var $t={};E($t,{base10:()=>Mr});var Mr=M({prefix:"9",name:"base10",alphabet:"0123456789"});var Ht={};E(Ht,{base16:()=>Vr,base16upper:()=>Pr});var Vr=p({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Pr=p({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var qt={};E(qt,{base2:()=>zr});var zr=p({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var jt={};E(jt,{base256emoji:()=>jr});var Ve=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}"),Gr=Ve.reduce((r,t,e)=>(r[e]=t,r),[]),$r=Ve.reduce((r,t,e)=>(r[t.codePointAt(0)]=e,r),[]);function Hr(r){return r.reduce((t,e)=>(t+=Gr[e],t),"")}function qr(r){let t=[];for(let e of r){let n=$r[e.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(n)}return new Uint8Array(t)}var jr=j({prefix:"\u{1F680}",name:"base256emoji",encode:Hr,decode:qr});var Xt={};E(Xt,{base32:()=>X,base32hex:()=>Kr,base32hexpad:()=>Zr,base32hexpadupper:()=>Yr,base32hexupper:()=>Qr,base32pad:()=>Wr,base32padupper:()=>Jr,base32upper:()=>Xr,base32z:()=>tn});var X=p({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Xr=p({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Wr=p({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Jr=p({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Kr=p({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qr=p({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Zr=p({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Yr=p({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),tn=p({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Wt={};E(Wt,{base36:()=>en,base36upper:()=>rn});var en=M({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),rn=M({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Jt={};E(Jt,{base64:()=>nn,base64pad:()=>sn,base64url:()=>on,base64urlpad:()=>an});var nn=p({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),sn=p({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),on=p({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),an=p({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Kt={};E(Kt,{base8:()=>cn});var cn=p({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Qt={};E(Qt,{identity:()=>hn});var hn=j({prefix:"\0",name:"identity",encode:r=>ke(r),decode:r=>_e(r)});var Ui=new TextEncoder,Ti=new TextDecoder;var Yt={};E(Yt,{identity:()=>Z});var ln=Ge,Pe=128,dn=127,pn=~dn,mn=Math.pow(2,31);function Ge(r,t,e){t=t||[],e=e||0;for(var n=e;r>=mn;)t[e++]=r&255|Pe,r/=128;for(;r&pn;)t[e++]=r&255|Pe,r>>>=7;return t[e]=r|0,Ge.bytes=e-n+1,t}var gn=Zt,wn=128,ze=127;function Zt(r,n){var e=0,n=n||0,i=0,s=n,o,a=r.length;do{if(s>=a)throw Zt.bytes=0,new RangeError("Could not decode varint");o=r[s++],e+=i<28?(o&ze)<<i:(o&ze)*Math.pow(2,i),i+=7}while(o>=wn);return Zt.bytes=s-n,e}var bn=Math.pow(2,7),yn=Math.pow(2,14),xn=Math.pow(2,21),En=Math.pow(2,28),An=Math.pow(2,35),Ln=Math.pow(2,42),Sn=Math.pow(2,49),Dn=Math.pow(2,56),Nn=Math.pow(2,63),In=function(r){return r<bn?1:r<yn?2:r<xn?3:r<En?4:r<An?5:r<Ln?6:r<Sn?7:r<Dn?8:r<Nn?9:10},Rn={encode:ln,decode:gn,encodingLength:In},Un=Rn,ot=Un;var at=(r,t=0)=>[ot.decode(r,t),ot.decode.bytes],W=(r,t,e=0)=>(ot.encode(r,t,e),t),J=r=>ot.encodingLength(r);var F=(r,t)=>{let e=t.byteLength,n=J(r),i=n+J(e),s=new Uint8Array(i+e);return W(r,s,0),W(e,s,n),s.set(t,i),new K(r,e,t,s)},ct=r=>{let t=v(r),[e,n]=at(t),[i,s]=at(t.subarray(n)),o=t.subarray(n+s);if(o.byteLength!==i)throw new Error("Incorrect length");return new K(e,i,o,t)},$e=(r,t)=>{if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ve(r.bytes,e.bytes)}},K=class{constructor(t,e,n,i){this.code=t,this.size=e,this.digest=n,this.bytes=i}};var He=0,Tn="identity",qe=v,Bn=r=>F(He,qe(r)),Z={code:He,name:Tn,encode:qe,digest:Bn};var re={};E(re,{sha256:()=>ht,sha512:()=>Fn});var ee=({name:r,code:t,encode:e})=>new te(r,t,e),te=class{constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?F(this.code,e):e.then(n=>F(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Xe=r=>async t=>new Uint8Array(await crypto.subtle.digest(r,t)),ht=ee({name:"sha2-256",code:18,encode:Xe("SHA-256")}),Fn=ee({name:"sha2-512",code:19,encode:Xe("SHA-512")});var We=(r,t)=>{let{bytes:e,version:n}=r;switch(n){case 0:return vn(e,ne(r),t||A.encoder);default:return _n(e,ne(r),t||X.encoder)}};var Je=new WeakMap,ne=r=>{let t=Je.get(r);if(t==null){let e=new Map;return Je.set(r,e),e}return t},G=class r{constructor(t,e,n,i){this.code=e,this.version=t,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==ut)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==kn)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=F(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n&&t.code===n.code&&t.version===n.version&&$e(t.multihash,n.multihash)}toString(t){return We(this,t)}toJSON(){return{"/":We(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:i,multihash:s,bytes:o}=e;return new r(n,i,s,o||Ke(n,i,s.bytes))}else if(e[On]===!0){let{version:n,multihash:i,code:s}=e,o=ct(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!==ut)throw new Error(`Version 0 CID must use dag-pb (code: ${ut}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let i=Ke(t,e,n.bytes);return new r(t,e,n,i)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,ut,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,i=v(t.subarray(n,n+e.multihashSize));if(i.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=i.subarray(e.multihashSize-e.digestSize),o=new K(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,b]=at(t.subarray(e));return e+=b,u},i=n(),s=ut;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(),c=n(),f=e+c,d=f-o;return{version:i,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:f}}static parse(t,e){let[n,i]=Cn(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 ne(s).set(n,t),s}},Cn=(r,t)=>{switch(r[0]){case"Q":{let e=t||A;return[A.prefix,e.decode(`${A.prefix}${r}`)]}case A.prefix:{let e=t||A;return[A.prefix,e.decode(r)]}case X.prefix:{let e=t||X;return[X.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)]}}},vn=(r,t,e)=>{let{prefix:n}=e;if(n!==A.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},_n=(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},ut=112,kn=18,Ke=(r,t,e)=>{let n=J(r),i=n+J(t),s=new Uint8Array(i+e.byteLength);return W(r,s,0),W(t,s,n),s.set(e,i),s},On=Symbol.for("@ipld/js-cid/CID");var Y={...Qt,...qt,...Kt,...$t,...Ht,...Xt,...Wt,...Gt,...Jt,...jt},ji={...re,...Yt};function ft(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 Mn=Symbol.for("nodejs.util.inspect.custom"),Qe=Object.values(Y).map(r=>r.decoder).reduce((r,t)=>r.or(t),Y.identity.decoder),Ze=114,ie=36,se=37,lt=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()})`}[Fe]=!0;toString(){return this.string==null&&(this.string=A.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return G.createV1(Ze,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t instanceof Uint8Array)return ft(this.multihash.bytes,t);if(typeof t=="string")return Vn(t).equals(this);if(t?.multihash?.bytes!=null)return ft(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[Mn](){return`PeerId(${this.toString()})`}},tt=class extends lt{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},et=class extends lt{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},rt=class extends lt{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function Vn(r,t){if(t=t??Qe,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=ct(A.decode(`z${r}`));return r.startsWith("12D")?new et({multihash:e}):r.startsWith("16U")?new rt({multihash:e}):new tt({multihash:e})}return oe(Qe.decode(r))}function oe(r){try{let t=ct(r);if(t.code===Z.code){if(t.digest.length===ie)return new et({multihash:t});if(t.digest.length===se)return new rt({multihash:t})}if(t.code===ht.code)return new tt({multihash:t})}catch{return Pn(G.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function Pn(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Ze)throw new Error("Supplied PeerID CID is invalid");let t=r.multihash;if(t.code===ht.code)return new tt({multihash:r.multihash});if(t.code===Z.code){if(t.digest.length===ie)return new et({multihash:r.multihash});if(t.digest.length===se)return new rt({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function Ye(r,t){return r.length===ie?new et({multihash:F(Z.code,r),privateKey:t}):r.length===se?new rt({multihash:F(Z.code,r),privateKey:t}):new tt({multihash:await ht.digest(r),publicKey:r,privateKey:t})}function V(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function _(r=0){return globalThis.Buffer?.alloc!=null?V(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function m(r=0){return globalThis.Buffer?.allocUnsafe!=null?V(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function ae(r,t){if(globalThis.Buffer!=null)return V(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((i,s)=>i+s.length,0));let e=m(t),n=0;for(let i of r)e.set(i,n),n+=i.length;return V(e)}var er=Symbol.for("@achingbrain/uint8arraylist");function tr(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let i=e+n.byteLength;if(t<i)return{buf:n,index:t-e};e=i}throw new RangeError("index is out of bounds")}function Lt(r){return!!r?.[er]}var S=class r{bufs;length;[er]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Lt(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Lt(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=tr(this.bufs,t);return e.buf[e.index]}set(t,e){let n=tr(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Lt(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:i}=this._subList(t,e);return ae(n,i)}subarray(t,e){let{bufs:n,length:i}=this._subList(t,e);return n.length===1?n[0]:ae(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,c=a+o.byteLength;if(i=c,t>=c)continue;let f=t>=a&&t<c,d=e>a&&e<=c;if(f&&d){if(t===a&&e===c){n.push(o);break}let u=t-a;n.push(o.subarray(u,u+(e-t)));break}if(f){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(d){if(e===c){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(!Lt(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let 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,c=this.byteLength-n.byteLength,f=n.byteLength-1,d;for(let u=e;u<=c;u+=d){d=0;for(let b=f;b>=0;b--){let wt=this.get(u+b);if(n[b]!==wt){d=Math.max(1,b-a[wt]);break}}if(d===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=m(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=_(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=_(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=_(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=m(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=_(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=_(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=_(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=_(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=_(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(!ft(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}};function nt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var St=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function rr(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new St(e?.errorMessage,e?.errorCode));let n,i=new St(e?.errorMessage,e?.errorCode);try{return await Promise.race([r,new Promise((s,o)=>{n=()=>{o(i)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var ce=class{needNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.needNext=nt(),this.needNext.resolve(),this.haveNext=nt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("Have next but next was undefined");let t=this.nextResult;return this.nextResult=void 0,this.needNext.resolve(),this.needNext=nt(),t}async throw(t){return this.ended=!0,t!=null&&this.haveNext.reject(t),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");this.nextResult!=null&&await this.needNext.promise,t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=nt(),await rr(this.needNext.promise,e?.signal,e)}};function nr(){return new ce}var Dt=class extends Error{code;constructor(t,e){super(t),this.code=e}},he=class extends Dt{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function ir(r,t){let e=nr();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 S;return{read:async(o,a)=>{a?.signal?.throwIfAborted();let c,f=new Promise((d,u)=>{c=()=>{u(new he("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(o==null){let{done:u,value:b}=await Promise.race([n.next(),f]);return u===!0?new S:b}for(;i.byteLength<o;){let{value:u,done:b}=await Promise.race([n.next(),f]);if(b===!0)throw new Dt("unexpected end of input","ERR_UNEXPECTED_EOF");i.append(u)}let d=i.sublist(0,o);return i.consume(o),d}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},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 zn=Math.pow(2,7),Gn=Math.pow(2,14),$n=Math.pow(2,21),ue=Math.pow(2,28),fe=Math.pow(2,35),le=Math.pow(2,42),de=Math.pow(2,49),h=128,g=127;function k(r){if(r<zn)return 1;if(r<Gn)return 2;if(r<$n)return 3;if(r<ue)return 4;if(r<fe)return 5;if(r<le)return 6;if(r<de)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Hn(r,t,e=0){switch(k(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 qn(r,t,e=0){switch(k(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 jn(r,t){let e=r[t],n=0;if(n+=e&g,e<h||(e=r[t+1],n+=(e&g)<<7,e<h)||(e=r[t+2],n+=(e&g)<<14,e<h)||(e=r[t+3],n+=(e&g)<<21,e<h)||(e=r[t+4],n+=(e&g)*ue,e<h)||(e=r[t+5],n+=(e&g)*fe,e<h)||(e=r[t+6],n+=(e&g)*le,e<h)||(e=r[t+7],n+=(e&g)*de,e<h))return n;throw new RangeError("Could not decode varint")}function Xn(r,t){let e=r.get(t),n=0;if(n+=e&g,e<h||(e=r.get(t+1),n+=(e&g)<<7,e<h)||(e=r.get(t+2),n+=(e&g)<<14,e<h)||(e=r.get(t+3),n+=(e&g)<<21,e<h)||(e=r.get(t+4),n+=(e&g)*ue,e<h)||(e=r.get(t+5),n+=(e&g)*fe,e<h)||(e=r.get(t+6),n+=(e&g)*le,e<h)||(e=r.get(t+7),n+=(e&g)*de,e<h))return n;throw new RangeError("Could not decode varint")}function sr(r,t,e=0){return t==null&&(t=m(k(r))),t instanceof Uint8Array?Hn(r,t,e):qn(r,t,e)}function Nt(r,t=0){return r instanceof Uint8Array?jn(r,t):Xn(r,t)}function It(r){return r[Symbol.asyncIterator]!=null}var Rt=r=>{let t=k(r),e=m(t);return sr(r,e),Rt.bytes=t,e};Rt.bytes=0;function dt(r,t){t=t??{};let e=t.lengthEncoder??Rt;function*n(i){let s=e(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return It(r)?async function*(){for await(let i of r)yield*n(i)}():function*(){for(let i of r)yield*n(i)}()}dt.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Rt;return new S(e(r.byteLength),r)};var it=Tr(cr(),1);var Jn=8,Kn=1024*1024*4,$;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})($||($={}));var ge=r=>{let t=Nt(r);return ge.bytes=k(t),t};ge.bytes=0;function me(r,t){let e=new S,n=$.LENGTH,i=-1,s=t?.lengthDecoder??ge,o=t?.maxLengthLength??Jn,a=t?.maxDataLength??Kn;function*c(){for(;e.byteLength>0;){if(n===$.LENGTH)try{if(i=s(e),i<0)throw(0,it.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(i>a)throw(0,it.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let f=s.bytes;e.consume(f),t?.onLength!=null&&t.onLength(i),n=$.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>o)throw(0,it.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw f}if(n===$.DATA){if(e.byteLength<i)break;let f=e.sublist(0,i);e.consume(i),t?.onData!=null&&t.onData(f),yield f,n=$.LENGTH}}}return It(r)?async function*(){for await(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw(0,it.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let f of r)e.append(f),yield*c();if(e.byteLength>0)throw(0,it.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}me.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:o}=await r.next(e);if(s===!0)return;o!=null&&(yield o)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return me(n,{...t??{},onLength:s=>{e=s}})};var Ut=class extends Error{code;constructor(t,e){super(t),this.code=e}},hr=r=>Nt(r);hr.bytes=0;function ur(r,t={}){let e=ir(r,t);return t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=k(t.maxDataLength)),{read:async i=>{let s=-1,o=new S,a=t?.lengthDecoder??hr;for(;;){o.append(await e.read(1,i));try{s=a(o)}catch(c){if(c instanceof RangeError)continue;throw c}if(t?.maxLengthLength!=null&&o.byteLength>t.maxLengthLength)throw new Ut("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(s>-1)break}if(t?.maxDataLength!=null&&s>t.maxDataLength)throw new Ut("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(s,i)},write:async(i,s)=>{await e.write(dt.single(i,t),s)},writeV:async(i,s)=>{let o=new S(...i.map(a=>dt.single(a,t)));await e.write(o,s)},unwrap:()=>e.unwrap()}}function fr(r,t){let e=ur(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 we=new Float32Array([-0]),P=new Uint8Array(we.buffer);function lr(r,t,e){we[0]=r,t[e]=P[0],t[e+1]=P[1],t[e+2]=P[2],t[e+3]=P[3]}function dr(r,t){return P[0]=r[t],P[1]=r[t+1],P[2]=r[t+2],P[3]=r[t+3],we[0]}var be=new Float64Array([-0]),w=new Uint8Array(be.buffer);function pr(r,t,e){be[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 mr(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],be[0]}var Zn=BigInt(Number.MAX_SAFE_INTEGER),Yn=BigInt(Number.MIN_SAFE_INTEGER),x=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 H;if(t<Zn&&t>Yn)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>gr&&(i=0n,++n>gr&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(t){if(t===0)return H;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):H}},H=new x(0,0);H.toBigInt=function(){return 0n};H.zzEncode=H.zzDecode=function(){return this};H.length=function(){return 1};var gr=4294967296n;function wr(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 br(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 ye(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 Tt(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var xe=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 Tt(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw I(this,4);return Tt(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw I(this,4);let t=dr(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw I(this,4);let t=mr(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 br(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 x(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=Tt(this.buf,this.pos+=4),e=Tt(this.buf,this.pos+=4);return new x(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ee(r){return new xe(r instanceof Uint8Array?r:r.subarray())}function Bt(r,t){let e=Ee(r);return t.decode(e)}function Er(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var xr=Er("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ae=Er("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=m(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ti={utf8:xr,"utf-8":xr,hex:Y.base16,latin1:Ae,ascii:Ae,binary:Ae,...Y},Ar=ti;function Lr(r,t="utf8"){let e=Ar[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?V(globalThis.Buffer.from(r,"utf-8")):e.decoder.decode(`${e.prefix}${r}`)}function Le(r){let t=r??8192,e=t>>>1,n,i=t;return function(o){if(o<1||o>e)return m(o);i+o>t&&(n=m(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 Se(){}var Ne=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ei=Le();function ri(r){return globalThis.Buffer!=null?m(r):ei(r)}var gt=class{len;head;tail;states;constructor(){this.len=0,this.head=new q(Se,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 Ie((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(pt,10,x.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=x.fromBigInt(t);return this._push(pt,e.length(),e)}uint64Number(t){let e=x.fromNumber(t);return this._push(pt,e.length(),e)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=x.fromBigInt(t).zzEncode();return this._push(pt,e.length(),e)}sint64Number(t){let e=x.fromNumber(t).zzEncode();return this._push(pt,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(De,1,t?1:0)}fixed32(t){return this._push(mt,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=x.fromBigInt(t);return this._push(mt,4,e.lo)._push(mt,4,e.hi)}fixed64Number(t){let e=x.fromNumber(t);return this._push(mt,4,e.lo)._push(mt,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(lr,4,t)}double(t){return this._push(pr,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(De,1,0):this.uint32(e)._push(ii,e,t)}string(t){let e=wr(t);return e!==0?this.uint32(e)._push(ye,e,t):this._push(De,1,0)}fork(){return this.states=new Ne(this),this.head=this.tail=new q(Se,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(Se,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=ri(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function De(r,t,e){t[e]=r&255}function ni(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Ie=class extends q{next;constructor(t,e){super(ni,t,e),this.next=void 0}};function pt(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function mt(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function ii(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(gt.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(si,t,r),this},gt.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(oi,t,r),this});function si(r,t,e){t.set(r,e)}function oi(r,t,e){r.length<40?ye(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Lr(r),e)}function Re(){return new gt}function Ft(r,t){let e=Re();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var st;(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"})(st||(st={}));function Ct(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ue(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 Ct("enum",st.VARINT,e,n)}function vt(r,t){return Ct("message",st.LENGTH_DELIMITED,r,t)}var _t;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),e.id!=null&&(n.uint32(10),n.bytes(e.id)),e.pubkey!=null&&(n.uint32(18),Ot.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=Ot.codec().decode(e,e.uint32());break;default:e.skipType(o&7);break}}return i})),t),r.encode=e=>Ft(e,r.codec()),r.decode=e=>Bt(e,r.codec())})(_t||(_t={}));var R;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.Secp256k1="Secp256k1",r.ECDSA="ECDSA"})(R||(R={}));var kt;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.Secp256k1=2]="Secp256k1",r[r.ECDSA=3]="ECDSA"})(kt||(kt={}));(function(r){r.codec=()=>Ue(kt)})(R||(R={}));var Ot;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),e.Type!=null&&kt[e.Type]!==0&&(n.uint32(8),R.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:R.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=R.codec().decode(e);break;case 2:i.Data=e.bytes();break;default:e.skipType(o&7);break}}return i})),t),r.encode=e=>Ft(e,r.codec()),r.decode=e=>Bt(e,r.codec())})(Ot||(Ot={}));var ai="/plaintext/2.0.0",Te=class{protocol=ai;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=fr(e).pb(_t),o=R.RSA;t.type==="Ed25519"?o=R.Ed25519:t.type==="secp256k1"&&(o=R.Secp256k1),await s.write({id:t.toBytes(),pubkey:{Type:o,Data:t.publicKey??new Uint8Array(0)}},{signal:i}),this.log("write pubkey exchange to peer %p",n);let a=await s.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 Ye(a.pubkey.Data),!c.equals(oe(a.id)))throw new Error("Public key did not match id")}catch(f){throw this.log.error(f),new Et("Remote did not provide its public key")}if(n!=null&&!c.equals(n))throw new xt;return this.log("plaintext key exchange completed successfully with peer %p",c),{conn:s.unwrap().unwrap(),remotePeer:c}}};function ci(r){return t=>new Te(t,r)}return Br(hi);})();
|
|
3
3
|
return Libp2PPlaintext}));
|
package/dist/src/index.d.ts
CHANGED
|
@@ -24,5 +24,12 @@ import type { ConnectionEncrypter } from '@libp2p/interface/connection-encrypter
|
|
|
24
24
|
export interface PlaintextComponents {
|
|
25
25
|
logger: ComponentLogger;
|
|
26
26
|
}
|
|
27
|
-
export
|
|
27
|
+
export interface PlaintextInit {
|
|
28
|
+
/**
|
|
29
|
+
* The peer id exchange must complete within this many milliseconds
|
|
30
|
+
* (default: 1000)
|
|
31
|
+
*/
|
|
32
|
+
timeout?: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function plaintext(init?: PlaintextInit): (components: PlaintextComponents) => ConnectionEncrypter;
|
|
28
35
|
//# sourceMappingURL=index.d.ts.map
|
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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,mBAAmB,CAAA;AAEhE,OAAO,KAAK,EAAE,mBAAmB,EAAqB,MAAM,wCAAwC,CAAA;AAOpG,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AA0FD,wBAAgB,SAAS,CAAE,IAAI,CAAC,EAAE,aAAa,GAAG,CAAC,UAAU,EAAE,mBAAmB,KAAK,mBAAmB,CAEzG"}
|
package/dist/src/index.js
CHANGED
|
@@ -21,20 +21,16 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { UnexpectedPeerError, InvalidCryptoExchangeError } from '@libp2p/interface/errors';
|
|
23
23
|
import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id';
|
|
24
|
-
import {
|
|
25
|
-
import * as lp from 'it-length-prefixed';
|
|
26
|
-
import map from 'it-map';
|
|
24
|
+
import { pbStream } from 'it-protobuf-stream';
|
|
27
25
|
import { Exchange, KeyType } from './pb/proto.js';
|
|
28
26
|
const PROTOCOL = '/plaintext/2.0.0';
|
|
29
|
-
function lpEncodeExchange(exchange) {
|
|
30
|
-
const pb = Exchange.encode(exchange);
|
|
31
|
-
return lp.encode.single(pb);
|
|
32
|
-
}
|
|
33
27
|
class Plaintext {
|
|
34
28
|
protocol = PROTOCOL;
|
|
35
29
|
log;
|
|
36
|
-
|
|
30
|
+
timeout;
|
|
31
|
+
constructor(components, init = {}) {
|
|
37
32
|
this.log = components.logger.forComponent('libp2p:plaintext');
|
|
33
|
+
this.timeout = init.timeout ?? 1000;
|
|
38
34
|
}
|
|
39
35
|
async secureInbound(localId, conn, remoteId) {
|
|
40
36
|
return this._encrypt(localId, conn, remoteId);
|
|
@@ -46,7 +42,8 @@ class Plaintext {
|
|
|
46
42
|
* Encrypt connection
|
|
47
43
|
*/
|
|
48
44
|
async _encrypt(localId, conn, remoteId) {
|
|
49
|
-
const
|
|
45
|
+
const signal = AbortSignal.timeout(this.timeout);
|
|
46
|
+
const pb = pbStream(conn).pb(Exchange);
|
|
50
47
|
let type = KeyType.RSA;
|
|
51
48
|
if (localId.type === 'Ed25519') {
|
|
52
49
|
type = KeyType.Ed25519;
|
|
@@ -55,34 +52,33 @@ class Plaintext {
|
|
|
55
52
|
type = KeyType.Secp256k1;
|
|
56
53
|
}
|
|
57
54
|
// Encode the public key and write it to the remote peer
|
|
58
|
-
|
|
55
|
+
await pb.write({
|
|
59
56
|
id: localId.toBytes(),
|
|
60
57
|
pubkey: {
|
|
61
58
|
Type: type,
|
|
62
59
|
Data: localId.publicKey ?? new Uint8Array(0)
|
|
63
60
|
}
|
|
64
|
-
}
|
|
61
|
+
}, {
|
|
62
|
+
signal
|
|
63
|
+
});
|
|
65
64
|
this.log('write pubkey exchange to peer %p', remoteId);
|
|
66
65
|
// Get the Exchange message
|
|
67
|
-
const response =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
const id = Exchange.decode(response);
|
|
72
|
-
this.log('read pubkey exchange from peer %p', remoteId);
|
|
66
|
+
const response = await pb.read({
|
|
67
|
+
signal
|
|
68
|
+
});
|
|
73
69
|
let peerId;
|
|
74
70
|
try {
|
|
75
|
-
if (
|
|
71
|
+
if (response.pubkey == null) {
|
|
76
72
|
throw new Error('Public key missing');
|
|
77
73
|
}
|
|
78
|
-
if (
|
|
74
|
+
if (response.pubkey.Data.length === 0) {
|
|
79
75
|
throw new Error('Public key data too short');
|
|
80
76
|
}
|
|
81
|
-
if (
|
|
77
|
+
if (response.id == null) {
|
|
82
78
|
throw new Error('Remote id missing');
|
|
83
79
|
}
|
|
84
|
-
peerId = await peerIdFromKeys(
|
|
85
|
-
if (!peerId.equals(peerIdFromBytes(
|
|
80
|
+
peerId = await peerIdFromKeys(response.pubkey.Data);
|
|
81
|
+
if (!peerId.equals(peerIdFromBytes(response.id))) {
|
|
86
82
|
throw new Error('Public key did not match id');
|
|
87
83
|
}
|
|
88
84
|
}
|
|
@@ -94,17 +90,13 @@ class Plaintext {
|
|
|
94
90
|
throw new UnexpectedPeerError();
|
|
95
91
|
}
|
|
96
92
|
this.log('plaintext key exchange completed successfully with peer %p', peerId);
|
|
97
|
-
shake.rest();
|
|
98
93
|
return {
|
|
99
|
-
conn:
|
|
100
|
-
sink: shake.stream.sink,
|
|
101
|
-
source: map(shake.stream.source, (buf) => buf.subarray())
|
|
102
|
-
},
|
|
94
|
+
conn: pb.unwrap().unwrap(),
|
|
103
95
|
remotePeer: peerId
|
|
104
96
|
};
|
|
105
97
|
}
|
|
106
98
|
}
|
|
107
|
-
export function plaintext() {
|
|
108
|
-
return (components) => new Plaintext(components);
|
|
99
|
+
export function plaintext(init) {
|
|
100
|
+
return (components) => new Plaintext(components, init);
|
|
109
101
|
}
|
|
110
102
|
//# sourceMappingURL=index.js.map
|
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,0BAA0B,CAAA;AAC1F,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACjE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"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"}
|
package/dist/src/pb/proto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proto.js","sourceRoot":"","sources":["../../../src/pb/proto.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,+BAA+B;AAC/B,oDAAoD;AACpD,8EAA8E;AAC9E,0DAA0D;AAE1D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AASpF,MAAM,KAAW,QAAQ,CA0DxB;AA1DD,WAAiB,QAAQ;IACvB,IAAI,MAAuB,CAAA;IAEd,cAAK,GAAG,GAAoB,EAAE;QACzC,IAAI,MAAM,IAAI,IAAI,EAAE;
|
|
1
|
+
{"version":3,"file":"proto.js","sourceRoot":"","sources":["../../../src/pb/proto.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/plaintext",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-e2267d437",
|
|
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",
|
|
@@ -47,20 +47,18 @@
|
|
|
47
47
|
"dep-check": "aegir dep-check"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@libp2p/interface": "0.1.6-
|
|
51
|
-
"@libp2p/peer-id": "3.0.6-
|
|
50
|
+
"@libp2p/interface": "0.1.6-e2267d437",
|
|
51
|
+
"@libp2p/peer-id": "3.0.6-e2267d437",
|
|
52
52
|
"@multiformats/multiaddr": "^12.1.10",
|
|
53
|
-
"it-
|
|
54
|
-
"it-length-prefixed": "^9.0.3",
|
|
55
|
-
"it-map": "^3.0.4",
|
|
53
|
+
"it-protobuf-stream": "^1.1.1",
|
|
56
54
|
"it-stream-types": "^2.0.1",
|
|
57
55
|
"protons-runtime": "^5.0.0",
|
|
58
56
|
"uint8arraylist": "^2.4.3"
|
|
59
57
|
},
|
|
60
58
|
"devDependencies": {
|
|
61
|
-
"@libp2p/interface-compliance-tests": "4.1.5-
|
|
62
|
-
"@libp2p/logger": "3.1.0-
|
|
63
|
-
"@libp2p/peer-id-factory": "3.0.8-
|
|
59
|
+
"@libp2p/interface-compliance-tests": "4.1.5-e2267d437",
|
|
60
|
+
"@libp2p/logger": "3.1.0-e2267d437",
|
|
61
|
+
"@libp2p/peer-id-factory": "3.0.8-e2267d437",
|
|
64
62
|
"aegir": "^41.0.2",
|
|
65
63
|
"protons": "^7.3.0",
|
|
66
64
|
"sinon": "^17.0.0"
|
package/src/index.ts
CHANGED
|
@@ -22,49 +22,53 @@
|
|
|
22
22
|
|
|
23
23
|
import { UnexpectedPeerError, InvalidCryptoExchangeError } from '@libp2p/interface/errors'
|
|
24
24
|
import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id'
|
|
25
|
-
import {
|
|
26
|
-
import * as lp from 'it-length-prefixed'
|
|
27
|
-
import map from 'it-map'
|
|
25
|
+
import { pbStream } from 'it-protobuf-stream'
|
|
28
26
|
import { Exchange, KeyType } from './pb/proto.js'
|
|
29
27
|
import type { ComponentLogger, Logger } from '@libp2p/interface'
|
|
28
|
+
import type { MultiaddrConnection } from '@libp2p/interface/connection'
|
|
30
29
|
import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface/connection-encrypter'
|
|
31
30
|
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
32
|
-
import type { Duplex
|
|
31
|
+
import type { Duplex } from 'it-stream-types'
|
|
33
32
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
34
33
|
|
|
35
34
|
const PROTOCOL = '/plaintext/2.0.0'
|
|
36
35
|
|
|
37
|
-
function lpEncodeExchange (exchange: Exchange): Uint8ArrayList {
|
|
38
|
-
const pb = Exchange.encode(exchange)
|
|
39
|
-
|
|
40
|
-
return lp.encode.single(pb)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
36
|
export interface PlaintextComponents {
|
|
44
37
|
logger: ComponentLogger
|
|
45
38
|
}
|
|
46
39
|
|
|
40
|
+
export interface PlaintextInit {
|
|
41
|
+
/**
|
|
42
|
+
* The peer id exchange must complete within this many milliseconds
|
|
43
|
+
* (default: 1000)
|
|
44
|
+
*/
|
|
45
|
+
timeout?: number
|
|
46
|
+
}
|
|
47
|
+
|
|
47
48
|
class Plaintext implements ConnectionEncrypter {
|
|
48
49
|
public protocol: string = PROTOCOL
|
|
49
50
|
private readonly log: Logger
|
|
51
|
+
private readonly timeout: number
|
|
50
52
|
|
|
51
|
-
constructor (components: PlaintextComponents) {
|
|
53
|
+
constructor (components: PlaintextComponents, init: PlaintextInit = {}) {
|
|
52
54
|
this.log = components.logger.forComponent('libp2p:plaintext')
|
|
55
|
+
this.timeout = init.timeout ?? 1000
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
async secureInbound (localId: PeerId, conn:
|
|
58
|
+
async secureInbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (localId: PeerId, conn: Stream, remoteId?: PeerId): Promise<SecuredConnection<Stream>> {
|
|
56
59
|
return this._encrypt(localId, conn, remoteId)
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
async secureOutbound (localId: PeerId, conn:
|
|
62
|
+
async secureOutbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (localId: PeerId, conn: Stream, remoteId?: PeerId): Promise<SecuredConnection<Stream>> {
|
|
60
63
|
return this._encrypt(localId, conn, remoteId)
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
/**
|
|
64
67
|
* Encrypt connection
|
|
65
68
|
*/
|
|
66
|
-
async _encrypt (localId: PeerId, conn:
|
|
67
|
-
const
|
|
69
|
+
async _encrypt <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (localId: PeerId, conn: Stream, remoteId?: PeerId): Promise<SecuredConnection<Stream>> {
|
|
70
|
+
const signal = AbortSignal.timeout(this.timeout)
|
|
71
|
+
const pb = pbStream(conn).pb(Exchange)
|
|
68
72
|
|
|
69
73
|
let type = KeyType.RSA
|
|
70
74
|
|
|
@@ -75,45 +79,40 @@ class Plaintext implements ConnectionEncrypter {
|
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
// Encode the public key and write it to the remote peer
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
)
|
|
82
|
+
await pb.write({
|
|
83
|
+
id: localId.toBytes(),
|
|
84
|
+
pubkey: {
|
|
85
|
+
Type: type,
|
|
86
|
+
Data: localId.publicKey ?? new Uint8Array(0)
|
|
87
|
+
}
|
|
88
|
+
}, {
|
|
89
|
+
signal
|
|
90
|
+
})
|
|
87
91
|
|
|
88
92
|
this.log('write pubkey exchange to peer %p', remoteId)
|
|
89
93
|
|
|
90
94
|
// Get the Exchange message
|
|
91
|
-
const response =
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
throw new Error('Did not read response')
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const id = Exchange.decode(response)
|
|
98
|
-
this.log('read pubkey exchange from peer %p', remoteId)
|
|
95
|
+
const response = await pb.read({
|
|
96
|
+
signal
|
|
97
|
+
})
|
|
99
98
|
|
|
100
99
|
let peerId
|
|
101
100
|
try {
|
|
102
|
-
if (
|
|
101
|
+
if (response.pubkey == null) {
|
|
103
102
|
throw new Error('Public key missing')
|
|
104
103
|
}
|
|
105
104
|
|
|
106
|
-
if (
|
|
105
|
+
if (response.pubkey.Data.length === 0) {
|
|
107
106
|
throw new Error('Public key data too short')
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
if (
|
|
109
|
+
if (response.id == null) {
|
|
111
110
|
throw new Error('Remote id missing')
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
peerId = await peerIdFromKeys(
|
|
113
|
+
peerId = await peerIdFromKeys(response.pubkey.Data)
|
|
115
114
|
|
|
116
|
-
if (!peerId.equals(peerIdFromBytes(
|
|
115
|
+
if (!peerId.equals(peerIdFromBytes(response.id))) {
|
|
117
116
|
throw new Error('Public key did not match id')
|
|
118
117
|
}
|
|
119
118
|
} catch (err: any) {
|
|
@@ -127,18 +126,13 @@ class Plaintext implements ConnectionEncrypter {
|
|
|
127
126
|
|
|
128
127
|
this.log('plaintext key exchange completed successfully with peer %p', peerId)
|
|
129
128
|
|
|
130
|
-
shake.rest()
|
|
131
|
-
|
|
132
129
|
return {
|
|
133
|
-
conn:
|
|
134
|
-
sink: shake.stream.sink,
|
|
135
|
-
source: map(shake.stream.source, (buf) => buf.subarray())
|
|
136
|
-
},
|
|
130
|
+
conn: pb.unwrap().unwrap(),
|
|
137
131
|
remotePeer: peerId
|
|
138
132
|
}
|
|
139
133
|
}
|
|
140
134
|
}
|
|
141
135
|
|
|
142
|
-
export function plaintext (): (components: PlaintextComponents) => ConnectionEncrypter {
|
|
143
|
-
return (components) => new Plaintext(components)
|
|
136
|
+
export function plaintext (init?: PlaintextInit): (components: PlaintextComponents) => ConnectionEncrypter {
|
|
137
|
+
return (components) => new Plaintext(components, init)
|
|
144
138
|
}
|