ssi_data_integrity_core/suite/
sd.rs

1use ssi_verification_methods::VerificationMethodResolutionError;
2
3use crate::{CryptographicSuite, DataIntegrity, ProofRef};
4
5#[derive(Debug, thiserror::Error)]
6pub enum SelectionError {
7    #[error("missing proof")]
8    MissingProof,
9
10    #[error("ambiguous proof")]
11    AmbiguousProof,
12
13    #[error(transparent)]
14    VerificationMethodResolution(#[from] VerificationMethodResolutionError),
15
16    #[error("proof derivation failed: {0}")]
17    ProofDerivation(String),
18
19    #[error("non-selective cryptographic suite")]
20    NonSelectiveSuite,
21}
22
23impl SelectionError {
24    pub fn proof_derivation(e: impl ToString) -> Self {
25        Self::ProofDerivation(e.to_string())
26    }
27}
28
29/// Cryptographic suite with selective disclosure capabilities.
30pub trait SelectiveCryptographicSuite: CryptographicSuite {
31    /// Options specifying what claims to select and how.
32    type SelectionOptions;
33}
34
35/// Cryptographic suite with selective disclosure capabilities on a given type
36/// `T`.
37///
38/// Provides the `select` method on the cryptosuite.
39pub trait CryptographicSuiteSelect<T, P>: SelectiveCryptographicSuite {
40    /// Select a subset of claims to disclose.
41    #[allow(async_fn_in_trait)]
42    async fn select(
43        &self,
44        unsecured_document: &T,
45        proof: ProofRef<'_, Self>,
46        params: P,
47        options: Self::SelectionOptions,
48    ) -> Result<DataIntegrity<ssi_json_ld::syntax::Object, Self>, SelectionError>;
49}