experimental-cli/pigeon/util.go

34 lines
836 B
Go
Raw Normal View History

2020-08-17 12:55:12 +00:00
package pigeon
import (
"crypto/ed25519"
2020-08-21 13:23:53 +00:00
"log"
2020-08-17 12:55:12 +00:00
)
2020-08-20 13:13:38 +00:00
// CreateIdentity is used by the CLI to create an ED25519
// keypair and store it to disk. It returns the private key
// as a Base32 encoded string
func CreateIdentity() (ed25519.PublicKey, ed25519.PrivateKey) {
pub, priv, err := ed25519.GenerateKey(nil)
if err != nil {
log.Fatalf("Keypair creation error %s", err)
}
2020-09-01 12:38:30 +00:00
SetConfig("public_key", pub)
SetConfig("private_key", priv)
2020-08-20 13:13:38 +00:00
return pub, priv
2020-08-17 12:55:12 +00:00
}
2020-08-21 13:23:53 +00:00
// EncodeUserMhash Takes a []byte and converts it to a B32
// string in the format "USER.DATA.ED25519"
2020-08-31 11:58:11 +00:00
// func EncodeUserMhash(pubKey []byte) string {
// b32 := B32Encode(pubKey)
// b32Length := len(b32)
2020-08-21 13:23:53 +00:00
2020-08-31 11:58:11 +00:00
// if b32Length != 52 {
// m := "Expected %s to be 52 bytes long. Got %d"
// log.Fatal(m, b32, b32Length)
// }
2020-08-21 13:23:53 +00:00
2020-08-31 11:58:11 +00:00
// return fmt.Sprintf("%s%s", UserSigil, b32)
// }