Skip to content

Commit

Permalink
Merge pull request #30 from andrewwhitehead/replace-ursa
Browse files Browse the repository at this point in the history
Switch from Ursa to anoncreds-clsignatures
  • Loading branch information
swcurran authored Jul 11, 2023
2 parents f2396c6 + 0bed50a commit a87baee
Show file tree
Hide file tree
Showing 31 changed files with 394 additions and 345 deletions.
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

Shared Rust libraries for Hyperledger Indy.

- `indy-credx`: Indy verifiable credential issuance and presentation (aka Anoncreds)
- `indy-credx`: Indy verifiable credential issuance and presentation (aka Anoncreds).

- `indy-data-types`: Data type definitions for Schemas, Credential Definitions and other
types related to credential issuance and processing
- `indy-data-types`: Data type definitions for Schemas, Credential Definitions and other types related to credential issuance and processing.

- `indy-test-utils`: Utilities for use in integration tests.

- `indy-utils`: Standard wrappers around binary data encodings and Ursa-provided
cryptography functions. Includes support for representing WQL (wallet query
language) expressions, normalizing transactions for signing, deriving DIDs and
verification keys, and packing and unpacking agent messages using the DIDComm
v1 envelope format.
- `indy-utils`: Standard wrappers around binary data encodings. Includes support for normalizing transactions for signing, deriving DIDs and verification keys.

## Credit

Expand Down
16 changes: 8 additions & 8 deletions indy-credx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "indy-credx"
version = "0.3.3"
version = "0.4.0"
authors = ["Hyperledger Indy Contributors <[email protected]>"]
description = "Verifiable credential issuance and presentation for Hyperledger Indy (https://www.hyperledger.org/projects), which provides a distributed-ledger-based foundation for self-sovereign identity (https://sovrin.org)."
edition = "2018"
edition = "2021"
license = "Apache-2.0"
readme = "../README.md"
repository = "https://github.com/hyperledger/indy-shared-rs/"
Expand All @@ -26,17 +26,17 @@ vendored = ["indy-data-types/vendored"]
env_logger = { version = "0.10", optional = true }
ffi-support = { version = "0.4.0", optional = true }
log = "0.4"
once_cell = "1.9"
rand = "0.7"
regex = "1.2.1"
once_cell = "1"
rand = "0.8"
regex = "1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha2 = "0.9"
sha2 = "0.10"
thiserror = "1.0"
zeroize = { version = "1.3", optional = true }
zeroize = { version = "1", optional = true }

[dependencies.indy-data-types]
version = "0.5.2"
version = "0.6"
path = "../indy-data-types"
features = ["cl_native"]

Expand Down
17 changes: 5 additions & 12 deletions indy-credx/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::error::Error as StdError;
use std::fmt::{self, Display, Formatter};
use std::result::Result as StdResult;

use crate::ursa::errors::{UrsaCryptoError, UrsaCryptoErrorKind};
use crate::anoncreds_clsignatures::{Error as ClError, ErrorKind as ClErrorKind};

pub type Result<T> = std::result::Result<T, Error>;

Expand Down Expand Up @@ -135,19 +135,12 @@ impl From<serde_json::Error> for Error {
}
}

