@layr-labs/ecloud-sdk 0.2.1-dev → 0.3.0-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/VERSION +2 -2
- package/dist/billing.cjs +286 -9
- package/dist/billing.cjs.map +1 -1
- package/dist/billing.d.cts +1 -1
- package/dist/billing.d.ts +1 -1
- package/dist/billing.js +288 -9
- package/dist/billing.js.map +1 -1
- package/dist/browser.cjs +2551 -127
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +243 -5
- package/dist/browser.d.ts +243 -5
- package/dist/browser.js +2514 -132
- package/dist/browser.js.map +1 -1
- package/dist/{compute-B85ikS78.d.ts → compute-CdZxISln.d.ts} +1 -1
- package/dist/{compute-CC0R7HEu.d.cts → compute-Dstl0CA0.d.cts} +1 -1
- package/dist/compute.cjs +247 -22
- 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 +250 -27
- package/dist/compute.js.map +1 -1
- package/dist/helpers-4w0Iojmm.d.ts +983 -0
- package/dist/helpers-Dk0zwgms.d.cts +983 -0
- package/dist/{index-D5oW73Dx.d.cts → index-C0w92tCs.d.cts} +313 -2
- package/dist/{index-D5oW73Dx.d.ts → index-C0w92tCs.d.ts} +313 -2
- package/dist/index.cjs +751 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -88
- package/dist/index.d.ts +8 -88
- package/dist/index.js +743 -65
- package/dist/index.js.map +1 -1
- package/package.json +12 -2
- package/dist/eip7702-CXCYfOnk.d.ts +0 -400
- package/dist/eip7702-DeqoCP5b.d.cts +0 -400
package/dist/browser.d.cts
CHANGED
|
@@ -1,7 +1,93 @@
|
|
|
1
|
-
import { A as AppId } from './index-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { A as AppId } from './index-C0w92tCs.cjs';
|
|
2
|
+
export { al as AlreadyActiveResponse, w as AppConfig, ac as AppProfile, ad as AppProfileResponse, a2 as AppRecord, K as BatchedDeployResult, a5 as BillingEnvironmentConfig, C as CalculateAppIDOptions, aq as CancelResponse, ao as CancelSuccessResponse, af as ChainID, ak as CheckoutCreatedResponse, ai as CreateSubscriptionOptions, aj as CreateSubscriptionResponse, D as DeployAppOptions, N as DeployAppOpts, a3 as DeployOptions, at as DeployProgressCallback, a4 as DeployResult, au as DeployStep, aa as DockerImageConfig, a6 as EnvironmentConfig, E as EstimateGasOptions, J as ExecuteDeployBatchedOptions, X as ExecuteDeployResult, H as ExecuteDeploySequentialOptions, Y as ExecuteUpgradeResult, G as GasEstimate, W as GasOpts, a9 as ImageDigestResult, I as IsDelegatedOptions, a1 as LifecycleOpts, ab as Logger, ap as NoActiveSubscriptionResponse, a8 as ParsedEnvironment, am as PaymentIssueResponse, P as PrepareDeployBatchOptions, T as PrepareDeployFromVerifiableBuildOpts, Q as PrepareDeployOpts, x as PrepareUpgradeBatchOptions, V as PrepareUpgradeFromVerifiableBuildOpts, R as PrepareUpgradeOpts, $ as PreparedDeploy, y as PreparedDeployBatch, Z as PreparedDeployData, a0 as PreparedUpgrade, z as PreparedUpgradeBatch, _ as PreparedUpgradeData, ae as ProductID, ar as ProductSubscriptionResponse, a7 as Release, S as SendTransactionOptions, av as SequentialDeployResult, an as SubscribeResponse, ah as SubscriptionLineItem, as as SubscriptionOpts, ag as SubscriptionStatus, B as SuspendOptions, F as UndelegateOptions, U as UpgradeAppOptions, O as UpgradeAppOpts, j as calculateAppID, i as deployApp, e as estimateTransactionGas, h as executeDeployBatch, l as executeDeployBatched, k as executeDeploySequential, o as executeUpgradeBatch, f as formatETH, c as getActiveAppCount, g as getAllAppsByDeveloper, a as getAppsByCreator, b as getAppsByDeveloper, d as getMaxActiveAppsPerUser, r as isDelegated, M as logVisibility, L as noopLogger, p as prepareDeployBatch, n as prepareUpgradeBatch, q as sendAndWaitForTransaction, m as supportsEIP5792, s as supportsEIP7702, t as suspend, v as undelegate, u as upgradeApp } from './index-C0w92tCs.cjs';
|
|
3
|
+
import { C as ComputeApiConfig, S as SessionInfo, a as SessionError, b as SiweMessageParams } from './helpers-Dk0zwgms.cjs';
|
|
4
|
+
export { F as AppInfo, J as AppInfoResponse, I as AppMetrics, H as AppProfileInfo, K as BillingApiClient, M as BillingApiClientOptions, ac as BillingApiConfig, af as BillingLoginRequest, ae as BillingLoginResult, ab as BillingSessionError, ad as BillingSessionInfo, z as CreateAppParams, Q as EstimateBatchGasOptions, R as ExecuteBatchOptions, T as Execution, G as GeneratedKey, L as LogVisibility, a4 as LoginRequest, a3 as LoginResult, A as LogsParams, _ as SiweMessageResult, U as UserApiClient, E as UserApiClientOptions, ah as addHexPrefix, j as assertValidImageReference, n as assertValidPrivateKey, P as checkERC7702Delegation, V as createSiweMessage, N as estimateBatchGas, O as executeBatch, k as extractAppNameFromImage, D as generateNewPrivateKey, X as generateNonce, d as getAvailableEnvironments, a7 as getBillingApiSession, c as getBillingEnvironmentConfig, e as getBuildType, ag as getChainFromID, a1 as getComputeApiSession, g as getEnvironmentConfig, a8 as isBillingSessionValid, i as isEnvironmentAvailable, f as isMainnet, a2 as isSessionValid, Y as isSiweMessageExpired, Z as isSiweMessageNotYetValid, B as isSubscriptionActive, a5 as loginToBillingApi, a9 as loginToBothApis, $ as loginToComputeApi, a6 as logoutFromBillingApi, aa as logoutFromBothApis, 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, q as validateDescription, h as validateImageReference, l as validateInstanceTypeSKU, s as validateLogVisibility, y as validateLogsParams, m as validatePrivateKeyFormat, o as validateURL, p as validateXURL } from './helpers-Dk0zwgms.cjs';
|
|
5
|
+
import { WalletClient, Address, Hex } from 'viem';
|
|
6
|
+
import { Buffer as Buffer$1 } from 'buffer';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Build API Client to manage verifiable builds and provenance
|
|
10
|
+
*
|
|
11
|
+
* This is a standalone HTTP client that talks to the (compute) UserAPI host.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
interface BuildApiClientOptions {
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
walletClient?: WalletClient;
|
|
17
|
+
clientId?: string;
|
|
18
|
+
/** Use session-based auth (cookies) instead of signature-based auth */
|
|
19
|
+
useSession?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Billing session ID (value of the billing_session cookie).
|
|
22
|
+
* When provided with useSession=true, this is sent via X-Billing-Session header
|
|
23
|
+
* to authenticate with the billing API for subscription verification.
|
|
24
|
+
* Required for submitBuild when using session auth.
|
|
25
|
+
*/
|
|
26
|
+
billingSessionId?: string;
|
|
27
|
+
}
|
|
28
|
+
declare class BuildApiClient {
|
|
29
|
+
private readonly baseUrl;
|
|
30
|
+
private readonly walletClient?;
|
|
31
|
+
private readonly clientId?;
|
|
32
|
+
private readonly useSession;
|
|
33
|
+
private billingSessionId?;
|
|
34
|
+
constructor(options: BuildApiClientOptions);
|
|
35
|
+
/**
|
|
36
|
+
* Update the billing session ID.
|
|
37
|
+
* Call this after logging into the billing API to enable session-based auth for builds.
|
|
38
|
+
*/
|
|
39
|
+
setBillingSessionId(sessionId: string | undefined): void;
|
|
40
|
+
/**
|
|
41
|
+
* Get the address of the connected wallet
|
|
42
|
+
*/
|
|
43
|
+
get address(): Address;
|
|
44
|
+
/**
|
|
45
|
+
* Submit a new build request.
|
|
46
|
+
* Supports two auth modes (session auth is tried first when billingSessionId is available):
|
|
47
|
+
* 1. Session-based auth: X-Billing-Session header (forwarded billing_session cookie)
|
|
48
|
+
* 2. Signature-based auth: Authorization + X-Account + X-eigenx-expiry headers (requires walletClient)
|
|
49
|
+
*/
|
|
50
|
+
submitBuild(payload: {
|
|
51
|
+
repo_url: string;
|
|
52
|
+
git_ref: string;
|
|
53
|
+
dockerfile_path: string;
|
|
54
|
+
caddyfile_path?: string;
|
|
55
|
+
build_context_path: string;
|
|
56
|
+
dependencies: string[];
|
|
57
|
+
}): Promise<{
|
|
58
|
+
build_id: string;
|
|
59
|
+
}>;
|
|
60
|
+
getBuild(buildId: string): Promise<any>;
|
|
61
|
+
getBuildByDigest(digest: string): Promise<any>;
|
|
62
|
+
verify(identifier: string): Promise<any>;
|
|
63
|
+
/**
|
|
64
|
+
* Get build logs. Supports session auth (identity verification only, no billing check).
|
|
65
|
+
*/
|
|
66
|
+
getLogs(buildId: string): Promise<string>;
|
|
67
|
+
listBuilds(params: {
|
|
68
|
+
billing_address: string;
|
|
69
|
+
limit?: number;
|
|
70
|
+
offset?: number;
|
|
71
|
+
}): Promise<any[]>;
|
|
72
|
+
private publicJsonRequest;
|
|
73
|
+
/**
|
|
74
|
+
* Make a request that ALWAYS requires signature auth (for billing verification).
|
|
75
|
+
* Used for endpoints like POST /builds that need to verify subscription status.
|
|
76
|
+
*/
|
|
77
|
+
private signatureAuthJsonRequest;
|
|
78
|
+
/**
|
|
79
|
+
* Make a request using billing session auth (for billing verification without wallet signature).
|
|
80
|
+
* Forwards the billing_session cookie value via X-Billing-Session header.
|
|
81
|
+
* Used for endpoints that need to verify subscription status when using session-based auth.
|
|
82
|
+
*/
|
|
83
|
+
private billingSessionAuthJsonRequest;
|
|
84
|
+
/**
|
|
85
|
+
* Make an authenticated request that can use session OR signature auth.
|
|
86
|
+
* When useSession is true, relies on cookies for identity verification.
|
|
87
|
+
* Used for endpoints that only need identity verification (not billing).
|
|
88
|
+
*/
|
|
89
|
+
private sessionOrSignatureTextRequest;
|
|
90
|
+
}
|
|
5
91
|
|
|
6
92
|
/**
|
|
7
93
|
* Browser-safe app action encoders
|
|
@@ -23,6 +109,158 @@ declare function encodeStopAppData(appId: AppId): `0x${string}`;
|
|
|
23
109
|
*/
|
|
24
110
|
declare function encodeTerminateAppData(appId: AppId): `0x${string}`;
|
|
25
111
|
|
|
112
|
+
/**
|
|
113
|
+
* React Hook for Compute API Session Management
|
|
114
|
+
*
|
|
115
|
+
* This hook provides a convenient way to manage compute API sessions in React applications.
|
|
116
|
+
* It handles session state, auto-refresh, and provides login/logout methods.
|
|
117
|
+
*
|
|
118
|
+
* IMPORTANT: This hook requires React 18+ as a peer dependency.
|
|
119
|
+
* Make sure your application has React installed.
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
interface UseComputeSessionConfig extends ComputeApiConfig {
|
|
123
|
+
/**
|
|
124
|
+
* Interval in milliseconds to check session validity
|
|
125
|
+
* Set to 0 to disable auto-refresh
|
|
126
|
+
* @default 60000 (1 minute)
|
|
127
|
+
*/
|
|
128
|
+
refreshInterval?: number;
|
|
129
|
+
/**
|
|
130
|
+
* Whether to automatically check session on mount
|
|
131
|
+
* @default true
|
|
132
|
+
*/
|
|
133
|
+
checkOnMount?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Callback when session expires or becomes invalid
|
|
136
|
+
*/
|
|
137
|
+
onSessionExpired?: () => void;
|
|
138
|
+
/**
|
|
139
|
+
* Callback when session is successfully refreshed/validated
|
|
140
|
+
*/
|
|
141
|
+
onSessionRefreshed?: (session: SessionInfo) => void;
|
|
142
|
+
/**
|
|
143
|
+
* Callback when an error occurs
|
|
144
|
+
*/
|
|
145
|
+
onError?: (error: SessionError) => void;
|
|
146
|
+
}
|
|
147
|
+
interface UseComputeSessionReturn {
|
|
148
|
+
/** Current session information */
|
|
149
|
+
session: SessionInfo | null;
|
|
150
|
+
/** Whether the session is currently being loaded/checked */
|
|
151
|
+
isLoading: boolean;
|
|
152
|
+
/** Any error that occurred during session operations */
|
|
153
|
+
error: SessionError | null;
|
|
154
|
+
/** Whether the user is authenticated */
|
|
155
|
+
isAuthenticated: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Login to compute API with SIWE
|
|
158
|
+
*
|
|
159
|
+
* @param params - SIWE message parameters (address, chainId required)
|
|
160
|
+
* @param signMessage - Function to sign the message (from wagmi's useSignMessage)
|
|
161
|
+
* @returns Login result
|
|
162
|
+
*/
|
|
163
|
+
login: (params: Omit<SiweMessageParams, "domain" | "uri"> & {
|
|
164
|
+
domain?: string;
|
|
165
|
+
uri?: string;
|
|
166
|
+
}, signMessage: (args: {
|
|
167
|
+
message: string;
|
|
168
|
+
}) => Promise<Hex>) => Promise<SessionInfo>;
|
|
169
|
+
/**
|
|
170
|
+
* Logout from compute API
|
|
171
|
+
*/
|
|
172
|
+
logout: () => Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Manually refresh/check session status
|
|
175
|
+
*/
|
|
176
|
+
refresh: () => Promise<SessionInfo>;
|
|
177
|
+
/**
|
|
178
|
+
* Clear any error state
|
|
179
|
+
*/
|
|
180
|
+
clearError: () => void;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* React hook for managing compute API sessions with SIWE authentication
|
|
184
|
+
*
|
|
185
|
+
* @param config - Configuration options including baseUrl and refresh settings
|
|
186
|
+
* @returns Session state and methods for login/logout/refresh
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```tsx
|
|
190
|
+
* import { useComputeSession } from "@layr-labs/ecloud-sdk/browser";
|
|
191
|
+
* import { useSignMessage, useAccount } from "wagmi";
|
|
192
|
+
*
|
|
193
|
+
* function MyComponent() {
|
|
194
|
+
* const { address, chainId } = useAccount();
|
|
195
|
+
* const { signMessageAsync } = useSignMessage();
|
|
196
|
+
*
|
|
197
|
+
* const {
|
|
198
|
+
* session,
|
|
199
|
+
* isLoading,
|
|
200
|
+
* isAuthenticated,
|
|
201
|
+
* login,
|
|
202
|
+
* logout,
|
|
203
|
+
* error,
|
|
204
|
+
* } = useComputeSession({
|
|
205
|
+
* baseUrl: "https://api.eigencloud.xyz",
|
|
206
|
+
* onSessionExpired: () => console.log("Session expired!"),
|
|
207
|
+
* });
|
|
208
|
+
*
|
|
209
|
+
* const handleLogin = async () => {
|
|
210
|
+
* if (!address || !chainId) return;
|
|
211
|
+
* await login(
|
|
212
|
+
* { address, chainId },
|
|
213
|
+
* signMessageAsync
|
|
214
|
+
* );
|
|
215
|
+
* };
|
|
216
|
+
*
|
|
217
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
218
|
+
*
|
|
219
|
+
* return (
|
|
220
|
+
* <div>
|
|
221
|
+
* {isAuthenticated ? (
|
|
222
|
+
* <>
|
|
223
|
+
* <p>Logged in as {session?.address}</p>
|
|
224
|
+
* <button onClick={logout}>Logout</button>
|
|
225
|
+
* </>
|
|
226
|
+
* ) : (
|
|
227
|
+
* <button onClick={handleLogin}>Login</button>
|
|
228
|
+
* )}
|
|
229
|
+
* {error && <p>Error: {error.message}</p>}
|
|
230
|
+
* </div>
|
|
231
|
+
* );
|
|
232
|
+
* }
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare function useComputeSession(config: UseComputeSessionConfig): UseComputeSessionReturn;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* KMS encryption utilities
|
|
239
|
+
* Implements RSA-OAEP-256 + AES-256-GCM encryption using JWE format
|
|
240
|
+
*/
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Get app protected headers for encryption
|
|
244
|
+
*/
|
|
245
|
+
declare function getAppProtectedHeaders(appID: string): Record<string, string>;
|
|
246
|
+
/**
|
|
247
|
+
* Encrypt data using RSA-OAEP-256 for key encryption and AES-256-GCM for data encryption
|
|
248
|
+
* Uses jose library which properly implements JWE with RSA-OAEP-256
|
|
249
|
+
*/
|
|
250
|
+
declare function encryptRSAOAEPAndAES256GCM(encryptionKeyPEM: string | Buffer$1, plaintext: Buffer$1, protectedHeaders?: Record<string, string> | null): Promise<string>;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* KMS key loading utilities
|
|
254
|
+
*/
|
|
255
|
+
type BuildType = "dev" | "prod";
|
|
256
|
+
/**
|
|
257
|
+
* Get KMS keys for environment
|
|
258
|
+
*/
|
|
259
|
+
declare function getKMSKeysForEnvironment(environment: string, build?: BuildType): {
|
|
260
|
+
encryptionKey: Buffer;
|
|
261
|
+
signingKey: Buffer;
|
|
262
|
+
};
|
|
263
|
+
|
|
26
264
|
/**
|
|
27
265
|
* Browser-safe SDK entry point
|
|
28
266
|
*
|
|
@@ -39,4 +277,4 @@ declare function encodeTerminateAppData(appId: AppId): `0x${string}`;
|
|
|
39
277
|
|
|
40
278
|
type Environment = "sepolia" | "sepolia-dev" | "mainnet-alpha";
|
|
41
279
|
|
|
42
|
-
export { AppId, type Environment, encodeStartAppData, encodeStopAppData, encodeTerminateAppData };
|
|
280
|
+
export { AppId, BuildApiClient, type BuildApiClientOptions, ComputeApiConfig, type Environment, SessionError, SessionInfo, SiweMessageParams, type UseComputeSessionConfig, type UseComputeSessionReturn, encodeStartAppData, encodeStopAppData, encodeTerminateAppData, encryptRSAOAEPAndAES256GCM, getAppProtectedHeaders, getKMSKeysForEnvironment, useComputeSession };
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,7 +1,93 @@
|
|
|
1
|
-
import { A as AppId } from './index-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { A as AppId } from './index-C0w92tCs.js';
|
|
2
|
+
export { al as AlreadyActiveResponse, w as AppConfig, ac as AppProfile, ad as AppProfileResponse, a2 as AppRecord, K as BatchedDeployResult, a5 as BillingEnvironmentConfig, C as CalculateAppIDOptions, aq as CancelResponse, ao as CancelSuccessResponse, af as ChainID, ak as CheckoutCreatedResponse, ai as CreateSubscriptionOptions, aj as CreateSubscriptionResponse, D as DeployAppOptions, N as DeployAppOpts, a3 as DeployOptions, at as DeployProgressCallback, a4 as DeployResult, au as DeployStep, aa as DockerImageConfig, a6 as EnvironmentConfig, E as EstimateGasOptions, J as ExecuteDeployBatchedOptions, X as ExecuteDeployResult, H as ExecuteDeploySequentialOptions, Y as ExecuteUpgradeResult, G as GasEstimate, W as GasOpts, a9 as ImageDigestResult, I as IsDelegatedOptions, a1 as LifecycleOpts, ab as Logger, ap as NoActiveSubscriptionResponse, a8 as ParsedEnvironment, am as PaymentIssueResponse, P as PrepareDeployBatchOptions, T as PrepareDeployFromVerifiableBuildOpts, Q as PrepareDeployOpts, x as PrepareUpgradeBatchOptions, V as PrepareUpgradeFromVerifiableBuildOpts, R as PrepareUpgradeOpts, $ as PreparedDeploy, y as PreparedDeployBatch, Z as PreparedDeployData, a0 as PreparedUpgrade, z as PreparedUpgradeBatch, _ as PreparedUpgradeData, ae as ProductID, ar as ProductSubscriptionResponse, a7 as Release, S as SendTransactionOptions, av as SequentialDeployResult, an as SubscribeResponse, ah as SubscriptionLineItem, as as SubscriptionOpts, ag as SubscriptionStatus, B as SuspendOptions, F as UndelegateOptions, U as UpgradeAppOptions, O as UpgradeAppOpts, j as calculateAppID, i as deployApp, e as estimateTransactionGas, h as executeDeployBatch, l as executeDeployBatched, k as executeDeploySequential, o as executeUpgradeBatch, f as formatETH, c as getActiveAppCount, g as getAllAppsByDeveloper, a as getAppsByCreator, b as getAppsByDeveloper, d as getMaxActiveAppsPerUser, r as isDelegated, M as logVisibility, L as noopLogger, p as prepareDeployBatch, n as prepareUpgradeBatch, q as sendAndWaitForTransaction, m as supportsEIP5792, s as supportsEIP7702, t as suspend, v as undelegate, u as upgradeApp } from './index-C0w92tCs.js';
|
|
3
|
+
import { C as ComputeApiConfig, S as SessionInfo, a as SessionError, b as SiweMessageParams } from './helpers-4w0Iojmm.js';
|
|
4
|
+
export { F as AppInfo, J as AppInfoResponse, I as AppMetrics, H as AppProfileInfo, K as BillingApiClient, M as BillingApiClientOptions, ac as BillingApiConfig, af as BillingLoginRequest, ae as BillingLoginResult, ab as BillingSessionError, ad as BillingSessionInfo, z as CreateAppParams, Q as EstimateBatchGasOptions, R as ExecuteBatchOptions, T as Execution, G as GeneratedKey, L as LogVisibility, a4 as LoginRequest, a3 as LoginResult, A as LogsParams, _ as SiweMessageResult, U as UserApiClient, E as UserApiClientOptions, ah as addHexPrefix, j as assertValidImageReference, n as assertValidPrivateKey, P as checkERC7702Delegation, V as createSiweMessage, N as estimateBatchGas, O as executeBatch, k as extractAppNameFromImage, D as generateNewPrivateKey, X as generateNonce, d as getAvailableEnvironments, a7 as getBillingApiSession, c as getBillingEnvironmentConfig, e as getBuildType, ag as getChainFromID, a1 as getComputeApiSession, g as getEnvironmentConfig, a8 as isBillingSessionValid, i as isEnvironmentAvailable, f as isMainnet, a2 as isSessionValid, Y as isSiweMessageExpired, Z as isSiweMessageNotYetValid, B as isSubscriptionActive, a5 as loginToBillingApi, a9 as loginToBothApis, $ as loginToComputeApi, a6 as logoutFromBillingApi, aa as logoutFromBothApis, 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, q as validateDescription, h as validateImageReference, l as validateInstanceTypeSKU, s as validateLogVisibility, y as validateLogsParams, m as validatePrivateKeyFormat, o as validateURL, p as validateXURL } from './helpers-4w0Iojmm.js';
|
|
5
|
+
import { WalletClient, Address, Hex } from 'viem';
|
|
6
|
+
import { Buffer as Buffer$1 } from 'buffer';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Build API Client to manage verifiable builds and provenance
|
|
10
|
+
*
|
|
11
|
+
* This is a standalone HTTP client that talks to the (compute) UserAPI host.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
interface BuildApiClientOptions {
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
walletClient?: WalletClient;
|
|
17
|
+
clientId?: string;
|
|
18
|
+
/** Use session-based auth (cookies) instead of signature-based auth */
|
|
19
|
+
useSession?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Billing session ID (value of the billing_session cookie).
|
|
22
|
+
* When provided with useSession=true, this is sent via X-Billing-Session header
|
|
23
|
+
* to authenticate with the billing API for subscription verification.
|
|
24
|
+
* Required for submitBuild when using session auth.
|
|
25
|
+
*/
|
|
26
|
+
billingSessionId?: string;
|
|
27
|
+
}
|
|
28
|
+
declare class BuildApiClient {
|
|
29
|
+
private readonly baseUrl;
|
|
30
|
+
private readonly walletClient?;
|
|
31
|
+
private readonly clientId?;
|
|
32
|
+
private readonly useSession;
|
|
33
|
+
private billingSessionId?;
|
|
34
|
+
constructor(options: BuildApiClientOptions);
|
|
35
|
+
/**
|
|
36
|
+
* Update the billing session ID.
|
|
37
|
+
* Call this after logging into the billing API to enable session-based auth for builds.
|
|
38
|
+
*/
|
|
39
|
+
setBillingSessionId(sessionId: string | undefined): void;
|
|
40
|
+
/**
|
|
41
|
+
* Get the address of the connected wallet
|
|
42
|
+
*/
|
|
43
|
+
get address(): Address;
|
|
44
|
+
/**
|
|
45
|
+
* Submit a new build request.
|
|
46
|
+
* Supports two auth modes (session auth is tried first when billingSessionId is available):
|
|
47
|
+
* 1. Session-based auth: X-Billing-Session header (forwarded billing_session cookie)
|
|
48
|
+
* 2. Signature-based auth: Authorization + X-Account + X-eigenx-expiry headers (requires walletClient)
|
|
49
|
+
*/
|
|
50
|
+
submitBuild(payload: {
|
|
51
|
+
repo_url: string;
|
|
52
|
+
git_ref: string;
|
|
53
|
+
dockerfile_path: string;
|
|
54
|
+
caddyfile_path?: string;
|
|
55
|
+
build_context_path: string;
|
|
56
|
+
dependencies: string[];
|
|
57
|
+
}): Promise<{
|
|
58
|
+
build_id: string;
|
|
59
|
+
}>;
|
|
60
|
+
getBuild(buildId: string): Promise<any>;
|
|
61
|
+
getBuildByDigest(digest: string): Promise<any>;
|
|
62
|
+
verify(identifier: string): Promise<any>;
|
|
63
|
+
/**
|
|
64
|
+
* Get build logs. Supports session auth (identity verification only, no billing check).
|
|
65
|
+
*/
|
|
66
|
+
getLogs(buildId: string): Promise<string>;
|
|
67
|
+
listBuilds(params: {
|
|
68
|
+
billing_address: string;
|
|
69
|
+
limit?: number;
|
|
70
|
+
offset?: number;
|
|
71
|
+
}): Promise<any[]>;
|
|
72
|
+
private publicJsonRequest;
|
|
73
|
+
/**
|
|
74
|
+
* Make a request that ALWAYS requires signature auth (for billing verification).
|
|
75
|
+
* Used for endpoints like POST /builds that need to verify subscription status.
|
|
76
|
+
*/
|
|
77
|
+
private signatureAuthJsonRequest;
|
|
78
|
+
/**
|
|
79
|
+
* Make a request using billing session auth (for billing verification without wallet signature).
|
|
80
|
+
* Forwards the billing_session cookie value via X-Billing-Session header.
|
|
81
|
+
* Used for endpoints that need to verify subscription status when using session-based auth.
|
|
82
|
+
*/
|
|
83
|
+
private billingSessionAuthJsonRequest;
|
|
84
|
+
/**
|
|
85
|
+
* Make an authenticated request that can use session OR signature auth.
|
|
86
|
+
* When useSession is true, relies on cookies for identity verification.
|
|
87
|
+
* Used for endpoints that only need identity verification (not billing).
|
|
88
|
+
*/
|
|
89
|
+
private sessionOrSignatureTextRequest;
|
|
90
|
+
}
|
|
5
91
|
|
|
6
92
|
/**
|
|
7
93
|
* Browser-safe app action encoders
|
|
@@ -23,6 +109,158 @@ declare function encodeStopAppData(appId: AppId): `0x${string}`;
|
|
|
23
109
|
*/
|
|
24
110
|
declare function encodeTerminateAppData(appId: AppId): `0x${string}`;
|
|
25
111
|
|
|
112
|
+
/**
|
|
113
|
+
* React Hook for Compute API Session Management
|
|
114
|
+
*
|
|
115
|
+
* This hook provides a convenient way to manage compute API sessions in React applications.
|
|
116
|
+
* It handles session state, auto-refresh, and provides login/logout methods.
|
|
117
|
+
*
|
|
118
|
+
* IMPORTANT: This hook requires React 18+ as a peer dependency.
|
|
119
|
+
* Make sure your application has React installed.
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
interface UseComputeSessionConfig extends ComputeApiConfig {
|
|
123
|
+
/**
|
|
124
|
+
* Interval in milliseconds to check session validity
|
|
125
|
+
* Set to 0 to disable auto-refresh
|
|
126
|
+
* @default 60000 (1 minute)
|
|
127
|
+
*/
|
|
128
|
+
refreshInterval?: number;
|
|
129
|
+
/**
|
|
130
|
+
* Whether to automatically check session on mount
|
|
131
|
+
* @default true
|
|
132
|
+
*/
|
|
133
|
+
checkOnMount?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Callback when session expires or becomes invalid
|
|
136
|
+
*/
|
|
137
|
+
onSessionExpired?: () => void;
|
|
138
|
+
/**
|
|
139
|
+
* Callback when session is successfully refreshed/validated
|
|
140
|
+
*/
|
|
141
|
+
onSessionRefreshed?: (session: SessionInfo) => void;
|
|
142
|
+
/**
|
|
143
|
+
* Callback when an error occurs
|
|
144
|
+
*/
|
|
145
|
+
onError?: (error: SessionError) => void;
|
|
146
|
+
}
|
|
147
|
+
interface UseComputeSessionReturn {
|
|
148
|
+
/** Current session information */
|
|
149
|
+
session: SessionInfo | null;
|
|
150
|
+
/** Whether the session is currently being loaded/checked */
|
|
151
|
+
isLoading: boolean;
|
|
152
|
+
/** Any error that occurred during session operations */
|
|
153
|
+
error: SessionError | null;
|
|
154
|
+
/** Whether the user is authenticated */
|
|
155
|
+
isAuthenticated: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Login to compute API with SIWE
|
|
158
|
+
*
|
|
159
|
+
* @param params - SIWE message parameters (address, chainId required)
|
|
160
|
+
* @param signMessage - Function to sign the message (from wagmi's useSignMessage)
|
|
161
|
+
* @returns Login result
|
|
162
|
+
*/
|
|
163
|
+
login: (params: Omit<SiweMessageParams, "domain" | "uri"> & {
|
|
164
|
+
domain?: string;
|
|
165
|
+
uri?: string;
|
|
166
|
+
}, signMessage: (args: {
|
|
167
|
+
message: string;
|
|
168
|
+
}) => Promise<Hex>) => Promise<SessionInfo>;
|
|
169
|
+
/**
|
|
170
|
+
* Logout from compute API
|
|
171
|
+
*/
|
|
172
|
+
logout: () => Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Manually refresh/check session status
|
|
175
|
+
*/
|
|
176
|
+
refresh: () => Promise<SessionInfo>;
|
|
177
|
+
/**
|
|
178
|
+
* Clear any error state
|
|
179
|
+
*/
|
|
180
|
+
clearError: () => void;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* React hook for managing compute API sessions with SIWE authentication
|
|
184
|
+
*
|
|
185
|
+
* @param config - Configuration options including baseUrl and refresh settings
|
|
186
|
+
* @returns Session state and methods for login/logout/refresh
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```tsx
|
|
190
|
+
* import { useComputeSession } from "@layr-labs/ecloud-sdk/browser";
|
|
191
|
+
* import { useSignMessage, useAccount } from "wagmi";
|
|
192
|
+
*
|
|
193
|
+
* function MyComponent() {
|
|
194
|
+
* const { address, chainId } = useAccount();
|
|
195
|
+
* const { signMessageAsync } = useSignMessage();
|
|
196
|
+
*
|
|
197
|
+
* const {
|
|
198
|
+
* session,
|
|
199
|
+
* isLoading,
|
|
200
|
+
* isAuthenticated,
|
|
201
|
+
* login,
|
|
202
|
+
* logout,
|
|
203
|
+
* error,
|
|
204
|
+
* } = useComputeSession({
|
|
205
|
+
* baseUrl: "https://api.eigencloud.xyz",
|
|
206
|
+
* onSessionExpired: () => console.log("Session expired!"),
|
|
207
|
+
* });
|
|
208
|
+
*
|
|
209
|
+
* const handleLogin = async () => {
|
|
210
|
+
* if (!address || !chainId) return;
|
|
211
|
+
* await login(
|
|
212
|
+
* { address, chainId },
|
|
213
|
+
* signMessageAsync
|
|
214
|
+
* );
|
|
215
|
+
* };
|
|
216
|
+
*
|
|
217
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
218
|
+
*
|
|
219
|
+
* return (
|
|
220
|
+
* <div>
|
|
221
|
+
* {isAuthenticated ? (
|
|
222
|
+
* <>
|
|
223
|
+
* <p>Logged in as {session?.address}</p>
|
|
224
|
+
* <button onClick={logout}>Logout</button>
|
|
225
|
+
* </>
|
|
226
|
+
* ) : (
|
|
227
|
+
* <button onClick={handleLogin}>Login</button>
|
|
228
|
+
* )}
|
|
229
|
+
* {error && <p>Error: {error.message}</p>}
|
|
230
|
+
* </div>
|
|
231
|
+
* );
|
|
232
|
+
* }
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare function useComputeSession(config: UseComputeSessionConfig): UseComputeSessionReturn;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* KMS encryption utilities
|
|
239
|
+
* Implements RSA-OAEP-256 + AES-256-GCM encryption using JWE format
|
|
240
|
+
*/
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Get app protected headers for encryption
|
|
244
|
+
*/
|
|
245
|
+
declare function getAppProtectedHeaders(appID: string): Record<string, string>;
|
|
246
|
+
/**
|
|
247
|
+
* Encrypt data using RSA-OAEP-256 for key encryption and AES-256-GCM for data encryption
|
|
248
|
+
* Uses jose library which properly implements JWE with RSA-OAEP-256
|
|
249
|
+
*/
|
|
250
|
+
declare function encryptRSAOAEPAndAES256GCM(encryptionKeyPEM: string | Buffer$1, plaintext: Buffer$1, protectedHeaders?: Record<string, string> | null): Promise<string>;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* KMS key loading utilities
|
|
254
|
+
*/
|
|
255
|
+
type BuildType = "dev" | "prod";
|
|
256
|
+
/**
|
|
257
|
+
* Get KMS keys for environment
|
|
258
|
+
*/
|
|
259
|
+
declare function getKMSKeysForEnvironment(environment: string, build?: BuildType): {
|
|
260
|
+
encryptionKey: Buffer;
|
|
261
|
+
signingKey: Buffer;
|
|
262
|
+
};
|
|
263
|
+
|
|
26
264
|
/**
|
|
27
265
|
* Browser-safe SDK entry point
|
|
28
266
|
*
|
|
@@ -39,4 +277,4 @@ declare function encodeTerminateAppData(appId: AppId): `0x${string}`;
|
|
|
39
277
|
|
|
40
278
|
type Environment = "sepolia" | "sepolia-dev" | "mainnet-alpha";
|
|
41
279
|
|
|
42
|
-
export { AppId, type Environment, encodeStartAppData, encodeStopAppData, encodeTerminateAppData };
|
|
280
|
+
export { AppId, BuildApiClient, type BuildApiClientOptions, ComputeApiConfig, type Environment, SessionError, SessionInfo, SiweMessageParams, type UseComputeSessionConfig, type UseComputeSessionReturn, encodeStartAppData, encodeStopAppData, encodeTerminateAppData, encryptRSAOAEPAndAES256GCM, getAppProtectedHeaders, getKMSKeysForEnvironment, useComputeSession };
|