@layr-labs/ecloud-sdk 0.0.1-rfc.1 → 0.1.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/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Address, Hex } from 'viem';
1
+ import { Address, Hex, WalletClient, PublicClient, PrivateKeyAccount } from 'viem';
2
2
 
3
3
  /**
4
4
  * Core types for ECloud SDK
@@ -7,24 +7,35 @@ import { Address, Hex } from 'viem';
7
7
  type AppId = Address;
8
8
  type logVisibility = "public" | "private" | "off";
9
9
  interface DeployAppOpts {
10
- name?: string;
10
+ /** App name - required */
11
+ name: string;
12
+ /** Path to Dockerfile (if building from Dockerfile) - either this or imageRef is required */
11
13
  dockerfile?: string;
14
+ /** Path to .env file - optional */
12
15
  envFile?: string;
16
+ /** Image reference (registry/path:tag) - either this or dockerfile is required */
13
17
  imageRef?: string;
14
- instanceType?: string;
15
- logVisibility?: logVisibility;
18
+ /** Instance type SKU - required */
19
+ instanceType: string;
20
+ /** Log visibility setting - required */
21
+ logVisibility: logVisibility;
22
+ /** Optional gas params from estimation */
23
+ gas?: {
24
+ maxFeePerGas?: bigint;
25
+ maxPriorityFeePerGas?: bigint;
26
+ };
16
27
  }
