@helia/ipns 4.0.0-a0692f9 → 4.0.0-a2229bd
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 +41 -3
- package/dist/index.min.js +73 -26
- package/dist/src/index.d.ts +44 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +47 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/routing/helia.d.ts +20 -0
- package/dist/src/routing/helia.d.ts.map +1 -0
- package/dist/src/routing/helia.js +32 -0
- package/dist/src/routing/helia.js.map +1 -0
- package/dist/src/routing/index.d.ts +3 -3
- package/dist/src/routing/index.d.ts.map +1 -1
- package/dist/src/routing/index.js +1 -1
- package/dist/src/routing/index.js.map +1 -1
- package/package.json +6 -7
- package/src/index.ts +49 -5
- package/src/routing/helia.ts +45 -0
- package/src/routing/index.ts +3 -3
- package/dist/src/routing/libp2p.d.ts +0 -22
- package/dist/src/routing/libp2p.d.ts.map +0 -1
- package/dist/src/routing/libp2p.js +0 -32
- package/dist/src/routing/libp2p.js.map +0 -1
- package/src/routing/libp2p.ts +0 -47
package/dist/src/index.d.ts
CHANGED
|
@@ -3,20 +3,58 @@
|
|
|
3
3
|
*
|
|
4
4
|
* IPNS operations using a Helia node
|
|
5
5
|
*
|
|
6
|
-
* @example
|
|
6
|
+
* @example Getting started
|
|
7
7
|
*
|
|
8
8
|
* With {@link IPNSRouting} routers:
|
|
9
9
|
*
|
|
10
10
|
* ```typescript
|
|
11
11
|
* import { createHelia } from 'helia'
|
|
12
12
|
* import { ipns } from '@helia/ipns'
|
|
13
|
-
* import {
|
|
13
|
+
* import { unixfs } from '@helia/unixfs'
|
|
14
|
+
*
|
|
15
|
+
* const helia = await createHelia()
|
|
16
|
+
* const name = ipns(helia)
|
|
17
|
+
*
|
|
18
|
+
* // create a public key to publish as an IPNS name
|
|
19
|
+
* const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
|
|
20
|
+
* const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
|
|
21
|
+
*
|
|
22
|
+
* // store some data to publish
|
|
23
|
+
* const fs = unixfs(helia)
|
|
24
|
+
* const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
25
|
+
*
|
|
26
|
+
* // publish the name
|
|
27
|
+
* await name.publish(peerId, cid)
|
|
28
|
+
*
|
|
29
|
+
* // resolve the name
|
|
30
|
+
* const cid = name.resolve(peerId)
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example Using custom PubSub router
|
|
34
|
+
*
|
|
35
|
+
* Additional IPNS routers can be configured - these enable alternative means to
|
|
36
|
+
* publish and resolve IPNS names.
|
|
37
|
+
*
|
|
38
|
+
* One example is the PubSub router - this requires an instance of Helia with
|
|
39
|
+
* libp2p PubSub configured.
|
|
40
|
+
*
|
|
41
|
+
* It works by subscribing to a pubsub topic for each IPNS name that we try to
|
|
42
|
+
* resolve. Updated IPNS records are shared on these topics so an update must
|
|
43
|
+
* occur before the name is resolvable.
|
|
44
|
+
*
|
|
45
|
+
* This router is only suitable for networks where IPNS updates are frequent
|
|
46
|
+
* and multiple peers are listening on the topic(s), otherwise update messages
|
|
47
|
+
* may fail to be published with "Insufficient peers" errors.
|
|
48
|
+
*
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { createHelia } from 'helia'
|
|
51
|
+
* import { ipns } from '@helia/ipns'
|
|
52
|
+
* import { pubsub } from '@helia/ipns/routing'
|
|
14
53
|
* import { unixfs } from '@helia/unixfs'
|
|
15
54
|
*
|
|
16
55
|
* const helia = await createHelia()
|
|
17
56
|
* const name = ipns(helia, {
|
|
18
57
|
* routers: [
|
|
19
|
-
* libp2p(helia),
|
|
20
58
|
* pubsub(helia)
|
|
21
59
|
* ]
|
|
22
60
|
* })
|
|
@@ -115,6 +153,7 @@ import { ipnsValidator } from 'ipns/validator';
|
|
|
115
153
|
import { CID } from 'multiformats/cid';
|
|
116
154
|
import type { IPNSRouting, IPNSRoutingEvents } from './routing/index.js';
|
|
117
155
|
import type { DNSResponse } from './utils/dns.js';
|
|
156
|
+
import type { Routing } from '@helia/interface';
|
|
118
157
|
import type { AbortOptions, PeerId } from '@libp2p/interface';
|
|
119
158
|
import type { Datastore } from 'interface-datastore';
|
|
120
159
|
import type { IPNSRecord } from 'ipns';
|
|
@@ -203,12 +242,13 @@ export interface IPNS {
|
|
|
203
242
|
export type { IPNSRouting } from './routing/index.js';
|
|
204
243
|
export interface IPNSComponents {
|
|
205
244
|
datastore: Datastore;
|
|
245
|
+
routing: Routing;
|
|
206
246
|
}
|
|
207
247
|
export interface IPNSOptions {
|
|
208
248
|
routers?: IPNSRouting[];
|
|
209
249
|
resolvers?: DNSResolver[];
|
|
210
250
|
}
|
|
211
|
-
export declare function ipns(components: IPNSComponents, { routers, resolvers }
|
|
251
|
+
export declare function ipns(components: IPNSComponents, { routers, resolvers }?: IPNSOptions): IPNS;
|
|
212
252
|
export { ipnsValidator };
|
|
213
253
|
export { ipnsSelector } from 'ipns/selector';
|
|
214
254
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsJG;AAOH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAKtC,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oBAAo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AAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IAErE;;OAEG;IACH,SAAS,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAA;CAC5C;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAA;IACpB,OAAO,EAAE,OAAO,CAAA;CACjB;AA4JD,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,WAAW,EAAE,CAAA;IACvB,SAAS,CAAC,EAAE,WAAW,EAAE,CAAA;CAC1B;AAED,wBAAgB,IAAI,CAAE,UAAU,EAAE,cAAc,EAAE,EAAE,OAAY,EAAE,SAAc,EAAE,GAAE,WAAgB,GAAG,IAAI,CAE1G;AAED,OAAO,EAAE,aAAa,EAAE,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -3,20 +3,58 @@
|
|
|
3
3
|
*
|
|
4
4
|
* IPNS operations using a Helia node
|
|
5
5
|
*
|
|
6
|
-
* @example
|
|
6
|
+
* @example Getting started
|
|
7
7
|
*
|
|
8
8
|
* With {@link IPNSRouting} routers:
|
|
9
9
|
*
|
|
10
10
|
* ```typescript
|
|
11
11
|
* import { createHelia } from 'helia'
|
|
12
12
|
* import { ipns } from '@helia/ipns'
|
|
13
|
-
* import {
|
|
13
|
+
* import { unixfs } from '@helia/unixfs'
|
|
14
|
+
*
|
|
15
|
+
* const helia = await createHelia()
|
|
16
|
+
* const name = ipns(helia)
|
|
17
|
+
*
|
|
18
|
+
* // create a public key to publish as an IPNS name
|
|
19
|
+
* const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
|
|
20
|
+
* const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
|
|
21
|
+
*
|
|
22
|
+
* // store some data to publish
|
|
23
|
+
* const fs = unixfs(helia)
|
|
24
|
+
* const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
25
|
+
*
|
|
26
|
+
* // publish the name
|
|
27
|
+
* await name.publish(peerId, cid)
|
|
28
|
+
*
|
|
29
|
+
* // resolve the name
|
|
30
|
+
* const cid = name.resolve(peerId)
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example Using custom PubSub router
|
|
34
|
+
*
|
|
35
|
+
* Additional IPNS routers can be configured - these enable alternative means to
|
|
36
|
+
* publish and resolve IPNS names.
|
|
37
|
+
*
|
|
38
|
+
* One example is the PubSub router - this requires an instance of Helia with
|
|
39
|
+
* libp2p PubSub configured.
|
|
40
|
+
*
|
|
41
|
+
* It works by subscribing to a pubsub topic for each IPNS name that we try to
|
|
42
|
+
* resolve. Updated IPNS records are shared on these topics so an update must
|
|
43
|
+
* occur before the name is resolvable.
|
|
44
|
+
*
|
|
45
|
+
* This router is only suitable for networks where IPNS updates are frequent
|
|
46
|
+
* and multiple peers are listening on the topic(s), otherwise update messages
|
|
47
|
+
* may fail to be published with "Insufficient peers" errors.
|
|
48
|
+
*
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { createHelia } from 'helia'
|
|
51
|
+
* import { ipns } from '@helia/ipns'
|
|
52
|
+
* import { pubsub } from '@helia/ipns/routing'
|
|
14
53
|
* import { unixfs } from '@helia/unixfs'
|
|
15
54
|
*
|
|
16
55
|
* const helia = await createHelia()
|
|
17
56
|
* const name = ipns(helia, {
|
|
18
57
|
* routers: [
|
|
19
|
-
* libp2p(helia),
|
|
20
58
|
* pubsub(helia)
|
|
21
59
|
* ]
|
|
22
60
|
* })
|
|
@@ -120,6 +158,7 @@ import { ipnsValidator } from 'ipns/validator';
|
|
|
120
158
|
import { CID } from 'multiformats/cid';
|
|
121
159
|
import { CustomProgressEvent } from 'progress-events';
|
|
122
160
|
import { defaultResolver } from './dns-resolvers/default.js';
|
|
161
|
+
import { helia } from './routing/helia.js';
|
|
123
162
|
import { localStore } from './routing/local-store.js';
|
|
124
163
|
const log = logger('helia:ipns');
|
|
125
164
|
const MINUTE = 60 * 1000;
|
|
@@ -132,7 +171,10 @@ class DefaultIPNS {
|
|
|
132
171
|
timeout;
|
|
133
172
|
defaultResolvers;
|
|
134
173
|
constructor(components, routers = [], resolvers = []) {
|
|
135
|
-
this.routers =
|
|
174
|
+
this.routers = [
|
|
175
|
+
helia(components.routing),
|
|
176
|
+
...routers
|
|
177
|
+
];
|
|
136
178
|
this.localStore = localStore(components.datastore);
|
|
137
179
|
this.defaultResolvers = resolvers.length > 0 ? resolvers : [defaultResolver()];
|
|
138
180
|
}
|
|
@@ -242,7 +284,7 @@ class DefaultIPNS {
|
|
|
242
284
|
return unmarshal(record);
|
|
243
285
|
}
|
|
244
286
|
}
|
|
245
|
-
export function ipns(components, { routers = [], resolvers = [] }) {
|
|
287
|
+
export function ipns(components, { routers = [], resolvers = [] } = {}) {
|
|
246
288
|
return new DefaultIPNS(components, routers, resolvers);
|
|
247
289
|
}
|
|
248
290
|
export { ipnsValidator };
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsJG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,OAAO,EAA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,EAAE,EAAE,SAAS,GAAG,EAAE,KAAkB,EAAE;IAClG,OAAO,IAAI,WAAW,CAAC,UAAU,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;AACxD,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ProgressEvent } from 'progress-events';
|
|
2
|
+
import type { GetOptions, PutOptions } from './index.js';
|
|
3
|
+
import type { IPNSRouting } from '../index.js';
|
|
4
|
+
import type { Routing } from '@helia/interface';
|
|
5
|
+
export interface HeliaRoutingComponents {
|
|
6
|
+
routing: Routing;
|
|
7
|
+
}
|
|
8
|
+
export type HeliaRoutingProgressEvents = ProgressEvent<'ipns:routing:helia:error', Error>;
|
|
9
|
+
export declare class HeliaRouting implements IPNSRouting {
|
|
10
|
+
private readonly routing;
|
|
11
|
+
constructor(routing: Routing);
|
|
12
|
+
put(routingKey: Uint8Array, marshaledRecord: Uint8Array, options?: PutOptions): Promise<void>;
|
|
13
|
+
get(routingKey: Uint8Array, options?: GetOptions): Promise<Uint8Array>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The helia routing uses any available Routers configured on the passed Helia
|
|
17
|
+
* node. This could be libp2p, HTTP API Delegated Routing, etc.
|
|
18
|
+
*/
|
|
19
|
+
export declare function helia(routing: Routing): IPNSRouting;
|
|
20
|
+
//# sourceMappingURL=helia.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helia.d.ts","sourceRoot":"","sources":["../../../src/routing/helia.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE/C,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,MAAM,0BAA0B,GACpC,aAAa,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAA;AAElD,qBAAa,YAAa,YAAW,WAAW;IAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAEpB,OAAO,EAAE,OAAO;IAIvB,GAAG,CAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAQlG,GAAG,CAAE,UAAU,EAAE,UAAU,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,UAAU,CAAC;CASlF;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAE,OAAO,EAAE,OAAO,GAAG,WAAW,CAEpD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CustomProgressEvent } from 'progress-events';
|
|
2
|
+
export class HeliaRouting {
|
|
3
|
+
routing;
|
|
4
|
+
constructor(routing) {
|
|
5
|
+
this.routing = routing;
|
|
6
|
+
}
|
|
7
|
+
async put(routingKey, marshaledRecord, options = {}) {
|
|
8
|
+
try {
|
|
9
|
+
await this.routing.put(routingKey, marshaledRecord, options);
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
options.onProgress?.(new CustomProgressEvent('ipns:routing:helia:error', err));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
async get(routingKey, options = {}) {
|
|
16
|
+
try {
|
|
17
|
+
return await this.routing.get(routingKey, options);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
options.onProgress?.(new CustomProgressEvent('ipns:routing:helia:error', err));
|
|
21
|
+
}
|
|
22
|
+
throw new Error('Not found');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The helia routing uses any available Routers configured on the passed Helia
|
|
27
|
+
* node. This could be libp2p, HTTP API Delegated Routing, etc.
|
|
28
|
+
*/
|
|
29
|
+
export function helia(routing) {
|
|
30
|
+
return new HeliaRouting(routing);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=helia.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helia.js","sourceRoot":"","sources":["../../../src/routing/helia.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAsB,MAAM,iBAAiB,CAAA;AAYzE,MAAM,OAAO,YAAY;IACN,OAAO,CAAS;IAEjC,YAAa,OAAgB;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,GAAG,CAAE,UAAsB,EAAE,eAA2B,EAAE,UAAsB,EAAE;QACtF,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,eAAe,EAAE,OAAO,CAAC,CAAA;QAC9D,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAQ,0BAA0B,EAAE,GAAG,CAAC,CAAC,CAAA;QACvF,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CAAE,UAAsB,EAAE,UAAsB,EAAE;QACzD,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;QACpD,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAQ,0BAA0B,EAAE,GAAG,CAAC,CAAC,CAAA;QACvF,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAA;IAC9B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAE,OAAgB;IACrC,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,CAAA;AAClC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HeliaRoutingProgressEvents } from './helia.js';
|
|
2
2
|
import type { DatastoreProgressEvents } from './local-store.js';
|
|
3
3
|
import type { PubSubProgressEvents } from './pubsub.js';
|
|
4
4
|
import type { AbortOptions } from '@libp2p/interface';
|
|
@@ -11,7 +11,7 @@ export interface IPNSRouting {
|
|
|
11
11
|
put(routingKey: Uint8Array, marshaledRecord: Uint8Array, options?: PutOptions): Promise<void>;
|
|
12
12
|
get(routingKey: Uint8Array, options?: GetOptions): Promise<Uint8Array>;
|
|
13
13
|
}
|
|
14
|
-
export type IPNSRoutingEvents = DatastoreProgressEvents |
|
|
15
|
-
export {
|
|
14
|
+
export type IPNSRoutingEvents = DatastoreProgressEvents | HeliaRoutingProgressEvents | PubSubProgressEvents;
|
|
15
|
+
export { helia } from './helia.js';
|
|
16
16
|
export { pubsub } from './pubsub.js';
|
|
17
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/routing/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/routing/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD,MAAM,WAAW,UAAW,SAAQ,YAAY,EAAE,eAAe;CAEhE;AAED,MAAM,WAAW,UAAW,SAAQ,YAAY,EAAE,eAAe;CAEhE;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7F,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;CACvE;AAED,MAAM,MAAM,iBAAiB,GAC3B,uBAAuB,GACvB,0BAA0B,GAC1B,oBAAoB,CAAA;AAEtB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/routing/index.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/routing/index.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/ipns",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-a2229bd",
|
|
4
4
|
"description": "An implementation of IPNS for Helia",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/ipns#readme",
|
|
@@ -153,6 +153,7 @@
|
|
|
153
153
|
"lint": "aegir lint",
|
|
154
154
|
"dep-check": "aegir dep-check",
|
|
155
155
|
"build": "aegir build",
|
|
156
|
+
"docs": "aegir docs",
|
|
156
157
|
"test": "aegir test",
|
|
157
158
|
"test:chrome": "aegir test -t browser --cov",
|
|
158
159
|
"test:chrome-webworker": "aegir test -t webworker",
|
|
@@ -163,6 +164,7 @@
|
|
|
163
164
|
"release": "aegir release"
|
|
164
165
|
},
|
|
165
166
|
"dependencies": {
|
|
167
|
+
"@helia/interface": "3.0.1-a2229bd",
|
|
166
168
|
"@libp2p/interface": "^1.1.1",
|
|
167
169
|
"@libp2p/kad-dht": "^12.0.2",
|
|
168
170
|
"@libp2p/logger": "^4.0.4",
|
|
@@ -170,7 +172,7 @@
|
|
|
170
172
|
"dns-over-http-resolver": "^3.0.0",
|
|
171
173
|
"dns-packet": "^5.6.0",
|
|
172
174
|
"hashlru": "^2.3.0",
|
|
173
|
-
"interface-datastore": "^8.2.
|
|
175
|
+
"interface-datastore": "^8.2.9",
|
|
174
176
|
"ipns": "^8.0.0",
|
|
175
177
|
"is-ipfs": "^8.0.1",
|
|
176
178
|
"multiformats": "^13.0.0",
|
|
@@ -181,15 +183,12 @@
|
|
|
181
183
|
"devDependencies": {
|
|
182
184
|
"@libp2p/peer-id-factory": "^4.0.3",
|
|
183
185
|
"@types/dns-packet": "^5.6.4",
|
|
184
|
-
"aegir": "^42.0
|
|
185
|
-
"datastore-core": "^9.2.
|
|
186
|
+
"aegir": "^42.1.0",
|
|
187
|
+
"datastore-core": "^9.2.7",
|
|
186
188
|
"sinon": "^17.0.1",
|
|
187
189
|
"sinon-ts": "^2.0.0"
|
|
188
190
|
},
|
|
189
191
|
"browser": {
|
|
190
192
|
"./dist/src/dns-resolvers/resolver.js": "./dist/src/dns-resolvers/resolver.browser.js"
|
|
191
|
-
},
|
|
192
|
-
"typedoc": {
|
|
193
|
-
"entryPoint": "./src/index.ts"
|
|
194
193
|
}
|
|
195
194
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,20 +3,58 @@
|
|
|
3
3
|
*
|
|
4
4
|
* IPNS operations using a Helia node
|
|
5
5
|
*
|
|
6
|
-
* @example
|
|
6
|
+
* @example Getting started
|
|
7
7
|
*
|
|
8
8
|
* With {@link IPNSRouting} routers:
|
|
9
9
|
*
|
|
10
10
|
* ```typescript
|
|
11
11
|
* import { createHelia } from 'helia'
|
|
12
12
|
* import { ipns } from '@helia/ipns'
|
|
13
|
-
* import {
|
|
13
|
+
* import { unixfs } from '@helia/unixfs'
|
|
14
|
+
*
|
|
15
|
+
* const helia = await createHelia()
|
|
16
|
+
* const name = ipns(helia)
|
|
17
|
+
*
|
|
18
|
+
* // create a public key to publish as an IPNS name
|
|
19
|
+
* const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
|
|
20
|
+
* const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
|
|
21
|
+
*
|
|
22
|
+
* // store some data to publish
|
|
23
|
+
* const fs = unixfs(helia)
|
|
24
|
+
* const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
25
|
+
*
|
|
26
|
+
* // publish the name
|
|
27
|
+
* await name.publish(peerId, cid)
|
|
28
|
+
*
|
|
29
|
+
* // resolve the name
|
|
30
|
+
* const cid = name.resolve(peerId)
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example Using custom PubSub router
|
|
34
|
+
*
|
|
35
|
+
* Additional IPNS routers can be configured - these enable alternative means to
|
|
36
|
+
* publish and resolve IPNS names.
|
|
37
|
+
*
|
|
38
|
+
* One example is the PubSub router - this requires an instance of Helia with
|
|
39
|
+
* libp2p PubSub configured.
|
|
40
|
+
*
|
|
41
|
+
* It works by subscribing to a pubsub topic for each IPNS name that we try to
|
|
42
|
+
* resolve. Updated IPNS records are shared on these topics so an update must
|
|
43
|
+
* occur before the name is resolvable.
|
|
44
|
+
*
|
|
45
|
+
* This router is only suitable for networks where IPNS updates are frequent
|
|
46
|
+
* and multiple peers are listening on the topic(s), otherwise update messages
|
|
47
|
+
* may fail to be published with "Insufficient peers" errors.
|
|
48
|
+
*
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { createHelia } from 'helia'
|
|
51
|
+
* import { ipns } from '@helia/ipns'
|
|
52
|
+
* import { pubsub } from '@helia/ipns/routing'
|
|
14
53
|
* import { unixfs } from '@helia/unixfs'
|
|
15
54
|
*
|
|
16
55
|
* const helia = await createHelia()
|
|
17
56
|
* const name = ipns(helia, {
|
|
18
57
|
* routers: [
|
|
19
|
-
* libp2p(helia),
|
|
20
58
|
* pubsub(helia)
|
|
21
59
|
* ]
|
|
22
60
|
* })
|
|
@@ -121,9 +159,11 @@ import { ipnsValidator } from 'ipns/validator'
|
|
|
121
159
|
import { CID } from 'multiformats/cid'
|
|
122
160
|
import { CustomProgressEvent } from 'progress-events'
|
|
123
161
|
import { defaultResolver } from './dns-resolvers/default.js'
|
|
162
|
+
import { helia } from './routing/helia.js'
|
|
124
163
|
import { localStore, type LocalStore } from './routing/local-store.js'
|
|
125
164
|
import type { IPNSRouting, IPNSRoutingEvents } from './routing/index.js'
|
|
126
165
|
import type { DNSResponse } from './utils/dns.js'
|
|
166
|
+
import type { Routing } from '@helia/interface'
|
|
127
167
|
import type { AbortOptions, PeerId } from '@libp2p/interface'
|
|
128
168
|
import type { Datastore } from 'interface-datastore'
|
|
129
169
|
import type { IPNSRecord } from 'ipns'
|
|
@@ -249,6 +289,7 @@ export type { IPNSRouting } from './routing/index.js'
|
|
|
249
289
|
|
|
250
290
|
export interface IPNSComponents {
|
|
251
291
|
datastore: Datastore
|
|
292
|
+
routing: Routing
|
|
252
293
|
}
|
|
253
294
|
|
|
254
295
|
class DefaultIPNS implements IPNS {
|
|
@@ -258,7 +299,10 @@ class DefaultIPNS implements IPNS {
|
|
|
258
299
|
private readonly defaultResolvers: DNSResolver[]
|
|
259
300
|
|
|
260
301
|
constructor (components: IPNSComponents, routers: IPNSRouting[] = [], resolvers: DNSResolver[] = []) {
|
|
261
|
-
this.routers =
|
|
302
|
+
this.routers = [
|
|
303
|
+
helia(components.routing),
|
|
304
|
+
...routers
|
|
305
|
+
]
|
|
262
306
|
this.localStore = localStore(components.datastore)
|
|
263
307
|
this.defaultResolvers = resolvers.length > 0 ? resolvers : [defaultResolver()]
|
|
264
308
|
}
|
|
@@ -407,7 +451,7 @@ export interface IPNSOptions {
|
|
|
407
451
|
resolvers?: DNSResolver[]
|
|
408
452
|
}
|
|
409
453
|
|
|
410
|
-
export function ipns (components: IPNSComponents, { routers = [], resolvers = [] }: IPNSOptions): IPNS {
|
|
454
|
+
export function ipns (components: IPNSComponents, { routers = [], resolvers = [] }: IPNSOptions = {}): IPNS {
|
|
411
455
|
return new DefaultIPNS(components, routers, resolvers)
|
|
412
456
|
}
|
|
413
457
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CustomProgressEvent, type ProgressEvent } from 'progress-events'
|
|
2
|
+
import type { GetOptions, PutOptions } from './index.js'
|
|
3
|
+
import type { IPNSRouting } from '../index.js'
|
|
4
|
+
import type { Routing } from '@helia/interface'
|
|
5
|
+
|
|
6
|
+
export interface HeliaRoutingComponents {
|
|
7
|
+
routing: Routing
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type HeliaRoutingProgressEvents =
|
|
11
|
+
ProgressEvent<'ipns:routing:helia:error', Error>
|
|
12
|
+
|
|
13
|
+
export class HeliaRouting implements IPNSRouting {
|
|
14
|
+
private readonly routing: Routing
|
|
15
|
+
|
|
16
|
+
constructor (routing: Routing) {
|
|
17
|
+
this.routing = routing
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async put (routingKey: Uint8Array, marshaledRecord: Uint8Array, options: PutOptions = {}): Promise<void> {
|
|
21
|
+
try {
|
|
22
|
+
await this.routing.put(routingKey, marshaledRecord, options)
|
|
23
|
+
} catch (err: any) {
|
|
24
|
+
options.onProgress?.(new CustomProgressEvent<Error>('ipns:routing:helia:error', err))
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async get (routingKey: Uint8Array, options: GetOptions = {}): Promise<Uint8Array> {
|
|
29
|
+
try {
|
|
30
|
+
return await this.routing.get(routingKey, options)
|
|
31
|
+
} catch (err: any) {
|
|
32
|
+
options.onProgress?.(new CustomProgressEvent<Error>('ipns:routing:helia:error', err))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
throw new Error('Not found')
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The helia routing uses any available Routers configured on the passed Helia
|
|
41
|
+
* node. This could be libp2p, HTTP API Delegated Routing, etc.
|
|
42
|
+
*/
|
|
43
|
+
export function helia (routing: Routing): IPNSRouting {
|
|
44
|
+
return new HeliaRouting(routing)
|
|
45
|
+
}
|
package/src/routing/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HeliaRoutingProgressEvents } from './helia.js'
|
|
2
2
|
import type { DatastoreProgressEvents } from './local-store.js'
|
|
3
3
|
import type { PubSubProgressEvents } from './pubsub.js'
|
|
4
4
|
import type { AbortOptions } from '@libp2p/interface'
|
|
@@ -19,8 +19,8 @@ export interface IPNSRouting {
|
|
|
19
19
|
|
|
20
20
|
export type IPNSRoutingEvents =
|
|
21
21
|
DatastoreProgressEvents |
|
|
22
|
-
|
|
22
|
+
HeliaRoutingProgressEvents |
|
|
23
23
|
PubSubProgressEvents
|
|
24
24
|
|
|
25
|
-
export {
|
|
25
|
+
export { helia } from './helia.js'
|
|
26
26
|
export { pubsub } from './pubsub.js'
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type ProgressEvent } from 'progress-events';
|
|
2
|
-
import type { GetOptions, PutOptions } from './index.js';
|
|
3
|
-
import type { IPNSRouting } from '../index.js';
|
|
4
|
-
import type { ContentRouting } from '@libp2p/interface';
|
|
5
|
-
export interface Libp2pContentRoutingComponents {
|
|
6
|
-
libp2p: {
|
|
7
|
-
contentRouting: ContentRouting;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export type Libp2pContentRoutingProgressEvents = ProgressEvent<'ipns:routing:libp2p:error', Error>;
|
|
11
|
-
export declare class Libp2pContentRouting implements IPNSRouting {
|
|
12
|
-
private readonly contentRouting;
|
|
13
|
-
constructor(components: Libp2pContentRoutingComponents);
|
|
14
|
-
put(routingKey: Uint8Array, marshaledRecord: Uint8Array, options?: PutOptions): Promise<void>;
|
|
15
|
-
get(routingKey: Uint8Array, options?: GetOptions): Promise<Uint8Array>;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* The libp2p routing uses any available Content Routers configured on the
|
|
19
|
-
* passed libp2p node. This could be KadDHT, HTTP API Delegated Routing, etc.
|
|
20
|
-
*/
|
|
21
|
-
export declare function libp2p(components: Libp2pContentRoutingComponents): IPNSRouting;
|
|
22
|
-
//# sourceMappingURL=libp2p.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p.d.ts","sourceRoot":"","sources":["../../../src/routing/libp2p.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEvD,MAAM,WAAW,8BAA8B;IAC7C,MAAM,EAAE;QACN,cAAc,EAAE,cAAc,CAAA;KAC/B,CAAA;CACF;AAED,MAAM,MAAM,kCAAkC,GAC5C,aAAa,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAA;AAEnD,qBAAa,oBAAqB,YAAW,WAAW;IACtD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgB;gBAElC,UAAU,EAAE,8BAA8B;IAIjD,GAAG,CAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAQlG,GAAG,CAAE,UAAU,EAAE,UAAU,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,UAAU,CAAC;CASlF;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAE,UAAU,EAAE,8BAA8B,GAAG,WAAW,CAE/E"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { CustomProgressEvent } from 'progress-events';
|
|
2
|
-
export class Libp2pContentRouting {
|
|
3
|
-
contentRouting;
|
|
4
|
-
constructor(components) {
|
|
5
|
-
this.contentRouting = components.libp2p.contentRouting;
|
|
6
|
-
}
|
|
7
|
-
async put(routingKey, marshaledRecord, options = {}) {
|
|
8
|
-
try {
|
|
9
|
-
await this.contentRouting.put(routingKey, marshaledRecord, options);
|
|
10
|
-
}
|
|
11
|
-
catch (err) {
|
|
12
|
-
options.onProgress?.(new CustomProgressEvent('ipns:routing:libp2p:error', err));
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
async get(routingKey, options = {}) {
|
|
16
|
-
try {
|
|
17
|
-
return await this.contentRouting.get(routingKey, options);
|
|
18
|
-
}
|
|
19
|
-
catch (err) {
|
|
20
|
-
options.onProgress?.(new CustomProgressEvent('ipns:routing:libp2p:error', err));
|
|
21
|
-
}
|
|
22
|
-
throw new Error('Not found');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* The libp2p routing uses any available Content Routers configured on the
|
|
27
|
-
* passed libp2p node. This could be KadDHT, HTTP API Delegated Routing, etc.
|
|
28
|
-
*/
|
|
29
|
-
export function libp2p(components) {
|
|
30
|
-
return new Libp2pContentRouting(components);
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=libp2p.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p.js","sourceRoot":"","sources":["../../../src/routing/libp2p.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAsB,MAAM,iBAAiB,CAAA;AAczE,MAAM,OAAO,oBAAoB;IACd,cAAc,CAAgB;IAE/C,YAAa,UAA0C;QACrD,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,MAAM,CAAC,cAAc,CAAA;IACxD,CAAC;IAED,KAAK,CAAC,GAAG,CAAE,UAAsB,EAAE,eAA2B,EAAE,UAAsB,EAAE;QACtF,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,UAAU,EAAE,eAAe,EAAE,OAAO,CAAC,CAAA;QACrE,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAQ,2BAA2B,EAAE,GAAG,CAAC,CAAC,CAAA;QACxF,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CAAE,UAAsB,EAAE,UAAsB,EAAE;QACzD,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;QAC3D,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAQ,2BAA2B,EAAE,GAAG,CAAC,CAAC,CAAA;QACxF,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAA;IAC9B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAE,UAA0C;IAChE,OAAO,IAAI,oBAAoB,CAAC,UAAU,CAAC,CAAA;AAC7C,CAAC"}
|
package/src/routing/libp2p.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { CustomProgressEvent, type ProgressEvent } from 'progress-events'
|
|
2
|
-
import type { GetOptions, PutOptions } from './index.js'
|
|
3
|
-
import type { IPNSRouting } from '../index.js'
|
|
4
|
-
import type { ContentRouting } from '@libp2p/interface'
|
|
5
|
-
|
|
6
|
-
export interface Libp2pContentRoutingComponents {
|
|
7
|
-
libp2p: {
|
|
8
|
-
contentRouting: ContentRouting
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type Libp2pContentRoutingProgressEvents =
|
|
13
|
-
ProgressEvent<'ipns:routing:libp2p:error', Error>
|
|
14
|
-
|
|
15
|
-
export class Libp2pContentRouting implements IPNSRouting {
|
|
16
|
-
private readonly contentRouting: ContentRouting
|
|
17
|
-
|
|
18
|
-
constructor (components: Libp2pContentRoutingComponents) {
|
|
19
|
-
this.contentRouting = components.libp2p.contentRouting
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async put (routingKey: Uint8Array, marshaledRecord: Uint8Array, options: PutOptions = {}): Promise<void> {
|
|
23
|
-
try {
|
|
24
|
-
await this.contentRouting.put(routingKey, marshaledRecord, options)
|
|
25
|
-
} catch (err: any) {
|
|
26
|
-
options.onProgress?.(new CustomProgressEvent<Error>('ipns:routing:libp2p:error', err))
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async get (routingKey: Uint8Array, options: GetOptions = {}): Promise<Uint8Array> {
|
|
31
|
-
try {
|
|
32
|
-
return await this.contentRouting.get(routingKey, options)
|
|
33
|
-
} catch (err: any) {
|
|
34
|
-
options.onProgress?.(new CustomProgressEvent<Error>('ipns:routing:libp2p:error', err))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
throw new Error('Not found')
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The libp2p routing uses any available Content Routers configured on the
|
|
43
|
-
* passed libp2p node. This could be KadDHT, HTTP API Delegated Routing, etc.
|
|
44
|
-
*/
|
|
45
|
-
export function libp2p (components: Libp2pContentRoutingComponents): IPNSRouting {
|
|
46
|
-
return new Libp2pContentRouting(components)
|
|
47
|
-
}
|