Made it a bit cleaner :)

This commit is contained in:
2025-12-19 16:57:47 -07:00
parent 302979b01a
commit 3822b1813c
7 changed files with 217 additions and 137 deletions

35
pkg/engine/keys.go Normal file
View File

@@ -0,0 +1,35 @@
package engine
import (
"crypto/ecdh"
"encoding/hex"
)
type KeyPair struct {
PrivateKey *ecdh.PrivateKey
PublicKey *ecdh.PublicKey
}
func (kp *KeyPair) EncodePublicKey() string {
return hex.EncodeToString(kp.PublicKey.Bytes())
}
func (kp *KeyPair) EncodePrivateKey() string {
return hex.EncodeToString(kp.PrivateKey.Bytes())
}
func (e *Engine) DecodePrivateKey(hexKey string) (*ecdh.PrivateKey, error) {
bytes, err := hex.DecodeString(hexKey)
if err != nil {
return nil, err
}
return e.curve.NewPrivateKey(bytes)
}
func (e *Engine) DecodePublicKey(hexKey string) (*ecdh.PublicKey, error) {
bytes, err := hex.DecodeString(hexKey)
if err != nil {
return nil, err
}
return e.curve.NewPublicKey(bytes)
}