aries_bbssignatures/
messages.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/// Creates the BTreeMap used for blind signing
#[macro_export]
macro_rules! sm_map {
    ($($index:expr => $data:expr),*) => {
        {
            let mut msgs = std::collections::BTreeMap::new();
            $(
                msgs.insert($index, crate::SignatureMessage::hash($data));
            )*
            msgs
        }
    };
}

/// Creates a proof message to be revealed
#[macro_export]
macro_rules! pm_revealed {
    ($data:expr) => {
        ProofMessage::Revealed(SignatureMessage::hash($data))
    };
}

/// Wrap a raw message in a revealed enum
#[macro_export]
macro_rules! pm_revealed_raw {
    ($data:expr) => {
        ProofMessage::Revealed($data)
    };
}

/// Creates a proof message that is hidden based on the number of parameters
/// One means hidden and only used in this proof
/// Two means hidden but can be used in other proofs
#[macro_export]
macro_rules! pm_hidden {
    ($data:expr) => {
        ProofMessage::Hidden(HiddenMessage::ProofSpecificBlinding(
            SignatureMessage::hash($data),
        ))
    };
    ($data:expr, $bf:expr) => {
        ProofMessage::Hidden(HiddenMessage::ExternalBlinding(
            SignatureMessage::hash($data),
            $bf,
        ))
    };
}

/// Wrap a raw message in its respective hidden
#[macro_export]
macro_rules! pm_hidden_raw {
    ($data:expr) => {
        ProofMessage::Hidden(HiddenMessage::ProofSpecificBlinding($data))
    };
    ($data:expr, $bf:expr) => {
        ProofMessage::Hidden(HiddenMessage::ExternalBlinding($data, $bf))
    };
}

use crate::{ProofNonce, SignatureMessage};

/// A message classification by the prover
pub enum ProofMessage {
    /// Message will be revealed to a verifier
    Revealed(SignatureMessage),
    /// Message will be hidden from a verifier
    Hidden(HiddenMessage),
}

impl ProofMessage {
    /// Extract the internal message
    pub fn get_message(&self) -> SignatureMessage {
        match *self {
            ProofMessage::Revealed(ref r) => *r,
            ProofMessage::Hidden(HiddenMessage::ProofSpecificBlinding(ref p)) => *p,
            ProofMessage::Hidden(HiddenMessage::ExternalBlinding(ref m, _)) => *m,
        }
    }
}

/// Two types of hidden messages
pub enum HiddenMessage {
    /// Indicates the message is hidden and no other work is involved
    ///     so a blinding factor will be generated specific to this proof
    ProofSpecificBlinding(SignatureMessage),
    /// Indicates the message is hidden but it is involved with other proofs
    ///     like boundchecks, set memberships or inequalities, so the blinding factor
    ///     is provided from an external source.
    ExternalBlinding(SignatureMessage, ProofNonce),
}