@helia/ipns 1.1.2 → 1.1.3
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/dist/index.min.js +10 -10
- package/dist/src/index.d.ts +5 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +49 -52
- package/dist/src/index.js.map +1 -1
- package/dist/src/routing/dht.d.ts +2 -2
- package/dist/src/routing/dht.d.ts.map +1 -1
- package/dist/src/routing/dht.js +1 -0
- package/dist/src/routing/dht.js.map +1 -1
- package/dist/src/routing/index.d.ts +2 -2
- package/dist/src/routing/index.d.ts.map +1 -1
- package/dist/src/routing/local-store.d.ts +3 -3
- package/dist/src/routing/local-store.d.ts.map +1 -1
- package/dist/src/routing/local-store.js +2 -2
- package/dist/src/routing/local-store.js.map +1 -1
- package/dist/src/routing/pubsub.d.ts +5 -3
- package/dist/src/routing/pubsub.d.ts.map +1 -1
- package/dist/src/routing/pubsub.js +39 -42
- package/dist/src/routing/pubsub.js.map +1 -1
- package/dist/src/utils/resolve-dns-link.browser.js +2 -2
- package/dist/src/utils/resolve-dns-link.browser.js.map +1 -1
- package/dist/src/utils/resolve-dns-link.d.ts.map +1 -1
- package/dist/src/utils/resolve-dns-link.js +2 -2
- package/dist/src/utils/resolve-dns-link.js.map +1 -1
- package/dist/src/utils/tlru.js +1 -0
- package/dist/src/utils/tlru.js.map +1 -1
- package/package.json +3 -4
- package/src/index.ts +15 -15
- package/src/routing/dht.ts +2 -2
- package/src/routing/index.ts +2 -2
- package/src/routing/local-store.ts +4 -4
- package/src/routing/pubsub.ts +12 -10
- package/src/utils/resolve-dns-link.browser.ts +2 -2
- package/src/utils/resolve-dns-link.ts +3 -3
package/src/index.ts
CHANGED
|
@@ -62,24 +62,24 @@
|
|
|
62
62
|
* ```
|
|
63
63
|
*/
|
|
64
64
|
|
|
65
|
-
import type
|
|
66
|
-
import {
|
|
65
|
+
import { isPeerId, type PeerId } from '@libp2p/interface-peer-id'
|
|
66
|
+
import { CodeError } from '@libp2p/interfaces/errors'
|
|
67
|
+
import { logger } from '@libp2p/logger'
|
|
68
|
+
import { peerIdFromString } from '@libp2p/peer-id'
|
|
67
69
|
import { create, marshal, peerIdToRoutingKey, unmarshal } from 'ipns'
|
|
68
|
-
import type { IPNSEntry } from 'ipns'
|
|
69
|
-
import type { IPNSRouting, IPNSRoutingEvents } from './routing/index.js'
|
|
70
|
-
import { ipnsValidator } from 'ipns/validator'
|
|
71
70
|
import { ipnsSelector } from 'ipns/selector'
|
|
71
|
+
import { ipnsValidator } from 'ipns/validator'
|
|
72
72
|
import { CID } from 'multiformats/cid'
|
|
73
|
-
import { resolveDnslink } from './utils/resolve-dns-link.js'
|
|
74
|
-
import { logger } from '@libp2p/logger'
|
|
75
|
-
import { peerIdFromString } from '@libp2p/peer-id'
|
|
76
|
-
import type { ProgressEvent, ProgressOptions } from 'progress-events'
|
|
77
73
|
import { CustomProgressEvent } from 'progress-events'
|
|
78
|
-
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
79
74
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
75
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
76
|
+
import { localStore, type LocalStore } from './routing/local-store.js'
|
|
77
|
+
import { resolveDnslink } from './utils/resolve-dns-link.js'
|
|
78
|
+
import type { IPNSRouting, IPNSRoutingEvents } from './routing/index.js'
|
|
79
|
+
import type { AbortOptions } from '@libp2p/interfaces'
|
|
80
80
|
import type { Datastore } from 'interface-datastore'
|
|
81
|
-
import {
|
|
82
|
-
import {
|
|
81
|
+
import type { IPNSEntry } from 'ipns'
|
|
82
|
+
import type { ProgressEvent, ProgressOptions } from 'progress-events'
|
|
83
83
|
|
|
84
84
|
const log = logger('helia:ipns')
|
|
85
85
|
|
|
@@ -223,13 +223,13 @@ class DefaultIPNS implements IPNS {
|
|
|
223
223
|
const record = await this.#findIpnsRecord(routingKey, options)
|
|
224
224
|
const str = uint8ArrayToString(record.value)
|
|
225
225
|
|
|
226
|
-
return
|
|
226
|
+
return this.#resolve(str, options)
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
async resolveDns (domain: string, options: ResolveDNSOptions = {}): Promise<CID> {
|
|
230
230
|
const dnslink = await resolveDnslink(domain, options)
|
|
231
231
|
|
|
232
|
-
return
|
|
232
|
+
return this.#resolve(dnslink, options)
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
republish (options: RepublishOptions = {}): void {
|
|
@@ -275,7 +275,7 @@ class DefaultIPNS implements IPNS {
|
|
|
275
275
|
const scheme = parts[1]
|
|
276
276
|
|
|
277
277
|
if (scheme === 'ipns') {
|
|
278
|
-
return
|
|
278
|
+
return this.resolve(peerIdFromString(parts[2]), options)
|
|
279
279
|
} else if (scheme === 'ipfs') {
|
|
280
280
|
return CID.parse(parts[2])
|
|
281
281
|
}
|
package/src/routing/dht.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { CustomProgressEvent, type ProgressEvent } from 'progress-events'
|
|
2
2
|
import type { GetOptions, PutOptions } from './index.js'
|
|
3
|
-
import {
|
|
3
|
+
import type { IPNSRouting } from '../index.js'
|
|
4
4
|
import type { ContentRouting } from '@libp2p/interface-content-routing'
|
|
5
5
|
|
|
6
6
|
export interface DHTRoutingComponents {
|
package/src/routing/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ProgressOptions } from 'progress-events'
|
|
2
|
-
import type { AbortOptions } from '@libp2p/interfaces'
|
|
3
1
|
import type { DHTProgressEvents } from './dht.js'
|
|
4
2
|
import type { DatastoreProgressEvents } from './local-store.js'
|
|
5
3
|
import type { PubSubProgressEvents } from './pubsub.js'
|
|
4
|
+
import type { AbortOptions } from '@libp2p/interfaces'
|
|
5
|
+
import type { ProgressOptions } from 'progress-events'
|
|
6
6
|
|
|
7
7
|
export interface PutOptions extends AbortOptions, ProgressOptions {
|
|
8
8
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CustomProgressEvent, ProgressEvent } from 'progress-events'
|
|
2
|
-
import type { AbortOptions } from '@libp2p/interfaces'
|
|
3
1
|
import { Libp2pRecord } from '@libp2p/record'
|
|
4
|
-
import { Datastore, Key } from 'interface-datastore'
|
|
2
|
+
import { type Datastore, Key } from 'interface-datastore'
|
|
3
|
+
import { CustomProgressEvent, type ProgressEvent } from 'progress-events'
|
|
5
4
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
6
5
|
import type { GetOptions, IPNSRouting, PutOptions } from '../routing'
|
|
6
|
+
import type { AbortOptions } from '@libp2p/interfaces'
|
|
7
7
|
|
|
8
8
|
function dhtRoutingKey (key: Uint8Array): Key {
|
|
9
9
|
return new Key('/dht/record/' + uint8ArrayToString(key, 'base32'), false)
|
|
@@ -57,7 +57,7 @@ export function localStore (datastore: Datastore): LocalStore {
|
|
|
57
57
|
},
|
|
58
58
|
async has (routingKey: Uint8Array, options: AbortOptions = {}): Promise<boolean> {
|
|
59
59
|
const key = dhtRoutingKey(routingKey)
|
|
60
|
-
return
|
|
60
|
+
return datastore.has(key, options)
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
package/src/routing/pubsub.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
import { CodeError } from '@libp2p/interfaces/errors'
|
|
2
|
+
import { logger } from '@libp2p/logger'
|
|
1
3
|
import { peerIdToRoutingKey } from 'ipns'
|
|
4
|
+
import { ipnsSelector } from 'ipns/selector'
|
|
5
|
+
import { ipnsValidator } from 'ipns/validator'
|
|
6
|
+
import { CustomProgressEvent, type ProgressEvent } from 'progress-events'
|
|
7
|
+
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
2
8
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
3
9
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
4
|
-
import {
|
|
10
|
+
import { localStore, type LocalStore } from './local-store.js'
|
|
11
|
+
import type { GetOptions, IPNSRouting, PutOptions } from './index.js'
|
|
5
12
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
6
13
|
import type { Message, PublishResult, PubSub } from '@libp2p/interface-pubsub'
|
|
7
14
|
import type { Datastore } from 'interface-datastore'
|
|
8
|
-
import type { GetOptions, IPNSRouting, PutOptions } from './index.js'
|
|
9
|
-
import { CodeError } from '@libp2p/interfaces/errors'
|
|
10
|
-
import { localStore, LocalStore } from './local-store.js'
|
|
11
|
-
import { ipnsValidator } from 'ipns/validator'
|
|
12
|
-
import { ipnsSelector } from 'ipns/selector'
|
|
13
|
-
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
14
|
-
import { CustomProgressEvent, ProgressEvent } from 'progress-events'
|
|
15
15
|
|
|
16
16
|
const log = logger('helia:ipns:routing:pubsub')
|
|
17
17
|
|
|
@@ -19,7 +19,9 @@ export interface PubsubRoutingComponents {
|
|
|
19
19
|
datastore: Datastore
|
|
20
20
|
libp2p: {
|
|
21
21
|
peerId: PeerId
|
|
22
|
-
|
|
22
|
+
services: {
|
|
23
|
+
pubsub: PubSub
|
|
24
|
+
}
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -46,7 +48,7 @@ class PubSubRouting implements IPNSRouting {
|
|
|
46
48
|
this.subscriptions = []
|
|
47
49
|
this.localStore = localStore(components.datastore)
|
|
48
50
|
this.peerId = components.libp2p.peerId
|
|
49
|
-
this.pubsub = components.libp2p.pubsub
|
|
51
|
+
this.pubsub = components.libp2p.services.pubsub
|
|
50
52
|
|
|
51
53
|
this.pubsub.addEventListener('message', (evt) => {
|
|
52
54
|
const message = evt.detail
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-env browser */
|
|
2
2
|
|
|
3
|
-
import { TLRU } from './tlru.js'
|
|
4
3
|
import PQueue from 'p-queue'
|
|
4
|
+
import { TLRU } from './tlru.js'
|
|
5
5
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
6
6
|
|
|
7
7
|
// Avoid sending multiple queries for the same hostname by caching results
|
|
@@ -57,5 +57,5 @@ export async function resolveDnslink (fqdn: string, opts: ResolveDnsLinkOptions
|
|
|
57
57
|
return ipfsPath(response)
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
return
|
|
60
|
+
return resolve(fqdn, opts)
|
|
61
61
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import dns from 'dns'
|
|
2
2
|
import { promisify } from 'util'
|
|
3
|
-
import type { AbortOptions } from '@libp2p/interfaces'
|
|
4
3
|
import * as isIPFS from 'is-ipfs'
|
|
4
|
+
import type { AbortOptions } from '@libp2p/interfaces'
|
|
5
5
|
|
|
6
6
|
const MAX_RECURSIVE_DEPTH = 32
|
|
7
7
|
|
|
8
8
|
export async function resolveDnslink (domain: string, options: AbortOptions = {}): Promise<string> {
|
|
9
|
-
return
|
|
9
|
+
return recursiveResolveDnslink(domain, MAX_RECURSIVE_DEPTH, options)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
async function recursiveResolveDnslink (domain: string, depth: number, options: AbortOptions = {}): Promise<string> {
|
|
@@ -44,7 +44,7 @@ async function recursiveResolveDnslink (domain: string, depth: number, options:
|
|
|
44
44
|
return result
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
return
|
|
47
|
+
return recursiveResolveDnslink(domainOrCID, depth - 1, options)
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
async function resolve (domain: string, options: AbortOptions = {}): Promise<string> {
|