@0xmonaco/types 0.1.5 → 0.1.7

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.
Files changed (48) hide show
  1. package/README.md +190 -73
  2. package/dist/applications/index.d.ts +24 -0
  3. package/dist/applications/index.d.ts.map +1 -0
  4. package/dist/applications/index.js +7 -0
  5. package/dist/applications/index.js.map +1 -0
  6. package/dist/applications/responses.d.ts +21 -0
  7. package/dist/applications/responses.d.ts.map +1 -0
  8. package/dist/applications/responses.js +7 -0
  9. package/dist/applications/responses.js.map +1 -0
  10. package/dist/auth/index.d.ts +72 -91
  11. package/dist/auth/index.d.ts.map +1 -1
  12. package/dist/auth/responses.d.ts +37 -37
  13. package/dist/auth/responses.d.ts.map +1 -1
  14. package/dist/contracts/balances.d.ts +17 -17
  15. package/dist/contracts/index.d.ts +5 -5
  16. package/dist/index.d.ts +7 -4
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +7 -4
  19. package/dist/index.js.map +1 -1
  20. package/dist/market/index.d.ts +79 -0
  21. package/dist/market/index.d.ts.map +1 -0
  22. package/dist/market/index.js +7 -0
  23. package/dist/market/index.js.map +1 -0
  24. package/dist/sdk/index.d.ts +13 -5
  25. package/dist/sdk/index.d.ts.map +1 -1
  26. package/dist/sdk/index.js +0 -5
  27. package/dist/sdk/index.js.map +1 -1
  28. package/dist/sdk/network.d.ts +4 -3
  29. package/dist/sdk/network.d.ts.map +1 -1
  30. package/dist/trading/index.d.ts +4 -14
  31. package/dist/trading/index.d.ts.map +1 -1
  32. package/dist/trading/orders.d.ts +4 -0
  33. package/dist/trading/orders.d.ts.map +1 -1
  34. package/dist/trading/responses.d.ts +0 -42
  35. package/dist/trading/responses.d.ts.map +1 -1
  36. package/dist/vault/index.d.ts +13 -5
  37. package/dist/vault/index.d.ts.map +1 -1
  38. package/dist/vault/responses.d.ts +19 -17
  39. package/dist/vault/responses.d.ts.map +1 -1
  40. package/dist/websocket/events.d.ts +51 -0
  41. package/dist/websocket/events.d.ts.map +1 -0
  42. package/dist/websocket/events.js +7 -0
  43. package/dist/websocket/events.js.map +1 -0
  44. package/dist/websocket/index.d.ts +87 -0
  45. package/dist/websocket/index.d.ts.map +1 -0
  46. package/dist/websocket/index.js +7 -0
  47. package/dist/websocket/index.js.map +1 -0
  48. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @0xmonaco/types
2
2
 
3
- Core type definitions for the Monaco protocol. This package provides TypeScript types and interfaces used throughout the Monaco ecosystem, focusing on SDK configuration, vault operations, trading operations, and contract management.
3
+ Core type definitions for the Monaco protocol. This package provides TypeScript types and interfaces used throughout the Monaco ecosystem, focusing on SDK configuration, vault operations, trading operations, market data, and contract management.
4
4
 
5
5
  ## Installation
6
6
 
@@ -19,28 +19,40 @@ import { MonacoSDK, SDKConfig } from "@0xmonaco/types";
19
19
 
20
20
  // SDK configuration
21
21
  interface SDKConfig {
22
- privateKey?: Hex; // Private key as hex string (0x-prefixed)
23
- signer?: PrivateKeyAccount; // Viem Account for advanced account management
24
- account?: Account; // Custom Account implementation
25
- network?: Network; // Network override (defaults to 'mainnet')
22
+ walletClient: WalletClient; // Wallet client for signing operations
23
+ network?: Network; // Network override (defaults to 'mainnet')
24
+ transport?: Transport; // Optional transport for the public client
26
25
  }
