@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,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-Bpjb3hYD.cjs';
2
2
  import 'viem';
3
- import './index-D5oW73Dx.cjs';
3
+ import './index-DeQzn_yM.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-BYhSs8en.js';
2
2
  import 'viem';
3
- import './index-D5oW73Dx.js';
3
+ import './index-DeQzn_yM.js';
package/dist/compute.js CHANGED
@@ -1101,6 +1101,18 @@ function extractRegistryNameNoDocker(imageRef) {
1101
1101
  // src/client/common/contract/eip7702.ts
1102
1102
  import { encodeFunctionData, encodeAbiParameters, decodeErrorResult } from "viem";
1103
1103
 
1104
+ // src/client/common/types/index.ts
1105
+ var noopLogger = {
1106
+ debug: () => {
1107
+ },
1108
+ info: () => {
1109
+ },
1110
+ warn: () => {
1111
+ },
1112
+ error: () => {
1113
+ }
1114
+ };
1115
+
1104
1116
  // src/client/common/abis/ERC7702Delegator.json
1105
1117
  var ERC7702Delegator_default = [
1106
1118
  {
@@ -2186,7 +2198,7 @@ async function checkERC7702Delegation(publicClient, account, delegatorAddress) {
2186
2198
  const expectedCode = `0xef0100${delegatorAddress.slice(2)}`;
2187
2199
  return code.toLowerCase() === expectedCode.toLowerCase();
2188
2200
  }
2189
- async function executeBatch(options, logger) {
2201
+ async function executeBatch(options, logger = noopLogger) {
2190
2202
  const { walletClient, publicClient, environmentConfig, executions, pendingMessage, gas } = options;
2191
2203
  const account = walletClient.account;
2192
2204
  if (!account) {
@@ -2270,11 +2282,7 @@ async function executeBatch(options, logger) {
2270
2282
  }
2271
2283
 
2272
2284
  // src/client/common/contract/caller.ts
2273
- import {
2274
- encodeFunctionData as encodeFunctionData2,
2275
- decodeErrorResult as decodeErrorResult2,
2276
- bytesToHex
2277
- } from "viem";
2285
+ import { encodeFunctionData as encodeFunctionData2, decodeErrorResult as decodeErrorResult2, bytesToHex } from "viem";
2278
2286
 
2279
2287
  // src/client/common/utils/helpers.ts
2280
2288
  import { extractChain, createPublicClient, createWalletClient, http } from "viem";
@@ -3858,7 +3866,7 @@ async function calculateAppID(options) {
3858
3866
  });
3859
3867
  return appID;
3860
3868
  }
3861
- async function prepareDeployBatch(options, logger) {
3869
+ async function prepareDeployBatch(options, logger = noopLogger) {
3862
3870
  const { walletClient, publicClient, environmentConfig, salt, release, publicLogs } = options;
3863
3871
  const account = walletClient.account;
3864
3872
  if (!account) {
@@ -3938,7 +3946,7 @@ async function prepareDeployBatch(options, logger) {
3938
3946
  environmentConfig
3939
3947
  };
3940
3948
  }
3941
- async function executeDeployBatch(data, context, gas, logger) {
3949
+ async function executeDeployBatch(data, context, gas, logger = noopLogger) {
3942
3950
  const pendingMessage = "Deploying new app...";
3943
3951
  const txHash = await executeBatch(
3944
3952
  {
@@ -3953,7 +3961,7 @@ async function executeDeployBatch(data, context, gas, logger) {
3953
3961
  );
3954
3962
  return { appId: data.appId, txHash };
3955
3963
  }
3956
- async function deployApp(options, logger) {
3964
+ async function deployApp(options, logger = noopLogger) {
3957
3965
  const prepared = await prepareDeployBatch(options, logger);
3958
3966
  const data = {
3959
3967
  appId: prepared.appId,
@@ -3968,7 +3976,15 @@ async function deployApp(options, logger) {
3968
3976
  return executeDeployBatch(data, context, options.gas, logger);
3969
3977
  }
3970
3978
  async function prepareUpgradeBatch(options) {
3971
- const { walletClient, publicClient, environmentConfig, appID, release, publicLogs, needsPermissionChange } = options;
3979
+ const {
3980
+ walletClient,
3981
+ publicClient,
3982
+ environmentConfig,
3983
+ appID,
3984
+ release,
3985
+ publicLogs,
3986
+ needsPermissionChange
3987
+ } = options;
3972
3988
  const releaseForViem = {
3973
3989
  rmsRelease: {
3974
3990
  artifacts: release.rmsRelease.artifacts.map((artifact) => ({
@@ -4041,7 +4057,7 @@ async function prepareUpgradeBatch(options) {
4041
4057
  environmentConfig
4042
4058
  };
4043
4059
  }
4044
- async function executeUpgradeBatch(data, context, gas, logger) {
4060
+ async function executeUpgradeBatch(data, context, gas, logger = noopLogger) {
4045
4061
  const pendingMessage = `Upgrading app ${data.appId}...`;
4046
4062
  const txHash = await executeBatch(
4047
4063
  {
@@ -4056,7 +4072,7 @@ async function executeUpgradeBatch(data, context, gas, logger) {
4056
4072
  );
4057
4073
  return txHash;
4058
4074
  }
4059
- async function upgradeApp(options, logger) {
4075
+ async function upgradeApp(options, logger = noopLogger) {
4060
4076
  const prepared = await prepareUpgradeBatch(options);
4061
4077
  const data = {
4062
4078
  appId: prepared.appId,
@@ -4069,8 +4085,18 @@ async function upgradeApp(options, logger) {
4069
4085
  };
4070
4086
  return executeUpgradeBatch(data, context, options.gas, logger);
4071
4087
  }
4072
- async function sendAndWaitForTransaction(options, logger) {
4073
- const { walletClient, publicClient, environmentConfig, to, data, value = 0n, pendingMessage, txDescription, gas } = options;
4088
+ async function sendAndWaitForTransaction(options, logger = noopLogger) {
4089
+ const {
4090
+ walletClient,
4091
+ publicClient,
4092
+ environmentConfig,
4093
+ to,
4094
+ data,
4095
+ value = 0n,
4096
+ pendingMessage,
4097
+ txDescription,
4098
+ gas
4099
+ } = options;
4074
4100
  const account = walletClient.account;
4075
4101
  if (!account) {
4076
4102
  throw new Error("WalletClient must have an account attached");
@@ -4181,7 +4207,7 @@ async function isDelegated(options) {
4181
4207
  environmentConfig.erc7702DelegatorAddress
4182
4208
  );
4183
4209
  }
4184
- async function undelegate(options, logger) {
4210
+ async function undelegate(options, logger = noopLogger) {
4185
4211
  const { walletClient, publicClient, environmentConfig } = options;
4186
4212
  const account = walletClient.account;
4187
4213
  if (!account) {
@@ -4248,6 +4274,125 @@ async function calculatePermissionSignature(options) {
4248
4274
  return { signature, digest };
4249
4275
  }
4250
4276
 
4277
+ // src/client/common/auth/session.ts
4278
+ var SessionError = class extends Error {
4279
+ constructor(message, code, statusCode) {
4280
+ super(message);
4281
+ this.code = code;
4282
+ this.statusCode = statusCode;
4283
+ this.name = "SessionError";
4284
+ }
4285
+ };
4286
+ function stripHexPrefix2(hex) {
4287
+ return hex.startsWith("0x") ? hex.slice(2) : hex;
4288
+ }
4289
+ async function parseErrorResponse(response) {
4290
+ try {
4291
+ const data = await response.json();
4292
+ return data.error || response.statusText;
4293
+ } catch {
4294
+ return response.statusText;
4295
+ }
4296
+ }
4297
+ async function loginToComputeApi(config, request) {
4298
+ let response;
4299
+ try {
4300
+ response = await fetch(`${config.baseUrl}/auth/siwe/login`, {
4301
+ method: "POST",
4302
+ credentials: "include",
4303
+ // Include cookies for session management
4304
+ headers: {
4305
+ "Content-Type": "application/json"
4306
+ },
4307
+ body: JSON.stringify({
4308
+ message: request.message,
4309
+ signature: stripHexPrefix2(request.signature)
4310
+ })
4311
+ });
4312
+ } catch (error) {
4313
+ throw new SessionError(
4314
+ `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
4315
+ "NETWORK_ERROR"
4316
+ );
4317
+ }
4318
+ if (!response.ok) {
4319
+ const errorMessage = await parseErrorResponse(response);
4320
+ const status = response.status;
4321
+ if (status === 400) {
4322
+ if (errorMessage.toLowerCase().includes("siwe")) {
4323
+ throw new SessionError(`Invalid SIWE message: ${errorMessage}`, "INVALID_MESSAGE", status);
4324
+ }
4325
+ throw new SessionError(`Bad request: ${errorMessage}`, "INVALID_MESSAGE", status);
4326
+ }
4327
+ if (status === 401) {
4328
+ throw new SessionError(`Invalid signature: ${errorMessage}`, "INVALID_SIGNATURE", status);
4329
+ }
4330
+ throw new SessionError(`Login failed: ${errorMessage}`, "UNKNOWN", status);
4331
+ }
4332
+ const data = await response.json();
4333
+ return {
4334
+ success: data.success,
4335
+ address: data.address
4336
+ };
4337
+ }
4338
+ async function getComputeApiSession(config) {
4339
+ let response;
4340
+ try {
4341
+ response = await fetch(`${config.baseUrl}/auth/session`, {
4342
+ method: "GET",
4343
+ credentials: "include",
4344
+ // Include cookies for session management
4345
+ headers: {
4346
+ "Content-Type": "application/json"
4347
+ }
4348
+ });
4349
+ } catch {
4350
+ return {
4351
+ authenticated: false
4352
+ };
4353
+ }
4354
+ if (response.status === 401) {
4355
+ return {
4356
+ authenticated: false
4357
+ };
4358
+ }
4359
+ if (!response.ok) {
4360
+ const errorMessage = await parseErrorResponse(response);
4361
+ throw new SessionError(`Failed to get session: ${errorMessage}`, "UNKNOWN", response.status);
4362
+ }
4363
+ const data = await response.json();
4364
+ return {
4365
+ authenticated: data.authenticated,
4366
+ address: data.address,
4367
+ chainId: data.chain_id
4368
+ };
4369
+ }
4370
+ async function logoutFromComputeApi(config) {
4371
+ let response;
4372
+ try {
4373
+ response = await fetch(`${config.baseUrl}/auth/logout`, {
4374
+ method: "POST",
4375
+ credentials: "include",
4376
+ // Include cookies for session management
4377
+ headers: {
4378
+ "Content-Type": "application/json"
4379
+ }
4380
+ });
4381
+ } catch (error) {
4382
+ throw new SessionError(
4383
+ `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
4384
+ "NETWORK_ERROR"
4385
+ );
4386
+ }
4387
+ if (response.status === 401) {
4388
+ return;
4389
+ }
4390
+ if (!response.ok) {
4391
+ const errorMessage = await parseErrorResponse(response);
4392
+ throw new SessionError(`Logout failed: ${errorMessage}`, "UNKNOWN", response.status);
4393
+ }
4394
+ }
4395
+
4251
4396
  // src/client/common/utils/userapi.ts
4252
4397
  function isJsonObject(value) {
4253
4398
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -4265,15 +4410,16 @@ var CanViewAppLogsPermission = "0x2fd3f2fe";
4265
4410
  var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
4266
4411
  var CanUpdateAppProfilePermission = "0x036fef61";
4267
4412
  function getDefaultClientId() {
4268
- const version = true ? "0.2.1-dev" : "0.0.0";
4413
+ const version = true ? "0.2.2-dev" : "0.0.0";
4269
4414
  return `ecloud-sdk/v${version}`;
4270
4415
  }
4271
4416
  var UserApiClient = class {
4272
- constructor(config, walletClient, publicClient, clientId) {
4417
+ constructor(config, walletClient, publicClient, options) {
4273
4418
  this.config = config;
4274
4419
  this.walletClient = walletClient;
4275
4420
  this.publicClient = publicClient;
4276
- this.clientId = clientId || getDefaultClientId();
4421
+ this.clientId = options?.clientId || getDefaultClientId();
4422
+ this.useSession = options?.useSession ?? false;
4277
4423
  }
4278
4424
  /**
4279
4425
  * Get the address of the connected wallet
@@ -4361,7 +4507,7 @@ var UserApiClient = class {
4361
4507
  const apps = result.apps || result.Apps || [];
4362
4508
  return apps.map((app, i) => ({
4363
4509
  address: app.address || appIDs[i],
4364
- status: app.status || app.Status || ""
4510
+ status: app.app_status || app.App_Status || ""
4365
4511
  }));
4366
4512
  }
4367
4513
  /**
@@ -4393,9 +4539,11 @@ var UserApiClient = class {
4393
4539
  const headers = {
4394
4540
  "x-client-id": this.clientId
4395
4541
  };
4396
- const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
4397
- const authHeaders = await this.generateAuthHeaders(CanUpdateAppProfilePermission, expiry);
4398
- Object.assign(headers, authHeaders);
4542
+ if (!this.useSession) {
4543
+ const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
4544
+ const authHeaders = await this.generateAuthHeaders(CanUpdateAppProfilePermission, expiry);
4545
+ Object.assign(headers, authHeaders);
4546
+ }
4399
4547
  try {
4400
4548
  const response = await axios.post(endpoint, formData, {
4401
4549
  headers,
@@ -4404,8 +4552,10 @@ var UserApiClient = class {
4404
4552
  // Don't throw on any status
4405
4553
  maxContentLength: Infinity,
4406
4554
  // Allow large file uploads
4407
- maxBodyLength: Infinity
4555
+ maxBodyLength: Infinity,
4408
4556
  // Allow large file uploads
4557
+ withCredentials: true
4558
+ // Include cookies for session auth
4409
4559
  });
4410
4560
  const status = response.status;
4411
4561
  if (status !== 200 && status !== 201) {
@@ -4439,7 +4589,7 @@ Please check:
4439
4589
  const headers = {
4440
4590
  "x-client-id": this.clientId
4441
4591
  };
4442
- if (permission) {
4592
+ if (permission && !this.useSession) {
4443
4593
  const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
4444
4594
  const authHeaders = await this.generateAuthHeaders(permission, expiry);
4445
4595
  Object.assign(headers, authHeaders);
@@ -4448,8 +4598,10 @@ Please check:
4448
4598
  const response = await axios.get(url, {
4449
4599
  headers,
4450
4600
  maxRedirects: 0,
4451
- validateStatus: () => true
4601
+ validateStatus: () => true,
4452
4602
  // Don't throw on any status
4603
+ withCredentials: true
4604
+ // Include cookies for session auth
4453
4605
  });
4454
4606
  const status = response.status;
4455
4607
  const statusText = status >= 200 && status < 300 ? "OK" : "Error";
@@ -4491,6 +4643,65 @@ Please check:
4491
4643
  "X-eigenx-expiry": expiry.toString()
4492
4644
  };
4493
4645
  }
4646
+ // ==========================================================================
4647
+ // SIWE Session Management
4648
+ // ==========================================================================
4649
+ /**
4650
+ * Login to the compute API using SIWE (Sign-In with Ethereum)
4651
+ *
4652
+ * This establishes a session with the compute API by verifying the SIWE message
4653
+ * and signature. On success, a session cookie is set in the browser.
4654
+ *
4655
+ * @param request - Login request containing SIWE message and signature
4656
+ * @returns Login result with the authenticated address
4657
+ *
4658
+ * @example
4659
+ * ```typescript
4660
+ * import { createSiweMessage } from "@layr-labs/ecloud-sdk/browser";
4661
+ *
4662
+ * const { message } = createSiweMessage({
4663
+ * address: userAddress,
4664
+ * chainId: 11155111,
4665
+ * domain: window.location.host,
4666
+ * uri: window.location.origin,
4667
+ * });
4668
+ *
4669
+ * const signature = await signMessageAsync({ message });
4670
+ * const result = await client.siweLogin({ message, signature });
4671
+ * ```
4672
+ */
4673
+ async siweLogin(request) {
4674
+ return loginToComputeApi({ baseUrl: this.config.userApiServerURL }, request);
4675
+ }
4676
+ /**
4677
+ * Logout from the compute API
4678
+ *
4679
+ * This destroys the current session and clears the session cookie.
4680
+ *
4681
+ * @example
4682
+ * ```typescript
4683
+ * await client.siweLogout();
4684
+ * ```
4685
+ */
4686
+ async siweLogout() {
4687
+ return logoutFromComputeApi({ baseUrl: this.config.userApiServerURL });
4688
+ }
4689
+ /**
4690
+ * Get the current SIWE session status from the compute API
4691
+ *
4692
+ * @returns Session information including authentication status and address
4693
+ *
4694
+ * @example
4695
+ * ```typescript
4696
+ * const session = await client.getSiweSession();
4697
+ * if (session.authenticated) {
4698
+ * console.log(`Logged in as ${session.address}`);
4699
+ * }
4700
+ * ```
4701
+ */
4702
+ async getSiweSession() {
4703
+ return getComputeApiSession({ baseUrl: this.config.userApiServerURL });
4704
+ }
4494
4705
  };
4495
4706
  function transformAppReleaseBuild(raw) {
4496
4707
  if (!isJsonObject(raw)) return void 0;
@@ -6338,7 +6549,7 @@ async function logs(options, walletClient, publicClient, environmentConfig, logg
6338
6549
  environmentConfig,
6339
6550
  walletClient,
6340
6551
  publicClient,
6341
- options.clientId
6552
+ options.clientId ? { clientId: options.clientId } : void 0
6342
6553
  );
6343
6554
  let logsText;
6344
6555
  let logsError = null;
@@ -6637,7 +6848,7 @@ function createAppModule(ctx) {
6637
6848
  environment,
6638
6849
  walletClient,
6639
6850
  publicClient,
6640
- ctx.clientId
6851
+ ctx.clientId ? { clientId: ctx.clientId } : void 0
6641
6852
  );
6642
6853
  return userApiClient.uploadAppProfile(appId, profile.name, {
6643
6854
  website: profile.website,