@helia/ipns 1.1.7 → 2.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/dist/index.min.js +10 -10
- package/dist/src/index.d.ts +13 -27
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -34
- package/dist/src/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +18 -44
package/dist/src/index.d.ts
CHANGED
|
@@ -6,30 +6,11 @@
|
|
|
6
6
|
* @example
|
|
7
7
|
*
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import { gossipsub } from '@chainsafe/libp2p-gossipsub'
|
|
10
|
-
* import { kadDHT } from '@libp2p/kad-dht'
|
|
11
|
-
* import { createLibp2p } from 'libp2p'
|
|
12
9
|
* import { createHelia } from 'helia'
|
|
13
|
-
* import { ipns, ipnsValidator, ipnsSelector } from '@helia/ipns'
|
|
14
10
|
* import { dht, pubsub } from '@helia/ipns/routing'
|
|
15
11
|
* import { unixfs } from '@helia/unixfs'
|
|
16
12
|
*
|
|
17
|
-
* const
|
|
18
|
-
* dht: kadDHT({
|
|
19
|
-
* validators: {
|
|
20
|
-
* ipns: ipnsValidator
|
|
21
|
-
* },
|
|
22
|
-
* selectors: {
|
|
23
|
-
* ipns: ipnsSelector
|
|
24
|
-
* }
|
|
25
|
-
* }),
|
|
26
|
-
* pubsub: gossipsub()
|
|
27
|
-
* })
|
|
28
|
-
*
|
|
29
|
-
* const helia = await createHelia({
|
|
30
|
-
* libp2p,
|
|
31
|
-
* //.. other options
|
|
32
|
-
* })
|
|
13
|
+
* const helia = await createHelia()
|
|
33
14
|
* const name = ipns(helia, [
|
|
34
15
|
* dht(helia),
|
|
35
16
|
* pubsub(helia)
|
|
@@ -61,18 +42,18 @@
|
|
|
61
42
|
* const cid = name.resolveDns('ipfs.io')
|
|
62
43
|
* ```
|
|
63
44
|
*/
|
|
64
|
-
import { type PeerId } from '@libp2p/interface/peer-id';
|
|
65
45
|
import { ipnsValidator } from 'ipns/validator';
|
|
66
46
|
import { CID } from 'multiformats/cid';
|
|
67
47
|
import type { IPNSRouting, IPNSRoutingEvents } from './routing/index.js';
|
|
68
48
|
import type { AbortOptions } from '@libp2p/interface';
|
|
49
|
+
import type { PeerId } from '@libp2p/interface/peer-id';
|
|
69
50
|
import type { Datastore } from 'interface-datastore';
|
|
70
|
-
import type {
|
|
51
|
+
import type { IPNSRecord } from 'ipns';
|
|
71
52
|
import type { ProgressEvent, ProgressOptions } from 'progress-events';
|
|
72
|
-
export type PublishProgressEvents = ProgressEvent<'ipns:publish:start'> | ProgressEvent<'ipns:publish:success',
|
|
73
|
-
export type ResolveProgressEvents = ProgressEvent<'ipns:resolve:start', unknown> | ProgressEvent<'ipns:resolve:success',
|
|
74
|
-
export type RepublishProgressEvents = ProgressEvent<'ipns:republish:start', unknown> | ProgressEvent<'ipns:republish:success',
|
|
75
|
-
record:
|
|
53
|
+
export type PublishProgressEvents = ProgressEvent<'ipns:publish:start'> | ProgressEvent<'ipns:publish:success', IPNSRecord> | ProgressEvent<'ipns:publish:error', Error>;
|
|
54
|
+
export type ResolveProgressEvents = ProgressEvent<'ipns:resolve:start', unknown> | ProgressEvent<'ipns:resolve:success', IPNSRecord> | ProgressEvent<'ipns:resolve:error', Error>;
|
|
55
|
+
export type RepublishProgressEvents = ProgressEvent<'ipns:republish:start', unknown> | ProgressEvent<'ipns:republish:success', IPNSRecord> | ProgressEvent<'ipns:republish:error', {
|
|
56
|
+
record: IPNSRecord;
|
|
76
57
|
err: Error;
|
|
77
58
|
}>;
|
|
78
59
|
export interface PublishOptions extends AbortOptions, ProgressOptions<PublishProgressEvents | IPNSRoutingEvents> {
|
|
@@ -84,6 +65,11 @@ export interface PublishOptions extends AbortOptions, ProgressOptions<PublishPro
|
|
|
84
65
|
* Only publish to a local datastore (default: false)
|
|
85
66
|
*/
|
|
86
67
|
offline?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* By default a IPNS V1 and a V2 signature is added to every record. Pass
|
|
70
|
+
* false here to only add a V2 signature. (default: true)
|
|
71
|
+
*/
|
|
72
|
+
v1Compatible?: boolean;
|
|
87
73
|
}
|
|
88
74
|
export interface ResolveOptions extends AbortOptions, ProgressOptions<ResolveProgressEvents | IPNSRoutingEvents> {
|
|
89
75
|
/**
|
|
@@ -109,7 +95,7 @@ export interface IPNS {
|
|
|
109
95
|
*
|
|
110
96
|
* If the valid is a PeerId, a recursive IPNS record will be created.
|
|
111
97
|
*/
|
|
112
|
-
publish: (key: PeerId, value: CID | PeerId, options?: PublishOptions) => Promise<
|
|
98
|
+
publish: (key: PeerId, value: CID | PeerId, options?: PublishOptions) => Promise<IPNSRecord>;
|
|
113
99
|
/**
|
|
114
100
|
* Accepts a public key formatted as a libp2p PeerID and resolves the IPNS record
|
|
115
101
|
* corresponding to that public key until a value is found
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAOH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAItC,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE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,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;IAE5F;;;OAGG;IACH,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAEhE;;OAEG;IACH,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAEzE;;OAEG;IACH,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,gBAAgB,KAAK,IAAI,CAAA;CAChD;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAA;CACrB;AAmJD,wBAAgB,IAAI,CAAE,UAAU,EAAE,cAAc,EAAE,OAAO,GAAE,WAAW,EAAO,GAAG,IAAI,CAEnF;AAED,OAAO,EAAE,aAAa,EAAE,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -6,30 +6,11 @@
|
|
|
6
6
|
* @example
|
|
7
7
|
*
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import { gossipsub } from '@chainsafe/libp2p-gossipsub'
|
|
10
|
-
* import { kadDHT } from '@libp2p/kad-dht'
|
|
11
|
-
* import { createLibp2p } from 'libp2p'
|
|
12
9
|
* import { createHelia } from 'helia'
|
|
13
|
-
* import { ipns, ipnsValidator, ipnsSelector } from '@helia/ipns'
|
|
14
10
|
* import { dht, pubsub } from '@helia/ipns/routing'
|
|
15
11
|
* import { unixfs } from '@helia/unixfs'
|
|
16
12
|
*
|
|
17
|
-
* const
|
|
18
|
-
* dht: kadDHT({
|
|
19
|
-
* validators: {
|
|
20
|
-
* ipns: ipnsValidator
|
|
21
|
-
* },
|
|
22
|
-
* selectors: {
|
|
23
|
-
* ipns: ipnsSelector
|
|
24
|
-
* }
|
|
25
|
-
* }),
|
|
26
|
-
* pubsub: gossipsub()
|
|
27
|
-
* })
|
|
28
|
-
*
|
|
29
|
-
* const helia = await createHelia({
|
|
30
|
-
* libp2p,
|
|
31
|
-
* //.. other options
|
|
32
|
-
* })
|
|
13
|
+
* const helia = await createHelia()
|
|
33
14
|
* const name = ipns(helia, [
|
|
34
15
|
* dht(helia),
|
|
35
16
|
* pubsub(helia)
|
|
@@ -62,7 +43,6 @@
|
|
|
62
43
|
* ```
|
|
63
44
|
*/
|
|
64
45
|
import { CodeError } from '@libp2p/interface/errors';
|
|
65
|
-
import { isPeerId } from '@libp2p/interface/peer-id';
|
|
66
46
|
import { logger } from '@libp2p/logger';
|
|
67
47
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
68
48
|
import { create, marshal, peerIdToRoutingKey, unmarshal } from 'ipns';
|
|
@@ -70,8 +50,6 @@ import { ipnsSelector } from 'ipns/selector';
|
|
|
70
50
|
import { ipnsValidator } from 'ipns/validator';
|
|
71
51
|
import { CID } from 'multiformats/cid';
|
|
72
52
|
import { CustomProgressEvent } from 'progress-events';
|
|
73
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
74
|
-
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
75
53
|
import { localStore } from './routing/local-store.js';
|
|
76
54
|
import { resolveDnslink } from './utils/resolve-dns-link.js';
|
|
77
55
|
const log = logger('helia:ipns');
|
|
@@ -97,16 +75,8 @@ class DefaultIPNS {
|
|
|
97
75
|
const existingRecord = unmarshal(buf);
|
|
98
76
|
sequenceNumber = existingRecord.sequence + 1n;
|
|
99
77
|
}
|
|
100
|
-
let str;
|
|
101
|
-
if (isPeerId(value)) {
|
|
102
|
-
str = `/ipns/${value.toString()}`;
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
str = `/ipfs/${value.toString()}`;
|
|
106
|
-
}
|
|
107
|
-
const bytes = uint8ArrayFromString(str);
|
|
108
78
|
// create record
|
|
109
|
-
const record = await create(key,
|
|
79
|
+
const record = await create(key, value, sequenceNumber, options.lifetime ?? DEFAULT_LIFETIME_MS, options);
|
|
110
80
|
const marshaledRecord = marshal(record);
|
|
111
81
|
await this.localStore.put(routingKey, marshaledRecord, options);
|
|
112
82
|
if (options.offline !== true) {
|
|
@@ -123,8 +93,7 @@ class DefaultIPNS {
|
|
|
123
93
|
async resolve(key, options = {}) {
|
|
124
94
|
const routingKey = peerIdToRoutingKey(key);
|
|
125
95
|
const record = await this.#findIpnsRecord(routingKey, options);
|
|
126
|
-
|
|
127
|
-
return this.#resolve(str, options);
|
|
96
|
+
return this.#resolve(record.value, options);
|
|
128
97
|
}
|
|
129
98
|
async resolveDns(domain, options = {}) {
|
|
130
99
|
const dnslink = await resolveDnslink(domain, options);
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACt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A;QAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;YACxB,MAAM,IAAI,SAAS,CAAC,uCAAuC,EAAE,eAAe,CAAC,CAAA;SAC9E;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;QAEzD,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;QAEtD,OAAO,SAAS,CAAC,MAAM,CAAC,CAAA;IAC1B,CAAC;CACF;AAED,MAAM,UAAU,IAAI,CAAE,UAA0B,EAAE,UAAyB,EAAE;IAC3E,OAAO,IAAI,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;AAC7C,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/ipns",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "An implementation of IPNS for Helia",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia-ipns/tree/master/packages/ipns#readme",
|
|
@@ -160,7 +160,7 @@
|
|
|
160
160
|
"@libp2p/record": "^3.0.0",
|
|
161
161
|
"hashlru": "^2.3.0",
|
|
162
162
|
"interface-datastore": "^8.0.0",
|
|
163
|
-
"ipns": "^
|
|
163
|
+
"ipns": "^7.0.1",
|
|
164
164
|
"is-ipfs": "^8.0.1",
|
|
165
165
|
"multiformats": "^12.0.1",
|
|
166
166
|
"p-queue": "^7.3.0",
|
package/src/index.ts
CHANGED
|
@@ -6,30 +6,11 @@
|
|
|
6
6
|
* @example
|
|
7
7
|
*
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import { gossipsub } from '@chainsafe/libp2p-gossipsub'
|
|
10
|
-
* import { kadDHT } from '@libp2p/kad-dht'
|
|
11
|
-
* import { createLibp2p } from 'libp2p'
|
|
12
9
|
* import { createHelia } from 'helia'
|
|
13
|
-
* import { ipns, ipnsValidator, ipnsSelector } from '@helia/ipns'
|
|
14
10
|
* import { dht, pubsub } from '@helia/ipns/routing'
|
|
15
11
|
* import { unixfs } from '@helia/unixfs'
|
|
16
12
|
*
|
|
17
|
-
* const
|
|
18
|
-
* dht: kadDHT({
|
|
19
|
-
* validators: {
|
|
20
|
-
* ipns: ipnsValidator
|
|
21
|
-
* },
|
|
22
|
-
* selectors: {
|
|
23
|
-
* ipns: ipnsSelector
|
|
24
|
-
* }
|
|
25
|
-
* }),
|
|
26
|
-
* pubsub: gossipsub()
|
|
27
|
-
* })
|
|
28
|
-
*
|
|
29
|
-
* const helia = await createHelia({
|
|
30
|
-
* libp2p,
|
|
31
|
-
* //.. other options
|
|
32
|
-
* })
|
|
13
|
+
* const helia = await createHelia()
|
|
33
14
|
* const name = ipns(helia, [
|
|
34
15
|
* dht(helia),
|
|
35
16
|
* pubsub(helia)
|
|
@@ -63,7 +44,6 @@
|
|
|
63
44
|
*/
|
|
64
45
|
|
|
65
46
|
import { CodeError } from '@libp2p/interface/errors'
|
|
66
|
-
import { isPeerId, type PeerId } from '@libp2p/interface/peer-id'
|
|
67
47
|
import { logger } from '@libp2p/logger'
|
|
68
48
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
69
49
|
import { create, marshal, peerIdToRoutingKey, unmarshal } from 'ipns'
|
|
@@ -71,14 +51,13 @@ import { ipnsSelector } from 'ipns/selector'
|
|
|
71
51
|
import { ipnsValidator } from 'ipns/validator'
|
|
72
52
|
import { CID } from 'multiformats/cid'
|
|
73
53
|
import { CustomProgressEvent } from 'progress-events'
|
|
74
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
75
|
-
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
76
54
|
import { localStore, type LocalStore } from './routing/local-store.js'
|
|
77
55
|
import { resolveDnslink } from './utils/resolve-dns-link.js'
|
|
78
56
|
import type { IPNSRouting, IPNSRoutingEvents } from './routing/index.js'
|
|
79
57
|
import type { AbortOptions } from '@libp2p/interface'
|
|
58
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
80
59
|
import type { Datastore } from 'interface-datastore'
|
|
81
|
-
import type {
|
|
60
|
+
import type { IPNSRecord } from 'ipns'
|
|
82
61
|
import type { ProgressEvent, ProgressOptions } from 'progress-events'
|
|
83
62
|
|
|
84
63
|
const log = logger('helia:ipns')
|
|
@@ -91,18 +70,18 @@ const DEFAULT_REPUBLISH_INTERVAL_MS = 23 * HOUR
|
|
|
91
70
|
|
|
92
71
|
export type PublishProgressEvents =
|
|
93
72
|
ProgressEvent<'ipns:publish:start'> |
|
|
94
|
-
ProgressEvent<'ipns:publish:success',
|
|
73
|
+
ProgressEvent<'ipns:publish:success', IPNSRecord> |
|
|
95
74
|
ProgressEvent<'ipns:publish:error', Error>
|
|
96
75
|
|
|
97
76
|
export type ResolveProgressEvents =
|
|
98
77
|
ProgressEvent<'ipns:resolve:start', unknown> |
|
|
99
|
-
ProgressEvent<'ipns:resolve:success',
|
|
78
|
+
ProgressEvent<'ipns:resolve:success', IPNSRecord> |
|
|
100
79
|
ProgressEvent<'ipns:resolve:error', Error>
|
|
101
80
|
|
|
102
81
|
export type RepublishProgressEvents =
|
|
103
82
|
ProgressEvent<'ipns:republish:start', unknown> |
|
|
104
|
-
ProgressEvent<'ipns:republish:success',
|
|
105
|
-
ProgressEvent<'ipns:republish:error', { record:
|
|
83
|
+
ProgressEvent<'ipns:republish:success', IPNSRecord> |
|
|
84
|
+
ProgressEvent<'ipns:republish:error', { record: IPNSRecord, err: Error }>
|
|
106
85
|
|
|
107
86
|
export interface PublishOptions extends AbortOptions, ProgressOptions<PublishProgressEvents | IPNSRoutingEvents> {
|
|
108
87
|
/**
|
|
@@ -114,6 +93,12 @@ export interface PublishOptions extends AbortOptions, ProgressOptions<PublishPro
|
|
|
114
93
|
* Only publish to a local datastore (default: false)
|
|
115
94
|
*/
|
|
116
95
|
offline?: boolean
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* By default a IPNS V1 and a V2 signature is added to every record. Pass
|
|
99
|
+
* false here to only add a V2 signature. (default: true)
|
|
100
|
+
*/
|
|
101
|
+
v1Compatible?: boolean
|
|
117
102
|
}
|
|
118
103
|
|
|
119
104
|
export interface ResolveOptions extends AbortOptions, ProgressOptions<ResolveProgressEvents | IPNSRoutingEvents> {
|
|
@@ -143,7 +128,7 @@ export interface IPNS {
|
|
|
143
128
|
*
|
|
144
129
|
* If the valid is a PeerId, a recursive IPNS record will be created.
|
|
145
130
|
*/
|
|
146
|
-
publish: (key: PeerId, value: CID | PeerId, options?: PublishOptions) => Promise<
|
|
131
|
+
publish: (key: PeerId, value: CID | PeerId, options?: PublishOptions) => Promise<IPNSRecord>
|
|
147
132
|
|
|
148
133
|
/**
|
|
149
134
|
* Accepts a public key formatted as a libp2p PeerID and resolves the IPNS record
|
|
@@ -178,7 +163,7 @@ class DefaultIPNS implements IPNS {
|
|
|
178
163
|
this.localStore = localStore(components.datastore)
|
|
179
164
|
}
|
|
180
165
|
|
|
181
|
-
async publish (key: PeerId, value: CID | PeerId, options: PublishOptions = {}): Promise<
|
|
166
|
+
async publish (key: PeerId, value: CID | PeerId, options: PublishOptions = {}): Promise<IPNSRecord> {
|
|
182
167
|
try {
|
|
183
168
|
let sequenceNumber = 1n
|
|
184
169
|
const routingKey = peerIdToRoutingKey(key)
|
|
@@ -190,18 +175,8 @@ class DefaultIPNS implements IPNS {
|
|
|
190
175
|
sequenceNumber = existingRecord.sequence + 1n
|
|
191
176
|
}
|
|
192
177
|
|
|
193
|
-
let str
|
|
194
|
-
|
|
195
|
-
if (isPeerId(value)) {
|
|
196
|
-
str = `/ipns/${value.toString()}`
|
|
197
|
-
} else {
|
|
198
|
-
str = `/ipfs/${value.toString()}`
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const bytes = uint8ArrayFromString(str)
|
|
202
|
-
|
|
203
178
|
// create record
|
|
204
|
-
const record = await create(key,
|
|
179
|
+
const record = await create(key, value, sequenceNumber, options.lifetime ?? DEFAULT_LIFETIME_MS, options)
|
|
205
180
|
const marshaledRecord = marshal(record)
|
|
206
181
|
|
|
207
182
|
await this.localStore.put(routingKey, marshaledRecord, options)
|
|
@@ -221,9 +196,8 @@ class DefaultIPNS implements IPNS {
|
|
|
221
196
|
async resolve (key: PeerId, options: ResolveOptions = {}): Promise<CID> {
|
|
222
197
|
const routingKey = peerIdToRoutingKey(key)
|
|
223
198
|
const record = await this.#findIpnsRecord(routingKey, options)
|
|
224
|
-
const str = uint8ArrayToString(record.value)
|
|
225
199
|
|
|
226
|
-
return this.#resolve(
|
|
200
|
+
return this.#resolve(record.value, options)
|
|
227
201
|
}
|
|
228
202
|
|
|
229
203
|
async resolveDns (domain: string, options: ResolveDNSOptions = {}): Promise<CID> {
|
|
@@ -285,7 +259,7 @@ class DefaultIPNS implements IPNS {
|
|
|
285
259
|
throw new Error('Invalid value')
|
|
286
260
|
}
|
|
287
261
|
|
|
288
|
-
async #findIpnsRecord (routingKey: Uint8Array, options: ResolveOptions = {}): Promise<
|
|
262
|
+
async #findIpnsRecord (routingKey: Uint8Array, options: ResolveOptions = {}): Promise<IPNSRecord> {
|
|
289
263
|
let routers = [
|
|
290
264
|
this.localStore,
|
|
291
265
|
...this.routers
|