@helia/ipns 4.0.0 → 5.0.0-e554493

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.
@@ -3,20 +3,64 @@
3
3
  *
4
4
  * IPNS operations using a Helia node
5
5
  *
6
- * @example Using libp2p and pubsub routers
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 { libp2p, pubsub } from '@helia/ipns/routing'
14
13
  * import { unixfs } from '@helia/unixfs'
15
14
  *
16
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, libp2pDefaults } from 'helia'
51
+ * import { ipns } from '@helia/ipns'
52
+ * import { pubsub } from '@helia/ipns/routing'
53
+ * import { unixfs } from '@helia/unixfs'
54
+ * import { gossipsub } from '@chainsafe/libp2p-gossipsub'
55
+ *
56
+ * const libp2pOptions = libp2pDefaults()
57
+ * libp2pOptions.services.pubsub = gossipsub()
58
+ *
59
+ * const helia = await createHelia({
60
+ * libp2p: libp2pOptions
61
+ * })
17
62
  * const name = ipns(helia, {
18
63
  * routers: [
19
- * libp2p(helia),
20
64
  * pubsub(helia)
21
65
  * ]
22
66
  * })
@@ -115,6 +159,7 @@ import { ipnsValidator } from 'ipns/validator';
115
159
  import { CID } from 'multiformats/cid';
116
160
  import type { IPNSRouting, IPNSRoutingEvents } from './routing/index.js';
117
161
  import type { DNSResponse } from './utils/dns.js';
162
+ import type { Routing } from '@helia/interface';
118
163
  import type { AbortOptions, PeerId } from '@libp2p/interface';
119
164
  import type { Datastore } from 'interface-datastore';
120
165
  import type { IPNSRecord } from 'ipns';
@@ -203,12 +248,13 @@ export interface IPNS {
203
248
  export type { IPNSRouting } from './routing/index.js';
204
249
  export interface IPNSComponents {
205
250
  datastore: Datastore;
251
+ routing: Routing;
206
252
  }
207
253
  export interface IPNSOptions {
208
254
  routers?: IPNSRouting[];
209
255
  resolvers?: DNSResolver[];
210
256
  }
211
- export declare function ipns(components: IPNSComponents, { routers, resolvers }: IPNSOptions): IPNS;
212
- export { ipnsValidator };
257
+ export declare function ipns(components: IPNSComponents, { routers, resolvers }?: IPNSOptions): IPNS;
258
+ export { ipnsValidator, type IPNSRoutingEvents };
213
259
  export { ipnsSelector } from 'ipns/selector';
214
260
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgHG;AAOH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB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ED,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAA;IACpB,OAAO,EAAE,OAAO,CAAA;CACjB;AAmLD,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,KAAK,iBAAiB,EAAE,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA"}
package/dist/src/index.js CHANGED
@@ -3,20 +3,64 @@
3
3
  *
4
4
  * IPNS operations using a Helia node
5
5
  *
6
- * @example Using libp2p and pubsub routers
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 { libp2p, pubsub } from '@helia/ipns/routing'
14
13
  * import { unixfs } from '@helia/unixfs'
15
14
  *
16
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, libp2pDefaults } from 'helia'
51
+ * import { ipns } from '@helia/ipns'
52
+ * import { pubsub } from '@helia/ipns/routing'
53
+ * import { unixfs } from '@helia/unixfs'
54
+ * import { gossipsub } from '@chainsafe/libp2p-gossipsub'
55
+ *
56
+ * const libp2pOptions = libp2pDefaults()
57
+ * libp2pOptions.services.pubsub = gossipsub()
58
+ *
59
+ * const helia = await createHelia({
60
+ * libp2p: libp2pOptions
61
+ * })
17
62
  * const name = ipns(helia, {
18
63
  * routers: [
19
- * libp2p(helia),
20
64
  * pubsub(helia)
21
65
  * ]
22
66
  * })
@@ -120,6 +164,7 @@ import { ipnsValidator } from 'ipns/validator';
120
164
  import { CID } from 'multiformats/cid';
121
165
  import { CustomProgressEvent } from 'progress-events';
