@helia/ipns 3.0.0 → 4.0.0
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 +17 -23
- package/dist/index.min.js +24 -24
- package/dist/src/index.d.ts +14 -13
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +13 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/routing/index.d.ts +3 -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/libp2p.d.ts +22 -0
- package/dist/src/routing/libp2p.d.ts.map +1 -0
- package/dist/src/routing/{dht.js → libp2p.js} +10 -6
- package/dist/src/routing/libp2p.js.map +1 -0
- 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/dist/typedoc-urls.json +3 -1
- package/package.json +22 -17
- package/src/index.ts +15 -14
- package/src/routing/index.ts +3 -3
- package/src/routing/{dht.ts → libp2p.ts} +14 -10
- 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.map +0 -1
package/src/index.ts
CHANGED
|
@@ -3,26 +3,27 @@
|
|
|
3
3
|
*
|
|
4
4
|
* IPNS operations using a Helia node
|
|
5
5
|
*
|
|
6
|
-
* @example
|
|
6
|
+
* @example Using libp2p and pubsub routers
|
|
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 { libp2p, pubsub } from '@helia/ipns/routing'
|
|
13
14
|
* import { unixfs } from '@helia/unixfs'
|
|
14
15
|
*
|
|
15
16
|
* const helia = await createHelia()
|
|
16
17
|
* const name = ipns(helia, {
|
|
17
18
|
* routers: [
|
|
18
|
-
*
|
|
19
|
+
* libp2p(helia),
|
|
19
20
|
* pubsub(helia)
|
|
20
21
|
* ]
|
|
21
22
|
* })
|
|
22
23
|
*
|
|
23
24
|
* // 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)
|
|
25
|
+
* const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
|
|
26
|
+
* const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
|
|
26
27
|
*
|
|
27
28
|
* // store some data to publish
|
|
28
29
|
* const fs = unixfs(helia)
|
|
@@ -35,14 +36,15 @@
|
|
|
35
36
|
* const cid = name.resolve(peerId)
|
|
36
37
|
* ```
|
|
37
38
|
*
|
|
38
|
-
* @example
|
|
39
|
+
* @example Using custom DNS over HTTPS resolvers
|
|
39
40
|
*
|
|
40
41
|
* With default {@link DNSResolver} resolvers:
|
|
41
42
|
*
|
|
42
43
|
* ```typescript
|
|
43
44
|
* import { createHelia } from 'helia'
|
|
44
|
-
* import {
|
|
45
|
+
* import { ipns } from '@helia/ipns'
|
|
45
46
|
* import { unixfs } from '@helia/unixfs'
|
|
47
|
+
* import { dnsOverHttps } from '@helia/ipns/dns-resolvers'
|
|
46
48
|
*
|
|
47
49
|
* const helia = await createHelia()
|
|
48
50
|
* const name = ipns(helia, {
|
|
@@ -54,7 +56,7 @@
|
|
|
54
56
|
* const cid = name.resolveDns('some-domain-with-dnslink-entry.com')
|
|
55
57
|
* ```
|
|
56
58
|
*
|
|
57
|
-
* @example
|
|
59
|
+
* @example Resolving a domain with a dnslink entry
|
|
58
60
|
*
|
|
59
61
|
* Calling `resolveDns` with the `@helia/ipns` instance:
|
|
60
62
|
*
|
|
@@ -74,7 +76,7 @@
|
|
|
74
76
|
* // QmWebsite
|
|
75
77
|
* ```
|
|
76
78
|
*
|
|
77
|
-
* @example
|
|
79
|
+
* @example Using DNS-Over-HTTPS
|
|
78
80
|
*
|
|
79
81
|
* This example uses the Mozilla provided RFC 1035 DNS over HTTPS service. This
|
|
80
82
|
* uses binary DNS records so requires extra dependencies to process the
|
|
@@ -93,7 +95,7 @@
|
|
|
93
95
|
* })
|
|
94
96
|
* ```
|
|
95
97
|
*
|
|
96
|
-
* @example
|
|
98
|
+
* @example Using DNS-JSON-Over-HTTPS
|
|
97
99
|
*
|
|
98
100
|
* DNS-JSON-Over-HTTPS resolvers use the RFC 8427 `application/dns-json` and can
|
|
99
101
|
* result in a smaller browser bundle due to the response being plain JSON.
|
|
@@ -110,7 +112,7 @@
|
|
|
110
112
|
* ```
|
|
111
113
|
*/
|
|
112
114
|
|
|
113
|
-
import { CodeError } from '@libp2p/interface
|
|
115
|
+
import { CodeError } from '@libp2p/interface'
|
|
114
116
|
import { logger } from '@libp2p/logger'
|
|
115
117
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
116
118
|
import { create, marshal, peerIdToRoutingKey, unmarshal } from 'ipns'
|
|
@@ -122,8 +124,7 @@ import { defaultResolver } from './dns-resolvers/default.js'
|
|
|
122
124
|
import { localStore, type LocalStore } from './routing/local-store.js'
|
|
123
125
|
import type { IPNSRouting, IPNSRoutingEvents } from './routing/index.js'
|
|
124
126
|
import type { DNSResponse } from './utils/dns.js'
|
|
125
|
-
import type { AbortOptions } from '@libp2p/interface'
|
|
126
|
-
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
127
|
+
import type { AbortOptions, PeerId } from '@libp2p/interface'
|
|
127
128
|
import type { Datastore } from 'interface-datastore'
|
|
128
129
|
import type { IPNSRecord } from 'ipns'
|
|
129
130
|
import type { ProgressEvent, ProgressOptions } from 'progress-events'
|
|
@@ -223,7 +224,7 @@ export interface IPNS {
|
|
|
223
224
|
/**
|
|
224
225
|
* Creates an IPNS record signed by the passed PeerId that will resolve to the passed value
|
|
225
226
|
*
|
|
226
|
-
* If the
|
|
227
|
+
* If the value is a PeerId, a recursive IPNS record will be created.
|
|
227
228
|
*/
|
|
228
229
|
publish(key: PeerId, value: CID | PeerId, options?: PublishOptions): Promise<IPNSRecord>
|
|
229
230
|
|
package/src/routing/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Libp2pContentRoutingProgressEvents } from './libp2p.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'
|
|
@@ -19,8 +19,8 @@ export interface IPNSRouting {
|
|
|
19
19
|
|
|
20
20
|
export type IPNSRoutingEvents =
|
|
21
21
|
DatastoreProgressEvents |
|
|
22
|
-
|
|
22
|
+
Libp2pContentRoutingProgressEvents |
|
|
23
23
|
PubSubProgressEvents
|
|
24
24
|
|
|
25
|
-
export {
|
|
25
|
+
export { libp2p } from './libp2p.js'
|
|
26
26
|
export { pubsub } from './pubsub.js'
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { CustomProgressEvent, type ProgressEvent } from 'progress-events'
|
|
2
2
|
import type { GetOptions, PutOptions } from './index.js'
|
|
3
3
|
import type { IPNSRouting } from '../index.js'
|
|
4
|
-
import type { ContentRouting } from '@libp2p/interface
|
|
4
|
+
import type { ContentRouting } from '@libp2p/interface'
|
|
5
5
|
|
|
6
|
-
export interface
|
|
6
|
+
export interface Libp2pContentRoutingComponents {
|
|
7
7
|
libp2p: {
|
|
8
8
|
contentRouting: ContentRouting
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export type
|
|
13
|
-
ProgressEvent<'ipns:routing:
|
|
12
|
+
export type Libp2pContentRoutingProgressEvents =
|
|
13
|
+
ProgressEvent<'ipns:routing:libp2p:error', Error>
|
|
14
14
|
|
|
15
|
-
export class
|
|
15
|
+
export class Libp2pContentRouting implements IPNSRouting {
|
|
16
16
|
private readonly contentRouting: ContentRouting
|
|
17
17
|
|
|
18
|
-
constructor (components:
|
|
18
|
+
constructor (components: Libp2pContentRoutingComponents) {
|
|
19
19
|
this.contentRouting = components.libp2p.contentRouting
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -23,7 +23,7 @@ export class DHTRouting implements IPNSRouting {
|
|
|
23
23
|
try {
|
|
24
24
|
await this.contentRouting.put(routingKey, marshaledRecord, options)
|
|
25
25
|
} catch (err: any) {
|
|
26
|
-
options.onProgress?.(new CustomProgressEvent<Error>('ipns:routing:
|
|
26
|
+
options.onProgress?.(new CustomProgressEvent<Error>('ipns:routing:libp2p:error', err))
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -31,13 +31,17 @@ export class DHTRouting implements IPNSRouting {
|
|
|
31
31
|
try {
|
|
32
32
|
return await this.contentRouting.get(routingKey, options)
|
|
33
33
|
} catch (err: any) {
|
|
34
|
-
options.onProgress?.(new CustomProgressEvent<Error>('ipns:routing:
|
|
34
|
+
options.onProgress?.(new CustomProgressEvent<Error>('ipns:routing:libp2p:error', err))
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
throw new Error('Not found')
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
/**
|
|
42
|
+
* The libp2p routing uses any available Content Routers configured on the
|
|
43
|
+
* passed libp2p node. This could be KadDHT, HTTP API Delegated Routing, etc.
|
|
44
|
+
*/
|
|
45
|
+
export function libp2p (components: Libp2pContentRoutingComponents): IPNSRouting {
|
|
46
|
+
return new Libp2pContentRouting(components)
|
|
43
47
|
}
|
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,cA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