@layr-labs/ecloud-sdk 0.2.1-dev → 0.3.0-dev

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.
@@ -1,3 +1,3 @@
1
- export { A as AppModule, j as AppModuleConfig, C as ComputeModule, d as ComputeModuleConfig, i as createAppModule, b as createComputeModule, e as encodeStartAppData, f as encodeStopAppData, h as encodeTerminateAppData } from './compute-CC0R7HEu.cjs';
1
+ export { A as AppModule, j as AppModuleConfig, C as ComputeModule, d as ComputeModuleConfig, i as createAppModule, b as createComputeModule, e as encodeStartAppData, f as encodeStopAppData, h as encodeTerminateAppData } from './compute-Dstl0CA0.cjs';
2
2
  import 'viem';
3
- import './index-D5oW73Dx.cjs';
3
+ import './index-C0w92tCs.cjs';
package/dist/compute.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { A as AppModule, j as AppModuleConfig, C as ComputeModule, d as ComputeModuleConfig, i as createAppModule, b as createComputeModule, e as encodeStartAppData, f as encodeStopAppData, h as encodeTerminateAppData } from './compute-B85ikS78.js';
1
+ export { A as AppModule, j as AppModuleConfig, C as ComputeModule, d as ComputeModuleConfig, i as createAppModule, b as createComputeModule, e as encodeStartAppData, f as encodeStopAppData, h as encodeTerminateAppData } from './compute-CdZxISln.js';
2
2
  import 'viem';
3
- import './index-D5oW73Dx.js';
3
+ import './index-C0w92tCs.js';
package/dist/compute.js CHANGED
@@ -1,3 +1,133 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __esm = (fn, res) => function __init() {
3
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
4
+ };
5
+
6
+ // src/client/common/auth/session.ts
7
+ function stripHexPrefix2(hex) {
8
+ return hex.startsWith("0x") ? hex.slice(2) : hex;
9
+ }
10
+ async function parseErrorResponse(response) {
11
+ try {
12
+ const data = await response.json();
13
+ return data.error || response.statusText;
14
+ } catch {
15
+ return response.statusText;
16
+ }
17
+ }
18
+ async function loginToComputeApi(config, request) {
19
+ let response;
20
+ try {
21
+ response = await fetch(`${config.baseUrl}/auth/siwe/login`, {
22
+ method: "POST",
23
+ credentials: "include",
24
+ // Include cookies for session management
25
+ headers: {
26
+ "Content-Type": "application/json"
27
+ },
28
+ body: JSON.stringify({
29
+ message: request.message,
30
+ signature: stripHexPrefix2(request.signature)
31
+ })
32
+ });
33
+ } catch (error) {
34
+ throw new SessionError(
35
+ `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
36
+ "NETWORK_ERROR"
37
+ );
38
+ }
39
+ if (!response.ok) {
40
+ const errorMessage = await parseErrorResponse(response);
41
+ const status = response.status;
42
+ if (status === 400) {
43
+ if (errorMessage.toLowerCase().includes("siwe")) {
44
+ throw new SessionError(`Invalid SIWE message: ${errorMessage}`, "INVALID_MESSAGE", status);
45
+ }
46
+ throw new SessionError(`Bad request: ${errorMessage}`, "INVALID_MESSAGE", status);
47
+ }
48
+ if (status === 401) {
49
+ throw new SessionError(`Invalid signature: ${errorMessage}`, "INVALID_SIGNATURE", status);
50
+ }
51
+ throw new SessionError(`Login failed: ${errorMessage}`, "UNKNOWN", status);
52
+ }
53
+ const data = await response.json();
54
+ return {
55
+ success: data.success,
56
+ address: data.address
57
+ };
58
+ }
59
+ async function getComputeApiSession(config) {
60
+ let response;
61
+ try {
62
+ response = await fetch(`${config.baseUrl}/auth/session`, {
63
+ method: "GET",
64
+ credentials: "include",
65
+ // Include cookies for session management
66
+ headers: {
67
+ "Content-Type": "application/json"
68
+ }
69
+ });
70
+ } catch {
71
+ return {
72
+ authenticated: false
73
+ };
74
+ }
75
+ if (response.status === 401) {
76
+ return {
77
+ authenticated: false
78
+ };
79
+ }
80
+ if (!response.ok) {
81
+ const errorMessage = await parseErrorResponse(response);
82
+ throw new SessionError(`Failed to get session: ${errorMessage}`, "UNKNOWN", response.status);
83
+ }
84
+ const data = await response.json();
85
+ return {
86
+ authenticated: data.authenticated,
87
+ address: data.address,
88
+ chainId: data.chain_id
89
+ };
90
+ }
91
+ async function logoutFromComputeApi(config) {
92
+ let response;
93
+ try {
94
+ response = await fetch(`${config.baseUrl}/auth/logout`, {
95
+ method: "POST",
96
+ credentials: "include",
97
+ // Include cookies for session management
98
+ headers: {
99
+ "Content-Type": "application/json"
100
+ }
101
+ });
102
+ } catch (error) {
103
+ throw new SessionError(
104
+ `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
105
+ "NETWORK_ERROR"
106
+ );
107
+ }
108
+ if (response.status === 401) {
109
+ return;
110
+ }
111
+ if (!response.ok) {
112
+ const errorMessage = await parseErrorResponse(response);
113
+ throw new SessionError(`Logout failed: ${errorMessage}`, "UNKNOWN", response.status);
114
+ }
115
+ }
116
+ var SessionError;
117
+ var init_session = __esm({
118
+ "src/client/common/auth/session.ts"() {
119
+ "use strict";
120
+ SessionError = class extends Error {
121
+ constructor(message, code, statusCode) {
122
+ super(message);
123
+ this.code = code;
124
+ this.statusCode = statusCode;
125
+ this.name = "SessionError";
126
+ }
127
+ };
128
+ }
129
+ });
130
+
1
131
  // src/client/modules/compute/app/index.ts
