@helia/http 3.1.4-070b7528 → 3.1.4-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.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * Exports a `createHeliaHTTP` function that returns an object that implements a lightweight version of the {@link Helia} API that functions only over HTTP.
4
+ * Exports a `withHTTP` function configures a {@link Helia} node that with block brokers and gateways that only run over HTTP.
5
5
  *
6
6
  * By default, content and peer routing are requests are resolved using the [Delegated HTTP Routing API](https://specs.ipfs.tech/routing/http-routing-v1/) and blocks are fetched from [Trustless Gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/).
7
7
  *
@@ -10,57 +10,53 @@
10
10
  * @example
11
11
  *
12
12
  * ```typescript
13
- * import { createHeliaHTTP } from '@helia/http'
13
+ * import { withHTTP } from '@helia/http'
14
14
  * import { unixfs } from '@helia/unixfs'
15
+ * import { createHelia } from 'helia'
15
16
  * import { CID } from 'multiformats/cid'
16
17
  *
17
- * const helia = await createHeliaHTTP()
18
+ * const helia = await withHTTP(createHelia()).start()
18
19
  *
19
20
  * const fs = unixfs(helia)
20
21
  * fs.cat(CID.parse('bafyFoo'))
21
22
  * ```
22
- * @example with custom gateways and delegated routing endpoints
23
+ * @example without using this module
24
+ *
25
+ * It's possible to manually configure your node without using this module.
26
+ *
23
27
  * ```typescript
24
- * import { createHeliaHTTP } from '@helia/http'
25
- * import { trustlessGateway } from '@helia/block-brokers'
26
- * import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers'
28
+ * import { createHelia } from 'helia'
29
+ * import { trustlessGatewayBlockBroker } from '@helia/trustless-gateway-client'
30
+ * import { fallbackRouter } from '@helia/fallback-router'
31
+ * import { delegatedHTTPRouter } from '@helia/delegated-http-routing-client'
27
32
  * import { unixfs } from '@helia/unixfs'
28
33
  * import { CID } from 'multiformats/cid'
29
34
  *
30
- * const helia = await createHeliaHTTP({
35
+ * const helia = await createHelia({
31
36
  * blockBrokers: [
32
- * trustlessGateway()
37
+ * trustlessGatewayBlockBroker()
33
38
  * ],
34
39
  * routers: [
35
- * delegatedHTTPRouting({
40
+ * delegatedHTTPRouter({
36
41
  * url: 'https://delegated-ipfs.dev'
37
42
  * }),
38
- * httpGatewayRouting({
43
+ * fallbackRouter({
39
44
  * gateways: ['https://cloudflare-ipfs.com', 'https://ipfs.io']
40
45
  * })
41
46
  * ]
42
- * })
47
+ * }).start()
43
48
  *
44
49
  * const fs = unixfs(helia)
45
50
  * fs.cat(CID.parse('bafyFoo'))
46
51
  * ```
47
52
  */
48
- import type { DefaultLibp2pHTTPServices } from './utils/libp2p-defaults.ts';
49
- import type { Libp2pHTTPDefaultOptions } from './utils/libp2p.ts';
50
- import type { Helia } from '@helia/interface';
51
- import type { HeliaInit } from '@helia/utils';
52
- import type { Libp2p } from '@libp2p/interface';
53
- export * from '@helia/interface';
54
- export type HeliaHTTPInit = HeliaInit<Libp2p<DefaultLibp2pHTTPServices>>;
55
- export type { DefaultLibp2pHTTPServices, Libp2pHTTPDefaultOptions };
56
- /**
57
- * Create and return the default options used to create a Helia node
58
- */
59
- export declare function heliaDefaults<T extends Libp2p>(init?: Partial<HeliaInit<T>>): Promise<Omit<HeliaInit<T>, 'libp2p'> & {
60
- libp2p: T;
61
- }>;
53
+ import type { BlockBroker, Helia, Router } from '@helia/interface';
54
+ export interface HTTPOptions {
55
+ routers?: Router[];
56
+ blockBrokers?: BlockBroker[];
57
+ }
62
58
  /**
63
- * Create and return a Helia node
59
+ * Augment a Helia node with HTTP routers and block brokers
64
60
  */
65
- export declare function createHeliaHTTP(init?: Partial<HeliaHTTPInit>): Promise<Helia<Libp2p<DefaultLibp2pHTTPServices>>>;
61
+ export declare function withHTTP<H extends Helia>(helia: H, init?: HTTPOptions): H;
66
62
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"m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,WAAW,EAAE,CAAA;CAC7B;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAE,CAAC,SAAS,KAAK,EAAG,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,CAAC,CAiB3E"}
package/dist/src/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * Exports a `createHeliaHTTP` function that returns an object that implements a lightweight version of the {@link Helia} API that functions only over HTTP.
4
+ * Exports a `withHTTP` function configures a {@link Helia} node that with block brokers and gateways that only run over HTTP.
5
5
  *
