Documentation ¶
Index ¶
- Constants
- Variables
- func KMToDBPath(dir string, km *km.KeyManager) (string, error)
- func Migrate(prodDBFile string, migrations []Migration) error
- type AddUserToChat
- type BoltChatStorage
- func (s *BoltChatStorage) AddListener(fn func(e MessagePersistedEvent))
- func (s *BoltChatStorage) AllChats() ([]Chat, error)
- func (s *BoltChatStorage) CreateChat(partner ed25519.PublicKey) (int, error)
- func (s *BoltChatStorage) CreateGroupChat(partners []ed25519.PublicKey, name string) (int, error)
- func (s *BoltChatStorage) CreateGroupChatFromMsg(msg Message) error
- func (s *BoltChatStorage) GetChat(chatID int) (*Chat, error)
- func (s *BoltChatStorage) GetChatByPartner(partner ed25519.PublicKey) (*Chat, error)
- func (s *BoltChatStorage) GetGroupChatByRemoteID(id []byte) (*Chat, error)
- func (s *BoltChatStorage) ReadMessages(chatID int) error
- func (s *BoltChatStorage) UnreadMessages(c Chat) error
- type BoltDRKeyStorage
- func (s *BoltDRKeyStorage) All() map[dr.Key]map[uint]dr.Key
- func (s *BoltDRKeyStorage) Count(k dr.Key) uint
- func (s *BoltDRKeyStorage) DeleteMk(k dr.Key, msgNum uint)
- func (s *BoltDRKeyStorage) DeletePk(k dr.Key)
- func (s *BoltDRKeyStorage) Get(k dr.Key, msgNum uint) (mk dr.Key, ok bool)
- func (s *BoltDRKeyStorage) Put(k dr.Key, msgNum uint, mk dr.Key)
- type BoltOneTimePreKeyStorage
- type BoltSharedSecretStorage
- func (b *BoltSharedSecretStorage) Accept(sharedSec *SharedSecret) error
- func (b *BoltSharedSecretStorage) Get(partner ed25519.PublicKey, id []byte) (*SharedSecret, error)
- func (b *BoltSharedSecretStorage) GetYoungest(partner ed25519.PublicKey) (*SharedSecret, error)
- func (b *BoltSharedSecretStorage) HasAny(partner ed25519.PublicKey) (bool, error)
- func (b *BoltSharedSecretStorage) Put(ss SharedSecret) error
- type BoltSignedPreKeyStorage
- type BoltToStormMigration
- type BoltUserStorage
- type Chat
- func (c *Chat) AddChatPartners(partners []ed25519.PublicKey) error
- func (c *Chat) GetMessage(msgID int64) (*Message, error)
- func (c *Chat) IsGroupChat() bool
- func (c *Chat) Messages(start int64, amount uint) ([]*Message, error)
- func (c *Chat) PersistMessage(msg Message) error
- func (c *Chat) SaveMessage(rawMessage []byte) error
- type ChatStorage
- type DAppMessage
- type DRKey
- type DRKeyStorage
- type Message
- type MessagePersistedEvent
- type Migration
- type OneTimePreKeyStorage
- type SharedSecret
- type SharedSecretStorage
- type SignedPreKey
- type SignedPreKeyStorage
- type Status
- type User
- type UserStorage
Constants ¶
View Source
const ( StatusSent Status = 100 StatusFailedToSend Status = 200 StatusDelivered Status = 300 StatusFailedToHandle Status = 400 StatusPersisted Status = 500 DAppMessageVersion uint = 1 )
View Source
const (
SignedPreKeyValidTimeFrame = time.Hour * 24 * 60
)
Variables ¶
View Source
var ValidMessage = func(m Message) error { if m.ID == "" { return errors.New("invalid message id (empty string)") } if m.Version == 0 { return errors.New("invalid version - got 0") } if _, exist := statuses[m.Status]; !exist { return fmt.Errorf("invalid status: %d (is not registered)", m.Status) } if m.DApp == nil && m.AddUserToChat == nil && len(m.Message) == 0 { return errors.New("got invalid message - dapp and message are both nil") } if m.DApp != nil { if len(m.DApp.DAppPublicKey) != 32 { return fmt.Errorf("invalid dapp public key of length %d", len(m.DApp.DAppPublicKey)) } } if m.CreatedAt <= 2147483647 { return errors.New("invalid created at - must be bigger than 2147483647") } if len(m.Sender) != 32 && m.DApp == nil { return fmt.Errorf("invalid sender of length %d", len(m.Sender)) } return nil }
validate a given message
Functions ¶
func KMToDBPath ¶
func KMToDBPath(dir string, km *km.KeyManager) (string, error)
get database path for key manager
Types ¶
type AddUserToChat ¶
type BoltChatStorage ¶
type BoltChatStorage struct {
// contains filtered or unexported fields
}
func NewChatStorage ¶
func NewChatStorage(db storm.Node, listeners []func(event MessagePersistedEvent), km *km.KeyManager) *BoltChatStorage
func (*BoltChatStorage) AddListener ¶
func (s *BoltChatStorage) AddListener(fn func(e MessagePersistedEvent))
func (*BoltChatStorage) AllChats ¶
func (s *BoltChatStorage) AllChats() ([]Chat, error)
func (*BoltChatStorage) CreateChat ¶
func (s *BoltChatStorage) CreateChat(partner ed25519.PublicKey) (int, error)
func (*BoltChatStorage) CreateGroupChat ¶
func (*BoltChatStorage) CreateGroupChatFromMsg ¶
func (s *BoltChatStorage) CreateGroupChatFromMsg(msg Message) error
func (*BoltChatStorage) GetChatByPartner ¶
func (s *BoltChatStorage) GetChatByPartner(partner ed25519.PublicKey) (*Chat, error)
func (*BoltChatStorage) GetGroupChatByRemoteID ¶
func (s *BoltChatStorage) GetGroupChatByRemoteID(id []byte) (*Chat, error)
func (*BoltChatStorage) ReadMessages ¶
func (s *BoltChatStorage) ReadMessages(chatID int) error
func (*BoltChatStorage) UnreadMessages ¶
func (s *BoltChatStorage) UnreadMessages(c Chat) error
type BoltDRKeyStorage ¶
type BoltDRKeyStorage struct {
// contains filtered or unexported fields
}
func NewBoltDRKeyStorage ¶
func NewBoltDRKeyStorage(db storm.Node, km *km.KeyManager) *BoltDRKeyStorage
func (*BoltDRKeyStorage) DeleteMk ¶
func (s *BoltDRKeyStorage) DeleteMk(k dr.Key, msgNum uint)
@todo we need to change the dr package to use a better interface (error handling)
func (*BoltDRKeyStorage) DeletePk ¶
func (s *BoltDRKeyStorage) DeletePk(k dr.Key)
type BoltOneTimePreKeyStorage ¶
type BoltOneTimePreKeyStorage struct {
// contains filtered or unexported fields
}
func NewBoltOneTimePreKeyStorage ¶
func NewBoltOneTimePreKeyStorage(db storm.Node, km *km.KeyManager) *BoltOneTimePreKeyStorage
func (*BoltOneTimePreKeyStorage) Count ¶
func (s *BoltOneTimePreKeyStorage) Count() (uint32, error)
func (*BoltOneTimePreKeyStorage) Cut ¶
func (s *BoltOneTimePreKeyStorage) Cut(pubKey []byte) (*x3dh.PrivateKey, error)
type BoltSharedSecretStorage ¶
type BoltSharedSecretStorage struct {
// contains filtered or unexported fields
}
func NewBoltSharedSecretStorage ¶
func NewBoltSharedSecretStorage(db storm.Node, km *keyManager.KeyManager) *BoltSharedSecretStorage
func (*BoltSharedSecretStorage) Accept ¶
func (b *BoltSharedSecretStorage) Accept(sharedSec *SharedSecret) error
func (*BoltSharedSecretStorage) Get ¶
func (b *BoltSharedSecretStorage) Get(partner ed25519.PublicKey, id []byte) (*SharedSecret, error)
func (*BoltSharedSecretStorage) GetYoungest ¶
func (b *BoltSharedSecretStorage) GetYoungest(partner ed25519.PublicKey) (*SharedSecret, error)
func (*BoltSharedSecretStorage) HasAny ¶
func (b *BoltSharedSecretStorage) HasAny(partner ed25519.PublicKey) (bool, error)
func (*BoltSharedSecretStorage) Put ¶
func (b *BoltSharedSecretStorage) Put(ss SharedSecret) error
type BoltSignedPreKeyStorage ¶
type BoltSignedPreKeyStorage struct {
// contains filtered or unexported fields
}
func NewBoltSignedPreKeyStorage ¶
func NewBoltSignedPreKeyStorage(db storm.Node, km *keyManager.KeyManager) *BoltSignedPreKeyStorage
func (*BoltSignedPreKeyStorage) All ¶
func (s *BoltSignedPreKeyStorage) All() ([]*x3dh.KeyPair, error)
func (*BoltSignedPreKeyStorage) Get ¶
func (s *BoltSignedPreKeyStorage) Get(publicKey x3dh.PublicKey) (*x3dh.PrivateKey, error)
type BoltToStormMigration ¶
type BoltToStormMigration struct {
Km *keyManager.KeyManager
}
func (*BoltToStormMigration) Version ¶
func (m *BoltToStormMigration) Version() uint32
type BoltUserStorage ¶
type BoltUserStorage struct {
// contains filtered or unexported fields
}
func NewBoltUserStorage ¶
func NewBoltUserStorage(db *storm.DB) *BoltUserStorage
func (*BoltUserStorage) GetSignedPreKey ¶
func (*BoltUserStorage) PutSignedPreKey ¶
type Chat ¶
type Chat struct { ID int `storm:"id,increment"` GroupChatName string // partner will only be filled if this is a private chat Partner ed25519.PublicKey `storm:"index,unique"` Partners []ed25519.PublicKey UnreadMessages bool GroupChatRemoteID []byte `storm:"unique"` // contains filtered or unexported fields }
func (*Chat) PersistMessage ¶
Persist Message struct
type ChatStorage ¶
type ChatStorage interface { GetChatByPartner(pubKey ed25519.PublicKey) (*Chat, error) GetChat(chatID int) (*Chat, error) GetGroupChatByRemoteID(id []byte) (*Chat, error) // returned int is the chat ID CreateChat(partner ed25519.PublicKey) (int, error) CreateGroupChat(partners []ed25519.PublicKey, name string) (int, error) CreateGroupChatFromMsg(createMessage Message) error AddListener(func(e MessagePersistedEvent)) AllChats() ([]Chat, error) // set state of chat to unread messages UnreadMessages(c Chat) error // set state of chat all messages read ReadMessages(chatID int) error }
type DAppMessage ¶
type DRKeyStorage ¶
type Message ¶
type Message struct { DBID int `storm:"id,increment"` ID string Version uint Status Status Received bool DApp *DAppMessage Message []byte `json:"-"` PersistedMessage aes.CipherText CreatedAt int64 Sender []byte `storm:"index"` // the UniqueID is a unix nano timestamp // it's only unique in the relation with a chat id UniqueMsgID int64 `storm:"index"` ChatID int `storm:"index"` AddUserToChat *AddUserToChat GroupChatID []byte }
type MessagePersistedEvent ¶
type OneTimePreKeyStorage ¶
type SharedSecret ¶
type SharedSecret struct { aes.CipherText // contains filtered or unexported fields }X3dhSS
func (*SharedSecret) GetX3dhSecret ¶
func (ss *SharedSecret) GetX3dhSecret() x3dh.SharedSecret
@todo I don't like this solution. However, we still need to figure out @todo how to ignore fields from storm
func (*SharedSecret) SetX3dhSecret ¶
func (ss *SharedSecret) SetX3dhSecret(secret x3dh.SharedSecret)
type SharedSecretStorage ¶
type SharedSecretStorage interface { // must return an error if no shared secret found // and will set a destroy date for all other shared secrets Accept(sharedSec *SharedSecret) error Get(key ed25519.PublicKey, sharedSecretID []byte) (*SharedSecret, error) }
type SignedPreKey ¶
type SignedPreKey struct { ValidTill int64 `storm:"index"` EncryptedPrivateKey aes.CipherText PublicKey x3dh.PublicKey `storm:"index,id"` Version uint // contains filtered or unexported fields }
func (*SignedPreKey) PrivateKey ¶
func (s *SignedPreKey) PrivateKey() x3dh.PrivateKey
type SignedPreKeyStorage ¶
type SignedPreKeyStorage interface { // persist the signed pre key // @todo don't forget to give the option to register a listener in the put function // @todo publish signed pre key to backend Put(signedPreKey x3dh.KeyPair) error Get(publicKey x3dh.PublicKey) (*x3dh.PrivateKey, error) All() ([]*x3dh.KeyPair, error) }
Click to show internal directories.
Click to hide internal directories.