Skip to main content

canic_host/frontend/model/
mod.rs

1//! Passive operator input and browser handoff records.
2//!
3//! No credentials, controller lists or Fleet mutation authority belong in these records.
4
5use candid::Principal;
6use canic_core::ids::{CanisterRole, CanonicalNetworkId};
7use serde::{Deserialize, Serialize};
8use std::path::PathBuf;
9
10///
11/// FrontendUploadedInput
12///
13/// Exact local handoff and external target for read-only post-sync verification.
14///
15
16pub struct FrontendUploadedInput {
17    pub directory: PathBuf,
18    pub manifest_sha256: String,
19    pub environment: String,
20    pub network: CanonicalNetworkId,
21    pub canister_id: Principal,
22    pub prefix: String,
23}
24
25/// Explicit finite limits for an external asset payload review.
26pub struct FrontendAssetCapacityInput {
27    pub environment: String,
28    pub canister_id: Principal,
29    pub payload_directory: PathBuf,
30    pub minimum_native_cycles: u128,
31    pub maximum_payload_bytes: u64,
32    pub maximum_files: u32,
33}
34
35/// Exact role instance explicitly selected for browser use.
36#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
37#[serde(deny_unknown_fields)]
38pub struct FrontendRoleInput {
39    pub role: CanisterRole,
40    pub canister_id: Principal,
41}
42
43/// Internet Identity provider and the caller namespace retained by the frontend.
44#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
45#[serde(deny_unknown_fields)]
46pub struct FrontendIdentityInput {
47    pub canister_id: Principal,
48    pub provider_origin: String,
49    pub derivation_origin: String,
50    /// Complete contents of the certified II alternative-origins asset.
51    pub alternative_origins: Vec<String>,
52}
53
54/// External static-asset identity; Canic neither uploads assets nor controls this canister.
55#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
56#[serde(deny_unknown_fields)]
57pub struct FrontendAssetInput {
58    pub canister_id: Principal,
59    pub origin: String,
60}
61
62/// Selected-environment input to a bounded frontend export.
63#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
64#[serde(deny_unknown_fields)]
65pub struct FrontendEnvironmentInput {
66    pub schema_version: u16,
67    pub environment: String,
68    pub canonical_network_id: CanonicalNetworkId,
69    pub api_origin: String,
70    pub identity: FrontendIdentityInput,
71    pub asset: Option<FrontendAssetInput>,
72    pub roles: Vec<FrontendRoleInput>,
73}
74
75/// File identity included in the browser bundle digest.
76#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
77#[serde(deny_unknown_fields)]
78pub struct FrontendFileRecord {
79    pub path: String,
80    pub sha256: String,
81    pub bytes: u64,
82}
83
84/// Public identity and exact generated binding artifacts for one selected instance.
85#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
86#[serde(deny_unknown_fields)]
87pub struct FrontendRoleRecord {
88    pub role: CanisterRole,
89    pub canister_id: Principal,
90    pub release_identity: String,
91    pub module_sha256: String,
92    pub candid: FrontendFileRecord,
93    pub javascript: FrontendFileRecord,
94    pub typescript: FrontendFileRecord,
95}
96
97/// Integrity-covered browser data derived from one terminal Fleet review.
98#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
99#[serde(deny_unknown_fields)]
100pub struct FrontendManifestRecord {
101    pub schema_version: u16,
102    pub manifest_sha256: String,
103    pub generator: String,
104    pub app: String,
105    pub fleet: String,
106    pub fleet_id: String,
107    pub source_plan_sha256: String,
108    pub environment: String,
109    pub canonical_network_id: CanonicalNetworkId,
110    pub api_origin: String,
111    /// Present only for an explicitly enrolled local network; never fetched by the browser.
112    #[serde(deserialize_with = "Option::deserialize")]
113    pub local_root_key_der_hex: Option<String>,
114    pub identity: FrontendIdentityInput,
115    pub alternative_origins: FrontendFileRecord,
116    #[serde(deserialize_with = "Option::deserialize")]
117    pub asset: Option<FrontendAssetInput>,
118    pub roles: Vec<FrontendRoleRecord>,
119}