@helia/ipns 4.0.0-3f4c6bf → 4.0.0-4836d52
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 +69 -6
- 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 +9 -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 +8 -9
- package/src/index.ts +73 -6
- package/src/routing/helia.ts +45 -0
- package/src/routing/index.ts +9 -4
- 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;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,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
|
}
|
|
@@ -224,17 +266,38 @@ class DefaultIPNS {
|
|
|
224
266
|
];
|
|
225
267
|
}
|
|
226
268
|
const records = [];
|
|
269
|
+
let foundInvalid = 0;
|
|
227
270
|
await Promise.all(routers.map(async (router) => {
|
|
271
|
+
let record;
|
|
272
|
+
try {
|
|
273
|
+
record = await router.get(routingKey, {
|
|
274
|
+
...options,
|
|
275
|
+
validate: false
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
catch (err) {
|
|
279
|
+
if (router === this.localStore && err.code === 'ERR_NOT_FOUND') {
|
|
280
|
+
log('did not have record locally');
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
log.error('error finding IPNS record', err);
|
|
284
|
+
}
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
228
287
|
try {
|
|
229
|
-
const record = await router.get(routingKey, options);
|
|
230
288
|
await ipnsValidator(routingKey, record);
|
|
231
289
|
records.push(record);
|
|
232
290
|
}
|
|
233
291
|
catch (err) {
|
|
292
|
+
// we found a record, but the validator rejected it
|
|
293
|
+
foundInvalid++;
|
|
234
294
|
log.error('error finding IPNS record', err);
|
|
235
295
|
}
|
|
236
296
|
}));
|
|
237
297
|
if (records.length === 0) {
|
|
298
|
+
if (foundInvalid > 0) {
|
|
299
|
+
throw new CodeError(`${foundInvalid > 1 ? `${foundInvalid} records` : 'Record'} found for routing key ${foundInvalid > 1 ? 'were' : 'was'} invalid`, 'ERR_RECORDS_FAILED_VALIDATION');
|
|
300
|
+
}
|
|
238
301
|
throw new CodeError('Could not find record for routing key', 'ERR_NOT_FOUND');
|
|
239
302
|
}
|
|
240
303
|
const record = records[ipnsSelector(routingKey, records)];
|
|
@@ -242,7 +305,7 @@ class DefaultIPNS {
|
|
|
242
305
|
return unmarshal(record);
|
|
243
306
|
}
|
|
244
307
|
}
|
|
245
|
-
export function ipns(components, { routers = [], resolvers = [] }) {
|
|
308
|
+
export function ipns(components, { routers = [], resolvers = [] } = {}) {
|
|
246
309
|
return new DefaultIPNS(components, routers, resolvers);
|
|
247
310
|
}
|
|
248
311
|
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,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC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GAAG,YAAY,UAAU,CAAC,CAAC,CAAC,QAAQ,0BAA0B,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE,+BAA+B,CAAC,CAAA;YACvL,CAAC;YAED,MAAM,IAAI,SAAS,CAAC,uCAAuC,EAAE,eAAe,CAAC,CAAA;QAC/E,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;QAEzD,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;QAEtD,OAAO,SAAS,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,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';
|
|
@@ -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 |
|
|
15
|
-
export {
|
|
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,
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/routing/index.ts"],"names":[],"mappings":"
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/ipns",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-4836d52",
|
|
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,15 +164,16 @@
|
|
|
163
164
|
"release": "aegir release"
|
|
164
165
|
},
|
|
165
166
|
"dependencies": {
|
|
167
|
+
"@helia/interface": "3.0.1-4836d52",
|
|
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.
|
|
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.2.
|
|
174
|
-
"ipns": "^
|
|
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.
|
|
184
|
+
"@libp2p/peer-id-factory": "^4.0.5",
|
|
183
185
|
"@types/dns-packet": "^5.6.4",
|
|
184
186
|
"aegir": "^42.1.0",
|
|
185
|
-
"datastore-core": "^9.2.
|
|
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
|
}
|
|
@@ -376,21 +420,44 @@ class DefaultIPNS implements IPNS {
|
|
|
376
420
|
}
|
|
377
421
|
|
|
378
422
|
const records: Uint8Array[] = []
|
|
423
|
+
let foundInvalid = 0
|
|
379
424
|
|
|
380
425
|
await Promise.all(
|
|
381
426
|
routers.map(async (router) => {
|
|
427
|
+
let record: Uint8Array
|
|
428
|
+
|
|
429
|
+
try {
|
|
430
|
+
record = await router.get(routingKey, {
|
|
431
|
+
...options,
|
|
432
|
+
validate: false
|
|
433
|
+
})
|
|
434
|
+
} catch (err: any) {
|
|
435
|
+
if (router === this.localStore && err.code === 'ERR_NOT_FOUND') {
|
|
436
|
+
log('did not have record locally')
|
|
437
|
+
} else {
|
|
438
|
+
log.error('error finding IPNS record', err)
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return
|
|
442
|
+
}
|
|
443
|
+
|
|
382
444
|
try {
|
|
383
|
-
const record = await router.get(routingKey, options)
|
|
384
445
|
await ipnsValidator(routingKey, record)
|
|
385
446
|
|
|
386
447
|
records.push(record)
|
|
387
448
|
} catch (err) {
|
|
449
|
+
// we found a record, but the validator rejected it
|
|
450
|
+
foundInvalid++
|
|
388
451
|
log.error('error finding IPNS record', err)
|
|
389
452
|
}
|
|
390
453
|
})
|
|
391
454
|
)
|
|
392
455
|
|
|
393
456
|
if (records.length === 0) {
|
|
457
|
+
if (foundInvalid > 0) {
|
|
458
|
+
throw new CodeError(`${foundInvalid > 1 ? `${foundInvalid} records` : 'Record'} found for routing key ${foundInvalid > 1 ? 'were' : 'was'} invalid`, 'ERR_RECORDS_FAILED_VALIDATION')
|
|
459
|
+
}
|
|
460
|
+
|
|
394
461
|
throw new CodeError('Could not find record for routing key', 'ERR_NOT_FOUND')
|
|
395
462
|
}
|
|
396
463
|
|
|
@@ -407,7 +474,7 @@ export interface IPNSOptions {
|
|
|
407
474
|
resolvers?: DNSResolver[]
|
|
408
475
|
}
|
|
409
476
|
|
|
410
|
-
export function ipns (components: IPNSComponents, { routers = [], resolvers = [] }: IPNSOptions): IPNS {
|
|
477
|
+
export function ipns (components: IPNSComponents, { routers = [], resolvers = [] }: IPNSOptions = {}): IPNS {
|
|
411
478
|
return new DefaultIPNS(components, routers, resolvers)
|
|
412
479
|
}
|
|
413
480
|
|
|
@@ -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'
|
|
@@ -9,7 +9,12 @@ export interface PutOptions extends AbortOptions, ProgressOptions {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface GetOptions extends AbortOptions, ProgressOptions {
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Pass false to not perform validation actions
|
|
14
|
+
*
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
17
|
+
validate?: boolean
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
export interface IPNSRouting {
|
|
@@ -19,8 +24,8 @@ export interface IPNSRouting {
|
|
|
19
24
|
|
|
20
25
|
export type IPNSRoutingEvents =
|
|
21
26
|
DatastoreProgressEvents |
|
|
22
|
-
|
|
27
|
+
HeliaRoutingProgressEvents |
|
|
23
28
|
PubSubProgressEvents
|
|
24
29
|
|
|
25
|
-
export {
|
|
30
|
+
export { helia } from './helia.js'
|
|
26
31
|
export { pubsub } from './pubsub.js'
|