@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.
@@ -0,0 +1,983 @@
1
+ import { a6 as EnvironmentConfig, ag as SubscriptionStatus, a5 as BillingEnvironmentConfig, ae as ProductID, ai as CreateSubscriptionOptions, aj as CreateSubscriptionResponse, ar as ProductSubscriptionResponse, G as GasEstimate, ab as Logger } from './index-C0w92tCs.cjs';
2
+ import { Address, Hex, WalletClient, PublicClient, Chain } from 'viem';
3
+
4
+ /**
5
+ * Environment configuration for different networks
6
+ */
7
+
8
+ /**
9
+ * Get environment configuration
10
+ */
11
+ declare function getEnvironmentConfig(environment: string, chainID?: bigint): EnvironmentConfig;
12
+ /**
13
+ * Get billing environment configuration
14
+ * @param build - The build type ("dev" or "prod")
15
+ */
16
+ declare function getBillingEnvironmentConfig(build: "dev" | "prod"): {
17
+ billingApiServerURL: string;
18
+ };
19
+ declare function getBuildType(): "dev" | "prod";
20
+ /**
21
+ * Get available environments based on build type
22
+ * - dev: only "sepolia-dev"
23
+ * - prod: "sepolia" and "mainnet-alpha"
24
+ */
25
+ declare function getAvailableEnvironments(): string[];
26
+ /**
27
+ * Check if an environment is available in the current build
28
+ */
29
+ declare function isEnvironmentAvailable(environment: string): boolean;
30
+ /**
31
+ * Check if environment is mainnet (chain ID 1)
32
+ */
33
+ declare function isMainnet(environmentConfig: EnvironmentConfig): boolean;
34
+
35
+ /**
36
+ * Non-interactive validation utilities for SDK
37
+ *
38
+ * These functions validate parameters without any interactive prompts.
39
+ * They either return the validated value or throw an error.
40
+ */
41
+
42
+ /**
43
+ * Validate app name format
44
+ * @throws Error if name is invalid
45
+ */
46
+ declare function validateAppName(name: string): void;
47
+ /**
48
+ * Validate Docker image reference format
49
+ * @returns true if valid, error message string if invalid
50
+ */
51
+ declare function validateImageReference(value: string): true | string;
52
+ /**
53
+ * Validate image reference and throw if invalid
54
+ * @throws Error if image reference is invalid
55
+ */
56
+ declare function assertValidImageReference(value: string): void;
57
+ /**
58
+ * Extract app name from image reference
59
+ */
60
+ declare function extractAppNameFromImage(imageRef: string): string;
61
+ /**
62
+ * Validate that a file path exists
63
+ * @returns true if valid, error message string if invalid
64
+ */
65
+ declare function validateFilePath(value: string): true | string;
66
+ /**
67
+ * Validate file path and throw if invalid
68
+ * @throws Error if file path is invalid or doesn't exist
69
+ */
70
+ declare function assertValidFilePath(value: string): void;
71
+ /**
72
+ * Validate instance type SKU against available types
73
+ * @returns the validated SKU
74
+ * @throws Error if SKU is not in the available types list
75
+ */
76
+ declare function validateInstanceTypeSKU(sku: string, availableTypes: Array<{
77
+ sku: string;
78
+ }>): string;
79
+ /**
80
+ * Validate private key format
81
+ * Matches Go's common.ValidatePrivateKey() function
82
+ */
83
+ declare function validatePrivateKeyFormat(key: string): boolean;
84
+ /**
85
+ * Validate private key and throw if invalid
86
+ * @throws Error if private key format is invalid
87
+ */
88
+ declare function assertValidPrivateKey(key: string): void;
89
+ /**
90
+ * Validate URL format
91
+ * @returns undefined if valid, error message string if invalid
92
+ */
93
+ declare function validateURL(rawURL: string): string | undefined;
94
+ /**
95
+ * Validate X/Twitter URL format
96
+ * @returns undefined if valid, error message string if invalid
97
+ */
98
+ declare function validateXURL(rawURL: string): string | undefined;
99
+ /**
100
+ * Validate description length
101
+ * @returns undefined if valid, error message string if invalid
102
+ */
103
+ declare function validateDescription(description: string): string | undefined;
104
+ /**
105
+ * Validate image file path
106
+ * @returns undefined if valid, error message string if invalid
107
+ */
108
+ declare function validateImagePath(filePath: string): string | undefined;
109
+ /**
110
+ * Validate and normalize app ID address
111
+ * @param appID - App ID (must be a valid address)
112
+ * @returns Normalized app address
113
+ * @throws Error if app ID is not a valid address
114
+ *
115
+ * Note: Name resolution should be handled by CLI before calling SDK functions.
116
+ * The SDK only accepts resolved addresses.
117
+ */
118
+ declare function validateAppID(appID: string | Address): Address;
119
+ type LogVisibility = "public" | "private" | "off";
120
+ /**
121
+ * Validate and convert log visibility setting to internal format
122
+ * @param logVisibility - Log visibility setting
123
+ * @returns Object with logRedirect and publicLogs settings
124
+ * @throws Error if log visibility value is invalid
125
+ */
126
+ declare function validateLogVisibility(logVisibility: LogVisibility): {
127
+ logRedirect: string;
128
+ publicLogs: boolean;
129
+ };
130
+ type ResourceUsageMonitoring = "enable" | "disable";
131
+ /**
132
+ * Validate and convert resource usage monitoring setting to internal format
133
+ * @param resourceUsageMonitoring - Resource usage monitoring setting
134
+ * @returns The resourceUsageAllow value for the Dockerfile label ("always" or "never")
135
+ * @throws Error if resource usage monitoring value is invalid
136
+ */
137
+ declare function validateResourceUsageMonitoring(resourceUsageMonitoring: ResourceUsageMonitoring | undefined): string;
138
+ /**
139
+ * Sanitize string (HTML escape and trim)
140
+ */
141
+ declare function sanitizeString(s: string): string;
142
+ /**
143
+ * Sanitize URL (add https:// if missing, validate)
144
+ * @throws Error if URL is invalid after sanitization
145
+ */
146
+ declare function sanitizeURL(rawURL: string): string;
147
+ /**
148
+ * Sanitize X/Twitter URL (handle username-only input, normalize)
149
+ * @throws Error if URL is invalid after sanitization
150
+ */
151
+ declare function sanitizeXURL(rawURL: string): string;
152
+ interface DeployParams {
153
+ dockerfilePath?: string;
154
+ imageRef?: string;
155
+ appName: string;
156
+ envFilePath?: string;
157
+ instanceType: string;
158
+ logVisibility: LogVisibility;
159
+ }
160
+ /**
161
+ * Validate deploy parameters
162
+ * @throws Error if required parameters are missing or invalid
163
+ */
164
+ declare function validateDeployParams(params: Partial<DeployParams>): void;
165
+ interface UpgradeParams {
166
+ appID: string | Address;
167
+ dockerfilePath?: string;
168
+ imageRef?: string;
169
+ envFilePath?: string;
170
+ instanceType: string;
171
+ logVisibility: LogVisibility;
172
+ }
173
+ /**
174
+ * Validate upgrade parameters
175
+ * @throws Error if required parameters are missing or invalid
176
+ */
177
+ declare function validateUpgradeParams(params: Partial<UpgradeParams>): void;
178
+ interface CreateAppParams {
179
+ name: string;
180
+ language: string;
181
+ template?: string;
182
+ templateVersion?: string;
183
+ }
184
+ /**
185
+ * Validate create app parameters
186
+ * @throws Error if required parameters are missing or invalid
187
+ */
188
+ declare function validateCreateAppParams(params: Partial<CreateAppParams>): void;
189
+ interface LogsParams {
190
+ appID: string | Address;
191
+ watch?: boolean;
192
+ }
193
+ /**
194
+ * Validate logs parameters
195
+ * @throws Error if required parameters are missing or invalid
196
+ */
197
+ declare function validateLogsParams(params: Partial<LogsParams>): void;
198
+
199
+ /**
200
+ * Billing utility functions
201
+ */
202
+
203
+ /**
204
+ * Check if subscription status allows deploying apps
205
+ */
206
+ declare function isSubscriptionActive(status: SubscriptionStatus): boolean;
207
+
208
+ /**
209
+ * Private Key Generation
210
+ *
211
+ * Generate new secp256k1 private keys for Ethereum
212
+ */
213
+ interface GeneratedKey {
214
+ privateKey: string;
215
+ address: string;
216
+ }
217
+ /**
218
+ * Generate a new secp256k1 private key
219
+ */
220
+ declare function generateNewPrivateKey(): GeneratedKey;
221
+
222
+ /**
223
+ * Compute API Session Management
224
+ *
225
+ * This module provides utilities for managing authentication sessions with the compute API
226
+ * using SIWE (Sign-In with Ethereum).
227
+ */
228
+
229
+ interface ComputeApiConfig {
230
+ /** Base URL of the compute API (e.g., "https://api.eigencloud.xyz") */
231
+ baseUrl: string;
232
+ }
233
+ interface SessionInfo {
234
+ /** Whether the session is authenticated */
235
+ authenticated: boolean;
236
+ /** Authenticated wallet address (if authenticated) */
237
+ address?: Address;
238
+ /** Chain ID used for authentication (if authenticated) */
239
+ chainId?: number;
240
+ }
241
+ interface LoginResult {
242
+ /** Whether login was successful */
243
+ success: boolean;
244
+ /** Authenticated wallet address */
245
+ address: Address;
246
+ }
247
+ interface LoginRequest {
248
+ /** SIWE message string */
249
+ message: string;
250
+ /** Hex-encoded signature (with or without 0x prefix) */
251
+ signature: Hex | string;
252
+ }
253
+ /**
254
+ * Error thrown when session operations fail
255
+ */
256
+ declare class SessionError extends Error {
257
+ readonly code: "NETWORK_ERROR" | "INVALID_SIGNATURE" | "INVALID_MESSAGE" | "SESSION_EXPIRED" | "UNAUTHORIZED" | "UNKNOWN";
258
+ readonly statusCode?: number | undefined;
259
+ constructor(message: string, code: "NETWORK_ERROR" | "INVALID_SIGNATURE" | "INVALID_MESSAGE" | "SESSION_EXPIRED" | "UNAUTHORIZED" | "UNKNOWN", statusCode?: number | undefined);
260
+ }
261
+ /**
262
+ * Login to the compute API using SIWE
263
+ *
264
+ * This establishes a session with the compute API by verifying the SIWE message
265
+ * and signature. On success, a session cookie is set in the browser.
266
+ *
267
+ * @param config - Compute API configuration
268
+ * @param request - Login request containing SIWE message and signature
269
+ * @returns Login result with the authenticated address
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * import { createSiweMessage, loginToComputeApi } from "@layr-labs/ecloud-sdk/browser";
274
+ *
275
+ * const { message } = createSiweMessage({
276
+ * address: userAddress,
277
+ * chainId: 11155111,
278
+ * domain: window.location.host,
279
+ * uri: window.location.origin,
280
+ * });
281
+ *
282
+ * const signature = await signMessageAsync({ message });
283
+ * const result = await loginToComputeApi(
284
+ * { baseUrl: "https://api.eigencloud.xyz" },
285
+ * { message, signature }
286
+ * );
287
+ * ```
288
+ */
289
+ declare function loginToComputeApi(config: ComputeApiConfig, request: LoginRequest): Promise<LoginResult>;
290
+ /**
291
+ * Get the current session status from the compute API
292
+ *
293
+ * @param config - Compute API configuration
294
+ * @returns Session information including authentication status and address
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * const session = await getComputeApiSession({ baseUrl: "https://api.eigencloud.xyz" });
299
+ * if (session.authenticated) {
300
+ * console.log(`Logged in as ${session.address}`);
301
+ * }
302
+ * ```
303
+ */
304
+ declare function getComputeApiSession(config: ComputeApiConfig): Promise<SessionInfo>;
305
+ /**
306
+ * Logout from the compute API
307
+ *
308
+ * This destroys the current session and clears the session cookie.
309
+ *
310
+ * @param config - Compute API configuration
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * await logoutFromComputeApi({ baseUrl: "https://api.eigencloud.xyz" });
315
+ * ```
316
+ */
317
+ declare function logoutFromComputeApi(config: ComputeApiConfig): Promise<void>;
318
+ /**
319
+ * Check if a session is still valid (not expired)
320
+ *
321
+ * This is a convenience function that checks the session status
322
+ * and returns a boolean.
323
+ *
324
+ * @param config - Compute API configuration
325
+ * @returns True if session is authenticated, false otherwise
326
+ */
327
+ declare function isSessionValid(config: ComputeApiConfig): Promise<boolean>;
328
+
329
+ interface AppProfileInfo {
330
+ name: string;
331
+ website?: string;
332
+ description?: string;
333
+ xURL?: string;
334
+ imageURL?: string;
335
+ }
336
+ interface AppMetrics {
337
+ cpu_utilization_percent?: number;
338
+ memory_utilization_percent?: number;
339
+ memory_used_bytes?: number;
340
+ memory_total_bytes?: number;
341
+ }
342
+ interface DerivedAddress {
343
+ address: string;
344
+ derivationPath: string;
345
+ }
346
+ interface AppInfo {
347
+ address: Address;
348
+ status: string;
349
+ ip: string;
350
+ machineType: string;
351
+ profile?: AppProfileInfo;
352
+ metrics?: AppMetrics;
353
+ evmAddresses: DerivedAddress[];
354
+ solanaAddresses: DerivedAddress[];
355
+ }
356
+ interface AppInfoResponse {
357
+ apps: Array<{
358
+ addresses: {
359
+ data: {
360
+ evmAddresses: DerivedAddress[];
361
+ solanaAddresses: DerivedAddress[];
362
+ };
363
+ signature: string;
364
+ };
365
+ app_status: string;
366
+ ip: string;
367
+ machine_type: string;
368
+ profile?: AppProfileInfo;
369
+ metrics?: AppMetrics;
370
+ }>;
371
+ }
372
+ type AppContractStatus = "STARTED" | "STOPPED" | "TERMINATED" | "SUSPENDED" | string;
373
+ interface AppReleaseBuild {
374
+ buildId?: string;
375
+ billingAddress?: string;
376
+ repoUrl?: string;
377
+ gitRef?: string;
378
+ status?: string;
379
+ buildType?: string;
380
+ imageName?: string;
381
+ imageDigest?: string;
382
+ imageUrl?: string;
383
+ provenanceJson?: unknown;
384
+ provenanceSignature?: string;
385
+ createdAt?: string;
386
+ updatedAt?: string;
387
+ errorMessage?: string;
388
+ dependencies?: Record<string, AppReleaseBuild>;
389
+ }
390
+ interface AppRelease {
391
+ appId?: string;
392
+ rmsReleaseId?: string;
393
+ imageDigest?: string;
394
+ registryUrl?: string;
395
+ publicEnv?: string;
396
+ encryptedEnv?: string;
397
+ upgradeByTime?: number;
398
+ createdAt?: string;
399
+ createdAtBlock?: string;
400
+ build?: AppReleaseBuild;
401
+ }
402
+ interface AppResponse {
403
+ id: string;
404
+ creator?: string;
405
+ contractStatus?: AppContractStatus;
406
+ releases: AppRelease[];
407
+ }
408
+ /**
409
+ * Options for UserApiClient
410
+ */
411
+ interface UserApiClientOptions {
412
+ /** Custom client ID for request tracking */
413
+ clientId?: string;
414
+ /**
415
+ * Use SIWE session authentication instead of per-request signatures.
416
+ * When true, requests rely on session cookies set by loginToComputeApi().
417
+ * When false (default), each request is signed individually.
418
+ */
419
+ useSession?: boolean;
420
+ }
421
+ /**
422
+ * UserAPI Client for interacting with the EigenCloud UserAPI service.
423
+ */
424
+ declare class UserApiClient {
425
+ private readonly config;
426
+ private readonly walletClient;
427
+ private readonly publicClient;
428
+ private readonly clientId;
429
+ private readonly useSession;
430
+ constructor(config: EnvironmentConfig, walletClient: WalletClient, publicClient: PublicClient, options?: UserApiClientOptions);
431
+ /**
432
+ * Get the address of the connected wallet
433
+ */
434
+ get address(): Address;
435
+ getInfos(appIDs: Address[], addressCount?: number): Promise<AppInfo[]>;
436
+ /**
437
+ * Get app details from UserAPI (includes releases and build/provenance info when available).
438
+ *
439
+ * Endpoint: GET /apps/:appAddress
440
+ */
441
+ getApp(appAddress: Address): Promise<AppResponse>;
442
+ /**
443
+ * Get available SKUs (instance types) from UserAPI
444
+ */
445
+ getSKUs(): Promise<{
446
+ skus: Array<{
447
+ sku: string;
448
+ description: string;
449
+ }>;
450
+ }>;
451
+ /**
452
+ * Get logs for an app
453
+ */
454
+ getLogs(appID: Address): Promise<string>;
455
+ /**
456
+ * Get statuses for apps
457
+ */
458
+ getStatuses(appIDs: Address[]): Promise<Array<{
459
+ address: Address;
460
+ status: string;
461
+ }>>;
462
+ /**
463
+ * Upload app profile information with optional image
464
+ *
465
+ * @param appAddress - The app's contract address
466
+ * @param name - Display name for the app
467
+ * @param options - Optional fields including website, description, xURL, and image
468
+ * @param options.image - Image file as Blob or File (browser: from input element, Node.js: new Blob([buffer]))
469
+ * @param options.imageName - Filename for the image (required if image is provided)
470
+ */
471
+ uploadAppProfile(appAddress: Address, name: string, options?: {
472
+ website?: string;
473
+ description?: string;
474
+ xURL?: string;
475
+ image?: Blob | File;
476
+ imageName?: string;
477
+ }): Promise<{
478
+ name: string;
479
+ website?: string;
480
+ description?: string;
481
+ xURL?: string;
482
+ imageURL?: string;
483
+ }>;
484
+ private makeAuthenticatedRequest;
485
+ /**
486
+ * Generate authentication headers for UserAPI requests
487
+ */
488
+ private generateAuthHeaders;
489
+ /**
490
+ * Login to the compute API using SIWE (Sign-In with Ethereum)
491
+ *
492
+ * This establishes a session with the compute API by verifying the SIWE message
493
+ * and signature. On success, a session cookie is set in the browser.
494
+ *
495
+ * @param request - Login request containing SIWE message and signature
496
+ * @returns Login result with the authenticated address
497
+ *
498
+ * @example
499
+ * ```typescript
500
+ * import { createSiweMessage } from "@layr-labs/ecloud-sdk/browser";
501
+ *
502
+ * const { message } = createSiweMessage({
503
+ * address: userAddress,
504
+ * chainId: 11155111,
505
+ * domain: window.location.host,
506
+ * uri: window.location.origin,
507
+ * });
508
+ *
509
+ * const signature = await signMessageAsync({ message });
510
+ * const result = await client.siweLogin({ message, signature });
511
+ * ```
512
+ */
513
+ siweLogin(request: LoginRequest): Promise<LoginResult>;
514
+ /**
515
+ * Logout from the compute API
516
+ *
517
+ * This destroys the current session and clears the session cookie.
518
+ *
519
+ * @example
520
+ * ```typescript
521
+ * await client.siweLogout();
522
+ * ```
523
+ */
524
+ siweLogout(): Promise<void>;
525
+ /**
526
+ * Get the current SIWE session status from the compute API
527
+ *
528
+ * @returns Session information including authentication status and address
529
+ *
530
+ * @example
531
+ * ```typescript
532
+ * const session = await client.getSiweSession();
533
+ * if (session.authenticated) {
534
+ * console.log(`Logged in as ${session.address}`);
535
+ * }
536
+ * ```
537
+ */
538
+ getSiweSession(): Promise<SessionInfo>;
539
+ }
540
+
541
+ /**
542
+ * Billing API Session Management
543
+ *
544
+ * This module provides utilities for managing authentication sessions with the billing API
545
+ * using SIWE (Sign-In with Ethereum).
546
+ *
547
+ * The billing API now supports the same SIWE-based session authentication as the compute API,
548
+ * allowing users to sign once and authenticate to both APIs simultaneously.
549
+ */
550
+
551
+ interface BillingApiConfig {
552
+ /** Base URL of the billing API (e.g., "https://billing.eigencloud.xyz") */
553
+ baseUrl: string;
554
+ }
555
+ interface BillingSessionInfo {
556
+ /** Whether the session is authenticated */
557
+ authenticated: boolean;
558
+ /** Authenticated wallet address (if authenticated) */
559
+ address?: Address;
560
+ /** Chain ID used for authentication (if authenticated) */
561
+ chainId?: number;
562
+ /** Unix timestamp when authentication occurred (if authenticated) */
563
+ authenticatedAt?: number;
564
+ }
565
+ interface BillingLoginResult {
566
+ /** Whether login was successful */
567
+ success: boolean;
568
+ /** Authenticated wallet address */
569
+ address: Address;
570
+ }
571
+ interface BillingLoginRequest {
572
+ /** SIWE message string */
573
+ message: string;
574
+ /** Hex-encoded signature (with or without 0x prefix) */
575
+ signature: Hex | string;
576
+ }
577
+ /**
578
+ * Error thrown when billing session operations fail
579
+ */
580
+ declare class BillingSessionError extends Error {
581
+ readonly code: "NETWORK_ERROR" | "INVALID_SIGNATURE" | "INVALID_MESSAGE" | "SESSION_EXPIRED" | "UNAUTHORIZED" | "UNKNOWN";
582
+ readonly statusCode?: number | undefined;
583
+ constructor(message: string, code: "NETWORK_ERROR" | "INVALID_SIGNATURE" | "INVALID_MESSAGE" | "SESSION_EXPIRED" | "UNAUTHORIZED" | "UNKNOWN", statusCode?: number | undefined);
584
+ }
585
+ /**
586
+ * Login to the billing API using SIWE
587
+ *
588
+ * This establishes a session with the billing API by verifying the SIWE message
589
+ * and signature. On success, a session cookie is set in the browser.
590
+ *
591
+ * The billing API accepts the same SIWE message format as the compute API,
592
+ * so users only need to sign once and can send the same message/signature
593
+ * to both APIs.
594
+ *
595
+ * @param config - Billing API configuration
596
+ * @param request - Login request containing SIWE message and signature
597
+ * @returns Login result with the authenticated address
598
+ *
599
+ * @example
600
+ * ```typescript
601
+ * import { createSiweMessage, loginToBillingApi } from "@layr-labs/ecloud-sdk/browser";
602
+ *
603
+ * const { message } = createSiweMessage({
604
+ * address: userAddress,
605
+ * chainId: 11155111,
606
+ * domain: window.location.host,
607
+ * uri: window.location.origin,
608
+ * });
609
+ *
610
+ * const signature = await signMessageAsync({ message });
611
+ *
612
+ * // Can send to both APIs with the same message/signature
613
+ * const [computeResult, billingResult] = await Promise.all([
614
+ * loginToComputeApi({ baseUrl: computeApiUrl }, { message, signature }),
615
+ * loginToBillingApi({ baseUrl: billingApiUrl }, { message, signature }),
616
+ * ]);
617
+ * ```
618
+ */
619
+ declare function loginToBillingApi(config: BillingApiConfig, request: BillingLoginRequest): Promise<BillingLoginResult>;
620
+ /**
621
+ * Get the current session status from the billing API
622
+ *
623
+ * @param config - Billing API configuration
624
+ * @returns Session information including authentication status and address
625
+ *
626
+ * @example
627
+ * ```typescript
628
+ * const session = await getBillingApiSession({ baseUrl: "https://billing.eigencloud.xyz" });
629
+ * if (session.authenticated) {
630
+ * console.log(`Logged in as ${session.address}`);
631
+ * }
632
+ * ```
633
+ */
634
+ declare function getBillingApiSession(config: BillingApiConfig): Promise<BillingSessionInfo>;
635
+ /**
636
+ * Logout from the billing API
637
+ *
638
+ * This destroys the current session and clears the session cookie.
639
+ *
640
+ * @param config - Billing API configuration
641
+ *
642
+ * @example
643
+ * ```typescript
644
+ * await logoutFromBillingApi({ baseUrl: "https://billing.eigencloud.xyz" });
645
+ * ```
646
+ */
647
+ declare function logoutFromBillingApi(config: BillingApiConfig): Promise<void>;
648
+ /**
649
+ * Check if a billing session is still valid (not expired)
650
+ *
651
+ * This is a convenience function that checks the session status
652
+ * and returns a boolean.
653
+ *
654
+ * @param config - Billing API configuration
655
+ * @returns True if session is authenticated, false otherwise
656
+ */
657
+ declare function isBillingSessionValid(config: BillingApiConfig): Promise<boolean>;
658
+ /**
659
+ * Login to both compute and billing APIs simultaneously
660
+ *
661
+ * This is a convenience function that sends the same SIWE message and signature
662
+ * to both APIs in parallel, establishing sessions with both services at once.
663
+ *
664
+ * @param computeConfig - Compute API configuration
665
+ * @param billingConfig - Billing API configuration
666
+ * @param request - Login request containing SIWE message and signature
667
+ * @returns Object containing login results for both APIs
668
+ *
669
+ * @example
670
+ * ```typescript
671
+ * import { createSiweMessage, loginToBothApis } from "@layr-labs/ecloud-sdk/browser";
672
+ *
673
+ * const { message } = createSiweMessage({
674
+ * address: userAddress,
675
+ * chainId: 11155111,
676
+ * domain: window.location.host,
677
+ * uri: window.location.origin,
678
+ * });
679
+ *
680
+ * const signature = await signMessageAsync({ message });
681
+ * const { compute, billing } = await loginToBothApis(
682
+ * { baseUrl: computeApiUrl },
683
+ * { baseUrl: billingApiUrl },
684
+ * { message, signature }
685
+ * );
686
+ * ```
687
+ */
688
+ declare function loginToBothApis(computeConfig: {
689
+ baseUrl: string;
690
+ }, billingConfig: BillingApiConfig, request: BillingLoginRequest): Promise<{
691
+ compute: BillingLoginResult;
692
+ billing: BillingLoginResult;
693
+ }>;
694
+ /**
695
+ * Logout from both compute and billing APIs simultaneously
696
+ *
697
+ * @param computeConfig - Compute API configuration
698
+ * @param billingConfig - Billing API configuration
699
+ *
700
+ * @example
701
+ * ```typescript
702
+ * await logoutFromBothApis(
703
+ * { baseUrl: computeApiUrl },
704
+ * { baseUrl: billingApiUrl }
705
+ * );
706
+ * ```
707
+ */
708
+ declare function logoutFromBothApis(computeConfig: {
709
+ baseUrl: string;
710
+ }, billingConfig: BillingApiConfig): Promise<void>;
711
+
712
+ /**
713
+ * BillingAPI Client to manage product subscriptions
714
+ * Standalone client - does not depend on chain infrastructure
715
+ *
716
+ * Accepts viem's WalletClient which abstracts over both local accounts
717
+ * (privateKeyToAccount) and external signers (MetaMask, etc.).
718
+ *
719
+ * Supports two authentication modes:
720
+ * 1. EIP-712 signature auth (default) - signs each request with typed data
721
+ * 2. Session auth (optional) - uses SIWE session cookies
722
+ */
723
+
724
+ interface BillingApiClientOptions {
725
+ /**
726
+ * Use session-based authentication instead of per-request signatures.
727
+ * When true, the client will rely on session cookies set by SIWE login.
728
+ * When false (default), uses EIP-712 typed data signatures for each request.
729
+ */
730
+ useSession?: boolean;
731
+ }
732
+ /**
733
+ * BillingAPI Client for managing product subscriptions.
734
+ */
735
+ declare class BillingApiClient {
736
+ private readonly config;
737
+ private readonly walletClient;
738
+ private readonly options;
739
+ private readonly useSession;
740
+ constructor(config: BillingEnvironmentConfig, walletClient: WalletClient | null, options?: BillingApiClientOptions);
741
+ /**
742
+ * Get the address of the connected wallet
743
+ * Returns undefined if using session auth without a wallet client
744
+ */
745
+ get address(): Address | undefined;
746
+ /**
747
+ * Get the base URL of the billing API
748
+ */
749
+ get baseUrl(): string;
750
+ /**
751
+ * Login to the billing API using SIWE
752
+ *
753
+ * This establishes a session with the billing API by verifying the SIWE message
754
+ * and signature. On success, a session cookie is set in the browser.
755
+ *
756
+ * @param request - Login request containing SIWE message and signature
757
+ * @returns Login result with the authenticated address
758
+ *
759
+ * @example
760
+ * ```typescript
761
+ * const { message } = createSiweMessage({
762
+ * address: userAddress,
763
+ * chainId: 11155111,
764
+ * domain: window.location.host,
765
+ * uri: window.location.origin,
766
+ * });
767
+ *
768
+ * const signature = await signMessageAsync({ message });
769
+ * const result = await billingClient.siweLogin({ message, signature });
770
+ * ```
771
+ */
772
+ siweLogin(request: BillingLoginRequest): Promise<BillingLoginResult>;
773
+ /**
774
+ * Logout from the billing API
775
+ *
776
+ * This destroys the current session and clears the session cookie.
777
+ */
778
+ siweLogout(): Promise<void>;
779
+ /**
780
+ * Get the current session status from the billing API
781
+ *
782
+ * @returns Session information including authentication status and address
783
+ */
784
+ getSession(): Promise<BillingSessionInfo>;
785
+ /**
786
+ * Check if there is a valid session
787
+ *
788
+ * @returns True if session is authenticated, false otherwise
789
+ */
790
+ isSessionValid(): Promise<boolean>;
791
+ createSubscription(productId?: ProductID, options?: CreateSubscriptionOptions): Promise<CreateSubscriptionResponse>;
792
+ getSubscription(productId?: ProductID): Promise<ProductSubscriptionResponse>;
793
+ cancelSubscription(productId?: ProductID): Promise<void>;
794
+ /**
795
+ * Make an authenticated request to the billing API
796
+ *
797
+ * Uses session auth if useSession is true, otherwise uses EIP-712 signature auth.
798
+ */
799
+ private makeAuthenticatedRequest;
800
+ /**
801
+ * Make a request using session-based authentication (cookies)
802
+ */
803
+ private makeSessionAuthenticatedRequest;
804
+ /**
805
+ * Make a request using EIP-712 signature authentication
806
+ */
807
+ private makeSignatureAuthenticatedRequest;
808
+ }
809
+
810
+ /**
811
+ * EIP-7702 transaction handling
812
+ *
813
+ * This module handles EIP-7702 delegation and batch execution.
814
+ */
815
+
816
+ type Execution = {
817
+ target: Address;
818
+ value: bigint;
819
+ callData: Hex;
820
+ };
821
+ /**
822
+ * Options for estimating batch gas
823
+ */
824
+ interface EstimateBatchGasOptions {
825
+ publicClient: PublicClient;
826
+ account: Address;
827
+ executions: Execution[];
828
+ }
829
+ /**
830
+ * Estimate gas cost for a batch transaction
831
+ *
832
+ * Use this to get cost estimate before prompting user for confirmation.
833
+ */
834
+ declare function estimateBatchGas(options: EstimateBatchGasOptions): Promise<GasEstimate>;
835
+ interface ExecuteBatchOptions {
836
+ walletClient: WalletClient;
837
+ publicClient: PublicClient;
838
+ environmentConfig: EnvironmentConfig;
839
+ executions: Execution[];
840
+ pendingMessage: string;
841
+ /** Optional gas params from estimation */
842
+ gas?: GasEstimate;
843
+ }
844
+ /**
845
+ * Check if account is delegated to ERC-7702 delegator
846
+ */
847
+ declare function checkERC7702Delegation(publicClient: PublicClient, account: Address, delegatorAddress: Address): Promise<boolean>;
848
+ /**
849
+ * Execute batch of operations via EIP-7702 delegator
850
+ */
851
+ declare function executeBatch(options: ExecuteBatchOptions, logger?: Logger): Promise<Hex>;
852
+
853
+ /**
854
+ * SIWE (Sign-In with Ethereum) utilities for compute API authentication
855
+ *
856
+ * This module provides browser-safe utilities for creating and parsing SIWE messages
857
+ * compatible with the compute-tee API. Uses the official `siwe` package (EIP-4361).
858
+ */
859
+
860
+ interface SiweMessageParams {
861
+ /** Ethereum address (checksummed or lowercase) */
862
+ address: Address;
863
+ /** Chain ID (e.g., 1 for mainnet, 11155111 for sepolia) */
864
+ chainId: number;
865
+ /** Domain requesting the signature (e.g., "api.eigencloud.xyz") */
866
+ domain: string;
867
+ /** Full URI of the signing request (e.g., "https://api.eigencloud.xyz") */
868
+ uri: string;
869
+ /** Optional nonce for replay protection (generated if not provided) */
870
+ nonce?: string;
871
+ /** Optional human-readable statement */
872
+ statement?: string;
873
+ /** Optional expiration time (defaults to 24 hours from now) */
874
+ expirationTime?: Date;
875
+ /** Optional issued at time (defaults to now) */
876
+ issuedAt?: Date;
877
+ /** Optional not-before time */
878
+ notBefore?: Date;
879
+ /** Optional request ID */
880
+ requestId?: string;
881
+ /** Optional resources array */
882
+ resources?: string[];
883
+ }
884
+ interface SiweMessageResult {
885
+ /** Raw SIWE message string for signing */
886
+ message: string;
887
+ /** Parsed parameters */
888
+ params: Required<Pick<SiweMessageParams, "address" | "chainId" | "domain" | "uri" | "nonce" | "issuedAt">> & Omit<SiweMessageParams, "address" | "chainId" | "domain" | "uri" | "nonce" | "issuedAt">;
889
+ }
890
+ /**
891
+ * Re-export generateNonce from siwe package
892
+ */
893
+ declare const generateNonce: () => string;
894
+ /**
895
+ * Create a SIWE message for compute API authentication
896
+ *
897
+ * @param params - Parameters for the SIWE message
898
+ * @returns The SIWE message object with the raw message string
899
+ *
900
+ * @example
901
+ * ```typescript
902
+ * const { message } = createSiweMessage({
903
+ * address: "0x1234...",
904
+ * chainId: 11155111,
905
+ * domain: "api.eigencloud.xyz",
906
+ * uri: "https://api.eigencloud.xyz",
907
+ * statement: "Sign in to EigenCloud",
908
+ * });
909
+ *
910
+ * // Sign with wagmi
911
+ * const signature = await signMessageAsync({ message });
912
+ * ```
913
+ */
914
+ declare function createSiweMessage(params: SiweMessageParams): SiweMessageResult;
915
+ /**
916
+ * Parse a SIWE message string back to structured parameters
917
+ *
918
+ * @param message - Raw SIWE message string
919
+ * @returns Parsed parameters or null if invalid
920
+ */
921
+ declare function parseSiweMessage(message: string): SiweMessageParams | null;
922
+ /**
923
+ * Check if a SIWE message has expired
924
+ */
925
+ declare function isSiweMessageExpired(params: SiweMessageParams): boolean;
926
+ /**
927
+ * Check if a SIWE message is not yet valid (notBefore)
928
+ */
929
+ declare function isSiweMessageNotYetValid(params: SiweMessageParams): boolean;
930
+
931
+ /**
932
+ * General utility helpers
933
+ */
934
+
935
+ /**
936
+ * Get a viem Chain object from a chain ID.
937
+ * Supports mainnet (1) and sepolia (11155111), defaults to the fallback chain for unknown chains.
938
+ */
939
+ declare function getChainFromID(chainID: bigint, fallback?: Chain): Chain;
940
+ /**
941
+ * Create viem clients from a private key
942
+ *
943
+ * This is a convenience helper for CLI and server applications that have direct
944
+ * access to a private key. For browser applications using external wallets (MetaMask, etc.),
945
+ * create the WalletClient directly using viem's createWalletClient with a custom transport.
946
+ *
947
+ * @example
948
+ * // CLI usage with private key
949
+ * const { walletClient, publicClient } = createClients({
950
+ * privateKey: '0x...',
951
+ * rpcUrl: 'https://sepolia.infura.io/v3/...',
952
+ * chainId: 11155111n
953
+ * });
954
+ *
955
+ * @example
956
+ * // Browser usage with external wallet (create clients directly)
957
+ * const walletClient = createWalletClient({
958
+ * chain: sepolia,
959
+ * transport: custom(window.ethereum!)
960
+ * });
961
+ * const publicClient = createPublicClient({
962
+ * chain: sepolia,
963
+ * transport: custom(window.ethereum!)
964
+ * });
965
+ */
966
+ declare function createClients(options: {
967
+ privateKey: string | Hex;
968
+ rpcUrl: string;
969
+ chainId: bigint;
970
+ }): {
971
+ walletClient: WalletClient;
972
+ publicClient: PublicClient;
973
+ };
974
+ /**
975
+ * Ensure hex string has 0x prefix
976
+ */
977
+ declare function addHexPrefix(value: string): Hex;
978
+ /**
979
+ * Remove 0x prefix from hex string if present
980
+ */
981
+ declare function stripHexPrefix(value: string): string;
982
+
983
+ export { loginToComputeApi as $, type LogsParams as A, isSubscriptionActive as B, type ComputeApiConfig as C, generateNewPrivateKey as D, type UserApiClientOptions as E, type AppInfo as F, type GeneratedKey as G, type AppProfileInfo as H, type AppMetrics as I, type AppInfoResponse as J, BillingApiClient as K, type LogVisibility as L, type BillingApiClientOptions as M, estimateBatchGas as N, executeBatch as O, checkERC7702Delegation as P, type EstimateBatchGasOptions as Q, type ExecuteBatchOptions as R, type SessionInfo as S, type Execution as T, UserApiClient as U, createSiweMessage as V, parseSiweMessage as W, generateNonce as X, isSiweMessageExpired as Y, isSiweMessageNotYetValid as Z, type SiweMessageResult as _, SessionError as a, logoutFromComputeApi as a0, getComputeApiSession as a1, isSessionValid as a2, type LoginResult as a3, type LoginRequest as a4, loginToBillingApi as a5, logoutFromBillingApi as a6, getBillingApiSession as a7, isBillingSessionValid as a8, loginToBothApis as a9, logoutFromBothApis as aa, BillingSessionError as ab, type BillingApiConfig as ac, type BillingSessionInfo as ad, type BillingLoginResult as ae, type BillingLoginRequest as af, getChainFromID as ag, addHexPrefix as ah, stripHexPrefix as ai, type ResourceUsageMonitoring as aj, createClients as ak, type AppRelease as al, type AppReleaseBuild as am, type AppResponse as an, validateFilePath as ao, assertValidFilePath as ap, validateImagePath as aq, validateResourceUsageMonitoring as ar, type DeployParams as as, validateDeployParams as at, type UpgradeParams as au, validateUpgradeParams as av, type SiweMessageParams as b, getBillingEnvironmentConfig as c, getAvailableEnvironments as d, getBuildType as e, isMainnet as f, getEnvironmentConfig as g, validateImageReference as h, isEnvironmentAvailable as i, assertValidImageReference as j, extractAppNameFromImage as k, validateInstanceTypeSKU as l, validatePrivateKeyFormat as m, assertValidPrivateKey as n, validateURL as o, validateXURL as p, validateDescription as q, validateAppID as r, validateLogVisibility as s, sanitizeString as t, sanitizeURL as u, validateAppName as v, sanitizeXURL as w, validateCreateAppParams as x, validateLogsParams as y, type CreateAppParams as z };