whatsmeowgo.mau.fi/whatsmeow/store Index | Files | Directories

package store

import "go.mau.fi/whatsmeow/store"

Package store contains interfaces for storing data needed for WhatsApp multidevice.

Index

Variables

var BaseClientPayload = &waWa6.ClientPayload{
	UserAgent: &waWa6.ClientPayload_UserAgent{
		Platform:       waWa6.ClientPayload_UserAgent_WEB.Enum(),
		ReleaseChannel: waWa6.ClientPayload_UserAgent_RELEASE.Enum(),
		AppVersion:     waVersion.ProtoAppVersion(),
		Mcc:            proto.String("000"),
		Mnc:            proto.String("000"),
		OsVersion:      proto.String("0.1.0"),
		Manufacturer:   proto.String(""),
		Device:         proto.String("Desktop"),
		OsBuildNumber:  proto.String("0.1.0"),

		LocaleLanguageIso6391:       proto.String("en"),
		LocaleCountryIso31661Alpha2: proto.String("en"),
	},
	WebInfo: &waWa6.ClientPayload_WebInfo{
		WebSubPlatform: waWa6.ClientPayload_WebInfo_WEB_BROWSER.Enum(),
	},
	ConnectType:   waWa6.ClientPayload_WIFI_UNKNOWN.Enum(),
	ConnectReason: waWa6.ClientPayload_USER_ACTIVATED.Enum(),
}
var DeviceProps = &waCompanionReg.DeviceProps{
	Os: proto.String("whatsmeow"),
	Version: &waCompanionReg.DeviceProps_AppVersion{
		Primary:   proto.Uint32(0),
		Secondary: proto.Uint32(1),
		Tertiary:  proto.Uint32(0),
	},
	PlatformType:    waCompanionReg.DeviceProps_UNKNOWN.Enum(),
	RequireFullSync: proto.Bool(false),
}
var NoopDevice = &Device{
	ID:          &types.EmptyJID,
	NoiseKey:    nilKey,
	IdentityKey: nilKey,

	Identities:    nilStore,
	Sessions:      nilStore,
	PreKeys:       nilStore,
	SenderKeys:    nilStore,
	AppStateKeys:  nilStore,
	AppState:      nilStore,
	Contacts:      nilStore,
	ChatSettings:  nilStore,
	MsgSecrets:    nilStore,
	PrivacyTokens: nilStore,
	EventBuffer:   nilStore,
	Container:     nilStore,
}
var SignalProtobufSerializer = serialize.NewProtoBufSerializer()

Functions

func SetOSInfo

func SetOSInfo(name string, version [3]uint32)

func SetWAVersion

func SetWAVersion(version WAVersionContainer)

SetWAVersion sets the current WhatsApp web client version.

In general, you should keep the library up-to-date instead of using this, as there may be code changes that are necessary too (like protobuf schema changes).

Types

type AllGlobalStores

type AllGlobalStores interface {
	LIDStore
}

type AllSessionSpecificStores

type AllStores

type AllStores interface {
	AllSessionSpecificStores
	AllGlobalStores
}

type AppStateMutationMAC

type AppStateMutationMAC struct {
	IndexMAC []byte
	ValueMAC []byte
}

type AppStateStore

type AppStateStore interface {
	PutAppStateVersion(ctx context.Context, name string, version uint64, hash [128]byte) error
	GetAppStateVersion(ctx context.Context, name string) (uint64, [128]byte, error)
	DeleteAppStateVersion(ctx context.Context, name string) error

	PutAppStateMutationMACs(ctx context.Context, name string, version uint64, mutations []AppStateMutationMAC) error
	DeleteAppStateMutationMACs(ctx context.Context, name string, indexMACs [][]byte) error
	GetAppStateMutationMAC(ctx context.Context, name string, indexMAC []byte) (valueMAC []byte, err error)
}

type AppStateSyncKey

