@@ -10,6 +10,7 @@ import {
1010} from "../deps.ts" ;
1111
1212import {
13+ getSigningSecretKeyForEnv ,
1314 logSelectedOutputFormat ,
1415 signItemData ,
1516 throwApiError ,
@@ -34,7 +35,7 @@ const itemsCreate = new Command<{
3435 env : typeof environmentType ;
3536 apiKey ?: string ;
3637 output : typeof outputType ;
37- signingKeySeed ?: string ;
38+ signingSecretKey ?: string ;
3839} > ( )
3940 . description (
4041 `Create a new Item.
@@ -293,15 +294,18 @@ Pipe JSON content to the 'items create' command using '--input json' plus the '-
293294 skipOE : ! options . observableEntropy ,
294295 } ;
295296
297+ const signingSecretKeyFromConfig = getSigningSecretKeyForEnv ( options . env ) ;
298+
296299 if ( jsonItem ) {
297300 const itemRequest : ItemRequest = ItemRequestSchema . parse ( jsonItem ) ;
298301
299- itemRequest . itemDataSignatures = options . signingKeySeed
300- ? signItemData ( itemRequest , options . signingKeySeed )
302+ // Signing Secret Key provided as an option or env var overrides a key stored in the config file.
303+ itemRequest . itemDataSignatures = options . signingSecretKey
304+ ? signItemData ( itemRequest , options . signingSecretKey )
305+ : signingSecretKeyFromConfig
306+ ? signItemData ( itemRequest , signingSecretKeyFromConfig )
301307 : undefined ;
302308
303- console . log ( "itemRequest" , JSON . stringify ( itemRequest , null , 2 ) ) ;
304-
305309 itemResp = await truestamp . createItem ( itemRequest , createItemArgs ) ;
306310 } else if ( options . hash && options . hashType ) {
307311 const itemRequest : ItemRequest = {
@@ -313,12 +317,13 @@ Pipe JSON content to the 'items create' command using '--input json' plus the '-
313317 ] ,
314318 } ;
315319
316- itemRequest . itemDataSignatures = options . signingKeySeed
317- ? signItemData ( itemRequest , options . signingKeySeed )
320+ // Signing Secret Key provided as an option or env var overrides a key stored in the config file.
321+ itemRequest . itemDataSignatures = options . signingSecretKey
322+ ? signItemData ( itemRequest , options . signingSecretKey )
323+ : signingSecretKeyFromConfig
324+ ? signItemData ( itemRequest , signingSecretKeyFromConfig )
318325 : undefined ;
319326
320- // console.log("itemRequest", JSON.stringify(itemRequest, null, 2));
321-
322327 itemResp = await truestamp . createItem (
323328 itemRequest ,
324329 createItemArgs ,
@@ -333,12 +338,13 @@ Pipe JSON content to the 'items create' command using '--input json' plus the '-
333338 ] ,
334339 } ;
335340
336- itemRequest . itemDataSignatures = options . signingKeySeed
337- ? signItemData ( itemRequest , options . signingKeySeed )
341+ // Signing Secret Key provided as an option or env var overrides a key stored in the config file.
342+ itemRequest . itemDataSignatures = options . signingSecretKey
343+ ? signItemData ( itemRequest , options . signingSecretKey )
344+ : signingSecretKeyFromConfig
345+ ? signItemData ( itemRequest , signingSecretKeyFromConfig )
338346 : undefined ;
339347
340- // console.log("itemRequest", JSON.stringify(itemRequest, null, 2));
341-
342348 itemResp = await truestamp . createItem (
343349 itemRequest ,
344350 createItemArgs ,
@@ -396,7 +402,7 @@ const itemsUpdate = new Command<{
396402 env : typeof environmentType ;
397403 apiKey ?: string ;
398404 output : typeof outputType ;
399- signingKeySeed ?: string ;
405+ signingSecretKey ?: string ;
400406} > ( )
401407 . description (
402408 `Update an existing Item by replacing it with a new one.
@@ -602,15 +608,18 @@ Pipe JSON content to the 'items update' command using '--input json' plus the '-
602608 skipOE : ! options . observableEntropy ,
603609 } ;
604610
611+ const signingSecretKeyFromConfig = getSigningSecretKeyForEnv ( options . env ) ;
612+
605613 if ( jsonItem ) {
606614 const itemRequest : ItemRequest = ItemRequestSchema . parse ( jsonItem ) ;
607615
608- itemRequest . itemDataSignatures = options . signingKeySeed
609- ? signItemData ( itemRequest , options . signingKeySeed )
616+ // Signing Secret Key provided as an option or env var overrides a key stored in the config file.
617+ itemRequest . itemDataSignatures = options . signingSecretKey
618+ ? signItemData ( itemRequest , options . signingSecretKey )
619+ : signingSecretKeyFromConfig
620+ ? signItemData ( itemRequest , signingSecretKeyFromConfig )
610621 : undefined ;
611622
612- console . log ( "itemRequest" , JSON . stringify ( itemRequest , null , 2 ) ) ;
613-
614623 itemResp = await truestamp . updateItem (
615624 options . id ,
616625 itemRequest ,
@@ -626,12 +635,13 @@ Pipe JSON content to the 'items update' command using '--input json' plus the '-
626635 ] ,
627636 } ;
628637
629- itemRequest . itemDataSignatures = options . signingKeySeed
630- ? signItemData ( itemRequest , options . signingKeySeed )
638+ // Signing Secret Key provided as an option or env var overrides a key stored in the config file.
639+ itemRequest . itemDataSignatures = options . signingSecretKey
640+ ? signItemData ( itemRequest , options . signingSecretKey )
641+ : signingSecretKeyFromConfig
642+ ? signItemData ( itemRequest , signingSecretKeyFromConfig )
631643 : undefined ;
632644
633- // console.log("itemRequest", JSON.stringify(itemRequest, null, 2));
634-
635645 itemResp = await truestamp . updateItem (
636646 options . id ,
637647 itemRequest ,
@@ -647,12 +657,13 @@ Pipe JSON content to the 'items update' command using '--input json' plus the '-
647657 ] ,
648658 } ;
649659
650- itemRequest . itemDataSignatures = options . signingKeySeed
651- ? signItemData ( itemRequest , options . signingKeySeed )
660+ // Signing Secret Key provided as an option or env var overrides a key stored in the config file.
661+ itemRequest . itemDataSignatures = options . signingSecretKey
662+ ? signItemData ( itemRequest , options . signingSecretKey )
663+ : signingSecretKeyFromConfig
664+ ? signItemData ( itemRequest , signingSecretKeyFromConfig )
652665 : undefined ;
653666
654- // console.log("itemRequest", JSON.stringify(itemRequest, null, 2));
655-
656667 itemResp = await truestamp . updateItem (
657668 options . id ,
658669 itemRequest ,
@@ -680,7 +691,7 @@ export const items = new Command<{
680691 env : typeof environmentType ;
681692 apiKey ?: string ;
682693 output : typeof outputType ;
683- signingKeySeed ?: string ;
694+ signingSecretKey ?: string ;
684695} > ( )
685696 . description ( "Create or update Items." )
686697 . action ( ( ) => {
0 commit comments