ssi_data_integrity_core/proof/
reference.rs

1use std::collections::BTreeMap;
2
3use ssi_core::Lexical;
4use ssi_verification_methods::{ProofPurpose, ReferenceOrOwnedRef};
5
6use crate::{CryptographicSuite, ProofConfigurationRef};
7
8pub struct ProofRef<'a, S: CryptographicSuite> {
9    pub context: Option<&'a ssi_json_ld::syntax::Context>,
10
11    pub type_: &'a S,
12
13    pub created: Option<&'a Lexical<xsd_types::DateTimeStamp>>,
14
15    pub verification_method: ReferenceOrOwnedRef<'a, S::VerificationMethod>,
16
17    pub proof_purpose: ProofPurpose,
18
19    pub expires: Option<&'a Lexical<xsd_types::DateTimeStamp>>,
20
21    pub domains: &'a [String],
22
23    pub challenge: Option<&'a str>,
24
25    pub nonce: Option<&'a str>,
26
27    pub options: &'a S::ProofOptions,
28
29    pub signature: &'a S::Signature,
30
31    pub extra_properties: &'a BTreeMap<String, json_syntax::Value>,
32}
33
34impl<'a, S: CryptographicSuite> ProofRef<'a, S> {
35    pub fn configuration(&self) -> ProofConfigurationRef<'a, S> {
36        ProofConfigurationRef {
37            context: self.context,
38            type_: self.type_,
39            created: self.created,
40            verification_method: self.verification_method,
41            proof_purpose: self.proof_purpose,
42            expires: self.expires,
43            domains: self.domains,
44            challenge: self.challenge,
45            nonce: self.nonce,
46            options: self.options,
47            extra_properties: self.extra_properties,
48        }
49    }
50
51    pub fn map<T: CryptographicSuite>(
52        self,
53        map_type: impl FnOnce(&'a S) -> &'a T,
54        map_verification_method: impl FnOnce(&'a S::VerificationMethod) -> &'a T::VerificationMethod,
55        map_options: impl FnOnce(&'a S::ProofOptions) -> &'a T::ProofOptions,
56        map_signature: impl FnOnce(&'a S::Signature) -> &'a T::Signature,
57    ) -> ProofRef<'a, T> {
58        ProofRef {
59            context: self.context,
60            type_: map_type(self.type_),
61            created: self.created,
62            verification_method: self.verification_method.map(map_verification_method),
63            proof_purpose: self.proof_purpose,
64            expires: self.expires,
65            domains: self.domains,
66            challenge: self.challenge,
67            nonce: self.nonce,
68            options: map_options(self.options),
69            signature: map_signature(self.signature),
70            extra_properties: self.extra_properties,
71        }
72    }
73}