forked from frankh/nano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrai.go
37 lines (31 loc) · 732 Bytes
/
rai.go
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
31
32
33
34
35
36
37
package rai
import (
"encoding/hex"
"github.com/frankh/crypto/ed25519"
"strings"
)
type BlockHash string
type Account string
type Work string
type Signature string
func (hash BlockHash) ToBytes() []byte {
bytes, err := hex.DecodeString(string(hash))
if err != nil {
panic(err)
}
return bytes
}
func (sig Signature) ToBytes() []byte {
bytes, err := hex.DecodeString(string(sig))
if err != nil {
panic(err)
}
return bytes
}
func (hash BlockHash) Sign(private_key ed25519.PrivateKey) Signature {
sig := hex.EncodeToString(ed25519.Sign(private_key, hash.ToBytes()))
return Signature(strings.ToUpper(sig))
}
func BlockHashFromBytes(b []byte) BlockHash {
return BlockHash(strings.ToUpper(hex.EncodeToString(b)))
}