Skip to main content

ic_auth_wire/model/
mod.rs

1//! Transport records and discriminants, kept distinct from engine decisions.
2
3mod credential;
4
5use ic_auth_protocol_types::Principal;
6use serde::{Deserialize, Serialize};
7
8pub use credential::{
9    AudienceId, CertifiedProof, ChainKeyAlgorithm, ChainKeyBatchHeaderV1,
10    ChainKeyBatchWitnessStepV1, ChainKeyBatchWitnessV1, ChainKeyDelegationCertV1, ChainKeyKeyId,
11    ChainKeyRootSignatureV1, DelegatedRoleGrant, DelegationAudience, DelegationCert,
12    DelegationProof, IcCanisterSignatureProofV1, IcChainKeyBatchSignatureProofV1,
13    IssuerProofAlgorithm, IssuerProofBinding, PortableCredential, PortableProof, RootProof,
14};
15
16/// Session-admission refusals in their fixed transport order.
17#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
18#[cfg_attr(
19    all(feature = "typescript", not(target_family = "wasm")),
20    derive(ic_wire::typescript::Wire)
21)]
22pub enum AdmissionRefusal {
23    /// Credential is not yet valid at trusted time.
24    NotYetValid,
25    /// Credential has expired for fresh admission.
26    Expired,
27    /// Credential verification failed.
28    InvalidCredential,
29    /// Protected authority is not ready.
30    AuthorityUnavailable,
31    /// Credential predates the protected reset boundary.
32    BeforeReset,
33    /// Requested scopes are not admitted.
34    ScopeRejected,
35    /// A consumed credential conflicts with this request.
36    ReplayConflict,
37    /// Retained revocation prevents admission.
38    Revoked,
39    /// Required bounded state has no capacity.
40    Capacity,
41    /// The applicable attempt budget is exhausted.
42    Throttled,
43    /// Admission could not be completed.
44    Unavailable,
45}
46
47/// A local session receipt; receiving or constructing it grants no authority.
48#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
49#[cfg_attr(
50    all(feature = "typescript", not(target_family = "wasm")),
51    derive(ic_wire::typescript::Wire)
52)]
53pub struct SessionView {
54    /// Host-authenticated browser principal bound to the session.
55    pub caller: Principal,
56    /// Issuer qualifying the subject.
57    pub issuer: Principal,
58    /// Issuer-qualified account subject.
59    pub subject: Principal,
60    /// Exclusive local lease deadline in nanoseconds.
61    pub expires_at_ns: u64,
62}
63
64/// Existing read-refusal discriminants, in their fixed Wire order.
65#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
66#[cfg_attr(
67    all(feature = "typescript", not(target_family = "wasm")),
68    derive(ic_wire::typescript::Wire)
69)]
70pub enum SessionReadRefusal {
71    /// No live local session.
72    MissingOrExpired,
73    /// Protected authority is not ready.
74    AuthorityUnavailable,
75    /// The required scope is not granted.
76    ScopeRejected,
77    /// Revocation prevents use.
78    Revoked,
79    /// The read could not be completed.
80    Unavailable,
81}
82
83/// Existing unavailable-logout discriminants, in their fixed Wire order.
84#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
85#[cfg_attr(
86    all(feature = "typescript", not(target_family = "wasm")),
87    derive(ic_wire::typescript::Wire)
88)]
89pub enum LogoutUnavailable {
90    /// No capacity to retain the required denial.
91    Capacity,
92    /// Storage could not commit the denial.
93    Storage,
94    /// Trusted time could not support the operation.
95    Clock,
96    /// A reset is pending.
97    ResetPending,
98}
99
100/// Local logout result; no variant acknowledges logout at another receiver.
101#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
102#[cfg_attr(
103    all(feature = "typescript", not(target_family = "wasm")),
104    derive(ic_wire::typescript::Wire)
105)]
106pub enum LogoutResult {
107    /// Committed denial through this nanosecond deadline.
108    Revoked(u64),
109    /// Local denial deadline without confirmation of outstanding issuance.
110    Unconfirmed(u64),
111    /// The host-authenticated caller is not a valid logout identity.
112    InvalidCaller,
113    /// No revocation acknowledgement; issuance uncertainty must be retained.
114    Unavailable(LogoutUnavailable),
115}