Skip to content

Commit

Permalink
Merge pull request #78 from evannetwork/feature/use-experimental-bbs
Browse files Browse the repository at this point in the history
Use experimental vade-evan-bbs
  • Loading branch information
S3bb1 authored Jul 10, 2023
2 parents 0216b5f + 64c2c1f commit 8a11cf3
Show file tree
Hide file tree
Showing 10 changed files with 447 additions and 37 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vade-evan"
version = "0.6.0-rc.2"
version = "0.6.0-rc.3"
authors = ["evan GmbH"]
edition = "2018"
license-file = "LICENSE.txt"
Expand All @@ -26,7 +26,7 @@ required-features = ["target-cli"]
wasm-opt = ["-Oz", "--enable-mutable-globals"]

[features]
default = ["did-sidetree", "did-substrate", "didcomm", "jwt-vc", "vc-zkp-bbs", "cli"]
default = ["did-sidetree", "did-substrate", "didcomm", "jwt-vc", "vc-zkp-bbs", "target-cli"]

did-sidetree = ["base64", "did-read", "did-write", "vade-sidetree", "uuid"]

Expand Down Expand Up @@ -62,7 +62,7 @@ target-c-sdk = ["c-lib", "vade-sidetree/sdk", "didcomm", "did-sidetree", "did-su
target-c-lib = ["c-lib", "default"]

# build for command line usage
target-cli = ["default"]
target-cli = ["cli"]

# build for consuming vade-evan from Java
target-java-lib = ["c-lib", "default"]
Expand All @@ -78,7 +78,7 @@ jni = "0.19.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.53", features = ["preserve_order", "raw_value"] }
thiserror = "1.0.38"
vade = "0.1.0"
vade = "0.1.1"
chrono = "0.4.23"

###################################################################### feature specific dependencies
Expand Down Expand Up @@ -147,7 +147,7 @@ optional = true

[dependencies.vade-evan-bbs]
git = "https://github.com/evannetwork/vade-evan-bbs.git"
branch = "develop"
branch = "experimental/develop-next"
optional = true
default-features = false

Expand Down
2 changes: 2 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Features

- add support for `vc_zkp_propose_proof` function in `vade-evan-bbs` plugin

### Fixes