impl From<UrsaCryptoError> for Error {
fn from(err: UrsaCryptoError) -> Self {
// let message = format!("Ursa Crypto Error: {}", Fail::iter_causes(&err).map(|e| e.to_string()).collect::<String>());
impl From<ClError> for Error {
fn from(err: ClError) -> Self {
let message = err.to_string();
let kind = match err.kind() {
UrsaCryptoErrorKind::InvalidState => ErrorKind::InvalidState,
UrsaCryptoErrorKind::InvalidStructure => ErrorKind::Input,
UrsaCryptoErrorKind::IOError => ErrorKind::IOError,
UrsaCryptoErrorKind::InvalidRevocationAccumulatorIndex => ErrorKind::InvalidUserRevocId,
UrsaCryptoErrorKind::RevocationAccumulatorIsFull => ErrorKind::RevocationRegistryFull,
UrsaCryptoErrorKind::ProofRejected => ErrorKind::ProofRejected,
UrsaCryptoErrorKind::CredentialRevoked => ErrorKind::CredentialRevoked,
UrsaCryptoErrorKind::InvalidParam(_) => ErrorKind::Input,
ClErrorKind::InvalidState => ErrorKind::InvalidState,
ClErrorKind::ProofRejected => ErrorKind::ProofRejected,
};
Error::from_msg(kind, message)
}
Expand Down
10 changes: 0 additions & 10 deletions indy-credx/src/ffi/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::error::Result;
use crate::services::{
issuer::create_credential,
prover::process_credential,
tails::TailsFileReader,
types::{Credential, CredentialRevocationConfig, MakeCredentialValues},
utils::encode_credential_attribute,
};
Expand All @@ -25,7 +24,6 @@ pub struct FfiCredRevInfo<'a> {
registry: ObjectHandle,
reg_idx: i64,
reg_used: FfiList<'a, i64>,
tails_path: FfiStr<'a>,
}

struct RevocationConfig {
Expand All @@ -34,7 +32,6 @@ struct RevocationConfig {
registry: IndyObject,
reg_idx: u32,
reg_used: HashSet<u32>,
tails_path: String,
}

impl RevocationConfig {
Expand All @@ -45,7 +42,6 @@ impl RevocationConfig {
registry: self.registry.cast_ref()?,
registry_idx: self.reg_idx,
registry_used: &self.reg_used,
tails_reader: TailsFileReader::new(self.tails_path.as_str()),
})
}
}
Expand Down Expand Up @@ -104,11 +100,6 @@ pub extern "C" fn credx_create_credential(
}
let revocation_config = if !revocation.is_null() {
let revocation = unsafe { &*revocation };
let tails_path = revocation
.tails_path
.as_opt_str()
.ok_or_else(|| err_msg!("Missing tails file path"))?
.to_string();
let mut reg_used = HashSet::new();
for reg_idx in revocation.reg_used.as_slice() {
reg_used.insert(
Expand All @@ -126,7 +117,6 @@ pub extern "C" fn credx_create_credential(
.try_into()
.map_err(|_| err_msg!("Invalid revocation index"))?,
reg_used,
tails_path,
})
} else {
None
Expand Down
49 changes: 47 additions & 2 deletions indy-credx/src/ffi/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::error::Result;
use crate::services::{
prover::create_presentation,
types::{PresentCredentials, Presentation, RevocationRegistryDefinition},
verifier::verify_presentation,
verifier::_verify_presentation,
};

impl_indy_object!(Presentation, "Presentation");
Expand Down Expand Up @@ -193,6 +193,50 @@ pub extern "C" fn credx_verify_presentation(
rev_reg_defs: FfiList<ObjectHandle>,
rev_reg_entries: FfiList<FfiRevocationEntry>,
result_p: *mut i8,
) -> ErrorCode {
_credx_verify_presentation(
presentation,
pres_req,
schemas,
cred_defs,
rev_reg_defs,
rev_reg_entries,
false,
result_p,
)
}

#[no_mangle]
pub extern "C" fn credx_verify_presentation_legacy(
presentation: ObjectHandle,
pres_req: ObjectHandle,
schemas: FfiList<ObjectHandle>,
cred_defs: FfiList<ObjectHandle>,
rev_reg_defs: FfiList<ObjectHandle>,
rev_reg_entries: FfiList<FfiRevocationEntry>,
result_p: *mut i8,
) -> ErrorCode {
_credx_verify_presentation(
presentation,
pres_req,
schemas,
cred_defs,
rev_reg_defs,
rev_reg_entries,
true,
result_p,
)
}

fn _credx_verify_presentation(
presentation: ObjectHandle,
pres_req: ObjectHandle,
schemas: FfiList<ObjectHandle>,
cred_defs: FfiList<ObjectHandle>,
rev_reg_defs: FfiList<ObjectHandle>,
rev_reg_entries: FfiList<FfiRevocationEntry>,
accept_legacy_revocation: bool,
result_p: *mut i8,
) -> ErrorCode {
catch_error(|| {
let schemas = IndyObjectList::load(schemas.as_slice())?;
Expand Down Expand Up @@ -221,13 +265,14 @@ pub extern "C" fn credx_verify_presentation(
.or_insert_with(HashMap::new)
.insert(*timestamp, entry.cast_ref()?);
}
let verify = verify_presentation(
let verify = _verify_presentation(
presentation.load()?.cast_ref()?,
pres_req.load()?.cast_ref()?,
&schemas.refs_map()?,
&cred_defs.refs_map()?,
Some(&rev_reg_defs.refs_map()?),
Some(&rev_regs),
accept_legacy_revocation,
)?;
unsafe { *result_p = verify as i8 };
Ok(())
Expand Down
22 changes: 8 additions & 14 deletions indy-credx/src/ffi/revocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ pub extern "C" fn credx_create_revocation_registry(

#[no_mangle]
pub extern "C" fn credx_update_revocation_registry(
cred_def: ObjectHandle,
rev_reg_def: ObjectHandle,
rev_reg_def_priv: ObjectHandle,
rev_reg: ObjectHandle,
issued: FfiList<i64>,
revoked: FfiList<i64>,
tails_path: FfiStr,
rev_reg_p: *mut ObjectHandle,
rev_reg_delta_p: *mut ObjectHandle,
) -> ErrorCode {
Expand All @@ -100,17 +101,13 @@ pub extern "C" fn credx_update_revocation_registry(
check_useful_c_ptr!(rev_reg_delta_p);
let issued = registry_indices_to_set(issued.as_slice().into_iter().cloned())?;
let revoked = registry_indices_to_set(revoked.as_slice().into_iter().cloned())?;
let tails_reader = TailsFileReader::new(
tails_path
.as_opt_str()
.ok_or_else(|| err_msg!("Missing tails file path"))?,
);
let (rev_reg, rev_reg_delta) = update_revocation_registry(
cred_def.load()?.cast_ref()?,
rev_reg_def.load()?.cast_ref()?,
rev_reg_def_priv.load()?.cast_ref()?,
rev_reg.load()?.cast_ref()?,
issued,
revoked,
&tails_reader,
)?;
let rev_reg = ObjectHandle::create(rev_reg)?;
let rev_reg_delta = ObjectHandle::create(rev_reg_delta)?;
Expand All @@ -124,28 +121,25 @@ pub extern "C" fn credx_update_revocation_registry(

#[no_mangle]
pub extern "C" fn credx_revoke_credential(
cred_def: ObjectHandle,
rev_reg_def: ObjectHandle,
rev_reg_def_priv: ObjectHandle,
rev_reg: ObjectHandle,
cred_rev_idx: i64,
tails_path: FfiStr,
rev_reg_p: *mut ObjectHandle,
rev_reg_delta_p: *mut ObjectHandle,
) -> ErrorCode {
catch_error(|| {
check_useful_c_ptr!(rev_reg_p);
check_useful_c_ptr!(rev_reg_delta_p);
let tails_reader = TailsFileReader::new(
tails_path
.as_opt_str()
.ok_or_else(|| err_msg!("Missing tails file path"))?,
);
let (rev_reg, rev_reg_delta) = revoke_credential(
cred_def.load()?.cast_ref()?,
rev_reg_def.load()?.cast_ref()?,
rev_reg_def_priv.load()?.cast_ref()?,
rev_reg.load()?.cast_ref()?,
cred_rev_idx
.try_into()
.map_err(|_| err_msg!("Invalid registry index"))?,
&tails_reader,
)?;
let rev_reg = ObjectHandle::create(rev_reg)?;
let rev_reg_delta = ObjectHandle::create(rev_reg_delta)?;
Expand Down
2 changes: 1 addition & 1 deletion indy-credx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate log;
extern crate serde;

#[doc(hidden)]
pub use indy_data_types::ursa;
pub use indy_data_types::anoncreds_clsignatures;

#[macro_use]
mod error;
Expand Down
Loading

0 comments on commit a87baee

Please sign in to comment.