122
166
  import { defaultResolver } from './dns-resolvers/default.js';
167
+ import { helia } from './routing/helia.js';
123
168
  import { localStore } from './routing/local-store.js';
124
169
  const log = logger('helia:ipns');
125
170
  const MINUTE = 60 * 1000;
@@ -132,7 +177,10 @@ class DefaultIPNS {
132
177
  timeout;
133
178
  defaultResolvers;
134
179
  constructor(components, routers = [], resolvers = []) {
135
- this.routers = routers;
180
+ this.routers = [
181
+ helia(components.routing),
182
+ ...routers
183
+ ];
136
184
  this.localStore = localStore(components.datastore);
137
185
  this.defaultResolvers = resolvers.length > 0 ? resolvers : [defaultResolver()];
138
186
  }
@@ -224,17 +272,38 @@ class DefaultIPNS {
224
272
  ];
225
273
  }
226
274
  const records = [];
275
+ let foundInvalid = 0;
227
276
  await Promise.all(routers.map(async (router) => {
277
+ let record;
278
+ try {
279
+ record = await router.get(routingKey, {
280
+ ...options,
281
+ validate: false
282
+ });
283
+ }
284
+ catch (err) {
285
+ if (router === this.localStore && err.code === 'ERR_NOT_FOUND') {
286
+ log('did not have record locally');
287
+ }
288
+ else {
289
+ log.error('error finding IPNS record', err);
290
+ }
291
+ return;
292
+ }
228
293
  try {
229
- const record = await router.get(routingKey, options);
230
294
  await ipnsValidator(routingKey, record);
231
295
  records.push(record);
232
296
  }
233
297
  catch (err) {
298
+ // we found a record, but the validator rejected it
299
+ foundInvalid++;
234
300
  log.error('error finding IPNS record', err);
235
301
  }
236
302
  }));
237
303
  if (records.length === 0) {
304
+ if (foundInvalid > 0) {
305
+ throw new CodeError(`${foundInvalid > 1 ? `${foundInvalid} records` : 'Record'} found for routing key ${foundInvalid > 1 ? 'were' : 'was'} invalid`, 'ERR_RECORDS_FAILED_VALIDATION');
306
+ }
238
307
  throw new CodeError('Could not find record for routing key', 'ERR_NOT_FOUND');
239
308
  }
240
309
  const record = records[ipnsSelector(routingKey, records)];
@@ -242,7 +311,7 @@ class DefaultIPNS {
242
311
  return unmarshal(record);
243
312
  }
244
313
  }
245
- export function ipns(components, { routers = [], resolvers = [] }) {
314
+ export function ipns(components, { routers = [], resolvers = [] } = {}) {
246
315
  return new DefaultIPNS(components, routers, resolvers);
247
316
  }
248
317
  export { ipnsValidator };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgHG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA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,CAAC,MAAM,CAAC,CAAA;IAC1B,CAAC;CACF;AAOD,MAAM,UAAU,IAAI,CAAE,UAA0B,EAAE,EAAE,OAAO,GAAG,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,EAA0B,CAAA;AAChD,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 { Libp2pContentRoutingProgressEvents } from './libp2p.js';
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';
@@ -6,12 +6,18 @@ import type { ProgressOptions } from 'progress-events';
6
6
  export interface PutOptions extends AbortOptions, ProgressOptions {
7
7
  }
8
8
  export interface GetOptions extends AbortOptions, ProgressOptions {
9
+ /**
10
+ * Pass false to not perform validation actions
11
+ *
12
+ * @default true
13
+ */
14
+ validate?: boolean;
9
15
  }
10
16
  export interface IPNSRouting {
11
17
  put(routingKey: Uint8Array, marshaledRecord: Uint8Array, options?: PutOptions): Promise<void>;
12
18
  get(routingKey: Uint8Array, options?: GetOptions): Promise<Uint8Array>;
13
19
  }
14
- export type IPNSRoutingEvents = DatastoreProgressEvents | Libp2pContentRoutingProgressEvents | PubSubProgressEvents;
15
- export { libp2p } from './libp2p.js';
20
+ export type IPNSRoutingEvents = DatastoreProgressEvents | HeliaRoutingProgressEvents | PubSubProgressEvents;
21
+ export { helia } from './helia.js';
16
22
  export { pubsub } from './pubsub.js';
17
23
  //# 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,kCAAkC,EAAE,MAAM,aAAa,CAAA;AACrE,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,kCAAkC,GAClC,oBAAoB,CAAA;AAEtB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
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;IAC/D;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;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,3 +1,3 @@
1
- export { libp2p } from './libp2p.js';
1
+ export { helia } from './helia.js';
2
2
  export { pubsub } from './pubsub.js';
3
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/routing/index.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/routing/index.ts"],"names":[],"mappings":"AA6BA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@helia/ipns",
3
- "version": "4.0.0",
3
+ "version": "5.0.0-e554493",
4
4
  "description": "An implementation of IPNS for Helia",
5
5
  "license": "Apache-2.0 OR MIT",
6
- "homepage": "https://github.com/ipfs/helia-ipns/tree/main/packages/ipns#readme",
6
+ "homepage": "https://github.com/ipfs/helia/tree/main/packages/ipns#readme",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/ipfs/helia-ipns.git"
9
+ "url": "git+https://github.com/ipfs/helia.git"
10
10
  },
