@helia/libp2p 0.0.0-1361bfa5
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 +83 -0
- package/dist/index.min.js +177 -0
- package/dist/index.min.js.map +7 -0
- package/dist/src/index.d.ts +35 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +74 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/routing.d.ts +4 -0
- package/dist/src/routing.d.ts.map +1 -0
- package/dist/src/routing.js +46 -0
- package/dist/src/routing.js.map +1 -0
- package/dist/src/utils/bootstrappers.d.ts +4 -0
- package/dist/src/utils/bootstrappers.d.ts.map +1 -0
- package/dist/src/utils/bootstrappers.js +13 -0
- package/dist/src/utils/bootstrappers.js.map +1 -0
- package/dist/src/utils/libp2p-defaults.browser.d.ts +18 -0
- package/dist/src/utils/libp2p-defaults.browser.d.ts.map +1 -0
- package/dist/src/utils/libp2p-defaults.browser.js +66 -0
- package/dist/src/utils/libp2p-defaults.browser.js.map +1 -0
- package/dist/src/utils/libp2p-defaults.d.ts +50 -0
- package/dist/src/utils/libp2p-defaults.d.ts.map +1 -0
- package/dist/src/utils/libp2p-defaults.js +107 -0
- package/dist/src/utils/libp2p-defaults.js.map +1 -0
- package/dist/src/utils/libp2p.d.ts +17 -0
- package/dist/src/utils/libp2p.d.ts.map +1 -0
- package/dist/src/utils/libp2p.js +22 -0
- package/dist/src/utils/libp2p.js.map +1 -0
- package/package.json +92 -0
- package/src/index.ts +103 -0
- package/src/routing.ts +60 -0
- package/src/utils/bootstrappers.ts +12 -0
- package/src/utils/libp2p-defaults.browser.ts +85 -0
- package/src/utils/libp2p-defaults.ts +133 -0
- package/src/utils/libp2p.ts +43 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* Adds libp2p functionality to Helia
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createHelia } from 'helia'
|
|
10
|
+
* import { withLibp2p } from '@helia/libp2p'
|
|
11
|
+
*
|
|
12
|
+
* const node = await withLibp2p(createHelia()).start()
|
|
13
|
+
*
|
|
14
|
+
* console.info(node.libp2p.peerId) // 12D3Koo...
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
import type { DefaultLibp2pServices } from './utils/libp2p-defaults.ts';
|
|
18
|
+
import type { CreateLibp2pOptions } from './utils/libp2p.ts';
|
|
19
|
+
import type { Helia } from '@helia/interface';
|
|
20
|
+
import type { Libp2p, ServiceMap } from '@libp2p/interface';
|
|
21
|
+
export { libp2pDefaults } from './utils/libp2p-defaults.ts';
|
|
22
|
+
export type { DefaultLibp2pServices } from './utils/libp2p-defaults.ts';
|
|
23
|
+
export type { CreateLibp2pOptions };
|
|
24
|
+
export interface HeliaWithLibp2p<M extends ServiceMap = DefaultLibp2pServices> extends Helia {
|
|
25
|
+
/**
|
|
26
|
+
* Libp2p provides a peer identity and a networking layer
|
|
27
|
+
*/
|
|
28
|
+
libp2p: Libp2p<M>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Return a Helia node augmented with a libp2p instance
|
|
32
|
+
*/
|
|
33
|
+
export declare function withLibp2p<H extends Helia, M extends ServiceMap = ServiceMap, L extends Libp2p = Libp2p<M>>(helia: H, opts: L): HeliaWithLibp2p<M>;
|
|
34
|
+
export declare function withLibp2p<H extends Helia, M extends ServiceMap = ServiceMap>(helia: H, opts?: CreateLibp2pOptions<M>): HeliaWithLibp2p<M>;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAc,MAAM,kBAAkB,CAAA;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,YAAY,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,YAAY,EAAE,mBAAmB,EAAE,CAAA;AAEnC,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,GAAG,UAAU,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,EAAG,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAA;AACrJ,wBAAgB,UAAU,CAAE,CAAC,SAAS,KAAK,EAAE,CAAC,SAAS,UAAU,GAAG,UAAU,EAAG,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* Adds libp2p functionality to Helia
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createHelia } from 'helia'
|
|
10
|
+
* import { withLibp2p } from '@helia/libp2p'
|
|
11
|
+
*
|
|
12
|
+
* const node = await withLibp2p(createHelia()).start()
|
|
13
|
+
*
|
|
14
|
+
* console.info(node.libp2p.peerId) // 12D3Koo...
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
import { NotStartedError } from '@libp2p/interface';
|
|
18
|
+
import { isLibp2p } from 'libp2p';
|
|
19
|
+
import { libp2pRouting } from "./routing.js";
|
|
20
|
+
import { createLibp2p } from "./utils/libp2p.js";
|
|
21
|
+
export { libp2pDefaults } from "./utils/libp2p-defaults.js";
|
|
22
|
+
async function getLibp2p(helia, opts) {
|
|
23
|
+
if (isLibp2p(opts)) {
|
|
24
|
+
return opts;
|
|
25
|
+
}
|
|
26
|
+
return createLibp2p(helia, {
|
|
27
|
+
...opts,
|
|
28
|
+
dns: helia.dns,
|
|
29
|
+
logger: helia.logger,
|
|
30
|
+
datastore: helia.datastore
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export function withLibp2p(helia, opts) {
|
|
34
|
+
let libp2p;
|
|
35
|
+
// add a getter that informs the user they need to start Helia
|
|
36
|
+
Object.defineProperty(helia, 'libp2p', {
|
|
37
|
+
configurable: true,
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get() {
|
|
40
|
+
if (libp2p != null) {
|
|
41
|
+
return libp2p;
|
|
42
|
+
}
|
|
43
|
+
throw new NotStartedError();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const mixin = {
|
|
47
|
+
start: async (helia) => {
|
|
48
|
+
if (libp2p == null) {
|
|
49
|
+
libp2p = await getLibp2p(helia, opts);
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
if (!helia.hasRouter('libp2p-router')) {
|
|
53
|
+
helia.addRouter(libp2pRouting(libp2p));
|
|
54
|
+
}
|
|
55
|
+
if (isLibp2p(helia.libp2p)) {
|
|
56
|
+
// already configured libp2p
|
|
57
|
+
await helia.libp2p.start();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
if (err.name !== 'NotStartedError') {
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
stop: async () => {
|
|
67
|
+
await libp2p?.stop();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
helia.addMixin(mixin);
|
|
71
|
+
// @ts-expect-error libp2p property is missing, even though we just defined it
|
|
72
|
+
return helia;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAMhD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAW3D,KAAK,UAAU,SAAS,CAAuD,KAAQ,EAAE,IAA6B;IACpH,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACnB,OAAO,IAAW,CAAA;IACpB,CAAC;IAED,OAAO,YAAY,CAAC,KAAK,EAAE;QACzB,GAAG,IAAI;QACP,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,SAAS,EAAE,KAAK,CAAC,SAAS;KAC3B,CAAC,CAAA;AACJ,CAAC;AAOD,MAAM,UAAU,UAAU,CAAuD,KAAQ,EAAE,IAA6B;IACtH,IAAI,MAAW,CAAA;IAEf,8DAA8D;IAC9D,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE;QACrC,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,IAAI;QAChB,GAAG;YACD,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;gBACnB,OAAO,MAAM,CAAA;YACf,CAAC;YAED,MAAM,IAAI,eAAe,EAA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IdFromCID } from '@libp2p/peer-id';
|
|
2
|
+
import map from 'it-map';
|
|
3
|
+
function peerInfoToPeer(info) {
|
|
4
|
+
return {
|
|
5
|
+
...info,
|
|
6
|
+
id: info.id.toCID()
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
class Libp2pRouter {
|
|
10
|
+
name = 'libp2p-router';
|
|
11
|
+
libp2p;
|
|
12
|
+
constructor(libp2p) {
|
|
13
|
+
this.libp2p = libp2p;
|
|
14
|
+
}
|
|
15
|
+
async provide(cid, options) {
|
|
16
|
+
await this.libp2p.contentRouting.provide(cid, options);
|
|
17
|
+
}
|
|
18
|
+
async cancelReprovide(key, options) {
|
|
19
|
+
await this.libp2p.contentRouting.cancelReprovide(key, options);
|
|
20
|
+
}
|
|
21
|
+
async *findProviders(cid, options) {
|
|
22
|
+
yield* map(this.libp2p.contentRouting.findProviders(cid, options), prov => ({
|
|
23
|
+
routing: this.name,
|
|
24
|
+
...peerInfoToPeer(prov)
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
async put(key, value, options) {
|
|
28
|
+
await this.libp2p.contentRouting.put(key, value, options);
|
|
29
|
+
}
|
|
30
|
+
async get(key, options) {
|
|
31
|
+
return this.libp2p.contentRouting.get(key, options);
|
|
32
|
+
}
|
|
33
|
+
async findPeer(peerId, options) {
|
|
34
|
+
return peerInfoToPeer(await this.libp2p.peerRouting.findPeer(peerIdFromCID(peerId), options));
|
|
35
|
+
}
|
|
36
|
+
async *getClosestPeers(key, options) {
|
|
37
|
+
yield* map(this.libp2p.peerRouting.getClosestPeers(key, options), peerInfoToPeer);
|
|
38
|
+
}
|
|
39
|
+
toString() {
|
|
40
|
+
return 'Libp2pRouter()';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function libp2pRouting(libp2p) {
|
|
44
|
+
return new Libp2pRouter(libp2p);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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AAG,CAAE,GAAe,EAAE,OAAwB;QAClD,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACrD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAE,MAAW,EAAE,OAAwB;QACnD,OAAO,cAAc,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAA;IAC/F,CAAC;IAED,KAAK,CAAC,CAAE,eAAe,CAAE,GAAe,EAAE,OAAwB;QAChE,KAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,CAAA;IACpF,CAAC;IAED,QAAQ;QACN,OAAO,gBAAgB,CAAA;IACzB,CAAC;CACF;AAED,MAAM,UAAU,aAAa,CAAE,MAAc;IAC3C,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,CAAA;AACjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrappers.d.ts","sourceRoot":"","sources":["../../../src/utils/bootstrappers.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,eAAe;;CAU3B,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// this list comes from https://github.com/ipfs/kubo/blob/da28fbc65a2e0f1ce59f9923823326ae2bc4f713/config/bootstrap_peers.go#L17
|
|
2
|
+
export const bootstrapConfig = {
|
|
3
|
+
list: [
|
|
4
|
+
'/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
|
|
5
|
+
'/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb',
|
|
6
|
+
'/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt',
|
|
7
|
+
// va1 is not in the TXT records for _dnsaddr.bootstrap.libp2p.io yet
|
|
8
|
+
// so use the host name directly
|
|
9
|
+
'/dnsaddr/va1.bootstrap.libp2p.io/p2p/12D3KooWKnDdG3iXw9eTFijk3EWSunZcFi54Zka4wmtqtt6rPxc8',
|
|
10
|
+
'/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ'
|
|
11
|
+
]
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=bootstrappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrappers.js","sourceRoot":"","sources":["../../../src/utils/bootstrappers.ts"],"names":[],"mappings":"AAAA,gIAAgI;AAChI,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE;QACJ,iFAAiF;QACjF,iFAAiF;QACjF,iFAAiF;QACjF,qEAAqE;QACrE,gCAAgC;QAChC,2FAA2F;QAC3F,iFAAiF;KAClF;CACF,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Libp2pDefaultsOptions } from './libp2p.ts';
|
|
2
|
+
import type { HTTP } from '@libp2p/http';
|
|
3
|
+
import type { Identify } from '@libp2p/identify';
|
|
4
|
+
import type { KadDHT } from '@libp2p/kad-dht';
|
|
5
|
+
import type { Ping } from '@libp2p/ping';
|
|
6
|
+
import type { Libp2pOptions } from 'libp2p';
|
|
7
|
+
export interface DefaultLibp2pServices extends Record<string, unknown> {
|
|
8
|
+
autoNAT: unknown;
|
|
9
|
+
dcutr: unknown;
|
|
10
|
+
delegatedContentRouting: unknown;
|
|
11
|
+
delegatedPeerRouting: unknown;
|
|
12
|
+
dht: KadDHT;
|
|
13
|
+
identify: Identify;
|
|
14
|
+
ping: Ping;
|
|
15
|
+
http: HTTP;
|
|
16
|
+
}
|
|
17
|
+
export declare function libp2pDefaults(options?: Libp2pDefaultsOptions): Libp2pOptions<DefaultLibp2pServices> & Required<Pick<Libp2pOptions<DefaultLibp2pServices>, 'services'>>;
|
|
18
|
+
//# sourceMappingURL=libp2p-defaults.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libp2p-defaults.browser.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.browser.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAChD,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,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,IAAI,CAAA;CACX;AAED,wBAAgB,cAAc,CAAE,OAAO,GAAE,qBAA0B,GAAG,aAAa,CAAC,qBAAqB,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,qBAAqB,CAAC,EAAE,UAAU,CAAC,CAAC,CAiD5K"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { noise } from '@chainsafe/libp2p-noise';
|
|
2
|
+
import { yamux } from '@chainsafe/libp2p-yamux';
|
|
3
|
+
import { delegatedHTTPRoutingDefaults } from '@helia/delegated-routing-client';
|
|
4
|
+
import { delegatedRoutingV1HttpApiClientContentRouting, delegatedRoutingV1HttpApiClientPeerRouting } from '@helia/delegated-routing-v1-http-api-client';
|
|
5
|
+
import { autoNAT } from '@libp2p/autonat';
|
|
6
|
+
import { bootstrap } from '@libp2p/bootstrap';
|
|
7
|
+
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2';
|
|
8
|
+
import { dcutr } from '@libp2p/dcutr';
|
|
9
|
+
import { http } from '@libp2p/http';
|
|
10
|
+
import { identify, identifyPush } from '@libp2p/identify';
|
|
11
|
+
import { kadDHT } from '@libp2p/kad-dht';
|
|
12
|
+
import { mplex } from '@libp2p/mplex';
|
|
13
|
+
import { ping } from '@libp2p/ping';
|
|
14
|
+
import { webRTC, webRTCDirect } from '@libp2p/webrtc';
|
|
15
|
+
import { webSockets } from '@libp2p/websockets';
|
|
16
|
+
import { userAgent } from 'libp2p/user-agent';
|
|
17
|
+
import { bootstrapConfig } from "./bootstrappers.js";
|
|
18
|
+
export function libp2pDefaults(options = {}) {
|
|
19
|
+
let agentVersion;
|
|
20
|
+
if (options.name != null && options.version != null) {
|
|
21
|
+
agentVersion = `${options.name}/${options.version} ${userAgent()}`;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
privateKey: options.privateKey,
|
|
25
|
+
dns: options.dns,
|
|
26
|
+
nodeInfo: {
|
|
27
|
+
userAgent: agentVersion
|
|
28
|
+
},
|
|
29
|
+
addresses: {
|
|
30
|
+
listen: [
|
|
31
|
+
'/p2p-circuit',
|
|
32
|
+
'/webrtc'
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
transports: [
|
|
36
|
+
circuitRelayTransport(),
|
|
37
|
+
webRTC(),
|
|
38
|
+
webRTCDirect(),
|
|
39
|
+
webSockets()
|
|
40
|
+
],
|
|
41
|
+
connectionEncrypters: [
|
|
42
|
+
noise()
|
|
43
|
+
],
|
|
44
|
+
streamMuxers: [
|
|
45
|
+
yamux(),
|
|
46
|
+
mplex()
|
|
47
|
+
],
|
|
48
|
+
peerDiscovery: [
|
|
49
|
+
bootstrap(bootstrapConfig)
|
|
50
|
+
],
|
|
51
|
+
services: {
|
|
52
|
+
autoNAT: autoNAT(),
|
|
53
|
+
dcutr: dcutr(),
|
|
54
|
+
delegatedContentRouting: delegatedRoutingV1HttpApiClientContentRouting(delegatedHTTPRoutingDefaults()),
|
|
55
|
+
delegatedPeerRouting: delegatedRoutingV1HttpApiClientPeerRouting(delegatedHTTPRoutingDefaults()),
|
|
56
|
+
dht: kadDHT({
|
|
57
|
+
clientMode: true
|
|
58
|
+
}),
|
|
59
|
+
identify: identify(),
|
|
60
|
+
identifyPush: identifyPush(),
|
|
61
|
+
ping: ping(),
|
|
62
|
+
http: http()
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=libp2p-defaults.browser.js.map
|
|
@@ -0,0 +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,yBAAyB,CAAA;AAC/C,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAA;AAC9E,OAAO,EAAE,6CAA6C,EAAE,0CAA0C,EAAE,MAAM,6CAA6C,CAAA;AACvJ,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,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E,CAAC;YACtG,oBAAoB,EAAE,0CAA0C,CAAC,4BAA4B,EAAE,CAAC;YAChG,GAAG,EAAE,MAAM,CAAC;gBACV,UAAU,EAAE,IAAI;aACjB,CAAC;YACF,QAAQ,EAAE,QAAQ,EAAE;YACpB,YAAY,EAAE,YAAY,EAAE;YAC5B,IAAI,EAAE,IAAI,EAAE;YACZ,IAAI,EAAE,IAAI,EAAE;SACb;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Libp2pDefaultsOptions } from './libp2p.ts';
|
|
2
|
+
import type { AutoTLS } from '@ipshipyard/libp2p-auto-tls';
|
|
3
|
+
import type { CircuitRelayService } from '@libp2p/circuit-relay-v2';
|
|
4
|
+
import type { HTTP } from '@libp2p/http';
|
|
5
|
+
import type { Identify } from '@libp2p/identify';
|
|
6
|
+
import type { KadDHT } from '@libp2p/kad-dht';
|
|
7
|
+
import type { Keychain } from '@libp2p/keychain';
|
|
8
|
+
import type { Ping } from '@libp2p/ping';
|
|
9
|
+
import type { Libp2pOptions } from 'libp2p';
|
|
10
|
+
export interface DefaultLibp2pServices extends Record<string, unknown> {
|
|
11
|
+
autoNAT: unknown;
|
|
12
|
+
autoTLS: AutoTLS;
|
|
13
|
+
dcutr: unknown;
|
|
14
|
+
delegatedContentRouting: unknown;
|
|
15
|
+
delegatedPeerRouting: unknown;
|
|
16
|
+
dht: KadDHT;
|
|
17
|
+
identify: Identify;
|
|
18
|
+
keychain: Keychain;
|
|
19
|
+
ping: Ping;
|
|
20
|
+
relay: CircuitRelayService;
|
|
21
|
+
upnp: unknown;
|
|
22
|
+
http: HTTP;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns the default libp2p config used by Helia which can then be modified or
|
|
26
|
+
* extended to suit individual applications.
|
|
27
|
+
*
|
|
28
|
+
* @example Adding an additional libp2p service
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { myService } from '@example/my-service'
|
|
32
|
+
* import { createHelia, libp2pDefaults } from 'helia'
|
|
33
|
+
*
|
|
34
|
+
* // get a copy of the default libp2p config
|
|
35
|
+
* const libp2p = libp2pDefaults()
|
|
36
|
+
*
|
|
37
|
+
* // add the custom service to the service map
|
|
38
|
+
* libp2p.services.myService = myService()
|
|
39
|
+
*
|
|
40
|
+
* // create a Helia node with the custom libp2p config
|
|
41
|
+
* const helia = await createHelia({
|
|
42
|
+
* libp2p
|
|
43
|
+
* })
|
|
44
|
+
*
|
|
45
|
+
* //... use service
|
|
46
|
+
* helia.libp2p.services.myService.serviceMethod()
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function libp2pDefaults(options?: Libp2pDefaultsOptions): Libp2pOptions<DefaultLibp2pServices> & Required<Pick<Libp2pOptions<DefaultLibp2pServices>, 'services'>>;
|
|
50
|
+
//# sourceMappingURL=libp2p-defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libp2p-defaults.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACxD,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,MAAM,kBAAkB,CAAA;AAChD,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,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;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,cAAc,CAAE,OAAO,GAAE,qBAA0B,GAAG,aAAa,CAAC,qBAAqB,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,qBAAqB,CAAC,EAAE,UAAU,CAAC,CAAC,CA2D5K"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { noise } from '@chainsafe/libp2p-noise';
|
|
2
|
+
import { yamux } from '@chainsafe/libp2p-yamux';
|
|
3
|
+
import { delegatedHTTPRoutingDefaults } from '@helia/delegated-routing-client';
|
|
4
|
+
import { delegatedRoutingV1HttpApiClientContentRouting, delegatedRoutingV1HttpApiClientPeerRouting } from '@helia/delegated-routing-v1-http-api-client';
|
|
5
|
+
import { autoTLS } from '@ipshipyard/libp2p-auto-tls';
|
|
6
|
+
import { autoNAT } from '@libp2p/autonat';
|
|
7
|
+
import { bootstrap } from '@libp2p/bootstrap';
|
|
8
|
+
import { circuitRelayTransport, circuitRelayServer } from '@libp2p/circuit-relay-v2';
|
|
9
|
+
import { dcutr } from '@libp2p/dcutr';
|
|
10
|
+
import { http } from '@libp2p/http';
|
|
11
|
+
import { identify, identifyPush } from '@libp2p/identify';
|
|
12
|
+
import { kadDHT } from '@libp2p/kad-dht';
|
|
13
|
+
import { keychain } from '@libp2p/keychain';
|
|
14
|
+
import { mdns } from '@libp2p/mdns';
|
|
15
|
+
import { mplex } from '@libp2p/mplex';
|
|
16
|
+
import { ping } from '@libp2p/ping';
|
|
17
|
+
import { tcp } from '@libp2p/tcp';
|
|
18
|
+
import { tls } from '@libp2p/tls';
|
|
19
|
+
import { uPnPNAT } from '@libp2p/upnp-nat';
|
|
20
|
+
import { webRTC, webRTCDirect } from '@libp2p/webrtc';
|
|
21
|
+
import { webSockets } from '@libp2p/websockets';
|
|
22
|
+
import { userAgent } from 'libp2p/user-agent';
|
|
23
|
+
import { bootstrapConfig } from "./bootstrappers.js";
|
|
24
|
+
/**
|
|
25
|
+
* Returns the default libp2p config used by Helia which can then be modified or
|
|
26
|
+
* extended to suit individual applications.
|
|
27
|
+
*
|
|
28
|
+
* @example Adding an additional libp2p service
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { myService } from '@example/my-service'
|
|
32
|
+
* import { createHelia, libp2pDefaults } from 'helia'
|
|
33
|
+
*
|
|
34
|
+
* // get a copy of the default libp2p config
|
|
35
|
+
* const libp2p = libp2pDefaults()
|
|
36
|
+
*
|
|
37
|
+
* // add the custom service to the service map
|
|
38
|
+
* libp2p.services.myService = myService()
|
|
39
|
+
*
|
|
40
|
+
* // create a Helia node with the custom libp2p config
|
|
41
|
+
* const helia = await createHelia({
|
|
42
|
+
* libp2p
|
|
43
|
+
* })
|
|
44
|
+
*
|
|
45
|
+
* //... use service
|
|
46
|
+
* helia.libp2p.services.myService.serviceMethod()
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
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
|
+
return {
|
|
55
|
+
privateKey: options.privateKey,
|
|
56
|
+
dns: options.dns,
|
|
57
|
+
nodeInfo: {
|
|
58
|
+
userAgent: agentVersion
|
|
59
|
+
},
|
|
60
|
+
addresses: {
|
|
61
|
+
listen: [
|
|
62
|
+
'/ip4/0.0.0.0/tcp/0',
|
|
63
|
+
'/ip4/0.0.0.0/tcp/0/ws',
|
|
64
|
+
'/ip4/0.0.0.0/udp/0/webrtc-direct',
|
|
65
|
+
'/ip6/::/tcp/0',
|
|
66
|
+
'/ip6/::/tcp/0/ws',
|
|
67
|
+
'/ip6/::/udp/0/webrtc-direct',
|
|
68
|
+
'/p2p-circuit'
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
transports: [
|
|
72
|
+
circuitRelayTransport(),
|
|
73
|
+
tcp(),
|
|
74
|
+
webRTC(),
|
|
75
|
+
webRTCDirect(),
|
|
76
|
+
webSockets()
|
|
77
|
+
],
|
|
78
|
+
connectionEncrypters: [
|
|
79
|
+
noise(),
|
|
80
|
+
tls()
|
|
81
|
+
],
|
|
82
|
+
streamMuxers: [
|
|
83
|
+
yamux(),
|
|
84
|
+
mplex()
|
|
85
|
+
],
|
|
86
|
+
peerDiscovery: [
|
|
87
|
+
mdns(),
|
|
88
|
+
bootstrap(bootstrapConfig)
|
|
89
|
+
],
|
|
90
|
+
services: {
|
|
91
|
+
autoNAT: autoNAT(),
|
|
92
|
+
autoTLS: autoTLS(),
|
|
93
|
+
dcutr: dcutr(),
|
|
94
|
+
delegatedPeerRouting: delegatedRoutingV1HttpApiClientPeerRouting(delegatedHTTPRoutingDefaults()),
|
|
95
|
+
delegatedContentRouting: delegatedRoutingV1HttpApiClientContentRouting(delegatedHTTPRoutingDefaults()),
|
|
96
|
+
dht: kadDHT(),
|
|
97
|
+
identify: identify(),
|
|
98
|
+
identifyPush: identifyPush(),
|
|
99
|
+
keychain: keychain(options.keychain),
|
|
100
|
+
ping: ping(),
|
|
101
|
+
relay: circuitRelayServer(),
|
|
102
|
+
upnp: uPnPNAT(),
|
|
103
|
+
http: http()
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107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AAC;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;SACb;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Helia } from '@helia/interface';
|
|
2
|
+
import type { Libp2p, PrivateKey } from '@libp2p/interface';
|
|
3
|
+
import type { KeychainInit } from '@libp2p/keychain';
|
|
4
|
+
import type { DNS } from '@multiformats/dns';
|
|
5
|
+
import type { Libp2pOptions } from 'libp2p';
|
|
6
|
+
export interface CreateLibp2pOptions<T extends Record<string, unknown>> extends Libp2pOptions<T> {
|
|
7
|
+
keychain?: KeychainInit;
|
|
8
|
+
}
|
|
9
|
+
export interface Libp2pDefaultsOptions {
|
|
10
|
+
privateKey?: PrivateKey;
|
|
11
|
+
keychain?: KeychainInit;
|
|
12
|
+
dns?: DNS;
|
|
13
|
+
name?: string;
|
|
14
|
+
version?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function createLibp2p<T extends Record<string, unknown>>(helia: Helia, options: CreateLibp2pOptions<T>): Promise<Libp2p<T>>;
|
|
17
|
+
//# sourceMappingURL=libp2p.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libp2p.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p.ts"],"names":[],"mappings":"AAGA,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,YAAY,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,CAqBzI"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { loadOrCreateSelfKey } from '@libp2p/config';
|
|
2
|
+
import { createLibp2p as create } from 'libp2p';
|
|
3
|
+
import { libp2pDefaults } from "./libp2p-defaults.js";
|
|
4
|
+
export async function createLibp2p(helia, options) {
|
|
5
|
+
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
|
+
const defaults = libp2pDefaults({
|
|
11
|
+
...libp2pOptions,
|
|
12
|
+
name: libp2pOptions.nodeInfo?.name ?? helia.info.name,
|
|
13
|
+
version: libp2pOptions.nodeInfo?.version ?? helia.info.version
|
|
14
|
+
});
|
|
15
|
+
defaults.datastore = defaults.datastore ?? options.datastore;
|
|
16
|
+
const node = await create({
|
|
17
|
+
...defaults,
|
|
18
|
+
...libp2pOptions
|
|
19
|
+
});
|
|
20
|
+
return node;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=libp2p.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libp2p.js","sourceRoot":"","sources":["../../../src/utils/libp2p.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,YAAY,IAAI,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAmBrD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAsC,KAAY,EAAE,OAA+B;IACnH,MAAM,aAAa,GAAG,OAAO,IAAI,EAAE,CAAA;IAEnC,6DAA6D;IAC7D,IAAI,aAAa,CAAC,UAAU,IAAI,IAAI,IAAI,OAAO,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;QAClE,aAAa,CAAC,UAAU,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC3F,CAAC;IAED,MAAM,QAAQ,GAAQ,cAAc,CAAC;QACnC,GAAG,aAAa;QAChB,IAAI,EAAE,aAAa,CAAC,QAAQ,EAAE,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI;QACrD,OAAO,EAAE,aAAa,CAAC,QAAQ,EAAE,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO;KAC/D,CAAC,CAAA;IACF,QAAQ,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAA;IAE5D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAI;QAC3B,GAAG,QAAQ;QACX,GAAG,aAAa;KACjB,CAAC,CAAA;IAEF,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@helia/libp2p",
|
|
3
|
+
"version": "0.0.0-1361bfa5",
|
|
4
|
+
"description": "libp2p functionality for Helia",
|
|
5
|
+
"license": "Apache-2.0 OR MIT",
|
|
6
|
+
"homepage": "https://github.com/ipfs/helia/tree/main/packages/libp2p#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/ipfs/helia.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/ipfs/helia/issues"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"provenance": true
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"IPFS"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"types": "./dist/src/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"src",
|
|
25
|
+
"dist",
|
|
26
|
+
"!dist/test",
|
|
27
|
+
"!**/*.tsbuildinfo"
|
|
28
|
+
],
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/src/index.d.ts",
|
|
32
|
+
"import": "./dist/src/index.js",
|
|
33
|
+
"module-sync": "./dist/src/index.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"clean": "aegir clean",
|
|
38
|
+
"lint": "aegir lint",
|
|
39
|
+
"dep-check": "aegir dep-check",
|
|
40
|
+
"doc-check": "aegir doc-check",
|
|
41
|
+
"build": "aegir build",
|
|
42
|
+
"test": "aegir test",
|
|
43
|
+
"test:chrome": "aegir test -t browser --cov",
|
|
44
|
+
"test:chrome-webworker": "aegir test -t webworker",
|
|
45
|
+
"test:firefox": "aegir test -t browser -- --browser firefox",
|
|
46
|
+
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
|
|
47
|
+
"test:node": "aegir test -t node --cov",
|
|
48
|
+
"test:electron-main": "aegir test -t electron-main"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@chainsafe/libp2p-noise": "^17.0.0",
|
|
52
|
+
"@chainsafe/libp2p-yamux": "^8.0.1",
|
|
53
|
+
"@helia/delegated-routing-client": "0.0.0-1361bfa5",
|
|
54
|
+
"@helia/delegated-routing-v1-http-api-client": "^8.0.0",
|
|
55
|
+
"@helia/interface": "6.2.1-1361bfa5",
|
|
56
|
+
"@ipshipyard/libp2p-auto-tls": "^2.0.1",
|
|
57
|
+
"@libp2p/autonat": "^3.0.21",
|
|
58
|
+
"@libp2p/bootstrap": "^12.0.24",
|
|
59
|
+
"@libp2p/circuit-relay-v2": "^4.2.6",
|
|
60
|
+
"@libp2p/config": "^1.1.32",
|
|
61
|
+
"@libp2p/dcutr": "^3.0.21",
|
|
62
|
+
"@libp2p/http": "^2.0.2",
|
|
63
|
+
"@libp2p/identify": "^4.1.7",
|
|
64
|
+
"@libp2p/interface": "^3.2.3",
|
|
65
|
+
"@libp2p/kad-dht": "^16.3.2",
|
|
66
|
+
"@libp2p/keychain": "^6.1.2",
|
|
67
|
+
"@libp2p/mdns": "^12.0.24",
|
|
68
|
+
"@libp2p/mplex": "^12.0.24",
|
|
69
|
+
"@libp2p/peer-id": "^6.0.10",
|
|
70
|
+
"@libp2p/ping": "^3.1.6",
|
|
71
|
+
"@libp2p/tcp": "^11.0.21",
|
|
72
|
+
"@libp2p/tls": "^3.1.3",
|
|
73
|
+
"@libp2p/upnp-nat": "^4.0.21",
|
|
74
|
+
"@libp2p/webrtc": "^6.0.24",
|
|
75
|
+
"@libp2p/websockets": "^10.1.14",
|
|
76
|
+
"@multiformats/dns": "^1.0.13",
|
|
77
|
+
"it-map": "^3.1.6",
|
|
78
|
+
"libp2p": "^3.3.3",
|
|
79
|
+
"multiformats": "^14.0.0"
|
|
80
|
+
},
|
|
81
|
+
"devDependencies": {
|
|
82
|
+
"aegir": "^48.0.11",
|
|
83
|
+
"helia": "6.1.4-1361bfa5",
|
|
84
|
+
"it-drain": "^3.0.12",
|
|
85
|
+
"sinon-ts": "^2.0.0",
|
|
86
|
+
"uint8arrays": "^6.1.1"
|
|
87
|
+
},
|
|
88
|
+
"browser": {
|
|
89
|
+
"./dist/src/utils/libp2p-defaults.js": "./dist/src/utils/libp2p-defaults.browser.js"
|
|
90
|
+
},
|
|
91
|
+
"sideEffects": false
|
|
92
|
+
}
|