generate

package
v0.12.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "generate",
	Short: "Generate a new key-pair",
	Run: func(cmd *cobra.Command, args []string) {
		var seed []byte
		if conf.Seed == "" {
			seed = cli.RandomSeed(crypto.MinSeedLength)
		} else {
			seed = []byte(conf.Seed)
		}

		sigAlgo := crypto.StringToSignatureAlgorithm(conf.SigAlgo)
		if sigAlgo == crypto.UnknownSignatureAlgorithm {
			cli.Exitf(1, "Invalid signature algorithm: %s", conf.SigAlgo)
		}

		fmt.Printf(
			"Generating key pair with signature algorithm:                 %s\n...\n",
			sigAlgo,
		)

		privateKey, err := crypto.GeneratePrivateKey(sigAlgo, seed)
		if err != nil {
			cli.Exitf(1, "Failed to generate private key: %v", err)
		}

		fmt.Printf(
			"\U0001F510 Private key (\u26A0\uFE0F\u202F store safely and don't share with anyone): %s\n",
			hex.EncodeToString(privateKey.Encode()),
		)
		fmt.Printf(
			"\U0001F54A️\uFE0F\u202F Encoded public key (share freely):                         %x\n",
			privateKey.PublicKey().Encode(),
		)
	},
}

Functions

This section is empty.

Types

type Config

type Config struct {
	Seed    string `flag:"seed,s" info:"Deterministic seed phrase"`
	SigAlgo string `default:"ECDSA_P256" flag:"algo,a" info:"Signature algorithm"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL