Skip to main content

canic_core/
protocol.rs

1/// Runtime wire-level endpoint names used by `canic-core` for inter-canister calls.
2///
3/// Keep these synchronized with the macro-defined endpoints.
4use crate::{api::ic::ProtectedInternalEndpoint, ids::CanisterRole};
5
6pub const CANIC_RESPONSE_CAPABILITY_V1: &str = "canic_response_capability_v1";
7pub const CANIC_REQUEST_DELEGATION: &str = "canic_request_delegation";
8pub const CANIC_REQUEST_ROLE_ATTESTATION: &str = "canic_request_role_attestation";
9pub const CANIC_REQUEST_INTERNAL_INVOCATION_PROOF: &str = "canic_request_internal_invocation_proof";
10pub const CANIC_ATTESTATION_KEY_SET: &str = "canic_attestation_key_set";
11pub const CANIC_BOOTSTRAP_STATUS: &str = "canic_bootstrap_status";
12pub const CANIC_CYCLE_BALANCE: &str = "canic_cycle_balance";
13pub const CANIC_CYCLE_TRACKER: &str = "canic_cycle_tracker";
14pub const CANIC_CYCLE_TOPUPS: &str = "canic_cycle_topups";
15pub const CANIC_METADATA: &str = "canic_metadata";
16pub const CANIC_WASM_STORE_CATALOG: &str = "canic_wasm_store_catalog";
17pub const CANIC_WASM_STORE_INFO: &str = "canic_wasm_store_info";
18pub const CANIC_WASM_STORE_STATUS: &str = "canic_wasm_store_status";
19pub const CANIC_WASM_STORE_PREPARE_GC: &str = "canic_wasm_store_prepare_gc";
20pub const CANIC_WASM_STORE_BEGIN_GC: &str = "canic_wasm_store_begin_gc";
21pub const CANIC_WASM_STORE_COMPLETE_GC: &str = "canic_wasm_store_complete_gc";
22pub const CANIC_WASM_STORE_PREPARE: &str = "canic_wasm_store_prepare";
23pub const CANIC_WASM_STORE_CHUNK: &str = "canic_wasm_store_chunk";
24pub const CANIC_WASM_STORE_PUBLISH_CHUNK: &str = "canic_wasm_store_publish_chunk";
25pub const CANIC_WASM_STORE_STAGE_MANIFEST: &str = "canic_wasm_store_stage_manifest";
26pub const CANIC_WASM_STORE_BOOTSTRAP_RESUME_ROOT_ADMIN: &str =
27    "canic_wasm_store_bootstrap_resume_root_admin";
28pub const CANIC_WASM_STORE_BOOTSTRAP_DEBUG: &str = "canic_wasm_store_bootstrap_debug";
29pub const CANIC_WASM_STORE_OVERVIEW: &str = "canic_wasm_store_overview";
30pub const CANIC_TEMPLATE_PREPARE_ADMIN: &str = "canic_template_prepare_admin";
31pub const CANIC_TEMPLATE_PUBLISH_CHUNK_ADMIN: &str = "canic_template_publish_chunk_admin";
32pub const CANIC_TEMPLATE_STAGE_MANIFEST_ADMIN: &str = "canic_template_stage_manifest_admin";
33
34pub const CANIC_SYNC_STATE: &str = "canic_sync_state";
35pub const CANIC_SYNC_TOPOLOGY: &str = "canic_sync_topology";
36
37pub const CANIC_WASM_STORE_PROTECTED_UPDATE_METHODS: &[&str] = &[
38    CANIC_WASM_STORE_BEGIN_GC,
39    CANIC_WASM_STORE_CHUNK,
40    CANIC_WASM_STORE_COMPLETE_GC,
41    CANIC_WASM_STORE_INFO,
42    CANIC_WASM_STORE_PREPARE,
43    CANIC_WASM_STORE_PREPARE_GC,
44    CANIC_WASM_STORE_PUBLISH_CHUNK,
45    CANIC_WASM_STORE_STAGE_MANIFEST,
46];
47
48pub const CANIC_WASM_STORE_STRUCTURAL_QUERY_METHODS: &[&str] =
49    &[CANIC_WASM_STORE_CATALOG, CANIC_WASM_STORE_STATUS];
50
51#[must_use]
52pub fn canic_wasm_store_method_requires_internal_proof(method: &str) -> bool {
53    CANIC_WASM_STORE_PROTECTED_UPDATE_METHODS.contains(&method)
54}
55
56#[must_use]
57pub fn canic_wasm_store_begin_gc_endpoint() -> ProtectedInternalEndpoint {
58    wasm_store_root_endpoint(CANIC_WASM_STORE_BEGIN_GC)
59}
60
61#[must_use]
62pub fn canic_wasm_store_chunk_endpoint() -> ProtectedInternalEndpoint {
63    wasm_store_root_endpoint(CANIC_WASM_STORE_CHUNK)
64}
65
66#[must_use]
67pub fn canic_wasm_store_complete_gc_endpoint() -> ProtectedInternalEndpoint {
68    wasm_store_root_endpoint(CANIC_WASM_STORE_COMPLETE_GC)
69}
70
71#[must_use]
72pub fn canic_wasm_store_info_endpoint() -> ProtectedInternalEndpoint {
73    wasm_store_root_endpoint(CANIC_WASM_STORE_INFO)
74}
75
76#[must_use]
77pub fn canic_wasm_store_prepare_endpoint() -> ProtectedInternalEndpoint {
78    wasm_store_root_endpoint(CANIC_WASM_STORE_PREPARE)
79}
80
81#[must_use]
82pub fn canic_wasm_store_prepare_gc_endpoint() -> ProtectedInternalEndpoint {
83    wasm_store_root_endpoint(CANIC_WASM_STORE_PREPARE_GC)
84}
85
86#[must_use]
87pub fn canic_wasm_store_publish_chunk_endpoint() -> ProtectedInternalEndpoint {
88    wasm_store_root_endpoint(CANIC_WASM_STORE_PUBLISH_CHUNK)
89}
90
91#[must_use]
92pub fn canic_wasm_store_stage_manifest_endpoint() -> ProtectedInternalEndpoint {
93    wasm_store_root_endpoint(CANIC_WASM_STORE_STAGE_MANIFEST)
94}
95
96fn wasm_store_root_endpoint(method: &'static str) -> ProtectedInternalEndpoint {
97    ProtectedInternalEndpoint::new(method, [CanisterRole::ROOT])
98}