Skip to content

Commit 3514451

Browse files
author
Vyacheslav
authored
Merge pull request hyperledger-indy#682 from jovfer/feature/revocation
Feature Revocation StateProofs
2 parents 7d40e9a + 7cc3476 commit 3514451

File tree

2 files changed

+85
-20
lines changed

2 files changed

+85
-20
lines changed

libindy/src/errors/wallet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl ToErrorCode for WalletError {
9292

9393
impl From<io::Error> for WalletError {
9494
fn from(err: io::Error) -> WalletError {
95-
WalletError::CommonError(CommonError::IOError((err)))
95+
WalletError::CommonError(CommonError::IOError(err))
9696
}
9797
}
9898

libindy/src/services/pool/transaction_handler.rs

Lines changed: 84 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ use services::ledger::constants;
2929
use services::ledger::merkletree::merkletree::MerkleTree;
3030
use self::indy_crypto::bls::Generator;
3131

32-
const REQUESTS_FOR_STATE_PROOFS: [&'static str; 4] = [constants::GET_NYM, constants::GET_SCHEMA, constants::GET_CRED_DEF, constants::GET_ATTR];
32+
const REQUESTS_FOR_STATE_PROOFS: [&'static str; 7] = [
33+
constants::GET_NYM,
34+
constants::GET_SCHEMA,
35+
constants::GET_CRED_DEF,
36+
constants::GET_ATTR,
37+
constants::GET_REVOC_REG,
38+
constants::GET_REVOC_REG_DEF,
39+
constants::GET_REVOC_REG_DELTA,
40+
];
3341
const RESENDABLE_REQUEST_TIMEOUT: i64 = 1;
3442
const REQUEST_TIMEOUT_ACK: i64 = 10;
3543
const REQUEST_TIMEOUT_REPLY: i64 = 100;
@@ -345,30 +353,84 @@ impl TransactionHandler {
345353
return None;
346354
}
347355
}
356+
constants::GET_REVOC_REG_DEF => {
357+
//{DID}:{MARKER}:{CRED_DEF_ID}:{REVOC_DEF_TYPE}:{REVOC_DEF_TAG}
358+
if let (Some(cred_def_id), Some(revoc_def_type), Some(tag)) = (
359+
parsed_data["credDefId"].as_str(),
360+
parsed_data["revocDefType"].as_str(),
361+
parsed_data["tag"].as_str()) {
362+
trace!("TransactionHandler::parse_reply_for_proof_checking: GET_REVOC_REG_DEF cred_def_id {:?}, revoc_def_type: {:?}, tag: {:?}", cred_def_id, revoc_def_type, tag);
363+
format!(":4:{}:{}:{}", cred_def_id, revoc_def_type, tag)
364+
} else {
365+
trace!("TransactionHandler::parse_reply_for_proof_checking: <<< GET_REVOC_REG_DEF No key suffix");
366+
return None;
367+
}
368+
}
369+
constants::GET_REVOC_REG | constants::GET_REVOC_REG_DELTA if parsed_data["value"]["accum_from"].is_null() => {
370+
//{MARKER}:{REVOC_REG_DEF_ID}
371+
if let Some(revoc_reg_def_id) = parsed_data["revocRegDefId"].as_str() {
372+
trace!("TransactionHandler::parse_reply_for_proof_checking: GET_REVOC_REG revoc_reg_def_id {:?}", revoc_reg_def_id);
373+
format!("5:{}", revoc_reg_def_id)
374+
} else {
375+
trace!("TransactionHandler::parse_reply_for_proof_checking: <<< GET_REVOC_REG No key suffix");
376+
return None;
377+
}
378+
}
379+
/* TODO add multiproof checking and external verification of indexes
380+
constants::GET_REVOC_REG_DELTA if !parsed_data["value"]["accum_from"].is_null() => {
381+
//{MARKER}:{REVOC_REG_DEF_ID}
382+
if let Some(revoc_reg_def_id) = parsed_data["value"]["accum_to"]["revocRegDefId"].as_str() {
383+
trace!("TransactionHandler::parse_reply_for_proof_checking: GET_REVOC_REG_DELTA revoc_reg_def_id {:?}", revoc_reg_def_id);
384+
format!("6:{}", revoc_reg_def_id)
385+
} else {
386+
trace!("TransactionHandler::parse_reply_for_proof_checking: <<< GET_REVOC_REG_DELTA No key suffix");
387+
return None;
388+
}
389+
}
390+
*/
348391
_ => {
349-
trace!("TransactionHandler::parse_reply_for_proof_checking: <<< Unknown transaction");
392+
trace!("TransactionHandler::parse_reply_for_proof_checking: <<< Unsupported transaction");
350393
return None;
351394
}
352395
};
353396

