store

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

README

Store

SQLite Store

Identity Store

The identity store stores the user's long term public and private identity keys

Prekey Store

The prekey store stores the user's unsigned prekeys, which are used for establishing secure sessions with other users.

Signed Prekey Store

The signed prekey store stores the user's signed prekeys, which are used for establishing secure sessions with other users.

Session Store

The session store stores the user's active sessions with other users, including the session keys and other metadata.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTables

func CreateTables(db *sql.DB) error

CreateTables ensures that the necessary tables for the Signal Protocol stores exist.

func DecodeAndDeserializeKeyPair

func DecodeAndDeserializeKeyPair(data []byte, value interface{}) error

DecodeAndDeserializeKeyPair deserializes a JSON-encoded byte slice into the provided struct (mimics gobDecode).

func ExtractUserIDAndDeviceID

func ExtractUserIDAndDeviceID(registrationID uint32) (uint32, uint32)

ExtractUserIDAndDeviceID extracts the userID and deviceID from a combined registrationID.

func GenerateRegistrationID

func GenerateRegistrationID(userID, deviceID uint32) uint32

func GetMACAddress

func GetMACAddress() (string, error)

func LoadLocalIdentity

func LoadLocalIdentity(db *sql.DB, userID uint32) (identity.KeyPair, uint32, error)

LoadLocalIdentity loads the identity key pair and registration ID based on the current device's MAC address.

func MacToUint32

func MacToUint32(macAddr string) (uint32, error)

Convert a MAC address string into a uint32 with a limit to 10 bits

func NewGroupStore

func NewGroupStore() session.GroupStore

NewIdentityStore creates a new SQLite-backed identity store.

func NewIdentityStore

func NewIdentityStore(db *sql.DB) identity.Store

NewIdentityStore creates a new SQLite-backed identity store.

func NewPreKeyStore

func NewPreKeyStore(db *sql.DB) prekey.Store

NewPreKeyStore creates a new SQLite-backed pre-key store.

func NewSessionStore

func NewSessionStore(db *sql.DB) session.Store

NewSessionStore creates a new SQLite-backed session store.

func NewSignedPreKeyStore

func NewSignedPreKeyStore(db *sql.DB) prekey.SignedStore

NewSignedPreKeyStore creates a new SQLite-backed signed pre-key store.

func SerializeKeyPairAndEncode

func SerializeKeyPairAndEncode(keyPair interface{}) ([]byte, error)

SerializeKeyPairAndEncode serializes a struct to JSON format (mimics gobEncode).

func To

func To[T any](t T) *T

To returns a pointer to the given type.

Types

type ChatMessage

type ChatMessage struct {
	MessageID  string    `json:"messageId"`
	SenderID   uint32    `json:"senderId"`
	ReceiverID uint32    `json:"receiverId"`
	Message    string    `json:"message"`
	Timestamp  time.Time `json:"timestamp"`
	Delivered  int       `json:"delivered"`
}

type GroupStore

type GroupStore struct{}

func (*GroupStore) Load

func (g *GroupStore) Load(ctx context.Context, sender address.Address, distributionID distribution.ID) (*session.GroupRecord, bool, error)

func (*GroupStore) Store

func (g *GroupStore) Store(ctx context.Context, sender address.Address, distributionID distribution.ID, record *session.GroupRecord) error

type IdentityStore

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

func (*IdentityStore) Clear

func (s *IdentityStore) Clear() error

Clear removes all items from the store.

func (*IdentityStore) IsTrustedIdentity

func (s *IdentityStore) IsTrustedIdentity(ctx context.Context, addr address.Address, identityKey identity.Key, _ direction.Direction) (bool, error)

IsTrustedIdentity returns "true" if the given identity key for the given address is already trusted. If there is no entry for the given address, the given identity key is trusted.

func (*IdentityStore) KeyPair

KeyPair returns the associated identity key pair from the database.

func (*IdentityStore) Load

Load loads the identity key associated with the remote address.

func (*IdentityStore) LocalRegistrationID

func (s *IdentityStore) LocalRegistrationID(_ context.Context) uint32

LocalRegistrationID returns the associated registration ID from the database.

func (*IdentityStore) Store

