@layr-labs/ecloud-sdk 0.2.2-dev → 0.3.0-dev.0

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-Bpjb3hYD.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-oD9uqLtr.cjs';
2
2
  import 'viem';
3
- import './index-DeQzn_yM.cjs';
3
+ import './index-5y9NG_Id.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-BYhSs8en.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-BcJuIxc1.js';
2
2
  import 'viem';
3
- import './index-DeQzn_yM.js';
3
+ import './index-5y9NG_Id.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
 
@@ -2167,7 +2297,7 @@ function encodeExecuteBatchData(executions) {
2167
2297
  });
2168
2298
  }
2169
2299
  async function estimateBatchGas(options) {
2170
- const { publicClient, account, executions } = options;
2300
+ const { publicClient, account, executions, authorizationList } = options;
2171
2301
  const executeBatchData = encodeExecuteBatchData(executions);
2172
2302
  const [gasTipCap, block, estimatedGas] = await Promise.all([
2173
2303
  publicClient.estimateMaxPriorityFeePerGas(),
@@ -2175,7 +2305,8 @@ async function estimateBatchGas(options) {
2175
2305
  publicClient.estimateGas({
2176
2306
  account,
2177
2307
  to: account,
2178
- data: executeBatchData
2308
+ data: executeBatchData,
2309
+ authorizationList
2179
2310
  })
2180
2311
  ]);
2181
2312
  const baseFee = block.baseFeePerGas ?? 0n;
@@ -2198,8 +2329,44 @@ async function checkERC7702Delegation(publicClient, account, delegatorAddress) {
2198
2329
  const expectedCode = `0xef0100${delegatorAddress.slice(2)}`;
2199
2330
  return code.toLowerCase() === expectedCode.toLowerCase();
2200
2331
  }
2332
+ async function createAuthorizationList(options) {
2333
+ const { walletClient, publicClient, environmentConfig } = options;
2334
+ const account = walletClient.account;
2335
+ if (!account) {
2336
+ throw new Error("Wallet client must have an account");
2337
+ }
2338
+ const isDelegated2 = await checkERC7702Delegation(
2339
+ publicClient,
2340
+ account.address,
2341
+ environmentConfig.erc7702DelegatorAddress
2342
+ );
2343
+ if (isDelegated2) {
2344
+ return void 0;
2345
+ }
2346
+ const transactionNonce = await publicClient.getTransactionCount({
2347
+ address: account.address,
2348
+ blockTag: "pending"
2349
+ });
2350
+ const chainId = await publicClient.getChainId();
2351
+ const authorizationNonce = transactionNonce + 1;
2352
+ const signedAuthorization = await walletClient.signAuthorization({
2353
+ account,
2354
+ contractAddress: environmentConfig.erc7702DelegatorAddress,
2355
+ chainId,
2356
+ nonce: Number(authorizationNonce)
2357
+ });
2358
+ return [signedAuthorization];
2359
+ }
2201
2360
  async function executeBatch(options, logger = noopLogger) {
2202
- const { walletClient, publicClient, environmentConfig, executions, pendingMessage, gas } = options;
2361
+ const {
2362
+ walletClient,
2363
+ publicClient,
2364
+ environmentConfig,
2365
+ executions,
2366
+ pendingMessage,
2367
+ gas,
2368
+ authorizationList: providedAuthList
2369
+ } = options;
2203
2370
  const account = walletClient.account;
2204
2371
  if (!account) {
2205
2372
  throw new Error("Wallet client must have an account");
@@ -2209,27 +2376,29 @@ async function executeBatch(options, logger = noopLogger) {
2209
2376
  throw new Error("Wallet client must have a chain");
2210
2377
  }
2211
2378
  const executeBatchData = encodeExecuteBatchData(executions);
2212
- const isDelegated2 = await checkERC7702Delegation(
2213
- publicClient,
2214
- account.address,
2215
- environmentConfig.erc7702DelegatorAddress
2216
- );
2217
- let authorizationList = [];
2218
- if (!isDelegated2) {
2219
- const transactionNonce = await publicClient.getTransactionCount({
2220
- address: account.address,
2221
- blockTag: "pending"
2222
- });
2223
- const chainId = await publicClient.getChainId();
2224
- const authorizationNonce = transactionNonce + 1;
2225
- logger.debug("Using wallet client signing for EIP-7702 authorization");
2226
- const signedAuthorization = await walletClient.signAuthorization({
2227
- account: account.address,
2228
- contractAddress: environmentConfig.erc7702DelegatorAddress,
2229
- chainId,
2230
- nonce: Number(authorizationNonce)
2231
- });
2232
- authorizationList = [signedAuthorization];
2379
+ let authorizationList = providedAuthList || [];
2380
+ if (authorizationList.length === 0) {
2381
+ const isDelegated2 = await checkERC7702Delegation(
2382
+ publicClient,
2383
+ account.address,
2384
+ environmentConfig.erc7702DelegatorAddress
2385
+ );
2386
+ if (!isDelegated2) {
2387
+ const transactionNonce = await publicClient.getTransactionCount({
2388
+ address: account.address,
2389
+ blockTag: "pending"
2390
+ });
2391
+ const chainId = await publicClient.getChainId();
2392
+ const authorizationNonce = transactionNonce + 1;
2393
+ logger.debug("Using wallet client signing for EIP-7702 authorization");
2394
+ const signedAuthorization = await walletClient.signAuthorization({
2395
+ account,
2396
+ contractAddress: environmentConfig.erc7702DelegatorAddress,
2397
+ chainId,
2398
+ nonce: Number(authorizationNonce)
2399
+ });
2400
+ authorizationList = [signedAuthorization];
2401
+ }
2233
2402
  }
2234
2403
  if (pendingMessage) {
2235
2404
  logger.info(pendingMessage);
@@ -2244,6 +2413,9 @@ async function executeBatch(options, logger = noopLogger) {
2244
2413
  if (authorizationList.length > 0) {
2245
2414
  txRequest.authorizationList = authorizationList;
2246
2415
  }
2416
+ if (gas?.gasLimit) {
2417
+ txRequest.gas = gas.gasLimit;
2418
+ }
2247
2419
  if (gas?.maxFeePerGas) {
2248
2420
  txRequest.maxFeePerGas = gas.maxFeePerGas;
2249
2421
  }
@@ -3955,7 +4127,8 @@ async function executeDeployBatch(data, context, gas, logger = noopLogger) {
3955
4127
  environmentConfig: context.environmentConfig,
3956
4128
  executions: data.executions,
3957
4129
  pendingMessage,
3958
- gas
4130
+ gas,
4131
+ authorizationList: data.authorizationList
3959
4132
  },
3960
4133
  logger
3961
4134
  );
@@ -4066,7 +4239,8 @@ async function executeUpgradeBatch(data, context, gas, logger = noopLogger) {
4066
4239
  environmentConfig: context.environmentConfig,
4067
4240
  executions: data.executions,
4068
4241
  pendingMessage,
4069
- gas
4242
+ gas,
4243
+ authorizationList: data.authorizationList
4070
4244
  },
4071
4245
  logger
4072
4246
  );
@@ -4274,126 +4448,8 @@ async function calculatePermissionSignature(options) {
4274
4448
  return { signature, digest };
4275
4449
  }
4276
4450
 
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
-
4396
4451
  // src/client/common/utils/userapi.ts
4452
+ init_session();
4397
4453
  function isJsonObject(value) {
4398
4454
  return typeof value === "object" && value !== null && !Array.isArray(value);
4399
4455
  }
@@ -4410,7 +4466,7 @@ var CanViewAppLogsPermission = "0x2fd3f2fe";
4410
4466
  var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
4411
4467
  var CanUpdateAppProfilePermission = "0x036fef61";
4412
4468
  function getDefaultClientId() {
4413
- const version = true ? "0.2.2-dev" : "0.0.0";
4469
+ const version = true ? "0.3.0-dev.0" : "0.0.0";
4414
4470
  return `ecloud-sdk/v${version}`;
4415
4471
  }
4416
4472
  var UserApiClient = class {
@@ -5353,16 +5409,24 @@ async function prepareDeployFromVerifiableBuild(options, logger = defaultLogger)
5353
5409
  },
5354
5410
  logger
5355
5411
  );
5412
+ logger.debug("Checking delegation status...");
5413
+ const authorizationList = await createAuthorizationList({
5414
+ walletClient: batch.walletClient,
5415
+ publicClient: batch.publicClient,
5416
+ environmentConfig: batch.environmentConfig
5417
+ });
5356
5418
  logger.debug("Estimating gas...");
5357
5419
  const gasEstimate = await estimateBatchGas({
5358
5420
  publicClient: batch.publicClient,
5359
5421
  account: batch.walletClient.account.address,
5360
- executions: batch.executions
5422
+ executions: batch.executions,
5423
+ authorizationList
5361
5424
  });
5362
5425
  const data = {
5363
5426
  appId: batch.appId,
5364
5427
  salt: batch.salt,
5365
- executions: batch.executions
5428
+ executions: batch.executions,
5429
+ authorizationList
5366
5430
  };
5367
5431
  return {
5368
5432
  prepared: {
@@ -5591,16 +5655,24 @@ async function prepareDeploy(options, logger = defaultLogger) {
5591
5655
  },
5592
5656
  logger
5593
5657
  );
5658
+ logger.debug("Checking delegation status...");
5659
+ const authorizationList = await createAuthorizationList({
5660
+ walletClient: batch.walletClient,
5661
+ publicClient: batch.publicClient,
5662
+ environmentConfig: batch.environmentConfig
5663
+ });
5594
5664
  logger.debug("Estimating gas...");
5595
5665
  const gasEstimate = await estimateBatchGas({
5596
5666
  publicClient: batch.publicClient,
5597
5667
  account: batch.walletClient.account.address,
5598
- executions: batch.executions
5668
+ executions: batch.executions,
5669
+ authorizationList
5599
5670
  });
5600
5671
  const data = {
5601
5672
  appId: batch.appId,
5602
5673
  salt: batch.salt,
5603
- executions: batch.executions
5674
+ executions: batch.executions,
5675
+ authorizationList
5604
5676
  };
5605
5677
  return {
5606
5678
  prepared: {
@@ -5731,15 +5803,23 @@ async function prepareUpgradeFromVerifiableBuild(options, logger = defaultLogger
5731
5803
  needsPermissionChange,
5732
5804
  imageRef: options.imageRef
5733
5805
  });
5806
+ logger.debug("Checking delegation status...");
5807
+ const authorizationList = await createAuthorizationList({
5808
+ walletClient: batch.walletClient,
5809
+ publicClient: batch.publicClient,
5810
+ environmentConfig: batch.environmentConfig
5811
+ });
5734
5812
  logger.debug("Estimating gas...");
5735
5813
  const gasEstimate = await estimateBatchGas({
5736
5814
  publicClient: batch.publicClient,
5737
5815
  account: batch.walletClient.account.address,
5738
- executions: batch.executions
5816
+ executions: batch.executions,
5817
+ authorizationList
5739
5818
  });
5740
5819
  const data = {
5741
5820
  appId: batch.appId,
5742
- executions: batch.executions
5821
+ executions: batch.executions,
5822
+ authorizationList
5743
5823
  };
5744
5824
  return {
5745
5825
  prepared: {
@@ -5912,15 +5992,23 @@ async function prepareUpgrade(options, logger = defaultLogger) {
5912
5992
  needsPermissionChange,
5913
5993
  imageRef: finalImageRef
5914
5994
  });
5995
+ logger.debug("Checking delegation status...");
5996
+ const authorizationList = await createAuthorizationList({
5997
+ walletClient: batch.walletClient,
5998
+ publicClient: batch.publicClient,
5999
+ environmentConfig: batch.environmentConfig
6000
+ });
5915
6001
  logger.debug("Estimating gas...");
5916
6002
  const gasEstimate = await estimateBatchGas({
5917
6003
  publicClient: batch.publicClient,
5918
6004
  account: batch.walletClient.account.address,
5919
- executions: batch.executions
6005
+ executions: batch.executions,
6006
+ authorizationList
5920
6007
  });
5921
6008
  const data = {
5922
6009
  appId: batch.appId,
5923
- executions: batch.executions
6010
+ executions: batch.executions,
6011
+ authorizationList
5924
6012
  };
5925
6013
  return {
5926
6014
  prepared: {