Completed event and key libraries.

This commit is contained in:
Jay
2025-10-20 11:00:44 -04:00
parent 0ab4edb45d
commit 2c893f9619
12 changed files with 824 additions and 0 deletions

30
keys.go Normal file
View File

@@ -0,0 +1,30 @@
package roots
import (
"encoding/hex"
"fmt"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
)
func GeneratePrivateKey() (string, error) {
sk, err := secp256k1.GeneratePrivateKey()
if err != nil {
return "", err
}
skBytes := sk.Serialize()
return hex.EncodeToString(skBytes), nil
}
func GetPublicKey(privateKeyHex string) (string, error) {
if len(privateKeyHex) != 64 {
return "", fmt.Errorf("private key must be 64 hex characters")
}
skBytes, err := hex.DecodeString(privateKeyHex)
if err != nil {
return "", fmt.Errorf("invalid private key hex: %w", err)
}
pk := secp256k1.PrivKeyFromBytes(skBytes).PubKey()
pkBytes := pk.SerializeCompressed()[1:]
return hex.EncodeToString(pkBytes), nil
}