statusproto

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2019 License: MPL-2.0 Imports: 30 Imported by: 0

README

status-protocol-go

This is the Status Protocol implementation in Go.

TBD

Documentation

Index

Constants

View Source
const (
	ChatTypeOneToOne = iota + 1
	ChatTypePublic
	ChatTypePrivateGroupChat
)

Variables

View Source
var (
	ErrChatIDEmpty    = errors.New("chat ID is empty")
	ErrNotImplemented = errors.New("not implemented")
)
View Source
var (
	RetrieveLatest  = RetrieveConfig{/* contains filtered or unexported fields */}
	RetrieveLastDay = RetrieveConfig{/* contains filtered or unexported fields */}
)
View Source
var (
	// ErrMsgAlreadyExist returned if msg already exist.
	ErrMsgAlreadyExist = errors.New("message with given ID already exist")
)

Functions

func WithDatasync

func WithDatasync() func(c *config) error

Types

type Chat

type Chat struct {
	// ID is the id of the chat, for public chats it is the name e.g. status, for one-to-one
	// is the hex encoded public key and for group chats is a random uuid appended with
	// the hex encoded pk of the creator of the chat
	ID    string `json:"id"`
	Name  string `json:"name"`
	Color string `json:"color"`
	// Active indicates whether the chat has been soft deleted
	Active bool `json:"active"`

	ChatType ChatType `json:"chatType"`

	// Only filled for one to one chats
	PublicKey *ecdsa.PublicKey `json:"-"`

	// Timestamp indicates the last time this chat has received/sent a message
	Timestamp int64 `json:"timestamp"`
	// LastClockValue indicates the last clock value to be used when sending messages
	LastClockValue uint64 `json:"lastClockValue"`
	// DeletedAtClockValue indicates the clock value at time of deletion, messages
	// with lower clock value of this should be discarded
	DeletedAtClockValue uint64 `json:"deletedAtClockValue"`

	// Denormalized fields
	UnviewedMessagesCount  uint   `json:"unviewedMessagesCount"`
	LastMessageContentType string `json:"lastMessageContentType"`
	LastMessageContent     string `json:"lastMessageContent"`

	// Group chat fields
	// Members are the members who have been invited to the group chat
	Members []ChatMember `json:"members"`
	// MembershipUpdates is all the membership events in the chat
	MembershipUpdates []ChatMembershipUpdate `json:"membershipUpdates"`
}

type ChatMember

type ChatMember struct {
	// ID is the hex encoded public key of the member
	ID string `json:"id"`
	// Admin indicates if the member is an admin of the group chat
	Admin bool `json:"admin"`
	// Joined indicates if the member has joined the group chat
	Joined bool `json:"joined"`
}

ChatMember represents a member who participates in a group chat

func (ChatMember) PublicKey added in v0.2.0

func (c ChatMember) PublicKey() (*ecdsa.PublicKey, error)

type ChatMembershipUpdate

type ChatMembershipUpdate struct {
	// Unique identifier for the event
	ID string `json:"id"`
	// Type indicates the kind of event (i.e changed-name, added-member, etc)
	Type string `json:"type"`
	// Name represents the name in the event of changing name events
	Name string `json:"name,omitempty"`
	// Clock value of the event
	ClockValue uint64 `json:"clockValue"`
	// Signature of the event
	Signature string `json:"signature"`
	// Hex encoded public key of the creator of the event
	From string `json:"from"`
	// Target of the event for single-target events
	Member string `json:"member,omitempty"`
	// Target of the event for multi-target events
	Members []string `json:"members,omitempty"`
}

ChatMembershipUpdate represent an event on membership of the chat

type ChatMessages

type ChatMessages struct {
	Messages []*protocol.Message
	Public   bool
	ChatID   string
}

type ChatPagination

type ChatPagination struct {
	From uint
	To   uint
}

type ChatType

type ChatType int

type Contact

type Contact struct {
	// ID of the contact. It's a hex-encoded public key (prefixed with 0x).
	ID string `json:"id"`
	// Ethereum address of the contact
	Address string `json:"address"`
	// Name of contact
	Name string `json:"name"`
	// Photo is the base64 encoded photo
	Photo string `json:"photoPath"`
	// LastUpdated is the last time we received an update from the contact
	// updates should be discarded if last updated is less than the one stored
	LastUpdated int64 `json:"lastUpdated"`
	// SystemTags contains information about whether we blocked/added/have been
	// added.
	SystemTags []string `json:"systemTags"`

	DeviceInfo    []ContactDeviceInfo `json:"deviceInfo"`
	TributeToTalk string              `json:"tributeToTalk"`
}

