From 7e0f0f84eac2e37edfd177196ed65afa0559f967 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Mon, 20 Dec 2021 14:37:43 +0100 Subject: types: Add types and tests --- pkg/types/crypto.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 pkg/types/crypto.go (limited to 'pkg/types/crypto.go') diff --git a/pkg/types/crypto.go b/pkg/types/crypto.go new file mode 100644 index 0000000..72152bf --- /dev/null +++ b/pkg/types/crypto.go @@ -0,0 +1,30 @@ +package types + +import ( + "crypto/ed25519" + "crypto/sha256" +) + +const ( + HashSize = sha256.Size + SignatureSize = ed25519.SignatureSize + PublicKeySize = ed25519.PublicKeySize + + InteriorNodePrefix = byte(0x00) + LeafNodePrefix = byte(0x01) +) + +type ( + Hash [HashSize]byte + Signature [SignatureSize]byte + PublicKey [PublicKeySize]byte +) + +func HashFn(buf []byte) *Hash { + var hash Hash = sha256.Sum256(buf) + return &hash +} + +func LeafHash(buf []byte) *Hash { + return HashFn(append([]byte{LeafNodePrefix}, buf...)) +} -- cgit v1.2.3