@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,5 +1,5 @@
1
1
  import { Address, WalletClient, PublicClient, Hex } from 'viem';
2
- import { z as Logger, w as EnvironmentConfig, D as DeployAppOpts, A as AppId, U as UpgradeAppOpts, P as PrepareDeployOpts, r as PreparedDeploy, G as GasEstimate, j as PrepareDeployFromVerifiableBuildOpts, n as ExecuteDeployResult, i as PrepareUpgradeOpts, s as PreparedUpgrade, k as PrepareUpgradeFromVerifiableBuildOpts, o as ExecuteUpgradeResult, C as AppProfile, F as AppProfileResponse, L as LifecycleOpts } from './index-D5oW73Dx.js';
2
+ import { ab as Logger, a6 as EnvironmentConfig, N as DeployAppOpts, A as AppId, O as UpgradeAppOpts, Q as PrepareDeployOpts, $ as PreparedDeploy, G as GasEstimate, T as PrepareDeployFromVerifiableBuildOpts, X as ExecuteDeployResult, R as PrepareUpgradeOpts, a0 as PreparedUpgrade, V as PrepareUpgradeFromVerifiableBuildOpts, Y as ExecuteUpgradeResult, ac as AppProfile, ad as AppProfileResponse, a1 as LifecycleOpts } from './index-C0w92tCs.js';
3
3
 
