Skip to content

Commit

Permalink
Add function to create VerifiablePresentation from statement + context
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenbf committed Sep 24, 2024
1 parent 813e40e commit 5a1e92d
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 134 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ serde_json = "1.0"
rand = "0.8.5"
hex = { version = "0.4.3", features = ["serde"] }
derive_more = "0.99.18"
chrono = "0.4.24"

[dependencies.concordium_base]
path = "./concordium-base/rust-src/concordium_base"
Expand Down
22 changes: 11 additions & 11 deletions src/id_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use crate::{
/// attribute and prove that it is indeed the value inside the on-chain
/// commitment. Since the verifier does not know the attribute value before
/// seing the proof, the value is not present here.
#[derive(Serialize)]
pub struct RevealAttributeStatement<Tag: Serialize> {
#[derive(Serialize, Deserialize)]
pub struct RevealAttributeStatement<Tag> {
/// The attribute that the verifier wants the user to reveal.
#[serde(rename = "attributeTag")]
pub attribute_tag: Tag,
Expand All @@ -34,8 +34,8 @@ pub type RevealAttributeStatementV1 = RevealAttributeStatement<String>;
/// For the case where the verifier wants the user to prove that an attribute is
/// in a range. The statement is that the attribute value lies in `[lower,
/// upper)` in the scalar field.
#[derive(Serialize)]
pub struct AttributeInRangeStatement<Tag: Serialize, Value: Serialize> {
#[derive(Serialize, Deserialize)]
pub struct AttributeInRangeStatement<Tag, Value> {
/// The attribute that the verifier wants the user to prove is in a range.
#[serde(rename = "attributeTag")]
pub attribute_tag: Tag,
Expand All @@ -54,8 +54,8 @@ pub type AttributeInRangeStatementV1 = AttributeInRangeStatement<String, String>
/// in a set of attributes.
///
/// Serves as a uniFFI compatible bridge to [`concordium_base::id::id_proof_types::AttributeInSetStatement<ArCurve, AttributeTag, AttributeKind>`]
#[derive(Serialize)]
pub struct AttributeInSetStatement<Tag: Serialize, Value: Serialize> {
#[derive(Serialize, Deserialize)]
pub struct AttributeInSetStatement<Tag, Value> {
/// The attribute that the verifier wants the user prove lies in a set.
#[serde(rename = "attributeTag")]
pub attribute_tag: Tag,
Expand All @@ -71,8 +71,8 @@ pub type AttributeInSetStatementV1 = AttributeInSetStatement<String, String>;
/// not in a set of attributes.
///
/// Serves as a uniFFI compatible bridge to [`concordium_base::id::id_proof_types::AttributeNotInSetStatement<ArCurve, AttributeTag, AttributeKind>`]
#[derive(Serialize)]
pub struct AttributeNotInSetStatement<Tag: Serialize, Value: Serialize> {
#[derive(Serialize, Deserialize)]
pub struct AttributeNotInSetStatement<Tag, Value> {
/// The attribute that the verifier wants the user to prove does not lie in
/// a set.
#[serde(rename = "attributeTag")]
Expand All @@ -85,9 +85,9 @@ pub struct AttributeNotInSetStatement<Tag: Serialize, Value: Serialize> {
/// Serves as a uniFFI compatible bridge to [`concordium_base::id::id_proof_types::AttributeNotInSetStatement<ArCurve, AttributeTag, AttributeKind>`]
pub type AttributeNotInSetStatementV1 = AttributeNotInSetStatement<String, String>;

#[derive(Serialize)]
#[derive(Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum AtomicStatement<Tag: Serialize, Value: Serialize> {
pub enum AtomicStatement<Tag, Value> {
/// The atomic statement stating that an attribute should be revealed.
RevealAttribute {
#[serde(flatten)]
Expand Down Expand Up @@ -115,7 +115,7 @@ pub type AtomicStatementV1 = AtomicStatement<String, String>;

#[derive(Serialize)]
#[serde(transparent)]
pub struct Statement<Tag: Serialize, Value: Serialize> {
pub struct Statement<Tag, Value> {
pub statements: Vec<AtomicStatement<Tag, Value>>,
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl ConvertError for hex::FromHexError {}
/// This should generally be used instead of hex string representation as it takes up half the space when compared to storing strings
#[repr(transparent)]
#[derive(Debug, Serialize, Deserialize, derive_more::From, Clone, PartialEq)]
pub struct Bytes(#[serde(with = "hex")] Vec<u8>);
pub struct Bytes(#[serde(with = "hex")] pub Vec<u8>);

impl std::fmt::Display for Bytes {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down
Loading

0 comments on commit 5a1e92d

Please sign in to comment.