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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
mod assignments;
#[macro_use]
pub mod data;
mod conceal;
mod metadata;
pub mod nodes;
pub mod reveal;
mod rights;
pub mod seal;
pub mod value;
pub mod attachment;
pub(self) use assignments::EMPTY_ASSIGNMENTS;
pub use assignments::{
Assignment, AttachmentStrategy, ConfidentialState, DeclarativeStrategy, EndpointValueMap,
HashStrategy, PedersenStrategy, RevealedState, SealValueMap, State, StateType,
TypedAssignments,
};
pub use attachment::AttachmentId;
pub use conceal::{ConcealSeals, ConcealState};
pub use metadata::Metadata;
pub use nodes::{ContractId, Extension, Genesis, Node, NodeId, NodeOutpoint, Transition};
use once_cell::sync::Lazy;
pub use reveal::{MergeReveal, RevealSeals};
pub use rights::{OwnedRights, ParentOwnedRights, ParentPublicRights, PublicRights};
pub(crate) use rights::{OwnedRightsInner, PublicRightsInner};
pub use seal::{IntoRevealedSeal, SealEndpoint};
use secp256k1zkp::Secp256k1 as Secp256k1zkp;
pub use value::{AtomicValue, HomomorphicBulletproofGrin};
pub(crate) static SECP256K1_ZKP: Lazy<Secp256k1zkp> =
Lazy::new(|| Secp256k1zkp::with_caps(secp256k1zkp::ContextFlag::Commit));
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display, Error, From)]
#[display(doc_comments)]
pub enum StateRetrievalError {
StateTypeMismatch,
#[from(ConfidentialDataError)]
ConfidentialData,
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display, Error)]
#[display(doc_comments)]
pub struct NoDataError;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display, Error)]
#[display(doc_comments)]
pub struct ConfidentialDataError;
#[cfg(test)]
pub(crate) mod test {
use commit_verify::{CommitConceal, CommitEncode};
use strict_encoding::{StrictDecode, StrictEncode};
pub fn test_confidential<T>(data: &[u8], encoded: &[u8], commitment: &[u8])
where
T: CommitConceal + StrictDecode + StrictEncode + Clone + CommitEncode,
<T as CommitConceal>::ConcealedCommitment: StrictDecode + StrictEncode + Eq,
{
let revealed = T::strict_decode(data).unwrap();
let confidential = revealed.commit_conceal();
let mut confidential_encoded = vec![];
confidential
.strict_encode(&mut confidential_encoded)
.unwrap();
let mut revealed_encoded: Vec<u8> = vec![];
revealed.strict_encode(&mut revealed_encoded).unwrap();
assert_eq!(encoded, &confidential_encoded[..]);
assert_ne!(confidential_encoded.to_vec(), revealed_encoded);
let mut commit_encoded_revealed = vec![];
revealed.clone().commit_encode(&mut commit_encoded_revealed);
if encoded == commitment {
assert_eq!(commit_encoded_revealed, confidential_encoded);
} else {
assert_ne!(commit_encoded_revealed, confidential_encoded);
}
assert_eq!(commit_encoded_revealed, commitment);
}
}