type AppStateSyncKey struct {
	Data        []byte
	Fingerprint []byte
	Timestamp   int64
}

type AppStateSyncKeyStore

type AppStateSyncKeyStore interface {
	PutAppStateSyncKey(ctx context.Context, id []byte, key AppStateSyncKey) error
	GetAppStateSyncKey(ctx context.Context, id []byte) (*AppStateSyncKey, error)
	GetLatestAppStateSyncKeyID(ctx context.Context) ([]byte, error)
}

type BufferedEvent

type BufferedEvent struct {
	Plaintext  []byte
	InsertTime time.Time
	ServerTime time.Time
}

type ChatSettingsStore

type ChatSettingsStore interface {
	PutMutedUntil(ctx context.Context, chat types.JID, mutedUntil time.Time) error
	PutPinned(ctx context.Context, chat types.JID, pinned bool) error
	PutArchived(ctx context.Context, chat types.JID, archived bool) error
	GetChatSettings(ctx context.Context, chat types.JID) (types.LocalChatSettings, error)
}

type ContactEntry

type ContactEntry struct {
	JID       types.JID
	FirstName string
	FullName  string
}

type ContactStore

type ContactStore interface {
	PutPushName(ctx context.Context, user types.JID, pushName string) (bool, string, error)
	PutBusinessName(ctx context.Context, user types.JID, businessName string) (bool, string, error)
	PutContactName(ctx context.Context, user types.JID, fullName, firstName string) error
	PutAllContactNames(ctx context.Context, contacts []ContactEntry) error
	GetContact(ctx context.Context, user types.JID) (types.ContactInfo, error)
	GetAllContacts(ctx context.Context) (map[types.JID]types.ContactInfo, error)
}

type Device

type Device struct {
	Log waLog.Logger

	NoiseKey       *keys.KeyPair
	IdentityKey    *keys.KeyPair
	SignedPreKey   *keys.PreKey
	RegistrationID uint32
	AdvSecretKey   []byte

	ID           *types.JID
	LID          types.JID
	Account      *waAdv.ADVSignedDeviceIdentity
	Platform     string
	BusinessName string
	PushName     string

	FacebookUUID uuid.UUID

	Initialized   bool
	Identities    IdentityStore
	Sessions      SessionStore
	PreKeys       PreKeyStore
	SenderKeys    SenderKeyStore
	AppStateKeys  AppStateSyncKeyStore
	AppState      AppStateStore
	Contacts      ContactStore
	ChatSettings  ChatSettingsStore
	MsgSecrets    MsgSecretStore
	PrivacyTokens PrivacyTokenStore
	EventBuffer   EventBuffer
	LIDs          LIDStore
	Container     DeviceContainer
}

func (*Device) ContainsPreKey

func (device *Device) ContainsPreKey(ctx context.Context, preKeyID uint32) (bool, error)

func (*Device) ContainsSession

func (device *Device) ContainsSession(ctx context.Context, remoteAddress *protocol.SignalAddress) (bool, error)

func (*Device) ContainsSignedPreKey

func (device *Device) ContainsSignedPreKey(ctx context.Context, signedPreKeyID uint32) (bool, error)

func (*Device) Delete

func (device *Device) Delete(ctx context.Context) error

func (*Device) DeleteAllSessions

func (device *Device) DeleteAllSessions(ctx context.Context) error

func (*Device) DeleteSession

func (device *Device) DeleteSession(ctx context.Context, remoteAddress *protocol.SignalAddress) error

func (*Device) GetClientPayload

func (device *Device) GetClientPayload() *waWa6.ClientPayload

func (*Device) GetIdentityKeyPair

func (device *Device) GetIdentityKeyPair() *identity.KeyPair

func (*Device) GetJID

func (device *Device) GetJID() types.JID

func (*Device) GetLID

func (device *Device) GetLID() types.JID

func (*Device) GetLocalRegistrationID

func (device *Device) GetLocalRegistrationID() uint32

func (*Device) GetSubDeviceSessions

func (device *Device) GetSubDeviceSessions(ctx context.Context, name string) ([]uint32, error)

func (*Device) IsTrustedIdentity

func (device *Device) IsTrustedIdentity(ctx context.Context, address *protocol.SignalAddress, identityKey *identity.Key) (bool, error)

func (*Device) LoadPreKey

func (device *Device) LoadPreKey(ctx context.Context, id uint32) (*record.PreKey, error)

func (*Device) LoadSenderKey

func (device *Device) LoadSenderKey(ctx context.Context, senderKeyName *protocol.SenderKeyName) (*groupRecord.SenderKey, error)

func (*Device) LoadSession

func (device *Device) LoadSession(ctx context.Context, address *protocol.SignalAddress) (*record.Session, error)

func (*Device) LoadSignedPreKey

func (device *Device) LoadSignedPreKey(ctx context.Context, signedPreKeyID uint32) (*record.SignedPreKey, error)

func (*Device) LoadSignedPreKeys

func (device *Device) LoadSignedPreKeys(ctx context.Context) ([]*record.SignedPreKey, error)

func (*Device) RemovePreKey

func (device *Device) RemovePreKey(ctx context.Context, id uint32) error

func (*Device) RemoveSignedPreKey

func (device *Device) RemoveSignedPreKey(ctx context.Context, signedPreKeyID uint32) error

func (*Device) Save

func (device *Device) Save(ctx context.Context) error

func (*Device) SaveIdentity

func (device *Device) SaveIdentity(ctx context.Context, address *protocol.SignalAddress, identityKey *identity.Key) error

func (*Device) StorePreKey

func (device *Device) StorePreKey(ctx context.Context, preKeyID uint32, preKeyRecord *record.PreKey) error

func (*Device) StoreSenderKey

func (device *Device) StoreSenderKey(ctx context.Context, senderKeyName *protocol.SenderKeyName, keyRecord *groupRecord.SenderKey) error

func (*Device) StoreSession

func (device *Device) StoreSession(ctx context.Context, address *protocol.SignalAddress, record *record.Session) error

func (*Device) StoreSignedPreKey

func (device *Device) StoreSignedPreKey(ctx context.Context, signedPreKeyID uint32, record *record.SignedPreKey) error

type DeviceContainer

type DeviceContainer interface {
	PutDevice(ctx context.Context, store *Device) error
	DeleteDevice(ctx context.Context, store *Device) error
}

type EventBuffer

type EventBuffer interface {
	GetBufferedEvent(ctx context.Context, ciphertextHash [32]byte) (*BufferedEvent, error)
	PutBufferedEvent(ctx context.Context, ciphertextHash [32]byte, plaintext []byte, serverTimestamp time.Time) error
	DoDecryptionTxn(ctx context.Context, fn func(context.Context) error) error
	ClearBufferedEventPlaintext(ctx context.Context, ciphertextHash [32]byte) error
	DeleteOldBufferedHashes(ctx context.Context) error
}

type IdentityStore

type IdentityStore interface {
	PutIdentity(ctx context.Context, address string, key [32]byte) error
	DeleteAllIdentities(ctx context.Context, phone string) error
	DeleteIdentity(ctx context.Context, address string) error
	IsTrustedIdentity(ctx context.Context, address string, key [32]byte) (bool, error)
}

type LIDMapping

type LIDMapping struct {
	LID types.JID
	PN  types.JID
}

type LIDStore

type LIDStore interface {
	PutManyLIDMappings(ctx context.Context, mappings []LIDMapping) error
	PutLIDMapping(ctx context.Context, lid, jid types.JID) error
	GetPNForLID(ctx context.Context, lid types.JID) (types.JID, error)
	GetLIDForPN(ctx context.Context, pn types.JID) (types.JID, error)
}

type MessageSecretInsert

