+59
-1
cmd/goat/plc.go
+59
-1
cmd/goat/plc.go
···
100
100
&cli.Command{
101
101
Name: "calc-did",
102
102
Usage: "calculate the DID corresponding to a signed PLC operation (input in JSON format)",
103
-
ArgsUsage: `<genesis.json>`,
103
+
ArgsUsage: `<signed_genesis.json>`,
104
104
Flags: []cli.Flag{},
105
105
Action: runPLCCalcDID,
106
+
},
107
+
&cli.Command{
108
+
Name: "sign",
109
+
Usage: "",
110
+
ArgsUsage: `<operation.json>`,
111
+
Flags: []cli.Flag{
112
+
&cli.StringFlag{
113
+
Name: "plc-private-rotation-key",
114
+
Usage: "private key used as a rotation key, if operation is not signed (multibase syntax)",
115
+
EnvVars: []string{"PLC_PRIVATE_ROTATION_KEY"},
116
+
},
117
+
},
118
+
Action: runPLCSign,
106
119
},
107
120
},
108
121
}
···
447
460
448
461
return nil
449
462
}
463
+
464
+
func runPLCSign(cctx *cli.Context) error {
465
+
s := cctx.Args().First()
466
+
if s == "" {
467
+
return fmt.Errorf("need to provide PLC operation json path as input")
468
+
}
469
+
470
+
privStr := cctx.String("plc-private-rotation-key")
471
+
if privStr == "" {
472
+
return fmt.Errorf("private key must be provided")
473
+
}
474
+
475
+
inputReader, err := getFileOrStdin(s)
476
+
if err != nil {
477
+
return err
478
+
}
479
+
480
+
inBytes, err := io.ReadAll(inputReader)
481
+
if err != nil {
482
+
return err
483
+
}
484
+
485
+
var enum didplc.OpEnum
486
+
if err := json.Unmarshal(inBytes, &enum); err != nil {
487
+
return err
488
+
}
489
+
op := enum.AsOperation()
490
+
491
+
privkey, err := crypto.ParsePrivateMultibase(privStr)
492
+
if err != nil {
493
+
return err
494
+
}
495
+
496
+
if err := op.Sign(privkey); err != nil {
497
+
return err
498
+
}
499
+
500
+
res, err := json.MarshalIndent(op, "", " ")
501
+
if err != nil {
502
+
return err
503
+
}
504
+
fmt.Println(string(res))
505
+
506
+
return nil
507
+
}