6
6
  * By default, content and peer routing are requests are resolved using the [Delegated HTTP Routing API](https://specs.ipfs.tech/routing/http-routing-v1/) and blocks are fetched from [Trustless Gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/).
7
7
  *
@@ -10,98 +10,66 @@
10
10
  * @example
11
11
  *
12
12
  * ```typescript
13
- * import { createHeliaHTTP } from '@helia/http'
13
+ * import { withHTTP } from '@helia/http'
14
14
  * import { unixfs } from '@helia/unixfs'
15
+ * import { createHelia } from 'helia'
15
16
  * import { CID } from 'multiformats/cid'
16
17
  *
17
- * const helia = await createHeliaHTTP()
18
+ * const helia = await withHTTP(createHelia()).start()
18
19
  *
19
20
  * const fs = unixfs(helia)
20
21
  * fs.cat(CID.parse('bafyFoo'))
21
22
  * ```
22
- * @example with custom gateways and delegated routing endpoints
23
+ * @example without using this module
24
+ *
25
+ * It's possible to manually configure your node without using this module.
26
+ *
23
27
  * ```typescript
24
- * import { createHeliaHTTP } from '@helia/http'
25
- * import { trustlessGateway } from '@helia/block-brokers'
26
- * import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers'
28
+ * import { createHelia } from 'helia'
29
+ * import { trustlessGatewayBlockBroker } from '@helia/trustless-gateway-client'
30
+ * import { fallbackRouter } from '@helia/fallback-router'
31
+ * import { delegatedHTTPRouter } from '@helia/delegated-http-routing-client'
27
32
  * import { unixfs } from '@helia/unixfs'
28
33
  * import { CID } from 'multiformats/cid'
29
34
  *
30
- * const helia = await createHeliaHTTP({
35
+ * const helia = await createHelia({
31
36
  * blockBrokers: [
32
- * trustlessGateway()
37
+ * trustlessGatewayBlockBroker()
33
38
  * ],
34
39
  * routers: [
35
- * delegatedHTTPRouting({
40
+ * delegatedHTTPRouter({
36
41
  * url: 'https://delegated-ipfs.dev'
37
42
  * }),
38
- * httpGatewayRouting({
43
+ * fallbackRouter({
39
44
  * gateways: ['https://cloudflare-ipfs.com', 'https://ipfs.io']
40
45
  * })
41
46
  * ]
42
- * })
47
+ * }).start()
43
48
  *
44
49
  * const fs = unixfs(helia)
45
50
  * fs.cat(CID.parse('bafyFoo'))
46
51
  * ```
47
52
  */
48
- import { trustlessGateway } from '@helia/block-brokers';
49
- import { httpGatewayRouting, libp2pRouting } from '@helia/routers';
50
- import { Helia as HeliaClass } from '@helia/utils';
51
- import { MemoryBlockstore } from 'blockstore-core';
52
- import { MemoryDatastore } from 'datastore-core';
53
- import { isLibp2p } from 'libp2p';
54
- import { createLibp2p } from "./utils/libp2p.js";
55
- // re-export interface types so people don't have to depend on @helia/interface
56
- // if they don't want to
57
- export * from '@helia/interface';
58
- /**
59
- * Create and return the default options used to create a Helia node
60
- */
61
- export async function heliaDefaults(init = {}) {
62
- const datastore = init.datastore ?? new MemoryDatastore();
63
- const blockstore = init.blockstore ?? new MemoryBlockstore();
64
- let libp2p;
65
- if (isLibp2p(init.libp2p)) {
66
- libp2p = init.libp2p;
67
- }
68
- else {
69
- libp2p = await createLibp2p({
70
- ...init,
71
- libp2p: {
72
- dns: init.dns,
73
- ...init.libp2p,
74
- // ignore the libp2p start parameter as it should be on the main init
75
- // object instead
76
- start: undefined
77
- },
78
- datastore
79
- });
80
- }
81
- return {
82
- ...init,
83
- libp2p,
84
- datastore,
85
- blockstore,
86
- blockBrokers: init.blockBrokers ?? [
87
- trustlessGateway()
88
- ],
89
- routers: init.routers ?? [
90
- libp2pRouting(libp2p),
91
- httpGatewayRouting()
92
- ],
93
- metrics: libp2p.metrics
94
- };
95
- }
53
+ import { delegatedHTTPRouter } from '@helia/delegated-routing-client';
54
+ import { fallbackRouter } from '@helia/fallback-router';
55
+ import { trustlessGatewayBlockBroker } from '@helia/trustless-gateway-client';
96
56
  /**
97
- * Create and return a Helia node
57
+ * Augment a Helia node with HTTP routers and block brokers
98
58
  */
99
- export async function createHeliaHTTP(init = {}) {
100
- const options = await heliaDefaults(init);
101
- const helia = new HeliaClass(options);
102
- if (options.start !== false) {
103
- await helia.start();
104
- }
59
+ export function withHTTP(helia, init) {
60
+ init?.routers ?? [
61
+ fallbackRouter(),
62
+ delegatedHTTPRouter({
63
+ url: 'https://delegated-ipfs.dev'
64
+ })
65
+ ].forEach(router => {
66
+ helia.addRouter(router);
67
+ });
68
+ init?.blockBrokers ?? [
69
+ trustlessGatewayBlockBroker()
70
+ ].forEach(broker => {
71
+ helia.addBlockBroker(broker);
72
+ });
105
73
  return helia;
106
74
  }
107
75
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAClE,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAOhD,+EAA+E;AAC/E,wBAAwB;AACxB,cAAc,kBAAkB,CAAA;AAMhC;;GAEG;AACH,MAAM,CAAC,K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src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAA;AAQ7E;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAoB,KAAQ,EAAE,IAAkB;IACtE,IAAI,EAAE,OAAO,IAAI;QACf,cAAc,EAAE;QAChB,mBAAmB,CAAC;YAClB,GAAG,EAAE,4BAA4B;SAClC,CAAC;KACH,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjB,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IACzB,CAAC,CAAC,CAAA;IAEF,IAAI,EAAE,YAAY,IAAI;QACpB,2BAA2B,EAAE;KAC9B,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjB,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;IAC9B,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,CAAA;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/http",
3
- "version": "3.1.4-070b7528",
3
+ "version": "3.1.4-1361bfa5",
4
4
  "description": "A lightweight implementation of IPFS over HTTP in JavaScript",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/ipfs/helia/tree/main/packages/http#readme",
@@ -48,23 +48,15 @@
48
48
  "test:electron-main": "aegir test -t electron-main"
49
49
  },
50
50
  "dependencies": {
51
- "@helia/block-brokers": "5.2.4-070b7528",
52
- "@helia/delegated-routing-v1-http-api-client": "^6.0.1",
53
- "@helia/interface": "6.2.1-070b7528",
54
- "@helia/routers": "5.1.1-070b7528",
55
- "@helia/utils": "2.5.2-070b7528",
56
- "@libp2p/config": "^1.1.27",
57
- "@libp2p/interface": "^3.2.0",
58
- "@libp2p/keychain": "^6.0.12",
59
- "@multiformats/dns": "^1.0.13",
60
- "blockstore-core": "^6.1.3",
61
- "datastore-core": "^11.0.3",
62
- "interface-datastore": "^9.0.3",
63
- "libp2p": "^3.2.0"
51
+ "@helia/delegated-routing-client": "0.0.0-1361bfa5",
52
+ "@helia/fallback-router": "0.0.0-1361bfa5",
53
+ "@helia/interface": "6.2.1-1361bfa5",
54
+ "@helia/trustless-gateway-client": "0.0.0-1361bfa5"
64
55
  },
65
56
  "devDependencies": {
66
- "aegir": "^48.0.4",
67
- "multiformats": "^13.4.2",
57
+ "@libp2p/interface": "^3.2.3",
58
+ "aegir": "^48.0.11",
59
+ "helia": "6.1.4-1361bfa5",
68
60
  "sinon": "^22.0.0",
69
61
  "sinon-ts": "^2.0.0"
70
62
  },
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * Exports a `createHeliaHTTP` function that returns an object that implements a lightweight version of the {@link Helia} API that functions only over HTTP.
4
+ * Exports a `withHTTP` function configures a {@link Helia} node that with block brokers and gateways that only run over HTTP.
5
5
  *
6
6
  * By default, content and peer routing are requests are resolved using the [Delegated HTTP Routing API](https://specs.ipfs.tech/routing/http-routing-v1/) and blocks are fetched from [Trustless Gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/).
7
7
  *
@@ -10,115 +10,75 @@
10
10
  * @example
11
11
  *
12
12
  * ```typescript
13
- * import { createHeliaHTTP } from '@helia/http'
13
+ * import { withHTTP } from '@helia/http'
14
14
  * import { unixfs } from '@helia/unixfs'
15
+ * import { createHelia } from 'helia'
15
16
  * import { CID } from 'multiformats/cid'
16
17
  *
17
- * const helia = await createHeliaHTTP()
18
+ * const helia = await withHTTP(createHelia()).start()
18
19
  *
19
20
  * const fs = unixfs(helia)
20
21
  * fs.cat(CID.parse('bafyFoo'))
21
22
  * ```
22
- * @example with custom gateways and delegated routing endpoints
23
+ * @example without using this module
24
+ *
25
+ * It's possible to manually configure your node without using this module.
26
+ *
23
27
  * ```typescript
24
- * import { createHeliaHTTP } from '@helia/http'
25
- * import { trustlessGateway } from '@helia/block-brokers'
26
- * import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers'
28
+ * import { createHelia } from 'helia'
29
+ * import { trustlessGatewayBlockBroker } from '@helia/trustless-gateway-client'
30
+ * import { fallbackRouter } from '@helia/fallback-router'
31
+ * import { delegatedHTTPRouter } from '@helia/delegated-http-routing-client'
27
32
  * import { unixfs } from '@helia/unixfs'
28
33
  * import { CID } from 'multiformats/cid'
29
34
  *
30
- * const helia = await createHeliaHTTP({
35
+ * const helia = await createHelia({
31
36
  * blockBrokers: [
32
- * trustlessGateway()
37
+ * trustlessGatewayBlockBroker()
33
38
  * ],
34
39
  * routers: [
35
- * delegatedHTTPRouting({
40
+ * delegatedHTTPRouter({
36
41
  * url: 'https://delegated-ipfs.dev'
37
42
  * }),
38
- * httpGatewayRouting({
43
+ * fallbackRouter({
39
44
  * gateways: ['https://cloudflare-ipfs.com', 'https://ipfs.io']
40
45
  * })
41
46
  * ]
42
- * })
47
+ * }).start()
43
48
  *
44
49
  * const fs = unixfs(helia)
45
50
  * fs.cat(CID.parse('bafyFoo'))
46
51
  * ```
47
52
  */
48
53
 
49
- import { trustlessGateway } from '@helia/block-brokers'
50
- import { httpGatewayRouting, libp2pRouting } from '@helia/routers'
51
- import { Helia as HeliaClass } from '@helia/utils'
52
- import { MemoryBlockstore } from 'blockstore-core'
53
- import { MemoryDatastore } from 'datastore-core'
54
- import { isLibp2p } from 'libp2p'
55
- import { createLibp2p } from './utils/libp2p.ts'
56
- import type { DefaultLibp2pHTTPServices } from './utils/libp2p-defaults.ts'
57
- import type { Libp2pHTTPDefaultOptions } from './utils/libp2p.ts'
58
- import type { Helia } from '@helia/interface'
59
- import type { HeliaInit } from '@helia/utils'
60
- import type { Libp2p } from '@libp2p/interface'
61
-
62
- // re-export interface types so people don't have to depend on @helia/interface
63
- // if they don't want to
64
- export * from '@helia/interface'
65
-
66
- export type HeliaHTTPInit = HeliaInit<Libp2p<DefaultLibp2pHTTPServices>>
54
+ import { delegatedHTTPRouter } from '@helia/delegated-routing-client'
55
+ import { fallbackRouter } from '@helia/fallback-router'
56
+ import { trustlessGatewayBlockBroker } from '@helia/trustless-gateway-client'
57
+ import type { BlockBroker, Helia, Router } from '@helia/interface'
67
58
 
68
- export type { DefaultLibp2pHTTPServices, Libp2pHTTPDefaultOptions }
69
-
70
- /**
71
- * Create and return the default options used to create a Helia node
72
- */
73
- export async function heliaDefaults <T extends Libp2p> (init: Partial<HeliaInit<T>> = {}): Promise<Omit<HeliaInit<T>, 'libp2p'> & { libp2p: T }> {
74
- const datastore = init.datastore ?? new MemoryDatastore()
75
- const blockstore = init.blockstore ?? new MemoryBlockstore()
76
-
77
- let libp2p: any
78
-
79
- if (isLibp2p(init.libp2p)) {
80
- libp2p = init.libp2p
81
- } else {
82
- libp2p = await createLibp2p<DefaultLibp2pHTTPServices>({
83
- ...init,
84
- libp2p: {
85
- dns: init.dns,
86
- ...init.libp2p,
87
-
88
- // ignore the libp2p start parameter as it should be on the main init
89
- // object instead
90
- start: undefined
91
- },
92
- datastore
93
- })
94
- }
95
-
96
- return {
97
- ...init,
98
- libp2p,
99
- datastore,
100
- blockstore,
101
- blockBrokers: init.blockBrokers ?? [
102
- trustlessGateway()
103
- ],
104
- routers: init.routers ?? [
105
- libp2pRouting(libp2p),
106
- httpGatewayRouting()
107
- ],
108
- metrics: libp2p.metrics
109
- }
59
+ export interface HTTPOptions {
60
+ routers?: Router[]
61
+ blockBrokers?: BlockBroker[]
110
62
  }
111
63
 
112
64
  /**
113
- * Create and return a Helia node
65
+ * Augment a Helia node with HTTP routers and block brokers
114
66
  */
115
- export async function createHeliaHTTP (init: Partial<HeliaHTTPInit> = {}): Promise<Helia<Libp2p<DefaultLibp2pHTTPServices>>> {
116
- const options = await heliaDefaults(init)
117
- const helia = new HeliaClass(options)
67
+ export function withHTTP <H extends Helia> (helia: H, init?: HTTPOptions): H {
68
+ init?.routers ?? [
69
+ fallbackRouter(),
70
+ delegatedHTTPRouter({
71
+ url: 'https://delegated-ipfs.dev'
72
+ })
73
+ ].forEach(router => {
74
+ helia.addRouter(router)
75
+ })
118
76
 
119
- if (options.start !== false) {
120
- await helia.start()
121
- }
77
+ init?.blockBrokers ?? [
78
+ trustlessGatewayBlockBroker()
79
+ ].forEach(broker => {
80
+ helia.addBlockBroker(broker)
81
+ })
122
82
 
123
83
  return helia
124
84
  }
@@ -1,9 +0,0 @@
1
- import type { Libp2pHTTPDefaultOptions } from './libp2p.ts';
2
- import type { Keychain } from '@libp2p/keychain';
3
- import type { Libp2pOptions } from 'libp2p';
4
- export interface DefaultLibp2pHTTPServices extends Record<string, unknown> {
5
- delegatedRouting: unknown;
6
- keychain: Keychain;
7
- }
8
- export declare function libp2pDefaults(options?: Libp2pHTTPDefaultOptions): Libp2pOptions<DefaultLibp2pHTTPServices> & Required<Pick<Libp2pOptions<DefaultLibp2pHTTPServices>, 'services'>>;
9
- //# sourceMappingURL=libp2p-defaults.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"libp2p-defaults.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAE3C,MAAM,WAAW,yBAA0B,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACxE,gBAAgB,EAAE,OAAO,CAAA;IACzB,QAAQ,EAAE,QAAQ,CAAA;CACnB;AAED,wBAAgB,cAAc,CAAE,OAAO,GAAE,wBAA6B,GAAG,aAAa,CAAC,yBAAyB,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,EAAE,UAAU,CAAC,CAAC,CAyBvL"}
@@ -1,29 +0,0 @@
1
- import { delegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client';
2
- import { keychain } from '@libp2p/keychain';
3
- import { userAgent } from 'libp2p/user-agent';
4
- export function libp2pDefaults(options = {}) {
5
- const agentVersion = `@helia/http ${userAgent()}`;
6
- return {
7
- privateKey: options.privateKey,
8
- dns: options.dns,
9
- nodeInfo: {
10
- userAgent: agentVersion
11
- },
12
- addresses: {
13
- listen: []
14
- },
15
- transports: [],
16
- connectionEncrypters: [],
17
- streamMuxers: [],
18
- peerDiscovery: [],
19
- services: {
20
- delegatedRouting: delegatedRoutingV1HttpApiClient({
21
- url: 'https://delegated-ipfs.dev',
22
- filterAddrs: ['https'],
23
- filterProtocols: ['transport-ipfs-gateway-http']
24
- }),
25
- keychain: keychain(options.keychain)
26
- }
27
- };
28
- }
29
- //# sourceMappingURL=libp2p-defaults.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"libp2p-defaults.js","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAA;AAC7F,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAU7C,MAAM,UAAU,cAAc,CAAE,UAAoC,EAAE;IACpE,MAAM,YAAY,GAAG,eAAe,SAAS,EAAE,EAAE,CAAA;IAEjD,OAAO;QACL,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,QAAQ,EAAE;YACR,SAAS,EAAE,YAAY;SACxB;QACD,SAAS,EAAE;YACT,MAAM,EAAE,EAAE;SACX;QACD,UAAU,EAAE,EAAE;QACd,oBAAoB,EAAE,EAAE;QACxB,YAAY,EAAE,EAAE;QAChB,aAAa,EAAE,EAAE;QACjB,QAAQ,EAAE;YACR,gBAAgB,EAAE,+BAA+B,CAAC;gBAChD,GAAG,EAAE,4BAA4B;gBACjC,WAAW,EAAE,CAAC,OAAO,CAAC;gBACtB,eAAe,EAAE,CAAC,6BAA6B,CAAC;aACjD,CAAC;YACF,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC;SACrC;KACF,CAAA;AACH,CAAC"}
@@ -1,19 +0,0 @@
1
- import type { ComponentLogger, Libp2p, PrivateKey } from '@libp2p/interface';
2
- import type { KeychainInit } from '@libp2p/keychain';
3
- import type { DNS } from '@multiformats/dns';
4
- import type { Datastore } from 'interface-datastore';
5
- import type { Libp2pOptions } from 'libp2p';
6
- export interface CreateLibp2pHTTPOptions<T extends Record<string, unknown>> {
7
- datastore: Datastore;
8
- libp2p?: Libp2pOptions<T>;
9
- logger?: ComponentLogger;
10
- keychain?: KeychainInit;
11
- start?: boolean;
12
- }
13
- export interface Libp2pHTTPDefaultOptions {
14
- privateKey?: PrivateKey;
15
- keychain?: KeychainInit;
16
- dns?: DNS;
17
- }
18
- export declare function createLibp2p<T extends Record<string, unknown>>(options: CreateLibp2pHTTPOptions<T>): Promise<Libp2p<T>>;
19
- //# sourceMappingURL=libp2p.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"libp2p.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAE3C,MAAM,WAAW,uBAAuB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACxE,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;IACzB,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,CAAC,EAAE,GAAG,CAAA;CACV;AAED,wBAAsB,YAAY,CAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAG,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAkB/H"}
@@ -1,19 +0,0 @@
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(options) {
5
- const libp2pOptions = options.libp2p ?? {};
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(libp2pOptions);
11
- defaults.datastore = defaults.datastore ?? options.datastore;
12
- const node = await create({
13
- ...defaults,
14
- ...libp2pOptions,
15
- start: false
16
- });
17
- return node;
18
- }
19
- //# sourceMappingURL=libp2p.js.map
@@ -1 +0,0 @@
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;AAqBrD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAsC,OAAmC;IACzG,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAA;IAE1C,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,aAAa,CAAC,CAAA;IACnD,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;QAChB,KAAK,EAAE,KAAK;KACb,CAAC,CAAA;IAEF,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -1,38 +0,0 @@
1
- import { delegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
2
- import { keychain } from '@libp2p/keychain'
3
- import { userAgent } from 'libp2p/user-agent'
4
- import type { Libp2pHTTPDefaultOptions } from './libp2p.ts'
5
- import type { Keychain } from '@libp2p/keychain'
6
- import type { Libp2pOptions } from 'libp2p'
7
-
8
- export interface DefaultLibp2pHTTPServices extends Record<string, unknown> {
9
- delegatedRouting: unknown
10
- keychain: Keychain
11
- }
12
-
13
- export function libp2pDefaults (options: Libp2pHTTPDefaultOptions = {}): Libp2pOptions<DefaultLibp2pHTTPServices> & Required<Pick<Libp2pOptions<DefaultLibp2pHTTPServices>, 'services'>> {
14
- const agentVersion = `@helia/http ${userAgent()}`
15
-
16
- return {
17
- privateKey: options.privateKey,
18
- dns: options.dns,
19
- nodeInfo: {
20
- userAgent: agentVersion
21
- },
22
- addresses: {
23
- listen: []
24
- },
25
- transports: [],
26
- connectionEncrypters: [],
27
- streamMuxers: [],
28
- peerDiscovery: [],
29
- services: {
30
- delegatedRouting: delegatedRoutingV1HttpApiClient({
31
- url: 'https://delegated-ipfs.dev',
32
- filterAddrs: ['https'],
33
- filterProtocols: ['transport-ipfs-gateway-http']
34
- }),
35
- keychain: keychain(options.keychain)
36
- }
37
- }
38
- }
@@ -1,42 +0,0 @@
1
- import { loadOrCreateSelfKey } from '@libp2p/config'
2
- import { createLibp2p as create } from 'libp2p'
3
- import { libp2pDefaults } from './libp2p-defaults.ts'
4
- import type { ComponentLogger, Libp2p, PrivateKey } from '@libp2p/interface'
5
- import type { KeychainInit } from '@libp2p/keychain'
6
- import type { DNS } from '@multiformats/dns'
7
- import type { Datastore } from 'interface-datastore'
8
- import type { Libp2pOptions } from 'libp2p'
9
-
10
- export interface CreateLibp2pHTTPOptions<T extends Record<string, unknown>> {
11
- datastore: Datastore
12
- libp2p?: Libp2pOptions<T>
13
- logger?: ComponentLogger
14
- keychain?: KeychainInit
15
- start?: boolean
16
- }
17
-
18
- export interface Libp2pHTTPDefaultOptions {
19
- privateKey?: PrivateKey
20
- keychain?: KeychainInit
21
- dns?: DNS
22
- }
23
-
24
- export async function createLibp2p <T extends Record<string, unknown>> (options: CreateLibp2pHTTPOptions<T>): Promise<Libp2p<T>> {
25
- const libp2pOptions = options.libp2p ?? {}
26
-
27
- // if no peer id was passed, try to load it from the keychain
28
- if (libp2pOptions.privateKey == null && options.datastore != null) {
29
- libp2pOptions.privateKey = await loadOrCreateSelfKey(options.datastore, options.keychain)
30
- }
31
-
32
- const defaults: any = libp2pDefaults(libp2pOptions)
33
- defaults.datastore = defaults.datastore ?? options.datastore
34
-
35
- const node = await create<T>({
36
- ...defaults,
37
- ...libp2pOptions,
38
- start: false
39
- })
40
-
41
- return node
42
- }