type MessageSecretInsert struct {
	Chat   types.JID
	Sender types.JID
	ID     types.MessageID
	Secret []byte
}

type MsgSecretStore

type MsgSecretStore interface {
	PutMessageSecrets(ctx context.Context, inserts []MessageSecretInsert) error
	PutMessageSecret(ctx context.Context, chat, sender types.JID, id types.MessageID, secret []byte) error
	GetMessageSecret(ctx context.Context, chat, sender types.JID, id types.MessageID) ([]byte, error)
}

type NoopStore

type NoopStore struct {
	Error error
}

func (*NoopStore) ClearBufferedEventPlaintext

func (n *NoopStore) ClearBufferedEventPlaintext(ctx context.Context, ciphertextHash [32]byte) error

func (*NoopStore) DeleteAllIdentities

func (n *NoopStore) DeleteAllIdentities(ctx context.Context, phone string) error

func (*NoopStore) DeleteAllSessions

func (n *NoopStore) DeleteAllSessions(ctx context.Context, phone string) error

func (*NoopStore) DeleteAppStateMutationMACs

func (n *NoopStore) DeleteAppStateMutationMACs(ctx context.Context, name string, indexMACs [][]byte) error

func (*NoopStore) DeleteAppStateVersion

func (n *NoopStore) DeleteAppStateVersion(ctx context.Context, name string) error

func (*NoopStore) DeleteDevice

func (n *NoopStore) DeleteDevice(ctx context.Context, store *Device) error

func (*NoopStore) DeleteIdentity

func (n *NoopStore) DeleteIdentity(ctx context.Context, address string) error

func (*NoopStore) DeleteOldBufferedHashes

func (n *NoopStore) DeleteOldBufferedHashes(ctx context.Context) error

func (*NoopStore) DeleteSession

func (n *NoopStore) DeleteSession(ctx context.Context, address string) error

func (*NoopStore) DoDecryptionTxn

func (n *NoopStore) DoDecryptionTxn(ctx context.Context, fn func(context.Context) error) error

func (*NoopStore) GenOnePreKey

func (n *NoopStore) GenOnePreKey(ctx context.Context) (*keys.PreKey, error)

func (*NoopStore) GetAllContacts

func (n *NoopStore) GetAllContacts(ctx context.Context) (map[types.JID]types.ContactInfo, error)

func (*NoopStore) GetAppStateMutationMAC

func (n *NoopStore) GetAppStateMutationMAC(ctx context.Context, name string, indexMAC []byte) (valueMAC []byte, err error)

func (*NoopStore) GetAppStateSyncKey

func (n *NoopStore) GetAppStateSyncKey(ctx context.Context, id []byte) (*AppStateSyncKey, error)

func (*NoopStore) GetAppStateVersion

func (n *NoopStore) GetAppStateVersion(ctx context.Context, name string) (uint64, [128]byte, error)

func (*NoopStore) GetBufferedEvent

func (n *NoopStore) GetBufferedEvent(ctx context.Context, ciphertextHash [32]byte) (*BufferedEvent, error)

func (*NoopStore) GetChatSettings

func (n *NoopStore) GetChatSettings(ctx context.Context, chat types.JID) (types.LocalChatSettings, error)

func (*NoopStore) GetContact

func (n *NoopStore) GetContact(ctx context.Context, user types.JID) (types.ContactInfo, error)

func (*NoopStore) GetLIDForPN

func (n *NoopStore) GetLIDForPN(ctx context.Context, pn types.JID) (types.JID, error)

func (*NoopStore) GetLatestAppStateSyncKeyID

func (n *NoopStore) GetLatestAppStateSyncKeyID(ctx context.Context) ([]byte, error)

func (*NoopStore) GetMessageSecret

func (n *NoopStore) GetMessageSecret(ctx context.Context, chat, sender types.JID, id types.MessageID) ([]byte, error)

func (*NoopStore) GetOrGenPreKeys

