@helia/libp2p 1.0.8-e1cc85b9 → 2.0.0-c9f35dab
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 +32 -32
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +33 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +46 -36
- package/dist/src/index.js.map +1 -1
- package/dist/src/utils/libp2p-defaults.browser.d.ts +5 -3
- 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 +5 -3
- package/dist/src/utils/libp2p-defaults.d.ts.map +1 -1
- package/dist/src/utils/libp2p-defaults.js +5 -9
- 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 -47
- package/src/utils/libp2p-defaults.browser.ts +11 -15
- package/src/utils/libp2p-defaults.ts +11 -15
- package/src/utils/libp2p.ts +8 -14
|
@@ -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
|
-
import type { Identify } from '@libp2p/identify'
|
|
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'
|
|
@@ -30,23 +30,18 @@ export interface DefaultLibp2pServices extends Record<string, unknown> {
|
|
|
30
30
|
delegatedPeerRouting: unknown
|
|
31
31
|
dht: KadDHT
|
|
32
32
|
identify: Identify
|
|
33
|
+
identifyPush: IdentifyPush
|
|
33
34
|
ping: Ping
|
|
34
35
|
http: HTTP
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
export function libp2pDefaults (options:
|
|
38
|
-
let agentVersion: string | undefined
|
|
39
|
-
|
|
40
|
-
if (options.name != null && options.version != null) {
|
|
41
|
-
agentVersion = `${options.name}/${options.version} ${userAgent()}`
|
|
42
|
-
}
|
|
43
|
-
|
|
38
|
+
export function libp2pDefaults <M extends ServiceMap = ServiceMap> (options: CreateLibp2pOptions<M> = {}): Libp2pOptions<DefaultLibp2pServices & M> {
|
|
44
39
|
return {
|
|
45
|
-
privateKey: options.privateKey,
|
|
46
|
-
dns: options.dns,
|
|
47
40
|
nodeInfo: {
|
|
48
|
-
|
|
41
|
+
...options.nodeInfo
|
|
49
42
|
},
|
|
43
|
+
privateKey: options.privateKey,
|
|
44
|
+
dns: options.dns,
|
|
50
45
|
addresses: {
|
|
51
46
|
listen: [
|
|
52
47
|
'/p2p-circuit',
|
|
@@ -81,7 +76,8 @@ export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOpti
|
|
|
81
76
|
identifyPush: identifyPush(),
|
|
82
77
|
keychain: keychain(options.keychain),
|
|
83
78
|
ping: ping(),
|
|
84
|
-
http: http()
|
|
85
|
-
|
|
79
|
+
http: http(),
|
|
80
|
+
...options.services
|
|
81
|
+
} as any
|
|
86
82
|
}
|
|
87
83
|
}
|
|
@@ -19,13 +19,13 @@ 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.ts'
|
|
24
|
-
import type {
|
|
23
|
+
import type { CreateLibp2pOptions } from '../index.ts'
|
|
25
24
|
import type { AutoTLS } from '@ipshipyard/libp2p-auto-tls'
|
|
26
25
|
import type { CircuitRelayService } from '@libp2p/circuit-relay-v2'
|
|
27
26
|
import type { HTTP } from '@libp2p/http'
|
|
28
|
-
import type { Identify } from '@libp2p/identify'
|
|
27
|
+
import type { Identify, IdentifyPush } from '@libp2p/identify'
|
|
28
|
+
import type { ServiceMap } from '@libp2p/interface'
|
|
29
29
|
import type { KadDHT } from '@libp2p/kad-dht'
|
|
30
30
|
import type { Keychain } from '@libp2p/keychain'
|
|
31
31
|
import type { Ping } from '@libp2p/ping'
|
|
@@ -39,6 +39,7 @@ export interface DefaultLibp2pServices extends Record<string, unknown> {
|
|
|
39
39
|
delegatedPeerRouting: unknown
|
|
40
40
|
dht: KadDHT
|
|
41
41
|
identify: Identify
|
|
42
|
+
identifyPush: IdentifyPush
|
|
42
43
|
keychain: Keychain
|
|
43
44
|
ping: Ping
|
|
44
45
|
relay: CircuitRelayService
|
|
@@ -71,19 +72,13 @@ export interface DefaultLibp2pServices extends Record<string, unknown> {
|
|
|
71
72
|
* helia.libp2p.services.myService.serviceMethod()
|
|
72
73
|
* ```
|
|
73
74
|
*/
|
|
74
|
-
export function libp2pDefaults (options:
|
|
75
|
-
let agentVersion: string | undefined
|
|
76
|
-
|
|
77
|
-
if (options.name != null && options.version != null) {
|
|
78
|
-
agentVersion = `${options.name}/${options.version} ${userAgent()}`
|
|
79
|
-
}
|
|
80
|
-
|
|
75
|
+
export function libp2pDefaults <M extends ServiceMap = ServiceMap> (options: CreateLibp2pOptions<M> = {}): Libp2pOptions<DefaultLibp2pServices & M> {
|
|
81
76
|
return {
|
|
82
|
-
privateKey: options.privateKey,
|
|
83
|
-
dns: options.dns,
|
|
84
77
|
nodeInfo: {
|
|
85
|
-
|
|
78
|
+
...options.nodeInfo
|
|
86
79
|
},
|
|
80
|
+
privateKey: options.privateKey,
|
|
81
|
+
dns: options.dns,
|
|
87
82
|
addresses: {
|
|
88
83
|
listen: [
|
|
89
84
|
'/ip4/0.0.0.0/tcp/0',
|
|
@@ -127,7 +122,8 @@ export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOpti
|
|
|
127
122
|
ping: ping(),
|
|
128
123
|
relay: circuitRelayServer(),
|
|
129
124
|
upnp: uPnPNAT(),
|
|
130
|
-
http: http()
|
|
131
|
-
|
|
125
|
+
http: http(),
|
|
126
|
+
...options.services
|
|
127
|
+
} as any
|
|
132
128
|
}
|
|
133
129
|
}
|
package/src/utils/libp2p.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { loadOrCreateSelfKey } from '@libp2p/config'
|
|
2
|
-
import { createLibp2p as create } from 'libp2p'
|
|
3
1
|
import { libp2pDefaults } from './libp2p-defaults.ts'
|
|
4
2
|
import type { Helia } from '@helia/interface'
|
|
5
3
|
import type { Libp2p, PrivateKey } from '@libp2p/interface'
|
|
@@ -19,25 +17,21 @@ export interface Libp2pDefaultsOptions {
|
|
|
19
17
|
version?: string
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
export async function
|
|
20
|
+
export async function createLibp2pOptions <T extends Record<string, unknown>> (helia: Helia, options: CreateLibp2pOptions<T>): Promise<Libp2p<T>> {
|
|
23
21
|
const libp2pOptions = options ?? {}
|
|
24
22
|
|
|
25
|
-
// if no peer id was passed, try to load it from the keychain
|
|
26
|
-
if (libp2pOptions.privateKey == null && options.datastore != null) {
|
|
27
|
-
libp2pOptions.privateKey = await loadOrCreateSelfKey(options.datastore, options.keychain)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
23
|
const defaults: any = libp2pDefaults({
|
|
31
24
|
...libp2pOptions,
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
nodeInfo: {
|
|
26
|
+
...libp2pOptions.nodeInfo,
|
|
27
|
+
name: libp2pOptions.nodeInfo?.name ?? helia.info.name,
|
|
28
|
+
version: libp2pOptions.nodeInfo?.version ?? helia.info.version
|
|
29
|
+
}
|
|
34
30
|
})
|
|
35
31
|
defaults.datastore = defaults.datastore ?? options.datastore
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
return {
|
|
38
34
|
...defaults,
|
|
39
35
|
...libp2pOptions
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return node
|
|
36
|
+
}
|
|
43
37
|
}
|