Authentication API
API endpoints for authentication
Authentication API
Section titled “Authentication API”Authentication endpoints for the Turbine.cash API.
Base URL
Section titled “Base URL”| Network | URL |
|---|---|
| Mainnet | https://worker.turbine.cash |
| Devnet | https://api-devnet.turbine.cash |
POST /login
Section titled “POST /login”Authenticate with a wallet signature.
Request
Section titled “Request”POST /loginContent-Type: application/json{ "wallet": "YourWalletPublicKeyBase58", "signature": "SignatureBase58", "message": 1705432800}| Field | Type | Description |
|---|---|---|
wallet | string | Wallet public key (base58) |
signature | string | Signature of the message (base58) |
message | number | Unix timestamp that was signed |
Response
Section titled “Response”{ "id": "550e8400-e29b-41d4-a716-446655440000"}| Field | Type | Description |
|---|---|---|
id | string (UUID) | Auth token for subsequent requests |
Example
Section titled “Example”const timestamp = Math.floor(Date.now() / 1000);const messageBytes = new TextEncoder().encode(timestamp.toString());const signatureBytes = await wallet.signMessage(messageBytes);
const response = await fetch('https://worker.turbine.cash/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ wallet: wallet.publicKey.toBase58(), signature: bs58.encode(signatureBytes), message: timestamp, }),});
const { id: authToken } = await response.json();Errors
Section titled “Errors”| Status | Error | Cause |
|---|---|---|
| 400 | Invalid signature | Signature doesn’t match wallet/message |
| 400 | Message too old | Timestamp is stale |
| 500 | Server error | Internal error |
GET /is_logged/{id}
Section titled “GET /is_logged/{id}”Check if an auth token is valid.
Request
Section titled “Request”GET /is_logged/{id}| Parameter | Type | Description |
|---|---|---|
id | string | Auth token to check |
Response
Section titled “Response”Valid token:
200 OK"true"Invalid token:
200 OK"false"Example
Section titled “Example”async function isTokenValid(authToken: string): Promise<boolean> { const response = await fetch( `https://worker.turbine.cash/is_logged/${authToken}` ); const result = await response.text(); return result === 'true';}Using Auth Tokens
Section titled “Using Auth Tokens”Include the auth token in the x-api-auth header for authenticated endpoints:
const response = await fetch('https://worker.turbine.cash/some-endpoint', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-auth': authToken, }, body: JSON.stringify(requestBody),});