From d2cbd7cf1e9ed6b127a67691347ccf129ba33484 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 5 Mar 2019 09:40:36 +0300 Subject: [PATCH 01/18] Added AUTH_RULE request builder Signed-off-by: artem.ivanov --- ci/indy-pool.dockerfile | 4 +- libindy/include/indy_ledger.h | 31 +++++ libindy/src/api/ledger.rs | 70 +++++++++++ libindy/src/commands/ledger.rs | 33 +++++ libindy/src/domain/ledger/auth_rule.rs | 64 ++++++++++ libindy/src/domain/ledger/constants.rs | 23 ++++ libindy/src/domain/ledger/mod.rs | 1 + libindy/src/services/ledger/mod.rs | 156 +++++++++++++++++++++++- libindy/tests/ledger.rs | 162 ++++++++++++++++++++++++- libindy/tests/utils/ledger.rs | 18 ++- wrappers/rust/indy-sys/src/ledger.rs | 11 ++ wrappers/rust/src/ledger.rs | 64 +++++++++- wrappers/rust/tests/ledger.rs | 113 ++++++++--------- 13 files changed, 678 insertions(+), 72 deletions(-) create mode 100644 libindy/src/domain/ledger/auth_rule.rs diff --git a/ci/indy-pool.dockerfile b/ci/indy-pool.dockerfile index eddce0a419..67d51a182b 100644 --- a/ci/indy-pool.dockerfile +++ b/ci/indy-pool.dockerfile @@ -24,9 +24,9 @@ RUN echo "deb https://repo.sovrin.org/deb xenial $indy_stream" >> /etc/apt/sourc RUN useradd -ms /bin/bash -u $uid indy -ARG indy_plenum_ver=1.6.662 +ARG indy_plenum_ver=1.6.705 ARG indy_anoncreds_ver=1.0.32 -ARG indy_node_ver=1.6.772 +ARG indy_node_ver=1.6.839 ARG python3_indy_crypto_ver=0.4.5 ARG indy_crypto_ver=0.4.5 diff --git a/libindy/include/indy_ledger.h b/libindy/include/indy_ledger.h index d2a511ab06..9d15cfd2dd 100644 --- a/libindy/include/indy_ledger.h +++ b/libindy/include/indy_ledger.h @@ -955,6 +955,37 @@ extern "C" { const char* response_metadata) ); + /// Builds a AUTH_RULE request. + /// + /// #Params + /// command_handle: command handle to map callback to caller context. + /// auth_type: + /// field: + /// auth_action: + /// old_value: + /// new_value: + /// constraint: + /// cb: Callback that takes command result as parameter. + /// + /// #Returns + /// Request result as json. + /// + /// #Errors + /// Common* + extern indy_error_t indy_build_auth_rule_request(indy_handle_t command_handle, + const char * submitter_did, + const char * auth_type, + const char * auth_action, + const char * field, + const char * old_value, + const char * new_value, + const char * constraint, + + void (*cb)(indy_handle_t command_handle_, + indy_error_t err, + const char* request_json) + ); + #ifdef __cplusplus } #endif diff --git a/libindy/src/api/ledger.rs b/libindy/src/api/ledger.rs index e310f98285..485373aeed 100644 --- a/libindy/src/api/ledger.rs +++ b/libindy/src/api/ledger.rs @@ -1832,5 +1832,75 @@ pub extern fn indy_get_response_metadata(command_handle: IndyHandle, trace!("indy_get_response_metadata: <<< res: {:?}", res); + res +} + +/// Builds a AUTH_RULE request. +/// +/// #Params +/// command_handle: command handle to map callback to caller context. +/// auth_type: +/// field: +/// auth_action: +/// old_value: +/// new_value: +/// constraint: +/// cb: Callback that takes command result as parameter. +/// +/// #Returns +/// Request result as json. +/// +/// #Errors +/// Common* +#[no_mangle] +pub extern fn indy_build_auth_rule_request(command_handle: IndyHandle, + submitter_did: *const c_char, + auth_type: *const c_char, + auth_action: *const c_char, + field: *const c_char, + old_value: *const c_char, + new_value: *const c_char, + constraint: *const c_char, + cb: Option) -> ErrorCode { + trace!("indy_build_auth_rule_request: >>> submitter_did: {:?}, auth_type: {:?}, auth_action: {:?}, field: {:?}, \ + old_value: {:?}, new_value: {:?}, constraint: {:?}", + submitter_did, auth_type, auth_action, field, old_value, new_value, constraint); + + check_useful_c_str!(submitter_did, ErrorCode::CommonInvalidParam2); + check_useful_c_str!(auth_type, ErrorCode::CommonInvalidParam3); + check_useful_c_str!(auth_action, ErrorCode::CommonInvalidParam4); + check_useful_c_str!(field, ErrorCode::CommonInvalidParam5); + check_useful_opt_c_str!(old_value, ErrorCode::CommonInvalidParam6); + check_useful_c_str!(new_value, ErrorCode::CommonInvalidParam7); + check_useful_c_str!(constraint, ErrorCode::CommonInvalidParam8); + check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam9); + + trace!("indy_build_auth_rule_request: entities >>> submitter_did: {:?}, auth_type: {:?}, auth_action: {:?}, field: {:?}, \ + old_value: {:?}, new_value: {:?}, constraint: {:?}", + submitter_did, auth_type, auth_action, field, old_value, new_value, constraint); + + let result = CommandExecutor::instance() + .send(Command::Ledger(LedgerCommand::BuildAuthRuleRequest( + submitter_did, + auth_type, + auth_action, + field, + old_value, + new_value, + constraint, + Box::new(move |result| { + let (err, request_json) = prepare_result_1!(result, String::new()); + trace!("indy_build_nym_request: request_json: {:?}", request_json); + let request_json = ctypes::string_to_cstring(request_json); + cb(command_handle, err, request_json.as_ptr()) + }) + ))); + + let res = prepare_result!(result); + + trace!("indy_build_auth_rule_request: <<< res: {:?}", res); + res } \ No newline at end of file diff --git a/libindy/src/commands/ledger.rs b/libindy/src/commands/ledger.rs index 1a72be8ede..fcbfeb24af 100644 --- a/libindy/src/commands/ledger.rs +++ b/libindy/src/commands/ledger.rs @@ -184,6 +184,15 @@ pub enum LedgerCommand { GetResponseMetadata( String, // response Box) + Send>), + BuildAuthRuleRequest( + String, // submitter did + String, // auth type + String, // auth action + String, // field + Option, // old value + String, // new value + String, // constraint + Box) + Send>), } pub struct LedgerCommandExecutor { @@ -361,6 +370,10 @@ impl LedgerCommandExecutor { info!(target: "ledger_command_executor", "GetResponseMetadata command received"); cb(self.get_response_metadata(&response)); } + LedgerCommand::BuildAuthRuleRequest(submitter_did, auth_type, auth_action, field, old_value, new_value, constraint, cb) => { + info!(target: "ledger_command_executor", "BuildAuthRuleRequest command received"); + cb(self.build_auth_rule_request(&submitter_did, &auth_type, &auth_action, &field, old_value.as_ref().map(String::as_str), &new_value, &constraint)); + } }; } @@ -890,6 +903,26 @@ impl LedgerCommandExecutor { Ok(res) } + fn build_auth_rule_request(&self, + submitter_did: &str, + auth_type: &str, + auth_action: &str, + field: &str, + old_value: Option<&str>, + new_value: &str, + constraint: &str) -> IndyResult { + debug!("build_auth_rule_request >>> submitter_did: {:?}, auth_type: {:?}, auth_action: {:?}, field: {:?}, \ + old_value: {:?}, new_value: {:?}, constraint: {:?}", submitter_did, auth_type, auth_action, field, old_value, new_value, constraint); + + self.validate_opt_did(Some(submitter_did))?; + + let res = self.ledger_service.build_auth_rule_request(submitter_did, auth_type, auth_action, field, old_value, new_value, constraint)?; + + debug!("build_auth_rule_request <<< res: {:?}", res); + + Ok(res) + } + fn validate_opt_did(&self, did: Option<&str>) -> IndyResult<()> { match did { Some(did) => Ok(self.crypto_service.validate_did(did)?), diff --git a/libindy/src/domain/ledger/auth_rule.rs b/libindy/src/domain/ledger/auth_rule.rs new file mode 100644 index 0000000000..fbd69733d7 --- /dev/null +++ b/libindy/src/domain/ledger/auth_rule.rs @@ -0,0 +1,64 @@ +use serde_json::Value; + +use super::constants::AUTH_RULE; + +#[allow(non_camel_case_types)] +#[derive(Deserialize, Debug, Serialize, PartialEq)] +pub enum AuthAction { + ADD, + EDIT +} + +#[derive(Serialize, Deserialize, PartialEq, Debug)] +#[serde(tag = "constraint_id")] +pub enum Constraint { + #[serde(rename = "OR")] + OrConstraint(CombinationConstraint), + #[serde(rename = "AND")] + AndConstraint(CombinationConstraint), + #[serde(rename = "ROLE")] + RoleConstraint(RoleConstraint), +} + +#[derive(Serialize, Deserialize, PartialEq, Debug)] +pub struct RoleConstraint { + pub sig_count: u32, + pub role: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub metadata: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub need_to_be_owner: Option, +} + +#[derive(Serialize, Deserialize, PartialEq, Debug)] +pub struct CombinationConstraint { + pub auth_constraints: Vec +} + +#[derive(Serialize, PartialEq, Debug)] +pub struct AuthRuleOperation { + #[serde(rename = "type")] + pub _type: String, + pub auth_type: String, + pub field: String, + pub auth_action: AuthAction, + #[serde(skip_serializing_if = "Option::is_none")] + pub old_value: Option, + pub new_value: String, + pub constraint: Constraint, +} + +impl AuthRuleOperation { + pub fn new(auth_type: String, field: String, auth_action: AuthAction, + old_value: Option, new_value: String, constraint: Constraint) -> AuthRuleOperation { + AuthRuleOperation { + _type: AUTH_RULE.to_string(), + auth_type, + field, + auth_action, + old_value, + new_value, + constraint, + } + } +} \ No newline at end of file diff --git a/libindy/src/domain/ledger/constants.rs b/libindy/src/domain/ledger/constants.rs index 998a8aab89..4ff517afa2 100644 --- a/libindy/src/domain/ledger/constants.rs +++ b/libindy/src/domain/ledger/constants.rs @@ -17,10 +17,33 @@ pub const GET_REVOC_REG_DEF: &str = "115"; pub const GET_REVOC_REG: &str = "116"; pub const GET_REVOC_REG_DELTA: &str = "117"; pub const GET_VALIDATOR_INFO: &str = "119"; +pub const AUTH_RULE: &str = "120"; pub const GET_DDO: &str = "120";//TODO change number +pub const WRITE_REQUESTS: [&str; 11] = [NODE, NYM, ATTRIB, ATTRIB, SCHEMA, CRED_DEF, POOL_UPGRADE, POOL_RESTART, POOL_CONFIG, REVOC_REG_DEF, REVOC_REG_ENTRY]; + pub const TRUSTEE: &str = "0"; pub const STEWARD: &str = "2"; pub const TRUST_ANCHOR: &str = "101"; pub const NETWORK_MONITOR: &str = "201"; pub const ROLE_REMOVE: &str = ""; + + +pub fn txn_name_to_code(txn: &str) -> Option<&str> { + if WRITE_REQUESTS.contains(&txn) { + return Some(txn) + } + + match txn { + "NODE" => Some(NODE), + "NYM" => Some(NYM), + "ATTRIB" => Some(ATTRIB), + "SCHEMA" => Some(SCHEMA), + "CRED_DEF" => Some(CRED_DEF), + "POOL_UPGRADE" => Some(POOL_UPGRADE), + "POOL_RESTART" => Some(POOL_RESTART), + "REVOC_REG_DEF" => Some(REVOC_REG_DEF), + "REVOC_REG_ENTRY" => Some(REVOC_REG_ENTRY), + _ => None + } +} \ No newline at end of file diff --git a/libindy/src/domain/ledger/mod.rs b/libindy/src/domain/ledger/mod.rs index 1748ecee0c..efaefab01c 100644 --- a/libindy/src/domain/ledger/mod.rs +++ b/libindy/src/domain/ledger/mod.rs @@ -12,3 +12,4 @@ pub mod rev_reg; pub mod response; pub mod validator_info; pub mod constants; +pub mod auth_rule; diff --git a/libindy/src/services/ledger/mod.rs b/libindy/src/services/ledger/mod.rs index 2c842b0bd0..3e2cbcee0c 100644 --- a/libindy/src/services/ledger/mod.rs +++ b/libindy/src/services/ledger/mod.rs @@ -12,7 +12,7 @@ use domain::anoncreds::revocation_registry_definition::{RevocationRegistryDefini use domain::anoncreds::revocation_registry_delta::{RevocationRegistryDelta, RevocationRegistryDeltaV1}; use domain::anoncreds::schema::{Schema, SchemaV1, MAX_ATTRIBUTES_COUNT}; use domain::ledger::attrib::{AttribOperation, GetAttribOperation}; -use domain::ledger::constants::{GET_VALIDATOR_INFO, NYM, POOL_RESTART, ROLE_REMOVE, STEWARD, TRUST_ANCHOR, TRUSTEE, NETWORK_MONITOR}; +use domain::ledger::constants::{GET_VALIDATOR_INFO, NYM, POOL_RESTART, ROLE_REMOVE, STEWARD, TRUST_ANCHOR, TRUSTEE, NETWORK_MONITOR, txn_name_to_code}; use domain::ledger::cred_def::{CredDefOperation, GetCredDefOperation, GetCredDefReplyResult}; use domain::ledger::ddo::GetDdoOperation; use domain::ledger::node::{NodeOperation, NodeOperationData}; @@ -25,6 +25,7 @@ use domain::ledger::rev_reg_def::{GetRevocRegDefReplyResult, GetRevRegDefOperati use domain::ledger::schema::{GetSchemaOperation, GetSchemaOperationData, GetSchemaReplyResult, SchemaOperation, SchemaOperationData}; use domain::ledger::txn::{GetTxnOperation, LedgerType}; use domain::ledger::validator_info::GetValidatorInfoOperation; +use domain::ledger::auth_rule::*; use errors::prelude::*; pub mod merkletree; @@ -78,6 +79,35 @@ impl LedgerService { Ok(request) } + pub fn build_auth_rule_request(&self, submitter_did: &str, auth_type: &str, auth_action: &str, field: &str, + old_value: Option<&str>, new_value: &str, constraint: &str) -> IndyResult { + info!("build_auth_rule_request >>> submitter_did: {:?}, auth_type: {:?}, auth_action: {:?}, field: {:?}, \ + old_value: {:?}, new_value: {:?}, constraint: {:?}", submitter_did, auth_type, auth_action, field, old_value, new_value, constraint); + + let auth_type = txn_name_to_code(&auth_type) + .ok_or(err_msg(IndyErrorKind::InvalidStructure, format!("Unsupported `auth_type`: {}", auth_type)))?; + + let auth_action = serde_json::from_str::(&format!("\"{}\"", auth_action)) + .map_err(|err| IndyError::from_msg(IndyErrorKind::InvalidStructure, format!("Cannot parse auth action: {}", err)))?; + + if auth_action == AuthAction::EDIT && old_value.is_none() { + return Err(err_msg(IndyErrorKind::InvalidStructure, "`old_value` must be specified for EDIT auth action")); + } + + let constraint = serde_json::from_str::(constraint) + .map_err(|err| IndyError::from_msg(IndyErrorKind::InvalidStructure, format!("Can not deserialize Constraint: {}", err)))?; + + let operation = AuthRuleOperation::new(auth_type.to_string(), field.to_string(), auth_action, + old_value.map(String::from), new_value.to_string(), constraint); + + let request = Request::build_request(Some(submitter_did), operation) + .to_indy(IndyErrorKind::InvalidState, "AUTH_RULE request json is invalid")?; + + info!("build_auth_rule_request <<< request: {:?}", request); + + Ok(request) + } + pub fn build_get_nym_request(&self, identifier: Option<&str>, dest: &str) -> IndyResult { info!("build_get_nym_request >>> identifier: {:?}, dest: {:?}", identifier, dest); @@ -924,6 +954,130 @@ mod tests { ledger_service.validate_action(&request).unwrap(); } + mod auth_rule { + use super::*; + + const ADD_AUTH_ACTION: &str = "ADD"; + const EDIT_AUTH_ACTION: &str = "EDIT"; + const FIELD: &str = "role"; + const OLD_VALUE: &str = "0"; + const NEW_VALUE: &str = "101"; + + fn _role_constraint() -> Constraint { + Constraint::RoleConstraint(RoleConstraint { + sig_count: 0, + metadata: None, + role: String::new(), + need_to_be_owner: Some(false), + }) + } + + fn _role_constraint_json() -> String { + serde_json::to_string(&_role_constraint()).unwrap() + } + + #[test] + fn build_auth_rule_request_works_for_role_constraint() { + let ledger_service = LedgerService::new(); + + let expected_result = json!({ + "type": AUTH_RULE, + "auth_type": NYM, + "field": FIELD, + "new_value": NEW_VALUE, + "auth_action": AuthAction::ADD, + "constraint": _role_constraint(), + }); + + let request = ledger_service.build_auth_rule_request(IDENTIFIER, NYM, ADD_AUTH_ACTION, FIELD, + None, NEW_VALUE, + &_role_constraint_json()).unwrap(); + check_request(&request, expected_result); + } + + #[test] + fn build_auth_rule_request_works_for_combination_constraints() { + let ledger_service = LedgerService::new(); + + let constraint = Constraint::AndConstraint( + CombinationConstraint { + auth_constraints: vec![ + _role_constraint(), + Constraint::OrConstraint( + CombinationConstraint { + auth_constraints: vec![ + _role_constraint(), _role_constraint(), ] + } + ) + ] + }); + let constraint_json = serde_json::to_string(&constraint).unwrap(); + + let expected_result = json!({ + "type": AUTH_RULE, + "auth_type": NYM, + "field": FIELD, + "new_value": NEW_VALUE, + "auth_action": AuthAction::ADD, + "constraint": constraint, + }); + + let request = ledger_service.build_auth_rule_request(IDENTIFIER, NYM, ADD_AUTH_ACTION, FIELD, + None, NEW_VALUE, + &constraint_json).unwrap(); + + check_request(&request, expected_result); + } + + #[test] + fn build_auth_rule_request_works_for_edit_auth_action() { + let ledger_service = LedgerService::new(); + + let expected_result = json!({ + "type": AUTH_RULE, + "auth_type": NYM, + "field": FIELD, + "old_value": OLD_VALUE, + "new_value": NEW_VALUE, + "auth_action": AuthAction::EDIT, + "constraint": _role_constraint(), + }); + + let request = ledger_service.build_auth_rule_request(IDENTIFIER, NYM, EDIT_AUTH_ACTION, FIELD, + Some(OLD_VALUE), NEW_VALUE, + &_role_constraint_json()).unwrap(); + check_request(&request, expected_result); + } + + #[test] + fn build_auth_rule_request_works_for_edit_auth_action_missed_old_value() { + let ledger_service = LedgerService::new(); + + let res = ledger_service.build_auth_rule_request(IDENTIFIER, NYM, EDIT_AUTH_ACTION, FIELD, + None, NEW_VALUE, + &_role_constraint_json()); + assert_kind!(IndyErrorKind::InvalidStructure, res); + } + + #[test] + fn build_auth_rule_request_works_for_invalid_auth_type() { + let ledger_service = LedgerService::new(); + + let res = ledger_service.build_auth_rule_request(IDENTIFIER, "WRONG", ADD_AUTH_ACTION, FIELD, + None, NEW_VALUE, + &_role_constraint_json()); + assert_kind!(IndyErrorKind::InvalidStructure, res); + } + + #[test] + fn build_auth_rule_request_works_for_invalid_auth_action() { + let ledger_service = LedgerService::new(); + + let res = ledger_service.build_auth_rule_request(IDENTIFIER, NYM, "WRONG", FIELD, None, NEW_VALUE, &_role_constraint_json()); + assert_kind!(IndyErrorKind::InvalidStructure, res); + } + } + fn check_request(request: &str, expected_result: serde_json::Value) { let request: serde_json::Value = serde_json::from_str(request).unwrap(); assert_eq!(request["operation"], expected_result); diff --git a/libindy/tests/ledger.rs b/libindy/tests/ledger.rs index 3152375244..f62413bfcd 100644 --- a/libindy/tests/ledger.rs +++ b/libindy/tests/ledger.rs @@ -549,7 +549,7 @@ mod high_cases { #[test] #[cfg(feature = "local_nodes_pool")] fn indy_attrib_requests_works_for_raw_value() { - let (wallet_handle, pool_handle, did,_) = utils::setup_new_identity(); + let (wallet_handle, pool_handle, did, _) = utils::setup_new_identity(); let attrib_request = ledger::build_attrib_request(&did, &did, @@ -571,7 +571,7 @@ mod high_cases { #[test] #[cfg(feature = "local_nodes_pool")] fn indy_attrib_requests_works_for_hash_value() { - let (wallet_handle, pool_handle, did,_) = utils::setup_new_identity(); + let (wallet_handle, pool_handle, did, _) = utils::setup_new_identity(); let mut ctx = Hasher::new(MessageDigest::sha256()).unwrap(); ctx.update(&ATTRIB_RAW_DATA.as_bytes()).unwrap(); @@ -597,7 +597,7 @@ mod high_cases { #[test] #[cfg(feature = "local_nodes_pool")] fn indy_attrib_requests_works_for_encrypted_value() { - let (wallet_handle, pool_handle, did,_) = utils::setup_new_identity(); + let (wallet_handle, pool_handle, did, _) = utils::setup_new_identity(); let key = secretbox::gen_key(); let nonce = secretbox::gen_nonce(); @@ -623,7 +623,7 @@ mod high_cases { #[test] #[cfg(feature = "local_nodes_pool")] fn indy_get_attrib_requests_works_for_default_submitter_did() { - let (wallet_handle, pool_handle, did,_) = utils::setup_new_identity(); + let (wallet_handle, pool_handle, did, _) = utils::setup_new_identity(); let attrib_request = ledger::build_attrib_request(&did, &did, @@ -1668,6 +1668,160 @@ mod high_cases { assert!(response_metadata["lastSeqNo"].as_u64().is_none()); } } + + mod auth_rule { + use super::*; + + const ADD_AUTH_ACTION: &str = "ADD"; + const EDIT_AUTH_ACTION: &str = "EDIT"; + const FIELD: &str = "role"; + const OLD_VALUE: &str = "0"; + const NEW_VALUE: &str = "101"; + const ROLE_CONSTRAINT: &str = r#"{ + "sig_count": 1, + "metadata": {}, + "role": "0", + "constraint_id": "ROLE", + "need_to_be_owner": false + }"#; + + #[test] + fn indy_build_auth_rule_request_works_for_add_action() { + let expected_result = json!({ + "type": constants::AUTH_RULE, + "auth_type": constants::NYM, + "field": FIELD, + "new_value": NEW_VALUE, + "auth_action": ADD_AUTH_ACTION, + "constraint": json!({ + "sig_count": 1, + "metadata": {}, + "role": "0", + "constraint_id": "ROLE", + "need_to_be_owner": false + }), + }); + + let request = ledger::build_auth_rule_request(DID_TRUSTEE, + constants::NYM, + &ADD_AUTH_ACTION, + FIELD, + None, + NEW_VALUE, + ROLE_CONSTRAINT).unwrap(); + check_request(&request, expected_result); + } + + #[test] + fn indy_build_auth_rule_request_works_for_edit_action() { + let expected_result = json!({ + "type": constants::AUTH_RULE, + "auth_type": constants::NYM, + "field": FIELD, + "old_value": OLD_VALUE, + "new_value": NEW_VALUE, + "auth_action": EDIT_AUTH_ACTION, + "constraint": json!({ + "sig_count": 1, + "metadata": {}, + "role": "0", + "constraint_id": "ROLE", + "need_to_be_owner": false + }), + }); + + let request = ledger::build_auth_rule_request(DID_TRUSTEE, + constants::NYM, + &EDIT_AUTH_ACTION, + FIELD, + Some(OLD_VALUE), + NEW_VALUE, + ROLE_CONSTRAINT).unwrap(); + check_request(&request, expected_result); + } + + + #[test] + fn indy_build_auth_rule_request_works_for_complex_constraint() { + let constraint = r#"{ + "constraint_id": "AND", + "auth_constraints": [ + { + "constraint_id": "ROLE", + "role": "0", + "sig_count": 1, + "need_to_be_owner": false, + "metadata": {} + }, + { + "constraint_id": "OR", + "auth_constraints": [ + { + "constraint_id": "ROLE", + "role": "0", + "sig_count": 1, + "need_to_be_owner": false, + "metadata": {} + }, + { + "constraint_id": "ROLE", + "role": "0", + "sig_count": 1 + } + ] + } + ] + }"#; + + let expected_result = json!({ + "type": constants::AUTH_RULE, + "auth_type": constants::NYM, + "field": FIELD, + "new_value": NEW_VALUE, + "auth_action": ADD_AUTH_ACTION, + "constraint": serde_json::from_str::(constraint).unwrap(), + }); + + let request = ledger::build_auth_rule_request(DID_TRUSTEE, + constants::NYM, + &ADD_AUTH_ACTION, + FIELD, + None, + NEW_VALUE, + constraint).unwrap(); + check_request(&request, expected_result); + } + + #[test] + fn indy_build_auth_rule_request_works_for_invalid_constraint() { + let res = ledger::build_auth_rule_request(DID_TRUSTEE, + constants::NYM, + &ADD_AUTH_ACTION, + FIELD, + None, + NEW_VALUE, + r#"{"field":"value"}"#); + assert_code!(ErrorCode::CommonInvalidStructure, res); + } + + #[test] + #[cfg(feature = "local_nodes_pool")] + fn indy_auth_rule_request_works() { + let (wallet_handle, pool_handle, trustee_did) = utils::setup_trustee(); + + let auth_rule_request = ledger::build_auth_rule_request(&trustee_did, + constants::NYM, + &ADD_AUTH_ACTION, + FIELD, + None, + NEW_VALUE, + ROLE_CONSTRAINT).unwrap(); + let response = ledger::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &auth_rule_request).unwrap(); + pool::check_response_type(&response, ResponseType::REPLY); + + utils::tear_down_with_wallet_and_pool(wallet_handle, pool_handle); + } + } } mod medium_cases { diff --git a/libindy/tests/utils/ledger.rs b/libindy/tests/utils/ledger.rs index b0db88179d..4b84c91021 100644 --- a/libindy/tests/utils/ledger.rs +++ b/libindy/tests/utils/ledger.rs @@ -187,10 +187,10 @@ pub fn register_transaction_parser_for_sp(txn_type: &str, parse: CustomTransacti let err = unsafe { indy_register_transaction_parser_for_sp(command_handle, - txn_type.as_ptr(), - Some(parse), - Some(free), - cb) + txn_type.as_ptr(), + Some(parse), + Some(free), + cb) }; super::results::result_to_empty(err, receiver) @@ -200,6 +200,16 @@ pub fn get_response_metadata(response: &str) -> Result { ledger::get_response_metadata(response).wait() } +pub fn build_auth_rule_request(submitter_did: &str, + auth_type: &str, + auth_action: &str, + field: &str, + old_value: Option<&str>, + new_value: &str, + constraint: &str, ) -> Result { + ledger::build_auth_rule_request(submitter_did, auth_type, auth_action, field, old_value, new_value, constraint).wait() +} + pub fn post_entities() -> (&'static str, &'static str, &'static str) { lazy_static! { static ref COMMON_ENTITIES_INIT: Once = ONCE_INIT; diff --git a/wrappers/rust/indy-sys/src/ledger.rs b/wrappers/rust/indy-sys/src/ledger.rs index f76620284c..2263ae5a03 100644 --- a/wrappers/rust/indy-sys/src/ledger.rs +++ b/wrappers/rust/indy-sys/src/ledger.rs @@ -221,6 +221,17 @@ extern { pub fn indy_get_response_metadata(command_handle: Handle, response: CString, cb: Option) -> Error; + + #[no_mangle] + pub fn indy_build_auth_rule_request(command_handle: Handle, + submitter_did: CString, + auth_type: CString, + auth_action: CString, + field: CString, + old_value: CString, + new_value: CString, + constraint: CString, + cb: Option) -> Error; } pub type CustomTransactionParser = extern fn(reply_from_node: CString, parsed_sp: *mut CString) -> Error; diff --git a/wrappers/rust/src/ledger.rs b/wrappers/rust/src/ledger.rs index 3d8aa37807..5adc3b7c71 100644 --- a/wrappers/rust/src/ledger.rs +++ b/wrappers/rust/src/ledger.rs @@ -85,7 +85,7 @@ fn _submit_action(command_handle: IndyHandle, pool_handle: IndyHandle, request_j let nodes_str = opt_c_str!(nodes); ErrorCode::from(unsafe { - ledger::indy_submit_action(command_handle, pool_handle, request_json.as_ptr(), opt_c_ptr!(nodes, nodes_str), wait_timeout.unwrap_or(-1), cb) + ledger::indy_submit_action(command_handle, pool_handle, request_json.as_ptr(), opt_c_ptr!(nodes, nodes_str), wait_timeout.unwrap_or(-1), cb) }) } @@ -259,7 +259,7 @@ pub fn build_get_txn_request(submitter_did: Option<&str>, ledger_type: Option<&s ResultHandler::str(command_handle, err, receiver) } -fn _build_get_txn_request(command_handle: IndyHandle, submitter_did: Option<&str>, ledger_type: Option<&str>, seq_no: i32, cb: Option) -> ErrorCode { +fn _build_get_txn_request(command_handle: IndyHandle, submitter_did: Option<&str>, ledger_type: Option<&str>, seq_no: i32, cb: Option) -> ErrorCode { let submitter_did_str = opt_c_str!(submitter_did); let ledger_type_str = opt_c_str!(ledger_type); @@ -566,7 +566,7 @@ fn _build_get_validator_info_request(command_handle: IndyHandle, submitter_did: let submitter_did = c_str!(submitter_did); ErrorCode::from(unsafe { - ledger::indy_build_get_validator_info_request(command_handle, submitter_did.as_ptr(), cb) + ledger::indy_build_get_validator_info_request(command_handle, submitter_did.as_ptr(), cb) }) } @@ -890,7 +890,7 @@ pub fn parse_get_revoc_reg_response(get_revoc_reg_response: &str) -> Box) -> ErrorCode { let get_revoc_reg_response = c_str!(get_revoc_reg_response); - ErrorCode::from(unsafe { ledger::indy_parse_get_revoc_reg_response(command_handle,get_revoc_reg_response.as_ptr(), cb) }) + ErrorCode::from(unsafe { ledger::indy_parse_get_revoc_reg_response(command_handle, get_revoc_reg_response.as_ptr(), cb) }) } /// Builds a GET_REVOC_REG_DELTA request. Request to get the delta of the accumulated state of the Revocation Registry. @@ -947,7 +947,7 @@ pub fn parse_get_revoc_reg_delta_response(get_revoc_reg_delta_response: &str) -> fn _parse_get_revoc_reg_delta_response(command_handle: IndyHandle, get_revoc_reg_delta_response: &str, cb: Option) -> ErrorCode { let get_revoc_reg_delta_response = c_str!(get_revoc_reg_delta_response); - ErrorCode::from(unsafe { ledger::indy_parse_get_revoc_reg_delta_response(command_handle,get_revoc_reg_delta_response.as_ptr(), cb) }) + ErrorCode::from(unsafe { ledger::indy_parse_get_revoc_reg_delta_response(command_handle, get_revoc_reg_delta_response.as_ptr(), cb) }) } /// Parse transaction response to fetch metadata. @@ -991,5 +991,57 @@ pub fn get_response_metadata(response: &str) -> Box) -> ErrorCode { let response = c_str!(response); - ErrorCode::from(unsafe { ledger::indy_get_response_metadata(command_handle,response.as_ptr(), cb) }) + ErrorCode::from(unsafe { ledger::indy_get_response_metadata(command_handle, response.as_ptr(), cb) }) } + +/// Builds a AUTH_RULE request. +/// +/// # Arguments +/// * `auth_type`: +/// * `field`: +/// * `auth_action`: +/// * `old_value`: +/// * `new_value`: +/// * `constraint`: +/// +/// # Returns +/// Request result as json. +pub fn build_auth_rule_request(submitter_did: &str, auth_type: &str, auth_action: &str, field: &str, + old_value: Option<&str>, new_value: &str, constraint: &str) -> Box> { + let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string(); + + let err = _build_auth_rule_request(command_handle, submitter_did, auth_type, auth_action, field, old_value, new_value, constraint, cb); + + ResultHandler::str(command_handle, err, receiver) +} + +fn _build_auth_rule_request(command_handle: IndyHandle, + submitter_did: &str, + auth_type: &str, + auth_action: &str, + field: &str, + old_value: Option<&str>, + new_value: &str, + constraint: &str, + cb: Option) -> ErrorCode { + let submitter_did = c_str!(submitter_did); + let auth_type = c_str!(auth_type); + let auth_action = c_str!(auth_action); + let field = c_str!(field); + let new_value = c_str!(new_value); + let constraint = c_str!(constraint); + + let old_value_str = opt_c_str!(old_value); + + ErrorCode::from(unsafe { + ledger::indy_build_auth_rule_request(command_handle, + submitter_did.as_ptr(), + auth_type.as_ptr(), + auth_action.as_ptr(), + field.as_ptr(), + opt_c_ptr!(old_value, old_value_str), + new_value.as_ptr(), + constraint.as_ptr(), + cb) + }) +} \ No newline at end of file diff --git a/wrappers/rust/tests/ledger.rs b/wrappers/rust/tests/ledger.rs index 52c2115f81..fa9211796b 100644 --- a/wrappers/rust/tests/ledger.rs +++ b/wrappers/rust/tests/ledger.rs @@ -1,9 +1,12 @@ -#[macro_use] extern crate serde_json; -#[macro_use] extern crate serde_derive; +#[macro_use] +extern crate serde_json; +#[macro_use] +extern crate serde_derive; extern crate rmp_serde; extern crate byteorder; extern crate indyrs as indy; extern crate futures; + #[allow(unused_variables)] #[allow(unused_macros)] #[allow(dead_code)] @@ -133,7 +136,7 @@ mod test_submit_request { mod test_submit_action { use super::*; - const NODES : &str = "[\"Node1\", \"Node2\"]"; + const NODES: &str = "[\"Node1\", \"Node2\"]"; #[test] #[ignore] // TODO: restore after IS-1027 will be fixed @@ -407,7 +410,7 @@ mod test_build_get_attrib_request { mod test_build_schema_request { use super::*; - const SCHEMA_DATA : &str = r#"{"id":"id","attrNames": ["name", "male"],"name":"gvt2","version":"3.1","ver":"1.0"}"#; + const SCHEMA_DATA: &str = r#"{"id":"id","attrNames": ["name", "male"],"name":"gvt2","version":"3.1","ver":"1.0"}"#; #[test] pub fn build_schema_request_success() { @@ -425,9 +428,9 @@ mod test_build_schema_request { #[cfg(test)] mod test_build_get_schema_request { -use super::*; + use super::*; - const SCHEMA_REQUEST : &str = "5LEV4bTAXntXqmtLFm7yCS:2:bob:1.0"; + const SCHEMA_REQUEST: &str = "5LEV4bTAXntXqmtLFm7yCS:2:bob:1.0"; #[test] pub fn build_get_schema_request_success() { @@ -450,11 +453,11 @@ mod test_parse_get_schema_response { use super::*; - const SCHEMA_NAME : &str = "schema_1234"; - const SCHEMA_DATA : &str = r#"{"id":"schema_id1234","attrNames": ["name", "male"],"name":"schema_1234","version":"1.0","ver":"1.0"}"#; + const SCHEMA_NAME: &str = "schema_1234"; + const SCHEMA_DATA: &str = r#"{"id":"schema_id1234","attrNames": ["name", "male"],"name":"schema_1234","version":"1.0","ver":"1.0"}"#; - fn create_build_schema_request(did : &String) -> String { + fn create_build_schema_request(did: &String) -> String { format!("{}:2:{}:1.0", did, SCHEMA_NAME) } @@ -483,7 +486,7 @@ mod test_parse_get_schema_response { let schema_request = create_build_schema_request(&did); let schema_response = ledger::build_get_schema_request(Some(&did), &schema_request).wait().unwrap(); - let signed_response = ledger::sign_request(wallet.handle, &did,&schema_response).wait().unwrap(); + let signed_response = ledger::sign_request(wallet.handle, &did, &schema_response).wait().unwrap(); let submit_response = ledger::submit_request(pool_handle, &signed_response).wait().unwrap(); let parse_response = ledger::parse_get_schema_response(&submit_response).wait(); @@ -522,7 +525,7 @@ mod test_build_get_ddo_request { mod test_build_get_txn_request { use super::*; - const LEDGER_TYPE : &str = "DOMAIN"; + const LEDGER_TYPE: &str = "DOMAIN"; #[test] pub fn build_get_txn_request_success() { @@ -542,10 +545,10 @@ mod test_build_get_txn_request { mod test_build_cred_def_request { use super::*; - const CRED_DATA : &str = r#"{"ver":"1.0","id":"V4SGRU86Z58d6TV7PBUe6f:3:CL:17:oI6Iokv","schemaId":"17","type":"CL","tag":"oI6Iokv","value":{"primary":{"n":"87178281071734731437690387382922138711010162107879888888538848407132327215161696479014638246148780516059076502007170233816521638866237445955186196199106181664196333035350522256775772678749757516076687671733088043974750225859037634391059057871128952528114293385763258675546471992534732373945591487042489023109902330242980705545998552851661474245748466697559479508930710234503328250288511766352977719334252928597855882930620741923986586828547412389638821815758450532251881301327049927072714545264108360496728434366393519356711418047944068773770531352206244052618670493983767902201878934735288733850555036281883721724473","s":"66794590351311400173440340223561508784777853797981871904981559245334503567545616382611784848902543717386870008558289905316601662574754089209687052710438230437549560386636286514822680768065835610624750399055088116166226098175424830519537908801592274839622946402090491946787040058370552124732885892610142242847158959492000732292603755213902976259446731410240912872744210451254301242220759673686769861789834996124153811460984114732824978048021325148492655982695079333718710090836034672739682282204904856516947015563681443657793597047393731812247221167838278986153621564706820976058621996938916226023920421313258317181056","r":{"height":"37686658568948037814775431903843597441856100114754323955796133079330648476309192012260294209465266635551131504125646637359931844595436529982289207908218765877672222632310887737940054188921134584912244256324727048869497937750475441196124576035922245172355820888415660512858847440533214955712359488689065763607483137995713620001810321655685884305156101062519673602853819411046367019986397235673847881046529391589711229735614071805410066894389088951657447726215788267372471488185033424222037788505918934857840957649277458736101301203881379280675945440723899652144116975079241713669490809165909240425120649887001447597783","sex":"48901017446440182649799731593114947230876351500273905015595989118217119375071111218399500737051508041416910144890371937193478691958771514378058820388069120931504416289663010431000145369715463131882383259114210820041731832960312557792681552574471886139487662967612807830334835729846093444859302732007584479807271091676491277902271511164922767210557187133481955551837663018165430244652992048757580783775433571336475692686259720997931194126203237043117966211161878071070916577025579669942228991696500136399569383974985399786080235342264485395522119939857486145401501612186163491615961653478438596959371113747671419654818","master_secret":"25754344723836699563584283879786692153622691083042382144160949511089528018631287834606498465418239311334501386316618629687258527283908520406207259178795217648481719864528515688115872808761112818709464686844054961387398147908732686218740513751960844653382166618983380191016571483892249629309506399346596975262589381752411984820505602091163687287542251803844421163362364666975191601496467090517324300542321861313152630025880504086070664031524805153571288074723002683472372414034607393588926109015678216745625826790077479058525170476570603845174669212586627449339894597259739762350550126584394404404482135882343197379054","name":"64945144723199018124037264140277156942131666148001245998219662472757345342279533884405888431954009830746588251472121029944168008438815350643138701794229741155411122621890661138856631059298571458398258239896113210276837384872922411226059610000961503919325158321529528085516642820682380678880886510720705463915144189095545183388444662260696183777535832602518582169729325489244691039221691384084009024188000745680035168934609700642727769603625029893488551202843527601643121220149122355960460523112480070939364242895718918315978456710031746858656148388609050488969420517950113219916527876709626082332309036117494497571230","age":"32059832863983999153613274260157019698296212529496396734792926477728751870868732126531732944880026440901943732956875433636855727848522486073745001899386738358016223503298068118020520201025961660332519845724521320552467451946852925824035412812595344753770029091958417300642692814810865758776286263929051571009155820474717897179825570107678882180230319004359558595714472285100325554837250772201405847343231203624749918461130474867722155978675551762505078508248381791048831193422832357874770535478244636601382323151375446307087219224928662366021820679699538198192887109930714869161019271417169222414370495648047714662103"},"rctxt":"38527464755916130963069611882293312815641859720607042775748742527688895624917359948168832828223678535804570958646474457323858571801037955359525462917173252086033591899208879285429574561167189107147758287137082689831331351781369164690717667586513821072095969666206581907243540078811132148136508600170388059098530570400824663936962403223100603326027117401899329035603739144303108339956544437073624926208818126402005595194344120188160525632489014089138283290414616529527375527577666875823786710497945303252443476610222721607664991987281949777517734685590949741562190122640202895612444667451959072089271004850428610427341","z":"31160349078984317779569363785252606468286101126154161634595102825752576352018565401209247600497171866986884547654707390053445672860929599916189762737605262398652714436350679825010487409345252016639698884761154432723648619393558760904141612222413004613912305317054390982133492273484244661652402423836430130022761985374095739624351663212686292616011934960947889676162946869205272435766196882679460333258355511812361345778943009086137697548566706243827603133668933678120765799991107515465495261132740007129958253450651703438567276912235691326876396719017894799034243480316169679472944643292666194979984921170821328746189"}}}"#; + const CRED_DATA: &str = r#"{"ver":"1.0","id":"V4SGRU86Z58d6TV7PBUe6f:3:CL:17:oI6Iokv","schemaId":"17","type":"CL","tag":"oI6Iokv","value":{"primary":{"n":"87178281071734731437690387382922138711010162107879888888538848407132327215161696479014638246148780516059076502007170233816521638866237445955186196199106181664196333035350522256775772678749757516076687671733088043974750225859037634391059057871128952528114293385763258675546471992534732373945591487042489023109902330242980705545998552851661474245748466697559479508930710234503328250288511766352977719334252928597855882930620741923986586828547412389638821815758450532251881301327049927072714545264108360496728434366393519356711418047944068773770531352206244052618670493983767902201878934735288733850555036281883721724473","s":"66794590351311400173440340223561508784777853797981871904981559245334503567545616382611784848902543717386870008558289905316601662574754089209687052710438230437549560386636286514822680768065835610624750399055088116166226098175424830519537908801592274839622946402090491946787040058370552124732885892610142242847158959492000732292603755213902976259446731410240912872744210451254301242220759673686769861789834996124153811460984114732824978048021325148492655982695079333718710090836034672739682282204904856516947015563681443657793597047393731812247221167838278986153621564706820976058621996938916226023920421313258317181056","r":{"height":"37686658568948037814775431903843597441856100114754323955796133079330648476309192012260294209465266635551131504125646637359931844595436529982289207908218765877672222632310887737940054188921134584912244256324727048869497937750475441196124576035922245172355820888415660512858847440533214955712359488689065763607483137995713620001810321655685884305156101062519673602853819411046367019986397235673847881046529391589711229735614071805410066894389088951657447726215788267372471488185033424222037788505918934857840957649277458736101301203881379280675945440723899652144116975079241713669490809165909240425120649887001447597783","sex":"48901017446440182649799731593114947230876351500273905015595989118217119375071111218399500737051508041416910144890371937193478691958771514378058820388069120931504416289663010431000145369715463131882383259114210820041731832960312557792681552574471886139487662967612807830334835729846093444859302732007584479807271091676491277902271511164922767210557187133481955551837663018165430244652992048757580783775433571336475692686259720997931194126203237043117966211161878071070916577025579669942228991696500136399569383974985399786080235342264485395522119939857486145401501612186163491615961653478438596959371113747671419654818","master_secret":"25754344723836699563584283879786692153622691083042382144160949511089528018631287834606498465418239311334501386316618629687258527283908520406207259178795217648481719864528515688115872808761112818709464686844054961387398147908732686218740513751960844653382166618983380191016571483892249629309506399346596975262589381752411984820505602091163687287542251803844421163362364666975191601496467090517324300542321861313152630025880504086070664031524805153571288074723002683472372414034607393588926109015678216745625826790077479058525170476570603845174669212586627449339894597259739762350550126584394404404482135882343197379054","name":"64945144723199018124037264140277156942131666148001245998219662472757345342279533884405888431954009830746588251472121029944168008438815350643138701794229741155411122621890661138856631059298571458398258239896113210276837384872922411226059610000961503919325158321529528085516642820682380678880886510720705463915144189095545183388444662260696183777535832602518582169729325489244691039221691384084009024188000745680035168934609700642727769603625029893488551202843527601643121220149122355960460523112480070939364242895718918315978456710031746858656148388609050488969420517950113219916527876709626082332309036117494497571230","age":"32059832863983999153613274260157019698296212529496396734792926477728751870868732126531732944880026440901943732956875433636855727848522486073745001899386738358016223503298068118020520201025961660332519845724521320552467451946852925824035412812595344753770029091958417300642692814810865758776286263929051571009155820474717897179825570107678882180230319004359558595714472285100325554837250772201405847343231203624749918461130474867722155978675551762505078508248381791048831193422832357874770535478244636601382323151375446307087219224928662366021820679699538198192887109930714869161019271417169222414370495648047714662103"},"rctxt":"38527464755916130963069611882293312815641859720607042775748742527688895624917359948168832828223678535804570958646474457323858571801037955359525462917173252086033591899208879285429574561167189107147758287137082689831331351781369164690717667586513821072095969666206581907243540078811132148136508600170388059098530570400824663936962403223100603326027117401899329035603739144303108339956544437073624926208818126402005595194344120188160525632489014089138283290414616529527375527577666875823786710497945303252443476610222721607664991987281949777517734685590949741562190122640202895612444667451959072089271004850428610427341","z":"31160349078984317779569363785252606468286101126154161634595102825752576352018565401209247600497171866986884547654707390053445672860929599916189762737605262398652714436350679825010487409345252016639698884761154432723648619393558760904141612222413004613912305317054390982133492273484244661652402423836430130022761985374095739624351663212686292616011934960947889676162946869205272435766196882679460333258355511812361345778943009086137697548566706243827603133668933678120765799991107515465495261132740007129958253450651703438567276912235691326876396719017894799034243480316169679472944643292666194979984921170821328746189"}}}"#; #[test] - pub fn test_build_cred_def_request_success(){ + pub fn test_build_cred_def_request_success() { let wallet = Wallet::new(); let (did, _) = did::create_and_store_my_did(wallet.handle, "{}").wait().unwrap(); @@ -560,75 +563,75 @@ mod test_build_cred_def_request { } #[cfg(test)] -mod test_build_get_cred_def_request { - -} +mod test_build_get_cred_def_request {} #[cfg(test)] -mod test_build_node_request { - -} +mod test_build_node_request {} #[cfg(test)] -mod test_build_get_validator_info_request { - -} +mod test_build_get_validator_info_request {} #[cfg(test)] -mod test_build_pool_config_request { - -} +mod test_build_pool_config_request {} #[cfg(test)] -mod test_build_pool_restart_request { - -} +mod test_build_pool_restart_request {} #[cfg(test)] -mod test_build_pool_upgrade_request { - -} +mod test_build_pool_upgrade_request {} #[cfg(test)] -mod test_build_revoc_reg_def_request { - -} +mod test_build_revoc_reg_def_request {} #[cfg(test)] -mod test_build_get_revoc_reg_def_request { - -} +mod test_build_get_revoc_reg_def_request {} #[cfg(test)] -mod test_parse_get_revoc_reg_def_response { - -} +mod test_parse_get_revoc_reg_def_response {} #[cfg(test)] -mod test_build_revoc_reg_entry_request { -} +mod test_build_revoc_reg_entry_request {} #[cfg(test)] -mod test_build_get_revoc_reg_request { - -} +mod test_build_get_revoc_reg_request {} #[cfg(test)] -mod test_parse_get_revoc_reg_response { - -} +mod test_parse_get_revoc_reg_response {} #[cfg(test)] -mod test_build_get_revoc_reg_delta_request { - -} +mod test_build_get_revoc_reg_delta_request {} #[cfg(test)] -mod test_parse_get_revoc_reg_delta_response { +mod test_parse_get_revoc_reg_delta_response {} -} +#[cfg(test)] +mod test_register_transaction_parser_for_sp {} #[cfg(test)] -mod test_register_transaction_parser_for_sp { +mod test_build_auth_rule_request { + use super::*; -} + const DID: &str = "VsKV7grR1BUE29mG2Fm2kX"; + const NYM_AUTH_TYPE: &str = "1"; + const ADD_AUTH_ACTION: &str = "ADD"; + const FIELD: &str = "role"; + const NEW_VALUE: &str = "101"; + const ROLE_CONSTRAINT: &str = r#"{ + "sig_count": 1, + "metadata": {}, + "role": "0", + "constraint_id": "ROLE", + "need_to_be_owner": false + }"#; + + #[test] + pub fn build_auth_rule_request_success() { + let _nym_result = ledger::build_auth_rule_request(DID, + NYM_AUTH_TYPE, + &ADD_AUTH_ACTION, + FIELD, + None, + NEW_VALUE, + ROLE_CONSTRAINT).wait().unwrap(); + } +} \ No newline at end of file From 63f950cd3e30d403f9584483c45241eda462bb28 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 5 Mar 2019 10:57:08 +0300 Subject: [PATCH 02/18] Updated Java wrapper Signed-off-by: artem.ivanov --- .../org/hyperledger/indy/sdk/LibIndy.java | 1 + .../hyperledger/indy/sdk/ledger/Ledger.java | 46 +++++++++++++ .../indy/sdk/ledger/AuthRuleRequestsTest.java | 65 +++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AuthRuleRequestsTest.java diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java index 76daa98324..84459dccfa 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java @@ -70,6 +70,7 @@ public interface API extends Library { public int indy_build_get_revoc_reg_delta_request(int command_handle, String submitter_did, String revoc_reg_def_id, long from, long to, Callback cb); public int indy_parse_get_revoc_reg_delta_response(int command_handle, String get_revoc_reg_delta_response, Callback cb); public int indy_get_response_metadata(int command_handle, String response, Callback cb); + public int indy_build_auth_rule_request(int command_handle, String submitter_did, String auth_type, String auth_action, String field, String old_value, String new_value, String constraint, Callback cb); // did.rs diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java index c936466f7d..f30ff33dbf 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java @@ -1265,4 +1265,50 @@ public static CompletableFuture getResponseMetadata( return future; } + + /** + * Builds a AUTH_RULE request. + * + * @param submitterDid DID of the submitter stored in secured Wallet. + * @param authType - + * @param authAction - + * @param field - + * @param oldValue - + * @param newValue - + * @param constraint - + + * @return A future resolving to a request result as json. + * @throws IndyException Thrown if an error occurs when calling the underlying SDK. + */ + public static CompletableFuture buildAuthRuleRequest( + String submitterDid, + String authType, + String authAction, + String field, + String oldValue, + String newValue, + String constraint) throws IndyException { + + ParamGuard.notNullOrWhiteSpace(submitterDid, "submitterDid"); + ParamGuard.notNullOrWhiteSpace(authType, "authType"); + ParamGuard.notNullOrWhiteSpace(authAction, "authAction"); + + CompletableFuture future = new CompletableFuture(); + int commandHandle = addFuture(future); + + int result = LibIndy.api.indy_build_auth_rule_request( + commandHandle, + submitterDid, + authType, + authAction, + field, + oldValue, + newValue, + constraint, + buildRequestCb); + + checkResult(future, result); + + return future; + } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AuthRuleRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AuthRuleRequestsTest.java new file mode 100644 index 0000000000..4c3f019b83 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AuthRuleRequestsTest.java @@ -0,0 +1,65 @@ +package org.hyperledger.indy.sdk.ledger; + +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.json.JSONObject; +import org.junit.Test; + +public class AuthRuleRequestsTest extends IndyIntegrationTest { + + private String authType = "NYM"; + private String field = "role"; + private String newValue = "101"; + private JSONObject constraint = new JSONObject() + .put("sig_count", 1) + .put("role", "0") + .put("constraint_id", "ROLE") + .put("need_to_be_owner", false); + + @Test + public void testBuildAuthRuleRequestWorksForAddAction() throws Exception { + String addAuthAction = "ADD"; + + JSONObject expectedResult = new JSONObject() + .put("identifier", DID) + .put("operation", + new JSONObject() + .put("type", "120") + .put("auth_type", authType) + .put("auth_action", addAuthAction) + .put("field", field) + .put("new_value", newValue) + .put("constraint", constraint) + ); + + String request = Ledger.buildAuthRuleRequest(DID, authType, addAuthAction, field, null, newValue, constraint.toString()).get(); + + assert (new JSONObject(request).toMap().entrySet() + .containsAll( + expectedResult.toMap().entrySet())); + } + + @Test + public void testBuildAuthRuleRequestWorksForEditAction() throws Exception { + String editAuthAction = "EDIT"; + String oldValue = "0"; + + JSONObject expectedResult = new JSONObject() + .put("identifier", DID) + .put("operation", + new JSONObject() + .put("type", "120") + .put("auth_type", authType) + .put("auth_action", editAuthAction) + .put("field", field) + .put("old_value", oldValue) + .put("new_value", newValue) + .put("constraint", constraint) + ); + + String request = Ledger.buildAuthRuleRequest(DID, authType, editAuthAction, field, oldValue, newValue, constraint.toString()).get(); + + assert (new JSONObject(request).toMap().entrySet() + .containsAll( + expectedResult.toMap().entrySet())); + } +} From e6f49d6ac0c1cf43b9d7c51e3f8db397573bd64b Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 5 Mar 2019 10:57:38 +0300 Subject: [PATCH 03/18] Updated NodeJs wrapper Signed-off-by: artem.ivanov --- wrappers/nodejs/README.md | 15 +++++++++++++++ wrappers/nodejs/src/index.js | 6 ++++++ wrappers/nodejs/src/indy.cc | 35 ++++++++++++++++++++++++++++++++++ wrappers/nodejs/test/ledger.js | 11 +++++++++++ 4 files changed, 67 insertions(+) diff --git a/wrappers/nodejs/README.md b/wrappers/nodejs/README.md index b7c197aa1b..416c25ec93 100644 --- a/wrappers/nodejs/README.md +++ b/wrappers/nodejs/README.md @@ -1748,6 +1748,21 @@ Parse a GET\_REVOC\_REG\_DELTA response to get Revocation Registry Delta in the Errors: `Common*` +#### buildAuthRuleRequest \( submitterDid, authType, authAction, field, oldValue, newValue, constraint \) -> request + +Builds a AUTH_RULE request. + +* `submitterDid`: String - \(Optional\) DID of the read request sender \(if not provided then default Libindy DID will be used\). +* `authType`: String - +* `authAction`: String - +* `field`: String - +* `oldValue`: String - \(Optional\) +* `newValue`: String - +* `constraint`: String - +* __->__ `request`: Json + +Errors: `Common*` + #### getResponseMetadata \( response \) -> responseMetadata Parse transaction response to fetch metadata. diff --git a/wrappers/nodejs/src/index.js b/wrappers/nodejs/src/index.js index 2614cd899c..2a61c5b72d 100644 --- a/wrappers/nodejs/src/index.js +++ b/wrappers/nodejs/src/index.js @@ -541,6 +541,12 @@ indy.parseGetRevocRegDeltaResponse = function parseGetRevocRegDeltaResponse (get return cb.promise } +indy.buildAuthRuleRequest = function buildAuthRuleRequest (submitterDid, authType, authAction, field, oldValue, newValue, constraint, cb) { + cb = wrapIndyCallback(cb, fromJson) + capi.buildAuthRuleRequest(submitterDid, authType, authAction, field, oldValue, newValue, toJson(constraint), cb) + return cb.promise +} + indy.getResponseMetadata = function getResponseMetadata (response, cb) { cb = wrapIndyCallback(cb, fromJson) capi.getResponseMetadata(toJson(response), cb) diff --git a/wrappers/nodejs/src/indy.cc b/wrappers/nodejs/src/indy.cc index b0a1228d3e..a57acfe314 100644 --- a/wrappers/nodejs/src/indy.cc +++ b/wrappers/nodejs/src/indy.cc @@ -2038,6 +2038,40 @@ NAN_METHOD(parseGetRevocRegDeltaResponse) { delete arg0; } +void buildAuthRuleRequest_cb(indy_handle_t handle, indy_error_t xerr, const char* arg0) { + IndyCallback* icb = IndyCallback::getCallback(handle); + if(icb != nullptr){ + icb->cbString(xerr, arg0); + } +} +NAN_METHOD(buildAuthRuleRequest) { + INDY_ASSERT_NARGS(buildAuthRuleRequest, 8) + INDY_ASSERT_STRING(buildAuthRuleRequest, 0, submitterDid) + INDY_ASSERT_STRING(buildAuthRuleRequest, 1, authType) + INDY_ASSERT_STRING(buildAuthRuleRequest, 2, authAction) + INDY_ASSERT_STRING(buildAuthRuleRequest, 3, field) + INDY_ASSERT_STRING(buildAuthRuleRequest, 4, oldValue) + INDY_ASSERT_STRING(buildAuthRuleRequest, 5, newValue) + INDY_ASSERT_STRING(buildAuthRuleRequest, 6, constraint) + INDY_ASSERT_FUNCTION(buildAuthRuleRequest, 7) + const char* arg0 = argToCString(info[0]); + const char* arg1 = argToCString(info[1]); + const char* arg2 = argToCString(info[2]); + const char* arg3 = argToCString(info[3]); + const char* arg4 = argToCString(info[4]); + const char* arg5 = argToCString(info[5]); + const char* arg6 = argToCString(info[6]); + IndyCallback* icb = argToIndyCb(info[7]); + indyCalled(icb, indy_build_auth_rule_request(icb->handle, arg0, arg1, arg2, arg3, arg4, arg5, arg6, buildAuthRuleRequest_cb)); + delete arg0; + delete arg1; + delete arg2; + delete arg3; + delete arg4; + delete arg5; + delete arg6; +} + void getResponseMetadata_cb(indy_handle_t handle, indy_error_t xerr, const char* arg0) { IndyCallback* icb = IndyCallback::getCallback(handle); if(icb != nullptr){ @@ -3115,6 +3149,7 @@ NAN_MODULE_INIT(InitAll) { Nan::Export(target, "parseGetRevocRegResponse", parseGetRevocRegResponse); Nan::Export(target, "buildGetRevocRegDeltaRequest", buildGetRevocRegDeltaRequest); Nan::Export(target, "parseGetRevocRegDeltaResponse", parseGetRevocRegDeltaResponse); + Nan::Export(target, "buildAuthRuleRequest", buildAuthRuleRequest); Nan::Export(target, "getResponseMetadata", getResponseMetadata); Nan::Export(target, "addWalletRecord", addWalletRecord); Nan::Export(target, "updateWalletRecordValue", updateWalletRecordValue); diff --git a/wrappers/nodejs/test/ledger.js b/wrappers/nodejs/test/ledger.js index 28cbb857a9..9883c07e45 100644 --- a/wrappers/nodejs/test/ledger.js +++ b/wrappers/nodejs/test/ledger.js @@ -151,6 +151,17 @@ test('ledger', async function (t) { req = await indy.signRequest(wh, myDid, req) res = await indy.submitAction(pool.handle, req, null, null) + var constraint = { + 'sig_count': 1, + 'metadata': {}, + 'role': '0', + 'constraint_id': 'ROLE', + 'need_to_be_owner': false + } + req = await indy.buildAuthRuleRequest(trusteeDid, 'NYM', 'ADD', 'role', null, '101', constraint) + res = await indy.signAndSubmitRequest(pool.handle, wh, trusteeDid, req) + t.is(res.op, 'REPLY') + await indy.closeWallet(wh) await indy.deleteWallet(walletConfig, walletCredentials) pool.cleanup() From 339bd32f7a7bc4dae6b97893c3e1ee7c0820ff15 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 5 Mar 2019 10:58:28 +0300 Subject: [PATCH 04/18] Updated Python wrapper Signed-off-by: artem.ivanov --- wrappers/python/indy/ledger.py | 58 ++++++++++++++++++ .../ledger/test_build_auth_rule_request.py | 61 +++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 wrappers/python/tests/ledger/test_build_auth_rule_request.py diff --git a/wrappers/python/indy/ledger.py b/wrappers/python/indy/ledger.py index 8700d60682..3bf6c038d7 100644 --- a/wrappers/python/indy/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -1261,3 +1261,61 @@ async def get_response_metadata(response: str) -> str: res = response_metadata.decode() logger.debug("get_response_metadata: <<< res: %r", res) return res + + +async def build_auth_rule_request(submitter_did: str, + auth_type: str, + auth_action: str, + field: str, + old_value: Optional[str], + new_value: str, + constraint: str) -> str: + """ + Builds a AUTH_RULE request. + + :param submitter_did: DID of the submitter stored in secured Wallet. + :param auth_type: + :param auth_action: + :param field: + :param old_value: + :param new_value: + :param constraint: + :return: Request result as json. + """ + + logger = logging.getLogger(__name__) + logger.debug("build_auth_rule_request: >>> submitter_did: %r, auth_type: %r, auth_action: %r, field: %r, " + "old_value: %r, new_value: %r, constraint: %r", + submitter_did, + auth_type, + auth_action, + field, + old_value, + new_value, + constraint) + + if not hasattr(build_auth_rule_request, "cb"): + logger.debug("build_auth_rule_request: Creating callback") + build_auth_rule_request.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_submitter_did = c_char_p(submitter_did.encode('utf-8')) + c_auth_type = c_char_p(auth_type.encode('utf-8')) + c_auth_action = c_char_p(auth_action.encode('utf-8')) + c_field = c_char_p(field.encode('utf-8')) + c_old_value = c_char_p(old_value.encode('utf-8')) if old_value is not None else None + c_new_value = c_char_p(new_value.encode('utf-8')) + c_constraint = c_char_p(constraint.encode('utf-8')) + + request_json = await do_call('indy_build_auth_rule_request', + c_submitter_did, + c_auth_type, + c_auth_action, + c_field, + c_old_value, + c_new_value, + c_constraint, + build_auth_rule_request.cb) + + res = request_json.decode() + logger.debug("build_auth_rule_request: <<< res: %r", res) + return res diff --git a/wrappers/python/tests/ledger/test_build_auth_rule_request.py b/wrappers/python/tests/ledger/test_build_auth_rule_request.py new file mode 100644 index 0000000000..2ce1bf675b --- /dev/null +++ b/wrappers/python/tests/ledger/test_build_auth_rule_request.py @@ -0,0 +1,61 @@ +from indy import ledger +from indy.error import * + +import json +import pytest + +identifier = "Th7MpTaRZVRYnPiabds81Y" +auth_type = "NYM" +add_auth_action = "ADD" +edit_auth_action = "EDIT" +field = 'role' +old_value = '0' +new_value = '101' +constraint = { + "sig_count": 1, + "metadata": {}, + "role": "0", + "constraint_id": "ROLE", + "need_to_be_owner": False +} + + +@pytest.mark.asyncio +async def test_build_auth_rule_request_works_for_add_auth_action(): + expected_request = { + "identifier": identifier, + "operation": { + "type": "120", + "auth_type": auth_type, + "auth_action": add_auth_action, + "field": field, + "new_value": new_value, + "constraint": constraint + } + } + + request = json.loads( + await ledger.build_auth_rule_request(identifier, auth_type, add_auth_action, field, None, new_value, + json.dumps(constraint))) + assert expected_request.items() <= request.items() + + +@pytest.mark.asyncio +async def test_build_auth_rule_request_works_for_edit_auth_action(): + expected_request = { + "identifier": identifier, + "operation": { + "type": "120", + "auth_type": auth_type, + "auth_action": edit_auth_action, + "field": field, + "old_value": old_value, + "new_value": new_value, + "constraint": constraint + } + } + + request = json.loads( + await ledger.build_auth_rule_request(identifier, auth_type, edit_auth_action, field, old_value, new_value, + json.dumps(constraint))) + assert expected_request.items() <= request.items() From 3a3f12b0380b58931cd096551fcf3b90b111a066 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 5 Mar 2019 11:43:17 +0300 Subject: [PATCH 05/18] Updated xCode wrapper Signed-off-by: artem.ivanov --- .../Case Tests/Ledger/LedgerBuildRequest.mm | 38 +++++++++++++++++++ .../Indy-demoTests/Test Utils/LedgerUtils.h | 10 +++++ .../Indy-demoTests/Test Utils/LedgerUtils.mm | 32 ++++++++++++++++ .../ios/libindy-pod/Indy/Wrapper/IndyLedger.h | 25 +++++++++++- .../libindy-pod/Indy/Wrapper/IndyLedger.mm | 31 +++++++++++++++ 5 files changed, 135 insertions(+), 1 deletion(-) diff --git a/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Ledger/LedgerBuildRequest.mm b/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Ledger/LedgerBuildRequest.mm index 690bc320aa..50bea227cf 100644 --- a/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Ledger/LedgerBuildRequest.mm +++ b/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Ledger/LedgerBuildRequest.mm @@ -641,4 +641,42 @@ - (void)testBuildGetTxnRequest { XCTAssertTrue([getTxnRequest contains:expectedResult], @"getTxnRequest json doesn't contain expectedResult json"); } +// MARK: Auth Rule request + +- (void)testBuildAuthRuleRequestsWorks { + NSDictionary *constraint = @{ + @"sig_count": @(1)", + @"role": @"0", + @"constraint_id": @"ROLE", + @"need_to_be_owner": false + }; + + NSDictionary *expectedResult = @{ + @"identifier": [TestUtils trusteeDid], + @"operation": @{ + @"type": @"120", + @"auth_type": @"1", + @"auth_action": @"ADD", + @"field": @"role", + @"new_value": @"101", + @"constraint": constraint, + } + }; + + NSString *requestJson; + ret = [[LedgerUtils sharedInstance] buildAuthRuleRequestWithSubmitterDid:[TestUtils trusteeDid] + authType:@"NYM" + authAction:@"ADD" + field:@"role" + oldValue:nil + newValue:@"101" + constraint:[NSDictionary toString:constraint]" + outRequest:&requestJson]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::buildNymRequestWithSubmitterDid() failed!"); + + NSDictionary *request = [NSDictionary fromString:requestJson]; + + XCTAssertTrue([request contains:expectedResult], @"Request doesn't contain expectedResult"); +} + @end diff --git a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.h b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.h index b01cba99e1..a690af5c41 100644 --- a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.h +++ b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.h @@ -179,6 +179,16 @@ requestJson:(NSString *)requestJson resultJson:(NSString **)resultJson; +// MARK: - Auth Rule request +- (NSError *)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid + authType:(NSString *)authType + authAction:(NSString *)authAction + field:(NSString *)field + oldValue:(NSString *)oldValue + newValue:(NSString *)newValue + constraint:(NSString *)constraint + outRequest:(NSString **)resultJson; + // MARK: - Response Metadata - (NSError *)getResponseMetadata:(NSString *)response responseMetadata:(NSString **)responseMetadata; diff --git a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.mm b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.mm index c99724d7fb..9aaf83cdea 100644 --- a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.mm +++ b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.mm @@ -729,6 +729,38 @@ - (NSError *)multiSignRequestWithWalletHandle:(IndyHandle)walletHandle return err; } +- (NSError *)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid + authType:(NSString *)authType + authAction:(NSString *)authAction + field:(NSString *)field + oldValue:(NSString *)oldValue + newValue:(NSString *)newValue + constraint:(NSString *)constraint + outRequest:(NSString **)resultJson { + XCTestExpectation *completionExpectation = [[XCTestExpectation alloc] initWithDescription:@"completion finished"]; + __block NSError *err = nil; + __block NSString *outJson = nil; + + [IndyLedger buildAuthRuleRequestWithSubmitterDid:submitterDid + authType:authType + authAction:authAction + field:field + oldValue:oldValue + newValue:newValue + constraint:constraint + completion:^(NSError *error, NSString *json) { + err = error; + outJson = json; + [completionExpectation fulfill]; + }]; + + [self waitForExpectations:@[completionExpectation] timeout:[TestUtils longTimeout]]; + + if (resultJson) {*resultJson = outJson;} + + return err; +} + - (NSError *)getResponseMetadata:(NSString *)response responseMetadata:(NSString **)responseMetadata { XCTestExpectation *completionExpectation = [[XCTestExpectation alloc] initWithDescription:@"completion finished"]; diff --git a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h index 66464febda..3a0582ab6e 100644 --- a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h +++ b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h @@ -568,7 +568,30 @@ */ + (void)parseGetRevocRegDeltaResponse:(NSString *)getRevocRegDeltaResponse completion:(void (^)(NSError *error, NSString *revocRegDefId, NSString *revocRegDeltaJson, NSNumber *timestamp))completion; - + +// MARK: - Auth Rule request + +/** + Builds a AUTH_RULE request. + + @param submitterDid DID of the submitter stored in secured Wallet. + @param authType + @param authAction + @param field + @param oldValue + @param newValue + @param constraint + @param completion Callback that takes command result as parameter. Returns request result as json. + */ ++ (void)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid + authType:(NSString *)authType + authAction:(NSString *)authAction + field:(NSString *)field + oldValue:(NSString *)oldValue + newValue:(NSString *)newValue + constraint:(NSString *)constraint + completion:(void (^)(NSError *error, NSString *requestJSON))completion; + /** Parse transaction response to fetch metadata. The important use case for this method is validation of Node's response freshens. diff --git a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.mm b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.mm index 2d373124b7..b2ec9876eb 100644 --- a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.mm +++ b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.mm @@ -706,6 +706,37 @@ + (void)parseGetRevocRegDeltaResponse:(NSString *)getRevocRegDeltaResponse } } ++ (void)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid + authType:(NSString *)authType + authAction:(NSString *)authAction + field:(NSString *)field + oldValue:(NSString *)oldValue + newValue:(NSString *)newValue + constraint:(NSString *)constraint + completion:(void (^)(NSError *error, NSString *requestJSON))completion { + indy_error_t ret; + + indy_handle_t handle = [[IndyCallbacks sharedInstance] createCommandHandleFor:completion]; + + + ret = indy_build_auth_rule_request(handle, + [submitterDid UTF8String], + [authType UTF8String], + [authAction UTF8String], + [field UTF8String], + [oldValue UTF8String], + [newValue UTF8String], + [constraint UTF8String], + IndyWrapperCommonStringCallback); + if (ret != Success) { + [[IndyCallbacks sharedInstance] deleteCommandHandleFor:handle]; + + dispatch_async(dispatch_get_main_queue(), ^{ + completion([NSError errorFromIndyError:ret], nil); + }); + } +} + + (void)getResponseMetadata:(NSString *)response completion:(void (^)(NSError *error, NSString *responseMetadata))completion { indy_error_t ret; From 6a3470ce9cb86953a90a051471fa802623b9b238 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 5 Mar 2019 11:43:17 +0300 Subject: [PATCH 06/18] Updated xCode wrapper Signed-off-by: artem.ivanov --- .../Case Tests/Ledger/LedgerBuildRequest.mm | 38 +++++++++++++++++++ .../Indy-demoTests/Test Utils/LedgerUtils.h | 10 +++++ .../Indy-demoTests/Test Utils/LedgerUtils.mm | 32 ++++++++++++++++ .../ios/libindy-pod/Indy/Wrapper/IndyLedger.h | 25 +++++++++++- .../libindy-pod/Indy/Wrapper/IndyLedger.mm | 31 +++++++++++++++ 5 files changed, 135 insertions(+), 1 deletion(-) diff --git a/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Ledger/LedgerBuildRequest.mm b/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Ledger/LedgerBuildRequest.mm index 690bc320aa..440c5072ac 100644 --- a/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Ledger/LedgerBuildRequest.mm +++ b/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Ledger/LedgerBuildRequest.mm @@ -641,4 +641,42 @@ - (void)testBuildGetTxnRequest { XCTAssertTrue([getTxnRequest contains:expectedResult], @"getTxnRequest json doesn't contain expectedResult json"); } +// MARK: Auth Rule request + +- (void)testBuildAuthRuleRequestsWorks { + NSDictionary *constraint = @{ + @"sig_count": @(1), + @"role": @"0", + @"constraint_id": @"ROLE", + @"need_to_be_owner": @(false) + }; + + NSDictionary *expectedResult = @{ + @"identifier": [TestUtils trusteeDid], + @"operation": @{ + @"type": @"120", + @"auth_type": @"1", + @"auth_action": @"ADD", + @"field": @"role", + @"new_value": @"101", + @"constraint": constraint, + } + }; + + NSString *requestJson; + ret = [[LedgerUtils sharedInstance] buildAuthRuleRequestWithSubmitterDid:[TestUtils trusteeDid] + authType:@"NYM" + authAction:@"ADD" + field:@"role" + oldValue:nil + newValue:@"101" + constraint:[NSDictionary toString:constraint] + outRequest:&requestJson]; + XCTAssertEqual(ret.code, Success, @"LedgerUtils::buildNymRequestWithSubmitterDid() failed!"); + + NSDictionary *request = [NSDictionary fromString:requestJson]; + + XCTAssertTrue([request contains:expectedResult], @"Request doesn't contain expectedResult"); +} + @end diff --git a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.h b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.h index b01cba99e1..a690af5c41 100644 --- a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.h +++ b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.h @@ -179,6 +179,16 @@ requestJson:(NSString *)requestJson resultJson:(NSString **)resultJson; +// MARK: - Auth Rule request +- (NSError *)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid + authType:(NSString *)authType + authAction:(NSString *)authAction + field:(NSString *)field + oldValue:(NSString *)oldValue + newValue:(NSString *)newValue + constraint:(NSString *)constraint + outRequest:(NSString **)resultJson; + // MARK: - Response Metadata - (NSError *)getResponseMetadata:(NSString *)response responseMetadata:(NSString **)responseMetadata; diff --git a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.mm b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.mm index c99724d7fb..9aaf83cdea 100644 --- a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.mm +++ b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.mm @@ -729,6 +729,38 @@ - (NSError *)multiSignRequestWithWalletHandle:(IndyHandle)walletHandle return err; } +- (NSError *)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid + authType:(NSString *)authType + authAction:(NSString *)authAction + field:(NSString *)field + oldValue:(NSString *)oldValue + newValue:(NSString *)newValue + constraint:(NSString *)constraint + outRequest:(NSString **)resultJson { + XCTestExpectation *completionExpectation = [[XCTestExpectation alloc] initWithDescription:@"completion finished"]; + __block NSError *err = nil; + __block NSString *outJson = nil; + + [IndyLedger buildAuthRuleRequestWithSubmitterDid:submitterDid + authType:authType + authAction:authAction + field:field + oldValue:oldValue + newValue:newValue + constraint:constraint + completion:^(NSError *error, NSString *json) { + err = error; + outJson = json; + [completionExpectation fulfill]; + }]; + + [self waitForExpectations:@[completionExpectation] timeout:[TestUtils longTimeout]]; + + if (resultJson) {*resultJson = outJson;} + + return err; +} + - (NSError *)getResponseMetadata:(NSString *)response responseMetadata:(NSString **)responseMetadata { XCTestExpectation *completionExpectation = [[XCTestExpectation alloc] initWithDescription:@"completion finished"]; diff --git a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h index 66464febda..3a0582ab6e 100644 --- a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h +++ b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h @@ -568,7 +568,30 @@ */ + (void)parseGetRevocRegDeltaResponse:(NSString *)getRevocRegDeltaResponse completion:(void (^)(NSError *error, NSString *revocRegDefId, NSString *revocRegDeltaJson, NSNumber *timestamp))completion; - + +// MARK: - Auth Rule request + +/** + Builds a AUTH_RULE request. + + @param submitterDid DID of the submitter stored in secured Wallet. + @param authType + @param authAction + @param field + @param oldValue + @param newValue + @param constraint + @param completion Callback that takes command result as parameter. Returns request result as json. + */ ++ (void)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid + authType:(NSString *)authType + authAction:(NSString *)authAction + field:(NSString *)field + oldValue:(NSString *)oldValue + newValue:(NSString *)newValue + constraint:(NSString *)constraint + completion:(void (^)(NSError *error, NSString *requestJSON))completion; + /** Parse transaction response to fetch metadata. The important use case for this method is validation of Node's response freshens. diff --git a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.mm b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.mm index 2d373124b7..b2ec9876eb 100644 --- a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.mm +++ b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.mm @@ -706,6 +706,37 @@ + (void)parseGetRevocRegDeltaResponse:(NSString *)getRevocRegDeltaResponse } } ++ (void)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid + authType:(NSString *)authType + authAction:(NSString *)authAction + field:(NSString *)field + oldValue:(NSString *)oldValue + newValue:(NSString *)newValue + constraint:(NSString *)constraint + completion:(void (^)(NSError *error, NSString *requestJSON))completion { + indy_error_t ret; + + indy_handle_t handle = [[IndyCallbacks sharedInstance] createCommandHandleFor:completion]; + + + ret = indy_build_auth_rule_request(handle, + [submitterDid UTF8String], + [authType UTF8String], + [authAction UTF8String], + [field UTF8String], + [oldValue UTF8String], + [newValue UTF8String], + [constraint UTF8String], + IndyWrapperCommonStringCallback); + if (ret != Success) { + [[IndyCallbacks sharedInstance] deleteCommandHandleFor:handle]; + + dispatch_async(dispatch_get_main_queue(), ^{ + completion([NSError errorFromIndyError:ret], nil); + }); + } +} + + (void)getResponseMetadata:(NSString *)response completion:(void (^)(NSError *error, NSString *responseMetadata))completion { indy_error_t ret; From 932ba5863a9ac1f84895307db28e736ffec679a6 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 5 Mar 2019 13:32:54 +0300 Subject: [PATCH 07/18] Added ledger auth-rule command to Indy-Cli Signed-off-by: artem.ivanov --- cli/src/commands/ledger.rs | 107 ++++++++++++++++++++++++- cli/src/libindy/ledger.rs | 15 +++- cli/src/main.rs | 1 + docs/design/001-cli/README.md | 6 ++ libindy/src/domain/ledger/constants.rs | 2 +- 5 files changed, 127 insertions(+), 4 deletions(-) diff --git a/cli/src/commands/ledger.rs b/cli/src/commands/ledger.rs index 5f648fd817..ac4b143c13 100644 --- a/cli/src/commands/ledger.rs +++ b/cli/src/commands/ledger.rs @@ -1218,6 +1218,64 @@ pub mod sign_multi_command { } } +pub mod auth_rule_command { + use super::*; + + command!(CommandMetadata::build("auth-rule", "Send AUTH_RULE transaction to the Ledger.") + .add_required_param("type", "") + .add_required_param("action", "") + .add_required_param("field", "") + .add_optional_param("old_value", "") + .add_required_param("new_value", "") + .add_required_param("constraint", "") + .add_example(r#"ledger change-auth-rule type=NYM action=ADD field=role new_value=101 constraint={"sig_count":1,"role":0,"constraint_id":"role","need_to_be_owner":false}"#) + .add_example(r#"ledger change-auth-rule type=NYM action=EDIT field=role old_value=101 new_value=0 constraint={"sig_count":1,"role":0,"constraint_id":"role","need_to_be_owner":false}"#) + .finalize() + ); + + fn execute(ctx: &CommandContext, params: &CommandParams) -> Result<(), ()> { + trace!("execute >> ctx {:?} params {:?}", ctx, params); + + let (pool_handle, pool_name) = ensure_connected_pool(&ctx)?; + let (wallet_handle, wallet_name) = ensure_opened_wallet(&ctx)?; + let submitter_did = ensure_active_did(&ctx)?; + + let auth_type = get_str_param("type", params).map_err(error_err!())?; + let auth_action = get_str_param("action", params).map_err(error_err!())?; + let field = get_str_param("field", params).map_err(error_err!())?; + let old_value = get_opt_str_param("old_value", params).map_err(error_err!())?; + let new_value = get_str_param("new_value", params).map_err(error_err!())?; + let constraint = get_str_param("constraint", params).map_err(error_err!())?; + + let request = Ledger::build_auth_rule_request(&submitter_did, auth_type, &auth_action.to_uppercase(), field, old_value, new_value, constraint) + .map_err(|err| handle_indy_error(err, None, None, None))?; + + let response_json = Ledger::sign_and_submit_request(pool_handle, wallet_handle, &submitter_did, &request) + .map_err(|err| handle_indy_error(err, Some(&submitter_did), Some(&pool_name), Some(&wallet_name)))?; + + let mut response: Response = serde_json::from_str::>(&response_json) + .map_err(|err| println_err!("Invalid data has been received: {:?}", err))?; + + if let Some(result) = response.result.as_mut() { + result["txn"]["data"]["auth_type"] = get_txn_title(&result["txn"]["data"]["auth_type"]); + } + + let res = handle_transaction_response(response) + .map(|result| print_transaction_response(result, + "Auth Rule request has been sent to Ledger.", + None, + &mut vec![("auth_type", "Type"), + ("auth_action", "Action"), + ("field", "Field"), + ("old_value", "Old Value"), + ("new_value", "New Value"), + ("constraint", "Constraint")]))?; + + trace!("execute << {:?}", res); + Ok(res) + } +} + pub fn set_request_fees(request: &mut String, wallet_handle: i32, submitter_did: Option<&str>, fees_inputs: &Option>, fees_outputs: &Option>, extra: Option<&str>) -> Result, ()> { let mut payment_method: Option = None; if let &Some(ref inputs) = fees_inputs { @@ -1413,6 +1471,23 @@ fn get_role_title(role: &serde_json::Value) -> serde_json::Value { }.to_string()) } +fn get_txn_title(role: &serde_json::Value) -> serde_json::Value { + serde_json::Value::String(match role.as_str() { + Some("0") => "NODE", + Some("1") => "NYM", + Some("100") => "ATTRIB", + Some("101") => "SCHEMA", + Some("102") => "CRED_DEF", + Some("109") => "POOL_UPGRADE", + Some("111") => "POOL_CONFIG", + Some("113") => "REVOC_REG_DEF", + Some("114") => "REVOC_REG_ENTRY", + Some("118") => "POOL_RESTART", + Some(val) => val, + _ => "-" + }.to_string()) +} + fn timestamp_to_datetime(_time: i64) -> String { NaiveDateTime::from_timestamp(_time, 0).to_string() } @@ -1444,7 +1519,7 @@ pub struct ReplyResult { pub mod tests { use super::*; use commands::wallet::tests::{create_and_open_wallet, close_and_delete_wallet, open_wallet, close_wallet}; - use commands::pool::tests::{disconnect_and_delete_pool}; + use commands::pool::tests::disconnect_and_delete_pool; use commands::did::tests::{new_did, use_did, SEED_TRUSTEE, DID_TRUSTEE, DID_MY1, VERKEY_MY1, SEED_MY3, DID_MY3, VERKEY_MY3}; #[cfg(feature = "nullpay_plugin")] use commands::common::tests::{load_null_payment_plugin, NULL_PAYMENT_METHOD}; @@ -3473,6 +3548,36 @@ pub mod tests { } } + mod auth_rule { + use super::*; + + const ROLE_CONSTRAINT: &str = r#"{ + "sig_count": 1, + "metadata": {}, + "role": "0", + "constraint_id": "ROLE", + "need_to_be_owner": false + }"#; + + #[test] + pub fn auth_rule_works() { + let ctx = setup_with_wallet_and_pool(); + use_trustee(&ctx); + let (did, verkey) = create_new_did(&ctx); + { + let cmd = auth_rule_command::new(); + let mut params = CommandParams::new(); + params.insert("type", "NYM".to_string()); + params.insert("action", "add".to_string()); + params.insert("field", "role".to_string()); + params.insert("new_value", "101".to_string()); + params.insert("constraint", ROLE_CONSTRAINT.to_string()); + cmd.execute(&ctx, ¶ms).unwrap(); + } + tear_down_with_wallet_and_pool(&ctx); + } + } + fn create_new_did(ctx: &CommandContext) -> (String, String) { let (wallet_handle, _) = get_opened_wallet(ctx).unwrap(); Did::new(wallet_handle, "{}").unwrap() diff --git a/cli/src/libindy/ledger.rs b/cli/src/libindy/ledger.rs index a15dd3aed6..8e378c227e 100644 --- a/cli/src/libindy/ledger.rs +++ b/cli/src/libindy/ledger.rs @@ -77,7 +77,18 @@ impl Ledger { pub fn indy_build_pool_upgrade_request(submitter_did: &str, name: &str, version: &str, action: &str, sha256: &str, timeout: Option, schedule: Option<&str>, justification: Option<&str>, reinstall: bool, force: bool, package: Option<&str>) -> Result { ledger::build_pool_upgrade_request(submitter_did, name, version, action, sha256, - timeout, schedule, justification, - reinstall, force, package).wait() + timeout, schedule, justification, + reinstall, force, package).wait() + } + + pub fn build_auth_rule_request(submitter_did: &str, + auth_type: &str, + auth_action: &str, + field: &str, + old_value: Option<&str>, + new_value: &str, + constraint: &str, ) -> Result { + ledger::build_auth_rule_request(submitter_did, auth_type, auth_action, field, + old_value, new_value, constraint).wait() } } \ No newline at end of file diff --git a/cli/src/main.rs b/cli/src/main.rs index 1e58388311..b8f7ab9619 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -126,6 +126,7 @@ fn build_executor() -> CommandExecutor { .add_command(ledger::set_fees_prepare_command::new()) .add_command(ledger::verify_payment_receipt_command::new()) .add_command(ledger::sign_multi_command::new()) + .add_command(ledger::auth_rule_command::new()) .finalize_group() .add_group(payment_address::group::new()) .add_command(payment_address::create_command::new()) diff --git a/docs/design/001-cli/README.md b/docs/design/001-cli/README.md index 1100ed366a..be4eca6e6a 100644 --- a/docs/design/001-cli/README.md +++ b/docs/design/001-cli/README.md @@ -333,6 +333,12 @@ Send custom transaction with user defined json body and optional signature ledger custom [txn=] [sign=] ``` +#### AUTH_RULE transaction +Send AUTH_RULE transaction +``` +ledger auth-rule type= action= field= [old_value=] new_value= constraint=<{constraint json}> +``` + #### GET_PAYMENT_SOURCES transaction Send GET_PAYMENT_SOURCES transaction ``` diff --git a/libindy/src/domain/ledger/constants.rs b/libindy/src/domain/ledger/constants.rs index 4ff517afa2..447798fab1 100644 --- a/libindy/src/domain/ledger/constants.rs +++ b/libindy/src/domain/ledger/constants.rs @@ -20,7 +20,7 @@ pub const GET_VALIDATOR_INFO: &str = "119"; pub const AUTH_RULE: &str = "120"; pub const GET_DDO: &str = "120";//TODO change number -pub const WRITE_REQUESTS: [&str; 11] = [NODE, NYM, ATTRIB, ATTRIB, SCHEMA, CRED_DEF, POOL_UPGRADE, POOL_RESTART, POOL_CONFIG, REVOC_REG_DEF, REVOC_REG_ENTRY]; +pub const WRITE_REQUESTS: [&str; 10] = [NODE, NYM, ATTRIB, SCHEMA, CRED_DEF, POOL_UPGRADE, POOL_RESTART, POOL_CONFIG, REVOC_REG_DEF, REVOC_REG_ENTRY]; pub const TRUSTEE: &str = "0"; pub const STEWARD: &str = "2"; From baad2294a771f38d0331b8cd95c99aa15d4c51f4 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 5 Mar 2019 15:26:24 +0300 Subject: [PATCH 08/18] Updated documentation for new function Signed-off-by: artem.ivanov --- cli/src/commands/ledger.rs | 28 +++++++++---- libindy/include/indy_ledger.h | 40 ++++++++++++++---- libindy/src/api/ledger.rs | 39 ++++++++++++++---- libindy/src/domain/ledger/constants.rs | 6 +-- .../ios/libindy-pod/Indy/Wrapper/IndyLedger.h | 39 ++++++++++++++---- .../hyperledger/indy/sdk/ledger/Ledger.java | 38 +++++++++++++---- wrappers/nodejs/README.md | 41 +++++++++++++++---- wrappers/python/indy/ledger.py | 39 ++++++++++++++---- 8 files changed, 217 insertions(+), 53 deletions(-) diff --git a/cli/src/commands/ledger.rs b/cli/src/commands/ledger.rs index ac4b143c13..64bedb6755 100644 --- a/cli/src/commands/ledger.rs +++ b/cli/src/commands/ledger.rs @@ -1221,13 +1221,26 @@ pub mod sign_multi_command { pub mod auth_rule_command { use super::*; - command!(CommandMetadata::build("auth-rule", "Send AUTH_RULE transaction to the Ledger.") - .add_required_param("type", "") - .add_required_param("action", "") - .add_required_param("field", "") - .add_optional_param("old_value", "") - .add_required_param("new_value", "") - .add_required_param("constraint", "") + command!(CommandMetadata::build("auth-rule", "Send AUTH_RULE request to change authentication rules for a ledger transaction.") + .add_required_param("type", "Ledger transaction for which authentication rules will be applied. Can be an alias or associated value") + .add_required_param("action", "Type of action for which authentication rules will be applied. One of: ADD, EDIT") + .add_required_param("field", "Transaction field for which authentication rule will be applied") + .add_optional_param("old_value", "Old value of field, which can be changed to a new_value (must be specified for EDIT action)") + .add_required_param("new_value", "New value that can be used to fill the field") + .add_required_param("constraint", r#"Set of constraints required for execution of action + { + constraint_id - type of a constraint. Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. + role - role of a user which satisfy to constrain. + sig_count - the number of signatures required to execution action. + need_to_be_owner - if user must be an owner of transaction. + metadata - additional parameters of constraint. + } + can be combined by + { + constraint_id: <"AND" or "OR"> + auth_constraints: [, ] + } + "#) .add_example(r#"ledger change-auth-rule type=NYM action=ADD field=role new_value=101 constraint={"sig_count":1,"role":0,"constraint_id":"role","need_to_be_owner":false}"#) .add_example(r#"ledger change-auth-rule type=NYM action=EDIT field=role old_value=101 new_value=0 constraint={"sig_count":1,"role":0,"constraint_id":"role","need_to_be_owner":false}"#) .finalize() @@ -1482,7 +1495,6 @@ fn get_txn_title(role: &serde_json::Value) -> serde_json::Value { Some("111") => "POOL_CONFIG", Some("113") => "REVOC_REG_DEF", Some("114") => "REVOC_REG_ENTRY", - Some("118") => "POOL_RESTART", Some(val) => val, _ => "-" }.to_string()) diff --git a/libindy/include/indy_ledger.h b/libindy/include/indy_ledger.h index 9d15cfd2dd..2149e1cbee 100644 --- a/libindy/include/indy_ledger.h +++ b/libindy/include/indy_ledger.h @@ -955,16 +955,42 @@ extern "C" { const char* response_metadata) ); - /// Builds a AUTH_RULE request. + /// Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. /// /// #Params /// command_handle: command handle to map callback to caller context. - /// auth_type: - /// field: - /// auth_action: - /// old_value: - /// new_value: - /// constraint: + /// auth_type: ledger transaction for which authentication rules will be applied. + /// Can be an alias or associated value: + /// NODE or 0 + /// NYM or 1 + /// ATTRIB or 100 + /// SCHEMA or 101 + /// CRED_DEF or 102 + /// POOL_UPGRADE or 109 + /// POOL_CONFIG or 111 + /// REVOC_REG_DEF or 113 + /// REVOC_REG_ENTRY or 114 + /// auth_action: type of action for which authentication rules will be applied. + /// Can be either "ADD" (to add new rule) or "EDIT" (to edit an existing one). + /// field: transaction field for which authentication rule will be applied. + /// old_value: old value of field, which can be changed to a new_value (must be specified for EDIT action). + /// new_value: new value that can be used to fill the field. + /// constraint: set of constraints required for execution of action: + /// the following format: + /// { + /// constraint_id - type of a constraint. + /// Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. + /// role - role of a user which satisfy to constrain. + /// sig_count - the number of signatures required to execution action. + /// need_to_be_owner - if user must be an owner of transaction. + /// metadata - additional parameters of constraint. + /// } + /// can be combined by + /// { + /// 'constraint_id': <"AND" or "OR"> + /// 'auth_constraints': [, ] + /// } + /// /// cb: Callback that takes command result as parameter. /// /// #Returns diff --git a/libindy/src/api/ledger.rs b/libindy/src/api/ledger.rs index 485373aeed..04b75d8f07 100644 --- a/libindy/src/api/ledger.rs +++ b/libindy/src/api/ledger.rs @@ -1835,16 +1835,41 @@ pub extern fn indy_get_response_metadata(command_handle: IndyHandle, res } -/// Builds a AUTH_RULE request. +/// Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. /// /// #Params /// command_handle: command handle to map callback to caller context. -/// auth_type: -/// field: -/// auth_action: -/// old_value: -/// new_value: -/// constraint: +/// auth_type: ledger transaction for which authentication rules will be applied. +/// Can be an alias or associated value: +/// NODE or 0 +/// NYM or 1 +/// ATTRIB or 100 +/// SCHEMA or 101 +/// CRED_DEF or 102 +/// POOL_UPGRADE or 109 +/// POOL_CONFIG or 111 +/// REVOC_REG_DEF or 113 +/// REVOC_REG_ENTRY or 114 +/// auth_action: type of action for which authentication rules will be applied. +/// Can be either "ADD" (to add new rule) or "EDIT" (to edit an existing one). +/// field: transaction field for which authentication rule will be applied. +/// old_value: old value of field, which can be changed to a new_value (must be specified for EDIT action). +/// new_value: new value that can be used to fill the field. +/// constraint: set of constraints required for execution of action in the following format: +/// { +/// constraint_id - type of a constraint. +/// Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. +/// role - role of a user which satisfy to constrain. +/// sig_count - the number of signatures required to execution action. +/// need_to_be_owner - if user must be an owner of transaction. +/// metadata - additional parameters of constraint. +/// } +/// can be combined by +/// { +/// 'constraint_id': <"AND" or "OR"> +/// 'auth_constraints': [, ] +/// } +/// /// cb: Callback that takes command result as parameter. /// /// #Returns diff --git a/libindy/src/domain/ledger/constants.rs b/libindy/src/domain/ledger/constants.rs index 447798fab1..2aec567220 100644 --- a/libindy/src/domain/ledger/constants.rs +++ b/libindy/src/domain/ledger/constants.rs @@ -20,7 +20,7 @@ pub const GET_VALIDATOR_INFO: &str = "119"; pub const AUTH_RULE: &str = "120"; pub const GET_DDO: &str = "120";//TODO change number -pub const WRITE_REQUESTS: [&str; 10] = [NODE, NYM, ATTRIB, SCHEMA, CRED_DEF, POOL_UPGRADE, POOL_RESTART, POOL_CONFIG, REVOC_REG_DEF, REVOC_REG_ENTRY]; +pub const WRITE_REQUESTS: [&str; 10] = [NODE, NYM, ATTRIB, SCHEMA, CRED_DEF, POOL_UPGRADE, POOL_CONFIG, REVOC_REG_DEF, REVOC_REG_ENTRY]; pub const TRUSTEE: &str = "0"; pub const STEWARD: &str = "2"; @@ -39,9 +39,9 @@ pub fn txn_name_to_code(txn: &str) -> Option<&str> { "NYM" => Some(NYM), "ATTRIB" => Some(ATTRIB), "SCHEMA" => Some(SCHEMA), - "CRED_DEF" => Some(CRED_DEF), + "CRED_DEF" | "CLAIM_DEF" => Some(CRED_DEF), "POOL_UPGRADE" => Some(POOL_UPGRADE), - "POOL_RESTART" => Some(POOL_RESTART), + "POOL_CONFIG" => Some(POOL_CONFIG), "REVOC_REG_DEF" => Some(REVOC_REG_DEF), "REVOC_REG_ENTRY" => Some(REVOC_REG_ENTRY), _ => None diff --git a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h index 3a0582ab6e..076eea6543 100644 --- a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h +++ b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h @@ -572,15 +572,40 @@ // MARK: - Auth Rule request /** - Builds a AUTH_RULE request. + Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. @param submitterDid DID of the submitter stored in secured Wallet. - @param authType - @param authAction - @param field - @param oldValue - @param newValue - @param constraint + @param authType - ledger transaction for which authentication rules will be applied. + Can be an alias or associated value: + NODE or 0 + NYM or 1 + ATTRIB or 100 + SCHEMA or 101 + CRED_DEF or 102 + POOL_UPGRADE or 109 + POOL_CONFIG or 111 + REVOC_REG_DEF or 113 + REVOC_REG_ENTRY or 114 + @param authAction - type of action for which authentication rules will be applied. + Can be either "ADD" (to add new rule) or "EDIT" (to edit an existing one). + @param field - transaction field for which authentication rule will be applied. + @param oldValue - old value of field, which can be changed to a new_value (must be specified for EDIT action). + @param newValue - new value that can be used to fill the field. + @param constraint - set of constraints required for execution of action in the following format: + { + constraint_id - type of a constraint. + Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. + role - role of a user which satisfy to constrain. + sig_count - the number of signatures required to execution action. + need_to_be_owner - if user must be an owner of transaction. + metadata - additional parameters of constraint. + } + can be combined by + { + 'constraint_id': <"AND" or "OR"> + 'auth_constraints': [, ] + } + @param completion Callback that takes command result as parameter. Returns request result as json. */ + (void)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java index f30ff33dbf..d8dbba179e 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java @@ -1267,15 +1267,39 @@ public static CompletableFuture getResponseMetadata( } /** - * Builds a AUTH_RULE request. + * Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. * * @param submitterDid DID of the submitter stored in secured Wallet. - * @param authType - - * @param authAction - - * @param field - - * @param oldValue - - * @param newValue - - * @param constraint - + * @param authType - ledger transaction for which authentication rules will be applied. + * Can be an alias or associated value: + * NODE or 0 + * NYM or 1 + * ATTRIB or 100 + * SCHEMA or 101 + * CRED_DEF or 102 + * POOL_UPGRADE or 109 + * POOL_CONFIG or 111 + * REVOC_REG_DEF or 113 + * REVOC_REG_ENTRY or 114 + * @param authAction - type of action for which authentication rules will be applied. + * Can be either "ADD" (to add new rule) or "EDIT" (to edit an existing one). + * @param field - transaction field for which authentication rule will be applied. + * @param oldValue - old value of field, which can be changed to a new_value (must be specified for EDIT action). + * @param newValue - new value that can be used to fill the field. + * @param constraint - set of constraints required for execution of action in the following format: + * { + * constraint_id - [string] type of a constraint. + * Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. + * role - [string] role of a user which satisfy to constrain. + * sig_count - [u32] the number of signatures required to execution action. + * need_to_be_owner - [bool] if user must be an owner of transaction. + * metadata - [object] additional parameters of constraint. + * } + * can be combined by + * { + * 'constraint_id': "AND" or "OR" + * 'auth_constraints': [[constraint_1], [constraint_2]] + * } * @return A future resolving to a request result as json. * @throws IndyException Thrown if an error occurs when calling the underlying SDK. diff --git a/wrappers/nodejs/README.md b/wrappers/nodejs/README.md index 416c25ec93..3508d784c6 100644 --- a/wrappers/nodejs/README.md +++ b/wrappers/nodejs/README.md @@ -1750,15 +1750,42 @@ Errors: `Common*` #### buildAuthRuleRequest \( submitterDid, authType, authAction, field, oldValue, newValue, constraint \) -> request -Builds a AUTH_RULE request. +Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. * `submitterDid`: String - \(Optional\) DID of the read request sender \(if not provided then default Libindy DID will be used\). -* `authType`: String - -* `authAction`: String - -* `field`: String - -* `oldValue`: String - \(Optional\) -* `newValue`: String - -* `constraint`: String - +* `authType`: String - ledger transaction for which authentication rules will be applied. +Can be an alias or associated value: + * NODE or 0 + * NYM or 1 + * ATTRIB or 100 + * SCHEMA or 101 + * CRED_DEF or 102 + * POOL_UPGRADE or 109 + * POOL_CONFIG or 111 + * REVOC_REG_DEF or 113 + * REVOC_REG_ENTRY or 114 +* `authAction`: String - type of action for which authentication rules will be applied. + * "ADD" - to add new rule + * "EDIT" - to edit an existing one +* `field`: String - transaction field for which authentication rule will be applied. +* `oldValue`: String - \(Optional\) old value of field, which can be changed to a new_value (must be specified for EDIT action). +* `newValue`: String - new value that can be used to fill the field. +* `constraint`: String - set of constraints required for execution of action in the following format: +``` + { + constraint_id - type of a constraint. + Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. + role - role of a user which satisfy to constrain. + sig_count - the number of signatures required to execution action. + need_to_be_owner - if user must be an owner of transaction. + metadata - additional parameters of constraint. + } +can be combined by + { + 'constraint_id': <"AND" or "OR"> + 'auth_constraints': [, ] + } +``` * __->__ `request`: Json Errors: `Common*` diff --git a/wrappers/python/indy/ledger.py b/wrappers/python/indy/ledger.py index 3bf6c038d7..0a716f1d88 100644 --- a/wrappers/python/indy/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -1271,15 +1271,40 @@ async def build_auth_rule_request(submitter_did: str, new_value: str, constraint: str) -> str: """ - Builds a AUTH_RULE request. + Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. :param submitter_did: DID of the submitter stored in secured Wallet. - :param auth_type: - :param auth_action: - :param field: - :param old_value: - :param new_value: - :param constraint: + :param auth_type: ledger transaction for which authentication rules will be applied. + Can be an alias or associated value: + NODE or 0 + NYM or 1 + ATTRIB or 100 + SCHEMA or 101 + CRED_DEF or 102 + POOL_UPGRADE or 109 + POOL_CONFIG or 111 + REVOC_REG_DEF or 113 + REVOC_REG_ENTRY or 114 + :param auth_action: type of action for which authentication rules will be applied. + Can be either "ADD" (to add new rule) or "EDIT" (to edit an existing one). + :param field: transaction field for which authentication rule will be applied. + :param old_value: old value of field, which can be changed to a new_value (must be specified for EDIT action). + :param new_value: new value that can be used to fill the field. + :param constraint: set of constraints required for execution of action in the following format: + { + constraint_id - type of a constraint. + Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. + role - role of a user which satisfy to constrain. + sig_count - the number of signatures required to execution action. + need_to_be_owner - if user must be an owner of transaction. + metadata - additional parameters of constraint. + } + can be combined by + { + 'constraint_id': <"AND" or "OR"> + 'auth_constraints': [, ] + } + :return: Request result as json. """ From ed10ddcc15cfbfe09ee9a0cd84c497e350257409 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 5 Mar 2019 16:08:42 +0300 Subject: [PATCH 09/18] Fixed compilation error Signed-off-by: artem.ivanov --- libindy/src/domain/ledger/constants.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libindy/src/domain/ledger/constants.rs b/libindy/src/domain/ledger/constants.rs index 2aec567220..b56a398b15 100644 --- a/libindy/src/domain/ledger/constants.rs +++ b/libindy/src/domain/ledger/constants.rs @@ -20,7 +20,7 @@ pub const GET_VALIDATOR_INFO: &str = "119"; pub const AUTH_RULE: &str = "120"; pub const GET_DDO: &str = "120";//TODO change number -pub const WRITE_REQUESTS: [&str; 10] = [NODE, NYM, ATTRIB, SCHEMA, CRED_DEF, POOL_UPGRADE, POOL_CONFIG, REVOC_REG_DEF, REVOC_REG_ENTRY]; +pub const WRITE_REQUESTS: [&str; 9] = [NODE, NYM, ATTRIB, SCHEMA, CRED_DEF, POOL_UPGRADE, POOL_CONFIG, REVOC_REG_DEF, REVOC_REG_ENTRY]; pub const TRUSTEE: &str = "0"; pub const STEWARD: &str = "2"; From 99139f9d17534c6883b433369c298c458df8f0ee Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 5 Mar 2019 16:13:45 +0300 Subject: [PATCH 10/18] Updated rust wrapper documentation Signed-off-by: artem.ivanov --- wrappers/rust/src/ledger.rs | 38 ++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/wrappers/rust/src/ledger.rs b/wrappers/rust/src/ledger.rs index 5adc3b7c71..e8c9524320 100644 --- a/wrappers/rust/src/ledger.rs +++ b/wrappers/rust/src/ledger.rs @@ -994,15 +994,39 @@ fn _get_response_metadata(command_handle: IndyHandle, response: &str, cb: Option ErrorCode::from(unsafe { ledger::indy_get_response_metadata(command_handle, response.as_ptr(), cb) }) } -/// Builds a AUTH_RULE request. +/// Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. /// /// # Arguments -/// * `auth_type`: -/// * `field`: -/// * `auth_action`: -/// * `old_value`: -/// * `new_value`: -/// * `constraint`: +/// * `auth_type`: ledger transaction for which authentication rules will be applied. +/// Can be an alias or associated value: +/// NODE or 0 +/// NYM or 1 +/// ATTRIB or 100 +/// SCHEMA or 101 +/// CRED_DEF or 102 +/// POOL_UPGRADE or 109 +/// POOL_CONFIG or 111 +/// REVOC_REG_DEF or 113 +/// REVOC_REG_ENTRY or 114 +/// * `field`: type of action for which authentication rules will be applied. +/// Can be either "ADD" (to add new rule) or "EDIT" (to edit an existing one). +/// * `auth_action`: transaction field for which authentication rule will be applied. +/// * `old_value`: old value of field, which can be changed to a new_value (must be specified for EDIT action). +/// * `new_value`: new value that can be used to fill the field. +/// * `constraint`: set of constraints required for execution of action in the following format: +/// { +/// constraint_id - type of a constraint. +/// Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. +/// role - role of a user which satisfy to constrain. +/// sig_count - the number of signatures required to execution action. +/// need_to_be_owner - if user must be an owner of transaction. +/// metadata - additional parameters of constraint. +/// } +/// can be combined by +/// { +/// 'constraint_id': <"AND" or "OR"> +/// 'auth_constraints': [, ] +/// } /// /// # Returns /// Request result as json. From 701295b4b3691607f801aac53af85cb67928bf3b Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Tue, 5 Mar 2019 16:40:32 +0300 Subject: [PATCH 11/18] Fixed test mistakes Signed-off-by: artem.ivanov --- .../org/hyperledger/indy/sdk/ledger/AuthRuleRequestsTest.java | 4 ++-- wrappers/python/tests/ledger/test_build_auth_rule_request.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AuthRuleRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AuthRuleRequestsTest.java index 4c3f019b83..8c3e991332 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AuthRuleRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AuthRuleRequestsTest.java @@ -24,7 +24,7 @@ public void testBuildAuthRuleRequestWorksForAddAction() throws Exception { .put("operation", new JSONObject() .put("type", "120") - .put("auth_type", authType) + .put("auth_type", "1") .put("auth_action", addAuthAction) .put("field", field) .put("new_value", newValue) @@ -48,7 +48,7 @@ public void testBuildAuthRuleRequestWorksForEditAction() throws Exception { .put("operation", new JSONObject() .put("type", "120") - .put("auth_type", authType) + .put("auth_type", "1") .put("auth_action", editAuthAction) .put("field", field) .put("old_value", oldValue) diff --git a/wrappers/python/tests/ledger/test_build_auth_rule_request.py b/wrappers/python/tests/ledger/test_build_auth_rule_request.py index 2ce1bf675b..f0955ef21b 100644 --- a/wrappers/python/tests/ledger/test_build_auth_rule_request.py +++ b/wrappers/python/tests/ledger/test_build_auth_rule_request.py @@ -26,7 +26,7 @@ async def test_build_auth_rule_request_works_for_add_auth_action(): "identifier": identifier, "operation": { "type": "120", - "auth_type": auth_type, + "auth_type": "1", "auth_action": add_auth_action, "field": field, "new_value": new_value, @@ -46,7 +46,7 @@ async def test_build_auth_rule_request_works_for_edit_auth_action(): "identifier": identifier, "operation": { "type": "120", - "auth_type": auth_type, + "auth_type": "1", "auth_action": edit_auth_action, "field": field, "old_value": old_value, From b6d0a36b59f96f3eca9feab9b770ce6e903a2ef2 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 6 Mar 2019 09:53:50 +0300 Subject: [PATCH 12/18] Corrected cli command example Signed-off-by: artem.ivanov --- cli/src/commands/ledger.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/src/commands/ledger.rs b/cli/src/commands/ledger.rs index 64bedb6755..eb2d2fdf94 100644 --- a/cli/src/commands/ledger.rs +++ b/cli/src/commands/ledger.rs @@ -1225,7 +1225,7 @@ pub mod auth_rule_command { .add_required_param("type", "Ledger transaction for which authentication rules will be applied. Can be an alias or associated value") .add_required_param("action", "Type of action for which authentication rules will be applied. One of: ADD, EDIT") .add_required_param("field", "Transaction field for which authentication rule will be applied") - .add_optional_param("old_value", "Old value of field, which can be changed to a new_value (must be specified for EDIT action)") + .add_optional_param("old_value", "Old value of field, which can be changed to a new_value (mandatory for EDIT action)") .add_required_param("new_value", "New value that can be used to fill the field") .add_required_param("constraint", r#"Set of constraints required for execution of action { @@ -1241,8 +1241,8 @@ pub mod auth_rule_command { auth_constraints: [, ] } "#) - .add_example(r#"ledger change-auth-rule type=NYM action=ADD field=role new_value=101 constraint={"sig_count":1,"role":0,"constraint_id":"role","need_to_be_owner":false}"#) - .add_example(r#"ledger change-auth-rule type=NYM action=EDIT field=role old_value=101 new_value=0 constraint={"sig_count":1,"role":0,"constraint_id":"role","need_to_be_owner":false}"#) + .add_example(r#"ledger auth-rule type=NYM action=ADD field=role new_value=101 constraint={"sig_count":1,"role":0,"constraint_id":"role","need_to_be_owner":false}"#) + .add_example(r#"ledger auth-rule type=NYM action=EDIT field=role old_value=101 new_value=0 constraint={"sig_count":1,"role":0,"constraint_id":"role","need_to_be_owner":false}"#) .finalize() ); From c6a35e310265d1a02bea442a59e864013cffae6e Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 6 Mar 2019 10:41:10 +0300 Subject: [PATCH 13/18] Corrected documentation Signed-off-by: artem.ivanov --- cli/src/commands/ledger.rs | 6 +++--- libindy/include/indy_ledger.h | 11 +++++------ libindy/src/api/ledger.rs | 12 ++++++------ wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h | 10 +++++----- .../java/org/hyperledger/indy/sdk/ledger/Ledger.java | 10 +++++----- wrappers/nodejs/README.md | 10 +++++----- wrappers/python/indy/ledger.py | 10 +++++----- wrappers/rust/src/ledger.rs | 10 +++++----- 8 files changed, 39 insertions(+), 40 deletions(-) diff --git a/cli/src/commands/ledger.rs b/cli/src/commands/ledger.rs index eb2d2fdf94..5433f3583a 100644 --- a/cli/src/commands/ledger.rs +++ b/cli/src/commands/ledger.rs @@ -1223,17 +1223,17 @@ pub mod auth_rule_command { command!(CommandMetadata::build("auth-rule", "Send AUTH_RULE request to change authentication rules for a ledger transaction.") .add_required_param("type", "Ledger transaction for which authentication rules will be applied. Can be an alias or associated value") - .add_required_param("action", "Type of action for which authentication rules will be applied. One of: ADD, EDIT") + .add_required_param("action", "Type of an action for which authentication rules will be applied. One of: ADD, EDIT") .add_required_param("field", "Transaction field for which authentication rule will be applied") .add_optional_param("old_value", "Old value of field, which can be changed to a new_value (mandatory for EDIT action)") .add_required_param("new_value", "New value that can be used to fill the field") - .add_required_param("constraint", r#"Set of constraints required for execution of action + .add_required_param("constraint", r#"Set of constraints required for execution of an action { constraint_id - type of a constraint. Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. role - role of a user which satisfy to constrain. sig_count - the number of signatures required to execution action. need_to_be_owner - if user must be an owner of transaction. - metadata - additional parameters of constraint. + metadata - additional parameters of the constraint. } can be combined by { diff --git a/libindy/include/indy_ledger.h b/libindy/include/indy_ledger.h index 2149e1cbee..a4017f638d 100644 --- a/libindy/include/indy_ledger.h +++ b/libindy/include/indy_ledger.h @@ -970,20 +970,19 @@ extern "C" { /// POOL_CONFIG or 111 /// REVOC_REG_DEF or 113 /// REVOC_REG_ENTRY or 114 - /// auth_action: type of action for which authentication rules will be applied. - /// Can be either "ADD" (to add new rule) or "EDIT" (to edit an existing one). + /// auth_action: type of an action for which authentication rules will be applied. + /// Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). /// field: transaction field for which authentication rule will be applied. - /// old_value: old value of field, which can be changed to a new_value (must be specified for EDIT action). + /// old_value: old value of a field, which can be changed to a new_value (mandatory for EDIT action). /// new_value: new value that can be used to fill the field. - /// constraint: set of constraints required for execution of action: - /// the following format: + /// constraint: set of constraints required for execution of an action in the following format /// { /// constraint_id - type of a constraint. /// Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. /// role - role of a user which satisfy to constrain. /// sig_count - the number of signatures required to execution action. /// need_to_be_owner - if user must be an owner of transaction. - /// metadata - additional parameters of constraint. + /// metadata - additional parameters of the constraint. /// } /// can be combined by /// { diff --git a/libindy/src/api/ledger.rs b/libindy/src/api/ledger.rs index 04b75d8f07..6fbd165d40 100644 --- a/libindy/src/api/ledger.rs +++ b/libindy/src/api/ledger.rs @@ -1850,19 +1850,19 @@ pub extern fn indy_get_response_metadata(command_handle: IndyHandle, /// POOL_CONFIG or 111 /// REVOC_REG_DEF or 113 /// REVOC_REG_ENTRY or 114 -/// auth_action: type of action for which authentication rules will be applied. -/// Can be either "ADD" (to add new rule) or "EDIT" (to edit an existing one). +/// auth_action: type of an action for which authentication rules will be applied. +/// Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). /// field: transaction field for which authentication rule will be applied. -/// old_value: old value of field, which can be changed to a new_value (must be specified for EDIT action). +/// old_value: old value of a field, which can be changed to a new_value (mandatory for EDIT action). /// new_value: new value that can be used to fill the field. -/// constraint: set of constraints required for execution of action in the following format: +/// constraint: set of constraints required for execution of an action in the following format: /// { /// constraint_id - type of a constraint. /// Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. /// role - role of a user which satisfy to constrain. /// sig_count - the number of signatures required to execution action. /// need_to_be_owner - if user must be an owner of transaction. -/// metadata - additional parameters of constraint. +/// metadata - additional parameters of the constraint. /// } /// can be combined by /// { @@ -1917,7 +1917,7 @@ pub extern fn indy_build_auth_rule_request(command_handle: IndyHandle, constraint, Box::new(move |result| { let (err, request_json) = prepare_result_1!(result, String::new()); - trace!("indy_build_nym_request: request_json: {:?}", request_json); + trace!("indy_build_auth_rule_request: request_json: {:?}", request_json); let request_json = ctypes::string_to_cstring(request_json); cb(command_handle, err, request_json.as_ptr()) }) diff --git a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h index 076eea6543..b8e74679f4 100644 --- a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h +++ b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h @@ -586,19 +586,19 @@ POOL_CONFIG or 111 REVOC_REG_DEF or 113 REVOC_REG_ENTRY or 114 - @param authAction - type of action for which authentication rules will be applied. - Can be either "ADD" (to add new rule) or "EDIT" (to edit an existing one). + @param authAction - type of an action for which authentication rules will be applied. + Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). @param field - transaction field for which authentication rule will be applied. - @param oldValue - old value of field, which can be changed to a new_value (must be specified for EDIT action). + @param oldValue - old value of a field, which can be changed to a new_value (mandatory for EDIT action). @param newValue - new value that can be used to fill the field. - @param constraint - set of constraints required for execution of action in the following format: + @param constraint - set of constraints required for execution of an action in the following format: { constraint_id - type of a constraint. Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. role - role of a user which satisfy to constrain. sig_count - the number of signatures required to execution action. need_to_be_owner - if user must be an owner of transaction. - metadata - additional parameters of constraint. + metadata - additional parameters of the constraint. } can be combined by { diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java index d8dbba179e..1effcb411d 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java @@ -1281,19 +1281,19 @@ public static CompletableFuture getResponseMetadata( * POOL_CONFIG or 111 * REVOC_REG_DEF or 113 * REVOC_REG_ENTRY or 114 - * @param authAction - type of action for which authentication rules will be applied. - * Can be either "ADD" (to add new rule) or "EDIT" (to edit an existing one). + * @param authAction - type of an action for which authentication rules will be applied. + * Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). * @param field - transaction field for which authentication rule will be applied. - * @param oldValue - old value of field, which can be changed to a new_value (must be specified for EDIT action). + * @param oldValue - old value of a field, which can be changed to a new_value (mandatory for EDIT action). * @param newValue - new value that can be used to fill the field. - * @param constraint - set of constraints required for execution of action in the following format: + * @param constraint - set of constraints required for execution of an action in the following format: * { * constraint_id - [string] type of a constraint. * Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. * role - [string] role of a user which satisfy to constrain. * sig_count - [u32] the number of signatures required to execution action. * need_to_be_owner - [bool] if user must be an owner of transaction. - * metadata - [object] additional parameters of constraint. + * metadata - [object] additional parameters of the constraint. * } * can be combined by * { diff --git a/wrappers/nodejs/README.md b/wrappers/nodejs/README.md index 3508d784c6..e75502e17e 100644 --- a/wrappers/nodejs/README.md +++ b/wrappers/nodejs/README.md @@ -1764,13 +1764,13 @@ Can be an alias or associated value: * POOL_CONFIG or 111 * REVOC_REG_DEF or 113 * REVOC_REG_ENTRY or 114 -* `authAction`: String - type of action for which authentication rules will be applied. - * "ADD" - to add new rule +* `authAction`: String - type of an action for which authentication rules will be applied. + * "ADD" - to add a new rule * "EDIT" - to edit an existing one * `field`: String - transaction field for which authentication rule will be applied. -* `oldValue`: String - \(Optional\) old value of field, which can be changed to a new_value (must be specified for EDIT action). +* `oldValue`: String - \(Optional\) old value of a field, which can be changed to a new_value (mandatory for EDIT action). * `newValue`: String - new value that can be used to fill the field. -* `constraint`: String - set of constraints required for execution of action in the following format: +* `constraint`: String - set of constraints required for execution of an action in the following format: ``` { constraint_id - type of a constraint. @@ -1778,7 +1778,7 @@ Can be an alias or associated value: role - role of a user which satisfy to constrain. sig_count - the number of signatures required to execution action. need_to_be_owner - if user must be an owner of transaction. - metadata - additional parameters of constraint. + metadata - additional parameters of the constraint. } can be combined by { diff --git a/wrappers/python/indy/ledger.py b/wrappers/python/indy/ledger.py index 0a716f1d88..43522feb3f 100644 --- a/wrappers/python/indy/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -1285,19 +1285,19 @@ async def build_auth_rule_request(submitter_did: str, POOL_CONFIG or 111 REVOC_REG_DEF or 113 REVOC_REG_ENTRY or 114 - :param auth_action: type of action for which authentication rules will be applied. - Can be either "ADD" (to add new rule) or "EDIT" (to edit an existing one). + :param auth_action: type of an action for which authentication rules will be applied. + Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). :param field: transaction field for which authentication rule will be applied. - :param old_value: old value of field, which can be changed to a new_value (must be specified for EDIT action). + :param old_value: old value of a field, which can be changed to a new_value (mandatory for EDIT action). :param new_value: new value that can be used to fill the field. - :param constraint: set of constraints required for execution of action in the following format: + :param constraint: set of constraints required for execution of an action in the following format: { constraint_id - type of a constraint. Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. role - role of a user which satisfy to constrain. sig_count - the number of signatures required to execution action. need_to_be_owner - if user must be an owner of transaction. - metadata - additional parameters of constraint. + metadata - additional parameters of the constraint. } can be combined by { diff --git a/wrappers/rust/src/ledger.rs b/wrappers/rust/src/ledger.rs index e8c9524320..1df82c4f52 100644 --- a/wrappers/rust/src/ledger.rs +++ b/wrappers/rust/src/ledger.rs @@ -1008,19 +1008,19 @@ fn _get_response_metadata(command_handle: IndyHandle, response: &str, cb: Option /// POOL_CONFIG or 111 /// REVOC_REG_DEF or 113 /// REVOC_REG_ENTRY or 114 -/// * `field`: type of action for which authentication rules will be applied. -/// Can be either "ADD" (to add new rule) or "EDIT" (to edit an existing one). +/// * `field`: type of an action for which authentication rules will be applied. +/// Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). /// * `auth_action`: transaction field for which authentication rule will be applied. -/// * `old_value`: old value of field, which can be changed to a new_value (must be specified for EDIT action). +/// * `old_value`: old value of a field, which can be changed to a new_value (mandatory for EDIT action). /// * `new_value`: new value that can be used to fill the field. -/// * `constraint`: set of constraints required for execution of action in the following format: +/// * `constraint`: set of constraints required for execution of an action in the following format: /// { /// constraint_id - type of a constraint. /// Can be either "ROLE" to specify final constraint or "AND"/"OR" to combine constraints. /// role - role of a user which satisfy to constrain. /// sig_count - the number of signatures required to execution action. /// need_to_be_owner - if user must be an owner of transaction. -/// metadata - additional parameters of constraint. +/// metadata - additional parameters of the constraint. /// } /// can be combined by /// { From 4b5c4b2af0e49204ef1678d96223cf7f19765697 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 6 Mar 2019 14:05:53 +0300 Subject: [PATCH 14/18] IS-1201 Renamed params Signed-off-by: artem.ivanov --- cli/src/commands/ledger.rs | 28 +++++++++----- cli/src/libindy/ledger.rs | 6 +-- docs/design/001-cli/README.md | 2 +- libindy/include/indy_ledger.h | 18 ++------- libindy/src/api/ledger.rs | 38 +++++++------------ libindy/src/commands/ledger.rs | 14 +++---- libindy/src/domain/ledger/constants.rs | 18 ++++++++- libindy/src/services/ledger/mod.rs | 18 ++++----- libindy/tests/utils/ledger.rs | 6 +-- .../Case Tests/Ledger/LedgerBuildRequest.mm | 4 +- .../Indy-demoTests/Test Utils/LedgerUtils.h | 4 +- .../Indy-demoTests/Test Utils/LedgerUtils.mm | 8 ++-- .../ios/libindy-pod/Indy/Wrapper/IndyLedger.h | 18 ++------- .../libindy-pod/Indy/Wrapper/IndyLedger.mm | 8 ++-- .../org/hyperledger/indy/sdk/LibIndy.java | 2 +- .../hyperledger/indy/sdk/ledger/Ledger.java | 26 ++++--------- .../indy/sdk/ledger/AuthRuleRequestsTest.java | 6 +-- wrappers/nodejs/README.md | 16 ++------ wrappers/nodejs/src/index.js | 4 +- wrappers/nodejs/src/indy.cc | 4 +- wrappers/python/indy/ledger.py | 30 +++++---------- .../ledger/test_build_auth_rule_request.py | 6 +-- wrappers/rust/indy-sys/src/ledger.rs | 4 +- wrappers/rust/src/ledger.rs | 30 +++++---------- 24 files changed, 136 insertions(+), 182 deletions(-) diff --git a/cli/src/commands/ledger.rs b/cli/src/commands/ledger.rs index 5433f3583a..95a60ff3bb 100644 --- a/cli/src/commands/ledger.rs +++ b/cli/src/commands/ledger.rs @@ -1222,7 +1222,7 @@ pub mod auth_rule_command { use super::*; command!(CommandMetadata::build("auth-rule", "Send AUTH_RULE request to change authentication rules for a ledger transaction.") - .add_required_param("type", "Ledger transaction for which authentication rules will be applied. Can be an alias or associated value") + .add_required_param("txn_type", "Ledger transaction alias or associated value for which authentication rules will be applied") .add_required_param("action", "Type of an action for which authentication rules will be applied. One of: ADD, EDIT") .add_required_param("field", "Transaction field for which authentication rule will be applied") .add_optional_param("old_value", "Old value of field, which can be changed to a new_value (mandatory for EDIT action)") @@ -1241,8 +1241,8 @@ pub mod auth_rule_command { auth_constraints: [, ] } "#) - .add_example(r#"ledger auth-rule type=NYM action=ADD field=role new_value=101 constraint={"sig_count":1,"role":0,"constraint_id":"role","need_to_be_owner":false}"#) - .add_example(r#"ledger auth-rule type=NYM action=EDIT field=role old_value=101 new_value=0 constraint={"sig_count":1,"role":0,"constraint_id":"role","need_to_be_owner":false}"#) + .add_example(r#"ledger auth-rule txn_type=NYM action=ADD field=role new_value=101 constraint={"sig_count":1,"role":0,"constraint_id":"role","need_to_be_owner":false}"#) + .add_example(r#"ledger auth-rule txn_type=NYM action=EDIT field=role old_value=101 new_value=0 constraint={"sig_count":1,"role":0,"constraint_id":"role","need_to_be_owner":false}"#) .finalize() ); @@ -1253,14 +1253,14 @@ pub mod auth_rule_command { let (wallet_handle, wallet_name) = ensure_opened_wallet(&ctx)?; let submitter_did = ensure_active_did(&ctx)?; - let auth_type = get_str_param("type", params).map_err(error_err!())?; - let auth_action = get_str_param("action", params).map_err(error_err!())?; + let txn_type = get_str_param("txn_type", params).map_err(error_err!())?; + let action = get_str_param("action", params).map_err(error_err!())?; let field = get_str_param("field", params).map_err(error_err!())?; let old_value = get_opt_str_param("old_value", params).map_err(error_err!())?; let new_value = get_str_param("new_value", params).map_err(error_err!())?; let constraint = get_str_param("constraint", params).map_err(error_err!())?; - let request = Ledger::build_auth_rule_request(&submitter_did, auth_type, &auth_action.to_uppercase(), field, old_value, new_value, constraint) + let request = Ledger::build_auth_rule_request(&submitter_did, txn_type, &action.to_uppercase(), field, old_value, new_value, constraint) .map_err(|err| handle_indy_error(err, None, None, None))?; let response_json = Ledger::sign_and_submit_request(pool_handle, wallet_handle, &submitter_did, &request) @@ -1277,7 +1277,7 @@ pub mod auth_rule_command { .map(|result| print_transaction_response(result, "Auth Rule request has been sent to Ledger.", None, - &mut vec![("auth_type", "Type"), + &mut vec![("auth_type", "Txn Type"), ("auth_action", "Action"), ("field", "Field"), ("old_value", "Old Value"), @@ -1488,13 +1488,24 @@ fn get_txn_title(role: &serde_json::Value) -> serde_json::Value { serde_json::Value::String(match role.as_str() { Some("0") => "NODE", Some("1") => "NYM", + Some("3") => "GET_TXN", Some("100") => "ATTRIB", Some("101") => "SCHEMA", + Some("104") => "GET_ATTR", + Some("105") => "GET_NYM", + Some("107") => "GET_SCHEMA", + Some("108") => "GET_CRED_DEF", Some("102") => "CRED_DEF", Some("109") => "POOL_UPGRADE", Some("111") => "POOL_CONFIG", Some("113") => "REVOC_REG_DEF", Some("114") => "REVOC_REG_ENTRY", + Some("115") => "GET_REVOC_REG_DEF", + Some("116") => "GET_REVOC_REG", + Some("117") => "GET_REVOC_REG_DELTA", + Some("118") => "POOL_RESTART", + Some("119") => "GET_VALIDATOR_INFO", + Some("120") => "AUTH_RULE", Some(val) => val, _ => "-" }.to_string()) @@ -3575,11 +3586,10 @@ pub mod tests { pub fn auth_rule_works() { let ctx = setup_with_wallet_and_pool(); use_trustee(&ctx); - let (did, verkey) = create_new_did(&ctx); { let cmd = auth_rule_command::new(); let mut params = CommandParams::new(); - params.insert("type", "NYM".to_string()); + params.insert("txn_type", "NYM".to_string()); params.insert("action", "add".to_string()); params.insert("field", "role".to_string()); params.insert("new_value", "101".to_string()); diff --git a/cli/src/libindy/ledger.rs b/cli/src/libindy/ledger.rs index 8e378c227e..4c1322b217 100644 --- a/cli/src/libindy/ledger.rs +++ b/cli/src/libindy/ledger.rs @@ -82,13 +82,13 @@ impl Ledger { } pub fn build_auth_rule_request(submitter_did: &str, - auth_type: &str, - auth_action: &str, + txn_type: &str, + action: &str, field: &str, old_value: Option<&str>, new_value: &str, constraint: &str, ) -> Result { - ledger::build_auth_rule_request(submitter_did, auth_type, auth_action, field, + ledger::build_auth_rule_request(submitter_did, txn_type, action, field, old_value, new_value, constraint).wait() } } \ No newline at end of file diff --git a/docs/design/001-cli/README.md b/docs/design/001-cli/README.md index be4eca6e6a..6523f95116 100644 --- a/docs/design/001-cli/README.md +++ b/docs/design/001-cli/README.md @@ -336,7 +336,7 @@ ledger custom [txn=] [sign=] #### AUTH_RULE transaction Send AUTH_RULE transaction ``` -ledger auth-rule type= action= field= [old_value=] new_value= constraint=<{constraint json}> +ledger auth-rule txn_type= action= field= [old_value=] new_value= constraint=<{constraint json}> ``` #### GET_PAYMENT_SOURCES transaction diff --git a/libindy/include/indy_ledger.h b/libindy/include/indy_ledger.h index a4017f638d..271055f9be 100644 --- a/libindy/include/indy_ledger.h +++ b/libindy/include/indy_ledger.h @@ -959,18 +959,8 @@ extern "C" { /// /// #Params /// command_handle: command handle to map callback to caller context. - /// auth_type: ledger transaction for which authentication rules will be applied. - /// Can be an alias or associated value: - /// NODE or 0 - /// NYM or 1 - /// ATTRIB or 100 - /// SCHEMA or 101 - /// CRED_DEF or 102 - /// POOL_UPGRADE or 109 - /// POOL_CONFIG or 111 - /// REVOC_REG_DEF or 113 - /// REVOC_REG_ENTRY or 114 - /// auth_action: type of an action for which authentication rules will be applied. + /// txn_type: ledger transaction alias or associated value for which authentication rules will be applied. + /// action: type of an action for which authentication rules will be applied. /// Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). /// field: transaction field for which authentication rule will be applied. /// old_value: old value of a field, which can be changed to a new_value (mandatory for EDIT action). @@ -999,8 +989,8 @@ extern "C" { /// Common* extern indy_error_t indy_build_auth_rule_request(indy_handle_t command_handle, const char * submitter_did, - const char * auth_type, - const char * auth_action, + const char * txn_type, + const char * action, const char * field, const char * old_value, const char * new_value, diff --git a/libindy/src/api/ledger.rs b/libindy/src/api/ledger.rs index 839b5ff5cd..3b5c9bb353 100644 --- a/libindy/src/api/ledger.rs +++ b/libindy/src/api/ledger.rs @@ -1839,18 +1839,8 @@ pub extern fn indy_get_response_metadata(command_handle: CommandHandle, /// /// #Params /// command_handle: command handle to map callback to caller context. -/// auth_type: ledger transaction for which authentication rules will be applied. -/// Can be an alias or associated value: -/// NODE or 0 -/// NYM or 1 -/// ATTRIB or 100 -/// SCHEMA or 101 -/// CRED_DEF or 102 -/// POOL_UPGRADE or 109 -/// POOL_CONFIG or 111 -/// REVOC_REG_DEF or 113 -/// REVOC_REG_ENTRY or 114 -/// auth_action: type of an action for which authentication rules will be applied. +/// txn_type: ledger transaction alias or associated value for which authentication rules will be applied. +/// action: type of an action for which authentication rules will be applied. /// Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). /// field: transaction field for which authentication rule will be applied. /// old_value: old value of a field, which can be changed to a new_value (mandatory for EDIT action). @@ -1878,39 +1868,39 @@ pub extern fn indy_get_response_metadata(command_handle: CommandHandle, /// #Errors /// Common* #[no_mangle] -pub extern fn indy_build_auth_rule_request(command_handle: IndyHandle, +pub extern fn indy_build_auth_rule_request(command_handle: CommandHandle, submitter_did: *const c_char, - auth_type: *const c_char, - auth_action: *const c_char, + txn_type: *const c_char, + action: *const c_char, field: *const c_char, old_value: *const c_char, new_value: *const c_char, constraint: *const c_char, - cb: Option) -> ErrorCode { - trace!("indy_build_auth_rule_request: >>> submitter_did: {:?}, auth_type: {:?}, auth_action: {:?}, field: {:?}, \ + trace!("indy_build_auth_rule_request: >>> submitter_did: {:?}, txn_type: {:?}, action: {:?}, field: {:?}, \ old_value: {:?}, new_value: {:?}, constraint: {:?}", - submitter_did, auth_type, auth_action, field, old_value, new_value, constraint); + submitter_did, txn_type, action, field, old_value, new_value, constraint); check_useful_c_str!(submitter_did, ErrorCode::CommonInvalidParam2); - check_useful_c_str!(auth_type, ErrorCode::CommonInvalidParam3); - check_useful_c_str!(auth_action, ErrorCode::CommonInvalidParam4); + check_useful_c_str!(txn_type, ErrorCode::CommonInvalidParam3); + check_useful_c_str!(action, ErrorCode::CommonInvalidParam4); check_useful_c_str!(field, ErrorCode::CommonInvalidParam5); check_useful_opt_c_str!(old_value, ErrorCode::CommonInvalidParam6); check_useful_c_str!(new_value, ErrorCode::CommonInvalidParam7); check_useful_c_str!(constraint, ErrorCode::CommonInvalidParam8); check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam9); - trace!("indy_build_auth_rule_request: entities >>> submitter_did: {:?}, auth_type: {:?}, auth_action: {:?}, field: {:?}, \ + trace!("indy_build_auth_rule_request: entities >>> submitter_did: {:?}, txn_type: {:?}, action: {:?}, field: {:?}, \ old_value: {:?}, new_value: {:?}, constraint: {:?}", - submitter_did, auth_type, auth_action, field, old_value, new_value, constraint); + submitter_did, txn_type, action, field, old_value, new_value, constraint); let result = CommandExecutor::instance() .send(Command::Ledger(LedgerCommand::BuildAuthRuleRequest( submitter_did, - auth_type, - auth_action, + txn_type, + action, field, old_value, new_value, diff --git a/libindy/src/commands/ledger.rs b/libindy/src/commands/ledger.rs index fcbfeb24af..9818afe5f4 100644 --- a/libindy/src/commands/ledger.rs +++ b/libindy/src/commands/ledger.rs @@ -370,9 +370,9 @@ impl LedgerCommandExecutor { info!(target: "ledger_command_executor", "GetResponseMetadata command received"); cb(self.get_response_metadata(&response)); } - LedgerCommand::BuildAuthRuleRequest(submitter_did, auth_type, auth_action, field, old_value, new_value, constraint, cb) => { + LedgerCommand::BuildAuthRuleRequest(submitter_did, txn_type, action, field, old_value, new_value, constraint, cb) => { info!(target: "ledger_command_executor", "BuildAuthRuleRequest command received"); - cb(self.build_auth_rule_request(&submitter_did, &auth_type, &auth_action, &field, old_value.as_ref().map(String::as_str), &new_value, &constraint)); + cb(self.build_auth_rule_request(&submitter_did, &txn_type, &action, &field, old_value.as_ref().map(String::as_str), &new_value, &constraint)); } }; } @@ -905,18 +905,18 @@ impl LedgerCommandExecutor { fn build_auth_rule_request(&self, submitter_did: &str, - auth_type: &str, - auth_action: &str, + txn_type: &str, + action: &str, field: &str, old_value: Option<&str>, new_value: &str, constraint: &str) -> IndyResult { - debug!("build_auth_rule_request >>> submitter_did: {:?}, auth_type: {:?}, auth_action: {:?}, field: {:?}, \ - old_value: {:?}, new_value: {:?}, constraint: {:?}", submitter_did, auth_type, auth_action, field, old_value, new_value, constraint); + debug!("build_auth_rule_request >>> submitter_did: {:?}, txn_type: {:?}, action: {:?}, field: {:?}, \ + old_value: {:?}, new_value: {:?}, constraint: {:?}", submitter_did, txn_type, action, field, old_value, new_value, constraint); self.validate_opt_did(Some(submitter_did))?; - let res = self.ledger_service.build_auth_rule_request(submitter_did, auth_type, auth_action, field, old_value, new_value, constraint)?; + let res = self.ledger_service.build_auth_rule_request(submitter_did, txn_type, action, field, old_value, new_value, constraint)?; debug!("build_auth_rule_request <<< res: {:?}", res); diff --git a/libindy/src/domain/ledger/constants.rs b/libindy/src/domain/ledger/constants.rs index b56a398b15..26f964bbb7 100644 --- a/libindy/src/domain/ledger/constants.rs +++ b/libindy/src/domain/ledger/constants.rs @@ -20,7 +20,9 @@ pub const GET_VALIDATOR_INFO: &str = "119"; pub const AUTH_RULE: &str = "120"; pub const GET_DDO: &str = "120";//TODO change number -pub const WRITE_REQUESTS: [&str; 9] = [NODE, NYM, ATTRIB, SCHEMA, CRED_DEF, POOL_UPGRADE, POOL_CONFIG, REVOC_REG_DEF, REVOC_REG_ENTRY]; +pub const REQUESTS: [&str; 21] = [NODE, NYM, GET_TXN, ATTRIB, SCHEMA, CRED_DEF, GET_ATTR, GET_NYM, GET_SCHEMA, + GET_CRED_DEF, POOL_UPGRADE, POOL_RESTART, POOL_CONFIG, REVOC_REG_DEF, REVOC_REG_ENTRY, GET_REVOC_REG_DEF, + GET_REVOC_REG, GET_REVOC_REG_DELTA, GET_VALIDATOR_INFO, AUTH_RULE, GET_DDO]; pub const TRUSTEE: &str = "0"; pub const STEWARD: &str = "2"; @@ -30,20 +32,32 @@ pub const ROLE_REMOVE: &str = ""; pub fn txn_name_to_code(txn: &str) -> Option<&str> { - if WRITE_REQUESTS.contains(&txn) { + if REQUESTS.contains(&txn) { return Some(txn) } match txn { "NODE" => Some(NODE), "NYM" => Some(NYM), + "GET_TXN" => Some(GET_TXN), "ATTRIB" => Some(ATTRIB), "SCHEMA" => Some(SCHEMA), "CRED_DEF" | "CLAIM_DEF" => Some(CRED_DEF), + "GET_ATTR" => Some(GET_ATTR), + "GET_NYM" => Some(GET_NYM), + "GET_SCHEMA" => Some(GET_SCHEMA), + "GET_CRED_DEF" => Some(GET_CRED_DEF), "POOL_UPGRADE" => Some(POOL_UPGRADE), + "POOL_RESTART" => Some(POOL_RESTART), "POOL_CONFIG" => Some(POOL_CONFIG), "REVOC_REG_DEF" => Some(REVOC_REG_DEF), "REVOC_REG_ENTRY" => Some(REVOC_REG_ENTRY), + "GET_REVOC_REG_DEF" => Some(GET_REVOC_REG_DEF), + "GET_REVOC_REG" => Some(GET_REVOC_REG), + "GET_REVOC_REG_DELTA" => Some(GET_REVOC_REG_DELTA), + "GET_VALIDATOR_INFO" => Some(GET_VALIDATOR_INFO), + "AUTH_RULE" => Some(AUTH_RULE), + "GET_DDO" => Some(GET_DDO), _ => None } } \ No newline at end of file diff --git a/libindy/src/services/ledger/mod.rs b/libindy/src/services/ledger/mod.rs index 3e2cbcee0c..ec6c9bb624 100644 --- a/libindy/src/services/ledger/mod.rs +++ b/libindy/src/services/ledger/mod.rs @@ -79,25 +79,25 @@ impl LedgerService { Ok(request) } - pub fn build_auth_rule_request(&self, submitter_did: &str, auth_type: &str, auth_action: &str, field: &str, + pub fn build_auth_rule_request(&self, submitter_did: &str, txn_type: &str, action: &str, field: &str, old_value: Option<&str>, new_value: &str, constraint: &str) -> IndyResult { - info!("build_auth_rule_request >>> submitter_did: {:?}, auth_type: {:?}, auth_action: {:?}, field: {:?}, \ - old_value: {:?}, new_value: {:?}, constraint: {:?}", submitter_did, auth_type, auth_action, field, old_value, new_value, constraint); + info!("build_auth_rule_request >>> submitter_did: {:?}, txn_type: {:?}, action: {:?}, field: {:?}, \ + old_value: {:?}, new_value: {:?}, constraint: {:?}", submitter_did, txn_type, action, field, old_value, new_value, constraint); - let auth_type = txn_name_to_code(&auth_type) - .ok_or(err_msg(IndyErrorKind::InvalidStructure, format!("Unsupported `auth_type`: {}", auth_type)))?; + let txn_type = txn_name_to_code(&txn_type) + .ok_or(err_msg(IndyErrorKind::InvalidStructure, format!("Unsupported `txn_type`: {}", txn_type)))?; - let auth_action = serde_json::from_str::(&format!("\"{}\"", auth_action)) - .map_err(|err| IndyError::from_msg(IndyErrorKind::InvalidStructure, format!("Cannot parse auth action: {}", err)))?; + let action = serde_json::from_str::(&format!("\"{}\"", action)) + .map_err(|err| IndyError::from_msg(IndyErrorKind::InvalidStructure, format!("Cannot parse action: {}", err)))?; - if auth_action == AuthAction::EDIT && old_value.is_none() { + if action == AuthAction::EDIT && old_value.is_none() { return Err(err_msg(IndyErrorKind::InvalidStructure, "`old_value` must be specified for EDIT auth action")); } let constraint = serde_json::from_str::(constraint) .map_err(|err| IndyError::from_msg(IndyErrorKind::InvalidStructure, format!("Can not deserialize Constraint: {}", err)))?; - let operation = AuthRuleOperation::new(auth_type.to_string(), field.to_string(), auth_action, + let operation = AuthRuleOperation::new(txn_type.to_string(), field.to_string(), action, old_value.map(String::from), new_value.to_string(), constraint); let request = Request::build_request(Some(submitter_did), operation) diff --git a/libindy/tests/utils/ledger.rs b/libindy/tests/utils/ledger.rs index 4b84c91021..b3d1b764f4 100644 --- a/libindy/tests/utils/ledger.rs +++ b/libindy/tests/utils/ledger.rs @@ -201,13 +201,13 @@ pub fn get_response_metadata(response: &str) -> Result { } pub fn build_auth_rule_request(submitter_did: &str, - auth_type: &str, - auth_action: &str, + txn_type: &str, + action: &str, field: &str, old_value: Option<&str>, new_value: &str, constraint: &str, ) -> Result { - ledger::build_auth_rule_request(submitter_did, auth_type, auth_action, field, old_value, new_value, constraint).wait() + ledger::build_auth_rule_request(submitter_did, txn_type, action, field, old_value, new_value, constraint).wait() } pub fn post_entities() -> (&'static str, &'static str, &'static str) { diff --git a/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Ledger/LedgerBuildRequest.mm b/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Ledger/LedgerBuildRequest.mm index 440c5072ac..0718ff437a 100644 --- a/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Ledger/LedgerBuildRequest.mm +++ b/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Ledger/LedgerBuildRequest.mm @@ -665,8 +665,8 @@ - (void)testBuildAuthRuleRequestsWorks { NSString *requestJson; ret = [[LedgerUtils sharedInstance] buildAuthRuleRequestWithSubmitterDid:[TestUtils trusteeDid] - authType:@"NYM" - authAction:@"ADD" + txnType:@"NYM" + action:@"ADD" field:@"role" oldValue:nil newValue:@"101" diff --git a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.h b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.h index a690af5c41..e08516828d 100644 --- a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.h +++ b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.h @@ -181,8 +181,8 @@ // MARK: - Auth Rule request - (NSError *)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid - authType:(NSString *)authType - authAction:(NSString *)authAction + txnType:(NSString *)txnType + action:(NSString *)action field:(NSString *)field oldValue:(NSString *)oldValue newValue:(NSString *)newValue diff --git a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.mm b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.mm index 9aaf83cdea..5414042ecb 100644 --- a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.mm +++ b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/LedgerUtils.mm @@ -730,8 +730,8 @@ - (NSError *)multiSignRequestWithWalletHandle:(IndyHandle)walletHandle } - (NSError *)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid - authType:(NSString *)authType - authAction:(NSString *)authAction + txnType:(NSString *)txnType + action:(NSString *)action field:(NSString *)field oldValue:(NSString *)oldValue newValue:(NSString *)newValue @@ -742,8 +742,8 @@ - (NSError *)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid __block NSString *outJson = nil; [IndyLedger buildAuthRuleRequestWithSubmitterDid:submitterDid - authType:authType - authAction:authAction + txnType:txnType + action:action field:field oldValue:oldValue newValue:newValue diff --git a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h index b8e74679f4..64329322b4 100644 --- a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h +++ b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h @@ -575,18 +575,8 @@ Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. @param submitterDid DID of the submitter stored in secured Wallet. - @param authType - ledger transaction for which authentication rules will be applied. - Can be an alias or associated value: - NODE or 0 - NYM or 1 - ATTRIB or 100 - SCHEMA or 101 - CRED_DEF or 102 - POOL_UPGRADE or 109 - POOL_CONFIG or 111 - REVOC_REG_DEF or 113 - REVOC_REG_ENTRY or 114 - @param authAction - type of an action for which authentication rules will be applied. + @param txnType - ledger transaction alias or associated value for which authentication rules will be applied. + @param action - type of an action for which authentication rules will be applied. Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). @param field - transaction field for which authentication rule will be applied. @param oldValue - old value of a field, which can be changed to a new_value (mandatory for EDIT action). @@ -609,8 +599,8 @@ @param completion Callback that takes command result as parameter. Returns request result as json. */ + (void)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid - authType:(NSString *)authType - authAction:(NSString *)authAction + txnType:(NSString *)txnType + action:(NSString *)action field:(NSString *)field oldValue:(NSString *)oldValue newValue:(NSString *)newValue diff --git a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.mm b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.mm index b2ec9876eb..40e7af3125 100644 --- a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.mm +++ b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.mm @@ -707,8 +707,8 @@ + (void)parseGetRevocRegDeltaResponse:(NSString *)getRevocRegDeltaResponse } + (void)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid - authType:(NSString *)authType - authAction:(NSString *)authAction + txnType:(NSString *)txnType + action:(NSString *)action field:(NSString *)field oldValue:(NSString *)oldValue newValue:(NSString *)newValue @@ -721,8 +721,8 @@ + (void)buildAuthRuleRequestWithSubmitterDid:(NSString *)submitterDid ret = indy_build_auth_rule_request(handle, [submitterDid UTF8String], - [authType UTF8String], - [authAction UTF8String], + [txnType UTF8String], + [action UTF8String], [field UTF8String], [oldValue UTF8String], [newValue UTF8String], diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java index 84459dccfa..06470f85ea 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/LibIndy.java @@ -70,7 +70,7 @@ public interface API extends Library { public int indy_build_get_revoc_reg_delta_request(int command_handle, String submitter_did, String revoc_reg_def_id, long from, long to, Callback cb); public int indy_parse_get_revoc_reg_delta_response(int command_handle, String get_revoc_reg_delta_response, Callback cb); public int indy_get_response_metadata(int command_handle, String response, Callback cb); - public int indy_build_auth_rule_request(int command_handle, String submitter_did, String auth_type, String auth_action, String field, String old_value, String new_value, String constraint, Callback cb); + public int indy_build_auth_rule_request(int command_handle, String submitter_did, String txn_type, String action, String field, String old_value, String new_value, String constraint, Callback cb); // did.rs diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java index 1effcb411d..77b4a33edd 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java @@ -1270,18 +1270,8 @@ public static CompletableFuture getResponseMetadata( * Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. * * @param submitterDid DID of the submitter stored in secured Wallet. - * @param authType - ledger transaction for which authentication rules will be applied. - * Can be an alias or associated value: - * NODE or 0 - * NYM or 1 - * ATTRIB or 100 - * SCHEMA or 101 - * CRED_DEF or 102 - * POOL_UPGRADE or 109 - * POOL_CONFIG or 111 - * REVOC_REG_DEF or 113 - * REVOC_REG_ENTRY or 114 - * @param authAction - type of an action for which authentication rules will be applied. + * @param txnType - ledger transaction alias or associated value for which authentication rules will be applied. + * @param action - type of an action for which authentication rules will be applied. * Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). * @param field - transaction field for which authentication rule will be applied. * @param oldValue - old value of a field, which can be changed to a new_value (mandatory for EDIT action). @@ -1306,16 +1296,16 @@ public static CompletableFuture getResponseMetadata( */ public static CompletableFuture buildAuthRuleRequest( String submitterDid, - String authType, - String authAction, + String txnType, + String action, String field, String oldValue, String newValue, String constraint) throws IndyException { ParamGuard.notNullOrWhiteSpace(submitterDid, "submitterDid"); - ParamGuard.notNullOrWhiteSpace(authType, "authType"); - ParamGuard.notNullOrWhiteSpace(authAction, "authAction"); + ParamGuard.notNullOrWhiteSpace(txnType, "txnType"); + ParamGuard.notNullOrWhiteSpace(action, "action"); CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); @@ -1323,8 +1313,8 @@ public static CompletableFuture buildAuthRuleRequest( int result = LibIndy.api.indy_build_auth_rule_request( commandHandle, submitterDid, - authType, - authAction, + txnType, + action, field, oldValue, newValue, diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AuthRuleRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AuthRuleRequestsTest.java index 8c3e991332..b71b49d258 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AuthRuleRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/AuthRuleRequestsTest.java @@ -6,7 +6,7 @@ public class AuthRuleRequestsTest extends IndyIntegrationTest { - private String authType = "NYM"; + private String txnType = "NYM"; private String field = "role"; private String newValue = "101"; private JSONObject constraint = new JSONObject() @@ -31,7 +31,7 @@ public void testBuildAuthRuleRequestWorksForAddAction() throws Exception { .put("constraint", constraint) ); - String request = Ledger.buildAuthRuleRequest(DID, authType, addAuthAction, field, null, newValue, constraint.toString()).get(); + String request = Ledger.buildAuthRuleRequest(DID, txnType, addAuthAction, field, null, newValue, constraint.toString()).get(); assert (new JSONObject(request).toMap().entrySet() .containsAll( @@ -56,7 +56,7 @@ public void testBuildAuthRuleRequestWorksForEditAction() throws Exception { .put("constraint", constraint) ); - String request = Ledger.buildAuthRuleRequest(DID, authType, editAuthAction, field, oldValue, newValue, constraint.toString()).get(); + String request = Ledger.buildAuthRuleRequest(DID, txnType, editAuthAction, field, oldValue, newValue, constraint.toString()).get(); assert (new JSONObject(request).toMap().entrySet() .containsAll( diff --git a/wrappers/nodejs/README.md b/wrappers/nodejs/README.md index e75502e17e..009b8fa964 100644 --- a/wrappers/nodejs/README.md +++ b/wrappers/nodejs/README.md @@ -1748,23 +1748,13 @@ Parse a GET\_REVOC\_REG\_DELTA response to get Revocation Registry Delta in the Errors: `Common*` -#### buildAuthRuleRequest \( submitterDid, authType, authAction, field, oldValue, newValue, constraint \) -> request +#### buildAuthRuleRequest \( submitterDid, txnType, action, field, oldValue, newValue, constraint \) -> request Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. * `submitterDid`: String - \(Optional\) DID of the read request sender \(if not provided then default Libindy DID will be used\). -* `authType`: String - ledger transaction for which authentication rules will be applied. -Can be an alias or associated value: - * NODE or 0 - * NYM or 1 - * ATTRIB or 100 - * SCHEMA or 101 - * CRED_DEF or 102 - * POOL_UPGRADE or 109 - * POOL_CONFIG or 111 - * REVOC_REG_DEF or 113 - * REVOC_REG_ENTRY or 114 -* `authAction`: String - type of an action for which authentication rules will be applied. +* `txnType`: String - ledger transaction alias or associated value for which authentication rules will be applied. +* `action`: String - type of an action for which authentication rules will be applied. * "ADD" - to add a new rule * "EDIT" - to edit an existing one * `field`: String - transaction field for which authentication rule will be applied. diff --git a/wrappers/nodejs/src/index.js b/wrappers/nodejs/src/index.js index 2a61c5b72d..b351e21fc1 100644 --- a/wrappers/nodejs/src/index.js +++ b/wrappers/nodejs/src/index.js @@ -541,9 +541,9 @@ indy.parseGetRevocRegDeltaResponse = function parseGetRevocRegDeltaResponse (get return cb.promise } -indy.buildAuthRuleRequest = function buildAuthRuleRequest (submitterDid, authType, authAction, field, oldValue, newValue, constraint, cb) { +indy.buildAuthRuleRequest = function buildAuthRuleRequest (submitterDid, txnType, action, field, oldValue, newValue, constraint, cb) { cb = wrapIndyCallback(cb, fromJson) - capi.buildAuthRuleRequest(submitterDid, authType, authAction, field, oldValue, newValue, toJson(constraint), cb) + capi.buildAuthRuleRequest(submitterDid, txnType, action, field, oldValue, newValue, toJson(constraint), cb) return cb.promise } diff --git a/wrappers/nodejs/src/indy.cc b/wrappers/nodejs/src/indy.cc index a57acfe314..da4698f82d 100644 --- a/wrappers/nodejs/src/indy.cc +++ b/wrappers/nodejs/src/indy.cc @@ -2047,8 +2047,8 @@ void buildAuthRuleRequest_cb(indy_handle_t handle, indy_error_t xerr, const char NAN_METHOD(buildAuthRuleRequest) { INDY_ASSERT_NARGS(buildAuthRuleRequest, 8) INDY_ASSERT_STRING(buildAuthRuleRequest, 0, submitterDid) - INDY_ASSERT_STRING(buildAuthRuleRequest, 1, authType) - INDY_ASSERT_STRING(buildAuthRuleRequest, 2, authAction) + INDY_ASSERT_STRING(buildAuthRuleRequest, 1, txnType) + INDY_ASSERT_STRING(buildAuthRuleRequest, 2, action) INDY_ASSERT_STRING(buildAuthRuleRequest, 3, field) INDY_ASSERT_STRING(buildAuthRuleRequest, 4, oldValue) INDY_ASSERT_STRING(buildAuthRuleRequest, 5, newValue) diff --git a/wrappers/python/indy/ledger.py b/wrappers/python/indy/ledger.py index 43522feb3f..017d88abe8 100644 --- a/wrappers/python/indy/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -1264,7 +1264,7 @@ async def get_response_metadata(response: str) -> str: async def build_auth_rule_request(submitter_did: str, - auth_type: str, + txn_type: str, auth_action: str, field: str, old_value: Optional[str], @@ -1274,18 +1274,8 @@ async def build_auth_rule_request(submitter_did: str, Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. :param submitter_did: DID of the submitter stored in secured Wallet. - :param auth_type: ledger transaction for which authentication rules will be applied. - Can be an alias or associated value: - NODE or 0 - NYM or 1 - ATTRIB or 100 - SCHEMA or 101 - CRED_DEF or 102 - POOL_UPGRADE or 109 - POOL_CONFIG or 111 - REVOC_REG_DEF or 113 - REVOC_REG_ENTRY or 114 - :param auth_action: type of an action for which authentication rules will be applied. + :param txn_type: ledger transaction alias or associated value for which authentication rules will be applied. + :param action: type of an action for which authentication rules will be applied. Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). :param field: transaction field for which authentication rule will be applied. :param old_value: old value of a field, which can be changed to a new_value (mandatory for EDIT action). @@ -1309,11 +1299,11 @@ async def build_auth_rule_request(submitter_did: str, """ logger = logging.getLogger(__name__) - logger.debug("build_auth_rule_request: >>> submitter_did: %r, auth_type: %r, auth_action: %r, field: %r, " + logger.debug("build_auth_rule_request: >>> submitter_did: %r, txn_type: %r, action: %r, field: %r, " "old_value: %r, new_value: %r, constraint: %r", submitter_did, - auth_type, - auth_action, + txn_type, + action, field, old_value, new_value, @@ -1324,8 +1314,8 @@ async def build_auth_rule_request(submitter_did: str, build_auth_rule_request.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) c_submitter_did = c_char_p(submitter_did.encode('utf-8')) - c_auth_type = c_char_p(auth_type.encode('utf-8')) - c_auth_action = c_char_p(auth_action.encode('utf-8')) + c_txn_type = c_char_p(txn_type.encode('utf-8')) + c_action = c_char_p(action.encode('utf-8')) c_field = c_char_p(field.encode('utf-8')) c_old_value = c_char_p(old_value.encode('utf-8')) if old_value is not None else None c_new_value = c_char_p(new_value.encode('utf-8')) @@ -1333,8 +1323,8 @@ async def build_auth_rule_request(submitter_did: str, request_json = await do_call('indy_build_auth_rule_request', c_submitter_did, - c_auth_type, - c_auth_action, + c_txn_type, + c_action, c_field, c_old_value, c_new_value, diff --git a/wrappers/python/tests/ledger/test_build_auth_rule_request.py b/wrappers/python/tests/ledger/test_build_auth_rule_request.py index f0955ef21b..aebe92a5dd 100644 --- a/wrappers/python/tests/ledger/test_build_auth_rule_request.py +++ b/wrappers/python/tests/ledger/test_build_auth_rule_request.py @@ -5,7 +5,7 @@ import pytest identifier = "Th7MpTaRZVRYnPiabds81Y" -auth_type = "NYM" +txn_type = "NYM" add_auth_action = "ADD" edit_auth_action = "EDIT" field = 'role' @@ -35,7 +35,7 @@ async def test_build_auth_rule_request_works_for_add_auth_action(): } request = json.loads( - await ledger.build_auth_rule_request(identifier, auth_type, add_auth_action, field, None, new_value, + await ledger.build_auth_rule_request(identifier, txn_type, add_auth_action, field, None, new_value, json.dumps(constraint))) assert expected_request.items() <= request.items() @@ -56,6 +56,6 @@ async def test_build_auth_rule_request_works_for_edit_auth_action(): } request = json.loads( - await ledger.build_auth_rule_request(identifier, auth_type, edit_auth_action, field, old_value, new_value, + await ledger.build_auth_rule_request(identifier, txn_type, edit_auth_action, field, old_value, new_value, json.dumps(constraint))) assert expected_request.items() <= request.items() diff --git a/wrappers/rust/indy-sys/src/ledger.rs b/wrappers/rust/indy-sys/src/ledger.rs index 2263ae5a03..7d0b784c51 100644 --- a/wrappers/rust/indy-sys/src/ledger.rs +++ b/wrappers/rust/indy-sys/src/ledger.rs @@ -225,8 +225,8 @@ extern { #[no_mangle] pub fn indy_build_auth_rule_request(command_handle: Handle, submitter_did: CString, - auth_type: CString, - auth_action: CString, + txn_type: CString, + action: CString, field: CString, old_value: CString, new_value: CString, diff --git a/wrappers/rust/src/ledger.rs b/wrappers/rust/src/ledger.rs index 1df82c4f52..cf23e3fe41 100644 --- a/wrappers/rust/src/ledger.rs +++ b/wrappers/rust/src/ledger.rs @@ -997,20 +997,10 @@ fn _get_response_metadata(command_handle: IndyHandle, response: &str, cb: Option /// Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. /// /// # Arguments -/// * `auth_type`: ledger transaction for which authentication rules will be applied. -/// Can be an alias or associated value: -/// NODE or 0 -/// NYM or 1 -/// ATTRIB or 100 -/// SCHEMA or 101 -/// CRED_DEF or 102 -/// POOL_UPGRADE or 109 -/// POOL_CONFIG or 111 -/// REVOC_REG_DEF or 113 -/// REVOC_REG_ENTRY or 114 +/// * `txn_type`: ledger transaction alias or associated value for which authentication rules will be applied. /// * `field`: type of an action for which authentication rules will be applied. /// Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). -/// * `auth_action`: transaction field for which authentication rule will be applied. +/// * `action`: transaction field for which authentication rule will be applied. /// * `old_value`: old value of a field, which can be changed to a new_value (mandatory for EDIT action). /// * `new_value`: new value that can be used to fill the field. /// * `constraint`: set of constraints required for execution of an action in the following format: @@ -1030,27 +1020,27 @@ fn _get_response_metadata(command_handle: IndyHandle, response: &str, cb: Option /// /// # Returns /// Request result as json. -pub fn build_auth_rule_request(submitter_did: &str, auth_type: &str, auth_action: &str, field: &str, +pub fn build_auth_rule_request(submitter_did: &str, txn_type: &str, action: &str, field: &str, old_value: Option<&str>, new_value: &str, constraint: &str) -> Box> { let (receiver, command_handle, cb) = ClosureHandler::cb_ec_string(); - let err = _build_auth_rule_request(command_handle, submitter_did, auth_type, auth_action, field, old_value, new_value, constraint, cb); + let err = _build_auth_rule_request(command_handle, submitter_did, txn_type, action, field, old_value, new_value, constraint, cb); ResultHandler::str(command_handle, err, receiver) } fn _build_auth_rule_request(command_handle: IndyHandle, submitter_did: &str, - auth_type: &str, - auth_action: &str, + txn_type: &str, + action: &str, field: &str, old_value: Option<&str>, new_value: &str, constraint: &str, cb: Option) -> ErrorCode { let submitter_did = c_str!(submitter_did); - let auth_type = c_str!(auth_type); - let auth_action = c_str!(auth_action); + let txn_type = c_str!(txn_type); + let action = c_str!(action); let field = c_str!(field); let new_value = c_str!(new_value); let constraint = c_str!(constraint); @@ -1060,8 +1050,8 @@ fn _build_auth_rule_request(command_handle: IndyHandle, ErrorCode::from(unsafe { ledger::indy_build_auth_rule_request(command_handle, submitter_did.as_ptr(), - auth_type.as_ptr(), - auth_action.as_ptr(), + txn_type.as_ptr(), + action.as_ptr(), field.as_ptr(), opt_c_ptr!(old_value, old_value_str), new_value.as_ptr(), From 4777dc5bbb7654c9cf93f05a254dce4590cfdbcf Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 7 Mar 2019 11:40:59 +0300 Subject: [PATCH 15/18] CI pretty constraint output Signed-off-by: artem.ivanov --- cli/src/commands/ledger.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/src/commands/ledger.rs b/cli/src/commands/ledger.rs index 95a60ff3bb..4bd4d6f464 100644 --- a/cli/src/commands/ledger.rs +++ b/cli/src/commands/ledger.rs @@ -1271,6 +1271,7 @@ pub mod auth_rule_command { if let Some(result) = response.result.as_mut() { result["txn"]["data"]["auth_type"] = get_txn_title(&result["txn"]["data"]["auth_type"]); + result["txn"]["data"]["constraint"] = serde_json::Value::String(::serde_json::to_string_pretty(&result["txn"]["data"]["constraint"]).unwrap()); } let res = handle_transaction_response(response) From c5028e9a510d9a119bd0893c4561dd418aa291e7 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 7 Mar 2019 11:54:39 +0300 Subject: [PATCH 16/18] Minor documentation updates Signed-off-by: artem.ivanov --- cli/src/commands/ledger.rs | 6 +++--- libindy/include/indy_ledger.h | 6 +++--- libindy/src/api/ledger.rs | 6 +++--- wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h | 6 +++--- .../main/java/org/hyperledger/indy/sdk/ledger/Ledger.java | 6 +++--- wrappers/nodejs/README.md | 6 +++--- wrappers/python/indy/ledger.py | 6 +++--- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/cli/src/commands/ledger.rs b/cli/src/commands/ledger.rs index 4bd4d6f464..6fa8f25ed0 100644 --- a/cli/src/commands/ledger.rs +++ b/cli/src/commands/ledger.rs @@ -1222,9 +1222,9 @@ pub mod auth_rule_command { use super::*; command!(CommandMetadata::build("auth-rule", "Send AUTH_RULE request to change authentication rules for a ledger transaction.") - .add_required_param("txn_type", "Ledger transaction alias or associated value for which authentication rules will be applied") - .add_required_param("action", "Type of an action for which authentication rules will be applied. One of: ADD, EDIT") - .add_required_param("field", "Transaction field for which authentication rule will be applied") + .add_required_param("txn_type", "Ledger transaction alias or associated value") + .add_required_param("action", "Type of an action. One of: ADD, EDIT") + .add_required_param("field", "Transaction field") .add_optional_param("old_value", "Old value of field, which can be changed to a new_value (mandatory for EDIT action)") .add_required_param("new_value", "New value that can be used to fill the field") .add_required_param("constraint", r#"Set of constraints required for execution of an action diff --git a/libindy/include/indy_ledger.h b/libindy/include/indy_ledger.h index 271055f9be..06ecda893b 100644 --- a/libindy/include/indy_ledger.h +++ b/libindy/include/indy_ledger.h @@ -959,10 +959,10 @@ extern "C" { /// /// #Params /// command_handle: command handle to map callback to caller context. - /// txn_type: ledger transaction alias or associated value for which authentication rules will be applied. - /// action: type of an action for which authentication rules will be applied. + /// txn_type: ledger transaction alias or associated value. + /// action: type of an action. /// Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). - /// field: transaction field for which authentication rule will be applied. + /// field: transaction field. /// old_value: old value of a field, which can be changed to a new_value (mandatory for EDIT action). /// new_value: new value that can be used to fill the field. /// constraint: set of constraints required for execution of an action in the following format diff --git a/libindy/src/api/ledger.rs b/libindy/src/api/ledger.rs index 3b5c9bb353..c0d05c7db7 100644 --- a/libindy/src/api/ledger.rs +++ b/libindy/src/api/ledger.rs @@ -1839,10 +1839,10 @@ pub extern fn indy_get_response_metadata(command_handle: CommandHandle, /// /// #Params /// command_handle: command handle to map callback to caller context. -/// txn_type: ledger transaction alias or associated value for which authentication rules will be applied. -/// action: type of an action for which authentication rules will be applied. +/// txn_type: ledger transaction alias or associated value. +/// action: type of an action. /// Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). -/// field: transaction field for which authentication rule will be applied. +/// field: transaction field. /// old_value: old value of a field, which can be changed to a new_value (mandatory for EDIT action). /// new_value: new value that can be used to fill the field. /// constraint: set of constraints required for execution of an action in the following format: diff --git a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h index 64329322b4..edafeaaf9f 100644 --- a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h +++ b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyLedger.h @@ -575,10 +575,10 @@ Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. @param submitterDid DID of the submitter stored in secured Wallet. - @param txnType - ledger transaction alias or associated value for which authentication rules will be applied. - @param action - type of an action for which authentication rules will be applied. + @param txnType - ledger transaction alias or associated value. + @param action - type of an action. Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). - @param field - transaction field for which authentication rule will be applied. + @param field - transaction field. @param oldValue - old value of a field, which can be changed to a new_value (mandatory for EDIT action). @param newValue - new value that can be used to fill the field. @param constraint - set of constraints required for execution of an action in the following format: diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java index 77b4a33edd..a2782e4212 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/ledger/Ledger.java @@ -1270,10 +1270,10 @@ public static CompletableFuture getResponseMetadata( * Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. * * @param submitterDid DID of the submitter stored in secured Wallet. - * @param txnType - ledger transaction alias or associated value for which authentication rules will be applied. - * @param action - type of an action for which authentication rules will be applied. + * @param txnType - ledger transaction alias or associated value. + * @param action - type of an action. * Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). - * @param field - transaction field for which authentication rule will be applied. + * @param field - transaction field. * @param oldValue - old value of a field, which can be changed to a new_value (mandatory for EDIT action). * @param newValue - new value that can be used to fill the field. * @param constraint - set of constraints required for execution of an action in the following format: diff --git a/wrappers/nodejs/README.md b/wrappers/nodejs/README.md index 009b8fa964..be942cb166 100644 --- a/wrappers/nodejs/README.md +++ b/wrappers/nodejs/README.md @@ -1753,11 +1753,11 @@ Errors: `Common*` Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. * `submitterDid`: String - \(Optional\) DID of the read request sender \(if not provided then default Libindy DID will be used\). -* `txnType`: String - ledger transaction alias or associated value for which authentication rules will be applied. -* `action`: String - type of an action for which authentication rules will be applied. +* `txnType`: String - ledger transaction alias or associated value. +* `action`: String - type of an action. * "ADD" - to add a new rule * "EDIT" - to edit an existing one -* `field`: String - transaction field for which authentication rule will be applied. +* `field`: String - transaction field. * `oldValue`: String - \(Optional\) old value of a field, which can be changed to a new_value (mandatory for EDIT action). * `newValue`: String - new value that can be used to fill the field. * `constraint`: String - set of constraints required for execution of an action in the following format: diff --git a/wrappers/python/indy/ledger.py b/wrappers/python/indy/ledger.py index 017d88abe8..7df5d7548b 100644 --- a/wrappers/python/indy/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -1274,10 +1274,10 @@ async def build_auth_rule_request(submitter_did: str, Builds a AUTH_RULE request. Request to change authentication rules for a ledger transaction. :param submitter_did: DID of the submitter stored in secured Wallet. - :param txn_type: ledger transaction alias or associated value for which authentication rules will be applied. - :param action: type of an action for which authentication rules will be applied. + :param txn_type: ledger transaction alias or associated value. + :param action: type of an action. Can be either "ADD" (to add a new rule) or "EDIT" (to edit an existing one). - :param field: transaction field for which authentication rule will be applied. + :param field: transaction field. :param old_value: old value of a field, which can be changed to a new_value (mandatory for EDIT action). :param new_value: new value that can be used to fill the field. :param constraint: set of constraints required for execution of an action in the following format: From 298c2d296e2a435151196c6a5cc53420f69f465b Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Wed, 13 Mar 2019 09:26:39 +0300 Subject: [PATCH 17/18] Fixed failed test Signed-off-by: artem.ivanov --- libindy/tests/ledger.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libindy/tests/ledger.rs b/libindy/tests/ledger.rs index f62413bfcd..489211f9a3 100644 --- a/libindy/tests/ledger.rs +++ b/libindy/tests/ledger.rs @@ -2354,7 +2354,7 @@ mod medium_cases { pool::check_response_type(&cred_def_response, ::utils::types::ResponseType::REPLY); let get_cred_def_request = ledger::build_get_cred_def_request(Some(DID_MY1), &cred_def_id).unwrap(); - let get_cred_def_response = ledger::submit_request(pool_handle, &get_cred_def_request).unwrap(); + let get_cred_def_response = ledger::submit_request_with_retries(pool_handle, &get_cred_def_request, &cred_def_response).unwrap(); let (_, cred_def_json) = ledger::parse_get_cred_def_response(&get_cred_def_response).unwrap(); let _cred_def: CredentialDefinitionV1 = serde_json::from_str(&cred_def_json).unwrap(); From 284ea6398407d8c0298633d20c7c29f2be077101 Mon Sep 17 00:00:00 2001 From: "artem.ivanov" Date: Thu, 14 Mar 2019 09:32:58 +0300 Subject: [PATCH 18/18] FIxed python wrapper Signed-off-by: artem.ivanov --- wrappers/python/indy/ledger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrappers/python/indy/ledger.py b/wrappers/python/indy/ledger.py index 7df5d7548b..8928d47bd9 100644 --- a/wrappers/python/indy/ledger.py +++ b/wrappers/python/indy/ledger.py @@ -1265,7 +1265,7 @@ async def get_response_metadata(response: str) -> str: async def build_auth_rule_request(submitter_did: str, txn_type: str, - auth_action: str, + action: str, field: str, old_value: Optional[str], new_value: str,