@helia/ipns 9.2.1-f6cc7640 → 10.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.
Files changed (66) hide show
  1. package/README.md +21 -57
  2. package/dist/index.min.js +5 -16
  3. package/dist/index.min.js.map +4 -4
  4. package/dist/src/errors.d.ts +33 -5
  5. package/dist/src/errors.d.ts.map +1 -1
  6. package/dist/src/errors.js +33 -20
  7. package/dist/src/errors.js.map +1 -1
  8. package/dist/src/index.d.ts +62 -99
  9. package/dist/src/index.d.ts.map +1 -1
  10. package/dist/src/index.js +21 -60
  11. package/dist/src/index.js.map +1 -1
  12. package/dist/src/ipns/publisher.d.ts +5 -9
  13. package/dist/src/ipns/publisher.d.ts.map +1 -1
  14. package/dist/src/ipns/publisher.js +30 -26
  15. package/dist/src/ipns/publisher.js.map +1 -1
  16. package/dist/src/ipns/republisher.d.ts +3 -5
  17. package/dist/src/ipns/republisher.d.ts.map +1 -1
  18. package/dist/src/ipns/republisher.js +18 -9
  19. package/dist/src/ipns/republisher.js.map +1 -1
  20. package/dist/src/ipns/resolver.d.ts +6 -5
  21. package/dist/src/ipns/resolver.d.ts.map +1 -1
  22. package/dist/src/ipns/resolver.js +32 -79
  23. package/dist/src/ipns/resolver.js.map +1 -1
  24. package/dist/src/ipns.d.ts +6 -4
  25. package/dist/src/ipns.d.ts.map +1 -1
  26. package/dist/src/ipns.js +33 -4
  27. package/dist/src/ipns.js.map +1 -1
  28. package/dist/src/pb/ipns.d.ts +62 -0
  29. package/dist/src/pb/ipns.d.ts.map +1 -0
  30. package/dist/src/pb/ipns.js +203 -0
  31. package/dist/src/pb/ipns.js.map +1 -0
  32. package/dist/src/records.d.ts +155 -0
  33. package/dist/src/records.d.ts.map +1 -0
  34. package/dist/src/records.js +88 -0
  35. package/dist/src/records.js.map +1 -0
  36. package/dist/src/routing/pubsub.d.ts +3 -0
  37. package/dist/src/routing/pubsub.d.ts.map +1 -1
  38. package/dist/src/routing/pubsub.js +15 -11
  39. package/dist/src/routing/pubsub.js.map +1 -1
  40. package/dist/src/selector.d.ts +14 -0
  41. package/dist/src/selector.d.ts.map +1 -0
  42. package/dist/src/selector.js +47 -0
  43. package/dist/src/selector.js.map +1 -0
  44. package/dist/src/utils.d.ts +29 -2
  45. package/dist/src/utils.d.ts.map +1 -1
  46. package/dist/src/utils.js +308 -0
  47. package/dist/src/utils.js.map +1 -1
  48. package/dist/src/validator.d.ts +18 -0
  49. package/dist/src/validator.d.ts.map +1 -0
  50. package/dist/src/validator.js +58 -0
  51. package/dist/src/validator.js.map +1 -0
  52. package/dist/typedoc-urls.json +49 -0
  53. package/package.json +16 -15
  54. package/src/errors.ts +40 -25
  55. package/src/index.ts +63 -100
  56. package/src/ipns/publisher.ts +34 -33
  57. package/src/ipns/republisher.ts +24 -13
  58. package/src/ipns/resolver.ts +40 -89
  59. package/src/ipns.ts +44 -7
  60. package/src/pb/ipns.proto +39 -0
  61. package/src/pb/ipns.ts +280 -0
  62. package/src/records.ts +273 -0
  63. package/src/routing/pubsub.ts +17 -11
  64. package/src/selector.ts +55 -0
  65. package/src/utils.ts +371 -2
  66. package/src/validator.ts +67 -0
