@@ -38,46 +38,46 @@ const namespace = '/ipns/'
38
38
* Note: This function does not embed the public key. If you want to do that, use `EmbedPublicKey`.
39
39
*
40
40
* @param {PrivateKey } privateKey - private key for signing the record.
41
- * @param {string } value - value to be stored in the record.
41
+ * @param {Uint8Array } value - value to be stored in the record.
42
42
* @param {number } seq - number representing the current version of the record.
43
- * @param {number|string } lifetime - lifetime of the record (in milliseconds).
43
+ * @param {number } lifetime - lifetime of the record (in milliseconds).
44
44
*/
45
45
const create = ( privateKey , value , seq , lifetime ) => {
46
46
// Validity in ISOString with nanoseconds precision and validity type EOL
47
47
const isoValidity = new NanoDate ( Date . now ( ) + Number ( lifetime ) ) . toString ( )
48
48
const validityType = ipnsEntryProto . ValidityType . EOL
49
- return _create ( privateKey , value , seq , isoValidity , validityType )
49
+ return _create ( privateKey , value , seq , uint8ArrayFromString ( isoValidity ) , validityType )
50
50
}
51
51
52
52
/**
53
53
* Same as create(), but instead of generating a new Date, it receives the intended expiration time
54
54
* WARNING: nano precision is not standard, make sure the value in seconds is 9 orders of magnitude lesser than the one provided.
55
55
*
56
56
* @param {PrivateKey } privateKey - private key for signing the record.
57
- * @param {string } value - value to be stored in the record.
57
+ * @param {Uint8Array } value - value to be stored in the record.
58
58
* @param {number } seq - number representing the current version of the record.
59
59
* @param {string } expiration - expiration datetime for record in the [RFC3339]{@link https://www.ietf.org/rfc/rfc3339.txt} with nanoseconds precision.
60
60
*/
61
61
const createWithExpiration = ( privateKey , value , seq , expiration ) => {
62
62
const validityType = ipnsEntryProto . ValidityType . EOL
63
- return _create ( privateKey , value , seq , expiration , validityType )
63
+ return _create ( privateKey , value , seq , uint8ArrayFromString ( expiration ) , validityType )
64
64
}
65
65
66
66
/**
67
67
* @param {PrivateKey } privateKey
68
- * @param {string } value
68
+ * @param {Uint8Array } value
69
69
* @param {number } seq
70
- * @param {string } isoValidity
70
+ * @param {Uint8Array } isoValidity
71
71
* @param {number } validityType
72
72
*/
73
73
const _create = async ( privateKey , value , seq , isoValidity , validityType ) => {
74
74
const signature = await sign ( privateKey , value , validityType , isoValidity )
75
75
76
76
const entry = {
77
- value : uint8ArrayFromString ( value ) ,
77
+ value,
78
78
signature : signature ,
79
79
validityType : validityType ,
80
- validity : uint8ArrayFromString ( isoValidity ) ,
80
+ validity : isoValidity ,
81
81
sequence : seq
82
82
}
83
83
@@ -248,9 +248,9 @@ const getIdKeys = (pid) => {
248
248
* Sign ipns record data
249
249
*
250
250
* @param {PrivateKey } privateKey
251
- * @param {string } value
251
+ * @param {Uint8Array } value
252
252
* @param {number } validityType
253
- * @param {Uint8Array | string } validity
253
+ * @param {Uint8Array } validity
254
254
*/
255
255
const sign = ( privateKey , value , validityType , validity ) => {
256
256
try {
@@ -281,19 +281,11 @@ const getValidityType = (validityType) => {
281
281
/**
282
282
* Utility for creating the record data for being signed
283
283
*
284
- * @param {string | Uint8Array } value
284
+ * @param {Uint8Array } value
285
285
* @param {number } validityType
286
- * @param {string | Uint8Array } validity
286
+ * @param {Uint8Array } validity
287
287
*/
288
288
const ipnsEntryDataForSig = ( value , validityType , validity ) => {
289
- if ( ! ( value instanceof Uint8Array ) ) {
290
- value = uint8ArrayFromString ( value )
291
- }
292
-
293
- if ( ! ( validity instanceof Uint8Array ) ) {
294
- validity = uint8ArrayFromString ( validity )
295
- }
296
-
297
289
const validityTypeBuffer = uint8ArrayFromString ( getValidityType ( validityType ) )
298
290
299
291
return uint8ArrayConcat ( [ value , validity , validityTypeBuffer ] )
@@ -327,14 +319,21 @@ const marshal = (obj) => {
327
319
*/
328
320
const unmarshal = ( buf ) => {
329
321
const message = ipnsEntryProto . decode ( buf )
330
-
331
- // @ts -ignore
332
- return ipnsEntryProto . toObject ( message , {
322
+ const object = ipnsEntryProto . toObject ( message , {
333
323
defaults : false ,
334
324
arrays : true ,
335
325
longs : Number ,
336
326
objects : false
337
327
} )
328
+
329
+ return {
330
+ value : object . value ,
331
+ signature : object . signature ,
332
+ validityType : object . validityType ,
333
+ validity : object . validity ,
334
+ sequence : object . sequence ,
335
+ pubKey : object . pubKey
336
+ }
338
337
}
339
338
340
339
const validator = {
0 commit comments