signingKey

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2018 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KeyNew = cli.Command{
	Name: "sk:new",
	Action: func(c *cli.Context) error {

		p := pui.Prompt{
			Label: "Enter name of new signing key",
		}
		name, err := p.Run()
		if err != nil {
			panic(err)
		}
		if name == "" {
			return errors.New("please enter a name for this signing key")
		}

		p = pui.Prompt{
			Label: "Enter password for signing key encryption",
			Mask:  '*',
		}
		pw, err := p.Run()
		if err != nil {
			panic(err)
		}

		p = pui.Prompt{
			Label: "Confirm password",
			Mask:  '*',
		}
		pwConfirm, err := p.Run()
		if err != nil {
			panic(err)
		}
		if pw != pwConfirm {
			return errors.New("failed to confirm password")
		}

		pub, priv, err := ed25519.GenerateKey(rand.Reader)
		sk := SingingKey{
			Name:       name,
			PublicKey:  pub[:],
			privateKey: priv[:],
			CreateAt:   time.Now(),
			Version:    uint8(1),
		}

		data, err := sk.Export([]byte(pw))
		if err != nil {
			return err
		}

		fileName := fmt.Sprintf("%s_%d.signing_key.json", name, time.Now().Unix())
		if err := ioutil.WriteFile(fileName, data, 0775); err != nil {
			return err
		}

		fmt.Println(fmt.Sprintf("wrote signing key to: %s", fileName))

		return nil

	},
}

Functions

This section is empty.

Types

type SingingKey

type SingingKey struct {
	Name       string            `json:"name"`
	PublicKey  ed25519.PublicKey `json:"public_key"`
	PrivateKey scrypt.CipherText `json:"private_key"`

	CreateAt time.Time `json:"created_at"`
	Version  uint8     `json:"version"`
	// contains filtered or unexported fields
}

func Decrypt

func Decrypt(data, password []byte) (SingingKey, error)

decrypt dapp key

func New

func New(name string) (SingingKey, error)

create new key

func (SingingKey) Export

func (k SingingKey) Export(password []byte) ([]byte, error)

export DApp Key

func (*SingingKey) Sign

func (k *SingingKey) Sign(data []byte) []byte

sign data with private key

Jump to

Keyboard shortcuts

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