@helia/http 2.1.2 → 2.2.0
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/dist/index.min.js +101 -12
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +10 -10
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +28 -20
- package/dist/src/index.js.map +1 -1
- package/dist/src/utils/libp2p-defaults.d.ts +9 -0
- package/dist/src/utils/libp2p-defaults.d.ts.map +1 -0
- package/dist/src/utils/libp2p-defaults.js +28 -0
- package/dist/src/utils/libp2p-defaults.js.map +1 -0
- package/dist/src/utils/libp2p.d.ts +19 -0
- package/dist/src/utils/libp2p.d.ts.map +1 -0
- package/dist/src/utils/libp2p.js +19 -0
- package/dist/src/utils/libp2p.js.map +1 -0
- package/dist/typedoc-urls.json +4 -2
- package/package.json +13 -8
- package/src/index.ts +38 -29
- package/src/utils/libp2p-defaults.ts +38 -0
- package/src/utils/libp2p.ts +42 -0
package/dist/src/index.d.ts
CHANGED
|
@@ -43,22 +43,22 @@
|
|
|
43
43
|
* fs.cat(CID.parse('bafyFoo'))
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
|
+
import type { DefaultLibp2pHTTPServices } from './utils/libp2p-defaults.ts';
|
|
47
|
+
import type { Libp2pHTTPDefaultOptions } from './utils/libp2p.js';
|
|
46
48
|
import type { Helia } from '@helia/interface';
|
|
47
49
|
import type { HeliaInit } from '@helia/utils';
|
|
50
|
+
import type { Libp2p } from '@libp2p/interface';
|
|
48
51
|
export * from '@helia/interface';
|
|
49
|
-
export
|
|
50
|
-
|
|
51
|
-
* Whether to start the Helia node
|
|
52
|
-
*/
|
|
53
|
-
start?: boolean;
|
|
54
|
-
}
|
|
52
|
+
export type HeliaHTTPInit = HeliaInit<Libp2p<DefaultLibp2pHTTPServices>>;
|
|
53
|
+
export type { DefaultLibp2pHTTPServices, Libp2pHTTPDefaultOptions };
|
|
55
54
|
/**
|
|
56
|
-
* Create and return the default options used to create a Helia node
|
|
57
|
-
* uses HTTP services
|
|
55
|
+
* Create and return the default options used to create a Helia node
|
|
58
56
|
*/
|
|
59
|
-
export declare function heliaDefaults(init?: Partial<
|
|
57
|
+
export declare function heliaDefaults<T extends Libp2p>(init?: Partial<HeliaInit<T>>): Promise<Omit<HeliaInit<T>, 'libp2p'> & {
|
|
58
|
+
libp2p: T;
|
|
59
|
+
}>;
|
|
60
60
|
/**
|
|
61
61
|
* Create and return a Helia node
|
|
62
62
|
*/
|
|
63
|
-
export declare function createHeliaHTTP(init?: Partial<HeliaHTTPInit>): Promise<Helia
|
|
63
|
+
export declare function createHeliaHTTP(init?: Partial<HeliaHTTPInit>): Promise<Helia<Libp2p<DefaultLibp2pHTTPServices>>>;
|
|
64
64
|
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AASH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAA;AAC3E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;AACjE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAI/C,cAAc,kBAAkB,CAAA;AAEhC,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC,CAAA;AAExE,YAAY,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,CAAA;AAEnE;;GAEG;AACH,wBAAsB,aAAa,CAAE,CAAC,SAAS,MAAM,EAAG,IAAI,GAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAM,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG;IAAE,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,CAqC/I;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAE,IAAI,GAAE,OAAO,CAAC,aAAa,CAAM,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAS3H"}
|
package/dist/src/index.js
CHANGED
|
@@ -44,52 +44,60 @@
|
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
46
|
import { trustlessGateway } from '@helia/block-brokers';
|
|
47
|
-
import {
|
|
47
|
+
import { httpGatewayRouting, libp2pRouting } from '@helia/routers';
|
|
48
48
|
import { Helia as HeliaClass } from '@helia/utils';
|
|
49
49
|
import { MemoryBlockstore } from 'blockstore-core';
|
|
50
50
|
import { MemoryDatastore } from 'datastore-core';
|
|
51
|
+
import { isLibp2p } from 'libp2p';
|
|
52
|
+
import { createLibp2p } from "./utils/libp2p.js";
|
|
51
53
|
// re-export interface types so people don't have to depend on @helia/interface
|
|
52
54
|
// if they don't want to
|
|
53
55
|
export * from '@helia/interface';
|
|
54
56
|
/**
|
|
55
|
-
* Create and return the default options used to create a Helia node
|
|
56
|
-
* uses HTTP services
|
|
57
|
+
* Create and return the default options used to create a Helia node
|
|
57
58
|
*/
|
|
58
59
|
export async function heliaDefaults(init = {}) {
|
|
59
60
|
const datastore = init.datastore ?? new MemoryDatastore();
|
|
60
61
|
const blockstore = init.blockstore ?? new MemoryBlockstore();
|
|
62
|
+
let libp2p;
|
|
63
|
+
if (isLibp2p(init.libp2p)) {
|
|
64
|
+
libp2p = init.libp2p;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
libp2p = await createLibp2p({
|
|
68
|
+
...init,
|
|
69
|
+
libp2p: {
|
|
70
|
+
dns: init.dns,
|
|
71
|
+
...init.libp2p,
|
|
72
|
+
// ignore the libp2p start parameter as it should be on the main init
|
|
73
|
+
// object instead
|
|
74
|
+
start: undefined
|
|
75
|
+
},
|
|
76
|
+
datastore
|
|
77
|
+
});
|
|
78
|
+
}
|
|
61
79
|
return {
|
|
62
80
|
...init,
|
|
81
|
+
libp2p,
|
|
63
82
|
datastore,
|
|
64
83
|
blockstore,
|
|
65
84
|
blockBrokers: init.blockBrokers ?? [
|
|
66
85
|
trustlessGateway()
|
|
67
86
|
],
|
|
68
87
|
routers: init.routers ?? [
|
|
69
|
-
|
|
88
|
+
libp2pRouting(libp2p),
|
|
70
89
|
httpGatewayRouting()
|
|
71
|
-
]
|
|
90
|
+
],
|
|
91
|
+
metrics: libp2p.metrics
|
|
72
92
|
};
|
|
73
93
|
}
|
|
74
94
|
/**
|
|
75
95
|
* Create and return a Helia node
|
|
76
96
|
*/
|
|
77
97
|
export async function createHeliaHTTP(init = {}) {
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
...init,
|
|
82
|
-
datastore,
|
|
83
|
-
blockstore,
|
|
84
|
-
blockBrokers: init.blockBrokers ?? [
|
|
85
|
-
trustlessGateway()
|
|
86
|
-
],
|
|
87
|
-
routers: init.routers ?? [
|
|
88
|
-
delegatedHTTPRouting('https://delegated-ipfs.dev'),
|
|
89
|
-
httpGatewayRouting()
|
|
90
|
-
]
|
|
91
|
-
});
|
|
92
|
-
if (init.start !== false) {
|
|
98
|
+
const options = await heliaDefaults(init);
|
|
99
|
+
const helia = new HeliaClass(options);
|
|
100
|
+
if (options.start !== false) {
|
|
93
101
|
await helia.start();
|
|
94
102
|
}
|
|
95
103
|
return helia;
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;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,KAAK,UAAU,aAAa,CAAqB,OAA8B,EAAE;IACtF,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,eAAe,EAAE,CAAA;IACzD,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,IAAI,gBAAgB,EAAE,CAAA;IAE5D,IAAI,MAAW,CAAA;IAEf,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;IACtB,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,MAAM,YAAY,CAA4B;YACrD,GAAG,IAAI;YACP,MAAM,EAAE;gBACN,GAAG,EAAE,IAAI,CAAC,GAAG;gBACb,GAAG,IAAI,CAAC,MAAM;gBAEd,qEAAqE;gBACrE,iBAAiB;gBACjB,KAAK,EAAE,SAAS;aACjB;YACD,SAAS;SACV,CAAC,CAAA;IACJ,CAAC;IAED,OAAO;QACL,GAAG,IAAI;QACP,MAAM;QACN,SAAS;QACT,UAAU;QACV,YAAY,EAAE,IAAI,CAAC,YAAY,IAAI;YACjC,gBAAgB,EAAE;SACnB;QACD,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI;YACvB,aAAa,CAAC,MAAM,CAAC;YACrB,kBAAkB,EAAE;SACrB;QACD,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAE,OAA+B,EAAE;IACtE,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,CAAA;IACzC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAA;IAErC,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;QAC5B,MAAM,KAAK,CAAC,KAAK,EAAE,CAAA;IACrB,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Libp2pHTTPDefaultOptions } from './libp2p.js';
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createDelegatedRoutingV1HttpApiClient } 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: () => createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev', {
|
|
21
|
+
filterAddrs: ['https'],
|
|
22
|
+
filterProtocols: ['transport-ipfs-gateway-http']
|
|
23
|
+
}),
|
|
24
|
+
keychain: keychain(options.keychain)
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=libp2p-defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libp2p-defaults.js","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qCAAqC,EAAE,MAAM,6CAA6C,CAAA;AACnG,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,GAAG,EAAE,CACrB,qCAAqC,CAAC,4BAA4B,EAAE;gBAClE,WAAW,EAAE,CAAC,OAAO,CAAC;gBACtB,eAAe,EAAE,CAAC,6BAA6B,CAAC;aACjD,CAAC;YACJ,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC;SACrC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
|
@@ -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;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"}
|
package/dist/typedoc-urls.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
2
|
+
"DefaultLibp2pHTTPServices": "https://ipfs.github.io/helia/interfaces/_helia_http.DefaultLibp2pHTTPServices.html",
|
|
3
|
+
"Libp2pHTTPDefaultOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.Libp2pHTTPDefaultOptions.html",
|
|
4
|
+
"HeliaHTTPInit": "https://ipfs.github.io/helia/types/_helia_http.HeliaHTTPInit.html",
|
|
5
|
+
".:HeliaHTTPInit": "https://ipfs.github.io/helia/types/_helia_http.HeliaHTTPInit.html",
|
|
4
6
|
"createHeliaHTTP": "https://ipfs.github.io/helia/functions/_helia_http.createHeliaHTTP.html",
|
|
5
7
|
".:createHeliaHTTP": "https://ipfs.github.io/helia/functions/_helia_http.createHeliaHTTP.html",
|
|
6
8
|
"heliaDefaults": "https://ipfs.github.io/helia/functions/_helia_http.heliaDefaults.html",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/http",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
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",
|
|
@@ -54,17 +54,22 @@
|
|
|
54
54
|
"test:electron-main": "aegir test -t electron-main"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@helia/block-brokers": "^4.2.
|
|
58
|
-
"@helia/
|
|
59
|
-
"@helia/
|
|
60
|
-
"@helia/
|
|
57
|
+
"@helia/block-brokers": "^4.2.3",
|
|
58
|
+
"@helia/delegated-routing-v1-http-api-client": "^4.2.5",
|
|
59
|
+
"@helia/interface": "^5.4.0",
|
|
60
|
+
"@helia/routers": "^3.1.3",
|
|
61
|
+
"@helia/utils": "^1.4.0",
|
|
62
|
+
"@libp2p/config": "^1.1.13",
|
|
63
|
+
"@libp2p/interface": "^2.10.5",
|
|
64
|
+
"@libp2p/keychain": "^5.2.8",
|
|
65
|
+
"@multiformats/dns": "^1.0.6",
|
|
61
66
|
"blockstore-core": "^5.0.2",
|
|
62
|
-
"datastore-core": "^10.0.2"
|
|
67
|
+
"datastore-core": "^10.0.2",
|
|
68
|
+
"interface-datastore": "^8.3.2",
|
|
69
|
+
"libp2p": "^2.9.0"
|
|
63
70
|
},
|
|
64
71
|
"devDependencies": {
|
|
65
|
-
"@libp2p/interface": "^2.2.1",
|
|
66
72
|
"aegir": "^47.0.7",
|
|
67
|
-
"interface-datastore": "^8.3.1",
|
|
68
73
|
"multiformats": "^13.3.1",
|
|
69
74
|
"sinon": "^20.0.0",
|
|
70
75
|
"sinon-ts": "^2.0.0"
|
package/src/index.ts
CHANGED
|
@@ -45,67 +45,76 @@
|
|
|
45
45
|
*/
|
|
46
46
|
|
|
47
47
|
import { trustlessGateway } from '@helia/block-brokers'
|
|
48
|
-
import {
|
|
48
|
+
import { httpGatewayRouting, libp2pRouting } from '@helia/routers'
|
|
49
49
|
import { Helia as HeliaClass } from '@helia/utils'
|
|
50
50
|
import { MemoryBlockstore } from 'blockstore-core'
|
|
51
51
|
import { MemoryDatastore } from 'datastore-core'
|
|
52
|
+
import { isLibp2p } from 'libp2p'
|
|
53
|
+
import { createLibp2p } from './utils/libp2p.ts'
|
|
54
|
+
import type { DefaultLibp2pHTTPServices } from './utils/libp2p-defaults.ts'
|
|
55
|
+
import type { Libp2pHTTPDefaultOptions } from './utils/libp2p.js'
|
|
52
56
|
import type { Helia } from '@helia/interface'
|
|
53
57
|
import type { HeliaInit } from '@helia/utils'
|
|
58
|
+
import type { Libp2p } from '@libp2p/interface'
|
|
54
59
|
|
|
55
60
|
// re-export interface types so people don't have to depend on @helia/interface
|
|
56
61
|
// if they don't want to
|
|
57
62
|
export * from '@helia/interface'
|
|
58
63
|
|
|
59
|
-
export
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*/
|
|
63
|
-
start?: boolean
|
|
64
|
-
}
|
|
64
|
+
export type HeliaHTTPInit = HeliaInit<Libp2p<DefaultLibp2pHTTPServices>>
|
|
65
|
+
|
|
66
|
+
export type { DefaultLibp2pHTTPServices, Libp2pHTTPDefaultOptions }
|
|
65
67
|
|
|
66
68
|
/**
|
|
67
|
-
* Create and return the default options used to create a Helia node
|
|
68
|
-
* uses HTTP services
|
|
69
|
+
* Create and return the default options used to create a Helia node
|
|
69
70
|
*/
|
|
70
|
-
export async function heliaDefaults (init: Partial<
|
|
71
|
+
export async function heliaDefaults <T extends Libp2p> (init: Partial<HeliaInit<T>> = {}): Promise<Omit<HeliaInit<T>, 'libp2p'> & { libp2p: T }> {
|
|
71
72
|
const datastore = init.datastore ?? new MemoryDatastore()
|
|
72
73
|
const blockstore = init.blockstore ?? new MemoryBlockstore()
|
|
73
74
|
|
|
75
|
+
let libp2p: any
|
|
76
|
+
|
|
77
|
+
if (isLibp2p(init.libp2p)) {
|
|
78
|
+
libp2p = init.libp2p
|
|
79
|
+
} else {
|
|
80
|
+
libp2p = await createLibp2p<DefaultLibp2pHTTPServices>({
|
|
81
|
+
...init,
|
|
82
|
+
libp2p: {
|
|
83
|
+
dns: init.dns,
|
|
84
|
+
...init.libp2p,
|
|
85
|
+
|
|
86
|
+
// ignore the libp2p start parameter as it should be on the main init
|
|
87
|
+
// object instead
|
|
88
|
+
start: undefined
|
|
89
|
+
},
|
|
90
|
+
datastore
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
74
94
|
return {
|
|
75
95
|
...init,
|
|
96
|
+
libp2p,
|
|
76
97
|
datastore,
|
|
77
98
|
blockstore,
|
|
78
99
|
blockBrokers: init.blockBrokers ?? [
|
|
79
100
|
trustlessGateway()
|
|
80
101
|
],
|
|
81
102
|
routers: init.routers ?? [
|
|
82
|
-
|
|
103
|
+
libp2pRouting(libp2p),
|
|
83
104
|
httpGatewayRouting()
|
|
84
|
-
]
|
|
105
|
+
],
|
|
106
|
+
metrics: libp2p.metrics
|
|
85
107
|
}
|
|
86
108
|
}
|
|
87
109
|
|
|
88
110
|
/**
|
|
89
111
|
* Create and return a Helia node
|
|
90
112
|
*/
|
|
91
|
-
export async function createHeliaHTTP (init: Partial<HeliaHTTPInit> = {}): Promise<Helia
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
const helia = new HeliaClass({
|
|
96
|
-
...init,
|
|
97
|
-
datastore,
|
|
98
|
-
blockstore,
|
|
99
|
-
blockBrokers: init.blockBrokers ?? [
|
|
100
|
-
trustlessGateway()
|
|
101
|
-
],
|
|
102
|
-
routers: init.routers ?? [
|
|
103
|
-
delegatedHTTPRouting('https://delegated-ipfs.dev'),
|
|
104
|
-
httpGatewayRouting()
|
|
105
|
-
]
|
|
106
|
-
})
|
|
113
|
+
export async function createHeliaHTTP (init: Partial<HeliaHTTPInit> = {}): Promise<Helia<Libp2p<DefaultLibp2pHTTPServices>>> {
|
|
114
|
+
const options = await heliaDefaults(init)
|
|
115
|
+
const helia = new HeliaClass(options)
|
|
107
116
|
|
|
108
|
-
if (
|
|
117
|
+
if (options.start !== false) {
|
|
109
118
|
await helia.start()
|
|
110
119
|
}
|
|
111
120
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createDelegatedRoutingV1HttpApiClient } 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.js'
|
|
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: () =>
|
|
31
|
+
createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev', {
|
|
32
|
+
filterAddrs: ['https'],
|
|
33
|
+
filterProtocols: ['transport-ipfs-gateway-http']
|
|
34
|
+
}),
|
|
35
|
+
keychain: keychain(options.keychain)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { loadOrCreateSelfKey } from '@libp2p/config'
|
|
2
|
+
import { createLibp2p as create } from 'libp2p'
|
|
3
|
+
import { libp2pDefaults } from './libp2p-defaults.js'
|
|
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
|
+
}
|