@layr-labs/ecloud-sdk 0.5.0-dev.3 → 1.0.0-dev.1
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/VERSION +2 -2
- package/dist/attest.cjs +31 -9
- package/dist/attest.cjs.map +1 -1
- package/dist/attest.d.cts +3 -2
- package/dist/attest.d.ts +3 -2
- package/dist/attest.js +31 -9
- package/dist/attest.js.map +1 -1
- package/dist/billing.cjs +46 -6
- package/dist/billing.cjs.map +1 -1
- package/dist/billing.d.cts +3 -1
- package/dist/billing.d.ts +3 -1
- package/dist/billing.js +46 -6
- package/dist/billing.js.map +1 -1
- package/dist/browser.cjs +40 -6
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +4 -4
- package/dist/browser.d.ts +4 -4
- package/dist/browser.js +40 -6
- package/dist/browser.js.map +1 -1
- package/dist/{compute-Ckyn8ils.d.cts → compute-Bn6KcW3x.d.cts} +1 -1
- package/dist/{compute-Cnw6rwSB.d.ts → compute-Do2t0Fo8.d.ts} +1 -1
- package/dist/compute.cjs +8 -2
- package/dist/compute.cjs.map +1 -1
- package/dist/compute.d.cts +2 -2
- package/dist/compute.d.ts +2 -2
- package/dist/compute.js +8 -2
- package/dist/compute.js.map +1 -1
- package/dist/{helpers-DZL2bg9p.d.cts → helpers-BRamdfGn.d.ts} +5 -1
- package/dist/{helpers-Dj2ME5rp.d.ts → helpers-CfsfcGJO.d.cts} +5 -1
- package/dist/{index-U2vKBrry.d.cts → index-BbH7ZCIu.d.cts} +15 -1
- package/dist/{index-U2vKBrry.d.ts → index-BbH7ZCIu.d.ts} +15 -1
- package/dist/index.cjs +78 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +78 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as EnvironmentConfig,
|
|
1
|
+
import { E as EnvironmentConfig, a7 as SubscriptionStatus, f as BillingEnvironmentConfig, $ as ProductID, k as CreateSubscriptionOptions, l as CreateSubscriptionResponse, z as GetSubscriptionOptions, a0 as ProductSubscriptionResponse, M as PaymentMethodsResponse, m as CreditPurchaseResponse, G as GasEstimate, H as Logger } from './index-BbH7ZCIu.js';
|
|
2
2
|
import { Address, Hex, WalletClient, PublicClient, SignAuthorizationReturnType, Chain } from 'viem';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -733,6 +733,8 @@ interface BillingApiClientOptions {
|
|
|
733
733
|
* When false (default), uses EIP-712 typed data signatures for each request.
|
|
734
734
|
*/
|
|
735
735
|
useSession?: boolean;
|
|
736
|
+
/** Log request/response details to stderr */
|
|
737
|
+
verbose?: boolean;
|
|
736
738
|
}
|
|
737
739
|
/**
|
|
738
740
|
* BillingAPI Client for managing product subscriptions.
|
|
@@ -796,6 +798,8 @@ declare class BillingApiClient {
|
|
|
796
798
|
createSubscription(productId?: ProductID, options?: CreateSubscriptionOptions): Promise<CreateSubscriptionResponse>;
|
|
797
799
|
getSubscription(productId?: ProductID, options?: GetSubscriptionOptions): Promise<ProductSubscriptionResponse>;
|
|
798
800
|
cancelSubscription(productId?: ProductID): Promise<void>;
|
|
801
|
+
getPaymentMethods(): Promise<PaymentMethodsResponse>;
|
|
802
|
+
purchaseCredits(amountCents: number, paymentMethodId?: string): Promise<CreditPurchaseResponse>;
|
|
799
803
|
/**
|
|
800
804
|
* Make an authenticated request to the billing API
|
|
801
805
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as EnvironmentConfig,
|
|
1
|
+
import { E as EnvironmentConfig, a7 as SubscriptionStatus, f as BillingEnvironmentConfig, $ as ProductID, k as CreateSubscriptionOptions, l as CreateSubscriptionResponse, z as GetSubscriptionOptions, a0 as ProductSubscriptionResponse, M as PaymentMethodsResponse, m as CreditPurchaseResponse, G as GasEstimate, H as Logger } from './index-BbH7ZCIu.cjs';
|
|
2
2
|
import { Address, Hex, WalletClient, PublicClient, SignAuthorizationReturnType, Chain } from 'viem';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -733,6 +733,8 @@ interface BillingApiClientOptions {
|
|
|
733
733
|
* When false (default), uses EIP-712 typed data signatures for each request.
|
|
734
734
|
*/
|
|
735
735
|
useSession?: boolean;
|
|
736
|
+
/** Log request/response details to stderr */
|
|
737
|
+
verbose?: boolean;
|
|
736
738
|
}
|
|
737
739
|
/**
|
|
738
740
|
* BillingAPI Client for managing product subscriptions.
|
|
@@ -796,6 +798,8 @@ declare class BillingApiClient {
|
|
|
796
798
|
createSubscription(productId?: ProductID, options?: CreateSubscriptionOptions): Promise<CreateSubscriptionResponse>;
|
|
797
799
|
getSubscription(productId?: ProductID, options?: GetSubscriptionOptions): Promise<ProductSubscriptionResponse>;
|
|
798
800
|
cancelSubscription(productId?: ProductID): Promise<void>;
|
|
801
|
+
getPaymentMethods(): Promise<PaymentMethodsResponse>;
|
|
802
|
+
purchaseCredits(amountCents: number, paymentMethodId?: string): Promise<CreditPurchaseResponse>;
|
|
799
803
|
/**
|
|
800
804
|
* Make an authenticated request to the billing API
|
|
801
805
|
*
|
|
@@ -749,6 +749,20 @@ interface SubscriptionOpts {
|
|
|
749
749
|
/** URL to redirect to if checkout is canceled */
|
|
750
750
|
cancelUrl?: string;
|
|
751
751
|
}
|
|
752
|
+
interface PaymentMethod {
|
|
753
|
+
id: string;
|
|
754
|
+
stripePaymentMethodId: string;
|
|
755
|
+
createdAt: string;
|
|
756
|
+
}
|
|
757
|
+
interface PaymentMethodsResponse {
|
|
758
|
+
paymentMethods: PaymentMethod[];
|
|
759
|
+
}
|
|
760
|
+
interface CreditPurchaseResponse {
|
|
761
|
+
purchaseId?: string;
|
|
762
|
+
checkoutSessionId?: string;
|
|
763
|
+
checkoutUrl?: string;
|
|
764
|
+
amountCents: string;
|
|
765
|
+
}
|
|
752
766
|
interface BillingEnvironmentConfig {
|
|
753
767
|
billingApiServerURL: string;
|
|
754
768
|
}
|
|
@@ -776,4 +790,4 @@ interface SequentialDeployResult {
|
|
|
776
790
|
};
|
|
777
791
|
}
|
|
778
792
|
|
|
779
|
-
export { type
|
|
793
|
+
export { type ProductID as $, type AppId as A, type BatchedDeployResult as B, type CalculateAppIDOptions as C, type DeployAppOptions as D, type EnvironmentConfig as E, type IsDelegatedOptions as F, type GasEstimate as G, type Logger as H, type ImageDigestResult as I, type PaymentIssueResponse as J, type PaymentMethod as K, type LifecycleOpts as L, type PaymentMethodsResponse as M, type NoActiveSubscriptionResponse as N, type PrepareDeployBatchOptions as O, type ParsedEnvironment as P, type PrepareDeployFromVerifiableBuildOpts as Q, type PrepareDeployOpts as R, type PrepareUpgradeBatchOptions as S, type PrepareUpgradeFromVerifiableBuildOpts as T, type PrepareUpgradeOpts as U, type PreparedDeploy as V, type PreparedDeployBatch as W, type PreparedDeployData as X, type PreparedUpgrade as Y, type PreparedUpgradeBatch as Z, type PreparedUpgradeData as _, type AlreadyActiveResponse as a, type ProductSubscriptionResponse as a0, type Release as a1, type SendTransactionOptions as a2, type SequentialDeployResult as a3, type SubscribeResponse as a4, type SubscriptionLineItem as a5, type SubscriptionOpts as a6, type SubscriptionStatus as a7, type SuspendOptions as a8, type UndelegateOptions as a9, undelegate as aA, upgradeApp as aB, getAppLatestReleaseBlockNumbers as aC, getBlockTimestamps as aD, type UpgradeAppOptions as aa, type UpgradeAppOpts as ab, calculateAppID as ac, deployApp as ad, estimateTransactionGas as ae, executeDeployBatch as af, executeDeployBatched as ag, executeDeploySequential as ah, executeUpgradeBatch as ai, formatETH as aj, getActiveAppCount as ak, getAllAppsByDeveloper as al, getAppsByBillingAccount as am, getAppsByCreator as an, getAppsByDeveloper as ao, getBillingType as ap, getMaxActiveAppsPerUser as aq, isDelegated as ar, type logVisibility as as, noopLogger as at, prepareDeployBatch as au, prepareUpgradeBatch as av, sendAndWaitForTransaction as aw, supportsEIP5792 as ax, supportsEIP7702 as ay, suspend as az, type AppConfig as b, type AppProfile as c, type AppProfileResponse as d, type AppRecord as e, type BillingEnvironmentConfig as f, type CancelResponse as g, type CancelSuccessResponse as h, type ChainID as i, type CheckoutCreatedResponse as j, type CreateSubscriptionOptions as k, type CreateSubscriptionResponse as l, type CreditPurchaseResponse as m, type DeployAppOpts as n, type DeployOptions as o, type DeployProgressCallback as p, type DeployResult as q, type DeployStep as r, type DockerImageConfig as s, type EstimateGasOptions as t, type ExecuteDeployBatchedOptions as u, type ExecuteDeployResult as v, type ExecuteDeploySequentialOptions as w, type ExecuteUpgradeResult as x, type GasOpts as y, type GetSubscriptionOptions as z };
|
|
@@ -749,6 +749,20 @@ interface SubscriptionOpts {
|
|
|
749
749
|
/** URL to redirect to if checkout is canceled */
|
|
750
750
|
cancelUrl?: string;
|
|
751
751
|
}
|
|
752
|
+
interface PaymentMethod {
|
|
753
|
+
id: string;
|
|
754
|
+
stripePaymentMethodId: string;
|
|
755
|
+
createdAt: string;
|
|
756
|
+
}
|
|
757
|
+
interface PaymentMethodsResponse {
|
|
758
|
+
paymentMethods: PaymentMethod[];
|
|
759
|
+
}
|
|
760
|
+
interface CreditPurchaseResponse {
|
|
761
|
+
purchaseId?: string;
|
|
762
|
+
checkoutSessionId?: string;
|
|
763
|
+
checkoutUrl?: string;
|
|
764
|
+
amountCents: string;
|
|
765
|
+
}
|
|
752
766
|
interface BillingEnvironmentConfig {
|
|
753
767
|
billingApiServerURL: string;
|
|
754
768
|
}
|
|
@@ -776,4 +790,4 @@ interface SequentialDeployResult {
|
|
|
776
790
|
};
|
|
777
791
|
}
|
|
778
792
|
|
|
779
|
-
export { type
|
|
793
|
+
export { type ProductID as $, type AppId as A, type BatchedDeployResult as B, type CalculateAppIDOptions as C, type DeployAppOptions as D, type EnvironmentConfig as E, type IsDelegatedOptions as F, type GasEstimate as G, type Logger as H, type ImageDigestResult as I, type PaymentIssueResponse as J, type PaymentMethod as K, type LifecycleOpts as L, type PaymentMethodsResponse as M, type NoActiveSubscriptionResponse as N, type PrepareDeployBatchOptions as O, type ParsedEnvironment as P, type PrepareDeployFromVerifiableBuildOpts as Q, type PrepareDeployOpts as R, type PrepareUpgradeBatchOptions as S, type PrepareUpgradeFromVerifiableBuildOpts as T, type PrepareUpgradeOpts as U, type PreparedDeploy as V, type PreparedDeployBatch as W, type PreparedDeployData as X, type PreparedUpgrade as Y, type PreparedUpgradeBatch as Z, type PreparedUpgradeData as _, type AlreadyActiveResponse as a, type ProductSubscriptionResponse as a0, type Release as a1, type SendTransactionOptions as a2, type SequentialDeployResult as a3, type SubscribeResponse as a4, type SubscriptionLineItem as a5, type SubscriptionOpts as a6, type SubscriptionStatus as a7, type SuspendOptions as a8, type UndelegateOptions as a9, undelegate as aA, upgradeApp as aB, getAppLatestReleaseBlockNumbers as aC, getBlockTimestamps as aD, type UpgradeAppOptions as aa, type UpgradeAppOpts as ab, calculateAppID as ac, deployApp as ad, estimateTransactionGas as ae, executeDeployBatch as af, executeDeployBatched as ag, executeDeploySequential as ah, executeUpgradeBatch as ai, formatETH as aj, getActiveAppCount as ak, getAllAppsByDeveloper as al, getAppsByBillingAccount as am, getAppsByCreator as an, getAppsByDeveloper as ao, getBillingType as ap, getMaxActiveAppsPerUser as aq, isDelegated as ar, type logVisibility as as, noopLogger as at, prepareDeployBatch as au, prepareUpgradeBatch as av, sendAndWaitForTransaction as aw, supportsEIP5792 as ax, supportsEIP7702 as ay, suspend as az, type AppConfig as b, type AppProfile as c, type AppProfileResponse as d, type AppRecord as e, type BillingEnvironmentConfig as f, type CancelResponse as g, type CancelSuccessResponse as h, type ChainID as i, type CheckoutCreatedResponse as j, type CreateSubscriptionOptions as k, type CreateSubscriptionResponse as l, type CreditPurchaseResponse as m, type DeployAppOpts as n, type DeployOptions as o, type DeployProgressCallback as p, type DeployResult as q, type DeployStep as r, type DockerImageConfig as s, type EstimateGasOptions as t, type ExecuteDeployBatchedOptions as u, type ExecuteDeployResult as v, type ExecuteDeploySequentialOptions as w, type ExecuteUpgradeResult as x, type GasOpts as y, type GetSubscriptionOptions as z };
|
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.
|
|
4989
|
+
const version = true ? "1.0.0-dev.1" : "0.0.0";
|
|
4990
4990
|
return `ecloud-sdk/v${version}`;
|
|
4991
4991
|
}
|
|
4992
4992
|
var UserApiClient = class {
|
|
@@ -5823,7 +5823,13 @@ function getEnvironmentConfig(environment, chainID) {
|
|
|
5823
5823
|
const resolvedChainID = chainID || (environment === "sepolia" || environment === "sepolia-dev" ? SEPOLIA_CHAIN_ID : MAINNET_CHAIN_ID);
|
|
5824
5824
|
return {
|
|
5825
5825
|
...env,
|
|
5826
|
-
chainID: BigInt(resolvedChainID)
|
|
5826
|
+
chainID: BigInt(resolvedChainID),
|
|
5827
|
+
...process.env.ECLOUD_USER_API_URL && {
|
|
5828
|
+
userApiServerURL: process.env.ECLOUD_USER_API_URL
|
|
5829
|
+
},
|
|
5830
|
+
...process.env.ECLOUD_RPC_URL && {
|
|
5831
|
+
defaultRPCURL: process.env.ECLOUD_RPC_URL
|
|
5832
|
+
}
|
|
5827
5833
|
};
|
|
5828
5834
|
}
|
|
5829
5835
|
function getBillingEnvironmentConfig(build) {
|
|
@@ -5831,7 +5837,12 @@ function getBillingEnvironmentConfig(build) {
|
|
|
5831
5837
|
if (!config) {
|
|
5832
5838
|
throw new Error(`Unknown billing environment: ${build}`);
|
|
5833
5839
|
}
|
|
5834
|
-
return
|
|
5840
|
+
return {
|
|
5841
|
+
...config,
|
|
5842
|
+
...process.env.ECLOUD_BILLING_API_URL && {
|
|
5843
|
+
billingApiServerURL: process.env.ECLOUD_BILLING_API_URL
|
|
5844
|
+
}
|
|
5845
|
+
};
|
|
5835
5846
|
}
|
|
5836
5847
|
function getBuildType() {
|
|
5837
5848
|
const buildTimeType = true ? "dev"?.toLowerCase() : void 0;
|
|
@@ -6136,6 +6147,20 @@ var BillingApiClient = class {
|
|
|
6136
6147
|
const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;
|
|
6137
6148
|
await this.makeAuthenticatedRequest(endpoint, "DELETE", productId);
|
|
6138
6149
|
}
|
|
6150
|
+
async getPaymentMethods() {
|
|
6151
|
+
const endpoint = `${this.config.billingApiServerURL}/v1/payment-methods`;
|
|
6152
|
+
const resp = await this.makeAuthenticatedRequest(endpoint, "GET", "compute");
|
|
6153
|
+
return resp.json();
|
|
6154
|
+
}
|
|
6155
|
+
async purchaseCredits(amountCents, paymentMethodId) {
|
|
6156
|
+
const endpoint = `${this.config.billingApiServerURL}/v1/credits/purchase`;
|
|
6157
|
+
const body = { amountCents };
|
|
6158
|
+
if (paymentMethodId) {
|
|
6159
|
+
body.paymentMethodId = paymentMethodId;
|
|
6160
|
+
}
|
|
6161
|
+
const resp = await this.makeAuthenticatedRequest(endpoint, "POST", "compute", body);
|
|
6162
|
+
return resp.json();
|
|
6163
|
+
}
|
|
6139
6164
|
// ==========================================================================
|
|
6140
6165
|
// Internal Methods
|
|
6141
6166
|
// ==========================================================================
|
|
@@ -6145,10 +6170,19 @@ var BillingApiClient = class {
|
|
|
6145
6170
|
* Uses session auth if useSession is true, otherwise uses EIP-712 signature auth.
|
|
6146
6171
|
*/
|
|
6147
6172
|
async makeAuthenticatedRequest(url, method, productId, body) {
|
|
6148
|
-
if (this.
|
|
6149
|
-
|
|
6173
|
+
if (this.options.verbose) {
|
|
6174
|
+
console.debug(`[BillingAPI] ${method} ${url}`);
|
|
6175
|
+
}
|
|
6176
|
+
const resp = this.useSession ? await this.makeSessionAuthenticatedRequest(url, method, body) : await this.makeSignatureAuthenticatedRequest(url, method, productId, body);
|
|
6177
|
+
if (this.options.verbose) {
|
|
6178
|
+
const data = await resp.json();
|
|
6179
|
+
console.debug(`[BillingAPI] Response:`, JSON.stringify(data, null, 2));
|
|
6180
|
+
return {
|
|
6181
|
+
json: async () => data,
|
|
6182
|
+
text: async () => JSON.stringify(data)
|
|
6183
|
+
};
|
|
6150
6184
|
}
|
|
6151
|
-
return
|
|
6185
|
+
return resp;
|
|
6152
6186
|
}
|
|
6153
6187
|
/**
|
|
6154
6188
|
* Make a request using session-based authentication (cookies)
|
|
@@ -8337,7 +8371,7 @@ function createBillingModule(config) {
|
|
|
8337
8371
|
const address = walletClient.account.address;
|
|
8338
8372
|
const logger = getLogger(verbose);
|
|
8339
8373
|
const billingEnvConfig = getBillingEnvironmentConfig(getBuildType());
|
|
8340
|
-
const billingApi = new BillingApiClient(billingEnvConfig, walletClient);
|
|
8374
|
+
const billingApi = new BillingApiClient(billingEnvConfig, walletClient, { verbose });
|
|
8341
8375
|
const environmentConfig = getEnvironmentConfig(environment);
|
|
8342
8376
|
const usdcCreditsAddress = environmentConfig.usdcCreditsAddress;
|
|
8343
8377
|
if (!usdcCreditsAddress) {
|
|
@@ -8501,6 +8535,12 @@ function createBillingModule(config) {
|
|
|
8501
8535
|
};
|
|
8502
8536
|
}
|
|
8503
8537
|
);
|
|
8538
|
+
},
|
|
8539
|
+
async getPaymentMethods() {
|
|
8540
|
+
return billingApi.getPaymentMethods();
|
|
8541
|
+
},
|
|
8542
|
+
async purchaseCredits(amountCents, paymentMethodId) {
|
|
8543
|
+
return billingApi.purchaseCredits(amountCents, paymentMethodId);
|
|
8504
8544
|
}
|
|
8505
8545
|
};
|
|
8506
8546
|
return module2;
|
|
@@ -9318,7 +9358,10 @@ var AttestClient = class {
|
|
|
9318
9358
|
constructor(config) {
|
|
9319
9359
|
this.config = config;
|
|
9320
9360
|
}
|
|
9321
|
-
async attest() {
|
|
9361
|
+
async attest(extraData) {
|
|
9362
|
+
if (extraData && extraData.length > 1048576) {
|
|
9363
|
+
throw new Error(`extraData exceeds 1MB limit (${extraData.length} bytes)`);
|
|
9364
|
+
}
|
|
9322
9365
|
const { publicKey, privateKey } = (0, import_node_crypto.generateKeyPairSync)("rsa", {
|
|
9323
9366
|
modulusLength: 4096,
|
|
9324
9367
|
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
@@ -9326,8 +9369,8 @@ var AttestClient = class {
|
|
|
9326
9369
|
});
|
|
9327
9370
|
const challengeHash = (0, import_node_crypto.createHash)("sha256").update(CHALLENGE_PREFIX).update(NULL_BYTE).update(publicKey).digest();
|
|
9328
9371
|
const socketPath = this.config.socketPath ?? DEFAULT_SOCKET_PATH;
|
|
9329
|
-
const attestationBytes = await this.getAttestation(socketPath, challengeHash);
|
|
9330
|
-
const attestResponse = await this.postAttest(attestationBytes, publicKey);
|
|
9372
|
+
const attestationBytes = await this.getAttestation(socketPath, challengeHash, extraData);
|
|
9373
|
+
const attestResponse = await this.postAttest(attestationBytes, publicKey, extraData);
|
|
9331
9374
|
this.verifySignature(JSON.stringify(attestResponse.data), attestResponse.signature);
|
|
9332
9375
|
const rsaPrivateKey = await crypto.subtle.importKey(
|
|
9333
9376
|
"pkcs8",
|
|
@@ -9359,9 +9402,13 @@ var AttestClient = class {
|
|
|
9359
9402
|
throw new Error("KMS response signature verification failed");
|
|
9360
9403
|
}
|
|
9361
9404
|
}
|
|
9362
|
-
getAttestation(socketPath, challenge) {
|
|
9405
|
+
getAttestation(socketPath, challenge, extraData) {
|
|
9363
9406
|
return new Promise((resolve2, reject) => {
|
|
9364
|
-
const
|
|
9407
|
+
const requestBody = { challenge: challenge.toString("base64") };
|
|
9408
|
+
if (extraData && extraData.length > 0) {
|
|
9409
|
+
requestBody.extra_data = extraData.toString("base64");
|
|
9410
|
+
}
|
|
9411
|
+
const body = JSON.stringify(requestBody);
|
|
9365
9412
|
const req = import_node_http.default.request(
|
|
9366
9413
|
{
|
|
9367
9414
|
socketPath,
|
|
@@ -9389,14 +9436,18 @@ var AttestClient = class {
|
|
|
9389
9436
|
req.end();
|
|
9390
9437
|
});
|
|
9391
9438
|
}
|
|
9392
|
-
async postAttest(attestationBytes, rsaPublicKey) {
|
|
9439
|
+
async postAttest(attestationBytes, rsaPublicKey, extraData) {
|
|
9393
9440
|
const url = `${this.config.kmsServerURL}/auth/attest`;
|
|
9394
|
-
const
|
|
9441
|
+
const requestBody = {
|
|
9395
9442
|
version: 3,
|
|
9396
9443
|
attestation: attestationBytes.toString("base64"),
|
|
9397
9444
|
rsaKey: rsaPublicKey,
|
|
9398
9445
|
audience: this.config.audience
|
|
9399
|
-
}
|
|
9446
|
+
};
|
|
9447
|
+
if (extraData && extraData.length > 0) {
|
|
9448
|
+
requestBody.extra_data = extraData.toString("base64");
|
|
9449
|
+
}
|
|
9450
|
+
const body = JSON.stringify(requestBody);
|
|
9400
9451
|
const response = await fetch(url, {
|
|
9401
9452
|
method: "POST",
|
|
9402
9453
|
headers: { "Content-Type": "application/json" },
|
|
@@ -9418,10 +9469,21 @@ function pemToBuffer(pem) {
|
|
|
9418
9469
|
// src/client/modules/attest/jwt-provider.ts
|
|
9419
9470
|
var JwtProvider = class {
|
|
9420
9471
|
constructor(attestClient, bufferSeconds = 30) {
|
|
9472
|
+
this.pendingExtraData = /* @__PURE__ */ new Map();
|
|
9421
9473
|
this.attestClient = attestClient;
|
|
9422
9474
|
this.bufferSeconds = bufferSeconds;
|
|
9423
9475
|
}
|
|
9424
|
-
async getToken() {
|
|
9476
|
+
async getToken(extraData) {
|
|
9477
|
+
if (extraData && extraData.length > 0) {
|
|
9478
|
+
const key = extraData.toString("hex");
|
|
9479
|
+
const existing = this.pendingExtraData.get(key);
|
|
9480
|
+
if (existing) return existing;
|
|
9481
|
+
const promise = this.attestClient.attest(extraData).finally(() => {
|
|
9482
|
+
this.pendingExtraData.delete(key);
|
|
9483
|
+
});
|
|
9484
|
+
this.pendingExtraData.set(key, promise);
|
|
9485
|
+
return promise;
|
|
9486
|
+
}
|
|
9425
9487
|
if (this.cachedToken && !this.isExpiringSoon()) {
|
|
9426
9488
|
return this.cachedToken;
|
|
9427
9489
|
}
|