UNPKG

@opendatalabs/vana-sdk

Version:

A TypeScript library for interacting with Vana Network smart contracts.

62 lines (61 loc) 1.8 kB
/** * Token storage primitives for OAuth grant and access tokens. * * @remarks * Defines the {@link TokenStore} interface and a default in-memory * implementation. Persistent backends (e.g., browser storage, secure * keychains) are intentionally not provided here — consumers can implement * the interface for their environment. * * @category Auth * @module auth/token-store */ /** * A persisted token record. */ export interface TokenRecord { /** The opaque token value. */ token: string; /** Optional expiration as a Unix timestamp in seconds. */ expiresAt?: number; } /** * Async key/value store for token records. */ export interface TokenStore { /** * Returns the record for `key`, or `null` if missing or expired. */ get(key: string): Promise<TokenRecord | null>; /** * Stores `record` under `key`, overwriting any existing entry. */ set(key: string, record: TokenRecord): Promise<void>; /** * Removes the entry for `key`. No-op if `key` is absent. */ delete(key: string): Promise<void>; /** * Removes all entries. */ clear(): Promise<void>; } /** * In-memory {@link TokenStore} implementation. * * @remarks * Expired entries are evicted lazily on read. Records are shallow-copied on * `set` and `get` so caller mutations do not leak into stored state. */ export declare class InMemoryTokenStore implements TokenStore { #private; get(key: string): Promise<TokenRecord | null>; set(key: string, record: TokenRecord): Promise<void>; delete(key: string): Promise<void>; clear(): Promise<void>; /** * Returns the number of stored entries (including any not yet * lazily evicted). Intended for tests and diagnostics. */ get size(): number; }