@layr-labs/ecloud-sdk 0.3.0-dev.0 → 0.3.1-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.
package/dist/index.cjs CHANGED
@@ -5,9 +5,6 @@ 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
- };
11
8
  var __export = (target, all) => {
12
9
  for (var name in all)
13
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -30,135 +27,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
27
  ));
31
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
29
 
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
- async function isSessionValid(config) {
144
- const session = await getComputeApiSession(config);
145
- return session.authenticated;
146
- }
147
- var SessionError;
148
- var init_session = __esm({
149
- "src/client/common/auth/session.ts"() {
150
- "use strict";
151
- SessionError = class extends Error {
152
- constructor(message, code, statusCode) {
153
- super(message);
154
- this.code = code;
155
- this.statusCode = statusCode;
156
- this.name = "SessionError";
157
- }
158
- };
159
- }
160
- });
161
-
162
30
  // src/index.ts
163
31
  var index_exports = {};
164
32
  __export(index_exports, {
@@ -2446,7 +2314,7 @@ function encodeExecuteBatchData(executions) {
2446
2314
  });
2447
2315
  }
2448
2316
  async function estimateBatchGas(options) {
2449
- const { publicClient, account, executions, authorizationList } = options;
2317
+ const { publicClient, account, executions } = options;
2450
2318
  const executeBatchData = encodeExecuteBatchData(executions);
2451
2319
  const [gasTipCap, block, estimatedGas] = await Promise.all([
2452
2320
  publicClient.estimateMaxPriorityFeePerGas(),
@@ -2454,8 +2322,7 @@ async function estimateBatchGas(options) {
2454
2322
  publicClient.estimateGas({
2455
2323
  account,
2456
2324
  to: account,
2457
- data: executeBatchData,
2458
- authorizationList
2325
+ data: executeBatchData
2459
2326
  })
2460
2327
  ]);
2461
2328
  const baseFee = block.baseFeePerGas ?? 0n;
@@ -2478,44 +2345,8 @@ async function checkERC7702Delegation(publicClient, account, delegatorAddress) {
2478
2345
  const expectedCode = `0xef0100${delegatorAddress.slice(2)}`;
2479
2346
  return code.toLowerCase() === expectedCode.toLowerCase();
2480
2347
  }
2481
- async function createAuthorizationList(options) {
2482
- const { walletClient, publicClient, environmentConfig } = options;
2483
- const account = walletClient.account;
2484
- if (!account) {
2485
- throw new Error("Wallet client must have an account");
2486
- }
2487
- const isDelegated2 = await checkERC7702Delegation(
2488
- publicClient,
2489
- account.address,
2490
- environmentConfig.erc7702DelegatorAddress
2491
- );
2492
- if (isDelegated2) {
2493
- return void 0;
2494
- }
2495
- const transactionNonce = await publicClient.getTransactionCount({
2496
- address: account.address,
2497
- blockTag: "pending"
2498
- });
2499
- const chainId = await publicClient.getChainId();
2500
- const authorizationNonce = transactionNonce + 1;
2501
- const signedAuthorization = await walletClient.signAuthorization({
2502
- account,
2503
- contractAddress: environmentConfig.erc7702DelegatorAddress,
2504
- chainId,
2505
- nonce: Number(authorizationNonce)
2506
- });
2507
- return [signedAuthorization];
2508
- }
2509
2348
  async function executeBatch(options, logger = noopLogger) {
2510
- const {
2511
- walletClient,
2512
- publicClient,
2513
- environmentConfig,
2514
- executions,
2515
- pendingMessage,
2516
- gas,
2517
- authorizationList: providedAuthList
2518
- } = options;
2349
+ const { walletClient, publicClient, environmentConfig, executions, pendingMessage, gas } = options;
2519
2350
  const account = walletClient.account;
2520
2351
  if (!account) {
2521
2352
  throw new Error("Wallet client must have an account");
@@ -2525,29 +2356,27 @@ async function executeBatch(options, logger = noopLogger) {
2525
2356
  throw new Error("Wallet client must have a chain");
2526
2357
  }
2527
2358
  const executeBatchData = encodeExecuteBatchData(executions);
2528
- let authorizationList = providedAuthList || [];
2529
- if (authorizationList.length === 0) {
2530
- const isDelegated2 = await checkERC7702Delegation(
2531
- publicClient,
2532
- account.address,
2533
- environmentConfig.erc7702DelegatorAddress
2534
- );
2535
- if (!isDelegated2) {
2536
- const transactionNonce = await publicClient.getTransactionCount({
2537
- address: account.address,
2538
- blockTag: "pending"
2539
- });
2540
- const chainId = await publicClient.getChainId();
2541
- const authorizationNonce = transactionNonce + 1;
2542
- logger.debug("Using wallet client signing for EIP-7702 authorization");
2543
- const signedAuthorization = await walletClient.signAuthorization({
2544
- account,
2545
- contractAddress: environmentConfig.erc7702DelegatorAddress,
2546
- chainId,
2547
- nonce: Number(authorizationNonce)
2548
- });
2549
- authorizationList = [signedAuthorization];
2550
- }
2359
+ const isDelegated2 = await checkERC7702Delegation(
2360
+ publicClient,
2361
+ account.address,
2362
+ environmentConfig.erc7702DelegatorAddress
2363
+ );
2364
+ let authorizationList = [];
2365
+ if (!isDelegated2) {
2366
+ const transactionNonce = await publicClient.getTransactionCount({
2367
+ address: account.address,
2368
+ blockTag: "pending"
2369
+ });
2370
+ const chainId = await publicClient.getChainId();
2371
+ const authorizationNonce = transactionNonce + 1;
2372
+ logger.debug("Using wallet client signing for EIP-7702 authorization");
2373
+ const signedAuthorization = await walletClient.signAuthorization({
2374
+ account: account.address,
2375
+ contractAddress: environmentConfig.erc7702DelegatorAddress,
2376
+ chainId,
2377
+ nonce: Number(authorizationNonce)
2378
+ });
2379
+ authorizationList = [signedAuthorization];
2551
2380
  }
2552
2381
  if (pendingMessage) {
2553
2382
  logger.info(pendingMessage);
@@ -2562,9 +2391,6 @@ async function executeBatch(options, logger = noopLogger) {
2562
2391
  if (authorizationList.length > 0) {
2563
2392
  txRequest.authorizationList = authorizationList;
2564
2393
  }
2565
- if (gas?.gasLimit) {
2566
- txRequest.gas = gas.gasLimit;
2567
- }
2568
2394
  if (gas?.maxFeePerGas) {
2569
2395
  txRequest.maxFeePerGas = gas.maxFeePerGas;
2570
2396
  }
@@ -4313,8 +4139,7 @@ async function executeDeployBatch(data, context, gas, logger = noopLogger) {
4313
4139
  environmentConfig: context.environmentConfig,
4314
4140
  executions: data.executions,
4315
4141
  pendingMessage,
4316
- gas,
4317
- authorizationList: data.authorizationList
4142
+ gas
4318
4143
  },
4319
4144
  logger
4320
4145
  );
@@ -4425,8 +4250,7 @@ async function executeUpgradeBatch(data, context, gas, logger = noopLogger) {
4425
4250
  environmentConfig: context.environmentConfig,
4426
4251
  executions: data.executions,
4427
4252
  pendingMessage,
4428
- gas,
4429
- authorizationList: data.authorizationList
4253
+ gas
4430
4254
  },
4431
4255
  logger
4432
4256
  );
@@ -4736,60 +4560,182 @@ async function calculateBillingAuthSignature(options) {
4736
4560
  return { signature, expiry };
4737
4561
  }
4738
4562
 
4739
- // src/client/common/utils/userapi.ts
4740
- init_session();
4741
- function isJsonObject(value) {
4742
- return typeof value === "object" && value !== null && !Array.isArray(value);
4743
- }
4744
- function readString(obj, key) {
4745
- const v = obj[key];
4746
- return typeof v === "string" ? v : void 0;
4747
- }
4748
- function readNumber(obj, key) {
4749
- const v = obj[key];
4750
- return typeof v === "number" && Number.isFinite(v) ? v : void 0;
4563
+ // src/client/common/auth/session.ts
4564
+ var SessionError = class extends Error {
4565
+ constructor(message, code, statusCode) {
4566
+ super(message);
4567
+ this.code = code;
4568
+ this.statusCode = statusCode;
4569
+ this.name = "SessionError";
4570
+ }
4571
+ };
4572
+ function stripHexPrefix2(hex) {
4573
+ return hex.startsWith("0x") ? hex.slice(2) : hex;
4751
4574
  }
4752
- var MAX_ADDRESS_COUNT = 5;
4753
- var CanViewAppLogsPermission = "0x2fd3f2fe";
4754
- var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
4755
- var CanUpdateAppProfilePermission = "0x036fef61";
4756
- function getDefaultClientId() {
4757
- const version = true ? "0.3.0-dev.0" : "0.0.0";
4758
- return `ecloud-sdk/v${version}`;
4575
+ async function parseErrorResponse(response) {
4576
+ try {
4577
+ const data = await response.json();
4578
+ return data.error || response.statusText;
4579
+ } catch {
4580
+ return response.statusText;
4581
+ }
4759
4582
  }
4760
- var UserApiClient = class {
4761
- constructor(config, walletClient, publicClient, options) {
4762
- this.config = config;
4763
- this.walletClient = walletClient;
4764
- this.publicClient = publicClient;
4765
- this.clientId = options?.clientId || getDefaultClientId();
4766
- this.useSession = options?.useSession ?? false;
4583
+ async function loginToComputeApi(config, request) {
4584
+ let response;
4585
+ try {
4586
+ response = await fetch(`${config.baseUrl}/auth/siwe/login`, {
4587
+ method: "POST",
4588
+ credentials: "include",
4589
+ // Include cookies for session management
4590
+ headers: {
4591
+ "Content-Type": "application/json"
4592
+ },
4593
+ body: JSON.stringify({
4594
+ message: request.message,
4595
+ signature: stripHexPrefix2(request.signature)
4596
+ })
4597
+ });
4598
+ } catch (error) {
4599
+ throw new SessionError(
4600
+ `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
4601
+ "NETWORK_ERROR"
4602
+ );
4767
4603
  }
4768
- /**
4769
- * Get the address of the connected wallet
4770
- */
4771
- get address() {
4772
- const account = this.walletClient.account;
4773
- if (!account) {
4774
- throw new Error("WalletClient must have an account attached");
4604
+ if (!response.ok) {
4605
+ const errorMessage = await parseErrorResponse(response);
4606
+ const status = response.status;
4607
+ if (status === 400) {
4608
+ if (errorMessage.toLowerCase().includes("siwe")) {
4609
+ throw new SessionError(`Invalid SIWE message: ${errorMessage}`, "INVALID_MESSAGE", status);
4610
+ }
4611
+ throw new SessionError(`Bad request: ${errorMessage}`, "INVALID_MESSAGE", status);
4775
4612
  }
4776
- return account.address;
4613
+ if (status === 401) {
4614
+ throw new SessionError(`Invalid signature: ${errorMessage}`, "INVALID_SIGNATURE", status);
4615
+ }
4616
+ throw new SessionError(`Login failed: ${errorMessage}`, "UNKNOWN", status);
4777
4617
  }
4778
- async getInfos(appIDs, addressCount = 1) {
4779
- const count = Math.min(addressCount, MAX_ADDRESS_COUNT);
4780
- const endpoint = `${this.config.userApiServerURL}/info`;
4781
- const url = `${endpoint}?${new URLSearchParams({ apps: appIDs.join(",") })}`;
4782
- const res = await this.makeAuthenticatedRequest(url, CanViewSensitiveAppInfoPermission);
4783
- const result = await res.json();
4784
- return result.apps.map((app, i) => {
4785
- const evmAddresses = app.addresses?.data?.evmAddresses?.slice(0, count) || [];
4786
- const solanaAddresses = app.addresses?.data?.solanaAddresses?.slice(0, count) || [];
4787
- return {
4788
- address: appIDs[i],
4789
- status: app.app_status,
4790
- ip: app.ip,
4791
- machineType: app.machine_type,
4792
- profile: app.profile,
4618
+ const data = await response.json();
4619
+ return {
4620
+ success: data.success,
4621
+ address: data.address
4622
+ };
4623
+ }
4624
+ async function getComputeApiSession(config) {
4625
+ let response;
4626
+ try {
4627
+ response = await fetch(`${config.baseUrl}/auth/session`, {
4628
+ method: "GET",
4629
+ credentials: "include",
4630
+ // Include cookies for session management
4631
+ headers: {
4632
+ "Content-Type": "application/json"
4633
+ }
4634
+ });
4635
+ } catch {
4636
+ return {
4637
+ authenticated: false
4638
+ };
4639
+ }
4640
+ if (response.status === 401) {
4641
+ return {
4642
+ authenticated: false
4643
+ };
4644
+ }
4645
+ if (!response.ok) {
4646
+ const errorMessage = await parseErrorResponse(response);
4647
+ throw new SessionError(`Failed to get session: ${errorMessage}`, "UNKNOWN", response.status);
4648
+ }
4649
+ const data = await response.json();
4650
+ return {
4651
+ authenticated: data.authenticated,
4652
+ address: data.address,
4653
+ chainId: data.chain_id
4654
+ };
4655
+ }
4656
+ async function logoutFromComputeApi(config) {
4657
+ let response;
4658
+ try {
4659
+ response = await fetch(`${config.baseUrl}/auth/logout`, {
4660
+ method: "POST",
4661
+ credentials: "include",
4662
+ // Include cookies for session management
4663
+ headers: {
4664
+ "Content-Type": "application/json"
4665
+ }
4666
+ });
4667
+ } catch (error) {
4668
+ throw new SessionError(
4669
+ `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
4670
+ "NETWORK_ERROR"
4671
+ );
4672
+ }
4673
+ if (response.status === 401) {
4674
+ return;
4675
+ }
4676
+ if (!response.ok) {
4677
+ const errorMessage = await parseErrorResponse(response);
4678
+ throw new SessionError(`Logout failed: ${errorMessage}`, "UNKNOWN", response.status);
4679
+ }
4680
+ }
4681
+ async function isSessionValid(config) {
4682
+ const session = await getComputeApiSession(config);
4683
+ return session.authenticated;
4684
+ }
4685
+
4686
+ // src/client/common/utils/userapi.ts
4687
+ function isJsonObject(value) {
4688
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4689
+ }
4690
+ function readString(obj, key) {
4691
+ const v = obj[key];
4692
+ return typeof v === "string" ? v : void 0;
4693
+ }
4694
+ function readNumber(obj, key) {
4695
+ const v = obj[key];
4696
+ return typeof v === "number" && Number.isFinite(v) ? v : void 0;
4697
+ }
4698
+ var MAX_ADDRESS_COUNT = 5;
4699
+ var CanViewAppLogsPermission = "0x2fd3f2fe";
4700
+ var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
4701
+ var CanUpdateAppProfilePermission = "0x036fef61";
4702
+ function getDefaultClientId() {
4703
+ const version = true ? "0.3.1-dev" : "0.0.0";
4704
+ return `ecloud-sdk/v${version}`;
4705
+ }
4706
+ var UserApiClient = class {
4707
+ constructor(config, walletClient, publicClient, options) {
4708
+ this.config = config;
4709
+ this.walletClient = walletClient;
4710
+ this.publicClient = publicClient;
4711
+ this.clientId = options?.clientId || getDefaultClientId();
4712
+ this.useSession = options?.useSession ?? false;
4713
+ }
4714
+ /**
4715
+ * Get the address of the connected wallet
4716
+ */
4717
+ get address() {
4718
+ const account = this.walletClient.account;
4719
+ if (!account) {
4720
+ throw new Error("WalletClient must have an account attached");
4721
+ }
4722
+ return account.address;
4723
+ }
4724
+ async getInfos(appIDs, addressCount = 1) {
4725
+ const count = Math.min(addressCount, MAX_ADDRESS_COUNT);
4726
+ const endpoint = `${this.config.userApiServerURL}/info`;
4727
+ const url = `${endpoint}?${new URLSearchParams({ apps: appIDs.join(",") })}`;
4728
+ const res = await this.makeAuthenticatedRequest(url, CanViewSensitiveAppInfoPermission);
4729
+ const result = await res.json();
4730
+ return result.apps.map((app, i) => {
4731
+ const evmAddresses = app.addresses?.data?.evmAddresses?.slice(0, count) || [];
4732
+ const solanaAddresses = app.addresses?.data?.solanaAddresses?.slice(0, count) || [];
4733
+ return {
4734
+ address: appIDs[i],
4735
+ status: app.app_status,
4736
+ ip: app.ip,
4737
+ machineType: app.machine_type,
4738
+ profile: app.profile,
4793
4739
  metrics: app.metrics,
4794
4740
  evmAddresses,
4795
4741
  solanaAddresses
@@ -5662,214 +5608,21 @@ function isSubscriptionActive(status) {
5662
5608
 
5663
5609
  // src/client/common/utils/billingapi.ts
5664
5610
  var import_axios2 = __toESM(require("axios"), 1);
5665
-
5666
- // src/client/common/auth/billingSession.ts
5667
- var BillingSessionError = class extends Error {
5668
- constructor(message, code, statusCode) {
5669
- super(message);
5670
- this.code = code;
5671
- this.statusCode = statusCode;
5672
- this.name = "BillingSessionError";
5673
- }
5674
- };
5675
- function stripHexPrefix3(hex) {
5676
- return hex.startsWith("0x") ? hex.slice(2) : hex;
5677
- }
5678
- async function parseErrorResponse2(response) {
5679
- try {
5680
- const data = await response.json();
5681
- return data.error || response.statusText;
5682
- } catch {
5683
- return response.statusText;
5684
- }
5685
- }
5686
- async function loginToBillingApi(config, request) {
5687
- let response;
5688
- try {
5689
- response = await fetch(`${config.baseUrl}/auth/siwe/login`, {
5690
- method: "POST",
5691
- credentials: "include",
5692
- // Include cookies for session management
5693
- headers: {
5694
- "Content-Type": "application/json"
5695
- },
5696
- body: JSON.stringify({
5697
- message: request.message,
5698
- signature: stripHexPrefix3(request.signature)
5699
- })
5700
- });
5701
- } catch (error) {
5702
- throw new BillingSessionError(
5703
- `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
5704
- "NETWORK_ERROR"
5705
- );
5706
- }
5707
- if (!response.ok) {
5708
- const errorMessage = await parseErrorResponse2(response);
5709
- const status = response.status;
5710
- if (status === 400) {
5711
- if (errorMessage.toLowerCase().includes("siwe")) {
5712
- throw new BillingSessionError(`Invalid SIWE message: ${errorMessage}`, "INVALID_MESSAGE", status);
5713
- }
5714
- throw new BillingSessionError(`Bad request: ${errorMessage}`, "INVALID_MESSAGE", status);
5715
- }
5716
- if (status === 401) {
5717
- throw new BillingSessionError(`Invalid signature: ${errorMessage}`, "INVALID_SIGNATURE", status);
5718
- }
5719
- throw new BillingSessionError(`Login failed: ${errorMessage}`, "UNKNOWN", status);
5720
- }
5721
- const data = await response.json();
5722
- return {
5723
- success: data.success,
5724
- address: data.address
5725
- };
5726
- }
5727
- async function getBillingApiSession(config) {
5728
- let response;
5729
- try {
5730
- response = await fetch(`${config.baseUrl}/auth/session`, {
5731
- method: "GET",
5732
- credentials: "include",
5733
- // Include cookies for session management
5734
- headers: {
5735
- "Content-Type": "application/json"
5736
- }
5737
- });
5738
- } catch {
5739
- return {
5740
- authenticated: false
5741
- };
5742
- }
5743
- if (response.status === 401) {
5744
- return {
5745
- authenticated: false
5746
- };
5747
- }
5748
- if (!response.ok) {
5749
- const errorMessage = await parseErrorResponse2(response);
5750
- throw new BillingSessionError(`Failed to get session: ${errorMessage}`, "UNKNOWN", response.status);
5751
- }
5752
- const data = await response.json();
5753
- return {
5754
- authenticated: data.authenticated,
5755
- address: data.address,
5756
- chainId: data.chainId,
5757
- authenticatedAt: data.authenticatedAt
5758
- };
5759
- }
5760
- async function logoutFromBillingApi(config) {
5761
- let response;
5762
- try {
5763
- response = await fetch(`${config.baseUrl}/auth/logout`, {
5764
- method: "POST",
5765
- credentials: "include",
5766
- // Include cookies for session management
5767
- headers: {
5768
- "Content-Type": "application/json"
5769
- }
5770
- });
5771
- } catch (error) {
5772
- throw new BillingSessionError(
5773
- `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
5774
- "NETWORK_ERROR"
5775
- );
5776
- }
5777
- if (response.status === 401) {
5778
- return;
5779
- }
5780
- if (!response.ok) {
5781
- const errorMessage = await parseErrorResponse2(response);
5782
- throw new BillingSessionError(`Logout failed: ${errorMessage}`, "UNKNOWN", response.status);
5783
- }
5784
- }
5785
-
5786
- // src/client/common/utils/billingapi.ts
5787
5611
  var BillingApiClient = class {
5788
- constructor(config, walletClient, options = {}) {
5612
+ constructor(config, walletClient) {
5789
5613
  this.config = config;
5790
5614
  this.walletClient = walletClient;
5791
- this.options = options;
5792
- this.useSession = options.useSession ?? false;
5793
- if (!this.useSession && !walletClient) {
5794
- throw new Error("WalletClient is required when not using session authentication");
5795
- }
5796
5615
  }
5797
5616
  /**
5798
5617
  * Get the address of the connected wallet
5799
- * Returns undefined if using session auth without a wallet client
5800
5618
  */
5801
5619
  get address() {
5802
- const account = this.walletClient?.account;
5620
+ const account = this.walletClient.account;
5803
5621
  if (!account) {
5804
- if (!this.useSession) {
5805
- throw new Error("WalletClient must have an account attached");
5806
- }
5807
- return void 0;
5622
+ throw new Error("WalletClient must have an account attached");
5808
5623
  }
5809
5624
  return account.address;
5810
5625
  }
5811
- /**
5812
- * Get the base URL of the billing API
5813
- */
5814
- get baseUrl() {
5815
- return this.config.billingApiServerURL;
5816
- }
5817
- // ==========================================================================
5818
- // SIWE Session Methods
5819
- // ==========================================================================
5820
- /**
5821
- * Login to the billing API using SIWE
5822
- *
5823
- * This establishes a session with the billing API by verifying the SIWE message
5824
- * and signature. On success, a session cookie is set in the browser.
5825
- *
5826
- * @param request - Login request containing SIWE message and signature
5827
- * @returns Login result with the authenticated address
5828
- *
5829
- * @example
5830
- * ```typescript
5831
- * const { message } = createSiweMessage({
5832
- * address: userAddress,
5833
- * chainId: 11155111,
5834
- * domain: window.location.host,
5835
- * uri: window.location.origin,
5836
- * });
5837
- *
5838
- * const signature = await signMessageAsync({ message });
5839
- * const result = await billingClient.siweLogin({ message, signature });
5840
- * ```
5841
- */
5842
- async siweLogin(request) {
5843
- return loginToBillingApi({ baseUrl: this.baseUrl }, request);
5844
- }
5845
- /**
5846
- * Logout from the billing API
5847
- *
5848
- * This destroys the current session and clears the session cookie.
5849
- */
5850
- async siweLogout() {
5851
- return logoutFromBillingApi({ baseUrl: this.baseUrl });
5852
- }
5853
- /**
5854
- * Get the current session status from the billing API
5855
- *
5856
- * @returns Session information including authentication status and address
5857
- */
5858
- async getSession() {
5859
- return getBillingApiSession({ baseUrl: this.baseUrl });
5860
- }
5861
- /**
5862
- * Check if there is a valid session
5863
- *
5864
- * @returns True if session is authenticated, false otherwise
5865
- */
5866
- async isSessionValid() {
5867
- const session = await this.getSession();
5868
- return session.authenticated;
5869
- }
5870
- // ==========================================================================
5871
- // Subscription Methods
5872
- // ==========================================================================
5873
5626
  async createSubscription(productId = "compute", options) {
5874
5627
  const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;
5875
5628
  const body = options ? {
@@ -5888,72 +5641,10 @@ var BillingApiClient = class {
5888
5641
  const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;
5889
5642
  await this.makeAuthenticatedRequest(endpoint, "DELETE", productId);
5890
5643
  }
5891
- // ==========================================================================
5892
- // Internal Methods
5893
- // ==========================================================================
5894
5644
  /**
5895
5645
  * Make an authenticated request to the billing API
5896
- *
5897
- * Uses session auth if useSession is true, otherwise uses EIP-712 signature auth.
5898
5646
  */
5899
5647
  async makeAuthenticatedRequest(url, method, productId, body) {
5900
- if (this.useSession) {
5901
- return this.makeSessionAuthenticatedRequest(url, method, body);
5902
- }
5903
- return this.makeSignatureAuthenticatedRequest(url, method, productId, body);
5904
- }
5905
- /**
5906
- * Make a request using session-based authentication (cookies)
5907
- */
5908
- async makeSessionAuthenticatedRequest(url, method, body) {
5909
- const headers = {};
5910
- if (body) {
5911
- headers["Content-Type"] = "application/json";
5912
- }
5913
- try {
5914
- const response = await fetch(url, {
5915
- method,
5916
- credentials: "include",
5917
- // Include cookies for session management
5918
- headers,
5919
- body: body ? JSON.stringify(body) : void 0
5920
- });
5921
- const status = response.status;
5922
- const statusText = status >= 200 && status < 300 ? "OK" : "Error";
5923
- if (status < 200 || status >= 300) {
5924
- let errorBody;
5925
- try {
5926
- errorBody = await response.text();
5927
- } catch {
5928
- errorBody = statusText;
5929
- }
5930
- throw new Error(`BillingAPI request failed: ${status} ${statusText} - ${errorBody}`);
5931
- }
5932
- const responseData = await response.json();
5933
- return {
5934
- json: async () => responseData,
5935
- text: async () => JSON.stringify(responseData)
5936
- };
5937
- } catch (error) {
5938
- if (error.name === "TypeError" || error.message?.includes("fetch")) {
5939
- throw new Error(
5940
- `Failed to connect to BillingAPI at ${url}: ${error.message}
5941
- Please check:
5942
- 1. Your internet connection
5943
- 2. The API server is accessible: ${this.config.billingApiServerURL}
5944
- 3. Firewall/proxy settings`
5945
- );
5946
- }
5947
- throw error;
5948
- }
5949
- }
5950
- /**
5951
- * Make a request using EIP-712 signature authentication
5952
- */
5953
- async makeSignatureAuthenticatedRequest(url, method, productId, body) {
5954
- if (!this.walletClient) {
5955
- throw new Error("WalletClient is required for signature authentication");
5956
- }
5957
5648
  const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
5958
5649
  const { signature } = await calculateBillingAuthSignature({
5959
5650
  walletClient: this.walletClient,
@@ -6273,24 +5964,16 @@ async function prepareDeployFromVerifiableBuild(options, logger = defaultLogger)
6273
5964
  },
6274
5965
  logger
6275
5966
  );
6276
- logger.debug("Checking delegation status...");
6277
- const authorizationList = await createAuthorizationList({
6278
- walletClient: batch.walletClient,
6279
- publicClient: batch.publicClient,
6280
- environmentConfig: batch.environmentConfig
6281
- });
6282
5967
  logger.debug("Estimating gas...");
6283
5968
  const gasEstimate = await estimateBatchGas({
6284
5969
  publicClient: batch.publicClient,
6285
5970
  account: batch.walletClient.account.address,
6286
- executions: batch.executions,
6287
- authorizationList
5971
+ executions: batch.executions
6288
5972
  });
6289
5973
  const data = {
6290
5974
  appId: batch.appId,
6291
5975
  salt: batch.salt,
6292
- executions: batch.executions,
6293
- authorizationList
5976
+ executions: batch.executions
6294
5977
  };
6295
5978
  return {
6296
5979
  prepared: {
@@ -6519,24 +6202,16 @@ async function prepareDeploy(options, logger = defaultLogger) {
6519
6202
  },
6520
6203
  logger
6521
6204
  );
6522
- logger.debug("Checking delegation status...");
6523
- const authorizationList = await createAuthorizationList({
6524
- walletClient: batch.walletClient,
6525
- publicClient: batch.publicClient,
6526
- environmentConfig: batch.environmentConfig
6527
- });
6528
6205
  logger.debug("Estimating gas...");
6529
6206
  const gasEstimate = await estimateBatchGas({
6530
6207
  publicClient: batch.publicClient,
6531
6208
  account: batch.walletClient.account.address,
6532
- executions: batch.executions,
6533
- authorizationList
6209
+ executions: batch.executions
6534
6210
  });
6535
6211
  const data = {
6536
6212
  appId: batch.appId,
6537
6213
  salt: batch.salt,
6538
- executions: batch.executions,
6539
- authorizationList
6214
+ executions: batch.executions
6540
6215
  };
6541
6216
  return {
6542
6217
  prepared: {
@@ -6667,23 +6342,15 @@ async function prepareUpgradeFromVerifiableBuild(options, logger = defaultLogger
6667
6342
  needsPermissionChange,
6668
6343
  imageRef: options.imageRef
6669
6344
  });
6670
- logger.debug("Checking delegation status...");
6671
- const authorizationList = await createAuthorizationList({
6672
- walletClient: batch.walletClient,
6673
- publicClient: batch.publicClient,
6674
- environmentConfig: batch.environmentConfig
6675
- });
6676
6345
  logger.debug("Estimating gas...");
6677
6346
  const gasEstimate = await estimateBatchGas({
6678
6347
  publicClient: batch.publicClient,
6679
6348
  account: batch.walletClient.account.address,
6680
- executions: batch.executions,
6681
- authorizationList
6349
+ executions: batch.executions
6682
6350
  });
6683
6351
  const data = {
6684
6352
  appId: batch.appId,
6685
- executions: batch.executions,
6686
- authorizationList
6353
+ executions: batch.executions
6687
6354
  };
6688
6355
  return {
6689
6356
  prepared: {
@@ -6856,23 +6523,15 @@ async function prepareUpgrade(options, logger = defaultLogger) {
6856
6523
  needsPermissionChange,
6857
6524
  imageRef: finalImageRef
6858
6525
  });
6859
- logger.debug("Checking delegation status...");
6860
- const authorizationList = await createAuthorizationList({
6861
- walletClient: batch.walletClient,
6862
- publicClient: batch.publicClient,
6863
- environmentConfig: batch.environmentConfig
6864
- });
6865
6526
  logger.debug("Estimating gas...");
6866
6527
  const gasEstimate = await estimateBatchGas({
6867
6528
  publicClient: batch.publicClient,
6868
6529
  account: batch.walletClient.account.address,
6869
- executions: batch.executions,
6870
- authorizationList
6530
+ executions: batch.executions
6871
6531
  });
6872
6532
  const data = {
6873
6533
  appId: batch.appId,
6874
- executions: batch.executions,
6875
- authorizationList
6534
+ executions: batch.executions
6876
6535
  };
6877
6536
  return {
6878
6537
  prepared: {
@@ -8000,10 +7659,7 @@ function createBillingModule(config) {
8000
7659
  };
8001
7660
  }
8002
7661
  logger.debug(`Creating subscription for ${productId}...`);
8003
- const result = await billingApi.createSubscription(productId, {
8004
- successUrl: opts?.successUrl,
8005
- cancelUrl: opts?.cancelUrl
8006
- });
7662
+ const result = await billingApi.createSubscription(productId);
8007
7663
  logger.debug(`Checkout URL: ${result.checkoutUrl}`);
8008
7664
  return {
8009
7665
  type: "checkout_created",
@@ -8095,22 +7751,9 @@ async function requestWithRetry(config) {
8095
7751
  }
8096
7752
  var BuildApiClient = class {
8097
7753
  constructor(options) {
8098
- let url = options.baseUrl;
8099
- while (url.endsWith("/")) {
8100
- url = url.slice(0, -1);
8101
- }
8102
- this.baseUrl = url;
7754
+ this.baseUrl = options.baseUrl.replace(/\/+$/, "");
8103
7755
  this.clientId = options.clientId;
8104
7756
  this.walletClient = options.walletClient;
8105
- this.useSession = options.useSession ?? false;
8106
- this.billingSessionId = options.billingSessionId;
8107
- }
8108
- /**
8109
- * Update the billing session ID.
8110
- * Call this after logging into the billing API to enable session-based auth for builds.
8111
- */
8112
- setBillingSessionId(sessionId) {
8113
- this.billingSessionId = sessionId;
8114
7757
  }
8115
7758
  /**
8116
7759
  * Get the address of the connected wallet
@@ -8122,17 +7765,8 @@ var BuildApiClient = class {
8122
7765
  }
8123
7766
  return account.address;
8124
7767
  }
8125
- /**
8126
- * Submit a new build request.
8127
- * Supports two auth modes (session auth is tried first when billingSessionId is available):
8128
- * 1. Session-based auth: X-Billing-Session header (forwarded billing_session cookie)
8129
- * 2. Signature-based auth: Authorization + X-Account + X-eigenx-expiry headers (requires walletClient)
8130
- */
8131
7768
  async submitBuild(payload) {
8132
- if (this.useSession && this.billingSessionId) {
8133
- return this.billingSessionAuthJsonRequest("/builds", "POST", payload);
8134
- }
8135
- return this.signatureAuthJsonRequest("/builds", "POST", payload);
7769
+ return this.authenticatedJsonRequest("/builds", "POST", payload);
8136
7770
  }
8137
7771
  async getBuild(buildId) {
8138
7772
  return this.publicJsonRequest(`/builds/${encodeURIComponent(buildId)}`);
@@ -8143,11 +7777,8 @@ var BuildApiClient = class {
8143
7777
  async verify(identifier) {
8144
7778
  return this.publicJsonRequest(`/builds/verify/${encodeURIComponent(identifier)}`);
8145
7779
  }
8146
- /**
8147
- * Get build logs. Supports session auth (identity verification only, no billing check).
8148
- */
8149
7780
  async getLogs(buildId) {
8150
- return this.sessionOrSignatureTextRequest(`/builds/${encodeURIComponent(buildId)}/logs`);
7781
+ return this.authenticatedTextRequest(`/builds/${encodeURIComponent(buildId)}/logs`);
8151
7782
  }
8152
7783
  async listBuilds(params) {
8153
7784
  const res = await requestWithRetry({
@@ -8155,9 +7786,7 @@ var BuildApiClient = class {
8155
7786
  method: "GET",
8156
7787
  params,
8157
7788
  headers: this.clientId ? { "x-client-id": this.clientId } : void 0,
8158
- timeout: 6e4,
8159
- validateStatus: () => true,
8160
- withCredentials: this.useSession
7789
+ timeout: 6e4
8161
7790
  });
8162
7791
  if (res.status < 200 || res.status >= 300) throw buildApiHttpError(res);
8163
7792
  return res.data;
@@ -8167,18 +7796,12 @@ var BuildApiClient = class {
8167
7796
  url: `${this.baseUrl}${path8}`,
8168
7797
  method: "GET",
8169
7798
  headers: this.clientId ? { "x-client-id": this.clientId } : void 0,
8170
- timeout: 6e4,
8171
- validateStatus: () => true,
8172
- withCredentials: this.useSession
7799
+ timeout: 6e4
8173
7800
  });
8174
7801
  if (res.status < 200 || res.status >= 300) throw buildApiHttpError(res);
8175
7802
  return res.data;
8176
7803
  }
8177
- /**
8178
- * Make a request that ALWAYS requires signature auth (for billing verification).
8179
- * Used for endpoints like POST /builds that need to verify subscription status.
8180
- */
8181
- async signatureAuthJsonRequest(path8, method, body) {
7804
+ async authenticatedJsonRequest(path8, method, body) {
8182
7805
  if (!this.walletClient?.account) {
8183
7806
  throw new Error("WalletClient with account required for authenticated requests");
8184
7807
  }
@@ -8200,69 +7823,32 @@ var BuildApiClient = class {
8200
7823
  method,
8201
7824
  headers,
8202
7825
  data: body,
8203
- timeout: 6e4,
8204
- validateStatus: () => true,
8205
- withCredentials: this.useSession
7826
+ timeout: 6e4
8206
7827
  });
8207
7828
  if (res.status < 200 || res.status >= 300) throw buildApiHttpError(res);
8208
7829
  return res.data;
8209
7830
  }
8210
- /**
8211
- * Make a request using billing session auth (for billing verification without wallet signature).
8212
- * Forwards the billing_session cookie value via X-Billing-Session header.
8213
- * Used for endpoints that need to verify subscription status when using session-based auth.
8214
- */
8215
- async billingSessionAuthJsonRequest(path8, method, body) {
8216
- if (!this.billingSessionId) {
8217
- throw new Error("billingSessionId required for session-based billing auth");
7831
+ async authenticatedTextRequest(path8) {
7832
+ if (!this.walletClient?.account) {
7833
+ throw new Error("WalletClient with account required for authenticated requests");
8218
7834
  }
8219
- const headers = {
8220
- "Content-Type": "application/json",
8221
- "X-Billing-Session": this.billingSessionId
8222
- };
8223
- if (this.clientId) headers["x-client-id"] = this.clientId;
8224
- const res = await requestWithRetry({
8225
- url: `${this.baseUrl}${path8}`,
8226
- method,
8227
- headers,
8228
- data: body,
8229
- timeout: 6e4,
8230
- validateStatus: () => true,
8231
- withCredentials: this.useSession
8232
- });
8233
- if (res.status < 200 || res.status >= 300) throw buildApiHttpError(res);
8234
- return res.data;
8235
- }
8236
- /**
8237
- * Make an authenticated request that can use session OR signature auth.
8238
- * When useSession is true, relies on cookies for identity verification.
8239
- * Used for endpoints that only need identity verification (not billing).
8240
- */
8241
- async sessionOrSignatureTextRequest(path8) {
8242
7835
  const headers = {};
8243
7836
  if (this.clientId) headers["x-client-id"] = this.clientId;
8244
- if (!this.useSession) {
8245
- if (!this.walletClient?.account) {
8246
- throw new Error("WalletClient with account required for authenticated requests");
8247
- }
8248
- const expiry = BigInt(Math.floor(Date.now() / 1e3) + 60);
8249
- const { signature } = await calculateBillingAuthSignature({
8250
- walletClient: this.walletClient,
8251
- product: "compute",
8252
- expiry
8253
- });
8254
- headers.Authorization = `Bearer ${signature}`;
8255
- headers["X-eigenx-expiry"] = expiry.toString();
8256
- headers["X-Account"] = this.address;
8257
- }
7837
+ const expiry = BigInt(Math.floor(Date.now() / 1e3) + 60);
7838
+ const { signature } = await calculateBillingAuthSignature({
7839
+ walletClient: this.walletClient,
7840
+ product: "compute",
7841
+ expiry
7842
+ });
7843
+ headers.Authorization = `Bearer ${signature}`;
7844
+ headers["X-eigenx-expiry"] = expiry.toString();
7845
+ headers["X-Account"] = this.address;
8258
7846
  const res = await requestWithRetry({
8259
7847
  url: `${this.baseUrl}${path8}`,
8260
7848
  method: "GET",
8261
7849
  headers,
8262
7850
  timeout: 6e4,
8263
- responseType: "text",
8264
- validateStatus: () => true,
8265
- withCredentials: this.useSession
7851
+ responseType: "text"
8266
7852
  });
8267
7853
  if (res.status < 200 || res.status >= 300) throw buildApiHttpError(res);
8268
7854
  return typeof res.data === "string" ? res.data : JSON.stringify(res.data);
@@ -8829,9 +8415,6 @@ function isSiweMessageNotYetValid(params) {
8829
8415
  return /* @__PURE__ */ new Date() < params.notBefore;
8830
8416
  }
8831
8417
 
8832
- // src/client/common/auth/index.ts
8833
- init_session();
8834
-
8835
8418
  // src/client/common/utils/instance.ts
8836
8419
  async function getCurrentInstanceType(preflightCtx, appID, logger, clientId) {
8837
8420
  try {