@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.js CHANGED
@@ -4837,7 +4837,7 @@ var CanViewAppLogsPermission = "0x2fd3f2fe";
4837
4837
  var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
4838
4838
  var CanUpdateAppProfilePermission = "0x036fef61";
4839
4839
  function getDefaultClientId() {
4840
- const version = true ? "0.5.0" : "0.0.0";
4840
+ const version = true ? "1.0.0-dev.2" : "0.0.0";
4841
4841
  return `ecloud-sdk/v${version}`;
4842
4842
  }
4843
4843
  var UserApiClient = class {
@@ -5655,6 +5655,12 @@ var CHAIN_ID_TO_ENVIRONMENT = {
5655
5655
  [SEPOLIA_CHAIN_ID.toString()]: "sepolia",
5656
5656
  [MAINNET_CHAIN_ID.toString()]: "mainnet-alpha"
5657
5657
  };
5658
+ function getApiUrlOverride() {
5659
+ const raw = process.env.ECLOUD_API_URL;
5660
+ if (!raw) return void 0;
5661
+ const trimmed = raw.trim().replace(/\/+$/, "");
5662
+ return trimmed.length > 0 ? trimmed : void 0;
5663
+ }
5658
5664
  function getEnvironmentConfig(environment, chainID) {
5659
5665
  const env = ENVIRONMENTS[environment];
5660
5666
  if (!env) {
@@ -5672,9 +5678,11 @@ function getEnvironmentConfig(environment, chainID) {
5672
5678
  }
5673
5679
  }
5674
5680
  const resolvedChainID = chainID || (environment === "sepolia" || environment === "sepolia-dev" ? SEPOLIA_CHAIN_ID : MAINNET_CHAIN_ID);
5681
+ const apiUrlOverride = getApiUrlOverride();
5675
5682
  return {
5676
5683
  ...env,
5677
- chainID: BigInt(resolvedChainID)
5684
+ chainID: BigInt(resolvedChainID),
5685
+ ...apiUrlOverride ? { userApiServerURL: apiUrlOverride } : {}
5678
5686
  };
5679
5687
  }
5680
5688
  function getBillingEnvironmentConfig(build) {
@@ -5682,10 +5690,14 @@ function getBillingEnvironmentConfig(build) {
5682
5690
  if (!config) {
5683
5691
  throw new Error(`Unknown billing environment: ${build}`);
5684
5692
  }
5693
+ const apiUrlOverride = getApiUrlOverride();
5694
+ if (apiUrlOverride) {
5695
+ return { billingApiServerURL: apiUrlOverride };
5696
+ }
5685
5697
  return config;
5686
5698
  }
5687
5699
  function getBuildType() {
5688
- const buildTimeType = true ? "prod"?.toLowerCase() : void 0;
5700
+ const buildTimeType = true ? "dev"?.toLowerCase() : void 0;
5689
5701
  const runtimeType = process.env.BUILD_TYPE?.toLowerCase();
5690
5702
  const buildType = buildTimeType || runtimeType;
5691
5703
  if (buildType === "dev") {
@@ -9169,7 +9181,10 @@ var AttestClient = class {
9169
9181
  constructor(config) {
9170
9182
  this.config = config;
9171
9183
  }
9172
- async attest() {
9184
+ async attest(extraData) {
9185
+ if (extraData && extraData.length > 1048576) {
9186
+ throw new Error(`extraData exceeds 1MB limit (${extraData.length} bytes)`);
9187
+ }
9173
9188
  const { publicKey, privateKey } = generateKeyPairSync("rsa", {
9174
9189
  modulusLength: 4096,
9175
9190
  publicKeyEncoding: { type: "spki", format: "pem" },
@@ -9177,8 +9192,8 @@ var AttestClient = class {
9177
9192
  });
9178
9193
  const challengeHash = createHash("sha256").update(CHALLENGE_PREFIX).update(NULL_BYTE).update(publicKey).digest();
9179
9194
  const socketPath = this.config.socketPath ?? DEFAULT_SOCKET_PATH;
9180
- const attestationBytes = await this.getAttestation(socketPath, challengeHash);
9181
- const attestResponse = await this.postAttest(attestationBytes, publicKey);
9195
+ const attestationBytes = await this.getAttestation(socketPath, challengeHash, extraData);
9196
+ const attestResponse = await this.postAttest(attestationBytes, publicKey, extraData);
9182
9197
  this.verifySignature(JSON.stringify(attestResponse.data), attestResponse.signature);
9183
9198
  const rsaPrivateKey = await crypto.subtle.importKey(
9184
9199
  "pkcs8",
@@ -9210,9 +9225,13 @@ var AttestClient = class {
9210
9225
  throw new Error("KMS response signature verification failed");
9211
9226
  }
9212
9227
  }
9213
- getAttestation(socketPath, challenge) {
9228
+ getAttestation(socketPath, challenge, extraData) {
9214
9229
  return new Promise((resolve2, reject) => {
9215
- const body = JSON.stringify({ challenge: challenge.toString("base64") });
9230
+ const requestBody = { challenge: challenge.toString("base64") };
9231
+ if (extraData && extraData.length > 0) {
9232
+ requestBody.extra_data = extraData.toString("base64");
9233
+ }
9234
+ const body = JSON.stringify(requestBody);
9216
9235
  const req = http2.request(
9217
9236
  {
9218
9237
  socketPath,
@@ -9240,14 +9259,18 @@ var AttestClient = class {
9240
9259
  req.end();
9241
9260
  });
9242
9261
  }
9243
- async postAttest(attestationBytes, rsaPublicKey) {
9262
+ async postAttest(attestationBytes, rsaPublicKey, extraData) {
9244
9263
  const url = `${this.config.kmsServerURL}/auth/attest`;
9245
- const body = JSON.stringify({
9264
+ const requestBody = {
9246
9265
  version: 3,
9247
9266
  attestation: attestationBytes.toString("base64"),
9248
9267
  rsaKey: rsaPublicKey,
9249
9268
  audience: this.config.audience
9250
- });
9269
+ };
9270
+ if (extraData && extraData.length > 0) {
9271
+ requestBody.extra_data = extraData.toString("base64");
9272
+ }
9273
+ const body = JSON.stringify(requestBody);
9251
9274
  const response = await fetch(url, {
9252
9275
  method: "POST",
9253
9276
  headers: { "Content-Type": "application/json" },
@@ -9269,10 +9292,21 @@ function pemToBuffer(pem) {
9269
9292
  // src/client/modules/attest/jwt-provider.ts
9270
9293
  var JwtProvider = class {
9271
9294
  constructor(attestClient, bufferSeconds = 30) {
9295
+ this.pendingExtraData = /* @__PURE__ */ new Map();
9272
9296
  this.attestClient = attestClient;
9273
9297
  this.bufferSeconds = bufferSeconds;
9274
9298
  }
9275
- async getToken() {
9299
+ async getToken(extraData) {
9300
+ if (extraData && extraData.length > 0) {
9301
+ const key = extraData.toString("hex");
9302
+ const existing = this.pendingExtraData.get(key);
9303
+ if (existing) return existing;
9304
+ const promise = this.attestClient.attest(extraData).finally(() => {
9305
+ this.pendingExtraData.delete(key);
9306
+ });
9307
+ this.pendingExtraData.set(key, promise);
9308
+ return promise;
9309
+ }
9276
9310
  if (this.cachedToken && !this.isExpiringSoon()) {
9277
9311
  return this.cachedToken;
9278
9312
  }