@0xmonaco/core 0.8.5 → 0.8.7-develop.0f12336
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.
- package/README.md +3 -12
- package/dist/api/applications/api.d.ts +61 -8
- package/dist/api/applications/api.js +75 -11
- package/dist/api/auth/api.d.ts +44 -76
- package/dist/api/auth/api.js +68 -111
- package/dist/api/base.d.ts +50 -9
- package/dist/api/base.js +97 -14
- package/dist/api/delegated-agents/api.d.ts +2 -1
- package/dist/api/delegated-agents/api.js +15 -11
- package/dist/api/faucet/api.d.ts +25 -0
- package/dist/api/faucet/api.js +29 -0
- package/dist/api/faucet/index.d.ts +1 -0
- package/dist/api/faucet/index.js +1 -0
- package/dist/api/fees/api.d.ts +13 -13
- package/dist/api/fees/api.js +18 -18
- package/dist/api/index.d.ts +4 -0
- package/dist/api/index.js +4 -0
- package/dist/api/margin-accounts/api.d.ts +9 -5
- package/dist/api/margin-accounts/api.js +70 -33
- package/dist/api/market/api.d.ts +5 -2
- package/dist/api/market/api.js +32 -16
- package/dist/api/orderbook/api.js +13 -12
- package/dist/api/perp/routes.d.ts +113 -37
- package/dist/api/perp/routes.js +37 -6
- package/dist/api/positions/api.d.ts +2 -1
- package/dist/api/positions/api.js +30 -18
- package/dist/api/profile/api.d.ts +40 -23
- package/dist/api/profile/api.js +78 -38
- package/dist/api/sub-accounts/api.d.ts +62 -0
- package/dist/api/sub-accounts/api.js +80 -0
- package/dist/api/sub-accounts/index.d.ts +1 -0
- package/dist/api/sub-accounts/index.js +1 -0
- package/dist/api/trades/api.d.ts +21 -10
- package/dist/api/trades/api.js +22 -10
- package/dist/api/trading/api.d.ts +11 -8
- package/dist/api/trading/api.js +76 -90
- package/dist/api/vault/api.d.ts +96 -29
- package/dist/api/vault/api.js +172 -43
- package/dist/api/vault/index.d.ts +1 -1
- package/dist/api/vault/index.js +1 -1
- package/dist/api/websocket/types.d.ts +5 -5
- package/dist/api/websocket/websocket.js +43 -22
- package/dist/api/whitelist/api.d.ts +27 -0
- package/dist/api/whitelist/api.js +32 -0
- package/dist/api/whitelist/index.d.ts +1 -0
- package/dist/api/whitelist/index.js +1 -0
- package/dist/api/withdrawals/api.d.ts +18 -0
- package/dist/api/withdrawals/api.js +35 -0
- package/dist/api/withdrawals/index.d.ts +1 -0
- package/dist/api/withdrawals/index.js +1 -0
- package/dist/coverage.d.ts +93 -0
- package/dist/coverage.js +93 -0
- package/dist/crypto/session.d.ts +40 -0
- package/dist/crypto/session.js +60 -0
- package/dist/sdk.d.ts +58 -20
- package/dist/sdk.js +156 -53
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -62,26 +62,17 @@ npm install viem@^2.31.7
|
|
|
62
62
|
|
|
63
63
|
## Network Support
|
|
64
64
|
|
|
65
|
-
The SDK supports the following preset networks. Configure the network by providing the `network` and `seiRpcUrl` parameters:
|
|
65
|
+
The SDK supports the following documented preset networks. Configure the network by providing the `network` and `seiRpcUrl` parameters:
|
|
66
66
|
|
|
67
67
|
**Preset Networks:**
|
|
68
|
-
- `"development"` - Development environment (https://develop.apimonaco.xyz)
|
|
69
68
|
- `"staging"` - Staging environment (https://staging.apimonaco.xyz)
|
|
70
69
|
- `"mainnet"` - Production environment (https://api.monaco.xyz)
|
|
71
|
-
- `"local"` - Local development (http://localhost:8080)
|
|
72
70
|
|
|
73
71
|
WebSocket URLs are automatically resolved per network.
|
|
74
72
|
|
|
75
73
|
```typescript
|
|
76
74
|
import { MonacoSDK } from "@0xmonaco/core";
|
|
77
75
|
|
|
78
|
-
// Development configuration
|
|
79
|
-
const devSdk = new MonacoSDK({
|
|
80
|
-
walletClient,
|
|
81
|
-
network: "development",
|
|
82
|
-
seiRpcUrl: "https://evm-rpc-testnet.sei-apis.com",
|
|
83
|
-
});
|
|
84
|
-
|
|
85
76
|
// Staging configuration
|
|
86
77
|
const stagingSdk = new MonacoSDK({
|
|
87
78
|
walletClient,
|
|
@@ -114,7 +105,7 @@ const walletClient = createWalletClient({
|
|
|
114
105
|
|
|
115
106
|
const monaco = new MonacoSDK({
|
|
116
107
|
walletClient,
|
|
117
|
-
network: "
|
|
108
|
+
network: "staging", // or "mainnet"
|
|
118
109
|
seiRpcUrl: "https://evm-rpc-testnet.sei-apis.com", // or https://evm-rpc.sei-apis.com for mainnet
|
|
119
110
|
});
|
|
120
111
|
|
|
@@ -251,7 +242,7 @@ interface SDKConfig {
|
|
|
251
242
|
/** Wallet client for signing operations (optional - can be set later via setWalletClient) */
|
|
252
243
|
walletClient?: WalletClient;
|
|
253
244
|
|
|
254
|
-
/**
|
|
245
|
+
/** Use "staging" for public testnet or "mainnet" for production. */
|
|
255
246
|
network: Network;
|
|
256
247
|
|
|
257
248
|
/** RPC URL for Sei blockchain interactions */
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Applications API Implementation
|
|
3
3
|
*
|
|
4
|
-
* Handles application configuration operations.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* on the Monaco protocol.
|
|
4
|
+
* Handles application configuration and reporting operations. This is a
|
|
5
|
+
* mixed-auth domain: `getApplicationConfig` is session-authenticated, while
|
|
6
|
+
* the reporting methods are backend-authenticated via the application secret
|
|
7
|
+
* key (set with {@link BaseAPI.setServerKey}, sent as `x-server-key`).
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
10
|
* ```typescript
|
|
12
11
|
* const applicationsAPI = new ApplicationsAPIImpl(apiUrl);
|
|
13
12
|
*
|
|
14
|
-
* // Get application configuration
|
|
13
|
+
* // Get application configuration (session auth)
|
|
15
14
|
* const config = await applicationsAPI.getApplicationConfig();
|
|
16
15
|
* console.log(`App name: ${config.name}`);
|
|
17
|
-
*
|
|
16
|
+
*
|
|
17
|
+
* // Reporting endpoints (backend auth)
|
|
18
|
+
* applicationsAPI.setServerKey("sk_live_...");
|
|
19
|
+
* const orders = await applicationsAPI.listApplicationOrders({ status: "FILLED" });
|
|
18
20
|
* ```
|
|
19
21
|
*/
|
|
20
|
-
import type { ApplicationConfigResponse, ApplicationsAPI } from "@0xmonaco/types";
|
|
22
|
+
import type { ApplicationConfigResponse, ApplicationsAPI, GetAppStatsParams, GetAppStatsResponse, ListAppBalancesParams, ListAppBalancesResponse, ListAppMovementsParams, ListAppMovementsResponse, ListAppOrdersParams, ListAppOrdersResponse, ListAppUsersParams, ListAppUsersResponse } from "@0xmonaco/types";
|
|
21
23
|
import { BaseAPI } from "../base";
|
|
22
24
|
export declare class ApplicationsAPIImpl extends BaseAPI implements ApplicationsAPI {
|
|
23
25
|
/**
|
|
@@ -40,4 +42,55 @@ export declare class ApplicationsAPIImpl extends BaseAPI implements Applications
|
|
|
40
42
|
* ```
|
|
41
43
|
*/
|
|
42
44
|
getApplicationConfig(): Promise<ApplicationConfigResponse>;
|
|
45
|
+
/**
|
|
46
|
+
* Lists orders placed by the application's users.
|
|
47
|
+
*
|
|
48
|
+
* Backend-authenticated — call {@link BaseAPI.setServerKey} first.
|
|
49
|
+
*
|
|
50
|
+
* @param params - Pagination and filter options
|
|
51
|
+
* @returns Promise resolving to a paginated list of orders
|
|
52
|
+
* @throws {APIError} When the server key is unset or the request fails
|
|
53
|
+
*/
|
|
54
|
+
listApplicationOrders(params?: ListAppOrdersParams): Promise<ListAppOrdersResponse>;
|
|
55
|
+
/**
|
|
56
|
+
* Lists the application's users.
|
|
57
|
+
*
|
|
58
|
+
* Backend-authenticated — call {@link BaseAPI.setServerKey} first.
|
|
59
|
+
*
|
|
60
|
+
* @param params - Pagination and filter options
|
|
61
|
+
* @returns Promise resolving to a paginated list of users
|
|
62
|
+
* @throws {APIError} When the server key is unset or the request fails
|
|
63
|
+
*/
|
|
64
|
+
listApplicationUsers(params?: ListAppUsersParams): Promise<ListAppUsersResponse>;
|
|
65
|
+
/**
|
|
66
|
+
* Lists ledger movements for the application's users.
|
|
67
|
+
*
|
|
68
|
+
* Backend-authenticated — call {@link BaseAPI.setServerKey} first.
|
|
69
|
+
*
|
|
70
|
+
* @param params - Pagination and filter options
|
|
71
|
+
* @returns Promise resolving to a paginated list of movements
|
|
72
|
+
* @throws {APIError} When the server key is unset or the request fails
|
|
73
|
+
*/
|
|
74
|
+
listApplicationMovements(params?: ListAppMovementsParams): Promise<ListAppMovementsResponse>;
|
|
75
|
+
/**
|
|
76
|
+
* Lists user balances held within the application.
|
|
77
|
+
*
|
|
78
|
+
* Backend-authenticated — call {@link BaseAPI.setServerKey} first.
|
|
79
|
+
*
|
|
80
|
+
* @param params - Pagination and filter options
|
|
81
|
+
* @returns Promise resolving to a paginated list of balances
|
|
82
|
+
* @throws {APIError} When the server key is unset or the request fails
|
|
83
|
+
*/
|
|
84
|
+
listApplicationBalances(params?: ListAppBalancesParams): Promise<ListAppBalancesResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Gets aggregate volume and fee stats for the application.
|
|
87
|
+
*
|
|
88
|
+
* Stats are scoped to trades where the application's users were the taker.
|
|
89
|
+
* Backend-authenticated — call {@link BaseAPI.setServerKey} first.
|
|
90
|
+
*
|
|
91
|
+
* @param params - Optional `since` filter
|
|
92
|
+
* @returns Promise resolving to the application stats
|
|
93
|
+
* @throws {APIError} When the server key is unset or the request fails
|
|
94
|
+
*/
|
|
95
|
+
getApplicationStats(params?: GetAppStatsParams): Promise<GetAppStatsResponse>;
|
|
43
96
|
}
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Applications API Implementation
|
|
3
3
|
*
|
|
4
|
-
* Handles application configuration operations.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* on the Monaco protocol.
|
|
4
|
+
* Handles application configuration and reporting operations. This is a
|
|
5
|
+
* mixed-auth domain: `getApplicationConfig` is session-authenticated, while
|
|
6
|
+
* the reporting methods are backend-authenticated via the application secret
|
|
7
|
+
* key (set with {@link BaseAPI.setServerKey}, sent as `x-server-key`).
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
10
|
* ```typescript
|
|
12
11
|
* const applicationsAPI = new ApplicationsAPIImpl(apiUrl);
|
|
13
12
|
*
|
|
14
|
-
* // Get application configuration
|
|
13
|
+
* // Get application configuration (session auth)
|
|
15
14
|
* const config = await applicationsAPI.getApplicationConfig();
|
|
16
15
|
* console.log(`App name: ${config.name}`);
|
|
17
|
-
*
|
|
16
|
+
*
|
|
17
|
+
* // Reporting endpoints (backend auth)
|
|
18
|
+
* applicationsAPI.setServerKey("sk_live_...");
|
|
19
|
+
* const orders = await applicationsAPI.listApplicationOrders({ status: "FILLED" });
|
|
18
20
|
* ```
|
|
19
21
|
*/
|
|
20
22
|
import { BaseAPI } from "../base";
|
|
23
|
+
import { perpRoutes } from "../perp/routes";
|
|
21
24
|
export class ApplicationsAPIImpl extends BaseAPI {
|
|
22
25
|
/**
|
|
23
26
|
* Gets the configuration for the authenticated application.
|
|
@@ -45,10 +48,71 @@ export class ApplicationsAPIImpl extends BaseAPI {
|
|
|
45
48
|
return {
|
|
46
49
|
id: data.id,
|
|
47
50
|
name: data.name,
|
|
48
|
-
allowedOrigins: data.
|
|
49
|
-
webhookUrl: data.
|
|
50
|
-
vaultContractAddress: data.
|
|
51
|
-
clientId: data.
|
|
51
|
+
allowedOrigins: data.allowedOrigins,
|
|
52
|
+
webhookUrl: data.webhookUrl,
|
|
53
|
+
vaultContractAddress: data.vaultContractAddress,
|
|
54
|
+
clientId: data.clientId,
|
|
52
55
|
};
|
|
53
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Lists orders placed by the application's users.
|
|
59
|
+
*
|
|
60
|
+
* Backend-authenticated — call {@link BaseAPI.setServerKey} first.
|
|
61
|
+
*
|
|
62
|
+
* @param params - Pagination and filter options
|
|
63
|
+
* @returns Promise resolving to a paginated list of orders
|
|
64
|
+
* @throws {APIError} When the server key is unset or the request fails
|
|
65
|
+
*/
|
|
66
|
+
async listApplicationOrders(params) {
|
|
67
|
+
return await this.makeBackendRequest(perpRoutes.applications.orders(params));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Lists the application's users.
|
|
71
|
+
*
|
|
72
|
+
* Backend-authenticated — call {@link BaseAPI.setServerKey} first.
|
|
73
|
+
*
|
|
74
|
+
* @param params - Pagination and filter options
|
|
75
|
+
* @returns Promise resolving to a paginated list of users
|
|
76
|
+
* @throws {APIError} When the server key is unset or the request fails
|
|
77
|
+
*/
|
|
78
|
+
async listApplicationUsers(params) {
|
|
79
|
+
return await this.makeBackendRequest(perpRoutes.applications.users(params));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Lists ledger movements for the application's users.
|
|
83
|
+
*
|
|
84
|
+
* Backend-authenticated — call {@link BaseAPI.setServerKey} first.
|
|
85
|
+
*
|
|
86
|
+
* @param params - Pagination and filter options
|
|
87
|
+
* @returns Promise resolving to a paginated list of movements
|
|
88
|
+
* @throws {APIError} When the server key is unset or the request fails
|
|
89
|
+
*/
|
|
90
|
+
async listApplicationMovements(params) {
|
|
91
|
+
return await this.makeBackendRequest(perpRoutes.applications.movements(params));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Lists user balances held within the application.
|
|
95
|
+
*
|
|
96
|
+
* Backend-authenticated — call {@link BaseAPI.setServerKey} first.
|
|
97
|
+
*
|
|
98
|
+
* @param params - Pagination and filter options
|
|
99
|
+
* @returns Promise resolving to a paginated list of balances
|
|
100
|
+
* @throws {APIError} When the server key is unset or the request fails
|
|
101
|
+
*/
|
|
102
|
+
async listApplicationBalances(params) {
|
|
103
|
+
return await this.makeBackendRequest(perpRoutes.applications.balances(params));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Gets aggregate volume and fee stats for the application.
|
|
107
|
+
*
|
|
108
|
+
* Stats are scoped to trades where the application's users were the taker.
|
|
109
|
+
* Backend-authenticated — call {@link BaseAPI.setServerKey} first.
|
|
110
|
+
*
|
|
111
|
+
* @param params - Optional `since` filter
|
|
112
|
+
* @returns Promise resolving to the application stats
|
|
113
|
+
* @throws {APIError} When the server key is unset or the request fails
|
|
114
|
+
*/
|
|
115
|
+
async getApplicationStats(params) {
|
|
116
|
+
return await this.makeBackendRequest(perpRoutes.applications.stats(params));
|
|
117
|
+
}
|
|
54
118
|
}
|
package/dist/api/auth/api.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Auth API Implementation
|
|
3
3
|
*
|
|
4
|
-
* Handles authentication operations including challenge creation, signature
|
|
5
|
-
* and
|
|
4
|
+
* Handles wallet authentication operations including challenge creation, signature
|
|
5
|
+
* verification, and session lifecycle. All operations go through the API Gateway.
|
|
6
6
|
*
|
|
7
|
-
* This class provides a complete interface for authentication on the
|
|
8
|
-
*
|
|
7
|
+
* This class provides a complete interface for wallet-based authentication on the
|
|
8
|
+
* Monaco protocol. Backend services authenticate separately by setting their
|
|
9
|
+
* application secret key (`sk_...`) via {@link BaseAPI.setServerKey}, which is sent
|
|
10
|
+
* in the `x-server-key` header on backend requests — there is no token exchange.
|
|
9
11
|
*
|
|
10
12
|
* @example
|
|
11
13
|
* ```typescript
|
|
@@ -23,12 +25,9 @@
|
|
|
23
25
|
* challenge.nonce,
|
|
24
26
|
* clientId
|
|
25
27
|
* );
|
|
26
|
-
*
|
|
27
|
-
* // Authenticate backend service
|
|
28
|
-
* const backendAuth = await authAPI.authenticateBackend(secretKey);
|
|
29
28
|
* ```
|
|
30
29
|
*/
|
|
31
|
-
import type { AuthAPI, AuthState,
|
|
30
|
+
import type { AuthAPI, AuthState, ChallengeResponse, SessionCredentials, SessionRefreshResponse } from "@0xmonaco/types";
|
|
32
31
|
import type { Chain, WalletClient } from "viem";
|
|
33
32
|
import { BaseAPI } from "../base";
|
|
34
33
|
export declare class AuthAPIImpl extends BaseAPI implements AuthAPI {
|
|
@@ -51,20 +50,24 @@ export declare class AuthAPIImpl extends BaseAPI implements AuthAPI {
|
|
|
51
50
|
* Complete authentication flow for frontend applications.
|
|
52
51
|
*
|
|
53
52
|
* This method handles the entire authentication process:
|
|
54
|
-
* 1.
|
|
55
|
-
* 2.
|
|
56
|
-
* 3.
|
|
53
|
+
* 1. Generates a fresh ed25519 session keypair locally
|
|
54
|
+
* 2. Creates a challenge that commits to the session public key
|
|
55
|
+
* 3. Signs the challenge message with the wallet
|
|
56
|
+
* 4. Verifies the signature, registering the session public key
|
|
57
|
+
*
|
|
58
|
+
* The returned {@link AuthState} carries the session keypair; sign subsequent
|
|
59
|
+
* requests with the private key (the wallet is not used again until the
|
|
60
|
+
* session expires).
|
|
57
61
|
*
|
|
58
62
|
* @param clientId - Client ID of the application
|
|
59
|
-
* @returns Promise resolving to the
|
|
63
|
+
* @returns Promise resolving to the authentication state (with the session keypair)
|
|
60
64
|
* @throws {APIError} When authentication fails
|
|
61
65
|
* @throws {InvalidConfigError} When wallet account is not available
|
|
62
66
|
*
|
|
63
67
|
* @example
|
|
64
68
|
* ```typescript
|
|
65
|
-
* // Complete authentication in one call
|
|
66
69
|
* const authResult = await authAPI.authenticate("my-app-client-id");
|
|
67
|
-
* console.log(`
|
|
70
|
+
* console.log(`Session public key: ${authResult.sessionPublicKey}`);
|
|
68
71
|
* console.log(`User ID: ${authResult.user.id}`);
|
|
69
72
|
* ```
|
|
70
73
|
*/
|
|
@@ -109,7 +112,7 @@ export declare class AuthAPIImpl extends BaseAPI implements AuthAPI {
|
|
|
109
112
|
* console.log(`Nonce: ${challenge.nonce}`);
|
|
110
113
|
* ```
|
|
111
114
|
*/
|
|
112
|
-
createChallenge(address: string, clientId: string): Promise<ChallengeResponse>;
|
|
115
|
+
createChallenge(address: string, clientId: string, sessionPublicKey: string): Promise<ChallengeResponse>;
|
|
113
116
|
/**
|
|
114
117
|
* Verifies a signature for frontend authentication.
|
|
115
118
|
*
|
|
@@ -117,90 +120,55 @@ export declare class AuthAPIImpl extends BaseAPI implements AuthAPI {
|
|
|
117
120
|
* authenticated API access. This is the second step in the authentication flow.
|
|
118
121
|
*
|
|
119
122
|
* @param address - Wallet address of the user
|
|
120
|
-
* @param signature -
|
|
123
|
+
* @param signature - Wallet signature of the challenge message
|
|
121
124
|
* @param nonce - Nonce from the challenge response
|
|
122
125
|
* @param clientId - Client ID of the application
|
|
123
|
-
* @
|
|
126
|
+
* @param session - The locally-generated session keypair (hex-encoded)
|
|
127
|
+
* @returns Promise resolving to the authentication state (with the session keypair)
|
|
124
128
|
* @throws {APIError} When signature verification fails
|
|
125
129
|
*
|
|
126
130
|
* @example
|
|
127
131
|
* ```typescript
|
|
128
|
-
*
|
|
129
|
-
* const
|
|
130
|
-
*
|
|
131
|
-
* // User signs the challenge message with their wallet
|
|
132
|
+
* const keypair = generateSessionKeypair();
|
|
133
|
+
* const session = { publicKey: publicKeyHex(keypair), privateKey: privateKeyHex(keypair) };
|
|
134
|
+
* const challenge = await authAPI.createChallenge(address, clientId, session.publicKey);
|
|
132
135
|
* const signature = await wallet.signMessage(challenge.message);
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* const authResult = await authAPI.verifySignature(
|
|
136
|
-
* address,
|
|
137
|
-
* signature,
|
|
138
|
-
* challenge.nonce,
|
|
139
|
-
* clientId
|
|
140
|
-
* );
|
|
141
|
-
*
|
|
142
|
-
* console.log(`Access token: ${authResult.accessToken}`);
|
|
143
|
-
* console.log(`User ID: ${authResult.user.id}`);
|
|
136
|
+
* const authResult = await authAPI.verifySignature(address, signature, challenge.nonce, clientId, session);
|
|
137
|
+
* console.log(`Session public key: ${authResult.sessionPublicKey}`);
|
|
144
138
|
* ```
|
|
145
139
|
*/
|
|
146
|
-
verifySignature(address: string, signature: string, nonce: string, clientId: string): Promise<AuthState>;
|
|
140
|
+
verifySignature(address: string, signature: string, nonce: string, clientId: string, session: SessionCredentials): Promise<AuthState>;
|
|
147
141
|
/**
|
|
148
|
-
*
|
|
142
|
+
* Extends the current session's expiry.
|
|
149
143
|
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
144
|
+
* The request is signed with the active session key (set via
|
|
145
|
+
* {@link setSessionKeypair}); the server bumps the session's `expiresAt`.
|
|
146
|
+
* No new credential is issued — the same keypair keeps working.
|
|
152
147
|
*
|
|
153
|
-
* @
|
|
154
|
-
* @
|
|
155
|
-
* @throws {APIError} When backend authentication fails
|
|
148
|
+
* @returns Promise resolving to the new expiry
|
|
149
|
+
* @throws {APIError} When refresh fails (e.g. session expired or revoked)
|
|
156
150
|
*
|
|
157
151
|
* @example
|
|
158
152
|
* ```typescript
|
|
159
|
-
* const
|
|
160
|
-
* console.log(`
|
|
161
|
-
* console.log(`Application: ${backendAuth.application.name}`);
|
|
153
|
+
* const { expiresAt } = await authAPI.refreshSession();
|
|
154
|
+
* console.log(`Session now expires at: ${new Date(expiresAt * 1000)}`);
|
|
162
155
|
* ```
|
|
163
156
|
*/
|
|
164
|
-
|
|
157
|
+
refreshSession(): Promise<SessionRefreshResponse>;
|
|
165
158
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* Obtains a new access token using a valid refresh token. This is useful for
|
|
169
|
-
* maintaining long-term authentication without requiring the user to sign
|
|
170
|
-
* a new challenge.
|
|
171
|
-
*
|
|
172
|
-
* @param refreshToken - The refresh token to use
|
|
173
|
-
* @returns Promise resolving to new access and refresh tokens
|
|
174
|
-
* @throws {APIError} When token refresh fails
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* ```typescript
|
|
178
|
-
* const newTokens = await authAPI.refreshToken(refreshToken);
|
|
179
|
-
* console.log(`New access token: ${newTokens.accessToken}`);
|
|
180
|
-
* console.log(`Expires at: ${new Date(newTokens.expiresAt * 1000)}`);
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
refreshToken(refreshToken: string): Promise<TokenRefreshResponse>;
|
|
184
|
-
/**
|
|
185
|
-
* Revokes the current session's refresh token.
|
|
186
|
-
*
|
|
187
|
-
* Invalidates the refresh token associated with the current access token,
|
|
188
|
-
* preventing it from being used to obtain new access tokens. This is useful
|
|
189
|
-
* for logout functionality or when a token has been compromised.
|
|
159
|
+
* Revokes the current session.
|
|
190
160
|
*
|
|
191
|
-
* The
|
|
192
|
-
*
|
|
161
|
+
* The request is signed with the active session key; the server deletes the
|
|
162
|
+
* matching session row. Used for logout or when a key may be compromised.
|
|
193
163
|
*
|
|
194
|
-
* @returns Promise resolving when the
|
|
195
|
-
* @throws {APIError} When
|
|
164
|
+
* @returns Promise resolving when the session is revoked
|
|
165
|
+
* @throws {APIError} When revocation fails
|
|
196
166
|
*
|
|
197
167
|
* @example
|
|
198
168
|
* ```typescript
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
* await authAPI.revokeToken();
|
|
202
|
-
* console.log("Token revoked successfully");
|
|
169
|
+
* await authAPI.revokeSession();
|
|
170
|
+
* console.log("Session revoked successfully");
|
|
203
171
|
* ```
|
|
204
172
|
*/
|
|
205
|
-
|
|
173
|
+
revokeSession(): Promise<void>;
|
|
206
174
|
}
|