go-nostr/keys.go

22 lines
401 B
Go
Raw Permalink Normal View History

2022-01-05 10:16:36 -04:00
package nostr
import (
"encoding/hex"
"github.com/fiatjaf/bip340"
2022-01-05 10:16:36 -04:00
)
func GeneratePrivateKey() string {
return hex.EncodeToString(bip340.GeneratePrivateKey().Bytes())
2022-01-05 10:16:36 -04:00
}
func GetPublicKey(sk string) (string, error) {
privateKey, err := bip340.ParsePrivateKey(sk)
2022-01-05 10:16:36 -04:00
if err != nil {
return "", err
2022-01-05 10:16:36 -04:00
}
publicKey := bip340.GetPublicKey(privateKey)
return hex.EncodeToString(publicKey[:]), nil
2022-01-05 10:16:36 -04:00
}