@0xmonaco/types 0.8.5 → 0.8.7-develop.34bd452

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,17 +2,18 @@
2
2
  * Base API Types
3
3
  *
4
4
  * Common interface that all API implementations should inherit from.
5
- * Provides standardized methods for token management and common functionality.
5
+ * Provides standardized methods for session-key management and common functionality.
6
6
  */
7
+ import type { SessionCredentials } from "../auth/responses";
7
8
  /**
8
9
  * Base API interface that all API implementations should inherit from.
9
- * Provides common functionality for access token management.
10
+ * Provides common functionality for session-key management.
10
11
  */
11
12
  export interface BaseAPI {
12
13
  /**
13
- * Set the access token for authenticated requests.
14
+ * Set (or clear) the session keypair used to sign authenticated requests.
14
15
  *
15
- * @param token - JWT access token
16
+ * @param credentials - Hex-encoded session keypair, or `undefined` to clear.
16
17
  */
17
- setAccessToken(token: string): void;
18
+ setSessionKeypair(credentials: SessionCredentials | undefined): void;
18
19
  }
package/dist/api/index.js CHANGED
@@ -2,5 +2,5 @@
2
2
  * Base API Types
3
3
  *
4
4
  * Common interface that all API implementations should inherit from.
5
- * Provides standardized methods for token management and common functionality.
5
+ * Provides standardized methods for session-key management and common functionality.
6
6
  */
@@ -5,7 +5,7 @@
5
5
  * signature verification, and backend authentication.
6
6
  */
7
7
  import type { BaseAPI } from "../api";
8
- import type { AuthState, BackendAuthResponse, ChallengeResponse, TokenRefreshResponse } from "./responses";
8
+ import type { AuthState, BackendAuthResponse, ChallengeResponse, SessionCredentials, SessionRefreshResponse } from "./responses";
9
9
  /**
10
10
  * Auth API interface.
11
11
  * Provides methods for frontend and backend authentication.
@@ -16,12 +16,13 @@ export interface AuthAPI extends BaseAPI {
16
16
  * Complete authentication flow for frontend applications.
17
17
  *
18
18
  * This method handles the entire authentication process:
19
- * 1. Creates a challenge
20
- * 2. Signs the challenge message
21
- * 3. Verifies the signature and returns JWT tokens
19
+ * 1. Generates a fresh ed25519 session keypair locally
20
+ * 2. Creates a challenge that commits to the session public key
21
+ * 3. Signs the challenge message with the wallet
22
+ * 4. Verifies the signature, registering the session public key
22
23
  *
23
24
  * @param clientId - Client ID of the application
24
- * @returns Promise resolving to the authentication state with JWT tokens
25
+ * @returns Promise resolving to the authentication state (including the session keypair)
25
26
  */
26
27
  authenticate(clientId: string): Promise<AuthState>;
27
28
  /**
@@ -36,41 +37,44 @@ export interface AuthAPI extends BaseAPI {
36
37
  signChallenge(message: string): Promise<string>;
37
38
  /**
38
39
  * Creates a challenge for frontend authentication.
39
- * Generates a unique nonce and message that the user must sign with their wallet.
40
+ * Generates a unique nonce and a message (embedding the session public key)
41
+ * that the user must sign with their wallet.
40
42
  * @param address - Wallet address of the user
41
43
  * @param clientId - Client ID of the application
44
+ * @param sessionPublicKey - Hex-encoded ed25519 session public key to bind
42
45
  * @returns Promise resolving to the challenge response
43
46
  */
44
- createChallenge(address: string, clientId: string): Promise<ChallengeResponse>;
47
+ createChallenge(address: string, clientId: string, sessionPublicKey: string): Promise<ChallengeResponse>;
45
48
  /**
46
49
  * Verifies a signature for frontend authentication.
47
- * Validates the signature against the challenge and returns JWT tokens.
50
+ * Validates the wallet signature against the challenge and registers the
51
+ * session public key, returning the new authentication state.
48
52
  * @param address - Wallet address of the user
49
- * @param signature - Signature of the challenge message
53
+ * @param signature - Wallet signature of the challenge message
50
54
  * @param nonce - Nonce from the challenge response
51
55
  * @param clientId - Client ID of the application
52
- * @returns Promise resolving to the authentication state with JWT tokens
56
+ * @param session - The locally-generated session keypair (hex-encoded)
57
+ * @returns Promise resolving to the authentication state
53
58
  */
