@helia/ipns 3.0.0 → 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/README.md +59 -27
- package/dist/index.min.js +73 -26
- package/dist/src/index.d.ts +55 -14
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +79 -14
- 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/dist/src/routing/pubsub.d.ts +9 -2
- package/dist/src/routing/pubsub.d.ts.map +1 -1
- package/dist/src/routing/pubsub.js +9 -9
- package/dist/src/routing/pubsub.js.map +1 -1
- package/dist/src/utils/dns.js +1 -1
- package/dist/src/utils/dns.js.map +1 -1
- package/package.json +29 -25
- package/src/index.ts +85 -17
- package/src/routing/helia.ts +45 -0
- package/src/routing/index.ts +9 -4
- package/src/routing/pubsub.ts +10 -11
- package/src/utils/dns.ts +1 -1
- package/dist/src/routing/dht.d.ts +0 -18
- package/dist/src/routing/dht.d.ts.map +0 -1
- package/dist/src/routing/dht.js +0 -28
- package/dist/src/routing/dht.js.map +0 -1
- package/dist/typedoc-urls.json +0 -40
- package/src/routing/dht.ts +0 -43
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/ipns",
|
|
3
|
-
"version": "
|
|
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
|
|
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
|
|
9
|
+
"url": "git+https://github.com/ipfs/helia.git"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/ipfs/helia
|
|
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,32 +164,31 @@
|
|
|
159
164
|
"release": "aegir release"
|
|
160
165
|
},
|
|
161
166
|
"dependencies": {
|
|
162
|
-
"@
|
|
163
|
-
"@libp2p/
|
|
164
|
-
"@libp2p/
|
|
165
|
-
"
|
|
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.
|
|
169
|
-
"ipns": "^
|
|
175
|
+
"interface-datastore": "^8.2.9",
|
|
176
|
+
"ipns": "^9.0.0",
|
|
170
177
|
"is-ipfs": "^8.0.1",
|
|
171
|
-
"multiformats": "^
|
|
172
|
-
"p-queue": "^
|
|
178
|
+
"multiformats": "^13.0.0",
|
|
179
|
+
"p-queue": "^8.0.1",
|
|
173
180
|
"progress-events": "^1.0.0",
|
|
174
|
-
"uint8arrays": "^
|
|
181
|
+
"uint8arrays": "^5.0.1"
|
|
175
182
|
},
|
|
176
183
|
"devDependencies": {
|
|
177
|
-
"@libp2p/
|
|
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
|
-
"
|
|
181
|
-
"
|
|
182
|
-
"sinon
|
|
186
|
+
"aegir": "^42.1.0",
|
|
187
|
+
"datastore-core": "^9.2.7",
|
|
188
|
+
"sinon": "^17.0.1",
|
|
189
|
+
"sinon-ts": "^2.0.0"
|
|
183
190
|
},
|
|
184
191
|
"browser": {
|
|
185
192
|
"./dist/src/dns-resolvers/resolver.js": "./dist/src/dns-resolvers/resolver.browser.js"
|
|
186
|
-
},
|
|
187
|
-
"typedoc": {
|
|
188
|
-
"entryPoint": "./src/index.ts"
|
|
189
193
|
}
|
|
190
194
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,26 +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
|
-
* import {
|
|
12
|
+
* import { ipns } from '@helia/ipns'
|
|
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'
|
|
13
53
|
* import { unixfs } from '@helia/unixfs'
|
|
14
54
|
*
|
|
15
55
|
* const helia = await createHelia()
|
|
16
56
|
* const name = ipns(helia, {
|
|
17
57
|
* routers: [
|
|
18
|
-
* dht(helia),
|
|
19
58
|
* pubsub(helia)
|
|
20
59
|
* ]
|
|
21
60
|
* })
|
|
22
61
|
*
|
|
23
62
|
* // create a public key to publish as an IPNS name
|
|
24
|
-
* const keyInfo = await helia.libp2p.keychain.createKey('my-key')
|
|
25
|
-
* 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)
|
|
26
65
|
*
|
|
27
66
|
* // store some data to publish
|
|
28
67
|
* const fs = unixfs(helia)
|
|
@@ -35,14 +74,15 @@
|
|
|
35
74
|
* const cid = name.resolve(peerId)
|
|
36
75
|
* ```
|
|
37
76
|
*
|
|
38
|
-
* @example
|
|
77
|
+
* @example Using custom DNS over HTTPS resolvers
|
|
39
78
|
*
|
|
40
79
|
* With default {@link DNSResolver} resolvers:
|
|
41
80
|
*
|
|
42
81
|
* ```typescript
|
|
43
82
|
* import { createHelia } from 'helia'
|
|
44
|
-
* import {
|
|
83
|
+
* import { ipns } from '@helia/ipns'
|
|
45
84
|
* import { unixfs } from '@helia/unixfs'
|
|
85
|
+
* import { dnsOverHttps } from '@helia/ipns/dns-resolvers'
|
|
46
86
|
*
|
|
47
87
|
* const helia = await createHelia()
|
|
48
88
|
* const name = ipns(helia, {
|
|
@@ -54,7 +94,7 @@
|
|
|
54
94
|
* const cid = name.resolveDns('some-domain-with-dnslink-entry.com')
|
|
55
95
|
* ```
|
|
56
96
|
*
|
|
57
|
-
* @example
|
|
97
|
+
* @example Resolving a domain with a dnslink entry
|
|
58
98
|
*
|
|
59
99
|
* Calling `resolveDns` with the `@helia/ipns` instance:
|
|
60
100
|
*
|
|
@@ -74,7 +114,7 @@
|
|
|
74
114
|
* // QmWebsite
|
|
75
115
|
* ```
|
|
76
116
|
*
|
|
77
|
-
* @example
|
|
117
|
+
* @example Using DNS-Over-HTTPS
|
|
78
118
|
*
|
|
79
119
|
* This example uses the Mozilla provided RFC 1035 DNS over HTTPS service. This
|
|
80
120
|
* uses binary DNS records so requires extra dependencies to process the
|
|
@@ -93,7 +133,7 @@
|
|
|
93
133
|
* })
|
|
94
134
|
* ```
|
|
95
135
|
*
|
|
96
|
-
* @example
|
|
136
|
+
* @example Using DNS-JSON-Over-HTTPS
|
|
97
137
|
*
|
|
98
138
|
* DNS-JSON-Over-HTTPS resolvers use the RFC 8427 `application/dns-json` and can
|
|
99
139
|
* result in a smaller browser bundle due to the response being plain JSON.
|
|
@@ -110,7 +150,7 @@
|
|
|
110
150
|
* ```
|
|
111
151
|
*/
|
|
112
152
|
|
|
113
|
-
import { CodeError } from '@libp2p/interface
|
|
153
|
+
import { CodeError } from '@libp2p/interface'
|
|
114
154
|
import { logger } from '@libp2p/logger'
|
|
115
155
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
116
156
|
import { create, marshal, peerIdToRoutingKey, unmarshal } from 'ipns'
|
|
@@ -119,11 +159,12 @@ import { ipnsValidator } from 'ipns/validator'
|
|
|
119
159
|
import { CID } from 'multiformats/cid'
|
|
120
160
|
import { CustomProgressEvent } from 'progress-events'
|
|
121
161
|
import { defaultResolver } from './dns-resolvers/default.js'
|
|
162
|
+
import { helia } from './routing/helia.js'
|
|
122
163
|
import { localStore, type LocalStore } from './routing/local-store.js'
|
|
123
164
|
import type { IPNSRouting, IPNSRoutingEvents } from './routing/index.js'
|
|
124
165
|
import type { DNSResponse } from './utils/dns.js'
|
|
125
|
-
import type {
|
|
126
|
-
import type { PeerId } from '@libp2p/interface
|
|
166
|
+
import type { Routing } from '@helia/interface'
|
|
167
|
+
import type { AbortOptions, PeerId } from '@libp2p/interface'
|
|
127
168
|
import type { Datastore } from 'interface-datastore'
|
|
128
169
|
import type { IPNSRecord } from 'ipns'
|
|
129
170
|
import type { ProgressEvent, ProgressOptions } from 'progress-events'
|
|
@@ -223,7 +264,7 @@ export interface IPNS {
|
|
|
223
264
|
/**
|
|
224
265
|
* Creates an IPNS record signed by the passed PeerId that will resolve to the passed value
|
|
225
266
|
*
|
|
226
|
-
* If the
|
|
267
|
+
* If the value is a PeerId, a recursive IPNS record will be created.
|
|
227
268
|
*/
|
|
228
269
|
publish(key: PeerId, value: CID | PeerId, options?: PublishOptions): Promise<IPNSRecord>
|
|
229
270
|
|
|
@@ -248,6 +289,7 @@ export type { IPNSRouting } from './routing/index.js'
|
|
|
248
289
|
|
|
249
290
|
export interface IPNSComponents {
|
|
250
291
|
datastore: Datastore
|
|
292
|
+
routing: Routing
|
|
251
293
|
}
|
|
252
294
|
|
|
253
295
|
class DefaultIPNS implements IPNS {
|
|
@@ -257,7 +299,10 @@ class DefaultIPNS implements IPNS {
|
|
|
257
299
|
private readonly defaultResolvers: DNSResolver[]
|
|
258
300
|
|
|
259
301
|
constructor (components: IPNSComponents, routers: IPNSRouting[] = [], resolvers: DNSResolver[] = []) {
|
|
260
|
-
this.routers =
|
|
302
|
+
this.routers = [
|
|
303
|
+
helia(components.routing),
|
|
304
|
+
...routers
|
|
305
|
+
]
|
|
261
306
|
this.localStore = localStore(components.datastore)
|
|
262
307
|
this.defaultResolvers = resolvers.length > 0 ? resolvers : [defaultResolver()]
|
|
263
308
|
}
|
|
@@ -375,21 +420,44 @@ class DefaultIPNS implements IPNS {
|
|
|
375
420
|
}
|
|
376
421
|
|
|
377
422
|
const records: Uint8Array[] = []
|
|
423
|
+
let foundInvalid = 0
|
|
378
424
|
|
|
379
425
|
await Promise.all(
|
|
380
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
|
+
|
|
381
444
|
try {
|
|
382
|
-
const record = await router.get(routingKey, options)
|
|
383
445
|
await ipnsValidator(routingKey, record)
|
|
384
446
|
|
|
385
447
|
records.push(record)
|
|
386
448
|
} catch (err) {
|
|
449
|
+
// we found a record, but the validator rejected it
|
|
450
|
+
foundInvalid++
|
|
387
451
|
log.error('error finding IPNS record', err)
|
|
388
452
|
}
|
|
389
453
|
})
|
|
390
454
|
)
|
|
391
455
|
|
|
392
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
|
+
|
|
393
461
|
throw new CodeError('Could not find record for routing key', 'ERR_NOT_FOUND')
|
|
394
462
|
}
|
|
395
463
|
|
|
@@ -406,7 +474,7 @@ export interface IPNSOptions {
|
|
|
406
474
|
resolvers?: DNSResolver[]
|
|
407
475
|
}
|
|
408
476
|
|
|
409
|
-
export function ipns (components: IPNSComponents, { routers = [], resolvers = [] }: IPNSOptions): IPNS {
|
|
477
|
+
export function ipns (components: IPNSComponents, { routers = [], resolvers = [] }: IPNSOptions = {}): IPNS {
|
|
410
478
|
return new DefaultIPNS(components, routers, resolvers)
|
|
411
479
|
}
|
|
412
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'
|
package/src/routing/pubsub.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CodeError } from '@libp2p/interface
|
|
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
|
|
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,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"}
|
package/dist/src/routing/dht.js
DELETED
|
@@ -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"}
|
package/dist/typedoc-urls.json
DELETED
|
@@ -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
|
-
}
|
package/src/routing/dht.ts
DELETED
|
@@ -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
|
-
}
|