@layr-labs/ecloud-sdk 0.4.0-dev.1 → 0.4.0-dev.2

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.
Files changed (41) hide show
  1. package/VERSION +2 -0
  2. package/dist/attest.cjs +185 -0
  3. package/dist/attest.cjs.map +1 -0
  4. package/dist/attest.d.cts +28 -0
  5. package/dist/attest.d.ts +28 -0
  6. package/dist/attest.js +147 -0
  7. package/dist/attest.js.map +1 -0
  8. package/dist/billing.cjs +1380 -4
  9. package/dist/billing.cjs.map +1 -1
  10. package/dist/billing.d.cts +25 -3
  11. package/dist/billing.d.ts +25 -3
  12. package/dist/billing.js +1380 -4
  13. package/dist/billing.js.map +1 -1
  14. package/dist/browser.cjs +3 -2
  15. package/dist/browser.cjs.map +1 -1
  16. package/dist/browser.d.cts +4 -4
  17. package/dist/browser.d.ts +4 -4
  18. package/dist/browser.js +3 -2
  19. package/dist/browser.js.map +1 -1
  20. package/dist/{compute-DccJLbtV.d.cts → compute-BRDk7QM4.d.cts} +1 -1
  21. package/dist/{compute-DlilmZYC.d.ts → compute-CC55YQ_a.d.ts} +1 -1
  22. package/dist/compute.cjs +8 -3
  23. package/dist/compute.cjs.map +1 -1
  24. package/dist/compute.d.cts +2 -2
  25. package/dist/compute.d.ts +2 -2
  26. package/dist/compute.js +8 -3
  27. package/dist/compute.js.map +1 -1
  28. package/dist/{helpers-D_AbDeP4.d.ts → helpers-BcoV07Me.d.ts} +1 -1
  29. package/dist/{helpers-BNeMZYcY.d.cts → helpers-DdtPaQr9.d.cts} +1 -1
  30. package/dist/{index-DD7ZLbqD.d.cts → index-BEbhrwWl.d.cts} +1 -0
  31. package/dist/{index-DD7ZLbqD.d.ts → index-BEbhrwWl.d.ts} +1 -0
  32. package/dist/index.cjs +330 -95
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +7 -6
  35. package/dist/index.d.ts +7 -6
  36. package/dist/index.js +328 -95
  37. package/dist/index.js.map +1 -1
  38. package/package.json +16 -10
  39. package/tools/kms-client-linux-amd64 +0 -0
  40. package/tools/tls-keygen-linux-amd64 +0 -0
  41. package/LICENSE +0 -7
package/dist/index.d.cts CHANGED
@@ -1,12 +1,13 @@
1
- import { C as ComputeModule } from './compute-DccJLbtV.cjs';
2
- export { d as ComputeModuleConfig, a as CreateAppOpts, L as LogsOptions, P as PRIMARY_LANGUAGES, S as SDKCreateAppOpts, c as createApp, b as createComputeModule, e as encodeStartAppData, f as encodeStopAppData, h as encodeTerminateAppData, g as getAvailableTemplates, l as logs } from './compute-DccJLbtV.cjs';
1
+ import { C as ComputeModule } from './compute-BRDk7QM4.cjs';
2
+ export { d as ComputeModuleConfig, a as CreateAppOpts, L as LogsOptions, P as PRIMARY_LANGUAGES, S as SDKCreateAppOpts, c as createApp, b as createComputeModule, e as encodeStartAppData, f as encodeStopAppData, h as encodeTerminateAppData, g as getAvailableTemplates, l as logs } from './compute-BRDk7QM4.cjs';
3
3
  import { BillingModule } from './billing.cjs';
4
4
  export { BillingModuleConfig, createBillingModule } from './billing.cjs';
5
5
  import { WalletClient, PublicClient, Address, Hex } from 'viem';
