this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

progress on key generation

+24 -4
+24 -4
cmd/goat/crypto.go
··· 21 21 Aliases: []string{"t"}, 22 22 Usage: "indicate curve type (P-256 is default)", 23 23 }, 24 + &cli.BoolFlag{ 25 + Name: "terse", 26 + Usage: "print just the secret key, in multikey format", 27 + }, 24 28 }, 25 29 Action: runCryptoGenerate, 26 30 }, 27 31 &cli.Command{ 28 32 Name: "inspect", 29 33 Usage: "parses and outputs metadata about a public or secret key", 34 + ArgsUsage: `<key>`, 30 35 Action: runCryptoInspect, 31 36 }, 32 37 }, 33 38 } 34 39 35 40 func runCryptoGenerate(cctx *cli.Context) error { 41 + var priv crypto.PrivateKey 42 + var privMultibase string 36 43 switch cctx.String("type") { 37 44 case "", "P-256", "p256", "ES256", "secp256r1": 38 - priv, err := crypto.GeneratePrivateKeyP256() 45 + sec, err := crypto.GeneratePrivateKeyP256() 39 46 if err != nil { 40 47 return err 41 48 } 42 - fmt.Println(priv.Multibase()) 49 + privMultibase = sec.Multibase() 50 + priv = sec 43 51 case "K-256", "k256", "ES256K", "secp256k1": 44 - priv, err := crypto.GeneratePrivateKeyK256() 52 + sec, err := crypto.GeneratePrivateKeyK256() 45 53 if err != nil { 46 54 return err 47 55 } 48 - fmt.Println(priv.Multibase()) 56 + privMultibase = sec.Multibase() 57 + priv = sec 49 58 default: 50 59 return fmt.Errorf("unknown key type: %s", cctx.String("type")) 51 60 } 61 + if cctx.Bool("terse") { 62 + fmt.Println(privMultibase) 63 + return nil 64 + } 65 + pub, err := priv.PublicKey() 66 + if err != nil { 67 + return err 68 + } 69 + fmt.Printf("Key Type: %s\n", descKeyType(priv)) 70 + fmt.Printf("Secret Key (Multibase Syntax): save this securely (eg, add to password manager)\n\t%s\n", privMultibase) 71 + fmt.Printf("Public Key (DID Key Syntax): share or publish this (eg, in DID document)\n\t%s\n", pub.DIDKey()) 52 72 return nil 53 73 } 54 74