Skip to content

Commit 32a1943

Browse files
Merge pull request #33 from andrewwhitehead/upd/cl-0.2
Update to anoncreds-clsignatures 0.2, lighten indy-utils
2 parents 8f51b31 + 5c1f313 commit 32a1943

File tree

15 files changed

+95
-263
lines changed

15 files changed

+95
-263
lines changed

indy-credx/Cargo.toml

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "indy-credx"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
authors = ["Hyperledger Indy Contributors <[email protected]>"]
55
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)."
66
edition = "2021"
@@ -25,6 +25,10 @@ vendored = ["indy-data-types/vendored"]
2525
[dependencies]
2626
env_logger = { version = "0.10", optional = true }
2727
ffi-support = { version = "0.4.0", optional = true }
28+
indy-data-types = { version = "0.6.1", features = [
29+
"cl_native",
30+
], path = "../indy-data-types" }
31+
indy-utils = { version = "0.6.0", default-features = false, path = "../indy-utils" }
2832
log = "0.4"
2933
once_cell = "1"
3034
rand = "0.8"
@@ -34,13 +38,3 @@ serde_json = "1.0"
3438
sha2 = "0.10"
3539
thiserror = "1.0"
3640
zeroize = { version = "1", optional = true }
37-
38-
[dependencies.indy-data-types]
39-
version = "0.6"
40-
path = "../indy-data-types"
41-
features = ["cl_native"]
42-
43-
[dependencies.indy-utils]
44-
version = "0.5"
45-
path = "../indy-utils"
46-
default-features = false