6
- import { L as LogVisibility, aj as ResourceUsageMonitoring } from './helpers-BNeMZYcY.cjs';
7
- export { F as AppInfo, I as AppMetrics, H as AppProfileInfo, al as AppRelease, am as AppReleaseBuild, an as AppResponse, K as BillingApiClient, C as ComputeApiConfig, z as CreateAppParams, as as DeployParams, Q as EstimateBatchGasOptions, G as GeneratedKey, a4 as LoginRequest, a3 as LoginResult, A as LogsParams, a as SessionError, S as SessionInfo, b as SiweMessageParams, _ as SiweMessageResult, au as UpgradeParams, U as UserApiClient, ah as addHexPrefix, ap as assertValidFilePath, j as assertValidImageReference, n as assertValidPrivateKey, P as checkERC7702Delegation, V as createSiweMessage, ak as createViemClients, N as estimateBatchGas, k as extractAppNameFromImage, D as generateNewPrivateKey, X as generateNonce, d as getAvailableEnvironments, c as getBillingEnvironmentConfig, e as getBuildType, ag as getChainFromID, a1 as getComputeApiSession, g as getEnvironmentConfig, i as isEnvironmentAvailable, f as isMainnet, a2 as isSessionValid, Y as isSiweMessageExpired, Z as isSiweMessageNotYetValid, B as isSubscriptionActive, $ as loginToComputeApi, a0 as logoutFromComputeApi, W as parseSiweMessage, t as sanitizeString, u as sanitizeURL, w as sanitizeXURL, ai as stripHexPrefix, r as validateAppID, v as validateAppName, x as validateCreateAppParams, at as validateDeployParams, q as validateDescription, ao as validateFilePath, aq as validateImagePath, h as validateImageReference, l as validateInstanceTypeSKU, s as validateLogVisibility, y as validateLogsParams, m as validatePrivateKeyFormat, ar as validateResourceUsageMonitoring, o as validateURL, av as validateUpgradeParams, p as validateXURL } from './helpers-BNeMZYcY.cjs';
8
- import { G as GasEstimate, ad as Logger, a1 as PreparedDeploy, a8 as EnvironmentConfig, a6 as DeployResult, a2 as PreparedUpgrade, A as AppId } from './index-DD7ZLbqD.cjs';
9
- export { ao as AlreadyActiveResponse, ae as AppProfile, af as AppProfileResponse, a4 as AppRecord, a7 as BillingEnvironmentConfig, at as CancelResponse, ar as CancelSuccessResponse, ah as ChainID, an as CheckoutCreatedResponse, ak as CreateSubscriptionOptions, am as CreateSubscriptionResponse, Q as DeployAppOpts, a5 as DeployOptions, aw as DeployProgressCallback, ax as DeployStep, ac as DockerImageConfig, E as EstimateGasOptions, Z as ExecuteDeployResult, _ as ExecuteUpgradeResult, Y as GasOpts, al as GetSubscriptionOptions, ab as ImageDigestResult, a3 as LifecycleOpts, as as NoActiveSubscriptionResponse, aa as ParsedEnvironment, ap as PaymentIssueResponse, W as PrepareDeployFromVerifiableBuildOpts, T as PrepareDeployOpts, X as PrepareUpgradeFromVerifiableBuildOpts, V as PrepareUpgradeOpts, $ as PreparedDeployData, a0 as PreparedUpgradeData, ag as ProductID, au as ProductSubscriptionResponse, a9 as Release, ay as SequentialDeployResult, aq as SubscribeResponse, aj as SubscriptionLineItem, av as SubscriptionOpts, ai as SubscriptionStatus, R as UpgradeAppOpts, l as calculateAppID, h as estimateTransactionGas, i as formatETH, g as getAllAppsByDeveloper, az as getAppLatestReleaseBlockNumbers, f as getAppsByBillingAccount, e as getBillingType, aA as getBlockTimestamps, O as logVisibility, N as noopLogger } from './index-DD7ZLbqD.cjs';
6
+ export { AttestClient, AttestClientConfig, JwtProvider } from './attest.cjs';
7
+ import { L as LogVisibility, aj as ResourceUsageMonitoring } from './helpers-DdtPaQr9.cjs';
8
+ export { F as AppInfo, I as AppMetrics, H as AppProfileInfo, al as AppRelease, am as AppReleaseBuild, an as AppResponse, K as BillingApiClient, C as ComputeApiConfig, z as CreateAppParams, as as DeployParams, Q as EstimateBatchGasOptions, G as GeneratedKey, a4 as LoginRequest, a3 as LoginResult, A as LogsParams, a as SessionError, S as SessionInfo, b as SiweMessageParams, _ as SiweMessageResult, au as UpgradeParams, U as UserApiClient, ah as addHexPrefix, ap as assertValidFilePath, j as assertValidImageReference, n as assertValidPrivateKey, P as checkERC7702Delegation, V as createSiweMessage, ak as createViemClients, N as estimateBatchGas, k as extractAppNameFromImage, D as generateNewPrivateKey, X as generateNonce, d as getAvailableEnvironments, c as getBillingEnvironmentConfig, e as getBuildType, ag as getChainFromID, a1 as getComputeApiSession, g as getEnvironmentConfig, i as isEnvironmentAvailable, f as isMainnet, a2 as isSessionValid, Y as isSiweMessageExpired, Z as isSiweMessageNotYetValid, B as isSubscriptionActive, $ as loginToComputeApi, a0 as logoutFromComputeApi, W as parseSiweMessage, t as sanitizeString, u as sanitizeURL, w as sanitizeXURL, ai as stripHexPrefix, r as validateAppID, v as validateAppName, x as validateCreateAppParams, at as validateDeployParams, q as validateDescription, ao as validateFilePath, aq as validateImagePath, h as validateImageReference, l as validateInstanceTypeSKU, s as validateLogVisibility, y as validateLogsParams, m as validatePrivateKeyFormat, ar as validateResourceUsageMonitoring, o as validateURL, av as validateUpgradeParams, p as validateXURL } from './helpers-DdtPaQr9.cjs';
9
+ import { G as GasEstimate, ad as Logger, a1 as PreparedDeploy, a8 as EnvironmentConfig, a6 as DeployResult, a2 as PreparedUpgrade, A as AppId } from './index-BEbhrwWl.cjs';
10
+ export { ao as AlreadyActiveResponse, ae as AppProfile, af as AppProfileResponse, a4 as AppRecord, a7 as BillingEnvironmentConfig, at as CancelResponse, ar as CancelSuccessResponse, ah as ChainID, an as CheckoutCreatedResponse, ak as CreateSubscriptionOptions, am as CreateSubscriptionResponse, Q as DeployAppOpts, a5 as DeployOptions, aw as DeployProgressCallback, ax as DeployStep, ac as DockerImageConfig, E as EstimateGasOptions, Z as ExecuteDeployResult, _ as ExecuteUpgradeResult, Y as GasOpts, al as GetSubscriptionOptions, ab as ImageDigestResult, a3 as LifecycleOpts, as as NoActiveSubscriptionResponse, aa as ParsedEnvironment, ap as PaymentIssueResponse, W as PrepareDeployFromVerifiableBuildOpts, T as PrepareDeployOpts, X as PrepareUpgradeFromVerifiableBuildOpts, V as PrepareUpgradeOpts, $ as PreparedDeployData, a0 as PreparedUpgradeData, ag as ProductID, au as ProductSubscriptionResponse, a9 as Release, ay as SequentialDeployResult, aq as SubscribeResponse, aj as SubscriptionLineItem, av as SubscriptionOpts, ai as SubscriptionStatus, R as UpgradeAppOpts, l as calculateAppID, h as estimateTransactionGas, i as formatETH, g as getAllAppsByDeveloper, az as getAppLatestReleaseBlockNumbers, f as getAppsByBillingAccount, e as getBillingType, aA as getBlockTimestamps, O as logVisibility, N as noopLogger } from './index-BEbhrwWl.cjs';
10
11
 