func (n *NoopStore) GetOrGenPreKeys(ctx context.Context, count uint32) ([]*keys.PreKey, error)

func (*NoopStore) GetPNForLID

func (n *NoopStore) GetPNForLID(ctx context.Context, lid types.JID) (types.JID, error)

func (*NoopStore) GetPreKey

func (n *NoopStore) GetPreKey(ctx context.Context, id uint32) (*keys.PreKey, error)

func (*NoopStore) GetPrivacyToken

func (n *NoopStore) GetPrivacyToken(ctx context.Context, user types.JID) (*PrivacyToken, error)

func (*NoopStore) GetSenderKey

func (n *NoopStore) GetSenderKey(ctx context.Context, group, user string) ([]byte, error)

func (*NoopStore) GetSession

func (n *NoopStore) GetSession(ctx context.Context, address string) ([]byte, error)

func (*NoopStore) HasSession

func (n *NoopStore) HasSession(ctx context.Context, address string) (bool, error)

func (*NoopStore) IsTrustedIdentity

func (n *NoopStore) IsTrustedIdentity(ctx context.Context, address string, key [32]byte) (bool, error)

func (*NoopStore) MarkPreKeysAsUploaded

func (n *NoopStore) MarkPreKeysAsUploaded(ctx context.Context, upToID uint32) error

func (*NoopStore) MigratePNToLID

func (n *NoopStore) MigratePNToLID(ctx context.Context, pn, lid types.JID) error

func (*NoopStore) PutAllContactNames

func (n *NoopStore) PutAllContactNames(ctx context.Context, contacts []ContactEntry) error

func (*NoopStore) PutAppStateMutationMACs

func (n *NoopStore) PutAppStateMutationMACs(ctx context.Context, name string, version uint64, mutations []AppStateMutationMAC) error

func (*NoopStore) PutAppStateSyncKey

func (n *NoopStore) PutAppStateSyncKey(ctx context.Context, id []byte, key AppStateSyncKey) error

func (*NoopStore) PutAppStateVersion

func (n *NoopStore) PutAppStateVersion(ctx context.Context, name string, version uint64, hash [128]byte) error

func (*NoopStore) PutArchived

func (n *NoopStore) PutArchived(ctx context.Context, chat types.JID, archived bool) error

func (*NoopStore) PutBufferedEvent

func (n *NoopStore) PutBufferedEvent(ctx context.Context, ciphertextHash [32]byte, plaintext []byte, serverTimestamp time.Time) error

func (*NoopStore) PutBusinessName

func (n *NoopStore) PutBusinessName(ctx context.Context, user types.JID, businessName string) (bool, string, error)

func (*NoopStore) PutContactName

func (n *NoopStore) PutContactName(ctx context.Context, user types.JID, fullName, firstName string) error

func (*NoopStore) PutDevice

func (n *NoopStore) PutDevice(ctx context.Context, store *Device) error

func (*NoopStore) PutIdentity

func (n *NoopStore) PutIdentity(ctx context.Context, address string, key [32]byte) error

func (*NoopStore) PutLIDMapping

func (n *NoopStore) PutLIDMapping(ctx context.Context, lid types.JID, jid types.JID) error

func (*NoopStore) PutManyLIDMappings

func (n *NoopStore) PutManyLIDMappings(ctx context.Context, mappings []LIDMapping) error

func (*NoopStore) PutMessageSecret

func (n *NoopStore) PutMessageSecret(ctx context.Context, chat, sender types.JID, id types.MessageID, secret []byte) error

func (*NoopStore) PutMessageSecrets

func (n *NoopStore) PutMessageSecrets(ctx context.Context, inserts []MessageSecretInsert) error

func (*NoopStore) PutMutedUntil

func (n *NoopStore) PutMutedUntil(ctx context.Context, chat types.JID, mutedUntil time.Time) error

func (*NoopStore) PutPinned

