From 93e0ce02f592686d5ec75fc7f87fd1485b60de91 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 3 Jan 2024 08:11:26 -0500 Subject: [PATCH] feat: add ed25519 package --- ed25519/ed25519.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ed25519/ed25519.go diff --git a/ed25519/ed25519.go b/ed25519/ed25519.go new file mode 100644 index 0000000..5b7187a --- /dev/null +++ b/ed25519/ed25519.go @@ -0,0 +1,27 @@ +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 { + return (ed25519.PrivateKey(kp.Bytes).Public()).([]byte) +} + +func (kp *KeyPairEd25519) ExtractBytes() []byte { + return kp.Bytes +}