aboutsummaryrefslogtreecommitdiff
path: root/pkg/types/crypto.go
blob: 72152bf83b8292f1c2ab71c01f73cf75bb74b714 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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...))
}