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