@helia/ipns 8.2.3 → 8.2.4-172345df
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 +31 -135
- package/dist/index.min.js +10 -11
- package/dist/index.min.js.map +4 -4
- package/dist/src/constants.d.ts +17 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +19 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/errors.d.ts +0 -4
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +0 -7
- package/dist/src/errors.js.map +1 -1
- package/dist/src/index.d.ts +109 -201
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +34 -417
- package/dist/src/index.js.map +1 -1
- package/dist/src/ipns.d.ts +22 -0
- package/dist/src/ipns.d.ts.map +1 -0
- package/dist/src/ipns.js +339 -0
- package/dist/src/ipns.js.map +1 -0
- package/dist/src/local-store.d.ts +42 -0
- package/dist/src/local-store.d.ts.map +1 -0
- package/dist/src/local-store.js +119 -0
- package/dist/src/local-store.js.map +1 -0
- package/dist/src/pb/metadata.d.ts +12 -0
- package/dist/src/pb/metadata.d.ts.map +1 -0
- package/dist/src/pb/metadata.js +57 -0
- package/dist/src/pb/metadata.js.map +1 -0
- package/dist/src/routing/index.d.ts +4 -2
- package/dist/src/routing/index.d.ts.map +1 -1
- package/dist/src/routing/index.js.map +1 -1
- package/dist/src/routing/local-store.d.ts +4 -19
- package/dist/src/routing/local-store.d.ts.map +1 -1
- package/dist/src/routing/local-store.js +7 -62
- package/dist/src/routing/local-store.js.map +1 -1
- package/dist/src/routing/pubsub.d.ts +21 -1
- package/dist/src/routing/pubsub.d.ts.map +1 -1
- package/dist/src/routing/pubsub.js +2 -2
- package/dist/src/routing/pubsub.js.map +1 -1
- package/dist/src/utils.d.ts +24 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +56 -0
- package/dist/src/utils.js.map +1 -1
- package/package.json +21 -23
- package/src/constants.ts +24 -0
- package/src/errors.ts +0 -9
- package/src/index.ts +116 -545
- package/src/ipns.ts +400 -0
- package/src/local-store.ts +162 -0
- package/src/pb/metadata.proto +9 -0
- package/src/pb/metadata.ts +74 -0
- package/src/routing/index.ts +4 -3
- package/src/routing/local-store.ts +9 -87
- package/src/routing/pubsub.ts +28 -4
- package/src/utils.ts +70 -0
- package/dist/src/dnslink.d.ts +0 -9
- package/dist/src/dnslink.d.ts.map +0 -1
- package/dist/src/dnslink.js +0 -138
- package/dist/src/dnslink.js.map +0 -1
- package/dist/typedoc-urls.json +0 -48
- package/src/dnslink.ts +0 -163
package/dist/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
*
|
|
4
|
-
* IPNS operations using a Helia node
|
|
4
|
+
* [IPNS](https://docs.ipfs.tech/concepts/ipns/) operations using a Helia node
|
|
5
5
|
*
|
|
6
6
|
* @example Getting started
|
|
7
7
|
*
|
|
@@ -11,23 +11,19 @@
|
|
|
11
11
|
* import { createHelia } from 'helia'
|
|
12
12
|
* import { ipns } from '@helia/ipns'
|
|
13
13
|
* import { unixfs } from '@helia/unixfs'
|
|
14
|
-
* import { generateKeyPair } from '@libp2p/crypto/keys'
|
|
15
14
|
*
|
|
16
15
|
* const helia = await createHelia()
|
|
17
16
|
* const name = ipns(helia)
|
|
18
17
|
*
|
|
19
|
-
* // create a keypair to publish an IPNS name
|
|
20
|
-
* const privateKey = await generateKeyPair('Ed25519')
|
|
21
|
-
*
|
|
22
18
|
* // store some data to publish
|
|
23
19
|
* const fs = unixfs(helia)
|
|
24
20
|
* const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
25
21
|
*
|
|
26
22
|
* // publish the name
|
|
27
|
-
* await name.publish(
|
|
23
|
+
* const { publicKey } = await name.publish('key-1', cid)
|
|
28
24
|
*
|
|
29
25
|
* // resolve the name
|
|
30
|
-
* const result = await name.resolve(
|
|
26
|
+
* const result = await name.resolve(publicKey)
|
|
31
27
|
*
|
|
32
28
|
* console.info(result.cid, result.path)
|
|
33
29
|
* ```
|
|
@@ -46,24 +42,18 @@
|
|
|
46
42
|
* const helia = await createHelia()
|
|
47
43
|
* const name = ipns(helia)
|
|
48
44
|
*
|
|
49
|
-
* // create a keypair to publish an IPNS name
|
|
50
|
-
* const privateKey = await generateKeyPair('Ed25519')
|
|
51
|
-
*
|
|
52
45
|
* // store some data to publish
|
|
53
46
|
* const fs = unixfs(helia)
|
|
54
47
|
* const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
55
48
|
*
|
|
56
49
|
* // publish the name
|
|
57
|
-
* await name.publish(
|
|
58
|
-
*
|
|
59
|
-
* // create another keypair to re-publish the original record
|
|
60
|
-
* const recursivePrivateKey = await generateKeyPair('Ed25519')
|
|
50
|
+
* const { publicKey } = await name.publish('key-1', cid)
|
|
61
51
|
*
|
|
62
52
|
* // publish the recursive name
|
|
63
|
-
* await name.publish(
|
|
53
|
+
* const { publicKey: recursivePublicKey } = await name.publish('key-2', publicKey)
|
|
64
54
|
*
|
|
65
55
|
* // resolve the name recursively - it resolves until a CID is found
|
|
66
|
-
* const result = await name.resolve(
|
|
56
|
+
* const result = await name.resolve(recursivePublicKey)
|
|
67
57
|
* console.info(result.cid.toString() === cid.toString()) // true
|
|
68
58
|
* ```
|
|
69
59
|
*
|
|
@@ -80,9 +70,6 @@
|
|
|
80
70
|
* const helia = await createHelia()
|
|
81
71
|
* const name = ipns(helia)
|
|
82
72
|
*
|
|
83
|
-
* // create a keypair to publish an IPNS name
|
|
84
|
-
* const privateKey = await generateKeyPair('Ed25519')
|
|
85
|
-
*
|
|
86
73
|
* // store some data to publish
|
|
87
74
|
* const fs = unixfs(helia)
|
|
88
75
|
* const fileCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
@@ -92,10 +79,10 @@
|
|
|
92
79
|
* const finalDirCid = await fs.cp(fileCid, dirCid, '/foo.txt')
|
|
93
80
|
*
|
|
94
81
|
* // publish the name
|
|
95
|
-
* await name.publish(
|
|
82
|
+
* const { publicKey } = await name.publish('key-1', `/ipfs/${finalDirCid}/foo.txt`)
|
|
96
83
|
*
|
|
97
84
|
* // resolve the name
|
|
98
|
-
* const result = await name.resolve(
|
|
85
|
+
* const result = await name.resolve(publicKey)
|
|
99
86
|
*
|
|
100
87
|
* console.info(result.cid, result.path) // QmFoo.. 'foo.txt'
|
|
101
88
|
* ```
|
|
@@ -121,13 +108,14 @@
|
|
|
121
108
|
* import { ipns } from '@helia/ipns'
|
|
122
109
|
* import { pubsub } from '@helia/ipns/routing'
|
|
123
110
|
* import { unixfs } from '@helia/unixfs'
|
|
124
|
-
* import {
|
|
111
|
+
* import { floodsub } from '@libp2p/floodsub'
|
|
125
112
|
* import { generateKeyPair } from '@libp2p/crypto/keys'
|
|
126
|
-
* import type {
|
|
113
|
+
* import type { PubSub } from '@helia/ipns/routing'
|
|
114
|
+
* import type { Libp2p } from '@libp2p/interface'
|
|
127
115
|
* import type { DefaultLibp2pServices } from 'helia'
|
|
128
116
|
*
|
|
129
117
|
* const libp2pOptions = libp2pDefaults()
|
|
130
|
-
* libp2pOptions.services.pubsub =
|
|
118
|
+
* libp2pOptions.services.pubsub = floodsub()
|
|
131
119
|
*
|
|
132
120
|
* const helia = await createHelia<Libp2p<DefaultLibp2pServices & { pubsub: PubSub }>>({
|
|
133
121
|
* libp2p: libp2pOptions
|
|
@@ -138,133 +126,30 @@
|
|
|
138
126
|
* ]
|
|
139
127
|
* })
|
|
140
128
|
*
|
|
141
|
-
* // create a keypair to publish an IPNS name
|
|
142
|
-
* const privateKey = await generateKeyPair('Ed25519')
|
|
143
129
|
*
|
|
144
130
|
* // store some data to publish
|
|
145
131
|
* const fs = unixfs(helia)
|
|
146
132
|
* const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
147
133
|
*
|
|
148
134
|
* // publish the name
|
|
149
|
-
* await name.publish(
|
|
135
|
+
* const { publicKey } = await name.publish('key-1', cid)
|
|
150
136
|
*
|
|
151
137
|
* // resolve the name
|
|
152
|
-
* const result = await name.resolve(
|
|
153
|
-
* ```
|
|
154
|
-
*
|
|
155
|
-
* @example Using custom DNS over HTTPS resolvers
|
|
156
|
-
*
|
|
157
|
-
* To use custom resolvers, configure Helia's `dns` option:
|
|
158
|
-
*
|
|
159
|
-
* ```TypeScript
|
|
160
|
-
* import { createHelia } from 'helia'
|
|
161
|
-
* import { ipns } from '@helia/ipns'
|
|
162
|
-
* import { dns } from '@multiformats/dns'
|
|
163
|
-
* import { dnsOverHttps } from '@multiformats/dns/resolvers'
|
|
164
|
-
* import { helia } from '@helia/ipns/routing'
|
|
165
|
-
*
|
|
166
|
-
* const node = await createHelia({
|
|
167
|
-
* dns: dns({
|
|
168
|
-
* resolvers: {
|
|
169
|
-
* '.': dnsOverHttps('https://private-dns-server.me/dns-query')
|
|
170
|
-
* }
|
|
171
|
-
* })
|
|
172
|
-
* })
|
|
173
|
-
* const name = ipns(node, {
|
|
174
|
-
* routers: [
|
|
175
|
-
* helia(node.routing)
|
|
176
|
-
* ]
|
|
177
|
-
* })
|
|
178
|
-
*
|
|
179
|
-
* const result = name.resolveDNSLink('some-domain-with-dnslink-entry.com')
|
|
180
|
-
* ```
|
|
181
|
-
*
|
|
182
|
-
* @example Resolving a domain with a dnslink entry
|
|
183
|
-
*
|
|
184
|
-
* Calling `resolveDNSLink` with the `@helia/ipns` instance:
|
|
185
|
-
*
|
|
186
|
-
* ```TypeScript
|
|
187
|
-
* // resolve a CID from a TXT record in a DNS zone file, using the default
|
|
188
|
-
* // resolver for the current platform eg:
|
|
189
|
-
* // > dig _dnslink.ipfs.io TXT
|
|
190
|
-
* // ;; ANSWER SECTION:
|
|
191
|
-
* // _dnslink.ipfs.io. 60 IN TXT "dnslink=/ipns/website.ipfs.io"
|
|
192
|
-
* // > dig _dnslink.website.ipfs.io TXT
|
|
193
|
-
* // ;; ANSWER SECTION:
|
|
194
|
-
* // _dnslink.website.ipfs.io. 60 IN TXT "dnslink=/ipfs/QmWebsite"
|
|
195
|
-
*
|
|
196
|
-
* import { createHelia } from 'helia'
|
|
197
|
-
* import { ipns } from '@helia/ipns'
|
|
198
|
-
*
|
|
199
|
-
* const node = await createHelia()
|
|
200
|
-
* const name = ipns(node)
|
|
201
|
-
*
|
|
202
|
-
* const { answer } = await name.resolveDNSLink('ipfs.io')
|
|
203
|
-
*
|
|
204
|
-
* console.info(answer)
|
|
205
|
-
* // { data: '/ipfs/QmWebsite' }
|
|
206
|
-
* ```
|
|
207
|
-
*
|
|
208
|
-
* @example Using DNS-Over-HTTPS
|
|
209
|
-
*
|
|
210
|
-
* This example uses the Mozilla provided RFC 1035 DNS over HTTPS service. This
|
|
211
|
-
* uses binary DNS records so requires extra dependencies to process the
|
|
212
|
-
* response which can increase browser bundle sizes.
|
|
213
|
-
*
|
|
214
|
-
* If this is a concern, use the DNS-JSON-Over-HTTPS resolver instead.
|
|
215
|
-
*
|
|
216
|
-
* ```TypeScript
|
|
217
|
-
* import { createHelia } from 'helia'
|
|
218
|
-
* import { ipns } from '@helia/ipns'
|
|
219
|
-
* import { dns } from '@multiformats/dns'
|
|
220
|
-
* import { dnsOverHttps } from '@multiformats/dns/resolvers'
|
|
221
|
-
*
|
|
222
|
-
* const node = await createHelia({
|
|
223
|
-
* dns: dns({
|
|
224
|
-
* resolvers: {
|
|
225
|
-
* '.': dnsOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
|
|
226
|
-
* }
|
|
227
|
-
* })
|
|
228
|
-
* })
|
|
229
|
-
* const name = ipns(node)
|
|
230
|
-
*
|
|
231
|
-
* const result = await name.resolveDNSLink('ipfs.io')
|
|
232
|
-
* ```
|
|
233
|
-
*
|
|
234
|
-
* @example Using DNS-JSON-Over-HTTPS
|
|
235
|
-
*
|
|
236
|
-
* DNS-JSON-Over-HTTPS resolvers use the RFC 8427 `application/dns-json` and can
|
|
237
|
-
* result in a smaller browser bundle due to the response being plain JSON.
|
|
238
|
-
*
|
|
239
|
-
* ```TypeScript
|
|
240
|
-
* import { createHelia } from 'helia'
|
|
241
|
-
* import { ipns } from '@helia/ipns'
|
|
242
|
-
* import { dns } from '@multiformats/dns'
|
|
243
|
-
* import { dnsJsonOverHttps } from '@multiformats/dns/resolvers'
|
|
244
|
-
*
|
|
245
|
-
* const node = await createHelia({
|
|
246
|
-
* dns: dns({
|
|
247
|
-
* resolvers: {
|
|
248
|
-
* '.': dnsJsonOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
|
|
249
|
-
* }
|
|
250
|
-
* })
|
|
251
|
-
* })
|
|
252
|
-
* const name = ipns(node)
|
|
253
|
-
*
|
|
254
|
-
* const result = await name.resolveDNSLink('ipfs.io')
|
|
138
|
+
* const result = await name.resolve(publicKey)
|
|
255
139
|
* ```
|
|
256
140
|
*
|
|
257
141
|
* @example Republishing an existing IPNS record
|
|
258
142
|
*
|
|
259
|
-
*
|
|
260
|
-
* needing the private key. This
|
|
261
|
-
*
|
|
143
|
+
* It is sometimes useful to be able to republish an existing IPNS record
|
|
144
|
+
* without needing the private key. This allows you to extend the availability
|
|
145
|
+
* of a record that was created elsewhere.
|
|
262
146
|
*
|
|
263
147
|
* ```TypeScript
|
|
264
148
|
* import { createHelia } from 'helia'
|
|
265
|
-
* import { ipns } from '@helia/ipns'
|
|
149
|
+
* import { ipns, ipnsValidator } from '@helia/ipns'
|
|
266
150
|
* import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
|
|
267
151
|
* import { CID } from 'multiformats/cid'
|
|
152
|
+
* import { multihashToIPNSRoutingKey, marshalIPNSRecord } from 'ipns'
|
|
268
153
|
*
|
|
269
154
|
* const helia = await createHelia()
|
|
270
155
|
* const name = ipns(helia)
|
|
@@ -274,293 +159,25 @@
|
|
|
274
159
|
* const delegatedClient = createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev')
|
|
275
160
|
* const record = await delegatedClient.getIPNS(parsedCid)
|
|
276
161
|
*
|
|
277
|
-
*
|
|
162
|
+
* const routingKey = multihashToIPNSRoutingKey(parsedCid.multihash)
|
|
163
|
+
* const marshaledRecord = marshalIPNSRecord(record)
|
|
164
|
+
*
|
|
165
|
+
* // validate that they key corresponds to the record
|
|
166
|
+
* await ipnsValidator(routingKey, marshaledRecord)
|
|
167
|
+
*
|
|
168
|
+
* // publish record to routing
|
|
169
|
+
* await Promise.all(
|
|
170
|
+
* name.routers.map(async r => {
|
|
171
|
+
* await r.put(routingKey, marshaledRecord)
|
|
172
|
+
* })
|
|
173
|
+
* )
|
|
278
174
|
* ```
|
|
279
175
|
*/
|
|
280
|
-
import { NotFoundError, isPublicKey } from '@libp2p/interface';
|
|
281
|
-
import { logger } from '@libp2p/logger';
|
|
282
|
-
import { peerIdFromString } from '@libp2p/peer-id';
|
|
283
|
-
import { createIPNSRecord, extractPublicKeyFromIPNSRecord, marshalIPNSRecord, multihashToIPNSRoutingKey, unmarshalIPNSRecord } from 'ipns';
|
|
284
|
-
import { ipnsSelector } from 'ipns/selector';
|
|
285
176
|
import { ipnsValidator } from 'ipns/validator';
|
|
286
|
-
import { base36 } from 'multiformats/bases/base36';
|
|
287
|
-
import { base58btc } from 'multiformats/bases/base58';
|
|
288
177
|
import { CID } from 'multiformats/cid';
|
|
289
|
-
import
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
import { InvalidValueError, RecordsFailedValidationError, UnsupportedMultibasePrefixError, UnsupportedMultihashCodecError } from './errors.js';
|
|
293
|
-
import { helia } from './routing/helia.js';
|
|
294
|
-
import { localStore } from './routing/local-store.js';
|
|
295
|
-
import { isCodec, IDENTITY_CODEC, SHA2_256_CODEC, IPNS_STRING_PREFIX } from './utils.js';
|
|
296
|
-
const log = logger('helia:ipns');
|
|
297
|
-
const MINUTE = 60 * 1000;
|
|
298
|
-
const HOUR = 60 * MINUTE;
|
|
299
|
-
const DEFAULT_LIFETIME_MS = 48 * HOUR;
|
|
300
|
-
const DEFAULT_REPUBLISH_INTERVAL_MS = 23 * HOUR;
|
|
301
|
-
const DEFAULT_TTL_NS = BigInt(MINUTE) * 5000000n; // 5 minutes
|
|
302
|
-
const bases = {
|
|
303
|
-
[base36.prefix]: base36,
|
|
304
|
-
[base58btc.prefix]: base58btc
|
|
305
|
-
};
|
|
306
|
-
class DefaultIPNS {
|
|
307
|
-
routers;
|
|
308
|
-
localStore;
|
|
309
|
-
timeout;
|
|
310
|
-
dns;
|
|
311
|
-
log;
|
|
312
|
-
constructor(components, routers = []) {
|
|
313
|
-
this.routers = [
|
|
314
|
-
helia(components.routing),
|
|
315
|
-
...routers
|
|
316
|
-
];
|
|
317
|
-
this.localStore = localStore(components.datastore);
|
|
318
|
-
this.dns = components.dns;
|
|
319
|
-
this.log = components.logger.forComponent('helia:ipns');
|
|
320
|
-
}
|
|
321
|
-
async publish(key, value, options = {}) {
|
|
322
|
-
try {
|
|
323
|
-
let sequenceNumber = 1n;
|
|
324
|
-
const routingKey = multihashToIPNSRoutingKey(key.publicKey.toMultihash());
|
|
325
|
-
if (await this.localStore.has(routingKey, options)) {
|
|
326
|
-
// if we have published under this key before, increment the sequence number
|
|
327
|
-
const { record } = await this.localStore.get(routingKey, options);
|
|
328
|
-
const existingRecord = unmarshalIPNSRecord(record);
|
|
329
|
-
sequenceNumber = existingRecord.sequence + 1n;
|
|
330
|
-
}
|
|
331
|
-
// convert ttl from milliseconds to nanoseconds as createIPNSRecord expects
|
|
332
|
-
const ttlNs = options.ttl != null ? BigInt(options.ttl) * 1000000n : DEFAULT_TTL_NS;
|
|
333
|
-
const record = await createIPNSRecord(key, value, sequenceNumber, options.lifetime ?? DEFAULT_LIFETIME_MS, { ...options, ttlNs });
|
|
334
|
-
const marshaledRecord = marshalIPNSRecord(record);
|
|
335
|
-
await this.localStore.put(routingKey, marshaledRecord, options);
|
|
336
|
-
if (options.offline !== true) {
|
|
337
|
-
// publish record to routing
|
|
338
|
-
await Promise.all(this.routers.map(async (r) => { await r.put(routingKey, marshaledRecord, options); }));
|
|
339
|
-
}
|
|
340
|
-
return record;
|
|
341
|
-
}
|
|
342
|
-
catch (err) {
|
|
343
|
-
options.onProgress?.(new CustomProgressEvent('ipns:publish:error', err));
|
|
344
|
-
throw err;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
async resolve(key, options = {}) {
|
|
348
|
-
const digest = isPublicKey(key) ? key.toMultihash() : key;
|
|
349
|
-
const routingKey = multihashToIPNSRoutingKey(digest);
|
|
350
|
-
const record = await this.#findIpnsRecord(routingKey, options);
|
|
351
|
-
return {
|
|
352
|
-
...(await this.#resolve(record.value, options)),
|
|
353
|
-
record
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
async resolveDNSLink(domain, options = {}) {
|
|
357
|
-
const dnslink = await resolveDNSLink(domain, this.dns, this.log, options);
|
|
358
|
-
return {
|
|
359
|
-
...(await this.#resolve(dnslink.value, options)),
|
|
360
|
-
answer: dnslink.answer
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
republish(options = {}) {
|
|
364
|
-
if (this.timeout != null) {
|
|
365
|
-
throw new Error('Republish is already running');
|
|
366
|
-
}
|
|
367
|
-
options.signal?.addEventListener('abort', () => {
|
|
368
|
-
clearTimeout(this.timeout);
|
|
369
|
-
});
|
|
370
|
-
async function republish() {
|
|
371
|
-
const startTime = Date.now();
|
|
372
|
-
options.onProgress?.(new CustomProgressEvent('ipns:republish:start'));
|
|
373
|
-
const finishType = Date.now();
|
|
374
|
-
const timeTaken = finishType - startTime;
|
|
375
|
-
let nextInterval = DEFAULT_REPUBLISH_INTERVAL_MS - timeTaken;
|
|
376
|
-
if (nextInterval < 0) {
|
|
377
|
-
nextInterval = options.interval ?? DEFAULT_REPUBLISH_INTERVAL_MS;
|
|
378
|
-
}
|
|
379
|
-
setTimeout(() => {
|
|
380
|
-
republish().catch(err => {
|
|
381
|
-
log.error('error republishing', err);
|
|
382
|
-
});
|
|
383
|
-
}, nextInterval);
|
|
384
|
-
}
|
|
385
|
-
this.timeout = setTimeout(() => {
|
|
386
|
-
republish().catch(err => {
|
|
387
|
-
log.error('error republishing', err);
|
|
388
|
-
});
|
|
389
|
-
}, options.interval ?? DEFAULT_REPUBLISH_INTERVAL_MS);
|
|
390
|
-
}
|
|
391
|
-
async #resolve(ipfsPath, options = {}) {
|
|
392
|
-
const parts = ipfsPath.split('/');
|
|
393
|
-
try {
|
|
394
|
-
const scheme = parts[1];
|
|
395
|
-
if (scheme === 'ipns') {
|
|
396
|
-
const str = parts[2];
|
|
397
|
-
const prefix = str.substring(0, 1);
|
|
398
|
-
let buf;
|
|
399
|
-
if (prefix === '1' || prefix === 'Q') {
|
|
400
|
-
buf = base58btc.decode(`z${str}`);
|
|
401
|
-
}
|
|
402
|
-
else if (bases[prefix] != null) {
|
|
403
|
-
buf = bases[prefix].decode(str);
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
throw new UnsupportedMultibasePrefixError(`Unsupported multibase prefix "${prefix}"`);
|
|
407
|
-
}
|
|
408
|
-
let digest;
|
|
409
|
-
try {
|
|
410
|
-
digest = Digest.decode(buf);
|
|
411
|
-
}
|
|
412
|
-
catch {
|
|
413
|
-
digest = CID.decode(buf).multihash;
|
|
414
|
-
}
|
|
415
|
-
if (!isCodec(digest, IDENTITY_CODEC) && !isCodec(digest, SHA2_256_CODEC)) {
|
|
416
|
-
throw new UnsupportedMultihashCodecError(`Unsupported multihash codec "${digest.code}"`);
|
|
417
|
-
}
|
|
418
|
-
const { cid } = await this.resolve(digest, options);
|
|
419
|
-
const path = parts.slice(3).join('/');
|
|
420
|
-
return {
|
|
421
|
-
cid,
|
|
422
|
-
path
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
else if (scheme === 'ipfs') {
|
|
426
|
-
const cid = CID.parse(parts[2]);
|
|
427
|
-
const path = parts.slice(3).join('/');
|
|
428
|
-
return {
|
|
429
|
-
cid,
|
|
430
|
-
path
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
catch (err) {
|
|
435
|
-
log.error('error parsing ipfs path', err);
|
|
436
|
-
}
|
|
437
|
-
log.error('invalid ipfs path %s', ipfsPath);
|
|
438
|
-
throw new InvalidValueError('Invalid value');
|
|
439
|
-
}
|
|
440
|
-
async #findIpnsRecord(routingKey, options = {}) {
|
|
441
|
-
const records = [];
|
|
442
|
-
const cached = await this.localStore.has(routingKey, options);
|
|
443
|
-
if (cached) {
|
|
444
|
-
log('record is present in the cache');
|
|
445
|
-
if (options.nocache !== true) {
|
|
446
|
-
try {
|
|
447
|
-
// check the local cache first
|
|
448
|
-
const { record, created } = await this.localStore.get(routingKey, options);
|
|
449
|
-
this.log('record retrieved from cache');
|
|
450
|
-
// validate the record
|
|
451
|
-
await ipnsValidator(routingKey, record);
|
|
452
|
-
this.log('record was valid');
|
|
453
|
-
// check the TTL
|
|
454
|
-
const ipnsRecord = unmarshalIPNSRecord(record);
|
|
455
|
-
// IPNS TTL is in nanoseconds, convert to milliseconds, default to one
|
|
456
|
-
// hour
|
|
457
|
-
const ttlMs = Number((ipnsRecord.ttl ?? DEFAULT_TTL_NS) / 1000000n);
|
|
458
|
-
const ttlExpires = created.getTime() + ttlMs;
|
|
459
|
-
if (ttlExpires > Date.now()) {
|
|
460
|
-
// the TTL has not yet expired, return the cached record
|
|
461
|
-
this.log('record TTL was valid');
|
|
462
|
-
return ipnsRecord;
|
|
463
|
-
}
|
|
464
|
-
if (options.offline === true) {
|
|
465
|
-
// the TTL has expired but we are skipping the routing search
|
|
466
|
-
this.log('record TTL has been reached but we are resolving offline-only, returning record');
|
|
467
|
-
return ipnsRecord;
|
|
468
|
-
}
|
|
469
|
-
this.log('record TTL has been reached, searching routing for updates');
|
|
470
|
-
// add the local record to our list of resolved record, and also
|
|
471
|
-
// search the routing for updates - the most up to date record will be
|
|
472
|
-
// returned
|
|
473
|
-
records.push(record);
|
|
474
|
-
}
|
|
475
|
-
catch (err) {
|
|
476
|
-
this.log('cached record was invalid', err);
|
|
477
|
-
await this.localStore.delete(routingKey, options);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
else {
|
|
481
|
-
log('ignoring local cache due to nocache=true option');
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
if (options.offline === true) {
|
|
485
|
-
throw new NotFoundError('Record was not present in the cache or has expired');
|
|
486
|
-
}
|
|
487
|
-
log('did not have record locally');
|
|
488
|
-
let foundInvalid = 0;
|
|
489
|
-
await Promise.all(this.routers.map(async (router) => {
|
|
490
|
-
let record;
|
|
491
|
-
try {
|
|
492
|
-
record = await router.get(routingKey, {
|
|
493
|
-
...options,
|
|
494
|
-
validate: false
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
catch (err) {
|
|
498
|
-
log.error('error finding IPNS record', err);
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
try {
|
|
502
|
-
await ipnsValidator(routingKey, record);
|
|
503
|
-
records.push(record);
|
|
504
|
-
}
|
|
505
|
-
catch (err) {
|
|
506
|
-
// we found a record, but the validator rejected it
|
|
507
|
-
foundInvalid++;
|
|
508
|
-
log.error('error finding IPNS record', err);
|
|
509
|
-
}
|
|
510
|
-
}));
|
|
511
|
-
if (records.length === 0) {
|
|
512
|
-
if (foundInvalid > 0) {
|
|
513
|
-
throw new RecordsFailedValidationError(`${foundInvalid > 1 ? `${foundInvalid} records` : 'Record'} found for routing key ${foundInvalid > 1 ? 'were' : 'was'} invalid`);
|
|
514
|
-
}
|
|
515
|
-
throw new NotFoundError('Could not find record for routing key');
|
|
516
|
-
}
|
|
517
|
-
const record = records[ipnsSelector(routingKey, records)];
|
|
518
|
-
await this.localStore.put(routingKey, record, options);
|
|
519
|
-
return unmarshalIPNSRecord(record);
|
|
520
|
-
}
|
|
521
|
-
async republishRecord(key, record, options = {}) {
|
|
522
|
-
let mh;
|
|
523
|
-
try {
|
|
524
|
-
mh = extractPublicKeyFromIPNSRecord(record)?.toMultihash(); // embedded public key take precedence, if present
|
|
525
|
-
if (mh == null) {
|
|
526
|
-
// if no public key is embedded in the record, use the key that was passed in
|
|
527
|
-
if (typeof key === 'string') {
|
|
528
|
-
if (key.startsWith(IPNS_STRING_PREFIX)) {
|
|
529
|
-
// remove the /ipns/ prefix from the key
|
|
530
|
-
key = key.slice(IPNS_STRING_PREFIX.length);
|
|
531
|
-
}
|
|
532
|
-
// Convert string key to MultihashDigest
|
|
533
|
-
try {
|
|
534
|
-
mh = peerIdFromString(key).toMultihash();
|
|
535
|
-
}
|
|
536
|
-
catch (err) {
|
|
537
|
-
throw new Error(`Invalid string key: ${err.message}`);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
else {
|
|
541
|
-
mh = key;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
if (mh == null) {
|
|
545
|
-
throw new Error('No public key multihash found to determine the routing key');
|
|
546
|
-
}
|
|
547
|
-
const routingKey = multihashToIPNSRoutingKey(mh);
|
|
548
|
-
const marshaledRecord = marshalIPNSRecord(record);
|
|
549
|
-
await ipnsValidator(routingKey, marshaledRecord); // validate that they key corresponds to the record
|
|
550
|
-
await this.localStore.put(routingKey, marshaledRecord, options); // add to local store
|
|
551
|
-
if (options.offline !== true) {
|
|
552
|
-
// publish record to routing
|
|
553
|
-
await Promise.all(this.routers.map(async (r) => { await r.put(routingKey, marshaledRecord, options); }));
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
catch (err) {
|
|
557
|
-
options.onProgress?.(new CustomProgressEvent('ipns:republish:error', { key: mh, record, err }));
|
|
558
|
-
throw err;
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
export function ipns(components, { routers = [] } = {}) {
|
|
563
|
-
return new DefaultIPNS(components, routers);
|
|
178
|
+
import { IPNS as IPNSClass } from './ipns.js';
|
|
179
|
+
export function ipns(components, options = {}) {
|
|
180
|
+
return new IPNSClass(components, options);
|
|
564
181
|
}
|
|
565
182
|
export { ipnsValidator };
|
|
566
183
|
export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AAA;AAkM7C,MAAM,UAAU,IAAI,CAAE,UAA0B,EAAE,UAAuB,EAAE;IACzE,OAAO,IAAI,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;AAC3C,CAAC;AAED,OAAO,EAAE,aAAa,EAA0B,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
import type { IPNSComponents, IPNS as IPNSInterface, IPNSOptions, IPNSPublishResult, IPNSResolveResult, PublishOptions, ResolveOptions } from './index.js';
|
|
3
|
+
import type { IPNSRouting } from './routing/index.js';
|
|
4
|
+
import type { AbortOptions, PeerId, PublicKey, Startable } from '@libp2p/interface';
|
|
5
|
+
import type { MultihashDigest } from 'multiformats/hashes/interface';
|
|
6
|
+
export declare class IPNS implements IPNSInterface, Startable {
|
|
7
|
+
#private;
|
|
8
|
+
readonly routers: IPNSRouting[];
|
|
9
|
+
private readonly localStore;
|
|
10
|
+
private readonly republishTask;
|
|
11
|
+
private readonly log;
|
|
12
|
+
private readonly keychain;
|
|
13
|
+
private started;
|
|
14
|
+
private readonly republishConcurrency;
|
|
15
|
+
constructor(components: IPNSComponents, init?: IPNSOptions);
|
|
16
|
+
start(): void;
|
|
17
|
+
stop(): void;
|
|
18
|
+
publish(keyName: string, value: CID | PublicKey | MultihashDigest<0x00 | 0x12> | PeerId | string, options?: PublishOptions): Promise<IPNSPublishResult>;
|
|
19
|
+
resolve(key: CID<unknown, 0x72, 0x00 | 0x12, 1> | PublicKey | MultihashDigest<0x00 | 0x12> | PeerId, options?: ResolveOptions): Promise<IPNSResolveResult>;
|
|
20
|
+
unpublish(keyName: string, options?: AbortOptions): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=ipns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipns.d.ts","sourceRoot":"","sources":["../../src/ipns.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