extern crate libc;
use api::ErrorCode;
use errors::ToErrorCode;
use commands::{Command, CommandExecutor};
use commands::anoncreds::AnoncredsCommand;
use commands::anoncreds::issuer::IssuerCommand;
use commands::anoncreds::prover::ProverCommand;
use commands::anoncreds::verifier::VerifierCommand;
use utils::cstring::CStringUtils;
use self::libc::c_char;
#[no_mangle]
pub extern fn indy_issuer_create_and_store_claim_def(command_handle: i32,
wallet_handle: i32,
issuer_did: *const c_char,
schema_json: *const c_char,
signature_type: *const c_char,
create_non_revoc: bool,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
claim_def_json: *const c_char
)>) -> ErrorCode {
check_useful_c_str!(issuer_did, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(schema_json, ErrorCode::CommonInvalidParam4);
check_useful_opt_c_str!(signature_type, ErrorCode::CommonInvalidParam5);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam7);
let result = CommandExecutor::instance()
.send(Command::Anoncreds(AnoncredsCommand::Issuer(IssuerCommand::CreateAndStoreClaimDefinition(
wallet_handle,
issuer_did,
schema_json,
signature_type,
create_non_revoc,
Box::new(move |result| {
let (err, claim_def_json) = result_to_err_code_1!(result, String::new());
let claim_def_json = CStringUtils::string_to_cstring(claim_def_json);
cb(command_handle, err, claim_def_json.as_ptr())
})
))));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_issuer_create_and_store_revoc_reg(command_handle: i32,
wallet_handle: i32,
issuer_did: *const c_char,
schema_seq_no: i32,
max_claim_num: i32,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
revoc_reg_json: *const c_char,
revoc_reg_uuid: *const c_char
)>) -> ErrorCode {
check_useful_c_str!(issuer_did, ErrorCode::CommonInvalidParam3);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam6);
let result = CommandExecutor::instance()
.send(Command::Anoncreds(
AnoncredsCommand::Issuer(
IssuerCommand::CreateAndStoreRevocationRegistry(
wallet_handle,
issuer_did,
schema_seq_no,
max_claim_num,
Box::new(move |result| {
let (err, revoc_reg_json, revoc_reg_wallet_key) = result_to_err_code_2!(result, String::new(), String::new());
let revoc_reg_json = CStringUtils::string_to_cstring(revoc_reg_json);
let revoc_reg_uuid = CStringUtils::string_to_cstring(revoc_reg_wallet_key);
cb(command_handle, err, revoc_reg_json.as_ptr(), revoc_reg_uuid.as_ptr())
})
))));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_issuer_create_claim(command_handle: i32,
wallet_handle: i32,
claim_req_json: *const c_char,
claim_json: *const c_char,
revoc_reg_seq_no: i32,
user_revoc_index: i32,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
revoc_reg_update_json: *const c_char, //TODO must be OPTIONAL
xclaim_json: *const c_char
)>) -> ErrorCode {
check_useful_c_str!(claim_req_json, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(claim_json, ErrorCode::CommonInvalidParam4);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam7);
let revoc_reg_seq_no = if revoc_reg_seq_no != -1 {Some(revoc_reg_seq_no)} else { None };
let user_revoc_index = if user_revoc_index != -1 {Some(user_revoc_index)} else { None };
let result = CommandExecutor::instance()
.send(Command::Anoncreds(AnoncredsCommand::Issuer(IssuerCommand::CreateClaim(
wallet_handle,
claim_req_json,
claim_json,
revoc_reg_seq_no,
user_revoc_index,
Box::new(move |result| {
let (err, revoc_reg_update_json, xclaim_json) = result_to_err_code_2!(result, String::new(), String::new());
let revoc_reg_update_json = CStringUtils::string_to_cstring(revoc_reg_update_json);
let xclaim_json = CStringUtils::string_to_cstring(xclaim_json);
cb(command_handle, err, revoc_reg_update_json.as_ptr(), xclaim_json.as_ptr())
})
))));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_issuer_revoke_claim(command_handle: i32,
wallet_handle: i32,
revoc_reg_seq_no: i32,
user_revoc_index: i32,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
revoc_reg_update_json: *const c_char,
)>) -> ErrorCode {
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam6);
let result = CommandExecutor::instance()
.send(Command::Anoncreds(
AnoncredsCommand::Issuer(
IssuerCommand::RevokeClaim(
wallet_handle,
revoc_reg_seq_no,
user_revoc_index,
Box::new(move |result| {
let (err, revoc_reg_update_json) = result_to_err_code_1!(result, String::new());
let revoc_reg_update_json = CStringUtils::string_to_cstring(revoc_reg_update_json);
cb(command_handle, err, revoc_reg_update_json.as_ptr())
})
))));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_prover_store_claim_offer(command_handle: i32,
wallet_handle: i32,
claim_offer_json: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode
)>) -> ErrorCode {
check_useful_c_str!(claim_offer_json, ErrorCode::CommonInvalidParam3);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4);
let result = CommandExecutor::instance()
.send(Command::Anoncreds(AnoncredsCommand::Prover(ProverCommand::StoreClaimOffer(
wallet_handle,
claim_offer_json,
Box::new(move |result| {
let err = result_to_err_code!(result);
cb(command_handle, err)
})
))));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_prover_get_claim_offers(command_handle: i32,
wallet_handle: i32,
filter_json: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
claim_offers_json: *const c_char
)>) -> ErrorCode {
check_useful_c_str!(filter_json, ErrorCode::CommonInvalidParam3);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4);
let result = CommandExecutor::instance()
.send(Command::Anoncreds(AnoncredsCommand::Prover(ProverCommand::GetClaimOffers(
wallet_handle,
filter_json,
Box::new(move |result| {
let (err, claim_offers_json) = result_to_err_code_1!(result, String::new());
let claim_offers_json = CStringUtils::string_to_cstring(claim_offers_json);
cb(command_handle, err, claim_offers_json.as_ptr())
})
))));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_prover_create_master_secret(command_handle: i32,
wallet_handle: i32,
master_secret_name: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode
)>) -> ErrorCode {
check_useful_c_str!(master_secret_name, ErrorCode::CommonInvalidParam3);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4);
let result = CommandExecutor::instance()
.send(Command::Anoncreds(AnoncredsCommand::Prover(ProverCommand::CreateMasterSecret(
wallet_handle,
master_secret_name,
Box::new(move |result| {
let err = result_to_err_code!(result);
cb(command_handle, err)
})
))));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_prover_create_and_store_claim_req(command_handle: i32,
wallet_handle: i32,
prover_did: *const c_char,
claim_offer_json: *const c_char,
claim_def_json: *const c_char,
master_secret_name: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
claim_req_json: *const c_char
)>) -> ErrorCode {
check_useful_c_str!(prover_did, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(claim_offer_json, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(claim_def_json, ErrorCode::CommonInvalidParam5);
check_useful_c_str!(master_secret_name, ErrorCode::CommonInvalidParam6);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam7);
let result = CommandExecutor::instance()
.send(Command::Anoncreds(AnoncredsCommand::Prover(ProverCommand::CreateAndStoreClaimRequest(
wallet_handle,
prover_did,
claim_offer_json,
claim_def_json,
master_secret_name,
Box::new(move |result| {
let (err, claim_req_json) = result_to_err_code_1!(result, String::new());
let claim_req_json = CStringUtils::string_to_cstring(claim_req_json);
cb(command_handle, err, claim_req_json.as_ptr())
})
))));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_prover_store_claim(command_handle: i32,
wallet_handle: i32,
claims_json: *const c_char,
cb: Option<extern fn(
xcommand_handle: i32, err: ErrorCode
)>) -> ErrorCode {
check_useful_c_str!(claims_json, ErrorCode::CommonInvalidParam3);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4);
let result = CommandExecutor::instance()
.send(Command::Anoncreds(AnoncredsCommand::Prover(ProverCommand::StoreClaim(
wallet_handle,
claims_json,
Box::new(move |result| {
let err = result_to_err_code!(result);
cb(command_handle, err)
})
))));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_prover_get_claims(command_handle: i32,
wallet_handle: i32,
filter_json: *const c_char,
cb: Option<extern fn(
xcommand_handle: i32, err: ErrorCode,
claims_json: *const c_char
)>) -> ErrorCode {
check_useful_c_str!(filter_json, ErrorCode::CommonInvalidParam3);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4);
let result = CommandExecutor::instance()
.send(Command::Anoncreds(AnoncredsCommand::Prover(ProverCommand::GetClaims(
wallet_handle,
filter_json,
Box::new(move |result| {
let (err, claims_json) = result_to_err_code_1!(result, String::new());
let claims_json = CStringUtils::string_to_cstring(claims_json);
cb(command_handle, err, claims_json.as_ptr())
})
))));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_prover_get_claims_for_proof_req(command_handle: i32,
wallet_handle: i32,
proof_request_json: *const c_char,
cb: Option<extern fn(
xcommand_handle: i32, err: ErrorCode,
claims_json: *const c_char
)>) -> ErrorCode {
check_useful_c_str!(proof_request_json, ErrorCode::CommonInvalidParam3);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4);
let result = CommandExecutor::instance()
.send(Command::Anoncreds(AnoncredsCommand::Prover(ProverCommand::GetClaimsForProofReq(
wallet_handle,
proof_request_json,
Box::new(move |result| {
let (err, claims_json) = result_to_err_code_1!(result, String::new());
let claims_json = CStringUtils::string_to_cstring(claims_json);
cb(command_handle, err, claims_json.as_ptr())
})
))));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_prover_create_proof(command_handle: i32,
wallet_handle: i32,
proof_req_json: *const c_char,
requested_claims_json: *const c_char,
schemas_json: *const c_char,
master_secret_name: *const c_char,
claim_defs_json: *const c_char,
revoc_regs_json: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
proof_json: *const c_char)>) -> ErrorCode {
check_useful_c_str!(proof_req_json, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(requested_claims_json, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(schemas_json, ErrorCode::CommonInvalidParam5);
check_useful_c_str!(master_secret_name, ErrorCode::CommonInvalidParam6);
check_useful_c_str!(claim_defs_json, ErrorCode::CommonInvalidParam7);
check_useful_c_str!(revoc_regs_json, ErrorCode::CommonInvalidParam8);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam9);
let result = CommandExecutor::instance()
.send(Command::Anoncreds(AnoncredsCommand::Prover(ProverCommand::CreateProof(
wallet_handle,
proof_req_json,
requested_claims_json,
schemas_json,
master_secret_name,
claim_defs_json,
revoc_regs_json,
Box::new(move |result| {
let (err, proof_json) = result_to_err_code_1!(result, String::new());
let proof_json = CStringUtils::string_to_cstring(proof_json);
cb(command_handle, err, proof_json.as_ptr())
})
))));
result_to_err_code!(result)
}
#[no_mangle]
pub extern fn indy_verifier_verify_proof(command_handle: i32,
proof_request_json: *const c_char,
proof_json: *const c_char,
schemas_json: *const c_char,
claim_defs_jsons: *const c_char,
revoc_regs_json: *const c_char,
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
valid: bool)>) -> ErrorCode {
check_useful_c_str!(proof_request_json, ErrorCode::CommonInvalidParam2);
check_useful_c_str!(proof_json, ErrorCode::CommonInvalidParam3);
check_useful_c_str!(schemas_json, ErrorCode::CommonInvalidParam4);
check_useful_c_str!(claim_defs_jsons, ErrorCode::CommonInvalidParam5);
check_useful_c_str!(revoc_regs_json, ErrorCode::CommonInvalidParam6);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam7);
let result = CommandExecutor::instance()
.send(Command::Anoncreds(AnoncredsCommand::Verifier(VerifierCommand::VerifyProof(
proof_request_json,
proof_json,
schemas_json,
claim_defs_jsons,
revoc_regs_json,
Box::new(move |result| {
let (err, valid) = result_to_err_code_1!(result, false);
cb(command_handle, err, valid)
})
))));
result_to_err_code!(result)
}