@phala/cloud 0.2.0 → 0.2.1-beta.2

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.
@@ -4,7 +4,19 @@ import { type Client } from "../../client";
4
4
  * Commit CVM Provision (Create CVM from provisioned data)
5
5
  *
6
6
  * This action creates a CVM using previously provisioned data and encrypted environment variables.
7
- * It should be called after `provisionCvm` to complete the CVM deployment process.
7
+ * It MUST be called after `provisionCvm` to complete the CVM deployment process.
8
+ *
9
+ * ## Two-Step Deployment Flow
10
+ *
11
+ * 1. **Provision** (`provisionCvm`): Prepares resources and returns `compose_hash` (and `app_id` for PHALA KMS)
12
+ * 2. **Commit** (this function): Creates the actual CVM using provisioned data
13
+ *
14
+ * ## KMS Type and app_id Source
15
+ *
16
+ * The `app_id` source depends on the KMS type used during provisioning:
17
+ *
18
+ * - **PHALA KMS** (default): `app_id` is obtained from centralized KMS - returned by `provisionCvm()`
19
+ * - **ETHEREUM/BASE KMS** (on-chain): `app_id` must be obtained by deploying your contract and interacting with the on-chain KMS - NOT provided by `provisionCvm()`
8
20
  *
9
21
  * @example
10
22
  * ```typescript
@@ -12,20 +24,43 @@ import { type Client } from "../../client";
12
24
  *
13
25
  * const client = createClient();
14
26
  *
15
- * // First, provision the CVM
16
- * const provision = await provisionCvm(client, appCompose);
27
+ * // Example 1: PHALA KMS (default - app_id from provision)
28
+ * const provision = await provisionCvm(client, {
29
+ * name: "my-cvm",
30
+ * instance_type: "tdx.small",
31
+ * kms: "PHALA", // or omit for default
32
+ * compose_file: { docker_compose_file: "..." },
33
+ * });
17
34
  *
18
- * // Then, commit the provision with encrypted environment variables
35
+ * // app_id is provided by provision API
19
36
  * const cvm = await commitCvmProvision(client, {
20
- * encrypted_env: "hex-encoded-encrypted-environment-data", // String, not array
21
- * app_id: provision.app_id,
37
+ * app_id: provision.app_id, // From provision response
22
38
  * compose_hash: provision.compose_hash,
23
- * kms_id: "your-kms-id",
24
- * contract_address: "0x123...",
25
- * deployer_address: "0x456..."
39
+ * encrypted_env: "...",
40
+ * });
41
+ *
42
+ * // Example 2: On-chain KMS (app_id from contract deployment)
43
+ * const provision = await provisionCvm(client, {
44
+ * name: "my-cvm",
45
+ * instance_type: "tdx.small",
46
+ * kms: "ETHEREUM", // or "BASE" for Base network
47
+ * compose_file: { docker_compose_file: "..." },
26
48
  * });
27
49
  *
28
- * console.log(cvm.id);
50
+ * // Step 1: Deploy your contract and get app_id from on-chain KMS
51
+ * const contractTx = await deployContract({
52
+ * kmsContract: "0x...",
53
+ * // ... contract deployment params
54
+ * });
55
+ * const appId = await getAppIdFromKms(contractTx);
56
+ *
57
+ * // Step 2: Commit with app_id from on-chain interaction
58
+ * const cvm = await commitCvmProvision(client, {
59
+ * app_id: appId, // From on-chain KMS, NOT from provision
60
+ * compose_hash: provision.compose_hash, // From provision response
61
+ * contract_address: "0x123...", // Your deployed contract
62
+ * deployer_address: "0x456...", // Deployer address
63
+ * });
29
64
  * ```
30
65
  *
31
66
  * ## Returns
@@ -34,9 +69,22 @@ import { type Client } from "../../client";
34
69
  *
35
70
  * The created CVM details including id, name, status, and other metadata. Return type depends on schema parameter.
36
71
  *
