@0xmonaco/core 0.8.15 → 0.8.16
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 +42 -48
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
# Monaco Core SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
This package is currently in **early development**.
|
|
6
|
-
|
|
7
|
-
**Breaking changes are expected** and may occur without notice. This version is intended for:
|
|
8
|
-
- Early adopters and testing
|
|
9
|
-
- Development and experimentation
|
|
10
|
-
- Feedback collection
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
Core SDK implementation for interacting with Monaco Protocol. This SDK provides a comprehensive implementation with Authentication, Vault, Trading, Market, and Profile APIs, featuring JWT authentication and secure API Gateway integration.
|
|
3
|
+
Core SDK implementation for interacting with Monaco Protocol. This SDK provides a comprehensive implementation with Authentication, Vault, Trading, Market, and Profile APIs, featuring noncustodial session-key authentication and secure API Gateway integration.
|
|
15
4
|
|
|
16
5
|
## Installation
|
|
17
6
|
|
|
@@ -27,10 +16,10 @@ npm install viem@^2.31.7
|
|
|
27
16
|
## Features
|
|
28
17
|
|
|
29
18
|
### 🔐 **Authentication**
|
|
30
|
-
- **
|
|
31
|
-
- **Wallet Signature Verification**: EIP-712 signature
|
|
32
|
-
- **
|
|
33
|
-
- **
|
|
19
|
+
- **Session-key Authentication**: Noncustodial ed25519 session keys — the server never holds a credential that can impersonate you
|
|
20
|
+
- **Wallet Signature Verification**: EIP-712 signature authorizes each session key
|
|
21
|
+
- **Session Refresh**: Extend session expiry without re-prompting the wallet
|
|
22
|
+
- **Server-key Auth**: Optional `sk_...` application key for backend/service access
|
|
34
23
|
|
|
35
24
|
### 🏦 **Vault Operations**
|
|
36
25
|
- **Token Approvals**: ERC20 token approvals for vault usage
|
|
@@ -55,8 +44,8 @@ npm install viem@^2.31.7
|
|
|
55
44
|
- **Balance Tracking**: Cross-platform balance monitoring
|
|
56
45
|
|
|
57
46
|
### 🔐 **Security Features**
|
|
58
|
-
- **
|
|
59
|
-
- **EIP-712 Signatures**: Type-safe, structured data signing for
|
|
47
|
+
- **Session-key Signing**: Every authenticated request is signed with a locally held ed25519 key
|
|
48
|
+
- **EIP-712 Signatures**: Type-safe, structured data signing for session authorization
|
|
60
49
|
- **API Gateway Integration**: Secure communication with Monaco backend
|
|
61
50
|
- **TLS Encryption**: Secure API communications
|
|
62
51
|
|
|
@@ -114,9 +103,9 @@ async function authExample() {
|
|
|
114
103
|
// Login with client ID and auto-connect authenticated WebSocket channels (Orders)
|
|
115
104
|
const authState = await monaco.login("your-client-id", { connectWebSocket: true });
|
|
116
105
|
console.log("Authenticated:", authState.user);
|
|
117
|
-
console.log("
|
|
118
|
-
|
|
119
|
-
|
|
106
|
+
console.log("Session:", {
|
|
107
|
+
sessionPublicKey: authState.sessionPublicKey,
|
|
108
|
+
expiresAt: authState.expiresAt,
|
|
120
109
|
});
|
|
121
110
|
|
|
122
111
|
// Authenticated WebSocket channels are now connected - start receiving real-time updates
|
|
@@ -128,11 +117,11 @@ async function authExample() {
|
|
|
128
117
|
// Check authentication status
|
|
129
118
|
console.log("Is authenticated:", monaco.isAuthenticated());
|
|
130
119
|
|
|
131
|
-
// Logout (revokes the
|
|
120
|
+
// Logout (revokes the session and disconnects authenticated WebSockets)
|
|
132
121
|
await monaco.logout();
|
|
133
122
|
|
|
134
|
-
// Or manually revoke the
|
|
135
|
-
await monaco.auth.
|
|
123
|
+
// Or manually revoke the session
|
|
124
|
+
await monaco.auth.revokeSession();
|
|
136
125
|
}
|
|
137
126
|
|
|
138
127
|
// Market Data
|
|
@@ -250,9 +239,9 @@ interface SDKConfig {
|
|
|
250
239
|
}
|
|
251
240
|
```
|
|
252
241
|
|
|
253
|
-
### Authentication &
|
|
242
|
+
### Authentication & Session Management
|
|
254
243
|
|
|
255
|
-
The SDK uses
|
|
244
|
+
The SDK uses a noncustodial session-key scheme. On login it generates an ed25519 keypair locally, has your wallet authorize it via an EIP-712 signature, and signs every subsequent request with the private key — the server never holds a credential that can impersonate you.
|
|
256
245
|
|
|
257
246
|
```typescript
|
|
258
247
|
// After login, you receive an AuthState object
|
|
@@ -260,35 +249,40 @@ const authState = await sdk.login(clientId);
|
|
|
260
249
|
|
|
261
250
|
// AuthState structure:
|
|
262
251
|
interface AuthState {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
expiresAt: number;
|
|
266
|
-
user: User;
|
|
252
|
+
sessionPublicKey: string; // ed25519 public key registered with the server
|
|
253
|
+
sessionPrivateKey: string; // ed25519 private key used to sign requests (the long-lived credential)
|
|
254
|
+
expiresAt: number; // Unix timestamp (seconds) when the session expires
|
|
255
|
+
user: User; // User information
|
|
267
256
|
}
|
|
268
257
|
```
|
|
269
258
|
|
|
259
|
+
> The private key is the long-lived credential. Persist it (e.g. `localStorage`, same risk profile as a JWT) to survive page reloads without re-prompting the wallet. When the session expires, call `refreshAuth()` or re-`login()`.
|
|
260
|
+
|
|
270
261
|
```typescript
|
|
271
|
-
// Revoke the current session
|
|
272
|
-
await sdk.auth.
|
|
262
|
+
// Revoke the current session
|
|
263
|
+
await sdk.auth.revokeSession();
|
|
273
264
|
|
|
274
265
|
// 💡 TIP: Use the built-in logout method
|
|
275
|
-
await sdk.logout(); // Automatically calls
|
|
266
|
+
await sdk.logout(); // Automatically calls revokeSession internally
|
|
276
267
|
```
|
|
277
268
|
|
|
278
|
-
**
|
|
279
|
-
- `login(clientId, options?)` -
|
|
269
|
+
**Session Management Methods:**
|
|
270
|
+
- `login(clientId, options?)` - Authorize a session key and authenticate
|
|
280
271
|
- `clientId`: Your application's client ID
|
|
281
272
|
- `options.connectWebSocket`: (optional) Auto-connect WebSocket after login (default: `false`)
|
|
282
|
-
- Returns `AuthState` with
|
|
283
|
-
- `logout()` - Revoke
|
|
284
|
-
- Calls `auth.
|
|
273
|
+
- Returns `AuthState` with the session keypair, expiration, and user info
|
|
274
|
+
- `logout()` - Revoke the session, disconnect WebSocket, and clear state
|
|
275
|
+
- Calls `auth.revokeSession()` internally
|
|
285
276
|
- Disconnects authenticated WebSocket channels
|
|
286
277
|
- Clears local auth state
|
|
287
|
-
- `refreshAuth()` -
|
|
288
|
-
- `isAuthenticated()` - Check if
|
|
289
|
-
- `getAuthState()` - Get current auth state with
|
|
278
|
+
- `refreshAuth()` - Extend the current session's expiry
|
|
279
|
+
- `isAuthenticated()` - Check if a session is active
|
|
280
|
+
- `getAuthState()` - Get current auth state with the session keypair
|
|
290
281
|
- `setAuthState(authState)` - Set auth state directly (useful for sharing across SDK instances)
|
|
291
282
|
|
|
283
|
+
**Server-key Auth (backend/service access):**
|
|
284
|
+
- `setServerKey(serverKey)` - Authenticate with an application secret key (`sk_...`) instead of, or alongside, a session. Useful for server-side integrations.
|
|
285
|
+
|
|
292
286
|
### Vault API
|
|
293
287
|
|
|
294
288
|
The vault API provides secure token management operations:
|
|
@@ -391,7 +385,7 @@ monaco.websocket.orderbook.subscribeToOrderbookEvents("BTC/USDC", "SPOT", (event
|
|
|
391
385
|
|
|
392
386
|
#### Authenticated WebSockets (Orders)
|
|
393
387
|
|
|
394
|
-
Requires
|
|
388
|
+
Requires an authenticated session for personal order updates. You can either auto-connect during login or connect manually:
|
|
395
389
|
|
|
396
390
|
**Option 1: Auto-connect (recommended for authenticated channels)**
|
|
397
391
|
```typescript
|
|
@@ -515,15 +509,15 @@ bun run lint --filter @0xmonaco/core
|
|
|
515
509
|
|
|
516
510
|
## Security Features
|
|
517
511
|
|
|
518
|
-
###
|
|
519
|
-
- **
|
|
520
|
-
- **EIP-712 login**: Wallet signature
|
|
521
|
-
- **
|
|
522
|
-
- **
|
|
512
|
+
### Session-key Authentication
|
|
513
|
+
- **Noncustodial**: ed25519 session keys are generated locally; the server never holds a credential that can impersonate you
|
|
514
|
+
- **EIP-712 login**: Wallet signature authorizes each session key
|
|
515
|
+
- **Session refresh**: Extend expiry without re-prompting the wallet
|
|
516
|
+
- **Server-key auth**: Optional `sk_...` application key for backend/service access
|
|
523
517
|
|
|
524
518
|
### API Gateway Integration
|
|
525
519
|
- **Secure communication**: TLS encryption for all API calls
|
|
526
|
-
- **
|
|
520
|
+
- **Request signing**: Backend verifies the session signature on every authenticated request
|
|
527
521
|
- **Rate limiting**: Protection against abuse
|
|
528
522
|
- **Audit logging**: Complete transaction history
|
|
529
523
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xmonaco/core",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"viem": "^2.45.2"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@0xmonaco/contracts": "0.8.
|
|
27
|
-
"@0xmonaco/types": "0.8.
|
|
26
|
+
"@0xmonaco/contracts": "0.8.16",
|
|
27
|
+
"@0xmonaco/types": "0.8.16",
|
|
28
28
|
"@noble/curves": "^1.9.1",
|
|
29
29
|
"@noble/hashes": "^1.8.0",
|
|
30
30
|
"http-status-codes": "^2.3.0"
|