@helia/libp2p 2.0.0 → 2.1.0-ae012cf9
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 +20 -1
- package/dist/index.min.js +22 -22
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +33 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +43 -16
- package/dist/src/index.js.map +1 -1
- package/dist/src/utils/libp2p-defaults.browser.d.ts +4 -2
- package/dist/src/utils/libp2p-defaults.browser.d.ts.map +1 -1
- package/dist/src/utils/libp2p-defaults.browser.js +5 -9
- package/dist/src/utils/libp2p-defaults.browser.js.map +1 -1
- package/dist/src/utils/libp2p-defaults.d.ts +6 -3
- package/dist/src/utils/libp2p-defaults.d.ts.map +1 -1
- package/dist/src/utils/libp2p-defaults.js +7 -10
- package/dist/src/utils/libp2p-defaults.js.map +1 -1
- package/dist/src/utils/libp2p.d.ts +1 -1
- package/dist/src/utils/libp2p.d.ts.map +1 -1
- package/dist/src/utils/libp2p.js +8 -12
- package/dist/src/utils/libp2p.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +53 -20
- package/src/utils/libp2p-defaults.browser.ts +10 -13
- package/src/utils/libp2p-defaults.ts +13 -15
- package/src/utils/libp2p.ts +8 -14
- package/dist/typedoc-urls.json +0 -9
package/dist/src/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Adds libp2p functionality to Helia
|
|
5
5
|
*
|
|
6
|
-
* @example
|
|
6
|
+
* @example With default config
|
|
7
7
|
*
|
|
8
8
|
* ```ts
|
|
9
9
|
* import { createHelia } from 'helia'
|
|
@@ -13,14 +13,36 @@
|
|
|
13
13
|
*
|
|
14
14
|
* console.info(node.libp2p.peerId) // 12D3Koo...
|
|
15
15
|
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example Custom config
|
|
18
|
+
*
|
|
19
|
+
* By default `withLibp2p` configures a libp2p node for the current environment.
|
|
20
|
+
*
|
|
21
|
+
* Any options passed will be merged with the default config.
|
|
22
|
+
*
|
|
23
|
+
* For full control over your node (and the bundle size), use `withLibp2pLight`:
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { createHelia } from 'helia'
|
|
27
|
+
* import { withLibp2pLight } from '@helia/libp2p'
|
|
28
|
+
*
|
|
29
|
+
* const node = await withLibp2pLight(createHelia(), {
|
|
30
|
+
* //... libp2p config here
|
|
31
|
+
* }).start()
|
|
32
|
+
*
|
|
33
|
+
* console.info(node.libp2p.peerId) // 12D3Koo...
|
|
34
|
+
* ```
|
|
16
35
|
*/
|
|
17
36
|
import type { DefaultLibp2pServices } from './utils/libp2p-defaults.ts';
|
|
18
|
-
import type { CreateLibp2pOptions } from './utils/libp2p.ts';
|
|
19
37
|
import type { Helia } from '@helia/interface';
|
|
20
38
|
import type { Libp2p, ServiceMap } from '@libp2p/interface';
|
|
39
|
+
import type { KeychainInit } from '@libp2p/keychain';
|
|
40
|
+
import type { Libp2pOptions } from 'libp2p';
|
|
21
41
|
export { libp2pDefaults } from './utils/libp2p-defaults.ts';
|
|
22
42
|
export type { DefaultLibp2pServices } from './utils/libp2p-defaults.ts';
|
|
23
|
-
export
|
|
43
|
+
export interface CreateLibp2pOptions<T extends ServiceMap> extends Libp2pOptions<T> {
|
|
44
|
+
keychain?: KeychainInit;
|
|
45
|
+
}
|
|
24
46
|
export interface HeliaWithLibp2p<M extends ServiceMap = DefaultLibp2pServices> extends Helia {
|
|
25
47
|
/**
|
|
26
48
|
* Libp2p provides a peer identity and a networking layer
|
|
@@ -30,5 +52,12 @@ export interface HeliaWithLibp2p<M extends ServiceMap = DefaultLibp2pServices> e
|
|
|
30
52
|
/**
|
|
31
53
|
* Return a Helia node augmented with a libp2p instance
|
|
32
54
|
*/
|
|
33
|
-
export declare function withLibp2p<H extends Helia, M extends ServiceMap
|
|
55
|
+
export declare function withLibp2p<H extends Helia, M extends ServiceMap>(helia: H, opts?: CreateLibp2pOptions<M>): H & HeliaWithLibp2p<DefaultLibp2pServices & M>;
|
|
56
|
+
/**
|
|
57
|
+
* Return a Helia node augmented with a libp2p instance. The passed
|
|
58
|
+
* configuration is passed to `createLibp2p` without adding any default config.
|
|
59
|
+
*
|
|
60
|
+
* Use this if you do not wish to have any extra config added.
|
|
61
|
+
*/
|
|
62
|
+
export declare function withLibp2pLight<H extends Helia, M extends ServiceMap = ServiceMap>(helia: H, opts: CreateLibp2pOptions<M>): H & HeliaWithLibp2p<M>;
|
|
34
63
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAUH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,KAAK,EAA8B,MAAM,kBAAkB,CAAA;AACzE,OAAO,KAAK,EAAE,MAAM,EAAY,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAG3C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,YAAY,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAEvE,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;IACjF,QAAQ,CAAC,EAAE,YAAY,CAAA;CACxB;AAED,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,UAAU,GAAG,qBAAqB,CAAE,SAAQ,KAAK;IAC1F;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;CAClB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAE,CAAC,SAAS,KAAK,EAAE,CAAC,SAAS,UAAU,EAAG,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,qBAAqB,GAAG,CAAC,CAAC,CAE3J;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAE,CAAC,SAAS,KAAK,EAAE,CAAC,SAAS,UAAU,GAAG,UAAU,EAAG,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAoGpJ"}
|
package/dist/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Adds libp2p functionality to Helia
|
|
5
5
|
*
|
|
6
|
-
* @example
|
|
6
|
+
* @example With default config
|
|
7
7
|
*
|
|
8
8
|
* ```ts
|
|
9
9
|
* import { createHelia } from 'helia'
|
|
@@ -13,31 +13,48 @@
|
|
|
13
13
|
*
|
|
14
14
|
* console.info(node.libp2p.peerId) // 12D3Koo...
|
|
15
15
|
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example Custom config
|
|
18
|
+
*
|
|
19
|
+
* By default `withLibp2p` configures a libp2p node for the current environment.
|
|
20
|
+
*
|
|
21
|
+
* Any options passed will be merged with the default config.
|
|
22
|
+
*
|
|
23
|
+
* For full control over your node (and the bundle size), use `withLibp2pLight`:
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { createHelia } from 'helia'
|
|
27
|
+
* import { withLibp2pLight } from '@helia/libp2p'
|
|
28
|
+
*
|
|
29
|
+
* const node = await withLibp2pLight(createHelia(), {
|
|
30
|
+
* //... libp2p config here
|
|
31
|
+
* }).start()
|
|
32
|
+
*
|
|
33
|
+
* console.info(node.libp2p.peerId) // 12D3Koo...
|
|
34
|
+
* ```
|
|
16
35
|
*/
|
|
36
|
+
import { loadOrCreateSelfKey } from '@libp2p/config';
|
|
17
37
|
import { NotStartedError } from '@libp2p/interface';
|
|
18
38
|
import { peerIdFromCID } from '@libp2p/peer-id';
|
|
19
39
|
import forEach from 'it-foreach';
|
|
20
|
-
import { isLibp2p } from 'libp2p';
|
|
40
|
+
import { createLibp2p, isLibp2p } from 'libp2p';
|
|
21
41
|
import { userAgent } from 'libp2p/user-agent';
|
|
22
42
|
import { libp2pRouting } from "./routing.js";
|
|
23
|
-
import {
|
|
43
|
+
import { libp2pDefaults } from "./utils/libp2p-defaults.js";
|
|
24
44
|
export { libp2pDefaults } from "./utils/libp2p-defaults.js";
|
|
25
|
-
async function getLibp2p(helia, opts) {
|
|
26
|
-
const heliaAgent = `${helia.info.name}/${helia.info.version} ${userAgent()}`;
|
|
27
|
-
return createLibp2p(helia, {
|
|
28
|
-
...opts,
|
|
29
|
-
dns: helia.dns,
|
|
30
|
-
logger: helia.logger,
|
|
31
|
-
datastore: helia.datastore,
|
|
32
|
-
nodeInfo: {
|
|
33
|
-
userAgent: opts?.nodeInfo?.userAgent ?? heliaAgent
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
45
|
/**
|
|
38
46
|
* Return a Helia node augmented with a libp2p instance
|
|
39
47
|
*/
|
|
40
48
|
export function withLibp2p(helia, opts) {
|
|
49
|
+
return withLibp2pLight(helia, libp2pDefaults(opts));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Return a Helia node augmented with a libp2p instance. The passed
|
|
53
|
+
* configuration is passed to `createLibp2p` without adding any default config.
|
|
54
|
+
*
|
|
55
|
+
* Use this if you do not wish to have any extra config added.
|
|
56
|
+
*/
|
|
57
|
+
export function withLibp2pLight(helia, opts) {
|
|
41
58
|
let libp2p;
|
|
42
59
|
// add a getter that informs the user they need to start Helia
|
|
43
60
|
Object.defineProperty(helia, 'libp2p', {
|
|
@@ -54,7 +71,17 @@ export function withLibp2p(helia, opts) {
|
|
|
54
71
|
name: 'libp2p',
|
|
55
72
|
start: async (helia) => {
|
|
56
73
|
if (libp2p == null) {
|
|
57
|
-
|
|
74
|
+
// if no peer id was passed, try to load it from the keychain
|
|
75
|
+
if (opts.privateKey == null) {
|
|
76
|
+
opts.privateKey = await loadOrCreateSelfKey(helia.datastore, opts.keychain);
|
|
77
|
+
}
|
|
78
|
+
// copy options from Helia node
|
|
79
|
+
opts.nodeInfo ??= {};
|
|
80
|
+
opts.nodeInfo.name ??= helia.info.name;
|
|
81
|
+
opts.nodeInfo.version ??= helia.info.version;
|
|
82
|
+
opts.nodeInfo.userAgent ??= `${helia.info.name}/${helia.info.version} ${userAgent()}`;
|
|
83
|
+
opts.datastore ??= helia.datastore;
|
|
84
|
+
libp2p = await createLibp2p(opts);
|
|
58
85
|
// override peer discovery methods to ensure we persist peer data in the
|
|
59
86
|
// peer store, otherwise we can't dial by peer id without extra lookups
|
|
60
87
|
const findProviders = helia.routing.findProviders.bind(helia.routing);
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AA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KAAK,iBAAiB,EAAE,CAAC;oBACnC,MAAM,GAAG,CAAA;gBACX,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,MAAM,MAAM,EAAE,IAAI,EAAE,CAAA;QACtB,CAAC;KACF,CAAA;IAED,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAErB,8EAA8E;IAC9E,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,UAAU,CAAE,IAA0C;IAC7D,OAAO;QACL,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,UAAU,EAAE,IAAI,CAAC,UAAU;KAC5B,CAAA;AACH,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CreateLibp2pOptions } from '../index.ts';
|
|
2
2
|
import type { HTTP } from '@libp2p/http';
|
|
3
3
|
import type { Identify, IdentifyPush } from '@libp2p/identify';
|
|
4
|
+
import type { ServiceMap } from '@libp2p/interface';
|
|
4
5
|
import type { KadDHT } from '@libp2p/kad-dht';
|
|
5
6
|
import type { Ping } from '@libp2p/ping';
|
|
6
7
|
import type { Libp2pOptions } from 'libp2p';
|
|
@@ -15,5 +16,6 @@ export interface DefaultLibp2pServices extends Record<string, unknown> {
|
|
|
15
16
|
ping: Ping;
|
|
16
17
|
http: HTTP;
|
|
17
18
|
}
|
|
18
|
-
export
|
|
19
|
+
export type DefaultLibp2pOptions<M extends ServiceMap> = Libp2pOptions<DefaultLibp2pServices & M> & Required<Pick<Libp2pOptions<DefaultLibp2pServices & M>, 'nodeInfo' | 'addresses' | 'transports' | 'connectionEncrypters' | 'streamMuxers' | 'peerDiscovery' | 'services'>>;
|
|
20
|
+
export declare function libp2pDefaults<M extends ServiceMap = ServiceMap>(options?: CreateLibp2pOptions<M>): DefaultLibp2pOptions<M>;
|
|
19
21
|
//# sourceMappingURL=libp2p-defaults.browser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p-defaults.browser.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.browser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"libp2p-defaults.browser.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.browser.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAE3C,MAAM,WAAW,qBAAsB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACpE,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;IACd,uBAAuB,EAAE,OAAO,CAAA;IAChC,oBAAoB,EAAE,OAAO,CAAA;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,QAAQ,CAAA;IAClB,YAAY,EAAE,YAAY,CAAA;IAC1B,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,IAAI,CAAA;CACX;AAED,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,UAAU,IAAI,aAAa,CAAC,qBAAqB,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,qBAAqB,GAAG,CAAC,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,YAAY,GAAG,sBAAsB,GAAG,cAAc,GAAG,eAAe,GAAG,UAAU,CAAC,CAAC,CAAA;AAE9Q,wBAAgB,cAAc,CAAE,CAAC,SAAS,UAAU,GAAG,UAAU,EAAG,OAAO,GAAE,mBAAmB,CAAC,CAAC,CAAM,GAAG,oBAAoB,CAAC,CAAC,CAAC,CA6CjI"}
|
|
@@ -14,19 +14,14 @@ import { mplex } from '@libp2p/mplex';
|
|
|
14
14
|
import { ping } from '@libp2p/ping';
|
|
15
15
|
import { webRTC, webRTCDirect } from '@libp2p/webrtc';
|
|
16
16
|
import { webSockets } from '@libp2p/websockets';
|
|
17
|
-
import { userAgent } from 'libp2p/user-agent';
|
|
18
17
|
import { bootstrapConfig } from "./bootstrappers.js";
|
|
19
18
|
export function libp2pDefaults(options = {}) {
|
|
20
|
-
let agentVersion;
|
|
21
|
-
if (options.name != null && options.version != null) {
|
|
22
|
-
agentVersion = `${options.name}/${options.version} ${userAgent()}`;
|
|
23
|
-
}
|
|
24
19
|
return {
|
|
25
|
-
privateKey: options.privateKey,
|
|
26
|
-
dns: options.dns,
|
|
27
20
|
nodeInfo: {
|
|
28
|
-
|
|
21
|
+
...options.nodeInfo
|
|
29
22
|
},
|
|
23
|
+
privateKey: options.privateKey,
|
|
24
|
+
dns: options.dns,
|
|
30
25
|
addresses: {
|
|
31
26
|
listen: [
|
|
32
27
|
'/p2p-circuit',
|
|
@@ -61,7 +56,8 @@ export function libp2pDefaults(options = {}) {
|
|
|
61
56
|
identifyPush: identifyPush(),
|
|
62
57
|
keychain: keychain(options.keychain),
|
|
63
58
|
ping: ping(),
|
|
64
|
-
http: http()
|
|
59
|
+
http: http(),
|
|
60
|
+
...options.services
|
|
65
61
|
}
|
|
66
62
|
};
|
|
67
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p-defaults.browser.js","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,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EAAE,CAAC;YAChG,GAAG,EAAE,MAAM,CAAC;gBACV,UAAU,EAAE,IAAI;aACjB,CAAC;YACF,QAAQ,EAAE,QAAQ,EAAE;YACpB,YAAY,EAAE,YAAY,EAAE;YAC5B,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC;YACpC,IAAI,EAAE,IAAI,EAAE;YACZ,IAAI,EAAE,IAAI,EAAE;YACZ,GAAG,OAAO,CAAC,QAAQ;SACb;KACT,CAAA;AACH,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CreateLibp2pOptions } from '../index.ts';
|
|
2
2
|
import type { AutoTLS } from '@ipshipyard/libp2p-auto-tls';
|
|
3
3
|
import type { CircuitRelayService } from '@libp2p/circuit-relay-v2';
|
|
4
4
|
import type { HTTP } from '@libp2p/http';
|
|
5
5
|
import type { Identify, IdentifyPush } from '@libp2p/identify';
|
|
6
|
+
import type { ServiceMap } from '@libp2p/interface';
|
|
6
7
|
import type { KadDHT } from '@libp2p/kad-dht';
|
|
7
8
|
import type { Keychain } from '@libp2p/keychain';
|
|
8
9
|
import type { Ping } from '@libp2p/ping';
|
|
@@ -22,6 +23,7 @@ export interface DefaultLibp2pServices extends Record<string, unknown> {
|
|
|
22
23
|
upnp: unknown;
|
|
23
24
|
http: HTTP;
|
|
24
25
|
}
|
|
26
|
+
export type DefaultLibp2pOptions<M extends ServiceMap> = Libp2pOptions<DefaultLibp2pServices & M> & Required<Pick<Libp2pOptions<DefaultLibp2pServices & M>, 'nodeInfo' | 'addresses' | 'transports' | 'connectionEncrypters' | 'streamMuxers' | 'peerDiscovery' | 'services'>>;
|
|
25
27
|
/**
|
|
26
28
|
* Returns the default libp2p config used by Helia which can then be modified or
|
|
27
29
|
* extended to suit individual applications.
|
|
@@ -30,7 +32,8 @@ export interface DefaultLibp2pServices extends Record<string, unknown> {
|
|
|
30
32
|
*
|
|
31
33
|
* ```ts
|
|
32
34
|
* import { myService } from '@example/my-service'
|
|
33
|
-
* import { createHelia
|
|
35
|
+
* import { createHelia } from 'helia'
|
|
36
|
+
* import { libp2pDefaults } from '@helia/libp2p'
|
|
34
37
|
*
|
|
35
38
|
* // get a copy of the default libp2p config
|
|
36
39
|
* const libp2p = libp2pDefaults()
|
|
@@ -47,5 +50,5 @@ export interface DefaultLibp2pServices extends Record<string, unknown> {
|
|
|
47
50
|
* helia.libp2p.services.myService.serviceMethod()
|
|
48
51
|
* ```
|
|
49
52
|
*/
|
|
50
|
-
export declare function libp2pDefaults(options?:
|
|
53
|
+
export declare function libp2pDefaults<M extends ServiceMap = ServiceMap>(options?: CreateLibp2pOptions<M>): DefaultLibp2pOptions<M>;
|
|
51
54
|
//# sourceMappingURL=libp2p-defaults.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p-defaults.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"libp2p-defaults.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAA;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AACnE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAE3C,MAAM,WAAW,qBAAsB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACpE,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;IACd,uBAAuB,EAAE,OAAO,CAAA;IAChC,oBAAoB,EAAE,OAAO,CAAA;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,QAAQ,CAAA;IAClB,YAAY,EAAE,YAAY,CAAA;IAC1B,QAAQ,EAAE,QAAQ,CAAA;IAClB,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,mBAAmB,CAAA;IAC1B,IAAI,EAAE,OAAO,CAAA;IACb,IAAI,EAAE,IAAI,CAAA;CACX;AAED,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,UAAU,IAAI,aAAa,CAAC,qBAAqB,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,qBAAqB,GAAG,CAAC,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,YAAY,GAAG,sBAAsB,GAAG,cAAc,GAAG,eAAe,GAAG,UAAU,CAAC,CAAC,CAAA;AAE9Q;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,CAAE,CAAC,SAAS,UAAU,GAAG,UAAU,EAAG,OAAO,GAAE,mBAAmB,CAAC,CAAC,CAAM,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAsDjI"}
|
|
@@ -19,7 +19,6 @@ import { tls } from '@libp2p/tls';
|
|
|
19
19
|
import { uPnPNAT } from '@libp2p/upnp-nat';
|
|
20
20
|
import { webRTC, webRTCDirect } from '@libp2p/webrtc';
|
|
21
21
|
import { webSockets } from '@libp2p/websockets';
|
|
22
|
-
import { userAgent } from 'libp2p/user-agent';
|
|
23
22
|
import { bootstrapConfig } from "./bootstrappers.js";
|
|
24
23
|
/**
|
|
25
24
|
* Returns the default libp2p config used by Helia which can then be modified or
|
|
@@ -29,7 +28,8 @@ import { bootstrapConfig } from "./bootstrappers.js";
|
|
|
29
28
|
*
|
|
30
29
|
* ```ts
|
|
31
30
|
* import { myService } from '@example/my-service'
|
|
32
|
-
* import { createHelia
|
|
31
|
+
* import { createHelia } from 'helia'
|
|
32
|
+
* import { libp2pDefaults } from '@helia/libp2p'
|
|
33
33
|
*
|
|
34
34
|
* // get a copy of the default libp2p config
|
|
35
35
|
* const libp2p = libp2pDefaults()
|
|
@@ -47,16 +47,12 @@ import { bootstrapConfig } from "./bootstrappers.js";
|
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
49
|
export function libp2pDefaults(options = {}) {
|
|
50
|
-
let agentVersion;
|
|
51
|
-
if (options.name != null && options.version != null) {
|
|
52
|
-
agentVersion = `${options.name}/${options.version} ${userAgent()}`;
|
|
53
|
-
}
|
|
54
50
|
return {
|
|
55
|
-
privateKey: options.privateKey,
|
|
56
|
-
dns: options.dns,
|
|
57
51
|
nodeInfo: {
|
|
58
|
-
|
|
52
|
+
...options.nodeInfo
|
|
59
53
|
},
|
|
54
|
+
privateKey: options.privateKey,
|
|
55
|
+
dns: options.dns,
|
|
60
56
|
addresses: {
|
|
61
57
|
listen: [
|
|
62
58
|
'/ip4/0.0.0.0/tcp/0',
|
|
@@ -100,7 +96,8 @@ export function libp2pDefaults(options = {}) {
|
|
|
100
96
|
ping: ping(),
|
|
101
97
|
relay: circuitRelayServer(),
|
|
102
98
|
upnp: uPnPNAT(),
|
|
103
|
-
http: http()
|
|
99
|
+
http: http(),
|
|
100
|
+
...options.services
|
|
104
101
|
}
|
|
105
102
|
};
|
|
106
103
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p-defaults.js","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA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ACR,GAAG,OAAO,CAAC,QAAQ;SACpB;QACD,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,SAAS,EAAE;YACT,MAAM,EAAE;gBACN,oBAAoB;gBACpB,uBAAuB;gBACvB,kCAAkC;gBAClC,eAAe;gBACf,kBAAkB;gBAClB,6BAA6B;gBAC7B,cAAc;aACf;SACF;QACD,UAAU,EAAE;YACV,qBAAqB,EAAE;YACvB,GAAG,EAAE;YACL,MAAM,EAAE;YACR,YAAY,EAAE;YACd,UAAU,EAAE;SACb;QACD,oBAAoB,EAAE;YACpB,KAAK,EAAE;YACP,GAAG,EAAE;SACN;QACD,YAAY,EAAE;YACZ,KAAK,EAAE;YACP,KAAK,EAAE;SACR;QACD,aAAa,EAAE;YACb,IAAI,EAAE;YACN,SAAS,CAAC,eAAe,CAAC;SAC3B;QACD,QAAQ,EAAE;YACR,OAAO,EAAE,OAAO,EAAE;YAClB,OAAO,EAAE,OAAO,EAAE;YAClB,KAAK,EAAE,KAAK,EAAE;YACd,oBAAoB,EAAE,0CAA0C,CAAC,4BAA4B,EAAE,CAAC;YAChG,uBAAuB,EAAE,6CAA6C,CAAC,4BAA4B,EAAE,CAAC;YACtG,GAAG,EAAE,MAAM,EAAE;YACb,QAAQ,EAAE,QAAQ,EAAE;YACpB,YAAY,EAAE,YAAY,EAAE;YAC5B,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC;YACpC,IAAI,EAAE,IAAI,EAAE;YACZ,KAAK,EAAE,kBAAkB,EAAE;YAC3B,IAAI,EAAE,OAAO,EAAE;YACf,IAAI,EAAE,IAAI,EAAE;YACZ,GAAG,OAAO,CAAC,QAAQ;SACb;KACT,CAAA;AACH,CAAC"}
|
|
@@ -13,5 +13,5 @@ export interface Libp2pDefaultsOptions {
|
|
|
13
13
|
name?: string;
|
|
14
14
|
version?: string;
|
|
15
15
|
}
|
|
16
|
-
export declare function
|
|
16
|
+
export declare function createLibp2pOptions<T extends Record<string, unknown>>(helia: Helia, options: CreateLibp2pOptions<T>): Promise<Libp2p<T>>;
|
|
17
17
|
//# sourceMappingURL=libp2p.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"libp2p.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAE3C,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;IAC9F,QAAQ,CAAC,EAAE,YAAY,CAAA;CACxB;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,CAAC,EAAE,GAAG,CAAA;IACT,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,wBAAsB,mBAAmB,CAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAG,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAiBhJ"}
|
package/dist/src/utils/libp2p.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import { loadOrCreateSelfKey } from '@libp2p/config';
|
|
2
|
-
import { createLibp2p as create } from 'libp2p';
|
|
3
1
|
import { libp2pDefaults } from "./libp2p-defaults.js";
|
|
4
|
-
export async function
|
|
2
|
+
export async function createLibp2pOptions(helia, options) {
|
|
5
3
|
const libp2pOptions = options ?? {};
|
|
6
|
-
// if no peer id was passed, try to load it from the keychain
|
|
7
|
-
if (libp2pOptions.privateKey == null && options.datastore != null) {
|
|
8
|
-
libp2pOptions.privateKey = await loadOrCreateSelfKey(options.datastore, options.keychain);
|
|
9
|
-
}
|
|
10
4
|
const defaults = libp2pDefaults({
|
|
11
5
|
...libp2pOptions,
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
nodeInfo: {
|
|
7
|
+
...libp2pOptions.nodeInfo,
|
|
8
|
+
name: libp2pOptions.nodeInfo?.name ?? helia.info.name,
|
|
9
|
+
version: libp2pOptions.nodeInfo?.version ?? helia.info.version
|
|
10
|
+
}
|
|
14
11
|
});
|
|
15
12
|
defaults.datastore = defaults.datastore ?? options.datastore;
|
|
16
|
-
|
|
13
|
+
return {
|
|
17
14
|
...defaults,
|
|
18
15
|
...libp2pOptions
|
|
19
|
-
}
|
|
20
|
-
return node;
|
|
16
|
+
};
|
|
21
17
|
}
|
|
22
18
|
//# sourceMappingURL=libp2p.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p.js","sourceRoot":"","sources":["../../../src/utils/libp2p.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"libp2p.js","sourceRoot":"","sources":["../../../src/utils/libp2p.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAmBrD,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAsC,KAAY,EAAE,OAA+B;IAC1H,MAAM,aAAa,GAAG,OAAO,IAAI,EAAE,CAAA;IAEnC,MAAM,QAAQ,GAAQ,cAAc,CAAC;QACnC,GAAG,aAAa;QAChB,QAAQ,EAAE;YACR,GAAG,aAAa,CAAC,QAAQ;YACzB,IAAI,EAAE,aAAa,CAAC,QAAQ,EAAE,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI;YACrD,OAAO,EAAE,aAAa,CAAC,QAAQ,EAAE,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO;SAC/D;KACF,CAAC,CAAA;IACF,QAAQ,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAA;IAE5D,OAAO;QACL,GAAG,QAAQ;QACX,GAAG,aAAa;KACjB,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/libp2p",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0-ae012cf9",
|
|
4
4
|
"description": "libp2p functionality for Helia",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/libp2p#readme",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@chainsafe/libp2p-noise": "^17.0.0",
|
|
52
52
|
"@chainsafe/libp2p-yamux": "^8.0.1",
|
|
53
|
-
"@helia/delegated-routing-client": "
|
|
53
|
+
"@helia/delegated-routing-client": "1.0.6-ae012cf9",
|
|
54
54
|
"@helia/delegated-routing-v1-http-api-client": "^9.0.0",
|
|
55
|
-
"@helia/interface": "
|
|
55
|
+
"@helia/interface": "7.1.1-ae012cf9",
|
|
56
56
|
"@ipshipyard/libp2p-auto-tls": "^2.0.1",
|
|
57
57
|
"@libp2p/autonat": "^3.0.21",
|
|
58
58
|
"@libp2p/bootstrap": "^12.0.24",
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Adds libp2p functionality to Helia
|
|
5
5
|
*
|
|
6
|
-
* @example
|
|
6
|
+
* @example With default config
|
|
7
7
|
*
|
|
8
8
|
* ```ts
|
|
9
9
|
* import { createHelia } from 'helia'
|
|
@@ -13,25 +13,49 @@
|
|
|
13
13
|
*
|
|
14
14
|
* console.info(node.libp2p.peerId) // 12D3Koo...
|
|
15
15
|
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example Custom config
|
|
18
|
+
*
|
|
19
|
+
* By default `withLibp2p` configures a libp2p node for the current environment.
|
|
20
|
+
*
|
|
21
|
+
* Any options passed will be merged with the default config.
|
|
22
|
+
*
|
|
23
|
+
* For full control over your node (and the bundle size), use `withLibp2pLight`:
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { createHelia } from 'helia'
|
|
27
|
+
* import { withLibp2pLight } from '@helia/libp2p'
|
|
28
|
+
*
|
|
29
|
+
* const node = await withLibp2pLight(createHelia(), {
|
|
30
|
+
* //... libp2p config here
|
|
31
|
+
* }).start()
|
|
32
|
+
*
|
|
33
|
+
* console.info(node.libp2p.peerId) // 12D3Koo...
|
|
34
|
+
* ```
|
|
16
35
|
*/
|
|
17
36
|
|
|
37
|
+
import { loadOrCreateSelfKey } from '@libp2p/config'
|
|
18
38
|
import { NotStartedError } from '@libp2p/interface'
|
|
19
39
|
import { peerIdFromCID } from '@libp2p/peer-id'
|
|
20
40
|
import forEach from 'it-foreach'
|
|
21
|
-
import { isLibp2p } from 'libp2p'
|
|
41
|
+
import { createLibp2p, isLibp2p } from 'libp2p'
|
|
22
42
|
import { userAgent } from 'libp2p/user-agent'
|
|
23
43
|
import { libp2pRouting } from './routing.ts'
|
|
24
|
-
import {
|
|
44
|
+
import { libp2pDefaults } from './utils/libp2p-defaults.ts'
|
|
25
45
|
import type { DefaultLibp2pServices } from './utils/libp2p-defaults.ts'
|
|
26
|
-
import type { CreateLibp2pOptions } from './utils/libp2p.ts'
|
|
27
46
|
import type { Helia, HeliaMixin, Peer, Provider } from '@helia/interface'
|
|
28
47
|
import type { Libp2p, PeerInfo, ServiceMap } from '@libp2p/interface'
|
|
48
|
+
import type { KeychainInit } from '@libp2p/keychain'
|
|
29
49
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
50
|
+
import type { Libp2pOptions } from 'libp2p'
|
|
30
51
|
import type { CID } from 'multiformats'
|
|
31
52
|
|
|
32
53
|
export { libp2pDefaults } from './utils/libp2p-defaults.ts'
|
|
33
54
|
export type { DefaultLibp2pServices } from './utils/libp2p-defaults.ts'
|
|
34
|
-
|
|
55
|
+
|
|
56
|
+
export interface CreateLibp2pOptions<T extends ServiceMap> extends Libp2pOptions<T> {
|
|
57
|
+
keychain?: KeychainInit
|
|
58
|
+
}
|
|
35
59
|
|
|
36
60
|
export interface HeliaWithLibp2p<M extends ServiceMap = DefaultLibp2pServices> extends Helia {
|
|
37
61
|
/**
|
|
@@ -40,24 +64,20 @@ export interface HeliaWithLibp2p<M extends ServiceMap = DefaultLibp2pServices> e
|
|
|
40
64
|
libp2p: Libp2p<M>
|
|
41
65
|
}
|
|
42
66
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
dns: helia.dns,
|
|
49
|
-
logger: helia.logger,
|
|
50
|
-
datastore: helia.datastore,
|
|
51
|
-
nodeInfo: {
|
|
52
|
-
userAgent: opts?.nodeInfo?.userAgent ?? heliaAgent
|
|
53
|
-
}
|
|
54
|
-
})
|
|
67
|
+
/**
|
|
68
|
+
* Return a Helia node augmented with a libp2p instance
|
|
69
|
+
*/
|
|
70
|
+
export function withLibp2p <H extends Helia, M extends ServiceMap> (helia: H, opts?: CreateLibp2pOptions<M>): H & HeliaWithLibp2p<DefaultLibp2pServices & M> {
|
|
71
|
+
return withLibp2pLight(helia, libp2pDefaults(opts))
|
|
55
72
|
}
|
|
56
73
|
|
|
57
74
|
/**
|
|
58
|
-
* Return a Helia node augmented with a libp2p instance
|
|
75
|
+
* Return a Helia node augmented with a libp2p instance. The passed
|
|
76
|
+
* configuration is passed to `createLibp2p` without adding any default config.
|
|
77
|
+
*
|
|
78
|
+
* Use this if you do not wish to have any extra config added.
|
|
59
79
|
*/
|
|
60
|
-
export function
|
|
80
|
+
export function withLibp2pLight <H extends Helia, M extends ServiceMap = ServiceMap> (helia: H, opts: CreateLibp2pOptions<M>): H & HeliaWithLibp2p<M> {
|
|
61
81
|
let libp2p: Libp2p
|
|
62
82
|
|
|
63
83
|
// add a getter that informs the user they need to start Helia
|
|
@@ -77,7 +97,20 @@ export function withLibp2p <H extends Helia, M extends ServiceMap = ServiceMap>
|
|
|
77
97
|
name: 'libp2p',
|
|
78
98
|
start: async (helia) => {
|
|
79
99
|
if (libp2p == null) {
|
|
80
|
-
|
|
100
|
+
// if no peer id was passed, try to load it from the keychain
|
|
101
|
+
if (opts.privateKey == null) {
|
|
102
|
+
opts.privateKey = await loadOrCreateSelfKey(helia.datastore, opts.keychain)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// copy options from Helia node
|
|
106
|
+
opts.nodeInfo ??= {}
|
|
107
|
+
opts.nodeInfo.name ??= helia.info.name
|
|
108
|
+
opts.nodeInfo.version ??= helia.info.version
|
|
109
|
+
opts.nodeInfo.userAgent ??= `${helia.info.name}/${helia.info.version} ${userAgent()}`
|
|
110
|
+
|
|
111
|
+
opts.datastore ??= helia.datastore
|
|
112
|
+
|
|
113
|
+
libp2p = await createLibp2p(opts)
|
|
81
114
|
|
|
82
115
|
// override peer discovery methods to ensure we persist peer data in the
|
|
83
116
|
// peer store, otherwise we can't dial by peer id without extra lookups
|
|
@@ -14,11 +14,11 @@ import { mplex } from '@libp2p/mplex'
|
|
|
14
14
|
import { ping } from '@libp2p/ping'
|
|
15
15
|
import { webRTC, webRTCDirect } from '@libp2p/webrtc'
|
|
16
16
|
import { webSockets } from '@libp2p/websockets'
|
|
17
|
-
import { userAgent } from 'libp2p/user-agent'
|
|
18
17
|
import { bootstrapConfig } from './bootstrappers.ts'
|
|
19
|
-
import type {
|
|
18
|
+
import type { CreateLibp2pOptions } from '../index.ts'
|
|
20
19
|
import type { HTTP } from '@libp2p/http'
|
|
21
20
|
import type { Identify, IdentifyPush } from '@libp2p/identify'
|
|
21
|
+
import type { ServiceMap } from '@libp2p/interface'
|
|
22
22
|
import type { KadDHT } from '@libp2p/kad-dht'
|
|
23
23
|
import type { Ping } from '@libp2p/ping'
|
|
24
24
|
import type { Libp2pOptions } from 'libp2p'
|
|
@@ -35,19 +35,15 @@ export interface DefaultLibp2pServices extends Record<string, unknown> {
|
|
|
35
35
|
http: HTTP
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export
|
|
39
|
-
let agentVersion: string | undefined
|
|
40
|
-
|
|
41
|
-
if (options.name != null && options.version != null) {
|
|
42
|
-
agentVersion = `${options.name}/${options.version} ${userAgent()}`
|
|
43
|
-
}
|
|
38
|
+
export type DefaultLibp2pOptions<M extends ServiceMap> = Libp2pOptions<DefaultLibp2pServices & M> & Required<Pick<Libp2pOptions<DefaultLibp2pServices & M>, 'nodeInfo' | 'addresses' | 'transports' | 'connectionEncrypters' | 'streamMuxers' | 'peerDiscovery' | 'services'>>
|
|
44
39
|
|
|
40
|
+
export function libp2pDefaults <M extends ServiceMap = ServiceMap> (options: CreateLibp2pOptions<M> = {}): DefaultLibp2pOptions<M> {
|
|
45
41
|
return {
|
|
46
|
-
privateKey: options.privateKey,
|
|
47
|
-
dns: options.dns,
|
|
48
42
|
nodeInfo: {
|
|
49
|
-
|
|
43
|
+
...options.nodeInfo
|
|
50
44
|
},
|
|
45
|
+
privateKey: options.privateKey,
|
|
46
|
+
dns: options.dns,
|
|
51
47
|
addresses: {
|
|
52
48
|
listen: [
|
|
53
49
|
'/p2p-circuit',
|
|
@@ -82,7 +78,8 @@ export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOpti
|
|
|
82
78
|
identifyPush: identifyPush(),
|
|
83
79
|
keychain: keychain(options.keychain),
|
|
84
80
|
ping: ping(),
|
|
85
|
-
http: http()
|
|
86
|
-
|
|
81
|
+
http: http(),
|
|
82
|
+
...options.services
|
|
83
|
+
} as any
|
|
87
84
|
}
|
|
88
85
|
}
|