Skip to main content

dig_identity/
error.rs

1//! The crate's single error type.
2//!
3//! Every fallible public function returns [`Error`]; variants name the exact failure so a caller
4//! (or an agent reading a log) can branch on the cause without parsing a string.
5
6use thiserror::Error;
7
8/// A failure decoding a value, building/proving over the tree, or evaluating the pairing predicate.
9#[derive(Debug, Clone, Error, PartialEq, Eq)]
10pub enum Error {
11    /// A value blob was shorter than its declared header or length prefix.
12    #[error("value encoding is truncated: {0}")]
13    TruncatedValue(&'static str),
14
15    /// A value's declared length did not match the bytes that followed it.
16    #[error("value length prefix ({declared}) does not match the {actual} bytes present")]
17    LengthMismatch {
18        /// The length written in the 4-byte big-endian prefix.
19        declared: usize,
20        /// The number of payload bytes actually present.
21        actual: usize,
22    },
23
24    /// A value blob carried a tag byte this version does not define.
25    #[error("unknown value tag 0x{0:02x}")]
26    UnknownTag(u8),
27
28    /// A fixed-width value (u16/u32/u64) carried the wrong number of payload bytes.
29    #[error("fixed-width value for tag 0x{tag:02x} expected {expected} bytes, got {actual}")]
30    WrongWidth {
31        /// The value tag whose width was violated.
32        tag: u8,
33        /// The exact payload width the tag mandates.
34        expected: usize,
35        /// The payload width actually present.
36        actual: usize,
37    },
38
39    /// The underlying sparse-merkle-tree rejected an update or proof operation.
40    #[error("sparse-merkle-tree error: {0}")]
41    Smt(String),
42
43    /// A composed profile-field verification was declined because the supplied store is NOT the
44    /// DID's authoritative profile (the DID↔store pairing predicate failed — see [`crate::pairing`]).
45    #[error("store is not the DID's authoritative profile (pairing predicate failed)")]
46    NotAuthoritativeProfile,
47
48    /// A composed profile-field verification was declined because the merkle proof did not verify
49    /// the claimed value (or absence) against the supplied profile root.
50    #[error("profile-field merkle proof did not verify against the profile root")]
51    FieldProofRejected,
52
53    /// `IdentityProfile::mint_from_did` is not yet implemented. Minting is GATED on the dig-store
54    /// crate (#703/#754) and the WU3 chain layer (#778); dig-identity MUST NOT depend on dig-store
55    /// (the dependency graph stays acyclic), so the launch driver lands as a WU2 follow-on — not
56    /// here. The signature exists now so consumers code against the primitive's final shape.
57    #[error(
58        "IdentityProfile::mint_from_did is not yet implemented          (gated on the dig-store crate and the WU3 chain layer)"
59    )]
60    MintNotYetImplemented,
61}
62
63/// A `Result` specialized to this crate's [`Error`].
64pub type Result<T> = core::result::Result<T, Error>;