LighterAuthTokenManager

Documentation for eth_defi.lighter.sdk.LighterAuthTokenManager Python class.

class LighterAuthTokenManager

Bases: object

Manage and retry short-lived auth tokens for asynchronous SDK calls.

The manager stores only the current token in memory. token_factory must call the SDK’s token-generation method and return its (token, error) tuple. call passes 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

token_factory

Zero-argument SDK callback returning (auth_token, error).

token_lifetime

Token lifetime in seconds.

refresh_margin

Seconds before expiry at which the current token is refreshed.

clock

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.

operation is invoked with the current auth token. Only exceptions recognised by is_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
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
Return type

None