354-
let key = if let Some(dest) = json_msg["dest"].as_str().or(json_msg["origin"].as_str()) {
355-
let mut dest = if xtype == constants::GET_NYM {
356-
let mut hasher = sha2::Sha256::default();
357-
hasher.process(dest.as_bytes());
358-
hasher.fixed_result().to_vec()
359-
} else {
360-
dest.as_bytes().to_vec()
361-
};
362-
363-
dest.extend_from_slice(key_suffix.as_bytes());
364-
365-
trace!("TransactionHandler::parse_reply_for_proof_checking: dest: {:?}", dest);
366-
dest
367-
} else {
368-
trace!("TransactionHandler::parse_reply_for_proof_checking: <<< No dest");
369-
return None;
397+
let dest = json_msg["dest"].as_str().or(json_msg["origin"].as_str());
398+
let key_prefix = match xtype {
399+
constants::GET_NYM => {
400+
if let Some(dest) = dest {
401+
let mut hasher = sha2::Sha256::default();
402+
hasher.process(dest.as_bytes());
403+
hasher.fixed_result().to_vec()
404+
} else {
405+
trace!("TransactionHandler::parse_reply_for_proof_checking: <<< No dest");
406+
return None;
407+
}
408+
}
409+
constants::GET_REVOC_REG | constants::GET_REVOC_REG_DELTA => {
410+
Vec::new()
411+
}
412+
constants::GET_REVOC_REG_DEF => {
413+
if let Some(id) = json_msg["id"].as_str() { //FIXME
414+
id.splitn(2, ":").next().unwrap()
415+
.as_bytes().to_vec()
416+
} else {
417+
trace!("TransactionHandler::parse_reply_for_proof_checking: <<< No dest");
418+
return None;
419+
}
420+
}
421+
_ => {
422+
if let Some(dest) = dest {
423+
dest.as_bytes().to_vec()
424+
} else {
425+
trace!("TransactionHandler::parse_reply_for_proof_checking: <<< No dest");
426+
return None;
427+
}
428+
}
370429
};
371430

431+
let mut key = key_prefix;
432+
key.extend_from_slice(key_suffix.as_bytes());
433+
372434
let value: Option<String> = match TransactionHandler::parse_reply_for_proof_value(json_msg, data, parsed_data, xtype) {
373435
Ok(value) => value,
374436
Err(err_str) => {
@@ -407,7 +469,7 @@ impl TransactionHandler {
407469
hasher.process(data.as_bytes());
408470
value["val"] = SJsonValue::String(hasher.fixed_result().to_hex());
409471
}
410-
constants::GET_CRED_DEF => {
472+
constants::GET_CRED_DEF | constants::GET_REVOC_REG_DEF | constants::GET_REVOC_REG => {
411473
value["val"] = parsed_data;
412474
}
413475
constants::GET_SCHEMA => {
@@ -424,6 +486,9 @@ impl TransactionHandler {
424486
return Err("Invalid data for GET_SCHEMA".to_string());
425487
};
426488
}
489+
constants::GET_REVOC_REG_DELTA => {
490+
value["val"] = parsed_data["value"]["accum_to"].clone(); // TODO check accum_from also
491+
}
427492
_ => {
428493
return Err("Unknown transaction".to_string());
429494
}

0 commit comments

Comments
 (0)