indy-credx/src/services/helpers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use indy_data_types::anoncreds::{
88

99
use crate::anoncreds_clsignatures::{
1010
hash_credential_attribute, CredentialSchema, CredentialValues as ClCredentialValues,
11-
Issuer as ClIssuer, MasterSecret as ClMasterSecret, NonCredentialSchema, SubProofRequest,
11+
Issuer as ClIssuer, LinkSecret as ClLinkSecret, NonCredentialSchema, SubProofRequest,
1212
Verifier as ClVerifier,
1313
};
1414
use crate::error::Result;
@@ -45,7 +45,7 @@ pub fn build_non_credential_schema() -> Result<NonCredentialSchema> {
4545

4646
pub fn build_credential_values(
4747
credential_values: &HashMap<String, AttributeValues>,
48-
link_secret: Option<&ClMasterSecret>,
48+
link_secret: Option<&ClLinkSecret>,
4949
) -> Result<ClCredentialValues> {
5050
trace!(
5151
"build_credential_values >>> credential_values: {:?}",

indy-data-types/Cargo.toml

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "indy-data-types"
3-
version = "0.6.0"
3+
version = "0.6.1"
44
authors = ["Hyperledger Indy Contributors <[email protected]>"]
55
description = "Common data types for Hyperledger Indy (https://www.hyperledger.org/projects), which provides a distributed-ledger-based foundation for self-sovereign identity (https://sovrin.org)."
66
edition = "2021"
@@ -16,28 +16,31 @@ path = "src/lib.rs"
1616
crate-type = ["rlib"]
1717

1818
[features]
19-
default = ["serde_support", "cl_native"]
20-
cl = ["serde_support"]
21-
cl_native = ["serde_support", "anoncreds-clsignatures/openssl_bn"]
22-
merkle_tree = ["indy-utils/hash", "hex"]
19+
default = ["anoncreds", "merkle_tree"]
20+
anoncreds = ["serde_support"]
21+
cl = ["anoncreds", "anoncreds-clsignatures", "serde_support"]
22+
cl_native = ["anoncreds", "anoncreds-clsignatures/openssl_bn", "serde_support"]
23+
merkle_tree = ["hex", "sha2"]
2324
rich_schema = []
24-
serde_support = ["serde", "serde_json", "anoncreds-clsignatures?/serde", "indy-utils/serde"]
25+
serde_support = [
26+
"serde",
27+
"serde_json",
28+
"anoncreds-clsignatures?/serde",
29+
"indy-utils/serde",
30+
]
2531
vendored = ["anoncreds-clsignatures?/openssl_vendored"]
2632

2733
[dependencies]
28-
anoncreds-clsignatures = { version = "0.1", optional = true }
34+
anoncreds-clsignatures = { version = "0.2", optional = true }
35+
indy-utils = { version = "0.6.0", default-features = false, path = "../indy-utils" }
2936
hex = { version = "0.4", optional = true }
3037
once_cell = "1"
3138
regex = "1"
3239
serde = { version = "1.0", optional = true, features = ["derive"] }
3340
serde_json = { version = "1.0", optional = true, features = ["raw_value"] }
41+
sha2 = { version = "0.10", optional = true }
3442
zeroize = { version = "1", features = ["zeroize_derive"] }
3543

36-
[dependencies.indy-utils]
37-
version = "0.5"
38-
path = "../indy-utils"
39-
default-features = false
40-
4144
[dev-dependencies]
4245
hex = "0.4"
4346
rand = "0.8"

indy-data-types/src/anoncreds/cred_def.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(any(feature = "cl", feature = "cl_native"))]
12
use crate::anoncreds_clsignatures::CredentialPublicKey;
23
use crate::identifiers::cred_def::CredentialDefinitionId;
34
use crate::identifiers::schema::SchemaId;

indy-data-types/src/anoncreds/link_secret.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ use std::fmt;
22

33
use serde::{Deserialize, Serialize};
44

5-
use crate::anoncreds_clsignatures::{MasterSecret as ClMasterSecret, Prover as ClProver};
5+
use crate::anoncreds_clsignatures::{LinkSecret as ClLinkSecret, Prover as ClProver};
66
use crate::ConversionError;
77

88
#[derive(Serialize, Deserialize)]
99
pub struct LinkSecret {
10-
pub value: ClMasterSecret,
10+
pub value: ClLinkSecret,
1111
}
1212

1313
impl LinkSecret {
1414
#[cfg(any(feature = "cl", feature = "cl_native"))]
1515
#[inline]
1616
pub fn new() -> Result<Self, ConversionError> {
17-
let value = ClProver::new_master_secret().map_err(|err| {
18-
ConversionError::from_msg(format!("Error creating master secret: {}", err))
17+
let value = ClProver::new_link_secret().map_err(|err| {
18+
ConversionError::from_msg(format!("Error creating link secret: {}", err))
1919
})?;
2020
Ok(Self { value })
2121
}

indy-data-types/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub use indy_utils::{invalid, ConversionError, Validatable, ValidationError};
2121
#[cfg(any(feature = "cl", feature = "cl_native"))]
2222
pub use anoncreds_clsignatures;
2323

24+
#[cfg(feature = "anoncreds")]
2425
/// Type definitions related Indy credential issuance and verification
2526
pub mod anoncreds;
2627

indy-utils/src/hash.rs renamed to indy-data-types/src/merkle_tree/hash.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
pub use sha2::Digest;
22

3-
use super::ValidationError;
3+
use crate::ValidationError;
44

55
/// Derive a new hash type
66
#[macro_export]
77
macro_rules! hash_type {
88
($modname:ident, $digest:path, $doc:expr) => {
99
#[doc=$doc]
10-
#[allow(non_snake_case)]
10+
#[allow(non_snake_case, unused)]
1111
pub mod $modname {
1212
use once_cell::sync::Lazy;
1313
use sha2::Digest;

indy-data-types/src/merkle_tree/merkletree.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use indy_utils::hash::{
1+
use super::hash::{
22
TreeHash,
33
SHA256::{digest_empty, DigestType as Hash},
44
};
5-
65
use super::proof::{Lemma, Proof};
76
use super::tree::{LeavesIntoIterator, LeavesIterator, Tree, TreeLeafData};
87
use crate::ValidationError;

indy-data-types/src/merkle_tree/mod.rs

+46-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use indy_utils::hash::{TreeHash, SHA256::DigestType as Hash};
2-
1+
use self::hash::{TreeHash, SHA256::DigestType as Hash};
32
use self::tree::{Tree, TreeLeafData};
43
use crate::ValidationError;
54

6-
mod merkletree;
75
pub use self::merkletree::MerkleTree;
6+
pub use self::proof::Positioned;
87

8+
mod hash;
9+
mod merkletree;
910
mod proof;
1011
mod tree;
1112

@@ -199,6 +200,25 @@ impl MerkleTree {
199200
}
200201
Ok(())
201202
}
203+
204+
pub fn check_inclusion_proof(
205+
root_hash: &[u8],
206+
leaf_value: &TreeLeafData,
207+
path: &[Positioned<TreeLeafData>],
208+
) -> Result<bool, ValidationError> {
209+
let mut check_hash = Hash::hash_leaf(leaf_value)?;
210+
for node in path {
211+
match node {
212+
Positioned::Left(data) => {
213+
check_hash = Hash::hash_nodes(data, &check_hash)?;
214+
}
215+
Positioned::Right(data) => {
216+
check_hash = Hash::hash_nodes(&check_hash, data)?;
217+
}
218+
}
219+
}
220+
Ok(check_hash == root_hash)
221+
}
202222
}
203223

204224
#[cfg(test)]
@@ -443,4 +463,27 @@ mod tests {
443463
.consistency_proof(&full_root_hash, 8, &proofs_for_8)
444464
.unwrap());
445465
}
466+
467+
#[test]
468+
fn check_inclusion_proof_works() {
469+
let nodes = [
470+
(true, "Gf9aBhHCtBpTYbJXQWnt1DU8q33hwi6nN4f3NhnsBgMZ"),
471+
(false, "68TGAdRjeQ29eNcuFYhsX5uLakGQLgKMKp5wSyPzt9Nq"),
472+
(true, "25KLEkkyCEPSBj4qMFE3AcH87mFocyJEuPJ5xzPGwDgz"),
473+
];
474+
let path: Vec<Positioned<Vec<u8>>> = nodes
475+
.iter()
476+
.map(|(side, val)| {
477+
let val = base58::decode(val).unwrap();
478+
if *side {
479+
Positioned::Right(val)
480+
} else {
481+
Positioned::Left(val)
482+
}
483+
})
484+
.collect();
485+
let root_hash = base58::decode("CrA5sqYe3ruf2uY7d8re7ePmyHqptHqANtMZcfZd4BvK").unwrap();
486+
let leaf_value = b"\x81\xa13\xa13".to_vec(); // {"3":"3"} serialized via rmp
487+
assert!(MerkleTree::check_inclusion_proof(&root_hash, &leaf_value, &path).unwrap());
488+
}
446489
}

indy-data-types/src/merkle_tree/proof.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use indy_utils::hash::{TreeHash, SHA256::DigestType as Hash};
2-
1+
use super::hash::{TreeHash, SHA256::DigestType as Hash};
32
use super::tree::{Tree, TreeLeafData};
43
use crate::ValidationError;
54

@@ -46,13 +45,13 @@ impl Proof {
4645

4746
Some(Positioned::Left(ref hash)) => {
4847
let combined = Hash::hash_nodes(hash, &sub.node_hash)?;
49-
let hashes_match = combined.to_vec().as_slice() == lemma.node_hash.as_slice();
48+
let hashes_match = combined == lemma.node_hash;
5049
Ok(hashes_match && self.validate_lemma(sub)?)
5150
}
5251

5352
Some(Positioned::Right(ref hash)) => {
5453
let combined = Hash::hash_nodes(&sub.node_hash, hash)?;
55-
let hashes_match = combined.to_vec().as_slice() == lemma.node_hash.as_slice();
54+
let hashes_match = combined == lemma.node_hash;
5655
Ok(hashes_match && self.validate_lemma(sub)?)
5756
}
5857
},

indy-data-types/src/merkle_tree/tree.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::cmp;
22

3-
use indy_utils::hash::{TreeHash, SHA256::DigestType as Hash};
4-
3+
use super::hash::{TreeHash, SHA256::DigestType as Hash};
54
use crate::ValidationError;
65

76
pub type TreeLeafData = Vec<u8>;

indy-utils/Cargo.toml

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "indy-utils"
3-
version = "0.5.2"
3+
version = "0.6.0"
44
authors = ["Hyperledger Indy Contributors <[email protected]>"]
55
description = "Utilities for Hyperledger Indy (https://www.hyperledger.org/projects), which provides a distributed-ledger-based foundation for self-sovereign identity (https://sovrin.org)."
66
edition = "2018"
@@ -16,29 +16,30 @@ path = "src/lib.rs"
1616
crate-type = ["rlib"]
1717

1818
[features]
19-
default = ["ed25519", "hash", "txn_signature"]
20-
base64 = ["base64_rs"]
19+
default = ["ed25519"]
2120
ed25519 = ["curve25519-dalek", "ed25519-dalek", "rand", "sha2", "x25519-dalek"]
22-
hash = ["sha2"]
23-
txn_signature = ["hex", "sha2", "serde", "serde_json"]
2421

2522
[dependencies]
26-
base64_rs = { package = "base64", version = "0.13", optional = true }
27-
bs58 = "0.4"
28-
curve25519-dalek = { version = "3.1", default-features = false, features = ["u64_backend"], optional = true }
29-
ed25519-dalek = { version = "1.0", default-features = false, features = ["u64_backend"], optional = true }
30-
hex = { version = "0.4", optional = true }
23+
bs58 = "0.5"
24+
curve25519-dalek = { version = "3.1", default-features = false, features = [
25+
"u64_backend",
26+
], optional = true }
27+
ed25519-dalek = { version = "1.0", default-features = false, features = [
28+
"u64_backend",
29+
], optional = true }
3130
once_cell = "1.9"
3231
rand = { version = "0.8", optional = true }
3332
regex = "1.3"
3433
serde = { version = "1.0", optional = true, features = ["derive"] }
3534
serde_json = { version = "1.0", optional = true }
36-
sha2 = { version = "0.9", optional = true }
35+
sha2 = { version = "0.10", optional = true }
3736
thiserror = "1.0"
38-
x25519-dalek = { version = "=1.2", default-features = false, features = ["u64_backend"], optional = true }
37+
x25519-dalek = { version = "=1.2", default-features = false, features = [
38+
"u64_backend",
39+
], optional = true }
3940
zeroize = { version = "1.3" }
4041

4142
[dev-dependencies]
42-
async-global-executor = "1.2"
43+
async-global-executor = "2.3"
4344
serde = { version = "1.0", features = ["derive"] }
4445
serde_json = "1.0"

indy-utils/src/base64.rs

-18
This file was deleted.

indy-utils/src/lib.rs

-12
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,3 @@ pub mod did;
2727

2828
/// Indy signing keys and verification keys
2929
pub mod keys;
30-
31-
/// Base64 encoding and decoding
32-
#[cfg(feature = "base64")]
33-
pub mod base64;
34-
35-
/// Hash algorithms
36-
#[cfg(feature = "hash")]
37-
pub mod hash;
38-
39-
/// Generation of normalized ledger transaction for signing
40-
#[cfg(feature = "txn_signature")]
41-
pub mod txn_signature;

0 commit comments

Comments
 (0)