@@ -0,0 +1,62 @@
1
+ import type { Codec, DecodeOptions } from 'protons-runtime';
2
+ import type { Uint8ArrayList } from 'uint8arraylist';
3
+ export interface IpnsEntry {
4
+ value?: Uint8Array;
5
+ signatureV1?: Uint8Array;
6
+ validityType?: IpnsEntry.ValidityType;
7
+ validity?: Uint8Array;
8
+ sequence?: bigint;
9
+ ttl?: bigint;
10
+ publicKey?: Uint8Array;
11
+ signatureV2?: Uint8Array;
12
+ data?: Uint8Array;
13
+ }
14
+ export declare namespace IpnsEntry {
15
+ enum ValidityType {
16
+ EOL = "EOL"
17
+ }
18
+ namespace ValidityType {
19
+ const codec: () => Codec<ValidityType>;
20
+ }
21
+ const codec: () => Codec<IpnsEntry>;
22
+ interface IpnsEntryValueFieldEvent {
23
+ field: '$.value';
24
+ value: Uint8Array;
25
+ }
26
+ interface IpnsEntrySignatureV1FieldEvent {
27
+ field: '$.signatureV1';
28
+ value: Uint8Array;
29
+ }
30
+ interface IpnsEntryValidityTypeFieldEvent {
31
+ field: '$.validityType';
32
+ value: IpnsEntry.ValidityType;
33
+ }
34
+ interface IpnsEntryValidityFieldEvent {
35
+ field: '$.validity';
36
+ value: Uint8Array;
37
+ }
38
+ interface IpnsEntrySequenceFieldEvent {
39
+ field: '$.sequence';
40
+ value: bigint;
41
+ }
42
+ interface IpnsEntryTtlFieldEvent {
43
+ field: '$.ttl';
44
+ value: bigint;
45
+ }
46
+ interface IpnsEntryPublicKeyFieldEvent {
47
+ field: '$.publicKey';
48
+ value: Uint8Array;
49
+ }
50
+ interface IpnsEntrySignatureV2FieldEvent {
51
+ field: '$.signatureV2';
52
+ value: Uint8Array;
53
+ }
54
+ interface IpnsEntryDataFieldEvent {
55
+ field: '$.data';
56
+ value: Uint8Array;
57
+ }
58
+ function encode(obj: Partial<IpnsEntry>): Uint8Array<ArrayBuffer>;
59
+ function decode(buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<IpnsEntry>): IpnsEntry;
60
+ function stream(buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<IpnsEntry>): Generator<IpnsEntryValueFieldEvent | IpnsEntrySignatureV1FieldEvent | IpnsEntryValidityTypeFieldEvent | IpnsEntryValidityFieldEvent | IpnsEntrySequenceFieldEvent | IpnsEntryTtlFieldEvent | IpnsEntryPublicKeyFieldEvent | IpnsEntrySignatureV2FieldEvent | IpnsEntryDataFieldEvent>;
61
+ }
62
+ //# sourceMappingURL=ipns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ipns.d.ts","sourceRoot":"","sources":["../../../src/pb/ipns.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEp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K,EAAE,eAAe,CAAA;QACtB,KAAK,EAAE,UAAU,CAAA;KAClB;IAED,UAAiB,uBAAuB;QACtC,KAAK,EAAE,QAAQ,CAAA;QACf,KAAK,EAAE,UAAU,CAAA;KAClB;IAED,SAAgB,MAAM,CAAE,GAAG,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC,CAExE;IAED,SAAgB,MAAM,CAAE,GAAG,EAAE,UAAU,GAAG,cAAc,EAAE,IAAI,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,GAAG,SAAS,CAEpG;IAED,SAAgB,MAAM,CAAE,GAAG,EAAE,UAAU,GAAG,cAAc,EAAE,IAAI,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC,wBAAwB,GAAG,8BAA8B,GAAG,+BAA+B,GAAG,2BAA2B,GAAG,2BAA2B,GAAG,sBAAsB,GAAG,4BAA4B,GAAG,8BAA8B,GAAG,uBAAuB,CAAC,CAEhX;CACF"}
@@ -0,0 +1,203 @@
1
+ import { decodeMessage, encodeMessage, enumeration, message, streamMessage } from 'protons-runtime';
2
+ export var IpnsEntry;
3
+ (function (IpnsEntry) {
4
+ let ValidityType;
5
+ (function (ValidityType) {
6
+ ValidityType["EOL"] = "EOL";
7
+ })(ValidityType = IpnsEntry.ValidityType || (IpnsEntry.ValidityType = {}));
8
+ let __ValidityTypeValues;
9
+ (function (__ValidityTypeValues) {
10
+ __ValidityTypeValues[__ValidityTypeValues["EOL"] = 0] = "EOL";
11
+ })(__ValidityTypeValues || (__ValidityTypeValues = {}));
12
+ (function (ValidityType) {
13
+ ValidityType.codec = () => {
14
+ return enumeration(__ValidityTypeValues);
15
+ };
16
+ })(ValidityType = IpnsEntry.ValidityType || (IpnsEntry.ValidityType = {}));
17
+ let _codec;
18
+ IpnsEntry.codec = () => {
19
+ if (_codec == null) {
20
+ _codec = message((obj, w, opts = {}) => {
21
+ if (opts.lengthDelimited !== false) {
22
+ w.fork();
23
+ }
24
+ if (obj.value != null) {
25
+ w.uint32(10);
26
+ w.bytes(obj.value);
27
+ }
28
+ if (obj.signatureV1 != null) {
29
+ w.uint32(18);
30
+ w.bytes(obj.signatureV1);
31
+ }
32
+ if (obj.validityType != null) {
33
+ w.uint32(24);
34
+ IpnsEntry.ValidityType.codec().encode(obj.validityType, w);
35
+ }
36
+ if (obj.validity != null) {
37
+ w.uint32(34);
38
+ w.bytes(obj.validity);
39
+ }
40
+ if (obj.sequence != null) {
41
+ w.uint32(40);
42
+ w.uint64(obj.sequence);
43
+ }
44
+ if (obj.ttl != null) {
45
+ w.uint32(48);
46
+ w.uint64(obj.ttl);
47
+ }
48
+ if (obj.publicKey != null) {
49
+ w.uint32(58);
50
+ w.bytes(obj.publicKey);
51
+ }
52
+ if (obj.signatureV2 != null) {
53
+ w.uint32(66);
54
+ w.bytes(obj.signatureV2);
55
+ }
56
+ if (obj.data != null) {
57
+ w.uint32(74);
58
+ w.bytes(obj.data);
59
+ }
60
+ if (opts.lengthDelimited !== false) {
61
+ w.ldelim();
62
+ }
63
+ }, (reader, length, opts = {}) => {
64
+ const obj = {};
65
+ const end = length == null ? reader.len : reader.pos + length;
66
+ while (reader.pos < end) {
67
+ const tag = reader.uint32();
68
+ switch (tag >>> 3) {
69
+ case 1: {
70
+ obj.value = reader.bytes();
71
+ break;
72
+ }
73
+ case 2: {
74
+ obj.signatureV1 = reader.bytes();
75
+ break;
76
+ }
77
+ case 3: {
78
+ obj.validityType = IpnsEntry.ValidityType.codec().decode(reader);
79
+ break;
80
+ }
81
+ case 4: {
82
+ obj.validity = reader.bytes();
83
+ break;
84
+ }
85
+ case 5: {
86
+ obj.sequence = reader.uint64();
87
+ break;
88
+ }
89
+ case 6: {
90
+ obj.ttl = reader.uint64();
91
+ break;
92
+ }
93
+ case 7: {
94
+ obj.publicKey = reader.bytes();
95
+ break;
96
+ }
97
+ case 8: {
98
+ obj.signatureV2 = reader.bytes();
99
+ break;
100
+ }
101
+ case 9: {
102
+ obj.data = reader.bytes();
103
+ break;
104
+ }
105
+ default: {
106
+ reader.skipType(tag & 7);
107
+ break;
108
+ }
109
+ }
110
+ }
111
+ return obj;
112
+ }, function* (reader, length, prefix, opts = {}) {
113
+ const end = length == null ? reader.len : reader.pos + length;
114
+ while (reader.pos < end) {
115
+ const tag = reader.uint32();
116
+ switch (tag >>> 3) {
117
+ case 1: {
118
+ yield {
119
+ field: `${prefix}.value`,
120
+ value: reader.bytes()
121
+ };
122
+ break;
123
+ }
124
+ case 2: {
125
+ yield {
126
+ field: `${prefix}.signatureV1`,
127
+ value: reader.bytes()
128
+ };
129
+ break;
130
+ }
131
+ case 3: {
132
+ yield {
133
+ field: `${prefix}.validityType`,
134
+ value: IpnsEntry.ValidityType.codec().decode(reader)
135
+ };
136
+ break;
137
+ }
138
+ case 4: {
139
+ yield {
140
+ field: `${prefix}.validity`,
141
+ value: reader.bytes()
142
+ };
143
+ break;
144
+ }
145
+ case 5: {
146
+ yield {
147
+ field: `${prefix}.sequence`,
148
+ value: reader.uint64()
149
+ };
150
+ break;
151
+ }
152
+ case 6: {
153
+ yield {
154
+ field: `${prefix}.ttl`,
155
+ value: reader.uint64()
156
+ };
157
+ break;
158
+ }
159
+ case 7: {
160
+ yield {
161
+ field: `${prefix}.publicKey`,
162
+ value: reader.bytes()
163
+ };
164
+ break;
165
+ }
166
+ case 8: {
167
+ yield {
168
+ field: `${prefix}.signatureV2`,
169
+ value: reader.bytes()
170
+ };
171
+ break;
172
+ }
173
+ case 9: {
174
+ yield {
175
+ field: `${prefix}.data`,
176
+ value: reader.bytes()
177
+ };
178
+ break;
179
+ }
180
+ default: {
181
+ reader.skipType(tag & 7);
182
+ break;
183
+ }
184
+ }
185
+ }
186
+ });
187
+ }
188
+ return _codec;
189
+ };
190
+ function encode(obj) {
191
+ return encodeMessage(obj, IpnsEntry.codec());
192
+ }
193
+ IpnsEntry.encode = encode;
194
+ function decode(buf, opts) {
195
+ return decodeMessage(buf, IpnsEntry.codec(), opts);
196
+ }
197
+ IpnsEntry.decode = decode;
198
+ function stream(buf, opts) {
199
+ return streamMessage(buf, IpnsEntry.codec(), opts);
200
+ }
201
+ IpnsEntry.stream = stream;
202
+ })(IpnsEntry || (IpnsEntry = {}));
203
+ //# sourceMappingURL=ipns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ipns.js","sourceRoot":"","sources":["../../../src/pb/ipns.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAgBnG,MAAM,KAAW,SAAS,CAuQzB;AAvQD,WAAiB,SAAS;IACxB,IAAY,YAEX;IAFD,WAAY,YAAY;QACtB,2BAAW,CAAA;IACb,CAAC,EAFW,YAAY,GAAZ,sBAAY,KAAZ,sBAAY,QAEvB;IAED,IAAK,oBAEJ;IAFD,WAAK,oBAAoB;QACvB,6DAAO,CAAA;IACT,CAAC,EAFI,oBAAoB,KAApB,oBAAoB,QAExB;IAED,WAAiB,YAAY;QACd,kBAAK,GAAG,GAAwB,EAAE;YAC7C,OAAO,WAAW,CAAe,oBAAoB,CAAC,CAAA;QACxD,CAAC,CAAA;IACH,CAAC,EAJgB,YAAY,GAAZ,sBAAY,KAAZ,sBAAY,QAI5B;IAED,IAAI,MAAwB,CAAA;IAEf,eAAK,GAAG,GAAqB,EAAE;QAC1C,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;YACnB,MAAM,GAAG,OAAO,CAAY,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE;gBAChD,IAAI,IAAI,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;oBACnC,CAAC,CAAC,IAAI,EAAE,CAAA;gBACV,CAAC;gBAED,IAAI,GAAG,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;oBACtB,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;oBACZ,CAAC,CAAC,KAA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ACD,MAAK;wBACP,CAAC;wBACD,KAAK,CAAC,CAAC,CAAC,CAAC;4BACP,MAAM;gCACJ,KAAK,EAAE,GAAG,MAAM,cAAc;gCAC9B,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE;6BACtB,CAAA;4BACD,MAAK;wBACP,CAAC;wBACD,KAAK,CAAC,CAAC,CAAC,CAAC;4BACP,MAAM;gCACJ,KAAK,EAAE,GAAG,MAAM,OAAO;gCACvB,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE;6BACtB,CAAA;4BACD,MAAK;wBACP,CAAC;wBACD,OAAO,CAAC,CAAC,CAAC;4BACR,MAAM,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;4BACxB,MAAK;wBACP,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;IA+CD,SAAgB,MAAM,CAAE,GAAuB;QAC7C,OAAO,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC,CAAA;IAC9C,CAAC;IAFe,gBAAM,SAErB,CAAA;IAED,SAAgB,MAAM,CAAE,GAAgC,EAAE,IAA+B;QACvF,OAAO,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAA;IACpD,CAAC;IAFe,gBAAM,SAErB,CAAA;IAED,SAAgB,MAAM,CAAE,GAAgC,EAAE,IAA+B;QACvF,OAAO,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAA;IACpD,CAAC;IAFe,gBAAM,SAErB,CAAA;AACH,CAAC,EAvQgB,SAAS,KAAT,SAAS,QAuQzB"}
@@ -0,0 +1,155 @@
1
+ import { IpnsEntry } from './pb/ipns.ts';
2
+ import type { PrivateKey, PublicKey } from '@helia/interface';
3
+ import type { AbortOptions } from 'abort-error';
4
+ import type { Key } from 'interface-datastore/key';
5
+ export declare const namespace = "/ipns/";
6
+ export declare const namespaceLength: number;
7
+ export interface IPNSRecordV1V2 {
8
+ /**
9
+ * value of the record
10
+ */
11
+ value: string;
12
+ /**
13
+ * signature of the record
14
+ */
15
+ signatureV1: Uint8Array;
16
+ /**
17
+ * Type of validation being used
18
+ */
19
+ validityType: IpnsEntry.ValidityType;
20
+ /**
21
+ * expiration datetime for the record in RFC3339 format
22
+ */
23
+ validity: string;
24
+ /**
25
+ * number representing the version of the record
26
+ */
27
+ sequence: bigint;
28
+ /**
29
+ * ttl in nanoseconds
30
+ */
31
+ ttl?: bigint;
32
+ /**
33
+ * the public portion of the key that signed this record
34
+ */
35
+ publicKey: PublicKey;
36
+ /**
37
+ * the v2 signature of the record
38
+ */
39
+ signatureV2: Uint8Array;
40
+ /**
41
+ * extensible data
42
+ */
43
+ data: Uint8Array;
44
+ /**
45
+ * The marshalled record
46
+ */
47
+ bytes: Uint8Array;
48
+ }
49
+ export interface IPNSRecordV2 {
50
+ /**
51
+ * value of the record
52
+ */
53
+ value: string;
54
+ /**
55
+ * the v2 signature of the record
56
+ */
57
+ signatureV2: Uint8Array;
58
+ /**
59
+ * Type of validation being used
60
+ */
61
+ validityType: IpnsEntry.ValidityType;
62
+ /**
63
+ * If the validity type is EOL, this is the expiration datetime for the record
64
+ * in RFC3339 format
65
+ */
66
+ validity: string;
67
+ /**
68
+ * number representing the version of the record
69
+ */
70
+ sequence: bigint;
71
+ /**
72
+ * ttl in nanoseconds
73
+ */
74
+ ttl?: bigint;
75
+ /**
76
+ * the public portion of the key that signed this record
77
+ */
78
+ publicKey: PublicKey;
79
+ /**
80
+ * extensible data
81
+ */
82
+ data: Uint8Array;
83
+ /**
84
+ * The marshalled record
85
+ */
86
+ bytes: Uint8Array;
87
+ }
88
+ export type IPNSRecord = IPNSRecordV1V2 | IPNSRecordV2;
89
+ export interface IPNSRecordData {
90
+ Value: Uint8Array;
91
+ Validity: Uint8Array;
92
+ ValidityType: IpnsEntry.ValidityType;
93
+ Sequence: bigint;
94
+ TTL: bigint;
95
+ }
96
+ export interface IDKeys {
97
+ routingPubKey: Key;
98
+ pkKey: Key;
99
+ routingKey: Key;
100
+ ipnsKey: Key;
101
+ }
102
+ export interface CreateOptions extends AbortOptions {
103
+ ttlNs?: number | bigint;
104
+ v1Compatible?: boolean;
105
+ }
106
+ export interface CreateV2OrV1Options extends AbortOptions {
107
+ v1Compatible: true;
108
+ }
109
+ export interface CreateV2Options extends AbortOptions {
110
+ v1Compatible: false;
111
+ }
112
+ /**
113
+ * Creates a new IPNS record and signs it with the given private key.
114
+ * The IPNS Record validity should follow the [RFC3339]{@link https://www.ietf.org/rfc/rfc3339.txt} with nanoseconds precision.
115
+ * Note: This function does not embed the public key. If you want to do that, use `EmbedPublicKey`.
116
+ *
117
+ * The passed value can be a CID, a PublicKey or an arbitrary string path e.g. `/ipfs/...` or `/ipns/...`.
118
+ *
119
+ * CIDs will be converted to v1 and stored in the record as a string similar to: `/ipfs/${cid}`
120
+ * PublicKeys will create recursive records, eg. the record value will be `/ipns/${cidV1Libp2pKey}`
121
+ * String paths will be stored in the record as-is, but they must start with `"/"`
122
+ *
123
+ * @param {PrivateKey} privateKey - the private key for signing the record.
124
+ * @param {CID | PublicKey | string} value - content to be stored in the record.
125
+ * @param {number | bigint} seq - number representing the current version of the record.
126
+ * @param {number} lifetime - lifetime of the record (in milliseconds).
127
+ * @param {CreateOptions} options - additional create options.
128
+ */
129
+ export declare function createIPNSRecord(privateKey: PrivateKey, value: string, seq: number | bigint, lifetime: number, options?: CreateV2OrV1Options): Promise<IPNSRecordV1V2>;
130
+ export declare function createIPNSRecord(privateKey: PrivateKey, value: string, seq: number | bigint, lifetime: number, options: CreateV2Options): Promise<IPNSRecordV2>;
131
+ export declare function createIPNSRecord(privateKey: PrivateKey, value: string, seq: number | bigint, lifetime: number, options: CreateOptions): Promise<IPNSRecordV1V2>;
132
+ /**
133
+ * Same as create(), but instead of generating a new Date, it receives the intended expiration time
134
+ * WARNING: nano precision is not standard, make sure the value in seconds is 9 orders of magnitude lesser than the one provided.
135
+ *
136
+ * The passed value can be a CID, a PublicKey or an arbitrary string path e.g. `/ipfs/...` or `/ipns/...`.
137
+ *
138
+ * CIDs will be converted to v1 and stored in the record as a string similar to: `/ipfs/${cid}`
139
+ * PublicKeys will create recursive records, eg. the record value will be `/ipns/${cidV1Libp2pKey}`
140
+ * String paths will be stored in the record as-is, but they must start with `"/"`
141
+ *
142
+ * @param {PrivateKey} privateKey - the private key for signing the record.
143
+ * @param {CID | PublicKey | string} value - content to be stored in the record.
144
+ * @param {number | bigint} seq - number representing the current version of the record.
145
+ * @param {string} expiration - expiration datetime for record in the [RFC3339]{@link https://www.ietf.org/rfc/rfc3339.txt} with nanoseconds precision.
146
+ * @param {CreateOptions} options - additional creation options.
147
+ */
148
+ export declare function createIPNSRecordWithExpiration(privateKey: PrivateKey, value: string, seq: number | bigint, expiration: string, options?: CreateV2OrV1Options): Promise<IPNSRecordV1V2>;
149
+ export declare function createIPNSRecordWithExpiration(privateKey: PrivateKey, value: string, seq: number | bigint, expiration: string, options: CreateV2Options): Promise<IPNSRecordV2>;
150
+ export declare function createIPNSRecordWithExpiration(privateKey: PrivateKey, value: string, seq: number | bigint, expiration: string, options: CreateOptions): Promise<IPNSRecordV1V2>;
151
+ export { unmarshalIPNSRecord } from './utils.ts';
152
+ export { marshalIPNSRecord } from './utils.ts';
153
+ export { multihashToIPNSRoutingKey } from './utils.ts';
154
+ export { multihashFromIPNSRoutingKey } from './utils.ts';
155
+ //# sourceMappingURL=records.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../../src/records.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AA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GAAG,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAC9L,wBAAsB,8BAA8B,CAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;AACvL,wBAAsB,8BAA8B,CAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAkDvL,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AACtD,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,88 @@
1
+ import { logger } from '@libp2p/logger';
2
+ import NanoDate from 'timestamp-nano';
3
+ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
4
+ import { SignatureCreationError } from "./errors.js";
5
+ import { IpnsEntry } from "./pb/ipns.js";
6
+ import { createCborData, ipnsRecordDataForV1Sig, ipnsRecordDataForV2Sig, marshalIPNSRecord } from "./utils.js";
7
+ const log = logger('ipns');
8
+ const DEFAULT_TTL_NS = 5 * 60 * 1e+9; // 5 Minutes or 300 Seconds, as suggested by https://specs.ipfs.tech/ipns/ipns-record/#ttl-uint64
9
+ export const namespace = '/ipns/';
10
+ export const namespaceLength = namespace.length;
11
+ const defaultCreateOptions = {
12
+ v1Compatible: true,
13
+ ttlNs: DEFAULT_TTL_NS
14
+ };
15
+ export async function createIPNSRecord(privateKey, value, seq, lifetime, options = defaultCreateOptions) {
16
+ // Validity in ISOString with nanoseconds precision and validity type EOL
17
+ const expirationDate = new NanoDate(Date.now() + Number(lifetime));
18
+ const validityType = IpnsEntry.ValidityType.EOL;
19
+ const ttlNs = BigInt(options.ttlNs ?? DEFAULT_TTL_NS);
20
+ return _create(privateKey, value, seq, validityType, expirationDate.toString(), ttlNs, options);
21
+ }
22
+ export async function createIPNSRecordWithExpiration(privateKey, value, seq, expiration, options = defaultCreateOptions) {
23
+ const expirationDate = NanoDate.fromString(expiration);
24
+ const validityType = IpnsEntry.ValidityType.EOL;
25
+ const ttlNs = BigInt(options.ttlNs ?? DEFAULT_TTL_NS);
26
+ return _create(privateKey, value, seq, validityType, expirationDate.toString(), ttlNs, options);
27
+ }
28
+ const _create = async (privateKey, value, seq, validityType, validity, ttl, options = defaultCreateOptions) => {
29
+ seq = BigInt(seq);
30
+ const isoValidity = uint8ArrayFromString(validity);
31
+ const data = createCborData(value, validityType, isoValidity, seq, ttl);
32
+ const sigData = ipnsRecordDataForV2Sig(data);
33
+ const signatureV2 = await privateKey.sign(sigData, options);
34
+ const publicKey = shouldEmbedPublicKey(privateKey.publicKey) ? privateKey.publicKey : undefined;
35
+ let record;
36
+ if (options.v1Compatible === true) {
37
+ const signatureV1 = await signLegacyV1(privateKey, value, validityType, isoValidity);
38
+ record = {
39
+ value,
40
+ signatureV1,
41
+ validity,
42
+ validityType,
43
+ sequence: seq,
44
+ ttl,
45
+ signatureV2,
46
+ data,
47
+ publicKey
48
+ };
49
+ }
50
+ else {
51
+ record = {
52
+ value,
53
+ validity,
54
+ validityType,
55
+ sequence: seq,
56
+ ttl,
57
+ signatureV2,
58
+ data,
59
+ publicKey
60
+ };
61
+ }
62
+ record.bytes = marshalIPNSRecord(record);
63
+ return record;
64
+ };
65
+ export { unmarshalIPNSRecord } from "./utils.js";
66
+ export { marshalIPNSRecord } from "./utils.js";
67
+ export { multihashToIPNSRoutingKey } from "./utils.js";
68
+ export { multihashFromIPNSRoutingKey } from "./utils.js";
69
+ /**
70
+ * Sign ipns record data using the legacy V1 signature scheme
71
+ */
72
+ const signLegacyV1 = async (privateKey, value, validityType, validity, options) => {
73
+ try {
74
+ const dataForSignature = ipnsRecordDataForV1Sig(value, validityType, validity);
75
+ return await privateKey.sign(dataForSignature, options);
76
+ }
77
+ catch (error) {
78
+ log.error('record signature creation failed', error);
79
+ throw new SignatureCreationError('Record signature creation failed');
80
+ }
81
+ };
82
+ /**
83
+ * Returns true if the public key multihash is not an identity hash
84
+ */
85
+ function shouldEmbedPublicKey(key) {
86
+ return key.toMultihash().code !== 0;
87
+ }
88
+ //# sourceMappingURL=records.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records.js","sourceRoot":"","sources":["../../src/records.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,QAAQ,MAAM,gBAAgB,CAAA;AACrC,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAK9G,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;AAC1B,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA,CAAC,iGAAiG;AAEtI,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAA;AACjC,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC,MAAM,CAAA;AAoI/C,MAAM,oBAAoB,GAAkB;IAC1C,YAAY,EAAE,IAAI;IAClB,KAAK,EAAE,cAAc;CACtB,CAAA;AAsBD,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAE,UAAsB,EAAE,KAAa,EAAE,GAAoB,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H,MAAM,gBAAgB,GAAG,sBAAsB,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAA;QAE9E,OAAO,MAAM,UAAU,CAAC,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAA;IACzD,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,GAAG,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAA;QACpD,MAAM,IAAI,sBAAsB,CAAC,kCAAkC,CAAC,CAAA;IACtE,CAAC;AACH,CAAC,CAAA;AAED;;GAEG;AACH,SAAS,oBAAoB,CAAE,GAAc;IAC3C,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC,IAAI,KAAK,CAAC,CAAA;AACrC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import type { GetOptions, IPNSRouting, PutOptions } from './index.ts';
2
+ import type { Keychain } from '@helia/interface';
2
3
  import type { Fetch } from '@libp2p/fetch';
