@layr-labs/ecloud-sdk 0.5.0 → 1.0.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.
package/dist/index.cjs CHANGED
@@ -4986,7 +4986,7 @@ var CanViewAppLogsPermission = "0x2fd3f2fe";
4986
4986
  var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
4987
4987
  var CanUpdateAppProfilePermission = "0x036fef61";
4988
4988
  function getDefaultClientId() {
4989
- const version = true ? "0.5.0" : "0.0.0";
4989
+ const version = true ? "1.0.0-dev.2" : "0.0.0";
4990
4990
  return `ecloud-sdk/v${version}`;
4991
4991
  }
4992
4992
  var UserApiClient = class {
@@ -5804,6 +5804,12 @@ var CHAIN_ID_TO_ENVIRONMENT = {
5804
5804
  [SEPOLIA_CHAIN_ID.toString()]: "sepolia",
5805
5805
  [MAINNET_CHAIN_ID.toString()]: "mainnet-alpha"
5806
5806
  };
5807
+ function getApiUrlOverride() {
5808
+ const raw = process.env.ECLOUD_API_URL;
5809
+ if (!raw) return void 0;
5810
+ const trimmed = raw.trim().replace(/\/+$/, "");
5811
+ return trimmed.length > 0 ? trimmed : void 0;
5812
+ }
5807
5813
  function getEnvironmentConfig(environment, chainID) {
5808
5814
  const env = ENVIRONMENTS[environment];
5809
5815
  if (!env) {
@@ -5821,9 +5827,11 @@ function getEnvironmentConfig(environment, chainID) {
5821
5827
  }
5822
5828
  }
5823
5829
  const resolvedChainID = chainID || (environment === "sepolia" || environment === "sepolia-dev" ? SEPOLIA_CHAIN_ID : MAINNET_CHAIN_ID);
5830
+ const apiUrlOverride = getApiUrlOverride();
5824
5831
  return {
5825
5832
  ...env,
5826
- chainID: BigInt(resolvedChainID)
5833
+ chainID: BigInt(resolvedChainID),
5834
+ ...apiUrlOverride ? { userApiServerURL: apiUrlOverride } : {}
5827
5835
  };
5828
5836
  }
5829
5837
  function getBillingEnvironmentConfig(build) {
@@ -5831,10 +5839,14 @@ function getBillingEnvironmentConfig(build) {
5831
5839
  if (!config) {
5832
5840
  throw new Error(`Unknown billing environment: ${build}`);
5833
5841
  }
5842
+ const apiUrlOverride = getApiUrlOverride();
5843
+ if (apiUrlOverride) {
5844
+ return { billingApiServerURL: apiUrlOverride };
5845
+ }
5834
5846
  return config;
5835
5847
  }
5836
5848
  function getBuildType() {
5837
- const buildTimeType = true ? "prod"?.toLowerCase() : void 0;
5849
+ const buildTimeType = true ? "dev"?.toLowerCase() : void 0;
5838
5850
  const runtimeType = process.env.BUILD_TYPE?.toLowerCase();
5839
5851
  const buildType = buildTimeType || runtimeType;
5840
5852
  if (buildType === "dev") {
@@ -9318,7 +9330,10 @@ var AttestClient = class {
9318
9330
  constructor(config) {
9319
9331
  this.config = config;
9320
9332
  }
9321
- async attest() {
9333
+ async attest(extraData) {
9334
+ if (extraData && extraData.length > 1048576) {
9335
+ throw new Error(`extraData exceeds 1MB limit (${extraData.length} bytes)`);
9336
+ }
9322
9337
  const { publicKey, privateKey } = (0, import_node_crypto.generateKeyPairSync)("rsa", {
9323
9338
  modulusLength: 4096,
9324
9339
  publicKeyEncoding: { type: "spki", format: "pem" },
@@ -9326,8 +9341,8 @@ var AttestClient = class {
9326
9341
  });
9327
9342
  const challengeHash = (0, import_node_crypto.createHash)("sha256").update(CHALLENGE_PREFIX).update(NULL_BYTE).update(publicKey).digest();
9328
9343
  const socketPath = this.config.socketPath ?? DEFAULT_SOCKET_PATH;
9329
- const attestationBytes = await this.getAttestation(socketPath, challengeHash);
9330
- const attestResponse = await this.postAttest(attestationBytes, publicKey);
9344
+ const attestationBytes = await this.getAttestation(socketPath, challengeHash, extraData);
9345
+ const attestResponse = await this.postAttest(attestationBytes, publicKey, extraData);
9331
9346
  this.verifySignature(JSON.stringify(attestResponse.data), attestResponse.signature);
9332
9347
  const rsaPrivateKey = await crypto.subtle.importKey(
9333
9348
  "pkcs8",
@@ -9359,9 +9374,13 @@ var AttestClient = class {
9359
9374
  throw new Error("KMS response signature verification failed");
9360
9375
  }
9361
9376
  }
9362
- getAttestation(socketPath, challenge) {
9377
+ getAttestation(socketPath, challenge, extraData) {
9363
9378
  return new Promise((resolve2, reject) => {
9364
- const body = JSON.stringify({ challenge: challenge.toString("base64") });
9379
+ const requestBody = { challenge: challenge.toString("base64") };
9380
+ if (extraData && extraData.length > 0) {
9381
+ requestBody.extra_data = extraData.toString("base64");
9382
+ }
9383
+ const body = JSON.stringify(requestBody);
9365
9384
  const req = import_node_http.default.request(
9366
9385
  {
9367
9386
  socketPath,
@@ -9389,14 +9408,18 @@ var AttestClient = class {
9389
9408
  req.end();
9390
9409
  });
9391
9410
  }
9392
- async postAttest(attestationBytes, rsaPublicKey) {
9411
+ async postAttest(attestationBytes, rsaPublicKey, extraData) {
9393
9412
  const url = `${this.config.kmsServerURL}/auth/attest`;
9394
- const body = JSON.stringify({
9413
+ const requestBody = {
9395
9414
  version: 3,
9396
9415
  attestation: attestationBytes.toString("base64"),
9397
9416
  rsaKey: rsaPublicKey,
9398
9417
  audience: this.config.audience
9399
- });
9418
+ };
9419
+ if (extraData && extraData.length > 0) {
9420
+ requestBody.extra_data = extraData.toString("base64");
9421
+ }
9422
+ const body = JSON.stringify(requestBody);
9400
9423
  const response = await fetch(url, {
9401
9424
  method: "POST",
9402
9425
  headers: { "Content-Type": "application/json" },
@@ -9418,10 +9441,21 @@ function pemToBuffer(pem) {
9418
9441
  // src/client/modules/attest/jwt-provider.ts
9419
9442
  var JwtProvider = class {
9420
9443
  constructor(attestClient, bufferSeconds = 30) {
9444
+ this.pendingExtraData = /* @__PURE__ */ new Map();
9421
9445
  this.attestClient = attestClient;
9422
9446
  this.bufferSeconds = bufferSeconds;
9423
9447
  }
9424
- async getToken() {
9448
+ async getToken(extraData) {
9449
+ if (extraData && extraData.length > 0) {
9450
+ const key = extraData.toString("hex");
9451
+ const existing = this.pendingExtraData.get(key);
9452
+ if (existing) return existing;
9453
+ const promise = this.attestClient.attest(extraData).finally(() => {
9454
+ this.pendingExtraData.delete(key);
9455
+ });
9456
+ this.pendingExtraData.set(key, promise);
9457
+ return promise;
9458
+ }
9425
9459
  if (this.cachedToken && !this.isExpiringSoon()) {
9426
9460
  return this.cachedToken;
9427
9461
  }