func (n *NoopStore) PutPinned(ctx context.Context, chat types.JID, pinned bool) error

func (*NoopStore) PutPrivacyTokens

func (n *NoopStore) PutPrivacyTokens(ctx context.Context, tokens ...PrivacyToken) error

func (*NoopStore) PutPushName

func (n *NoopStore) PutPushName(ctx context.Context, user types.JID, pushName string) (bool, string, error)

func (*NoopStore) PutSenderKey

func (n *NoopStore) PutSenderKey(ctx context.Context, group, user string, session []byte) error

func (*NoopStore) PutSession

func (n *NoopStore) PutSession(ctx context.Context, address string, session []byte) error

func (*NoopStore) RemovePreKey

func (n *NoopStore) RemovePreKey(ctx context.Context, id uint32) error

func (*NoopStore) UploadedPreKeyCount

func (n *NoopStore) UploadedPreKeyCount(ctx context.Context) (int, error)

type PreKeyStore

type PreKeyStore interface {
	GetOrGenPreKeys(ctx context.Context, count uint32) ([]*keys.PreKey, error)
	GenOnePreKey(ctx context.Context) (*keys.PreKey, error)
	GetPreKey(ctx context.Context, id uint32) (*keys.PreKey, error)
	RemovePreKey(ctx context.Context, id uint32) error
	MarkPreKeysAsUploaded(ctx context.Context, upToID uint32) error
	UploadedPreKeyCount(ctx context.Context) (int, error)
}

type PrivacyToken

type PrivacyToken struct {
	User      types.JID
	Token     []byte
	Timestamp time.Time
}

type PrivacyTokenStore

type PrivacyTokenStore interface {
	PutPrivacyTokens(ctx context.Context, tokens ...PrivacyToken) error
	GetPrivacyToken(ctx context.Context, user types.JID) (*PrivacyToken, error)
}

type SenderKeyStore

type SenderKeyStore interface {
	PutSenderKey(ctx context.Context, group, user string, session []byte) error
	GetSenderKey(ctx context.Context, group, user string) ([]byte, error)
}

type SessionStore

type SessionStore interface {
	GetSession(ctx context.Context, address string) ([]byte, error)
	HasSession(ctx context.Context, address string) (bool, error)
	PutSession(ctx context.Context, address string, session []byte) error
	DeleteAllSessions(ctx context.Context, phone string) error
	DeleteSession(ctx context.Context, address string) error
	MigratePNToLID(ctx context.Context, pn, lid types.JID) error
}

type WAVersionContainer

type WAVersionContainer [3]uint32

WAVersionContainer is a container for a WhatsApp web version number.

func GetWAVersion

func GetWAVersion() WAVersionContainer

GetWAVersion gets the current WhatsApp web client version.

func ParseVersion

func ParseVersion(version string) (parsed WAVersionContainer, err error)

ParseVersion parses a version string (three dot-separated numbers) into a WAVersionContainer.

func (WAVersionContainer) Hash

func (vc WAVersionContainer) Hash() [16]byte

Hash returns the md5 hash of the String representation of this version.

func (WAVersionContainer) IsZero

func (vc WAVersionContainer) IsZero() bool

IsZero returns true if the version is zero.

func (WAVersionContainer) LessThan

func (vc WAVersionContainer) LessThan(other WAVersionContainer) bool

func (WAVersionContainer) ProtoAppVersion

func (WAVersionContainer) String

func (vc WAVersionContainer) String() string

String returns the version number as a dot-separated string.

Source Files

clientpayload.go noop.go signal.go store.go

Directories

PathSynopsis
store/sqlstorePackage sqlstore contains an SQL-backed implementation of the interfaces in the store package.
store/sqlstore/upgrades
Version
v0.0.0-20250603144927-2b269a5d396a (latest)
Published
Jun 3, 2025
Platform
linux/amd64
Imports
23 packages
Last checked
5 hours ago

Tools for package owners.