-
Notifications
You must be signed in to change notification settings - Fork 28
/
crypto.go
49 lines (41 loc) · 1.25 KB
/
crypto.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
38
39
40
41
42
43
44
45
46
47
48
49
package crypto
import (
"github.com/line/ostracon/crypto/tmhash"
"github.com/line/ostracon/libs/bytes"
)
const (
// AddressSize is the size of a pubkey address.
AddressSize = tmhash.TruncatedSize
)
// An address is a []byte, but hex-encoded even in JSON.
// []byte leaves us the option to change the address length.
// Use an alias so Unmarshal methods (with ptr receivers) are available too.
type Address = bytes.HexBytes
func AddressHash(bz []byte) Address {
return Address(tmhash.SumTruncated(bz))
}
// Proof represents the VRF Proof.
// It should be defined separately from Ed25519 VRF Proof to avoid circular import.
type Proof []byte
type Output []byte
type PubKey interface {
Address() Address
Bytes() []byte
VerifySignature(msg []byte, sig []byte) bool
VRFVerify(proof Proof, seed []byte) (Output, error) // TODO 🏺 rename to VerifyVRFProof to match VerifySignature
Equals(PubKey) bool
Type() string
}
type PrivKey interface {
Bytes() []byte
Sign(msg []byte) ([]byte, error)
VRFProve(seed []byte) (Proof, error)
PubKey() PubKey
Equals(PrivKey) bool
Type() string
}
type Symmetric interface {
Keygen() []byte
Encrypt(plaintext []byte, secret []byte) (ciphertext []byte)
Decrypt(ciphertext []byte, secret []byte) (plaintext []byte, err error)
}