---
name: onboarding
description: Onboard new agents and users to the Tetrac trading platform. Covers choosing between pay-per-call and a registered session, registering an account with the email + passkey challenge flow, logging in, and making a first authenticated call. Use when a new agent or user needs to get started with the platform.
license: Proprietary
compatibility: Designed for Claude Code (or similar products)
metadata:
  author: tetrac
  version: "2.1"
  category: "onboarding"
  emoji: "🚀"
---

## Skill Files

| File                     | URL                                                 |
| ------------------------ | --------------------------------------------------- |
| **SKILL.md** (this file) | `https://www.tetrac.xyz/skills/onboarding/SKILL.md` |

## Overview

There are two ways to call the Tetrac API:

1. **Pay per call (no account)** — attach a Solana USDC payment to each request. Nothing to register. See [x402 agent payments](https://www.tetrac.xyz/skills/x402-agent-payments/SKILL.md) or [MPP payments](https://www.tetrac.xyz/skills/mpp-payments/skill.md).
2. **Registered session** — register once, log in every 24 hours, and send two headers on every call. This skill covers that path:
   1. **Register** — create an account with an email + passkey
   2. **Log in** — exchange a signed challenge for a 24-hour `authToken`
   3. **Verify** — make a first authenticated call
   4. **Trade** — pass exchange credentials per request

> **Security model:** the passkey never leaves your machine. You derive a signing key from it locally and prove you hold it by signing a one-time server challenge. Never send the passkey, and never log it.

---

## Step 1: Register

Registration is a challenge + signature flow. All signatures are **Ed25519, detached, hex-encoded**.

### What you need

| Item             | Description                                                                                                                     |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| Identity keypair | A Solana (Ed25519) keypair you generate. Its base58 public key is your account identity and your `ttc-public-key` header value. |
| Email            | Your login identifier.                                                                                                          |
| Passkey          | A secret of at least 16 characters. It cannot be reset or recovered — store it in a secret manager.                             |
| App id           | Always `tetrac`.                                                                                                                |

### Derivations

| Value           | How to compute it                                                                                                                                         |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `appKey`        | PBKDF2-HMAC-SHA256 over the UTF-8 passkey, salt = SHA-256 of `tetrac:<email lowercased and trimmed>`, `pbkdf2Iterations` rounds, 32 bytes → lowercase hex |
| Auth keypair    | Ed25519 keypair from seed = SHA-256 of `ttc-auth-v1:<appKey hex>`                                                                                         |
| `authPublicKey` | The auth keypair's 32-byte public key → hex                                                                                                               |

Use the `pbkdf2Iterations` value the challenge endpoint returns (currently `600000`).

### Flow

1. `POST /api/auth/challenge` with `{ "publicKey": "<identity base58>", "appId": "tetrac" }` → `{ "challenge", "pbkdf2Iterations" }`.
2. Sign this exact message with the **identity** secret key (`\n` is a newline):
   `https://www.tetrac.xyz wants you to sign in with your Solana account.\n\nURI: https://www.tetrac.xyz\nNonce: <challenge>`
3. `POST /api/auth/register`:

```bash
curl -X POST https://www.tetrac.xyz/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "publicKey": "YOUR_IDENTITY_PUBLIC_KEY_BASE58",
    "email": "agent@example.com",
    "authPublicKey": "AUTH_PUBLIC_KEY_HEX",
    "authMethod": "email",
    "pbkdf2Iterations": 600000,
    "appId": "tetrac",
    "signature": "IDENTITY_SIGNATURE_HEX",
    "challenge": "CHALLENGE_FROM_STEP_1"
  }'
```

### Responses

| Status | Body                                           | Meaning                                                 |
| ------ | ---------------------------------------------- | ------------------------------------------------------- |
| `201`  | `{ "publicKey", "authToken", "user" }`         | Registered — you are also logged in                     |
| `400`  | `{ "error": "..." }`                           | A field is missing or malformed                         |
| `401`  | `{ "error": "Signature verification failed" }` | Wrong message bytes, wrong key, or wrong encoding       |
| `401`  | `{ "error": "Invalid or expired challenge" }`  | Challenges are single-use and expire after 5 minutes    |
| `409`  | `{ "error": "Account already exists" }`        | That public key or email is already registered — log in |
| `429`  | `{ "error": "..." }`                           | Account creation is rate-limited — wait and retry       |

Store the identity secret key like any private key; it proves ownership of your account identity.

---

## Step 2: Log In

Sessions last a fixed **24 hours** with no refresh. Log in again when the token expires.

1. `POST /api/auth/challenge` with `{ "email": "agent@example.com", "appId": "tetrac" }` → `{ "challenge", "pbkdf2Iterations" }`.
2. Re-derive `appKey` and the auth keypair (see the derivations above), then sign this exact message with the **auth** secret key:
   `Sign in to your TTC account: <challenge>`
3. `POST /api/auth/login`:

```bash
curl -X POST https://www.tetrac.xyz/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "agent@example.com",
    "appId": "tetrac",
    "challenge": "CHALLENGE_FROM_STEP_1",
    "signature": "AUTH_SIGNATURE_HEX"
  }'
```

Response `200`: `{ "publicKey", "authToken", "user" }`.

> **One session per account.** Each login revokes the previous `authToken` — including a browser session for the same account. Run one logged-in client per account.

### Reference implementation (Node.js)

```js
// npm i tweetnacl bs58
import crypto from "node:crypto";
import nacl from "tweetnacl";
import bs58 from "bs58";

const BASE = "https://www.tetrac.xyz";
const APP_ID = "tetrac";

const hex = (bytes) => Buffer.from(bytes).toString("hex");
const sign = (message, secretKey) =>
  hex(nacl.sign.detached(new TextEncoder().encode(message), secretKey));

function deriveAppKey(passkey, email, iterations) {
  const salt = crypto
    .createHash("sha256")
    .update(`${APP_ID}:${email.toLowerCase().trim()}`, "utf8")
    .digest();
  return crypto
    .pbkdf2Sync(Buffer.from(passkey, "utf8"), salt, iterations, 32, "sha256")
    .toString("hex");
}

function authKeyPair(appKeyHex) {
  const seed = crypto
    .createHash("sha256")
    .update(`ttc-auth-v1:${appKeyHex}`, "utf8")
    .digest();
  return nacl.sign.keyPair.fromSeed(new Uint8Array(seed));
}

async function post(path, body) {
  const res = await fetch(BASE + path, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(body),
  });
  const json = await res.json();
  if (!res.ok) throw new Error(`${path} ${res.status}: ${json.error}`);
  return json;
}

export async function register(email, passkey) {
  const identity = nacl.sign.keyPair(); // keep identity.secretKey private
  const publicKey = bs58.encode(identity.publicKey);
  const { challenge, pbkdf2Iterations } = await post("/api/auth/challenge", {
    publicKey,
    appId: APP_ID,
  });
  const authPublicKey = hex(
    authKeyPair(deriveAppKey(passkey, email, pbkdf2Iterations)).publicKey,
  );
  const message = `${BASE} wants you to sign in with your Solana account.\n\nURI: ${BASE}\nNonce: ${challenge}`;
  return post("/api/auth/register", {
    publicKey,
    email,
    authPublicKey,
    authMethod: "email",
    pbkdf2Iterations,
    appId: APP_ID,
    signature: sign(message, identity.secretKey),
    challenge,
  }); // → { publicKey, authToken, user }
}

export async function login(email, passkey) {
  const { challenge, pbkdf2Iterations } = await post("/api/auth/challenge", {
    email,
    appId: APP_ID,
  });
  const auth = authKeyPair(deriveAppKey(passkey, email, pbkdf2Iterations));
  return post("/api/auth/login", {
    email,
    appId: APP_ID,
    challenge,
    signature: sign(
      `Sign in to your TTC account: ${challenge}`,
      auth.secretKey,
    ),
  }); // → { publicKey, authToken, user }
}
```

---

## Step 3: Send Your Session Headers

| Header           | Value                                                       |
| ---------------- | ----------------------------------------------------------- |
| `ttc-auth-token` | The `authToken` from register or login (valid for 24 hours) |
| `ttc-public-key` | The `publicKey` from register or login (your identity key)  |

The session is bound to that public key — a token sent with any other key is rejected.

---

## Step 4: Verify Connectivity

```bash
curl https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY"
```

A valid session gets `200` with the venue roster (`supportedExchanges`), free.

A `401` means the token expired (24 hours), was replaced by a newer login, or is paired with the wrong public key — log in again. Paid routes answer an expired session with `401` too, never with a payment challenge: never pay to work around an expired session.

Then try a market-data call:

```bash
curl https://www.tetrac.xyz/api/v1/markets/hybrid-tickers \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY"
```

---

## Step 5: Trade With Your Exchange Credentials (Optional)

Nothing is stored server-side: send your exchange API credentials in the body of every `POST /api/v1/exchanges` call.

```bash
curl -X POST https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeName": "binance",
    "method": "getBalance",
    "params": {},
    "credentials": {
      "apiKey": "YOUR_EXCHANGE_API_KEY",
      "apiSecret": "YOUR_EXCHANGE_API_SECRET"
    }
  }'
```

### Orderly Network

Orderly derives your account ID from your **main wallet address** + broker ID. The server uses `credentials.walletAddress` when you send it, and falls back to your `ttc-public-key` otherwise. If your Orderly account was created with a different wallet than your identity key, pass that wallet as `walletAddress`:

```bash
curl -X POST https://www.tetrac.xyz/api/v1/exchanges \
  -H "ttc-auth-token: YOUR_AUTH_TOKEN" \
  -H "ttc-public-key: YOUR_PUBLIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "exchangeName": "orderly",
    "method": "getPositions",
    "params": {},
    "credentials": {
      "apiKey": "YOUR_ORDERLY_ED25519_PUBLIC_KEY",
      "apiSecret": "YOUR_ORDERLY_ED25519_PRIVATE_KEY",
      "passphrase": "ttc",
      "walletAddress": "YOUR_ORDERLY_MAIN_WALLET_ADDRESS"
    }
  }'
```

| Credential      | Description                                                                                               |
| --------------- | --------------------------------------------------------------------------------------------------------- |
| `apiKey`        | Ed25519 trading key **public key** (the `orderly-key`, not your main wallet)                              |
| `apiSecret`     | Ed25519 trading key **private key** (hex string, signs every request)                                     |
| `passphrase`    | Broker ID (default: `ttc`)                                                                                |
| `walletAddress` | The main Solana wallet linked to your Orderly account. Omit it when that wallet is your `ttc-public-key`. |

See the [trading skill](https://www.tetrac.xyz/skills/trading/SKILL.md) for every method.

---

## Common Issues

### 401 on login or register

- Sign the exact message bytes shown above — no extra whitespace, and `\n` is a real newline
- Hex-encode the 64-byte detached signature
- Request a fresh challenge: each one is single-use and expires after 5 minutes
- Login uses the **auth** key derived from the passkey; registration uses the **identity** key

### 401 on API calls

- The token expired (24 hours) or was revoked by a newer login — log in again
- `ttc-public-key` must be the `publicKey` returned by register/login
- If you sent session headers and get `401`, log in again. Never pay to work around an expired session.

### Rate Limited (429)

- Wait for the number of seconds in the `Retry-After` header
- Limits scale with your subscription tier (Free ×1, Pro ×3, Elite ×10)

### Exchange Call Failed

- Verify exchange API keys have the right permissions
- Check IP allowlist settings on the exchange

---

## Next Steps

After onboarding:

1. Explore [market data endpoints](https://www.tetrac.xyz/skills/market-data/SKILL.md)
2. Learn [trading operations](https://www.tetrac.xyz/skills/trading/SKILL.md)
3. Set up [x402 agent payments](https://www.tetrac.xyz/skills/x402-agent-payments/SKILL.md)

---

**API contract (machine-readable):** https://www.tetrac.xyz/openapi.json · **For humans:** https://www.tetrac.xyz/docs