17
28
  interface UpgradeAppOpts {
18
- /** Path to Dockerfile (if building from Dockerfile) */
29
+ /** Path to Dockerfile (if building from Dockerfile) - either this or imageRef is required */
19
30
  dockerfile?: string;
20
- /** Image reference (registry/path:tag) - optional, will prompt if not provided */
31
+ /** Image reference (registry/path:tag) - either this or dockerfile is required */
21
32
  imageRef?: string;
22
- /** Path to .env file - optional, will use .env if exists or prompt */
33
+ /** Path to .env file - optional */
23
34
  envFile?: string;
24
- /** Instance type - optional, will prompt if not provided */
25
- instanceType?: string;
26
- /** Log visibility setting - optional, will prompt if not provided */
27
- logVisibility?: logVisibility;
35
+ /** Instance type SKU - required */
36
+ instanceType: string;
37
+ /** Log visibility setting - required */
38
+ logVisibility: logVisibility;
28
39
  gas?: {
29
40
  maxFeePerGas?: bigint;
30
41
  maxPriorityFeePerGas?: bigint;
@@ -35,7 +46,6 @@ interface LifecycleOpts {
35
46
  maxFeePerGas?: bigint;
36
47
  maxPriorityFeePerGas?: bigint;
37
48
  };
38
- force?: boolean;
39
49
  }
40
50
  interface AppRecord {
41
51
  id: AppId;
@@ -67,7 +77,7 @@ interface DeployOptions {
67
77
  }
68
78
  interface DeployResult {
69
79
  /** App ID (contract address) */
70
- appID: string;
80
+ appId: string;
71
81
  /** App name */
72
82
  appName: string;
73
83
  /** Final image reference */
@@ -209,8 +219,30 @@ interface BillingEnvironmentConfig {
209
219
  * Create command
210
220
  *
211
221
  * Creates a new app project from a template
222
+ *
223
+ * NOTE: This SDK function is non-interactive. All required parameters must be
224
+ * provided explicitly. Use the CLI for interactive parameter collection.
212
225
  */
213
226
 
227
+ /**
228
+ * Required create app options for SDK (non-interactive)
229
+ */
230
+ interface SDKCreateAppOpts {
231
+ /** Project name - required */
232
+ name: string;
233
+ /** Programming language - required (typescript, golang, rust, python) */
234
+ language: string;
235
+ /** Template name/category (e.g., "minimal") or custom template URL - optional, defaults to first available */
236
+ template?: string;
237
+ /** Template version/ref - optional */
238
+ templateVersion?: string;
239
+ /** Verbose output - optional */
240
+ verbose?: boolean;
241
+ }
242
+ /**
243
+ * Legacy interface for backward compatibility
244
+ * @deprecated Use SDKCreateAppOpts instead
245
+ */
214
246
  interface CreateAppOpts {
215
247
  name?: string;
216
248
  language?: string;
@@ -218,45 +250,102 @@ interface CreateAppOpts {
218
250
  templateVersion?: string;
219
251
  verbose?: boolean;
220
252
  }
253
+ declare const PRIMARY_LANGUAGES: string[];
254
+ /**
255
+ * Get available template categories for a language
256
+ */
257
+ declare function getAvailableTemplates(language: string): Promise<Array<{
258
+ name: string;
259
+ description: string;
260
+ }>>;
221
261
  /**
222
262
  * Create a new app project from template
263
+ *
264
+ * This function is non-interactive and requires all parameters to be provided explicitly.
265
+ *
266
+ * @param options - Required options including name and language
267
+ * @param logger - Optional logger instance
268
+ * @throws Error if required parameters are missing or invalid
223
269
  */
224
- declare function createApp(options: CreateAppOpts, logger?: Logger): Promise<void>;
270
+ declare function createApp(options: SDKCreateAppOpts | CreateAppOpts, logger?: Logger): Promise<void>;
225
271
 
226
272
  /**
227
273
  * Logs command
228
274
  *
229
275
  * View app logs with optional watch mode
276
+ *
277
+ * NOTE: This SDK function is non-interactive. All required parameters must be
278
+ * provided explicitly. Use the CLI for interactive parameter collection.
230
279
  */
231
280
 
281
+ /**
282
+ * Required logs options for SDK (non-interactive)
283
+ */
284
+ interface SDKLogsOptions {
285
+ /** App ID (address) or app name - required */
286
+ appID: string | Address;
287
+ /** Watch logs continuously - optional */
288
+ watch?: boolean;
289
+ /** Environment name - optional, defaults to 'sepolia' */
290
+ environment?: string;
291
+ /** Private key for authenticated requests - optional */
292
+ privateKey?: string;
293
+ /** RPC URL - optional, uses environment default */
294
+ rpcUrl?: string;
295
+ /** Client ID for API requests - optional */
296
+ clientId?: string;
297
+ }
298
+ /**
299
+ * Legacy interface for backward compatibility
300
+ * @deprecated Use SDKLogsOptions instead
301
+ */
232
302
  interface LogsOptions {
233
303
  appID?: string | Address;
234
304
  watch?: boolean;
235
305
  environment?: string;
236
306
  privateKey?: string;
237
307
  rpcUrl?: string;
308
+ clientId?: string;
238
309
  }
239
310
  /**
240
311
  * View app logs
312
+ *
313
+ * This function is non-interactive and requires appID to be provided explicitly.
314
+ *
315
+ * @param options - Required options including appID
316
+ * @param logger - Optional logger instance
317
+ * @throws Error if appID is missing or invalid
241
318
  */
242
- declare function logs(options: LogsOptions, logger?: Logger): Promise<void>;
319
+ declare function logs(options: SDKLogsOptions | LogsOptions, logger?: Logger): Promise<void>;
243
320
 
244
321
  /**
245
322
  * Main App namespace entry point
246
323
  */
247
324
 
325
+ /**
326
+ * Encode start app call data for gas estimation
327
+ */
328
+ declare function encodeStartAppData(appId: AppId): `0x${string}`;
329
+ /**
330
+ * Encode stop app call data for gas estimation
331
+ */
332
+ declare function encodeStopAppData(appId: AppId): `0x${string}`;
333
+ /**
334
+ * Encode terminate app call data for gas estimation
335
+ */
336
+ declare function encodeTerminateAppData(appId: AppId): `0x${string}`;
248
337
  interface AppModule {
249
338
  create: (opts: CreateAppOpts) => Promise<void>;
250
339
  deploy: (opts: DeployAppOpts) => Promise<{
251
- appID: AppId;
340
+ appId: AppId;
252
341
  tx: `0x${string}`;
253
342
  appName: string;
254
343
  imageRef: string;
255
344
  ipAddress?: string;
256
345
  }>;
257
- upgrade: (appID: AppId, opts: UpgradeAppOpts) => Promise<{
346
+ upgrade: (appId: AppId, opts: UpgradeAppOpts) => Promise<{
258
347
  tx: `0x${string}`;
259
- appID: string;
348
+ appId: string;
260
349
  imageRef: string;
261
350
  }>;
262
351
  logs: (opts: LogsOptions) => Promise<void>;
@@ -269,12 +358,16 @@ interface AppModule {
269
358
  terminate: (appId: AppId, opts?: LifecycleOpts) => Promise<{
270
359
  tx: `0x${string}` | false;
271
360
  }>;
361
+ undelegate: () => Promise<{
362
+ tx: `0x${string}` | false;
363
+ }>;
272
364
  }
273
365
  interface AppModuleConfig {
274
366
  verbose?: boolean;
275
367
  privateKey: `0x${string}`;
276
368
  rpcUrl: string;
277
369
  environment: string;
370
+ clientId?: string;
278
371
  }
279
372
  declare function createAppModule(ctx: AppModuleConfig): AppModule;
280
373
 
@@ -294,85 +387,469 @@ interface BillingModuleConfig {
294
387
  declare function createBillingModule(config: BillingModuleConfig): BillingModule;
295
388
 
296
389
  /**
297
- * Interactive prompts using @inquirer/prompts
390
+ * Non-interactive validation utilities for SDK
391
+ *
392
+ * These functions validate parameters without any interactive prompts.
393
+ * They either return the validated value or throw an error.
298
394
  */
299
395
 
300
396
  /**
301
- * Prompt for Dockerfile selection
397
+ * Validate app name format
398
+ * @throws Error if name is invalid
302
399
  */
303
- declare function getDockerfileInteractive(dockerfilePath?: string): Promise<string>;
400
+ declare function validateAppName(name: string): void;
304
401
  /**
305
- * Prompt for image reference
402
+ * Validate Docker image reference format
403
+ * @returns true if valid, error message string if invalid
306
404
  */
307
- declare function getImageReferenceInteractive(imageRef?: string, buildFromDockerfile?: boolean): Promise<string>;
405
+ declare function validateImageReference(value: string): true | string;
308
406
  /**
309
- * Prompt for app name
407
+ * Validate image reference and throw if invalid
408
+ * @throws Error if image reference is invalid
310
409
  */
311
- declare function getOrPromptAppName(appName: string | undefined, environment: string, imageRef: string): Promise<string>;
410
+ declare function assertValidImageReference(value: string): void;
312
411
  /**
313
- * Prompt for environment file
412
+ * Extract app name from image reference
314
413
  */
315
- declare function getEnvFileInteractive(envFilePath?: string): Promise<string>;
414
+ declare function extractAppNameFromImage(imageRef: string): string;
415
+ /**
416
+ * Validate that a file path exists
417
+ * @returns true if valid, error message string if invalid
418
+ */
419
+ declare function validateFilePath(value: string): true | string;
420
+ /**
421
+ * Validate file path and throw if invalid
422
+ * @throws Error if file path is invalid or doesn't exist
423
+ */
424
+ declare function assertValidFilePath(value: string): void;
316
425
  /**
317
- * Prompt for instance type
426
+ * Validate instance type SKU against available types
427
+ * @returns the validated SKU
428
+ * @throws Error if SKU is not in the available types list
318
429
  */
319
- declare function getInstanceTypeInteractive(instanceType: string | undefined, defaultSKU: string, availableTypes: Array<{
430
+ declare function validateInstanceTypeSKU(sku: string, availableTypes: Array<{
320
431
  sku: string;
321
- description: string;
322
- }>): Promise<string>;
432
+ }>): string;
323
433
  /**
324
- * Prompt for app ID (supports app name or address)
434
+ * Validate private key format
435
+ * Matches Go's common.ValidatePrivateKey() function
325
436
  */
326
- interface GetAppIDOptions {
327
- appID?: string | Address;
328
- environment: string;
329
- privateKey?: string;
330
- rpcUrl?: string;
331
- action?: string;
332
- }
437
+ declare function validatePrivateKeyFormat(key: string): boolean;
438
+ /**
439
+ * Validate private key and throw if invalid
440
+ * @throws Error if private key format is invalid
441
+ */
442
+ declare function assertValidPrivateKey(key: string): void;
443
+ /**
444
+ * Validate URL format
445
+ * @returns undefined if valid, error message string if invalid
446
+ */
447
+ declare function validateURL(rawURL: string): string | undefined;
448
+ /**
449
+ * Validate X/Twitter URL format
450
+ * @returns undefined if valid, error message string if invalid
451
+ */
452
+ declare function validateXURL(rawURL: string): string | undefined;
333
453
  /**
334
- * Prompt for app ID (supports app name or address)
454
+ * Validate description length
455
+ * @returns undefined if valid, error message string if invalid
335
456
  */
336
- declare function getOrPromptAppID(appIDOrOptions: string | Address | GetAppIDOptions | undefined, environment?: string): Promise<Address>;
457
+ declare function validateDescription(description: string): string | undefined;
337
458
  /**
338
- * Prompt for log settings
459
+ * Validate image file path
460
+ * @returns undefined if valid, error message string if invalid
339
461
  */
340
- declare function getLogSettingsInteractive(logVisibility?: "public" | "private" | "off"): Promise<{
462
+ declare function validateImagePath(filePath: string): string | undefined;
463
+ /**
464
+ * Validate and normalize app ID address
465
+ * @param appID - App ID (must be a valid address)
466
+ * @returns Normalized app address
467
+ * @throws Error if app ID is not a valid address
468
+ *
469
+ * Note: Name resolution should be handled by CLI before calling SDK functions.
470
+ * The SDK only accepts resolved addresses.
471
+ */
472
+ declare function validateAppID(appID: string | Address): Address;
473
+ type LogVisibility = "public" | "private" | "off";
474
+ /**
475
+ * Validate and convert log visibility setting to internal format
476
+ * @param logVisibility - Log visibility setting
477
+ * @returns Object with logRedirect and publicLogs settings
478
+ * @throws Error if log visibility value is invalid
479
+ */
480
+ declare function validateLogVisibility(logVisibility: LogVisibility): {
341
481
  logRedirect: string;
342
482
  publicLogs: boolean;
483
+ };
484
+ type ResourceUsageMonitoring = "enable" | "disable";
485
+ /**
486
+ * Validate and convert resource usage monitoring setting to internal format
487
+ * @param resourceUsageMonitoring - Resource usage monitoring setting
488
+ * @returns The resourceUsageAllow value for the Dockerfile label ("always" or "never")
489
+ * @throws Error if resource usage monitoring value is invalid
490
+ */
491
+ declare function validateResourceUsageMonitoring(resourceUsageMonitoring: ResourceUsageMonitoring | undefined): string;
492
+ /**
493
+ * Sanitize string (HTML escape and trim)
494
+ */
495
+ declare function sanitizeString(s: string): string;
496
+ /**
497
+ * Sanitize URL (add https:// if missing, validate)
498
+ * @throws Error if URL is invalid after sanitization
499
+ */
500
+ declare function sanitizeURL(rawURL: string): string;
501
+ /**
502
+ * Sanitize X/Twitter URL (handle username-only input, normalize)
503
+ * @throws Error if URL is invalid after sanitization
504
+ */
505
+ declare function sanitizeXURL(rawURL: string): string;
506
+ interface DeployParams {
507
+ dockerfilePath?: string;
508
+ imageRef?: string;
509
+ appName: string;
510
+ envFilePath?: string;
511
+ instanceType: string;
512
+ logVisibility: LogVisibility;
513
+ }
514
+ /**
515
+ * Validate deploy parameters
516
+ * @throws Error if required parameters are missing or invalid
517
+ */
518
+ declare function validateDeployParams(params: Partial<DeployParams>): void;
519
+ interface UpgradeParams {
520
+ appID: string | Address;
521
+ dockerfilePath?: string;
522
+ imageRef?: string;
523
+ envFilePath?: string;
524
+ instanceType: string;
525
+ logVisibility: LogVisibility;
526
+ }
527
+ /**
528
+ * Validate upgrade parameters
529
+ * @throws Error if required parameters are missing or invalid
530
+ */
531
+ declare function validateUpgradeParams(params: Partial<UpgradeParams>): void;
532
+ interface CreateAppParams {
533
+ name: string;
534
+ language: string;
535
+ template?: string;
536
+ templateVersion?: string;
537
+ }
538
+ /**
539
+ * Validate create app parameters
540
+ * @throws Error if required parameters are missing or invalid
541
+ */
542
+ declare function validateCreateAppParams(params: Partial<CreateAppParams>): void;
543
+ interface LogsParams {
544
+ appID: string | Address;
545
+ watch?: boolean;
546
+ }
547
+ /**
548
+ * Validate logs parameters
549
+ * @throws Error if required parameters are missing or invalid
550
+ */
551
+ declare function validateLogsParams(params: Partial<LogsParams>): void;
552
+
553
+ /**
554
+ * Contract interactions
555
+ *
556
+ * This module handles on-chain contract interactions using viem
557
+ */
558
+
559
+ /**
560
+ * Gas estimation result
561
+ */
562
+ interface GasEstimate {
563
+ /** Estimated gas limit for the transaction */
564
+ gasLimit: bigint;
565
+ /** Max fee per gas (EIP-1559) */
566
+ maxFeePerGas: bigint;
567
+ /** Max priority fee per gas (EIP-1559) */
568
+ maxPriorityFeePerGas: bigint;
569
+ /** Maximum cost in wei (gasLimit * maxFeePerGas) */
570
+ maxCostWei: bigint;
571
+ /** Maximum cost formatted as ETH string */
572
+ maxCostEth: string;
573
+ }
574
+ /**
575
+ * Options for estimating transaction gas
576
+ */
577
+ interface EstimateGasOptions {
578
+ privateKey: string;
579
+ rpcUrl: string;
580
+ environmentConfig: EnvironmentConfig;
581
+ to: Address;
582
+ data: Hex;
583
+ value?: bigint;
584
+ }
585
+ /**
586
+ * Format Wei to ETH string
587
+ */
588
+ declare function formatETH(wei: bigint): string;
589
+ /**
590
+ * Estimate gas cost for a transaction
591
+ *
592
+ * Use this to get cost estimate before prompting user for confirmation.
593
+ */
594
+ declare function estimateTransactionGas(options: EstimateGasOptions): Promise<GasEstimate>;
595
+ /**
596
+ * Prepared deploy batch ready for gas estimation and execution
597
+ */
598
+ interface PreparedDeployBatch {
599
+ /** The app ID that will be deployed */
600
+ appId: Address;
601
+ /** The salt used for deployment */
602
+ salt: Uint8Array;
603
+ /** Batch executions to be sent */
604
+ executions: Array<{
605
+ target: Address;
606
+ value: bigint;
607
+ callData: Hex;
608
+ }>;
609
+ /** Wallet client for sending transaction */
610
+ walletClient: WalletClient;
611
+ /** Public client for reading chain state */
612
+ publicClient: PublicClient;
613
+ /** Environment configuration */
614
+ environmentConfig: EnvironmentConfig;
615
+ }
616
+ /**
617
+ * Prepared upgrade batch ready for gas estimation and execution
618
+ */
619
+ interface PreparedUpgradeBatch {
620
+ /** The app ID being upgraded */
621
+ appId: Address;
622
+ /** Batch executions to be sent */
623
+ executions: Array<{
624
+ target: Address;
625
+ value: bigint;
626
+ callData: Hex;
627
+ }>;
628
+ /** Wallet client for sending transaction */
629
+ walletClient: WalletClient;
630
+ /** Public client for reading chain state */
631
+ publicClient: PublicClient;
632
+ /** Environment configuration */
633
+ environmentConfig: EnvironmentConfig;
634
+ }
635
+ /**
636
+ * Get apps by creator (paginated)
637
+ */
638
+ interface AppConfig {
639
+ release: any;
640
+ status: number;
641
+ }
642
+ /**
643
+ * Fetch all apps by a developer by auto-pagination
644
+ */
645
+ declare function getAllAppsByDeveloper(rpcUrl: string, env: EnvironmentConfig, developer: Address, pageSize?: bigint): Promise<{
646
+ apps: Address[];
647
+ appConfigs: AppConfig[];
343
648
  }>;
344
- declare function extractAppNameFromImage(imageRef: string): string;
345
649
  /**
346
- * Confirm prompts the user to confirm an action with a yes/no question.
650
+ * Get latest release block numbers for multiple apps
347
651
  */
348
- declare function confirm(prompt: string): Promise<boolean>;
652
+ declare function getAppLatestReleaseBlockNumbers(rpcUrl: string, environmentConfig: EnvironmentConfig, appIDs: Address[]): Promise<Map<Address, number>>;
349
653
  /**
350
- * ConfirmWithDefault prompts the user to confirm an action with a yes/no question and a default value.
654
+ * Get block timestamps for multiple block numbers
351
655
  */
352
- declare function confirmWithDefault(prompt: string, defaultValue?: boolean): Promise<boolean>;
656
+ declare function getBlockTimestamps(rpcUrl: string, environmentConfig: EnvironmentConfig, blockNumbers: number[]): Promise<Map<number, number>>;
657
+
353
658
  /**
354
- * Prompt for RPC URL
355
- * Matches Go's getRPCURL() behavior with interactive prompt
659
+ * Main deploy function
660
+ *
661
+ * This is the main entry point for deploying applications to ecloud TEE.
662
+ * It orchestrates all the steps: build, push, encrypt, and deploy on-chain.
663
+ *
664
+ * NOTE: This SDK function is non-interactive. All required parameters must be
665
+ * provided explicitly. Use the CLI for interactive parameter collection.
356
666
  */
357
- declare function getRPCUrlInteractive(rpcUrl?: string, defaultRpcUrl?: string): Promise<string>;
667
+
358
668
  /**
359
- * Prompt for environment selection
360
- * Matches Go's GetEnvironmentConfig() behavior with interactive prompt
669
+ * Required deploy options for SDK (non-interactive)
361
670
  */
362
- declare function getEnvironmentInteractive(environment?: string): Promise<string>;
671
+ interface SDKDeployOptions {
672
+ /** Private key for signing transactions (hex string with or without 0x prefix) */
673
+ privateKey: string;
674
+ /** RPC URL for blockchain connection - optional, uses environment default if not provided */
675
+ rpcUrl?: string;
676
+ /** Environment name (e.g., 'sepolia', 'mainnet-alpha') - defaults to 'sepolia' */
677
+ environment?: string;
678
+ /** Path to Dockerfile (if building from Dockerfile) - either this or imageRef is required */
679
+ dockerfilePath?: string;
680
+ /** Image reference (registry/path:tag) - either this or dockerfilePath is required */
681
+ imageRef?: string;
682
+ /** Path to .env file - optional */
683
+ envFilePath?: string;
684
+ /** App name - required */
685
+ appName: string;
686
+ /** Instance type SKU - required */
687
+ instanceType: string;
688
+ /** Log visibility setting - required */
689
+ logVisibility: LogVisibility;
690
+ /** Resource usage monitoring setting - optional, defaults to 'enable' */
691
+ resourceUsageMonitoring?: ResourceUsageMonitoring;
692
+ /** Optional gas params from estimation */
693
+ gas?: {
694
+ maxFeePerGas?: bigint;
695
+ maxPriorityFeePerGas?: bigint;
696
+ };
697
+ }
363
698
  /**
364
- * Prompt for private key with hidden input
365
- * Matches Go's output.InputHiddenString() function
699
+ * Prepared deployment ready for gas estimation and execution
700
+ */
701
+ interface PreparedDeploy {
702
+ /** The prepared batch (executions, clients, etc.) */
703
+ batch: PreparedDeployBatch;
704
+ /** App name */
705
+ appName: string;
706
+ /** Final image reference */
707
+ imageRef: string;
708
+ /** Preflight context for post-deploy operations */
709
+ preflightCtx: {
710
+ privateKey: string;
711
+ rpcUrl: string;
712
+ environmentConfig: EnvironmentConfig;
713
+ };
714
+ }
715
+ /**
716
+ * Result from prepareDeploy - includes prepared batch and gas estimate
717
+ */
718
+ interface PrepareDeployResult {
719
+ /** Prepared deployment state */
720
+ prepared: PreparedDeploy;
721
+ /** Gas estimate for the batch transaction */
722
+ gasEstimate: GasEstimate;
723
+ }
724
+ /**
725
+ * Prepare deployment - does all work up to the transaction
726
+ *
727
+ * This allows CLI to:
728
+ * 1. Call prepareDeploy to build image, prepare release, get gas estimate
729
+ * 2. Prompt user to confirm the cost
730
+ * 3. Call executeDeploy with confirmed gas params
731
+ */
732
+ declare function prepareDeploy(options: Omit<SDKDeployOptions, "gas">, logger?: Logger): Promise<PrepareDeployResult>;
733
+ /**
734
+ * Execute a prepared deployment
735
+ *
736
+ * Call this after prepareDeploy and user confirmation.
737
+ * Note: This only submits the on-chain transaction. Call watchDeployment separately
738
+ * to wait for the app to be running.
739
+ */
740
+ declare function executeDeploy(prepared: PreparedDeploy, gas: {
741
+ maxFeePerGas?: bigint;
742
+ maxPriorityFeePerGas?: bigint;
743
+ } | undefined, logger?: Logger): Promise<DeployResult>;
744
+ /**
745
+ * Watch a deployment until the app is running
746
+ *
747
+ * Call this after executeDeploy to wait for the app to be provisioned.
748
+ * Can be called separately to allow for intermediate operations (e.g., profile upload).
366
749
  */
367
- declare function getPrivateKeyInteractive(privateKey?: string): Promise<string>;
750
+ declare function watchDeployment(appId: string, privateKey: string, rpcUrl: string, environment: string, logger?: Logger, clientId?: string): Promise<string | undefined>;
368
751
 
369
752
  /**
370
- * Collect app profile information interactively
371
- * If defaultName is provided, it will be used as the suggested name
372
- * If allowRetry is true, user can re-enter information on rejection (deploy flow)
373
- * If allowRetry is false, rejection returns an error (profile set flow)
753
+ * Main upgrade function
754
+ *
755
+ * This is the main entry point for upgrading existing applications on ecloud TEE.
756
+ * It orchestrates all the steps: build, push, encrypt, and upgrade on-chain.
757
+ *
758
+ * NOTE: This SDK function is non-interactive. All required parameters must be
759
+ * provided explicitly. Use the CLI for interactive parameter collection.
374
760
  */
375
- declare function getAppProfileInteractive(defaultName?: string, allowRetry?: boolean): Promise<AppProfile | null>;
761
+
762
+ /**
763
+ * Required upgrade options for SDK (non-interactive)
764
+ */
765
+ interface SDKUpgradeOptions {
766
+ /** App ID to upgrade - required */
767
+ appId: string | Address;
768
+ /** Private key for signing transactions (hex string with or without 0x prefix) */
769
+ privateKey: string;
770
+ /** RPC URL for blockchain connection - optional, uses environment default if not provided */
771
+ rpcUrl?: string;
772
+ /** Environment name (e.g., 'sepolia', 'mainnet-alpha') - defaults to 'sepolia' */
773
+ environment?: string;
774
+ /** Path to Dockerfile (if building from Dockerfile) - either this or imageRef is required */
775
+ dockerfilePath?: string;
776
+ /** Image reference (registry/path:tag) - either this or dockerfilePath is required */
777
+ imageRef?: string;
778
+ /** Path to .env file - optional */
779
+ envFilePath?: string;
780
+ /** Instance type SKU - required */
781
+ instanceType: string;
782
+ /** Log visibility setting - required */
783
+ logVisibility: LogVisibility;
784
+ /** Resource usage monitoring setting - optional, defaults to 'enable' */
785
+ resourceUsageMonitoring?: ResourceUsageMonitoring;
786
+ /** Optional gas params from estimation */
787
+ gas?: {
788
+ maxFeePerGas?: bigint;
789
+ maxPriorityFeePerGas?: bigint;
790
+ };
791
+ }
792
+ interface UpgradeResult {
793
+ /** App ID (contract address) */
794
+ appId: string;
795
+ /** Final image reference */
796
+ imageRef: string;
797
+ /** Transaction hash */
798
+ txHash: `0x${string}`;
799
+ }
800
+ /**
801
+ * Prepared upgrade ready for gas estimation and execution
802
+ */
803
+ interface PreparedUpgrade {
804
+ /** The prepared batch (executions, clients, etc.) */
805
+ batch: PreparedUpgradeBatch;
806
+ /** App ID being upgraded */
807
+ appId: string;
808
+ /** Final image reference */
809
+ imageRef: string;
810
+ /** Preflight context for post-upgrade operations */
811
+ preflightCtx: {
812
+ privateKey: string;
813
+ rpcUrl: string;
814
+ environmentConfig: EnvironmentConfig;
815
+ };
816
+ }
817
+ /**
818
+ * Result from prepareUpgrade - includes prepared batch and gas estimate
819
+ */
820
+ interface PrepareUpgradeResult {
821
+ /** Prepared upgrade state */
822
+ prepared: PreparedUpgrade;
823
+ /** Gas estimate for the batch transaction */
824
+ gasEstimate: GasEstimate;
825
+ }
826
+ /**
827
+ * Prepare upgrade - does all work up to the transaction
828
+ *
829
+ * This allows CLI to:
830
+ * 1. Call prepareUpgrade to build image, prepare release, get gas estimate
831
+ * 2. Prompt user to confirm the cost
832
+ * 3. Call executeUpgrade with confirmed gas params
833
+ */
834
+ declare function prepareUpgrade(options: Omit<SDKUpgradeOptions, "gas">, logger?: Logger): Promise<PrepareUpgradeResult>;
835
+ /**
836
+ * Execute a prepared upgrade
837
+ *
838
+ * Call this after prepareUpgrade and user confirmation.
839
+ * Note: This only submits the on-chain transaction. Call watchUpgrade separately
840
+ * to wait for the upgrade to complete.
841
+ */
842
+ declare function executeUpgrade(prepared: PreparedUpgrade, gas: {
843
+ maxFeePerGas?: bigint;
844
+ maxPriorityFeePerGas?: bigint;
845
+ } | undefined, logger?: Logger): Promise<UpgradeResult>;
846
+ /**
847
+ * Watch an upgrade until it completes
848
+ *
849
+ * Call this after executeUpgrade to wait for the upgrade to finish.
850
+ * Can be called separately to allow for intermediate operations.
851
+ */
852
+ declare function watchUpgrade(appId: string, privateKey: string, rpcUrl: string, environment: string, logger?: Logger, clientId?: string): Promise<void>;
376
853
 
377
854
  /**
378
855
  * Environment configuration for different networks
@@ -382,6 +859,7 @@ declare function getAppProfileInteractive(defaultName?: string, allowRetry?: boo
382
859
  * Get environment configuration
383
860
  */
384
861
  declare function getEnvironmentConfig(environment: string, chainID?: bigint): EnvironmentConfig;
862
+ declare function getBuildType(): "dev" | "prod";
385
863
  /**
386
864
  * Get available environments based on build type
387
865
  * - dev: only "sepolia-dev"
@@ -392,6 +870,10 @@ declare function getAvailableEnvironments(): string[];
392
870
  * Check if an environment is available in the current build
393
871
  */
394
872
  declare function isEnvironmentAvailable(environment: string): boolean;
873
+ /**
874
+ * Check if environment is mainnet (chain ID 1)
875
+ */
876
+ declare function isMainnet(environmentConfig: EnvironmentConfig): boolean;
395
877
 
396
878
  /**
397
879
  * Billing utility functions
@@ -433,7 +915,7 @@ declare function storePrivateKey(privateKey: string): Promise<void>;
433
915
  * Note: Returns the single stored key for all environments.
434
916
  * The environment parameter is kept for API compatibility but is ignored.
435
917
  */
436
- declare function getPrivateKey(): Promise<string | null>;
918
+ declare function getPrivateKey(): Promise<`0x${string}` | null>;
437
919
  /**
438
920
  * Delete a private key from OS keyring
439
921
  * Returns true if deletion was successful, false otherwise
@@ -486,7 +968,7 @@ declare function getAddressFromPrivateKey(privateKey: string): string;
486
968
  * 3. OS keyring (stored via `ecloud auth login`)
487
969
  */
488
970
  interface PrivateKeySource {
489
- key: string;
971
+ key: `0x${string}`;
490
972
  source: string;
491
973
  }
492
974
  /**
@@ -510,41 +992,176 @@ declare function requirePrivateKey(options: {
510
992
  }): Promise<PrivateKeySource>;
511
993
 
512
994
  /**
513
- * Security Utilities
995
+ * Private Key Generation
514
996
  *
515
- * Provides secure display and input handling for sensitive data like private keys
997
+ * Generate new secp256k1 private keys for Ethereum
998
+ */
999
+ interface GeneratedKey {
1000
+ privateKey: string;
1001
+ address: string;
1002
+ }
1003
+ /**
1004
+ * Generate a new secp256k1 private key
516
1005
  */
1006
+ declare function generateNewPrivateKey(): GeneratedKey;
1007
+
517
1008
  /**
518
- * Display sensitive content using system pager (less/more)
519
- * Returns true if content was displayed, false if user aborted
1009
+ * TemplateEntry represents a single template in the catalog
520
1010
  */
521
- declare function showPrivateKey(content: string): Promise<boolean>;
1011
+ interface TemplateEntry {
1012
+ path: string;
1013
+ description: string;
1014
+ postProcess?: {
1015
+ replaceNameIn?: string[];
1016
+ };
1017
+ }
522
1018
  /**
523
- * Clear terminal screen
1019
+ * TemplateCatalog represents the structure of templates.json
1020
+ * Organized by language first, then by category (e.g., "typescript" -> "minimal")
524
1021
  */
525
- declare function clearTerminal(): void;
1022
+ interface TemplateCatalog {
1023
+ [language: string]: {
1024
+ [category: string]: TemplateEntry;
1025
+ };
1026
+ }
526
1027
  /**
527
- * Get hidden input (password-style)
1028
+ * Fetch template catalog from remote URL or local file
1029
+ * Uses a 15-minute in-memory cache to avoid excessive network requests
528
1030
  */
529
- declare function getHiddenInput(message: string): Promise<string>;
1031
+ declare function fetchTemplateCatalog(): Promise<TemplateCatalog>;
530
1032
  /**
531
- * Display multi-line warning for destructive operations
1033
+ * Get template entry by language and category
532
1034
  */
533
- declare function displayWarning(lines: string[]): void;
1035
+ declare function getTemplate(catalog: TemplateCatalog, category: string, language: string): TemplateEntry;
1036
+ /**
1037
+ * Get category descriptions for a given language
1038
+ */
1039
+ declare function getCategoryDescriptions(catalog: TemplateCatalog, language: string): Record<string, string>;
534
1040
 
535
1041
  /**
536
- * Private Key Generation
1042
+ * EIP-7702 transaction handling
537
1043
  *
538
- * Generate new secp256k1 private keys for Ethereum
1044
+ * This module handles EIP-7702 delegation and batch execution
539
1045
  */
540
- interface GeneratedKey {
1046
+
1047
+ /**
1048
+ * Options for estimating batch gas
1049
+ */
1050
+ interface EstimateBatchGasOptions {
1051
+ publicClient: PublicClient;
1052
+ environmentConfig: EnvironmentConfig;
1053
+ executions: Array<{
1054
+ target: Address;
1055
+ value: bigint;
1056
+ callData: Hex;
1057
+ }>;
1058
+ }
1059
+ /**
1060
+ * Estimate gas cost for a batch transaction
1061
+ *
1062
+ * Use this to get cost estimate before prompting user for confirmation.
1063
+ * Note: This provides a conservative estimate since batch transactions
1064
+ * through EIP-7702 can have variable costs.
1065
+ */
1066
+ declare function estimateBatchGas(options: EstimateBatchGasOptions): Promise<GasEstimate>;
1067
+
1068
+ /**
1069
+ * Preflight checks
1070
+ */
1071
+
1072
+ interface PreflightContext {
541
1073
  privateKey: string;
542
- address: string;
1074
+ rpcUrl: string;
1075
+ environmentConfig: EnvironmentConfig;
1076
+ account: PrivateKeyAccount;
1077
+ selfAddress: Address;
543
1078
  }
1079
+
544
1080
  /**
545
- * Generate a new secp256k1 private key
1081
+ * Instance type utilities
546
1082
  */
547
- declare function generateNewPrivateKey(): GeneratedKey;
1083
+
1084
+ /**
1085
+ * Get current instance type for an app (best-effort)
1086
+ * Returns empty string if unable to fetch (API unavailable, app info not ready, etc.).
1087
+ * This is used as a convenience default for the upgrade flow.
1088
+ */
1089
+ declare function getCurrentInstanceType(preflightCtx: PreflightContext, appID: Address, logger: Logger, clientId?: string): Promise<string>;
1090
+
1091
+ /**
1092
+ * UserAPI Client to manage interactions with the coordinator
1093
+ */
1094
+
1095
+ interface AppProfileInfo {
1096
+ name: string;
1097
+ website?: string;
1098
+ description?: string;
1099
+ xURL?: string;
1100
+ imageURL?: string;
1101
+ }
1102
+ interface AppMetrics {
1103
+ cpu_utilization_percent?: number;
1104
+ memory_utilization_percent?: number;
1105
+ memory_used_bytes?: number;
1106
+ memory_total_bytes?: number;
1107
+ }
1108
+ interface DerivedAddress {
1109
+ address: string;
1110
+ derivationPath: string;
1111
+ }
1112
+ interface AppInfo {
1113
+ address: Address;
1114
+ status: string;
1115
+ ip: string;
1116
+ machineType: string;
1117
+ profile?: AppProfileInfo;
1118
+ metrics?: AppMetrics;
1119
+ evmAddresses: DerivedAddress[];
1120
+ solanaAddresses: DerivedAddress[];
1121
+ }
1122
+ declare class UserApiClient {
1123
+ private readonly config;
1124
+ private readonly account?;
1125
+ private readonly rpcUrl?;
1126
+ private readonly clientId;
1127
+ constructor(config: EnvironmentConfig, privateKey?: string | Hex, rpcUrl?: string, clientId?: string);
1128
+ getInfos(appIDs: Address[], addressCount?: number): Promise<AppInfo[]>;
1129
+ /**
1130
+ * Get available SKUs (instance types) from UserAPI
1131
+ */
1132
+ getSKUs(): Promise<{
1133
+ skus: Array<{
1134
+ sku: string;
1135
+ description: string;
1136
+ }>;
1137
+ }>;
1138
+ /**
1139
+ * Get logs for an app
1140
+ */
1141
+ getLogs(appID: Address): Promise<string>;
1142
+ /**
1143
+ * Get statuses for apps
1144
+ */
1145
+ getStatuses(appIDs: Address[]): Promise<Array<{
1146
+ address: Address;
1147
+ status: string;
1148
+ }>>;
1149
+ /**
1150
+ * Upload app profile information with optional image
1151
+ */
1152
+ uploadAppProfile(appAddress: Address, name: string, website?: string, description?: string, xURL?: string, imagePath?: string): Promise<{
1153
+ name: string;
1154
+ website?: string;
1155
+ description?: string;
1156
+ xURL?: string;
1157
+ imageURL?: string;
1158
+ }>;
1159
+ private makeAuthenticatedRequest;
1160
+ /**
1161
+ * Generate authentication headers for UserAPI requests
1162
+ */
1163
+ private generateAuthHeaders;
1164
+ }
548
1165
 
549
1166
  /**
550
1167
  * Main SDK Client entry point
@@ -563,4 +1180,4 @@ interface ECloudClient {
563
1180
  }
564
1181
  declare function createECloudClient(cfg: ClientConfig): ECloudClient;
565
1182
 
566
- export { type AlreadyActiveResponse, type AppId, type AppModuleConfig, type AppProfile, type AppProfileResponse, type AppRecord, type BillingEnvironmentConfig, type BillingModuleConfig, type CancelResponse, type CancelSuccessResponse, type ChainID, type CheckoutCreatedResponse, type ClientConfig, type CreateAppOpts, type CreateSubscriptionResponse, type DeployAppOpts, type DeployOptions, type DeployResult, type DockerImageConfig, type ECloudClient, type Environment, type EnvironmentConfig, type GeneratedKey, type GetAppIDOptions, type ImageDigestResult, type LegacyKey, type LifecycleOpts, type Logger, type LogsOptions, type NoActiveSubscriptionResponse, type ParsedEnvironment, type PaymentIssueResponse, type PrivateKeySource, type ProductID, type ProductSubscriptionResponse, type Release, type StoredKey, type SubscribeResponse, type SubscriptionLineItem, type SubscriptionOpts, type SubscriptionStatus, type UpgradeAppOpts, clearTerminal, confirm, confirmWithDefault, createApp, createAppModule, createBillingModule, createECloudClient, deleteLegacyPrivateKey, deletePrivateKey, displayWarning, extractAppNameFromImage, generateNewPrivateKey, getAddressFromPrivateKey, getAppProfileInteractive, getAvailableEnvironments, getDockerfileInteractive, getEnvFileInteractive, getEnvironmentConfig, getEnvironmentInteractive, getHiddenInput, getImageReferenceInteractive, getInstanceTypeInteractive, getLegacyKeys, getLegacyPrivateKey, getLogSettingsInteractive, getOrPromptAppID, getOrPromptAppName, getPrivateKey, getPrivateKeyInteractive, getPrivateKeyWithSource, getRPCUrlInteractive, isEnvironmentAvailable, isSubscriptionActive, keyExists, listStoredKeys, type logVisibility, logs, requirePrivateKey, showPrivateKey, storePrivateKey, validatePrivateKey };
1183
+ export { type AlreadyActiveResponse, type AppId, type AppInfo, type AppMetrics, type AppModuleConfig, type AppProfile, type AppProfileInfo, type AppProfileResponse, type AppRecord, type BillingEnvironmentConfig, type BillingModuleConfig, type CancelResponse, type CancelSuccessResponse, type ChainID, type CheckoutCreatedResponse, type ClientConfig, type CreateAppOpts, type CreateAppParams, type CreateSubscriptionResponse, type DeployAppOpts, type DeployOptions, type DeployParams, type DeployResult, type DockerImageConfig, type ECloudClient, type Environment, type EnvironmentConfig, type EstimateBatchGasOptions, type EstimateGasOptions, type GasEstimate, type GeneratedKey, type ImageDigestResult, type LegacyKey, type LifecycleOpts, type LogVisibility, type Logger, type LogsOptions, type LogsParams, type NoActiveSubscriptionResponse, PRIMARY_LANGUAGES, type ParsedEnvironment, type PaymentIssueResponse, type PrepareDeployResult, type PrepareUpgradeResult, type PreparedDeploy, type PreparedUpgrade, type PrivateKeySource, type ProductID, type ProductSubscriptionResponse, type Release, type ResourceUsageMonitoring, type SDKCreateAppOpts, type SDKDeployOptions, type SDKLogsOptions, type SDKUpgradeOptions, type StoredKey, type SubscribeResponse, type SubscriptionLineItem, type SubscriptionOpts, type SubscriptionStatus, type UpgradeAppOpts, type UpgradeParams, UserApiClient, assertValidFilePath, assertValidImageReference, assertValidPrivateKey, createApp, createAppModule, createBillingModule, createECloudClient, deleteLegacyPrivateKey, deletePrivateKey, encodeStartAppData, encodeStopAppData, encodeTerminateAppData, estimateBatchGas, estimateTransactionGas, executeDeploy, executeUpgrade, extractAppNameFromImage, fetchTemplateCatalog, formatETH, generateNewPrivateKey, getAddressFromPrivateKey, getAllAppsByDeveloper, getAppLatestReleaseBlockNumbers, getAvailableEnvironments, getAvailableTemplates, getBlockTimestamps, getBuildType, getCategoryDescriptions, getCurrentInstanceType, getEnvironmentConfig, getLegacyKeys, getLegacyPrivateKey, getPrivateKey, getPrivateKeyWithSource, getTemplate, isEnvironmentAvailable, isMainnet, isSubscriptionActive, keyExists, listStoredKeys, type logVisibility, logs, prepareDeploy, prepareUpgrade, requirePrivateKey, sanitizeString, sanitizeURL, sanitizeXURL, storePrivateKey, validateAppID, validateAppName, validateCreateAppParams, validateDeployParams, validateDescription, validateFilePath, validateImagePath, validateImageReference, validateInstanceTypeSKU, validateLogVisibility, validateLogsParams, validatePrivateKey, validatePrivateKeyFormat, validateResourceUsageMonitoring, validateURL, validateUpgradeParams, validateXURL, watchDeployment, watchUpgrade };