Skip to main content

ic_auth_protocol_types/
delegation.rs

1//! Passive root-delegation records, separate from transport and authentication.
2
3use crate::{AudienceId, DelegatedRoleGrant, Principal};
4
5///
6/// IssuerDelegation
7///
8/// Common issuer authorization fields carried by a certificate and its root leaf.
9/// This profile supports IC canister signatures and an application audience.
10/// Construction checks no authority, binding, ordering or time relationships.
11///
12
13#[derive(Clone, Debug, Eq, PartialEq)]
14pub struct IssuerDelegation {
15    /// Claimed root canister.
16    pub root: Principal,
17    /// Claimed delegated issuer.
18    pub issuer: Principal,
19    /// Submitted issuer/algorithm/seed commitment; never silently recomputed.
20    pub binding_hash: [u8; 32],
21    /// Claimed IC canister-signature seed commitment.
22    pub seed_hash: [u8; 32],
23    /// Maximum delegated credential lifetime, in nanoseconds.
24    pub max_token_ttl_ns: u64,
25    /// Claimed network/application restriction.
26    pub audience: AudienceId,
27    /// Claimed role-wise scopes in received order.
28    pub grants: Vec<DelegatedRoleGrant>,
29    /// Inclusive validity start.
30    pub not_before_ns: u64,
31    /// Exclusive expiry.
32    pub expires_at_ns: u64,
33}
34
35///
36/// DelegationCertificate
37///
38/// Certificate commitment used as the portable credential's key-binding identity.
39///
40
41#[derive(Clone, Debug, Eq, PartialEq)]
42pub struct DelegationCertificate {
43    /// Claimed authorization, requiring agreement with the signed issuer leaf.
44    pub delegation: IssuerDelegation,
45    /// Metadata included in the certificate hash but not the root-signed leaf.
46    pub issued_at_ns: u64,
47}
48
49///
50/// DelegationLeaf
51///
52/// Issuer leaf committed by a root-signed chain-key batch.
53///
54
55#[derive(Clone, Debug, Eq, PartialEq)]
56pub struct DelegationLeaf {
57    /// Claimed authorization. The verifier must compare it with the certificate.
58    pub delegation: IssuerDelegation,
59    /// Claimed proof epoch.
60    pub proof_epoch: u64,
61    /// Claimed registry epoch.
62    pub registry_epoch: u64,
63    /// Registry commitment.
64    pub registry_hash: [u8; 32],
65}
66
67///
68/// RootBatchHeader
69///
70/// Root batch header for the current ECDSA/secp256k1 signing profile.
71/// Schema, key identity, epochs, tree root and time still require verification.
72///
73
74#[derive(Clone, Debug, Eq, PartialEq)]
75pub struct RootBatchHeader {
76    /// Submitted schema, checked separately from canonical field encoding.
77    pub schema_version: u16,
78    /// Claimed root canister.
79    pub root: Principal,
80    /// Batch identity.
81    pub batch_id: [u8; 32],
82    /// Claimed proof epoch.
83    pub proof_epoch: u64,
84    /// Claimed registry epoch.
85    pub registry_epoch: u64,
86    /// Registry commitment.
87    pub registry_hash: [u8; 32],
88    /// Committed Merkle root.
89    pub tree_root: [u8; 32],
90    /// Inclusive validity start.
91    pub not_before_ns: u64,
92    /// Exclusive expiry.
93    pub expires_at_ns: u64,
94    /// Untrusted key name; the encoder bounds its UTF-8 length to 128 bytes.
95    pub key_name: String,
96    /// Ordered derivation-path commitment.
97    pub derivation_path_hash: [u8; 32],
98    /// Claimed key version.
99    pub key_version: u64,
100}
101
102///
103/// MerkleStep
104///
105/// One ordered sibling in the current root batch Merkle proof.
106///
107
108#[derive(Clone, Copy, Debug, Eq, PartialEq)]
109pub enum MerkleStep {
110    /// Sibling preceding the current node.
111    Left([u8; 32]),
112    /// Sibling following the current node.
113    Right([u8; 32]),
114}