@layr-labs/ecloud-sdk 0.2.1-dev → 0.2.2-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-DeQzn_yM.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-DeQzn_yM.cjs';
3
3
 
4
4
  /**
5
5
  * Create command
package/dist/compute.cjs CHANGED
@@ -1142,6 +1142,18 @@ function extractRegistryNameNoDocker(imageRef) {
1142
1142
  // src/client/common/contract/eip7702.ts
1143
1143
  var import_viem = require("viem");
1144
1144
 
1145
+ // src/client/common/types/index.ts
1146
+ var noopLogger = {
1147
+ debug: () => {
1148
+ },
1149
+ info: () => {
1150
+ },
1151
+ warn: () => {
1152
+ },
1153
+ error: () => {
1154
+ }
1155
+ };
1156
+
1145
1157
  // src/client/common/abis/ERC7702Delegator.json
1146
1158
  var ERC7702Delegator_default = [
1147
1159
  {
@@ -2227,7 +2239,7 @@ async function checkERC7702Delegation(publicClient, account, delegatorAddress) {
2227
2239
  const expectedCode = `0xef0100${delegatorAddress.slice(2)}`;
2228
2240
  return code.toLowerCase() === expectedCode.toLowerCase();
2229
2241
  }
2230
- async function executeBatch(options, logger) {
2242
+ async function executeBatch(options, logger = noopLogger) {
2231
2243
  const { walletClient, publicClient, environmentConfig, executions, pendingMessage, gas } = options;
2232
2244
  const account = walletClient.account;
2233
2245
  if (!account) {
@@ -3895,7 +3907,7 @@ async function calculateAppID(options) {
3895
3907
  });
3896
3908
  return appID;
3897
3909
  }
3898
- async function prepareDeployBatch(options, logger) {
3910
+ async function prepareDeployBatch(options, logger = noopLogger) {
3899
3911
  const { walletClient, publicClient, environmentConfig, salt, release, publicLogs } = options;
3900
3912
  const account = walletClient.account;
3901
3913
  if (!account) {
@@ -3975,7 +3987,7 @@ async function prepareDeployBatch(options, logger) {
3975
3987
  environmentConfig
3976
3988
  };
3977
3989
  }
3978
- async function executeDeployBatch(data, context, gas, logger) {
3990
+ async function executeDeployBatch(data, context, gas, logger = noopLogger) {
3979
3991
  const pendingMessage = "Deploying new app...";
3980
3992
  const txHash = await executeBatch(
3981
3993
  {
@@ -3990,7 +4002,7 @@ async function executeDeployBatch(data, context, gas, logger) {
3990
4002
  );
3991
4003
  return { appId: data.appId, txHash };
3992
4004
  }
3993
- async function deployApp(options, logger) {
4005
+ async function deployApp(options, logger = noopLogger) {
3994
4006
  const prepared = await prepareDeployBatch(options, logger);
3995
4007
  const data = {
3996
4008
  appId: prepared.appId,
@@ -4005,7 +4017,15 @@ async function deployApp(options, logger) {
4005
4017
  return executeDeployBatch(data, context, options.gas, logger);
4006
4018
  }
4007
4019
  async function prepareUpgradeBatch(options) {
4008
- const { walletClient, publicClient, environmentConfig, appID, release, publicLogs, needsPermissionChange } = options;
4020
+ const {
4021
+ walletClient,
4022
+ publicClient,
4023
+ environmentConfig,
4024
+ appID,
4025
+ release,
4026
+ publicLogs,
4027
+ needsPermissionChange
4028
+ } = options;
4009
4029
  const releaseForViem = {
4010
4030
  rmsRelease: {
4011
4031
  artifacts: release.rmsRelease.artifacts.map((artifact) => ({
@@ -4078,7 +4098,7 @@ async function prepareUpgradeBatch(options) {
4078
4098
  environmentConfig
4079
4099
  };
4080
4100
  }
4081
- async function executeUpgradeBatch(data, context, gas, logger) {
4101
+ async function executeUpgradeBatch(data, context, gas, logger = noopLogger) {
4082
4102
  const pendingMessage = `Upgrading app ${data.appId}...`;
4083
4103
  const txHash = await executeBatch(
4084
4104
  {
@@ -4093,7 +4113,7 @@ async function executeUpgradeBatch(data, context, gas, logger) {
4093
4113
  );
4094
4114
  return txHash;
4095
4115
  }
4096
- async function upgradeApp(options, logger) {
4116
+ async function upgradeApp(options, logger = noopLogger) {
4097
4117
  const prepared = await prepareUpgradeBatch(options);
4098
4118
  const data = {
4099
4119
  appId: prepared.appId,
@@ -4106,8 +4126,18 @@ async function upgradeApp(options, logger) {
4106
4126
  };
4107
4127
  return executeUpgradeBatch(data, context, options.gas, logger);
4108
4128
  }
4109
- async function sendAndWaitForTransaction(options, logger) {
4110
- const { walletClient, publicClient, environmentConfig, to, data, value = 0n, pendingMessage, txDescription, gas } = options;
4129
+ async function sendAndWaitForTransaction(options, logger = noopLogger) {
4130
+ const {
4131
+ walletClient,
4132
+ publicClient,
4133
+ environmentConfig,
4134
+ to,
4135
+ data,
4136
+ value = 0n,
4137
+ pendingMessage,
4138
+ txDescription,
4139
+ gas
4140
+ } = options;
4111
4141
  const account = walletClient.account;
4112
4142
  if (!account) {
4113
4143
  throw new Error("WalletClient must have an account attached");
@@ -4218,7 +4248,7 @@ async function isDelegated(options) {
4218
4248
  environmentConfig.erc7702DelegatorAddress
4219
4249
  );
4220
4250
  }
4221
- async function undelegate(options, logger) {
4251
+ async function undelegate(options, logger = noopLogger) {
4222
4252
  const { walletClient, publicClient, environmentConfig } = options;
4223
4253
  const account = walletClient.account;
4224
4254
  if (!account) {
@@ -4285,6 +4315,125 @@ async function calculatePermissionSignature(options) {
4285
4315
  return { signature, digest };
4286
4316
  }
4287
4317
 
4318
+ // src/client/common/auth/session.ts
4319
+ var SessionError = class extends Error {
4320
+ constructor(message, code, statusCode) {
4321
+ super(message);
4322
+ this.code = code;
4323
+ this.statusCode = statusCode;
4324
+ this.name = "SessionError";
4325
+ }
4326
+ };
4327
+ function stripHexPrefix2(hex) {
4328
+ return hex.startsWith("0x") ? hex.slice(2) : hex;
4329
+ }
4330
+ async function parseErrorResponse(response) {
4331
+ try {
4332
+ const data = await response.json();
4333
+ return data.error || response.statusText;
4334
+ } catch {
4335
+ return response.statusText;
4336
+ }
4337
+ }
4338
+ async function loginToComputeApi(config, request) {
4339
+ let response;
4340
+ try {
4341
+ response = await fetch(`${config.baseUrl}/auth/siwe/login`, {
4342
+ method: "POST",
4343
+ credentials: "include",
4344
+ // Include cookies for session management
4345
+ headers: {
4346
+ "Content-Type": "application/json"
4347
+ },
4348
+ body: JSON.stringify({
4349
+ message: request.message,
4350
+ signature: stripHexPrefix2(request.signature)
4351
+ })
4352
+ });
4353
+ } catch (error) {
4354
+ throw new SessionError(
4355
+ `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
4356
+ "NETWORK_ERROR"
4357
+ );
4358
+ }
4359
+ if (!response.ok) {
4360
+ const errorMessage = await parseErrorResponse(response);
4361
+ const status = response.status;
4362
+ if (status === 400) {
4363
+ if (errorMessage.toLowerCase().includes("siwe")) {
4364
+ throw new SessionError(`Invalid SIWE message: ${errorMessage}`, "INVALID_MESSAGE", status);
4365
+ }
4366
+ throw new SessionError(`Bad request: ${errorMessage}`, "INVALID_MESSAGE", status);
4367
+ }
4368
+ if (status === 401) {
4369
+ throw new SessionError(`Invalid signature: ${errorMessage}`, "INVALID_SIGNATURE", status);
4370
+ }
4371
+ throw new SessionError(`Login failed: ${errorMessage}`, "UNKNOWN", status);
4372
+ }
4373
+ const data = await response.json();
4374
+ return {
4375
+ success: data.success,
4376
+ address: data.address
4377
+ };
4378
+ }
4379
+ async function getComputeApiSession(config) {
4380
+ let response;
4381
+ try {
4382
+ response = await fetch(`${config.baseUrl}/auth/session`, {
4383
+ method: "GET",
4384
+ credentials: "include",
4385
+ // Include cookies for session management
4386
+ headers: {
4387
+ "Content-Type": "application/json"
4388
+ }
4389
+ });
4390
+ } catch {
4391
+ return {
4392
+ authenticated: false
4393
+ };
4394
+ }
4395
+ if (response.status === 401) {
4396
+ return {
4397
+ authenticated: false
4398
+ };
4399
+ }
4400
+ if (!response.ok) {
4401
+ const errorMessage = await parseErrorResponse(response);
4402
+ throw new SessionError(`Failed to get session: ${errorMessage}`, "UNKNOWN", response.status);
4403
+ }
4404
+ const data = await response.json();
4405
+ return {
4406
+ authenticated: data.authenticated,
4407
+ address: data.address,
4408
+ chainId: data.chain_id
4409
+ };
4410
+ }
4411
+ async function logoutFromComputeApi(config) {
4412
+ let response;
4413
+ try {
4414
+ response = await fetch(`${config.baseUrl}/auth/logout`, {
4415
+ method: "POST",
4416
+ credentials: "include",
4417
+ // Include cookies for session management
4418
+ headers: {
4419
+ "Content-Type": "application/json"
4420
+ }
4421
+ });
4422
+ } catch (error) {
4423
+ throw new SessionError(
4424
+ `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
4425
+ "NETWORK_ERROR"
4426
+ );
4427
+ }
4428
+ if (response.status === 401) {
4429
+ return;
4430
+ }
4431
+ if (!response.ok) {
4432
+ const errorMessage = await parseErrorResponse(response);
4433
+ throw new SessionError(`Logout failed: ${errorMessage}`, "UNKNOWN", response.status);
4434
+ }
4435
+ }
4436
+
4288
4437
  // src/client/common/utils/userapi.ts
4289
4438
  function isJsonObject(value) {
4290
4439
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -4302,15 +4451,16 @@ var CanViewAppLogsPermission = "0x2fd3f2fe";
4302
4451
  var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
4303
4452
  var CanUpdateAppProfilePermission = "0x036fef61";
4304
4453
  function getDefaultClientId() {
4305
- const version = true ? "0.2.1-dev" : "0.0.0";
4454
+ const version = true ? "0.2.2-dev" : "0.0.0";
4306
4455
  return `ecloud-sdk/v${version}`;
4307
4456
  }
4308
4457
  var UserApiClient = class {
4309
- constructor(config, walletClient, publicClient, clientId) {
4458
+ constructor(config, walletClient, publicClient, options) {
4310
4459
  this.config = config;
4311
4460
  this.walletClient = walletClient;
4312
4461
  this.publicClient = publicClient;
4313
- this.clientId = clientId || getDefaultClientId();
4462
+ this.clientId = options?.clientId || getDefaultClientId();
4463
+ this.useSession = options?.useSession ?? false;
4314
4464
  }
4315
4465
  /**
4316
4466
  * Get the address of the connected wallet
@@ -4398,7 +4548,7 @@ var UserApiClient = class {
4398
4548
  const apps = result.apps || result.Apps || [];
4399
4549
  return apps.map((app, i) => ({
4400
4550
  address: app.address || appIDs[i],
4401
- status: app.status || app.Status || ""
4551
+ status: app.app_status || app.App_Status || ""
4402
4552
  }));
4403
4553
  }
4404
4554
  /**
@@ -4430,9 +4580,11 @@ var UserApiClient = class {
4430
4580
  const headers = {
4431
4581
  "x-client-id": this.clientId
4432
4582
  };
4433
- const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
4434
- const authHeaders = await this.generateAuthHeaders(CanUpdateAppProfilePermission, expiry);
4435
- Object.assign(headers, authHeaders);
4583
+ if (!this.useSession) {
4584
+ const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
4585
+ const authHeaders = await this.generateAuthHeaders(CanUpdateAppProfilePermission, expiry);
4586
+ Object.assign(headers, authHeaders);
4587
+ }
4436
4588
  try {
4437
4589
  const response = await import_axios.default.post(endpoint, formData, {
4438
4590
  headers,
@@ -4441,8 +4593,10 @@ var UserApiClient = class {
4441
4593
  // Don't throw on any status
4442
4594
  maxContentLength: Infinity,
4443
4595
  // Allow large file uploads
4444
- maxBodyLength: Infinity
4596
+ maxBodyLength: Infinity,
4445
4597
  // Allow large file uploads
4598
+ withCredentials: true
4599
+ // Include cookies for session auth
4446
4600
  });
4447
4601
  const status = response.status;
4448
4602
  if (status !== 200 && status !== 201) {
@@ -4476,7 +4630,7 @@ Please check:
4476
4630
  const headers = {
4477
4631
  "x-client-id": this.clientId
4478
4632
  };
4479
- if (permission) {
4633
+ if (permission && !this.useSession) {
4480
4634
  const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
4481
4635
  const authHeaders = await this.generateAuthHeaders(permission, expiry);
4482
4636
  Object.assign(headers, authHeaders);
@@ -4485,8 +4639,10 @@ Please check:
4485
4639
  const response = await import_axios.default.get(url, {
4486
4640
  headers,
4487
4641
  maxRedirects: 0,
4488
- validateStatus: () => true
4642
+ validateStatus: () => true,
4489
4643
  // Don't throw on any status
4644
+ withCredentials: true
4645
+ // Include cookies for session auth
4490
4646
  });
4491
4647
  const status = response.status;
4492
4648
  const statusText = status >= 200 && status < 300 ? "OK" : "Error";
@@ -4528,6 +4684,65 @@ Please check:
4528
4684
  "X-eigenx-expiry": expiry.toString()
4529
4685
  };
4530
4686
  }
4687
+ // ==========================================================================
4688
+ // SIWE Session Management
4689
+ // ==========================================================================
4690
+ /**
4691
+ * Login to the compute API using SIWE (Sign-In with Ethereum)
4692
+ *
4693
+ * This establishes a session with the compute API by verifying the SIWE message
4694
+ * and signature. On success, a session cookie is set in the browser.
4695
+ *
4696
+ * @param request - Login request containing SIWE message and signature
4697
+ * @returns Login result with the authenticated address
4698
+ *
4699
+ * @example
4700
+ * ```typescript
4701
+ * import { createSiweMessage } from "@layr-labs/ecloud-sdk/browser";
4702
+ *
4703
+ * const { message } = createSiweMessage({
4704
+ * address: userAddress,
4705
+ * chainId: 11155111,
4706
+ * domain: window.location.host,
4707
+ * uri: window.location.origin,
4708
+ * });
4709
+ *
4710
+ * const signature = await signMessageAsync({ message });
4711
+ * const result = await client.siweLogin({ message, signature });
4712
+ * ```
4713
+ */
4714
+ async siweLogin(request) {
4715
+ return loginToComputeApi({ baseUrl: this.config.userApiServerURL }, request);
4716
+ }
4717
+ /**
4718
+ * Logout from the compute API
4719
+ *
4720
+ * This destroys the current session and clears the session cookie.
4721
+ *
4722
+ * @example
4723
+ * ```typescript
4724
+ * await client.siweLogout();
4725
+ * ```
4726
+ */
4727
+ async siweLogout() {
4728
+ return logoutFromComputeApi({ baseUrl: this.config.userApiServerURL });
4729
+ }
4730
+ /**
4731
+ * Get the current SIWE session status from the compute API
4732
+ *
4733
+ * @returns Session information including authentication status and address
4734
+ *
4735
+ * @example
4736
+ * ```typescript
4737
+ * const session = await client.getSiweSession();
4738
+ * if (session.authenticated) {
4739
+ * console.log(`Logged in as ${session.address}`);
4740
+ * }
4741
+ * ```
4742
+ */
4743
+ async getSiweSession() {
4744
+ return getComputeApiSession({ baseUrl: this.config.userApiServerURL });
4745
+ }
4531
4746
  };
4532
4747
  function transformAppReleaseBuild(raw) {
4533
4748
  if (!isJsonObject(raw)) return void 0;
@@ -6375,7 +6590,7 @@ async function logs(options, walletClient, publicClient, environmentConfig, logg
6375
6590
  environmentConfig,
6376
6591
  walletClient,
6377
6592
  publicClient,
6378
- options.clientId
6593
+ options.clientId ? { clientId: options.clientId } : void 0
6379
6594
  );
6380
6595
  let logsText;
6381
6596
  let logsError = null;
@@ -6674,7 +6889,7 @@ function createAppModule(ctx) {
6674
6889
  environment,
6675
6890
  walletClient,
6676
6891
  publicClient,
6677
- ctx.clientId
6892
+ ctx.clientId ? { clientId: ctx.clientId } : void 0
6678
6893
  );
6679
6894
  return userApiClient.uploadAppProfile(appId, profile.name, {
6680
6895
  website: profile.website,