Skip to content

Commit 3b37042

Browse files
committed
Add simple state proof checking for new Anoncreds txns.
Signed-off-by: Sergey Minaev <[email protected]>
1 parent 1769e28 commit 3b37042

File tree

1 file changed

+81
-18
lines changed

1 file changed

+81
-18
lines changed

libindy/src/services/pool/transaction_handler.rs

Lines changed: 81 additions & 18 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_CLAIM_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,82 @@ 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!(":\x04:{}:{}:{}", 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 => {
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!("\x05:{}", 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+
constants::GET_REVOC_REG_DELTA => {
380+
//{MARKER}:{REVOC_REG_DEF_ID}
381+
if let Some(revoc_reg_def_id) = parsed_data["value"]["accum_to"]["revocRegDefId"].as_str() {
382+
trace!("TransactionHandler::parse_reply_for_proof_checking: GET_REVOC_REG_DELTA revoc_reg_def_id {:?}", revoc_reg_def_id);
383+
format!("\x06:{}", revoc_reg_def_id)
384+
} else {
385+
trace!("TransactionHandler::parse_reply_for_proof_checking: <<< GET_REVOC_REG_DELTA No key suffix");
386+
return None;
387+
}
388+
}
348389
_ => {
349390
trace!("TransactionHandler::parse_reply_for_proof_checking: <<< Unknown transaction");
350391
return None;
351392
}
352393
};
353394

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;
395+
let dest = json_msg["dest"].as_str().or(json_msg["origin"].as_str());
396+
let key_prefix = match xtype {
397+
constants::GET_NYM => {
398+
if let Some(dest) = dest {
399+
let mut hasher = sha2::Sha256::default();
400+
hasher.process(dest.as_bytes());
401+
hasher.fixed_result().to_vec()
402+
} else {
403+
trace!("TransactionHandler::parse_reply_for_proof_checking: <<< No dest");
404+
return None;
405+
}
406+
}
407+
constants::GET_REVOC_REG | constants::GET_REVOC_REG_DELTA => {
408+
Vec::new()
409+
}
410+
constants::GET_REVOC_REG_DEF => {
411+
if let Some(id) = json_msg["id"].as_str() { //FIXME
412+
id.splitn(2, ":").next().unwrap()
413+
.as_bytes().to_vec()
414+
} else {
415+
trace!("TransactionHandler::parse_reply_for_proof_checking: <<< No dest");
416+
return None;
417+
}
418+
}
419+
_ => {
420+
if let Some(dest) = dest {
421+
dest.as_bytes().to_vec()
422+
} else {
423+
trace!("TransactionHandler::parse_reply_for_proof_checking: <<< No dest");
424+
return None;
425+
}
426+
}
370427
};
371428

429+
let mut key = key_prefix;
430+
key.extend_from_slice(key_suffix.as_bytes());
431+
372432
let value: Option<String> = match TransactionHandler::parse_reply_for_proof_value(json_msg, data, parsed_data, xtype) {
373433
Ok(value) => value,
374434
Err(err_str) => {
@@ -407,7 +467,7 @@ impl TransactionHandler {
407467
hasher.process(data.as_bytes());
408468
value["val"] = SJsonValue::String(hasher.fixed_result().to_hex());
409469
}
410-
constants::GET_CRED_DEF => {
470+
constants::GET_CLAIM_DEF | constants::GET_REVOC_REG_DEF | constants::GET_REVOC_REG => {
411471
value["val"] = parsed_data;
412472
}
413473
constants::GET_SCHEMA => {
@@ -424,6 +484,9 @@ impl TransactionHandler {
424484
return Err("Invalid data for GET_SCHEMA".to_string());
425485
};
426486
}
487+
constants::GET_REVOC_REG_DELTA => {
488+
value["val"] = parsed_data["value"]["accum_to"].clone(); // TODO check accum_from also
489+
}
427490
_ => {
428491
return Err("Unknown transaction".to_string());
429492
}

0 commit comments

Comments
 (0)