LighterAuthTokenManager
Documentation for eth_defi.lighter.sdk.LighterAuthTokenManager Python class.
- class LighterAuthTokenManager
Bases:
objectManage and retry short-lived auth tokens for asynchronous SDK calls.
The manager stores only the current token in memory.
token_factorymust call the SDK’s token-generation method and return its(token, error)tuple.callpasses the token to an arbitrary asynchronous operation, proactively refreshes it before expiry, and retries one rejected token. Token values and SDK error payloads are deliberately excluded from representations and logs.The token lifetime must match the expiry requested from the SDK. The default is ten minutes, matching the current Lighter SDK default; callers can use a shorter lifetime in tests to exercise rotation.
Attributes summary
Zero-argument SDK callback returning
(auth_token, error).Token lifetime in seconds.
Seconds before expiry at which the current token is refreshed.
Monotonic clock, injectable for deterministic tests.
Methods summary
__init__(token_factory[, token_lifetime, ...])call(operation, *[, operation_name])Call an authenticated SDK operation with token refresh and retry.
- token_factory: collections.abc.Callable[[], tuple[str | None, object | None]]
Zero-argument SDK callback returning
(auth_token, error).
- token_lifetime: float
Token lifetime in seconds.
- refresh_margin: float
Seconds before expiry at which the current token is refreshed.
- clock: collections.abc.Callable[[], float]
Monotonic clock, injectable for deterministic tests.
- async call(operation, *, operation_name='Lighter SDK call')
Call an authenticated SDK operation with token refresh and retry.
operationis invoked with the current auth token. Only exceptions recognised byis_lighter_unauthorized_exception()are retried; application errors and transport failures propagate unchanged. A retry warning contains no token, private key or SDK exception payload.- Parameters
operation (collections.abc.Callable[[str], collections.abc.Awaitable[eth_defi.lighter.sdk.T]]) – Async SDK call accepting an auth token.
operation_name (str) – Non-secret description used in retry logs.
- Returns
The SDK operation’s result.
- Return type
eth_defi.lighter.sdk.T
- __init__(token_factory, token_lifetime=600.0, refresh_margin=30.0, clock=<built-in function monotonic>)
- Parameters
token_factory (collections.abc.Callable[[], tuple[str | None, object | None]]) –
token_lifetime (float) –
refresh_margin (float) –
clock (collections.abc.Callable[[], float]) –
- Return type
None