func (s *IdentityStore) Store(ctx context.Context, addr address.Address, identityKey identity.Key) (bool, error)

Store stores the identity key associated with the remote address and returns "true" if there is already an entry for the address that is overwritten with a new identity key.

type LocalIdentity

type LocalIdentity struct {
	IdentityPublicKey     []byte
	PreKeyID              uint32
	PreKeyPublicKey       []byte
	SignedPreKeyID        uint32
	SignedPreKeyPublicKey []byte
	Signature             []byte
}

type PreKeyStore

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

func (*PreKeyStore) Delete

func (s *PreKeyStore) Delete(ctx context.Context, id prekey.ID) error

Delete removes a pre-key entry identified by the given ID from the store.

func (*PreKeyStore) Load

func (s *PreKeyStore) Load(ctx context.Context, id prekey.ID) (*prekey.PreKey, bool, error)

Load retrieves a pre-key record for the given ID.

func (*PreKeyStore) Store

func (s *PreKeyStore) Store(ctx context.Context, id prekey.ID, preKey *prekey.PreKey) error

Store saves a pre-key record for the given ID.

type SQLiteStore

type SQLiteStore struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

func NewSQLiteStore

func NewSQLiteStore(dbPath string) (*SQLiteStore, error)

func (*SQLiteStore) CreateLocalIdentity

func (s *SQLiteStore) CreateLocalIdentity(registrationID uint32) (*LocalIdentity, error)

func (*SQLiteStore) DeleteMessage

func (s *SQLiteStore) DeleteMessage(messageID int64) error

DeleteMessage deletes a specific message from the `chat_history` table.

func (*SQLiteStore) GetAllChatHistory

func (s *SQLiteStore) GetAllChatHistory() ([]ChatMessage, error)

GetAllChatHistory retrieves all stored chat messages.

func (*SQLiteStore) GetChatHistory

func (s *SQLiteStore) GetChatHistory(senderID, receiverID uint32) ([]ChatMessage, error)

GetChatHistory retrieves all chat messages between a sender and receiver.

func (*SQLiteStore) GetChatHistoryBetweenUsers

func (s *SQLiteStore) GetChatHistoryBetweenUsers(senderID, receiverID uint32) ([]ChatMessage, error)

func (*SQLiteStore) GroupStore

func (s *SQLiteStore) GroupStore() session.GroupStore

func (*SQLiteStore) IdentityStore

func (s *SQLiteStore) IdentityStore() identity.Store

func (*SQLiteStore) PreKeyStore

func (s *SQLiteStore) PreKeyStore() prekey.Store

func (*SQLiteStore) SaveChatMessage

func (s *SQLiteStore) SaveChatMessage(messageID string, senderID, receiverID uint32, message string, delivered int) error

SaveChatMessage inserts a new chat message with the specified messageId into the `chat_history` table.

func (*SQLiteStore) SessionStore

func (s *SQLiteStore) SessionStore() session.Store

func (*SQLiteStore) SignedPreKeyStore

func (s *SQLiteStore) SignedPreKeyStore() prekey.SignedStore

func (*SQLiteStore) UpdateMessageDeliveryStatus

func (s *SQLiteStore) UpdateMessageDeliveryStatus(messageID string, delivered bool) error

UpdateMessageDeliveryStatus updates the `delivered` status of a message in the `chat_history` table.

type SerializableKeyPair

type SerializableKeyPair struct {
	PrivateKey []byte `json:"privateKey"`
	PublicKey  []byte `json:"publicKey"`
}

type SessionStore

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

func (*SessionStore) Load

Load retrieves a session record for the given address.

func (*SessionStore) Store

func (s *SessionStore) Store(ctx context.Context, addr address.Address, record *session.Record) error

Store saves a session record for the given address.

type SignedPreKeyStore

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

func (*SignedPreKeyStore) Load

Load retrieves a signed pre-key record for the given ID.

func (*SignedPreKeyStore) Store

func (s *SignedPreKeyStore) Store(ctx context.Context, id prekey.ID, record *prekey.SignedPreKey) error

Store saves a signed pre-key record for the given ID.

Jump to

Keyboard shortcuts

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