pnyx/client.go

31 lines
514 B
Go

package pnyx
import (
"crypto/ed25519"
"crypto/rand"
"crypto/sha512"
)
type Client struct {
Key ed25519.PrivateKey
}
func(client Client) ID() ClientID {
hash := sha512.Sum512([]byte(client.Key.Public().(ed25519.PublicKey)))
return (ClientID)(hash[0:16])
}
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
}