@0xmonaco/core 0.8.8 → 0.8.10

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 (43) hide show
  1. package/dist/api/applications/api.d.ts +61 -8
  2. package/dist/api/applications/api.js +71 -7
  3. package/dist/api/auth/api.d.ts +7 -26
  4. package/dist/api/auth/api.js +6 -42
  5. package/dist/api/base.d.ts +35 -0
  6. package/dist/api/base.js +60 -0
  7. package/dist/api/delegated-agents/api.d.ts +2 -1
  8. package/dist/api/delegated-agents/api.js +4 -0
  9. package/dist/api/faucet/api.d.ts +25 -0
  10. package/dist/api/faucet/api.js +29 -0
  11. package/dist/api/faucet/index.d.ts +1 -0
  12. package/dist/api/faucet/index.js +1 -0
  13. package/dist/api/index.d.ts +4 -0
  14. package/dist/api/index.js +4 -0
  15. package/dist/api/margin-accounts/api.d.ts +3 -4
  16. package/dist/api/margin-accounts/api.js +8 -15
  17. package/dist/api/market/api.d.ts +3 -1
  18. package/dist/api/market/api.js +8 -0
  19. package/dist/api/perp/routes.d.ts +62 -4
  20. package/dist/api/perp/routes.js +27 -4
  21. package/dist/api/profile/api.d.ts +18 -1
  22. package/dist/api/profile/api.js +41 -1
  23. package/dist/api/sub-accounts/api.d.ts +62 -0
  24. package/dist/api/sub-accounts/api.js +80 -0
  25. package/dist/api/sub-accounts/index.d.ts +1 -0
  26. package/dist/api/sub-accounts/index.js +1 -0
  27. package/dist/api/trades/api.d.ts +12 -1
  28. package/dist/api/trades/api.js +13 -1
  29. package/dist/api/trading/api.d.ts +5 -2
  30. package/dist/api/trading/api.js +7 -24
  31. package/dist/api/whitelist/api.d.ts +27 -0
  32. package/dist/api/whitelist/api.js +32 -0
  33. package/dist/api/whitelist/index.d.ts +1 -0
  34. package/dist/api/whitelist/index.js +1 -0
  35. package/dist/api/withdrawals/api.d.ts +15 -0
  36. package/dist/api/withdrawals/api.js +27 -0
  37. package/dist/api/withdrawals/index.d.ts +1 -0
  38. package/dist/api/withdrawals/index.js +1 -0
  39. package/dist/coverage.d.ts +85 -0
  40. package/dist/coverage.js +85 -0
  41. package/dist/sdk.d.ts +32 -1
  42. package/dist/sdk.js +88 -0
  43. package/package.json +3 -3
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Whitelist API Implementation
3
+ *
4
+ * Public (unauthenticated) whitelist/waitlist application submission. The
5
+ * server validates and de-duplicates by wallet address and email, creating an
6
+ * inactive user pending manual approval. This is an onboarding endpoint, not a
7
+ * trading operation.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const { message, user_id } = await sdk.whitelist.submit({
12
+ * wallet_address: "0x...",
13
+ * email: "user@example.com",
14
+ * });
15
+ * ```
16
+ */
17
+ import { BaseAPI } from "../base";
18
+ import { perpRoutes } from "../perp/routes";
19
+ export class WhitelistAPIImpl extends BaseAPI {
20
+ /**
21
+ * Submits a whitelist (waitlist) application. Public — no auth required.
22
+ *
23
+ * @param body - Applicant details
24
+ * @returns Promise resolving to the status message and created user id
25
+ */
26
+ async submit(body) {
27
+ return await this.makePublicRequest(perpRoutes.whitelist.submit(), {
28
+ method: "POST",
29
+ body: JSON.stringify(body),
30
+ });
31
+ }
32
+ }
@@ -0,0 +1 @@
1
+ export { WhitelistAPIImpl } from "./api";
@@ -0,0 +1 @@
1
+ export { WhitelistAPIImpl } from "./api";
@@ -0,0 +1,15 @@
1
+ import type { InitiateWithdrawalRequest, WithdrawalResponse, WithdrawalsAPI } from "@0xmonaco/types";
2
+ import { BaseAPI } from "../base";
3
+ /**
4
+ * Low-level withdrawals client.
5
+ *
6
+ * `initiateWithdrawal` debits the caller's balance via the matching engine and
7
+ * returns the target vault address plus pre-signed `executeSignedWithdrawal`
8
+ * calldata; `getWithdrawal` re-fetches that calldata for a previously-initiated
9
+ * index. Neither submits on-chain — use the high-level vault API for the flow
10
+ * that also broadcasts the transaction.
11
+ */
12
+ export declare class WithdrawalsAPIImpl extends BaseAPI implements WithdrawalsAPI {
13
+ initiateWithdrawal(request: InitiateWithdrawalRequest): Promise<WithdrawalResponse>;
14
+ getWithdrawal(withdrawalIndex: number): Promise<WithdrawalResponse>;
15
+ }
@@ -0,0 +1,27 @@
1
+ import { BaseAPI } from "../base";
2
+ import { perpRoutes } from "../perp";
3
+ /**
4
+ * Low-level withdrawals client.
5
+ *
6
+ * `initiateWithdrawal` debits the caller's balance via the matching engine and
7
+ * returns the target vault address plus pre-signed `executeSignedWithdrawal`
8
+ * calldata; `getWithdrawal` re-fetches that calldata for a previously-initiated
9
+ * index. Neither submits on-chain — use the high-level vault API for the flow
10
+ * that also broadcasts the transaction.
11
+ */
12
+ export class WithdrawalsAPIImpl extends BaseAPI {
13
+ async initiateWithdrawal(request) {
14
+ return this.makeAuthenticatedRequest(perpRoutes.withdrawals.initiate(), {
15
+ method: "POST",
16
+ body: JSON.stringify({
17
+ asset_id: request.assetId,
18
+ amount: request.amount,
19
+ destination: request.destination,
20
+ }),
21
+ });
22
+ }
23
+ async getWithdrawal(withdrawalIndex) {
24
+ // Public lookup — no auth required.
25
+ return this.makePublicRequest(perpRoutes.withdrawals.byIndex(withdrawalIndex));
26
+ }
27
+ }
@@ -0,0 +1 @@
1
+ export * from "./api";
@@ -0,0 +1 @@
1
+ export * from "./api";
@@ -0,0 +1,85 @@
1
+ /** operationId → the @0xmonaco/core client method that covers it. */
2
+ export declare const COVERED: {
3
+ add_position_margin: string;
4
+ attach_position_tp_sl: string;
5
+ batch_cancel_all: string;
6
+ batch_cancel_all_by_pair: string;
7
+ batch_cancel_orders: string;
8
+ batch_create_orders: string;
9
+ batch_replace_orders: string;
10
+ cancel_conditional_order: string;
11
+ cancel_order: string;
12
+ close_position: string;
13
+ create_challenge: string;
14
+ create_delegated_session: string;
15
+ create_order: string;
16
+ create_sub_account_limit: string;
17
+ delete_sub_account_limit: string;
18
+ get_application_config: string;
19
+ get_application_stats: string;
20
+ get_available_collateral: string;
21
+ get_candles: string;
22
+ get_funding_state: string;
23
+ get_index_price: string;
24
+ get_margin_account_movements: string;
25
+ get_margin_account_summary: string;
26
+ get_mark_price: string;
27
+ get_market_metadata: string;
28
+ get_open_interest: string;
29
+ get_order_by_id: string;
30
+ get_orderbook_snapshot: string;
31
+ get_orders: string;
32
+ get_perp_market_config: string;
33
+ get_perp_market_summary: string;
34
+ get_portfolio_chart: string;
35
+ get_portfolio_stats: string;
36
+ get_position: string;
37
+ get_position_risk: string;
38
+ get_screener: string;
39
+ get_sub_account_limits: string;
40
+ get_trade_by_id: string;
41
+ get_trades: string;
42
+ get_trading_pair_by_id: string;
43
+ get_user_balance_by_asset: string;
44
+ get_user_balances: string;
45
+ get_user_movements: string;
46
+ get_user_profile: string;
47
+ get_user_trades: string;
48
+ get_withdrawal: string;
49
+ initiate_withdrawal: string;
50
+ list_application_balances: string;
51
+ list_application_movements: string;
52
+ list_application_orders: string;
53
+ list_application_users: string;
54
+ list_conditional_orders: string;
55
+ list_delegated_agent_owners: string;
56
+ list_delegated_agents: string;
57
+ list_funding_history: string;
58
+ list_funding_payments: string;
59
+ list_margin_accounts: string;
60
+ list_position_history: string;
61
+ list_positions: string;
62
+ list_sub_accounts_with_balances: string;
63
+ list_trading_pairs: string;
64
+ mint_tokens: string;
65
+ reduce_position_margin: string;
66
+ refresh_session: string;
67
+ replace_order: string;
68
+ revoke_delegated_agent: string;
69
+ revoke_session: string;
70
+ simulate_auto_margin_order_risk: string;
71
+ simulate_fees: string;
72
+ simulate_order_risk: string;
73
+ submit_whitelist: string;
74
+ transfer_collateral_from_margin_account: string;
75
+ transfer_collateral_to_auto_margin_account: string;
76
+ transfer_collateral_to_margin_account: string;
77
+ update_sub_account_limit: string;
78
+ upsert_delegated_agent: string;
79
+ verify_signature: string;
80
+ };
81
+ /** operationId → reason it is intentionally not covered by @0xmonaco/core. */
82
+ export declare const INTENTIONALLY_EXCLUDED: {
83
+ authenticate_backend: string;
84
+ health_check: string;
85
+ };
@@ -0,0 +1,85 @@
1
+ /** operationId → the @0xmonaco/core client method that covers it. */
2
+ export const COVERED = {
3
+ add_position_margin: "addPositionMargin",
4
+ attach_position_tp_sl: "attachPositionTpSl",
5
+ batch_cancel_all: "batchCancelAll",
6
+ batch_cancel_all_by_pair: "batchCancelAll (with tradingPairId)",
7
+ batch_cancel_orders: "batchCancel",
8
+ batch_create_orders: "batchCreate",
9
+ batch_replace_orders: "batchReplace",
10
+ cancel_conditional_order: "cancelConditionalOrder",
11
+ cancel_order: "cancelOrder",
12
+ close_position: "closePosition",
13
+ create_challenge: "createChallenge",
14
+ create_delegated_session: "createDelegatedSession",
15
+ create_order: "placeLimitOrder / placeMarketOrder",
16
+ create_sub_account_limit: "subAccounts.createLimit",
17
+ delete_sub_account_limit: "subAccounts.deleteLimit",
18
+ get_application_config: "getApplicationConfig",
19
+ get_application_stats: "getApplicationStats",
20
+ get_available_collateral: "getAvailableCollateral",
21
+ get_candles: "getCandlesticks",
22
+ get_funding_state: "getFundingState",
23
+ get_index_price: "getIndexPrice",
24
+ get_margin_account_movements: "getMarginAccountMovements",
25
+ get_margin_account_summary: "getMarginAccountSummary",
26
+ get_mark_price: "getMarkPrice",
27
+ get_market_metadata: "getMarketMetadata",
28
+ get_open_interest: "getOpenInterest",
29
+ get_order_by_id: "getOrder",
30
+ get_orderbook_snapshot: "getOrderbook",
31
+ get_orders: "getPaginatedOrders",
32
+ get_perp_market_config: "getPerpMarketConfig",
33
+ get_perp_market_summary: "getPerpMarketSummary",
34
+ get_portfolio_chart: "getPortfolioChart",
35
+ get_portfolio_stats: "getPortfolioStats",
36
+ get_position: "getPosition",
37
+ get_position_risk: "getPositionRisk",
38
+ get_screener: "getScreener",
39
+ get_sub_account_limits: "subAccounts.getLimits",
40
+ get_trade_by_id: "getTradeById",
41
+ get_trades: "getTrades",
42
+ get_trading_pair_by_id: "getTradingPair",
43
+ get_user_balance_by_asset: "getUserBalanceByAssetId",
44
+ get_user_balances: "getUserBalances",
45
+ get_user_movements: "getPaginatedUserMovements",
46
+ get_user_profile: "getProfile",
47
+ get_user_trades: "getUserTrades",
48
+ get_withdrawal: "getWithdrawal",
49
+ initiate_withdrawal: "initiateWithdrawal",
50
+ list_application_balances: "listApplicationBalances",
51
+ list_application_movements: "listApplicationMovements",
52
+ list_application_orders: "listApplicationOrders",
53
+ list_application_users: "listApplicationUsers",
54
+ list_conditional_orders: "listConditionalOrders",
55
+ list_delegated_agent_owners: "listDelegatedOwners",
56
+ list_delegated_agents: "listDelegatedAgents",
57
+ list_funding_history: "listFundingHistory",
58
+ list_funding_payments: "listFundingPayments",
59
+ list_margin_accounts: "listMarginAccounts",
60
+ list_position_history: "listPositionHistory",
61
+ list_positions: "listPositions",
62
+ list_sub_accounts_with_balances: "subAccounts.list",
63
+ list_trading_pairs: "getPaginatedTradingPairs",
64
+ mint_tokens: "faucet.mint",
65
+ reduce_position_margin: "reducePositionMargin",
66
+ refresh_session: "refreshSession",
67
+ replace_order: "replaceOrder",
68
+ revoke_delegated_agent: "revokeDelegatedAgent",
69
+ revoke_session: "revokeSession",
70
+ simulate_auto_margin_order_risk: "simulateAutoMarginOrderRisk",
71
+ simulate_fees: "simulateFees",
72
+ simulate_order_risk: "simulateOrderRisk",
73
+ submit_whitelist: "whitelist.submit",
74
+ transfer_collateral_from_margin_account: "transferCollateralFromMarginAccount",
75
+ transfer_collateral_to_auto_margin_account: "transferCollateralToAutoMarginAccount",
76
+ transfer_collateral_to_margin_account: "transferCollateralToMarginAccount",
77
+ update_sub_account_limit: "subAccounts.updateLimit",
78
+ upsert_delegated_agent: "upsertDelegatedAgent",
79
+ verify_signature: "verifySignature",
80
+ };
81
+ /** operationId → reason it is intentionally not covered by @0xmonaco/core. */
82
+ export const INTENTIONALLY_EXCLUDED = {
83
+ authenticate_backend: "Backend auth is header-based via setServerKey()/the x-server-key header, not an endpoint method (MON-1486).",
84
+ health_check: "Infrastructure liveness probe (GET /health); not part of the data SDK surface.",
85
+ };
package/dist/sdk.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ApplicationsAPI, AuthAPI, AuthState, DelegatedAgentsAPI, FeesAPI, MarginAccountsAPI, MarketAPI, MonacoSDK, Network, PositionsAPI, ProfileAPI, SDKConfig, TradingAPI, VaultAPI } from "@0xmonaco/types";
1
+ import type { ApplicationsAPI, AuthAPI, AuthState, DelegatedAgentsAPI, FaucetAPI, FeesAPI, MarginAccountsAPI, MarketAPI, MonacoSDK, Network, PositionsAPI, ProfileAPI, SDKConfig, SubAccountsAPI, TradingAPI, VaultAPI, WhitelistAPI, WithdrawalsAPI } from "@0xmonaco/types";
2
2
  import { type PublicClient, type TransactionReceipt, type WalletClient } from "viem";
3
3
  import { type MonacoWebSocket, OrderbookAPIImpl, TradesAPIImpl } from "./api";
4
4
  export declare class MonacoSDKImpl implements MonacoSDK {
@@ -7,10 +7,14 @@ export declare class MonacoSDKImpl implements MonacoSDK {
7
7
  applications: ApplicationsAPI;
8
8
  fees: FeesAPI;
9
9
  vault: VaultAPI;
10
+ withdrawals: WithdrawalsAPI;
10
11
  trading: TradingAPI;
11
12
  market: MarketAPI;
12
13
  marginAccounts: MarginAccountsAPI;
13
14
  positions: PositionsAPI;
15
+ subAccounts: SubAccountsAPI;
16
+ faucet: FaucetAPI;
17
+ whitelist: WhitelistAPI;
14
18
  profile: ProfileAPI;
15
19
  orderbook: OrderbookAPIImpl;
16
20
  trades: TradesAPIImpl;
@@ -25,6 +29,24 @@ export declare class MonacoSDKImpl implements MonacoSDK {
25
29
  * the WebSocket client.
26
30
  */
27
31
  private propagateSession;
32
+ /**
33
+ * Set (or clear) the application secret key used for backend-authenticated
34
+ * requests (those annotated `#[require_backend]` on the gateway, e.g. the
35
+ * `applications` reporting endpoints).
36
+ *
37
+ * The raw `sk_...` key is sent in the `x-server-key` header on each such
38
+ * request. This is independent of {@link login}/session auth — a client may
39
+ * hold both a session and a server key at once.
40
+ *
41
+ * @param serverKey - The application secret key (`sk_...`), or `undefined` to clear.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * sdk.setServerKey("sk_live_...");
46
+ * const orders = await sdk.applications.listApplicationOrders({ status: "FILLED" });
47
+ * ```
48
+ */
49
+ setServerKey(serverKey: string | undefined): void;
28
50
  /** Extract the session keypair from an auth state. */
29
51
  private sessionFromAuthState;
30
52
  constructor(cfg: SDKConfig);
@@ -63,6 +85,15 @@ export declare class MonacoSDKImpl implements MonacoSDK {
63
85
  login(clientId: string, options?: {
64
86
  connectWebSocket?: boolean;
65
87
  }): Promise<AuthState>;
88
+ /**
89
+ * Create and adopt an owner-scoped delegated session.
90
+ *
91
+ * This must be called while authenticated as the agent wallet. The delegated
92
+ * session uses a fresh ed25519 keypair generated locally; the current agent
93
+ * session signs the registration request, and subsequent SDK calls use the
94
+ * delegated session keypair.
95
+ */
96
+ loginAsDelegatedOwner(ownerUserId: string): Promise<AuthState>;
66
97
  /**
67
98
  * Get the current authentication state
68
99
  *
package/dist/sdk.js CHANGED
@@ -4,13 +4,18 @@ import { sei, seiTestnet } from "viem/chains";
4
4
  import { ApplicationsAPIImpl, createMonacoWebSocket, OrderbookAPIImpl, TradesAPIImpl } from "./api";
5
5
  import { AuthAPIImpl } from "./api/auth";
6
6
  import { DelegatedAgentsAPIImpl } from "./api/delegated-agents";
7
+ import { FaucetAPIImpl } from "./api/faucet";
7
8
  import { FeesAPIImpl } from "./api/fees";
8
9
  import { MarginAccountsAPIImpl } from "./api/margin-accounts";
9
10
  import { MarketAPIImpl } from "./api/market";
10
11
  import { PositionsAPIImpl } from "./api/positions";
11
12
  import { ProfileAPIImpl } from "./api/profile";
13
+ import { SubAccountsAPIImpl } from "./api/sub-accounts";
12
14
  import { TradingAPIImpl } from "./api/trading";
13
15
  import { VaultAPIImpl } from "./api/vault";
16
+ import { WhitelistAPIImpl } from "./api/whitelist";
17
+ import { WithdrawalsAPIImpl } from "./api/withdrawals";
18
+ import { generateSessionKeypair, privateKeyHex, publicKeyHex } from "./crypto/session";
14
19
  import { APIError, InvalidConfigError, InvalidStateError } from "./errors";
15
20
  import { resolveApiUrl, resolveWsUrl } from "./networks";
16
21
  /** Validate a user-supplied URL override, returning it unchanged when valid. */
@@ -29,10 +34,14 @@ export class MonacoSDKImpl {
29
34
  applications;
30
35
  fees;
31
36
  vault;
37
+ withdrawals;
32
38
  trading;
33
39
  market;
34
40
  marginAccounts;
35
41
  positions;
42
+ subAccounts;
43
+ faucet;
44
+ whitelist;
36
45
  profile;
37
46
  orderbook;
38
47
  trades;
@@ -52,15 +61,54 @@ export class MonacoSDKImpl {
52
61
  this.applications.setSessionKeypair(credentials);
53
62
  this.fees.setSessionKeypair(credentials);
54
63
  this.vault.setSessionKeypair(credentials);
64
+ this.withdrawals.setSessionKeypair(credentials);
55
65
  this.trading.setSessionKeypair(credentials);
56
66
  this.market.setSessionKeypair(credentials);
57
67
  this.marginAccounts.setSessionKeypair(credentials);
58
68
  this.positions.setSessionKeypair(credentials);
69
+ this.subAccounts.setSessionKeypair(credentials);
70
+ this.faucet.setSessionKeypair(credentials);
71
+ this.whitelist.setSessionKeypair(credentials);
59
72
  this.profile.setSessionKeypair(credentials);
60
73
  this.orderbook.setSessionKeypair(credentials);
61
74
  this.trades.setSessionKeypair(credentials);
62
75
  this.ws.setSessionKeypair(credentials);
63
76
  }
77
+ /**
78
+ * Set (or clear) the application secret key used for backend-authenticated
79
+ * requests (those annotated `#[require_backend]` on the gateway, e.g. the
80
+ * `applications` reporting endpoints).
81
+ *
82
+ * The raw `sk_...` key is sent in the `x-server-key` header on each such
83
+ * request. This is independent of {@link login}/session auth — a client may
84
+ * hold both a session and a server key at once.
85
+ *
86
+ * @param serverKey - The application secret key (`sk_...`), or `undefined` to clear.
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * sdk.setServerKey("sk_live_...");
91
+ * const orders = await sdk.applications.listApplicationOrders({ status: "FILLED" });
92
+ * ```
93
+ */
94
+ setServerKey(serverKey) {
95
+ this.auth.setServerKey(serverKey);
96
+ this.delegatedAgents.setServerKey(serverKey);
97
+ this.applications.setServerKey(serverKey);
98
+ this.fees.setServerKey(serverKey);
99
+ this.vault.setServerKey(serverKey);
100
+ this.withdrawals.setServerKey(serverKey);
101
+ this.trading.setServerKey(serverKey);
102
+ this.market.setServerKey(serverKey);
103
+ this.marginAccounts.setServerKey(serverKey);
104
+ this.positions.setServerKey(serverKey);
105
+ this.subAccounts.setServerKey(serverKey);
106
+ this.faucet.setServerKey(serverKey);
107
+ this.whitelist.setServerKey(serverKey);
108
+ this.profile.setServerKey(serverKey);
109
+ this.orderbook.setServerKey(serverKey);
110
+ this.trades.setServerKey(serverKey);
111
+ }
64
112
  /** Extract the session keypair from an auth state. */
65
113
  sessionFromAuthState(authState) {
66
114
  return {
@@ -110,11 +158,15 @@ export class MonacoSDKImpl {
110
158
  this.market = new MarketAPIImpl(apiUrl);
111
159
  this.marginAccounts = new MarginAccountsAPIImpl(apiUrl);
112
160
  this.positions = new PositionsAPIImpl(apiUrl);
161
+ this.subAccounts = new SubAccountsAPIImpl(apiUrl);
162
+ this.faucet = new FaucetAPIImpl(apiUrl);
163
+ this.whitelist = new WhitelistAPIImpl(apiUrl);
113
164
  this.auth = new AuthAPIImpl(this.walletClient, this.chain, apiUrl);
114
165
  this.delegatedAgents = new DelegatedAgentsAPIImpl(apiUrl);
115
166
  this.fees = new FeesAPIImpl(apiUrl);
116
167
  this.profile = new ProfileAPIImpl(apiUrl);
117
168
  this.vault = new VaultAPIImpl(this.publicClient, this.walletClient, this.chain, this.applications, this.profile, apiUrl);
169
+ this.withdrawals = new WithdrawalsAPIImpl(apiUrl);
118
170
  this.trading = new TradingAPIImpl(apiUrl);
119
171
  this.orderbook = new OrderbookAPIImpl(apiUrl);
120
172
  this.trades = new TradesAPIImpl(apiUrl);
@@ -163,6 +215,42 @@ export class MonacoSDKImpl {
163
215
  }
164
216
  return this.authState;
165
217
  }
218
+ /**
219
+ * Create and adopt an owner-scoped delegated session.
220
+ *
221
+ * This must be called while authenticated as the agent wallet. The delegated
222
+ * session uses a fresh ed25519 keypair generated locally; the current agent
223
+ * session signs the registration request, and subsequent SDK calls use the
224
+ * delegated session keypair.
225
+ */
226
+ async loginAsDelegatedOwner(ownerUserId) {
227
+ if (!this.authState) {
228
+ throw new APIError("No active agent session to create delegated session", {
229
+ endpoint: "delegated-agents/sessions",
230
+ statusCode: StatusCodes.UNAUTHORIZED,
231
+ });
232
+ }
233
+ const keypair = generateSessionKeypair();
234
+ const session = {
235
+ publicKey: publicKeyHex(keypair),
236
+ privateKey: privateKeyHex(keypair),
237
+ };
238
+ const delegatedSession = await this.delegatedAgents.createDelegatedSession({
239
+ ownerUserId,
240
+ sessionPublicKey: session.publicKey,
241
+ });
242
+ this.authState = {
243
+ sessionPublicKey: session.publicKey,
244
+ sessionPrivateKey: session.privateKey,
245
+ expiresAt: delegatedSession.expires_at,
246
+ user: {
247
+ id: delegatedSession.owner_user_id,
248
+ address: delegatedSession.agent_address,
249
+ },
250
+ };
251
+ this.propagateSession(this.sessionFromAuthState(this.authState));
252
+ return this.authState;
253
+ }
166
254
  /**
167
255
  * Get the current authentication state
168
256
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmonaco/core",
3
- "version": "0.8.8",
3
+ "version": "0.8.10",
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.8",
27
- "@0xmonaco/types": "0.8.8",
26
+ "@0xmonaco/contracts": "0.8.10",
27
+ "@0xmonaco/types": "0.8.10",
28
28
  "@noble/curves": "^1.9.1",
29
29
  "@noble/hashes": "^1.8.0",
30
30
  "http-status-codes": "^2.3.0"