11
11
  "bugs": {
12
- "url": "https://github.com/ipfs/helia-ipns/issues"
12
+ "url": "https://github.com/ipfs/helia/issues"
13
13
  },
14
14
  "publishConfig": {
15
15
  "access": "public",
@@ -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,15 +164,16 @@
163
164
  "release": "aegir release"
164
165
  },
165
166
  "dependencies": {
167
+ "@helia/interface": "4.0.0-e554493",
166
168
  "@libp2p/interface": "^1.1.1",
167
169
  "@libp2p/kad-dht": "^12.0.2",
168
170
  "@libp2p/logger": "^4.0.4",
169
- "@libp2p/peer-id": "^4.0.4",
171
+ "@libp2p/peer-id": "^4.0.5",
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.0.0",
174
- "ipns": "^8.0.0",
175
+ "interface-datastore": "^8.2.9",
176
+ "ipns": "^9.0.0",
175
177
  "is-ipfs": "^8.0.1",
176
178
  "multiformats": "^13.0.0",
177
179
  "p-queue": "^8.0.1",
@@ -179,17 +181,14 @@
179
181
  "uint8arrays": "^5.0.1"
180
182
  },
181
183
  "devDependencies": {
182
- "@libp2p/peer-id-factory": "^4.0.3",
184
+ "@libp2p/peer-id-factory": "^4.0.5",
183
185
  "@types/dns-packet": "^5.6.4",
184
- "aegir": "^42.0.1",
185
- "datastore-core": "^9.0.3",
186
- "sinon": "^17.0.0",
186
+ "aegir": "^42.1.0",
187
+ "datastore-core": "^9.2.7",
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,64 @@
3
3
  *
4
4
  * IPNS operations using a Helia node
5
5
  *
6
- * @example Using libp2p and pubsub routers
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 { libp2p, pubsub } from '@helia/ipns/routing'
14
13
  * import { unixfs } from '@helia/unixfs'
15
14
  *
16
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, libp2pDefaults } from 'helia'
51
+ * import { ipns } from '@helia/ipns'
52
+ * import { pubsub } from '@helia/ipns/routing'
53
+ * import { unixfs } from '@helia/unixfs'
54
+ * import { gossipsub } from '@chainsafe/libp2p-gossipsub'
55
+ *
56
+ * const libp2pOptions = libp2pDefaults()
57
+ * libp2pOptions.services.pubsub = gossipsub()
58
+ *
59
+ * const helia = await createHelia({
60
+ * libp2p: libp2pOptions
61
+ * })
17
62
  * const name = ipns(helia, {
18
63
  * routers: [
19
- * libp2p(helia),
20
64
  * pubsub(helia)
21
65
  * ]
22
66
  * })