Contact has information about a "Contact". A contact is not necessarily one that we added or added us, that's based on SystemTags.

func (Contact) HasBeenAdded added in v0.2.0

func (c Contact) HasBeenAdded() bool

func (Contact) IsAdded added in v0.2.0

func (c Contact) IsAdded() bool

func (Contact) IsBlocked added in v0.2.0

func (c Contact) IsBlocked() bool

func (Contact) PublicKey added in v0.2.0

func (c Contact) PublicKey() (*ecdsa.PublicKey, error)

type ContactDeviceInfo

type ContactDeviceInfo struct {
	// The installation id of the device
	InstallationID string `json:"id"`
	// Timestamp represents the last time we received this info
	Timestamp int64 `json:"timestamp"`
	// FCMToken is to be used for push notifications
	FCMToken string `json:"fcmToken"`
}

ContactDeviceInfo is a struct containing information about a particular device owned by a contact

type Message added in v0.2.0

type Message struct {
	// ID calculated as keccak256(compressedAuthorPubKey, data) where data is unencrypted payload.
	ID string `json:"id"`
	// WhisperTimestamp is a timestamp of a Whisper envelope.
	WhisperTimestamp int64 `json:"whisperTimestamp"`
	// From is a public key of the author of the message.
	From string `json:"from"`
	// To is a public key of the recipient unless it's a public message then it's empty.
	To hexutilSQL `json:"to,omitempty"`
	// BEGIN: fields from protocol.Message.
	Content       string `json:"content"`
	ContentType   string `json:"contentType"`
	Timestamp     int64  `json:"timestamp"`
	ChatID        string `json:"chatId"`
	MessageType   string `json:"messageType,omitempty"`
	MessageStatus string `json:"messageStatus,omitempty"`
	ClockValue    int64  `json:"clockValue"`
	// END
	Username       string `json:"username,omitempty"`
	RetryCount     int    `json:"retryCount"`
	Show           bool   `json:"show"` // default true
	Seen           bool   `json:"seen"`
	OutgoingStatus string `json:"outgoingStatus,omitempty"`
	// MessageID of the replied message
	ReplyTo       string         `json:"replyTo"`
	QuotedMessage *QuotedMessage `json:"quotedMessage"`
}

Message represents a message record in the database, more specifically in user_messages_legacy table. Encoding and decoding of byte blobs should be performed using hexutil package.

type Messenger

type Messenger struct {
	// contains filtered or unexported fields
}

Messenger is a entity managing chats and messages. It acts as a bridge between the application and encryption layers. It needs to expose an interface to manage installations because installations are managed by the user. Similarly, it needs to expose an interface to manage mailservers because they can also be managed by the user.

func NewMessenger

func NewMessenger(
	identity *ecdsa.PrivateKey,
	shh *whisper.Whisper,
	installationID string,
	opts ...Option,
) (*Messenger, error)

func (*Messenger) AddMailserver

func (m *Messenger) AddMailserver(enode string) error

NOT IMPLEMENTED

func (*Messenger) BlockContact added in v0.2.0

func (m *Messenger) BlockContact(contact Contact) ([]*Chat, error)

func (*Messenger) Chats

func (m *Messenger) Chats() ([]*Chat, error)

func (*Messenger) ConfirmMessagesProcessed

func (m *Messenger) ConfirmMessagesProcessed(messageIDs [][]byte) error

DEPRECATED

func (*Messenger) Contacts

func (m *Messenger) Contacts() ([]*Contact, error)

func (*Messenger) DeleteChat

func (m *Messenger) DeleteChat(chatID string) error

func (*Messenger) DeleteMessage added in v0.2.0

func (m *Messenger) DeleteMessage(id string) error

DEPRECATED: required by status-react.

func (*Messenger) DeleteMessagesByChatID added in v0.2.0

func (m *Messenger) DeleteMessagesByChatID(id string) error

DEPRECATED: required by status-react.

func (*Messenger) DisableInstallation

func (m *Messenger) DisableInstallation(id string) error

func (*Messenger) EnableInstallation

func (m *Messenger) EnableInstallation(id string) error

func (*Messenger) Init added in v0.2.0

func (m *Messenger) Init() error

Init analyzes chats and contacts in order to setup filters which are responsible for retrieving messages.

func (*Messenger) Installations

func (m *Messenger) Installations() ([]*multidevice.Installation, error)

func (*Messenger) Join

func (m *Messenger) Join(chat Chat) error

func (*Messenger) Leave

func (m *Messenger) Leave(chat Chat) error

func (*Messenger) LoadFilters

func (m *Messenger) LoadFilters(filters []*transport.Filter) ([]*transport.Filter, error)

