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