@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.
- package/README.md +190 -73
- package/dist/applications/index.d.ts +24 -0
- package/dist/applications/index.d.ts.map +1 -0
- package/dist/applications/index.js +7 -0
- package/dist/applications/index.js.map +1 -0
- package/dist/applications/responses.d.ts +21 -0
- package/dist/applications/responses.d.ts.map +1 -0
- package/dist/applications/responses.js +7 -0
- package/dist/applications/responses.js.map +1 -0
- package/dist/auth/index.d.ts +72 -91
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/responses.d.ts +37 -37
- package/dist/auth/responses.d.ts.map +1 -1
- package/dist/contracts/balances.d.ts +17 -17
- package/dist/contracts/index.d.ts +5 -5
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/market/index.d.ts +79 -0
- package/dist/market/index.d.ts.map +1 -0
- package/dist/market/index.js +7 -0
- package/dist/market/index.js.map +1 -0
- package/dist/sdk/index.d.ts +13 -5
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/index.js +0 -5
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/network.d.ts +4 -3
- package/dist/sdk/network.d.ts.map +1 -1
- package/dist/trading/index.d.ts +4 -14
- package/dist/trading/index.d.ts.map +1 -1
- package/dist/trading/orders.d.ts +4 -0
- package/dist/trading/orders.d.ts.map +1 -1
- package/dist/trading/responses.d.ts +0 -42
- package/dist/trading/responses.d.ts.map +1 -1
- package/dist/vault/index.d.ts +13 -5
- package/dist/vault/index.d.ts.map +1 -1
- package/dist/vault/responses.d.ts +19 -17
- package/dist/vault/responses.d.ts.map +1 -1
- package/dist/websocket/events.d.ts +51 -0
- package/dist/websocket/events.d.ts.map +1 -0
- package/dist/websocket/events.js +7 -0
- package/dist/websocket/events.js.map +1 -0
- package/dist/websocket/index.d.ts +87 -0
- package/dist/websocket/index.d.ts.map +1 -0
- package/dist/websocket/index.js +7 -0
- package/dist/websocket/index.js.map +1 -0
- 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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
90
|
-
|
|
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(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
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 = "
|
|
105
|
-
|
|
106
|
-
type
|
|
107
|
-
type
|
|
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
|
|
124
|
-
|
|
125
|
-
status: "
|
|
126
|
-
|
|
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
|
-
|
|
131
|
-
status: "
|
|
132
|
-
|
|
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
|
|
136
|
-
|
|
137
|
-
|
|
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 {
|
|
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
|
|
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 ("
|
|
209
|
-
- `OrderType`: Order type
|
|
210
|
-
- `
|
|
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
|
-
- `
|
|
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
|
-
├──
|
|
239
|
-
│ ├── index.ts #
|
|
240
|
-
│ └──
|
|
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 @@
|
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/applications/responses.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
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
|
package/dist/auth/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAMtH;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACtB;;;;;;;;;;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,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE/E;;;;;;;;OAQG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAE9G;;;;;OAKG;IACH,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAErE;;;;OAIG;IACH,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAElE;;;;OAIG;IACH,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClD;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,YAAY,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,+CAA+C;IAC/C,IAAI,EAAE,IAAI,CAAC;IACX,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;CACnB;AAGD,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,GACf,MAAM,aAAa,CAAC"}
|