@@ -9,12 +9,18 @@ import {
9
9
ValidationError ,
10
10
} from "../deps.ts" ;
11
11
12
- import { logSelectedOutputFormat , throwApiError } from "../utils.ts" ;
12
+ import {
13
+ logSelectedOutputFormat ,
14
+ signItemData ,
15
+ throwApiError ,
16
+ } from "../utils.ts" ;
13
17
14
18
import { createDataDir , writeItemToDb } from "../db.ts" ;
15
19
16
20
import { environmentType , outputType } from "../cli.ts" ;
17
21
22
+ import { ItemRequest , ItemRequestSchema } from "../types.ts" ;
23
+
18
24
export const inputType = new EnumType ( [ "binary" , "json" ] ) ;
19
25
20
26
// Limit the available hash types for now to those that are supported by the browser
@@ -28,6 +34,7 @@ const itemsCreate = new Command<{
28
34
env : typeof environmentType ;
29
35
apiKey ?: string ;
30
36
output : typeof outputType ;
37
+ signingKeySeed ?: string ;
31
38
} > ( )
32
39
. description (
33
40
`Create a new Item.
@@ -281,40 +288,60 @@ Pipe JSON content to the 'items create' command using '--input json' plus the '-
281
288
try {
282
289
let itemResp ;
283
290
291
+ const createItemArgs = {
292
+ skipCF : ! options . netMetadata ,
293
+ skipOE : ! options . observableEntropy ,
294
+ } ;
295
+
284
296
if ( jsonItem ) {
285
- itemResp = await truestamp . createItem ( jsonItem , {
286
- skipCF : ! options . netMetadata ,
287
- skipOE : ! options . observableEntropy ,
288
- } ) ;
297
+ const itemRequest : ItemRequest = ItemRequestSchema . parse ( jsonItem ) ;
298
+
299
+ itemRequest . itemDataSignatures = options . signingKeySeed
300
+ ? signItemData ( itemRequest , options . signingKeySeed )
301
+ : undefined ;
302
+
303
+ console . log ( "itemRequest" , JSON . stringify ( itemRequest , null , 2 ) ) ;
304
+
305
+ itemResp = await truestamp . createItem ( itemRequest , createItemArgs ) ;
289
306
} else if ( options . hash && options . hashType ) {
307
+ const itemRequest : ItemRequest = {
308
+ itemData : [
309
+ {
310
+ hash : options . hash ,
311
+ hashType : < HashTypes > options . hashType ,
312
+ } ,
313
+ ] ,
314
+ } ;
315
+
316
+ itemRequest . itemDataSignatures = options . signingKeySeed
317
+ ? signItemData ( itemRequest , options . signingKeySeed )
318
+ : undefined ;
319
+
320
+ // console.log("itemRequest", JSON.stringify(itemRequest, null, 2));
321
+
290
322
itemResp = await truestamp . createItem (
291
- {
292
- itemData : [
293
- {
294
- hash : options . hash ,
295
- hashType : < HashTypes > options . hashType ,
296
- } ,
297
- ] ,
298
- } ,
299
- {
300
- skipCF : ! options . netMetadata ,
301
- skipOE : ! options . observableEntropy ,
302
- } ,
323
+ itemRequest ,
324
+ createItemArgs ,
303
325
) ;
304
326
} else if ( altHash && altHashType ) {
327
+ const itemRequest : ItemRequest = {
328
+ itemData : [
329
+ {
330
+ hash : altHash ,
331
+ hashType : < HashTypes > altHashType ,
332
+ } ,
333
+ ] ,
334
+ } ;
335
+
336
+ itemRequest . itemDataSignatures = options . signingKeySeed
337
+ ? signItemData ( itemRequest , options . signingKeySeed )
338
+ : undefined ;
339
+
340
+ // console.log("itemRequest", JSON.stringify(itemRequest, null, 2));
341
+
305
342
itemResp = await truestamp . createItem (
306
- {
307
- itemData : [
308
- {
309
- hash : altHash ,
310
- hashType : < HashTypes > altHashType ,
311
- } ,
312
- ] ,
313
- } ,
314
- {
315
- skipCF : ! options . netMetadata ,
316
- skipOE : ! options . observableEntropy ,
317
- } ,
343
+ itemRequest ,
344
+ createItemArgs ,
318
345
) ;
319
346
} else {
320
347
throw new Error ( "No hash or hash-type provided" ) ;
@@ -369,6 +396,7 @@ const itemsUpdate = new Command<{
369
396
env : typeof environmentType ;
370
397
apiKey ?: string ;
371
398
output : typeof outputType ;
399
+ signingKeySeed ?: string ;
372
400
} > ( )
373
401
. description (
374
402
`Update an existing Item by replacing it with a new one.
@@ -569,45 +597,69 @@ Pipe JSON content to the 'items update' command using '--input json' plus the '-
569
597
try {
570
598
let itemResp ;
571
599
600
+ const updateItemsArgs = {
601
+ skipCF : ! options . netMetadata ,
602
+ skipOE : ! options . observableEntropy ,
603
+ } ;
604
+
572
605
if ( jsonItem ) {
573
- itemResp = await truestamp . updateItem ( options . id , jsonItem , {
574
- skipCF : ! options . netMetadata ,
575
- skipOE : ! options . observableEntropy ,
576
- } ) ;
606
+ const itemRequest : ItemRequest = ItemRequestSchema . parse ( jsonItem ) ;
607
+
608
+ itemRequest . itemDataSignatures = options . signingKeySeed
609
+ ? signItemData ( itemRequest , options . signingKeySeed )
610
+ : undefined ;
611
+
612
+ console . log ( "itemRequest" , JSON . stringify ( itemRequest , null , 2 ) ) ;
613
+
614
+ itemResp = await truestamp . updateItem (
615
+ options . id ,
616
+ itemRequest ,
617
+ updateItemsArgs ,
618
+ ) ;
577
619
} else if ( options . hash && options . hashType ) {
620
+ const itemRequest : ItemRequest = {
621
+ itemData : [
622
+ {
623
+ hash : options . hash ,
624
+ hashType : < HashTypes > options . hashType ,
625
+ } ,
626
+ ] ,
627
+ } ;
628
+
629
+ itemRequest . itemDataSignatures = options . signingKeySeed
630
+ ? signItemData ( itemRequest , options . signingKeySeed )
631
+ : undefined ;
632
+
633
+ // console.log("itemRequest", JSON.stringify(itemRequest, null, 2));
634
+
578
635
itemResp = await truestamp . updateItem (
579
636
options . id ,
580
- {
581
- itemData : [
582
- {
583
- hash : options . hash ,
584
- hashType : < HashTypes > options . hashType ,
585
- } ,
586
- ] ,
587
- } ,
588
- {
589
- skipCF : ! options . netMetadata ,
590
- skipOE : ! options . observableEntropy ,
591
- } ,
637
+ itemRequest ,
638
+ updateItemsArgs ,
592
639
) ;
593
640
} else if ( altHash && altHashType ) {
641
+ const itemRequest : ItemRequest = {
642
+ itemData : [
643
+ {
644
+ hash : altHash ,
645
+ hashType : < HashTypes > altHashType ,
646
+ } ,
647
+ ] ,
648
+ } ;
649
+
650
+ itemRequest . itemDataSignatures = options . signingKeySeed
651
+ ? signItemData ( itemRequest , options . signingKeySeed )
652
+ : undefined ;
653
+
654
+ // console.log("itemRequest", JSON.stringify(itemRequest, null, 2));
655
+
594
656
itemResp = await truestamp . updateItem (
595
657
options . id ,
596
- {
597
- itemData : [
598
- {
599
- hash : altHash ,
600
- hashType : < HashTypes > altHashType ,
601
- } ,
602
- ] ,
603
- } ,
604
- {
605
- skipCF : ! options . netMetadata ,
606
- skipOE : ! options . observableEntropy ,
607
- } ,
658
+ itemRequest ,
659
+ updateItemsArgs ,
608
660
) ;
609
661
} else {
610
- throw new Error ( "No hash or hashType provided" ) ;
662
+ throw new Error ( "No hash or hash-type provided" ) ;
611
663
}
612
664
613
665
const { id } = itemResp ;
@@ -628,6 +680,7 @@ export const items = new Command<{
628
680
env : typeof environmentType ;
629
681
apiKey ?: string ;
630
682
output : typeof outputType ;
683
+ signingKeySeed ?: string ;
631
684
} > ( )
632
685
. description ( "Create or update Items." )
633
686
. action ( ( ) => {
0 commit comments