2
132
  import { parseAbi as parseAbi2, encodeFunctionData as encodeFunctionData3 } from "viem";
3
133
 
@@ -1101,6 +1231,18 @@ function extractRegistryNameNoDocker(imageRef) {
1101
1231
  // src/client/common/contract/eip7702.ts
1102
1232
  import { encodeFunctionData, encodeAbiParameters, decodeErrorResult } from "viem";
1103
1233
 
1234
+ // src/client/common/types/index.ts
1235
+ var noopLogger = {
1236
+ debug: () => {
1237
+ },
1238
+ info: () => {
1239
+ },
1240
+ warn: () => {
1241
+ },
1242
+ error: () => {
1243
+ }
1244
+ };
1245
+
1104
1246
  // src/client/common/abis/ERC7702Delegator.json
1105
1247
  var ERC7702Delegator_default = [
1106
1248
  {
@@ -2186,7 +2328,7 @@ async function checkERC7702Delegation(publicClient, account, delegatorAddress) {
2186
2328
  const expectedCode = `0xef0100${delegatorAddress.slice(2)}`;
2187
2329
  return code.toLowerCase() === expectedCode.toLowerCase();
2188
2330
  }
2189
- async function executeBatch(options, logger) {
2331
+ async function executeBatch(options, logger = noopLogger) {
2190
2332
  const { walletClient, publicClient, environmentConfig, executions, pendingMessage, gas } = options;
2191
2333
  const account = walletClient.account;
2192
2334
  if (!account) {
@@ -2270,11 +2412,7 @@ async function executeBatch(options, logger) {
2270
2412
  }
2271
2413
 
2272
2414
  // src/client/common/contract/caller.ts
2273
- import {
2274
- encodeFunctionData as encodeFunctionData2,
2275
- decodeErrorResult as decodeErrorResult2,
2276
- bytesToHex
2277
- } from "viem";
2415
+ import { encodeFunctionData as encodeFunctionData2, decodeErrorResult as decodeErrorResult2, bytesToHex } from "viem";
2278
2416
 
2279
2417
  // src/client/common/utils/helpers.ts
2280
2418
  import { extractChain, createPublicClient, createWalletClient, http } from "viem";
@@ -3858,7 +3996,7 @@ async function calculateAppID(options) {
3858
3996
  });
3859
3997
  return appID;
3860
3998
  }
3861
- async function prepareDeployBatch(options, logger) {
3999
+ async function prepareDeployBatch(options, logger = noopLogger) {
3862
4000
  const { walletClient, publicClient, environmentConfig, salt, release, publicLogs } = options;
3863
4001
  const account = walletClient.account;
3864
4002
  if (!account) {
@@ -3938,7 +4076,7 @@ async function prepareDeployBatch(options, logger) {
3938
4076
  environmentConfig
3939
4077
  };
3940
4078
  }
3941
- async function executeDeployBatch(data, context, gas, logger) {
4079
+ async function executeDeployBatch(data, context, gas, logger = noopLogger) {
3942
4080
  const pendingMessage = "Deploying new app...";
3943
4081
  const txHash = await executeBatch(
3944
4082
  {
@@ -3953,7 +4091,7 @@ async function executeDeployBatch(data, context, gas, logger) {
3953
4091
  );
3954
4092
  return { appId: data.appId, txHash };
3955
4093
  }
3956
- async function deployApp(options, logger) {
4094
+ async function deployApp(options, logger = noopLogger) {
3957
4095
  const prepared = await prepareDeployBatch(options, logger);
3958
4096
  const data = {
3959
4097
  appId: prepared.appId,
@@ -3968,7 +4106,15 @@ async function deployApp(options, logger) {
3968
4106
  return executeDeployBatch(data, context, options.gas, logger);
3969
4107
  }
3970
4108
  async function prepareUpgradeBatch(options) {
3971
- const { walletClient, publicClient, environmentConfig, appID, release, publicLogs, needsPermissionChange } = options;
4109
+ const {
4110
+ walletClient,
4111
+ publicClient,
4112
+ environmentConfig,
4113
+ appID,
4114
+ release,
4115
+ publicLogs,
4116
+ needsPermissionChange
4117
+ } = options;
3972
4118
  const releaseForViem = {
3973
4119
  rmsRelease: {
3974
4120
  artifacts: release.rmsRelease.artifacts.map((artifact) => ({
@@ -4041,7 +4187,7 @@ async function prepareUpgradeBatch(options) {
4041
4187
  environmentConfig
4042
4188
  };
4043
4189
  }
4044
- async function executeUpgradeBatch(data, context, gas, logger) {
4190
+ async function executeUpgradeBatch(data, context, gas, logger = noopLogger) {
4045
4191
  const pendingMessage = `Upgrading app ${data.appId}...`;
4046
4192
  const txHash = await executeBatch(
4047
4193
  {
@@ -4056,7 +4202,7 @@ async function executeUpgradeBatch(data, context, gas, logger) {
4056
4202
  );
4057
4203
  return txHash;
4058
4204
  }
4059
- async function upgradeApp(options, logger) {
4205
+ async function upgradeApp(options, logger = noopLogger) {
4060
4206
  const prepared = await prepareUpgradeBatch(options);
4061
4207
  const data = {
4062
4208
  appId: prepared.appId,
@@ -4069,8 +4215,18 @@ async function upgradeApp(options, logger) {
4069
4215
  };
4070
4216
  return executeUpgradeBatch(data, context, options.gas, logger);
4071
4217
  }
4072
- async function sendAndWaitForTransaction(options, logger) {
4073
- const { walletClient, publicClient, environmentConfig, to, data, value = 0n, pendingMessage, txDescription, gas } = options;
4218
+ async function sendAndWaitForTransaction(options, logger = noopLogger) {
4219
+ const {
4220
+ walletClient,
4221
+ publicClient,
4222
+ environmentConfig,
4223
+ to,
4224
+ data,
4225
+ value = 0n,
4226
+ pendingMessage,
4227
+ txDescription,
4228
+ gas
4229
+ } = options;
4074
4230
  const account = walletClient.account;
4075
4231
  if (!account) {
4076
4232
  throw new Error("WalletClient must have an account attached");
@@ -4181,7 +4337,7 @@ async function isDelegated(options) {
4181
4337
  environmentConfig.erc7702DelegatorAddress
4182
4338
  );
4183
4339
  }
4184
- async function undelegate(options, logger) {
4340
+ async function undelegate(options, logger = noopLogger) {
4185
4341
  const { walletClient, publicClient, environmentConfig } = options;
4186
4342
  const account = walletClient.account;
4187
4343
  if (!account) {
@@ -4249,6 +4405,7 @@ async function calculatePermissionSignature(options) {
4249
4405
  }
4250
4406
 
4251
4407
  // src/client/common/utils/userapi.ts
4408
+ init_session();
4252
4409
  function isJsonObject(value) {
4253
4410
  return typeof value === "object" && value !== null && !Array.isArray(value);
4254
4411
  }
@@ -4265,15 +4422,16 @@ var CanViewAppLogsPermission = "0x2fd3f2fe";
4265
4422
  var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
4266
4423
  var CanUpdateAppProfilePermission = "0x036fef61";
4267
4424
  function getDefaultClientId() {
4268
- const version = true ? "0.2.1-dev" : "0.0.0";
4425
+ const version = true ? "0.3.0-dev" : "0.0.0";
4269
4426
  return `ecloud-sdk/v${version}`;
4270
4427
  }
4271
4428
  var UserApiClient = class {
4272
- constructor(config, walletClient, publicClient, clientId) {
4429
+ constructor(config, walletClient, publicClient, options) {
4273
4430
  this.config = config;
4274
4431
  this.walletClient = walletClient;
4275
4432
  this.publicClient = publicClient;
4276
- this.clientId = clientId || getDefaultClientId();
4433
+ this.clientId = options?.clientId || getDefaultClientId();
4434
+ this.useSession = options?.useSession ?? false;
4277
4435
  }
4278
4436
  /**
4279
4437
  * Get the address of the connected wallet
@@ -4361,7 +4519,7 @@ var UserApiClient = class {
4361
4519
  const apps = result.apps || result.Apps || [];
4362
4520
  return apps.map((app, i) => ({
4363
4521
  address: app.address || appIDs[i],
4364
- status: app.status || app.Status || ""
4522
+ status: app.app_status || app.App_Status || ""
4365
4523
  }));
4366
4524
  }
4367
4525
  /**
@@ -4393,9 +4551,11 @@ var UserApiClient = class {
4393
4551
  const headers = {
4394
4552
  "x-client-id": this.clientId
4395
4553
  };
4396
- const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
4397
- const authHeaders = await this.generateAuthHeaders(CanUpdateAppProfilePermission, expiry);
4398
- Object.assign(headers, authHeaders);
4554
+ if (!this.useSession) {
4555
+ const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
4556
+ const authHeaders = await this.generateAuthHeaders(CanUpdateAppProfilePermission, expiry);
4557
+ Object.assign(headers, authHeaders);
4558
+ }
4399
4559
  try {
4400
4560
  const response = await axios.post(endpoint, formData, {
4401
4561
  headers,
@@ -4404,8 +4564,10 @@ var UserApiClient = class {
4404
4564
  // Don't throw on any status
4405
4565
  maxContentLength: Infinity,
4406
4566
  // Allow large file uploads
4407
- maxBodyLength: Infinity
4567
+ maxBodyLength: Infinity,
4408
4568
  // Allow large file uploads
4569
+ withCredentials: true
4570
+ // Include cookies for session auth
4409
4571
  });
4410
4572
  const status = response.status;
4411
4573
  if (status !== 200 && status !== 201) {
@@ -4439,7 +4601,7 @@ Please check:
4439
4601
  const headers = {
4440
4602
  "x-client-id": this.clientId
4441
4603
  };
4442
- if (permission) {
4604
+ if (permission && !this.useSession) {
4443
4605
  const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
4444
4606
  const authHeaders = await this.generateAuthHeaders(permission, expiry);
4445
4607
  Object.assign(headers, authHeaders);
@@ -4448,8 +4610,10 @@ Please check:
4448
4610
  const response = await axios.get(url, {
4449
4611
  headers,
4450
4612
  maxRedirects: 0,
4451
- validateStatus: () => true
4613
+ validateStatus: () => true,
4452
4614
  // Don't throw on any status
4615
+ withCredentials: true
4616
+ // Include cookies for session auth
4453
4617
  });
4454
4618
  const status = response.status;
4455
4619
  const statusText = status >= 200 && status < 300 ? "OK" : "Error";
@@ -4491,6 +4655,65 @@ Please check:
4491
4655
  "X-eigenx-expiry": expiry.toString()
4492
4656
  };
4493
4657
  }
4658
+ // ==========================================================================
4659
+ // SIWE Session Management
4660
+ // ==========================================================================
4661
+ /**
4662
+ * Login to the compute API using SIWE (Sign-In with Ethereum)
4663
+ *
4664
+ * This establishes a session with the compute API by verifying the SIWE message
4665
+ * and signature. On success, a session cookie is set in the browser.
4666
+ *
4667
+ * @param request - Login request containing SIWE message and signature
4668
+ * @returns Login result with the authenticated address
4669
+ *
4670
+ * @example
4671
+ * ```typescript
4672
+ * import { createSiweMessage } from "@layr-labs/ecloud-sdk/browser";
4673
+ *
4674
+ * const { message } = createSiweMessage({
4675
+ * address: userAddress,
4676
+ * chainId: 11155111,
4677
+ * domain: window.location.host,
4678
+ * uri: window.location.origin,
4679
+ * });
4680
+ *
4681
+ * const signature = await signMessageAsync({ message });
4682
+ * const result = await client.siweLogin({ message, signature });
4683
+ * ```
4684
+ */
4685
+ async siweLogin(request) {
4686
+ return loginToComputeApi({ baseUrl: this.config.userApiServerURL }, request);
4687
+ }
4688
+ /**
4689
+ * Logout from the compute API
4690
+ *
4691
+ * This destroys the current session and clears the session cookie.
4692
+ *
4693
+ * @example
4694
+ * ```typescript
4695
+ * await client.siweLogout();
4696
+ * ```
4697
+ */
4698
+ async siweLogout() {
4699
+ return logoutFromComputeApi({ baseUrl: this.config.userApiServerURL });
4700
+ }
4701
+ /**
4702
+ * Get the current SIWE session status from the compute API
4703
+ *
4704
+ * @returns Session information including authentication status and address
4705
+ *
4706
+ * @example
4707
+ * ```typescript
4708
+ * const session = await client.getSiweSession();
4709
+ * if (session.authenticated) {
4710
+ * console.log(`Logged in as ${session.address}`);
4711
+ * }
4712
+ * ```
4713
+ */
4714
+ async getSiweSession() {
4715
+ return getComputeApiSession({ baseUrl: this.config.userApiServerURL });
4716
+ }
4494
4717
  };
4495
4718
  function transformAppReleaseBuild(raw) {
4496
4719
  if (!isJsonObject(raw)) return void 0;
@@ -6338,7 +6561,7 @@ async function logs(options, walletClient, publicClient, environmentConfig, logg
6338
6561
  environmentConfig,
6339
6562
  walletClient,
6340
6563
  publicClient,
6341
- options.clientId
6564
+ options.clientId ? { clientId: options.clientId } : void 0
6342
6565
  );
6343
6566
  let logsText;
6344
6567
  let logsError = null;
@@ -6637,7 +6860,7 @@ function createAppModule(ctx) {
6637
6860
  environment,
6638
6861
  walletClient,
6639
6862
  publicClient,
6640
- ctx.clientId
6863
+ ctx.clientId ? { clientId: ctx.clientId } : void 0
6641
6864
  );
6642
6865
  return userApiClient.uploadAppProfile(appId, profile.name, {
6643
6866
  website: profile.website,