54
- verifySignature(address: string, signature: string, nonce: string, clientId: string): Promise<AuthState>;
59
+ verifySignature(address: string, signature: string, nonce: string, clientId: string, session: SessionCredentials): Promise<AuthState>;
55
60
  /**
56
61
  * Authenticates a backend service using a secret key.
57
- * Returns JWT tokens for API access.
58
62
  * @param secretKey - Secret key of the application
59
- * @returns Promise resolving to the backend auth response with JWT tokens
63
+ * @returns Promise resolving to the backend auth response
60
64
  */
61
65
  authenticateBackend(secretKey: string): Promise<BackendAuthResponse>;
62
66
  /**
63
- * Refreshes an access token using a refresh token.
64
- * @param refreshToken - The refresh token to use
65
- * @returns Promise resolving to new access and refresh tokens
67
+ * Extends the current session's expiry. The request is signed with the
68
+ * active session key (set via {@link setSessionKeypair}).
69
+ * @returns Promise resolving to the new expiry
66
70
  */
67
- refreshToken(refreshToken: string): Promise<TokenRefreshResponse>;
71
+ refreshSession(): Promise<SessionRefreshResponse>;
68
72
  /**
69
- * Revokes the current session's refresh token.
70
- * The server identifies the token to revoke from the access token in the Authorization header.
71
- * @returns Promise resolving when the token is revoked
73
+ * Revokes the current session. The request is signed with the active session
74
+ * key, and the server deletes the matching session row.
75
+ * @returns Promise resolving when the session is revoked
72
76
  */
73
- revokeToken(): Promise<void>;
77
+ revokeSession(): Promise<void>;
74
78
  /**
75
79
  * Sets the wallet client for signing operations.
76
80
  * Used when the wallet becomes available after SDK initialization.
@@ -78,4 +82,4 @@ export interface AuthAPI extends BaseAPI {
78
82
  */
79
83
  setWalletClient(walletClient: unknown): void;
80
84
  }
81
- export type { ApplicationInfo, AuthState, BackendAuthResponse, ChallengeResponse, TokenRefreshResponse, User, } from "./responses";
85
+ export type { ApplicationInfo, AuthState, BackendAuthResponse, ChallengeResponse, SessionCredentials, SessionRefreshResponse, User, } from "./responses";
@@ -23,16 +23,22 @@ export interface User {
23
23
  username?: string;
24
24
  }
25
25
  /**
26
- * Authentication state containing all tokens and metadata
26
+ * Authentication state for the noncustodial session-key scheme.
27
27
  *
28
- * Returned by authentication methods and contains the tokens needed for API access.
28
+ * On login the SDK generates an ed25519 keypair locally and registers the
29
+ * public key with the server. Subsequent requests are signed with the private
30
+ * key — the server never holds a credential that can impersonate the user.
31
+ *
32
+ * The private key is the long-lived credential: persist it (e.g. localStorage,
33
+ * same risk profile as a JWT) to survive page reloads without re-prompting the
34
+ * wallet. When the session expires, call `refreshAuth()` or re-`login()`.
29
35
  */
