@agg-market/sdk
v7.0.0
Published
Vanilla TypeScript client for the [AGG](https://agg.market) prediction market aggregator. Works in browsers, Node.js, and React Native with no framework dependency.
Downloads
891
Readme
@agg-market/sdk
Vanilla TypeScript client for the AGG prediction market aggregator. Works in browsers, Node.js, and React Native with no framework dependency.
For React apps, see @agg-market/hooks,
@agg-market/ui, and
@agg-market/auth.
Install
npm install @agg-market/sdkQuick start
import { createAggClient } from "@agg-market/sdk";
const client = createAggClient({
baseUrl: "https://api.agg.market",
appId: "your-app-id",
});
// Health check
const hello = await client.getHello();
// Check auth state
console.log(client.isAuthenticated, client.user);Authentication
The SDK exposes the provider-agnostic auth primitives used by @agg-market/auth and custom app
integrations.
Message-signing auth (SIWE / SIWS)
// 1. Start the auth flow
const { nonce } = await client.authStart({ provider: "siwe" });
// 2. Build the SIWE message
const message = client.buildSiweMessage({
address: "0x...",
chainId: 1,
nonce,
domain: window.location.host,
uri: window.location.origin,
});
// 3. Sign with the user's wallet (wagmi, ethers, etc.)
const signature = await wallet.signMessage(message);
// 4. Verify and get tokens directly from /auth/verify
const { accessToken, refreshToken, user } = await client.verify({ message, signature });
// 5. Sign out
client.signOut();Redirect auth (Google / Twitter / Apple / Email)
const response = await client.authStart({
provider: "google",
redirectUrl: "https://yourapp.com/auth/callback",
});
if (response.type === "redirect") {
window.location.assign(response.url);
}When AGG redirects back with a one-time auth code, exchange it for tokens:
const params = new URLSearchParams(window.location.search);
const code = params.get("code");
if (code) {
const { accessToken, refreshToken, user } = await client.exchangeAuthCode(code);
window.history.replaceState(null, "", window.location.pathname);
}Auth sessions are automatically persisted to localStorage and restored on construction.
API methods
| Method | Description |
| -------------------------------------------------- | ------------------------------------------ |
| authStart(body) | Start any AGG auth flow |
| startAuth(body) | Alias for authStart(body) |
| getNonce() | Legacy SIWE nonce helper |
| buildSiweMessage(params) | Build an EIP-4361 message string |
| buildSiwsMessage(params) | Build a Solana sign-in message |
| verify({ message, signature }) | Verify signature and get auth tokens |
| verifySignIn({ message, signature }) | Alias for verify({ message, signature }) |
| exchangeAuthCode(code) | Exchange redirect auth code for tokens |
| setSession({ accessToken, refreshToken, user? }) | Seed tokens from a redirect callback |
| signOut() | Clear auth state |
| isAuthenticated | Check if user is signed in |
| user | Get the current user |
| onAuthStateChange(listener) | Subscribe to auth state changes |
Headers
The SDK automatically attaches the correct headers on every request:
x-app-id— from theappIdyou providedAuthorization: Bearer <jwt>— after sign-inx-admin-key— if you provided anadminKey
Related packages
| Package | Description |
| ---------------------------------------------------------------------- | -------------------------------------- |
| @agg-market/hooks | React hooks for auth and data fetching |
| @agg-market/ui | Pre-built React trading components |
| @agg-market/auth | Auth adapters and connect/sign-in UI |
License
MIT