DEPRECATED

func (*Messenger) Mailservers

func (m *Messenger) Mailservers() ([]string, error)

NOT IMPLEMENTED

func (*Messenger) MarkMessagesSeen added in v0.2.0

func (m *Messenger) MarkMessagesSeen(ids ...string) error

DEPRECATED: required by status-react.

func (*Messenger) MessageByChatID added in v0.2.0

func (m *Messenger) MessageByChatID(chatID, cursor string, limit int) ([]*Message, string, error)

DEPRECATED: required by status-react.

func (*Messenger) MessageByID added in v0.2.0

func (m *Messenger) MessageByID(id string) (*Message, error)

DEPRECATED: required by status-react.

func (*Messenger) MessagesExist added in v0.2.0

func (m *Messenger) MessagesExist(ids []string) (map[string]bool, error)

DEPRECATED: required by status-react.

func (*Messenger) RemoveFilters

func (m *Messenger) RemoveFilters(filters []*transport.Filter) error

DEPRECATED

func (*Messenger) RemoveMailserver

func (m *Messenger) RemoveMailserver(id string) error

NOT IMPLEMENTED

func (*Messenger) Retrieve

func (m *Messenger) Retrieve(ctx context.Context, chat Chat, c RetrieveConfig) (messages []*protocol.Message, err error)

func (*Messenger) RetrieveAll

func (m *Messenger) RetrieveAll(ctx context.Context, c RetrieveConfig) (allMessages []*protocol.Message, err error)

RetrieveAll retrieves all previously fetched messages

func (*Messenger) RetrieveRawAll

func (m *Messenger) RetrieveRawAll() (map[transport.Filter][]*protocol.StatusMessage, error)

DEPRECATED

func (*Messenger) SaveChat

func (m *Messenger) SaveChat(chat Chat) error

func (*Messenger) SaveContact

func (m *Messenger) SaveContact(contact Contact) error

func (*Messenger) SaveMessages added in v0.2.0

func (m *Messenger) SaveMessages(messages []*Message) error

DEPRECATED: required by status-react.

func (*Messenger) SelectMailserver

func (m *Messenger) SelectMailserver(id string) error

NOT IMPLEMENTED

func (*Messenger) Send

func (m *Messenger) Send(ctx context.Context, chat Chat, data []byte) ([]byte, error)

func (*Messenger) SendRaw

func (m *Messenger) SendRaw(ctx context.Context, chat Chat, data []byte) ([]byte, error)

SendRaw takes encoded data, encrypts it and sends through the wire. DEPRECATED

func (*Messenger) SetInstallationMetadata

func (m *Messenger) SetInstallationMetadata(id string, data *multidevice.InstallationMetadata) error

func (*Messenger) Shutdown

func (m *Messenger) Shutdown() (err error)

Shutdown takes care of ensuring a clean shutdown of Messenger

func (*Messenger) UpdateMessageOutgoingStatus added in v0.2.0

func (m *Messenger) UpdateMessageOutgoingStatus(id, newOutgoingStatus string) error

DEPRECATED: required by status-react.

type Option

type Option func(*config) error

func WithCustomLogger

func WithCustomLogger(logger *zap.Logger) Option

func WithDatabase

func WithDatabase(db *sql.DB) Option

func WithDatabaseConfig

func WithDatabaseConfig(dbPath, dbKey string) Option

func WithEnvelopesMonitorConfig

func WithEnvelopesMonitorConfig(emc *transport.EnvelopesMonitorConfig) Option

func WithGenericDiscoveryTopicSupport

func WithGenericDiscoveryTopicSupport() Option

func WithMessagesPersistenceEnabled

func WithMessagesPersistenceEnabled() Option

func WithOnNegotiatedFilters added in v0.2.0

func WithOnNegotiatedFilters(h func([]*transport.Filter)) Option

func WithOnNewInstallationsHandler

func WithOnNewInstallationsHandler(h func([]*multidevice.Installation)) Option

func WithSendV1Messages

func WithSendV1Messages() Option

type QuotedMessage added in v0.2.0

type QuotedMessage struct {
	// From is a public key of the author of the message.
	From    string `json:"from"`
	Content string `json:"content"`
}

QuotedMessage contains the original text of the message replied to

type RetrieveConfig

type RetrieveConfig struct {
	From time.Time
	To   time.Time
	// contains filtered or unexported fields
}

Directories

Path Synopsis
bridge
geth Module
internal
Package sqlite is responsible for creation of encrypted sqlite3 database using sqlcipher driver.
Package sqlite is responsible for creation of encrypted sqlite3 database using sqlcipher driver.
transport

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL