@helia/ipns 3.0.1 → 4.0.0-031519c

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/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "@helia/ipns",
3
- "version": "3.0.1",
3
+ "version": "4.0.0-031519c",
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/master/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
+ },
14
+ "publishConfig": {
15
+ "access": "public",
16
+ "provenance": true
13
17
  },
14
18
  "keywords": [
15
19
  "IPFS"
@@ -43,13 +47,13 @@
43
47
  "types": "./dist/src/index.d.ts",
44
48
  "import": "./dist/src/index.js"
45
49
  },
46
- "./routing": {
47
- "types": "./dist/src/routing/index.d.ts",
48
- "import": "./dist/src/routing/index.js"
49
- },
50
50
  "./dns-resolvers": {
51
51
  "types": "./dist/src/dns-resolvers/index.d.ts",
52
52
  "import": "./dist/src/dns-resolvers/index.js"
53
+ },
54
+ "./routing": {
55
+ "types": "./dist/src/routing/index.d.ts",
56
+ "import": "./dist/src/routing/index.js"
53
57
  }
54
58
  },
55
59
  "eslintConfig": {
@@ -149,6 +153,7 @@
149
153
  "lint": "aegir lint",
150
154
  "dep-check": "aegir dep-check",
151
155
  "build": "aegir build",
156
+ "docs": "aegir docs",
152
157
  "test": "aegir test",
153
158
  "test:chrome": "aegir test -t browser --cov",
154
159
  "test:chrome-webworker": "aegir test -t webworker",
@@ -159,33 +164,31 @@
159
164
  "release": "aegir release"
160
165
  },
161
166
  "dependencies": {
162
- "@libp2p/kad-dht": "^10.0.11",
163
- "@libp2p/logger": "^3.0.2",
164
- "@libp2p/peer-id": "^3.0.2",
165
- "dns-over-http-resolver": "^2.1.3",
167
+ "@helia/interface": "3.0.1-031519c",
168
+ "@libp2p/interface": "^1.1.1",
169
+ "@libp2p/kad-dht": "^12.0.2",
170
+ "@libp2p/logger": "^4.0.4",
171
+ "@libp2p/peer-id": "^4.0.5",
172
+ "dns-over-http-resolver": "^3.0.0",
166
173
  "dns-packet": "^5.6.0",
167
174
  "hashlru": "^2.3.0",
168
- "interface-datastore": "^8.0.0",
169
- "ipns": "^7.0.1",
175
+ "interface-datastore": "^8.2.9",
176
+ "ipns": "^9.0.0",
170
177
  "is-ipfs": "^8.0.1",
171
- "multiformats": "^12.0.1",
172
- "p-queue": "^7.3.0",
178
+ "multiformats": "^13.0.0",
179
+ "p-queue": "^8.0.1",
173
180
  "progress-events": "^1.0.0",
174
- "uint8arrays": "^4.0.3"
181
+ "uint8arrays": "^5.0.1"
175
182
  },
176
183
  "devDependencies": {
177
- "@libp2p/interface": "^0.1.4",
178
- "@libp2p/peer-id-factory": "^3.0.3",
184
+ "@libp2p/peer-id-factory": "^4.0.5",
179
185
  "@types/dns-packet": "^5.6.4",
180
- "aegir": "^41.1.14",
181
- "datastore-core": "^9.0.3",
182
- "sinon": "^17.0.0",
183
- "sinon-ts": "^1.0.0"
186
+ "aegir": "^42.1.0",
187
+ "datastore-core": "^9.2.7",
188
+ "sinon": "^17.0.1",
189
+ "sinon-ts": "^2.0.0"
184
190
  },
185
191
  "browser": {
186
192
  "./dist/src/dns-resolvers/resolver.js": "./dist/src/dns-resolvers/resolver.browser.js"
187
- },
188
- "typedoc": {
189
- "entryPoint": "./src/index.ts"
190
193
  }
191
194
  }
package/src/index.ts CHANGED
@@ -3,27 +3,65 @@
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 { dht, pubsub } from '@helia/ipns/routing'
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
- * dht(helia),
20
58
  * pubsub(helia)
21
59
  * ]
22
60
  * })
23
61
  *
24
62
  * // create a public key to publish as an IPNS name
25
- * const keyInfo = await helia.libp2p.keychain.createKey('my-key')
26
- * const peerId = await helia.libp2p.keychain.exportPeerId(keyInfo.name)
63
+ * const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
64
+ * const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
27
65
  *
28
66
  * // store some data to publish
29
67
  * const fs = unixfs(helia)
@@ -36,7 +74,7 @@
36
74
  * const cid = name.resolve(peerId)
37
75
  * ```
38
76
  *
39
- * @example
77
+ * @example Using custom DNS over HTTPS resolvers
40
78
  *
41
79
  * With default {@link DNSResolver} resolvers:
42
80
  *
@@ -56,7 +94,7 @@
56
94
  * const cid = name.resolveDns('some-domain-with-dnslink-entry.com')
57
95
  * ```
58
96
  *
59
- * @example
97
+ * @example Resolving a domain with a dnslink entry
60
98
  *
61
99
  * Calling `resolveDns` with the `@helia/ipns` instance:
62
100
  *
@@ -76,7 +114,7 @@
76
114
  * // QmWebsite
77
115
  * ```
78
116
  *
79
- * @example
117
+ * @example Using DNS-Over-HTTPS
80
118
  *
81
119
  * This example uses the Mozilla provided RFC 1035 DNS over HTTPS service. This
82
120
  * uses binary DNS records so requires extra dependencies to process the
@@ -95,7 +133,7 @@
95
133
  * })
96
134
  * ```
97
135
  *
98
- * @example
136
+ * @example Using DNS-JSON-Over-HTTPS
99
137
  *
100
138
  * DNS-JSON-Over-HTTPS resolvers use the RFC 8427 `application/dns-json` and can
101
139
  * result in a smaller browser bundle due to the response being plain JSON.
@@ -112,7 +150,7 @@
112
150
  * ```
113
151
  */
114
152
 
115
- import { CodeError } from '@libp2p/interface/errors'
153
+ import { CodeError } from '@libp2p/interface'
116
154
  import { logger } from '@libp2p/logger'
117
155
  import { peerIdFromString } from '@libp2p/peer-id'
118
156
  import { create, marshal, peerIdToRoutingKey, unmarshal } from 'ipns'
@@ -121,11 +159,12 @@ 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'
127
- import type { AbortOptions } from '@libp2p/interface'
128
- import type { PeerId } from '@libp2p/interface/peer-id'
166
+ import type { Routing } from '@helia/interface'
167
+ import type { AbortOptions, PeerId } from '@libp2p/interface'
129
168
  import type { Datastore } from 'interface-datastore'
130
169
  import type { IPNSRecord } from 'ipns'
131
170
  import type { ProgressEvent, ProgressOptions } from 'progress-events'
@@ -250,6 +289,7 @@ export type { IPNSRouting } from './routing/index.js'
250
289
 
251
290
  export interface IPNSComponents {
252
291
  datastore: Datastore
292
+ routing: Routing
253
293
  }
254
294
 
255
295
  class DefaultIPNS implements IPNS {
@@ -259,7 +299,10 @@ class DefaultIPNS implements IPNS {
259
299
  private readonly defaultResolvers: DNSResolver[]
260
300
 
261
301
  constructor (components: IPNSComponents, routers: IPNSRouting[] = [], resolvers: DNSResolver[] = []) {
262
- this.routers = routers
302
+ this.routers = [
303
+ helia(components.routing),
304
+ ...routers
305
+ ]
263
306
  this.localStore = localStore(components.datastore)
264
307
  this.defaultResolvers = resolvers.length > 0 ? resolvers : [defaultResolver()]
265
308
  }
@@ -377,21 +420,44 @@ class DefaultIPNS implements IPNS {
377
420
  }
378
421
 
379
422
  const records: Uint8Array[] = []
423
+ let foundInvalid = 0
380
424
 
381
425
  await Promise.all(
382
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
+
383
444
  try {
384
- const record = await router.get(routingKey, options)
385
445
  await ipnsValidator(routingKey, record)
386
446
 
387
447
  records.push(record)
388
448
  } catch (err) {
449
+ // we found a record, but the validator rejected it
450
+ foundInvalid++
389
451
  log.error('error finding IPNS record', err)
390
452
  }
391
453
  })
392
454
  )
393
455
 
394
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
+
395
461
  throw new CodeError('Could not find record for routing key', 'ERR_NOT_FOUND')
396
462
  }
397
463
 
@@ -408,7 +474,7 @@ export interface IPNSOptions {
408
474
  resolvers?: DNSResolver[]
409
475
  }
410
476
 
411
- export function ipns (components: IPNSComponents, { routers = [], resolvers = [] }: IPNSOptions): IPNS {
477
+ export function ipns (components: IPNSComponents, { routers = [], resolvers = [] }: IPNSOptions = {}): IPNS {
412
478
  return new DefaultIPNS(components, routers, resolvers)
413
479
  }
414
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
+ }
@@ -1,4 +1,4 @@
1
- import type { DHTProgressEvents } from './dht.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'
@@ -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
- DHTProgressEvents |
27
+ HeliaRoutingProgressEvents |
23
28
  PubSubProgressEvents
24
29
 
25
- export { dht } from './dht.js'
30
+ export { helia } from './helia.js'
26
31
  export { pubsub } from './pubsub.js'
@@ -1,4 +1,4 @@
1
- import { CodeError } from '@libp2p/interface/errors'
1
+ import { CodeError } from '@libp2p/interface'
2
2
  import { logger } from '@libp2p/logger'
3
3
  import { peerIdToRoutingKey } from 'ipns'
4
4
  import { ipnsSelector } from 'ipns/selector'
@@ -9,8 +9,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
9
9
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
10
10
  import { localStore, type LocalStore } from './local-store.js'
11
11
  import type { GetOptions, IPNSRouting, PutOptions } from './index.js'
12
- import type { PeerId } from '@libp2p/interface/peer-id'
13
- import type { Message, PublishResult, PubSub } from '@libp2p/interface/pubsub'
12
+ import type { PeerId, Message, PublishResult, PubSub } from '@libp2p/interface'
14
13
  import type { Datastore } from 'interface-datastore'
15
14
 
16
15
  const log = logger('helia:ipns:routing:pubsub')
@@ -30,14 +29,6 @@ export type PubSubProgressEvents =
30
29
  ProgressEvent<'ipns:pubsub:subscribe', { topic: string }> |
31
30
  ProgressEvent<'ipns:pubsub:error', Error>
32
31
 
33
- /**
34
- * This IPNS routing receives IPNS record updates via dedicated
35
- * pubsub topic.
36
- *
37
- * Note we must first be subscribed to the topic in order to receive
38
- * updated records, so the first call to `.get` should be expected
39
- * to fail!
40
- */
41
32
  class PubSubRouting implements IPNSRouting {
42
33
  private subscriptions: string[]
43
34
  private readonly localStore: LocalStore
@@ -192,6 +183,14 @@ function topicToKey (topic: string): Uint8Array {
192
183
  return uint8ArrayFromString(key, 'base64url')
193
184
  }
194
185
 
186
+ /**
187
+ * This IPNS routing receives IPNS record updates via dedicated
188
+ * pubsub topic.
189
+ *
190
+ * Note we must first be subscribed to the topic in order to receive
191
+ * updated records, so the first call to `.get` should be expected
192
+ * to fail!
193
+ */
195
194
  export function pubsub (components: PubsubRoutingComponents): IPNSRouting {
196
195
  return new PubSubRouting(components)
197
196
  }
package/src/utils/dns.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CodeError } from '@libp2p/interface/errors'
1
+ import { CodeError } from '@libp2p/interface'
2
2
  import * as isIPFS from 'is-ipfs'
3
3
  import type { DNSResolver, ResolveDnsLinkOptions } from '../index.js'
4
4
 
@@ -1,18 +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/content-routing';
5
- export interface DHTRoutingComponents {
6
- libp2p: {
7
- contentRouting: ContentRouting;
8
- };
9
- }
10
- export type DHTProgressEvents = ProgressEvent<'ipns:routing:dht:error', Error>;
11
- export declare class DHTRouting implements IPNSRouting {
12
- private readonly contentRouting;
13
- constructor(components: DHTRoutingComponents);
14
- put(routingKey: Uint8Array, marshaledRecord: Uint8Array, options?: PutOptions): Promise<void>;
15
- get(routingKey: Uint8Array, options?: GetOptions): Promise<Uint8Array>;
16
- }
17
- export declare function dht(components: DHTRoutingComponents): IPNSRouting;
18
- //# sourceMappingURL=dht.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dht.d.ts","sourceRoot":"","sources":["../../../src/routing/dht.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,mCAAmC,CAAA;AAEvE,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE;QACN,cAAc,EAAE,cAAc,CAAA;KAC/B,CAAA;CACF;AAED,MAAM,MAAM,iBAAiB,GAC3B,aAAa,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAA;AAEhD,qBAAa,UAAW,YAAW,WAAW;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgB;gBAElC,UAAU,EAAE,oBAAoB;IAIvC,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,wBAAgB,GAAG,CAAE,UAAU,EAAE,oBAAoB,GAAG,WAAW,CAElE"}
@@ -1,28 +0,0 @@
1
- import { CustomProgressEvent } from 'progress-events';
2
- export class DHTRouting {
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:dht: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:dht:error', err));
21
- }
22
- throw new Error('Not found');
23
- }
24
- }
25
- export function dht(components) {
26
- return new DHTRouting(components);
27
- }
28
- //# sourceMappingURL=dht.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dht.js","sourceRoot":"","sources":["../../../src/routing/dht.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAsB,MAAM,iBAAiB,CAAA;AAczE,MAAM,OAAO,UAAU;IACJ,cAAc,CAAgB;IAE/C,YAAa,UAAgC;QAC3C,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,wBAAwB,EAAE,GAAG,CAAC,CAAC,CAAA;QACrF,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,wBAAwB,EAAE,GAAG,CAAC,CAAC,CAAA;QACrF,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAA;IAC9B,CAAC;CACF;AAED,MAAM,UAAU,GAAG,CAAE,UAAgC;IACnD,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,CAAA;AACnC,CAAC"}
@@ -1,40 +0,0 @@
1
- {
2
- "DNSResolver": "https://ipfs.github.io/helia-ipns/interfaces/index.DNSResolver.html",
3
- ".:DNSResolver": "https://ipfs.github.io/helia-ipns/interfaces/index.DNSResolver.html",
4
- "IPNS": "https://ipfs.github.io/helia-ipns/interfaces/index.IPNS.html",
5
- ".:IPNS": "https://ipfs.github.io/helia-ipns/interfaces/index.IPNS.html",
6
- "IPNSComponents": "https://ipfs.github.io/helia-ipns/interfaces/index.IPNSComponents.html",
7
- ".:IPNSComponents": "https://ipfs.github.io/helia-ipns/interfaces/index.IPNSComponents.html",
8
- "IPNSOptions": "https://ipfs.github.io/helia-ipns/interfaces/index.IPNSOptions.html",
9
- ".:IPNSOptions": "https://ipfs.github.io/helia-ipns/interfaces/index.IPNSOptions.html",
10
- "PublishOptions": "https://ipfs.github.io/helia-ipns/interfaces/index.PublishOptions.html",
11
- ".:PublishOptions": "https://ipfs.github.io/helia-ipns/interfaces/index.PublishOptions.html",
12
- "RepublishOptions": "https://ipfs.github.io/helia-ipns/interfaces/index.RepublishOptions.html",
13
- ".:RepublishOptions": "https://ipfs.github.io/helia-ipns/interfaces/index.RepublishOptions.html",
14
- "ResolveDNSOptions": "https://ipfs.github.io/helia-ipns/interfaces/index.ResolveDNSOptions.html",
15
- ".:ResolveDNSOptions": "https://ipfs.github.io/helia-ipns/interfaces/index.ResolveDNSOptions.html",
16
- "ResolveDnsLinkOptions": "https://ipfs.github.io/helia-ipns/interfaces/index.ResolveDnsLinkOptions.html",
17
- ".:ResolveDnsLinkOptions": "https://ipfs.github.io/helia-ipns/interfaces/index.ResolveDnsLinkOptions.html",
18
- "ResolveOptions": "https://ipfs.github.io/helia-ipns/interfaces/index.ResolveOptions.html",
19
- ".:ResolveOptions": "https://ipfs.github.io/helia-ipns/interfaces/index.ResolveOptions.html",
20
- "PublishProgressEvents": "https://ipfs.github.io/helia-ipns/types/index.PublishProgressEvents.html",
21
- ".:PublishProgressEvents": "https://ipfs.github.io/helia-ipns/types/index.PublishProgressEvents.html",
22
- "RepublishProgressEvents": "https://ipfs.github.io/helia-ipns/types/index.RepublishProgressEvents.html",
23
- ".:RepublishProgressEvents": "https://ipfs.github.io/helia-ipns/types/index.RepublishProgressEvents.html",
24
- "ResolveDnsLinkProgressEvents": "https://ipfs.github.io/helia-ipns/types/index.ResolveDnsLinkProgressEvents.html",
25
- ".:ResolveDnsLinkProgressEvents": "https://ipfs.github.io/helia-ipns/types/index.ResolveDnsLinkProgressEvents.html",
26
- "ResolveProgressEvents": "https://ipfs.github.io/helia-ipns/types/index.ResolveProgressEvents.html",
27
- ".:ResolveProgressEvents": "https://ipfs.github.io/helia-ipns/types/index.ResolveProgressEvents.html",
28
- "ipns": "https://ipfs.github.io/helia-ipns/functions/index.ipns-1.html",
29
- ".:ipns": "https://ipfs.github.io/helia-ipns/functions/index.ipns-1.html",
30
- "GetOptions": "https://ipfs.github.io/helia-ipns/interfaces/routing.GetOptions.html",
31
- "./routing:GetOptions": "https://ipfs.github.io/helia-ipns/interfaces/routing.GetOptions.html",
32
- "IPNSRouting": "https://ipfs.github.io/helia-ipns/interfaces/routing.IPNSRouting.html",
33
- "./routing:IPNSRouting": "https://ipfs.github.io/helia-ipns/interfaces/routing.IPNSRouting.html",
34
- "PutOptions": "https://ipfs.github.io/helia-ipns/interfaces/routing.PutOptions.html",
35
- "./routing:PutOptions": "https://ipfs.github.io/helia-ipns/interfaces/routing.PutOptions.html",
36
- "IPNSRoutingEvents": "https://ipfs.github.io/helia-ipns/types/routing.IPNSRoutingEvents.html",
37
- "./routing:IPNSRoutingEvents": "https://ipfs.github.io/helia-ipns/types/routing.IPNSRoutingEvents.html",
38
- "dht": "https://ipfs.github.io/helia-ipns/functions/routing.dht.html",
39
- "pubsub": "https://ipfs.github.io/helia-ipns/functions/routing.pubsub.html"
40
- }
@@ -1,43 +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/content-routing'
5
-
6
- export interface DHTRoutingComponents {
7
- libp2p: {
8
- contentRouting: ContentRouting
9
- }
10
- }
11
-
12
- export type DHTProgressEvents =
13
- ProgressEvent<'ipns:routing:dht:error', Error>
14
-
15
- export class DHTRouting implements IPNSRouting {
16
- private readonly contentRouting: ContentRouting
17
-
18
- constructor (components: DHTRoutingComponents) {
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:dht: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:dht:error', err))
35
- }
36
-
37
- throw new Error('Not found')
38
- }
39
- }
40
-
41
- export function dht (components: DHTRoutingComponents): IPNSRouting {
42
- return new DHTRouting(components)
43
- }