libs5-go/ed25519/ed25519.go

30 lines
604 B
Go
Raw Normal View History

2024-01-03 13:11:26 +00:00
package ed25519
import (
"crypto/ed25519"
"git.lumeweb.com/LumeWeb/libs5-go/types"
"git.lumeweb.com/LumeWeb/libs5-go/utils"
)
type KeyPairEd25519 struct {
Bytes []byte
}
func New(bytes []byte) *KeyPairEd25519 {
return &KeyPairEd25519{Bytes: bytes}
}
func (kp *KeyPairEd25519) PublicKey() []byte {
return utils.ConcatBytes([]byte{byte(types.HashTypeEd25519)}, kp.PublicKeyRaw())
}
func (kp *KeyPairEd25519) PublicKeyRaw() []byte {
2024-01-07 10:22:00 +00:00
publicKey := ed25519.PrivateKey(kp.Bytes).Public()
return publicKey.(ed25519.PublicKey)
2024-01-03 13:11:26 +00:00
}
func (kp *KeyPairEd25519) ExtractBytes() []byte {
return kp.Bytes
}