3
4
  import type { PeerId, PublicKey, TypedEventTarget, ComponentLogger, Startable, Metrics, Libp2p } from '@libp2p/interface';
4
5
  import type { Datastore } from 'interface-datastore';
@@ -35,6 +36,7 @@ export interface PubSub extends TypedEventTarget<PubSubEvents> {
35
36
  export interface PubsubRoutingComponents {
36
37
  datastore: Datastore;
37
38
  logger: ComponentLogger;
39
+ keychain: Keychain;
38
40
  metrics?: Metrics;
39
41
  libp2p: Pick<Libp2p<{
40
42
  pubsub: PubSub;
@@ -79,6 +81,7 @@ export declare class PubSubRouting implements IPNSRouting, Startable {
79
81
  private readonly fetchPeers;
80
82
  private shutdownController;
81
83
  private fetchTopologyId?;
84
+ private keychain;
82
85
  constructor(components: PubsubRoutingComponents, init?: PubsubRoutingInit);
83
86
  /**
84
87
  * Put a value to the pubsub datastore indexed by the received key properly encoded
@@ -1 +1 @@
1
- {"version":3,"file":"pubsub.d.ts","sourceRoot":"","sources":["../../../src/routing/pubsub.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,UAAU,EAAE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C,IAAI,CAAC;IAgBxG;;;;OAIG;IACG,GAAG,CAAE,UAAU,EAAE,UAAU,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,UAAU,CAAC;IAuDjF;;OAEG;IACH,gBAAgB,IAAK,MAAM,EAAE;IAI7B;;OAEG;IACH,MAAM,CAAE,GAAG,EAAE,SAAS,GAAG,eAAe,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,IAAI;IAe5D,QAAQ,IAAK,MAAM;IAIb,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAkB7B,IAAI,IAAK,IAAI;CAQd;AA0BD;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAE,UAAU,EAAE,uBAAuB,EAAE,IAAI,GAAE,iBAAsB,GAAG,WAAW,CAEtG"}
@@ -4,9 +4,6 @@ import { PeerSet } from '@libp2p/peer-collections';
4
4
  import { Queue } from '@libp2p/utils';
5
5
  import { anySignal } from 'any-signal';
6
6
  import delay from 'delay';
7
- import { multihashToIPNSRoutingKey } from 'ipns';
8
- import { ipnsSelector } from 'ipns/selector';
9
- import { ipnsValidator } from 'ipns/validator';
10
7
  import { CustomProgressEvent } from 'progress-events';
11
8
  import { raceSignal } from 'race-signal';
12
9
  import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
@@ -14,7 +11,10 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
14
11
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
15
12
  import { InvalidTopicError } from "../errors.js";
16
13
  import { localStore } from "../local-store.js";
17
- import { IPNS_STRING_PREFIX } from "../utils.js";
14
+ import { multihashToIPNSRoutingKey } from "../records.js";
15
+ import { ipnsSelector } from "../selector.js";
16
+ import { IPNS_STRING_PREFIX, unmarshalIPNSRecord } from "../utils.js";
17
+ import { ipnsValidator } from "../validator.js";
18
18
  const log = logger('helia:ipns:routing:pubsub');
19
19
  export class PubSubRouting {
20
20
  subscriptions;
@@ -27,6 +27,7 @@ export class PubSubRouting {
27
27
  fetchPeers;
28
28
  shutdownController;
29
29
  fetchTopologyId;
30
+ keychain;
30
31
  constructor(components, init = {}) {
31
32
  this.subscriptions = new Set();
32
33
  this.shutdownController = new AbortController();
@@ -36,6 +37,7 @@ export class PubSubRouting {
36
37
  this.libp2p = components.libp2p;
37
38
  this.fetchConcurrency = init.fetchConcurrency ?? 8;
38
39
  this.fetchDelay = init.fetchDelay ?? 0;
40
+ this.keychain = components.keychain;
39
41
  // default libp2p-fetch timeout is 10 seconds - we should have an existing
40
42
  // connection to the peer so this can be shortened
41
43
  this.fetchTimeout = init.fetchTimeout ?? 2_500;
@@ -138,19 +140,21 @@ export class PubSubRouting {
138
140
  return this.#handleRecord(topic, routingKey, marshalledRecord, true, options);
139
141
  }
140
142
  async #handleRecord(topic, routingKey, marshalledRecord, publish, options) {
141
- await ipnsValidator(routingKey, marshalledRecord);
143
+ const record = await unmarshalIPNSRecord(routingKey, marshalledRecord, this.keychain, options);
144
+ await ipnsValidator(record, options);
142
145
  this.shutdownController.signal.throwIfAborted();
143
146
  if (await this.localStore.has(routingKey)) {
144
- const { record: currentRecord } = await this.localStore.get(routingKey, options);
145
- if (uint8ArrayEquals(currentRecord, marshalledRecord)) {
147
+ const { record: marshaledCurrentRecord } = await this.localStore.get(routingKey, options);
148
+ const currentRecord = await unmarshalIPNSRecord(routingKey, marshaledCurrentRecord, this.keychain, options);
149
+ if (uint8ArrayEquals(marshaledCurrentRecord, record.bytes)) {
146
150
  log.trace('found identical record for %m', routingKey);
147
- return currentRecord;
151
+ return currentRecord.bytes;
148
152
  }
149
- const records = [currentRecord, marshalledRecord];
153
+ const records = [currentRecord, record];
150
154
  const index = ipnsSelector(routingKey, records);
151
155
  if (index === 0) {
152
156
  log.trace('found old record for %m', routingKey);
153
- return currentRecord;
157
+ return currentRecord.bytes;
154
158
  }
155
159
  }
156
160
  log('found new record for %m', routingKey);
@@ -244,7 +248,7 @@ export class PubSubRouting {
244
248
  */
245
249
  cancel(key) {
246
250
  const digest = isPublicKey(key) ? key.toMultihash() : key;
247
- // @ts-expect-error @libp2p/crypto needs new multiformats
251
+ // @ ts-expect-error @libp2p/crypto needs new multiformats
248
252
  const routingKey = multihashToIPNSRoutingKey(digest);
249
253
  const topic = keyToTopic(routingKey);
250
254
  // Not found topic