@circles-market/session
v0.1.0
Published
Token storage for authenticated Market API calls.
Readme
@circles-market/session
Token storage for authenticated Market API calls.
This package is intentionally tiny: it stores a JWT + associated metadata and gives you a safe getToken() that returns null when the token is expired (with a small grace window).
Install
pnpm add @circles-market/sessionQuickstart
import { InMemoryAuthContext } from "@circles-market/session";
const session = new InMemoryAuthContext();
session.setToken("jwt-token", 60, "0x0000000000000000000000000000000000000000", 100);
const token = session.getToken();
if (!token) {
throw new Error("Not authenticated");
}
const meta = session.getMeta();Reference
Concepts
- Stores
{ token, expiresAt, address, chainId }and hides expired tokens. getToken()returnsnullwhen token is missing or expired (with a small grace window).- Lowercases the
addressfor consistency.
API and return values
setToken(token, expiresInSeconds, address, chainId)→void- Stores token + metadata; calculates
expiresAtfromexpiresInSeconds.
- Stores token + metadata; calculates
getToken()→string | null- Returns
nullwhen token is expired or not set.
- Returns
getMeta()→AuthMeta{ address: string; chainId: number } | nulldepending on validity of the token.
clear()→void- Clears token + metadata.
Types
AuthContext(interface) — implement this to provide your own storage (e.g. localStorage, secure store).InMemoryAuthContext— default in-memory implementation.AuthMeta:
type AuthMeta = { address: string; chainId: number } | null;Runtime notes
- No external dependencies; works in browser and Node environments.
- Does not perform network calls.
Related packages
@circles-market/authwrites tokens into anAuthContextafter sign-in.@circles-market/orders,@circles-market/cart, and@circles-market/salesread tokens from anAuthContext.@circles-market/sdkwires auth + session with the other domain clients.
