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