pnyx/client.go

31 lines
514 B
Go

2024-04-03 18:52:04 -06:00
package pnyx
import (
"crypto/ed25519"
"crypto/rand"
"crypto/sha512"
)
type Client struct {
Key ed25519.PrivateKey
}
func(client Client) ID() ClientID {
2024-04-03 19:31:58 -06:00
hash := sha512.Sum512([]byte(client.Key.Public().(ed25519.PublicKey)))
return (ClientID)(hash[0:16])
2024-04-03 18:52:04 -06:00
}
func NewClient(key ed25519.PrivateKey) (Client, error) {
if key == nil {
var err error
_, key, err = ed25519.GenerateKey(rand.Reader)
if err != nil {
return Client{}, err
}
}
return Client{
Key: key,
}, nil
}