@libp2p/peer-collections 5.1.10 → 5.1.11-3bc94b403
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/README.md +16 -2
- package/dist/index.min.js +6 -1
- package/dist/src/filter.d.ts +13 -0
- package/dist/src/filter.d.ts.map +1 -0
- package/dist/src/filter.js +21 -0
- package/dist/src/filter.js.map +1 -0
- package/dist/src/index.d.ts +15 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +15 -0
- package/dist/src/index.js.map +1 -1
- package/package.json +5 -4
- package/src/filter.ts +26 -0
- package/src/index.ts +15 -0
- package/dist/typedoc-urls.json +0 -11
package/README.md
CHANGED
|
@@ -108,6 +108,20 @@ const set = trackedPeerSet({ name: 'my_metric_name', metrics: libp2p.metrics })
|
|
|
108
108
|
set.add(peerId)
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
+
## Example - Peer filters
|
|
112
|
+
|
|
113
|
+
```TypeScript
|
|
114
|
+
import { peerFilter } from '@libp2p/peer-collections'
|
|
115
|
+
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
|
|
116
|
+
|
|
117
|
+
const peerId = await createEd25519PeerId()
|
|
118
|
+
|
|
119
|
+
const filter = peerFilter(1024)
|
|
120
|
+
filter.has(peerId) // false
|
|
121
|
+
filter.add(peerId)
|
|
122
|
+
filter.has(peerId) // true
|
|
123
|
+
```
|
|
124
|
+
|
|
111
125
|
# Install
|
|
112
126
|
|
|
113
127
|
```console
|
|
@@ -130,8 +144,8 @@ Loading this module through a script tag will make it's exports available as `Li
|
|
|
130
144
|
|
|
131
145
|
Licensed under either of
|
|
132
146
|
|
|
133
|
-
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
134
|
-
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
147
|
+
- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/peer-collections/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
148
|
+
- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/peer-collections/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
135
149
|
|
|
136
150
|
# Contribution
|
|
137
151
|
|
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPeerCollections = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PPeerCollections=(()=>{var ee=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var d=(r,e)=>{for(var t in e)ee(r,t,{get:e[t],enumerable:!0})},st=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of nt(e))!ot.call(r,o)&&o!==t&&ee(r,o,{get:()=>e[o],enumerable:!(n=rt(e,o))||n.enumerable});return r};var it=r=>st(ee({},"__esModule",{value:!0}),r);var mr={};d(mr,{PeerList:()=>z,PeerMap:()=>M,PeerSet:()=>U,peerList:()=>Ye,peerMap:()=>Xe,peerSet:()=>We,trackedPeerList:()=>et,trackedPeerMap:()=>Ze,trackedPeerSet:()=>_e});var Ie=Symbol.for("@libp2p/peer-id");var se={};d(se,{base58btc:()=>l,base58flickr:()=>ft});var gr=new Uint8Array(0);function De(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function C(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Me(r){return new TextEncoder().encode(r)}function Ue(r){return new TextDecoder().decode(r)}function at(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var c=r.length,h=r.charAt(0),N=Math.log(c)/Math.log(256),m=Math.log(256)/Math.log(c);function O(a){if(a instanceof Uint8Array||(ArrayBuffer.isView(a)?a=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):Array.isArray(a)&&(a=Uint8Array.from(a))),!(a instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(a.length===0)return"";for(var f=0,L=0,x=0,w=a.length;x!==w&&a[x]===0;)x++,f++;for(var y=(w-x)*m+1>>>0,b=new Uint8Array(y);x!==w;){for(var v=a[x],A=0,g=y-1;(v!==0||A<L)&&g!==-1;g--,A++)v+=256*b[g]>>>0,b[g]=v%c>>>0,v=v/c>>>0;if(v!==0)throw new Error("Non-zero carry");L=A,x++}for(var S=y-L;S!==y&&b[S]===0;)S++;for(var W=h.repeat(f);S<y;++S)W+=r.charAt(b[S]);return W}function X(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var f=0;if(a[f]!==" "){for(var L=0,x=0;a[f]===h;)L++,f++;for(var w=(a.length-f)*N+1>>>0,y=new Uint8Array(w);a[f];){var b=t[a.charCodeAt(f)];if(b===255)return;for(var v=0,A=w-1;(b!==0||v<x)&&A!==-1;A--,v++)b+=c*y[A]>>>0,y[A]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");x=v,f++}if(a[f]!==" "){for(var g=w-x;g!==w&&y[g]===0;)g++;for(var S=new Uint8Array(L+(w-g)),W=L;g!==w;)S[W++]=y[g++];return S}}}function tt(a){var f=X(a);if(f)return f;throw new Error(`Non-${e} character`)}return{encode:O,decodeUnsafe:X,decode:tt}}var ct=at,pt=ct,Le=pt;var te=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},re=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Pe(this,e)}},ne=class{decoders;constructor(e){this.decoders=e}or(e){return Pe(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Pe(r,e){return new ne({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var oe=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new te(e,t,n),this.decoder=new re(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function B({name:r,prefix:e,encode:t,decode:n}){return new oe(r,e,t,n)}function I({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Le(t,r);return B({prefix:e,name:r,encode:n,decode:s=>C(o(s))})}function ut(r,e,t,n){let o={};for(let m=0;m<e.length;++m)o[e[m]]=m;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),c=0,h=0,N=0;for(let m=0;m<s;++m){let O=o[r[m]];if(O===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<t|O,c+=t,c>=8&&(c-=8,i[N++]=255&h>>c)}if(c>=t||255&h<<8-c)throw new SyntaxError("Unexpected end of data");return i}function ht(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,c=0;for(let h=0;h<r.length;++h)for(c=c<<8|r[h],i+=8;i>t;)i-=t,s+=e[o&c>>i];if(i!==0&&(s+=e[o&c<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function p({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return B({prefix:e,name:r,encode(o){return ht(o,n,t)},decode(o){return ut(o,n,t,r)}})}var l=I({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ft=I({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ie={};d(ie,{base10:()=>dt});var dt=I({prefix:"9",name:"base10",alphabet:"0123456789"});var ae={};d(ae,{base16:()=>lt,base16upper:()=>mt});var lt=p({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),mt=p({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ce={};d(ce,{base2:()=>bt});var bt=p({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pe={};d(pe,{base256emoji:()=>vt});var Ne=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}"),xt=Ne.reduce((r,e,t)=>(r[t]=e,r),[]),gt=Ne.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function wt(r){return r.reduce((e,t)=>(e+=xt[t],e),"")}function yt(r){let e=[];for(let t of r){let n=gt[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var vt=B({prefix:"\u{1F680}",name:"base256emoji",encode:wt,decode:yt});var ue={};d(ue,{base32:()=>T,base32hex:()=>At,base32hexpad:()=>Dt,base32hexpadupper:()=>Mt,base32hexupper:()=>It,base32pad:()=>Ct,base32padupper:()=>Et,base32upper:()=>St,base32z:()=>Ut});var T=p({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),St=p({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ct=p({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Et=p({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),At=p({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),It=p({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Dt=p({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Mt=p({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ut=p({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var he={};d(he,{base36:()=>zt,base36upper:()=>Lt});var zt=I({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Lt=I({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var fe={};d(fe,{base64:()=>Pt,base64pad:()=>Nt,base64url:()=>Ot,base64urlpad:()=>Bt});var Pt=p({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Nt=p({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ot=p({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Bt=p({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var de={};d(de,{base8:()=>Tt});var Tt=p({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var le={};d(le,{identity:()=>kt});var kt=B({prefix:"\0",name:"identity",encode:r=>Ue(r),decode:r=>Me(r)});var Or=new TextEncoder,Br=new TextDecoder;var be={};d(be,{identity:()=>Z});var Vt=Te,Oe=128,qt=127,jt=~qt,$t=Math.pow(2,31);function Te(r,e,t){e=e||[],t=t||0;for(var n=t;r>=$t;)e[t++]=r&255|Oe,r/=128;for(;r&jt;)e[t++]=r&255|Oe,r>>>=7;return e[t]=r|0,Te.bytes=t-n+1,e}var Kt=me,Jt=128,Be=127;function me(r,n){var t=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw me.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Be)<<o:(i&Be)*Math.pow(2,o),o+=7}while(i>=Jt);return me.bytes=s-n,t}var Gt=Math.pow(2,7),Ht=Math.pow(2,14),Qt=Math.pow(2,21),Xt=Math.pow(2,28),Wt=Math.pow(2,35),Yt=Math.pow(2,42),Zt=Math.pow(2,49),_t=Math.pow(2,56),er=Math.pow(2,63),tr=function(r){return r<Gt?1:r<Ht?2:r<Qt?3:r<Xt?4:r<Wt?5:r<Yt?6:r<Zt?7:r<_t?8:r<er?9:10},rr={encode:Vt,decode:Kt,encodingLength:tr},nr=rr,q=nr;function j(r,e=0){return[q.decode(r,e),q.decode.bytes]}function k(r,e,t=0){return q.encode(r,e,t),e}function R(r){return q.encodingLength(r)}function D(r,e){let t=e.byteLength,n=R(r),o=n+R(t),s=new Uint8Array(o+t);return k(r,s,0),k(t,s,n),s.set(e,o),new F(r,t,e,s)}function $(r){let e=C(r),[t,n]=j(e),[o,s]=j(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new F(t,o,i,e)}function ke(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&De(r.bytes,t.bytes)}}var F=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Re=0,or="identity",Fe=C;function sr(r){return D(Re,Fe(r))}var Z={code:Re,name:or,encode:Fe,digest:sr};var we={};d(we,{sha256:()=>_,sha512:()=>ir});function ge({name:r,code:e,encode:t}){return new xe(r,e,t)}var xe=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?D(this.code,t):t.then(n=>D(this.code,n))}else throw Error("Unknown type, must be binary type")}};function qe(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var _=ge({name:"sha2-256",code:18,encode:qe("SHA-256")}),ir=ge({name:"sha2-512",code:19,encode:qe("SHA-512")});function je(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return cr(t,ye(r),e??l.encoder);default:return pr(t,ye(r),e??T.encoder)}}var $e=new WeakMap;function ye(r){let e=$e.get(r);if(e==null){let t=new Map;return $e.set(r,t),t}return e}var P=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==K)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==ur)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=D(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&ke(e.multihash,n.multihash)}toString(e){return je(this,e)}toJSON(){return{"/":je(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??Ke(n,o,s.bytes))}else if(t[hr]===!0){let{version:n,multihash:o,code:s}=t,i=$(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==K)throw new Error(`Version 0 CID must use dag-pb (code: ${K}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Ke(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,K,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=C(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new F(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[O,X]=j(e.subarray(t));return t+=X,O},o=n(),s=K;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,c=n(),h=n(),N=t+h,m=N-i;return{version:o,codec:s,multihashCode:c,digestSize:h,multihashSize:m,size:N}}static parse(e,t){let[n,o]=ar(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ye(s).set(n,e),s}};function ar(r,e){switch(r[0]){case"Q":{let t=e??l;return[l.prefix,t.decode(`${l.prefix}${r}`)]}case l.prefix:{let t=e??l;return[l.prefix,t.decode(r)]}case T.prefix:{let t=e??T;return[T.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function cr(r,e,t){let{prefix:n}=t;if(n!==l.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function pr(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var K=112,ur=18;function Ke(r,e,t){let n=R(r),o=n+R(e),s=new Uint8Array(o+t.byteLength);return k(r,s,0),k(e,s,n),s.set(t,o),s}var hr=Symbol.for("@ipld/js-cid/CID");var ve={...le,...ce,...de,...ie,...ae,...ue,...he,...se,...fe,...pe},rn={...we,...be};function Se(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var fr=Symbol.for("nodejs.util.inspect.custom"),Je=Object.values(ve).map(r=>r.decoder).reduce((r,e)=>r.or(e),ve.identity.decoder),Ge=114,He=36,Qe=37,J=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ie]=!0;toString(){return this.string==null&&(this.string=l.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return P.createV1(Ge,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Se(this.multihash.bytes,e);if(typeof e=="string")return u(e).equals(this);if(e?.multihash?.bytes!=null)return Se(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[fr](){return`PeerId(${this.toString()})`}},G=class extends J{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},H=class extends J{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},Q=class extends J{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function u(r,e){if(e=e??Je,r.charAt(0)==="1"||r.charAt(0)==="Q"){let t=$(l.decode(`z${r}`));return r.startsWith("12D")?new H({multihash:t}):r.startsWith("16U")?new Q({multihash:t}):new G({multihash:t})}return dr(Je.decode(r))}function dr(r){try{let e=$(r);if(e.code===Z.code){if(e.digest.length===He)return new H({multihash:e});if(e.digest.length===Qe)return new Q({multihash:e})}if(e.code===_.code)return new G({multihash:e})}catch{return lr(P.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function lr(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Ge)throw new Error("Supplied PeerID CID is invalid");let e=r.multihash;if(e.code===_.code)return new G({multihash:r.multihash});if(e.code===Z.code){if(e.digest.length===He)return new H({multihash:r.multihash});if(e.digest.length===Qe)return new Q({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}function E(r,e){let t={[Symbol.iterator]:()=>t,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:e(o)}}};return t}var M=class{map;constructor(e){if(this.map=new Map,e!=null)for(let[t,n]of e.entries())this.map.set(t.toString(),n)}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(e){return this.map.delete(e.toString())}entries(){return E(this.map.entries(),e=>[u(e[0]),e[1]])}forEach(e){this.map.forEach((t,n)=>{e(t,u(n),this)})}get(e){return this.map.get(e.toString())}has(e){return this.map.has(e.toString())}set(e,t){this.map.set(e.toString(),t)}keys(){return E(this.map.keys(),e=>u(e))}values(){return this.map.values()}get size(){return this.map.size}};function Xe(){return new M}var U=class r{set;constructor(e){if(this.set=new Set,e!=null)for(let t of e)this.set.add(t.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(e){this.set.add(e.toString())}clear(){this.set.clear()}delete(e){this.set.delete(e.toString())}entries(){return E(this.set.entries(),e=>{let t=u(e[0]);return[t,t]})}forEach(e){this.set.forEach(t=>{let n=u(t);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return E(this.set.values(),e=>u(e))}intersection(e){let t=new r;for(let n of e)this.has(n)&&t.add(n);return t}difference(e){let t=new r;for(let n of this)e.has(n)||t.add(n);return t}union(e){let t=new r;for(let n of e)t.add(n);for(let n of this)t.add(n);return t}};function We(){return new U}var z=class r{list;constructor(e){if(this.list=[],e!=null)for(let t of e)this.list.push(t.toString())}[Symbol.iterator](){return E(this.list.entries(),e=>u(e[1]))}concat(e){let t=new r(this);for(let n of e)t.push(n);return t}entries(){return E(this.list.entries(),e=>[e[0],u(e[1])])}every(e){return this.list.every((t,n)=>e(u(t),n,this))}filter(e){let t=new r;return this.list.forEach((n,o)=>{let s=u(n);e(s,o,this)&&t.push(s)}),t}find(e){let t=this.list.find((n,o)=>e(u(n),o,this));if(t!=null)return u(t)}findIndex(e){return this.list.findIndex((t,n)=>e(u(t),n,this))}forEach(e){this.list.forEach((t,n)=>{e(u(t),n,this)})}includes(e){return this.list.includes(e.toString())}indexOf(e){return this.list.indexOf(e.toString())}pop(){let e=this.list.pop();if(e!=null)return u(e)}push(...e){for(let t of e)this.list.push(t.toString())}shift(){let e=this.list.shift();if(e!=null)return u(e)}unshift(...e){let t=this.list.length;for(let n=e.length-1;n>-1;n--)t=this.list.unshift(e[n].toString());return t}clear(){this.list=[]}get length(){return this.list.length}};function Ye(){return new z}var Ce=class extends M{metric;constructor(e){super();let{name:t,metrics:n}=e;this.metric=n.registerMetric(t),this.updateComponentMetric()}set(e,t){return super.set(e,t),this.updateComponentMetric(),this}delete(e){let t=super.delete(e);return this.updateComponentMetric(),t}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Ze(r){let{name:e,metrics:t}=r,n;return t!=null?n=new Ce({name:e,metrics:t}):n=new M,n}var Ee=class extends U{metric;constructor(e){super();let{name:t,metrics:n}=e;this.metric=n.registerMetric(t),this.updateComponentMetric()}add(e){super.add(e),this.updateComponentMetric()}delete(e){super.delete(e),this.updateComponentMetric()}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function _e(r){let{name:e,metrics:t}=r,n;return t!=null?n=new Ee({name:e,metrics:t}):n=new U,n}var Ae=class extends z{metric;constructor(e){super();let{name:t,metrics:n}=e;this.metric=n.registerMetric(t),this.updateComponentMetric()}pop(){let e=super.pop();return this.updateComponentMetric(),e}push(...e){super.push(...e),this.updateComponentMetric()}shift(){let e=super.shift();return this.updateComponentMetric(),e}unshift(...e){let t=super.unshift(...e);return this.updateComponentMetric(),t}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.length)}};function et(r){let{name:e,metrics:t}=r,n;return t!=null?n=new Ae({name:e,metrics:t}):n=new z,n}return it(mr);})();
|
|
2
|
+
"use strict";var Libp2PPeerCollections=(()=>{var Ne=Object.create;var ct=Object.defineProperty;var Ve=Object.getOwnPropertyDescriptor;var Be=Object.getOwnPropertyNames;var Te=Object.getPrototypeOf,ke=Object.prototype.hasOwnProperty;var Kt=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),C=(n,t)=>{for(var e in t)ct(n,e,{get:t[e],enumerable:!0})},Jt=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Be(t))!ke.call(n,o)&&o!==e&&ct(n,o,{get:()=>t[o],enumerable:!(r=Ve(t,o))||r.enumerable});return n};var _e=(n,t,e)=>(e=n!=null?Ne(Te(n)):{},Jt(t||!n||!n.__esModule?ct(e,"default",{value:n,enumerable:!0}):e,n)),Pe=n=>Jt(ct({},"__esModule",{value:!0}),n);var Ee=Kt((nt,mt)=>{(function(n,t){"use strict";var e={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function r(s){if(!Array.isArray(s)&&!ArrayBuffer.isView(s))return!1;for(var i=0;i<s.length;i++)if(!Number.isInteger(s[i])||s[i]<0||s[i]>255)return!1;return!0}function o(s,i){return(s&65535)*i+(((s>>>16)*i&65535)<<16)}function a(s,i){return s<<i|s>>>32-i}function d(s){return s^=s>>>16,s=o(s,2246822507),s^=s>>>13,s=o(s,3266489909),s^=s>>>16,s}function g(s,i){s=[s[0]>>>16,s[0]&65535,s[1]>>>16,s[1]&65535],i=[i[0]>>>16,i[0]&65535,i[1]>>>16,i[1]&65535];var c=[0,0,0,0];return c[3]+=s[3]+i[3],c[2]+=c[3]>>>16,c[3]&=65535,c[2]+=s[2]+i[2],c[1]+=c[2]>>>16,c[2]&=65535,c[1]+=s[1]+i[1],c[0]+=c[1]>>>16,c[1]&=65535,c[0]+=s[0]+i[0],c[0]&=65535,[c[0]<<16|c[1],c[2]<<16|c[3]]}function x(s,i){s=[s[0]>>>16,s[0]&65535,s[1]>>>16,s[1]&65535],i=[i[0]>>>16,i[0]&65535,i[1]>>>16,i[1]&65535];var c=[0,0,0,0];return c[3]+=s[3]*i[3],c[2]+=c[3]>>>16,c[3]&=65535,c[2]+=s[2]*i[3],c[1]+=c[2]>>>16,c[2]&=65535,c[2]+=s[3]*i[2],c[1]+=c[2]>>>16,c[2]&=65535,c[1]+=s[1]*i[3],c[0]+=c[1]>>>16,c[1]&=65535,c[1]+=s[2]*i[2],c[0]+=c[1]>>>16,c[1]&=65535,c[1]+=s[3]*i[1],c[0]+=c[1]>>>16,c[1]&=65535,c[0]+=s[0]*i[3]+s[1]*i[2]+s[2]*i[1]+s[3]*i[0],c[0]&=65535,[c[0]<<16|c[1],c[2]<<16|c[3]]}function L(s,i){return i%=64,i===32?[s[1],s[0]]:i<32?[s[0]<<i|s[1]>>>32-i,s[1]<<i|s[0]>>>32-i]:(i-=32,[s[1]<<i|s[0]>>>32-i,s[0]<<i|s[1]>>>32-i])}function w(s,i){return i%=64,i===0?s:i<32?[s[0]<<i|s[1]>>>32-i,s[1]<<i]:[s[1]<<i-32,0]}function m(s,i){return[s[0]^i[0],s[1]^i[1]]}function U(s){return s=m(s,[0,s[0]>>>1]),s=x(s,[4283543511,3981806797]),s=m(s,[0,s[0]>>>1]),s=x(s,[3301882366,444984403]),s=m(s,[0,s[0]>>>1]),s}e.x86.hash32=function(s,i){if(e.inputValidation&&!r(s))return t;i=i||0;for(var c=s.length%4,D=s.length-c,f=i,u=0,p=3432918353,l=461845907,b=0;b<D;b=b+4)u=s[b]|s[b+1]<<8|s[b+2]<<16|s[b+3]<<24,u=o(u,p),u=a(u,15),u=o(u,l),f^=u,f=a(f,13),f=o(f,5)+3864292196;switch(u=0,c){case 3:u^=s[b+2]<<16;case 2:u^=s[b+1]<<8;case 1:u^=s[b],u=o(u,p),u=a(u,15),u=o(u,l),f^=u}return f^=s.length,f=d(f),f>>>0},e.x86.hash128=function(s,i){if(e.inputValidation&&!r(s))return t;i=i||0;for(var c=s.length%16,D=s.length-c,f=i,u=i,p=i,l=i,b=0,y=0,h=0,S=0,R=597399067,st=2869860233,it=951274213,at=2716044179,v=0;v<D;v=v+16)b=s[v]|s[v+1]<<8|s[v+2]<<16|s[v+3]<<24,y=s[v+4]|s[v+5]<<8|s[v+6]<<16|s[v+7]<<24,h=s[v+8]|s[v+9]<<8|s[v+10]<<16|s[v+11]<<24,S=s[v+12]|s[v+13]<<8|s[v+14]<<16|s[v+15]<<24,b=o(b,R),b=a(b,15),b=o(b,st),f^=b,f=a(f,19),f+=u,f=o(f,5)+1444728091,y=o(y,st),y=a(y,16),y=o(y,it),u^=y,u=a(u,17),u+=p,u=o(u,5)+197830471,h=o(h,it),h=a(h,17),h=o(h,at),p^=h,p=a(p,15),p+=l,p=o(p,5)+2530024501,S=o(S,at),S=a(S,18),S=o(S,R),l^=S,l=a(l,13),l+=f,l=o(l,5)+850148119;switch(b=0,y=0,h=0,S=0,c){case 15:S^=s[v+14]<<16;case 14:S^=s[v+13]<<8;case 13:S^=s[v+12],S=o(S,at),S=a(S,18),S=o(S,R),l^=S;case 12:h^=s[v+11]<<24;case 11:h^=s[v+10]<<16;case 10:h^=s[v+9]<<8;case 9:h^=s[v+8],h=o(h,it),h=a(h,17),h=o(h,at),p^=h;case 8:y^=s[v+7]<<24;case 7:y^=s[v+6]<<16;case 6:y^=s[v+5]<<8;case 5:y^=s[v+4],y=o(y,st),y=a(y,16),y=o(y,it),u^=y;case 4:b^=s[v+3]<<24;case 3:b^=s[v+2]<<16;case 2:b^=s[v+1]<<8;case 1:b^=s[v],b=o(b,R),b=a(b,15),b=o(b,st),f^=b}return f^=s.length,u^=s.length,p^=s.length,l^=s.length,f+=u,f+=p,f+=l,u+=f,p+=f,l+=f,f=d(f),u=d(u),p=d(p),l=d(l),f+=u,f+=p,f+=l,u+=f,p+=f,l+=f,("00000000"+(f>>>0).toString(16)).slice(-8)+("00000000"+(u>>>0).toString(16)).slice(-8)+("00000000"+(p>>>0).toString(16)).slice(-8)+("00000000"+(l>>>0).toString(16)).slice(-8)},e.x64.hash128=function(s,i){if(e.inputValidation&&!r(s))return t;i=i||0;for(var c=s.length%16,D=s.length-c,f=[0,i],u=[0,i],p=[0,0],l=[0,0],b=[2277735313,289559509],y=[1291169091,658871167],h=0;h<D;h=h+16)p=[s[h+4]|s[h+5]<<8|s[h+6]<<16|s[h+7]<<24,s[h]|s[h+1]<<8|s[h+2]<<16|s[h+3]<<24],l=[s[h+12]|s[h+13]<<8|s[h+14]<<16|s[h+15]<<24,s[h+8]|s[h+9]<<8|s[h+10]<<16|s[h+11]<<24],p=x(p,b),p=L(p,31),p=x(p,y),f=m(f,p),f=L(f,27),f=g(f,u),f=g(x(f,[0,5]),[0,1390208809]),l=x(l,y),l=L(l,33),l=x(l,b),u=m(u,l),u=L(u,31),u=g(u,f),u=g(x(u,[0,5]),[0,944331445]);switch(p=[0,0],l=[0,0],c){case 15:l=m(l,w([0,s[h+14]],48));case 14:l=m(l,w([0,s[h+13]],40));case 13:l=m(l,w([0,s[h+12]],32));case 12:l=m(l,w([0,s[h+11]],24));case 11:l=m(l,w([0,s[h+10]],16));case 10:l=m(l,w([0,s[h+9]],8));case 9:l=m(l,[0,s[h+8]]),l=x(l,y),l=L(l,33),l=x(l,b),u=m(u,l);case 8:p=m(p,w([0,s[h+7]],56));case 7:p=m(p,w([0,s[h+6]],48));case 6:p=m(p,w([0,s[h+5]],40));case 5:p=m(p,w([0,s[h+4]],32));case 4:p=m(p,w([0,s[h+3]],24));case 3:p=m(p,w([0,s[h+2]],16));case 2:p=m(p,w([0,s[h+1]],8));case 1:p=m(p,[0,s[h]]),p=x(p,b),p=L(p,31),p=x(p,y),f=m(f,p)}return f=m(f,[0,s.length]),u=m(u,[0,s.length]),f=g(f,u),u=g(u,f),f=U(f),u=U(u),f=g(f,u),u=g(u,f),("00000000"+(f[0]>>>0).toString(16)).slice(-8)+("00000000"+(f[1]>>>0).toString(16)).slice(-8)+("00000000"+(u[0]>>>0).toString(16)).slice(-8)+("00000000"+(u[1]>>>0).toString(16)).slice(-8)},typeof nt<"u"?(typeof mt<"u"&&mt.exports&&(nt=mt.exports=e),nt.murmurHash3=e):typeof define=="function"&&define.amd?define([],function(){return e}):(e._murmurHash3=n.murmurHash3,e.noConflict=function(){return n.murmurHash3=e._murmurHash3,e._murmurHash3=t,e.noConflict=t,e},n.murmurHash3=e)})(nt)});var Ue=Kt((Mo,Le)=>{Le.exports=Ee()});var Yr={};C(Yr,{PeerFilter:()=>ot,PeerList:()=>_,PeerMap:()=>T,PeerSet:()=>k,peerFilter:()=>Ie,peerList:()=>we,peerMap:()=>ge,peerSet:()=>xe,trackedPeerList:()=>Oe,trackedPeerMap:()=>Me,trackedPeerSet:()=>Re});var Gt=Symbol.for("@libp2p/peer-id");var ft=class extends Error{code;props;constructor(t,e,r){super(t),this.code=e,this.name=r?.name??"CodeError",this.props=r??{}}};var At={};C(At,{base58btc:()=>I,base58flickr:()=>He});var rn=new Uint8Array(0);function Xt(n,t){if(n===t)return!0;if(n.byteLength!==t.byteLength)return!1;for(let e=0;e<n.byteLength;e++)if(n[e]!==t[e])return!1;return!0}function O(n){if(n instanceof Uint8Array&&n.constructor.name==="Uint8Array")return n;if(n instanceof ArrayBuffer)return new Uint8Array(n);if(ArrayBuffer.isView(n))return new Uint8Array(n.buffer,n.byteOffset,n.byteLength);throw new Error("Unknown type, must be binary type")}function Qt(n){return new TextEncoder().encode(n)}function Wt(n){return new TextDecoder().decode(n)}function ze(n,t){if(n.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),r=0;r<e.length;r++)e[r]=255;for(var o=0;o<n.length;o++){var a=n.charAt(o),d=a.charCodeAt(0);if(e[d]!==255)throw new TypeError(a+" is ambiguous");e[d]=o}var g=n.length,x=n.charAt(0),L=Math.log(g)/Math.log(256),w=Math.log(256)/Math.log(g);function m(i){if(i instanceof Uint8Array||(ArrayBuffer.isView(i)?i=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):Array.isArray(i)&&(i=Uint8Array.from(i))),!(i instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(i.length===0)return"";for(var c=0,D=0,f=0,u=i.length;f!==u&&i[f]===0;)f++,c++;for(var p=(u-f)*w+1>>>0,l=new Uint8Array(p);f!==u;){for(var b=i[f],y=0,h=p-1;(b!==0||y<D)&&h!==-1;h--,y++)b+=256*l[h]>>>0,l[h]=b%g>>>0,b=b/g>>>0;if(b!==0)throw new Error("Non-zero carry");D=y,f++}for(var S=p-D;S!==p&&l[S]===0;)S++;for(var R=x.repeat(c);S<p;++S)R+=n.charAt(l[S]);return R}function U(i){if(typeof i!="string")throw new TypeError("Expected String");if(i.length===0)return new Uint8Array;var c=0;if(i[c]!==" "){for(var D=0,f=0;i[c]===x;)D++,c++;for(var u=(i.length-c)*L+1>>>0,p=new Uint8Array(u);i[c];){var l=e[i.charCodeAt(c)];if(l===255)return;for(var b=0,y=u-1;(l!==0||b<f)&&y!==-1;y--,b++)l+=g*p[y]>>>0,p[y]=l%256>>>0,l=l/256>>>0;if(l!==0)throw new Error("Non-zero carry");f=b,c++}if(i[c]!==" "){for(var h=u-f;h!==u&&p[h]===0;)h++;for(var S=new Uint8Array(D+(u-h)),R=D;h!==u;)S[R++]=p[h++];return S}}}function s(i){var c=U(i);if(c)return c;throw new Error(`Non-${t} character`)}return{encode:m,decodeUnsafe:U,decode:s}}var Fe=ze,je=Fe,Zt=je;var wt=class{name;prefix;baseEncode;constructor(t,e,r){this.name=t,this.prefix=e,this.baseEncode=r}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},yt=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,r){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=r}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 te(this,t)}},vt=class{decoders;constructor(t){this.decoders=t}or(t){return te(this,t)}decode(t){let e=t[0],r=this.decoders[e];if(r!=null)return r.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function te(n,t){return new vt({...n.decoders??{[n.prefix]:n},...t.decoders??{[t.prefix]:t}})}var St=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,r,o){this.name=t,this.prefix=e,this.baseEncode=r,this.baseDecode=o,this.encoder=new wt(t,e,r),this.decoder=new yt(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function F({name:n,prefix:t,encode:e,decode:r}){return new St(n,t,e,r)}function V({name:n,prefix:t,alphabet:e}){let{encode:r,decode:o}=Zt(e,n);return F({prefix:t,name:n,encode:r,decode:a=>O(o(a))})}function qe(n,t,e,r){let o={};for(let w=0;w<t.length;++w)o[t[w]]=w;let a=n.length;for(;n[a-1]==="=";)--a;let d=new Uint8Array(a*e/8|0),g=0,x=0,L=0;for(let w=0;w<a;++w){let m=o[n[w]];if(m===void 0)throw new SyntaxError(`Non-${r} character`);x=x<<e|m,g+=e,g>=8&&(g-=8,d[L++]=255&x>>g)}if(g>=e||255&x<<8-g)throw new SyntaxError("Unexpected end of data");return d}function $e(n,t,e){let r=t[t.length-1]==="=",o=(1<<e)-1,a="",d=0,g=0;for(let x=0;x<n.length;++x)for(g=g<<8|n[x],d+=8;d>e;)d-=e,a+=t[o&g>>d];if(d!==0&&(a+=t[o&g<<e-d]),r)for(;a.length*e&7;)a+="=";return a}function A({name:n,prefix:t,bitsPerChar:e,alphabet:r}){return F({prefix:t,name:n,encode(o){return $e(o,r,e)},decode(o){return qe(o,r,e,n)}})}var I=V({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),He=V({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Et={};C(Et,{base10:()=>Ke});var Ke=V({prefix:"9",name:"base10",alphabet:"0123456789"});var Lt={};C(Lt,{base16:()=>Je,base16upper:()=>Ge});var Je=A({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ge=A({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ut={};C(Ut,{base2:()=>Xe});var Xe=A({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Dt={};C(Dt,{base256emoji:()=>tr});var ee=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}"),Qe=ee.reduce((n,t,e)=>(n[e]=t,n),[]),We=ee.reduce((n,t,e)=>(n[t.codePointAt(0)]=e,n),[]);function Ye(n){return n.reduce((t,e)=>(t+=Qe[e],t),"")}function Ze(n){let t=[];for(let e of n){let r=We[e.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${e}`);t.push(r)}return new Uint8Array(t)}var tr=F({prefix:"\u{1F680}",name:"base256emoji",encode:Ye,decode:Ze});var Ct={};C(Ct,{base32:()=>j,base32hex:()=>or,base32hexpad:()=>ir,base32hexpadupper:()=>ar,base32hexupper:()=>sr,base32pad:()=>rr,base32padupper:()=>nr,base32upper:()=>er,base32z:()=>cr});var j=A({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),er=A({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),rr=A({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),nr=A({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),or=A({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),sr=A({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ir=A({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ar=A({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),cr=A({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var It={};C(It,{base36:()=>fr,base36upper:()=>ur});var fr=V({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ur=V({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Mt={};C(Mt,{base64:()=>hr,base64pad:()=>pr,base64url:()=>lr,base64urlpad:()=>dr});var hr=A({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),pr=A({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),lr=A({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),dr=A({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Rt={};C(Rt,{base8:()=>mr});var mr=A({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ot={};C(Ot,{identity:()=>br});var br=F({prefix:"\0",name:"identity",encode:n=>Wt(n),decode:n=>Qt(n)});var wn=new TextEncoder,yn=new TextDecoder;var Vt={};C(Vt,{identity:()=>ht});var wr=oe,re=128,yr=127,vr=~yr,Sr=Math.pow(2,31);function oe(n,t,e){t=t||[],e=e||0;for(var r=e;n>=Sr;)t[e++]=n&255|re,n/=128;for(;n&vr;)t[e++]=n&255|re,n>>>=7;return t[e]=n|0,oe.bytes=e-r+1,t}var Ar=Nt,Er=128,ne=127;function Nt(n,r){var e=0,r=r||0,o=0,a=r,d,g=n.length;do{if(a>=g)throw Nt.bytes=0,new RangeError("Could not decode varint");d=n[a++],e+=o<28?(d&ne)<<o:(d&ne)*Math.pow(2,o),o+=7}while(d>=Er);return Nt.bytes=a-r,e}var Lr=Math.pow(2,7),Ur=Math.pow(2,14),Dr=Math.pow(2,21),Cr=Math.pow(2,28),Ir=Math.pow(2,35),Mr=Math.pow(2,42),Rr=Math.pow(2,49),Or=Math.pow(2,56),Nr=Math.pow(2,63),Vr=function(n){return n<Lr?1:n<Ur?2:n<Dr?3:n<Cr?4:n<Ir?5:n<Mr?6:n<Rr?7:n<Or?8:n<Nr?9:10},Br={encode:wr,decode:Ar,encodingLength:Vr},Tr=Br,G=Tr;function X(n,t=0){return[G.decode(n,t),G.decode.bytes]}function q(n,t,e=0){return G.encode(n,t,e),t}function $(n){return G.encodingLength(n)}function B(n,t){let e=t.byteLength,r=$(n),o=r+$(e),a=new Uint8Array(o+e);return q(n,a,0),q(e,a,r),a.set(t,o),new H(n,e,t,a)}function Q(n){let t=O(n),[e,r]=X(t),[o,a]=X(t.subarray(r)),d=t.subarray(r+a);if(d.byteLength!==o)throw new Error("Incorrect length");return new H(e,o,d,t)}function se(n,t){if(n===t)return!0;{let e=t;return n.code===e.code&&n.size===e.size&&e.bytes instanceof Uint8Array&&Xt(n.bytes,e.bytes)}}var H=class{code;size;digest;bytes;constructor(t,e,r,o){this.code=t,this.size=e,this.digest=r,this.bytes=o}};var ie=0,kr="identity",ae=O;function _r(n){return B(ie,ae(n))}var ht={code:ie,name:kr,encode:ae,digest:_r};var kt={};C(kt,{sha256:()=>pt,sha512:()=>Pr});function Tt({name:n,code:t,encode:e}){return new Bt(n,t,e)}var Bt=class{name;code;encode;constructor(t,e,r){this.name=t,this.code=e,this.encode=r}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?B(this.code,e):e.then(r=>B(this.code,r))}else throw Error("Unknown type, must be binary type")}};function fe(n){return async t=>new Uint8Array(await crypto.subtle.digest(n,t))}var pt=Tt({name:"sha2-256",code:18,encode:fe("SHA-256")}),Pr=Tt({name:"sha2-512",code:19,encode:fe("SHA-512")});function ue(n,t){let{bytes:e,version:r}=n;switch(r){case 0:return Fr(e,_t(n),t??I.encoder);default:return jr(e,_t(n),t??j.encoder)}}var he=new WeakMap;function _t(n){let t=he.get(n);if(t==null){let e=new Map;return he.set(n,e),e}return t}var P=class n{code;version;multihash;bytes;"/";constructor(t,e,r,o){this.code=e,this.version=t,this.multihash=r,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==W)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==qr)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return n.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,r=B(t,e);return n.createV1(this.code,r)}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 n.equals(this,t)}static equals(t,e){let r=e;return r!=null&&t.code===r.code&&t.version===r.version&&se(t.multihash,r.multihash)}toString(t){return ue(this,t)}toJSON(){return{"/":ue(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof n)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:r,code:o,multihash:a,bytes:d}=e;return new n(r,o,a,d??pe(r,o,a.bytes))}else if(e[$r]===!0){let{version:r,multihash:o,code:a}=e,d=Q(o);return n.create(r,a,d)}else return null}static create(t,e,r){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(r.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==W)throw new Error(`Version 0 CID must use dag-pb (code: ${W}) block encoding`);return new n(t,e,r,r.bytes)}case 1:{let o=pe(t,e,r.bytes);return new n(t,e,r,o)}default:throw new Error("Invalid version")}}static createV0(t){return n.create(0,W,t)}static createV1(t,e){return n.create(1,t,e)}static decode(t){let[e,r]=n.decodeFirst(t);if(r.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=n.inspectBytes(t),r=e.size-e.multihashSize,o=O(t.subarray(r,r+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let a=o.subarray(e.multihashSize-e.digestSize),d=new H(e.multihashCode,e.digestSize,a,o);return[e.version===0?n.createV0(d):n.createV1(e.codec,d),t.subarray(e.size)]}static inspectBytes(t){let e=0,r=()=>{let[m,U]=X(t.subarray(e));return e+=U,m},o=r(),a=W;if(o===18?(o=0,e=0):a=r(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let d=e,g=r(),x=r(),L=e+x,w=L-d;return{version:o,codec:a,multihashCode:g,digestSize:x,multihashSize:w,size:L}}static parse(t,e){let[r,o]=zr(t,e),a=n.decode(o);if(a.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return _t(a).set(r,t),a}};function zr(n,t){switch(n[0]){case"Q":{let e=t??I;return[I.prefix,e.decode(`${I.prefix}${n}`)]}case I.prefix:{let e=t??I;return[I.prefix,e.decode(n)]}case j.prefix:{let e=t??j;return[j.prefix,e.decode(n)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[n[0],t.decode(n)]}}}function Fr(n,t,e){let{prefix:r}=e;if(r!==I.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(r);if(o==null){let a=e.encode(n).slice(1);return t.set(r,a),a}else return o}function jr(n,t,e){let{prefix:r}=e,o=t.get(r);if(o==null){let a=e.encode(n);return t.set(r,a),a}else return o}var W=112,qr=18;function pe(n,t,e){let r=$(n),o=r+$(t),a=new Uint8Array(o+e.byteLength);return q(n,a,0),q(t,a,r),a.set(e,o),a}var $r=Symbol.for("@ipld/js-cid/CID");var J={...Ot,...Ut,...Rt,...Et,...Lt,...Ct,...It,...At,...Mt,...Dt},Fn={...kt,...Vt};function Y(n,t){if(n===t)return!0;if(n.byteLength!==t.byteLength)return!1;for(let e=0;e<n.byteLength;e++)if(n[e]!==t[e])return!1;return!0}var Hr=Symbol.for("nodejs.util.inspect.custom"),le=Object.values(J).map(n=>n.decoder).reduce((n,t)=>n.or(t),J.identity.decoder),de=114,me=36,be=37,Z=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()})`}[Gt]=!0;toString(){return this.string==null&&(this.string=I.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return P.createV1(de,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Y(this.multihash.bytes,t);if(typeof t=="string")return E(t).equals(this);if(t?.multihash?.bytes!=null)return Y(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[Hr](){return`PeerId(${this.toString()})`}},tt=class extends Z{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},et=class extends Z{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},rt=class extends Z{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function E(n,t){if(t=t??le,n.charAt(0)==="1"||n.charAt(0)==="Q"){let e=Q(I.decode(`z${n}`));return n.startsWith("12D")?new et({multihash:e}):n.startsWith("16U")?new rt({multihash:e}):new tt({multihash:e})}return Kr(le.decode(n))}function Kr(n){try{let t=Q(n);if(t.code===ht.code){if(t.digest.length===me)return new et({multihash:t});if(t.digest.length===be)return new rt({multihash:t})}if(t.code===pt.code)return new tt({multihash:t})}catch{return Jr(P.decode(n))}throw new Error("Supplied PeerID CID is invalid")}function Jr(n){if(n==null||n.multihash==null||n.version==null||n.version===1&&n.code!==de)throw new Error("Supplied PeerID CID is invalid");let t=n.multihash;if(t.code===pt.code)return new tt({multihash:n.multihash});if(t.code===ht.code){if(t.digest.length===me)return new et({multihash:n.multihash});if(t.digest.length===be)return new rt({multihash:n.multihash})}throw new Error("Supplied PeerID CID is invalid")}function N(n,t){let e={[Symbol.iterator]:()=>e,next:()=>{let r=n.next(),o=r.value;return r.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}var T=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,r]of t.entries())this.map.set(e.toString(),r)}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return N(this.map.entries(),t=>[E(t[0]),t[1]])}forEach(t){this.map.forEach((e,r)=>{t(e,E(r),this)})}get(t){return this.map.get(t.toString())}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),e)}keys(){return N(this.map.keys(),t=>E(t))}values(){return this.map.values()}get size(){return this.map.size}};function ge(){return new T}var k=class n{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return N(this.set.entries(),t=>{let e=E(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let r=E(e);t(r,r,this)})}has(t){return this.set.has(t.toString())}values(){return N(this.set.values(),t=>E(t))}intersection(t){let e=new n;for(let r of t)this.has(r)&&e.add(r);return e}difference(t){let e=new n;for(let r of this)t.has(r)||e.add(r);return e}union(t){let e=new n;for(let r of t)e.add(r);for(let r of this)e.add(r);return e}};function xe(){return new k}var _=class n{list;constructor(t){if(this.list=[],t!=null)for(let e of t)this.list.push(e.toString())}[Symbol.iterator](){return N(this.list.entries(),t=>E(t[1]))}concat(t){let e=new n(this);for(let r of t)e.push(r);return e}entries(){return N(this.list.entries(),t=>[t[0],E(t[1])])}every(t){return this.list.every((e,r)=>t(E(e),r,this))}filter(t){let e=new n;return this.list.forEach((r,o)=>{let a=E(r);t(a,o,this)&&e.push(a)}),e}find(t){let e=this.list.find((r,o)=>t(E(r),o,this));if(e!=null)return E(e)}findIndex(t){return this.list.findIndex((e,r)=>t(E(e),r,this))}forEach(t){this.list.forEach((e,r)=>{t(E(e),r,this)})}includes(t){return this.list.includes(t.toString())}indexOf(t){return this.list.indexOf(t.toString())}pop(){let t=this.list.pop();if(t!=null)return E(t)}push(...t){for(let e of t)this.list.push(e.toString())}shift(){let t=this.list.shift();if(t!=null)return E(t)}unshift(...t){let e=this.list.length;for(let r=t.length-1;r>-1;r--)e=this.list.unshift(t[r].toString());return e}clear(){this.list=[]}get length(){return this.list.length}};function we(){return new _}function M(n=0){return new Uint8Array(n)}function z(n=0){return new Uint8Array(n)}function Pt(n,t){t==null&&(t=n.reduce((o,a)=>o+a.length,0));let e=z(t),r=0;for(let o of n)e.set(o,r),r+=o.length;return e}function ve(n,t,e,r){return{name:n,prefix:t,encoder:{name:n,prefix:t,encode:e},decoder:{decode:r}}}var ye=ve("utf8","u",n=>"u"+new TextDecoder("utf8").decode(n),n=>new TextEncoder().encode(n.substring(1))),zt=ve("ascii","a",n=>{let t="a";for(let e=0;e<n.length;e++)t+=String.fromCharCode(n[e]);return t},n=>{n=n.substring(1);let t=z(n.length);for(let e=0;e<n.length;e++)t[e]=n.charCodeAt(e);return t}),Gr={utf8:ye,"utf-8":ye,hex:J.base16,latin1:zt,ascii:zt,binary:zt,...J},Se=Gr;function Ft(n,t="utf8"){let e=Se[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${n}`)}var lt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var So=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var Ao={}.toString;function Ae(n=32){if(lt&&typeof lt.getRandomValues=="function")return lt.getRandomValues(new Uint8Array(n));throw new Error("crypto.getRandomValues must be defined")}function dt(n){if(isNaN(n)||n<=0)throw new ft("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return Ae(n)}var jt=_e(Ue(),1);var Ce=Symbol.for("@achingbrain/uint8arraylist");function De(n,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let r of n){let o=e+r.byteLength;if(t<o)return{buf:r,index:t-e};e=o}throw new RangeError("index is out of bounds")}function bt(n){return!!n?.[Ce]}var gt=class n{bufs;length;[Ce]=!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 r of t)if(r instanceof Uint8Array)e+=r.byteLength,this.bufs.push(r);else if(bt(r))e+=r.byteLength,this.bufs.push(...r.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 r of t.reverse())if(r instanceof Uint8Array)e+=r.byteLength,this.bufs.unshift(r);else if(bt(r))e+=r.byteLength,this.bufs.unshift(...r.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=De(this.bufs,t);return e.buf[e.index]}set(t,e){let r=De(this.bufs,t);r.buf[r.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let r=0;r<t.length;r++)this.set(e+r,t[r]);else if(bt(t))for(let r=0;r<t.length;r++)this.set(e+r,t.get(r));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:r,length:o}=this._subList(t,e);return Pt(r,o)}subarray(t,e){let{bufs:r,length:o}=this._subList(t,e);return r.length===1?r[0]:Pt(r,o)}sublist(t,e){let{bufs:r,length:o}=this._subList(t,e),a=new n;return a.length=o,a.bufs=[...r],a}_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 r=[],o=0;for(let a=0;a<this.bufs.length;a++){let d=this.bufs[a],g=o,x=g+d.byteLength;if(o=x,t>=x)continue;let L=t>=g&&t<x,w=e>g&&e<=x;if(L&&w){if(t===g&&e===x){r.push(d);break}let m=t-g;r.push(d.subarray(m,m+(e-t)));break}if(L){if(t===0){r.push(d);continue}r.push(d.subarray(t-g));continue}if(w){if(e===x){r.push(d);break}r.push(d.subarray(0,e-g));break}r.push(d)}return{bufs:r,length:e-t}}indexOf(t,e=0){if(!bt(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let r=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=r.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let a=256,d=new Int32Array(a);for(let m=0;m<a;m++)d[m]=-1;for(let m=0;m<o;m++)d[r[m]]=m;let g=d,x=this.byteLength-r.byteLength,L=r.byteLength-1,w;for(let m=e;m<=x;m+=w){w=0;for(let U=L;U>=0;U--){let s=this.get(m+U);if(r[U]!==s){w=Math.max(1,U-g[s]);break}}if(w===0)return m}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 r=z(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt8(0,e),this.write(r,t)}getInt16(t,e){let r=this.subarray(t,t+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt16(0,e)}setInt16(t,e,r){let o=M(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,r),this.write(o,t)}getInt32(t,e){let r=this.subarray(t,t+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt32(0,e)}setInt32(t,e,r){let o=M(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,r),this.write(o,t)}getBigInt64(t,e){let r=this.subarray(t,t+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigInt64(0,e)}setBigInt64(t,e,r){let o=M(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,r),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let r=z(1);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint8(0,e),this.write(r,t)}getUint16(t,e){let r=this.subarray(t,t+2);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint16(0,e)}setUint16(t,e,r){let o=M(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,r),this.write(o,t)}getUint32(t,e){let r=this.subarray(t,t+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint32(0,e)}setUint32(t,e,r){let o=M(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,r),this.write(o,t)}getBigUint64(t,e){let r=this.subarray(t,t+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getBigUint64(0,e)}setBigUint64(t,e,r){let o=M(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,r),this.write(o,t)}getFloat32(t,e){let r=this.subarray(t,t+4);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat32(0,e)}setFloat32(t,e,r){let o=M(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,r),this.write(o,t)}getFloat64(t,e){let r=this.subarray(t,t+8);return new DataView(r.buffer,r.byteOffset,r.byteLength).getFloat64(0,e)}setFloat64(t,e,r){let o=M(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,r),this.write(o,t)}equals(t){if(t==null||!(t instanceof n)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!Y(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let r=new n;return r.bufs=t,e==null&&(e=t.reduce((o,a)=>o+a.byteLength,0)),r.length=e,r}};var Xr=Math.LN2*Math.LN2,xt=class n{static create(t,e=.005){let r=Qr(t,e);return new n(r)}seeds;bits;buffer;constructor(t={}){t.seeds!=null?this.seeds=t.seeds:this.seeds=Wr(t.hashes??8),this.bits=t.bits??1024,this.buffer=M(Math.ceil(this.bits/8))}add(t){typeof t=="string"&&(t=Ft(t));for(let e=0;e<this.seeds.length;e++){let o=jt.default.x86.hash32(t,this.seeds[e])%this.bits;this.setbit(o)}}has(t){typeof t=="string"&&(t=Ft(t));for(let e=0;e<this.seeds.length;e++){let o=jt.default.x86.hash32(t,this.seeds[e])%this.bits;if(!this.getbit(o))return!1}return!0}clear(){this.buffer.fill(0)}setbit(t){let e=0,r=t;for(;r>7;)e++,r-=8;let o=this.buffer[e];o|=1<<r,this.buffer[e]=o}getbit(t){let e=0,r=t;for(;r>7;)e++,r-=8;return(this.buffer[e]&1<<r)!==0}};function Qr(n,t=.005){let e=Math.round(-1*n*Math.log(t)/Xr),r=Math.round(e/n*Math.LN2);return{bits:e,hashes:r}}function Wr(n){let t,e,r=[];for(let o=0;o<n;o++)for(t=new gt(dt(4)),r[o]=t.getUint32(0,!0),e=0;e<o;e++)if(r[o]===r[e]){o--;break}return r}var ot=class{filter;constructor(t,e){this.filter=xt.create(t,e)}has(t){return this.filter.has(t.toBytes())}add(t){this.filter.add(t.toBytes())}};function Ie(n){return new ot(n)}var qt=class extends T{metric;constructor(t){super();let{name:e,metrics:r}=t;this.metric=r.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Me(n){let{name:t,metrics:e}=n,r;return e!=null?r=new qt({name:t,metrics:e}):r=new T,r}var $t=class extends k{metric;constructor(t){super();let{name:e,metrics:r}=t;this.metric=r.registerMetric(e),this.updateComponentMetric()}add(t){super.add(t),this.updateComponentMetric()}delete(t){super.delete(t),this.updateComponentMetric()}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Re(n){let{name:t,metrics:e}=n,r;return e!=null?r=new $t({name:t,metrics:e}):r=new k,r}var Ht=class extends _{metric;constructor(t){super();let{name:e,metrics:r}=t;this.metric=r.registerMetric(e),this.updateComponentMetric()}pop(){let t=super.pop();return this.updateComponentMetric(),t}push(...t){super.push(...t),this.updateComponentMetric()}shift(){let t=super.shift();return this.updateComponentMetric(),t}unshift(...t){let e=super.unshift(...t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.length)}};function Oe(n){let{name:t,metrics:e}=n,r;return e!=null?r=new Ht({name:t,metrics:e}):r=new _,r}return Pe(Yr);})();
|
|
3
|
+
/*! Bundled license information:
|
|
4
|
+
|
|
5
|
+
@noble/hashes/esm/utils.js:
|
|
6
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
7
|
+
*/
|
|
3
8
|
return Libp2PPeerCollections}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PeerId } from '@libp2p/interface';
|
|
2
|
+
/**
|
|
3
|
+
* Uses a Bloom filter to implement a mechansim for deduplicating PeerIds in a
|
|
4
|
+
* way that uses a fixed amount of memory.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PeerFilter {
|
|
7
|
+
private readonly filter;
|
|
8
|
+
constructor(size: number, errorRate?: number);
|
|
9
|
+
has(peerId: PeerId): boolean;
|
|
10
|
+
add(peerId: PeerId): void;
|
|
11
|
+
}
|
|
12
|
+
export declare function peerFilter(size: number): PeerFilter;
|
|
13
|
+
//# sourceMappingURL=filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/filter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;gBAEvB,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;IAI7C,GAAG,CAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAI7B,GAAG,CAAE,MAAM,EAAE,MAAM,GAAG,IAAI;CAG3B;AAED,wBAAgB,UAAU,CAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAEpD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BloomFilter } from '@libp2p/utils/bloom-filter';
|
|
2
|
+
/**
|
|
3
|
+
* Uses a Bloom filter to implement a mechansim for deduplicating PeerIds in a
|
|
4
|
+
* way that uses a fixed amount of memory.
|
|
5
|
+
*/
|
|
6
|
+
export class PeerFilter {
|
|
7
|
+
filter;
|
|
8
|
+
constructor(size, errorRate) {
|
|
9
|
+
this.filter = BloomFilter.create(size, errorRate);
|
|
10
|
+
}
|
|
11
|
+
has(peerId) {
|
|
12
|
+
return this.filter.has(peerId.toBytes());
|
|
13
|
+
}
|
|
14
|
+
add(peerId) {
|
|
15
|
+
this.filter.add(peerId.toBytes());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function peerFilter(size) {
|
|
19
|
+
return new PeerFilter(size);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAGxD;;;GAGG;AACH,MAAM,OAAO,UAAU;IACJ,MAAM,CAAa;IAEpC,YAAa,IAAY,EAAE,SAAkB;QAC3C,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;IACnD,CAAC;IAED,GAAG,CAAE,MAAc;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAA;IAC1C,CAAC;IAED,GAAG,CAAE,MAAc;QACjB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAA;IACnC,CAAC;CACF;AAED,MAAM,UAAU,UAAU,CAAE,IAAY;IACtC,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAA;AAC7B,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -84,10 +84,25 @@
|
|
|
84
84
|
* const set = trackedPeerSet({ name: 'my_metric_name', metrics: libp2p.metrics })
|
|
85
85
|
* set.add(peerId)
|
|
86
86
|
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example Peer filters
|
|
89
|
+
*
|
|
90
|
+
* ```TypeScript
|
|
91
|
+
* import { peerFilter } from '@libp2p/peer-collections'
|
|
92
|
+
* import { createEd25519PeerId } from '@libp2p/peer-id-factory'
|
|
93
|
+
*
|
|
94
|
+
* const peerId = await createEd25519PeerId()
|
|
95
|
+
*
|
|
96
|
+
* const filter = peerFilter(1024)
|
|
97
|
+
* filter.has(peerId) // false
|
|
98
|
+
* filter.add(peerId)
|
|
99
|
+
* filter.has(peerId) // true
|
|
100
|
+
* ```
|
|
87
101
|
*/
|
|
88
102
|
export { PeerMap, peerMap } from './map.js';
|
|
89
103
|
export { PeerSet, peerSet } from './set.js';
|
|
90
104
|
export { PeerList, peerList } from './list.js';
|
|
105
|
+
export { PeerFilter, peerFilter } from './filter.js';
|
|
91
106
|
export { trackedPeerMap } from './tracked-map.js';
|
|
92
107
|
export { trackedPeerSet } from './tracked-set.js';
|
|
93
108
|
export { trackedPeerList } from './tracked-list.js';
|
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
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoGG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -84,10 +84,25 @@
|
|
|
84
84
|
* const set = trackedPeerSet({ name: 'my_metric_name', metrics: libp2p.metrics })
|
|
85
85
|
* set.add(peerId)
|
|
86
86
|
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example Peer filters
|
|
89
|
+
*
|
|
90
|
+
* ```TypeScript
|
|
91
|
+
* import { peerFilter } from '@libp2p/peer-collections'
|
|
92
|
+
* import { createEd25519PeerId } from '@libp2p/peer-id-factory'
|
|
93
|
+
*
|
|
94
|
+
* const peerId = await createEd25519PeerId()
|
|
95
|
+
*
|
|
96
|
+
* const filter = peerFilter(1024)
|
|
97
|
+
* filter.has(peerId) // false
|
|
98
|
+
* filter.add(peerId)
|
|
99
|
+
* filter.has(peerId) // true
|
|
100
|
+
* ```
|
|
87
101
|
*/
|
|
88
102
|
export { PeerMap, peerMap } from './map.js';
|
|
89
103
|
export { PeerSet, peerSet } from './set.js';
|
|
90
104
|
export { PeerList, peerList } from './list.js';
|
|
105
|
+
export { PeerFilter, peerFilter } from './filter.js';
|
|
91
106
|
export { trackedPeerMap } from './tracked-map.js';
|
|
92
107
|
export { trackedPeerSet } from './tracked-set.js';
|
|
93
108
|
export { trackedPeerList } from './tracked-list.js';
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoGG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/peer-collections",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.11-3bc94b403",
|
|
4
4
|
"description": "Stores values against a peer id",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/peer-collections#readme",
|
|
@@ -54,11 +54,12 @@
|
|
|
54
54
|
"test:electron-main": "aegir test -t electron-main"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@libp2p/interface": "
|
|
58
|
-
"@libp2p/peer-id": "
|
|
57
|
+
"@libp2p/interface": "1.3.0-3bc94b403",
|
|
58
|
+
"@libp2p/peer-id": "4.1.0-3bc94b403",
|
|
59
|
+
"@libp2p/utils": "5.3.2-3bc94b403"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
|
-
"@libp2p/peer-id-factory": "
|
|
62
|
+
"@libp2p/peer-id-factory": "4.1.0-3bc94b403",
|
|
62
63
|
"@types/sinon": "^17.0.3",
|
|
63
64
|
"aegir": "^42.2.5",
|
|
64
65
|
"sinon": "^17.0.1",
|
package/src/filter.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BloomFilter } from '@libp2p/utils/bloom-filter'
|
|
2
|
+
import type { PeerId } from '@libp2p/interface'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Uses a Bloom filter to implement a mechansim for deduplicating PeerIds in a
|
|
6
|
+
* way that uses a fixed amount of memory.
|
|
7
|
+
*/
|
|
8
|
+
export class PeerFilter {
|
|
9
|
+
private readonly filter: BloomFilter
|
|
10
|
+
|
|
11
|
+
constructor (size: number, errorRate?: number) {
|
|
12
|
+
this.filter = BloomFilter.create(size, errorRate)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
has (peerId: PeerId): boolean {
|
|
16
|
+
return this.filter.has(peerId.toBytes())
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
add (peerId: PeerId): void {
|
|
20
|
+
this.filter.add(peerId.toBytes())
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function peerFilter (size: number): PeerFilter {
|
|
25
|
+
return new PeerFilter(size)
|
|
26
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -84,11 +84,26 @@
|
|
|
84
84
|
* const set = trackedPeerSet({ name: 'my_metric_name', metrics: libp2p.metrics })
|
|
85
85
|
* set.add(peerId)
|
|
86
86
|
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example Peer filters
|
|
89
|
+
*
|
|
90
|
+
* ```TypeScript
|
|
91
|
+
* import { peerFilter } from '@libp2p/peer-collections'
|
|
92
|
+
* import { createEd25519PeerId } from '@libp2p/peer-id-factory'
|
|
93
|
+
*
|
|
94
|
+
* const peerId = await createEd25519PeerId()
|
|
95
|
+
*
|
|
96
|
+
* const filter = peerFilter(1024)
|
|
97
|
+
* filter.has(peerId) // false
|
|
98
|
+
* filter.add(peerId)
|
|
99
|
+
* filter.has(peerId) // true
|
|
100
|
+
* ```
|
|
87
101
|
*/
|
|
88
102
|
|
|
89
103
|
export { PeerMap, peerMap } from './map.js'
|
|
90
104
|
export { PeerSet, peerSet } from './set.js'
|
|
91
105
|
export { PeerList, peerList } from './list.js'
|
|
106
|
+
export { PeerFilter, peerFilter } from './filter.js'
|
|
92
107
|
|
|
93
108
|
export { trackedPeerMap } from './tracked-map.js'
|
|
94
109
|
export { trackedPeerSet } from './tracked-set.js'
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"PeerList": "https://libp2p.github.io/js-libp2p/classes/_libp2p_peer_collections.PeerList.html",
|
|
3
|
-
"PeerMap": "https://libp2p.github.io/js-libp2p/classes/_libp2p_peer_collections.PeerMap.html",
|
|
4
|
-
"PeerSet": "https://libp2p.github.io/js-libp2p/classes/_libp2p_peer_collections.PeerSet.html",
|
|
5
|
-
"peerList": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_collections.peerList-1.html",
|
|
6
|
-
"peerMap": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_collections.peerMap-1.html",
|
|
7
|
-
"peerSet": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_collections.peerSet-1.html",
|
|
8
|
-
"trackedPeerList": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_collections.trackedPeerList.html",
|
|
9
|
-
"trackedPeerMap": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_collections.trackedPeerMap.html",
|
|
10
|
-
"trackedPeerSet": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_collections.trackedPeerSet.html"
|
|
11
|
-
}
|