Skip to main content

ic_auth_wire/model/
mod.rs

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