37
- * ## Parameters
72
+ * ## Required Parameters
73
+ *
74
+ * - **app_id**: Application identifier
75
+ * - For PHALA KMS: Use `provision.app_id` from `provisionCvm()` response
76
+ * - For ETHEREUM/BASE KMS (on-chain): Obtain from your on-chain KMS contract deployment
77
+ * - **compose_hash**: Must be obtained from `provisionCvm()` response (used to retrieve provision data from Redis)
78
+ *
79
+ * ## Optional Parameters
80
+ *
81
+ * - **encrypted_env**: Hex-encoded encrypted environment variables
82
+ * - **env_keys**: List of environment variable keys to allow
83
+ * - **kms_id**: KMS instance identifier (if using specific KMS)
84
+ * - **contract_address**: On-chain KMS contract address (required for ETHEREUM/BASE KMS)
85
+ * - **deployer_address**: Deployer address for on-chain verification (required for ETHEREUM/BASE KMS)
38
86
  *
39
- * ### schema (optional)
87
+ * ## Schema Parameter
40
88
  *
41
89
  * - **Type:** `ZodSchema | false`
42
90
  * - **Default:** `CommitCvmProvisionSchema`
@@ -178,7 +226,7 @@ export type CommitCvmProvision = z.infer<typeof CommitCvmProvisionSchema>;
178
226
  export declare const CommitCvmProvisionRequestSchema: z.ZodObject<{
179
227
  encrypted_env: z.ZodNullable<z.ZodOptional<z.ZodString>>;
180
228
  app_id: z.ZodString;
181
- compose_hash: z.ZodOptional<z.ZodString>;
229
+ compose_hash: z.ZodString;
182
230
  kms_id: z.ZodOptional<z.ZodString>;
183
231
  contract_address: z.ZodOptional<z.ZodString>;
184
232
  deployer_address: z.ZodOptional<z.ZodString>;
@@ -186,7 +234,7 @@ export declare const CommitCvmProvisionRequestSchema: z.ZodObject<{
186
234
  }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
187
235
  encrypted_env: z.ZodNullable<z.ZodOptional<z.ZodString>>;
188
236
  app_id: z.ZodString;
189
- compose_hash: z.ZodOptional<z.ZodString>;
237
+ compose_hash: z.ZodString;
190
238
  kms_id: z.ZodOptional<z.ZodString>;
191
239
  contract_address: z.ZodOptional<z.ZodString>;
192
240
  deployer_address: z.ZodOptional<z.ZodString>;
@@ -194,7 +242,7 @@ export declare const CommitCvmProvisionRequestSchema: z.ZodObject<{
194
242
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
195
243
  encrypted_env: z.ZodNullable<z.ZodOptional<z.ZodString>>;
196
244
  app_id: z.ZodString;
197
- compose_hash: z.ZodOptional<z.ZodString>;
245
+ compose_hash: z.ZodString;
198
246
  kms_id: z.ZodOptional<z.ZodString>;
199
247
  contract_address: z.ZodOptional<z.ZodString>;
200
248
  deployer_address: z.ZodOptional<z.ZodString>;
@@ -205,7 +253,7 @@ declare const commitCvmProvision: {
205
253
  (client: Client, params: z.objectOutputType<{
206
254
  encrypted_env: z.ZodNullable<z.ZodOptional<z.ZodString>>;
207
255
  app_id: z.ZodString;
208
- compose_hash: z.ZodOptional<z.ZodString>;
256
+ compose_hash: z.ZodString;
209
257
  kms_id: z.ZodOptional<z.ZodString>;
210
258
  contract_address: z.ZodOptional<z.ZodString>;
211
259
  deployer_address: z.ZodOptional<z.ZodString>;
@@ -247,7 +295,7 @@ declare const commitCvmProvision: {
247
295
  <T extends z.ZodTypeAny>(client: Client, params: z.objectOutputType<{
248
296
  encrypted_env: z.ZodNullable<z.ZodOptional<z.ZodString>>;
249
297
  app_id: z.ZodString;
250
- compose_hash: z.ZodOptional<z.ZodString>;
298
+ compose_hash: z.ZodString;
251
299
  kms_id: z.ZodOptional<z.ZodString>;
252
300
  contract_address: z.ZodOptional<z.ZodString>;
253
301
  deployer_address: z.ZodOptional<z.ZodString>;
@@ -258,7 +306,7 @@ declare const commitCvmProvision: {
258
306
  (client: Client, params: z.objectOutputType<{
259
307
  encrypted_env: z.ZodNullable<z.ZodOptional<z.ZodString>>;
260
308
  app_id: z.ZodString;
261
- compose_hash: z.ZodOptional<z.ZodString>;
309
+ compose_hash: z.ZodString;
262
310
  kms_id: z.ZodOptional<z.ZodString>;
263
311
  contract_address: z.ZodOptional<z.ZodString>;
264
312
  deployer_address: z.ZodOptional<z.ZodString>;
@@ -270,7 +318,7 @@ declare const commitCvmProvision: {
270
318
  (client: Client, params: z.objectOutputType<{
271
319
  encrypted_env: z.ZodNullable<z.ZodOptional<z.ZodString>>;
272
320
  app_id: z.ZodString;
273
- compose_hash: z.ZodOptional<z.ZodString>;
321
+ compose_hash: z.ZodString;
274
322
  kms_id: z.ZodOptional<z.ZodString>;
275
323
  contract_address: z.ZodOptional<z.ZodString>;
276
324
  deployer_address: z.ZodOptional<z.ZodString>;
@@ -312,7 +360,7 @@ declare const commitCvmProvision: {
312
360
  <T extends z.ZodTypeAny>(client: Client, params: z.objectOutputType<{
313
361
  encrypted_env: z.ZodNullable<z.ZodOptional<z.ZodString>>;
314
362
  app_id: z.ZodString;
315
- compose_hash: z.ZodOptional<z.ZodString>;
363
+ compose_hash: z.ZodString;
316
364
  kms_id: z.ZodOptional<z.ZodString>;
317
365
  contract_address: z.ZodOptional<z.ZodString>;
318
366
  deployer_address: z.ZodOptional<z.ZodString>;
@@ -323,7 +371,7 @@ declare const commitCvmProvision: {
323
371
  (client: Client, params: z.objectOutputType<{
324
372
  encrypted_env: z.ZodNullable<z.ZodOptional<z.ZodString>>;
325
373
  app_id: z.ZodString;
326
- compose_hash: z.ZodOptional<z.ZodString>;
374
+ compose_hash: z.ZodString;
327
375
  kms_id: z.ZodOptional<z.ZodString>;
328
376
  contract_address: z.ZodOptional<z.ZodString>;
329
377
  deployer_address: z.ZodOptional<z.ZodString>;
@@ -8,15 +8,15 @@ export declare const GetCvmListRequestSchema: z.ZodObject<{
8
8
  user_id: z.ZodOptional<z.ZodString>;
9
9
  }, "strict", z.ZodTypeAny, {
10
10
  teepod_id?: number | undefined;
11
+ user_id?: string | undefined;
11
12
  page?: number | undefined;
12
13
  page_size?: number | undefined;
13
- user_id?: string | undefined;
14
14
  node_id?: number | undefined;
15
15
  }, {
16
16
  teepod_id?: number | undefined;
17
+ user_id?: string | undefined;
17
18
  page?: number | undefined;
18
19
  page_size?: number | undefined;
19
- user_id?: string | undefined;
20
20
  node_id?: number | undefined;
21
21
  }>;
22
22
  export declare const GetCvmListSchema: z.ZodObject<{
@@ -262,8 +262,6 @@ export declare const GetCvmListSchema: z.ZodObject<{
262
262
  page_size: z.ZodNumber;
263
263
  pages: z.ZodNumber;
264
264
  }, "strict", z.ZodTypeAny, {
265
- page: number;
266
- page_size: number;
267
265
  items: {
268
266
  status: string;
269
267
  name: string;
@@ -318,10 +316,10 @@ export declare const GetCvmListSchema: z.ZodObject<{
318
316
  }[];
319
317
  }[];
320
318
  total: number;
321
- pages: number;
322
- }, {
323
319
  page: number;
324
320
  page_size: number;
321
+ pages: number;
322
+ }, {
325
323
  items: {
326
324
  status: string;
327
325
  name: string;
@@ -376,6 +374,8 @@ export declare const GetCvmListSchema: z.ZodObject<{
376
374
  allow_upgrade?: boolean | undefined;
377
375
  }[];
378
376
  total: number;
377
+ page: number;
378
+ page_size: number;
379
379
  pages: number;
380
380
  }>;
381
381
  export type GetCvmListRequest = z.infer<typeof GetCvmListRequestSchema>;
@@ -405,13 +405,11 @@ export type GetCvmListResponse = z.infer<typeof GetCvmListSchema>;
405
405
  declare const getCvmList: {
406
406
  (client: Client, params?: {
407
407
  teepod_id?: number | undefined;
408
+ user_id?: string | undefined;
408
409
  page?: number | undefined;
409
410
  page_size?: number | undefined;
410
- user_id?: string | undefined;
411
411
  node_id?: number | undefined;
412
412
  } | undefined): Promise<{
413
- page: number;
414
- page_size: number;
415
413
  items: {
416
414
  status: string;
417
415
  name: string;
@@ -466,22 +464,24 @@ declare const getCvmList: {
466
464
  }[];
467
465
  }[];
468
466
  total: number;
467
+ page: number;
468
+ page_size: number;
469
469
  pages: number;
470
470
  }>;
471
471
  <T extends z.ZodTypeAny>(client: Client, params?: {
472
472
  teepod_id?: number | undefined;
473
+ user_id?: string | undefined;
473
474
  page?: number | undefined;
474
475
  page_size?: number | undefined;
475
- user_id?: string | undefined;
476
476
  node_id?: number | undefined;
477
477
  } | undefined, parameters?: {
478
478
  schema: T;
479
479
  } | undefined): Promise<z.TypeOf<T>>;
480
480
  (client: Client, params?: {
481
481
  teepod_id?: number | undefined;
482
+ user_id?: string | undefined;
482
483
  page?: number | undefined;
483
484
  page_size?: number | undefined;
484
- user_id?: string | undefined;
485
485
  node_id?: number | undefined;
486
486
  } | undefined, parameters?: {
487
487
  schema: false;
@@ -489,13 +489,11 @@ declare const getCvmList: {
489
489
  }, safeGetCvmList: {
490
490
  (client: Client, params?: {
491
491
  teepod_id?: number | undefined;
492
+ user_id?: string | undefined;
492
493
  page?: number | undefined;
493
494
  page_size?: number | undefined;
494
- user_id?: string | undefined;
495
495
  node_id?: number | undefined;
496
496
  } | undefined): Promise<import("../..").SafeResult<{
497
- page: number;
498
- page_size: number;
499
497
  items: {
500
498
  status: string;
501
499
  name: string;
@@ -550,22 +548,24 @@ declare const getCvmList: {
550
548
  }[];
551
549
  }[];
552
550
  total: number;
551
+ page: number;
552
+ page_size: number;
553
553
  pages: number;
554
554
  }>>;
555
555
  <T extends z.ZodTypeAny>(client: Client, params?: {
556
556
  teepod_id?: number | undefined;
557
+ user_id?: string | undefined;
557
558
  page?: number | undefined;
558
559
  page_size?: number | undefined;
559
- user_id?: string | undefined;
560
560
  node_id?: number | undefined;
561
561
  } | undefined, parameters?: {
562
562
  schema: T;
563
563
  } | undefined): Promise<import("../..").SafeResult<z.TypeOf<T>>>;
564
564
  (client: Client, params?: {
565
565
  teepod_id?: number | undefined;
566
+ user_id?: string | undefined;
566
567
  page?: number | undefined;
567
568
  page_size?: number | undefined;
568
- user_id?: string | undefined;
569
569
  node_id?: number | undefined;
570
570
  } | undefined, parameters?: {
571
571
  schema: false;
@@ -5,23 +5,35 @@ import { type CvmIdInput } from "../../types/cvm_id";
5
5
  * CVM state response schema
6
6
  */
7
7
  export declare const CvmStateSchema: z.ZodObject<{
8
- status: z.ZodString;
9
- derived_status: z.ZodOptional<z.ZodString>;
10
- vm_uuid: z.ZodOptional<z.ZodString>;
8
+ id: z.ZodOptional<z.ZodString>;
11
9
  instance_id: z.ZodOptional<z.ZodString>;
10
+ name: z.ZodString;
11
+ status: z.ZodString;
12
12
  uptime: z.ZodOptional<z.ZodString>;
13
+ exited_at: z.ZodOptional<z.ZodString>;
14
+ boot_progress: z.ZodOptional<z.ZodString>;
15
+ boot_error: z.ZodOptional<z.ZodString>;
16
+ shutdown_progress: z.ZodOptional<z.ZodString>;
13
17
  }, "strip", z.ZodTypeAny, {
14
18
  status: string;
19
+ name: string;
20
+ id?: string | undefined;
15
21
  uptime?: string | undefined;
16
22
  instance_id?: string | undefined;
17
- vm_uuid?: string | undefined;
18
- derived_status?: string | undefined;
23
+ exited_at?: string | undefined;
24
+ boot_progress?: string | undefined;
25
+ boot_error?: string | undefined;
26
+ shutdown_progress?: string | undefined;
19
27
  }, {
20
28
  status: string;
29
+ name: string;
30
+ id?: string | undefined;
21
31
  uptime?: string | undefined;
22
32
  instance_id?: string | undefined;
23
- vm_uuid?: string | undefined;
24
- derived_status?: string | undefined;
33
+ exited_at?: string | undefined;
34
+ boot_progress?: string | undefined;
35
+ boot_error?: string | undefined;
36
+ shutdown_progress?: string | undefined;
25
37
  }>;
26
38
  export type CvmState = z.infer<typeof CvmStateSchema>;
27
39
  export declare const GetCvmStateRequestSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
@@ -64,10 +76,14 @@ export type GetCvmStateRequest = CvmIdInput;
64
76
  declare const getCvmState: {
65
77
  (client: Client, params: CvmIdInput): Promise<{
66
78
  status: string;
79
+ name: string;
80
+ id?: string | undefined;
67
81
  uptime?: string | undefined;
68
82
  instance_id?: string | undefined;
69
- vm_uuid?: string | undefined;
70
- derived_status?: string | undefined;
83
+ exited_at?: string | undefined;
84
+ boot_progress?: string | undefined;
85
+ boot_error?: string | undefined;
86
+ shutdown_progress?: string | undefined;
71
87
  }>;
72
88
  <T extends z.ZodTypeAny>(client: Client, params: CvmIdInput, parameters: {
73
89
  schema: T;
@@ -78,10 +94,14 @@ declare const getCvmState: {
78
94
  }, safeGetCvmState: {
79
95
  (client: Client, params: CvmIdInput): Promise<import("../..").SafeResult<{
80
96
  status: string;
97
+ name: string;
98
+ id?: string | undefined;
81
99
  uptime?: string | undefined;
82
100
  instance_id?: string | undefined;
83
- vm_uuid?: string | undefined;
84
- derived_status?: string | undefined;
101
+ exited_at?: string | undefined;
102
+ boot_progress?: string | undefined;
103
+ boot_error?: string | undefined;
104
+ shutdown_progress?: string | undefined;
85
105
  }>>;
86
106
  <T extends z.ZodTypeAny>(client: Client, params: CvmIdInput, parameters: {
87
107
  schema: T;