@libp2p/interface 1.1.3 → 1.1.4-1fc929c1c
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 +17 -8
- package/dist/index.min.js +1 -1
- package/dist/src/content-routing/index.d.ts +5 -5
- package/dist/src/content-routing/index.js +1 -1
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +4 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/event-target.d.ts +1 -0
- package/dist/src/event-target.d.ts.map +1 -1
- package/dist/src/event-target.js +7 -0
- package/dist/src/event-target.js.map +1 -1
- package/dist/src/index.d.ts +26 -26
- package/dist/src/peer-discovery/index.d.ts +1 -1
- package/dist/src/peer-discovery/index.js +1 -1
- package/dist/src/peer-routing/index.d.ts +3 -3
- package/dist/src/peer-routing/index.js +1 -1
- package/dist/src/peer-store/index.d.ts +9 -9
- package/dist/src/pubsub/index.d.ts +6 -6
- package/package.json +5 -4
- package/src/content-routing/index.ts +5 -5
- package/src/errors.ts +4 -0
- package/src/event-target.ts +10 -0
- package/src/index.ts +26 -26
- package/src/peer-discovery/index.ts +1 -1
- package/src/peer-routing/index.ts +3 -3
- package/src/peer-store/index.ts +9 -9
- package/src/pubsub/index.ts +6 -6
- package/dist/typedoc-urls.json +0 -158
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# @libp2p/interface
|
|
2
|
+
|
|
1
3
|
[](http://libp2p.io/)
|
|
2
4
|
[](https://discuss.libp2p.io)
|
|
3
5
|
[](https://codecov.io/gh/libp2p/js-libp2p)
|
|
@@ -7,6 +9,21 @@
|
|
|
7
9
|
|
|
8
10
|
# About
|
|
9
11
|
|
|
12
|
+
<!--
|
|
13
|
+
|
|
14
|
+
!IMPORTANT!
|
|
15
|
+
|
|
16
|
+
Everything in this README between "# About" and "# Install" is automatically
|
|
17
|
+
generated and will be overwritten the next time the doc generator is run.
|
|
18
|
+
|
|
19
|
+
To make changes to this section, please update the @packageDocumentation section
|
|
20
|
+
of src/index.js or src/index.ts
|
|
21
|
+
|
|
22
|
+
To experiment with formatting, please run "npm run docs" from the root of this
|
|
23
|
+
repo and examine the changes made.
|
|
24
|
+
|
|
25
|
+
-->
|
|
26
|
+
|
|
10
27
|
Exports a `Libp2p` type for modules to use as a type argument.
|
|
11
28
|
|
|
12
29
|
## Example
|
|
@@ -25,14 +42,6 @@ function doSomethingWithLibp2p (node: Libp2p) {
|
|
|
25
42
|
$ npm i @libp2p/interface
|
|
26
43
|
```
|
|
27
44
|
|
|
28
|
-
## Browser `<script>` tag
|
|
29
|
-
|
|
30
|
-
Loading this module through a script tag will make it's exports available as `Libp2pInterface` in the global namespace.
|
|
31
|
-
|
|
32
|
-
```html
|
|
33
|
-
<script src="https://unpkg.com/@libp2p/interface/dist/index.min.js"></script>
|
|
34
|
-
```
|
|
35
|
-
|
|
36
45
|
# API Docs
|
|
37
46
|
|
|
38
47
|
- <https://libp2p.github.io/js-libp2p/modules/_libp2p_interface.html>
|
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PInterface = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PInterface=(()=>{var n=Object.defineProperty;var
|
|
2
|
+
"use strict";var Libp2PInterface=(()=>{var n=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var g=(e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})},N=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of L(t))!_.call(e,r)&&r!==o&&n(e,r,{get:()=>t[r],enumerable:!(s=I(t,r))||s.enumerable});return e};var v=e=>N(n({},"__esModule",{value:!0}),e);var q={};g(q,{AbortError:()=>p,AggregateCodeError:()=>l,CodeError:()=>a,CustomEvent:()=>b,ERR_INVALID_MESSAGE:()=>Y,ERR_INVALID_PARAMETERS:()=>j,ERR_NOT_FOUND:()=>X,ERR_TIMEOUT:()=>G,Ed25519:()=>P,FaultTolerance:()=>i,InvalidCryptoExchangeError:()=>x,InvalidCryptoTransmissionError:()=>m,KEEP_ALIVE:()=>V,RSA:()=>M,StrictNoSign:()=>B,StrictSign:()=>k,TopicValidatorResult:()=>c,TypedEventEmitter:()=>E,UnexpectedPeerError:()=>f,connectionSymbol:()=>R,contentRoutingSymbol:()=>w,isConnection:()=>T,isPeerId:()=>C,isStartable:()=>S,isTransport:()=>F,peerDiscoverySymbol:()=>D,peerIdSymbol:()=>h,peerRoutingSymbol:()=>U,secp256k1:()=>O,setMaxListeners:()=>u,start:()=>H,stop:()=>K,transportSymbol:()=>A});var R=Symbol.for("@libp2p/connection");function T(e){return e!=null&&!!e[R]}var w=Symbol.for("@libp2p/content-routing");var P="Ed25519",M="RSA",O="secp256k1";var D=Symbol.for("@libp2p/peer-discovery");var h=Symbol.for("@libp2p/peer-id");function C(e){return e!=null&&!!e[h]}var U=Symbol.for("@libp2p/peer-routing");var V="keep-alive";var k="StrictSign",B="StrictNoSign",c;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(c||(c={}));var A=Symbol.for("@libp2p/transport");function F(e){return e!=null&&!!e[A]}var i;(function(e){e[e.FATAL_ALL=0]="FATAL_ALL",e[e.NO_FATAL=1]="NO_FATAL"})(i||(i={}));var p=class e extends Error{code;type;constructor(t="The operation was aborted"){super(t),this.name="AbortError",this.code=e.code,this.type=e.type}static code="ABORT_ERR";static type="aborted"},a=class extends Error{code;props;constructor(t,o,s){super(t),this.code=o,this.name=s?.name??"CodeError",this.props=s??{}}},l=class extends AggregateError{code;props;constructor(t,o,s,r){super(t,o),this.code=s,this.name=r?.name??"AggregateCodeError",this.props=r??{}}},f=class e extends Error{code;constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError",this.code=e.code}static code="ERR_UNEXPECTED_PEER"},x=class e extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError",this.code=e.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"},m=class e extends Error{code;constructor(t="Invalid crypto transmission"){super(t),this.name="InvalidCryptoTransmissionError",this.code=e.code}static code="ERR_INVALID_CRYPTO_TRANSMISSION"},G="ERR_TIMEOUT",j="ERR_INVALID_PARAMETERS",X="ERR_NOT_FOUND",Y="ERR_INVALID_MESSAGE";var u=(e,...t)=>{try{[...t]}catch{}};var E=class extends EventTarget{#t=new Map;constructor(){super(),u(1/0,this)}listenerCount(t){let o=this.#t.get(t);return o==null?0:o.length}addEventListener(t,o,s){super.addEventListener(t,o,s);let r=this.#t.get(t);r==null&&(r=[],this.#t.set(t,r)),r.push({callback:o,once:(s!==!0&&s!==!1&&s?.once)??!1})}removeEventListener(t,o,s){super.removeEventListener(t.toString(),o??null,s);let r=this.#t.get(t);r!=null&&(r=r.filter(({callback:y})=>y!==o),this.#t.set(t,r))}dispatchEvent(t){let o=super.dispatchEvent(t),s=this.#t.get(t.type);return s==null||(s=s.filter(({once:r})=>!r),this.#t.set(t.type,s)),o}safeDispatchEvent(t,o={}){return this.dispatchEvent(new b(t,o))}},d=class extends Event{detail;constructor(t,o){super(t,o),this.detail=o?.detail}},b=globalThis.CustomEvent??d;function S(e){return e!=null&&typeof e.start=="function"&&typeof e.stop=="function"}async function H(...e){let t=[];for(let o of e)S(o)&&t.push(o);await Promise.all(t.map(async o=>{o.beforeStart!=null&&await o.beforeStart()})),await Promise.all(t.map(async o=>{await o.start()})),await Promise.all(t.map(async o=>{o.afterStart!=null&&await o.afterStart()}))}async function K(...e){let t=[];for(let o of e)S(o)&&t.push(o);await Promise.all(t.map(async o=>{o.beforeStop!=null&&await o.beforeStop()})),await Promise.all(t.map(async o=>{await o.stop()})),await Promise.all(t.map(async o=>{o.afterStop!=null&&await o.afterStop()}))}return v(q);})();
|
|
3
3
|
return Libp2PInterface}));
|
|
@@ -8,7 +8,7 @@ import type { CID } from 'multiformats/cid';
|
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
*
|
|
11
|
-
* ```
|
|
11
|
+
* ```TypeScript
|
|
12
12
|
* import { contentRoutingSymbol, ContentRouting } from '@libp2p/content-routing'
|
|
13
13
|
*
|
|
14
14
|
* class MyContentRouter implements ContentRouting {
|
|
@@ -35,7 +35,7 @@ export interface ContentRouting {
|
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
37
37
|
*
|
|
38
|
-
* ```
|
|
38
|
+
* ```TypeScript
|
|
39
39
|
* // ...
|
|
40
40
|
* await contentRouting.provide(cid)
|
|
41
41
|
* ```
|
|
@@ -46,7 +46,7 @@ export interface ContentRouting {
|
|
|
46
46
|
*
|
|
47
47
|
* @example
|
|
48
48
|
*
|
|
49
|
-
* ```
|
|
49
|
+
* ```TypeScript
|
|
50
50
|
* // Iterate over the providers found for the given cid
|
|
51
51
|
* for await (const provider of contentRouting.findProviders(cid)) {
|
|
52
52
|
* console.log(provider.id, provider.multiaddrs)
|
|
@@ -60,7 +60,7 @@ export interface ContentRouting {
|
|
|
60
60
|
*
|
|
61
61
|
* @example
|
|
62
62
|
*
|
|
63
|
-
* ```
|
|
63
|
+
* ```TypeScript
|
|
64
64
|
* // ...
|
|
65
65
|
* const key = '/key'
|
|
66
66
|
* const value = uint8ArrayFromString('oh hello there')
|
|
@@ -74,7 +74,7 @@ export interface ContentRouting {
|
|
|
74
74
|
*
|
|
75
75
|
* @example
|
|
76
76
|
*
|
|
77
|
-
* ```
|
|
77
|
+
* ```TypeScript
|
|
78
78
|
* // ...
|
|
79
79
|
*
|
|
80
80
|
* const key = '/key'
|
package/dist/src/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,SAAgB,IAAI,EAAE,MAAM,CAAA;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AAQ,CAAC,IAAI,iCAAgC;CACrD;AAED,qBAAa,8BAA+B,SAAQ,KAAK;IAChD,IAAI,EAAE,MAAM,CAAA;gBAEN,OAAO,SAAgC;IAMpD,MAAM,CAAC,QAAQ,CAAC,IAAI,qCAAoC;CACzD;AAID,eAAO,MAAM,WAAW,gBAAgB,CAAA;AACxC,eAAO,MAAM,sBAAsB,2BAA2B,CAAA;AAC9D,eAAO,MAAM,aAAa,kBAAkB,CAAA;AAC5C,eAAO,MAAM,mBAAmB,wBAAwB,CAAA"}
|
package/dist/src/errors.js
CHANGED
|
@@ -8,6 +8,7 @@ export class AbortError extends Error {
|
|
|
8
8
|
type;
|
|
9
9
|
constructor(message = 'The operation was aborted') {
|
|
10
10
|
super(message);
|
|
11
|
+
this.name = 'AbortError';
|
|
11
12
|
this.code = AbortError.code;
|
|
12
13
|
this.type = AbortError.type;
|
|
13
14
|
}
|
|
@@ -38,6 +39,7 @@ export class UnexpectedPeerError extends Error {
|
|
|
38
39
|
code;
|
|
39
40
|
constructor(message = 'Unexpected Peer') {
|
|
40
41
|
super(message);
|
|
42
|
+
this.name = 'UnexpectedPeerError';
|
|
41
43
|
this.code = UnexpectedPeerError.code;
|
|
42
44
|
}
|
|
43
45
|
static code = 'ERR_UNEXPECTED_PEER';
|
|
@@ -46,6 +48,7 @@ export class InvalidCryptoExchangeError extends Error {
|
|
|
46
48
|
code;
|
|
47
49
|
constructor(message = 'Invalid crypto exchange') {
|
|
48
50
|
super(message);
|
|
51
|
+
this.name = 'InvalidCryptoExchangeError';
|
|
49
52
|
this.code = InvalidCryptoExchangeError.code;
|
|
50
53
|
}
|
|
51
54
|
static code = 'ERR_INVALID_CRYPTO_EXCHANGE';
|
|
@@ -54,6 +57,7 @@ export class InvalidCryptoTransmissionError extends Error {
|
|
|
54
57
|
code;
|
|
55
58
|
constructor(message = 'Invalid crypto transmission') {
|
|
56
59
|
super(message);
|
|
60
|
+
this.name = 'InvalidCryptoTransmissionError';
|
|
57
61
|
this.code = InvalidCryptoTransmissionError.code;
|
|
58
62
|
}
|
|
59
63
|
static code = 'ERR_INVALID_CRYPTO_TRANSMISSION';
|
package/dist/src/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnB,IAAI,CAAQ;IACZ,IAAI,CAAQ;IAE5B,YAAa,UAAkB,2BAA2B;QACxD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAA;QAC3B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAA;IAC7B,CAAC;IAED,MAAM,CAAU,IAAI,GAAG,WAAW,CAAA;IAElC,MAAM,CAAU,IAAI,GAAG,SAAS,CAAA;;AAGlC,MAAM,OAAO,SAAiE,SAAQ,KAAK;IAKvE;IAJF,KAAK,CAAG;IAExB,YACE,OAAe,EACC,IAAY,EAC5B,KAAS;QAET,KAAK,CAAC,OAAO,CAAC,CAAA;QAHE,SAAI,GAAJ,IAAI,CAAQ;QAK5B,IAAI,CAAC,IAAI,GAAG,KAAK,EAAE,IAAI,IAAI,WAAW,CAAA;QACtC,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,EAAO,CAAA,CAAC,oEAAoE;IACpG,CAAC;CACF;AAED,MAAM,OAAO,kBAA0E,SAAQ,cAAc;IAMzF;IALF,KAAK,CAAG;IAExB,YACE,MAAe,EACf,OAAe,EACC,IAAY,EAC5B,KAAS;QAET,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAHN,SAAI,GAAJ,IAAI,CAAQ;QAK5B,IAAI,CAAC,IAAI,GAAG,KAAK,EAAE,IAAI,IAAI,oBAAoB,CAAA;QAC/C,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,EAAO,CAAA,CAAC,oEAAoE;IACpG,C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a,OAAO,GAAG,yBAAyB;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAA;QACxC,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC,IAAI,CAAA;IAC7C,CAAC;IAED,MAAM,CAAU,IAAI,GAAG,6BAA6B,CAAA;;AAGtD,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IAChD,IAAI,CAAQ;IAEnB,YAAa,OAAO,GAAG,6BAA6B;QAClD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAA;QAC5C,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC,IAAI,CAAA;IACjD,CAAC;IAED,MAAM,CAAU,IAAI,GAAG,iCAAiC,CAAA;;AAG1D,cAAc;AAEd,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAA;AACxC,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAA;AAC9D,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAA;AAC5C,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAA"}
|
|
@@ -26,6 +26,7 @@ export interface TypedEventTarget<EventMap extends Record<string, any>> extends
|
|
|
26
26
|
*/
|
|
27
27
|
export declare class TypedEventEmitter<EventMap extends Record<string, any>> extends EventTarget implements TypedEventTarget<EventMap> {
|
|
28
28
|
#private;
|
|
29
|
+
constructor();
|
|
29
30
|
listenerCount(type: string): number;
|
|
30
31
|
addEventListener<K extends keyof EventMap>(type: K, listener: EventHandler<EventMap[K]> | null, options?: boolean | AddEventListenerOptions): void;
|
|
31
32
|
removeEventListener<K extends keyof EventMap>(type: K, listener?: EventHandler<EventMap[K]> | null, options?: boolean | EventListenerOptions): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-target.d.ts","sourceRoot":"","sources":["../../src/event-target.ts"],"names":[],"mappings":"
|
|
1
|
+
{"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GG;AACH,qBAAa,iBAAiB,CAAC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAE,SAAQ,WAAY,YAAW,gBAAgB,CAAC,QAAQ,CAAC;;;IAW5H,aAAa,CAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAUpC,gBAAgB,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,GAAG,IAAI;IAiBlJ,mBAAmB,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,oBAAoB,GAAG,IAAI;IAcnJ,aAAa,CAAE,KAAK,EAAE,KAAK,GAAG,OAAO;IAerC,iBAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,EAAE,MAAM,GAAE,eAAe,CAAC,MAAM,CAAM,GAAG,OAAO;CAG/F;AAoBD,eAAO,MAAM,WAAW;;;CAAgD,CAAA"}
|
package/dist/src/event-target.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import { setMaxListeners } from './events.js';
|
|
1
2
|
/**
|
|
2
3
|
* An implementation of a typed event target
|
|
3
4
|
* etc
|
|
4
5
|
*/
|
|
5
6
|
export class TypedEventEmitter extends EventTarget {
|
|
6
7
|
#listeners = new Map();
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
// silence MaxListenersExceededWarning warning on Node.js, this is a red
|
|
11
|
+
// herring almost all of the time
|
|
12
|
+
setMaxListeners(Infinity, this);
|
|
13
|
+
}
|
|
7
14
|
listenerCount(type) {
|
|
8
15
|
const listeners = this.#listeners.get(type);
|
|
9
16
|
if (listeners == null) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-target.js","sourceRoot":"","sources":["../../src/event-target.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-target.js","sourceRoot":"","sources":["../../src/event-target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AA+B7C;;;GAGG;AACH,MAAM,OAAO,iBAAwD,SAAQ,WAAW;IACtF,UAAU,GAAG,IAAI,GAAG,EAAmB,CAAA;IAEvC;QACE,KAAK,EAAE,CAAA;QAEP,wEAAwE;QACxE,iCAAiC;QACjC,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IACjC,CAAC;IAED,aAAa,CAAE,IAAY;QACzB,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAE3C,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,OAAO,CAAC,CAAA;QACV,CAAC;QAED,OAAO,SAAS,CAAC,MAAM,CAAA;IACzB,CAAC;IAGD,gBAAgB,CAAE,IAAY,EAAE,QAA6B,EAAE,OAA2C;QACxG,KAAK,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAA;QAE/C,IAAI,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAEpC,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;YACjB,IAAI,GAAG,EAAE,CAAA;YACT,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QACjC,CAAC;QAED,IAAI,CAAC,IAAI,CAAC;YACR,QAAQ,EAAE,QAAQ;YAClB,IAAI,EAAE,CAAC,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,IAAI,OAAO,EAAE,IAAI,CAAC,IAAI,KAAK;SACxE,CAAC,CA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MAAM,CAAG;IAEhB,YAAa,OAAe,EAAE,IAAgC;QAC5D,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACpB,sCAAsC;QACtC,IAAI,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,CAAA;IAC5B,CAAC;CACF;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,IAAI,mBAAmB,CAAA"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -120,7 +120,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
120
120
|
*
|
|
121
121
|
* @example
|
|
122
122
|
*
|
|
123
|
-
* ```
|
|
123
|
+
* ```TypeScript
|
|
124
124
|
* libp2p.addEventListener('peer:discovery', (event) => {
|
|
125
125
|
* const peerInfo = event.detail
|
|
126
126
|
* // ...
|
|
@@ -133,7 +133,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
133
133
|
*
|
|
134
134
|
* @example
|
|
135
135
|
*
|
|
136
|
-
* ```
|
|
136
|
+
* ```TypeScript
|
|
137
137
|
* libp2p.addEventListener('peer:connect', (event) => {
|
|
138
138
|
* const peerId = event.detail
|
|
139
139
|
* // ...
|
|
@@ -148,7 +148,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
148
148
|
*
|
|
149
149
|
* @example
|
|
150
150
|
*
|
|
151
|
-
* ```
|
|
151
|
+
* ```TypeScript
|
|
152
152
|
* libp2p.addEventListener('peer:disconnect', (event) => {
|
|
153
153
|
* const peerId = event.detail
|
|
154
154
|
* // ...
|
|
@@ -163,7 +163,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
163
163
|
*
|
|
164
164
|
* @example
|
|
165
165
|
*
|
|
166
|
-
* ```
|
|
166
|
+
* ```TypeScript
|
|
167
167
|
* libp2p.addEventListener('peer:identify', (event) => {
|
|
168
168
|
* const identifyResult = event.detail
|
|
169
169
|
* // ...
|
|
@@ -189,7 +189,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
189
189
|
*
|
|
190
190
|
* @example
|
|
191
191
|
*
|
|
192
|
-
* ```
|
|
192
|
+
* ```TypeScript
|
|
193
193
|
* libp2p.addEventListener('self:peer:update', (event) => {
|
|
194
194
|
* const { peer } = event.detail
|
|
195
195
|
* // ...
|
|
@@ -224,7 +224,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
224
224
|
/**
|
|
225
225
|
* This event notifies listeners that the node has started
|
|
226
226
|
*
|
|
227
|
-
* ```
|
|
227
|
+
* ```TypeScript
|
|
228
228
|
* libp2p.addEventListener('start', (event) => {
|
|
229
229
|
* console.info(libp2p.isStarted()) // true
|
|
230
230
|
* })
|
|
@@ -234,7 +234,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
234
234
|
/**
|
|
235
235
|
* This event notifies listeners that the node has stopped
|
|
236
236
|
*
|
|
237
|
-
* ```
|
|
237
|
+
* ```TypeScript
|
|
238
238
|
* libp2p.addEventListener('stop', (event) => {
|
|
239
239
|
* console.info(libp2p.isStarted()) // false
|
|
240
240
|
* })
|
|
@@ -248,7 +248,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
248
248
|
*
|
|
249
249
|
* @example
|
|
250
250
|
*
|
|
251
|
-
* ```
|
|
251
|
+
* ```TypeScript
|
|
252
252
|
* const node = await createLibp2p({
|
|
253
253
|
* // ...other options
|
|
254
254
|
* services: {
|
|
@@ -300,7 +300,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
300
300
|
*
|
|
301
301
|
* @example
|
|
302
302
|
*
|
|
303
|
-
* ```
|
|
303
|
+
* ```TypeScript
|
|
304
304
|
* console.info(libp2p.peerId)
|
|
305
305
|
* // PeerId(12D3Foo...)
|
|
306
306
|
* ````
|
|
@@ -312,7 +312,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
312
312
|
*
|
|
313
313
|
* @example
|
|
314
314
|
*
|
|
315
|
-
* ```
|
|
315
|
+
* ```TypeScript
|
|
316
316
|
* const peer = await libp2p.peerStore.get(peerId)
|
|
317
317
|
* console.info(peer)
|
|
318
318
|
* // { id: PeerId(12D3Foo...), addresses: [] ... }
|
|
@@ -325,7 +325,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
325
325
|
*
|
|
326
326
|
* @example
|
|
327
327
|
*
|
|
328
|
-
* ```
|
|
328
|
+
* ```TypeScript
|
|
329
329
|
* const peerInfo = await libp2p.peerRouting.findPeer(peerId)
|
|
330
330
|
* console.info(peerInfo)
|
|
331
331
|
* // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
|
|
@@ -333,7 +333,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
333
333
|
*
|
|
334
334
|
* @example
|
|
335
335
|
*
|
|
336
|
-
* ```
|
|
336
|
+
* ```TypeScript
|
|
337
337
|
* for await (const peerInfo of libp2p.peerRouting.getClosestPeers(key)) {
|
|
338
338
|
* console.info(peerInfo)
|
|
339
339
|
* // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
|
|
@@ -348,7 +348,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
348
348
|
*
|
|
349
349
|
* @example
|
|
350
350
|
*
|
|
351
|
-
* ```
|
|
351
|
+
* ```TypeScript
|
|
352
352
|
* for await (const peerInfo of libp2p.contentRouting.findProviders(cid)) {
|
|
353
353
|
* console.info(peerInfo)
|
|
354
354
|
* // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
|
|
@@ -362,7 +362,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
362
362
|
*
|
|
363
363
|
* @example
|
|
364
364
|
*
|
|
365
|
-
* ```
|
|
365
|
+
* ```TypeScript
|
|
366
366
|
* const metric = libp2p.metrics.registerMetric({
|
|
367
367
|
* 'my-metric'
|
|
368
368
|
* })
|
|
@@ -390,7 +390,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
390
390
|
*
|
|
391
391
|
* @example
|
|
392
392
|
*
|
|
393
|
-
* ```
|
|
393
|
+
* ```TypeScript
|
|
394
394
|
* const listenMa = libp2p.getMultiaddrs()
|
|
395
395
|
* // [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]
|
|
396
396
|
* ```
|
|
@@ -401,7 +401,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
401
401
|
*
|
|
402
402
|
* @example
|
|
403
403
|
*
|
|
404
|
-
* ```
|
|
404
|
+
* ```TypeScript
|
|
405
405
|
* const protocols = libp2p.getProtocols()
|
|
406
406
|
* // [ '/ipfs/ping/1.0.0', '/ipfs/id/1.0.0' ]
|
|
407
407
|
* ```
|
|
@@ -413,7 +413,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
413
413
|
*
|
|
414
414
|
* @example
|
|
415
415
|
*
|
|
416
|
-
* ```
|
|
416
|
+
* ```TypeScript
|
|
417
417
|
* for (const connection of libp2p.getConnections()) {
|
|
418
418
|
* console.log(peerId, connection.remoteAddr.toString())
|
|
419
419
|
* // Logs the PeerId string and the observed remote multiaddr of each Connection
|
|
@@ -426,7 +426,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
426
426
|
*
|
|
427
427
|
* @example
|
|
428
428
|
*
|
|
429
|
-
* ```
|
|
429
|
+
* ```TypeScript
|
|
430
430
|
* for (const pendingDial of libp2p.getDialQueue()) {
|
|
431
431
|
* console.log(pendingDial)
|
|
432
432
|
* }
|
|
@@ -445,7 +445,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
445
445
|
*
|
|
446
446
|
* @example
|
|
447
447
|
*
|
|
448
|
-
* ```
|
|
448
|
+
* ```TypeScript
|
|
449
449
|
* const conn = await libp2p.dial(remotePeerId)
|
|
450
450
|
*
|
|
451
451
|
* // create a new stream within the connection
|
|
@@ -465,7 +465,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
465
465
|
*
|
|
466
466
|
* @example
|
|
467
467
|
*
|
|
468
|
-
* ```
|
|
468
|
+
* ```TypeScript
|
|
469
469
|
* import { pipe } from 'it-pipe'
|
|
470
470
|
*
|
|
471
471
|
* const { stream, protocol } = await libp2p.dialProtocol(remotePeerId, protocols)
|
|
@@ -484,7 +484,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
484
484
|
*
|
|
485
485
|
* @example
|
|
486
486
|
*
|
|
487
|
-
* ```
|
|
487
|
+
* ```TypeScript
|
|
488
488
|
* await libp2p.hangUp(remotePeerId)
|
|
489
489
|
* ```
|
|
490
490
|
*/
|
|
@@ -498,7 +498,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
498
498
|
*
|
|
499
499
|
* @example
|
|
500
500
|
*
|
|
501
|
-
* ```
|
|
501
|
+
* ```TypeScript
|
|
502
502
|
* const handler = ({ connection, stream, protocol }) => {
|
|
503
503
|
* // use stream or connection according to the needs
|
|
504
504
|
* }
|
|
@@ -516,7 +516,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
516
516
|
*
|
|
517
517
|
* @example
|
|
518
518
|
*
|
|
519
|
-
* ```
|
|
519
|
+
* ```TypeScript
|
|
520
520
|
* libp2p.unhandle(['/echo/1.0.0'])
|
|
521
521
|
* ```
|
|
522
522
|
*/
|
|
@@ -527,7 +527,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
527
527
|
*
|
|
528
528
|
* @example
|
|
529
529
|
*
|
|
530
|
-
* ```
|
|
530
|
+
* ```TypeScript
|
|
531
531
|
* const id = await libp2p.register('/echo/1.0.0', {
|
|
532
532
|
* onConnect: (peer, connection) => {
|
|
533
533
|
* // handle connect
|
|
@@ -545,7 +545,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
545
545
|
*
|
|
546
546
|
* @example
|
|
547
547
|
*
|
|
548
|
-
* ```
|
|
548
|
+
* ```TypeScript
|
|
549
549
|
* const id = await libp2p.register(...)
|
|
550
550
|
*
|
|
551
551
|
* libp2p.unregister(id)
|
|
@@ -582,7 +582,7 @@ export interface NodeInfo {
|
|
|
582
582
|
*
|
|
583
583
|
* @example
|
|
584
584
|
*
|
|
585
|
-
* ```
|
|
585
|
+
* ```TypeScript
|
|
586
586
|
* const controller = new AbortController()
|
|
587
587
|
*
|
|
588
588
|
* aLongRunningOperation({
|
|
@@ -8,7 +8,7 @@ import type { PeerInfo } from '../peer-info/index.js';
|
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
*
|
|
11
|
-
* ```
|
|
11
|
+
* ```TypeScript
|
|
12
12
|
* import { peerRouting, PeerRouting } from '@libp2p/peer-routing'
|
|
13
13
|
*
|
|
14
14
|
* class MyPeerRouter implements PeerRouting {
|
|
@@ -34,7 +34,7 @@ export interface PeerRouting {
|
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
36
36
|
*
|
|
37
|
-
* ```
|
|
37
|
+
* ```TypeScript
|
|
38
38
|
* // ...
|
|
39
39
|
* const peer = await peerRouting.findPeer(peerId, options)
|
|
40
40
|
* ```
|
|
@@ -46,7 +46,7 @@ export interface PeerRouting {
|
|
|
46
46
|
*
|
|
47
47
|
* @example
|
|
48
48
|
*
|
|
49
|
-
* ```
|
|
49
|
+
* ```TypeScript
|
|
50
50
|
* // Iterate over the closest peers found for the given key
|
|
51
51
|
* for await (const peer of peerRouting.getClosestPeers(key)) {
|
|
52
52
|
* console.log(peer.id, peer.multiaddrs)
|
|
@@ -132,7 +132,7 @@ export interface PeerStore {
|
|
|
132
132
|
*
|
|
133
133
|
* @example
|
|
134
134
|
*
|
|
135
|
-
* ```
|
|
135
|
+
* ```TypeScript
|
|
136
136
|
* await peerStore.forEach(peer => {
|
|
137
137
|
* // ...
|
|
138
138
|
* })
|
|
@@ -144,7 +144,7 @@ export interface PeerStore {
|
|
|
144
144
|
*
|
|
145
145
|
* @example
|
|
146
146
|
*
|
|
147
|
-
* ```
|
|
147
|
+
* ```TypeScript
|
|
148
148
|
* for (const peer of await peerStore.all()) {
|
|
149
149
|
* // ...
|
|
150
150
|
* }
|
|
@@ -156,7 +156,7 @@ export interface PeerStore {
|
|
|
156
156
|
*
|
|
157
157
|
* @example
|
|
158
158
|
*
|
|
159
|
-
* ```
|
|
159
|
+
* ```TypeScript
|
|
160
160
|
* await peerStore.addressBook.set(peerId, multiaddrs)
|
|
161
161
|
* await peerStore.addressBook.get(peerId)
|
|
162
162
|
* // multiaddrs[]
|
|
@@ -173,7 +173,7 @@ export interface PeerStore {
|
|
|
173
173
|
*
|
|
174
174
|
* @example
|
|
175
175
|
*
|
|
176
|
-
* ```
|
|
176
|
+
* ```TypeScript
|
|
177
177
|
* await peerStore.has(peerId)
|
|
178
178
|
* // false
|
|
179
179
|
* await peerStore.addressBook.add(peerId, multiaddrs)
|
|
@@ -187,7 +187,7 @@ export interface PeerStore {
|
|
|
187
187
|
*
|
|
188
188
|
* @example
|
|
189
189
|
*
|
|
190
|
-
* ```
|
|
190
|
+
* ```TypeScript
|
|
191
191
|
* const peer = await peerStore.get(peerId)
|
|
192
192
|
* // { .. }
|
|
193
193
|
* ```
|
|
@@ -198,7 +198,7 @@ export interface PeerStore {
|
|
|
198
198
|
*
|
|
199
199
|
* @example
|
|
200
200
|
*
|
|
201
|
-
* ```
|
|
201
|
+
* ```TypeScript
|
|
202
202
|
* await peerStore.save(peerId, {
|
|
203
203
|
* multiaddrs
|
|
204
204
|
* })
|
|
@@ -210,7 +210,7 @@ export interface PeerStore {
|
|
|
210
210
|
*
|
|
211
211
|
* @example
|
|
212
212
|
*
|
|
213
|
-
* ```
|
|
213
|
+
* ```TypeScript
|
|
214
214
|
* await peerStore.patch(peerId, {
|
|
215
215
|
* multiaddrs
|
|
216
216
|
* })
|
|
@@ -222,7 +222,7 @@ export interface PeerStore {
|
|
|
222
222
|
*
|
|
223
223
|
* @example
|
|
224
224
|
*
|
|
225
|
-
* ```
|
|
225
|
+
* ```TypeScript
|
|
226
226
|
* await peerStore.merge(peerId, {
|
|
227
227
|
* multiaddrs
|
|
228
228
|
* })
|
|
@@ -238,7 +238,7 @@ export interface PeerStore {
|
|
|
238
238
|
*
|
|
239
239
|
* @example
|
|
240
240
|
*
|
|
241
|
-
* ```
|
|
241
|
+
* ```TypeScript
|
|
242
242
|
* await peerStore.consumePeerRecord(buf, expectedPeer)
|
|
243
243
|
* ```
|
|
244
244
|
*/
|
|
@@ -146,7 +146,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
|
|
|
146
146
|
*
|
|
147
147
|
* @example
|
|
148
148
|
*
|
|
149
|
-
* ```
|
|
149
|
+
* ```TypeScript
|
|
150
150
|
* const topic = 'topic'
|
|
151
151
|
* const validateMessage = (msgTopic, msg) => {
|
|
152
152
|
* const input = uint8ArrayToString(msg.data)
|
|
@@ -164,7 +164,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
|
|
|
164
164
|
/**
|
|
165
165
|
* Gets a list of topics the node is subscribed to.
|
|
166
166
|
*
|
|
167
|
-
* ```
|
|
167
|
+
* ```TypeScript
|
|
168
168
|
* const topics = libp2p.pubsub.getTopics()
|
|
169
169
|
* ```
|
|
170
170
|
*/
|
|
@@ -174,7 +174,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
|
|
|
174
174
|
*
|
|
175
175
|
* @example
|
|
176
176
|
*
|
|
177
|
-
* ```
|
|
177
|
+
* ```TypeScript
|
|
178
178
|
* const topic = 'topic'
|
|
179
179
|
* const handler = (msg) => {
|
|
180
180
|
* if (msg.topic === topic) {
|
|
@@ -192,7 +192,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
|
|
|
192
192
|
*
|
|
193
193
|
* @example
|
|
194
194
|
*
|
|
195
|
-
* ```
|
|
195
|
+
* ```TypeScript
|
|
196
196
|
* const topic = 'topic'
|
|
197
197
|
* const handler = (msg) => {
|
|
198
198
|
* // msg.data - pubsub data received
|
|
@@ -208,7 +208,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
|
|
|
208
208
|
*
|
|
209
209
|
* @example
|
|
210
210
|
*
|
|
211
|
-
* ```
|
|
211
|
+
* ```TypeScript
|
|
212
212
|
* const peerIds = libp2p.pubsub.getSubscribers(topic)
|
|
213
213
|
* ```
|
|
214
214
|
*/
|
|
@@ -218,7 +218,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
|
|
|
218
218
|
*
|
|
219
219
|
* @example
|
|
220
220
|
*
|
|
221
|
-
* ```
|
|
221
|
+
* ```TypeScript
|
|
222
222
|
* const topic = 'topic'
|
|
223
223
|
* const data = uint8ArrayFromString('data')
|
|
224
224
|
*
|