just some basic bip340 key functions instead.
This commit is contained in:
32
keys.go
32
keys.go
@@ -1,37 +1,21 @@
|
||||
package nostr
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
||||
"github.com/tyler-smith/go-bip39"
|
||||
"github.com/fiatjaf/bip340"
|
||||
)
|
||||
|
||||
func PrivateKeyAsHex(key *ecdsa.PrivateKey) string {
|
||||
skBytes := crypto.FromECDSA(key)
|
||||
return hex.EncodeToString(skBytes)
|
||||
func GeneratePrivateKey() string {
|
||||
return hex.EncodeToString(bip340.GeneratePrivateKey().Bytes())
|
||||
}
|
||||
|
||||
func PrivateKeyAsMnemonic(key *ecdsa.PrivateKey) (string, error) {
|
||||
skBytes := crypto.FromECDSA(key)
|
||||
return bip39.NewMnemonic(skBytes)
|
||||
}
|
||||
|
||||
func PublicKeyAsHex(key ecdsa.PublicKey) string {
|
||||
return hex.EncodeToString(secp256k1.CompressPubkey(key.X, key.Y))
|
||||
}
|
||||
|
||||
func GenerateKey() (*ecdsa.PrivateKey, error) {
|
||||
return crypto.GenerateKey()
|
||||
}
|
||||
|
||||
func PrivateKeyFromMnemonic(mnemonic string) (*ecdsa.PrivateKey, error) {
|
||||
e, err := bip39.EntropyFromMnemonic(mnemonic)
|
||||
func GetPublicKey(sk string) (string, error) {
|
||||
privateKey, err := bip340.ParsePrivateKey(sk)
|
||||
if err != nil {
|
||||
return &ecdsa.PrivateKey{}, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
return crypto.ToECDSA(e)
|
||||
publicKey := bip340.GetPublicKey(privateKey)
|
||||
return hex.EncodeToString(publicKey[:]), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user