30
36
  export interface AuthState {
31
- /** JWT access token for authenticated requests */
32
- accessToken: string;
33
- /** JWT refresh token for token renewal and revocation */
34
- refreshToken: string;
35
- /** Unix timestamp (in seconds) when the access token expires */
37
+ /** Hex-encoded (64 chars) ed25519 session public key registered with the server */
38
+ sessionPublicKey: string;
39
+ /** Hex-encoded (64 chars) ed25519 session private key used to sign requests */
40
+ sessionPrivateKey: string;
41
+ /** Unix timestamp (in seconds) when the session expires */
36
42
  expiresAt: number;
37
43
  /** Information about the authenticated user */
38
44
  user: User;
@@ -57,11 +63,19 @@ export interface BackendAuthResponse {
57
63
  application: ApplicationInfo;
58
64
  }
59
65
  /**
60
- * Response to a token refresh request.
66
+ * A session keypair, hex-encoded. The private key is used to sign requests;
67
+ * the public key identifies the session server-side.
61
68
  */
62
- export interface TokenRefreshResponse {
63
- /** New JWT access token */
64
- accessToken: string;
65
- /** Unix timestamp when the access token expires */
69
+ export interface SessionCredentials {
70
+ /** Hex-encoded (64 chars) ed25519 public key */
71
+ publicKey: string;
72
+ /** Hex-encoded (64 chars) ed25519 private key */
73
+ privateKey: string;
74
+ }
75
+ /**
76
+ * Response to a session refresh request — extends the session's expiry.
77
+ */
78
+ export interface SessionRefreshResponse {
79
+ /** Unix timestamp when the session expires after refresh */
66
80
  expiresAt: number;
67
81
  }
@@ -259,6 +259,7 @@ export interface ListFundingHistoryResponse {
259
259
  }
260
260
  export interface OpenInterest {
261
261
  trading_pair_id: string;
262
+ open_interest?: string;
262
263
  open_interest_base: string;
263
264
  open_interest_notional: string;
264
265
  updated_at: string;
@@ -116,7 +116,7 @@ export interface GetUserBalancesParams {
116
116
  */
117
117
  export interface GetPaginatedUserMovementsResponse {
118
118
  /**
119
- * Latest movements from Redis cache (real-time, instant updates).
119
+ * Latest movements from the live engine cache (real-time, instant updates).
120
120
  * These are the most recent movements that may not yet be in PostgreSQL.
121
121
  * Only populated on page 1; empty for subsequent pages.
122
122
  */
@@ -1,6 +1,6 @@
1
1
  import type { PublicClient, TransactionReceipt, WalletClient } from "viem";
2
2
  import type { ApplicationsAPI } from "../applications";
3
- import type { AuthAPI, AuthState } from "../auth/index";
3
+ import type { AuthAPI, AuthState, SessionCredentials } from "../auth/index";
4
4
  import type { DelegatedAgentsAPI } from "../delegated-agents";
5
5
  import type { FeesAPI } from "../fees";
6
6
  import type { MarginAccountsAPI } from "../margin-accounts";
@@ -29,10 +29,27 @@ export interface SDKConfig {
29
29
  * - "mainnet": https://api.monaco.xyz
30
30
  *
31
31
  * Only "mainnet" uses the Sei mainnet chain. All other networks use Sei testnet.
32
+ * `network` always selects the chain; supply {@link apiUrl} / {@link wsUrl}
33
+ * to point the SDK at a gateway that the preset URL doesn't cover.
32
34
  */
33
35
  network: Network;
34
36
  /** RPC URL for Sei blockchain interactions */
35
37
  seiRpcUrl: string;
38
+ /**
39
+ * Override the API gateway base URL. When set, the SDK sends all HTTP
40
+ * requests here instead of the {@link network} preset's default URL. Use for
41
+ * self-hosted gateways or e2e/dev stacks reachable only by a custom host
42
+ * (e.g. Docker DNS `http://api-gateway:8080`). `network` still selects the
43
+ * chain. Must be a valid absolute URL.
44
+ */
45
+ apiUrl?: string;
46
+ /**
47
+ * Override the WebSocket base URL. When set, the SDK connects here instead of
48
+ * the {@link network} preset's default WS URL. Pair with {@link apiUrl} when
49
+ * the WS service is reachable at a different host than the API gateway
50
+ * (e.g. Docker DNS `ws://ws-api:8080/ws`). Must be a valid absolute URL.
51
+ */
52
+ wsUrl?: string;
36
53
  }
37
54
  /**
38
55
  * Core SDK interface providing access to all Monaco functionality.
@@ -86,7 +103,7 @@ export interface MonacoSDK {
86
103
  disconnect: () => void;
87
104
  isConnected: () => boolean;
88
105
  getStatus: () => "connected" | "connecting" | "disconnected" | "reconnecting";
89
- setToken: (token: string) => void;
106
+ setSessionKeypair: (credentials: SessionCredentials | undefined) => void;
90
107
  orders: (tradingPairId: string, tradingMode: TradingMode, handler: (event: OrderEvent) => void) => () => void;
91
108
  orderbook: (tradingPairId: string, tradingMode: TradingMode, magnitude: number, quotationMode: OrderbookQuotationMode, handler: (event: OrderbookEvent) => void) => () => void;
92
109
  ohlcv: (tradingPairId: string, tradingMode: TradingMode, interval: Interval, handler: (event: OHLCVEvent) => void) => () => void;
@@ -141,7 +141,7 @@ export interface GetPaginatedOrdersParams {
141
141
  * Response from getting paginated orders
142
142
  */
143
143
  export interface GetPaginatedOrdersResponse {
144
- /** Latest orders from Redis cache (real-time, instant updates).
144
+ /** Latest orders from the live engine cache (real-time, instant updates).
145
145
  * These are the most recently created/updated orders that may not yet be in PostgreSQL.
146
146
  * Only populated on page 1.
147
147
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmonaco/types",
3
- "version": "0.8.5",
3
+ "version": "0.8.7-develop.34bd452",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,7 +20,7 @@
20
20
  "lint": "biome lint ."
21
21
  },
22
22
  "dependencies": {
23
- "@0xmonaco/contracts": "0.8.5",
23
+ "@0xmonaco/contracts": "0.8.7-develop.34bd452",
24
24
  "zod": "^4.1.12"
25
25
  },
26
26
  "peerDependencies": {