github.com/line/ostracon@v1.0.10-0.20230328032236-7f20145f065d/crypto/crypto.go (about) 1 package crypto 2 3 import ( 4 "github.com/line/ostracon/crypto/tmhash" 5 "github.com/line/ostracon/libs/bytes" 6 ) 7 8 const ( 9 // AddressSize is the size of a pubkey address. 10 AddressSize = tmhash.TruncatedSize 11 ) 12 13 // An address is a []byte, but hex-encoded even in JSON. 14 // []byte leaves us the option to change the address length. 15 // Use an alias so Unmarshal methods (with ptr receivers) are available too. 16 type Address = bytes.HexBytes 17 18 func AddressHash(bz []byte) Address { 19 return Address(tmhash.SumTruncated(bz)) 20 } 21 22 // Proof represents the VRF Proof. 23 // It should be defined separately from Ed25519 VRF Proof to avoid circular import. 24 type Proof []byte 25 type Output []byte 26 27 type PubKey interface { 28 Address() Address 29 Bytes() []byte 30 VerifySignature(msg []byte, sig []byte) bool 31 VRFVerify(proof Proof, seed []byte) (Output, error) // TODO 🏺 rename to VerifyVRFProof to match VerifySignature 32 Equals(PubKey) bool 33 Type() string 34 } 35 36 type PrivKey interface { 37 Bytes() []byte 38 Sign(msg []byte) ([]byte, error) 39 VRFProve(seed []byte) (Proof, error) 40 PubKey() PubKey 41 Equals(PrivKey) bool 42 Type() string 43 } 44 45 type Symmetric interface { 46 Keygen() []byte 47 Encrypt(plaintext []byte, secret []byte) (ciphertext []byte) 48 Decrypt(ciphertext []byte, secret []byte) (plaintext []byte, err error) 49 }