PreKeyStore

interface PreKeyStore

The local device's private prekeys.

Signed prekeys follow a lifecycle (docs/signed-prekey-lifecycle.md): the current one is published; storeCurrentSignedPreKey moves it into a grace period in which an incoming PreKeyMessage may still name it; the client deletes it with removeSignedPreKey once the grace period is over. Storage only records the timestamps, the client makes the decisions.

IDs are allocated upward from a persisted high-water mark (the highest ID ever stored, see highestSignedPreKeyId and highestOneTimePreKeyId). Removing a key does not lower it, so IDs are never reused. Storing a key whose ID is not above the high-water mark throws IllegalArgumentException.

Functions

Link copied to clipboard
abstract suspend fun currentSignedPreKey(): SignedPreKeyPair?

The signed prekey to publish, or null if none was stored yet.

Link copied to clipboard
abstract suspend fun highestOneTimePreKeyId(): OneTimePreKeyId?
Link copied to clipboard
abstract suspend fun highestSignedPreKeyId(): SignedPreKeyId?
Link copied to clipboard
abstract suspend fun oneTimePreKey(id: OneTimePreKeyId): OneTimePreKeyPair?
Link copied to clipboard
abstract suspend fun oneTimePreKeyCount(): Int
Link copied to clipboard

Public halves of all stored one-time prekeys, ordered by ID.

Link copied to clipboard
abstract suspend fun removeOneTimePreKey(id: OneTimePreKeyId)

Deletes a one-time prekey after a session was accepted with it.

Link copied to clipboard
abstract suspend fun removeSignedPreKey(id: SignedPreKeyId)

Deletes the signed prekey id, private key included. Throws IllegalArgumentException for the current one. Deleting a key that is not stored does nothing. The high-water mark is kept.

Link copied to clipboard
abstract suspend fun signedPreKey(id: SignedPreKeyId): SignedPreKeyPair?

Any stored signed prekey, current or replaced.

Link copied to clipboard

Metadata of the stored signed prekey id, or null if it is not stored.

Link copied to clipboard
abstract suspend fun signedPreKeyInfos(): List<SignedPreKeyInfo>

Metadata of all stored signed prekeys, ordered by ID.

Link copied to clipboard
abstract suspend fun stampLegacySignedPreKeys(at: Instant)

Gives keys stored before milestone 7 their timestamps: a missing SignedPreKeyInfo.createdAt becomes at, and so does a missing SignedPreKeyInfo.replacedAt of a key that is not current. Keys that have timestamps are not changed.

Link copied to clipboard
abstract suspend fun storeCurrentSignedPreKey(preKey: SignedPreKeyPair, createdAt: Instant)

Stores preKey, created at createdAt, and makes it current. The previous current key stays available by ID; its SignedPreKeyInfo.replacedAt becomes createdAt.

Link copied to clipboard
abstract suspend fun storeOneTimePreKeys(preKeys: List<OneTimePreKeyPair>)