2020-07-28 09:35:42 -07:00
|
|
|
package storage
|
|
|
|
|
2020-08-14 05:34:15 -07:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"crypto/ed25519"
|
|
|
|
)
|
2020-08-13 08:27:28 -07:00
|
|
|
|
2020-07-28 09:35:42 -07:00
|
|
|
type Message struct {
|
2020-08-22 05:04:44 -07:00
|
|
|
ID string `json:"id"`
|
|
|
|
DkgRoundID string `json:"dkg_round_id"`
|
|
|
|
Offset uint64 `json:"offset"`
|
|
|
|
Event string `json:"event"`
|
|
|
|
Data []byte `json:"data"`
|
|
|
|
Signature []byte `json:"signature"`
|
|
|
|
SenderAddr string `json:"sender"`
|
|
|
|
RecipientAddr string `json:"recipient"`
|
2020-08-14 05:34:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Message) Bytes() []byte {
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
buf.Write(m.Data)
|
|
|
|
|
|
|
|
return buf.Bytes()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Message) Verify(pubKey ed25519.PublicKey) bool {
|
|
|
|
return ed25519.Verify(pubKey, m.Bytes(), m.Signature)
|
2020-07-28 09:35:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type Storage interface {
|
2020-07-29 07:20:17 -07:00
|
|
|
Send(message Message) (Message, error)
|
2020-07-30 03:29:47 -07:00
|
|
|
GetMessages(offset uint64) ([]Message, error)
|
2020-07-28 09:35:42 -07:00
|
|
|
Close() error
|
2020-08-22 05:04:44 -07:00
|
|
|
}
|