27
26
 
28
27
  // Main SDK interface
29
28
  interface MonacoSDK {
30
- vault: VaultAPI; // Vault operations API
31
- trading: TradingAPI; // Trading operations API
29
+ applications: ApplicationsAPI; // Applications operations API
30
+ auth: AuthAPI; // Auth operations API
31
+ vault: VaultAPI; // Vault operations API
32
+ trading: TradingAPI; // Trading operations API
33
+ market: MarketAPI; // Market metadata API
34
+ profile: ProfileAPI; // Profile operations API
35
+ websocket: OrderWebSocketClient; // WebSocket client for real-time order events
32
36
  walletClient: WalletClient; // Wallet client for blockchain operations
33
37
  publicClient: PublicClient; // Public client for read-only operations
34
-
38
+
39
+ // Authentication
40
+ login(clientId: string): Promise<AuthState>;
41
+ logout(): Promise<void>;
42
+ refreshAuth(): Promise<AuthState>;
43
+ getAuthState(): AuthState | undefined;
44
+
35
45
  // Account management
46
+ isAuthenticated(): boolean;
36
47
  isConnected(): boolean;
37
48
  getAccountAddress(): string;
38
49
  getNetwork(): Network;
39
50
  getChainId(): number;
40
- switchAccount(newAccount: Account): void;
41
- switchPrivateKey(privateKey: Hex): void;
42
- canSign(): boolean;
43
- waitForTransaction(hash: string, confirmations?: number, timeout?: number): Promise<TransactionReceipt>;
51
+ waitForTransaction(
52
+ hash: string,
53
+ confirmations?: number,
54
+ timeout?: number
55
+ ): Promise<TransactionReceipt>;
44
56
  }
45
57
  ```
46
58
 
@@ -52,13 +64,25 @@ Types for vault operations including deposits, withdrawals, and balance manageme
52
64
  import { VaultAPI, Balance, TransactionResult } from "@0xmonaco/types";
53
65
 
54
66
  // Vault operations
55
- interface VaultAPI {
56
- approve(token: string, amount: bigint): Promise<TransactionResult>;
57
- deposit(token: string, amount: bigint): Promise<TransactionResult>;
58
- withdraw(token: string, amount: bigint): Promise<TransactionResult>;
67
+ interface VaultAPI extends BaseAPI {
68
+ setVaultAddress(vaultAddress: Address): void;
69
+ getVaultAddress(): Address | undefined;
70
+ approve(
71
+ token: string,
72
+ amount: bigint,
73
+ autoWait?: boolean
74
+ ): Promise<TransactionResult>;
75
+ deposit(
76
+ token: string,
77
+ amount: bigint,
78
+ autoWait?: boolean
79
+ ): Promise<TransactionResult>;
80
+ withdraw(
81
+ token: string,
82
+ amount: bigint,
83
+ autoWait?: boolean
84
+ ): Promise<TransactionResult>;
59
85
  getBalance(token: string): Promise<Balance>;
60
- getAllowance(token: string): Promise<bigint>;
61
- needsApproval(token: string, amount: bigint): Promise<boolean>;
62
86
  }
63
87
 
64
88
  // Vault response types
@@ -74,6 +98,7 @@ interface TransactionResult {
74
98
  hash: string;
75
99
  status: "pending" | "confirmed" | "failed";
76
100
  nonce: bigint;
101
+ receipt?: TransactionReceipt;
77
102
  }
78
103
  ```
79
104
 