@@ -121,9 +165,11 @@ import { ipnsValidator } from 'ipns/validator'
121
165
  import { CID } from 'multiformats/cid'
122
166
  import { CustomProgressEvent } from 'progress-events'
123
167
  import { defaultResolver } from './dns-resolvers/default.js'
168
+ import { helia } from './routing/helia.js'
124
169
  import { localStore, type LocalStore } from './routing/local-store.js'
125
170
  import type { IPNSRouting, IPNSRoutingEvents } from './routing/index.js'
126
171
  import type { DNSResponse } from './utils/dns.js'
172
+ import type { Routing } from '@helia/interface'
127
173
  import type { AbortOptions, PeerId } from '@libp2p/interface'
128
174
  import type { Datastore } from 'interface-datastore'
129
175
  import type { IPNSRecord } from 'ipns'
@@ -249,6 +295,7 @@ export type { IPNSRouting } from './routing/index.js'
249
295
 
250
296
  export interface IPNSComponents {
251
297
  datastore: Datastore
298
+ routing: Routing
252
299
  }
253
300
 
254
301
  class DefaultIPNS implements IPNS {
@@ -258,7 +305,10 @@ class DefaultIPNS implements IPNS {
258
305
  private readonly defaultResolvers: DNSResolver[]
259
306
 
260
307
  constructor (components: IPNSComponents, routers: IPNSRouting[] = [], resolvers: DNSResolver[] = []) {
261
- this.routers = routers
308
+ this.routers = [
309
+ helia(components.routing),
310
+ ...routers
311
+ ]
262
312
  this.localStore = localStore(components.datastore)
263
313
  this.defaultResolvers = resolvers.length > 0 ? resolvers : [defaultResolver()]
264
314
  }
@@ -376,21 +426,44 @@ class DefaultIPNS implements IPNS {
376
426
  }
377
427
 
378
428
  const records: Uint8Array[] = []
429
+ let foundInvalid = 0
379
430
 
380
431
  await Promise.all(
381
432
  routers.map(async (router) => {
433
+ let record: Uint8Array
434
+
435
+ try {
436
+ record = await router.get(routingKey, {
437
+ ...options,
438
+ validate: false
439
+ })
440
+ } catch (err: any) {
441
+ if (router === this.localStore && err.code === 'ERR_NOT_FOUND') {
442
+ log('did not have record locally')
443
+ } else {
444
+ log.error('error finding IPNS record', err)
445
+ }
446
+
447
+ return
448
+ }
449
+
382
450
  try {
383
- const record = await router.get(routingKey, options)
384
451
  await ipnsValidator(routingKey, record)
385
452
 
386
453
  records.push(record)
387
454
  } catch (err) {
455
+ // we found a record, but the validator rejected it
456
+ foundInvalid++
388
457
  log.error('error finding IPNS record', err)
389
458
  }
390
459
  })
391
460
  )
392
461
 
393
462
  if (records.length === 0) {
463
+ if (foundInvalid > 0) {
464
+ throw new CodeError(`${foundInvalid > 1 ? `${foundInvalid} records` : 'Record'} found for routing key ${foundInvalid > 1 ? 'were' : 'was'} invalid`, 'ERR_RECORDS_FAILED_VALIDATION')
465
+ }
466
+
394
467
  throw new CodeError('Could not find record for routing key', 'ERR_NOT_FOUND')
395
468
  }
396
469
 
@@ -407,9 +480,9 @@ export interface IPNSOptions {
407
480
  resolvers?: DNSResolver[]
408
481
  }
409
482
 
410
- export function ipns (components: IPNSComponents, { routers = [], resolvers = [] }: IPNSOptions): IPNS {
483
+ export function ipns (components: IPNSComponents, { routers = [], resolvers = [] }: IPNSOptions = {}): IPNS {
411
484
  return new DefaultIPNS(components, routers, resolvers)
412
485
  }
413
486
 
414
- export { ipnsValidator }
487
+ export { ipnsValidator, type IPNSRoutingEvents }
415
488
  export { ipnsSelector } from 'ipns/selector'
@@ -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
+ }