### Deprecation
Expand Down
151 changes: 143 additions & 8 deletions src/api/vade_evan_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use vade::Vade;
use crate::helpers::Credential;
#[cfg(feature = "did-sidetree")]
use crate::helpers::Did;
#[cfg(all(feature = "vc-zkp-bbs", feature = "did-sidetree"))]
use crate::helpers::Presentation;
#[cfg(all(feature = "c-lib", feature = "target-c-sdk"))]
use crate::in3_request_list::ResolveHttpRequest;
use crate::{
Expand Down Expand Up @@ -494,6 +496,107 @@ impl VadeEvan {
.map_err(|err| err.into())
}

/// Proposes to share a proof for a credential.
/// The proof proposal consists of the fields the prover wants to reveal per schema.
///
/// # Arguments
///
/// * `schema_did` - DID of schema to propose proof for
/// * `revealed_attributes` - list of names of revealed attributes in specified schema, reveals all if omitted
///
/// # Returns
/// * `Option<String>` - A `ProofProposal` as JSON
///
/// # Example
///
/// ```
/// cfg_if::cfg_if! {
/// if #[cfg(not(all(feature = "c-lib", feature = "target-c-sdk")))] {
/// use anyhow::Result;
/// use vade_evan::{VadeEvan, VadeEvanConfig, DEFAULT_TARGET, DEFAULT_SIGNER};
///
/// async fn example() -> Result<()> {
/// let mut vade_evan = VadeEvan::new(VadeEvanConfig { target: DEFAULT_TARGET, signer: DEFAULT_SIGNER })?;
/// let schema_did = "did:evan:EiBrPL8Yif5NWHOzbKvyh1PX1wKVlWvIa6nTG1v8PXytvg";
/// let revealed_attributes = Some(r#"["zip", "country"]"#);
///
/// vade_evan
/// .helper_create_proof_proposal(schema_did, revealed_attributes)
/// .await?;
///
/// Ok(())
/// }
/// } else {
/// // currently no example for target-c-sdk and c-lib/target-java-lib
/// }
/// }
#[cfg(all(feature = "vc-zkp-bbs", feature = "did-sidetree"))]
pub async fn helper_create_proof_proposal(
&mut self,
schema_did: &str,
revealed_attributes: Option<&str>,
) -> Result<String, VadeEvanError> {
let mut presentation_helper = Presentation::new(self)?;
presentation_helper
.create_proof_proposal(schema_did, revealed_attributes)
.await
.map_err(|err| err.into())
}

/// Requests a proof for a credential by providing a proof proposal.
/// The proof request consists of the fields the verifier wants to be revealed per schema.
///
/// # Arguments
///
/// * `proof_proposal` - proof proposal to use to generate a proof request from
///
/// # Returns
/// * `Option<String>` - A `ProofRequest` as JSON
///
/// # Example
///
/// ```
/// cfg_if::cfg_if! {
/// if #[cfg(not(all(feature = "c-lib", feature = "target-c-sdk")))] {
/// use anyhow::Result;
/// use vade_evan::{VadeEvan, VadeEvanConfig, DEFAULT_TARGET, DEFAULT_SIGNER};
///
/// async fn example() -> Result<()> {
/// let mut vade_evan = VadeEvan::new(VadeEvanConfig { target: DEFAULT_TARGET, signer: DEFAULT_SIGNER })?;
///
/// let proposal = r###"{
/// "verifier": "verifier",
/// "createdAt": "createdAt",
/// "nonce": "nonce",
/// "type": "BBS",
/// "subProofRequests": [{
/// "schema": "did:evan:EiBrPL8Yif5NWHOzbKvyh1PX1wKVlWvIa6nTG1v8PXytvg",
/// "revealedAttributes": [13, 15]
/// }]
/// }"###;
///
/// vade_evan
/// .helper_create_proof_request_from_proposal(proposal)
/// .await?;
///
/// Ok(())
/// }
/// } else {
/// // currently no example for target-c-sdk and c-lib/target-java-lib
/// }
/// }
#[cfg(all(feature = "vc-zkp-bbs", feature = "did-sidetree"))]
pub async fn helper_create_proof_request_from_proposal(
&mut self,
proof_proposal: &str,
) -> Result<String, VadeEvanError> {
let mut presentation_helper = Presentation::new(self)?;
presentation_helper
.create_proof_request_from_proposal(proof_proposal)
.await
.map_err(|err| err.into())
}

/// Requests a proof for a credential.
/// The proof request consists of the fields the verifier wants to be revealed per schema.
///
Expand Down Expand Up @@ -534,8 +637,6 @@ impl VadeEvan {
schema_did: &str,
revealed_attributes: Option<&str>,
) -> Result<String, VadeEvanError> {
use crate::helpers::Presentation;

let mut presentation_helper = Presentation::new(self)?;
presentation_helper
.create_proof_request(schema_did, revealed_attributes)
Expand Down Expand Up @@ -639,8 +740,6 @@ impl VadeEvan {
prover_did: &str,
revealed_attributes: Option<&str>,
) -> Result<String, VadeEvanError> {
use crate::helpers::Presentation;

let mut presentation_helper = Presentation::new(self)?;
presentation_helper
.create_presentation(
Expand Down Expand Up @@ -719,8 +818,6 @@ impl VadeEvan {
&mut self,
unsigned_credential_str: &str,
) -> Result<String, VadeEvanError> {
use crate::helpers::Presentation;

let mut presentation_helper = Presentation::new(self)?;
presentation_helper
.create_self_issued_presentation(unsigned_credential_str)
Expand Down Expand Up @@ -818,8 +915,6 @@ impl VadeEvan {
presentation_str: &str,
proof_request_str: &str,
) -> Result<String, VadeEvanError> {
use crate::helpers::Presentation;

let mut presentation_helper = Presentation::new(self)?;
presentation_helper
.verify_presentation(presentation_str, proof_request_str)
Expand Down Expand Up @@ -1355,6 +1450,46 @@ impl VadeEvan {
)
}

/// Proposes a zero-knowledge proof for one or more credentials issued under one or more specific schemas.
///
/// # Arguments
///
/// * `method` - method to propose a proof for (e.g. "did:example")
/// * `options` - JSON string with additional information supporting the proposal (e.g. authentication data)
/// * `payload` - JSON string with information for the proposal (e.g. actual data to write)
///
/// # Example
///
/// ```
/// cfg_if::cfg_if! {
/// if #[cfg(not(all(feature = "c-lib", feature = "target-c-sdk")))] {
/// use anyhow::Result;
/// use vade_evan::{VadeEvan, VadeEvanConfig, DEFAULT_TARGET, DEFAULT_SIGNER};
///
/// async fn example() -> Result<()> {
/// let mut vade_evan = VadeEvan::new(VadeEvanConfig { target: DEFAULT_TARGET, signer: DEFAULT_SIGNER })?;
/// let result = vade_evan.vc_zkp_propose_proof("did:example", "", "").await?;
/// println!("created proof proposal: {}", result);
/// Ok(())
/// }
/// } else {
/// // currently no example for target-c-sdk and c-lib/target-java-lib
/// }
/// }
/// ```
pub async fn vc_zkp_propose_proof(
&mut self,
method: &str,
options: &str,
payload: &str,
) -> Result<String, VadeEvanError> {
get_first_result(
self.vade
.vc_zkp_propose_proof(method, options, payload)
.await?,
)
}

/// Presents a proof for a zero-knowledge proof credential. A proof presentation is the response to a
/// proof request.
///
Expand Down
49 changes: 47 additions & 2 deletions src/c_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,20 @@ pub extern "C" fn execute_vade(
)
}),
#[cfg(any(feature = "vc-zkp-bbs"))]
"vc_zkp_propose_proof" => runtime.block_on({
execute_vade_function!(
vc_zkp_propose_proof,
arguments_vec.get(0).unwrap_or_else(|| &no_args),
&str_options,
arguments_vec.get(1).unwrap_or_else(|| &no_args),
str_config,
#[cfg(all(feature = "c-lib", feature = "target-c-sdk"))]
ptr_request_list,
#[cfg(all(feature = "c-lib", feature = "target-c-sdk"))]
request_function_callback
)
}),
#[cfg(any(feature = "vc-zkp-bbs"))]
"vc_zkp_request_proof" => runtime.block_on({
execute_vade_function!(
vc_zkp_request_proof,
Expand Down Expand Up @@ -643,7 +657,7 @@ pub extern "C" fn execute_vade(
}
}),
#[cfg(all(feature = "vc-zkp-bbs", feature = "did-sidetree"))]
"helper_create_proof_request" => runtime.block_on({
"helper_create_proof_proposal" => runtime.block_on({
async {
let mut vade_evan = get_vade_evan(
Some(&str_config),
Expand All @@ -653,8 +667,9 @@ pub extern "C" fn execute_vade(
request_function_callback,
)
.map_err(stringify_generic_error)?;

vade_evan
.helper_create_proof_request(
.helper_create_proof_proposal(
arguments_vec.get(0).unwrap_or_else(|| &no_args),
arguments_vec.get(1).map(|v| v.as_str()),
)
Expand All @@ -663,6 +678,36 @@ pub extern "C" fn execute_vade(
}
}),
#[cfg(all(feature = "vc-zkp-bbs", feature = "did-sidetree"))]
"helper_create_proof_request" => runtime.block_on({
async {
let mut vade_evan = get_vade_evan(
Some(&str_config),
#[cfg(all(feature = "c-lib", feature = "target-c-sdk"))]
ptr_request_list,
#[cfg(all(feature = "c-lib", feature = "target-c-sdk"))]
request_function_callback,
)
.map_err(stringify_generic_error)?;

let first_arg = arguments_vec.get(0).unwrap_or_else(|| &no_args);
match first_arg.starts_with("did:") {
// first arg starts with "did:", assume it's a schema
true => vade_evan
.helper_create_proof_request(
first_arg,
arguments_vec.get(1).map(|v| v.as_str()),
)
.await
.map_err(stringify_vade_evan_error),
// else assume it's a proposal
false => vade_evan
.helper_create_proof_request_from_proposal(first_arg)
.await
.map_err(stringify_vade_evan_error),
}
}
}),
#[cfg(all(feature = "vc-zkp-bbs", feature = "did-sidetree"))]
"helper_create_presentation" => runtime.block_on({
async {
let mut vade_evan = get_vade_evan(
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ mod tests {
.await?;
let did_create_result: DidCreateResponse = serde_json::from_str(&did_create_result)?;
let mut credential: BbsCredential = serde_json::from_str(CREDENTIAL_ACTIVE)?;
let mut credential_status = credential.credential_status.ok_or_else(|| {
let credential_status = &mut credential.credential_status.ok_or_else(|| {
CredentialError::InvalidCredentialStatus(
"Error in parsing credential_status".to_string(),
)
Expand Down
Loading

0 comments on commit 8a11cf3

Please sign in to comment.