11
12
  interface SubmitBuildRequest {
12
13
  repoUrl: string;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
- import { C as ComputeModule } from './compute-DlilmZYC.js';
2
- export { d as ComputeModuleConfig, a as CreateAppOpts, L as LogsOptions, P as PRIMARY_LANGUAGES, S as SDKCreateAppOpts, c as createApp, b as createComputeModule, e as encodeStartAppData, f as encodeStopAppData, h as encodeTerminateAppData, g as getAvailableTemplates, l as logs } from './compute-DlilmZYC.js';
1
+ import { C as ComputeModule } from './compute-CC55YQ_a.js';
2
+ export { d as ComputeModuleConfig, a as CreateAppOpts, L as LogsOptions, P as PRIMARY_LANGUAGES, S as SDKCreateAppOpts, c as createApp, b as createComputeModule, e as encodeStartAppData, f as encodeStopAppData, h as encodeTerminateAppData, g as getAvailableTemplates, l as logs } from './compute-CC55YQ_a.js';
3
3
  import { BillingModule } from './billing.js';
4
4
  export { BillingModuleConfig, createBillingModule } from './billing.js';
5
5
  import { WalletClient, PublicClient, Address, Hex } from 'viem';
6
- import { L as LogVisibility, aj as ResourceUsageMonitoring } from './helpers-D_AbDeP4.js';
7
- export { F as AppInfo, I as AppMetrics, H as AppProfileInfo, al as AppRelease, am as AppReleaseBuild, an as AppResponse, K as BillingApiClient, C as ComputeApiConfig, z as CreateAppParams, as as DeployParams, Q as EstimateBatchGasOptions, G as GeneratedKey, a4 as LoginRequest, a3 as LoginResult, A as LogsParams, a as SessionError, S as SessionInfo, b as SiweMessageParams, _ as SiweMessageResult, au as UpgradeParams, U as UserApiClient, ah as addHexPrefix, ap as assertValidFilePath, j as assertValidImageReference, n as assertValidPrivateKey, P as checkERC7702Delegation, V as createSiweMessage, ak as createViemClients, N as estimateBatchGas, k as extractAppNameFromImage, D as generateNewPrivateKey, X as generateNonce, d as getAvailableEnvironments, c as getBillingEnvironmentConfig, e as getBuildType, ag as getChainFromID, a1 as getComputeApiSession, g as getEnvironmentConfig, i as isEnvironmentAvailable, f as isMainnet, a2 as isSessionValid, Y as isSiweMessageExpired, Z as isSiweMessageNotYetValid, B as isSubscriptionActive, $ as loginToComputeApi, a0 as logoutFromComputeApi, W as parseSiweMessage, t as sanitizeString, u as sanitizeURL, w as sanitizeXURL, ai as stripHexPrefix, r as validateAppID, v as validateAppName, x as validateCreateAppParams, at as validateDeployParams, q as validateDescription, ao as validateFilePath, aq as validateImagePath, h as validateImageReference, l as validateInstanceTypeSKU, s as validateLogVisibility, y as validateLogsParams, m as validatePrivateKeyFormat, ar as validateResourceUsageMonitoring, o as validateURL, av as validateUpgradeParams, p as validateXURL } from './helpers-D_AbDeP4.js';
8
- import { G as GasEstimate, ad as Logger, a1 as PreparedDeploy, a8 as EnvironmentConfig, a6 as DeployResult, a2 as PreparedUpgrade, A as AppId } from './index-DD7ZLbqD.js';
9
- export { ao as AlreadyActiveResponse, ae as AppProfile, af as AppProfileResponse, a4 as AppRecord, a7 as BillingEnvironmentConfig, at as CancelResponse, ar as CancelSuccessResponse, ah as ChainID, an as CheckoutCreatedResponse, ak as CreateSubscriptionOptions, am as CreateSubscriptionResponse, Q as DeployAppOpts, a5 as DeployOptions, aw as DeployProgressCallback, ax as DeployStep, ac as DockerImageConfig, E as EstimateGasOptions, Z as ExecuteDeployResult, _ as ExecuteUpgradeResult, Y as GasOpts, al as GetSubscriptionOptions, ab as ImageDigestResult, a3 as LifecycleOpts, as as NoActiveSubscriptionResponse, aa as ParsedEnvironment, ap as PaymentIssueResponse, W as PrepareDeployFromVerifiableBuildOpts, T as PrepareDeployOpts, X as PrepareUpgradeFromVerifiableBuildOpts, V as PrepareUpgradeOpts, $ as PreparedDeployData, a0 as PreparedUpgradeData, ag as ProductID, au as ProductSubscriptionResponse, a9 as Release, ay as SequentialDeployResult, aq as SubscribeResponse, aj as SubscriptionLineItem, av as SubscriptionOpts, ai as SubscriptionStatus, R as UpgradeAppOpts, l as calculateAppID, h as estimateTransactionGas, i as formatETH, g as getAllAppsByDeveloper, az as getAppLatestReleaseBlockNumbers, f as getAppsByBillingAccount, e as getBillingType, aA as getBlockTimestamps, O as logVisibility, N as noopLogger } from './index-DD7ZLbqD.js';
6
+ export { AttestClient, AttestClientConfig, JwtProvider } from './attest.js';
7
+ import { L as LogVisibility, aj as ResourceUsageMonitoring } from './helpers-BcoV07Me.js';
8
+ export { F as AppInfo, I as AppMetrics, H as AppProfileInfo, al as AppRelease, am as AppReleaseBuild, an as AppResponse, K as BillingApiClient, C as ComputeApiConfig, z as CreateAppParams, as as DeployParams, Q as EstimateBatchGasOptions, G as GeneratedKey, a4 as LoginRequest, a3 as LoginResult, A as LogsParams, a as SessionError, S as SessionInfo, b as SiweMessageParams, _ as SiweMessageResult, au as UpgradeParams, U as UserApiClient, ah as addHexPrefix, ap as assertValidFilePath, j as assertValidImageReference, n as assertValidPrivateKey, P as checkERC7702Delegation, V as createSiweMessage, ak as createViemClients, N as estimateBatchGas, k as extractAppNameFromImage, D as generateNewPrivateKey, X as generateNonce, d as getAvailableEnvironments, c as getBillingEnvironmentConfig, e as getBuildType, ag as getChainFromID, a1 as getComputeApiSession, g as getEnvironmentConfig, i as isEnvironmentAvailable, f as isMainnet, a2 as isSessionValid, Y as isSiweMessageExpired, Z as isSiweMessageNotYetValid, B as isSubscriptionActive, $ as loginToComputeApi, a0 as logoutFromComputeApi, W as parseSiweMessage, t as sanitizeString, u as sanitizeURL, w as sanitizeXURL, ai as stripHexPrefix, r as validateAppID, v as validateAppName, x as validateCreateAppParams, at as validateDeployParams, q as validateDescription, ao as validateFilePath, aq as validateImagePath, h as validateImageReference, l as validateInstanceTypeSKU, s as validateLogVisibility, y as validateLogsParams, m as validatePrivateKeyFormat, ar as validateResourceUsageMonitoring, o as validateURL, av as validateUpgradeParams, p as validateXURL } from './helpers-BcoV07Me.js';
9
+ import { G as GasEstimate, ad as Logger, a1 as PreparedDeploy, a8 as EnvironmentConfig, a6 as DeployResult, a2 as PreparedUpgrade, A as AppId } from './index-BEbhrwWl.js';
10
+ export { ao as AlreadyActiveResponse, ae as AppProfile, af as AppProfileResponse, a4 as AppRecord, a7 as BillingEnvironmentConfig, at as CancelResponse, ar as CancelSuccessResponse, ah as ChainID, an as CheckoutCreatedResponse, ak as CreateSubscriptionOptions, am as CreateSubscriptionResponse, Q as DeployAppOpts, a5 as DeployOptions, aw as DeployProgressCallback, ax as DeployStep, ac as DockerImageConfig, E as EstimateGasOptions, Z as ExecuteDeployResult, _ as ExecuteUpgradeResult, Y as GasOpts, al as GetSubscriptionOptions, ab as ImageDigestResult, a3 as LifecycleOpts, as as NoActiveSubscriptionResponse, aa as ParsedEnvironment, ap as PaymentIssueResponse, W as PrepareDeployFromVerifiableBuildOpts, T as PrepareDeployOpts, X as PrepareUpgradeFromVerifiableBuildOpts, V as PrepareUpgradeOpts, $ as PreparedDeployData, a0 as PreparedUpgradeData, ag as ProductID, au as ProductSubscriptionResponse, a9 as Release, ay as SequentialDeployResult, aq as SubscribeResponse, aj as SubscriptionLineItem, av as SubscriptionOpts, ai as SubscriptionStatus, R as UpgradeAppOpts, l as calculateAppID, h as estimateTransactionGas, i as formatETH, g as getAllAppsByDeveloper, az as getAppLatestReleaseBlockNumbers, f as getAppsByBillingAccount, e as getBillingType, aA as getBlockTimestamps, O as logVisibility, N as noopLogger } from './index-BEbhrwWl.js';
10
11
 
11
12
  interface SubmitBuildRequest {
12
13
  repoUrl: string;
package/dist/index.js CHANGED
@@ -545,6 +545,10 @@ setup_tls() {
545
545
  # Run TLS setup
546
546
  setup_tls
547
547
 
548
+ # Export KMS variables for attestation-based JWT auth
549
+ export KMS_SERVER_URL="{{kmsServerURL}}"
550
+ export KMS_PUBLIC_KEY="$(cat /usr/local/bin/kms-signing-public-key.pem)"
551
+
548
552
  echo "compute-source-env.sh: Environment sourced."
549
553
 
550
554
  # Drop privileges to original user for the application command
@@ -4807,7 +4811,7 @@ var CanViewAppLogsPermission = "0x2fd3f2fe";
4807
4811
  var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
4808
4812
  var CanUpdateAppProfilePermission = "0x036fef61";
4809
4813
  function getDefaultClientId() {
4810
- const version = true ? "0.4.0-dev.1" : "0.0.0";
4814
+ const version = true ? "0.4.0-dev.2" : "0.0.0";
4811
4815
  return `ecloud-sdk/v${version}`;
4812
4816
  }
4813
4817
  var UserApiClient = class {
@@ -5598,7 +5602,8 @@ var ENVIRONMENTS = {
5598
5602
  erc7702DelegatorAddress: CommonAddresses.ERC7702Delegator,
5599
5603
  kmsServerURL: "http://10.128.15.203:8080",
5600
5604
  userApiServerURL: "https://userapi-compute-sepolia-prod.eigencloud.xyz",
5601
- defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com"
5605
+ defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com",
5606
+ billingRPCURL: "https://ethereum-rpc.publicnode.com"
5602
5607
  },
5603
5608
  "mainnet-alpha": {
5604
5609
  name: "mainnet-alpha",
@@ -6138,7 +6143,7 @@ function getPostHogAPIKey() {
6138
6143
  if (process.env.ECLOUD_POSTHOG_KEY) {
6139
6144
  return process.env.ECLOUD_POSTHOG_KEY;
6140
6145
  }
6141
- return typeof POSTHOG_API_KEY_BUILD_TIME !== "undefined" ? POSTHOG_API_KEY_BUILD_TIME : void 0;
6146
+ return true ? "phc_BiKfywNft5iBI8N7MxmuVCkb4GGZj4mDFXYPmOPUAI8" : void 0;
6142
6147
  }
6143
6148
  function getPostHogEndpoint() {
6144
6149
  return process.env.ECLOUD_POSTHOG_ENDPOINT || "https://us.i.posthog.com";
@@ -8047,9 +8052,101 @@ function createComputeModule(config) {
8047
8052
  };
8048
8053
  }
8049
8054
 
8055
+ // src/client/modules/billing/index.ts
8056
+ import { encodeFunctionData as encodeFunctionData4 } from "viem";
8057
+
8058
+ // src/client/common/abis/USDCCredits.json
8059
+ var USDCCredits_default = [
8060
+ {
8061
+ type: "function",
8062
+ name: "purchaseCreditsFor",
8063
+ stateMutability: "nonpayable",
8064
+ inputs: [
8065
+ { name: "amount", type: "uint256" },
8066
+ { name: "account", type: "address" }
8067
+ ],
8068
+ outputs: []
8069
+ },
8070
+ {
8071
+ type: "function",
8072
+ name: "purchaseCredits",
8073
+ stateMutability: "nonpayable",
8074
+ inputs: [
8075
+ { name: "amount", type: "uint256" }
8076
+ ],
8077
+ outputs: []
8078
+ },
8079
+ {
8080
+ type: "function",
8081
+ name: "usdc",
8082
+ stateMutability: "view",
8083
+ inputs: [],
8084
+ outputs: [
8085
+ { name: "", type: "address" }
8086
+ ]
8087
+ },
8088
+ {
8089
+ type: "function",
8090
+ name: "minimumPurchase",
8091
+ stateMutability: "view",
8092
+ inputs: [],
8093
+ outputs: [
8094
+ { name: "", type: "uint256" }
8095
+ ]
8096
+ },
8097
+ {
8098
+ type: "event",
8099
+ name: "CreditsPurchased",
8100
+ inputs: [
8101
+ { name: "purchaser", type: "address", indexed: true },
8102
+ { name: "account", type: "address", indexed: true },
8103
+ { name: "amount", type: "uint256", indexed: false }
8104
+ ]
8105
+ }
8106
+ ];
8107
+
8108
+ // src/client/common/abis/ERC20.json
8109
+ var ERC20_default = [
8110
+ {
8111
+ type: "function",
8112
+ name: "approve",
8113
+ stateMutability: "nonpayable",
8114
+ inputs: [
8115
+ { name: "spender", type: "address" },
8116
+ { name: "amount", type: "uint256" }
8117
+ ],
8118
+ outputs: [
8119
+ { name: "", type: "bool" }
8120
+ ]
8121
+ },
8122
+ {
8123
+ type: "function",
8124
+ name: "balanceOf",
8125
+ stateMutability: "view",
8126
+ inputs: [
8127
+ { name: "account", type: "address" }
8128
+ ],
8129
+ outputs: [
8130
+ { name: "", type: "uint256" }
8131
+ ]
8132
+ },
8133
+ {
8134
+ type: "function",
8135
+ name: "allowance",
8136
+ stateMutability: "view",
8137
+ inputs: [
8138
+ { name: "owner", type: "address" },
8139
+ { name: "spender", type: "address" }
8140
+ ],
8141
+ outputs: [
8142
+ { name: "", type: "uint256" }
8143
+ ]
8144
+ }
8145
+ ];
8146
+
8050
8147
  // src/client/modules/billing/index.ts
8051
8148
  function createBillingModule(config) {
8052
- const { verbose = false, skipTelemetry = false, walletClient } = config;
8149
+ const { verbose = false, skipTelemetry = false, walletClient, publicClient, environment } = config;
8053
8150
  if (!walletClient.account) {
8054
8151
  throw new Error("WalletClient must have an account attached");
8055
8152
  }
@@ -8057,8 +8154,85 @@ function createBillingModule(config) {
8057
8154
  const logger = getLogger(verbose);
8058
8155
  const billingEnvConfig = getBillingEnvironmentConfig(getBuildType());
8059
8156
  const billingApi = new BillingApiClient(billingEnvConfig, walletClient);
8060
- return {
8157
+ const environmentConfig = getEnvironmentConfig(environment);
8158
+ const usdcCreditsAddress = environmentConfig.usdcCreditsAddress;
8159
+ if (!usdcCreditsAddress) {
8160
+ throw new Error(`USDCCredits contract address not configured for environment "${environment}"`);
8161
+ }
8162
+ const module = {
8061
8163
  address,
8164
+ async getTopUpInfo() {
8165
+ const usdcAddress = await publicClient.readContract({
8166
+ address: usdcCreditsAddress,
8167
+ abi: USDCCredits_default,
8168
+ functionName: "usdc"
8169
+ });
8170
+ const [minimumPurchase, usdcBalance, currentAllowance] = await Promise.all([
8171
+ publicClient.readContract({
8172
+ address: usdcCreditsAddress,
8173
+ abi: USDCCredits_default,
8174
+ functionName: "minimumPurchase"
8175
+ }),
8176
+ publicClient.readContract({
8177
+ address: usdcAddress,
8178
+ abi: ERC20_default,
8179
+ functionName: "balanceOf",
8180
+ args: [address]
8181
+ }),
8182
+ publicClient.readContract({
8183
+ address: usdcAddress,
8184
+ abi: ERC20_default,
8185
+ functionName: "allowance",
8186
+ args: [address, usdcCreditsAddress]
8187
+ })
8188
+ ]);
8189
+ return { usdcAddress, minimumPurchase, usdcBalance, currentAllowance };
8190
+ },
8191
+ async topUp(opts) {
8192
+ return withSDKTelemetry(
8193
+ {
8194
+ functionName: "topUp",
8195
+ skipTelemetry,
8196
+ properties: { amount: opts.amount.toString() }
8197
+ },
8198
+ async () => {
8199
+ const targetAccount = opts.account ?? address;
8200
+ const { usdcAddress, currentAllowance } = await module.getTopUpInfo();
8201
+ const executions = [];
8202
+ if (currentAllowance < opts.amount) {
8203
+ executions.push({
8204
+ target: usdcAddress,
8205
+ value: 0n,
8206
+ callData: encodeFunctionData4({
8207
+ abi: ERC20_default,
8208
+ functionName: "approve",
8209
+ args: [usdcCreditsAddress, opts.amount]
8210
+ })
8211
+ });
8212
+ }
8213
+ executions.push({
8214
+ target: usdcCreditsAddress,
8215
+ value: 0n,
8216
+ callData: encodeFunctionData4({
8217
+ abi: USDCCredits_default,
8218
+ functionName: "purchaseCreditsFor",
8219
+ args: [opts.amount, targetAccount]
8220
+ })
8221
+ });
8222
+ const txHash = await executeBatch(
8223
+ {
8224
+ walletClient,
8225
+ publicClient,
8226
+ environmentConfig,
8227
+ executions,
8228
+ pendingMessage: "Submitting credit purchase..."
8229
+ },
8230
+ logger
8231
+ );
8232
+ return { txHash, walletAddress: address };
8233
+ }
8234
+ );
8235
+ },
8062
8236
  async subscribe(opts) {
8063
8237
  return withSDKTelemetry(
8064
8238
  {
@@ -8145,6 +8319,7 @@ function createBillingModule(config) {
8145
8319
  );
8146
8320
  }
8147
8321
  };
8322
+ return module;
8148
8323
  }
8149
8324
 
8150
8325
  // src/client/common/utils/buildapi.ts
@@ -8907,95 +9082,6 @@ async function getCurrentInstanceType(preflightCtx, appID, logger, clientId) {
8907
9082
  }
8908
9083
  }
8909
9084
 
8910
- // src/client/common/abis/USDCCredits.json
8911
- var USDCCredits_default = [
8912
- {
8913
- type: "function",
8914
- name: "purchaseCreditsFor",
8915
- stateMutability: "nonpayable",
8916
- inputs: [
8917
- { name: "amount", type: "uint256" },
8918
- { name: "account", type: "address" }
8919
- ],
8920
- outputs: []
8921
- },
8922
- {
8923
- type: "function",
8924
- name: "purchaseCredits",
8925
- stateMutability: "nonpayable",
8926
- inputs: [
8927
- { name: "amount", type: "uint256" }
8928
- ],
8929
- outputs: []
8930
- },
8931
- {
8932
- type: "function",
8933
- name: "usdc",
8934
- stateMutability: "view",
8935
- inputs: [],
8936
- outputs: [
8937
- { name: "", type: "address" }
8938
- ]
8939
- },
8940
- {
8941
- type: "function",
8942
- name: "minimumPurchase",
8943
- stateMutability: "view",
8944
- inputs: [],
8945
- outputs: [
8946
- { name: "", type: "uint256" }
8947
- ]
8948
- },
8949
- {
8950
- type: "event",
8951
- name: "CreditsPurchased",
8952
- inputs: [
8953
- { name: "purchaser", type: "address", indexed: true },
8954
- { name: "account", type: "address", indexed: true },
8955
- { name: "amount", type: "uint256", indexed: false }
8956
- ]
8957
- }
8958
- ];
8959
-
8960
- // src/client/common/abis/ERC20.json
8961
- var ERC20_default = [
8962
- {
8963
- type: "function",
8964
- name: "approve",
8965
- stateMutability: "nonpayable",
8966
- inputs: [
8967
- { name: "spender", type: "address" },
8968
- { name: "amount", type: "uint256" }
8969
- ],
8970
- outputs: [
8971
- { name: "", type: "bool" }
8972
- ]
8973
- },
8974
- {
8975
- type: "function",
8976
- name: "balanceOf",
8977
- stateMutability: "view",
8978
- inputs: [
8979
- { name: "account", type: "address" }
8980
- ],
8981
- outputs: [
8982
- { name: "", type: "uint256" }
8983
- ]
8984
- },
8985
- {
8986
- type: "function",
8987
- name: "allowance",
8988
- stateMutability: "view",
8989
- inputs: [
8990
- { name: "owner", type: "address" },
8991
- { name: "spender", type: "address" }
8992
- ],
8993
- outputs: [
8994
- { name: "", type: "uint256" }
8995
- ]
8996
- }
8997
- ];
8998
-
8999
9085
  // src/client/index.ts
9000
9086
  function createECloudClient(cfg) {
9001
9087
  cfg.privateKey = addHexPrefix(cfg.privateKey);
@@ -9029,11 +9115,157 @@ function createECloudClient(cfg) {
9029
9115
  }),
9030
9116
  billing: createBillingModule({
9031
9117
  verbose: cfg.verbose,
9032
- walletClient
9118
+ walletClient,
9119
+ publicClient,
9120
+ environment: cfg.environment
9033
9121
  })
9034
9122
  };
9035
9123
  }
9124
+
9125
+ // src/client/modules/attest/attest-client.ts
9126
+ import { generateKeyPairSync, createHash, verify } from "crypto";
9127
+ import http2 from "http";
9128
+ import { compactDecrypt } from "jose";
9129
+ var DEFAULT_SOCKET_PATH = "/run/container_launcher/teeserver.sock";
9130
+ var CHALLENGE_PREFIX = "COMPUTE_APP_JWT_REQUEST_RSA_KEY_V1";
9131
+ var SIGNATURE_PREFIX = "COMPUTE_APP_KMS_SIGNATURE_V1";
9132
+ var NULL_BYTE = Buffer.from([0]);
9133
+ var AttestClient = class {
9134
+ constructor(config) {
9135
+ this.config = config;
9136
+ }
9137
+ async attest() {
9138
+ const { publicKey, privateKey } = generateKeyPairSync("rsa", {
9139
+ modulusLength: 4096,
9140
+ publicKeyEncoding: { type: "spki", format: "pem" },
9141
+ privateKeyEncoding: { type: "pkcs8", format: "pem" }
9142
+ });
9143
+ const challengeHash = createHash("sha256").update(CHALLENGE_PREFIX).update(NULL_BYTE).update(publicKey).digest();
9144
+ const socketPath = this.config.socketPath ?? DEFAULT_SOCKET_PATH;
9145
+ const attestationBytes = await this.getAttestation(socketPath, challengeHash);
9146
+ const attestResponse = await this.postAttest(attestationBytes, publicKey);
9147
+ this.verifySignature(JSON.stringify(attestResponse.data), attestResponse.signature);
9148
+ const rsaPrivateKey = await crypto.subtle.importKey(
9149
+ "pkcs8",
9150
+ pemToBuffer(privateKey),
9151
+ { name: "RSA-OAEP", hash: "SHA-256" },
9152
+ false,
9153
+ ["decrypt"]
9154
+ );
9155
+ const { plaintext } = await compactDecrypt(
9156
+ attestResponse.data.encryptedToken,
9157
+ rsaPrivateKey
9158
+ );
9159
+ const decrypted = JSON.parse(new TextDecoder().decode(plaintext));
9160
+ return decrypted.token;
9161
+ }
9162
+ verifySignature(dataJson, signature) {
9163
+ const message = Buffer.concat([
9164
+ Buffer.from(SIGNATURE_PREFIX),
9165
+ NULL_BYTE,
9166
+ Buffer.from(dataJson)
9167
+ ]);
9168
+ const valid = verify(
9169
+ "sha256",
9170
+ message,
9171
+ this.config.kmsPublicKey,
9172
+ Buffer.from(signature, "base64")
9173
+ );
9174
+ if (!valid) {
9175
+ throw new Error("KMS response signature verification failed");
9176
+ }
9177
+ }
9178
+ getAttestation(socketPath, challenge) {
9179
+ return new Promise((resolve2, reject) => {
9180
+ const body = JSON.stringify({ challenge: challenge.toString("base64") });
9181
+ const req = http2.request(
9182
+ {
9183
+ socketPath,
9184
+ path: "/v1/bound_evidence",
9185
+ method: "POST",
9186
+ headers: {
9187
+ "Content-Type": "application/json",
9188
+ "Content-Length": Buffer.byteLength(body)
9189
+ }
9190
+ },
9191
+ (res) => {
9192
+ const chunks = [];
9193
+ res.on("data", (chunk) => chunks.push(chunk));
9194
+ res.on("end", () => {
9195
+ if (res.statusCode !== 200) {
9196
+ reject(new Error(`TEE attestation failed (${res.statusCode}): ${Buffer.concat(chunks).toString()}`));
9197
+ return;
9198
+ }
9199
+ resolve2(Buffer.concat(chunks));
9200
+ });
9201
+ }
9202
+ );
9203
+ req.on("error", (err) => reject(new Error(`TEE attestation request failed: ${err.message}`)));
9204
+ req.write(body);
9205
+ req.end();
9206
+ });
9207
+ }
9208
+ async postAttest(attestationBytes, rsaPublicKey) {
9209
+ const url = `${this.config.kmsServerURL}/auth/attest`;
9210
+ const body = JSON.stringify({
9211
+ version: 3,
9212
+ attestation: attestationBytes.toString("base64"),
9213
+ rsaKey: rsaPublicKey,
9214
+ audience: this.config.audience
9215
+ });
9216
+ const response = await fetch(url, {
9217
+ method: "POST",
9218
+ headers: { "Content-Type": "application/json" },
9219
+ body
9220
+ });
9221
+ if (!response.ok) {
9222
+ const text = await response.text();
9223
+ throw new Error(`KMS attest failed (${response.status}): ${text}`);
9224
+ }
9225
+ return response.json();
9226
+ }
9227
+ };
9228
+ function pemToBuffer(pem) {
9229
+ const b64 = pem.replace(/-----[A-Z ]+-----/g, "").replace(/\s/g, "");
9230
+ const buf = Buffer.from(b64, "base64");
9231
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
9232
+ }
9233
+
9234
+ // src/client/modules/attest/jwt-provider.ts
9235
+ var JwtProvider = class {
9236
+ constructor(attestClient, bufferSeconds = 30) {
9237
+ this.attestClient = attestClient;
9238
+ this.bufferSeconds = bufferSeconds;
9239
+ }
9240
+ async getToken() {
9241
+ if (this.cachedToken && !this.isExpiringSoon()) {
9242
+ return this.cachedToken;
9243
+ }
9244
+ if (this.pending) {
9245
+ return this.pending;
9246
+ }
9247
+ this.pending = this.attestClient.attest().then((token) => {
9248
+ this.cachedToken = token;
9249
+ this.expiresAt = this.decodeJwtExp(token);
9250
+ return token;
9251
+ }).finally(() => {
9252
+ this.pending = void 0;
9253
+ });
9254
+ return this.pending;
9255
+ }
9256
+ isExpiringSoon() {
9257
+ if (!this.expiresAt) return true;
9258
+ return Date.now() / 1e3 >= this.expiresAt - this.bufferSeconds;
9259
+ }
9260
+ decodeJwtExp(jwt) {
9261
+ const payload = jwt.split(".")[1];
9262
+ if (!payload) return void 0;
9263
+ const decoded = JSON.parse(Buffer.from(payload, "base64url").toString());
9264
+ return decoded.exp;
9265
+ }
9266
+ };
9036
9267
  export {
9268
+ AttestClient,
9037
9269
  AuthRequiredError,
9038
9270
  BUILD_STATUS,
9039
9271
  BadRequestError,
@@ -9043,6 +9275,7 @@ export {
9043
9275
  ConflictError,
9044
9276
  ERC20_default as ERC20ABI,
9045
9277
  ForbiddenError,
9278
+ JwtProvider,
9046
9279
  NoopClient,
9047
9280
  NotFoundError,
9048
9281
  PRIMARY_LANGUAGES,