@@ -82,62 +107,134 @@ interface TransactionResult {
82
107
  Types for trading operations including order placement and management:
83
108
 
84
109
  ```typescript
85
- import {
86
- TradingAPI,
87
- OrderSide,
88
- OrderType,
89
- OrderIntent,
90
- OrderResponse
110
+ import {
111
+ TradingAPI,
112
+ OrderSide,
113
+ OrderType,
114
+ CreateOrderResponse,
115
+ CancelOrderResponse,
116
+ ReplaceOrderResponse,
117
+ GetPaginatedOrdersResponse,
118
+ GetOrderResponse,
91
119
  } from "@0xmonaco/types";
92
120
 
93
121
  // Trading operations
94
- interface TradingAPI {
95
- placeLimitOrder(market: string, side: OrderSide, size: bigint, price: bigint, options?: { timeInForce?: TimeInForce }): Promise<OrderResponse>;
96
- placeMarketOrder(market: string, side: OrderSide, size: bigint, options?: { slippageToleranceBps?: number }): Promise<OrderResponse>;
97
- placePostOnlyOrder(market: string, side: OrderSide, size: bigint, price: bigint): Promise<OrderResponse>;
98
- replaceOrder(originalOrderId: string, newOrder: { market: string; side: OrderSide; size: bigint; price?: bigint; type: "limit" | "market" | "post_only"; timeInForce?: TimeInForce }): Promise<OrderResponse>;
122
+ interface TradingAPI extends BaseAPI {
123
+ placeLimitOrder(
124
+ market: string,
125
+ side: OrderSide,
126
+ quantity: string,
127
+ price: string,
128
+ options?: {
129
+ tradingMode?: string;
130
+ useMasterBalance?: boolean;
131
+ expirationDate?: string;
132
+ }
133
+ ): Promise<CreateOrderResponse>;
134
+
135
+ placeMarketOrder(
136
+ market: string,
137
+ side: OrderSide,
138
+ quantity: string,
139
+ options?: { tradingMode?: string }
140
+ ): Promise<CreateOrderResponse>;
141
+
99
142
  cancelOrder(orderId: string): Promise<CancelOrderResponse>;
100
- closePosition(market: string, options?: { maxSlippage?: number }): Promise<ClosePositionResponse>;
143
+
144
+ replaceOrder(
145
+ orderId: string,
146
+ newOrder: {
147
+ price?: string;
148
+ quantity: string;
149
+ useMasterBalance?: boolean;
150
+ }
151
+ ): Promise<ReplaceOrderResponse>;
152
+
153
+ getPaginatedOrders(
154
+ params?: GetPaginatedOrdersParams
155
+ ): Promise<GetPaginatedOrdersResponse>;
156
+ getOrder(orderId: string): Promise<GetOrderResponse>;
101
157
  }
102
158
 
103
159
  // Trading types
104
- type OrderSide = "buy" | "sell";
105
-
106
- type OrderType = "limit" | "market" | "post_only";
107
- type TimeInForce = "GTC" | "IOC" | "FOK";
108
-
109
- interface OrderIntent {
110
- market: string;
111
- side: OrderSide;
112
- size: string;
113
- orderType: OrderType;
114
- userAddress: string;
115
- timestamp: bigint;
116
- nonce: bigint;
117
- price?: string;
118
- timeInForce?: TimeInForce;
119
- slippageTolerance?: string;
120
- }
160
+ type OrderSide = "BUY" | "SELL";
161
+ type OrderType = "LIMIT" | "MARKET";
162
+ type OrderStatus = "PENDING" | "FILLED" | "CANCELLED" | "REJECTED";
163
+ type TradingMode = "SPOT";
121
164
 
122
165
  // Trading response types
123
- interface OrderResponse {
124
- orderId: string;
125
- status: "accepted" | "rejected";
126
- timestamp: number;
166
+ interface CreateOrderResponse {
167
+ order_id: string;
168
+ status: "SUCCESS" | "FAILED";
169
+ match_result?: {
170
+ remaining_quantity: string;
171
+ status: string;
172
+ };
127
173
  }
128
174
 
129
175
  interface CancelOrderResponse {
130
- orderId: string;
131
- status: "cancelled" | "failed";
132
- timestamp: number;
176
+ order_id: string;
177
+ status: "SUCCESS" | "FAILED";
178
+ }
179
+
180
+ interface ReplaceOrderResponse {
181
+ order_id: string;
182
+ status: "SUCCESS" | "FAILED";
183
+ }
184
+ ```
185
+
186
+ ### Market Types
187
+
188
+ Types for market data operations including trading pair metadata:
189
+
190
+ ```typescript
191
+ import {
192
+ MarketAPI,
193
+ TradingPair,
194
+ GetTradingPairsResponse,
195
+ GetTradingPairResponse,
196
+ } from "@0xmonaco/types";
197
+
198
+ // Market operations
199
+ interface MarketAPI extends BaseAPI {
200
+ getTradingPairs(): Promise<TradingPair[]>;
201
+ getTradingPairBySymbol(symbol: string): Promise<TradingPair | undefined>;
202
+ }
203
+
204
+ // Market data types
205
+ interface TradingPair {
206
+ id: string;
207
+ symbol: string;
208
+ base_token: string;
209
+ quote_token: string;
210
+ base_token_contract: string;
211
+ quote_token_contract: string;
212
+ base_decimals: number;
213
+ quote_decimals: number;
214
+ market_type: string;
215
+ is_active: boolean;
216
+ maker_fee_bps: number;
217
+ taker_fee_bps: number;
218
+ min_order_size: string;
219
+ max_order_size: string;
220
+ tick_size: string;
221
+ }
222
+
223
+ // Market response types
224
+ interface GetTradingPairsResponse {
225
+ data: {
226
+ data: TradingPair[];
227
+ limit: number;
228
+ page: number;
229
+ total: number;
230
+ total_pages: number;
231
+ };
232
+ success: boolean;
133
233
  }
134
234
 
135
- interface ClosePositionResponse {
136
- market: string;
137
- status: "closed" | "no_position" | "partial_close";
138
- closedSize?: bigint;
139
- remainingSize?: bigint;
140
- timestamp: number;
235
+ interface GetTradingPairResponse {
236
+ data: TradingPair;
237
+ success: boolean;
141
238
  }
142
239
  ```
143
240
 
@@ -146,7 +243,12 @@ interface ClosePositionResponse {
146
243
  Types for contract addresses, instances, and contract-related operations:
147
244
 
148
245
  ```typescript
149
- import { ContractAddresses, ContractInstances, Token, UserBalance } from "@0xmonaco/types";
246
+ import {
247
+ ContractAddresses,
248
+ ContractInstances,
249
+ Token,
250
+ UserBalance,
251
+ } from "@0xmonaco/types";
150
252
 
151
253
  // Contract addresses
152
254
  interface ContractAddresses {
@@ -192,9 +294,10 @@ interface NetworkEndpoints {
192
294
 
193
295
  ### SDK Types
194
296
 
195
- - `MonacoSDK`: Main SDK interface with vault and trading APIs
297
+ - `MonacoSDK`: Main SDK interface with all API modules
196
298
  - `SDKConfig`: Configuration options for the Monaco SDK
197
299
  - `Network`: Network type ("mainnet" | "testnet")
300
+ - `AuthState`: Authentication state information
198
301
 
199
302
  ### Vault Types
200
303
 
@@ -205,12 +308,18 @@ interface NetworkEndpoints {
205
308
  ### Trading Types
206
309
 
207
310
  - `TradingAPI`: Interface for trading operations (orders, positions)
208
- - `OrderSide`: Order side type ("buy" | "sell")
209
- - `OrderType`: Order type for different strategies
210
- - `OrderIntent`: Intent interface for placing orders
211
- - `OrderResponse`: Response from order operations
311
+ - `OrderSide`: Order side type ("BUY" | "SELL")
312
+ - `OrderType`: Order type ("LIMIT" | "MARKET")
313
+ - `CreateOrderResponse`: Response from order placement
212
314
  - `CancelOrderResponse`: Response from order cancellation
213
- - `ClosePositionResponse`: Response from position closing
315
+ - `ReplaceOrderResponse`: Response from order replacement
316
+
317
+ ### Market Types
318
+
319
+ - `MarketAPI`: Interface for market data operations
320
+ - `TradingPair`: Trading pair metadata with all market information
321
+ - `GetTradingPairsResponse`: Response wrapper for trading pairs list
322
+ - `GetTradingPairResponse`: Response wrapper for single trading pair
214
323
 
215
324
  ### Contract Types
216
325
 
@@ -225,19 +334,27 @@ The types package is organized into domain-specific modules:
225
334
 
226
335
  ```
227
336
  src/
337
+ ├── api/ # Base API types
338
+ │ └── index.ts # Common API interfaces
339
+ ├── applications/ # Applications types
340
+ ├── auth/ # Authentication types
341
+ ├── contracts/ # Contract types
342
+ │ ├── index.ts # Contract interfaces
343
+ │ └── balances.ts # Balance-related types
344
+ ├── market/ # Market data types
345
+ │ └── index.ts # Market API interface and types
346
+ ├── profile/ # Profile types
228
347
  ├── sdk/ # SDK types
229
348
  │ ├── index.ts # Main SDK interfaces and configuration
230
349
  │ └── network.ts # Network-related types
231
- ├── vault/ # Vault types
232
- │ ├── index.ts # Vault API interface
233
- │ └── responses.ts # Vault response types
234
350
  ├── trading/ # Trading types
235
351
  │ ├── index.ts # Trading API interface
236
352
  │ ├── orders.ts # Order-related types
237
353
  │ └── responses.ts # Trading response types
238
- ├── contracts/ # Contract types
239
- │ ├── index.ts # Contract interfaces
240
- │ └── balances.ts # Balance-related types
354
+ ├── vault/ # Vault types
355
+ │ ├── index.ts # Vault API interface
356
+ │ └── responses.ts # Vault response types
357
+ ├── websocket/ # WebSocket types
241
358
  └── index.ts # Package exports
242
359
  ```
243
360
 
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Applications Types
3
+ *
4
+ * Types for application configuration operations.
5
+ */
6
+ import type { BaseAPI } from "../api";
7
+ import type { ApplicationConfigResponse } from "./responses";
8
+ /**
9
+ * Applications API interface.
10
+ * Provides methods for retrieving application configuration.
11
+ */
12
+ export interface ApplicationsAPI extends BaseAPI {
13
+ /**
14
+ * Gets the configuration for the authenticated application.
15
+ *
16
+ * Returns the application's configuration including allowed origins,
17
+ * webhook URL, and other settings. Requires valid authentication.
18
+ *
19
+ * @returns Promise resolving to the application configuration
20
+ */
21
+ getApplicationConfig(): Promise<ApplicationConfigResponse>;
22
+ }
23
+ export type { ApplicationConfigResponse } from "./responses";
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/applications/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAM7D;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,OAAO;IAC/C;;;;;;;OAOG;IACH,oBAAoB,IAAI,OAAO,CAAC,yBAAyB,CAAC,CAAC;CAC3D;AAGD,YAAY,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Applications Types
3
+ *
4
+ * Types for application configuration operations.
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/applications/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Applications Response Types
3
+ *
4
+ * Response types for application configuration operations.
5
+ */
6
+ /**
7
+ * Response to an application configuration request.
8
+ */
9
+ export interface ApplicationConfigResponse {
10
+ /** Unique identifier for the application */
11
+ id: string;
12
+ /** Human-readable name of the application */
13
+ name: string;
14
+ /** List of allowed origins for CORS */
15
+ allowedOrigins: string[];
16
+ /** Webhook URL for receiving events (optional) */
17
+ webhookUrl?: string;
18
+ /** Vault contract address */
19
+ vaultContractAddress: string;
20
+ }
21
+ //# sourceMappingURL=responses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/applications/responses.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACzC,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,oBAAoB,EAAE,MAAM,CAAC;CAC7B"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Applications Response Types
3
+ *
4
+ * Response types for application configuration operations.
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=responses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/applications/responses.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -4,106 +4,87 @@
4
4
  * Types for authentication operations including challenge creation,
5
5
  * signature verification, and backend authentication.
6
6
  */
7
- import {
8
- type ChallengeResponse,
9
- type VerifyResponse,
10
- type BackendAuthResponse,
11
- type TokenRefreshResponse,
12
- User,
13
- } from "./responses";
7
+ import type { BackendAuthResponse, ChallengeResponse, TokenRefreshResponse, User, VerifyResponse } from "./responses";
14
8
  /**
15
9
  * Auth API interface.
16
10
  * Provides methods for frontend and backend authentication.
17
11
  * Handles challenge creation, signature verification, and backend auth.
18
12
  */
19
13
  export interface AuthAPI {
20
- /**
21
- * Complete authentication flow for frontend applications.
22
- *
23
- * This method handles the entire authentication process:
24
- * 1. Creates a challenge
25
- * 2. Signs the challenge message
26
- * 3. Verifies the signature and returns JWT tokens
27
- *
28
- * @param clientId - Client ID of the application
29
- * @returns Promise resolving to the verification response with JWT tokens
30
- */
31
- authenticate(clientId: string): Promise<VerifyResponse>;
32
- /**
33
- * Signs a challenge message using the wallet client.
34
- *
35
- * Signs the provided message using the wallet's private key.
36
- * This is used in the authentication flow to prove ownership of the wallet.
37
- *
38
- * @param message - The message to sign
39
- * @returns Promise resolving to the signature
40
- */
41
- signChallenge(message: string): Promise<string>;
42
- /**
43
- * Creates a challenge for frontend authentication.
44
- * Generates a unique nonce and message that the user must sign with their wallet.
45
- * @param address - Wallet address of the user
46
- * @param clientId - Client ID of the application
47
- * @returns Promise resolving to the challenge response
48
- */
49
- createChallenge(
50
- address: string,
51
- clientId: string,
52
- ): Promise<ChallengeResponse>;
53
- /**
54
- * Verifies a signature for frontend authentication.
55
- * Validates the signature against the challenge and returns JWT tokens.
56
- * @param address - Wallet address of the user
57
- * @param signature - Signature of the challenge message
58
- * @param nonce - Nonce from the challenge response
59
- * @param clientId - Client ID of the application
60
- * @returns Promise resolving to the verification response with JWT tokens
61
- */
62
- verifySignature(
63
- address: string,
64
- signature: string,
65
- nonce: string,
66
- clientId: string,
67
- ): Promise<VerifyResponse>;
68
- /**
69
- * Authenticates a backend service using a secret key.
70
- * Returns JWT tokens for API access.
71
- * @param secretKey - Secret key of the application
72
- * @returns Promise resolving to the backend auth response with JWT tokens
73
- */
74
- authenticateBackend(secretKey: string): Promise<BackendAuthResponse>;
75
- /**
76
- * Refreshes an access token using a refresh token.
77
- * @param refreshToken - The refresh token to use
78
- * @returns Promise resolving to new access and refresh tokens
79
- */
80
- refreshToken(refreshToken: string): Promise<TokenRefreshResponse>;
81
- /**
82
- * Revokes a refresh token.
83
- * @param refreshToken - The refresh token to revoke
84
- * @returns Promise resolving when the token is revoked
85
- */
86
- revokeToken(refreshToken: string): Promise<void>;
14
+ /**
15
+ * Complete authentication flow for frontend applications.
16
+ *
17
+ * This method handles the entire authentication process:
18
+ * 1. Creates a challenge
19
+ * 2. Signs the challenge message
20
+ * 3. Verifies the signature and returns JWT tokens
21
+ *
22
+ * @param clientId - Client ID of the application
23
+ * @returns Promise resolving to the verification response with JWT tokens
24
+ */
25
+ authenticate(clientId: string): Promise<VerifyResponse>;
26
+ /**
27
+ * Signs a challenge message using the wallet client.
28
+ *
29
+ * Signs the provided message using the wallet's private key.
30
+ * This is used in the authentication flow to prove ownership of the wallet.
31
+ *
32
+ * @param message - The message to sign
33
+ * @returns Promise resolving to the signature
34
+ */
35
+ signChallenge(message: string): Promise<string>;
36
+ /**
37
+ * Creates a challenge for frontend authentication.
38
+ * Generates a unique nonce and message that the user must sign with their wallet.
39
+ * @param address - Wallet address of the user
40
+ * @param clientId - Client ID of the application
41
+ * @returns Promise resolving to the challenge response
42
+ */
43
+ createChallenge(address: string, clientId: string): Promise<ChallengeResponse>;
44
+ /**
45
+ * Verifies a signature for frontend authentication.
46
+ * Validates the signature against the challenge and returns JWT tokens.
47
+ * @param address - Wallet address of the user
48
+ * @param signature - Signature of the challenge message
49
+ * @param nonce - Nonce from the challenge response
50
+ * @param clientId - Client ID of the application
51
+ * @returns Promise resolving to the verification response with JWT tokens
52
+ */
53
+ verifySignature(address: string, signature: string, nonce: string, clientId: string): Promise<VerifyResponse>;
54
+ /**
55
+ * Authenticates a backend service using a secret key.
56
+ * Returns JWT tokens for API access.
57
+ * @param secretKey - Secret key of the application
58
+ * @returns Promise resolving to the backend auth response with JWT tokens
59
+ */
60
+ authenticateBackend(secretKey: string): Promise<BackendAuthResponse>;
61
+ /**
62
+ * Refreshes an access token using a refresh token.
63
+ * @param refreshToken - The refresh token to use
64
+ * @returns Promise resolving to new access and refresh tokens
65
+ */
66
+ refreshToken(refreshToken: string): Promise<TokenRefreshResponse>;
67
+ /**
68
+ * Revokes a refresh token.
69
+ * @param refreshToken - The refresh token to revoke
70
+ * @returns Promise resolving when the token is revoked
71
+ */
72
+ revokeToken(refreshToken: string): Promise<void>;
87
73
  }
88
74
  /**
89
75
  * Authentication state containing all tokens and metadata
90
76
  */
91
77
  export interface AuthState {
92
- /** JWT access token for authenticated requests */
93
- accessToken: string;
94
- /** JWT refresh token for token renewal */
95
- refreshToken: string;
96
- /** Unix timestamp when the access token expires */
97
- expiresAt: number;
98
- /** Information about the authenticated user */
99
- user: User;
100
- /** When the auth state was created */
101
- createdAt: number;
78
+ /** JWT access token for authenticated requests */
79
+ accessToken: string;
80
+ /** JWT refresh token for token renewal */
81
+ refreshToken: string;
82
+ /** Unix timestamp when the access token expires */
83
+ expiresAt: number | string;
84
+ /** Information about the authenticated user */
85
+ user: User;
86
+ /** When the auth state was created */
87
+ createdAt: number;
102
88
  }
103
- export type {
104
- ChallengeResponse,
105
- VerifyResponse,
106
- BackendAuthResponse,
107
- TokenRefreshResponse,
108
- } from "./responses";
109
- //# sourceMappingURL=index.d.ts.map
89
+ export type { BackendAuthResponse, ChallengeResponse, TokenRefreshResponse, VerifyResponse, } from "./responses";
90
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACN,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,IAAI,EACJ,MAAM,aAAa,CAAC;AAMrB;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACvB;;;;;;;;;;OAUG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAExD;;;;;;;;OAQG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEhD;;;;;;OAMG;IACH,eAAe,CACd,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE9B;;;;;;;;OAQG;IACH,eAAe,CACd,OAAO,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