TokenStore

class TokenStore(seedPrimary: String? = null)

Bearer-token authority for HttpTransport.

Holds one primary token (the value surfaced as DroidMcp.serverToken and embedded in the pairing QR) plus any number of paired-client tokens, each tied to an opaque host-supplied label so it can be revoked individually.

  • verify returns the label that owns a presented token, or null if none matches — callers use the label for audit attribution.

  • rotatePrimary mints a fresh primary, invalidating the old one. Paired clients are unaffected.

  • pair mints a new per-client token; revoke drops it.

All comparisons are constant-time over each candidate token so a presented value can't be recovered byte-by-byte via timing. The number of paired clients is small and host-controlled, so iterating them is not a concern.

Thread-safe: the primary is @Volatile, clients live in a ConcurrentHashMap.

Constructors

Link copied to clipboard
constructor(seedPrimary: String? = null)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
data class PairedClient(val label: String, val token: String, val createdAt: Long)

A minted per-client credential.

Properties

Link copied to clipboard

The current primary token.

Functions

Link copied to clipboard
fun pair(label: String): String

Mint a token for a named client. Re-pairing an existing label replaces its token (and invalidates the previous one). Returns the new token.

Link copied to clipboard

Snapshot of paired clients (does not include the primary), oldest first. Ties on PairedClient.createdAt (two pairings within the same millisecond) break deterministically on the unique label, so the order is stable rather than dependent on map iteration order.

Link copied to clipboard
fun revoke(label: String): Boolean

Revoke a client's token. @return true if a client with that label existed.

Link copied to clipboard

Replace the primary token with a fresh value and return it.

Link copied to clipboard
fun verify(provided: String?): String?

Resolve a presented token to the label that owns it.