4
4
  /**
5
5
  * Create command
@@ -1,5 +1,5 @@
1
1
  import { Address, WalletClient, PublicClient, Hex } from 'viem';
2
- import { z as Logger, w as EnvironmentConfig, D as DeployAppOpts, A as AppId, U as UpgradeAppOpts, P as PrepareDeployOpts, r as PreparedDeploy, G as GasEstimate, j as PrepareDeployFromVerifiableBuildOpts, n as ExecuteDeployResult, i as PrepareUpgradeOpts, s as PreparedUpgrade, k as PrepareUpgradeFromVerifiableBuildOpts, o as ExecuteUpgradeResult, C as AppProfile, F as AppProfileResponse, L as LifecycleOpts } from './index-D5oW73Dx.cjs';
2
+ import { ab as Logger, a6 as EnvironmentConfig, N as DeployAppOpts, A as AppId, O as UpgradeAppOpts, Q as PrepareDeployOpts, $ as PreparedDeploy, G as GasEstimate, T as PrepareDeployFromVerifiableBuildOpts, X as ExecuteDeployResult, R as PrepareUpgradeOpts, a0 as PreparedUpgrade, V as PrepareUpgradeFromVerifiableBuildOpts, Y as ExecuteUpgradeResult, ac as AppProfile, ad as AppProfileResponse, a1 as LifecycleOpts } from './index-C0w92tCs.cjs';
3
3
 
4
4
  /**
5
5
  * Create command
package/dist/compute.cjs CHANGED
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
8
11
  var __export = (target, all) => {
9
12
  for (var name in all)
10
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -27,6 +30,131 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
30
  ));
28
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
32
 
33
+ // src/client/common/auth/session.ts
34
+ function stripHexPrefix2(hex) {
35
+ return hex.startsWith("0x") ? hex.slice(2) : hex;
36
+ }
37
+ async function parseErrorResponse(response) {
38
+ try {
39
+ const data = await response.json();
40
+ return data.error || response.statusText;
41
+ } catch {
42
+ return response.statusText;
43
+ }
44
+ }
45
+ async function loginToComputeApi(config, request) {
46
+ let response;
47
+ try {
48
+ response = await fetch(`${config.baseUrl}/auth/siwe/login`, {
49
+ method: "POST",
50
+ credentials: "include",
51
+ // Include cookies for session management
52
+ headers: {
53
+ "Content-Type": "application/json"
54
+ },
55
+ body: JSON.stringify({
56
+ message: request.message,
57
+ signature: stripHexPrefix2(request.signature)
58
+ })
59
+ });
60
+ } catch (error) {
61
+ throw new SessionError(
62
+ `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
63
+ "NETWORK_ERROR"
64
+ );
65
+ }
66
+ if (!response.ok) {
67
+ const errorMessage = await parseErrorResponse(response);
68
+ const status = response.status;
69
+ if (status === 400) {
70
+ if (errorMessage.toLowerCase().includes("siwe")) {
71
+ throw new SessionError(`Invalid SIWE message: ${errorMessage}`, "INVALID_MESSAGE", status);
72
+ }
73
+ throw new SessionError(`Bad request: ${errorMessage}`, "INVALID_MESSAGE", status);
74
+ }
75
+ if (status === 401) {
76
+ throw new SessionError(`Invalid signature: ${errorMessage}`, "INVALID_SIGNATURE", status);
77
+ }
78
+ throw new SessionError(`Login failed: ${errorMessage}`, "UNKNOWN", status);
79
+ }
80
+ const data = await response.json();
81
+ return {
82
+ success: data.success,
83
+ address: data.address
84
+ };
85
+ }
86
+ async function getComputeApiSession(config) {
87
+ let response;
88
+ try {
89
+ response = await fetch(`${config.baseUrl}/auth/session`, {
90
+ method: "GET",
91
+ credentials: "include",
92
+ // Include cookies for session management
93
+ headers: {
94
+ "Content-Type": "application/json"
95
+ }
96
+ });
97
+ } catch {
98
+ return {
99
+ authenticated: false
100
+ };
101
+ }
102
+ if (response.status === 401) {
103
+ return {
104
+ authenticated: false
105
+ };
106
+ }
107
+ if (!response.ok) {
108
+ const errorMessage = await parseErrorResponse(response);
109
+ throw new SessionError(`Failed to get session: ${errorMessage}`, "UNKNOWN", response.status);
110
+ }
111
+ const data = await response.json();
112
+ return {
113
+ authenticated: data.authenticated,
114
+ address: data.address,
115
+ chainId: data.chain_id
116
+ };
117
+ }
118
+ async function logoutFromComputeApi(config) {
119
+ let response;
120
+ try {
121
+ response = await fetch(`${config.baseUrl}/auth/logout`, {
122
+ method: "POST",
123
+ credentials: "include",
124
+ // Include cookies for session management
125
+ headers: {
126
+ "Content-Type": "application/json"
127
+ }
128
+ });
129
+ } catch (error) {
130
+ throw new SessionError(
131
+ `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
132
+ "NETWORK_ERROR"
133
+ );
134
+ }
135
+ if (response.status === 401) {
136
+ return;
137
+ }
138
+ if (!response.ok) {
139
+ const errorMessage = await parseErrorResponse(response);
140
+ throw new SessionError(`Logout failed: ${errorMessage}`, "UNKNOWN", response.status);
141
+ }
142
+ }
143
+ var SessionError;
144
+ var init_session = __esm({
145
+ "src/client/common/auth/session.ts"() {
146
+ "use strict";
147
+ SessionError = class extends Error {
148
+ constructor(message, code, statusCode) {
149
+ super(message);
150
+ this.code = code;
151
+ this.statusCode = statusCode;
152
+ this.name = "SessionError";
153
+ }
154
+ };
155
+ }
156
+ });
157
+
30
158
  // src/compute.ts
31
159
  var compute_exports = {};
32
160
  __export(compute_exports, {
@@ -1142,6 +1270,18 @@ function extractRegistryNameNoDocker(imageRef) {
1142
1270
  // src/client/common/contract/eip7702.ts
1143
1271
  var import_viem = require("viem");
1144
1272
 
1273
+ // src/client/common/types/index.ts
1274
+ var noopLogger = {
1275
+ debug: () => {
1276
+ },
1277
+ info: () => {
1278
+ },
1279
+ warn: () => {
1280
+ },
1281
+ error: () => {
1282
+ }
1283
+ };
1284
+
1145
1285
  // src/client/common/abis/ERC7702Delegator.json
1146
1286
  var ERC7702Delegator_default = [
1147
1287
  {
@@ -2227,7 +2367,7 @@ async function checkERC7702Delegation(publicClient, account, delegatorAddress) {
2227
2367
  const expectedCode = `0xef0100${delegatorAddress.slice(2)}`;
2228
2368
  return code.toLowerCase() === expectedCode.toLowerCase();
2229
2369
  }
2230
- async function executeBatch(options, logger) {
2370
+ async function executeBatch(options, logger = noopLogger) {
2231
2371
  const { walletClient, publicClient, environmentConfig, executions, pendingMessage, gas } = options;
2232
2372
  const account = walletClient.account;
2233
2373
  if (!account) {
@@ -3895,7 +4035,7 @@ async function calculateAppID(options) {
3895
4035
  });
3896
4036
  return appID;
3897
4037
  }
3898
- async function prepareDeployBatch(options, logger) {
4038
+ async function prepareDeployBatch(options, logger = noopLogger) {
3899
4039
  const { walletClient, publicClient, environmentConfig, salt, release, publicLogs } = options;
3900
4040
  const account = walletClient.account;
3901
4041
  if (!account) {
@@ -3975,7 +4115,7 @@ async function prepareDeployBatch(options, logger) {
3975
4115
  environmentConfig
3976
4116
  };
3977
4117
  }
3978
- async function executeDeployBatch(data, context, gas, logger) {
4118
+ async function executeDeployBatch(data, context, gas, logger = noopLogger) {
3979
4119
  const pendingMessage = "Deploying new app...";
3980
4120
  const txHash = await executeBatch(
3981
4121
  {
@@ -3990,7 +4130,7 @@ async function executeDeployBatch(data, context, gas, logger) {
3990
4130
  );
3991
4131
  return { appId: data.appId, txHash };
3992
4132
  }
3993
- async function deployApp(options, logger) {
4133
+ async function deployApp(options, logger = noopLogger) {
3994
4134
  const prepared = await prepareDeployBatch(options, logger);
3995
4135
  const data = {
3996
4136
  appId: prepared.appId,
@@ -4005,7 +4145,15 @@ async function deployApp(options, logger) {
4005
4145
  return executeDeployBatch(data, context, options.gas, logger);
4006
4146
  }
4007
4147
  async function prepareUpgradeBatch(options) {
4008
- const { walletClient, publicClient, environmentConfig, appID, release, publicLogs, needsPermissionChange } = options;
4148
+ const {
4149
+ walletClient,
4150
+ publicClient,
4151
+ environmentConfig,
4152
+ appID,
4153
+ release,
4154
+ publicLogs,
4155
+ needsPermissionChange
4156
+ } = options;
4009
4157
  const releaseForViem = {
4010
4158
  rmsRelease: {
4011
4159
  artifacts: release.rmsRelease.artifacts.map((artifact) => ({
@@ -4078,7 +4226,7 @@ async function prepareUpgradeBatch(options) {
4078
4226
  environmentConfig
4079
4227
  };
4080
4228
  }
4081
- async function executeUpgradeBatch(data, context, gas, logger) {
4229
+ async function executeUpgradeBatch(data, context, gas, logger = noopLogger) {
4082
4230
  const pendingMessage = `Upgrading app ${data.appId}...`;
4083
4231
  const txHash = await executeBatch(
4084
4232
  {
@@ -4093,7 +4241,7 @@ async function executeUpgradeBatch(data, context, gas, logger) {
4093
4241
  );
4094
4242
  return txHash;
4095
4243
  }
4096
- async function upgradeApp(options, logger) {
4244
+ async function upgradeApp(options, logger = noopLogger) {
4097
4245
  const prepared = await prepareUpgradeBatch(options);
4098
4246
  const data = {
4099
4247
  appId: prepared.appId,
@@ -4106,8 +4254,18 @@ async function upgradeApp(options, logger) {
4106
4254
  };
4107
4255
  return executeUpgradeBatch(data, context, options.gas, logger);
4108
4256
  }
4109
- async function sendAndWaitForTransaction(options, logger) {
4110
- const { walletClient, publicClient, environmentConfig, to, data, value = 0n, pendingMessage, txDescription, gas } = options;
4257
+ async function sendAndWaitForTransaction(options, logger = noopLogger) {
4258
+ const {
4259
+ walletClient,
4260
+ publicClient,
4261
+ environmentConfig,
4262
+ to,
4263
+ data,
4264
+ value = 0n,
4265
+ pendingMessage,
4266
+ txDescription,
4267
+ gas
4268
+ } = options;
4111
4269
  const account = walletClient.account;
4112
4270
  if (!account) {
4113
4271
  throw new Error("WalletClient must have an account attached");
@@ -4218,7 +4376,7 @@ async function isDelegated(options) {
4218
4376
  environmentConfig.erc7702DelegatorAddress
4219
4377
  );
4220
4378
  }
4221
- async function undelegate(options, logger) {
4379
+ async function undelegate(options, logger = noopLogger) {
4222
4380
  const { walletClient, publicClient, environmentConfig } = options;
4223
4381
  const account = walletClient.account;
4224
4382
  if (!account) {
@@ -4286,6 +4444,7 @@ async function calculatePermissionSignature(options) {
4286
4444
  }
4287
4445
 
4288
4446
  // src/client/common/utils/userapi.ts
4447
+ init_session();
4289
4448
  function isJsonObject(value) {
4290
4449
  return typeof value === "object" && value !== null && !Array.isArray(value);
4291
4450
  }
@@ -4302,15 +4461,16 @@ var CanViewAppLogsPermission = "0x2fd3f2fe";
4302
4461
  var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
4303
4462
  var CanUpdateAppProfilePermission = "0x036fef61";
4304
4463
  function getDefaultClientId() {
4305
- const version = true ? "0.2.1-dev" : "0.0.0";
4464
+ const version = true ? "0.3.0-dev" : "0.0.0";
4306
4465
  return `ecloud-sdk/v${version}`;
4307
4466
  }
4308
4467
  var UserApiClient = class {
4309
- constructor(config, walletClient, publicClient, clientId) {
4468
+ constructor(config, walletClient, publicClient, options) {
4310
4469
  this.config = config;
4311
4470
  this.walletClient = walletClient;
4312
4471
  this.publicClient = publicClient;
4313
- this.clientId = clientId || getDefaultClientId();
4472
+ this.clientId = options?.clientId || getDefaultClientId();
4473
+ this.useSession = options?.useSession ?? false;
4314
4474
  }
4315
4475
  /**
4316
4476
  * Get the address of the connected wallet
@@ -4398,7 +4558,7 @@ var UserApiClient = class {
4398
4558
  const apps = result.apps || result.Apps || [];
4399
4559
  return apps.map((app, i) => ({
4400
4560
  address: app.address || appIDs[i],
4401
- status: app.status || app.Status || ""
4561
+ status: app.app_status || app.App_Status || ""
4402
4562
  }));
4403
4563
  }
4404
4564
  /**
@@ -4430,9 +4590,11 @@ var UserApiClient = class {
4430
4590
  const headers = {
4431
4591
  "x-client-id": this.clientId
4432
4592
  };
4433
- const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
4434
- const authHeaders = await this.generateAuthHeaders(CanUpdateAppProfilePermission, expiry);
4435
- Object.assign(headers, authHeaders);
4593
+ if (!this.useSession) {
4594
+ const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
4595
+ const authHeaders = await this.generateAuthHeaders(CanUpdateAppProfilePermission, expiry);
4596
+ Object.assign(headers, authHeaders);
4597
+ }
4436
4598
  try {
4437
4599
  const response = await import_axios.default.post(endpoint, formData, {
4438
4600
  headers,
@@ -4441,8 +4603,10 @@ var UserApiClient = class {
4441
4603
  // Don't throw on any status
4442
4604
  maxContentLength: Infinity,
4443
4605
  // Allow large file uploads
4444
- maxBodyLength: Infinity
4606
+ maxBodyLength: Infinity,
4445
4607
  // Allow large file uploads
4608
+ withCredentials: true
4609
+ // Include cookies for session auth
4446
4610
  });
4447
4611
  const status = response.status;
4448
4612
  if (status !== 200 && status !== 201) {
@@ -4476,7 +4640,7 @@ Please check:
4476
4640
  const headers = {
4477
4641
  "x-client-id": this.clientId
4478
4642
  };
4479
- if (permission) {
4643
+ if (permission && !this.useSession) {
4480
4644
  const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
4481
4645
  const authHeaders = await this.generateAuthHeaders(permission, expiry);
4482
4646
  Object.assign(headers, authHeaders);
@@ -4485,8 +4649,10 @@ Please check:
4485
4649
  const response = await import_axios.default.get(url, {
4486
4650
  headers,
4487
4651
  maxRedirects: 0,
4488
- validateStatus: () => true
4652
+ validateStatus: () => true,
4489
4653
  // Don't throw on any status
4654
+ withCredentials: true
4655
+ // Include cookies for session auth
4490
4656
  });
4491
4657
  const status = response.status;
4492
4658
  const statusText = status >= 200 && status < 300 ? "OK" : "Error";
@@ -4528,6 +4694,65 @@ Please check:
4528
4694
  "X-eigenx-expiry": expiry.toString()
4529
4695
  };
4530
4696
  }
4697
+ // ==========================================================================
4698
+ // SIWE Session Management
4699
+ // ==========================================================================
4700
+ /**
4701
+ * Login to the compute API using SIWE (Sign-In with Ethereum)
4702
+ *
4703
+ * This establishes a session with the compute API by verifying the SIWE message
4704
+ * and signature. On success, a session cookie is set in the browser.
4705
+ *
4706
+ * @param request - Login request containing SIWE message and signature
4707
+ * @returns Login result with the authenticated address
4708
+ *
4709
+ * @example
4710
+ * ```typescript
4711
+ * import { createSiweMessage } from "@layr-labs/ecloud-sdk/browser";
4712
+ *
4713
+ * const { message } = createSiweMessage({
4714
+ * address: userAddress,
4715
+ * chainId: 11155111,
4716
+ * domain: window.location.host,
4717
+ * uri: window.location.origin,
4718
+ * });
4719
+ *
4720
+ * const signature = await signMessageAsync({ message });
4721
+ * const result = await client.siweLogin({ message, signature });
4722
+ * ```
4723
+ */
4724
+ async siweLogin(request) {
4725
+ return loginToComputeApi({ baseUrl: this.config.userApiServerURL }, request);
4726
+ }
4727
+ /**
4728
+ * Logout from the compute API
4729
+ *
4730
+ * This destroys the current session and clears the session cookie.
4731
+ *
4732
+ * @example
4733
+ * ```typescript
4734
+ * await client.siweLogout();
4735
+ * ```
4736
+ */
4737
+ async siweLogout() {
4738
+ return logoutFromComputeApi({ baseUrl: this.config.userApiServerURL });
4739
+ }
4740
+ /**
4741
+ * Get the current SIWE session status from the compute API
4742
+ *
4743
+ * @returns Session information including authentication status and address
4744
+ *
4745
+ * @example
4746
+ * ```typescript
4747
+ * const session = await client.getSiweSession();
4748
+ * if (session.authenticated) {
4749
+ * console.log(`Logged in as ${session.address}`);
4750
+ * }
4751
+ * ```
4752
+ */
4753
+ async getSiweSession() {
4754
+ return getComputeApiSession({ baseUrl: this.config.userApiServerURL });
4755
+ }
4531
4756
  };
4532
4757
  function transformAppReleaseBuild(raw) {
4533
4758
  if (!isJsonObject(raw)) return void 0;
@@ -6375,7 +6600,7 @@ async function logs(options, walletClient, publicClient, environmentConfig, logg
6375
6600
  environmentConfig,
6376
6601
  walletClient,
6377
6602
  publicClient,
6378
- options.clientId
6603
+ options.clientId ? { clientId: options.clientId } : void 0
6379
6604
  );
6380
6605
  let logsText;
6381
6606
  let logsError = null;
@@ -6674,7 +6899,7 @@ function createAppModule(ctx) {
6674
6899
  environment,
6675
6900
  walletClient,
6676
6901
  publicClient,
6677
- ctx.clientId
6902
+ ctx.clientId ? { clientId: ctx.clientId } : void 0
6678
6903
  );
6679
6904
  return userApiClient.uploadAppProfile(appId, profile.name, {
6680
6905
  website: profile.website,