diff --git a/CHANGELOG.md b/CHANGELOG.md index d444351713..b351e5532c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 1.6.3 +* Performed the following changes related to Libindy Wallet API: + * Added separate API function `indy_generate_wallet_key` to generate a random wallet master key. + * Updated `key_derivation_method` parameter of wallet `credentials` to accept the addition type - `RAW`. + By using this type, the result of `indy_generate_wallet_key` can be passed as a wallet master key (key derivation will be skipped). + * Updated Indy CLI wallet related commands to accept the addition parameter `key_derivation_method`. +* Updated `data` parameter of `indy_build_node_request` API function to accept `blskey_pop` (Proof of possession for BLS key). +* Bugfixes + * Fixed build flags for Android.s + * Other minor bugfixes. + ## 1.6.2 * Performed the following changes related to Libindy Ledger API: * Added `indy_submit_action` endpoint that provides the ability to send either GET_VALIDATOR_INFO or @@ -42,6 +53,7 @@ Performed the following changes related to Libindy Payments API: * Added `indy_build_verify_payment_req` and `indy_parse_verify_payment_response` API functions. * Removed EXPERIMENTAL notice from endpoints. * Added `ledger verify-payment-receipt` command in Indy CLI. +* Implemented experimental support of Android. * Bugfixes Notes: diff --git a/Specs/libindy-objc/1.6.3/libindy-objc.podspec.json b/Specs/libindy-objc/1.6.3/libindy-objc.podspec.json new file mode 100644 index 0000000000..b486b1198b --- /dev/null +++ b/Specs/libindy-objc/1.6.3/libindy-objc.podspec.json @@ -0,0 +1,23 @@ +{ + "name": "libindy-objc", + "version": "1.6.3", + "summary": "Summary TODO.", + "homepage": "TODO", + "license": { + "type": "Apache License 2.0", + "file": "LICENSE" + }, + "authors": { + "Daniel Hardman": "daniel.hardman@evernym.com" + }, + "source": { + "http": "https://repo.sovrin.org/ios/libindy/stable/indy-objc/1.6.3/libindy-objc.zip" + }, + "platforms": { + "ios": "10.0" + }, + "ios": { + "vendored_frameworks": "libindy-objc/Indy.framework" + }, + "module_name": "Indy" +} diff --git a/Specs/libindy/1.6.3/libindy.podspec.json b/Specs/libindy/1.6.3/libindy.podspec.json new file mode 100644 index 0000000000..01ec4076d9 --- /dev/null +++ b/Specs/libindy/1.6.3/libindy.podspec.json @@ -0,0 +1,23 @@ +{ + "name": "libindy", + "version": "1.6.3", + "summary": "Summary TODO.", + "description": "Description TODO.", + "homepage": "TODO", + "license": { + "type": "Apache License 2.0", + "file": "LICENSE" + }, + "authors": { + "Daniel Hardman": "daniel.hardman@evernym.com" + }, + "platforms": { + "ios": "10.0" + }, + "source": { + "http": "https://repo.sovrin.org/ios/libindy/stable/libindy-core/1.6.3/libindy.tar.gz" + }, + "source_files": "*.h", + "vendored_libraries": "*.a", + "requires_arc": false +} diff --git a/ci/indy-pool.dockerfile b/ci/indy-pool.dockerfile index 1722e5f42f..1ac2004253 100644 --- a/ci/indy-pool.dockerfile +++ b/ci/indy-pool.dockerfile @@ -19,16 +19,16 @@ RUN pip3 install -U \ setuptools RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 68DB5E88 -ARG indy_stream=stable +ARG indy_stream=master RUN echo "deb https://repo.sovrin.org/deb xenial $indy_stream" >> /etc/apt/sources.list RUN useradd -ms /bin/bash -u $uid indy -ARG indy_plenum_ver=1.4.45 -ARG indy_anoncreds_ver=1.0.11 -ARG indy_node_ver=1.4.66 -ARG python3_indy_crypto_ver=0.4.1 -ARG indy_crypto_ver=0.4.0 +ARG indy_plenum_ver=1.6.520 +ARG indy_anoncreds_ver=1.0.32 +ARG indy_node_ver=1.6.576 +ARG python3_indy_crypto_ver=0.4.3 +ARG indy_crypto_ver=0.4.3 RUN apt-get update -y && apt-get install -y \ indy-plenum=${indy_plenum_ver} \ diff --git a/cli/Cargo.lock b/cli/Cargo.lock index 4b39138e18..475ade3072 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -96,7 +96,7 @@ dependencies = [ [[package]] name = "indy-cli" -version = "1.6.2" +version = "1.6.3" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 4325b67e5f..78550eca16 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "indy-cli" -version = "1.6.2" +version = "1.6.3" authors = ["Vyacheslav Gudkov "] [features] diff --git a/cli/debian/changelog b/cli/debian/changelog index 4ded299f8f..8ee994be8d 100644 --- a/cli/debian/changelog +++ b/cli/debian/changelog @@ -1,4 +1,4 @@ -indy-cli (1.6.2) unstable; urgency=medium +indy-cli (1.6.3) unstable; urgency=medium [ Hyperledger ] * Created Indy-Cli diff --git a/cli/docker_pool_transactions_genesis b/cli/docker_pool_transactions_genesis index e502f438b8..78b9096d89 100644 --- a/cli/docker_pool_transactions_genesis +++ b/cli/docker_pool_transactions_genesis @@ -1,4 +1,4 @@ -{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","client_ip":"10.0.0.2","client_port":9702,"node_ip":"10.0.0.2","node_port":9701,"services":["VALIDATOR"]},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"},"metadata":{"from":"Th7MpTaRZVRYnPiabds81Y"},"type":"0"},"txnMetadata":{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"},"ver":"1"} -{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","client_ip":"10.0.0.2","client_port":9704,"node_ip":"10.0.0.2","node_port":9703,"services":["VALIDATOR"]},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"},"metadata":{"from":"EbP4aYNeTHL6q385GuVpRV"},"type":"0"},"txnMetadata":{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"},"ver":"1"} -{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","client_ip":"10.0.0.2","client_port":9706,"node_ip":"10.0.0.2","node_port":9705,"services":["VALIDATOR"]},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"},"metadata":{"from":"4cU41vWW82ArfxJxHkzXPG"},"type":"0"},"txnMetadata":{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"},"ver":"1"} -{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","client_ip":"10.0.0.2","client_port":9708,"node_ip":"10.0.0.2","node_port":9707,"services":["VALIDATOR"]},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"},"metadata":{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"},"type":"0"},"txnMetadata":{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"},"ver":"1"} \ No newline at end of file +{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","blskey_pop":"RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1","client_ip":"10.0.0.2","client_port":9702,"node_ip":"10.0.0.2","node_port":9701,"services":["VALIDATOR"]},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"},"metadata":{"from":"Th7MpTaRZVRYnPiabds81Y"},"type":"0"},"txnMetadata":{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"},"ver":"1"} +{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","blskey_pop":"Qr658mWZ2YC8JXGXwMDQTzuZCWF7NK9EwxphGmcBvCh6ybUuLxbG65nsX4JvD4SPNtkJ2w9ug1yLTj6fgmuDg41TgECXjLCij3RMsV8CwewBVgVN67wsA45DFWvqvLtu4rjNnE9JbdFTc1Z4WCPA3Xan44K1HoHAq9EVeaRYs8zoF5","client_ip":"10.0.0.2","client_port":9704,"node_ip":"10.0.0.2","node_port":9703,"services":["VALIDATOR"]},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"},"metadata":{"from":"EbP4aYNeTHL6q385GuVpRV"},"type":"0"},"txnMetadata":{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"},"ver":"1"} +{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","blskey_pop":"QwDeb2CkNSx6r8QC8vGQK3GRv7Yndn84TGNijX8YXHPiagXajyfTjoR87rXUu4G4QLk2cF8NNyqWiYMus1623dELWwx57rLCFqGh7N4ZRbGDRP4fnVcaKg1BcUxQ866Ven4gw8y4N56S5HzxXNBZtLYmhGHvDtk6PFkFwCvxYrNYjh","client_ip":"10.0.0.2","client_port":9706,"node_ip":"10.0.0.2","node_port":9705,"services":["VALIDATOR"]},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"},"metadata":{"from":"4cU41vWW82ArfxJxHkzXPG"},"type":"0"},"txnMetadata":{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"},"ver":"1"} +{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","blskey_pop":"RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP","client_ip":"10.0.0.2","client_port":9708,"node_ip":"10.0.0.2","node_port":9707,"services":["VALIDATOR"]},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"},"metadata":{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"},"type":"0"},"txnMetadata":{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"},"ver":"1"} \ No newline at end of file diff --git a/cli/src/commands/ledger.rs b/cli/src/commands/ledger.rs index eeef90c529..85d4e649a9 100644 --- a/cli/src/commands/ledger.rs +++ b/cli/src/commands/ledger.rs @@ -2789,6 +2789,7 @@ pub mod tests { params.insert("client_port", "9711".to_string()); params.insert("alias", "Node5".to_string()); params.insert("blskey", "2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw".to_string()); + params.insert("blskey_pop", "RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP".to_string()); params.insert("services", "VALIDATOR".to_string()); cmd.execute(&ctx, ¶ms).unwrap(); } diff --git a/cli/src/commands/pool.rs b/cli/src/commands/pool.rs index c19db67073..5e7108f237 100644 --- a/cli/src/commands/pool.rs +++ b/cli/src/commands/pool.rs @@ -167,7 +167,7 @@ pub mod list_command { let pools: Vec = serde_json::from_str(&pools) .map_err(|_| println_err!("Wrong data has been received"))?; - print_list_table(&pools, &vec![("pool", "Pool")], "There are no pool"); + print_list_table(&pools, &vec![("pool", "Pool")], "There are no pools defined"); if let Some((_, cur_pool)) = get_connected_pool(ctx) { println_succ!("Current pool \"{}\"", cur_pool); diff --git a/cli/src/commands/wallet.rs b/cli/src/commands/wallet.rs index 47a9c5aff9..cf86d6bf12 100644 --- a/cli/src/commands/wallet.rs +++ b/cli/src/commands/wallet.rs @@ -25,7 +25,12 @@ pub mod create_command { command!(CommandMetadata::build("create", "Create new wallet with specified name") .add_main_param("name", "Identifier of the wallet") - .add_required_deferred_param("key", "Auth key for the wallet") + .add_required_deferred_param("key", "Key or passphrase used for wallet key derivation. + Look to key_derivation_method param for information about supported key derivation methods.") + .add_optional_param("key_derivation_method", "Algorithm to use for wallet key derivation. One of: + argon2m - derive secured wallet key (used by default) + argon2i - derive secured wallet key (less secured but faster) + raw - raw wallet key provided (skip derivation)") .add_optional_param("storage_type", "Type of the wallet storage.") .add_optional_param("storage_config", "The list of key:value pairs defined by storage type.") .add_example("wallet create wallet1 key") @@ -39,11 +44,12 @@ pub mod create_command { let id = get_str_param("name", params).map_err(error_err!())?; let key = get_str_param("key", params).map_err(error_err!())?; + let key_derivation_method = get_opt_str_param("key_derivation_method", params).map_err(error_err!())?; let storage_type = get_opt_str_param("storage_type", params).map_err(error_err!())?.unwrap_or("default"); let storage_config = get_opt_object_param("storage_config", params).map_err(error_err!())?; let config: String = json!({ "id": id.clone(), "storage_type": storage_type, "storage_config": storage_config }).to_string(); - let credentials: String = json!({ "key": key.clone() }).to_string(); + let credentials: String = json!({ "key": key.clone(), "key_derivation_method": map_key_derivation_method(key_derivation_method)? }).to_string(); trace!("Wallet::create_wallet try: config {}", config); @@ -60,6 +66,7 @@ pub mod create_command { Ok(println_succ!("Wallet \"{}\" has been created", id)) } + Err(ErrorCode::CommonInvalidStructure) => Err(println_err!("Invalid key has been provided")), Err(ErrorCode::WalletAlreadyExistsError) => Err(println_err!("Wallet \"{}\" already exists", id)), Err(ErrorCode::CommonIOError) => Err(println_err!("Invalid wallet name \"{}\"", id)), Err(err) => return Err(println_err!("Indy SDK error occurred {:?}", err)), @@ -75,8 +82,17 @@ pub mod open_command { command_with_cleanup!(CommandMetadata::build("open", "Open wallet with specified name. Also close previously opened.") .add_main_param("name", "The name of wallet") - .add_required_deferred_param("key", "Auth key for the wallet") - .add_optional_deferred_param("rekey", "New auth key for the wallet (will replace previous one).") + .add_required_deferred_param("key", "Key or passphrase used for wallet key derivation. + Look to key_derivation_method param for information about supported key derivation methods.") + .add_optional_param("key_derivation_method", "Algorithm to use for wallet key derivation. One of: + argon2m - derive secured wallet key (used by default) + argon2i - derive secured wallet key (less secured but faster) + raw - raw key provided (skip derivation)") + .add_optional_deferred_param("rekey", "New key or passphrase used for wallet key derivation (will replace previous one).") + .add_optional_param("rekey_derivation_method", "Algorithm to use for wallet rekey derivation. One of: + argon2m - derive secured wallet key (used by default) + argon2i - derive secured wallet key (less secured but faster) + raw - raw key provided (skip derivation)") .add_example("wallet open wallet1 key") .add_example("wallet open wallet1 key rekey") .finalize()); @@ -87,6 +103,8 @@ pub mod open_command { let id = get_str_param("name", params).map_err(error_err!())?; let key = get_str_param("key", params).map_err(error_err!())?; let rekey = get_opt_str_param("rekey", params).map_err(error_err!())?; + let key_derivation_method = get_opt_str_param("key_derivation_method", params).map_err(error_err!())?; + let rekey_derivation_method = get_opt_str_param("rekey_derivation_method", params).map_err(error_err!())?; let config = _read_wallet_config(id) .map_err(|_| println_err!("Wallet \"{}\" not found or unavailable", id))?; @@ -95,8 +113,10 @@ pub mod open_command { let mut json = JSONMap::new(); json.insert("key".to_string(), serde_json::Value::String(key.to_string())); + json.insert("key_derivation_method".to_string(), serde_json::Value::String(map_key_derivation_method(key_derivation_method)?.to_string())); update_json_map_opt_key!(json, "rekey", rekey); + json.insert("rekey_derivation_method".to_string(), serde_json::Value::String(map_key_derivation_method(rekey_derivation_method)?.to_string())); JSONValue::from(json).to_string() }; @@ -122,7 +142,7 @@ pub mod open_command { Err(err) => { set_opened_wallet(ctx, None); match err { - ErrorCode::CommonInvalidStructure => Err(println_err!("Invalid wallet config")), + ErrorCode::CommonInvalidStructure => Err(println_err!("Invalid key or config has been provided")), ErrorCode::WalletAlreadyOpenedError => Err(println_err!("Wallet \"{}\" already opened", id)), ErrorCode::WalletAccessFailed => Err(println_err!("Cannot open wallet \"{}\". Invalid key has been provided", id)), ErrorCode::WalletNotFoundError => Err(println_err!("Wallet \"{}\" not found or unavailable", id)), @@ -220,7 +240,12 @@ pub mod delete_command { command!(CommandMetadata::build("delete", "Delete wallet with specified name") .add_main_param("name", "The name of deleted wallet") - .add_required_deferred_param("key", "Auth key for the wallet") + .add_required_deferred_param("key", "Key or passphrase used for wallet key derivation. + Look to key_derivation_method param for information about supported key derivation methods.") + .add_optional_param("key_derivation_method", "Algorithm to use for wallet key derivation. One of: + argon2m - derive secured wallet key (used by default) + argon2i - derive secured wallet key (less secured but faster) + raw - raw key provided (skip derivation)") .add_example("wallet delete wallet1 key") .finalize() ); @@ -230,11 +255,12 @@ pub mod delete_command { let id = get_str_param("name", params).map_err(error_err!())?; let key = get_str_param("key", params).map_err(error_err!())?; + let key_derivation_method = get_opt_str_param("key_derivation_method", params).map_err(error_err!())?; let config = _read_wallet_config(id) .map_err(|_| println_err!("Wallet \"{}\" not found or unavailable", id))?; - let credentials: String = json!({ "key": key }).to_string(); + let credentials: String = json!({ "key": key.clone(), "key_derivation_method": map_key_derivation_method(key_derivation_method)? }).to_string(); let res = match Wallet::delete_wallet(config.as_str(), credentials.as_str()) { Ok(()) => { @@ -246,6 +272,7 @@ pub mod delete_command { Err(ErrorCode::CommonIOError) => Err(println_err!("Wallet \"{}\" not found or unavailable", id)), Err(ErrorCode::WalletNotFoundError) => Err(println_err!("Wallet \"{}\" not found or unavailable", id)), Err(ErrorCode::WalletAccessFailed) => Err(println_err!("Cannot delete wallet \"{}\". Invalid key has been provided ", id)), + Err(ErrorCode::CommonInvalidStructure) => Err(println_err!("Invalid key has been provided")), Err(ErrorCode::CommonInvalidState) => Err(println_err!("Wallet {:?} is opened", id)), Err(err) => Err(println_err!("Indy SDK error occurred {:?}", err)), }; @@ -260,7 +287,12 @@ pub mod export_command { command!(CommandMetadata::build("export", "Export opened wallet to the file") .add_required_param("export_path", "Path to the export file") - .add_required_deferred_param("export_key", "Passphrase used to derive export key") + .add_required_deferred_param("export_key", "Key or passphrase used for export wallet key derivation. + Look to key_derivation_method param for information about supported key derivation methods.") + .add_optional_param("export_key_derivation_method", "Algorithm to use for export key derivation. One of: + argon2m - derive secured export key (used by default) + argon2i - derive secured export key (less secured but faster) + raw - raw export key provided (skip derivation)") .add_example("wallet export export_path=/home/indy/export_wallet export_key") .finalize() ); @@ -272,8 +304,9 @@ pub mod export_command { let export_path = get_str_param("export_path", params).map_err(error_err!())?; let export_key = get_str_param("export_key", params).map_err(error_err!())?; + let export_key_derivation_method = get_opt_str_param("export_key_derivation_method", params).map_err(error_err!())?; - let export_config: String = json!({ "path": export_path.clone(), "key": export_key.clone() }).to_string(); + let export_config: String = json!({ "path": export_path.clone(), "key": export_key.clone(), "key_derivation_method": map_key_derivation_method(export_key_derivation_method)? }).to_string(); trace!("Wallet::export_wallet try: wallet_name {}, export_path {}", wallet_name, export_path); @@ -284,6 +317,7 @@ pub mod export_command { let res = match res { Ok(()) => Ok(println_succ!("Wallet \"{}\" has been exported to the file \"{}\"", wallet_name, export_path)), + Err(ErrorCode::CommonInvalidStructure) => Err(println_err!("Can not export Wallet: Invalid export file or encryption key")), Err(ErrorCode::CommonIOError) => Err(println_err!("Can not export Wallet: Path \"{}\" is invalid or file already exists", export_path)), Err(err) => return Err(println_err!("Indy SDK error occurred {:?}", err)), }; @@ -293,17 +327,21 @@ pub mod export_command { } } - pub mod import_command { use super::*; command!(CommandMetadata::build("import", "Create new wallet and then import content from the specified file") .add_main_param("name", "The name of new wallet") - .add_required_deferred_param("key", "Auth key for the wallet") + .add_required_deferred_param("key", "Key or passphrase used for wallet key derivation. + Look to key_derivation_method param for information about supported key derivation methods.") + .add_optional_param("key_derivation_method", "Algorithm to use for wallet key derivation. One of: + argon2m - derive secured wallet key (used by default) + argon2i - derive secured wallet key (less secured but faster) + raw - raw key provided (skip derivation)") .add_optional_param("storage_type", "Type of the wallet storage.") .add_optional_param("storage_config", "The list of key:value pairs defined by storage type.") .add_required_param("export_path", "Path to the file that contains exported wallet content") - .add_required_deferred_param("export_key", "Passphrase used to derive export key") + .add_required_deferred_param("export_key", "Key used for export of the wallet") .add_example("wallet import wallet1 key export_path=/home/indy/export_wallet export_key") .add_example(r#"wallet import wallet1 key export_path=/home/indy/export_wallet export_key storage_type=default storage_config={"key1":"value1","key2":"value2"}"#) .finalize() @@ -314,14 +352,15 @@ pub mod import_command { let id = get_str_param("name", params).map_err(error_err!())?; let key = get_str_param("key", params).map_err(error_err!())?; + let key_derivation_method = get_opt_str_param("key_derivation_method", params).map_err(error_err!())?; let export_path = get_str_param("export_path", params).map_err(error_err!())?; let export_key = get_str_param("export_key", params).map_err(error_err!())?; let storage_type = get_opt_str_param("storage_type", params).map_err(error_err!())?; let storage_config = get_opt_object_param("storage_config", params).map_err(error_err!())?; let config: String = json!({ "id": id.clone(), "storage_type": storage_type, "storage_config": storage_config }).to_string(); - let credentials: String = json!({ "key": key.clone() }).to_string(); - let import_config: String = json!({ "path": export_path.clone(), "key": export_key.clone() }).to_string(); + let credentials: String = json!({ "key": key.clone(), "key_derivation_method": map_key_derivation_method(key_derivation_method)? }).to_string(); + let import_config: String = json!({ "path": export_path.clone(), "key": export_key.clone()}).to_string(); trace!("Wallet::import_wallet try: config {}, import_config {}", config, import_config); @@ -415,6 +454,16 @@ fn _list_wallets() -> Vec { configs } +fn map_key_derivation_method(key: Option<&str>) -> Result<&'static str, ()> { + // argon2m, argon2i, raw + match key { + None | Some("argon2m") => Ok("ARGON2I_MOD"), + Some("argon2i") => Ok("ARGON2I_INT"), + Some("raw") => Ok("RAW"), + val @ _ => Err(println_err!("Unsupported Wallet Key type has been specified \"{}\"", val.unwrap())), + } +} + #[cfg(test)] pub mod tests { use super::*; @@ -528,6 +577,44 @@ pub mod tests { delete_wallet(&ctx); TestUtils::cleanup_storage(); } + + #[test] + pub fn create_works_for_key_derivation_method() { + TestUtils::cleanup_storage(); + let ctx = CommandContext::new(); + { + let cmd = create_command::new(); + let mut params = CommandParams::new(); + params.insert("name", WALLET.to_string()); + params.insert("key", WALLET_KEY.to_string()); + params.insert("key_derivation_method", "argon2m".to_string()); + cmd.execute(&ctx, ¶ms).unwrap(); + } + + let wallets = _list_wallets(); + assert_eq!(1, wallets.len()); + + assert_eq!(wallets[0]["id"].as_str().unwrap(), WALLET); + + delete_wallet(&ctx); + TestUtils::cleanup_storage(); + } + + #[test] + pub fn create_works_for_wrong_export_key_derivation_method() { + TestUtils::cleanup_storage(); + let ctx = CommandContext::new(); + { + let cmd = create_command::new(); + let mut params = CommandParams::new(); + params.insert("name", WALLET.to_string()); + params.insert("key", WALLET_KEY.to_string()); + params.insert("key_derivation_method", "some_type".to_string()); + cmd.execute(&ctx, ¶ms).unwrap_err(); + } + + TestUtils::cleanup_storage(); + } } mod open { @@ -974,6 +1061,96 @@ pub mod tests { TestUtils::cleanup_storage(); } + + #[test] + pub fn import_works_for_different_key_derivation_methods() { + TestUtils::cleanup_storage(); + let ctx = CommandContext::new(); + + { + let cmd = create_command::new(); + let mut params = CommandParams::new(); + params.insert("name", WALLET.to_string()); + params.insert("key", WALLET_KEY.to_string()); + params.insert("key_derivation_method", "argon2i".to_string()); + cmd.execute(&ctx, ¶ms).unwrap(); + } + { + let cmd = open_command::new(); + let mut params = CommandParams::new(); + params.insert("name", WALLET.to_string()); + params.insert("key", WALLET_KEY.to_string()); + params.insert("key_derivation_method", "argon2i".to_string()); + cmd.execute(&ctx, ¶ms).unwrap(); + } + new_did(&ctx, SEED_MY1); + use_did(&ctx, DID_MY1); + + let (_, path_str) = export_wallet_path(); + + { + let cmd = export_command::new(); + let mut params = CommandParams::new(); + params.insert("export_path", path_str.clone()); + params.insert("export_key", EXPORT_KEY.to_string()); + params.insert("key_derivation_method", "argon2m".to_string()); + cmd.execute(&ctx, ¶ms).unwrap(); + } + + let wallet_name = "imported_wallet"; + let key = "6nxtSiXFvBd593Y2DCed2dYvRY1PGK9WMtxCBjLzKgbw"; + // import wallet + { + let cmd = import_command::new(); + let mut params = CommandParams::new(); + params.insert("name", wallet_name.to_string()); + params.insert("key", key.to_string()); + params.insert("key_derivation_method", "raw".to_string()); + params.insert("export_path", path_str); + params.insert("export_key", EXPORT_KEY.to_string()); + cmd.execute(&ctx, ¶ms).unwrap(); + } + + // open exported wallet + { + let cmd = open_command::new(); + let mut params = CommandParams::new(); + params.insert("name", wallet_name.to_string()); + params.insert("key", key.to_string()); + params.insert("key_derivation_method", "raw".to_string()); + cmd.execute(&ctx, ¶ms).unwrap(); + } + + use_did(&ctx, DID_MY1); + + { + let cmd = close_command::new(); + let params = CommandParams::new(); + cmd.execute(&ctx, ¶ms).unwrap(); + } + + // delete first wallet + { + let cmd = delete_command::new(); + let mut params = CommandParams::new(); + params.insert("name", WALLET.to_string()); + params.insert("key", WALLET_KEY.to_string()); + params.insert("key_derivation_method", "argon2i".to_string()); + cmd.execute(&CommandContext::new(), ¶ms).unwrap(); + } + + // delete second wallet + { + let cmd = delete_command::new(); + let mut params = CommandParams::new(); + params.insert("name", wallet_name.to_string()); + params.insert("key", key.to_string()); + params.insert("key_derivation_method", "raw".to_string()); + cmd.execute(&CommandContext::new(), ¶ms).unwrap(); + } + + TestUtils::cleanup_storage(); + } } pub fn create_wallet(ctx: &CommandContext) { diff --git a/doc/design/001-cli/README.md b/doc/design/001-cli/README.md index bc27769317..ad452a5b74 100644 --- a/doc/design/001-cli/README.md +++ b/doc/design/001-cli/README.md @@ -127,14 +127,14 @@ indy> wallet #### Wallet create Create new wallet with specified name: ``` -indy> wallet create key [storage_type=] [storage_config={config json}] +indy> wallet create key [key_derivation_method=] [storage_type=] [storage_config={config json}] ``` TODO: Think about custom wallet types support. Now we force default wallet security model.. #### Wallet open Open the wallet with specified name and make it available for commands that require wallet. If there was opened wallet it will be closed: ``` -indy> wallet open key [rekey] +indy> wallet open key [key_derivation_method=] [rekey] [rekey_derivation_method=] ``` #### Wallet close @@ -146,7 +146,7 @@ indy> wallet close #### Wallet delete Delete the opened wallet ``` -indy> wallet delete key +indy> wallet delete key [key_derivation_method=] ``` #### Wallet list @@ -159,14 +159,14 @@ indy> wallet list Exports opened wallet to the specified file. ```indy-cli -indy> wallet export export_path= export_key=[] +indy> wallet export export_path= export_key=[] [export_key_derivation_method=] ``` ### Import wallet Create new wallet and then import content from the specified file. ```indy-cli -indy> wallet import key= export_path= export_key= [storage_type=] [storage_config={config json}] +indy> wallet import key= [key_derivation_method=] export_path= export_key= [storage_type=] [storage_config={config json}] ``` ### Pool management commands diff --git a/doc/getting-started/getting-started.dockerfile b/doc/getting-started/getting-started.dockerfile index 30185ba195..0b62391225 100644 --- a/doc/getting-started/getting-started.dockerfile +++ b/doc/getting-started/getting-started.dockerfile @@ -20,13 +20,13 @@ RUN pip3 install -U \ pip \ setuptools \ jupyter \ - python3-indy==1.5.0-dev-625 + python3-indy==1.6.2-dev-720 RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 68DB5E88 \ && add-apt-repository "deb https://repo.sovrin.org/sdk/deb xenial master" \ && apt-get update \ && apt-get install -y \ - libindy=1.5.0~625 + libindy=1.6.2~720 USER indy diff --git a/doc/getting-started/getting-started.md b/doc/getting-started/getting-started.md index 77dec7c7e9..0c08312042 100644 --- a/doc/getting-started/getting-started.md +++ b/doc/getting-started/getting-started.md @@ -255,7 +255,7 @@ After the connection is established **Faber** must create new DID record that he }) ``` -3. **Faber** authenticates and encrypts the message by calling ``crypto.auth_crypt`` using verkeys created for secure communication with **Steward**. The Authenticated-encryption schema is designed for the sending of a confidential message specifically for a Recipient, using the Sender's public key. Using the Recipient's public key, the Sender can compute a shared secret key. Using the Sender's public key and his secret key, the Recipient can compute the exact same shared secret key. That shared secret key can be used to verify that the encrypted message was not tampered with, before eventually decrypting it. +3. **Faber** authenticates and encrypts the message by calling ``crypto.auth_crypt`` function, which is an implementation of the authenticated-encryption schema. Authenticated encryption is designed for sending of a confidential message specifically for the Recipient. The Sender can compute a shared secret key using the Recipient's public key (verkey) and his secret (signing) key. The Recipient can compute exactly the same shared secret key using the Sender's public key (verkey) and his secret (signing) key. That shared secret key can be used to verify that the encrypted message was not tampered with, before eventually decrypting it. ```python # Faber Agent authcrypted_faber_did_info_json = \ diff --git a/doc/how-tos/issue-credential/python/README.md b/doc/how-tos/issue-credential/python/README.md new file mode 100644 index 0000000000..ea3f3d28d6 --- /dev/null +++ b/doc/how-tos/issue-credential/python/README.md @@ -0,0 +1,96 @@ +# Issue a Credential +Indy-SDK Developer Walkthrough #4, Python Edition + +[ [Java](../java/README.md) | [.NET](../../not-yet-written.md) | [Node.js](../../not-yet-written.md) | [Objective C](../../not-yet-written.md) ] + + +## Prerequisites + +Setup your workstation with an indy development virtual machine(VM). See [prerequisites](../../prerequisites.md). +Ensure you have the 64-bit version of Python 3 installed, as the 32-bit version may have problems loading the Indy .dll files. + + +## Steps + +### Step 1 + +In your normal workstation operating system (not the VM), open a Python editor of your +choice and paste the code from [template.py](template.py) +into a new doc. We will be modifying this code in later steps. + +Save the doc as `IssueCredential.py`. + +This is a very simple app framework into which you'll plug the code +you'll be writing. + +### Step 2 + +This how-to builds on the work in ["Save Schema and Cred Def"](../save-schema-and-cred-def/python/README.md). +Rather than duplicate our explanation of those steps here, we will simply +copy that code as our starting point. + +Copy the contents of [step2.py](step2.py) into +`IssueCredential.py` on top of the `Step 2 code goes here` placeholder comment. + +Save the updated version of `IssueCredential.py`. + +### Step 3 + +So far, we have created an identity that can be used to issue credentials. +We need another one, now, that can be used to hold credentials once they're issued. + +Copy the contents of [step3.py](step3.py) into +`IssueCredential.py` on top of the `Step 3 code goes here` placeholder comment. + +Save the updated version of `IssueCredential.py`. + +Notice that this identity creates something called a *link secret* (formerly +called a *master secret*; this older term is now deprecated). +A link secret is a special piece of data that's inserted into +a credential, in blinded form, on issuance; it is used to prove that the +credential in question belongs to a particular holder and not to someone +else. Because Alice's credentials contain her link secret, only she can +use them. + +### Step 4 + +At this point, the issuer and the person who receives the credential +(called the *holder*) engage in an interactive protocol that results +in issuance. + +First, the issuer offers a credential. This step is optional; we include +it for completeness. Next, the holder requests the credential, supplying +the blinded link secret that will bind it to them. Finally, the issuer +generates the credential and gives it to the holder. + +![3-phase negotiation on issuance](../3-phase-negotiation.png) + +These three steps embody a negotiation pattern that is used in many +indy interactions (e.g., in proving). Either party can begin; the other +party acknowledges and accepts--or makes a counter proposal. In the case +of a counter proposal, a new negotiation cycle begins; in the simpler +case, the negotiation is concluded successfully. Negotiation could be used +during credential issuance to negotiate a change to a credential (e.g., +to correct a typo or to ask an issuer to include or omit a piece of data +that they didn't initially propose); however, we don't cover that +advanced workflow here. + +One other note: the sample code in this step uses the word "claim" in +places where you might expect "credential." These used to be synonyms, +but usage has evolved in the W3C since the Indy SDK was built. "Credential" +is the newer word, and function and parameter names that refer to "claims" +are now deprecated. Eventually, all usage will show "credential." + +Copy the contents of [step4.py](step4.py) into +`IssueCredential.py` on top of the `Step 4 code goes here` placeholder comment. + +Save the updated version of `IssueCredential.py`. + +### Step 5 + +Run the [finished code](IssueCredential.py) and observe the whole sequence. + +## More experiments + +You might try the ["Negotiate a Proof"](../../negotiate-proof/python/README.md) +how-to, which can be done in only one step once you complete this one. diff --git a/doc/how-tos/issue-credential/python/issue_credential.py b/doc/how-tos/issue-credential/python/issue_credential.py index c265bfd72a..4b2bbd8f8a 100644 --- a/doc/how-tos/issue-credential/python/issue_credential.py +++ b/doc/how-tos/issue-credential/python/issue_credential.py @@ -6,27 +6,26 @@ After Trust Anchor has successfully created and stored a Cred Definition using Anonymous Credentials, Prover's wallet is created and opened, and used to generate Prover's Master Secret. -After that, Trust Anchor generates Claim Offer for given Cred Definition, using Prover's DID -Prover uses Claim Offer to create Claim Request -Trust Anchor then uses Prover's Claim Request to issue a Claim. -Finally, Prover stores Claim in its wallet. +After that, Trust Anchor generates Credential Offer for given Cred Definition, using Prover's DID +Prover uses Credential Offer to create Credential Request +Trust Anchor then uses Prover's Credential Request to issue a Credential. +Finally, Prover stores Credential in its wallet. """ import asyncio import json import pprint -import sys -sys.path.insert(0, '/home/vagrant/code/evernym/indy-sdk/wrappers/python') - from indy import pool, ledger, wallet, did, anoncreds from indy.error import IndyError pool_name = 'pool' -wallet_name = 'wallet' genesis_file_path = '/home/vagrant/code/evernym/indy-sdk/cli/docker_pool_transactions_genesis' +wallet_config = json.dumps({"id": "wallet"}) +wallet_credentials = json.dumps({"key": "wallet_key"}) +PROTOCOL_VERSION=2 def print_log(value_color="", value_noncolor=""): @@ -38,23 +37,32 @@ def print_log(value_color="", value_noncolor=""): async def issue_credential(): try: + await pool.set_protocol_version(2) # 1. print_log('\n1. Creates a new local pool ledger configuration that is used ' 'later when connecting to ledger.\n') pool_config = json.dumps({'genesis_txn': genesis_file_path}) - await pool.create_pool_ledger_config(config_name=pool_name, config=pool_config) + try: + await pool.create_pool_ledger_config(pool_name, pool_config) + except IndyError: + await pool.delete_pool_ledger_config(config_name=pool_name) + await pool.create_pool_ledger_config(pool_name, pool_config) # 2. print_log('\n2. Open pool ledger and get handle from libindy\n') pool_handle = await pool.open_pool_ledger(config_name=pool_name, config=None) # 3. - print_log('\n3. Creating new secure wallet_handle\n') - await wallet.create_wallet(pool_name, wallet_name, None, None, None) + print_log('\n3. Creating new secure wallet\n') + try: + await wallet.create_wallet(wallet_config, wallet_credentials) + except IndyError: + await wallet.delete_wallet(wallet_config, wallet_credentials) + await wallet.create_wallet(wallet_config, wallet_credentials) # 4. - print_log('\n4. Open wallet_handle and get handle from libindy\n') - wallet_handle = await wallet.open_wallet(wallet_name, None, None) + print_log('\n4. Open wallet and get handle from libindy\n') + wallet_handle = await wallet.open_wallet(wallet_config, wallet_credentials) # 5. print_log('\n5. Generating and storing steward DID and verkey\n') @@ -96,14 +104,18 @@ async def issue_credential(): 'seqNo': seq_no, 'dest': steward_did, 'data': { + 'id': '1', 'name': 'gvt', 'version': '1.0', - 'attr_names': ['age', 'sex', 'height', 'name'] + 'ver': '1.0', + 'attrNames': ['age', 'sex', 'height', 'name'] } } schema_data = schema['data'] - print_log('Schema: ') + print_log('Schema data: ') pprint.pprint(schema_data) + print_log('Schema: ') + pprint.pprint(schema) schema_request = await ledger.build_schema_request(steward_did, json.dumps(schema_data)) print_log('Schema request: ') pprint.pprint(json.loads(schema_request)) @@ -115,51 +127,57 @@ async def issue_credential(): pprint.pprint(json.loads(schema_response)) # 11. - print_log('\n11. Creating and storing CLAIM DEFINITION using anoncreds as Trust Anchor, for the given schema') - claim_def_json = await anoncreds.issuer_create_and_store_claim_def(wallet_handle, trust_anchor_did, json.dumps(schema), 'CL', False) - print_log('Claim Definition: ') - pprint.pprint(json.loads(claim_def_json)) + print_log('\n11. Creating and storing CRED DEFINITION using anoncreds as Trust Anchor, for the given Schema\n') + cred_def_tag = 'cred_def_tag' + cred_def_type = 'CL' + cred_def_config = json.dumps({"support_revocation": False}) + + (cred_def_id, cred_def_json) = await anoncreds.issuer_create_and_store_credential_def(wallet_handle, trust_anchor_did, json.dumps(schema_data), + cred_def_tag, cred_def_type, cred_def_config) + print_log('Credential definition: ') + pprint.pprint(json.loads(cred_def_json)) # 12. print_log('\n12. Creating Prover wallet and opening it to get the handle\n') prover_did = 'VsKV7grR1BUE29mG2Fm2kX' - prover_wallet_name = 'prover_wallet' - await wallet.create_wallet(pool_name, prover_wallet_name, None, None, None) - prover_wallet_handle = await wallet.open_wallet(prover_wallet_name, None, None) + prover_wallet_config = json.dumps({"id": "prover_wallet"}) + prover_wallet_credentials = json.dumps({"key": "prover_wallet_key"}) + await wallet.create_wallet(prover_wallet_config, prover_wallet_credentials) + prover_wallet_handle = await wallet.open_wallet(prover_wallet_config, prover_wallet_credentials) # 13. print_log('\n13. Prover is creating Master Secret\n') master_secret_name = 'master_secret' - await anoncreds.prover_create_master_secret(prover_wallet_handle, master_secret_name) + master_secret_id = await anoncreds.prover_create_master_secret(prover_wallet_handle, master_secret_name) # 14. - print_log('\n14. Issuer (Trust Anchor) is creating a Claim Offer for Prover\n') + print_log('\n14. Issuer (Trust Anchor) is creating a Credential Offer for Prover\n') schema_json = json.dumps(schema) - claim_offer_json = await anoncreds.issuer_create_claim_offer(wallet_handle, schema_json, trust_anchor_did, prover_did) - print_log('Claim Offer: ') - pprint.pprint(json.loads(claim_offer_json)) - + cred_offer_json = await anoncreds.issuer_create_credential_offer(wallet_handle, cred_def_id) + print_log('Credential Offer: ') + pprint.pprint(json.loads(cred_offer_json)) + # 15. - print_log('\n15. Prover creates Claim Request\n') - claim_req_json = await anoncreds.prover_create_and_store_claim_req(prover_wallet_handle, prover_did, claim_offer_json, claim_def_json, master_secret_name) - print_log('Claim Request: ') - pprint.pprint(json.loads(claim_req_json)) - + print_log('\n15. Prover creates Credential Request for the given credential offer\n') + (cred_req_json, cred_req_metadata_json) = await anoncreds.prover_create_credential_req(prover_wallet_handle, prover_did, cred_offer_json, cred_def_json, master_secret_id) + print_log('Credential Request: ') + pprint.pprint(json.loads(cred_req_json)) + # 16. - print_log('\n16. Issuer (Trust Anchor) creates Claim for Claim Request\n') - claim_json = json.dumps({ + print_log('\n16. Issuer (Trust Anchor) creates Credential for Credential Request\n') + cred_values_json = json.dumps({ 'sex': ['male', '5944657099558967239210949258394887428692050081607692519917050011144233115103'], 'name': ['Alex', '1139481716457488690172217916278103335'], 'height': ['175', '175'], 'age': ['28', '28'] }) - _, claim_json = await anoncreds.issuer_create_claim(wallet_handle, claim_req_json, claim_json, -1) - print_log('Claim: ') - pprint.pprint(json.loads(claim_json)) + (cred_json, _, _) = await anoncreds.issuer_create_credential(wallet_handle, cred_offer_json, cred_req_json, cred_values_json, None, None) + print_log('Credential: ') + pprint.pprint(json.loads(cred_json)) # 17. - print_log('\n17. Prover processes and stores Claim\n') - await anoncreds.prover_store_claim(prover_wallet_handle, claim_json, None) + print_log('\n17. Prover processes and stores Credential\n') + await anoncreds.prover_store_credential(prover_wallet_handle, None, cred_req_metadata_json, cred_json, cred_def_json, None) # 18. print_log('\n18. Closing both wallet_handles and pool\n') @@ -169,8 +187,8 @@ async def issue_credential(): # 19. print_log('\n19. Deleting created wallet_handles\n') - await wallet.delete_wallet(wallet_name, None) - await wallet.delete_wallet(prover_wallet_name, None) + await wallet.delete_wallet(wallet_config, wallet_credentials) + await wallet.delete_wallet(prover_wallet_config, prover_wallet_credentials) # 20. print_log('\n20. Deleting pool ledger config\n') @@ -188,4 +206,3 @@ def main(): if __name__ == '__main__': main() - diff --git a/doc/how-tos/issue-credential/python/step2.py b/doc/how-tos/issue-credential/python/step2.py new file mode 100644 index 0000000000..b66af6aa3b --- /dev/null +++ b/doc/how-tos/issue-credential/python/step2.py @@ -0,0 +1,98 @@ + # 1. + print_log('\n1. Creates a new local pool ledger configuration that is used ' + 'later when connecting to ledger.\n') + pool_config = json.dumps({'genesis_txn': genesis_file_path}) + try: + await pool.create_pool_ledger_config(pool_name, pool_config) + except IndyError: + await pool.delete_pool_ledger_config(config_name=pool_name) + await pool.create_pool_ledger_config(pool_name, pool_config) + + # 2. + print_log('\n2. Open pool ledger and get handle from libindy\n') + pool_handle = await pool.open_pool_ledger(config_name=pool_name, config=None) + + # 3. + print_log('\n3. Creating new secure wallet\n') + try: + await wallet.create_wallet(wallet_config, wallet_credentials) + except IndyError: + await wallet.delete_wallet(wallet_config, wallet_credentials) + await wallet.create_wallet(wallet_config, wallet_credentials) + + # 4. + print_log('\n4. Open wallet and get handle from libindy\n') + wallet_handle = await wallet.open_wallet(wallet_config, wallet_credentials) + + # 5. + print_log('\n5. Generating and storing steward DID and verkey\n') + steward_seed = '000000000000000000000000Steward1' + did_json = json.dumps({'seed': steward_seed}) + steward_did, steward_verkey = await did.create_and_store_my_did(wallet_handle, did_json) + print_log('Steward DID: ', steward_did) + print_log('Steward Verkey: ', steward_verkey) + + # 6. + print_log('\n6. Generating and storing trust anchor DID and verkey\n') + trust_anchor_did, trust_anchor_verkey = await did.create_and_store_my_did(wallet_handle, "{}") + print_log('Trust anchor DID: ', trust_anchor_did) + print_log('Trust anchor Verkey: ', trust_anchor_verkey) + + # 7. + print_log('\n7. Building NYM request to add Trust Anchor to the ledger\n') + nym_transaction_request = await ledger.build_nym_request(submitter_did=steward_did, + target_did=trust_anchor_did, + ver_key=trust_anchor_verkey, + alias=None, + role='TRUST_ANCHOR') + print_log('NYM transaction request: ') + pprint.pprint(json.loads(nym_transaction_request)) + + # 8. + print_log('\n8. Sending NYM request to the ledger\n') + nym_transaction_response = await ledger.sign_and_submit_request(pool_handle=pool_handle, + wallet_handle=wallet_handle, + submitter_did=steward_did, + request_json=nym_transaction_request) + print_log('NYM transaction response: ') + pprint.pprint(json.loads(nym_transaction_response)) + + # 9. + print_log('\n9. Build the SCHEMA request to add new schema to the ledger as a Steward\n') + seq_no = 1 + schema = { + 'seqNo': seq_no, + 'dest': steward_did, + 'data': { + 'id': '1', + 'name': 'gvt', + 'version': '1.0', + 'ver': '1.0', + 'attrNames': ['age', 'sex', 'height', 'name'] + } + } + schema_data = schema['data'] + print_log('Schema data: ') + pprint.pprint(schema_data) + print_log('Schema: ') + pprint.pprint(schema) + schema_request = await ledger.build_schema_request(steward_did, json.dumps(schema_data)) + print_log('Schema request: ') + pprint.pprint(json.loads(schema_request)) + + # 10. + print_log('\n10. Sending the SCHEMA request to the ledger\n') + schema_response = await ledger.sign_and_submit_request(pool_handle, wallet_handle, steward_did, schema_request) + print_log('Schema response:') + pprint.pprint(json.loads(schema_response)) + + # 11. + print_log('\n11. Creating and storing CRED DEFINITION using anoncreds as Trust Anchor, for the given Schema\n') + cred_def_tag = 'cred_def_tag' + cred_def_type = 'CL' + cred_def_config = json.dumps({"support_revocation": False}) + + (cred_def_id, cred_def_json) = await anoncreds.issuer_create_and_store_credential_def(wallet_handle, trust_anchor_did, json.dumps(schema_data), + cred_def_tag, cred_def_type, cred_def_config) + print_log('Credential definition: ') + pprint.pprint(json.loads(cred_def_json)) diff --git a/doc/how-tos/issue-credential/python/step3.py b/doc/how-tos/issue-credential/python/step3.py new file mode 100644 index 0000000000..6efe2bbe71 --- /dev/null +++ b/doc/how-tos/issue-credential/python/step3.py @@ -0,0 +1,12 @@ + # 12. + print_log('\n12. Creating Prover wallet and opening it to get the handle\n') + prover_did = 'VsKV7grR1BUE29mG2Fm2kX' + prover_wallet_config = json.dumps({"id": "prover_wallet"}) + prover_wallet_credentials = json.dumps({"key": "prover_wallet_key"}) + await wallet.create_wallet(prover_wallet_config, prover_wallet_credentials) + prover_wallet_handle = await wallet.open_wallet(prover_wallet_config, prover_wallet_credentials) + + # 13. + print_log('\n13. Prover is creating Master Secret\n') + master_secret_name = 'master_secret' + master_secret_id = await anoncreds.prover_create_master_secret(prover_wallet_handle, master_secret_name) diff --git a/doc/how-tos/issue-credential/python/step4.py b/doc/how-tos/issue-credential/python/step4.py new file mode 100644 index 0000000000..b38bc1ebfe --- /dev/null +++ b/doc/how-tos/issue-credential/python/step4.py @@ -0,0 +1,43 @@ + # 14. + print_log('\n14. Issuer (Trust Anchor) is creating a Credential Offer for Prover\n') + schema_json = json.dumps(schema) + cred_offer_json = await anoncreds.issuer_create_credential_offer(wallet_handle, cred_def_id) + print_log('Credential Offer: ') + pprint.pprint(json.loads(cred_offer_json)) + + # 15. + print_log('\n15. Prover creates Credential Request for the given credential offer\n') + (cred_req_json, cred_req_metadata_json) = await anoncreds.prover_create_credential_req(prover_wallet_handle, prover_did, cred_offer_json, cred_def_json, master_secret_id) + print_log('Credential Request: ') + pprint.pprint(json.loads(cred_req_json)) + + # 16. + print_log('\n16. Issuer (Trust Anchor) creates Credential for Credential Request\n') + cred_values_json = json.dumps({ + 'sex': ['male', '5944657099558967239210949258394887428692050081607692519917050011144233115103'], + 'name': ['Alex', '1139481716457488690172217916278103335'], + 'height': ['175', '175'], + 'age': ['28', '28'] + }) + (cred_json, _, _) = await anoncreds.issuer_create_credential(wallet_handle, cred_offer_json, cred_req_json, cred_values_json, None, None) + print_log('Credential: ') + pprint.pprint(json.loads(cred_json)) + + # 17. + print_log('\n17. Prover processes and stores Credential\n') + await anoncreds.prover_store_credential(prover_wallet_handle, None, cred_req_metadata_json, cred_json, cred_def_json, None) + + # 18. + print_log('\n18. Closing both wallet_handles and pool\n') + await wallet.close_wallet(wallet_handle) + await wallet.close_wallet(prover_wallet_handle) + await pool.close_pool_ledger(pool_handle) + + # 19. + print_log('\n19. Deleting created wallet_handles\n') + await wallet.delete_wallet(wallet_config, wallet_credentials) + await wallet.delete_wallet(prover_wallet_config, prover_wallet_credentials) + + # 20. + print_log('\n20. Deleting pool ledger config\n') + await pool.delete_pool_ledger_config(pool_name) diff --git a/doc/how-tos/issue-credential/python/template.py b/doc/how-tos/issue-credential/python/template.py new file mode 100644 index 0000000000..8335b58ac2 --- /dev/null +++ b/doc/how-tos/issue-credential/python/template.py @@ -0,0 +1,58 @@ +""" +This sample is extensions of "write_schema_and_cred_def.py" + +Shows how to issue a credential as a Trust Anchor which has created a Cred Definition +for an existing Schema. + +After Trust Anchor has successfully created and stored a Cred Definition using Anonymous Credentials, +Prover's wallet is created and opened, and used to generate Prover's Master Secret. +After that, Trust Anchor generates Credential Offer for given Cred Definition, using Prover's DID +Prover uses Credential Offer to create Credential Request +Trust Anchor then uses Prover's Credential Request to issue a Credential. +Finally, Prover stores Credential in its wallet. +""" + + +import asyncio +import json +import pprint + +from indy import pool, ledger, wallet, did, anoncreds +from indy.error import IndyError + + +pool_name = 'pool' +genesis_file_path = '/home/vagrant/code/evernym/indy-sdk/cli/docker_pool_transactions_genesis' +wallet_config = json.dumps({"id": "wallet"}) +wallet_credentials = json.dumps({"key": "wallet_key"}) +PROTOCOL_VERSION=2 + + +def print_log(value_color="", value_noncolor=""): + """set the colors for text.""" + HEADER = '\033[92m' + ENDC = '\033[0m' + print(HEADER + value_color + ENDC + str(value_noncolor)) + + +async def issue_credential(): + try: + await pool.set_protocol_version(2) + # Step 2 code goes here. + + # Step 3 code goes here. + + # Step 4 code goes here. + + except IndyError as e: + print('Error occurred: %s' % e) + + +def main(): + loop = asyncio.get_event_loop() + loop.run_until_complete(issue_credential()) + loop.close() + + +if __name__ == '__main__': + main() diff --git a/doc/how-tos/rotate-key/python/step2.py b/doc/how-tos/rotate-key/python/step2.py index 527df14536..456e7982b5 100644 --- a/doc/how-tos/rotate-key/python/step2.py +++ b/doc/how-tos/rotate-key/python/step2.py @@ -10,10 +10,10 @@ pool_handle = await pool.open_pool_ledger(config_name=pool_name, config=None) print_log('\n3. Creating new secure wallet with the given unique name\n') - await wallet.create_wallet(pool_name, wallet_name, None, None, wallet_credentials) + await wallet.create_wallet(wallet_config, wallet_credentials) print_log('\n4. Open wallet and get handle from libindy to use in methods that require wallet access\n') - wallet_handle = await wallet.open_wallet(wallet_name, None, wallet_credentials) + wallet_handle = await wallet.open_wallet(wallet_config, wallet_credentials) # First, put a steward DID and its keypair in the wallet. This doesn't write anything to the ledger, # but it gives us a key that we can use to sign a ledger transaction that we're going to submit later. diff --git a/doc/how-tos/rotate-key/python/step3.py b/doc/how-tos/rotate-key/python/step3.py index 302302e98e..1a2d4f69ea 100644 --- a/doc/how-tos/rotate-key/python/step3.py +++ b/doc/how-tos/rotate-key/python/step3.py @@ -1,16 +1,16 @@ - print_log('\n9. Generating new verkey of trust anchor in wallet\n') - new_verkey = await did.replace_keys_start(wallet_handle, trust_anchor_did, "{}") - print_log('New Trust Anchor Verkey: ', new_verkey) - - print_log('\n10. Building NYM request to update new verkey to ledger\n') - nym_request = await ledger.build_nym_request(trust_anchor_did, trust_anchor_did, new_verkey, None, 'TRUST_ANCHOR') - print_log('NYM request:') - pprint.pprint(json.loads(nym_request)) - - print_log('\n11. Sending NYM request to the ledger\n') - nym_response = await ledger.sign_and_submit_request(pool_handle, wallet_handle, trust_anchor_did, nym_request) - print_log('NYM response:') - pprint.pprint(json.loads(nym_response)) - - print_log('\n12. Apply new verkey in wallet\n') - await did.replace_keys_apply(wallet_handle, trust_anchor_did) + print_log('\n9. Generating new verkey of trust anchor in wallet\n') + new_verkey = await did.replace_keys_start(wallet_handle, trust_anchor_did, "{}") + print_log('New Trust Anchor Verkey: ', new_verkey) + + print_log('\n10. Building NYM request to update new verkey to ledger\n') + nym_request = await ledger.build_nym_request(trust_anchor_did, trust_anchor_did, new_verkey, None, 'TRUST_ANCHOR') + print_log('NYM request:') + pprint.pprint(json.loads(nym_request)) + + print_log('\n11. Sending NYM request to the ledger\n') + nym_response = await ledger.sign_and_submit_request(pool_handle, wallet_handle, trust_anchor_did, nym_request) + print_log('NYM response:') + pprint.pprint(json.loads(nym_response)) + + print_log('\n12. Apply new verkey in wallet\n') + await did.replace_keys_apply(wallet_handle, trust_anchor_did) diff --git a/doc/how-tos/rotate-key/python/step4.py b/doc/how-tos/rotate-key/python/step4.py index 7e9a5d8f8e..1f87dedf37 100644 --- a/doc/how-tos/rotate-key/python/step4.py +++ b/doc/how-tos/rotate-key/python/step4.py @@ -14,7 +14,7 @@ pprint.pprint(get_nym_response) print_log('\n16. Comparing Trust Anchor verkeys: written by Steward (original), ' - 'current in wallet and current from ledger\n') + 'current in wallet and current from ledger\n') print_log('Written by Steward: ', trust_anchor_verkey) print_log('Current in wallet: ', verkey_in_wallet) verkey_from_ledger = json.loads(get_nym_response['result']['data'])['verkey'] @@ -27,7 +27,7 @@ await pool.close_pool_ledger(pool_handle) print_log('\n18. Deleting created wallet\n') - await wallet.delete_wallet(wallet_name, wallet_credentials) + await wallet.delete_wallet(wallet_config, wallet_credentials) print_log('\n19. Deleting pool ledger config') await pool.delete_pool_ledger_config(pool_name) diff --git a/doc/how-tos/rotate-key/python/template.py b/doc/how-tos/rotate-key/python/template.py index 79b75f48a0..4ce376b77e 100644 --- a/doc/how-tos/rotate-key/python/template.py +++ b/doc/how-tos/rotate-key/python/template.py @@ -25,10 +25,12 @@ pool_name = 'pool' -wallet_name = 'wallet' genesis_file_path = '/home/vagrant/code/evernym/indy-sdk/cli/docker_pool_transactions_genesis' +wallet_config = json.dumps({"id": "wallet"}) wallet_credentials = json.dumps({"key": "wallet_key"}) +# Set protocol version to 2 to work with the current version of Indy Node +PROTOCOL_VERSION = 2 def print_log(value_color="", value_noncolor=""): """set the colors for text.""" @@ -38,15 +40,17 @@ def print_log(value_color="", value_noncolor=""): async def rotate_key_on_the_ledger(): - try: - # Step 2 code goes here. + try: + await pool.set_protocol_version(PROTOCOL_VERSION) - # Step 3 code goes here. + # Step 2 code goes here. - # Step 4 code goes here. + # Step 3 code goes here. - except IndyError as e: - print('Error occurred: %s' % e) + # Step 4 code goes here. + + except IndyError as e: + print('Error occurred: %s' % e) def main(): diff --git a/doc/how-tos/save-schema-and-cred-def/python/README.md b/doc/how-tos/save-schema-and-cred-def/python/README.md index 6e61db172b..6e70569632 100644 --- a/doc/how-tos/save-schema-and-cred-def/python/README.md +++ b/doc/how-tos/save-schema-and-cred-def/python/README.md @@ -93,11 +93,7 @@ Copy the contents of [step4.py](step4.py) into Save the updated version of `save_schema_and_cred_def.py``. -### Step 5 - -Run the [finished code](save_schema_and_cred_def.py) and observe the whole sequence. - ## More experiments -You might try the ["Issue a Credential"](../../issue-credential/../not-yet-written.md) +You might try the ["Issue a Credential"](../../issue-credential/python/README.md) how-to, which can be done in only one step once you complete this one. diff --git a/doc/how-tos/save-schema-and-cred-def/python/step2.py b/doc/how-tos/save-schema-and-cred-def/python/step2.py index 05253aaf70..a6deee0390 100644 --- a/doc/how-tos/save-schema-and-cred-def/python/step2.py +++ b/doc/how-tos/save-schema-and-cred-def/python/step2.py @@ -1,58 +1,58 @@ - # 1. - print_log('\n1. Creates a new local pool ledger configuration that is used ' - 'later when connecting to ledger.\n') - pool_config = json.dumps({'genesis_txn': genesis_file_path}) - try: - await pool.create_pool_ledger_config(pool_name, pool_config) - except IndyError: - await pool.delete_pool_ledger_config(config_name=pool_name) - await pool.create_pool_ledger_config(pool_name, pool_config) - - # 2. - print_log('\n2. Open pool ledger and get handle from libindy\n') - pool_handle = await pool.open_pool_ledger(config_name=pool_name, config=None) - - # 3. - print_log('\n3. Creating new secure wallet\n') - try: - await wallet.create_wallet(pool_name, wallet_name, None, None, wallet_credentials) - except IndyError: - await wallet.delete_wallet(wallet_name, wallet_credentials) - await wallet.create_wallet(pool_name, wallet_name, None, None, wallet_credentials) - - # 4. - print_log('\n4. Open wallet and get handle from libindy\n') - wallet_handle = await wallet.open_wallet(wallet_name, None, wallet_credentials) - - # 5. - print_log('\n5. Generating and storing steward DID and verkey\n') - steward_seed = '000000000000000000000000Steward1' - did_json = json.dumps({'seed': steward_seed}) - steward_did, steward_verkey = await did.create_and_store_my_did(wallet_handle, did_json) - print_log('Steward DID: ', steward_did) - print_log('Steward Verkey: ', steward_verkey) - - # 6. - print_log('\n6. Generating and storing trust anchor DID and verkey\n') - trust_anchor_did, trust_anchor_verkey = await did.create_and_store_my_did(wallet_handle, "{}") - print_log('Trust anchor DID: ', trust_anchor_did) - print_log('Trust anchor Verkey: ', trust_anchor_verkey) - - # 7. - print_log('\n7. Building NYM request to add Trust Anchor to the ledger\n') - nym_transaction_request = await ledger.build_nym_request(submitter_did=steward_did, - target_did=trust_anchor_did, - ver_key=trust_anchor_verkey, - alias=None, - role='TRUST_ANCHOR') - print_log('NYM transaction request: ') - pprint.pprint(json.loads(nym_transaction_request)) - - # 8. - print_log('\n8. Sending NYM request to the ledger\n') - nym_transaction_response = await ledger.sign_and_submit_request(pool_handle=pool_handle, - wallet_handle=wallet_handle, - submitter_did=steward_did, - request_json=nym_transaction_request) - print_log('NYM transaction response: ') - pprint.pprint(json.loads(nym_transaction_response)) \ No newline at end of file + # 1. + print_log('\n1. Creates a new local pool ledger configuration that is used ' + 'later when connecting to ledger.\n') + pool_config = json.dumps({'genesis_txn': genesis_file_path}) + try: + await pool.create_pool_ledger_config(pool_name, pool_config) + except IndyError: + await pool.delete_pool_ledger_config(config_name=pool_name) + await pool.create_pool_ledger_config(pool_name, pool_config) + + # 2. + print_log('\n2. Open pool ledger and get handle from libindy\n') + pool_handle = await pool.open_pool_ledger(config_name=pool_name, config=None) + + # 3. + print_log('\n3. Creating new secure wallet\n') + try: + await wallet.create_wallet(wallet_config, wallet_credentials) + except IndyError: + await wallet.delete_wallet(wallet_config, wallet_credentials) + await wallet.create_wallet(wallet_config, wallet_credentials) + + # 4. + print_log('\n4. Open wallet and get handle from libindy\n') + wallet_handle = await wallet.open_wallet(wallet_config, wallet_credentials) + + # 5. + print_log('\n5. Generating and storing steward DID and verkey\n') + steward_seed = '000000000000000000000000Steward1' + did_json = json.dumps({'seed': steward_seed}) + steward_did, steward_verkey = await did.create_and_store_my_did(wallet_handle, did_json) + print_log('Steward DID: ', steward_did) + print_log('Steward Verkey: ', steward_verkey) + + # 6. + print_log('\n6. Generating and storing trust anchor DID and verkey\n') + trust_anchor_did, trust_anchor_verkey = await did.create_and_store_my_did(wallet_handle, "{}") + print_log('Trust anchor DID: ', trust_anchor_did) + print_log('Trust anchor Verkey: ', trust_anchor_verkey) + + # 7. + print_log('\n7. Building NYM request to add Trust Anchor to the ledger\n') + nym_transaction_request = await ledger.build_nym_request(submitter_did=steward_did, + target_did=trust_anchor_did, + ver_key=trust_anchor_verkey, + alias=None, + role='TRUST_ANCHOR') + print_log('NYM transaction request: ') + pprint.pprint(json.loads(nym_transaction_request)) + + # 8. + print_log('\n8. Sending NYM request to the ledger\n') + nym_transaction_response = await ledger.sign_and_submit_request(pool_handle=pool_handle, + wallet_handle=wallet_handle, + submitter_did=steward_did, + request_json=nym_transaction_request) + print_log('NYM transaction response: ') + pprint.pprint(json.loads(nym_transaction_response)) diff --git a/doc/how-tos/save-schema-and-cred-def/python/step3.py b/doc/how-tos/save-schema-and-cred-def/python/step3.py index 504236dd19..87617e0207 100644 --- a/doc/how-tos/save-schema-and-cred-def/python/step3.py +++ b/doc/how-tos/save-schema-and-cred-def/python/step3.py @@ -25,4 +25,4 @@ print_log('\n10. Sending the SCHEMA request to the ledger\n') schema_response = await ledger.sign_and_submit_request(pool_handle, wallet_handle, steward_did, schema_request) print_log('Schema response:') - pprint.pprint(json.loads(schema_response)) \ No newline at end of file + pprint.pprint(json.loads(schema_response)) diff --git a/doc/how-tos/save-schema-and-cred-def/python/step4.py b/doc/how-tos/save-schema-and-cred-def/python/step4.py index b3d273dcc7..94abf2fa3e 100644 --- a/doc/how-tos/save-schema-and-cred-def/python/step4.py +++ b/doc/how-tos/save-schema-and-cred-def/python/step4.py @@ -1,24 +1,24 @@ - - # 11. - print_log('\n11. Creating and storing CRED DEFINITION using anoncreds as Trust Anchor, for the given Schema\n') - cred_def_tag = 'cred_def_tag' - cred_def_type = 'CL' - cred_def_config = json.dumps({"support_revocation": False}) - - (cred_def_id, cred_def_json) = await anoncreds.issuer_create_and_store_credential_def(wallet_handle, trust_anchor_did, json.dumps(schema_data), - cred_def_tag, cred_def_type, cred_def_config) - print_log('Credential definition: ') - pprint.pprint(json.loads(cred_def_json)) - - # 12. - print_log('\n12. Closing wallet and pool\n') - await wallet.close_wallet(wallet_handle) - await pool.close_pool_ledger(pool_handle) - - # 13. - print_log('\n13. Deleting created wallet\n') - await wallet.delete_wallet(wallet_name, wallet_credentials) - - # 14. - print_log('\n14. Deleting pool ledger config\n') - await pool.delete_pool_ledger_config(pool_name) \ No newline at end of file + + # 11. + print_log('\n11. Creating and storing CRED DEFINITION using anoncreds as Trust Anchor, for the given Schema\n') + cred_def_tag = 'cred_def_tag' + cred_def_type = 'CL' + cred_def_config = json.dumps({"support_revocation": False}) + + (cred_def_id, cred_def_json) = await anoncreds.issuer_create_and_store_credential_def(wallet_handle, trust_anchor_did, json.dumps(schema_data), + cred_def_tag, cred_def_type, cred_def_config) + print_log('Credential definition: ') + pprint.pprint(json.loads(cred_def_json)) + + # 12. + print_log('\n12. Closing wallet and pool\n') + await wallet.close_wallet(wallet_handle) + await pool.close_pool_ledger(pool_handle) + + # 13. + print_log('\n13. Deleting created wallet\n') + await wallet.delete_wallet(wallet_config, wallet_credentials) + + # 14. + print_log('\n14. Deleting pool ledger config\n') + await pool.delete_pool_ledger_config(pool_name) diff --git a/doc/how-tos/save-schema-and-cred-def/python/template.py b/doc/how-tos/save-schema-and-cred-def/python/template.py index 079d7c9592..f3c6073dfb 100644 --- a/doc/how-tos/save-schema-and-cred-def/python/template.py +++ b/doc/how-tos/save-schema-and-cred-def/python/template.py @@ -18,10 +18,10 @@ pool_name = 'pool' -wallet_name = 'wallet' genesis_file_path = '/home/vagrant/code/evernym/indy-sdk/cli/docker_pool_transactions_genesis' +wallet_config = json.dumps({"id": "wallet"}) wallet_credentials = json.dumps({"key": "wallet_key"}) - +PROTOCOL_VERSION=2 def print_log(value_color="", value_noncolor=""): """set the colors for text.""" @@ -32,15 +32,13 @@ def print_log(value_color="", value_noncolor=""): async def write_schema_and_cred_def(): try: - await pool.set_protocol_version(2) + await pool.set_protocol_version(PROTOCOL_VERSION) # Step 2 code goes here. # Step 3 code goes here. # Step 4 code goes here. - # Step 5 code goes here. - except IndyError as e: print('Error occurred: %s' % e) diff --git a/doc/how-tos/write-did-and-query-verkey/python/step2.py b/doc/how-tos/write-did-and-query-verkey/python/step2.py index ea4d1994ae..0e0f96a7f3 100644 --- a/doc/how-tos/write-did-and-query-verkey/python/step2.py +++ b/doc/how-tos/write-did-and-query-verkey/python/step2.py @@ -9,7 +9,7 @@ pool_handle = await pool.open_pool_ledger(config_name=pool_name, config=None) print_log('\n3. Create new identity wallet\n') - await wallet.create_wallet(pool_name, wallet_name, None, None, wallet_credentials) + await wallet.create_wallet(wallet_config, wallet_credentials) print_log('\n4. Open identity wallet and get handle\n') - wallet_handle = await wallet.open_wallet(wallet_name, None, wallet_credentials) + wallet_handle = await wallet.open_wallet(wallet_config, wallet_credentials) diff --git a/doc/how-tos/write-did-and-query-verkey/python/step5.py b/doc/how-tos/write-did-and-query-verkey/python/step5.py index c28768f083..732ab68d5e 100644 --- a/doc/how-tos/write-did-and-query-verkey/python/step5.py +++ b/doc/how-tos/write-did-and-query-verkey/python/step5.py @@ -35,7 +35,7 @@ await pool.close_pool_ledger(pool_handle) print_log('\n14. Deleting created wallet\n') - await wallet.delete_wallet(wallet_name, wallet_credentials) + await wallet.delete_wallet(wallet_config, wallet_credentials) print_log('\n15. Deleting pool ledger config\n') await pool.delete_pool_ledger_config(pool_name) diff --git a/doc/how-tos/write-did-and-query-verkey/python/template.py b/doc/how-tos/write-did-and-query-verkey/python/template.py index b944f625b6..f790ee4e83 100644 --- a/doc/how-tos/write-did-and-query-verkey/python/template.py +++ b/doc/how-tos/write-did-and-query-verkey/python/template.py @@ -19,9 +19,11 @@ pool_name = 'pool' -wallet_name = 'wallet' genesis_file_path = '/home/vagrant/code/evernym/indy-sdk/cli/docker_pool_transactions_genesis' +wallet_config = json.dumps({"id": "wallet"}) wallet_credentials = json.dumps({"key": "wallet_key"}) +# Set protocol version to 2 to work with the current version of Indy Node +PROTOCOL_VERSION = 2 def print_log(value_color="", value_noncolor=""): @@ -33,6 +35,7 @@ def print_log(value_color="", value_noncolor=""): async def write_nym_and_query_verkey(): try: + await pool.set_protocol_version(PROTOCOL_VERSION) # Step 2 code goes here. # Step 3 code goes here. diff --git a/doc/migration-guide-1.5.0-1.6.0.md b/doc/migration-guide-1.5.0-1.6.0.md index 0dca03d9e5..805c559280 100644 --- a/doc/migration-guide-1.5.0-1.6.0.md +++ b/doc/migration-guide-1.5.0-1.6.0.md @@ -12,11 +12,18 @@ version you can check migration guides history: ## Table of contents * [Notes](#notes) -* [Wallet API](#wallet-api) -* [Anoncreds API](#anoncreds-api) -* [Payments API](#payments-api) -* [Pool API](#payments-api) -* [Ledger API](#ledger-api) +* [Libindy 1.5 to 1.6.0 migration](#libindy-15-to-160-migration-guide) + * [Wallet API](#wallet-api) + * [Anoncreds API](#anoncreds-api) + * [Payments API](#payments-api) + * [Pool API](#payments-api) +* [Libindy 1.6.0 to 1.6.1 migration](#libindy-160-to-161-migration-guide) +* [Libindy 1.6.1 to 1.6.2 migration](#libindy-161-to-162-migration-guide) + * [Wallet API 1.6.2](#wallet-api-162) + * [Ledger API 1.6.2](#ledger-api-162) +* [Libindy 1.6.2 to 1.6.3 migration](#libindy-162-to-163-migration-guide) + * [Wallet API 1.6.3](#wallet-api-163) + * [Ledger API 1.6.3](#ledger-api-163) ## Notes @@ -32,6 +39,8 @@ Functions from older version are listed in the left column, and the equivalent n * Bellow are signatures of functions in Libindy C API. The params of ```cb``` (except command_handle and err) will be result values of the similar function in any Libindy wrapper. +## Libindy 1.5 to 1.6.0 migration Guide + ### Wallet API The main idea of changes performed in Wallet API is to avoid maintaining created wallet list on Libindy side. @@ -65,20 +74,6 @@ This wallet configuration json has the following format: } } ``` -* Updated wallet `credentials` to accept the additional parameter `key_derivation_method`. - This parameter provides the ability to use different crypto algorithms for master key derivation. -Wallet credentials json has the following format: -``` - { - "key": string, Passphrase used to derive wallet master key - "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. - Can be optional if storage supports default configuration. - For 'default' storage type should be empty. - "key_derivation_method": optional algorithm to use for master key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster - } -``` *WARNING* Wallet format of libindy v1.6 isn't compatible with a wallet format of libindy v1.5. @@ -89,7 +84,7 @@ Wallet credentials json has the following format: - + Create a new secure wallet @@ -114,13 +109,12 @@ indy_create_wallet(command_handle: i32, err: ErrorCode)>) Note: Format of config parameter was changed. Current format is described above. - Note: Format of credentials parameter was changed. Current format is described above. - + Open the wallet @@ -150,7 +144,7 @@ indy_open_wallet(command_handle: i32, - + Deletes created wallet @@ -175,7 +169,7 @@ indy_delete_wallet(command_handle: i32, - + Import wallet @@ -278,7 +272,7 @@ References: - + Gets human readable credential by the given id @@ -299,7 +293,7 @@ indy_prover_get_credential( - + Gets human readable credentials according to the filter @@ -320,7 +314,7 @@ indy_prover_get_credentials( - + Search for credentials stored in wallet @@ -342,7 +336,7 @@ indy_prover_search_credentials( - + Fetch next credentials for search @@ -363,7 +357,7 @@ indy_prover_fetch_credentials( - + Close credentials search @@ -382,7 +376,7 @@ indy_prover_close_credentials_search( - + Gets human readable credentials matching the given proof request @@ -403,7 +397,7 @@ indy_prover_get_credentials_for_proof_req( - + Search for credentials matching the given proof request. @@ -428,7 +422,7 @@ indy_prover_search_credentials_for_proof_req( - + Fetch next credentials for the requested item using proof request search handle @@ -450,7 +444,7 @@ indy_prover_fetch_credentials_for_proof_req( - + Close credentials search for proof request @@ -490,7 +484,7 @@ The following changes have been performed: - + Modifies Indy request by adding information how to pay fees for this transaction according to selected payment method @@ -526,7 +520,7 @@ changed to: - + Parses response for Indy request with fees @@ -565,7 +559,7 @@ indy_parse_response_with_fees( - + Builds Indy request for getting sources list for payment address according to this payment method @@ -602,7 +596,7 @@ indy_build_get_sources_request( - + Parses response for Indy request for getting sources list @@ -641,7 +635,7 @@ indy_parse_get_sources_response( - + Builds Indy request for doing payment according to this payment method @@ -675,7 +669,7 @@ changed to: - + Builds Indy request for doing payment according to this payment method @@ -714,7 +708,7 @@ indy_parse_payment_response( - + Builds Indy request for doing tokens minting according to this payment method @@ -747,7 +741,7 @@ changed to: - + Builds Indy request for information to verify the payment receipt @@ -770,7 +764,7 @@ indy_build_verify_payment_req( - + Parses Indy response with information to verify receipt @@ -801,7 +795,7 @@ indy_parse_verify_payment_response( - + Opens pool ledger and performs connecting to pool nodes @@ -833,16 +827,169 @@ Left the same but the format of config has been changed to: -### Ledger API +## Libindy 1.6.0 to 1.6.1 migration Guide + +The Libindy 1.6.1 release contains fixes that don't affect API functions. +Most of them relate to pool connection performance. + +## Libindy 1.6.1 to 1.6.2 migration Guide + +### Wallet API 1.6.2 + +Updated wallet `credentials` to accept the additional parameter `key_derivation_method`. + +This parameter provides the ability to use different crypto algorithms for wallet master key derivation. + +Wallet credentials json has the following format: +``` + { + "key": string, Passphrase used to derive wallet master key + "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. + Can be optional if storage supports default configuration. + For 'default' storage type should be empty. + "key_derivation_method": optional algorithm to use for master key derivation: + ARGON2I_MOD (used by default) + ARGON2I_INT - less secured but faster + } +``` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
v1.6.1 - Wallet APIv1.6.2 - Wallet API
+ + Create a new secure wallet + +
+
+indy_create_wallet(command_handle: i32,
+                   config: *const c_char,
+                   credentials: *const c_char,
+                   cb: fn(xcommand_handle: i32,
+                          err: ErrorCode))
+      
+
+ Note: Left the same but format of credentials parameter was changed. + The current format is described above. +
+ + Open the wallet + +
+
+indy_open_wallet(command_handle: i32,
+                 config: *const c_char,
+                 credentials: *const c_char,
+                 cb: fn(xcommand_handle: i32,
+                                      err: ErrorCode,
+                                      handle: i32))
+      
+
+ Note: Left the same but format of credentials parameter was changed. + The current format is described above. +
+ + Deletes created wallet + +
+
+indy_delete_wallet(command_handle: i32,
+                   config: *const c_char,
+                   credentials: *const c_char,
+                   cb: fn(xcommand_handle: i32, 
+                          err: ErrorCode))
+      
+
+ Note: Left the same but format of credentials parameter was changed. + The current format is described above. +
+ + Exports opened wallet + +
+
+indy_export_wallet(
+                command_handle: i32,
+                wallet_handle: i32,
+                export_config: *const c_char,
+                cb: fn(xcommand_handle: i32,
+                       err: ErrorCode))
+        
+
+ Note: Format of export_config parameter was changed to. +
+{
+ "path": , Path of the file that contains exported wallet content
+ "key": , Key or passphrase used for wallet export key derivation.
+ "key_derivation_method": optional Algorithm to use for wallet export key derivation:
+                          ARGON2I_MOD - derive secured export key (used by default)
+                          ARGON2I_INT - derive secured export key (less secured but faster)
+}
+      
+
+ + Import wallet + +
+
+indy_import_wallet(
+            command_handle: i32,
+            config: *const c_char,
+            credentials: *const c_char,
+            import_config_json: *const c_char,
+            cb: fn(xcommand_handle: i32, 
+                   err: ErrorCode)
+        
+
+ Note: Left the same but format of credentials parameter was changed. + The current format is described above. +
+ +### Ledger API 1.6.2 - + @@ -851,60 +998,272 @@ Left the same but the format of config has been changed to: + +
v1.5.0 - Ledger APIv1.6.1 - Ledger API v1.6.2 - Ledger API
- + Send action to particular nodes of validator pool NEW
-indy_submit_action(command_handle: i32,
-                   pool_handle: i32,
-                   request_json: *const c_char,
-                   nodes: *const c_char,
-                   timeout: i32,
-                   cb: fn(xcommand_handle: i32,
-                          err: ErrorCode,
-                          request_result_json: *const c_char))
+indy_submit_action(
+               command_handle: i32,
+               pool_handle: i32,
+               request_json: *const c_char,
+               nodes: *const c_char,
+               timeout: i32,
+               cb: fn(xcommand_handle: i32,
+                      err: ErrorCode,
+                      request_result_json: *const c_char))
       
- + Builds a POOL_UPGRADE request
-indy_build_pool_upgrade_request(command_handle: i32,
-                                submitter_did: *const c_char,
-                                name: *const c_char,
-                                version: *const c_char,
-                                action: *const c_char,
-                                sha256: *const c_char,
-                                timeout: i32,
-                                schedule: *const c_char,
-                                justification: *const c_char,
-                                reinstall: bool,
-                                force: bool,
-                                cb: fn(xcommand_handle: i32,
-                                       err: ErrorCode,
-                                       request_json: *const c_char))
+indy_build_pool_upgrade_request(
+            command_handle: i32,
+            submitter_did: *const c_char,
+            name: *const c_char,
+            version: *const c_char,
+            action: *const c_char,
+            sha256: *const c_char,
+            timeout: i32,
+            schedule: *const c_char,
+            justification: *const c_char,
+            reinstall: bool,
+            force: bool,
+            cb: fn(xcommand_handle: i32,
+                   err: ErrorCode,
+                   request_json: *const c_char))
       
+
-indy_build_pool_upgrade_request(command_handle: i32,
-                                submitter_did: *const c_char,
-                                name: *const c_char,
-                                version: *const c_char,
-                                action: *const c_char,
-                                sha256: *const c_char,
-                                timeout: i32,
-                                schedule: *const c_char,
-                                justification: *const c_char,
-                                reinstall: bool,
-                                force: bool,
-                                package: *const c_char,
-                                cb: fn(xcommand_handle: i32,
-                                       err: ErrorCode,
-                                       request_json: *const c_char))
+indy_build_pool_upgrade_request(
+                command_handle: i32,
+                submitter_did: *const c_char,
+                name: *const c_char,
+                version: *const c_char,
+                action: *const c_char,
+                sha256: *const c_char,
+                timeout: i32,
+                schedule: *const c_char,
+                justification: *const c_char,
+                reinstall: bool,
+                force: bool,
+                package: *const c_char,
+                cb: fn(xcommand_handle: i32,
+                       err: ErrorCode,
+                       request_json: *const c_char))
       
Note: Added package parameter that allows to specify package to be upgraded
+ +## Libindy 1.6.2 to 1.6.3 migration Guide + +### Wallet API 1.6.3 + +* Added separate API function `indy_generate_wallet_key` to generate a random wallet master key. +* Updated `key_derivation_method` parameter of wallet `credentials` to accept the addition type - `RAW`. + By using this type, the result of `indy_generate_wallet_key` can be passed as a wallet master key (key derivation will be skipped). +* Fixed **typo** in the naming of key derivation methods - **ARGON** instead of **ARAGON**. + +Wallet credentials json has the following format: +``` + { + "key": string, Key or passphrase used for wallet key derivation. + Look to key_derivation_method param for information about supported key derivation methods. + "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. + Can be optional if storage supports default configuration. + For 'default' storage type should be empty. + "key_derivation_method": optional Algorithm to use for wallet key derivation: + ARGON2I_MOD - derive secured wallet master key (used by default) + ARGON2I_INT - derive secured wallet master key (less secured but faster) + RAW - raw wallet key master provided (skip derivation). + RAW keys can be generated with indy_generate_wallet_key call + } +``` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
v1.6.2 - Wallet APIv1.6.3 - Wallet API
+ + Generate wallet master key. + +
+ NEW + +
+indy_generate_wallet_key(command_handle: i32,
+                         config: *const c_char,
+                         cb: fn(xcommand_handle: i32,
+                                err: ErrorCode,
+                                key: *const c_char))
+        
+
+ + Create a new secure wallet + +
+
+indy_create_wallet(command_handle: i32,
+                   config: *const c_char,
+                   credentials: *const c_char,
+                   cb: fn(xcommand_handle: i32,
+                          err: ErrorCode))
+      
+
+ Note: Left the same but format of credentials parameter was changed. + The current format is described above. +
+ + Open the wallet + +
+
+indy_open_wallet(command_handle: i32,
+                 config: *const c_char,
+                 credentials: *const c_char,
+                 cb: fn(xcommand_handle: i32,
+                                      err: ErrorCode,
+                                      handle: i32))
+      
+
+ Note: Left the same but format of credentials parameter was changed. + The current format is described above. +
+ + Deletes created wallet + +
+
+indy_delete_wallet(command_handle: i32,
+                   config: *const c_char,
+                   credentials: *const c_char,
+                   cb: fn(xcommand_handle: i32, 
+                          err: ErrorCode))
+      
+
+ Note: Left the same but format of credentials parameter was changed. + The current format is described above. +
+ + Exports opened wallet + +
+
+indy_export_wallet(
+                command_handle: i32,
+                wallet_handle: i32,
+                export_config: *const c_char,
+                cb: fn(xcommand_handle: i32,
+                       err: ErrorCode))
+        
+
+ Note: Format of export_config parameter was changed to. +
+{
+ "path": , Path of the file that contains exported wallet content
+ "key": , Key or passphrase used for wallet export key derivation.
+ "key_derivation_method": optional Algorithm to use for wallet export key derivation:
+                          ARGON2I_MOD - derive secured export key (used by default)
+                          ARGON2I_INT - derive secured export key (less secured but faster)
+                          RAW - raw wallet key master provided (skip derivation).
+}
+      
+
+ + Import wallet + +
+
+indy_import_wallet(
+            command_handle: i32,
+            config: *const c_char,
+            credentials: *const c_char,
+            import_config_json: *const c_char,
+            cb: fn(xcommand_handle: i32, 
+                   err: ErrorCode)
+        
+
+ Note: Left the same but format of credentials parameter was changed. + The current format is described above. +
+ +### Ledger API 1.6.3 + + + + + + + + + + + + +
v1.6.2 - Ledger APIv1.6.3 - Ledger API
+ + Builds a NODE request + +
+
+indy_build_node_request(
+            command_handle: i32,
+            submitter_did: *const c_char,
+            target_did: *const c_char,
+            data: *const c_char,
+            cb: fn(xcommand_handle: i32,
+                   err: ErrorCode,
+                   request_json: *const c_char))
+      
+
+Left the same but the additional optional field blskey_pop has been added in data json. +
\ No newline at end of file diff --git a/libindy/Cargo.lock b/libindy/Cargo.lock index fe46982f2a..e09d9e910b 100644 --- a/libindy/Cargo.lock +++ b/libindy/Cargo.lock @@ -255,7 +255,7 @@ dependencies = [ [[package]] name = "indy" -version = "1.6.2" +version = "1.6.3" dependencies = [ "android_logger 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/libindy/Cargo.toml b/libindy/Cargo.toml index 3a9a1dbab0..e327b4e935 100644 --- a/libindy/Cargo.toml +++ b/libindy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "indy" -version = "1.6.2" +version = "1.6.3" authors = [ "Sergej Pupykin ", "Vyacheslav Gudkov ", diff --git a/libindy/android.build.sh b/libindy/android.build.sh index 2ecf72a6a3..8a4fccc78b 100755 --- a/libindy/android.build.sh +++ b/libindy/android.build.sh @@ -147,10 +147,15 @@ build(){ echo "**************************************************" pushd ${WORKDIR} rm -rf target/${TRIPLET} - cargo clean && - LD_LIBRARY_PATH=${TOOLCHAIN_DIR}/sysroot/usr/${TOOLCHAIN_SYSROOT_LIB} \ - RUSTFLAGS="-C link-args=-Wl,-rpath,${TOOLCHAIN_DIR}/sysroot/usr/${TOOLCHAIN_SYSROOT_LIB} -L${TOOLCHAIN_DIR}/${ANDROID_TRIPLET}/${TOOLCHAIN_SYSROOT_LIB} -lgnustl_shared" \ - cargo build --release --target=${TRIPLET} && + cargo clean + if [ "${ABSOLUTE_ARCH}" == "x86_64" ]; then + LD_LIBRARY_PATH=${TOOLCHAIN_DIR}/sysroot/usr/${TOOLCHAIN_SYSROOT_LIB} \ + RUSTFLAGS="-C link-args=-Wl,-rpath,${TOOLCHAIN_DIR}/sysroot/usr/${TOOLCHAIN_SYSROOT_LIB} -L${TOOLCHAIN_DIR}/${ANDROID_TRIPLET}/${TOOLCHAIN_SYSROOT_LIB} -lgnustl_shared" \ + cargo build --release --target=${TRIPLET} + else + cargo build --release --target=${TRIPLET} + fi + popd } diff --git a/libindy/ci/setup.android.env.sh b/libindy/ci/setup.android.env.sh index 70f8f2d070..4a32be6eaf 100644 --- a/libindy/ci/setup.android.env.sh +++ b/libindy/ci/setup.android.env.sh @@ -62,7 +62,7 @@ create_avd(){ -f \ -c 1000M - ANDROID_SDK_ROOT=${ANDROID_SDK} ANDROID_HOME=${ANDROID_SDK} ${ANDROID_HOME}/tools/emulator -avd arm -no-audio -no-window & + ANDROID_SDK_ROOT=${ANDROID_SDK} ANDROID_HOME=${ANDROID_SDK} ${ANDROID_HOME}/tools/emulator -avd ${TARGET_ARCH} -no-audio -no-window & } download_sdk(){ diff --git a/libindy/debian/changelog b/libindy/debian/changelog index e12c2ae112..a150ca4a65 100644 --- a/libindy/debian/changelog +++ b/libindy/debian/changelog @@ -1,12 +1,12 @@ -libindy (1.6.2) unstable; urgency=medium +libindy (1.6.3) unstable; urgency=medium [ Hyperledger ] -* 1.6.2 - * Performed the following changes related to Libindy Ledger API: - * Added `indy_submit_action` endpoint that provides the ability to send either GET_VALIDATOR_INFO or - POOL_RESTART request to specific nodes and to specify custom timeout for a response from a node. - * Updated `indy_build_pool_upgrade_request` API function to accept the additional parameter `package` that allow specify package to be upgraded. - * Updated wallet `credentials` to accept the additional parameter `key_derivation_method`. - This parameter provides the ability to use different crypto algorithms for master key derivation. +* 1.6.3 + * Performed the following changes related to Libindy Wallet API: + * Added separate API function `indy_generate_wallet_key` to generate a random wallet master key. + * Updated `key_derivation_method` parameter of wallet `credentials` to accept the addition type - `RAW`. + By using this type, the result of `indy_generate_wallet_key` can be passed as a wallet master key (key derivation will be skipped). + * Updated Indy CLI wallet related commands to accept the addition parameter `key_derivation_method`. + * Updated `data` parameter of `indy_build_node_request` API function to accept `blskey_pop` (Proof of possession for BLS key). * Bugfixes \ No newline at end of file diff --git a/libindy/include/indy_wallet.h b/libindy/include/indy_wallet.h index f45fb17ce3..20a6291488 100644 --- a/libindy/include/indy_wallet.h +++ b/libindy/include/indy_wallet.h @@ -156,7 +156,7 @@ extern "C" { /// Custom storage types can be registered with indy_register_wallet_storage call. /// "storage_config": optional, Storage configuration json. Storage type defines set of supported keys. /// Can be optional if storage supports default configuration. - // For 'default' storage type configuration is: + /// For 'default' storage type configuration is: /// { /// "path": optional, Path to the directory with wallet files. /// Defaults to $HOME/.indy_client/wallets. @@ -165,13 +165,16 @@ extern "C" { /// } /// credentials: Wallet credentials json /// { - /// "key": string, Passphrase used to derive wallet master key + /// "key": string, Key or passphrase used for wallet key derivation. + /// Look to key_derivation_method param for information about supported key derivation methods. /// "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. /// Can be optional if storage supports default configuration. /// For 'default' storage type should be empty. - /// "key_derivation_method": optional algorithm to use for master key derivation: - /// ARAGON2I_MOD (used by default) - /// ARAGON2I_INT - less secured but faster + /// "key_derivation_method": optional Algorithm to use for wallet key derivation: + /// ARGON2I_MOD - derive secured wallet master key (used by default) + /// ARGON2I_INT - derive secured wallet master key (less secured but faster) + /// RAW - raw wallet key master provided (skip derivation). + /// RAW keys can be generated with indy_generate_wallet_key call /// } /// /// #Returns @@ -211,18 +214,22 @@ extern "C" { /// } /// credentials: Wallet credentials json /// { - /// "key": string, Passphrase used to derive current wallet master key - /// "rekey": optional, If present than wallet master key will be rotated to a new one - /// derived from this passphrase. + /// "key": string, Key or passphrase used for wallet key derivation. + /// Look to key_derivation_method param for information about supported key derivation methods. + /// "rekey": optional, If present than wallet master key will be rotated to a new one. /// "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. /// Can be optional if storage supports default configuration. /// For 'default' storage type should be empty. - /// "key_derivation_method": optional algorithm to use for master key derivation: - /// ARAGON2I_MOD (used by default) - /// ARAGON2I_INT - less secured but faster - /// "rekey_derivation_method": optional algorithm to use for master rekey derivation: - /// ARAGON2I_MOD (used by default) - /// ARAGON2I_INT - less secured but faster + /// "key_derivation_method": optional Algorithm to use for wallet key derivation: + /// ARGON2I_MOD - derive secured wallet master key (used by default) + /// ARGON2I_INT - derive secured wallet master key (less secured but faster) + /// RAW - raw wallet key master provided (skip derivation). + /// RAW keys can be generated with indy_generate_wallet_key call + /// "rekey_derivation_method": optional Algorithm to use for wallet rekey derivation: + /// ARGON2I_MOD - derive secured wallet master rekey (used by default) + /// ARGON2I_INT - derive secured wallet master rekey (less secured but faster) + /// RAW - raw wallet key master provided (skip derivation). + /// RAW keys can be generated with indy_generate_wallet_key call /// } /// /// #Returns @@ -246,10 +253,13 @@ extern "C" { /// export_config: JSON containing settings for input operation. /// { /// "path": , Path of the file that contains exported wallet content - /// "key": , Passphrase used to derive export key - /// "key_derivation_method": optional algorithm to use for export key derivation: - /// ARAGON2I_MOD (used by default) - /// ARAGON2I_INT - less secured but faster + /// "key": , Key or passphrase used for wallet export key derivation. + /// Look to key_derivation_method param for information about supported key derivation methods. + /// "key_derivation_method": optional Algorithm to use for export key derivation: + /// ARGON2I_MOD - derive secured export key (used by default) + /// ARGON2I_INT - derive secured export key (less secured but faster) + /// RAW - raw export key provided (skip derivation). + /// RAW keys can be generated with indy_generate_wallet_key call /// } /// /// #Returns @@ -289,18 +299,21 @@ extern "C" { /// } /// credentials: Wallet credentials json /// { - /// "key": string, Passphrase used to derive wallet master key + /// "key": string, Key or passphrase used for wallet key derivation. + /// Look to key_derivation_method param for information about supported key derivation methods. /// "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. /// Can be optional if storage supports default configuration. /// For 'default' storage type should be empty. - /// "key_derivation_method": optional algorithm to use for master key derivation: - /// ARAGON2I_MOD (used by default) - /// ARAGON2I_INT - less secured but faster + /// "key_derivation_method": optional Algorithm to use for wallet key derivation: + /// ARGON2I_MOD - derive secured wallet master key (used by default) + /// ARGON2I_INT - derive secured wallet master key (less secured but faster) + /// RAW - raw wallet key master provided (skip derivation). + /// RAW keys can be generated with indy_generate_wallet_key call /// } /// import_config: Import settings json. /// { /// "path": , path of the file that contains exported wallet content - /// "key": , passphrase used to derive export key + /// "key": , key used for export of the wallet /// } /// /// #Returns @@ -355,13 +368,16 @@ extern "C" { /// } /// credentials: Wallet credentials json /// { - /// "key": string, Passphrase used to derive wallet master key + /// "key": string, Key or passphrase used for wallet key derivation. + /// Look to key_derivation_method param for information about supported key derivation methods. /// "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. /// Can be optional if storage supports default configuration. /// For 'default' storage type should be empty. - /// "key_derivation_method": optional algorithm to use for master key derivation: - /// ARAGON2I_MOD (used by default) - /// ARAGON2I_INT - less secured but faster + /// "key_derivation_method": optional Algorithm to use for wallet key derivation: + /// ARGON2I_MOD - derive secured wallet master key (used by default) + /// ARGON2I_INT - derive secured wallet master key (less secured but faster) + /// RAW - raw wallet key master provided (skip derivation). + /// RAW keys can be generated with indy_generate_wallet_key call /// } /// /// #Returns @@ -377,6 +393,30 @@ extern "C" { void (*fn)(indy_handle_t xcommand_handle, indy_error_t err) ); + /// Generate wallet master key. + /// Returned key is compatible with "RAW" key derivation method. + /// It allows to avoid expensive key derivation for use cases when wallet keys can be stored in a secure enclave. + /// + /// #Params + /// config: (optional) key configuration json. + /// { + /// "seed": optional Seed that allows deterministic key creation (if not set random one will be used). + /// } + /// + /// #Returns + /// err: Error code + /// + /// #Errors + /// Common* + /// Wallet* + extern indy_error_t indy_generate_wallet_key(indy_handle_t command_handle, + const char *const config, + + void (*cb)(indy_handle_t command_handle, + indy_error_t err, + const char *const key) + ); + #ifdef __cplusplus } #endif diff --git a/libindy/src/api/anoncreds.rs b/libindy/src/api/anoncreds.rs index b40381c232..e785446d98 100644 --- a/libindy/src/api/anoncreds.rs +++ b/libindy/src/api/anoncreds.rs @@ -770,7 +770,7 @@ pub extern fn indy_prover_store_credential(command_handle: i32, check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam8); trace!("indy_prover_store_credential: entities >>> wallet_handle: {:?}, cred_id: {:?}, cred_req_metadata_json: {:?}, cred_json: {:?}, cred_def_json: {:?}, \ - cred_def_json: {:?}", wallet_handle, cred_id, cred_req_metadata_json, cred_json, cred_def_json, rev_reg_def_json); + rev_reg_def_json: {:?}", wallet_handle, cred_id, cred_req_metadata_json, cred_json, cred_def_json, rev_reg_def_json); let result = CommandExecutor::instance() .send(Command::Anoncreds( diff --git a/libindy/src/api/wallet.rs b/libindy/src/api/wallet.rs index 8f7e7163d1..2463df79a3 100644 --- a/libindy/src/api/wallet.rs +++ b/libindy/src/api/wallet.rs @@ -160,13 +160,16 @@ pub extern fn indy_register_wallet_storage(command_handle: i32, /// } /// credentials: Wallet credentials json /// { -/// "key": string, Passphrase used to derive wallet master key +/// "key": string, Key or passphrase used for wallet key derivation. +/// Look to key_derivation_method param for information about supported key derivation methods. /// "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. /// Can be optional if storage supports default configuration. /// For 'default' storage type should be empty. -/// "key_derivation_method": optional algorithm to use for master key derivation: -/// ARAGON2I_MOD (used by default) -/// ARAGON2I_INT - less secured but faster +/// "key_derivation_method": optional Algorithm to use for wallet key derivation: +/// ARGON2I_MOD - derive secured wallet master key (used by default) +/// ARGON2I_INT - derive secured wallet master key (less secured but faster) +/// RAW - raw wallet key master provided (skip derivation). +/// RAW keys can be generated with indy_generate_wallet_key call /// } /// /// #Returns @@ -231,18 +234,22 @@ pub extern fn indy_create_wallet(command_handle: i32, /// } /// credentials: Wallet credentials json /// { -/// "key": string, Passphrase used to derive current wallet master key -/// "rekey": optional, If present than wallet master key will be rotated to a new one -/// derived from this passphrase. +/// "key": string, Key or passphrase used for wallet key derivation. +/// Look to key_derivation_method param for information about supported key derivation methods. +/// "rekey": optional, If present than wallet master key will be rotated to a new one. /// "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. /// Can be optional if storage supports default configuration. /// For 'default' storage type should be empty. -/// "key_derivation_method": optional algorithm to use for master key derivation: -/// ARAGON2I_MOD (used by default) -/// ARAGON2I_INT - less secured but faster -/// "rekey_derivation_method": optional algorithm to use for master rekey derivation: -/// ARAGON2I_MOD (used by default) -/// ARAGON2I_INT - less secured but faster +/// "key_derivation_method": optional Algorithm to use for wallet key derivation: +/// ARGON2I_MOD - derive secured wallet master key (used by default) +/// ARGON2I_INT - derive secured wallet master key (less secured but faster) +/// RAW - raw wallet key master provided (skip derivation). +/// RAW keys can be generated with indy_generate_wallet_key call +/// "rekey_derivation_method": optional Algorithm to use for wallet rekey derivation: +/// ARGON2I_MOD - derive secured wallet master rekey (used by default) +/// ARGON2I_INT - derive secured wallet master rekey (less secured but faster) +/// RAW - raw wallet rekey master provided (skip derivation). +/// RAW keys can be generated with indy_generate_wallet_key call /// } /// /// #Returns @@ -293,10 +300,13 @@ pub extern fn indy_open_wallet(command_handle: i32, /// export_config: JSON containing settings for input operation. /// { /// "path": , Path of the file that contains exported wallet content -/// "key": , Passphrase used to derive export key -/// "key_derivation_method": optional algorithm to use for export key derivation: -/// ARAGON2I_MOD (used by default) -/// ARAGON2I_INT - less secured but faster +/// "key": , Key or passphrase used for wallet export key derivation. +/// Look to key_derivation_method param for information about supported key derivation methods. +/// "key_derivation_method": optional Algorithm to use for wallet export key derivation: +/// ARGON2I_MOD - derive secured export key (used by default) +/// ARGON2I_INT - derive secured export key (less secured but faster) +/// RAW - raw export key provided (skip derivation). +/// RAW keys can be generated with indy_generate_wallet_key call /// } /// /// #Returns @@ -358,18 +368,21 @@ pub extern fn indy_export_wallet(command_handle: i32, /// } /// credentials: Wallet credentials json /// { -/// "key": string, Passphrase used to derive wallet master key +/// "key": string, Key or passphrase used for wallet key derivation. +/// Look to key_derivation_method param for information about supported key derivation methods. /// "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. /// Can be optional if storage supports default configuration. /// For 'default' storage type should be empty. -/// "key_derivation_method": optional algorithm to use for master key derivation: -/// ARAGON2I_MOD (used by default) -/// ARAGON2I_INT - less secured but faster +/// "key_derivation_method": optional Algorithm to use for wallet key derivation: +/// ARGON2I_MOD - derive secured wallet master key (used by default) +/// ARGON2I_INT - derive secured wallet master key (less secured but faster) +/// RAW - raw wallet key master provided (skip derivation). +/// RAW keys can be generated with indy_generate_wallet_key call /// } /// import_config: Import settings json. /// { /// "path": , path of the file that contains exported wallet content -/// "key": , passphrase used to derive export key +/// "key": , key used for export of the wallet /// } /// /// #Returns @@ -473,13 +486,16 @@ pub extern fn indy_close_wallet(command_handle: i32, /// } /// credentials: Wallet credentials json /// { -/// "key": string, Passphrase used to derive wallet master key +/// "key": string, Key or passphrase used for wallet key derivation. +/// Look to key_derivation_method param for information about supported key derivation methods. /// "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. /// Can be optional if storage supports default configuration. /// For 'default' storage type should be empty. -/// "key_derivation_method": optional algorithm to use for master key derivation: -/// ARAGON2I_MOD (used by default) -/// ARAGON2I_INT - less secured but faster +/// "key_derivation_method": optional Algorithm to use for wallet key derivation: +/// ARGON2I_MOD - derive secured wallet master key (used by default) +/// ARGON2I_INT - derive secured wallet master key (less secured but faster) +/// RAW - raw wallet key master provided (skip derivation). +/// RAW keys can be generated with indy_generate_wallet_key call /// } /// /// #Returns @@ -519,6 +535,52 @@ pub extern fn indy_delete_wallet(command_handle: i32, res } +/// Generate wallet master key. +/// Returned key is compatible with "RAW" key derivation method. +/// It allows to avoid expensive key derivation for use cases when wallet keys can be stored in a secure enclave. +/// +/// #Params +/// config: (optional) key configuration json. +/// { +/// "seed": optional Seed that allows deterministic key creation (if not set random one will be used). +/// } +/// +/// #Returns +/// err: Error code +/// +/// #Errors +/// Common* +/// Wallet* +#[no_mangle] +pub extern fn indy_generate_wallet_key(command_handle: i32, + config: *const c_char, + cb: Option) -> ErrorCode { + trace!("indy_generate_wallet_key: >>> command_handle: {:?}, config: {:?}, cb: {:?}", + command_handle, config, cb); + + check_useful_opt_c_str!(config, ErrorCode::CommonInvalidParam2); + check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam3); + + trace!("indy_generate_wallet_key: params config: {:?}", secret!(config.as_ref())); + + let result = CommandExecutor::instance() + .send(Command::Wallet(WalletCommand::GenerateKey( + config, + Box::new(move |result| { + let (err, key) = result_to_err_code_1!(result, String::new()); + trace!("indy_generate_wallet_key: key: {:?}", key); + let key = CStringUtils::string_to_cstring(key); + cb(command_handle, err, key.as_ptr()) + }) + ))); + + let res = result_to_err_code!(result); + trace!("indy_generate_wallet_key: <<< res: {:?}", res); + res +} + /// Create the wallet storage (For example, database creation) /// /// #Params diff --git a/libindy/src/commands/crypto.rs b/libindy/src/commands/crypto.rs index 88afb84283..efb9ec2318 100644 --- a/libindy/src/commands/crypto.rs +++ b/libindy/src/commands/crypto.rs @@ -4,9 +4,8 @@ extern crate serde_json; use std::collections::HashMap; use errors::common::CommonError; -use errors::wallet::WalletError; use errors::indy::IndyError; -use domain::crypto::key::{KeyInfo, Key}; +use domain::crypto::key::{KeyInfo, Key, KeyMetadata}; use domain::crypto::combo_box::ComboBox; use utils::crypto::base64; use services::wallet::{WalletService, RecordOptions}; @@ -260,16 +259,13 @@ impl CryptoCommandExecutor { self.crypto_service.validate_key(verkey)?; - self.wallet_service.get_indy_record::(wallet_handle, verkey, &RecordOptions::id())?; + let metadata = KeyMetadata {value: metadata.to_string()}; - let mut tags = HashMap::new(); - tags.insert("metadata".to_string(), metadata.to_string()); + self.wallet_service.upsert_indy_object(wallet_handle, &verkey, &metadata)?; - let res = self.wallet_service.add_indy_record_tags::(wallet_handle, verkey, &tags)?; + debug!("set_key_metadata <<<"); - debug!("set_key_metadata <<< res: {:?}", res); - - Ok(res) + Ok(()) } fn get_key_metadata(&self, @@ -279,10 +275,10 @@ impl CryptoCommandExecutor { self.crypto_service.validate_key(verkey)?; - let res = self.wallet_service.get_indy_record::(wallet_handle, verkey, &RecordOptions::full())? - .get_tags() - .and_then(|tags| tags.get("metadata").cloned()) - .ok_or(WalletError::ItemNotFound)?; + let metadata = + self.wallet_service.get_indy_object::(wallet_handle, &verkey, &RecordOptions::id_value(), &mut String::new())?; + + let res = metadata.value; debug!("get_key_metadata <<< res: {:?}", res); diff --git a/libindy/src/commands/did.rs b/libindy/src/commands/did.rs index 21e8e6da46..8a3758cb81 100644 --- a/libindy/src/commands/did.rs +++ b/libindy/src/commands/did.rs @@ -3,7 +3,7 @@ use errors::did::DidError; use errors::wallet::WalletError; use errors::indy::IndyError; use domain::crypto::key::KeyInfo; -use domain::crypto::did::{MyDidInfo, Did, TheirDidInfo, TheirDid, TemporaryDid, DidWithMeta}; +use domain::crypto::did::{MyDidInfo, Did, TheirDidInfo, TheirDid, TemporaryDid, DidWithMeta, DidMetadata}; use domain::ledger::response::Reply; use domain::ledger::nym::{GetNymReplyResult, GetNymResultDataV0}; use domain::ledger::attrib::{GetAttrReplyResult, AttribData, Endpoint}; @@ -290,19 +290,13 @@ impl DidCommandExecutor { self.crypto_service.validate_did(&my_did)?; - let did_record = self.wallet_service.get_indy_record::(wallet_handle, &my_did, &RecordOptions::full())?; - - let did: Did = did_record.get_value() - .and_then(|tags_json| serde_json::from_str(&tags_json).ok()) - .ok_or(CommonError::InvalidStructure(format!("Cannot deserialize Did: {:?}", my_did)))?; - - let meta: Option = did_record.get_tags() - .and_then(|tags| tags.get("metadata").cloned()); + let did = self.wallet_service.get_indy_object::(wallet_handle, &my_did, &RecordOptions::id_value(), &mut String::new())?; + let metadata = self.wallet_service.get_indy_opt_object::(wallet_handle, &did.did, &RecordOptions::id_value(), &mut String::new())?; let did_with_meta = DidWithMeta { did: did.did, verkey: did.verkey, - metadata: meta + metadata: metadata.map(|m|m.value) }; let res = serde_json::to_string(&did_with_meta) @@ -318,7 +312,7 @@ impl DidCommandExecutor { debug!("list_my_dids_with_meta >>> wallet_handle: {:?}", wallet_handle); let mut did_search = - self.wallet_service.search_indy_records::(wallet_handle, "{}", &SearchOptions::full())?; + self.wallet_service.search_indy_records::(wallet_handle, "{}", &SearchOptions::id_value())?; let mut dids: Vec = Vec::new(); @@ -329,13 +323,12 @@ impl DidCommandExecutor { .and_then(|tags_json| serde_json::from_str(&tags_json).ok()) .ok_or(CommonError::InvalidStructure(format!("Cannot deserialize Did: {:?}", did_id)))?; - let meta: Option = did_record.get_tags() - .and_then(|tags| tags.get("metadata").cloned()); + let metadata = self.wallet_service.get_indy_opt_object::(wallet_handle, &did.did, &RecordOptions::id_value(), &mut String::new())?; let did_with_meta = DidWithMeta { did: did.did, verkey: did.verkey, - metadata: meta + metadata: metadata.map(|m|m.value) }; dids.push(did_with_meta); @@ -463,16 +456,13 @@ impl DidCommandExecutor { self.crypto_service.validate_did(&did)?; - self.wallet_service.get_indy_record::(wallet_handle, &did, &RecordOptions::id())?; + let metadata = DidMetadata { value: metadata }; - let mut tags = HashMap::new(); - tags.insert(String::from("metadata"), metadata); + self.wallet_service.upsert_indy_object(wallet_handle, &did, &metadata)?; - let res = self.wallet_service.add_indy_record_tags::(wallet_handle, &did, &tags)?; + debug!("set_did_metadata >>>"); - debug!("set_did_metadata >>> res: {:?}", res); - - Ok(res) + Ok(()) } fn get_did_metadata(&self, @@ -482,10 +472,10 @@ impl DidCommandExecutor { self.crypto_service.validate_did(&did)?; - let res = self.wallet_service.get_indy_record::(wallet_handle, &did, &RecordOptions::full())? - .get_tags() - .and_then(|tags| tags.get("metadata").cloned()) - .ok_or(WalletError::ItemNotFound)?; + let metadata = + self.wallet_service.get_indy_object::(wallet_handle, &did, &RecordOptions::id_value(), &mut String::new())?; + + let res = metadata.value; debug!("get_did_metadata <<< res: {:?}", res); @@ -699,12 +689,4 @@ impl DidCommandExecutor { fn _wallet_get_their_did(&self, wallet_handle: i32, their_did: &str) -> Result { self.wallet_service.get_indy_object(wallet_handle, &their_did, &RecordOptions::id_value(), &mut String::new()) } - - fn _wallet_get_did_metadata(&self, wallet_handle: i32, did: &str) -> Option { - self.wallet_service.get_indy_record::(wallet_handle, did, &RecordOptions::full()).ok() - .and_then(|rec| - rec.get_tags() - .and_then(|tags| tags.get("metadata").cloned()) - ) - } } diff --git a/libindy/src/commands/mod.rs b/libindy/src/commands/mod.rs index 4ea2cba9ae..5b90e4c30a 100644 --- a/libindy/src/commands/mod.rs +++ b/libindy/src/commands/mod.rs @@ -87,7 +87,7 @@ impl CommandExecutor { let ledger_command_executor = LedgerCommandExecutor::new(pool_service.clone(), crypto_service.clone(), wallet_service.clone(), ledger_service.clone()); let pool_command_executor = PoolCommandExecutor::new(pool_service.clone()); let did_command_executor = DidCommandExecutor::new(wallet_service.clone(), crypto_service.clone(), ledger_service.clone()); - let wallet_command_executor = WalletCommandExecutor::new(wallet_service.clone()); + let wallet_command_executor = WalletCommandExecutor::new(wallet_service.clone(), crypto_service.clone()); let pairwise_command_executor = PairwiseCommandExecutor::new(wallet_service.clone()); let blob_storage_command_executor = BlobStorageCommandExecutor::new(blob_storage_service.clone()); let non_secret_command_executor = NonSecretsCommandExecutor::new(wallet_service.clone()); diff --git a/libindy/src/commands/wallet.rs b/libindy/src/commands/wallet.rs index 3ca6352730..7f27592901 100644 --- a/libindy/src/commands/wallet.rs +++ b/libindy/src/commands/wallet.rs @@ -3,10 +3,14 @@ extern crate serde_json; extern crate indy_crypto; use errors::indy::IndyError; +use errors::common::CommonError; use services::wallet::WalletService; +use services::crypto::CryptoService; use api::wallet::*; -use std::rc::Rc; +use utils::crypto::{base58, randombytes, chacha20poly1305_ietf}; +use domain::wallet::KeyConfig; +use std::rc::Rc; use std::result; type Result = result::Result; @@ -56,16 +60,20 @@ pub enum WalletCommand { String, // credentials String, // import config Box) + Send>), + GenerateKey(Option, // config + Box) + Send>), } pub struct WalletCommandExecutor { - wallet_service: Rc + wallet_service: Rc, + crypto_service: Rc, } impl WalletCommandExecutor { - pub fn new(wallet_service: Rc) -> WalletCommandExecutor { + pub fn new(wallet_service: Rc, crypto_service: Rc) -> WalletCommandExecutor { WalletCommandExecutor { - wallet_service + wallet_service, + crypto_service } } @@ -109,6 +117,10 @@ impl WalletCommandExecutor { debug!(target: "wallet_command_executor", "Import command received"); cb(self._import(&config, &credentials, &import_config)); } + WalletCommand::GenerateKey(config, cb) => { + debug!(target: "wallet_command_executor", "DeriveKey command received"); + cb(self._generate_key(config.as_ref().map(String::as_str))); + } }; } @@ -220,4 +232,22 @@ impl WalletCommandExecutor { trace!("_import <<< res: {:?}", res); Ok(res) } + + fn _generate_key(&self, + config: Option<&str>) -> Result { + trace!("_generate_key >>>config: {:?}", secret!(config)); + + let config: KeyConfig = serde_json::from_str(config.unwrap_or("{}")) + .map_err(|err| CommonError::InvalidStructure(format!("Cannot deserialize Key Config: {:?}", err)))?; + + let key = match self.crypto_service.convert_seed(config.seed.as_ref().map(String::as_str))? { + Some(seed) => randombytes::randombytes_deterministic(chacha20poly1305_ietf::KEYBYTES, &randombytes::Seed::from_slice(&seed[..])?), + None => randombytes::randombytes(chacha20poly1305_ietf::KEYBYTES) + }; + + let res = base58::encode(&key[..]); + + trace!("_generate_key <<< res: {:?}", res); + Ok(res) + } } diff --git a/libindy/src/domain/crypto/did.rs b/libindy/src/domain/crypto/did.rs index 24385e8cd3..d727f8bec6 100644 --- a/libindy/src/domain/crypto/did.rs +++ b/libindy/src/domain/crypto/did.rs @@ -40,6 +40,11 @@ impl Did { } } +#[derive(Serialize, Deserialize, Debug, NamedType)] +pub struct DidMetadata { + pub value: String +} + #[derive(Serialize, Clone, Debug, NamedType)] pub struct DidWithMeta { pub did: String, diff --git a/libindy/src/domain/crypto/key.rs b/libindy/src/domain/crypto/key.rs index 82c2c65000..542b8fcd05 100644 --- a/libindy/src/domain/crypto/key.rs +++ b/libindy/src/domain/crypto/key.rs @@ -28,4 +28,9 @@ impl Key { pub struct KeyInfo { pub seed: Option, pub crypto_type: Option +} + +#[derive(Serialize, Deserialize, Debug, NamedType)] +pub struct KeyMetadata { + pub value: String } \ No newline at end of file diff --git a/libindy/src/domain/wallet/export_import.rs b/libindy/src/domain/wallet/export_import.rs index 848d3c212c..eeff2b1469 100644 --- a/libindy/src/domain/wallet/export_import.rs +++ b/libindy/src/domain/wallet/export_import.rs @@ -20,6 +20,13 @@ pub enum EncryptionMethod { // size of encrypted chunk chunk_size: usize, }, + // **ChaCha20-Poly1305-IETF raw key** cypher in blocks per chunk_size bytes + ChaCha20Poly1305IETFRaw { + // chacha20poly1305_ietf::Nonce as bytes. Random start nonce. We increment nonce for each chunk to be sure in export file consistency + nonce: Vec, + // size of encrypted chunk + chunk_size: usize, + }, } #[derive(Debug, Serialize, Deserialize)] diff --git a/libindy/src/domain/wallet/mod.rs b/libindy/src/domain/wallet/mod.rs index af423c1bfa..df6a973df2 100644 --- a/libindy/src/domain/wallet/mod.rs +++ b/libindy/src/domain/wallet/mod.rs @@ -17,18 +17,19 @@ pub struct Credentials { #[serde(default = "default_key_derivation_method")] pub key_derivation_method: KeyDerivationMethod, #[serde(default = "default_key_derivation_method")] - pub rekey_key_derivation_method: KeyDerivationMethod + pub rekey_derivation_method: KeyDerivationMethod } #[allow(non_camel_case_types)] #[derive(Debug, Serialize, Deserialize)] pub enum KeyDerivationMethod { - ARAGON2I_MOD, - ARAGON2I_INT + RAW, + ARGON2I_MOD, + ARGON2I_INT } fn default_key_derivation_method() -> KeyDerivationMethod { - KeyDerivationMethod::ARAGON2I_MOD + KeyDerivationMethod::ARGON2I_MOD } #[derive(Debug, Serialize, Deserialize)] @@ -40,7 +41,24 @@ pub struct ExportConfig { } #[derive(Debug, Serialize, Deserialize)] -pub struct Metadata { +#[serde(untagged)] +pub enum Metadata { + MetadataArgon(MetadataArgon), + MetadataRaw(MetadataRaw), +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct MetadataArgon { pub keys: Vec, pub master_key_salt: Vec, } + +#[derive(Debug, Serialize, Deserialize)] +pub struct MetadataRaw { + pub keys: Vec +} + +#[derive(Debug, Deserialize)] +pub struct KeyConfig { + pub seed: Option +} \ No newline at end of file diff --git a/libindy/src/services/ledger/mod.rs b/libindy/src/services/ledger/mod.rs index 3ebc0c0ad7..6b3dc9eea9 100644 --- a/libindy/src/services/ledger/mod.rs +++ b/libindy/src/services/ledger/mod.rs @@ -809,6 +809,19 @@ mod tests { assert!(node_request.contains(expected_result)); } + #[test] + fn build_node_request_works_with_pop() { + let ledger_service = LedgerService::new(); + let identifier = "identifier"; + let dest = "dest"; + let data = r#"{"node_ip":"ip", "node_port": 1, "client_ip": "ip", "client_port": 1, "alias":"some", "services": ["VALIDATOR"], "blskey":"blskey", "blskey_pop":"pop"}"#; + + let expected_result = r#""identifier":"identifier","operation":{"type":"0","dest":"dest","data":{"node_ip":"ip","node_port":1,"client_ip":"ip","client_port":1,"alias":"some","services":["VALIDATOR"],"blskey":"blskey","blskey_pop":"pop"}}"#; + + let node_request = ledger_service.build_node_request(identifier, dest, data).unwrap(); + assert!(node_request.contains(expected_result)); + } + #[test] fn build_node_request_works_for_wrong_data() { let ledger_service = LedgerService::new(); diff --git a/libindy/src/services/pool/merkle_tree_factory.rs b/libindy/src/services/pool/merkle_tree_factory.rs index cd9b1ddc13..5e32131936 100644 --- a/libindy/src/services/pool/merkle_tree_factory.rs +++ b/libindy/src/services/pool/merkle_tree_factory.rs @@ -233,12 +233,6 @@ mod tests { pub const NODE1_OLD: &'static str = r#"{"data":{"alias":"Node1","client_ip":"192.168.1.35","client_port":9702,"node_ip":"192.168.1.35","node_port":9701,"services":["VALIDATOR"]},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv","identifier":"FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4","txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62","type":"0"}"#; pub const NODE2_OLD: &'static str = r#"{"data":{"alias":"Node2","client_ip":"192.168.1.35","client_port":9704,"node_ip":"192.168.1.35","node_port":9703,"services":["VALIDATOR"]},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb","identifier":"8QhFxKxyaFsJy4CyxeYX34dFH8oWqyBv1P4HLQCsoeLy","txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc","type":"0"}"#; - pub const NODE1: &'static str = r#"{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","client_ip":"10.0.0.2","client_port":9702,"node_ip":"10.0.0.2","node_port":9701,"services":["VALIDATOR"]},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"},"metadata":{"from":"Th7MpTaRZVRYnPiabds81Y"},"type":"0"},"txnMetadata":{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"},"ver":"1"}"#; - pub const NODE2: &'static str = r#"{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","client_ip":"10.0.0.2","client_port":9704,"node_ip":"10.0.0.2","node_port":9703,"services":["VALIDATOR"]},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"},"metadata":{"from":"EbP4aYNeTHL6q385GuVpRV"},"type":"0"},"txnMetadata":{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"},"ver":"1"}"#; - pub const NODE3: &'static str = r#"{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","client_ip":"10.0.0.2","client_port":9706,"node_ip":"10.0.0.2","node_port":9705,"services":["VALIDATOR"]},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"},"metadata":{"from":"4cU41vWW82ArfxJxHkzXPG"},"type":"0"},"txnMetadata":{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"},"ver":"1"}"#; - pub const NODE4: &'static str = r#"{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","client_ip":"10.0.0.2","client_port":9708,"node_ip":"10.0.0.2","node_port":9707,"services":["VALIDATOR"]},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"},"metadata":{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"},"type":"0"},"txnMetadata":{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"},"ver":"1"}"#; - - fn _write_genesis_txns(txns: &str) { let pool_name = "test"; let mut path = EnvironmentUtils::pool_path(pool_name); @@ -257,7 +251,8 @@ mod tests { _set_protocol_version(1); - let txns_src = format!("{}\n{}\n", NODE1, NODE2); + let node_txns = TestUtils::gen_txns(); + let txns_src = node_txns[0..(2 as usize)].join("\n"); _write_genesis_txns(&txns_src); @@ -272,10 +267,12 @@ mod tests { _set_protocol_version(TEST_PROTOCOL_VERSION); - let txn1_json: serde_json::Value = serde_json::from_str(NODE1).unwrap(); - let txn2_json: serde_json::Value = serde_json::from_str(NODE2).unwrap(); - let txn3_json: serde_json::Value = serde_json::from_str(NODE3).unwrap(); - let txn4_json: serde_json::Value = serde_json::from_str(NODE4).unwrap(); + let node_txns = TestUtils::gen_txns(); + + let txn1_json: serde_json::Value = serde_json::from_str(&node_txns[0]).unwrap(); + let txn2_json: serde_json::Value = serde_json::from_str(&node_txns[1]).unwrap(); + let txn3_json: serde_json::Value = serde_json::from_str(&node_txns[2]).unwrap(); + let txn4_json: serde_json::Value = serde_json::from_str(&node_txns[3]).unwrap(); let pool_cache = vec![rmp_serde::to_vec_named(&txn1_json).unwrap(), rmp_serde::to_vec_named(&txn2_json).unwrap(), @@ -300,14 +297,17 @@ mod tests { #[test] fn pool_worker_restore_merkle_tree_works_from_genesis_txns() { TestUtils::cleanup_storage(); - - let txns_src = format!("{}\n{}", NODE1, NODE2); + + let node_txns = TestUtils::gen_txns(); + let txns_src = format!("{}\n{}", + node_txns[0].replace(EnvironmentUtils::test_pool_ip().as_str(), "10.0.0.2"), + node_txns[1].replace(EnvironmentUtils::test_pool_ip().as_str(), "10.0.0.2")); _write_genesis_txns(&txns_src); let merkle_tree = super::create("test").unwrap(); assert_eq!(merkle_tree.count(), 2, "test restored MT size"); - assert_eq!(merkle_tree.root_hash_hex(), "3768ef5b25a01d19c0fda687f2354b29e004821bce8557e70085379f536907ed", "test restored MT root hash"); + assert_eq!(merkle_tree.root_hash_hex(), "c715aef44aaacab8746c9a505ba106b5554fe6d29ec7f0a2abc9d7723fdea523", "test restored MT root hash"); } #[test] @@ -342,10 +342,12 @@ mod tests { _set_protocol_version(TEST_PROTOCOL_VERSION); - let node1: NodeTransactionV1 = serde_json::from_str(NODE1).unwrap(); - let node2: NodeTransactionV1 = serde_json::from_str(NODE2).unwrap(); + let node_txns = TestUtils::gen_txns(); + + let node1: NodeTransactionV1 = serde_json::from_str(&node_txns[0]).unwrap(); + let node2: NodeTransactionV1 = serde_json::from_str(&node_txns[1]).unwrap(); - let txns_src = format!("{}\n{}\n{}\n{}\n", NODE1, NODE2, NODE3, NODE4); + let txns_src = node_txns.join("\n"); _write_genesis_txns(&txns_src); diff --git a/libindy/src/services/pool/mod.rs b/libindy/src/services/pool/mod.rs index af435505a3..3f0601ce01 100644 --- a/libindy/src/services/pool/mod.rs +++ b/libindy/src/services/pool/mod.rs @@ -264,7 +264,6 @@ mod tests { use domain::ledger::request::ProtocolVersion; use std::thread; - pub const NODE1: &'static str = r#"{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","client_ip":"10.0.0.2","client_port":9702,"node_ip":"10.0.0.2","node_port":9701,"services":["VALIDATOR"]},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"},"metadata":{"from":"Th7MpTaRZVRYnPiabds81Y"},"type":"0"},"txnMetadata":{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"},"ver":"1"}"#; const TEST_PROTOCOL_VERSION: usize = 2; fn _set_protocol_version(version: usize) { @@ -513,7 +512,7 @@ mod tests { let ps = PoolService::new(); let pool_name = "pool_drop_works"; - let gen_txn = NODE1; + let gen_txn = TestUtils::gen_txns()[0].clone(); let zmq_ctx = zmq::Context::new(); let send_cmd_sock = zmq_ctx.socket(zmq::SocketType::PAIR).unwrap(); diff --git a/libindy/src/services/pool/pool.rs b/libindy/src/services/pool/pool.rs index 9e5de92996..40eb090656 100644 --- a/libindy/src/services/pool/pool.rs +++ b/libindy/src/services/pool/pool.rs @@ -1171,14 +1171,8 @@ mod tests { TestUtils::cleanup_storage(); } - pub const NODE1: &'static str = r#"{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","client_ip":"10.0.0.2","client_port":9702,"node_ip":"10.0.0.2","node_port":9701,"services":["VALIDATOR"]},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"},"metadata":{"from":"Th7MpTaRZVRYnPiabds81Y"},"type":"0"},"txnMetadata":{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"},"ver":"1"}"#; - pub const NODE2: &'static str = r#"{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","client_ip":"10.0.0.2","client_port":9704,"node_ip":"10.0.0.2","node_port":9703,"services":["VALIDATOR"]},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"},"metadata":{"from":"EbP4aYNeTHL6q385GuVpRV"},"type":"0"},"txnMetadata":{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"},"ver":"1"}"#; - pub const NODE3: &'static str = r#"{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","client_ip":"10.0.0.2","client_port":9706,"node_ip":"10.0.0.2","node_port":9705,"services":["VALIDATOR"]},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"},"metadata":{"from":"4cU41vWW82ArfxJxHkzXPG"},"type":"0"},"txnMetadata":{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"},"ver":"1"}"#; - pub const NODE4: &'static str = r#"{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","client_ip":"10.0.0.2","client_port":9708,"node_ip":"10.0.0.2","node_port":9707,"services":["VALIDATOR"]},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"},"metadata":{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"},"type":"0"},"txnMetadata":{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"},"ver":"1"}"#; - - fn _write_genesis_txns() { - let txns = format!("{}\n{}\n{}\n{}", NODE1, NODE2, NODE3, NODE4); + let txns = TestUtils::gen_txns().join("\n"); let mut path = EnvironmentUtils::pool_path(POOL); fs::create_dir_all(path.as_path()).unwrap(); diff --git a/libindy/src/services/wallet/encryption.rs b/libindy/src/services/wallet/encryption.rs index 3baf63a118..bc545c7393 100644 --- a/libindy/src/services/wallet/encryption.rs +++ b/libindy/src/services/wallet/encryption.rs @@ -1,7 +1,7 @@ use std::str; use std::collections::HashMap; -use utils::crypto::{chacha20poly1305_ietf, hmacsha256, pwhash_argon2i13}; +use utils::crypto::{chacha20poly1305_ietf, hmacsha256, pwhash_argon2i13, base58}; use super::{Keys, WalletRecord}; use super::storage::{Tag, TagName, StorageRecord}; @@ -15,7 +15,7 @@ pub(super) fn gen_master_key_salt() -> Result Result { let salt = pwhash_argon2i13::Salt::from_slice(slice) - .map_err(|_| ::errors::common::CommonError::InvalidState("Invalid master key salt".to_string()))?; + .map_err(|_| WalletError::AccessFailed("Invalid master key salt".to_string()))?; Ok(salt) } @@ -25,6 +25,13 @@ pub(super) fn derive_master_key(passphrase: &str, salt: &pwhash_argon2i13::Salt, Ok(key) } +pub(super) fn raw_master_key(passphrase: &str) -> Result { + let bytes = &base58::decode(passphrase)?; + let key = chacha20poly1305_ietf::Key::from_slice(&bytes) + .map_err(|_| ::errors::common::CommonError::InvalidStructure("Invalid Master Key length".to_string()))?; + Ok(key) +} + pub(super) fn encrypt_tag_names(tag_names: &[&str], tag_name_key: &chacha20poly1305_ietf::Key, tags_hmac_key: &hmacsha256::Key) -> Vec { tag_names .iter() diff --git a/libindy/src/services/wallet/export_import.rs b/libindy/src/services/wallet/export_import.rs index 3083676789..c4ca5973db 100644 --- a/libindy/src/services/wallet/export_import.rs +++ b/libindy/src/services/wallet/export_import.rs @@ -9,6 +9,7 @@ use domain::wallet::export_import::{Header, EncryptionMethod, Record}; use errors::common::CommonError; use utils::crypto::hash::{hash, HASHBYTES}; use utils::crypto::{chacha20poly1305_ietf, pwhash_argon2i13}; +use services::wallet::encryption::raw_master_key; use super::{WalletError, Wallet, WalletRecord}; @@ -24,15 +25,19 @@ pub(super) fn export(wallet: &Wallet, writer: &mut Write, passphrase: &str, vers let chunk_size = CHUNK_SIZE; let encryption_method = match key_derivation_method { - KeyDerivationMethod::ARAGON2I_MOD => EncryptionMethod::ChaCha20Poly1305IETF { + KeyDerivationMethod::ARGON2I_MOD => EncryptionMethod::ChaCha20Poly1305IETF { salt: salt[..].to_vec(), nonce: nonce[..].to_vec(), chunk_size, }, - KeyDerivationMethod::ARAGON2I_INT => EncryptionMethod::ChaCha20Poly1305IETFInteractive { + KeyDerivationMethod::ARGON2I_INT => EncryptionMethod::ChaCha20Poly1305IETFInteractive { salt: salt[..].to_vec(), nonce: nonce[..].to_vec(), chunk_size, + }, + KeyDerivationMethod::RAW => EncryptionMethod::ChaCha20Poly1305IETFRaw { + nonce: nonce[..].to_vec(), + chunk_size, } }; @@ -50,9 +55,14 @@ pub(super) fn export(wallet: &Wallet, writer: &mut Write, passphrase: &str, vers writer.write_u32::(header.len() as u32)?; writer.write_all(&header)?; + let master_key = match key_derivation_method { + KeyDerivationMethod::ARGON2I_MOD | KeyDerivationMethod::ARGON2I_INT => chacha20poly1305_ietf::derive_key(passphrase, &salt, key_derivation_method)?, + KeyDerivationMethod::RAW => raw_master_key(passphrase)? + }; + // Write ecnrypted let mut writer = chacha20poly1305_ietf::Writer::new(writer, - chacha20poly1305_ietf::derive_key(passphrase, &salt, key_derivation_method)?, + master_key, nonce, chunk_size); @@ -101,12 +111,12 @@ pub(super) fn import(wallet: &Wallet, reader: &mut Read, passphrase: &str) -> Re } let key_derivation_method = match header.encryption_method { - EncryptionMethod::ChaCha20Poly1305IETF { .. } => KeyDerivationMethod::ARAGON2I_MOD, - EncryptionMethod::ChaCha20Poly1305IETFInteractive { .. } => KeyDerivationMethod::ARAGON2I_INT, + EncryptionMethod::ChaCha20Poly1305IETF { .. } => KeyDerivationMethod::ARGON2I_MOD, + EncryptionMethod::ChaCha20Poly1305IETFInteractive { .. } => KeyDerivationMethod::ARGON2I_INT, + EncryptionMethod::ChaCha20Poly1305IETFRaw { .. } => KeyDerivationMethod::RAW, }; - // Reads encrypted - let mut reader = match header.encryption_method { + let (key, nonce, chunk_size) = match header.encryption_method { EncryptionMethod::ChaCha20Poly1305IETF { salt, nonce, chunk_size } | EncryptionMethod::ChaCha20Poly1305IETFInteractive { salt, nonce, chunk_size } => { let salt = pwhash_argon2i13::Salt::from_slice(&salt) .map_err(|err| CommonError::InvalidStructure(format!("Invalid salt: {:?}", err)))?; @@ -116,10 +126,21 @@ pub(super) fn import(wallet: &Wallet, reader: &mut Read, passphrase: &str) -> Re let key = chacha20poly1305_ietf::derive_key(passphrase, &salt, &key_derivation_method)?; - chacha20poly1305_ietf::Reader::new(reader, key, nonce, chunk_size) + (key, nonce, chunk_size) + } + EncryptionMethod::ChaCha20Poly1305IETFRaw { nonce, chunk_size } => { + let nonce = chacha20poly1305_ietf::Nonce::from_slice(&nonce) + .map_err(|err| CommonError::InvalidStructure(format!("Invalid nonce: {:?}", err)))?; + + let key = raw_master_key(passphrase)?; + + (key, nonce, chunk_size) } }; + // Reads encrypted + let mut reader = chacha20poly1305_ietf::Reader::new(reader, key, nonce, chunk_size); + let mut header_hash = vec![0u8; HASHBYTES]; reader.read_exact(&mut header_hash).map_err(_map_io_err)?; @@ -162,7 +183,7 @@ mod tests { use std::rc::Rc; use std::collections::HashMap; - use domain::wallet::Metadata; + use domain::wallet::{Metadata, MetadataArgon}; use utils::crypto::pwhash_argon2i13; use utils::test::TestUtils; use services::wallet::encryption; @@ -175,7 +196,7 @@ mod tests { _cleanup(); let mut output: Vec = Vec::new(); - export(&_wallet1(), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARAGON2I_MOD).unwrap(); + export(&_wallet1(), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARGON2I_MOD).unwrap(); let wallet = _wallet2(); _assert_is_empty(&wallet); @@ -189,7 +210,7 @@ mod tests { _cleanup(); let mut output: Vec = Vec::new(); - export(&_add_2_records(_wallet1()), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARAGON2I_MOD).unwrap(); + export(&_add_2_records(_wallet1()), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARGON2I_MOD).unwrap(); let wallet = _wallet2(); _assert_is_empty(&wallet); @@ -203,7 +224,7 @@ mod tests { _cleanup(); let mut output: Vec = Vec::new(); - export(&_add_2_records(_wallet1()), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARAGON2I_INT).unwrap(); + export(&_add_2_records(_wallet1()), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARGON2I_INT).unwrap(); let wallet = _wallet2(); _assert_is_empty(&wallet); @@ -217,7 +238,7 @@ mod tests { _cleanup(); let mut output: Vec = Vec::new(); - export(&_add_300_records(_wallet1()), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARAGON2I_MOD).unwrap(); + export(&_add_300_records(_wallet1()), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARGON2I_MOD).unwrap(); let wallet = _wallet2(); _assert_is_empty(&wallet); @@ -272,7 +293,7 @@ mod tests { _cleanup(); let mut output: Vec = Vec::new(); - export(&_wallet1(), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARAGON2I_MOD).unwrap(); + export(&_wallet1(), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARGON2I_MOD).unwrap(); // Modifying one of the bytes in the header hash let pos = (&mut output.as_slice()).read_u32::().unwrap() as usize + 2; @@ -287,7 +308,7 @@ mod tests { _cleanup(); let mut output: Vec = Vec::new(); - export(&_add_300_records(_wallet1()), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARAGON2I_MOD).unwrap(); + export(&_add_300_records(_wallet1()), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARGON2I_MOD).unwrap(); // Modifying one byte in the middle of encrypted part let pos = output.len() / 2; @@ -302,7 +323,7 @@ mod tests { _cleanup(); let mut output: Vec = Vec::new(); - export(&_add_2_records(_wallet1()), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARAGON2I_MOD).unwrap(); + export(&_add_2_records(_wallet1()), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARGON2I_MOD).unwrap(); output.pop().unwrap(); @@ -315,7 +336,7 @@ mod tests { _cleanup(); let mut output: Vec = Vec::new(); - export(&_add_2_records(_wallet1()), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARAGON2I_MOD).unwrap(); + export(&_add_2_records(_wallet1()), &mut output, _passphrase(), _version1(), &KeyDerivationMethod::ARGON2I_MOD).unwrap(); output.push(10); @@ -343,10 +364,10 @@ mod tests { let metadata = { let master_key_salt = encryption::gen_master_key_salt().unwrap(); - let metadata = Metadata { + let metadata = Metadata::MetadataArgon(MetadataArgon { master_key_salt: master_key_salt[..].to_vec(), keys: keys.serialize_encrypted(&master_key).unwrap(), - }; + }); serde_json::to_vec(&metadata) .map_err(|err| CommonError::InvalidState(format!("Cannot serialize wallet metadata: {:?}", err))).unwrap() diff --git a/libindy/src/services/wallet/mod.rs b/libindy/src/services/wallet/mod.rs index f43e091d4a..07a4df4eda 100644 --- a/libindy/src/services/wallet/mod.rs +++ b/libindy/src/services/wallet/mod.rs @@ -15,7 +15,7 @@ use named_type::NamedType; use std::rc::Rc; use api::wallet::*; -use domain::wallet::{Config, Credentials, ExportConfig, Metadata}; +use domain::wallet::{Config, Credentials, ExportConfig, Metadata, MetadataArgon, MetadataRaw, KeyDerivationMethod}; use errors::wallet::WalletError; use errors::common::CommonError; use utils::sequence::SequenceUtils; @@ -123,18 +123,7 @@ impl WalletService { .ok_or(WalletError::UnknownType(storage_type.to_string()))? }; - let metadata = { - let master_key_salt = encryption::gen_master_key_salt()?; - let master_key = encryption::derive_master_key(&credentials.key, &master_key_salt, &credentials.key_derivation_method)?; - - let metadata = Metadata { - master_key_salt: master_key_salt[..].to_vec(), - keys: Keys::new().serialize_encrypted(&master_key)?, - }; - - serde_json::to_vec(&metadata) - .map_err(|err| CommonError::InvalidState(format!("Cannot serialize wallet metadata: {:?}", err)))? - }; + let metadata = self._prepare_metadata(&credentials.key, &credentials.key_derivation_method, &Keys::new())?; storage_type.create_storage(&config.id, config.storage_config @@ -195,13 +184,7 @@ impl WalletService { .map_err(|err| CommonError::InvalidState(format!("Cannot deserialize metadata: {:?}", err)))? }; - let master_key = { - let master_key_salt = encryption::master_key_salt_from_slice(&metadata.master_key_salt)?; - encryption::derive_master_key(&credentials.key, &master_key_salt, &credentials.key_derivation_method)? - }; - - Keys::deserialize_encrypted(&metadata.keys, &master_key) - .map_err(|_| WalletError::AccessFailed("Invalid master key provided".to_string()))?; + self._restore_keys(&metadata, &credentials.key, &credentials.key_derivation_method)?; } storage_type.delete_storage(&config.id, @@ -262,28 +245,11 @@ impl WalletService { .map_err(|err| CommonError::InvalidState(format!("Cannot deserialize metadata: {:?}", err)))? }; - let master_key = { - let master_key_salt = encryption::master_key_salt_from_slice(&metadata.master_key_salt)?; - encryption::derive_master_key(&credentials.key, &master_key_salt, &credentials.key_derivation_method)? - }; - - let keys = Keys::deserialize_encrypted(&metadata.keys, &master_key)?; + let keys = self._restore_keys(&metadata, &credentials.key, &credentials.key_derivation_method)?; // Rotate master key if let Some(rekey) = credentials.rekey { - let metadata = { - let master_key_salt = encryption::gen_master_key_salt()?; - let master_key = encryption::derive_master_key(&rekey, &master_key_salt, &credentials.rekey_key_derivation_method)?; - - let metadata = Metadata { - master_key_salt: master_key_salt[..].to_vec(), - keys: keys.serialize_encrypted(&master_key)?, - }; - - serde_json::to_vec(&metadata) - .map_err(|err| CommonError::InvalidState(format!("Cannot serialize wallet metadata: {:?}", err)))? - }; - + let metadata = self._prepare_metadata(&rekey, &credentials.rekey_derivation_method, &keys)?; storage.set_storage_metadata(&metadata)?; } @@ -354,11 +320,6 @@ impl WalletService { } } - pub fn add_indy_record_tags(&self, wallet_handle: i32, name: &str, tags: &HashMap) - -> Result<(), WalletError> where T: NamedType { - self.add_record_tags(wallet_handle, &self.add_prefix(T::short_type_name()), name, tags) - } - pub fn update_record_tags(&self, wallet_handle: i32, type_: &str, name: &str, tags: &HashMap) -> Result<(), WalletError> { match self.wallets.borrow_mut().get_mut(&wallet_handle) { Some(wallet) => wallet.update_tags(type_, name, tags), @@ -413,6 +374,15 @@ impl WalletService { WalletError::CommonError(CommonError::InvalidState(format!("Cannot deserialize {:?}: {:?}", type_, err)))) } + // Dirty hack. json must live longer then result T + pub fn get_indy_opt_object<'a, T>(&self, wallet_handle: i32, name: &str, options_json: &str, json: &'a mut String) -> Result, WalletError> where T: ::serde::Deserialize<'a>, T: NamedType { + match self.get_indy_object::(wallet_handle, name, options_json, json) { + Ok(res) => Ok(Some(res)), + Err(WalletError::ItemNotFound) => Ok(None), + Err(err) => Err(err) + } + } + pub fn search_records(&self, wallet_handle: i32, type_: &str, query_json: &str, options_json: &str) -> Result { match self.wallets.borrow().get(&wallet_handle) { Some(wallet) => Ok(WalletSearch { iter: wallet.search(type_, query_json, Some(options_json))? }), @@ -534,6 +504,51 @@ impl WalletService { res } + fn _prepare_metadata(&self, key: &str, key_derivation_method: &KeyDerivationMethod, keys: &Keys) -> Result, WalletError> { + let metadata = match key_derivation_method { + KeyDerivationMethod::RAW => { + let master_key = encryption::raw_master_key(key)?; + Metadata::MetadataRaw( + MetadataRaw { keys: keys.serialize_encrypted(&master_key)? } + ) + } + KeyDerivationMethod::ARGON2I_INT | KeyDerivationMethod::ARGON2I_MOD => { + let master_key_salt = encryption::gen_master_key_salt()?; + let master_key = encryption::derive_master_key(key, &master_key_salt, key_derivation_method)?; + Metadata::MetadataArgon( + MetadataArgon { + keys: keys.serialize_encrypted(&master_key)?, + master_key_salt: master_key_salt[..].to_vec() + } + ) + } + }; + + let res = serde_json::to_vec(&metadata) + .map_err(|err| CommonError::InvalidState(format!("Cannot serialize wallet metadata: {:?}", err)))?; + + Ok(res) + } + + fn _restore_keys(&self, metadata: &Metadata, key: &str, key_derivation_method: &KeyDerivationMethod) -> Result { + let (metadata_keys, master_key) = match (key_derivation_method, metadata) { + (KeyDerivationMethod::RAW, Metadata::MetadataRaw(metadata)) => + (metadata.keys.as_ref(), encryption::raw_master_key(key)?), + (KeyDerivationMethod::ARGON2I_INT, Metadata::MetadataArgon(metadata)) | + (KeyDerivationMethod::ARGON2I_MOD, Metadata::MetadataArgon(metadata)) => { + let master_key_salt = encryption::master_key_salt_from_slice(&metadata.master_key_salt)?; + let master_key = encryption::derive_master_key(key, &master_key_salt, key_derivation_method)?; + ((metadata.keys.as_ref(), master_key)) + } + _ => return Err(WalletError::AccessFailed("Invalid combination of KeyDerivationMethod and Metadata".to_string())) + }; + + let res = Keys::deserialize_encrypted(&metadata_keys, &master_key) + .map_err(|_| WalletError::AccessFailed("Invalid master key provided".to_string()))?; + + Ok(res) + } + pub const PREFIX: &'static str = "Indy"; pub fn add_prefix(&self, type_: &str) -> String { @@ -585,6 +600,7 @@ impl WalletRecord { self.value.as_ref().map(String::as_str) } + #[allow(dead_code)] pub fn get_tags(&self) -> Option<&HashMap> { self.tags.as_ref() } @@ -625,16 +641,6 @@ impl RecordOptions { serde_json::to_string(&options).unwrap() } - - pub fn full() -> String { - let options = RecordOptions { - retrieve_type: true, - retrieve_value: true, - retrieve_tags: true - }; - - serde_json::to_string(&options).unwrap() - } } impl Default for RecordOptions { @@ -677,18 +683,6 @@ pub struct SearchOptions { } impl SearchOptions { - pub fn full() -> String { - let options = SearchOptions { - retrieve_records: true, - retrieve_total_count: true, - retrieve_type: true, - retrieve_value: true, - retrieve_tags: true - }; - - serde_json::to_string(&options).unwrap() - } - pub fn id_value() -> String { let options = SearchOptions { retrieve_records: true, @@ -756,6 +750,14 @@ mod tests { wallet_service.create_wallet(&_config_default(), &_credentials_interactive()).unwrap(); } + #[test] + fn wallet_service_create_wallet_works_for_raw_key() { + _cleanup(); + + let wallet_service = WalletService::new(); + wallet_service.create_wallet(&_config_default(), &_credentials_raw()).unwrap(); + } + #[test] fn wallet_service_create_wallet_works_for_comparision_time_of_different_key_types() { use std::time::SystemTime; @@ -816,6 +818,16 @@ mod tests { assert_match!(Err(WalletError::AlreadyExists(_)), res); } + #[test] + fn wallet_service_create_wallet_works_for_invalid_raw_key() { + _cleanup(); + + let wallet_service = WalletService::new(); + wallet_service.create_wallet(&_config(), &_credentials()).unwrap(); + let res = wallet_service.create_wallet(&_config(), &_credentials_invalid_raw()); + assert_match!(Err(WalletError::CommonError(CommonError::InvalidStructure(_))), res); + } + #[test] fn wallet_service_delete_wallet_works() { _cleanup(); @@ -827,7 +839,7 @@ mod tests { } #[test] - fn wallet_service_delete_wallet_works_for_interactive_method() { + fn wallet_service_delete_wallet_works_for_interactive_key_derivation() { _cleanup(); let wallet_service = WalletService::new(); @@ -836,6 +848,16 @@ mod tests { wallet_service.create_wallet(&_config(), &_credentials_interactive()).unwrap(); } + #[test] + fn wallet_service_delete_wallet_works_for_raw_key() { + _cleanup(); + + let wallet_service = WalletService::new(); + wallet_service.create_wallet(&_config(), &_credentials_raw()).unwrap(); + wallet_service.delete_wallet(&_config(), &_credentials_raw()).unwrap(); + wallet_service.create_wallet(&_config(), &_credentials_raw()).unwrap(); + } + #[test] fn wallet_service_delete_works_for_plugged() { _cleanup(); @@ -886,7 +908,7 @@ mod tests { } #[test] - fn wallet_service_open_wallet_works_for_interactive_method() { + fn wallet_service_open_wallet_works_for_interactive_key_derivation() { _cleanup(); let wallet_service = WalletService::new(); @@ -897,6 +919,18 @@ mod tests { wallet_service.close_wallet(handle).unwrap(); } + #[test] + fn wallet_service_open_wallet_works_for_raw_key() { + _cleanup(); + + let wallet_service = WalletService::new(); + wallet_service.create_wallet(&_config(), &_credentials_raw()).unwrap(); + let handle = wallet_service.open_wallet(&_config(), &_credentials_raw()).unwrap(); + + // cleanup + wallet_service.close_wallet(handle).unwrap(); + } + #[test] fn wallet_service_open_unknown_wallet() { _cleanup(); @@ -928,7 +962,7 @@ mod tests { } #[test] - fn wallet_service_open_wallet_returns_error_if_passed_different_value_for_interactive_method() { + fn wallet_service_open_wallet_returns_error_if_used_different_methods_for_creating_and_opening() { _cleanup(); let wallet_service = WalletService::new(); @@ -1511,6 +1545,38 @@ mod tests { assert_eq!("value1", record.get_value().unwrap()); } + #[test] + fn wallet_service_key_rotation_for_rekey_raw_method() { + _cleanup(); + + let wallet_service = WalletService::new(); + wallet_service.create_wallet(&_config(), &_credentials()).unwrap(); + let wallet_handle = wallet_service.open_wallet(&_config(), &_credentials()).unwrap(); + + wallet_service.add_record(wallet_handle, "type", "key1", "value1", &HashMap::new()).unwrap(); + let record = wallet_service.get_record(wallet_handle, "type", "key1", &_fetch_options(true, true, true)).unwrap(); + assert_eq!("type", record.get_type().unwrap()); + assert_eq!("value1", record.get_value().unwrap()); + + wallet_service.close_wallet(wallet_handle).unwrap(); + + let wallet_handle = wallet_service.open_wallet(&_config(), &_rekey_credentials_raw()).unwrap(); + let record = wallet_service.get_record(wallet_handle, "type", "key1", &_fetch_options(true, true, true)).unwrap(); + assert_eq!("type", record.get_type().unwrap()); + assert_eq!("value1", record.get_value().unwrap()); + wallet_service.close_wallet(wallet_handle).unwrap(); + + // Access failed for old key + let res = wallet_service.open_wallet(&_config(), &_credentials()); + assert_match!(Err(WalletError::AccessFailed(_)), res); + + // Works ok with new key when reopening + let wallet_handle = wallet_service.open_wallet(&_config(), &_credentials_for_new_key_raw()).unwrap(); + let record = wallet_service.get_record(wallet_handle, "type", "key1", &_fetch_options(true, true, true)).unwrap(); + assert_eq!("type", record.get_type().unwrap()); + assert_eq!("value1", record.get_value().unwrap()); + } + #[test] fn wallet_service_export_wallet_when_empty() { _cleanup(); @@ -1557,6 +1623,22 @@ mod tests { assert!(Path::new(&_export_file_path()).exists()); } + #[test] + fn wallet_service_export_wallet_1_item_raw_method() { + _cleanup(); + + let wallet_service = WalletService::new(); + wallet_service.create_wallet(&_config(), &_credentials()).unwrap(); + let wallet_handle = wallet_service.open_wallet(&_config(), &_credentials()).unwrap(); + + wallet_service.add_record(wallet_handle, "type", "key1", "value1", &HashMap::new()).unwrap(); + wallet_service.get_record(wallet_handle, "type", "key1", "{}").unwrap(); + + let export_config = _export_config_raw(); + wallet_service.export_wallet(wallet_handle, &export_config, 0).unwrap(); + assert!(Path::new(&_export_file_path()).exists()); + } + #[test] fn wallet_service_export_wallet_returns_error_if_file_exists() { _cleanup(); @@ -1633,6 +1715,28 @@ mod tests { wallet_service.get_record(wallet_handle, "type", "key1", "{}").unwrap(); } + #[test] + fn wallet_service_export_import_wallet_1_item_for_raw_method() { + _cleanup(); + + let wallet_service = WalletService::new(); + wallet_service.create_wallet(&_config(), &_credentials()).unwrap(); + let wallet_handle = wallet_service.open_wallet(&_config(), &_credentials()).unwrap(); + + wallet_service.add_record(wallet_handle, "type", "key1", "value1", &HashMap::new()).unwrap(); + wallet_service.get_record(wallet_handle, "type", "key1", "{}").unwrap(); + + wallet_service.export_wallet(wallet_handle, &_export_config_raw(), 0).unwrap(); + assert!(_export_file_path().exists()); + + wallet_service.close_wallet(wallet_handle).unwrap(); + wallet_service.delete_wallet(&_config(), &_credentials()).unwrap(); + + wallet_service.import_wallet(&_config(), &_credentials_raw(), &_export_config_raw()).unwrap(); + let wallet_handle = wallet_service.open_wallet(&_config(), &_credentials_raw()).unwrap(); + wallet_service.get_record(wallet_handle, "type", "key1", "{}").unwrap(); + } + #[test] fn wallet_service_export_import_wallet_1_item_for_export_interactive_import_as_moderate() { _cleanup(); @@ -1737,7 +1841,15 @@ mod tests { } fn _credentials_interactive() -> String { - json!({"key": "my_key", "key_derivation_method": "ARAGON2I_INT"}).to_string() + json!({"key": "my_key", "key_derivation_method": "ARGON2I_INT"}).to_string() + } + + fn _credentials_raw() -> String { + json!({"key": "6nxtSiXFvBd593Y2DCed2dYvRY1PGK9WMtxCBjLzKgbw", "key_derivation_method": "RAW"}).to_string() + } + + fn _credentials_invalid_raw() -> String { + json!({"key": "key", "key_derivation_method": "RAW"}).to_string() } fn _rekey_credentials() -> String { @@ -1745,7 +1857,11 @@ mod tests { } fn _rekey_credentials_interactive() -> String { - json!({"key": "my_key", "rekey": "my_new_key", "rekey_derivation_method": "ARAGON2I_INT"}).to_string() + json!({"key": "my_key", "rekey": "my_new_key", "rekey_derivation_method": "ARGON2I_INT"}).to_string() + } + + fn _rekey_credentials_raw() -> String { + json!({"key": "my_key", "rekey": "6nxtSiXFvBd593Y2DCed2dYvRY1PGK9WMtxCBjLzKgbw", "rekey_derivation_method": "RAW"}).to_string() } fn _credentials_for_new_key() -> String { @@ -1753,7 +1869,11 @@ mod tests { } fn _credentials_for_new_key_interactive() -> String { - json!({"key": "my_new_key"}).to_string() + json!({"key": "my_new_key", "key_derivation_method": "ARGON2I_INT"}).to_string() + } + + fn _credentials_for_new_key_raw() -> String { + json!({"key": "6nxtSiXFvBd593Y2DCed2dYvRY1PGK9WMtxCBjLzKgbw", "key_derivation_method": "RAW"}).to_string() } fn _export_file_path() -> PathBuf { @@ -1773,7 +1893,15 @@ mod tests { json!({ "path": _export_file_path().to_str().unwrap(), "key": "export_key", - "key_derivation_method": "ARAGON2I_INT" + "key_derivation_method": "ARGON2I_INT" + }).to_string() + } + + fn _export_config_raw() -> String { + json!({ + "path": _export_file_path().to_str().unwrap(), + "key": "6nxtSiXFvBd593Y2DCed2dYvRY1PGK9WMtxCBjLzKgbw", + "key_derivation_method": "RAW" }).to_string() } diff --git a/libindy/src/services/wallet/wallet.rs b/libindy/src/services/wallet/wallet.rs index ec9185fecb..472a5bbfec 100644 --- a/libindy/src/services/wallet/wallet.rs +++ b/libindy/src/services/wallet/wallet.rs @@ -227,7 +227,7 @@ mod tests { use std::rc::Rc; use std::collections::HashMap; - use domain::wallet::Metadata; + use domain::wallet::{Metadata, MetadataArgon}; use errors::wallet::WalletError; use services::wallet::encryption; use services::wallet::wallet::Wallet; @@ -1816,10 +1816,10 @@ mod tests { let metadata = { let master_key_salt = encryption::gen_master_key_salt().unwrap(); - let metadata = Metadata { + let metadata = Metadata::MetadataArgon(MetadataArgon { master_key_salt: master_key_salt[..].to_vec(), keys: keys.serialize_encrypted(&master_key).unwrap(), - }; + }); serde_json::to_vec(&metadata) .map_err(|err| CommonError::InvalidState(format!("Cannot serialize wallet metadata: {:?}", err))).unwrap() @@ -1839,9 +1839,9 @@ mod tests { let storage_type = SQLiteStorageType::new(); let storage = storage_type.open_storage(_wallet_id(), None, None).unwrap(); - let metadata: Metadata = { + let metadata: MetadataArgon = { let metadata = storage.get_storage_metadata().unwrap(); - serde_json::from_slice(&metadata) + serde_json::from_slice::(&metadata) .map_err(|err| CommonError::InvalidState(format!("Cannot deserialize metadata: {:?}", err))).unwrap() }; diff --git a/libindy/src/utils/crypto/ed25519_sign/sodium.rs b/libindy/src/utils/crypto/ed25519_sign/sodium.rs index d5fb4a7f5b..b24c18a4e3 100644 --- a/libindy/src/utils/crypto/ed25519_sign/sodium.rs +++ b/libindy/src/utils/crypto/ed25519_sign/sodium.rs @@ -5,18 +5,21 @@ use errors::crypto::CryptoError; use self::libc::c_int; use self::sodiumoxide::crypto::sign; +use self::sodiumoxide::crypto::box_; use utils::crypto::ed25519_box; use utils::crypto::randombytes::randombytes; pub const SEEDBYTES: usize = sign::SEEDBYTES; -pub const PUBLICKEYBYTES: usize = sign::PUBLICKEYBYTES; -pub const SECRETKEYBYTES: usize = sign::SECRETKEYBYTES; +pub const SIG_PUBLICKEYBYTES: usize = sign::PUBLICKEYBYTES; +pub const ENC_PUBLICKEYBYTES: usize = box_::PUBLICKEYBYTES; +pub const SIG_SECRETKEYBYTES: usize = sign::SECRETKEYBYTES; +pub const ENC_SECRETKEYBYTES: usize = box_::SECRETKEYBYTES; pub const SIGNATUREBYTES: usize = sign::SIGNATUREBYTES; sodium_type!(Seed, sign::Seed, SEEDBYTES); -sodium_type!(PublicKey, sign::PublicKey, PUBLICKEYBYTES); -sodium_type!(SecretKey, sign::SecretKey, SECRETKEYBYTES); +sodium_type!(PublicKey, sign::PublicKey, SIG_PUBLICKEYBYTES); +sodium_type!(SecretKey, sign::SecretKey, SIG_SECRETKEYBYTES); sodium_type!(Signature, sign::Signature, SIGNATUREBYTES); extern { @@ -24,11 +27,11 @@ extern { // this functions isn't included to sodiumoxide rust wrappers, // temporary local binding is used to call libsodium-sys function pub fn crypto_sign_ed25519_pk_to_curve25519( - curve25519_pk: *mut [u8; 32], - ed25519_pk: *const [u8; 32]) -> c_int; + curve25519_pk: *mut [u8; ENC_PUBLICKEYBYTES], + ed25519_pk: *const [u8; SIG_PUBLICKEYBYTES]) -> c_int; pub fn crypto_sign_ed25519_sk_to_curve25519( - curve25519_sk: *mut [u8; 32], - ed25519_sk: *const [u8; 64]) -> c_int; + curve25519_sk: *mut [u8; ENC_SECRETKEYBYTES], + ed25519_sk: *const [u8; SIG_SECRETKEYBYTES]) -> c_int; } @@ -36,7 +39,7 @@ pub fn create_key_pair_for_signature(seed: Option<&Seed>) -> Result<(PublicKey, let (public_key, secret_key) = sign::keypair_from_seed( &seed.unwrap_or( - &Seed::from_slice(&randombytes(32)).unwrap() + &Seed::from_slice(&randombytes(SEEDBYTES)).unwrap() ).0 ); @@ -60,7 +63,7 @@ pub fn verify(public_key: &PublicKey, doc: &[u8], signature: &Signature) -> Resu } pub fn sk_to_curve25519(sk: &SecretKey) -> Result { - let mut to: [u8; 32] = [0; 32]; + let mut to: [u8; ENC_SECRETKEYBYTES] = [0; ENC_SECRETKEYBYTES]; unsafe { crypto_sign_ed25519_sk_to_curve25519(&mut to, &(sk.0).0); } @@ -68,7 +71,7 @@ pub fn sk_to_curve25519(sk: &SecretKey) -> Result Result { - let mut to: [u8; 32] = [0; 32]; + let mut to: [u8; ENC_PUBLICKEYBYTES] = [0; ENC_PUBLICKEYBYTES]; unsafe { crypto_sign_ed25519_pk_to_curve25519(&mut to, &(pk.0).0); } @@ -82,7 +85,7 @@ mod tests { #[test] fn signin_verify_works() { - let seed = Seed::from_slice(&randombytes(32)).unwrap(); + let seed = Seed::from_slice(&randombytes(SEEDBYTES)).unwrap(); let text = randombytes(16); let (public_key, secret_key) = create_key_pair_for_signature(Some(&seed)).unwrap(); diff --git a/libindy/src/utils/crypto/mod.rs b/libindy/src/utils/crypto/mod.rs index 03192a15fc..d1a6c7cbd4 100644 --- a/libindy/src/utils/crypto/mod.rs +++ b/libindy/src/utils/crypto/mod.rs @@ -7,6 +7,7 @@ pub mod ed25519_sign; #[cfg(feature = "ed25519_box_sodium")] #[path = "ed25519_box/sodium.rs"] +// TODO: The name is misleading as the operations do not happen over ed25519 curve pub mod ed25519_box; #[cfg(feature = "base58_rust_base58")] diff --git a/libindy/src/utils/crypto/pwhash_argon2i13/sodium.rs b/libindy/src/utils/crypto/pwhash_argon2i13/sodium.rs index 99036e9a36..815b4762a3 100644 --- a/libindy/src/utils/crypto/pwhash_argon2i13/sodium.rs +++ b/libindy/src/utils/crypto/pwhash_argon2i13/sodium.rs @@ -21,8 +21,9 @@ pub fn gen_salt() -> Salt { pub fn pwhash<'a>(key: &'a mut [u8], passwd: &[u8], salt: &Salt, key_derivation_method: &KeyDerivationMethod) -> Result<&'a [u8], CommonError> { let (opslimit, memlimit) = unsafe { match key_derivation_method { - KeyDerivationMethod::ARAGON2I_MOD => (crypto_pwhash_opslimit_moderate(), crypto_pwhash_memlimit_moderate()), - KeyDerivationMethod::ARAGON2I_INT => (crypto_pwhash_opslimit_interactive(), crypto_pwhash_memlimit_interactive()) + KeyDerivationMethod::ARGON2I_MOD => (crypto_pwhash_opslimit_moderate(), crypto_pwhash_memlimit_moderate()), + KeyDerivationMethod::ARGON2I_INT => (crypto_pwhash_opslimit_interactive(), crypto_pwhash_memlimit_interactive()), + KeyDerivationMethod::RAW => return Err(CommonError::InvalidStructure("RAW key derivation method is not acceptable".to_string())) } }; @@ -91,7 +92,7 @@ mod tests { let mut key = [0u8; 64]; let salt = gen_salt(); - let _key = pwhash(&mut key, passwd, &salt, &KeyDerivationMethod::ARAGON2I_MOD).unwrap(); + let _key = pwhash(&mut key, passwd, &salt, &KeyDerivationMethod::ARGON2I_MOD).unwrap(); } #[test] @@ -101,10 +102,10 @@ mod tests { let salt = gen_salt(); let mut key = [0u8; 64]; - let key_moderate = pwhash(&mut key, passwd, &salt, &KeyDerivationMethod::ARAGON2I_MOD).unwrap(); + let key_moderate = pwhash(&mut key, passwd, &salt, &KeyDerivationMethod::ARGON2I_MOD).unwrap(); let mut key = [0u8; 64]; - let key_interactive = pwhash(&mut key, passwd, &salt, &KeyDerivationMethod::ARAGON2I_INT).unwrap(); + let key_interactive = pwhash(&mut key, passwd, &salt, &KeyDerivationMethod::ARGON2I_INT).unwrap(); assert_ne!(key_moderate, key_interactive); } diff --git a/libindy/src/utils/crypto/randombytes/sodium.rs b/libindy/src/utils/crypto/randombytes/sodium.rs index c769cfd8ea..0a83d20d93 100644 --- a/libindy/src/utils/crypto/randombytes/sodium.rs +++ b/libindy/src/utils/crypto/randombytes/sodium.rs @@ -1,5 +1,64 @@ extern crate sodiumoxide; +extern crate libc; + +use self::libc::size_t; +use errors::common::CommonError; + +use utils::crypto::memzero::memzero; + +pub const SEEDBYTES: usize = 32; // randombytes_seedbytes + +pub struct Seed([u8; SEEDBYTES]); + +impl Seed { + pub fn from_slice(bytes: &[u8]) -> Result { + if bytes.len() != SEEDBYTES { + return Err(CommonError::InvalidStructure(format!("Invalid Seed bytes"))); + } + let mut seed = Seed([0; SEEDBYTES]); + for (ni, &bsi) in seed.0.iter_mut().zip(bytes.iter()) { + *ni = bsi + } + Ok(seed) + } +} + +impl Drop for Seed { + fn drop(&mut self) { + memzero(self.0.as_mut()); + } +} pub fn randombytes(size: usize) -> Vec { self::sodiumoxide::randombytes::randombytes(size) +} + +pub fn randombytes_deterministic(size: usize, seed: &Seed) -> Vec { + let mut out = vec![0u8; size]; + unsafe { + randombytes_buf_deterministic(out.as_mut_ptr(), + size, + &seed.0) + }; + out +} + + +extern { + fn randombytes_buf_deterministic(out: *mut u8, + size: size_t, + seed: *const [u8; SEEDBYTES]); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn randombytes_deterministic_works() { + let seed = Seed::from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5]).unwrap(); + let res = randombytes_deterministic(32, &seed); + let expected_bytes = vec![7, 183, 0, 143, 100, 203, 87, 27, 32, 132, 126, 172, 180, 123, 39, 26, 18, 243, 64, 60, 92, 43, 111, 227, 54, 129, 201, 185, 53, 73, 93, 93]; + assert_eq!(expected_bytes, res); + } } \ No newline at end of file diff --git a/libindy/src/utils/test.rs b/libindy/src/utils/test.rs index fd42ea6875..1afbf03e9a 100644 --- a/libindy/src/utils/test.rs +++ b/libindy/src/utils/test.rs @@ -23,6 +23,15 @@ impl TestUtils { TestUtils::cleanup_indy_home(); TestUtils::cleanup_temp(); } + + pub fn gen_txns() -> Vec { + let test_pool_ip = EnvironmentUtils::test_pool_ip(); + + vec![format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","blskey_pop":"RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1","client_ip":"{}","client_port":9702,"node_ip":"{}","node_port":9701,"services":["VALIDATOR"]}},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}},"metadata":{{"from":"Th7MpTaRZVRYnPiabds81Y"}},"type":"0"}},"txnMetadata":{{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), + format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","blskey_pop":"Qr658mWZ2YC8JXGXwMDQTzuZCWF7NK9EwxphGmcBvCh6ybUuLxbG65nsX4JvD4SPNtkJ2w9ug1yLTj6fgmuDg41TgECXjLCij3RMsV8CwewBVgVN67wsA45DFWvqvLtu4rjNnE9JbdFTc1Z4WCPA3Xan44K1HoHAq9EVeaRYs8zoF5","client_ip":"{}","client_port":9704,"node_ip":"{}","node_port":9703,"services":["VALIDATOR"]}},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}},"metadata":{{"from":"EbP4aYNeTHL6q385GuVpRV"}},"type":"0"}},"txnMetadata":{{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), + format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","blskey_pop":"QwDeb2CkNSx6r8QC8vGQK3GRv7Yndn84TGNijX8YXHPiagXajyfTjoR87rXUu4G4QLk2cF8NNyqWiYMus1623dELWwx57rLCFqGh7N4ZRbGDRP4fnVcaKg1BcUxQ866Ven4gw8y4N56S5HzxXNBZtLYmhGHvDtk6PFkFwCvxYrNYjh","client_ip":"{}","client_port":9706,"node_ip":"{}","node_port":9705,"services":["VALIDATOR"]}},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"}},"metadata":{{"from":"4cU41vWW82ArfxJxHkzXPG"}},"type":"0"}},"txnMetadata":{{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), + format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","blskey_pop":"RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP","client_ip":"{}","client_port":9708,"node_ip":"{}","node_port":9707,"services":["VALIDATOR"]}},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"}},"metadata":{{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"}},"type":"0"}},"txnMetadata":{{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip)] + } } #[cfg(test)] diff --git a/libindy/tests/did.rs b/libindy/tests/did.rs index 495f24e2ba..e4b31c915e 100644 --- a/libindy/tests/did.rs +++ b/libindy/tests/did.rs @@ -455,6 +455,22 @@ mod high_cases { TestUtils::cleanup_storage(); } + #[test] + fn indy_set_did_metadata_works_for_their_did() { + TestUtils::cleanup_storage(); + + let wallet_handle = WalletUtils::create_and_open_default_wallet().unwrap(); + + let identity_json = json!({"did": DID, "verkey": VERKEY}).to_string(); + DidUtils::store_their_did(wallet_handle, &identity_json).unwrap(); + + DidUtils::set_did_metadata(wallet_handle, DID, METADATA).unwrap(); + + WalletUtils::close_wallet(wallet_handle).unwrap(); + + TestUtils::cleanup_storage(); + } + #[test] fn indy_set_did_metadata_works_for_replace() { TestUtils::cleanup_storage(); @@ -512,8 +528,7 @@ mod high_cases { let wallet_handle = WalletUtils::create_and_open_default_wallet().unwrap(); - let res = DidUtils::set_did_metadata(wallet_handle, &DID, METADATA); - assert_eq!(ErrorCode::WalletItemNotFound, res.unwrap_err()); + DidUtils::set_did_metadata(wallet_handle, &DID, METADATA).unwrap(); WalletUtils::close_wallet(wallet_handle).unwrap(); @@ -559,6 +574,25 @@ mod high_cases { TestUtils::cleanup_storage(); } + #[test] + fn indy_get_did_metadata_works_for_their_did() { + TestUtils::cleanup_storage(); + + let wallet_handle = WalletUtils::create_and_open_default_wallet().unwrap(); + + let identity_json = json!({"did": DID, "verkey": VERKEY}).to_string(); + DidUtils::store_their_did(wallet_handle, &identity_json).unwrap(); + + DidUtils::set_did_metadata(wallet_handle, DID, METADATA).unwrap(); + + let metadata = DidUtils::get_did_metadata(wallet_handle, DID).unwrap(); + assert_eq!(METADATA.to_string(), metadata); + + WalletUtils::close_wallet(wallet_handle).unwrap(); + + TestUtils::cleanup_storage(); + } + #[test] fn indy_get_did_metadata_works_for_empty_string() { TestUtils::cleanup_storage(); diff --git a/libindy/tests/ledger.rs b/libindy/tests/ledger.rs index 05cdce29cb..6949ddc94c 100644 --- a/libindy/tests/ledger.rs +++ b/libindy/tests/ledger.rs @@ -878,7 +878,7 @@ mod high_cases { #[test] fn indy_build_node_request_works_for_correct_data_json() { - let expected_result = format!(r#""identifier":"{}","operation":{{"type":"0","dest":"{}","data":{{"node_ip":"10.0.0.100","node_port":1,"client_ip":"10.0.0.100","client_port":2,"alias":"some","services":["VALIDATOR"],"blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba"}}}}"#, + let expected_result = format!(r#""identifier":"{}","operation":{{"type":"0","dest":"{}","data":{{"node_ip":"10.0.0.100","node_port":2,"client_ip":"10.0.0.100","client_port":1,"alias":"Node5","services":["VALIDATOR"],"blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","blskey_pop":"RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1"}}}}"#, IDENTIFIER, DEST); let node_request = LedgerUtils::build_node_request(IDENTIFIER, DEST, NODE_DATA).unwrap(); @@ -915,12 +915,7 @@ mod high_cases { let pool_handle = PoolUtils::create_and_open_pool_ledger(POOL).unwrap(); let wallet_handle = WalletUtils::create_and_open_default_wallet().unwrap(); - let (trustee_did, _) = DidUtils::create_and_store_my_did(wallet_handle, Some(TRUSTEE_SEED)).unwrap(); - let (my_did, my_verkey) = DidUtils::create_and_store_my_did(wallet_handle, None).unwrap(); - - let role = "STEWARD"; - let nym_request = LedgerUtils::build_nym_request(&trustee_did, &my_did, Some(&my_verkey), None, Some(role)).unwrap(); - LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym_request).unwrap(); + let (my_did, _) = DidUtils::create_store_and_publish_my_did_from_steward(wallet_handle, pool_handle).unwrap(); let dest = "A5iWQVT3k8Zo9nXj4otmeqaUziPQPCiDqcydXkAJBk1Y"; // random(32) and base58 @@ -2162,7 +2157,7 @@ mod medium_cases { #[test] fn indy_build_node_request_works_for_wrong_service() { - let data = r#"{"node_ip":"10.0.0.100", "node_port": 1, "client_ip": "10.0.0.100", "client_port": 1, "alias":"some", "services": ["SERVICE"], "blskey": "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"}"#; + let data = r#"{"node_ip":"10.0.0.100", "node_port": 1, "client_ip": "10.0.0.100", "client_port": 1, "alias":"some", "services": ["SERVICE"], "blskey": "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", "blskey_pop": "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"}"#; let res = LedgerUtils::build_node_request(IDENTIFIER, DEST, data); assert_eq!(res.unwrap_err(), ErrorCode::CommonInvalidStructure); } @@ -2208,6 +2203,48 @@ mod medium_cases { TestUtils::cleanup_storage(); } + + #[test] + #[cfg(feature = "local_nodes_pool")] + fn indy_submit_node_request_works_for_new_node_without_bls_pop() { + TestUtils::cleanup_storage(); + + let pool_handle = PoolUtils::create_and_open_pool_ledger(POOL).unwrap(); + let wallet_handle = WalletUtils::create_and_open_default_wallet().unwrap(); + + let (my_did, _) = DidUtils::create_store_and_publish_my_did_from_steward(wallet_handle, pool_handle).unwrap(); + + let node_data = r#"{"node_ip":"10.0.0.100", "node_port": 1, "client_ip": "10.0.0.100", "client_port": 2, "alias":"some", "services": ["VALIDATOR"], "blskey": "4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba"}"#; + let node_request = LedgerUtils::build_node_request(&my_did, DEST, node_data).unwrap(); + let response = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &node_request).unwrap(); + PoolUtils::check_response_type(&response, ResponseType::REQNACK); + + PoolUtils::close(pool_handle).unwrap(); + WalletUtils::close_wallet(wallet_handle).unwrap(); + + TestUtils::cleanup_storage(); + } + + #[test] + #[cfg(feature = "local_nodes_pool")] + fn indy_submit_node_request_works_for_pop_not_correspond_blskey() { + TestUtils::cleanup_storage(); + + let pool_handle = PoolUtils::create_and_open_pool_ledger(POOL).unwrap(); + let wallet_handle = WalletUtils::create_and_open_default_wallet().unwrap(); + + let (my_did, _) = DidUtils::create_store_and_publish_my_did_from_steward(wallet_handle, pool_handle).unwrap(); + + let node_data = r#"{"node_ip":"10.0.0.100", "node_port": 1, "client_ip": "10.0.0.100", "client_port": 2, "alias":"some", "services": ["VALIDATOR"], "blskey": "4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba", "blskey_pop": "RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP"}"#; + let node_request = LedgerUtils::build_node_request(&my_did, DEST, node_data).unwrap(); + let response = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &node_request).unwrap(); + PoolUtils::check_response_type(&response, ResponseType::REQNACK); + + PoolUtils::close(pool_handle).unwrap(); + WalletUtils::close_wallet(wallet_handle).unwrap(); + + TestUtils::cleanup_storage(); + } } mod cred_def_requests { diff --git a/libindy/tests/utils/constants.rs b/libindy/tests/utils/constants.rs index fad17123b5..9fc8080a58 100644 --- a/libindy/tests/utils/constants.rs +++ b/libindy/tests/utils/constants.rs @@ -40,10 +40,10 @@ pub const GET_SCHEMA_DATA: &'static str = r#"{"name":"name","version":"1.0"}"#; pub const ATTRIB_RAW_DATA: &'static str = r#"{"endpoint":{"ha":"127.0.0.1:5555"}}"#; pub const ATTRIB_HASH_DATA: &'static str = r#"83d907821df1c87db829e96569a11f6fc2e7880acba5e43d07ab786959e13bd3"#; pub const ATTRIB_ENC_DATA: &'static str = r#"aa3f41f619aa7e5e6b6d0de555e05331787f9bf9aa672b94b57ab65b9b66c3ea960b18a98e3834b1fc6cebf49f463b81fd6e3181"#; -pub const NODE_DATA: &'static str = r#"{"node_ip":"10.0.0.100", "node_port": 1, "client_ip": "10.0.0.100", "client_port": 2, "alias":"some", "services": ["VALIDATOR"], "blskey": "4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba"}"#; +pub const NODE_DATA: &'static str = r#"{"alias":"Node5","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","blskey_pop":"RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1","client_ip":"10.0.0.100","client_port":1,"node_ip":"10.0.0.100","node_port":2,"services":["VALIDATOR"]}"#; pub const TAG_1: &'static str = "TAG_1"; pub const REVOC_REG_TYPE: &'static str = "CL_ACCUM"; -pub const WALLET_CREDENTIALS: &'static str = r#"{"key":"key", "key_derivation_method":"ARAGON2I_INT"}"#; +pub const WALLET_CREDENTIALS: &'static str = r#"{"key":"key", "key_derivation_method":"ARGON2I_INT"}"#; pub const WALLET_CONFIG: &'static str = r#"{"id":"wallet_1"}"#; pub const DEFAULT_WALLET_CONFIG: &'static str = r#"{"id":"wallet_1","storage_type":"default"}"#; pub const INMEM_WALLET_CONFIG: &'static str = r#"{"id":"wallet_1","storage_type":"inmem"}"#; diff --git a/libindy/tests/utils/did.rs b/libindy/tests/utils/did.rs index 2047874ad5..3484707e38 100644 --- a/libindy/tests/utils/did.rs +++ b/libindy/tests/utils/did.rs @@ -22,6 +22,15 @@ impl DidUtils { Ok((my_did, my_vk)) } + pub fn create_store_and_publish_my_did_from_steward(wallet_handle: i32, pool_handle: i32) -> Result<(String, String), ErrorCode> { + let (trustee_did, _) = DidUtils::create_and_store_my_did(wallet_handle, Some(::utils::constants::TRUSTEE_SEED))?; + let (my_did, my_vk) = DidUtils::create_and_store_my_did(wallet_handle, None)?; + let nym = LedgerUtils::build_nym_request(&trustee_did, &my_did, Some(&my_vk), None, Some("STEWARD"))?; + let response = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &trustee_did, &nym)?; + PoolUtils::check_response_type(&response, ResponseType::REPLY); + Ok((my_did, my_vk)) + } + pub fn create_and_store_my_did(wallet_handle: i32, seed: Option<&str>) -> Result<(String, String), ErrorCode> { let (receiver, command_handle, cb) = CallbackUtils::_closure_to_cb_ec_string_string(); diff --git a/libindy/tests/utils/pool.rs b/libindy/tests/utils/pool.rs index d744491ae3..b8912b976a 100644 --- a/libindy/tests/utils/pool.rs +++ b/libindy/tests/utils/pool.rs @@ -15,6 +15,7 @@ use utils::types::{Response, ResponseType}; use utils::constants::PROTOCOL_VERSION; use utils::callback::CallbackUtils; use utils::environment::EnvironmentUtils; +use utils::test::TestUtils; #[derive(Serialize, Deserialize)] struct PoolConfig { @@ -50,13 +51,7 @@ impl PoolUtils { txn_file_path: Option<&Path>) -> PathBuf { let nodes_count = nodes_count.unwrap_or(4); - let test_pool_ip = EnvironmentUtils::test_pool_ip(); - - let node_txns = vec![ - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","client_ip":"{}","client_port":9702,"node_ip":"{}","node_port":9701,"services":["VALIDATOR"]}},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}},"metadata":{{"from":"Th7MpTaRZVRYnPiabds81Y"}},"type":"0"}},"txnMetadata":{{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","client_ip":"{}","client_port":9704,"node_ip":"{}","node_port":9703,"services":["VALIDATOR"]}},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}},"metadata":{{"from":"EbP4aYNeTHL6q385GuVpRV"}},"type":"0"}},"txnMetadata":{{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","client_ip":"{}","client_port":9706,"node_ip":"{}","node_port":9705,"services":["VALIDATOR"]}},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"}},"metadata":{{"from":"4cU41vWW82ArfxJxHkzXPG"}},"type":"0"}},"txnMetadata":{{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","client_ip":"{}","client_port":9708,"node_ip":"{}","node_port":9707,"services":["VALIDATOR"]}},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"}},"metadata":{{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"}},"type":"0"}},"txnMetadata":{{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip)]; + let node_txns = TestUtils::gen_txns(); let txn_file_data = node_txns[0..(nodes_count as usize)].join("\n"); @@ -66,12 +61,11 @@ impl PoolUtils { pub fn create_genesis_txn_file_for_test_pool_with_invalid_nodes(pool_name: &str, txn_file_path: Option<&Path>) -> PathBuf { let test_pool_ip = EnvironmentUtils::test_pool_ip(); + let node_txns = TestUtils::gen_txns(); - let node_txns = vec![ - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"client_ip":"{}","client_port":9702,"node_ip":"{}","node_port":9701,"services":["VALIDATOR"]}},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}},"metadata":{{"from":"Th7MpTaRZVRYnPiabds81Y"}},"type":"0"}},"txnMetadata":{{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"client_ip":"{}","client_port":9704,"node_ip":"{}","node_port":9703,"services":["VALIDATOR"]}},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}},"metadata":{{"from":"EbP4aYNeTHL6q385GuVpRV"}},"type":"0"}},"txnMetadata":{{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"client_ip":"{}","client_port":9706,"node_ip":"{}","node_port":9705,"services":["VALIDATOR"]}},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"}},"metadata":{{"from":"4cU41vWW82ArfxJxHkzXPG"}},"type":"0"}},"txnMetadata":{{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"client_ip":"{}","client_port":9708,"node_ip":"{}","node_port":9707,"services":["VALIDATOR"]}},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"}},"metadata":{{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"}},"type":"0"}},"txnMetadata":{{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip)]; + let node_txns = node_txns.iter().map(|txn| + txn.replace(format!(r#""client_ip":"{0}","client_port":9702,"node_ip":"{0}","node_port":9701"#, test_pool_ip).as_str(), r#""node_port":9701"#)) + .collect::>(); let txn_file_data = node_txns.join("\n"); PoolUtils::create_genesis_txn_file(pool_name, txn_file_data.as_str(), txn_file_path) @@ -79,15 +73,11 @@ impl PoolUtils { pub fn create_genesis_txn_file_for_empty_lines(pool_name: &str, txn_file_path: Option<&Path>) -> PathBuf { - let test_pool_ip = EnvironmentUtils::test_pool_ip(); - - let node_txns = vec![ - format!(" \n"), - format!("\n"), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","client_ip":"{}","client_port":9702,"node_ip":"{}","node_port":9701,"services":["VALIDATOR"]}},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}},"metadata":{{"from":"Th7MpTaRZVRYnPiabds81Y"}},"type":"0"}},"txnMetadata":{{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(" \n"), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","client_ip":"{}","client_port":9704,"node_ip":"{}","node_port":9703,"services":["VALIDATOR"]}},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}},"metadata":{{"from":"EbP4aYNeTHL6q385GuVpRV"}},"type":"0"}},"txnMetadata":{{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(" \n")]; + let mut node_txns = TestUtils::gen_txns(); + node_txns.insert(0, " \n".to_string()); + node_txns.insert(2, "\n".to_string()); + node_txns.insert(5, " \n".to_string()); + node_txns.push(" \n".to_string()); let txn_file_data = node_txns.join("\n"); PoolUtils::create_genesis_txn_file(pool_name, txn_file_data.as_str(), txn_file_path) @@ -95,14 +85,8 @@ impl PoolUtils { pub fn create_genesis_txn_file_for_test_pool_with_wrong_alias(pool_name: &str, txn_file_path: Option<&Path>) -> PathBuf { - let test_pool_ip = EnvironmentUtils::test_pool_ip(); - - - let node_txns = vec![ - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","client_ip":"{}","client_port":9702,"node_ip":"{}","node_port":9701,"services":["VALIDATOR"]}},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}},"metadata":{{"from":"Th7MpTaRZVRYnPiabds81Y"}},"type":"0"}},"txnMetadata":{{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","client_ip":"{}","client_port":9704,"node_ip":"{}","node_port":9703,"services":["VALIDATOR"]}},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}},"metadata":{{"from":"EbP4aYNeTHL6q385GuVpRV"}},"type":"0"}},"txnMetadata":{{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","client_ip":"{}","client_port":9706,"node_ip":"{}","node_port":9705,"services":["VALIDATOR"]}},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"}},"metadata":{{"from":"4cU41vWW82ArfxJxHkzXPG"}},"type":"0"}},"txnMetadata":{{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"ALIAS_NODE","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","client_ip":"{}","client_port":9708,"node_ip":"{}","node_port":9707,"services":["VALIDATOR"]}},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"}},"metadata":{{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"}},"type":"0"}},"txnMetadata":{{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip)]; + let mut node_txns = TestUtils::gen_txns(); + node_txns[0] = node_txns[0].replace("Node1", "ALIAS_NODE"); let txn_file_data = node_txns.join("\n"); PoolUtils::create_genesis_txn_file(pool_name, txn_file_data.as_str(), txn_file_path) @@ -110,9 +94,9 @@ impl PoolUtils { pub fn create_genesis_txn_file_for_test_pool_with_wrong_ips(pool_name: &str, txn_file_path: Option<&Path>) -> PathBuf { - let node_txns = vec![ - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","client_ip":"aa","client_port":9702,"node_ip":"aa","node_port":9701,"services":["VALIDATOR"]}},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}},"metadata":{{"from":"Th7MpTaRZVRYnPiabds81Y"}},"type":"0"}},"txnMetadata":{{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}},"ver":"1"}}"#), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","client_ip":"aa","client_port":9704,"node_ip":"aa","node_port":9703,"services":["VALIDATOR"]}},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}},"metadata":{{"from":"EbP4aYNeTHL6q385GuVpRV"}},"type":"0"}},"txnMetadata":{{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}},"ver":"1"}}"#)]; + let node_txns = TestUtils::gen_txns(); + let node_txns = node_txns.iter().map(|txn| + txn.replace(EnvironmentUtils::test_pool_ip().as_str(), "aa")).collect::>(); let txn_file_data = node_txns.join("\n"); @@ -158,23 +142,14 @@ impl PoolUtils { } pub fn dump_correct_genesis_txns_to_cache(pool_name: &str) -> Result<(), ErrorCode> { - let test_pool_ip = EnvironmentUtils::test_pool_ip(); - PoolUtils::_dump_genesis_txns_to_cache(pool_name, &vec![ - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","client_ip":"{}","client_port":9702,"node_ip":"{}","node_port":9701,"services":["VALIDATOR"]}},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}},"metadata":{{"from":"Th7MpTaRZVRYnPiabds81Y"}},"type":"0"}},"txnMetadata":{{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","client_ip":"{}","client_port":9704,"node_ip":"{}","node_port":9703,"services":["VALIDATOR"]}},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}},"metadata":{{"from":"EbP4aYNeTHL6q385GuVpRV"}},"type":"0"}},"txnMetadata":{{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","client_ip":"{}","client_port":9706,"node_ip":"{}","node_port":9705,"services":["VALIDATOR"]}},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"}},"metadata":{{"from":"4cU41vWW82ArfxJxHkzXPG"}},"type":"0"}},"txnMetadata":{{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","client_ip":"{}","client_port":9708,"node_ip":"{}","node_port":9707,"services":["VALIDATOR"]}},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"}},"metadata":{{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"}},"type":"0"}},"txnMetadata":{{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip)] - ) + PoolUtils::_dump_genesis_txns_to_cache(pool_name, &TestUtils::gen_txns()) } pub fn dump_incorrect_genesis_txns_to_cache(pool_name: &str) -> Result<(), ErrorCode> { - let test_pool_ip = EnvironmentUtils::test_pool_ip(); - PoolUtils::_dump_genesis_txns_to_cache(pool_name, &vec![ - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","client_ip":"{}","client_port":9702,"node_ip":"{}","node_port":9701,"services":["VALIDAT"]}},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}},"metadata":{{"from":"Th7MpTaRZVRYnPiabds81Y"}},"type":"0"}},"txnMetadata":{{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","client_ip":"{}","client_port":9704,"node_ip":"{}","node_port":9703,"services":["VALIDATOR"]}},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}},"metadata":{{"from":"EbP4aYNeTHL6q385GuVpRV"}},"type":"0"}},"txnMetadata":{{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","client_ip":"{}","client_port":9706,"node_ip":"{}","node_port":9705,"services":["VALIDATOR"]}},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"}},"metadata":{{"from":"4cU41vWW82ArfxJxHkzXPG"}},"type":"0"}},"txnMetadata":{{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","client_ip":"{}","client_port":9708,"node_ip":"{}","node_port":9707,"services":["VALIDATOR"]}},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"}},"metadata":{{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"}},"type":"0"}},"txnMetadata":{{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip)] - ) + let mut node_txns = TestUtils::gen_txns(); + node_txns[0] = node_txns[0].replace("Node1", "ALIAS_NODE"); + + PoolUtils::_dump_genesis_txns_to_cache(pool_name, &node_txns) } fn _dump_genesis_txns_to_cache(pool_name: &str, node_txns: &Vec) -> Result<(), ErrorCode> { diff --git a/libindy/tests/utils/wallet.rs b/libindy/tests/utils/wallet.rs index d761ef9aee..efe2a64708 100644 --- a/libindy/tests/utils/wallet.rs +++ b/libindy/tests/utils/wallet.rs @@ -9,6 +9,7 @@ use utils::environment::EnvironmentUtils; use std::collections::HashSet; use std::ffi::CString; use std::sync::Mutex; +use std::ptr::null; use utils::constants::{TYPE, INMEM_TYPE, WALLET_CREDENTIALS}; use std::path::{Path, PathBuf}; @@ -186,4 +187,17 @@ impl WalletUtils { }); serde_json::to_string(&json).unwrap() } + + pub fn generate_wallet_key(config: Option<&str>) -> Result { + let (receiver, command_handle, cb) = CallbackUtils::_closure_to_cb_ec_string(); + + let config_str = config.map(|s| CString::new(s).unwrap()).unwrap_or(CString::new("").unwrap()); + + let err = + indy_generate_wallet_key(command_handle, + if config.is_some() { config_str.as_ptr() } else { null() }, + cb); + + super::results::result_to_string(err, receiver) + } } \ No newline at end of file diff --git a/libindy/tests/wallet.rs b/libindy/tests/wallet.rs index e1fbef1844..4ac37a6208 100644 --- a/libindy/tests/wallet.rs +++ b/libindy/tests/wallet.rs @@ -340,6 +340,45 @@ mod high_cases { TestUtils::cleanup_storage(); } } + + mod generate_wallet_key { + use super::*; + use rust_base58::FromBase58; + + #[test] + fn indy_generate_wallet_key_works() { + TestUtils::cleanup_storage(); + + let key = WalletUtils::generate_wallet_key(None).unwrap(); + + let credentials = json!({"key": key, "key_derivation_method": "RAW"}).to_string(); + WalletUtils::create_wallet(WALLET_CONFIG, &credentials).unwrap(); + + let wallet_handle = WalletUtils::open_wallet(WALLET_CONFIG, &credentials).unwrap(); + WalletUtils::close_wallet(wallet_handle).unwrap(); + WalletUtils::delete_wallet(WALLET_CONFIG, &credentials).unwrap(); + + TestUtils::cleanup_storage(); + } + + #[test] + fn indy_generate_wallet_key_works_for_seed() { + TestUtils::cleanup_storage(); + + let config = json!({"seed": MY1_SEED}).to_string(); + let key = WalletUtils::generate_wallet_key(Some(config.as_str())).unwrap(); + assert_eq!(key.from_base58().unwrap(), vec![177, 92, 220, 199, 104, 203, 161, 4, 218, 78, 105, 13, 7, 50, 66, 107, 154, 155, 108, 133, 1, 30, 87, 149, 233, 76, 39, 156, 178, 46, 230, 124]); + + let credentials = json!({"key": key, "key_derivation_method": "RAW"}).to_string(); + WalletUtils::create_wallet(WALLET_CONFIG, &credentials).unwrap(); + + let wallet_handle = WalletUtils::open_wallet(WALLET_CONFIG, &credentials).unwrap(); + WalletUtils::close_wallet(wallet_handle).unwrap(); + WalletUtils::delete_wallet(WALLET_CONFIG, &credentials).unwrap(); + + TestUtils::cleanup_storage(); + } + } } mod medium_cases { @@ -416,6 +455,17 @@ mod medium_cases { TestUtils::cleanup_storage(); } + + #[test] + fn indy_create_wallet_works_for_raw_key_invalid_length() { + TestUtils::cleanup_storage(); + + let credentials = json!({"key": "key", "key_derivation_method": "RAW"}).to_string(); + let res = WalletUtils::create_wallet(WALLET_CONFIG, &credentials); + assert_eq!(res.unwrap_err(), ErrorCode::CommonInvalidStructure); + + TestUtils::cleanup_storage(); + } } mod delete_wallet { diff --git a/libnullpay/Cargo.lock b/libnullpay/Cargo.lock index a0d34fec49..a83659bf53 100644 --- a/libnullpay/Cargo.lock +++ b/libnullpay/Cargo.lock @@ -121,7 +121,7 @@ dependencies = [ [[package]] name = "null-payment-method" -version = "1.6.2" +version = "1.6.3" dependencies = [ "android_logger 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/libnullpay/Cargo.toml b/libnullpay/Cargo.toml index 512291e3bf..2b79f079a6 100644 --- a/libnullpay/Cargo.toml +++ b/libnullpay/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "null-payment-method" -version = "1.6.2" +version = "1.6.3" authors = ["Nikita Khateev "] build = "build.rs" diff --git a/libnullpay/debian/changelog b/libnullpay/debian/changelog index d41c46819b..27859566d7 100644 --- a/libnullpay/debian/changelog +++ b/libnullpay/debian/changelog @@ -1,4 +1,4 @@ -libnullpay (1.6.2) unstable; urgency=medium +libnullpay (1.6.3) unstable; urgency=medium [ Hyperledger ] * Initial release diff --git a/libnullpay/tests/utils/pool.rs b/libnullpay/tests/utils/pool.rs index 2e175df4e8..b51452f83a 100644 --- a/libnullpay/tests/utils/pool.rs +++ b/libnullpay/tests/utils/pool.rs @@ -64,10 +64,10 @@ fn _create_genesis_txn_file_for_test_pool(pool_name: &str, let test_pool_ip = super::environment::test_pool_ip(); let node_txns = vec![ - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","client_ip":"{}","client_port":9702,"node_ip":"{}","node_port":9701,"services":["VALIDATOR"]}},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}},"metadata":{{"from":"Th7MpTaRZVRYnPiabds81Y"}},"type":"0"}},"txnMetadata":{{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","client_ip":"{}","client_port":9704,"node_ip":"{}","node_port":9703,"services":["VALIDATOR"]}},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}},"metadata":{{"from":"EbP4aYNeTHL6q385GuVpRV"}},"type":"0"}},"txnMetadata":{{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","client_ip":"{}","client_port":9706,"node_ip":"{}","node_port":9705,"services":["VALIDATOR"]}},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"}},"metadata":{{"from":"4cU41vWW82ArfxJxHkzXPG"}},"type":"0"}},"txnMetadata":{{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), - format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","client_ip":"{}","client_port":9708,"node_ip":"{}","node_port":9707,"services":["VALIDATOR"]}},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"}},"metadata":{{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"}},"type":"0"}},"txnMetadata":{{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip)]; + format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","blskey_pop":"RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1","client_ip":"{}","client_port":9702,"node_ip":"{}","node_port":9701,"services":["VALIDATOR"]}},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}},"metadata":{{"from":"Th7MpTaRZVRYnPiabds81Y"}},"type":"0"}},"txnMetadata":{{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), + format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","blskey_pop":"Qr658mWZ2YC8JXGXwMDQTzuZCWF7NK9EwxphGmcBvCh6ybUuLxbG65nsX4JvD4SPNtkJ2w9ug1yLTj6fgmuDg41TgECXjLCij3RMsV8CwewBVgVN67wsA45DFWvqvLtu4rjNnE9JbdFTc1Z4WCPA3Xan44K1HoHAq9EVeaRYs8zoF5","client_ip":"{}","client_port":9704,"node_ip":"{}","node_port":9703,"services":["VALIDATOR"]}},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}},"metadata":{{"from":"EbP4aYNeTHL6q385GuVpRV"}},"type":"0"}},"txnMetadata":{{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), + format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","blskey_pop":"QwDeb2CkNSx6r8QC8vGQK3GRv7Yndn84TGNijX8YXHPiagXajyfTjoR87rXUu4G4QLk2cF8NNyqWiYMus1623dELWwx57rLCFqGh7N4ZRbGDRP4fnVcaKg1BcUxQ866Ven4gw8y4N56S5HzxXNBZtLYmhGHvDtk6PFkFwCvxYrNYjh","client_ip":"{}","client_port":9706,"node_ip":"{}","node_port":9705,"services":["VALIDATOR"]}},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"}},"metadata":{{"from":"4cU41vWW82ArfxJxHkzXPG"}},"type":"0"}},"txnMetadata":{{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip), + format!(r#"{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","blskey_pop":"RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP","client_ip":"{}","client_port":9708,"node_ip":"{}","node_port":9707,"services":["VALIDATOR"]}},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"}},"metadata":{{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"}},"type":"0"}},"txnMetadata":{{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"}},"ver":"1"}}"#, test_pool_ip, test_pool_ip)]; let txn_file_data = node_txns[0..(nodes_count as usize)].join("\n"); diff --git a/samples/java/pom.xml b/samples/java/pom.xml index e18341ec93..ef206b0de3 100644 --- a/samples/java/pom.xml +++ b/samples/java/pom.xml @@ -109,7 +109,7 @@ org.hyperledger indy - 1.5.0-dev-625 + 1.6.2-dev-720 diff --git a/samples/java/src/main/java/utils/PoolUtils.java b/samples/java/src/main/java/utils/PoolUtils.java index 4b0c77d281..b9536f5c0c 100644 --- a/samples/java/src/main/java/utils/PoolUtils.java +++ b/samples/java/src/main/java/utils/PoolUtils.java @@ -20,10 +20,10 @@ private static File createGenesisTxnFile(String filename) throws IOException { String testPoolIp = EnvironmentUtils.getTestPoolIP(); String[] defaultTxns = new String[]{ - String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node1\",\"blskey\":\"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba\",\"client_ip\":\"%s\",\"client_port\":9702,\"node_ip\":\"%s\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\"},\"metadata\":{\"from\":\"Th7MpTaRZVRYnPiabds81Y\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":1,\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\"},\"ver\":\"1\"}", testPoolIp, testPoolIp), - String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node2\",\"blskey\":\"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk\",\"client_ip\":\"%s\",\"client_port\":9704,\"node_ip\":\"%s\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\"},\"metadata\":{\"from\":\"EbP4aYNeTHL6q385GuVpRV\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":2,\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\"},\"ver\":\"1\"}\n", testPoolIp, testPoolIp), - String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node3\",\"blskey\":\"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5\",\"client_ip\":\"%s\",\"client_port\":9706,\"node_ip\":\"%s\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\"},\"metadata\":{\"from\":\"4cU41vWW82ArfxJxHkzXPG\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":3,\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\"},\"ver\":\"1\"}\n", testPoolIp, testPoolIp), - String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node4\",\"blskey\":\"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw\",\"client_ip\":\"%s\",\"client_port\":9708,\"node_ip\":\"%s\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\"},\"metadata\":{\"from\":\"TWwCRQRZ2ZHMJFn9TzLp7W\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":4,\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\"},\"ver\":\"1\"}", testPoolIp, testPoolIp) + String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node1\",\"blskey\":\"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba\",\"blskey_pop\":\"RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1\",\"client_ip\":\"%s\",\"client_port\":9702,\"node_ip\":\"%s\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\"},\"metadata\":{\"from\":\"Th7MpTaRZVRYnPiabds81Y\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":1,\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\"},\"ver\":\"1\"}", testPoolIp, testPoolIp), + String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node2\",\"blskey\":\"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk\",\"blskey_pop\":\"Qr658mWZ2YC8JXGXwMDQTzuZCWF7NK9EwxphGmcBvCh6ybUuLxbG65nsX4JvD4SPNtkJ2w9ug1yLTj6fgmuDg41TgECXjLCij3RMsV8CwewBVgVN67wsA45DFWvqvLtu4rjNnE9JbdFTc1Z4WCPA3Xan44K1HoHAq9EVeaRYs8zoF5\",\"client_ip\":\"%s\",\"client_port\":9704,\"node_ip\":\"%s\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\"},\"metadata\":{\"from\":\"EbP4aYNeTHL6q385GuVpRV\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":2,\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\"},\"ver\":\"1\"}\n", testPoolIp, testPoolIp), + String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node3\",\"blskey\":\"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5\",\"blskey_pop\":\"QwDeb2CkNSx6r8QC8vGQK3GRv7Yndn84TGNijX8YXHPiagXajyfTjoR87rXUu4G4QLk2cF8NNyqWiYMus1623dELWwx57rLCFqGh7N4ZRbGDRP4fnVcaKg1BcUxQ866Ven4gw8y4N56S5HzxXNBZtLYmhGHvDtk6PFkFwCvxYrNYjh\",\"client_ip\":\"%s\",\"client_port\":9706,\"node_ip\":\"%s\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\"},\"metadata\":{\"from\":\"4cU41vWW82ArfxJxHkzXPG\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":3,\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\"},\"ver\":\"1\"}\n", testPoolIp, testPoolIp), + String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node4\",\"blskey\":\"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw\",\"blskey_pop\":\"RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP\",\"client_ip\":\"%s\",\"client_port\":9708,\"node_ip\":\"%s\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\"},\"metadata\":{\"from\":\"TWwCRQRZ2ZHMJFn9TzLp7W\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":4,\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\"},\"ver\":\"1\"}", testPoolIp, testPoolIp) }; File file = new File(path); diff --git a/samples/nodejs/util.js b/samples/nodejs/util.js index 660695bc37..dcc668e9d3 100644 --- a/samples/nodejs/util.js +++ b/samples/nodejs/util.js @@ -15,6 +15,10 @@ async function poolGenesisTxnData() { {"reqSignature": {}, "txn": {"data": {"data": {"alias": "Node2", "blskey": "37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk", "client_ip": "${poolIp}", "client_port": 9704, "node_ip": "${poolIp}", "node_port": 9703, "services": ["VALIDATOR"]}, "dest": "8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}, "metadata": {"from": "EbP4aYNeTHL6q385GuVpRV"}, "type": "0"}, "txnMetadata": {"seqNo": 2, "txnId": "1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}, "ver": "1"} {"reqSignature": {}, "txn": {"data": {"data": {"alias": "Node3", "blskey": "3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5", "client_ip": "${poolIp}", "client_port": 9706, "node_ip": "${poolIp}", "node_port": 9705, "services": ["VALIDATOR"]}, "dest": "DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"}, "metadata": {"from": "4cU41vWW82ArfxJxHkzXPG"}, "type": "0"}, "txnMetadata": {"seqNo": 3, "txnId": "7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"}, "ver": "1"} {"reqSignature": {}, "txn": {"data": {"data": {"alias": "Node4", "blskey": "2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw", "client_ip": "${poolIp}", "client_port": 9708, "node_ip": "${poolIp}", "node_port": 9707, "services": ["VALIDATOR"]}, "dest": "4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"}, "metadata": {"from": "TWwCRQRZ2ZHMJFn9TzLp7W"}, "type": "0"}, "txnMetadata": {"seqNo": 4, "txnId": "aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"}, "ver": "1"}`; + return `{"reqSignature": {}, "txn": {"data": {"data": {"alias": "Node1", "blskey": "4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba", "blskey_pop": "RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1", "client_ip": "${poolIp}", "client_port": 9702, "node_ip": "${poolIp}", "node_port": 9701, "services": ["VALIDATOR"]}, "dest": "Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}, "metadata": {"from": "Th7MpTaRZVRYnPiabds81Y"}, "type": "0"}, "txnMetadata": {"seqNo": 1, "txnId": "fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}, "ver": "1"} + {"reqSignature": {}, "txn": {"data": {"data": {"alias": "Node2", "blskey": "37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk", "blskey_pop": "Qr658mWZ2YC8JXGXwMDQTzuZCWF7NK9EwxphGmcBvCh6ybUuLxbG65nsX4JvD4SPNtkJ2w9ug1yLTj6fgmuDg41TgECXjLCij3RMsV8CwewBVgVN67wsA45DFWvqvLtu4rjNnE9JbdFTc1Z4WCPA3Xan44K1HoHAq9EVeaRYs8zoF5", "client_ip": "${poolIp}", "client_port": 9704, "node_ip": "${poolIp}", "node_port": 9703, "services": ["VALIDATOR"]}, "dest": "8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}, "metadata": {"from": "EbP4aYNeTHL6q385GuVpRV"}, "type": "0"}, "txnMetadata": {"seqNo": 2, "txnId": "1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}, "ver": "1"} + {"reqSignature": {}, "txn": {"data": {"data": {"alias": "Node3", "blskey": "3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5", "blskey_pop": "QwDeb2CkNSx6r8QC8vGQK3GRv7Yndn84TGNijX8YXHPiagXajyfTjoR87rXUu4G4QLk2cF8NNyqWiYMus1623dELWwx57rLCFqGh7N4ZRbGDRP4fnVcaKg1BcUxQ866Ven4gw8y4N56S5HzxXNBZtLYmhGHvDtk6PFkFwCvxYrNYjh", "client_ip": "${poolIp}", "client_port": 9706, "node_ip": "${poolIp}", "node_port": 9705, "services": ["VALIDATOR"]}, "dest": "DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"}, "metadata": {"from": "4cU41vWW82ArfxJxHkzXPG"}, "type": "0"}, "txnMetadata": {"seqNo": 3, "txnId": "7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"}, "ver": "1"} + {"reqSignature": {}, "txn": {"data": {"data": {"alias": "Node4", "blskey": "2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw", "blskey_pop": "RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP", "client_ip": "${poolIp}", "client_port": 9708, "node_ip": "${poolIp}", "node_port": 9707, "services": ["VALIDATOR"]}, "dest": "4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"}, "metadata": {"from": "TWwCRQRZ2ZHMJFn9TzLp7W"}, "type": "0"}, "txnMetadata": {"seqNo": 4, "txnId": "aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"}, "ver": "1"}`; } async function savePoolGenesisTxnFile(filePath) { diff --git a/samples/python/setup.py b/samples/python/setup.py index 8e74ea8632..29a862b152 100644 --- a/samples/python/setup.py +++ b/samples/python/setup.py @@ -8,5 +8,5 @@ author='Artem Ivanov', author_email='artem.ivanov@dsr-company.com', description='This is the sample of usage python wrapper for Hyperledger Indy SDK.', - install_requires=['python3-indy==1.5.0-dev-634'] + install_requires=['python3-indy==1.6.2-dev-720'] ) diff --git a/samples/python/src/getting_started.py b/samples/python/src/getting_started.py index 3ede9884d7..a676acba12 100644 --- a/samples/python/src/getting_started.py +++ b/samples/python/src/getting_started.py @@ -141,6 +141,8 @@ async def run(): logger.info("\"Government\" -> Send \"Transcript\" Schema to Ledger") await send_schema(pool_handle, government_wallet, government_did, transcript_schema) + time.sleep(1) # sleep 1 second before getting schema + logger.info("==============================") logger.info("=== Faber Credential Definition Setup ==") logger.info("------------------------------") diff --git a/samples/python/src/utils.py b/samples/python/src/utils.py index 91e8cf58ff..f4d81a786f 100644 --- a/samples/python/src/utils.py +++ b/samples/python/src/utils.py @@ -21,13 +21,13 @@ def pool_genesis_txn_data(): pool_ip = environ.get("TEST_POOL_IP", "127.0.0.1") return "\n".join([ - '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","client_ip":"{}","client_port":9702,"node_ip":"{}","node_port":9701,"services":["VALIDATOR"]}},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}},"metadata":{{"from":"Th7MpTaRZVRYnPiabds81Y"}},"type":"0"}},"txnMetadata":{{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}},"ver":"1"}}'.format( + '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","blskey_pop":"RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1","client_ip":"{}","client_port":9702,"node_ip":"{}","node_port":9701,"services":["VALIDATOR"]}},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}},"metadata":{{"from":"Th7MpTaRZVRYnPiabds81Y"}},"type":"0"}},"txnMetadata":{{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}},"ver":"1"}}'.format( pool_ip, pool_ip), - '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","client_ip":"{}","client_port":9704,"node_ip":"{}","node_port":9703,"services":["VALIDATOR"]}},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}},"metadata":{{"from":"EbP4aYNeTHL6q385GuVpRV"}},"type":"0"}},"txnMetadata":{{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}},"ver":"1"}}'.format( + '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","blskey_pop":"Qr658mWZ2YC8JXGXwMDQTzuZCWF7NK9EwxphGmcBvCh6ybUuLxbG65nsX4JvD4SPNtkJ2w9ug1yLTj6fgmuDg41TgECXjLCij3RMsV8CwewBVgVN67wsA45DFWvqvLtu4rjNnE9JbdFTc1Z4WCPA3Xan44K1HoHAq9EVeaRYs8zoF5","client_ip":"{}","client_port":9704,"node_ip":"{}","node_port":9703,"services":["VALIDATOR"]}},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}},"metadata":{{"from":"EbP4aYNeTHL6q385GuVpRV"}},"type":"0"}},"txnMetadata":{{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}},"ver":"1"}}'.format( pool_ip, pool_ip), - '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","client_ip":"{}","client_port":9706,"node_ip":"{}","node_port":9705,"services":["VALIDATOR"]}},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"}},"metadata":{{"from":"4cU41vWW82ArfxJxHkzXPG"}},"type":"0"}},"txnMetadata":{{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"}},"ver":"1"}}'.format( + '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","blskey_pop":"QwDeb2CkNSx6r8QC8vGQK3GRv7Yndn84TGNijX8YXHPiagXajyfTjoR87rXUu4G4QLk2cF8NNyqWiYMus1623dELWwx57rLCFqGh7N4ZRbGDRP4fnVcaKg1BcUxQ866Ven4gw8y4N56S5HzxXNBZtLYmhGHvDtk6PFkFwCvxYrNYjh","client_ip":"{}","client_port":9706,"node_ip":"{}","node_port":9705,"services":["VALIDATOR"]}},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"}},"metadata":{{"from":"4cU41vWW82ArfxJxHkzXPG"}},"type":"0"}},"txnMetadata":{{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"}},"ver":"1"}}'.format( pool_ip, pool_ip), - '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","client_ip":"{}","client_port":9708,"node_ip":"{}","node_port":9707,"services":["VALIDATOR"]}},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"}},"metadata":{{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"}},"type":"0"}},"txnMetadata":{{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"}},"ver":"1"}}'.format( + '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","blskey_pop":"RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP","client_ip":"{}","client_port":9708,"node_ip":"{}","node_port":9707,"services":["VALIDATOR"]}},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"}},"metadata":{{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"}},"type":"0"}},"txnMetadata":{{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"}},"ver":"1"}}'.format( pool_ip, pool_ip) ]) diff --git a/wrappers/dotnet/indy-sdk-dotnet/AnonCredsApi/AnonCreds.cs b/wrappers/dotnet/indy-sdk-dotnet/AnonCredsApi/AnonCreds.cs index 929d999f8b..4922f7e19c 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/AnonCredsApi/AnonCreds.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/AnonCredsApi/AnonCreds.cs @@ -1,10 +1,11 @@ using Hyperledger.Indy.BlobStorageApi; -using Hyperledger.Indy.LedgerApi; using Hyperledger.Indy.Utils; using Hyperledger.Indy.WalletApi; -using System; using System.Threading.Tasks; using static Hyperledger.Indy.AnonCredsApi.NativeMethods; +#if __IOS__ +using ObjCRuntime; +#endif namespace Hyperledger.Indy.AnonCredsApi { @@ -12,11 +13,14 @@ namespace Hyperledger.Indy.AnonCredsApi /// Provides methods for managing anonymous credentials. /// public static class AnonCreds - { + { /// /// Gets the callback to use when the IssuerCreateAndStoreClaimDefAsync command completes. /// - private static IssuerCreateSchemaCompletedDelegate _issuerCreateSchemaCallback = (xcommand_handle, err, schema_id, schema_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(IssuerCreateSchemaCompletedDelegate))] +#endif + private static void IssuerCreateSchemaCallback(int xcommand_handle, int err, string schema_id, string schema_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -24,12 +28,15 @@ public static class AnonCreds return; taskCompletionSource.SetResult(new IssuerCreateSchemaResult(schema_id, schema_json)); - }; - + } + /// /// Gets the callback to use when the IssuerCreateAndStoreClaimDefAsync command completes. /// - private static IssuerCreateAndStoreCredentialDefCompletedDelegate _issuerCreateAndStoreClaimDefCallback = (xcommand_handle, err, claim_def_id, claim_def_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(IssuerCreateAndStoreCredentialDefCompletedDelegate))] +#endif + private static void IssuerCreateAndStoreClaimDefCallback(int xcommand_handle, int err, string claim_def_id, string claim_def_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -37,12 +44,15 @@ public static class AnonCreds return; taskCompletionSource.SetResult(new IssuerCreateAndStoreCredentialDefResult(claim_def_id, claim_def_json)); - }; - + } + /// /// Gets the callback to use when the IssuerCreateAndStoreClaimRevocRegAsync command completes. /// - private static IssuerCreateAndStoreRevocRegCompletedDelegate _issuerCreateAndStoreClaimRevocRegCallback = (xcommand_handle, err, revoc_reg_id, revoc_reg_def_json, revoc_reg_entry_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(IssuerCreateAndStoreRevocRegCompletedDelegate))] +#endif + private static void IssuerCreateAndStoreClaimRevocRegCallback(int xcommand_handle, int err, string revoc_reg_id, string revoc_reg_def_json, string revoc_reg_entry_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -50,12 +60,15 @@ public static class AnonCreds return; taskCompletionSource.SetResult(new IssuerCreateAndStoreRevocRegResult(revoc_reg_id, revoc_reg_def_json, revoc_reg_entry_json)); - }; - + } + /// /// Gets the callback to use when the IssuerCreateClaimAsync command completes. /// - private static IssuerCreateCredentialOfferCompletedDelegate _issuerCreateCredentialOfferCallback = (xcommand_handle, err, cred_offer_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(IssuerCreateCredentialOfferCompletedDelegate))] +#endif + private static void IssuerCreateCredentialOfferCallback(int xcommand_handle, int err, string cred_offer_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -63,12 +76,15 @@ public static class AnonCreds return; taskCompletionSource.SetResult(cred_offer_json); - }; - + } + /// /// Gets the callback to use when the IssuerCreateClaimAsync command completes. /// - private static IssuerCreateCredentialCompletedDelegate _issuerCreateCredentialCallback = (xcommand_handle, err, cred_json, cred_revoc_id, revoc_reg_delta_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(IssuerCreateCredentialCompletedDelegate))] +#endif + private static void IssuerCreateCredentialCallback(int xcommand_handle, int err, string cred_json, string cred_revoc_id, string revoc_reg_delta_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -78,13 +94,15 @@ public static class AnonCreds var callbackResult = new IssuerCreateCredentialResult(cred_json, cred_revoc_id, revoc_reg_delta_json); taskCompletionSource.SetResult(callbackResult); - }; - - + } + /// /// Gets the callback to use when the IssuerRevokeCredentialAsync command completes. /// - private static IssuerRevokeCredentialCompletedDelegate _issuerRevokeCredentialCallback = (xcommand_handle, err, revoc_reg_delta_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(IssuerRevokeCredentialCompletedDelegate))] +#endif + private static void IssuerRevokeCredentialCallback(int xcommand_handle, int err, string revoc_reg_delta_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -92,12 +110,15 @@ public static class AnonCreds return; taskCompletionSource.SetResult(revoc_reg_delta_json); - }; - + } + /// /// The issuer merge revocation registry deltas callback. /// - private static IssuerMergeRevocationRegistryDeltasCompletedDelegate _issuerMergeRevocationRegistryDeltasCallback = (xcommand_handle, err, merged_rev_reg_delta) => +#if __IOS__ + [MonoPInvokeCallback(typeof(IssuerMergeRevocationRegistryDeltasCompletedDelegate))] +#endif + private static void IssuerMergeRevocationRegistryDeltasCallback(int xcommand_handle, int err, string merged_rev_reg_delta) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -105,12 +126,15 @@ public static class AnonCreds return; taskCompletionSource.SetResult(merged_rev_reg_delta); - }; - + } + /// /// The prover create master secret callback. /// - private static ProverCreateMasterSecretCompletedDelegate _proverCreateMasterSecretCallback = (xcommand_handle, err, out_master_secret_id) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ProverCreateMasterSecretCompletedDelegate))] +#endif + private static void ProverCreateMasterSecretCallback(int xcommand_handle, int err, string out_master_secret_id) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -118,12 +142,15 @@ public static class AnonCreds return; taskCompletionSource.SetResult(out_master_secret_id); - }; - + } + /// /// Gets the callback to use when the roverCreateAndStoreClaimReqAsync command completes. /// - private static ProverCreateCredentialReqCompletedDelegate _proverCreateCredentialReqCallback = (xcommand_handle, err, cred_req_json, cred_req_metadata_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ProverCreateCredentialReqCompletedDelegate))] +#endif + private static void ProverCreateCredentialReqCallback(int xcommand_handle, int err, string cred_req_json, string cred_req_metadata_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -131,12 +158,15 @@ public static class AnonCreds return; taskCompletionSource.SetResult(new ProverCreateCredentialRequestResult(cred_req_json, cred_req_metadata_json)); - }; - + } + /// /// The prover store credential callback. /// - private static ProverStoreCredentialCompletedDelegate _proverStoreCredentialCallback = (xcommand_handle, err, out_cred_id) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ProverStoreCredentialCompletedDelegate))] +#endif + private static void ProverStoreCredentialCallback(int xcommand_handle, int err, string out_cred_id) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -144,12 +174,15 @@ public static class AnonCreds return; taskCompletionSource.SetResult(out_cred_id); - }; - + } + /// /// Gets the callback to use when the ProverGetClaimsAsync command completes. /// - private static ProverGetCredentialsCompletedDelegate _proverGetCredentialsCallback = (xcommand_handle, err, matched_credentials_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ProverGetCredentialsCompletedDelegate))] +#endif + private static void ProverGetCredentialsCallback(int xcommand_handle, int err, string matched_credentials_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -157,12 +190,15 @@ public static class AnonCreds return; taskCompletionSource.SetResult(matched_credentials_json); - }; - + } + /// /// Gets the callback to use when the ProverGetClaimsForProofAsync command completes. /// - private static ProverGetCredentialsForProofCompletedDelegate _proverGetClaimsForProofCallback = (xcommand_handle, err, claims_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ProverGetCredentialsForProofCompletedDelegate))] +#endif + private static void ProverGetClaimsForProofCallback(int xcommand_handle, int err, string claims_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -170,12 +206,15 @@ public static class AnonCreds return; taskCompletionSource.SetResult(claims_json); - }; - + } + /// /// Gets the callback to use when the ProverCreateProofAsync command completes. /// - private static ProverCreateProofCompletedDelegate _proverCreateProofCallback = (xcommand_handle, err, proof_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ProverCreateProofCompletedDelegate))] +#endif + private static void ProverCreateProofCallback(int xcommand_handle, int err, string proof_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -183,12 +222,15 @@ public static class AnonCreds return; taskCompletionSource.SetResult(proof_json); - }; - + } + /// /// Gets the callback to use when the VerifierVerifyProofAsync command completes. /// - private static VerifierVerifyProofCompletedDelegate _verifierVerifyProofCallback = (xcommand_handle, err, valid) => +#if __IOS__ + [MonoPInvokeCallback(typeof(VerifierVerifyProofCompletedDelegate))] +#endif + private static void VerifierVerifyProofCallback(int xcommand_handle, int err, bool valid) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -196,12 +238,15 @@ public static class AnonCreds return; taskCompletionSource.SetResult(valid); - }; - + } + /// /// The create revocation state callback. /// - private static CreateRevocationStateCompletedDelegate _createRevocationStateCallback = (xcommand_handle, err, rev_state_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(CreateRevocationStateCompletedDelegate))] +#endif + private static void CreateRevocationStateCallback(int xcommand_handle, int err, string rev_state_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -209,12 +254,15 @@ public static class AnonCreds return; taskCompletionSource.SetResult(rev_state_json); - }; - + } + /// /// The update revocation state callback. /// - private static UpdateRevocationStateCompletedDelegate _updateRevocationStateCallback = (xcommand_handle, err, updated_rev_state_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(UpdateRevocationStateCompletedDelegate))] +#endif + private static void UpdateRevocationStateCallback(int xcommand_handle, int err, string updated_rev_state_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -222,7 +270,7 @@ public static class AnonCreds return; taskCompletionSource.SetResult(updated_rev_state_json); - }; + } /// /// Create credential schema entity that describes credential attributes list and allows credentials @@ -260,7 +308,7 @@ public static Task IssuerCreateSchemaAsync(string issu name, version, attrs, - _issuerCreateSchemaCallback + IssuerCreateSchemaCallback ); CallbackHelper.CheckResult(commandResult); @@ -307,7 +355,7 @@ public static Task IssuerCreateAndStore tag, type, configJson, - _issuerCreateAndStoreClaimDefCallback + IssuerCreateAndStoreClaimDefCallback ); CallbackHelper.CheckResult(commandResult); @@ -373,7 +421,7 @@ public static Task IssuerCreateAndStoreRevoc credDefId, configJson, tailsWriter.Handle, - _issuerCreateAndStoreClaimRevocRegCallback + IssuerCreateAndStoreClaimRevocRegCallback ); CallbackHelper.CheckResult(commandResult); @@ -410,7 +458,7 @@ public static Task IssuerCreateCredentialOfferAsync(Wallet wallet, strin commandHandle, wallet.Handle, credDefId, - _issuerCreateCredentialOfferCallback + IssuerCreateCredentialOfferCallback ); CallbackHelper.CheckResult(commandResult); @@ -474,7 +522,7 @@ public static Task IssuerCreateCredentialAsync(Wal credValuesJson, revRegId, blobStorageReader?.Handle ?? -1, - _issuerCreateCredentialCallback + IssuerCreateCredentialCallback ); CallbackHelper.CheckResult(commandResult); @@ -512,7 +560,7 @@ public static Task IssuerRevokeCredentialAsync(Wallet wallet, BlobStorag blobStorageReader.Handle, revRegId, credRevocId, - _issuerRevokeCredentialCallback + IssuerRevokeCredentialCallback ); CallbackHelper.CheckResult(commandResult); @@ -539,7 +587,7 @@ public static Task IssuerMergeRevocationRegistryDeltasAsync(string revRe commandHandle, revRegDelta, otherRevRegDelta, - _issuerMergeRevocationRegistryDeltasCallback + IssuerMergeRevocationRegistryDeltasCallback ); CallbackHelper.CheckResult(commandResult); @@ -567,7 +615,7 @@ public static Task ProverCreateMasterSecretAsync(Wallet wallet, string m commandHandle, wallet.Handle, masterSecretId, - _proverCreateMasterSecretCallback + ProverCreateMasterSecretCallback ); CallbackHelper.CheckResult(commandResult); @@ -617,7 +665,7 @@ public static Task ProverCreateCredentialRe credOfferJson, credDefJson, masterSecretId, - _proverCreateCredentialReqCallback + ProverCreateCredentialReqCallback ); CallbackHelper.CheckResult(commandResult); @@ -654,7 +702,7 @@ public static Task ProverStoreCredentialAsync(Wallet wallet, string cred credJson, credDefJson, revRegDefJson, - _proverStoreCredentialCallback + ProverStoreCredentialCallback ); CallbackHelper.CheckResult(commandResult); @@ -698,7 +746,7 @@ public static Task ProverGetCredentialsAsync(Wallet wallet, string filte commandHandle, wallet.Handle, filterJson, - _proverGetCredentialsCallback + ProverGetCredentialsCallback ); CallbackHelper.CheckResult(commandResult); @@ -794,7 +842,7 @@ public static Task ProverGetCredentialsForProofReqAsync(Wallet wallet, s commandHandle, wallet.Handle, proofRequestJson, - _proverGetClaimsForProofCallback + ProverGetClaimsForProofCallback ); CallbackHelper.CheckResult(commandResult); @@ -960,7 +1008,7 @@ public static Task ProverCreateProofAsync(Wallet wallet, string proofReq schemas, credentialDefs, revStates, - _proverCreateProofCallback); + ProverCreateProofCallback); CallbackHelper.CheckResult(commandResult); @@ -1071,7 +1119,7 @@ public static Task VerifierVerifyProofAsync(string proofRequest, string pr credentialDefs, revocRegDefs, revocRegs, - _verifierVerifyProofCallback + VerifierVerifyProofCallback ); CallbackHelper.CheckResult(commandResult); @@ -1111,7 +1159,7 @@ public static Task CreateRevocationStateAsync(BlobStorageReader blobStor revRegDelta, timestamp, credRevId, - _createRevocationStateCallback + CreateRevocationStateCallback ); CallbackHelper.CheckResult(commandResult); @@ -1155,7 +1203,7 @@ public static Task UpdateRevocationStateAsync(BlobStorageReader blobStor revRegDelta, timestamp, credRevId, - _updateRevocationStateCallback + UpdateRevocationStateCallback ); CallbackHelper.CheckResult(commandResult); diff --git a/wrappers/dotnet/indy-sdk-dotnet/AnonCredsApi/IssuerCreateCredentialResult.cs b/wrappers/dotnet/indy-sdk-dotnet/AnonCredsApi/IssuerCreateCredentialResult.cs index 827db3d7fe..275fc4d291 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/AnonCredsApi/IssuerCreateCredentialResult.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/AnonCredsApi/IssuerCreateCredentialResult.cs @@ -1,6 +1,4 @@ -using System; - -namespace Hyperledger.Indy.AnonCredsApi +namespace Hyperledger.Indy.AnonCredsApi { /// /// Result from calling IssuerCreateCredentialAsync. diff --git a/wrappers/dotnet/indy-sdk-dotnet/AnonCredsApi/NativeMethods.cs b/wrappers/dotnet/indy-sdk-dotnet/AnonCredsApi/NativeMethods.cs index 6123cf99bb..988c6de00d 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/AnonCredsApi/NativeMethods.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/AnonCredsApi/NativeMethods.cs @@ -1,6 +1,5 @@ using System; using System.Runtime.InteropServices; -using static Hyperledger.Indy.Utils.CallbackHelper; namespace Hyperledger.Indy.AnonCredsApi { diff --git a/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/BlobStorage.cs b/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/BlobStorage.cs index c005734646..a6df7080ee 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/BlobStorage.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/BlobStorage.cs @@ -1,7 +1,9 @@ -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; using Hyperledger.Indy.Utils; using static Hyperledger.Indy.BlobStorageApi.NativeMethods; +#if __IOS__ +using ObjCRuntime; +#endif namespace Hyperledger.Indy.BlobStorageApi { @@ -10,7 +12,10 @@ namespace Hyperledger.Indy.BlobStorageApi /// public static class BlobStorage { - private static BlobStorageCompletedDelegate _openReaderCallback = (xcommand_handle, err, handle) => +#if __IOS__ + [MonoPInvokeCallback(typeof(BlobStorageCompletedDelegate))] +#endif + private static void OpenReaderCallback(int xcommand_handle, int err, int handle) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -18,9 +23,11 @@ public static class BlobStorage return; taskCompletionSource.SetResult(new BlobStorageReader(handle)); - }; - - private static BlobStorageCompletedDelegate _openWriterCallback = (xcommand_handle, err, handle) => + } +#if __IOS__ + [MonoPInvokeCallback(typeof(BlobStorageCompletedDelegate))] +#endif + private static void OpenWriterCallback(int xcommand_handle, int err, int handle) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -28,7 +35,7 @@ public static class BlobStorage return; taskCompletionSource.SetResult(new BlobStorageWriter(handle)); - }; + } /// /// Opens the BLOB storage reader async. @@ -48,7 +55,7 @@ public static Task OpenReaderAsync(string type, string config commandHandle, type, configJson, - _openReaderCallback + OpenReaderCallback ); CallbackHelper.CheckResult(result); @@ -74,7 +81,7 @@ public static Task OpenWriterAsync(string type, string config commandHandle, type, configJson, - _openWriterCallback + OpenWriterCallback ); CallbackHelper.CheckResult(result); diff --git a/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/BlobStorageReader.cs b/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/BlobStorageReader.cs index 26dff6acc3..8d97024ce2 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/BlobStorageReader.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/BlobStorageReader.cs @@ -1,5 +1,4 @@ -using System; -namespace Hyperledger.Indy.BlobStorageApi +namespace Hyperledger.Indy.BlobStorageApi { /// /// BLOB storage reader. diff --git a/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/BlobStorageWriter.cs b/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/BlobStorageWriter.cs index bc43ec2716..1b723088ab 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/BlobStorageWriter.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/BlobStorageWriter.cs @@ -1,5 +1,4 @@ -using System; -namespace Hyperledger.Indy.BlobStorageApi +namespace Hyperledger.Indy.BlobStorageApi { /// /// BLOB storage writer. diff --git a/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/NativeMethods.cs b/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/NativeMethods.cs index 1ce0cdb720..be34f17875 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/NativeMethods.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/BlobStorageApi/NativeMethods.cs @@ -1,5 +1,4 @@ -using System; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; namespace Hyperledger.Indy.BlobStorageApi { diff --git a/wrappers/dotnet/indy-sdk-dotnet/Consts.cs b/wrappers/dotnet/indy-sdk-dotnet/Consts.cs index 219cdb9569..d11d4afbd2 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/Consts.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/Consts.cs @@ -1,13 +1,14 @@ -using System; -using System.Runtime.InteropServices; - -namespace Hyperledger.Indy +namespace Hyperledger.Indy { /// /// PInvoke import of C-Callable SDK library functions and associated delegates. /// internal static class Consts { +#if __IOS__ + public const string NATIVE_LIB_NAME = "__Internal"; +#else public const string NATIVE_LIB_NAME = "indy"; +#endif } } \ No newline at end of file diff --git a/wrappers/dotnet/indy-sdk-dotnet/CryptoApi/Crypto.cs b/wrappers/dotnet/indy-sdk-dotnet/CryptoApi/Crypto.cs index db183e2df5..e8d435a616 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/CryptoApi/Crypto.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/CryptoApi/Crypto.cs @@ -1,9 +1,13 @@ -using Hyperledger.Indy.DidApi; +using System; +using Hyperledger.Indy.DidApi; using Hyperledger.Indy.Utils; using Hyperledger.Indy.WalletApi; using System.Runtime.InteropServices; using System.Threading.Tasks; using static Hyperledger.Indy.CryptoApi.NativeMethods; +#if __IOS__ +using ObjCRuntime; +#endif namespace Hyperledger.Indy.CryptoApi { @@ -11,11 +15,14 @@ namespace Hyperledger.Indy.CryptoApi /// Provides methods for pure cryptographic functions. /// public static class Crypto - { + { /// /// Gets the callback to use when the indy_create_key command has completed. /// - private static CreateKeyCompletedDelegate _createKeyCompletedCallback = (xcommand_handle, err, verkey) => +#if __IOS__ + [MonoPInvokeCallback(typeof(CreateKeyCompletedDelegate))] +#endif + private static void CreateKeyCompletedCallback(int xcommand_handle, int err, string verkey) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -23,12 +30,15 @@ public static class Crypto return; taskCompletionSource.SetResult(verkey); - }; - + } + /// /// Gets the callback to use when the indy_get_key_metadata command has completed. /// - private static GetKeyMetadataCompletedDelegate _getKeyMetadataCompletedCallback = (xcommand_handle, err, metadata) => +#if __IOS__ + [MonoPInvokeCallback(typeof(GetKeyMetadataCompletedDelegate))] +#endif + private static void GetKeyMetadataCompletedCallback(int xcommand_handle, int err, string metadata) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -36,12 +46,15 @@ public static class Crypto return; taskCompletionSource.SetResult(metadata); - }; - + } + /// /// Gets the callback to use when the indy_crypto_sign command has completed. /// - private static SignCompletedDelegate _cryptoSignCompletedCallback = (xcommand_handle, err, signature_raw, signature_len) => +#if __IOS__ + [MonoPInvokeCallback(typeof(SignCompletedDelegate))] +#endif + private static void CryptoSignCompletedCallback(int xcommand_handle, int err, IntPtr signature_raw, int signature_len) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -52,12 +65,15 @@ public static class Crypto Marshal.Copy(signature_raw, signatureBytes, 0, signature_len); taskCompletionSource.SetResult(signatureBytes); - }; - + } + /// /// Gets the callback to use when the indy_crypto_verify command has completed. /// - private static VerifyCompletedDelegate _cryptoVerifyCompletedCallback = (xcommand_handle, err, valid) => +#if __IOS__ + [MonoPInvokeCallback(typeof(VerifyCompletedDelegate))] +#endif + private static void CryptoVerifyCompletedCallback(int xcommand_handle, int err, bool valid) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -65,12 +81,15 @@ public static class Crypto return; taskCompletionSource.SetResult(valid); - }; - + } + /// /// Gets the callback to use when indy_crypto_auth_crypt or indy_crypto_anon_crypt has completed /// - private static EncryptCompletedDelegate _cryptoEncryptCompletedCallback = (xcommand_handle, err, encrypted_msg, encrypted_len) => +#if __IOS__ + [MonoPInvokeCallback(typeof(EncryptCompletedDelegate))] +#endif + private static void CryptoEncryptCompletedCallback(int xcommand_handle, int err, IntPtr encrypted_msg, int encrypted_len) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -81,12 +100,15 @@ public static class Crypto Marshal.Copy(encrypted_msg, messageBytes, 0, encrypted_len); taskCompletionSource.SetResult(messageBytes); - }; - + } + /// /// Gets the callback to use when indy_crypto_auth_decrypt has completed /// - private static AuthDecryptCompletedDelegate _cryptoAuthDecryptCompletedCallback = (command_handle, err, their_vk, msg_data, msg_len) => +#if __IOS__ + [MonoPInvokeCallback(typeof(AuthDecryptCompletedDelegate))] +#endif + private static void CryptoAuthDecryptCompletedCallback(int command_handle, int err, string their_vk, IntPtr msg_data, int msg_len) { var taskCompletionSource = PendingCommands.Remove(command_handle); @@ -99,13 +121,16 @@ public static class Crypto var result = new AuthDecryptResult(their_vk, messageBytes); taskCompletionSource.SetResult(result); - }; - - + } + + /// /// Gets the callback to use when the indy_crypto_box_seal_open command has completed. /// - private static AnonDecryptCompletedDelegate _cryptoAnonDecryptCompletedCallback = (command_handle, err, msg_data, msg_len) => +#if __IOS__ + [MonoPInvokeCallback(typeof(AnonDecryptCompletedDelegate))] +#endif + private static void CryptoAnonDecryptCompletedCallback(int command_handle, int err, IntPtr msg_data, int msg_len) { var taskCompletionSource = PendingCommands.Remove(command_handle); @@ -116,7 +141,7 @@ public static class Crypto Marshal.Copy(msg_data, decryptedMsgBytes, 0, msg_len); taskCompletionSource.SetResult(decryptedMsgBytes); - }; + } /// /// Creates a key in the provided wallet. @@ -150,7 +175,7 @@ public static Task CreateKeyAsync(Wallet wallet, string keyJson) commandHandle, wallet.Handle, keyJson, - _createKeyCompletedCallback + CreateKeyCompletedCallback ); CallbackHelper.CheckResult(commandResult); @@ -211,7 +236,7 @@ public static Task GetKeyMetadataAsync(Wallet wallet, string verKey) commandHandle, wallet.Handle, verKey, - _getKeyMetadataCompletedCallback + GetKeyMetadataCompletedCallback ); CallbackHelper.CheckResult(commandResult); @@ -250,7 +275,7 @@ public static Task SignAsync(Wallet wallet, string myVk, byte[] message) myVk, message, message.Length, - _cryptoSignCompletedCallback + CryptoSignCompletedCallback ); CallbackHelper.CheckResult(commandResult); @@ -285,7 +310,7 @@ public static Task VerifyAsync(string theirVk, byte[] message, byte[] sign message.Length, signature, signature.Length, - _cryptoVerifyCompletedCallback + CryptoVerifyCompletedCallback ); CallbackHelper.CheckResult(commandResult); @@ -327,7 +352,7 @@ public static Task AuthCryptAsync(Wallet wallet, string myVk, string the theirVk, message, message.Length, - _cryptoEncryptCompletedCallback + CryptoEncryptCompletedCallback ); CallbackHelper.CheckResult(commandResult); @@ -367,7 +392,7 @@ public static Task AuthDecryptAsync(Wallet wallet, string myV myVk, message, message.Length, - _cryptoAuthDecryptCompletedCallback + CryptoAuthDecryptCompletedCallback ); CallbackHelper.CheckResult(commandResult); @@ -401,7 +426,7 @@ public static Task AnonCryptAsync(string theirVk, byte[] message) theirVk, message, message.Length, - _cryptoEncryptCompletedCallback + CryptoEncryptCompletedCallback ); CallbackHelper.CheckResult(commandResult); @@ -445,7 +470,7 @@ public static Task AnonDecryptAsync(Wallet wallet, string myVk, byte[] e myVk, encryptedMessage, encryptedMessage.Length, - _cryptoAnonDecryptCompletedCallback + CryptoAnonDecryptCompletedCallback ); CallbackHelper.CheckResult(commandResult); diff --git a/wrappers/dotnet/indy-sdk-dotnet/DidApi/Did.cs b/wrappers/dotnet/indy-sdk-dotnet/DidApi/Did.cs index 3710476885..023bee7fc9 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/DidApi/Did.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/DidApi/Did.cs @@ -2,21 +2,26 @@ using Hyperledger.Indy.PoolApi; using Hyperledger.Indy.Utils; using Hyperledger.Indy.WalletApi; -using System.Runtime.InteropServices; using System.Threading.Tasks; using static Hyperledger.Indy.DidApi.NativeMethods; +#if __IOS__ +using ObjCRuntime; +#endif namespace Hyperledger.Indy.DidApi { /// /// Provides cryptographic functionality related to DIDs. /// - public static class Did + public static class Did { /// /// Gets the callback to use when the command for CreateAndStoreMyDidResultAsync has completed. /// - private static CreateAndStoreMyDidCompletedDelegate _createAndStoreMyDidCallback = (xcommand_handle, err, did, verkey) => +#if __IOS__ + [MonoPInvokeCallback(typeof(CreateAndStoreMyDidCompletedDelegate))] +#endif + private static void CreateAndStoreMyDidCallback(int xcommand_handle, int err, string did, string verkey) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -26,12 +31,15 @@ public static class Did var callbackResult = new CreateAndStoreMyDidResult(did, verkey); taskCompletionSource.SetResult(callbackResult); - }; + } /// /// Gets the callback to use when the command for ReplaceKeysAsync has completed. /// - private static ReplaceKeysStartCompletedDelegate _replaceKeysCallback = (xcommand_handle, err, verkey) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ReplaceKeysStartCompletedDelegate))] +#endif + private static void ReplaceKeysCallback(int xcommand_handle, int err, string verkey) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -39,12 +47,15 @@ public static class Did return; taskCompletionSource.SetResult(verkey); - }; + } /// /// Gets the callback to use when the command for KeyForDidAsync has completed. /// - private static DidKeyForDidCompletedDelegate _keyForDidCompletedCallback = (xcommand_handle, err, key) => +#if __IOS__ + [MonoPInvokeCallback(typeof(DidKeyForDidCompletedDelegate))] +#endif + private static void KeyForDidCompletedCallback(int xcommand_handle, int err, string key) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -52,12 +63,15 @@ public static class Did return; taskCompletionSource.SetResult(key); - }; + } /// /// Gets the callback to use when the command for KeyForLocalDidAsync has completed. /// - private static DidKeyForLocalDidCompletedDelegate _keyForLocalDidCompletedCallback = (xcommand_handle, err, key) => +#if __IOS__ + [MonoPInvokeCallback(typeof(DidKeyForLocalDidCompletedDelegate))] +#endif + private static void KeyForLocalDidCompletedCallback(int xcommand_handle, int err, string key) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -65,12 +79,15 @@ public static class Did return; taskCompletionSource.SetResult(key); - }; + } /// /// Gets the callback to use when the command for GetEndpointForDidAsync has completed. /// - private static DidGetEndpointForDidCompletedDelegate _getEndpointForDidCompletedCallback = (xcommand_handle, err, endpoint, transport_vk) => +#if __IOS__ + [MonoPInvokeCallback(typeof(DidGetEndpointForDidCompletedDelegate))] +#endif + private static void GetEndpointForDidCompletedCallback(int xcommand_handle, int err, string endpoint, string transport_vk) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -80,12 +97,15 @@ public static class Did var result = new EndpointForDidResult(endpoint, transport_vk); taskCompletionSource.SetResult(result); - }; + } /// /// Gets the callback to use when the command for GetDidMetadataAsync has completed. /// - private static DidGetDidMetadataCompletedDelegate _getDidMetadataCompletedCallback = (xcommand_handle, err, metadata) => +#if __IOS__ + [MonoPInvokeCallback(typeof(DidGetDidMetadataCompletedDelegate))] +#endif + private static void GetDidMetadataCompletedCallback(int xcommand_handle, int err, string metadata) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -93,12 +113,15 @@ public static class Did return; taskCompletionSource.SetResult(metadata); - }; + } /// /// Gets the callback to use when the command for GetMyDidWithMetaAsync has completed. /// - private static GetMyDidWithMetaCompletedDelegate _getMyDidWithMetaCompletedCallback = (xcommand_handle, err, didWithMeta) => +#if __IOS__ + [MonoPInvokeCallback(typeof(GetMyDidWithMetaCompletedDelegate))] +#endif + private static void GetMyDidWithMetaCompletedCallback(int xcommand_handle, int err, string didWithMeta) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -106,12 +129,15 @@ public static class Did return; taskCompletionSource.SetResult(didWithMeta); - }; + } /// /// Gets the callback to use when the command for GetMyDidWithMetaAsync has completed. /// - private static ListMyDidsWithMetaCompletedDelegate _listMyDidsWithMetaCompletedCallback = (xcommand_handle, err, dids) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ListMyDidsWithMetaCompletedDelegate))] +#endif + private static void ListMyDidsWithMetaCompletedCallback(int xcommand_handle, int err, string dids) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -119,12 +145,15 @@ public static class Did return; taskCompletionSource.SetResult(dids); - }; + } /// /// Gets the callback to use when the command for AbbreviateVerkeyAsync has completed. /// - private static AbbreviateVerkeyCompletedDelegate _abbreviateVerkeyCompletedCallback = (xcommand_handle, err, verkey) => +#if __IOS__ + [MonoPInvokeCallback(typeof(AbbreviateVerkeyCompletedDelegate))] +#endif + private static void AbbreviateVerkeyCompletedCallback(int xcommand_handle, int err, string verkey) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -132,7 +161,7 @@ public static class Did return; taskCompletionSource.SetResult(verkey); - }; + } /// /// Creates signing and encryption keys in specified wallet for a new DID owned by the caller. @@ -180,7 +209,7 @@ public static Task CreateAndStoreMyDidAsync(Wallet wa commandHandle, wallet.Handle, didJson, - _createAndStoreMyDidCallback); + CreateAndStoreMyDidCallback); CallbackHelper.CheckResult(commandResult); @@ -225,7 +254,7 @@ public static Task ReplaceKeysStartAsync(Wallet wallet, string did, stri wallet.Handle, did, identityJson, - _replaceKeysCallback); + ReplaceKeysCallback); CallbackHelper.CheckResult(commandResult); @@ -300,7 +329,7 @@ public static Task StoreTheirDidAsync(Wallet wallet, string identityJson) return taskCompletionSource.Task; } - + /// /// Gets the verification key for the specified DID. /// @@ -332,7 +361,7 @@ public static Task KeyForDidAsync(Pool pool, Wallet wallet, string did) pool.Handle, wallet.Handle, did, - _keyForDidCompletedCallback + KeyForDidCompletedCallback ); CallbackHelper.CheckResult(commandResult); @@ -368,7 +397,7 @@ public static Task KeyForLocalDidAsync(Wallet wallet, string did) commandHandle, wallet.Handle, did, - _keyForLocalDidCompletedCallback + KeyForLocalDidCompletedCallback ); CallbackHelper.CheckResult(commandResult); @@ -436,7 +465,7 @@ public static Task GetEndpointForDidAsync(Wallet wallet, P wallet.Handle, pool.Handle, did, - _getEndpointForDidCompletedCallback + GetEndpointForDidCompletedCallback ); CallbackHelper.CheckResult(commandResult); @@ -497,7 +526,7 @@ public static Task GetDidMetadataAsync(Wallet wallet, string did) commandHandle, wallet.Handle, did, - _getDidMetadataCompletedCallback + GetDidMetadataCompletedCallback ); CallbackHelper.CheckResult(commandResult); @@ -523,7 +552,7 @@ public static Task GetMyDidWithMetaAsync(Wallet wallet, string myDid) commandHandle, wallet.Handle, myDid, - _getMyDidWithMetaCompletedCallback + GetMyDidWithMetaCompletedCallback ); CallbackHelper.CheckResult(commandResult); @@ -546,7 +575,7 @@ public static Task ListMyDidsWithMetaAsync(Wallet wallet) var commandResult = NativeMethods.indy_list_my_dids_with_meta( commandHandle, wallet.Handle, - _listMyDidsWithMetaCompletedCallback + ListMyDidsWithMetaCompletedCallback ); CallbackHelper.CheckResult(commandResult); @@ -572,7 +601,7 @@ public static Task AbbreviateVerkeyAsync(string did, string fullVerkey) commandHandle, did, fullVerkey, - _abbreviateVerkeyCompletedCallback + AbbreviateVerkeyCompletedCallback ); CallbackHelper.CheckResult(commandResult); diff --git a/wrappers/dotnet/indy-sdk-dotnet/DidApi/EndpointForDidResult.cs b/wrappers/dotnet/indy-sdk-dotnet/DidApi/EndpointForDidResult.cs index c6fd4b7598..afe45ab772 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/DidApi/EndpointForDidResult.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/DidApi/EndpointForDidResult.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Hyperledger.Indy.DidApi +namespace Hyperledger.Indy.DidApi { /// /// Result of getting the endpoint for a DID. diff --git a/wrappers/dotnet/indy-sdk-dotnet/ErrorCode.cs b/wrappers/dotnet/indy-sdk-dotnet/ErrorCode.cs index 5444ba9710..edfb0f2dc4 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/ErrorCode.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/ErrorCode.cs @@ -122,7 +122,12 @@ public enum ErrorCode /// /// Trying to open wallet that was opened already /// - WalletAlreadyOpenedError = 206, + WalletAlreadyOpenedError = 206, + + /// + /// No value with the specified key exists in the wallet from which it was requested. + /// + WalletItemNotFoundError = 212, // Ledger errors diff --git a/wrappers/dotnet/indy-sdk-dotnet/IndyException.cs b/wrappers/dotnet/indy-sdk-dotnet/IndyException.cs index 776e607713..d51db79c2d 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/IndyException.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/IndyException.cs @@ -96,8 +96,10 @@ internal static IndyException FromSdkError(int sdkErrorCode) return new ClaimRevokedException(); case ErrorCode.SignusUnknownCryptoError: return new UnknownCryptoException(); + case ErrorCode.WalletItemNotFoundError: + return new WalletItemNotFoundException(); default: - var message = string.Format("An unmapped error with the code '{0}' was returned by the SDK.", sdkErrorCode); + var message = $"An unmapped error with the code '{sdkErrorCode}' was returned by the SDK."; return new IndyException(message, sdkErrorCode); } } diff --git a/wrappers/dotnet/indy-sdk-dotnet/LedgerApi/Ledger.cs b/wrappers/dotnet/indy-sdk-dotnet/LedgerApi/Ledger.cs index 032cd9611f..9501d2db87 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/LedgerApi/Ledger.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/LedgerApi/Ledger.cs @@ -5,6 +5,9 @@ using System; using System.Threading.Tasks; using static Hyperledger.Indy.LedgerApi.NativeMethods; +#if __IOS__ +using ObjCRuntime; +#endif namespace Hyperledger.Indy.LedgerApi { @@ -42,7 +45,10 @@ public static class Ledger /// /// Gets the callback to use when a command that submits a message to the ledger completes. /// - private static SubmitRequestCompletedDelegate _submitRequestCallback = (xcommand_handle, err, response_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(SubmitRequestCompletedDelegate))] +#endif + private static void SubmitRequestCallback(int xcommand_handle, int err, string response_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -50,12 +56,15 @@ public static class Ledger return; taskCompletionSource.SetResult(response_json); - }; + } /// /// Gets the callback to use when a command that builds a request completes. /// - private static BuildRequestCompletedDelegate _buildRequestCallback = (xcommand_handle, err, request_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(BuildRequestCompletedDelegate))] +#endif + private static void BuildRequestCallback(int xcommand_handle, int err, string request_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -63,9 +72,12 @@ public static class Ledger return; taskCompletionSource.SetResult(request_json); - }; + } - private static ParseResponseCompletedDelegate _parseResponseCallback = (xcommand_handle, err, id, object_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ParseResponseCompletedDelegate))] +#endif + private static void ParseResponseCallback(int xcommand_handle, int err, string id, string object_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -73,9 +85,12 @@ public static class Ledger return; taskCompletionSource.SetResult(new ParseResponseResult(id, object_json)); - }; + } - private static ParseRegistryResponseCompletedDelegate _parseRegistryResponseCallback = (xcommand_handle, err, id, object_json, timestamp) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ParseRegistryResponseCompletedDelegate))] +#endif + private static void ParseRegistryResponseCallback(int xcommand_handle, int err, string id, string object_json, ulong timestamp) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -83,12 +98,15 @@ public static class Ledger return; taskCompletionSource.SetResult(new ParseRegistryResponseResult(id, object_json, timestamp)); - }; + } /// /// Gets the callback to use when the command for SignRequestAsync has completed. /// - private static SignRequestCompletedDelegate _signRequestCallback = (xcommand_handle, err, signed_request_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(SignRequestCompletedDelegate))] +#endif + private static void SignRequestCallback(int xcommand_handle, int err, string signed_request_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -96,7 +114,7 @@ public static class Ledger return; taskCompletionSource.SetResult(signed_request_json); - }; + } /// /// Signs a request message. @@ -125,7 +143,7 @@ public static Task SignRequestAsync(Wallet wallet, string submitterDid, wallet.Handle, submitterDid, requestJson, - _signRequestCallback); + SignRequestCallback); CallbackHelper.CheckResult(result); @@ -163,7 +181,7 @@ public static Task SignAndSubmitRequestAsync(Pool pool, Wallet wallet, s wallet.Handle, submitterDid, requestJson, - _submitRequestCallback + SubmitRequestCallback ); CallbackHelper.CheckResult(result); @@ -197,7 +215,7 @@ public static Task SubmitRequestAsync(Pool pool, string requestJson) commandHandle, pool.Handle, requestJson, - _submitRequestCallback); + SubmitRequestCallback); CallbackHelper.CheckResult(result); @@ -233,7 +251,7 @@ public static Task BuildGetDdoRequestAsync(string submitterDid, string t commandHandle, submitterDid, targetDid, - _buildRequestCallback); + BuildRequestCallback); CallbackHelper.CheckResult(result); @@ -281,7 +299,7 @@ public static Task BuildNymRequestAsync(string submitterDid, string targ verKey, alias, role, - _buildRequestCallback + BuildRequestCallback ); CallbackHelper.CheckResult(result); @@ -327,7 +345,7 @@ public static Task BuildAttribRequestAsync(string submitterDid, string t hash, raw, enc, - _buildRequestCallback + BuildRequestCallback ); CallbackHelper.CheckResult(result); @@ -366,7 +384,7 @@ public static Task BuildGetAttribRequestAsync(string submitterDid, strin raw, hash, enc, - _buildRequestCallback + BuildRequestCallback ); CallbackHelper.CheckResult(result); @@ -399,7 +417,7 @@ public static Task BuildGetNymRequestAsync(string submitterDid, string t commandHandle, submitterDid, targetDid, - _buildRequestCallback + BuildRequestCallback ); CallbackHelper.CheckResult(result); @@ -445,7 +463,7 @@ public static Task BuildSchemaRequestAsync(string submitterDid, string d commandHandle, submitterDid, data, - _buildRequestCallback + BuildRequestCallback ); CallbackHelper.CheckResult(result); @@ -471,7 +489,7 @@ public static Task BuildGetSchemaRequestAsync(string submitterDid, strin commandHandle, submitterDid, schemaId, - _buildRequestCallback + BuildRequestCallback ); CallbackHelper.CheckResult(result); @@ -502,7 +520,7 @@ public static Task ParseGetSchemaResponseAsync(string getSc var result = NativeMethods.indy_parse_get_schema_response( commandHandle, getSchemaResponse, - _parseResponseCallback + ParseResponseCallback ); CallbackHelper.CheckResult(result); @@ -529,7 +547,7 @@ public static Task BuildCredDefRequestAsync(string submitterDid, string commandHandle, submitterDid, data, - _buildRequestCallback + BuildRequestCallback ); CallbackHelper.CheckResult(result); @@ -556,7 +574,7 @@ public static Task BuildGetCredDefRequestAsync(string submitterDid, stri commandHandle, submitterDid, id, - _buildRequestCallback + BuildRequestCallback ); CallbackHelper.CheckResult(result); @@ -579,7 +597,7 @@ public static Task ParseGetCredDefResponseAsync(string getC var result = NativeMethods.indy_parse_get_cred_def_response( commandHandle, getCredDefResponse, - _parseResponseCallback + ParseResponseCallback ); CallbackHelper.CheckResult(result); @@ -609,7 +627,7 @@ public static Task BuildNodeRequestAsync(string submitterDid, string tar submitterDid, targetDid, data, - _buildRequestCallback + BuildRequestCallback ); CallbackHelper.CheckResult(result); @@ -635,7 +653,7 @@ public static Task BuildGetTxnRequestAsync(string submitterDid, int data commandHandle, submitterDid, data, - _buildRequestCallback); + BuildRequestCallback); CallbackHelper.CheckResult(result); @@ -661,7 +679,7 @@ public static Task BuildPoolConfigRequestAsync(string submitterDid, bool submitterDid, writes, force, - _buildRequestCallback); + BuildRequestCallback); CallbackHelper.CheckResult(result); @@ -707,7 +725,7 @@ public static Task BuildPoolUpgradeRequestAsync(string submitterDid, str justification, reinstall, force, - _buildRequestCallback); + BuildRequestCallback); CallbackHelper.CheckResult(result); @@ -747,7 +765,7 @@ public static Task BuildRevocRegDefRequestAsync(string submitterDid, str commandHandle, submitterDid, data, - _buildRequestCallback); + BuildRequestCallback); CallbackHelper.CheckResult(result); @@ -773,7 +791,7 @@ public static Task BuildGetRevocRegDefRequestAsync(string submitterDid, commandHandle, submitterDid, id, - _buildRequestCallback); + BuildRequestCallback); CallbackHelper.CheckResult(result); @@ -811,7 +829,7 @@ public static Task ParseGetRevocRegDefResponseAsync(string var result = NativeMethods.indy_parse_get_revoc_reg_def_response( commandHandle, getRevocRegDefResponse, - _parseResponseCallback); + ParseResponseCallback); CallbackHelper.CheckResult(result); @@ -854,7 +872,7 @@ public static Task BuildRevocRegEntryRequestAsync(string submitterDid, s revocRegDefId, revDefType, value, - _buildRequestCallback); + BuildRequestCallback); CallbackHelper.CheckResult(result); @@ -882,7 +900,7 @@ public static Task BuildGetRevocRegRequestAsync(string submitterDid, str submitterDid, revocRegDefId, timestamp, - _buildRequestCallback); + BuildRequestCallback); CallbackHelper.CheckResult(result); @@ -912,7 +930,7 @@ public static Task ParseGetRevocRegResponseAsync(st var result = NativeMethods.indy_parse_get_revoc_reg_response( commandHandle, getRevocRegResponse, - _parseRegistryResponseCallback); + ParseRegistryResponseCallback); CallbackHelper.CheckResult(result); @@ -943,7 +961,7 @@ public static Task BuildGetRevocRegDeltaRequestAsync(string submitterDid revocRegDefId, from, to, - _buildRequestCallback); + BuildRequestCallback); CallbackHelper.CheckResult(result); @@ -975,7 +993,7 @@ public static Task ParseGetRevocRegDeltaResponseAsy var result = NativeMethods.indy_parse_get_revoc_reg_response( commandHandle, getRevocRegDeltaResponse, - _parseRegistryResponseCallback); + ParseRegistryResponseCallback); CallbackHelper.CheckResult(result); diff --git a/wrappers/dotnet/indy-sdk-dotnet/LedgerApi/NativeMethods.cs b/wrappers/dotnet/indy-sdk-dotnet/LedgerApi/NativeMethods.cs index 3953d38741..a31e0ed1da 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/LedgerApi/NativeMethods.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/LedgerApi/NativeMethods.cs @@ -169,7 +169,7 @@ internal static class NativeMethods /// /// Parse registry response completed delegate. /// - internal delegate void ParseRegistryResponseCompletedDelegate(int xcommand_handle, int err, string id, string object_json, long timestamp); + internal delegate void ParseRegistryResponseCompletedDelegate(int xcommand_handle, int err, string id, string object_json, ulong timestamp); /// /// Indies the build cred def request. diff --git a/wrappers/dotnet/indy-sdk-dotnet/LedgerApi/ParseRegistryResponseResult.cs b/wrappers/dotnet/indy-sdk-dotnet/LedgerApi/ParseRegistryResponseResult.cs index 848daf8ef0..8a7c7e1f83 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/LedgerApi/ParseRegistryResponseResult.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/LedgerApi/ParseRegistryResponseResult.cs @@ -21,7 +21,7 @@ public class ParseRegistryResponseResult /// Gets the timestamp. /// /// The timestamp. - public long Timestamp { get; private set; } + public ulong Timestamp { get; private set; } /// /// Initializes a new instance of the class. @@ -29,7 +29,7 @@ public class ParseRegistryResponseResult /// Identifier. /// Object json. /// Timestamp. - internal ParseRegistryResponseResult(string id, string objectJson, long timestamp) + internal ParseRegistryResponseResult(string id, string objectJson, ulong timestamp) { Id = id; ObjectJson = objectJson; diff --git a/wrappers/dotnet/indy-sdk-dotnet/NonSecretsApi/NoRecordsException.cs b/wrappers/dotnet/indy-sdk-dotnet/NonSecretsApi/NoRecordsException.cs index 3c52050bdb..035119f784 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/NonSecretsApi/NoRecordsException.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/NonSecretsApi/NoRecordsException.cs @@ -1,5 +1,4 @@ -using System; -namespace Hyperledger.Indy.NonSecretsApi +namespace Hyperledger.Indy.NonSecretsApi { /// /// No records exception. diff --git a/wrappers/dotnet/indy-sdk-dotnet/NonSecretsApi/NonSecrets.cs b/wrappers/dotnet/indy-sdk-dotnet/NonSecretsApi/NonSecrets.cs index 713dcb139f..631f89ecd2 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/NonSecretsApi/NonSecrets.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/NonSecretsApi/NonSecrets.cs @@ -4,6 +4,9 @@ using Hyperledger.Indy.WalletApi; using static Hyperledger.Indy.NonSecretsApi.NativeMethods; using static Hyperledger.Indy.Utils.CallbackHelper; +#if __IOS__ +using ObjCRuntime; +#endif namespace Hyperledger.Indy.NonSecretsApi { @@ -12,19 +15,25 @@ namespace Hyperledger.Indy.NonSecretsApi /// public static class NonSecrets { - #region Static callback fields + #region Static callback methods - static readonly GetRecordCompletedDelegate _getRecordCallback = (xcommand_handle, err, value) => - { - var taskCompletionSource = PendingCommands.Remove(xcommand_handle); +#if __IOS__ + [MonoPInvokeCallback(typeof(GetRecordCompletedDelegate))] +#endif + static void GetRecordCallback(int xcommand_handle, int err, string value) + { + var taskCompletionSource = PendingCommands.Remove(xcommand_handle); - if (!CheckCallback(taskCompletionSource, err)) - return; + if (!CheckCallback(taskCompletionSource, err)) + return; - taskCompletionSource.SetResult(value); - }; + taskCompletionSource.SetResult(value); + } - static readonly OpenWalletSearchCompletedDelegate _openSearchCallback = (xcommand_handle, err, search_handle) => +#if __IOS__ + [MonoPInvokeCallback(typeof(OpenWalletSearchCompletedDelegate))] +#endif + static void OpenSearchCallback(int xcommand_handle, int err, IntPtr search_handle) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -32,9 +41,12 @@ public static class NonSecrets return; taskCompletionSource.SetResult(new WalletSearch(search_handle)); - }; + } - static readonly FetchNextRecordCompletedDelegate _fetchNextCallback = (xcommand_handle, err, records_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(FetchNextRecordCompletedDelegate))] +#endif + static void FetchNextCallback(int xcommand_handle, int err, string records_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -42,7 +54,7 @@ public static class NonSecrets return; taskCompletionSource.SetResult(records_json); - }; + } #endregion @@ -291,7 +303,7 @@ public static Task GetRecordAsync(Wallet wallet, string type, string id, type, id, optionsJson, - _getRecordCallback); + GetRecordCallback); return taskCompletionSource.Task; } @@ -343,7 +355,7 @@ public static Task OpenSearchAsync(Wallet wallet, string type, str type, queryJson, optionsJson, - _openSearchCallback); + OpenSearchCallback); return taskCompletionSource.Task; } @@ -380,7 +392,7 @@ public static Task FetchNextRecordsAsync(Wallet wallet, WalletSearch wal wallet.Handle, walletSearch.Handle, count, - _fetchNextCallback); + FetchNextCallback); return taskCompletionSource.Task; } diff --git a/wrappers/dotnet/indy-sdk-dotnet/NonSecretsApi/WalletSearch.cs b/wrappers/dotnet/indy-sdk-dotnet/NonSecretsApi/WalletSearch.cs index bf41f30146..abfeabafce 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/NonSecretsApi/WalletSearch.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/NonSecretsApi/WalletSearch.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Threading.Tasks; using Hyperledger.Indy.Utils; using Hyperledger.Indy.WalletApi; diff --git a/wrappers/dotnet/indy-sdk-dotnet/PairwiseApi/Pairwise.cs b/wrappers/dotnet/indy-sdk-dotnet/PairwiseApi/Pairwise.cs index efff917993..7bcdfd8cc0 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/PairwiseApi/Pairwise.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/PairwiseApi/Pairwise.cs @@ -1,10 +1,10 @@ using Hyperledger.Indy.Utils; using Hyperledger.Indy.WalletApi; -using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; using static Hyperledger.Indy.PairwiseApi.NativeMethods; +#if __IOS__ +using ObjCRuntime; +#endif namespace Hyperledger.Indy.PairwiseApi { @@ -21,7 +21,10 @@ public static class Pairwise /// /// Gets the callback to use when the IsExistsAsync command completes. /// - private static IsPairwiseExistsCompletedDelegate _isPairwiseExistsCallback = (xcommand_handle, err, exists) => +#if __IOS__ + [MonoPInvokeCallback(typeof(IsPairwiseExistsCompletedDelegate))] +#endif + private static void IsPairwiseExistsCallback(int xcommand_handle, int err, bool exists) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -29,12 +32,15 @@ public static class Pairwise return; taskCompletionSource.SetResult(exists); - }; + } /// /// Gets the callback to use when the ListAsync command completes. /// - private static ListPairwiseCompletedDelegate _listPairwiseCallback = (xcommand_handle, err, list_pairwise) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ListPairwiseCompletedDelegate))] +#endif + private static void ListPairwiseCallback(int xcommand_handle, int err, string list_pairwise) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -42,12 +48,15 @@ public static class Pairwise return; taskCompletionSource.SetResult(list_pairwise); - }; + } /// /// Gets the callback to use when the GetAsync command completes. /// - private static GetPairwiseCompletedDelegate _getPairwiseCallback = (xcommand_handle, err, get_pairwise_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(GetPairwiseCompletedDelegate))] +#endif + private static void GetPairwiseCallback(int xcommand_handle, int err, string get_pairwise_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -55,7 +64,7 @@ public static class Pairwise return; taskCompletionSource.SetResult(get_pairwise_json); - }; + } /// /// Gets whether or not a pairwise record exists in the provided wallet for the specified DID . @@ -76,7 +85,7 @@ public static Task IsExistsAsync(Wallet wallet, string theirDid) commandHandle, wallet.Handle, theirDid, - _isPairwiseExistsCallback); + IsPairwiseExistsCallback); CallbackHelper.CheckResult(result); @@ -145,7 +154,7 @@ public static Task ListAsync(Wallet wallet) int result = NativeMethods.indy_list_pairwise( commandHandle, wallet.Handle, - _listPairwiseCallback); + ListPairwiseCallback); CallbackHelper.CheckResult(result); @@ -186,7 +195,7 @@ public static Task GetAsync(Wallet wallet, string theirDid) commandHandle, wallet.Handle, theirDid, - _getPairwiseCallback); + GetPairwiseCallback); CallbackHelper.CheckResult(result); diff --git a/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/NativeMethods.cs b/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/NativeMethods.cs index ce32c71e3a..7886224394 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/NativeMethods.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/NativeMethods.cs @@ -13,19 +13,19 @@ public class NativeMethods internal delegate ErrorCode CreatePaymentAddressCallbackDelegate(int command_handle, IntPtr wallet_handle, string config, PaymentMethodResultDelegate cb); - internal delegate ErrorCode AddRequestFeesCallbackDelegate(int command_handle, IntPtr wallet_handle, string submitter_did, string req_json, string inputs_json, string outputs_json, PaymentMethodResultDelegate cb); + internal delegate ErrorCode AddRequestFeesCallbackDelegate(int command_handle, IntPtr wallet_handle, string submitter_did, string req_json, string inputs_json, string outputs_json, string extra, PaymentMethodResultDelegate cb); internal delegate ErrorCode ParseResponseWithFeesCallbackDelegate(int command_handle, string resp_json, PaymentMethodResultDelegate cb); - internal delegate ErrorCode BuildGetUtxoRequstCallbackDelegate(int command_handle, IntPtr wallet_handle, string submitter_did, string payment_address, PaymentMethodResultDelegate cb); + internal delegate ErrorCode BuildGetPaymentSourcesRequestCallbackDelegate(int command_handle, IntPtr wallet_handle, string submitter_did, string payment_address, PaymentMethodResultDelegate cb); - internal delegate ErrorCode ParseGetUtxoResponseCallbackDelegate(int command_handle, string resp_json, PaymentMethodResultDelegate cb); + internal delegate ErrorCode ParseGetPaymentSourcesResponseCallbackDelegate(int command_handle, string resp_json, PaymentMethodResultDelegate cb); - internal delegate ErrorCode BuildPaymentRequestCallbackDelegate(int command_handle, IntPtr wallet_handle, string submitter_did, string inputs_json, string outputs_json, PaymentMethodResultDelegate cb); + internal delegate ErrorCode BuildPaymentRequestCallbackDelegate(int command_handle, IntPtr wallet_handle, string submitter_did, string inputs_json, string outputs_json, string extra, PaymentMethodResultDelegate cb); internal delegate ErrorCode ParsePaymentResponseCallbackDelegate(int command_handle, string resp_json, PaymentMethodResultDelegate cb); - internal delegate ErrorCode BuildMintReqCallbackDelegate(int command_handle, IntPtr wallet_handle, string submitter_did, string outputs_json, PaymentMethodResultDelegate cb); + internal delegate ErrorCode BuildMintReqCallbackDelegate(int command_handle, IntPtr wallet_handle, string submitter_did, string outputs_json, string extra, PaymentMethodResultDelegate cb); internal delegate ErrorCode BuildSetTxnFeesReqCallbackDelegate(int command_handle, IntPtr wallet_handle, string submitter_did, string fees_json, PaymentMethodResultDelegate cb); @@ -33,19 +33,25 @@ public class NativeMethods internal delegate ErrorCode ParseGetTxnFeesResponseCallbackDelegate(int command_handle, string resp_json, PaymentMethodResultDelegate cb); + internal delegate ErrorCode BuildVerifyPaymentRequestCallbackDelegate(int command_handle, IntPtr wallet_handle, string submitter_did, string receipt, PaymentMethodResultDelegate cb); + + internal delegate ErrorCode ParseVerifyPaymentResponseCallbackDelegate(int command_handle, string resp_json, PaymentMethodResultDelegate cb); + [DllImport(Consts.NATIVE_LIB_NAME, CharSet = CharSet.Ansi, BestFitMapping = false)] internal static extern int indy_register_payment_method(int command_handle, string payment_method, CreatePaymentAddressCallbackDelegate create_payment_address, AddRequestFeesCallbackDelegate add_request_fees, ParseResponseWithFeesCallbackDelegate parse_response_with_fees, - BuildGetUtxoRequstCallbackDelegate build_get_utxo_request, - ParseGetUtxoResponseCallbackDelegate parse_get_utxo_response, + BuildGetPaymentSourcesRequestCallbackDelegate build_get_payment_sources_request, + ParseGetPaymentSourcesResponseCallbackDelegate parse_get_payment_sources_response, BuildPaymentRequestCallbackDelegate build_payment_req, ParsePaymentResponseCallbackDelegate parse_payment_response, BuildMintReqCallbackDelegate build_mint_req, BuildSetTxnFeesReqCallbackDelegate build_set_txn_fees_req, BuildGetTxnFeesReqCallbackDelegate build_get_txn_fees_req, ParseGetTxnFeesResponseCallbackDelegate parse_get_txn_fees_response, + BuildVerifyPaymentRequestCallbackDelegate build_verify_payment_req, + ParseVerifyPaymentResponseCallbackDelegate parse_verify_payment_response, IndyMethodCompletedDelegate cb); [DllImport(Consts.NATIVE_LIB_NAME, CharSet = CharSet.Ansi, BestFitMapping = false)] @@ -80,29 +86,29 @@ internal static extern int indy_register_payment_method(int command_handle, stri /// /// Parse response with fees delegate. /// - public delegate void ParseResponseWithFeesDelegate(int command_handle, int err, string utxo_json); + public delegate void ParseResponseWithFeesDelegate(int command_handle, int err, string receipts_json); [DllImport(Consts.NATIVE_LIB_NAME, CharSet = CharSet.Ansi, BestFitMapping = false)] - internal static extern int indy_build_get_utxo_request(int command_handle, IntPtr wallet_handle, string submitter_did, string payment_address, BuildGetUtxoRequstDelegate cb); + internal static extern int indy_build_get_payment_sources_request(int command_handle, IntPtr wallet_handle, string submitter_did, string payment_address, BuildGetUtxoRequstDelegate cb); /// /// Build get utxo requst delegate. /// - public delegate void BuildGetUtxoRequstDelegate(int command_handle, int err, string get_utxo_txn_json, string payment_method); + public delegate void BuildGetUtxoRequstDelegate(int command_handle, int err, string get_sources_txn_json, string payment_method); [DllImport(Consts.NATIVE_LIB_NAME, CharSet = CharSet.Ansi, BestFitMapping = false)] - internal static extern int indy_parse_get_utxo_response(int command_handle, string payment_method, string resp_json, ParseGetUtxoResponseDelegate cb); + internal static extern int indy_parse_get_payment_sources_response(int command_handle, string payment_method, string resp_json, ParseGetUtxoResponseDelegate cb); /// /// Parse get utxo response delegate. /// - public delegate void ParseGetUtxoResponseDelegate(int command_handle, int err, string utxo_json); + public delegate void ParseGetUtxoResponseDelegate(int command_handle, int err, string sources_json); [DllImport(Consts.NATIVE_LIB_NAME, CharSet = CharSet.Ansi, BestFitMapping = false)] - internal static extern int indy_build_payment_req(int command_handle, IntPtr wallet_handle, string submitter_did, string inputs_json, string outputs_json, BuildPaymentRequestDelegate cb); + internal static extern int indy_build_payment_req(int command_handle, IntPtr wallet_handle, string submitter_did, string inputs_json, string outputs_json, string extra, BuildPaymentRequestDelegate cb); /// /// Build payment request delegate. @@ -116,11 +122,11 @@ internal static extern int indy_register_payment_method(int command_handle, stri /// /// Parse payment response delegate. /// - public delegate void ParsePaymentResponseDelegate(int command_handle, int err, string utxo_json); + public delegate void ParsePaymentResponseDelegate(int command_handle, int err, string receipts_json); [DllImport(Consts.NATIVE_LIB_NAME, CharSet = CharSet.Ansi, BestFitMapping = false)] - internal static extern int indy_build_mint_req(int command_handle, IntPtr wallet_handle, string submitter_did, string outputs_json, BuildMintReqDelegate cb); + internal static extern int indy_build_mint_req(int command_handle, IntPtr wallet_handle, string submitter_did, string outputs_json, string extra, BuildMintReqDelegate cb); /// /// Build mint req delegate. @@ -151,5 +157,21 @@ internal static extern int indy_register_payment_method(int command_handle, stri /// Parse get txn fees response delegate. /// public delegate void ParseGetTxnFeesResponseDelegate(int command_handle, int err, string fees_json); + + [DllImport(Consts.NATIVE_LIB_NAME, CharSet = CharSet.Ansi, BestFitMapping = false)] + internal static extern int indy_build_verify_payment_req(int command_handle, IntPtr wallet_handle, string submitter_did, string receipt, BuildVerifyPaymentRequestDelegate cb); + + /// + /// Build verify payment request delegate. + /// + public delegate void BuildVerifyPaymentRequestDelegate(int command_handle, int err, string verify_txn_json, string payment_method); + + [DllImport(Consts.NATIVE_LIB_NAME, CharSet = CharSet.Ansi, BestFitMapping = false)] + internal static extern int indy_parse_verify_payment_response(int command_handle, string payment_method, string resp_json, ParseVerifyPaymentResponseDelegate cb); + + /// + /// Parse verify payment request delegate. + /// + public delegate void ParseVerifyPaymentResponseDelegate(int command_handle, int err, string txn_json); } } diff --git a/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/PaymentMethod.cs b/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/PaymentMethod.cs index 32df3338c1..084bd84b7e 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/PaymentMethod.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/PaymentMethod.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using Hyperledger.Indy.Utils; -using Hyperledger.Indy.WalletApi; using static Hyperledger.Indy.PaymentsApi.NativeMethods; namespace Hyperledger.Indy.PaymentsApi @@ -19,14 +18,16 @@ protected PaymentMethod() CreatePaymentAddressCallback = CreatePaymentAddressHandler; AddRequestFeesCallback = AddRequestFeesHandler; ParseResponseWithFeesCallback = ParseResponseWithFeesHandler; - BuildGetUtxoRequstCallback = BuildGetUtxoRequstHandler; - ParseGetUtxoResponseCallback = ParseGetUtxoResponseHandler; + BuildGetPaymentSourcesRequstCallback = BuildGetPaymentSourcesRequstHandler; + ParseGetPaymentSourcesResponseCallback = ParseGetPaymentSourcesResponseHandler; BuildPaymentRequestCallback = BuildPaymentRequestHandler; ParsePaymentResponseCallback = ParsePaymentResponseHandler; BuildMintReqCallback = BuildMintReqHandler; BuildSetTxnFeesReqCallback = BuildSetTxnFeesReqHandler; BuildGetTxnFeesReqCallback = BuildGetTxnFeesReqHandler; ParseGetTxnFeesResponseCallback = ParseGetTxnFeesResponseHandler; + BuildVerifyPaymentRequestCallback = BuildVerifyPaymentRequestHandler; + ParseVerifyPaymentResponseCallback = ParseVerifyPaymentResponseHandler; } ErrorCode CreatePaymentAddressHandler(int command_handle, IntPtr wallet_handle, string config, PaymentMethodResultDelegate cb) @@ -41,9 +42,9 @@ ErrorCode CreatePaymentAddressHandler(int command_handle, IntPtr wallet_handle, return ErrorCode.Success; } - ErrorCode AddRequestFeesHandler(int command_handle, IntPtr wallet_handle, string submitter_did, string req_json, string inputs_json, string outputs_json, PaymentMethodResultDelegate cb) + ErrorCode AddRequestFeesHandler(int command_handle, IntPtr wallet_handle, string submitter_did, string req_json, string inputs_json, string outputs_json, string extra, PaymentMethodResultDelegate cb) { - AddRequestFeesAsync(submitter_did, req_json, inputs_json, outputs_json) + AddRequestFeesAsync(submitter_did, req_json, inputs_json, outputs_json, extra) .ContinueWith(reqWithFeesJson => { var result = cb(command_handle, 0, reqWithFeesJson.Result); @@ -65,9 +66,9 @@ ErrorCode ParseResponseWithFeesHandler(int command_handle, string resp_json, Pay return ErrorCode.Success; } - ErrorCode BuildGetUtxoRequstHandler(int command_handle, IntPtr wallet_handle, string submitter_did, string payment_address, PaymentMethodResultDelegate cb) + ErrorCode BuildGetPaymentSourcesRequstHandler(int command_handle, IntPtr wallet_handle, string submitter_did, string payment_address, PaymentMethodResultDelegate cb) { - BuildGetUtxoRequestAsync(submitter_did, payment_address) + BuildGetPaymentSourcesRequestAsync(submitter_did, payment_address) .ContinueWith(getUtxoTxnJson => { var result = cb(command_handle, 0, getUtxoTxnJson.Result); @@ -77,9 +78,9 @@ ErrorCode BuildGetUtxoRequstHandler(int command_handle, IntPtr wallet_handle, st return ErrorCode.Success; } - ErrorCode ParseGetUtxoResponseHandler(int command_handle, string resp_json, PaymentMethodResultDelegate cb) + ErrorCode ParseGetPaymentSourcesResponseHandler(int command_handle, string resp_json, PaymentMethodResultDelegate cb) { - ParseGetUtxoResponseAsync(resp_json) + ParseGetPaymentSourcesResponseAsync(resp_json) .ContinueWith(utxoJson => { var result = cb(command_handle, 0, utxoJson.Result); @@ -89,9 +90,9 @@ ErrorCode ParseGetUtxoResponseHandler(int command_handle, string resp_json, Paym return ErrorCode.Success; } - ErrorCode BuildPaymentRequestHandler(int command_handle, IntPtr wallet_handle, string submitter_did, string inputs_json, string outputs_json, PaymentMethodResultDelegate cb) + ErrorCode BuildPaymentRequestHandler(int command_handle, IntPtr wallet_handle, string submitter_did, string inputs_json, string outputs_json, string extra, PaymentMethodResultDelegate cb) { - BuildPaymentRequestAsync(submitter_did, inputs_json, outputs_json) + BuildPaymentRequestAsync(submitter_did, inputs_json, outputs_json, extra) .ContinueWith(paymentReqJson => { var result = cb(command_handle, 0, paymentReqJson.Result); @@ -113,9 +114,9 @@ ErrorCode ParsePaymentResponseHandler(int command_handle, string resp_json, Paym return ErrorCode.Success; } - ErrorCode BuildMintReqHandler(int command_handle, IntPtr wallet_handle, string submitter_did, string outputs_json, PaymentMethodResultDelegate cb) + ErrorCode BuildMintReqHandler(int command_handle, IntPtr wallet_handle, string submitter_did, string outputs_json, string extra, PaymentMethodResultDelegate cb) { - BuildMintRequestAsync(submitter_did, outputs_json) + BuildMintRequestAsync(submitter_did, outputs_json, extra) .ContinueWith(mintReqJson => { var result = cb(command_handle, 0, mintReqJson.Result); @@ -161,15 +162,39 @@ ErrorCode ParseGetTxnFeesResponseHandler(int command_handle, string resp_json, P return ErrorCode.Success; } + ErrorCode BuildVerifyPaymentRequestHandler(int command_handle, IntPtr wallet_handle, string submitterDid, string receipt, PaymentMethodResultDelegate cb) + { + BuildVerifyPaymentRequestAsync(submitterDid, receipt) + .ContinueWith(feesJson => + { + var result = cb(command_handle, 0, feesJson.Result); + CallbackHelper.CheckCallback(result); + }); + + return ErrorCode.Success; + } + + ErrorCode ParseVerifyPaymentResponseHandler(int command_handle, string responseJson, PaymentMethodResultDelegate cb) + { + ParseVerifyPaymentResponseAsync(responseJson) + .ContinueWith(feesJson => + { + var result = cb(command_handle, 0, feesJson.Result); + CallbackHelper.CheckCallback(result); + }); + + return ErrorCode.Success; + } + internal CreatePaymentAddressCallbackDelegate CreatePaymentAddressCallback { get; } internal AddRequestFeesCallbackDelegate AddRequestFeesCallback { get; } internal ParseResponseWithFeesCallbackDelegate ParseResponseWithFeesCallback { get; } - internal BuildGetUtxoRequstCallbackDelegate BuildGetUtxoRequstCallback { get; } + internal BuildGetPaymentSourcesRequestCallbackDelegate BuildGetPaymentSourcesRequstCallback { get; } - internal ParseGetUtxoResponseCallbackDelegate ParseGetUtxoResponseCallback { get; } + internal ParseGetPaymentSourcesResponseCallbackDelegate ParseGetPaymentSourcesResponseCallback { get; } internal BuildPaymentRequestCallbackDelegate BuildPaymentRequestCallback { get; } @@ -183,6 +208,10 @@ ErrorCode ParseGetTxnFeesResponseHandler(int command_handle, string resp_json, P internal ParseGetTxnFeesResponseCallbackDelegate ParseGetTxnFeesResponseCallback { get; } + internal BuildVerifyPaymentRequestCallbackDelegate BuildVerifyPaymentRequestCallback { get; } + + internal ParseVerifyPaymentResponseCallbackDelegate ParseVerifyPaymentResponseCallback { get; } + /// /// Creates the payment address async. /// @@ -198,7 +227,8 @@ ErrorCode ParseGetTxnFeesResponseHandler(int command_handle, string resp_json, P /// Req json. /// Inputs json. /// Outputs json. - public abstract Task AddRequestFeesAsync(string submitterDid, string reqJson, string inputsJson, string outputsJson); + /// Optional exrra information about payment. + public abstract Task AddRequestFeesAsync(string submitterDid, string reqJson, string inputsJson, string outputsJson, string extra); /// /// Parses the response with fees async. @@ -213,14 +243,14 @@ ErrorCode ParseGetTxnFeesResponseHandler(int command_handle, string resp_json, P /// The get utxo request async. /// Submitted did. /// Payment address. - public abstract Task BuildGetUtxoRequestAsync(string submittedDid, string paymentAddress); + public abstract Task BuildGetPaymentSourcesRequestAsync(string submittedDid, string paymentAddress); /// /// Parses the get utxo response async. /// /// The get utxo response async. /// Response json. - public abstract Task ParseGetUtxoResponseAsync(string responseJson); + public abstract Task ParseGetPaymentSourcesResponseAsync(string responseJson); /// /// Builds the payment request async. @@ -229,7 +259,8 @@ ErrorCode ParseGetTxnFeesResponseHandler(int command_handle, string resp_json, P /// Submitter did. /// Inputs json. /// Outputs json. - public abstract Task BuildPaymentRequestAsync(string submitterDid, string inputsJson, string outputsJson); + /// Optional exrra information about payment. + public abstract Task BuildPaymentRequestAsync(string submitterDid, string inputsJson, string outputsJson, string extra); /// /// Parses the payment response async. @@ -244,7 +275,8 @@ ErrorCode ParseGetTxnFeesResponseHandler(int command_handle, string resp_json, P /// The mint request async. /// Submitter did. /// Outputs json. - public abstract Task BuildMintRequestAsync(string submitterDid, string outputsJson); + /// Optional exrra information about payment. + public abstract Task BuildMintRequestAsync(string submitterDid, string outputsJson, string extra); /// /// Builds the set txn fees async. @@ -267,5 +299,20 @@ ErrorCode ParseGetTxnFeesResponseHandler(int command_handle, string resp_json, P /// The get txn fees response async. /// Response json. public abstract Task ParseGetTxnFeesResponseAsync(string responseJson); + + /// + /// Builds the verify payment request async. + /// + /// The verify payment request async. + /// Submitter did. + /// Receipt. + public abstract Task BuildVerifyPaymentRequestAsync(string submitterDid, string receipt); + + /// + /// Parses the verify payment response async. + /// + /// The verify payment response async. + /// Response json. + public abstract Task ParseVerifyPaymentResponseAsync(string responseJson); } } \ No newline at end of file diff --git a/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/PaymentResult.cs b/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/PaymentResult.cs index d34c98fe30..d15ec17aef 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/PaymentResult.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/PaymentResult.cs @@ -1,5 +1,4 @@ -using System; -namespace Hyperledger.Indy.PaymentsApi +namespace Hyperledger.Indy.PaymentsApi { /// /// Payment result. diff --git a/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/Payments.cs b/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/Payments.cs index d5ecf84ce7..8cc402706c 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/Payments.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/PaymentsApi/Payments.cs @@ -1,9 +1,11 @@ -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; using Hyperledger.Indy.Utils; using Hyperledger.Indy.WalletApi; using static Hyperledger.Indy.PaymentsApi.NativeMethods; using static Hyperledger.Indy.Utils.CallbackHelper; +#if __IOS__ +using ObjCRuntime; +#endif namespace Hyperledger.Indy.PaymentsApi { @@ -12,7 +14,10 @@ namespace Hyperledger.Indy.PaymentsApi /// public class Payments { - static CreatePaymentAddressDelegate _createPaymentAddressCallback = (xcommand_handle, err, payment_address) => +#if __IOS__ + [MonoPInvokeCallback(typeof(CreatePaymentAddressDelegate))] +#endif + static void CreatePaymentAddressCallback(int xcommand_handle, int err, string payment_address) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -20,9 +25,12 @@ public class Payments return; taskCompletionSource.SetResult(payment_address); - }; + } - static ListPaymentAddressesDelegate _listPaymentAddressesCallback = (xcommand_handle, err, payment_addressed_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ListPaymentAddressesDelegate))] +#endif + static void ListPaymentAddressesCallback(int xcommand_handle, int err, string payment_addressed_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -30,19 +38,12 @@ public class Payments return; taskCompletionSource.SetResult(payment_addressed_json); - }; - - static IndyMethodCompletedDelegate _registerPaymentMethodCallback = (xcommand_handle, err) => - { - var taskCompletionSource = PendingCommands.Remove(xcommand_handle); - - if (!CallbackHelper.CheckCallback(taskCompletionSource, err)) - return; - - taskCompletionSource.SetResult(true); - }; + } - static AddRequestFeesDelegate _addRequestFeesCallback = (xcommand_handle, err, req_with_fees_json, payment_method) => +#if __IOS__ + [MonoPInvokeCallback(typeof(AddRequestFeesDelegate))] +#endif + static void AddRequestFeesCallback(int xcommand_handle, int err, string req_with_fees_json, string payment_method) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -50,9 +51,12 @@ public class Payments return; taskCompletionSource.SetResult(new PaymentResult(req_with_fees_json, payment_method)); - }; + } - static ParseResponseWithFeesDelegate _parseResponseWithFeesCallback = (xcommand_handle, err, utxo_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ParseResponseWithFeesDelegate))] +#endif + static void ParseResponseWithFeesCallback(int xcommand_handle, int err, string utxo_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -60,9 +64,12 @@ public class Payments return; taskCompletionSource.SetResult(utxo_json); - }; + } - static BuildGetUtxoRequstDelegate _buildGetUtxoRequestCallback = (xcommand_handle, err, get_utxo_txn_json, payment_method) => +#if __IOS__ + [MonoPInvokeCallback(typeof(BuildGetUtxoRequstDelegate))] +#endif + static void BuildGetUtxoRequestCallback(int xcommand_handle, int err, string get_utxo_txn_json, string payment_method) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -70,9 +77,12 @@ public class Payments return; taskCompletionSource.SetResult(new PaymentResult(get_utxo_txn_json, payment_method)); - }; + } - static ParseGetUtxoResponseDelegate _parseGetUtxoResponseCallback = (xcommand_handle, err, utxo_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ParseGetUtxoResponseDelegate))] +#endif + static void ParseGetUtxoResponseCallback(int xcommand_handle, int err, string utxo_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -80,9 +90,12 @@ public class Payments return; taskCompletionSource.SetResult(utxo_json); - }; + } - static BuildPaymentRequestDelegate _buildPaymentRequestCallback = (xcommand_handle, err, payment_req_json, payment_method) => +#if __IOS__ + [MonoPInvokeCallback(typeof(BuildPaymentRequestDelegate))] +#endif + static void BuildPaymentRequestCallback(int xcommand_handle, int err, string payment_req_json, string payment_method) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -90,9 +103,12 @@ public class Payments return; taskCompletionSource.SetResult(new PaymentResult(payment_req_json, payment_method)); - }; + } - static ParsePaymentResponseDelegate _parsePaymentResponseCallback = (xcommand_handle, err, utxo_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ParsePaymentResponseDelegate))] +#endif + static void ParsePaymentResponseCallback(int xcommand_handle, int err, string utxo_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -100,9 +116,12 @@ public class Payments return; taskCompletionSource.SetResult(utxo_json); - }; + } - static BuildMintReqDelegate _buildMintRequestCallback = (xcommand_handle, err, mint_req_json, payment_method) => +#if __IOS__ + [MonoPInvokeCallback(typeof(BuildMintReqDelegate))] +#endif + static void BuildMintRequestCallback(int xcommand_handle, int err, string mint_req_json, string payment_method) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -110,9 +129,12 @@ public class Payments return; taskCompletionSource.SetResult(new PaymentResult(mint_req_json, payment_method)); - }; + } - static BuildSetTxnFeesReqDelegate _buildSetTxnFeesReqCallback = (xcommand_handle, err, set_txn_fees_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(BuildSetTxnFeesReqDelegate))] +#endif + static void BuildSetTxnFeesReqCallback(int xcommand_handle, int err, string set_txn_fees_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -120,9 +142,12 @@ public class Payments return; taskCompletionSource.SetResult(set_txn_fees_json); - }; + } - static BuildGetTxnFeesReqDelegate _buildGetTxnFeesReqCallback = (xcommand_handle, err, get_txn_fees_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(BuildGetTxnFeesReqDelegate))] +#endif + static void BuildGetTxnFeesReqCallback(int xcommand_handle, int err, string get_txn_fees_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -130,17 +155,46 @@ public class Payments return; taskCompletionSource.SetResult(get_txn_fees_json); - }; + } - static ParseGetUtxoResponseDelegate _parseGetTxnFeesResponseCallback = (xcommand_handle, err, utxo_json) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ParseGetTxnFeesResponseDelegate))] +#endif + static void ParseGetTxnFeesResponseCallback(int xcommand_handle, int err, string get_txn_fees_json) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); if (!CallbackHelper.CheckCallback(taskCompletionSource, err)) return; - taskCompletionSource.SetResult(utxo_json); - }; + taskCompletionSource.SetResult(get_txn_fees_json); + } + +#if __IOS__ + [MonoPInvokeCallback(typeof(BuildVerifyPaymentRequestDelegate))] +#endif + static void BuildVerifyPaymentRequestCallback(int xcommand_handle, int err, string verify_txn_json, string payment_method) + { + var taskCompletionSource = PendingCommands.Remove(xcommand_handle); + + if (!CallbackHelper.CheckCallback(taskCompletionSource, err)) + return; + + taskCompletionSource.SetResult(new PaymentResult(verify_txn_json, payment_method)); + } + +#if __IOS__ + [MonoPInvokeCallback(typeof(ParseVerifyPaymentResponseDelegate))] +#endif + static void ParseVerifyPaymentResponseDelegate(int xcommand_handle, int err, string txn_json) + { + var taskCompletionSource = PendingCommands.Remove(xcommand_handle); + + if (!CallbackHelper.CheckCallback(taskCompletionSource, err)) + return; + + taskCompletionSource.SetResult(txn_json); + } /// /// Create the payment address for this payment method. @@ -175,7 +229,7 @@ public static Task CreatePaymentAddressAsync(Wallet wallet, string payme wallet.Handle, paymentMethod, config, - _createPaymentAddressCallback); + CreatePaymentAddressCallback); CallbackHelper.CheckResult(result); @@ -200,7 +254,7 @@ public static Task ListPaymentAddressesAsync(Wallet wallet) var result = NativeMethods.indy_list_payment_addresses( commandHandle, wallet.Handle, - _listPaymentAddressesCallback); + ListPaymentAddressesCallback); CallbackHelper.CheckResult(result); @@ -232,15 +286,17 @@ public static Task RegisterPaymentMethodAsync(string paymentMethod, PaymentMetho implementation.CreatePaymentAddressCallback, implementation.AddRequestFeesCallback, implementation.ParseResponseWithFeesCallback, - implementation.BuildGetUtxoRequstCallback, - implementation.ParseGetUtxoResponseCallback, + implementation.BuildGetPaymentSourcesRequstCallback, + implementation.ParseGetPaymentSourcesResponseCallback, implementation.BuildPaymentRequestCallback, implementation.ParsePaymentResponseCallback, implementation.BuildMintReqCallback, implementation.BuildSetTxnFeesReqCallback, implementation.BuildGetTxnFeesReqCallback, implementation.ParseGetTxnFeesResponseCallback, - _registerPaymentMethodCallback); + implementation.BuildVerifyPaymentRequestCallback, + implementation.ParseVerifyPaymentResponseCallback, + CallbackHelper.TaskCompletingNoValueCallback); CallbackHelper.CheckResult(result); @@ -295,7 +351,7 @@ public static Task AddRequestFeesAsync(Wallet wallet, string subm reqJson, inputsJson, outputsJson, - _addRequestFeesCallback); + AddRequestFeesCallback); CallbackHelper.CheckResult(result); @@ -330,7 +386,7 @@ public static Task ParseResponseWithFeesAsync(string paymentMethod, stri commandHandle, paymentMethod, responseJson, - _parseResponseWithFeesCallback); + ParseResponseWithFeesCallback); CallbackHelper.CheckResult(result); @@ -349,7 +405,7 @@ public static Task ParseResponseWithFeesAsync(string paymentMethod, stri /// Wallet. /// DID of request sender /// target payment address - public static Task BuildGetUtxoRequestAsync(Wallet wallet, string submittedDid, string paymentAddress) + public static Task BuildGetPaymentSourcesAsync(Wallet wallet, string submittedDid, string paymentAddress) { ParamGuard.NotNullOrWhiteSpace(submittedDid, "submittedDid"); ParamGuard.NotNullOrWhiteSpace(paymentAddress, "paymentAddress"); @@ -357,12 +413,12 @@ public static Task BuildGetUtxoRequestAsync(Wallet wallet, string var taskCompletionSource = new TaskCompletionSource(); var commandHandle = PendingCommands.Add(taskCompletionSource); - var result = NativeMethods.indy_build_get_utxo_request( + var result = NativeMethods.indy_build_get_payment_sources_request( commandHandle, wallet.Handle, submittedDid, paymentAddress, - _buildGetUtxoRequestCallback); + BuildGetUtxoRequestCallback); CallbackHelper.CheckResult(result); @@ -385,18 +441,18 @@ public static Task BuildGetUtxoRequestAsync(Wallet wallet, string /// Payment method. /// response for Indy request for getting UTXO list /// Note: this param will be used to determine payment_method - public static Task ParseGetUtxoResponseAsync(string paymentMethod, string responseJson) + public static Task ParseGetPaymentSourcesAsync(string paymentMethod, string responseJson) { ParamGuard.NotNullOrWhiteSpace(responseJson, "responseJson"); var taskCompletionSource = new TaskCompletionSource(); var commandHandle = PendingCommands.Add(taskCompletionSource); - var result = NativeMethods.indy_parse_get_utxo_response( + var result = NativeMethods.indy_parse_get_payment_sources_response( commandHandle, paymentMethod, responseJson, - _parseGetUtxoResponseCallback); + ParseGetUtxoResponseCallback); CallbackHelper.CheckResult(result); @@ -427,7 +483,8 @@ public static Task ParseGetUtxoResponseAsync(string paymentMethod, strin /// amount: <int>, // amount of tokens to transfer to this payment address /// extra: <str>, // optional data /// }] - public static Task BuildPaymentRequestAsync(Wallet wallet, string submitterDid, string inputsJson, string outputsJson) + /// Optional information for payment operation + public static Task BuildPaymentRequestAsync(Wallet wallet, string submitterDid, string inputsJson, string outputsJson, string extra) { ParamGuard.NotNull(wallet, "wallet"); ParamGuard.NotNullOrWhiteSpace(submitterDid, "submitterDid"); @@ -443,7 +500,8 @@ public static Task BuildPaymentRequestAsync(Wallet wallet, string submitterDid, inputsJson, outputsJson, - _buildPaymentRequestCallback); + extra, + BuildPaymentRequestCallback); CallbackHelper.CheckResult(result); @@ -478,7 +536,7 @@ public static Task ParsePaymentResponseAsync(string paymentMethod, strin commandHandle, paymentMethod, responseJson, - _parsePaymentResponseCallback); + ParsePaymentResponseCallback); CallbackHelper.CheckResult(result); @@ -501,7 +559,8 @@ public static Task ParsePaymentResponseAsync(string paymentMethod, strin /// amount: <int>, // amount of tokens to transfer to this payment address /// extra: <str>, // optional data /// }] - public static Task BuildMintRequestAsync(Wallet wallet, string submitterDid, string outputsJson) + /// Optional information for payment operation + public static Task BuildMintRequestAsync(Wallet wallet, string submitterDid, string outputsJson, string extra) { ParamGuard.NotNull(wallet, "wallet"); ParamGuard.NotNullOrWhiteSpace(submitterDid, "submitterDid"); @@ -515,7 +574,8 @@ public static Task BuildMintRequestAsync(Wallet wallet, string su wallet.Handle, submitterDid, outputsJson, - _buildMintRequestCallback); + extra, + BuildMintRequestCallback); CallbackHelper.CheckResult(result); @@ -555,7 +615,7 @@ public static Task BuildSetTxnFeesRequestAsync(Wallet wallet, string sub submitterDid, paymentMethod, feesJson, - _buildSetTxnFeesReqCallback); + BuildSetTxnFeesReqCallback); CallbackHelper.CheckResult(result); @@ -586,7 +646,7 @@ public static Task BuildGetTxnFeesRequestAsync(Wallet wallet, string sub wallet.Handle, submitterDid, paymentMethod, - _buildGetTxnFeesReqCallback); + BuildGetTxnFeesReqCallback); CallbackHelper.CheckResult(result); @@ -615,11 +675,72 @@ public static Task ParseGetTxnFeesResponseAsync(string paymentMethod, st var taskCompletionSource = new TaskCompletionSource(); var commandHandle = PendingCommands.Add(taskCompletionSource); - var result = NativeMethods.indy_parse_get_utxo_response( + var result = NativeMethods.indy_parse_get_txn_fees_response( + commandHandle, + paymentMethod, + responseJson, + ParseGetTxnFeesResponseCallback); + + CallbackHelper.CheckResult(result); + + return taskCompletionSource.Task; + } + + /// + /// Builds Indy request for information to verify the payment receipt + /// + /// Indy request for verification receipt. + /// Wallet. + /// DID of request sender + /// Payment receipt to verify. + public static Task BuildVerifyPaymentRequestAsync(Wallet wallet, string submitterDid, string receipt) + { + ParamGuard.NotNull(wallet, "wallet"); + ParamGuard.NotNullOrWhiteSpace(submitterDid, "submitterDid"); + ParamGuard.NotNullOrWhiteSpace(receipt, "receipt"); + + var taskCompletionSource = new TaskCompletionSource(); + var commandHandle = PendingCommands.Add(taskCompletionSource); + + var result = NativeMethods.indy_build_verify_payment_req( + commandHandle, + wallet.Handle, + submitterDid, + receipt, + BuildVerifyPaymentRequestCallback); + + CallbackHelper.CheckResult(result); + + return taskCompletionSource.Task; + } + + /// + /// Parses Indy response with information to verify receipt + /// + /// txn_json: { + /// sources: [<str>, ] + /// receipts: [ { + /// recipient: <str>, // payment address of recipient + /// receipt: <str>, // receipt that can be used for payment referencing and verification + /// amount: <int>, // amount + /// } ], + /// extra: <str>, //optional data + /// } + /// Payment method to use. + /// Response of the ledger for verify txn. + public static Task ParseVerifyPaymentResponseAsync(string paymentMethod, string responseJson) + { + ParamGuard.NotNullOrWhiteSpace(paymentMethod, "paymentMethod"); + ParamGuard.NotNullOrWhiteSpace(responseJson, "responseJson"); + + var taskCompletionSource = new TaskCompletionSource(); + var commandHandle = PendingCommands.Add(taskCompletionSource); + + var result = NativeMethods.indy_parse_verify_payment_response( commandHandle, paymentMethod, responseJson, - _parseGetTxnFeesResponseCallback); + ParseVerifyPaymentResponseDelegate); CallbackHelper.CheckResult(result); diff --git a/wrappers/dotnet/indy-sdk-dotnet/PoolApi/Pool.cs b/wrappers/dotnet/indy-sdk-dotnet/PoolApi/Pool.cs index 0c10e3e513..22d9b1aac3 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/PoolApi/Pool.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/PoolApi/Pool.cs @@ -2,6 +2,9 @@ using System; using System.Threading.Tasks; using static Hyperledger.Indy.PoolApi.NativeMethods; +#if __IOS__ +using ObjCRuntime; +#endif namespace Hyperledger.Indy.PoolApi { @@ -10,11 +13,14 @@ namespace Hyperledger.Indy.PoolApi /// connections to pools. /// public sealed class Pool : IDisposable - { + { /// /// Callback to use when a pool open command has completed. /// - private static OpenPoolLedgerCompletedDelegate _openPoolLedgerCallback = (command_handle, err, pool_handle) => +#if __IOS__ + [MonoPInvokeCallback(typeof(OpenPoolLedgerCompletedDelegate))] +#endif + private static void OpenPoolLedgerCallback(int command_handle, int err, IntPtr pool_handle) { var taskCompletionSource = PendingCommands.Remove(command_handle); @@ -22,12 +28,15 @@ public sealed class Pool : IDisposable return; taskCompletionSource.SetResult(new Pool(pool_handle)); - }; - + } + /// /// Callback to use when list pools command has completed. /// - private static ListPoolsCompletedDelegate _listPoolsCallback = (command_handle, err, pools) => +#if __IOS__ + [MonoPInvokeCallback(typeof(ListPoolsCompletedDelegate))] +#endif + private static void ListPoolsCallback(int command_handle, int err, string pools) { var taskCompletionSource = PendingCommands.Remove(command_handle); @@ -35,7 +44,7 @@ public sealed class Pool : IDisposable return; taskCompletionSource.SetResult(pools); - }; + } /// /// Creates a new local pool configuration with the specified name that can be used later to open a connection to @@ -144,7 +153,7 @@ public static Task OpenPoolLedgerAsync(string configName, string config) commandHandle, configName, config, - _openPoolLedgerCallback + OpenPoolLedgerCallback ); CallbackHelper.CheckResult(result); @@ -163,7 +172,7 @@ public static Task ListPoolsAsync() var result = NativeMethods.indy_list_pools( commandHandle, - _listPoolsCallback + ListPoolsCallback ); CallbackHelper.CheckResult(result); diff --git a/wrappers/dotnet/indy-sdk-dotnet/Utils/CallbackHelper.cs b/wrappers/dotnet/indy-sdk-dotnet/Utils/CallbackHelper.cs index 67b8dd1828..764f592843 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/Utils/CallbackHelper.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/Utils/CallbackHelper.cs @@ -1,5 +1,8 @@ using System.Threading.Tasks; -using static Hyperledger.Indy.Consts; + +#if __IOS__ +using ObjCRuntime; +#endif namespace Hyperledger.Indy.Utils { @@ -11,11 +14,14 @@ internal static class CallbackHelper /// The handle for the command that initiated the callback. /// The outcome of execution of the command. internal delegate void IndyMethodCompletedDelegate(int xcommand_handle, int err); - + /// /// Gets the callback to use for completing tasks that don't return a value. /// - public static IndyMethodCompletedDelegate TaskCompletingNoValueCallback = (xcommand_handle, err) => +#if __IOS__ + [MonoPInvokeCallback(typeof(IndyMethodCompletedDelegate))] +#endif + public static void TaskCompletingNoValueCallback(int xcommand_handle, int err) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -23,15 +29,18 @@ internal static class CallbackHelper return; taskCompletionSource.SetResult(true); - }; - + } + /// /// Gets the callback to use for functions that don't return a value and are not associated with a task. /// - public static IndyMethodCompletedDelegate NoValueCallback = (xcommand_handle, err) => +#if __IOS__ + [MonoPInvokeCallback(typeof(IndyMethodCompletedDelegate))] +#endif + public static void NoValueCallback(int xcommand_handle, int err) { CheckCallback(err); - }; + } /// /// Checks the result from a Sovrin function call. diff --git a/wrappers/dotnet/indy-sdk-dotnet/Utils/PendingCommands.cs b/wrappers/dotnet/indy-sdk-dotnet/Utils/PendingCommands.cs index 470dcea112..2173ccea78 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/Utils/PendingCommands.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/Utils/PendingCommands.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Concurrent; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Threading; diff --git a/wrappers/dotnet/indy-sdk-dotnet/WalletApi/NativeMethods.cs b/wrappers/dotnet/indy-sdk-dotnet/WalletApi/NativeMethods.cs index fb0f835b48..4f5e3b1b60 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/WalletApi/NativeMethods.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/WalletApi/NativeMethods.cs @@ -6,6 +6,7 @@ namespace Hyperledger.Indy.WalletApi { internal static class NativeMethods { + /* /// /// Registers custom wallet implementation. /// @@ -24,6 +25,7 @@ internal static class NativeMethods /// 0 if the command was initiated successfully. Any non-zero result indicates an error. [DllImport(Consts.NATIVE_LIB_NAME, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] internal static extern int indy_register_wallet_type(int command_handle, string xtype, WalletTypeCreateDelegate create, WalletTypeOpenDelegate open, WalletTypeSetDelegate set, WalletTypeGetDelegate get, WalletTypeGetNotExpiredDelegate get_not_expired, WalletTypeListDelegate list, WalletTypeCloseDelegate close, WalletTypeDeleteDelegate delete, WalletTypeFreeDelegate free, IndyMethodCompletedDelegate cb); + */ /// /// Delegate for the function called back to when a wallet of a custom type is created. diff --git a/wrappers/dotnet/indy-sdk-dotnet/WalletApi/Wallet.cs b/wrappers/dotnet/indy-sdk-dotnet/WalletApi/Wallet.cs index 70989dbe9c..8cce5e0198 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/WalletApi/Wallet.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/WalletApi/Wallet.cs @@ -3,6 +3,9 @@ using System.Collections.Concurrent; using System.Threading.Tasks; using static Hyperledger.Indy.WalletApi.NativeMethods; +#if __IOS__ +using ObjCRuntime; +#endif namespace Hyperledger.Indy.WalletApi { @@ -15,12 +18,15 @@ public sealed class Wallet : IDisposable /// /// Wallet type registrations by type name. /// - private static ConcurrentBag _registeredWalletTypes = new ConcurrentBag(); - + private static ConcurrentBag _registeredWalletTypes = new ConcurrentBag(); + /// /// Gets the callback to use when a wallet open command has completed. /// - private static OpenWalletCompletedDelegate _openWalletCallback = (xcommand_handle, err, wallet_handle) => +#if __IOS__ + [MonoPInvokeCallback(typeof(OpenWalletCompletedDelegate))] +#endif + private static void OpenWalletCallback(int xcommand_handle, int err, IntPtr wallet_handle) { var taskCompletionSource = PendingCommands.Remove(xcommand_handle); @@ -28,7 +34,7 @@ public sealed class Wallet : IDisposable return; taskCompletionSource.SetResult(new Wallet(wallet_handle)); - }; + } ///// ///// Registers a custom wallet type implementation. @@ -182,7 +188,7 @@ public static Task OpenWalletAsync(string config, string credentials) commandHandle, config, credentials, - _openWalletCallback + OpenWalletCallback ); CallbackHelper.CheckResult(result); diff --git a/wrappers/dotnet/indy-sdk-dotnet/WalletApi/WalletItemNotFoundException.cs b/wrappers/dotnet/indy-sdk-dotnet/WalletApi/WalletItemNotFoundException.cs new file mode 100644 index 0000000000..1d0821f005 --- /dev/null +++ b/wrappers/dotnet/indy-sdk-dotnet/WalletApi/WalletItemNotFoundException.cs @@ -0,0 +1,16 @@ +namespace Hyperledger.Indy.WalletApi +{ + /// + /// Exception thrown when value with the specified key doesn't exists in the wallet from which it was requested. + /// + /// + public class WalletItemNotFoundException : IndyException + { + private const string message = + "No value with the specified key exists in the wallet from which it was requested."; + + internal WalletItemNotFoundException() : base(message, (int)ErrorCode.WalletItemNotFoundError) + { + } + } +} diff --git a/wrappers/dotnet/indy-sdk-dotnet/WalletApi/WalletType.cs b/wrappers/dotnet/indy-sdk-dotnet/WalletApi/WalletType.cs index 74b6858f46..50a1030e71 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/WalletApi/WalletType.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/WalletApi/WalletType.cs @@ -2,7 +2,6 @@ using System; using System.Runtime.InteropServices; using System.Text; -using static Hyperledger.Indy.Consts; using static Hyperledger.Indy.WalletApi.NativeMethods; namespace Hyperledger.Indy.WalletApi diff --git a/wrappers/dotnet/indy-sdk-dotnet/indy-sdk-dotnet.csproj b/wrappers/dotnet/indy-sdk-dotnet/indy-sdk-dotnet.csproj index ceab37a79d..44692830af 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/indy-sdk-dotnet.csproj +++ b/wrappers/dotnet/indy-sdk-dotnet/indy-sdk-dotnet.csproj @@ -1,13 +1,13 @@ - + - netstandard1.1 + netstandard1.1;xamarinios10 Hyperledger.Indy.Sdk Hyperledger.Indy - False - 1.4.0 + true + 1.6.2 false - Symon Rottem + Symon Rottem, Tomislav Markovski Hyperledger Indy Hyperledger Indy SDK .NET wrapper for the Hyperledger Indy SDK. @@ -19,8 +19,8 @@ Please note that to function the C-Callable Hyperledger Indy SDK and its depende hyperledger indy sdk https://github.com/hyperledger/indy-sdk/blob/master/LICENSE - 1.4.0.0 - 1.4.0.0 + 1.6.2 + 1.6.2 @@ -29,8 +29,4 @@ Please note that to function the C-Callable Hyperledger Indy SDK and its depende - - - - \ No newline at end of file diff --git a/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Wallet/WalletHighCases.m b/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Wallet/WalletHighCases.m index 2ec6ebaaec..7303ae2537 100644 --- a/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Wallet/WalletHighCases.m +++ b/wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Wallet/WalletHighCases.m @@ -356,5 +356,20 @@ - (void)testImportWalletWorks { [[NSFileManager defaultManager] removeItemAtPath:exportFile error:nil]; } +// MARK: - Generate wallet key + +- (void)testGenerateWalletKeyWorks { + NSString *key; + NSError *ret = [[WalletUtils sharedInstance] generateWalletKeyForConfig:nil key:&key]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:generateWalletKeyForConfig failed"); +} + +- (void)testGenerateWalletKeyWorksForSeed { + NSString *key; + NSError *ret = [[WalletUtils sharedInstance] generateWalletKeyForConfig:[NSString stringWithFormat:@"{\"seed\":\"%@\"}", [TestUtils mySeed1]] + key:&key]; + XCTAssertEqual(ret.code, Success, @"WalletUtils:generateWalletKeyForConfig failed"); + XCTAssertEqualObjects(key, @"CwMHrEQJnwvuE8q9zbR49jyYtVxVBHNTjCPEPk1aV3cP"); +} @end diff --git a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/PoolUtils.m b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/PoolUtils.m index 52f70f1fa7..9cba15bb74 100644 --- a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/PoolUtils.m +++ b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/PoolUtils.m @@ -49,13 +49,13 @@ - (NSString *)createGenesisTxnFileForTestPool:(NSString *)poolName } NSString *nodeIp = [TestUtils testPoolIp]; - NSString *node1 = [NSString stringWithFormat:@"{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node1\",\"blskey\":\"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba\",\"client_ip\":\"%@\",\"client_port\":9702,\"node_ip\":\"%@\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\"},\"metadata\":{\"from\":\"Th7MpTaRZVRYnPiabds81Y\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":1,\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\"},\"ver\":\"1\"}", nodeIp, nodeIp]; + NSString *node1 = [NSString stringWithFormat:@"{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node1\",\"blskey\":\"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba\",\"blskey_pop\":\"RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1\",\"client_ip\":\"%@\",\"client_port\":9702,\"node_ip\":\"%@\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\"},\"metadata\":{\"from\":\"Th7MpTaRZVRYnPiabds81Y\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":1,\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\"},\"ver\":\"1\"}", nodeIp, nodeIp]; - NSString *node2 = [NSString stringWithFormat:@"{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node2\",\"blskey\":\"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk\",\"client_ip\":\"%@\",\"client_port\":9704,\"node_ip\":\"%@\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\"},\"metadata\":{\"from\":\"EbP4aYNeTHL6q385GuVpRV\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":2,\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\"},\"ver\":\"1\"}", nodeIp, nodeIp]; + NSString *node2 = [NSString stringWithFormat:@"{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node2\",\"blskey\":\"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk\",\"blskey_pop\":\"Qr658mWZ2YC8JXGXwMDQTzuZCWF7NK9EwxphGmcBvCh6ybUuLxbG65nsX4JvD4SPNtkJ2w9ug1yLTj6fgmuDg41TgECXjLCij3RMsV8CwewBVgVN67wsA45DFWvqvLtu4rjNnE9JbdFTc1Z4WCPA3Xan44K1HoHAq9EVeaRYs8zoF5\",\"client_ip\":\"%@\",\"client_port\":9704,\"node_ip\":\"%@\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\"},\"metadata\":{\"from\":\"EbP4aYNeTHL6q385GuVpRV\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":2,\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\"},\"ver\":\"1\"}", nodeIp, nodeIp]; - NSString *node3 = [NSString stringWithFormat:@"{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node3\",\"blskey\":\"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5\",\"client_ip\":\"%@\",\"client_port\":9706,\"node_ip\":\"%@\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\"},\"metadata\":{\"from\":\"4cU41vWW82ArfxJxHkzXPG\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":3,\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\"},\"ver\":\"1\"}", nodeIp, nodeIp]; + NSString *node3 = [NSString stringWithFormat:@"{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node3\",\"blskey\":\"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5\",\"blskey_pop\":\"QwDeb2CkNSx6r8QC8vGQK3GRv7Yndn84TGNijX8YXHPiagXajyfTjoR87rXUu4G4QLk2cF8NNyqWiYMus1623dELWwx57rLCFqGh7N4ZRbGDRP4fnVcaKg1BcUxQ866Ven4gw8y4N56S5HzxXNBZtLYmhGHvDtk6PFkFwCvxYrNYjh\",\"client_ip\":\"%@\",\"client_port\":9706,\"node_ip\":\"%@\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\"},\"metadata\":{\"from\":\"4cU41vWW82ArfxJxHkzXPG\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":3,\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\"},\"ver\":\"1\"}", nodeIp, nodeIp]; - NSString *node4 = [NSString stringWithFormat:@"{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node4\",\"blskey\":\"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw\",\"client_ip\":\"%@\",\"client_port\":9708,\"node_ip\":\"%@\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\"},\"metadata\":{\"from\":\"TWwCRQRZ2ZHMJFn9TzLp7W\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":4,\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\"},\"ver\":\"1\"}", nodeIp, nodeIp]; + NSString *node4 = [NSString stringWithFormat:@"{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node4\",\"blskey\":\"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw\",\"blskey_pop\":\"RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP\",\"client_ip\":\"%@\",\"client_port\":9708,\"node_ip\":\"%@\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\"},\"metadata\":{\"from\":\"TWwCRQRZ2ZHMJFn9TzLp7W\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":4,\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\"},\"ver\":\"1\"}", nodeIp, nodeIp]; NSArray *nodesArray = [NSArray arrayWithObjects:node1, node2, node3, node4, nil]; NSArray *requiredNodes = [nodesArray subarrayWithRange:NSMakeRange(0, nodes)]; diff --git a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/WalletUtils.h b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/WalletUtils.h index 906589ba3e..24a5f22faf 100644 --- a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/WalletUtils.h +++ b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/WalletUtils.h @@ -30,4 +30,8 @@ - (NSError *)importWalletWithConfig:(NSString *)config importConfigJson:(NSString *)importConfigJson; + +- (NSError *)generateWalletKeyForConfig:(NSString *)configJson + key:(NSString **)key; + @end diff --git a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/WalletUtils.m b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/WalletUtils.m index a51cc96add..3cbf4fa283 100644 --- a/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/WalletUtils.m +++ b/wrappers/ios/libindy-pod/Indy-demoTests/Test Utils/WalletUtils.m @@ -195,4 +195,21 @@ - (NSError *)importWalletWithConfig:(NSString *)config return err; } +- (NSError *)generateWalletKeyForConfig:(NSString *)configJson + key:(NSString **)key { + XCTestExpectation *completionExpectation = [[XCTestExpectation alloc] initWithDescription:@"completion finished"]; + __block NSError *err = nil; + + [IndyWallet generateWalletKeyForConfig:configJson + completion:^(NSError *error, NSString *res) { + err = error; + if (key) *key = res; + [completionExpectation fulfill]; + }]; + + [self waitForExpectations:@[completionExpectation] timeout:[TestUtils defaultTimeout]]; + + return err; +} + @end diff --git a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyWallet.h b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyWallet.h index 5ae5ab7734..a3d46972fe 100644 --- a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyWallet.h +++ b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyWallet.h @@ -59,13 +59,16 @@ @param credentials Wallet credentials json { - "key": string, Passphrase used to derive wallet master key + "key": string, Key or passphrase used for wallet key derivation. + Look to key_derivation_method param for information about supported key derivation methods. "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. Can be optional if storage supports default configuration. For 'default' storage type should be empty. - "key_derivation_method": optional algorithm to use for master key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster} + "key_derivation_method": optional Algorithm to use for wallet key derivation: + ARGON2I_MOD - derive secured wallet master key (used by default) + ARGON2I_INT - derive secured wallet master key (less secured but faster) + RAW - raw wallet key master provided (skip derivation). + RAW keys can be generated with generateWalletKeyForConfig call } @param completion Completion callback that returns error code. */ @@ -99,22 +102,29 @@ @param credentials Wallet credentials json { - "key": string, Passphrase used to derive wallet master key + "key": string, Key or passphrase used for wallet key derivation. + Look to key_derivation_method param for information about supported key derivation methods. + "rekey": optional, If present than wallet master key will be rotated to a new one. "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. Can be optional if storage supports default configuration. For 'default' storage type should be empty. - "key_derivation_method": optional algorithm to use for master key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster} - "rekey_derivation_method": optional algorithm to use for master rekey derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster} } + "key_derivation_method": optional Algorithm to use for wallet key derivation: + ARGON2I_MOD - derive secured wallet master key (used by default) + ARGON2I_INT - derive secured wallet master key (less secured but faster) + RAW - raw wallet key master provided (skip derivation). + RAW keys can be generated with generateWalletKeyForConfig call + "rekey_derivation_method": optional Algorithm to use for wallet rekey derivation: + ARGON2I_MOD - derive secured wallet master key (used by default) + ARGON2I_INT - derive secured wallet master key (less secured but faster) + RAW - raw wallet rekey master provided (skip derivation). + RAW keys can be generated with generateWalletKeyForConfig call + } @param completion Completion callback that returns error code and created handle to opened wallet to use in methods that require wallet access. */ - (void)openWalletWithConfig:(NSString *)config - credentials:(NSString *)credentials - completion:(void (^)(NSError *error, IndyHandle walletHandle))completion; + credentials:(NSString *)credentials + completion:(void (^)(NSError *error, IndyHandle walletHandle))completion; /** Closes opened wallet and frees allocated resources. @@ -147,18 +157,23 @@ @param credentials Wallet credentials json { - "key": string, Passphrase used to derive wallet master key + "key": string, Key or passphrase used for wallet key derivation. + Look to key_derivation_method param for information about supported key derivation methods. "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. Can be optional if storage supports default configuration. For 'default' storage type should be empty. - "key_derivation_method": optional algorithm to use for master key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster} } + "key_derivation_method": optional Algorithm to use for wallet key derivation: + ARGON2I_MOD - derive secured wallet master key (used by default) + ARGON2I_INT - derive secured wallet master key (less secured but faster) + RAW - raw wallet key master provided (skip derivation). + RAW keys can be generated with generateWalletKeyForConfig call + } + @param completion Completion callback that returns error code. */ - (void)deleteWalletWithConfig:(NSString *)config - credentials:(NSString *)credentials - completion:(void (^)(NSError *error))completion; + credentials:(NSString *)credentials + completion:(void (^)(NSError *error))completion; /** @@ -168,10 +183,14 @@ @param exportConfigJson JSON containing settings for input operation. { "path": path of the file that contains exported wallet content - "key": passphrase used to export key - "key_derivation_method": optional algorithm to use for export key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster} } + "key": string, Key or passphrase used for wallet export key derivation. + Look to key_derivation_method param for information about supported key derivation methods. + "key_derivation_method": optional Algorithm to use for wallet export key derivation: + ARGON2I_MOD - derive secured wallet export key (used by default) + ARGON2I_INT - derive secured wallet export key (less secured but faster) + RAW - raw wallet export key provided (skip derivation). + RAW keys can be generated with generateWalletKeyForConfig call + } @param completion Completion callback that returns error code. */ - (void)exportWalletWithHandle:(IndyHandle)walletHandle @@ -202,24 +221,43 @@ @param credentials Wallet credentials json { - "key": string, Passphrase used to derive wallet master key + "key": string, Key or passphrase used for wallet key derivation. + Look to key_derivation_method param for information about supported key derivation methods. "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. Can be optional if storage supports default configuration. For 'default' storage type should be empty. - "key_derivation_method": optional algorithm to use for master key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster} } + "key_derivation_method": optional Algorithm to use for wallet key derivation: + ARGON2I_MOD - derive secured wallet master key (used by default) + ARGON2I_INT - derive secured wallet master key (less secured but faster) + RAW - raw wallet key master provided (skip derivation). + RAW keys can be generated with generateWalletKeyForConfig call + } @param importConfigJson JSON containing settings for input operation. { "path": path of the file that contains exported wallet content - "key": passphrase used to export key + "key": Key used for export of the wallet } @param completion Completion callback that returns error code. */ - (void)importWalletWithConfig:(NSString *)config - credentials:(NSString *)credentials - importConfigJson:(NSString *)importConfigJson - completion:(void (^)(NSError *error))completion; + credentials:(NSString *)credentials + importConfigJson:(NSString *)importConfigJson + completion:(void (^)(NSError *error))completion; + +/** + Generate wallet master key. + Returned key is compatible with "RAW" key derivation method. + It allows to avoid expensive key derivation for use cases when wallet keys can be stored in a secure enclave. + + @param configJson (optional) key configuration json. + { + "seed": optional Seed that allows deterministic key creation (if not set random one will be used). + } + @param completion Completion callback that returns error code. + */ ++ (void)generateWalletKeyForConfig:(NSString *)configJson + completion:(void (^)(NSError *error, + NSString *key))completion; /** Delete all keychain wallets from Keychain. diff --git a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyWallet.mm b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyWallet.mm index a16a52ebd2..936372a96e 100644 --- a/wrappers/ios/libindy-pod/Indy/Wrapper/IndyWallet.mm +++ b/wrappers/ios/libindy-pod/Indy/Wrapper/IndyWallet.mm @@ -95,8 +95,8 @@ - (void)registerIndyKeychainWalletType:(NSString *)type } - (void)createWalletWithConfig:(NSString *)config - credentials:(NSString *)credentials - completion:(void (^)(NSError *error))completion { + credentials:(NSString *)credentials + completion:(void (^)(NSError *error))completion { indy_error_t ret; [completion copy]; @@ -117,8 +117,8 @@ - (void)createWalletWithConfig:(NSString *)config } - (void)openWalletWithConfig:(NSString *)config - credentials:(NSString *)credentials - completion:(void (^)(NSError *error, IndyHandle walletHandle))completion { + credentials:(NSString *)credentials + completion:(void (^)(NSError *error, IndyHandle walletHandle))completion { indy_error_t ret; //id hghg = [completion copy]; @@ -160,8 +160,8 @@ - (void)closeWalletWithHandle:(IndyHandle)walletHandle } - (void)deleteWalletWithConfig:(NSString *)config - credentials:(NSString *)credentials - completion:(void (^)(NSError *error))completion { + credentials:(NSString *)credentials + completion:(void (^)(NSError *error))completion { indy_error_t ret; indy_handle_t handle = [[IndyCallbacks sharedInstance] createCommandHandleFor:completion]; @@ -205,9 +205,9 @@ - (void)exportWalletWithHandle:(IndyHandle)walletHandle } - (void)importWalletWithConfig:(NSString *)config - credentials:(NSString *)credentials - importConfigJson:(NSString *)importConfigJson - completion:(void (^)(NSError *error))completion { + credentials:(NSString *)credentials + importConfigJson:(NSString *)importConfigJson + completion:(void (^)(NSError *error))completion { indy_error_t ret; [completion copy]; @@ -228,6 +228,14 @@ - (void)importWalletWithConfig:(NSString *)config } } ++ (void)generateWalletKeyForConfig:(NSString *)configJson + completion:(void (^)(NSError *error, NSString *key))completion { + indy_handle_t handle = [[IndyCallbacks sharedInstance] createCommandHandleFor:completion]; + indy_error_t ret = indy_generate_wallet_key(handle, [configJson UTF8String], IndyWrapperCommonStringCallback); + + [[IndyCallbacks sharedInstance] completeStr:completion forHandle:handle ifError:ret]; +} + - (void)cleanupIndyKeychainWallet { [[IndyKeychainWallet sharedInstance] cleanup]; } diff --git a/wrappers/ios/libindy-pod/Podfile b/wrappers/ios/libindy-pod/Podfile index c70d673520..d29eb3e99c 100644 --- a/wrappers/ios/libindy-pod/Podfile +++ b/wrappers/ios/libindy-pod/Podfile @@ -8,7 +8,7 @@ def appPods pod 'libsodium' pod 'libzmq',"4.2.3" pod 'OpenSSL' - pod 'libindy', "1.5.0" + pod 'libindy', "1.6.2" end target 'Indy-demo' do diff --git a/wrappers/java/README.md b/wrappers/java/README.md index 5401ef7546..bd6646b2c3 100644 --- a/wrappers/java/README.md +++ b/wrappers/java/README.md @@ -41,3 +41,14 @@ Then run #### Troubleshooting Use environment variable `RUST_LOG={info|debug|trace}` to output logs of Libindy. + +If your application that uses libindy crashes with a Null Pointer Exception then probably the libindy shared library could +not be loaded properly. If you have build libindy from source then either put the resulting shared library where your +operating system searches for shared libraries or set appropriate environment variables to help the OS's loader to find them. + +On Ubuntu either copy libindy.so to /usr/local/lib or set LD_LIBRARY_PATH to the directory that contains libindy.so. + +``` +export LD_LIBRARY_PATH= +``` + diff --git a/wrappers/java/pom.xml b/wrappers/java/pom.xml index a021b0ea6a..aeb9d2d2df 100644 --- a/wrappers/java/pom.xml +++ b/wrappers/java/pom.xml @@ -5,7 +5,7 @@ org.hyperledger indy jar - 1.6.2 + 1.6.3 indy This is the official SDK for Hyperledger Indy (https://www.hyperledger.org/projects), which provides a distributed-ledger-based foundation for self-sovereign identity (https://sovrin.org). diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java index e8a83b3318..61d15cfe26 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/IndyJava.java @@ -79,12 +79,12 @@ protected static CompletableFuture removeFuture(int xcommand_handle) { /** * Sets the provided future with an exception if the error code provided does not indicate success. - * + * * @param future The future. * @param err The error value to check. * @return true if the error code indeicated Success, otherwise false. */ - protected static boolean checkCallback(CompletableFuture future, int err) { + protected static boolean checkResult(CompletableFuture future, int err) { ErrorCode errorCode = ErrorCode.valueOf(err); if (! ErrorCode.Success.equals(errorCode)) { future.completeExceptionally(IndyException.fromSdkError(err)); return false; } @@ -92,31 +92,6 @@ protected static boolean checkCallback(CompletableFuture future, int err) { return true; } - //TODO: Is this redundant? - /** - * Throws an IndyException if the provided error code does not indicate success. - * - * @param err The error code to check. - * @throws IndyException Thrown if the error code does not indicate success. - */ - protected static void checkCallback(int err) throws IndyException { - - ErrorCode errorCode = ErrorCode.valueOf(err); - if (! ErrorCode.Success.equals(errorCode)) throw IndyException.fromSdkError(err); - } - - /** - * Throws an IndyException if the provided error code does not indicate success. - * - * @param err The error code to check. - * @throws IndyException Thrown if the error code does not indicate success. - */ - protected static void checkResult(int err) throws IndyException { - - ErrorCode errorCode = ErrorCode.valueOf(err); - if (! ErrorCode.Success.equals(errorCode)) throw IndyException.fromSdkError(err); - } - /* * OBJECT METHODS */ 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 bb80ff39f3..5febb12d71 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 @@ -43,6 +43,7 @@ public int indy_register_wallet_storage(int command_handle, String type, Callbac public int indy_delete_wallet(int command_handle, String config, String credentials, Callback cb); public int indy_export_wallet(int command_handle, int handle, String exportConfigJson, Callback cb); public int indy_import_wallet(int command_handle, String config, String credentials, String importConfigJson, Callback cb); + public int indy_generate_wallet_key(int command_handle, String config, Callback cb); // ledger.rs diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java index 667e79ef11..1e2e51c71e 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/Anoncreds.java @@ -42,7 +42,7 @@ private Anoncreds() { public void callback(int xcommand_handle, int err, String schema_id, String schema_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; IssuerCreateSchemaResult result = new IssuerCreateSchemaResult(schema_id, schema_json); future.complete(result); @@ -58,7 +58,7 @@ public void callback(int xcommand_handle, int err, String schema_id, String sche public void callback(int xcommand_handle, int err, String credential_def_id, String credential_def_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; IssuerCreateAndStoreCredentialDefResult result = new IssuerCreateAndStoreCredentialDefResult(credential_def_id, credential_def_json); future.complete(result); @@ -74,7 +74,7 @@ public void callback(int xcommand_handle, int err, String credential_def_id, Str public void callback(int xcommand_handle, int err, String revoc_reg_id, String revoc_reg_def_json, String revoc_reg_entry_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; IssuerCreateAndStoreRevocRegResult result = new IssuerCreateAndStoreRevocRegResult(revoc_reg_id, revoc_reg_def_json, revoc_reg_entry_json); future.complete(result); @@ -90,7 +90,7 @@ public void callback(int xcommand_handle, int err, String revoc_reg_id, String r public void callback(int xcommand_handle, int err, String str) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = str; future.complete(result); @@ -106,7 +106,7 @@ public void callback(int xcommand_handle, int err, String str) { public void callback(int xcommand_handle, int err, String cred_json, String cred_rev_id, String revoc_reg_delta_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; IssuerCreateCredentialResult result = new IssuerCreateCredentialResult(cred_json, cred_rev_id, revoc_reg_delta_json); future.complete(result); @@ -123,7 +123,7 @@ public void callback(int xcommand_handle, int err, String cred_json, String cred public void callback(int xcommand_handle, int err, String credential_req_json, String credential_req_metadata_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; ProverCreateCredentialRequestResult result = new ProverCreateCredentialRequestResult(credential_req_json, credential_req_metadata_json); future.complete(result); @@ -139,7 +139,7 @@ public void callback(int xcommand_handle, int err, String credential_req_json, S public void callback(int xcommand_handle, int err, Boolean valid) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Boolean result = valid; future.complete(result); @@ -192,7 +192,7 @@ public static CompletableFuture issuerCreateSchema( attrs, issuerCreateSchemaCb); - checkResult(result); + checkResult(future, result); return future; } @@ -250,7 +250,7 @@ public static CompletableFuture issuerC configJson, issuerCreateAndStoreCredentialDefCb); - checkResult(result); + checkResult(future, result); return future; } @@ -325,7 +325,7 @@ public static CompletableFuture issuerCreate tailsWriter.getBlobStorageWriterHandle(), issuerCreateAndStoreRevocRegCb); - checkResult(result); + checkResult(future, result); return future; } @@ -365,7 +365,7 @@ public static CompletableFuture issuerCreateCredentialOffer( credDefId, stringCb); - checkResult(result); + checkResult(future, result); return future; } @@ -436,7 +436,7 @@ public static CompletableFuture issuerCreateCreden blobStorageReaderHandle, issuerCreateCredentialCb); - checkResult(result); + checkResult(future, result); return future; } @@ -480,7 +480,7 @@ public static CompletableFuture issuerRevokeCredential( credRevocId, stringCb); - checkResult(result); + checkResult(future, result); return future; } @@ -524,7 +524,7 @@ public static CompletableFuture issuerRevokeCredential( // credRevocId, // issuerRecoverCredentialCb); // -// checkResult(result); +// checkResult(future, result); // // return future; // } @@ -554,7 +554,7 @@ public static CompletableFuture issuerMergeRevocationRegistryDeltas( otherRevRegDelta, stringCb); - checkResult(result); + checkResult(future, result); return future; } @@ -584,7 +584,7 @@ public static CompletableFuture proverCreateMasterSecret( masterSecretId, stringCb); - checkResult(result); + checkResult(future, result); return future; } @@ -641,7 +641,7 @@ public static CompletableFuture proverCreat masterSecretId, proverCreateCredentialReqCb); - checkResult(result); + checkResult(future, result); return future; } @@ -700,7 +700,7 @@ public static CompletableFuture proverStoreCredential( revRegDefJson, stringCb); - checkResult(result); + checkResult(future, result); return future; } @@ -752,7 +752,7 @@ public static CompletableFuture proverGetCredentials( filter, stringCb); - checkResult(result); + checkResult(future, result); return future; } @@ -791,7 +791,7 @@ public static CompletableFuture proverGetCredential( credId, stringCb); - checkResult(result); + checkResult(future, result); return future; } @@ -888,7 +888,7 @@ public static CompletableFuture proverGetCredentialsForProofReq( proofRequest, stringCb); - checkResult(result); + checkResult(future, result); return future; } @@ -1017,7 +1017,7 @@ public static CompletableFuture proverCreateProof( revStates, stringCb); - checkResult(result); + checkResult(future, result); return future; } @@ -1130,7 +1130,7 @@ public static CompletableFuture verifierVerifyProof( revocRegs, verifierVerifyProofCb); - checkResult(result); + checkResult(future, result); return future; } @@ -1174,7 +1174,7 @@ public static CompletableFuture createRevocationState( credRevId, stringCb); - checkResult(result); + checkResult(future, result); return future; } @@ -1223,7 +1223,7 @@ public static CompletableFuture updateRevocationState( credRevId, stringCb); - checkResult(result); + checkResult(future, result); return future; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/CredentialsSearch.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/CredentialsSearch.java index 5d298f64d7..45fe3f920e 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/CredentialsSearch.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/CredentialsSearch.java @@ -27,7 +27,7 @@ private CredentialsSearch(int searchHandle, int totalCount) { public void callback(int xcommand_handle, int err, int search_handle, int total_count) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (!checkResult(future, err)) return; CredentialsSearch result = new CredentialsSearch(search_handle, total_count); future.complete(result); @@ -43,7 +43,7 @@ public void callback(int xcommand_handle, int err, int search_handle, int total_ public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (!checkResult(future, err)) return; Void result = null; future.complete(result); @@ -82,7 +82,7 @@ public static CompletableFuture open( queryJson, proverSearchCredentialsCb); - checkResult(result); + checkResult(future, result); return future; } @@ -115,7 +115,7 @@ public CompletableFuture fetchNextCredentials( count, Anoncreds.stringCb); - checkResult(result); + checkResult(future, result); return future; } @@ -135,7 +135,7 @@ public CompletableFuture closeSearch() throws IndyException { searchHandle, voidCb); - checkResult(result); + checkResult(future, result); return future; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/CredentialsSearchForProofReq.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/CredentialsSearchForProofReq.java index 5dbae4c9fe..88db5b47b7 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/CredentialsSearchForProofReq.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/anoncreds/CredentialsSearchForProofReq.java @@ -25,7 +25,7 @@ private CredentialsSearchForProofReq(int searchHandle) { public void callback(int xcommand_handle, int err, int search_handle) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (!checkResult(future, err)) return; CredentialsSearchForProofReq result = new CredentialsSearchForProofReq(search_handle); future.complete(result); @@ -41,7 +41,7 @@ public void callback(int xcommand_handle, int err, int search_handle) { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (!checkCallback(future, err)) return; + if (!checkResult(future, err)) return; Void result = null; future.complete(result); @@ -131,7 +131,7 @@ public static CompletableFuture open( extraQueryJson, proverSearchCredentialsForProofReqCb); - checkResult(result); + checkResult(future, result); return future; } @@ -176,7 +176,7 @@ public CompletableFuture fetchNextCredentials( count, Anoncreds.stringCb); - checkResult(result); + checkResult(future, result); return future; } @@ -196,7 +196,7 @@ public CompletableFuture closeSearch() throws IndyException { searchHandle, voidCb); - checkResult(result); + checkResult(future, result); return future; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/blob_storage/BlobStorageReader.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/blob_storage/BlobStorageReader.java index e554a388ca..1c5090db18 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/blob_storage/BlobStorageReader.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/blob_storage/BlobStorageReader.java @@ -47,7 +47,7 @@ public int getBlobStorageReaderHandle() { public void callback(int xcommand_handle, int err, int handle) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; BlobStorageReader tailsReader = new BlobStorageReader(handle); @@ -75,7 +75,7 @@ public static CompletableFuture openReader( config, openReaderCb); - checkResult(result); + checkResult(future, result); return future; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/blob_storage/BlobStorageWriter.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/blob_storage/BlobStorageWriter.java index 43588b259f..53c07b1e71 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/blob_storage/BlobStorageWriter.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/blob_storage/BlobStorageWriter.java @@ -47,7 +47,7 @@ public int getBlobStorageWriterHandle() { public void callback(int xcommand_handle, int err, int handle) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; BlobStorageWriter blobStorageWriter = new BlobStorageWriter(handle); @@ -75,7 +75,7 @@ public static CompletableFuture openWriter( config, openWriterCb); - checkResult(result); + checkResult(future, result); return future; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/crypto/Crypto.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/crypto/Crypto.java index c5b6dc5b62..0729c63f03 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/crypto/Crypto.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/crypto/Crypto.java @@ -37,7 +37,7 @@ private Crypto() { public void callback(int xcommand_handle, int err, String verkey) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = verkey; future.complete(result); @@ -53,7 +53,7 @@ public void callback(int xcommand_handle, int err, String verkey) { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Void result = null; future.complete(result); @@ -69,7 +69,7 @@ public void callback(int xcommand_handle, int err) { public void callback(int xcommand_handle, int err, String metadata) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = metadata; future.complete(result); @@ -85,7 +85,7 @@ public void callback(int xcommand_handle, int err, String metadata) { public void callback(int xcommand_handle, int err, Pointer signature_raw, int signature_len) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; byte[] result = new byte[signature_len]; signature_raw.read(0, result, 0, signature_len); @@ -102,7 +102,7 @@ public void callback(int xcommand_handle, int err, Pointer signature_raw, int si public void callback(int xcommand_handle, int err, boolean valid) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Boolean result = Boolean.valueOf(valid); future.complete(result); @@ -118,7 +118,7 @@ public void callback(int xcommand_handle, int err, boolean valid) { public void callback(int xcommand_handle, int err, Pointer encrypted_msg_raw, int encrypted_msg_len, Pointer nonce_raw, int nonce_len) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; byte[] result = new byte[encrypted_msg_len]; encrypted_msg_raw.read(0, result, 0, encrypted_msg_len); @@ -136,7 +136,7 @@ public void callback(int xcommand_handle, int err, Pointer encrypted_msg_raw, in public void callback(int xcommand_handle, int err, String their_vk, Pointer decrypted_msg_raw, int decrypted_msg_len) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; byte[] decryptedMsg = new byte[decrypted_msg_len]; decrypted_msg_raw.read(0, decryptedMsg, 0, decrypted_msg_len); @@ -156,7 +156,7 @@ public void callback(int xcommand_handle, int err, String their_vk, Pointer decr public void callback(int xcommand_handle, int err, Pointer encrypted_msg_raw, int encrypted_msg_len) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; byte[] encryptedMsg = new byte[encrypted_msg_len]; encrypted_msg_raw.read(0, encryptedMsg, 0, encrypted_msg_len); @@ -174,7 +174,7 @@ public void callback(int xcommand_handle, int err, Pointer encrypted_msg_raw, in public void callback(int xcommand_handle, int err, Pointer decrypted_msg_raw, int decrypted_msg_len) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; byte[] result = new byte[decrypted_msg_len]; decrypted_msg_raw.read(0, result, 0, decrypted_msg_len); @@ -216,7 +216,7 @@ public static CompletableFuture createKey( keyJson, createKeyCb); - checkResult(result); + checkResult(future, result); return future; } @@ -251,7 +251,7 @@ public static CompletableFuture setKeyMetadata( metadata, setKeyMetadataCb); - checkResult(result); + checkResult(future, result); return future; } @@ -282,7 +282,7 @@ public static CompletableFuture getKeyMetadata( verkey, getKeyMetadataCb); - checkResult(result); + checkResult(future, result); return future; } @@ -321,7 +321,7 @@ public static CompletableFuture cryptoSign( message.length, cryptoSignCb); - checkResult(result); + checkResult(future, result); return future; } @@ -358,7 +358,7 @@ public static CompletableFuture cryptoVerify( signature.length, cryptoVerifyCb); - checkResult(result); + checkResult(future, result); return future; } @@ -410,7 +410,7 @@ public static CompletableFuture authCrypt( message.length, authCrypCb); - checkResult(result); + checkResult(future, result); return future; } @@ -458,7 +458,7 @@ public static CompletableFuture authDecrypt( encryptedMsg.length, authDecryptCb); - checkResult(result); + checkResult(future, result); return future; } @@ -495,7 +495,7 @@ public static CompletableFuture anonCrypt( message.length, anonCryptCb); - checkResult(result); + checkResult(future, result); return future; } @@ -538,7 +538,7 @@ public static CompletableFuture anonDecrypt( encryptedMsg.length, anonDecryptCb); - checkResult(result); + checkResult(future, result); return future; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/did/Did.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/did/Did.java index 45b56d9bb0..d2dfc34ee0 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/did/Did.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/did/Did.java @@ -8,12 +8,10 @@ import org.hyperledger.indy.sdk.ParamGuard; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.did.DidResults.CreateAndStoreMyDidResult; -import org.hyperledger.indy.sdk.did.DidResults.EncryptResult; import org.hyperledger.indy.sdk.did.DidResults.EndpointForDidResult; import org.hyperledger.indy.sdk.wallet.Wallet; import com.sun.jna.Callback; -import com.sun.jna.Pointer; /** * did.rs API @@ -41,7 +39,7 @@ private Did() { public void callback(int xcommand_handle, int err, String did, String verkey) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; CreateAndStoreMyDidResult result = new CreateAndStoreMyDidResult(did, verkey); future.complete(result); @@ -57,7 +55,7 @@ public void callback(int xcommand_handle, int err, String did, String verkey) { public void callback(int xcommand_handle, int err, String verkey) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = verkey; future.complete(result); @@ -73,7 +71,7 @@ public void callback(int xcommand_handle, int err, String verkey) { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Void result = null; future.complete(result); @@ -89,7 +87,7 @@ public void callback(int xcommand_handle, int err) { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Void result = null; future.complete(result); @@ -105,7 +103,7 @@ public void callback(int xcommand_handle, int err) { public void callback(int xcommand_handle, int err, String key) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = key; future.complete(result); @@ -121,7 +119,7 @@ public void callback(int xcommand_handle, int err, String key) { public void callback(int xcommand_handle, int err, String key) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = key; future.complete(result); @@ -137,7 +135,7 @@ public void callback(int xcommand_handle, int err, String key) { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Void result = null; future.complete(result); @@ -153,7 +151,7 @@ public void callback(int xcommand_handle, int err) { public void callback(int xcommand_handle, int err, String endpoint, String transport_vk) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; EndpointForDidResult result = new EndpointForDidResult(endpoint, transport_vk); future.complete(result); @@ -169,7 +167,7 @@ public void callback(int xcommand_handle, int err, String endpoint, String trans public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Void result = null; future.complete(result); @@ -185,7 +183,7 @@ public void callback(int xcommand_handle, int err) { public void callback(int xcommand_handle, int err, String metadata) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = metadata; future.complete(result); @@ -201,7 +199,7 @@ public void callback(int xcommand_handle, int err, String metadata) { public void callback(int xcommand_handle, int err, String verkey) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = verkey; future.complete(result); @@ -243,7 +241,7 @@ public static CompletableFuture createAndStoreMyDid( didJson, createAndStoreMyDidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -278,7 +276,7 @@ public static CompletableFuture replaceKeysStart( identityJson, replaceKeysStartCb); - checkResult(result); + checkResult(future, result); return future; } @@ -309,7 +307,7 @@ public static CompletableFuture replaceKeysApply( did, replaceKeysApplyCb); - checkResult(result); + checkResult(future, result); return future; } @@ -340,7 +338,7 @@ public static CompletableFuture storeTheirDid( identityJson, storeTheirDidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -387,7 +385,7 @@ public static CompletableFuture keyForDid( did, keyForDidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -426,7 +424,7 @@ public static CompletableFuture keyForLocalDid( did, keyForLocalDidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -465,7 +463,7 @@ public static CompletableFuture setEndpointForDid( transportKey, setEndpointForDidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -501,7 +499,7 @@ public static CompletableFuture getEndpointForDid( did, getEndpointForDidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -536,7 +534,7 @@ public static CompletableFuture setDidMetadata( metadata, setDidMetadataCb); - checkResult(result); + checkResult(future, result); return future; } @@ -567,7 +565,7 @@ public static CompletableFuture getDidMetadata( did, getDidMetadataCb); - checkResult(result); + checkResult(future, result); return future; } @@ -602,7 +600,7 @@ public static CompletableFuture getDidWithMeta( did, getDidMetadataCb); - checkResult(result); + checkResult(future, result); return future; } @@ -633,7 +631,7 @@ public static CompletableFuture getListMyDidsWithMeta( walletHandle, getDidMetadataCb); - checkResult(result); + checkResult(future, result); return future; } @@ -662,7 +660,7 @@ public static CompletableFuture AbbreviateVerkey( verkey, getAttrVerkeyCb); - checkResult(result); + checkResult(future, result); return future; } 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 f1a2070d90..e40d614d5d 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 @@ -40,7 +40,7 @@ private Ledger() { public void callback(int xcommand_handle, int err, String request_result_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = request_result_json; future.complete(result); @@ -56,7 +56,7 @@ public void callback(int xcommand_handle, int err, String request_result_json) { public void callback(int xcommand_handle, int err, String request_result_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = request_result_json; future.complete(result); @@ -72,7 +72,7 @@ public void callback(int xcommand_handle, int err, String request_result_json) { public void callback(int xcommand_handle, int err, String signed_request_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = signed_request_json; future.complete(result); @@ -88,7 +88,7 @@ public void callback(int xcommand_handle, int err, String signed_request_json) { public void callback(int xcommand_handle, int err, String request_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = request_json; future.complete(result); @@ -104,7 +104,7 @@ public void callback(int xcommand_handle, int err, String request_json) { public void callback(int xcommand_handle, int err, String id, String object_json) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; ParseResponseResult result = new ParseResponseResult(id, object_json); future.complete(result); @@ -120,7 +120,7 @@ public void callback(int xcommand_handle, int err, String id, String object_json public void callback(int xcommand_handle, int err, String id, String object_json, long timestamp) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; ParseRegistryResponseResult result = new ParseRegistryResponseResult(id, object_json, timestamp); future.complete(result); @@ -171,7 +171,7 @@ public static CompletableFuture signAndSubmitRequest( requestJson, signAndSubmitRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -204,7 +204,7 @@ public static CompletableFuture submitRequest( requestJson, submitRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -249,7 +249,7 @@ public static CompletableFuture submitAction( timeout, submitRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -287,7 +287,7 @@ public static CompletableFuture signRequest( requestJson, signRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -325,7 +325,7 @@ public static CompletableFuture multiSignRequest( requestJson, signRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -354,7 +354,7 @@ public static CompletableFuture buildGetDdoRequest( targetDid, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -397,7 +397,7 @@ public static CompletableFuture buildNymRequest( role, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -435,7 +435,7 @@ public static CompletableFuture buildAttribRequest( enc, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -473,7 +473,7 @@ public static CompletableFuture buildGetAttribRequest( enc, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -502,7 +502,7 @@ public static CompletableFuture buildGetNymRequest( targetDid, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -538,7 +538,7 @@ public static CompletableFuture buildSchemaRequest( data, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -567,7 +567,7 @@ public static CompletableFuture buildGetSchemaRequest( id, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -599,7 +599,7 @@ public static CompletableFuture parseGetSchemaResponse( getSchemaResponse, parseResponseCb); - checkResult(result); + checkResult(future, result); return future; } @@ -640,7 +640,7 @@ public static CompletableFuture buildCredDefRequest( data, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -670,7 +670,7 @@ public static CompletableFuture buildGetCredDefRequest( id, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -706,7 +706,7 @@ public static CompletableFuture parseGetCredDefResponse( getCredDefResponse, parseResponseCb); - checkResult(result); + checkResult(future, result); return future; } @@ -748,7 +748,7 @@ public static CompletableFuture buildNodeRequest( data, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -773,7 +773,7 @@ public static CompletableFuture buildGetValidatorInfoRequest( submitterDid, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -808,7 +808,7 @@ public static CompletableFuture buildGetTxnRequest( seqNo, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -841,7 +841,7 @@ public static CompletableFuture buildPoolConfigRequest( force, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -872,7 +872,7 @@ public static CompletableFuture buildPoolRestartRequest( datetime, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -929,7 +929,7 @@ public static CompletableFuture buildPoolUpgradeRequest( package_, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -972,7 +972,7 @@ public static CompletableFuture buildRevocRegDefRequest( data, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -1002,7 +1002,7 @@ public static CompletableFuture buildGetRevocRegDefRequest( id, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -1041,7 +1041,7 @@ public static CompletableFuture parseGetRevocRegDefResponse getRevocRegDefResponse, parseResponseCb); - checkResult(result); + checkResult(future, result); return future; } @@ -1089,7 +1089,7 @@ public static CompletableFuture buildRevocRegEntryRequest( value, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -1122,7 +1122,7 @@ public static CompletableFuture buildGetRevocRegRequest( timestamp, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -1153,7 +1153,7 @@ public static CompletableFuture parseGetRevocRegRes getRevocRegResponse, parseRegistryResponseCb); - checkResult(result); + checkResult(future, result); return future; } @@ -1190,7 +1190,7 @@ public static CompletableFuture buildGetRevocRegDeltaRequest( to, buildRequestCb); - checkResult(result); + checkResult(future, result); return future; } @@ -1224,7 +1224,7 @@ public static CompletableFuture parseGetRevocRegDel getRevocRegDeltaResponse, parseRegistryResponseCb); - checkResult(result); + checkResult(future, result); return future; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/non_secrets/WalletRecord.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/non_secrets/WalletRecord.java index 32634795d2..7f60fb5381 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/non_secrets/WalletRecord.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/non_secrets/WalletRecord.java @@ -35,7 +35,7 @@ private WalletRecord() { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Void result = null; future.complete(result); @@ -51,7 +51,7 @@ public void callback(int xcommand_handle, int err) { public void callback(int xcommand_handle, int err, String str) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = str; future.complete(result); @@ -103,7 +103,7 @@ public static CompletableFuture add( tagsJson, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -142,7 +142,7 @@ public static CompletableFuture updateValue( value, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -185,7 +185,7 @@ public static CompletableFuture updateTags( tagsJson, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -228,7 +228,7 @@ public static CompletableFuture addTags( tagsJson, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -268,7 +268,7 @@ public static CompletableFuture deleteTags( tagNamesJson, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -303,7 +303,7 @@ public static CompletableFuture delete( id, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -353,7 +353,7 @@ public static CompletableFuture get( optionsJson, stringCb); - checkResult(result); + checkResult(future, result); return future; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/non_secrets/WalletSearch.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/non_secrets/WalletSearch.java index 89d39da112..69649e5cd1 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/non_secrets/WalletSearch.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/non_secrets/WalletSearch.java @@ -48,7 +48,7 @@ public int getSearchHandle() { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Void result = null; future.complete(result); @@ -64,7 +64,7 @@ public void callback(int xcommand_handle, int err) { public void callback(int xcommand_handle, int err, String str) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = str; future.complete(result); @@ -80,7 +80,7 @@ public void callback(int xcommand_handle, int err, String str) { public void callback(int xcommand_handle, int err, int handle) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; WalletSearch result = new WalletSearch(handle); future.complete(result); @@ -138,7 +138,7 @@ public static CompletableFuture open( optionsJson, searchCb); - checkResult(result); + checkResult(future, result); return future; } @@ -179,7 +179,7 @@ public static CompletableFuture searchFetchNextRecords( count, stringCb); - checkResult(result); + checkResult(future, result); return future; } @@ -204,7 +204,7 @@ public static CompletableFuture closeSearch( searchHandle, voidCb); - checkResult(result); + checkResult(future, result); return future; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pairwise/Pairwise.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pairwise/Pairwise.java index e597faecbc..a611783a5e 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pairwise/Pairwise.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pairwise/Pairwise.java @@ -36,7 +36,7 @@ private Pairwise() { public void callback(int xcommand_handle, int err, boolean exists) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Boolean result = Boolean.valueOf(exists); future.complete(result); @@ -52,7 +52,7 @@ public void callback(int xcommand_handle, int err, boolean exists) { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Void result = null; future.complete(result); @@ -68,7 +68,7 @@ public void callback(int xcommand_handle, int err) { public void callback(int xcommand_handle, int err, String list_pairwise) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = list_pairwise; future.complete(result); @@ -84,7 +84,7 @@ public void callback(int xcommand_handle, int err, String list_pairwise) { public void callback(int xcommand_handle, int err, String pairwise_info) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; String result = pairwise_info; future.complete(result); @@ -100,7 +100,7 @@ public void callback(int xcommand_handle, int err, String pairwise_info) { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Void result = null; future.complete(result); @@ -137,7 +137,7 @@ public static CompletableFuture isPairwiseExists( theirDid, isPairwiseExistsCb); - checkResult(result); + checkResult(future, result); return future; } @@ -175,7 +175,7 @@ public static CompletableFuture createPairwise( metadata, createPairwiseCb); - checkResult(result); + checkResult(future, result); return future; } @@ -202,7 +202,7 @@ public static CompletableFuture listPairwise( walletHandle, listPairwiseCb); - checkResult(result); + checkResult(future, result); return future; } @@ -233,7 +233,7 @@ public static CompletableFuture getPairwise( theirDid, getPairwiseCb); - checkResult(result); + checkResult(future, result); return future; } @@ -267,7 +267,7 @@ public static CompletableFuture setPairwiseMetadata( metadata, setPairwiseMetadataCb); - checkResult(result); + checkResult(future, result); return future; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/payments/Payments.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/payments/Payments.java index 62b2ff4cb8..61c52ca11d 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/payments/Payments.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/payments/Payments.java @@ -28,7 +28,7 @@ private Payments() { @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommandHandle, int err, String paymentAddress) { CompletableFuture future = (CompletableFuture) removeFuture(xcommandHandle); - if (!checkCallback(future, err)) return; + if (!checkResult(future, err)) return; future.complete(paymentAddress); } @@ -41,7 +41,7 @@ public void callback(int xcommandHandle, int err, String paymentAddress) { @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommandHandle, int err, String reqWithFeesJson, String paymentMethod) { CompletableFuture future = (CompletableFuture) removeFuture(xcommandHandle); - if (!checkCallback(future, err)) return; + if (!checkResult(future, err)) return; AddRequestFeesResult addRequestFeesResult = new AddRequestFeesResult(reqWithFeesJson, paymentMethod); @@ -56,7 +56,7 @@ public void callback(int xcommandHandle, int err, String reqWithFeesJson, String @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommandHandle, int err, String sourcesJson, String paymentMethod) { CompletableFuture future = (CompletableFuture) removeFuture(xcommandHandle); - if (!checkCallback(future, err)) return; + if (!checkResult(future, err)) return; BuildGetPaymentSourcesRequestResult addRequestFeesResult = new BuildGetPaymentSourcesRequestResult(sourcesJson, paymentMethod); @@ -71,7 +71,7 @@ public void callback(int xcommandHandle, int err, String sourcesJson, String pay @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommandHandle, int err, String paymentReqJson, String paymentMethod) { CompletableFuture future = (CompletableFuture) removeFuture(xcommandHandle); - if (!checkCallback(future, err)) return; + if (!checkResult(future, err)) return; BuildPaymentReqResult addRequestFeesResult = new BuildPaymentReqResult(paymentReqJson, paymentMethod); @@ -86,7 +86,7 @@ public void callback(int xcommandHandle, int err, String paymentReqJson, String @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommandHandle, int err, String mintReqJson, String paymentMethod) { CompletableFuture future = (CompletableFuture) removeFuture(xcommandHandle); - if (!checkCallback(future, err)) return; + if (!checkResult(future, err)) return; BuildMintReqResult addRequestFeesResult = new BuildMintReqResult(mintReqJson, paymentMethod); @@ -101,7 +101,7 @@ public void callback(int xcommandHandle, int err, String mintReqJson, String pay @SuppressWarnings({"unused", "unchecked"}) public void callback(int xcommandHandle, int err, String verifyReqJson, String paymentMethod) { CompletableFuture future = (CompletableFuture) removeFuture(xcommandHandle); - if (!checkCallback(future, err)) return; + if (!checkResult(future, err)) return; BuildVerifyPaymentReqResult verifyRequestResult = new BuildVerifyPaymentReqResult(verifyReqJson, paymentMethod); @@ -153,7 +153,7 @@ public static CompletableFuture createPaymentAddress( stringCompleteCb ); - checkResult(result); + checkResult(future, result); return future; } @@ -179,7 +179,7 @@ public static CompletableFuture listPaymentAddresses( stringCompleteCb ); - checkResult(result); + checkResult(future, result); return future; } @@ -241,7 +241,7 @@ public static CompletableFuture addRequestFees( extra, addRequestFeesCb); - checkResult(result); + checkResult(future, result); return future; } @@ -297,7 +297,7 @@ public static CompletableFuture buildGetPay paymentAddress, BuildGetPaymentSourcesRequestCB); - checkResult(result); + checkResult(future, result); return future; } @@ -372,7 +372,7 @@ public static CompletableFuture buildPaymentRequest( extra, buildPaymentReqCb); - checkResult(result); + checkResult(future, result); return future; } @@ -437,7 +437,7 @@ public static CompletableFuture buildMintRequest( extra, buildMintReqCb); - checkResult(result); + checkResult(future, result); return future; } @@ -480,7 +480,7 @@ public static CompletableFuture buildSetTxnFeesRequest( feesJson, stringCompleteCb); - checkResult(result); + checkResult(future, result); return future; } @@ -514,7 +514,7 @@ public static CompletableFuture buildGetTxnFeesRequest( paymentMethod, stringCompleteCb); - checkResult(result); + checkResult(future, result); return future; } @@ -569,7 +569,7 @@ public static CompletableFuture buildVerifyPaymentR receipt, buildVerifyPaymentReqCb); - checkResult(result); + checkResult(future, result); return future; } @@ -611,7 +611,7 @@ private static CompletableFuture parseResponse( int result = method.apply(commandHandle, paymentMethod, respJson, stringCompleteCb); - checkResult(result); + checkResult(future, result); return future; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java index fb877ad17b..23319d4243 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/pool/Pool.java @@ -49,7 +49,7 @@ public int getPoolHandle() { public void callback(int xcommand_handle, int err, int pool_handle) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Pool pool = new Pool(pool_handle); @@ -67,7 +67,7 @@ public void callback(int xcommand_handle, int err, int pool_handle) { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Void result = null; future.complete(result); @@ -101,7 +101,7 @@ public static CompletableFuture createPoolLedgerConfig( config, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -138,7 +138,7 @@ public static CompletableFuture openPoolLedger( config, openPoolLedgerCb); - checkResult(result); + checkResult(future, result); return future; } @@ -165,7 +165,7 @@ private static CompletableFuture refreshPoolLedger( handle, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -192,7 +192,7 @@ private static CompletableFuture closePoolLedger( handle, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -217,7 +217,7 @@ public static CompletableFuture deletePoolLedgerConfig( configName, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -248,7 +248,7 @@ public static CompletableFuture setProtocolVersion( protocolVersion, voidCb); - checkResult(result); + checkResult(future, result); return future; } diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java index 9a301d9018..3e1f5b46bc 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/wallet/Wallet.java @@ -51,13 +51,29 @@ public int getWalletHandle() { public void callback(int xcommand_handle, int err) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Void result = null; future.complete(result); } }; + /** + * Callback used when function returning string completes. + */ + private static Callback stringCb = new Callback() { + + @SuppressWarnings({"unused", "unchecked"}) + public void callback(int xcommand_handle, int err, String str) { + + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + if (! checkResult(future, err)) return; + + String result = str; + future.complete(result); + } + }; + /** * Callback used when openWallet completes. */ @@ -67,7 +83,7 @@ public void callback(int xcommand_handle, int err) { public void callback(int xcommand_handle, int err, int handle) { CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); - if (! checkCallback(future, err)) return; + if (! checkResult(future, err)) return; Wallet wallet = new Wallet(handle); @@ -129,7 +145,7 @@ public static CompletableFuture registerWalletType( null, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -155,13 +171,16 @@ public static CompletableFuture registerWalletType( * } * @param credentials Wallet credentials json * { - * "key": string, Passphrase used to derive wallet master key + * "key": string, Key or passphrase used for wallet key derivation. + * Look to key_derivation_method param for information about supported key derivation methods. * "storage_credentials": optional[{credentials json}] Credentials for wallet storage. Storage type defines set of supported keys. * Can be optional if storage supports default configuration. * For 'default' storage type should be empty. - * "key_derivation_method": optional[string] algorithm to use for master key derivation: - * ARAGON2I_MOD (used by default) - * ARAGON2I_INT - less secured but faster + * "key_derivation_method": optional[string] Algorithm to use for wallet key derivation: + * ARGON2I_MOD - derive secured wallet master key (used by default) + * ARGON2I_INT - derive secured wallet master key (less secured but faster) + * RAW - raw wallet key master provided (skip derivation). + * RAW keys can be generated with generateWalletKey call * } * @return A future that resolves no value. * @throws IndyException Thrown if a call to the underlying SDK fails. @@ -179,7 +198,7 @@ public static CompletableFuture createWallet( credentials, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -205,18 +224,22 @@ public static CompletableFuture createWallet( * } * @param credentials Wallet credentials json * { - * "key": string, Passphrase used to derive current wallet master key - * "rekey": optional["string"], If present than wallet master key will be rotated to a new one - * derived from this passphrase. + * "key": string, Key or passphrase used for wallet key derivation. + * Look to key_derivation_method param for information about supported key derivation methods. + * "rekey": optional["string"], If present than wallet master key will be rotated to a new one. * "storage_credentials": optional[{credentiails object}] Credentials for wallet storage. Storage type defines set of supported keys. * Can be optional if storage supports default configuration. * For 'default' storage type should be empty. - * "key_derivation_method": optional[string] algorithm to use for master key derivation: - * ARAGON2I_MOD (used by default) - * ARAGON2I_INT - less secured but faster - * "rekey_derivation_method": optional[string] algorithm to use for master rekey derivation: - * ARAGON2I_MOD (used by default) - * ARAGON2I_INT - less secured but faster + * "key_derivation_method": optional[string] Algorithm to use for wallet key derivation: + * ARGON2I_MOD - derive secured wallet master key (used by default) + * ARGON2I_INT - derive secured wallet master key (less secured but faster) + * RAW - raw wallet key master provided (skip derivation). + * RAW keys can be generated with generateWalletKey call + * "rekey_derivation_method": optional[string] Algorithm to use for wallet rekey derivation: + * ARGON2I_MOD - derive secured wallet master rekey (used by default) + * ARGON2I_INT - derive secured wallet master rekey (less secured but faster) + * RAW - raw wallet master rekey provided (skip derivation). + * RAW keys can be generated with generateWalletKey call * * } * @return A future that resolves no value. @@ -236,7 +259,7 @@ public static CompletableFuture openWallet( credentials, openWalletCb); - checkResult(result); + checkResult(future, result); return future; } @@ -263,7 +286,7 @@ private static CompletableFuture closeWallet( handle, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -289,13 +312,16 @@ private static CompletableFuture closeWallet( * } * @param credentials Wallet credentials json * { - * "key": string, Passphrase used to derive current wallet master key + * "key": string, Key or passphrase used for wallet key derivation. + * Look to key_derivation_method param for information about supported key derivation methods. * "storage_credentials": optional[{credentials json}] Credentials for wallet storage. Storage type defines set of supported keys. * Can be optional if storage supports default configuration. * For 'default' storage type should be empty. - * "key_derivation_method": optional[string] algorithm to use for master key derivation: - * ARAGON2I_MOD (used by default) - * ARAGON2I_INT - less secured but faster + * "key_derivation_method": optional[string] Algorithm to use for wallet key derivation: + * ARGON2I_MOD - derive secured wallet master key (used by default) + * ARGON2I_INT - derive secured wallet master key (less secured but faster) + * RAW - raw wallet key master provided (skip derivation). + * RAW keys can be generated with generateWalletKey call * } * * @return A future that resolves no value. @@ -314,7 +340,7 @@ public static CompletableFuture deleteWallet( credentials, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -326,10 +352,13 @@ public static CompletableFuture deleteWallet( * @param exportConfigJson: JSON containing settings for input operation. * { * "path": "string", Path of the file that contains exported wallet content - * "key": "string", Passphrase used to derive export key + * "key": string, Key or passphrase used for wallet export key derivation. + * Look to key_derivation_method param for information about supported key derivation methods. * "key_derivation_method": optional[string] algorithm to use for export key derivation: - * ARAGON2I_MOD (used by default) - * ARAGON2I_INT - less secured but faster + * ARGON2I_MOD - derive secured wallet export key (used by default) + * ARGON2I_INT - derive secured wallet export key (less secured but faster) + * RAW - raw wallet export master provided (skip derivation). + * RAW keys can be generated with generateWalletKey call * } * @return A future that resolves no value. * @throws IndyException Thrown if a call to the underlying SDK fails. @@ -352,7 +381,7 @@ public static CompletableFuture exportWallet( exportConfigJson, voidCb); - checkResult(result); + checkResult(future, result); return future; } @@ -381,18 +410,21 @@ public static CompletableFuture exportWallet( * } * @param credentials Wallet credentials json * { - * "key": string, Passphrase used to derive wallet master key + * "key": string, Key or passphrase used for wallet key derivation. + * Look to key_derivation_method param for information about supported key derivation methods. * "storage_credentials": optional[{credentials json}] Credentials for wallet storage. Storage type defines set of supported keys. * Can be optional if storage supports default configuration. * For 'default' storage type should be empty. - * "key_derivation_method": optional[string] algorithm to use for master key derivation: - * ARAGON2I_MOD (used by default) - * ARAGON2I_INT - less secured but faster + * "key_derivation_method": optional[string] Algorithm to use for wallet key derivation: + * ARGON2I_MOD - derive secured wallet master key (used by default) + * ARGON2I_INT - derive secured wallet master key (less secured but faster) + * RAW - raw wallet key master provided (skip derivation). + * RAW keys can be generated with generateWalletKey call * } * @param importConfigJson Import settings json. * { - * "path": "string", path of the file that contains exported wallet content - * "key": "string", passphrase used to derive export key + * "path": "string", Path of the file that contains exported wallet content + * "key": "string", Key used for export of the wallet * } * @return A future that resolves no value. * @throws IndyException Thrown if a call to the underlying SDK fails. @@ -414,11 +446,40 @@ public static CompletableFuture importWallet( importConfigJson, voidCb); - checkResult(result); + checkResult(future, result); return future; } + /** + * Generate wallet master key. + * Returned key is compatible with "RAW" key derivation method. + * It allows to avoid expensive key derivation for use cases when wallet keys can be stored in a secure enclave. + * + * @param config (optional) key configuration json. + * { + * seed": optional[string] Seed that allows deterministic key creation (if not set random one will be used). + * } + * + * @return A future that resolves to key. + * @throws IndyException Thrown if a call to the underlying SDK fails. + */ + public static CompletableFuture generateWalletKey( + String config) throws IndyException { + + CompletableFuture future = new CompletableFuture(); + int commandHandle = addFuture(future); + + int result = LibIndy.api.indy_generate_wallet_key( + commandHandle, + config, + stringCb); + + checkResult(future, result); + + return future; + } + /* * INSTANCE METHODS */ diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java index a420ebc2fa..af281d7cf0 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/IndyIntegrationTest.java @@ -68,7 +68,7 @@ public class IndyIntegrationTest { " }"; protected static final String WALLET_CONFIG = "{ \"id\":\"" + WALLET + "\", \"storage_type\":\"" + TYPE + "\"}"; - protected static final String WALLET_CREDENTIALS = "{ \"key\":\"key\", \"key_derivation_method\": \"ARAGON2I_INT\"}"; + protected static final String WALLET_CREDENTIALS = "{ \"key\":\"key\", \"key_derivation_method\": \"ARGON2I_INT\"}"; protected static final String PLUGGED_WALLET_CONFIG = "{ \"id\":\"" + WALLET + "\", \"storage_type\":\"unknown_type\"}"; diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/AnoncredsIntegrationTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/AnoncredsIntegrationTest.java index d62b2cbc8d..3874cf2ceb 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/AnoncredsIntegrationTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/anoncreds/AnoncredsIntegrationTest.java @@ -36,7 +36,7 @@ public class AnoncredsIntegrationTest { static String issuer1GvtCredReq; static String issuer1GvtCredReqMetadata; static String issuer1GvtCredential; - protected String CREDENTIALS = "{\"key\": \"key\", \"key_derivation_method\": \"ARAGON2I_INT\"}"; + protected String CREDENTIALS = "{\"key\": \"key\", \"key_derivation_method\": \"ARGON2I_INT\"}"; String masterSecretId = "master_secret_name"; String issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; String proverDid = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"; diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/crypto/SetKeyMetadataTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/crypto/SetKeyMetadataTest.java index 838e9eee1e..4465f82d2f 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/crypto/SetKeyMetadataTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/crypto/SetKeyMetadataTest.java @@ -44,9 +44,6 @@ public void testSetKeyMetadataWorksForEmptyString() throws Exception { @Test public void testSetKeyMetadataWorksForNoKey() throws Exception { - thrown.expect(ExecutionException.class); - thrown.expectCause(isA(WalletItemNotFoundException.class)); - Crypto.setKeyMetadata(wallet, VERKEY, METADATA).get(); } } \ No newline at end of file diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/did/SetDidMetadataTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/did/SetDidMetadataTest.java index 71d61d18db..4d58327cd0 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/did/SetDidMetadataTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/did/SetDidMetadataTest.java @@ -45,10 +45,7 @@ public void testSetDidMetadataWorksForEmptyString() throws Exception { } @Test - public void testSetDidMetadataWorksForNotFoundDid() throws Exception { - thrown.expect(ExecutionException.class); - thrown.expectCause(isA(WalletItemNotFoundException.class)); - + public void testSetDidMetadataWorksForUnknownDid() throws Exception { Did.setDidMetadata(wallet, DID, METADATA).get(); } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java index fde908dad9..4273187c3f 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/ledger/NodeRequestsTest.java @@ -21,7 +21,9 @@ public class NodeRequestsTest extends IndyIntegrationTestWithPoolAndSingleWallet "\"client_port\":911," + "\"alias\":\"some\"," + "\"services\":[\"VALIDATOR\"]," + - "\"blskey\":\"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba\"}"; + "\"blskey\":\"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba\"," + + "\"blskey_pop\":\"RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1\"" + + "}"; private DidJSONParameters.CreateAndStoreMyDidJSONParameter stewardDidJson = new DidJSONParameters.CreateAndStoreMyDidJSONParameter(null, "000000000000000000000000Steward1", null, null); @@ -61,7 +63,9 @@ public void testBuildNodeRequestWorksForWrongServiceType() throws Exception { "\"client_port\":911," + "\"alias\":\"some\"," + "\"services\":[\"SERVICE\"]" + - "\"blskey\":\"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba\"}"; + "\"blskey\":\"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba\"," + + "\"blskey_pop\":\"RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1\"" + + "}"; Ledger.buildNodeRequest(DID, dest, data).get(); } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java index ffbbcaad01..c1c66101d2 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/utils/PoolUtils.java @@ -38,15 +38,16 @@ private static File createGenesisTxnFile(String filename, int nodesCnt) throws I public static void writeTransactions(File file, int nodesCnt) throws IOException { String testPoolIp = EnvironmentUtils.getTestPoolIP(); + // this data and pool_transactions_genesis must have the same data and IP addresses String[] defaultTxns = new String[]{ - String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node1\",\"blskey\":\"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba\",\"client_ip\":\"%s\",\"client_port\":9702,\"node_ip\":\"%s\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\"},\"metadata\":{\"from\":\"Th7MpTaRZVRYnPiabds81Y\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":1,\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\"},\"ver\":\"1\"}", testPoolIp, testPoolIp), - String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node2\",\"blskey\":\"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk\",\"client_ip\":\"%s\",\"client_port\":9704,\"node_ip\":\"%s\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\"},\"metadata\":{\"from\":\"EbP4aYNeTHL6q385GuVpRV\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":2,\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\"},\"ver\":\"1\"}", testPoolIp, testPoolIp), - String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node3\",\"blskey\":\"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5\",\"client_ip\":\"%s\",\"client_port\":9706,\"node_ip\":\"%s\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\"},\"metadata\":{\"from\":\"4cU41vWW82ArfxJxHkzXPG\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":3,\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\"},\"ver\":\"1\"}", testPoolIp, testPoolIp), - String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node4\",\"blskey\":\"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw\",\"client_ip\":\"%s\",\"client_port\":9708,\"node_ip\":\"%s\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\"},\"metadata\":{\"from\":\"TWwCRQRZ2ZHMJFn9TzLp7W\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":4,\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\"},\"ver\":\"1\"}", testPoolIp, testPoolIp) + String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node1\",\"blskey\":\"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba\",\"blskey_pop\":\"RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1\",\"client_ip\":\"%s\",\"client_port\":9702,\"node_ip\":\"%s\",\"node_port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\"},\"metadata\":{\"from\":\"Th7MpTaRZVRYnPiabds81Y\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":1,\"txnId\":\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\"},\"ver\":\"1\"}", testPoolIp, testPoolIp), + String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node2\",\"blskey\":\"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk\",\"blskey_pop\":\"Qr658mWZ2YC8JXGXwMDQTzuZCWF7NK9EwxphGmcBvCh6ybUuLxbG65nsX4JvD4SPNtkJ2w9ug1yLTj6fgmuDg41TgECXjLCij3RMsV8CwewBVgVN67wsA45DFWvqvLtu4rjNnE9JbdFTc1Z4WCPA3Xan44K1HoHAq9EVeaRYs8zoF5\",\"client_ip\":\"%s\",\"client_port\":9704,\"node_ip\":\"%s\",\"node_port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\"},\"metadata\":{\"from\":\"EbP4aYNeTHL6q385GuVpRV\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":2,\"txnId\":\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\"},\"ver\":\"1\"}", testPoolIp, testPoolIp), + String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node3\",\"blskey\":\"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5\",\"blskey_pop\":\"QwDeb2CkNSx6r8QC8vGQK3GRv7Yndn84TGNijX8YXHPiagXajyfTjoR87rXUu4G4QLk2cF8NNyqWiYMus1623dELWwx57rLCFqGh7N4ZRbGDRP4fnVcaKg1BcUxQ866Ven4gw8y4N56S5HzxXNBZtLYmhGHvDtk6PFkFwCvxYrNYjh\",\"client_ip\":\"%s\",\"client_port\":9706,\"node_ip\":\"%s\",\"node_port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\"},\"metadata\":{\"from\":\"4cU41vWW82ArfxJxHkzXPG\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":3,\"txnId\":\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\"},\"ver\":\"1\"}", testPoolIp, testPoolIp), + String.format("{\"reqSignature\":{},\"txn\":{\"data\":{\"data\":{\"alias\":\"Node4\",\"blskey\":\"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw\",\"blskey_pop\":\"RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP\",\"client_ip\":\"%s\",\"client_port\":9708,\"node_ip\":\"%s\",\"node_port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\"},\"metadata\":{\"from\":\"TWwCRQRZ2ZHMJFn9TzLp7W\"},\"type\":\"0\"},\"txnMetadata\":{\"seqNo\":4,\"txnId\":\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\"},\"ver\":\"1\"}", testPoolIp, testPoolIp) }; FileWriter fw = new FileWriter(file); - for (int i = 0; i < nodesCnt; i++) { + for (int i = 0; i < defaultTxns.length; i++) { fw.write(defaultTxns[i]); fw.write("\n"); } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/GenerateWalletKeyTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/GenerateWalletKeyTest.java new file mode 100644 index 0000000000..a6f734ddc5 --- /dev/null +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/GenerateWalletKeyTest.java @@ -0,0 +1,28 @@ +package org.hyperledger.indy.sdk.wallet; + +import org.hyperledger.indy.sdk.IndyIntegrationTest; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + + +public class GenerateWalletKeyTest extends IndyIntegrationTest { + + @Test + public void testGenerateWalletKeyWorks() throws Exception { + String key = Wallet.generateWalletKey(null).get(); + + String credentials = "{ \"key\":\"" + key + "\", \"key_derivation_method\":\"RAW\"}"; + Wallet.createWallet(WALLET_CONFIG, credentials).get(); + } + + @Test + public void testGenerateWalletKeyWorksForSeed() throws Exception { + String config = "{ \"seed\":\"" + MY1_SEED + "\"}"; + String key = Wallet.generateWalletKey(config).get(); + assertEquals("CwMHrEQJnwvuE8q9zbR49jyYtVxVBHNTjCPEPk1aV3cP", key); + + String credentials = "{ \"key\":\"" + key + "\", \"key_derivation_method\":\"RAW\"}"; + Wallet.createWallet(WALLET_CONFIG, credentials).get(); + } +} \ No newline at end of file diff --git a/wrappers/nodejs/README.md b/wrappers/nodejs/README.md index 30e8db017f..ca6eb1460d 100644 --- a/wrappers/nodejs/README.md +++ b/wrappers/nodejs/README.md @@ -2287,8 +2287,8 @@ Create a new secure wallet. Can be optional if storage supports default configuration. For 'default' storage type should be empty. "key_derivation_method": optional algorithm to use for master key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster + ARGON2I_MOD (used by default) + ARGON2I_INT - less secured but faster } ```` * __->__ void @@ -2328,11 +2328,11 @@ Wallet must be previously created with createWallet method. "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. Can be optional if storage supports default configuration. "key_derivation_method": optional algorithm to use for master key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster} + ARGON2I_MOD (used by default) + ARGON2I_INT - less secured but faster} "rekey_derivation_method": optional algorithm to use for master rekey derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster + ARGON2I_MOD (used by default) + ARGON2I_INT - less secured but faster } ```` * __->__ `handle`: Handle (Number) - err: Error code @@ -2351,8 +2351,8 @@ Exports opened wallet "path": , Path of the file that contains exported wallet content "key": , Passphrase used to derive export key "key_derivation_method": optional algorithm to use for export key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster + ARGON2I_MOD (used by default) + ARGON2I_INT - less secured but faster } ``` * __->__ void @@ -2391,8 +2391,8 @@ This can be seen as an createWallet call with additional content import Can be optional if storage supports default configuration. For 'default' storage type should be empty. "key_derivation_method": optional algorithm to use for master key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster + ARGON2I_MOD (used by default) + ARGON2I_INT - less secured but faster } ```` * `importConfig`: Json @@ -2445,8 +2445,8 @@ Deletes created wallet. Can be optional if storage supports default configuration. For 'default' storage type should be empty. "key_derivation_method": optional algorithm to use for master key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster + ARGON2I_MOD (used by default) + ARGON2I_INT - less secured but faster } ```` * __->__ void diff --git a/wrappers/nodejs/codegen/api.json b/wrappers/nodejs/codegen/api.json index dacce8ae30..f58c794689 100644 --- a/wrappers/nodejs/codegen/api.json +++ b/wrappers/nodejs/codegen/api.json @@ -245,7 +245,7 @@ "ret": "indy_error_t" }, "indy_prover_store_credential": { - "docs": "Check credential provided by Issuer for the given credential request,\nupdates the credential by a master secret and stores in a secure wallet.\n\nTo support efficient and flexible search the following tags will be created for stored credential:\n {\n \"schema_id\": ,\n \"schema_issuer_did\": ,\n \"schema_name\": ,\n \"schema_version\": ,\n \"issuer_did\": ,\n \"cred_def_id\": ,\n // for every attribute in \n \"attr::::marker\": \"1\",\n \"attr::::value\": ,\n }\n\n#Params\ncommand_handle: command handle to map callback to user context.\nwallet_handle: wallet handler (created by open_wallet).\ncred_id: (optional, default is a random one) identifier by which credential will be stored in the wallet\ncred_req_metadata_json: a credential request metadata created by indy_prover_create_credential_req\ncred_json: credential json received from issuer\ncred_def_json: credential definition json related to in \nrev_reg_def_json: revocation registry definition json related to in \ncb: Callback that takes command result as parameter.\n\n#Returns\nout_cred_id: identifier by which credential is stored in the wallet\n\n#Errors\nAnnoncreds*\nCommon*\nWallet*", + "docs": "Check credential provided by Issuer for the given credential request,\nupdates the credential by a master secret and stores in a secure wallet.\n\nTo support efficient and flexible search the following tags will be created for stored credential:\n {\n \"schema_id\": ,\n \"schema_issuer_did\": ,\n \"schema_name\": ,\n \"schema_version\": ,\n \"issuer_did\": ,\n \"cred_def_id\": ,\n \"rev_reg_id\": , // \"None\" as string if not present\n // for every attribute in \n \"attr::::marker\": \"1\",\n \"attr::::value\": ,\n }\n\n#Params\ncommand_handle: command handle to map callback to user context.\nwallet_handle: wallet handler (created by open_wallet).\ncred_id: (optional, default is a random one) identifier by which credential will be stored in the wallet\ncred_req_metadata_json: a credential request metadata created by indy_prover_create_credential_req\ncred_json: credential json received from issuer\ncred_def_json: credential definition json related to in \nrev_reg_def_json: revocation registry definition json related to in \ncb: Callback that takes command result as parameter.\n\n#Returns\nout_cred_id: identifier by which credential is stored in the wallet\n\n#Errors\nAnnoncreds*\nCommon*\nWallet*", "group": "anoncreds", "params": [ {"name": "command_handle", "type": "indy_handle_t"}, @@ -1008,14 +1008,14 @@ "ret": "indy_error_t" }, "indy_submit_action": { - "docs": "Send action to particular nodes of validator pool.\n\nThe request is sent to the nodes as is. It's assumed that it's already prepared.\n\n#Params\ncommand_handle: command handle to map callback to caller context.\npool_handle: pool handle (created by open_pool_ledger).\nrequest_json: Request data json.\nnodes: (Optional) List of node names to send the request.\ntimeout: (Optional) Time to wait respond from nodes (override the default timeout) (in sec).\ncb: Callback that takes command result as parameter.\n\n#Returns\nRequest result as json.\n\n#Errors\nCommon*\nLedger*", + "docs": "Send action to particular nodes of validator pool.\n\nThe list of requests can be send:\n POOL_RESTART\n GET_VALIDATOR_INFO\n\nThe request is sent to the nodes as is. It's assumed that it's already prepared.\n\n#Params\ncommand_handle: command handle to map callback to caller context.\npool_handle: pool handle (created by open_pool_ledger).\nrequest_json: Request data json.\nnodes: (Optional) List of node names to send the request.\n [\"Node1\", \"Node2\",....\"NodeN\"]\ntimeout: (Optional) Time to wait respond from nodes (override the default timeout) (in sec).\n Pass -1 to use default timeout\ncb: Callback that takes command result as parameter.\n\n#Returns\nRequest result as json.\n\n#Errors\nCommon*\nLedger*", "group": "ledger", "params": [ {"name": "command_handle", "type": "indy_handle_t"}, {"name": "pool_handle", "type": "indy_handle_t"}, {"name": "request_json", "type": "const char*", "json": true}, {"name": "nodes", "type": "const char*", "json": true}, - {"name": "timeout", "type": "indy_i32_t"}, + {"name": "timeout", "type": "indy_i32_t", "optional": true}, { "name": "cb", "params": [ @@ -1380,7 +1380,7 @@ {"name": "justification", "type": "const char*"}, {"name": "reinstall", "type": "indy_bool_t"}, {"name": "force", "type": "indy_bool_t"}, - {"name": "package", "type": "const char*"}, + {"name": "package_", "type": "const char*"}, { "name": "cb", "params": [ @@ -2228,7 +2228,7 @@ "ret": "indy_error_t" }, "indy_create_wallet": { - "docs": "Create a new secure wallet.\n\n#Params\nconfig: Wallet configuration json.\n{\n \"id\": string, Identifier of the wallet.\n Configured storage uses this identifier to lookup exact wallet data placement.\n \"storage_type\": optional, Type of the wallet storage. Defaults to 'default'.\n 'Default' storage type allows to store wallet data in the local file.\n Custom storage types can be registered with indy_register_wallet_storage call.\n \"storage_config\": optional, Storage configuration json. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type configuration is:\n {\n \"path\": optional, Path to the directory with wallet files.\n Defaults to $HOME/.indy_client/wallets.\n Wallet will be stored in the file {path}/{id}/sqlite.db\n }\n}\ncredentials: Wallet credentials json\n{\n \"key\": string, Passphrase used to derive wallet master key\n \"storage_credentials\": optional Credentials for wallet storage. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type should be empty.\n\n}\n\n#Returns\nerr: Error code\n\n#Errors\nCommon*\nWallet*", + "docs": "Create a new secure wallet.\n\n#Params\nconfig: Wallet configuration json.\n{\n \"id\": string, Identifier of the wallet.\n Configured storage uses this identifier to lookup exact wallet data placement.\n \"storage_type\": optional, Type of the wallet storage. Defaults to 'default'.\n 'Default' storage type allows to store wallet data in the local file.\n Custom storage types can be registered with indy_register_wallet_storage call.\n \"storage_config\": optional, Storage configuration json. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type configuration is:\n {\n \"path\": optional, Path to the directory with wallet files.\n Defaults to $HOME/.indy_client/wallets.\n Wallet will be stored in the file {path}/{id}/sqlite.db\n }\n}\ncredentials: Wallet credentials json\n{\n \"key\": string, Passphrase used to derive wallet master key\n \"storage_credentials\": optional Credentials for wallet storage. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type should be empty.\n \"key_derivation_method\": optional algorithm to use for master key derivation:\n ARGON2I_MOD (used by default)\n ARGON2I_INT - less secured but faster\n}\n\n#Returns\nerr: Error code\n\n#Errors\nCommon*\nWallet*", "group": "wallet", "params": [ {"name": "command_handle", "type": "indy_handle_t"}, @@ -2245,7 +2245,7 @@ "ret": "indy_error_t" }, "indy_open_wallet": { - "docs": "Open the wallet.\n\nWallet must be previously created with indy_create_wallet method.\n\n#Params\nconfig: Wallet configuration json.\n {\n \"id\": string, Identifier of the wallet.\n Configured storage uses this identifier to lookup exact wallet data placement.\n \"storage_type\": optional, Type of the wallet storage. Defaults to 'default'.\n 'Default' storage type allows to store wallet data in the local file.\n Custom storage types can be registered with indy_register_wallet_storage call.\n \"storage_config\": optional, Storage configuration json. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type configuration is:\n {\n \"path\": optional, Path to the directory with wallet files.\n Defaults to $HOME/.indy_client/wallets.\n Wallet will be stored in the file {path}/{id}/sqlite.db\n }\n\n }\ncredentials: Wallet credentials json\n {\n \"key\": string, Passphrase used to derive current wallet master key\n \"rekey\": optional, If present than wallet master key will be rotated to a new one\n derived from this passphrase.\n \"storage_credentials\": optional Credentials for wallet storage. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type should be empty.\n\n }\n\n#Returns\nerr: Error code\nhandle: Handle to opened wallet to use in methods that require wallet access.\n\n#Errors\nCommon*\nWallet*", + "docs": "Open the wallet.\n\nWallet must be previously created with indy_create_wallet method.\n\n#Params\nconfig: Wallet configuration json.\n {\n \"id\": string, Identifier of the wallet.\n Configured storage uses this identifier to lookup exact wallet data placement.\n \"storage_type\": optional, Type of the wallet storage. Defaults to 'default'.\n 'Default' storage type allows to store wallet data in the local file.\n Custom storage types can be registered with indy_register_wallet_storage call.\n \"storage_config\": optional, Storage configuration json. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type configuration is:\n {\n \"path\": optional, Path to the directory with wallet files.\n Defaults to $HOME/.indy_client/wallets.\n Wallet will be stored in the file {path}/{id}/sqlite.db\n }\n\n }\ncredentials: Wallet credentials json\n {\n \"key\": string, Passphrase used to derive current wallet master key\n \"rekey\": optional, If present than wallet master key will be rotated to a new one\n derived from this passphrase.\n \"storage_credentials\": optional Credentials for wallet storage. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type should be empty.\n \"key_derivation_method\": optional algorithm to use for master key derivation:\n ARGON2I_MOD (used by default)\n ARGON2I_INT - less secured but faster\n \"rekey_derivation_method\": optional algorithm to use for master rekey derivation:\n ARGON2I_MOD (used by default)\n ARGON2I_INT - less secured but faster\n }\n\n#Returns\nerr: Error code\nhandle: Handle to opened wallet to use in methods that require wallet access.\n\n#Errors\nCommon*\nWallet*", "group": "wallet", "params": [ {"name": "command_handle", "type": "indy_handle_t"}, @@ -2263,7 +2263,7 @@ "ret": "indy_error_t" }, "indy_export_wallet": { - "docs": "Exports opened wallet\n\n#Params:\nwallet_handle: wallet handle returned by indy_open_wallet\nexport_config: JSON containing settings for input operation.\n {\n \"path\": , Path of the file that contains exported wallet content\n \"key\": , Passphrase used to derive export key\n }\n\n#Returns\nError code\n\n#Errors\nCommon*\nWallet*", + "docs": "Exports opened wallet\n\n#Params:\nwallet_handle: wallet handle returned by indy_open_wallet\nexport_config: JSON containing settings for input operation.\n {\n \"path\": , Path of the file that contains exported wallet content\n \"key\": , Passphrase used to derive export key\n \"key_derivation_method\": optional algorithm to use for export key derivation:\n ARGON2I_MOD (used by default)\n ARGON2I_INT - less secured but faster\n }\n\n#Returns\nError code\n\n#Errors\nCommon*\nWallet*", "group": "wallet", "params": [ {"name": "command_handle", "type": "indy_handle_t"}, @@ -2280,7 +2280,7 @@ "ret": "indy_error_t" }, "indy_import_wallet": { - "docs": "Creates a new secure wallet and then imports its content\naccording to fields provided in import_config\nThis can be seen as an indy_create_wallet call with additional content import\n\n#Params\nconfig: Wallet configuration json.\n{\n \"id\": string, Identifier of the wallet.\n Configured storage uses this identifier to lookup exact wallet data placement.\n \"storage_type\": optional, Type of the wallet storage. Defaults to 'default'.\n 'Default' storage type allows to store wallet data in the local file.\n Custom storage types can be registered with indy_register_wallet_storage call.\n \"storage_config\": optional, Storage configuration json. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type configuration is:\n {\n \"path\": optional, Path to the directory with wallet files.\n Defaults to $HOME/.indy_client/wallets.\n Wallet will be stored in the file {path}/{id}/sqlite.db\n }\n}\ncredentials: Wallet credentials json\n{\n \"key\": string, Passphrase used to derive wallet master key\n \"storage_credentials\": optional Credentials for wallet storage. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type should be empty.\n\n}\nimport_config: Import settings json.\n{\n \"path\": , path of the file that contains exported wallet content\n \"key\": , passphrase used to derive export key\n}\n\n#Returns\nError code\n\n#Errors\nCommon*\nWallet*", + "docs": "Creates a new secure wallet and then imports its content\naccording to fields provided in import_config\nThis can be seen as an indy_create_wallet call with additional content import\n\n#Params\nconfig: Wallet configuration json.\n{\n \"id\": string, Identifier of the wallet.\n Configured storage uses this identifier to lookup exact wallet data placement.\n \"storage_type\": optional, Type of the wallet storage. Defaults to 'default'.\n 'Default' storage type allows to store wallet data in the local file.\n Custom storage types can be registered with indy_register_wallet_storage call.\n \"storage_config\": optional, Storage configuration json. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type configuration is:\n {\n \"path\": optional, Path to the directory with wallet files.\n Defaults to $HOME/.indy_client/wallets.\n Wallet will be stored in the file {path}/{id}/sqlite.db\n }\n}\ncredentials: Wallet credentials json\n{\n \"key\": string, Passphrase used to derive wallet master key\n \"storage_credentials\": optional Credentials for wallet storage. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type should be empty.\n \"key_derivation_method\": optional algorithm to use for master key derivation:\n ARGON2I_MOD (used by default)\n ARGON2I_INT - less secured but faster\n}\nimport_config: Import settings json.\n{\n \"path\": , path of the file that contains exported wallet content\n \"key\": , passphrase used to derive export key\n}\n\n#Returns\nError code\n\n#Errors\nCommon*\nWallet*", "group": "wallet", "params": [ {"name": "command_handle", "type": "indy_handle_t"}, @@ -2314,7 +2314,7 @@ "ret": "indy_error_t" }, "indy_delete_wallet": { - "docs": "Deletes created wallet.\n\n#Params\nconfig: Wallet configuration json.\n{\n \"id\": string, Identifier of the wallet.\n Configured storage uses this identifier to lookup exact wallet data placement.\n \"storage_type\": optional, Type of the wallet storage. Defaults to 'default'.\n 'Default' storage type allows to store wallet data in the local file.\n Custom storage types can be registered with indy_register_wallet_storage call.\n \"storage_config\": optional, Storage configuration json. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type configuration is:\n {\n \"path\": optional, Path to the directory with wallet files.\n Defaults to $HOME/.indy_client/wallets.\n Wallet will be stored in the file {path}/{id}/sqlite.db\n }\n}\ncredentials: Wallet credentials json\n{\n \"key\": string, Passphrase used to derive wallet master key\n \"storage_credentials\": optional Credentials for wallet storage. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type should be empty.\n\n}\n\n#Returns\nError code\n\n#Errors\nCommon*\nWallet*", + "docs": "Deletes created wallet.\n\n#Params\nconfig: Wallet configuration json.\n{\n \"id\": string, Identifier of the wallet.\n Configured storage uses this identifier to lookup exact wallet data placement.\n \"storage_type\": optional, Type of the wallet storage. Defaults to 'default'.\n 'Default' storage type allows to store wallet data in the local file.\n Custom storage types can be registered with indy_register_wallet_storage call.\n \"storage_config\": optional, Storage configuration json. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type configuration is:\n {\n \"path\": optional, Path to the directory with wallet files.\n Defaults to $HOME/.indy_client/wallets.\n Wallet will be stored in the file {path}/{id}/sqlite.db\n }\n}\ncredentials: Wallet credentials json\n{\n \"key\": string, Passphrase used to derive wallet master key\n \"storage_credentials\": optional Credentials for wallet storage. Storage type defines set of supported keys.\n Can be optional if storage supports default configuration.\n For 'default' storage type should be empty.\n \"key_derivation_method\": optional algorithm to use for master key derivation:\n ARGON2I_MOD (used by default)\n ARGON2I_INT - less secured but faster\n}\n\n#Returns\nError code\n\n#Errors\nCommon*\nWallet*", "group": "wallet", "params": [ {"name": "command_handle", "type": "indy_handle_t"}, @@ -2329,6 +2329,23 @@ } ], "ret": "indy_error_t" + }, + "indy_generate_wallet_key": { + "docs": "Generate wallet master key.\n\n#Params\nconfig: (optional) key configuration json.\n{\n \"seed\":optional Seed that allows deterministic key creation (if not set random one will be used).\n}\n\n#Returns\nError code\n\n#Errors\nCommon*\nWallet*", + "group": "wallet", + "params": [ + {"name": "command_handle", "type": "indy_handle_t"}, + {"name": "config", "type": "const char*", "json": true}, + { + "name": "fn", + "params": [ + {"name": "xcommand_handle", "type": "indy_handle_t"}, + {"name": "err", "type": "indy_error_t"}, + {"name": "key", "type": "const char *const"} + ] + } + ], + "ret": "indy_error_t" } } } \ No newline at end of file diff --git a/wrappers/nodejs/codegen/hParser.js b/wrappers/nodejs/codegen/hParser.js index fcc4153c00..6168bbb5f7 100644 --- a/wrappers/nodejs/codegen/hParser.js +++ b/wrappers/nodejs/codegen/hParser.js @@ -238,10 +238,12 @@ api.functions.indy_parse_get_revoc_reg_def_response.params[1].json = true api.functions.indy_parse_get_revoc_reg_delta_response.params[1].json = true api.functions.indy_parse_get_revoc_reg_response.params[1].json = true api.functions.indy_parse_get_schema_response.params[1].json = true +api.functions.indy_submit_action.params[3].json = true api.functions.indy_build_get_revoc_reg_delta_request.params[3].timestamp = true api.functions.indy_build_get_revoc_reg_delta_request.params[4].timestamp = true api.functions.indy_issuer_create_credential.params[6].optional = true +api.functions.indy_submit_action.params[4].optional = true fs.writeFileSync(path.resolve(__dirname, 'api.json'), stringify(api, {maxLength: 100}), 'utf8') diff --git a/wrappers/nodejs/package.json b/wrappers/nodejs/package.json index a75a3abd06..77aa1be34f 100644 --- a/wrappers/nodejs/package.json +++ b/wrappers/nodejs/package.json @@ -1,6 +1,6 @@ { "name": "indy-sdk", - "version": "1.6.2", + "version": "1.6.3", "description": "Native bindings for hyperledger indy", "author": "hyperledger", "license": "Apache-2.0", diff --git a/wrappers/nodejs/src/index.js b/wrappers/nodejs/src/index.js index 729a4e0a52..d3de419b9e 100644 --- a/wrappers/nodejs/src/index.js +++ b/wrappers/nodejs/src/index.js @@ -333,7 +333,7 @@ indy.submitRequest = function submitRequest (poolHandle, request, cb) { indy.submitAction = function submitAction (poolHandle, request, nodes, timeout, cb) { cb = wrapIndyCallback(cb, fromJson) - capi.submitAction(poolHandle, toJson(request), toJson(nodes), nodes == null ? -1 : nodes, cb) + capi.submitAction(poolHandle, toJson(request), toJson(nodes), timeout == null ? -1 : timeout, cb) return cb.promise } @@ -773,4 +773,10 @@ indy.deleteWallet = function deleteWallet (config, credentials, cb) { return cb.promise } +indy.generateWalletKey = function generateWalletKey (config, cb) { + cb = wrapIndyCallback(cb) + capi.generateWalletKey(toJson(config), cb) + return cb.promise +} + module.exports = indy diff --git a/wrappers/nodejs/src/indy_codegen.h b/wrappers/nodejs/src/indy_codegen.h index 3b98249f4d..a12cd98de9 100644 --- a/wrappers/nodejs/src/indy_codegen.h +++ b/wrappers/nodejs/src/indy_codegen.h @@ -1052,13 +1052,13 @@ NAN_METHOD(submitAction) { INDY_ASSERT_STRING(submitAction, 1, request) INDY_ASSERT_STRING(submitAction, 2, nodes) INDY_ASSERT_NUMBER(submitAction, 3, timeout) - INDY_ASSERT_FUNCTION(submitRequest, 4) + INDY_ASSERT_FUNCTION(submitAction, 4) indy_handle_t arg0 = info[0]->Int32Value(); const char* arg1 = argToCString(info[1]); const char* arg2 = argToCString(info[2]); indy_i32_t arg3 = info[3]->Int32Value(); IndyCallback* icb = argToIndyCb(info[4]); - indyCalled(icb, indy_submit_action(icb->handle, arg0, arg1, arg2, arg3, submitRequest_cb)); + indyCalled(icb, indy_submit_action(icb->handle, arg0, arg1, arg2, arg3, submitAction_cb)); delete arg1; delete arg2; } @@ -2479,6 +2479,22 @@ NAN_METHOD(deleteWallet) { delete arg1; } +void generateWalletKey_cb(indy_handle_t handle, indy_error_t xerr, const char *const arg0) { + IndyCallback* icb = IndyCallback::getCallback(handle); + if(icb != nullptr){ + icb->cbString(xerr, arg0); + } +} +NAN_METHOD(generateWalletKey) { + INDY_ASSERT_NARGS(generateWalletKey, 2) + INDY_ASSERT_STRING(generateWalletKey, 0, config) + INDY_ASSERT_FUNCTION(generateWalletKey, 1) + const char* arg0 = argToCString(info[0]); + IndyCallback* icb = argToIndyCb(info[1]); + indyCalled(icb, indy_generate_wallet_key(icb->handle, arg0, generateWalletKey_cb)); + delete arg0; +} + NAN_MODULE_INIT(InitAll) { Nan::Export(target, "issuerCreateSchema", issuerCreateSchema); Nan::Export(target, "issuerCreateAndStoreCredentialDef", issuerCreateAndStoreCredentialDef); @@ -2599,5 +2615,6 @@ NAN_MODULE_INIT(InitAll) { Nan::Export(target, "importWallet", importWallet); Nan::Export(target, "closeWallet", closeWallet); Nan::Export(target, "deleteWallet", deleteWallet); + Nan::Export(target, "generateWalletKey", generateWalletKey); } NODE_MODULE(indynodejs, InitAll) diff --git a/wrappers/nodejs/test/helpers/makeTestPool.js b/wrappers/nodejs/test/helpers/makeTestPool.js index c4f6481212..522ab5fa5d 100644 --- a/wrappers/nodejs/test/helpers/makeTestPool.js +++ b/wrappers/nodejs/test/helpers/makeTestPool.js @@ -6,10 +6,10 @@ module.exports = function () { var poolIp = process.env.TEST_POOL_IP || '127.0.0.1' var genesisTxn = [ - {'reqSignature': {}, 'txn': {'data': {'data': {'alias': 'Node1', 'blskey': '4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba', 'client_ip': poolIp, 'client_port': 9702, 'node_ip': poolIp, 'node_port': 9701, 'services': ['VALIDATOR']}, 'dest': 'Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv'}, 'metadata': {'from': 'Th7MpTaRZVRYnPiabds81Y'}, 'type': '0'}, 'txnMetadata': {'seqNo': 1, 'txnId': 'fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62'}, 'ver': '1'}, - {'reqSignature': {}, 'txn': {'data': {'data': {'alias': 'Node2', 'blskey': '37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk', 'client_ip': poolIp, 'client_port': 9704, 'node_ip': poolIp, 'node_port': 9703, 'services': ['VALIDATOR']}, 'dest': '8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb'}, 'metadata': {'from': 'EbP4aYNeTHL6q385GuVpRV'}, 'type': '0'}, 'txnMetadata': {'seqNo': 2, 'txnId': '1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc'}, 'ver': '1'}, - {'reqSignature': {}, 'txn': {'data': {'data': {'alias': 'Node3', 'blskey': '3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5', 'client_ip': poolIp, 'client_port': 9706, 'node_ip': poolIp, 'node_port': 9705, 'services': ['VALIDATOR']}, 'dest': 'DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya'}, 'metadata': {'from': '4cU41vWW82ArfxJxHkzXPG'}, 'type': '0'}, 'txnMetadata': {'seqNo': 3, 'txnId': '7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4'}, 'ver': '1'}, - {'reqSignature': {}, 'txn': {'data': {'data': {'alias': 'Node4', 'blskey': '2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw', 'client_ip': poolIp, 'client_port': 9708, 'node_ip': poolIp, 'node_port': 9707, 'services': ['VALIDATOR']}, 'dest': '4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA'}, 'metadata': {'from': 'TWwCRQRZ2ZHMJFn9TzLp7W'}, 'type': '0'}, 'txnMetadata': {'seqNo': 4, 'txnId': 'aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008'}, 'ver': '1'} + {'reqSignature': {}, 'txn': {'data': {'data': {'alias': 'Node1', 'blskey': '4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba', 'blskey_pop': 'RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1', 'client_ip': poolIp, 'client_port': 9702, 'node_ip': poolIp, 'node_port': 9701, 'services': ['VALIDATOR']}, 'dest': 'Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv'}, 'metadata': {'from': 'Th7MpTaRZVRYnPiabds81Y'}, 'type': '0'}, 'txnMetadata': {'seqNo': 1, 'txnId': 'fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62'}, 'ver': '1'}, + {'reqSignature': {}, 'txn': {'data': {'data': {'alias': 'Node2', 'blskey': '37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk', 'blskey_pop': 'Qr658mWZ2YC8JXGXwMDQTzuZCWF7NK9EwxphGmcBvCh6ybUuLxbG65nsX4JvD4SPNtkJ2w9ug1yLTj6fgmuDg41TgECXjLCij3RMsV8CwewBVgVN67wsA45DFWvqvLtu4rjNnE9JbdFTc1Z4WCPA3Xan44K1HoHAq9EVeaRYs8zoF5', 'client_ip': poolIp, 'client_port': 9704, 'node_ip': poolIp, 'node_port': 9703, 'services': ['VALIDATOR']}, 'dest': '8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb'}, 'metadata': {'from': 'EbP4aYNeTHL6q385GuVpRV'}, 'type': '0'}, 'txnMetadata': {'seqNo': 2, 'txnId': '1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc'}, 'ver': '1'}, + {'reqSignature': {}, 'txn': {'data': {'data': {'alias': 'Node3', 'blskey': '3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5', 'blskey_pop': 'QwDeb2CkNSx6r8QC8vGQK3GRv7Yndn84TGNijX8YXHPiagXajyfTjoR87rXUu4G4QLk2cF8NNyqWiYMus1623dELWwx57rLCFqGh7N4ZRbGDRP4fnVcaKg1BcUxQ866Ven4gw8y4N56S5HzxXNBZtLYmhGHvDtk6PFkFwCvxYrNYjh', 'client_ip': poolIp, 'client_port': 9706, 'node_ip': poolIp, 'node_port': 9705, 'services': ['VALIDATOR']}, 'dest': 'DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya'}, 'metadata': {'from': '4cU41vWW82ArfxJxHkzXPG'}, 'type': '0'}, 'txnMetadata': {'seqNo': 3, 'txnId': '7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4'}, 'ver': '1'}, + {'reqSignature': {}, 'txn': {'data': {'data': {'alias': 'Node4', 'blskey': '2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw', 'blskey_pop': 'RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP', 'client_ip': poolIp, 'client_port': 9708, 'node_ip': poolIp, 'node_port': 9707, 'services': ['VALIDATOR']}, 'dest': '4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA'}, 'metadata': {'from': 'TWwCRQRZ2ZHMJFn9TzLp7W'}, 'type': '0'}, 'txnMetadata': {'seqNo': 4, 'txnId': 'aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008'}, 'ver': '1'} ] var txnData = genesisTxn.map(function (line) { diff --git a/wrappers/nodejs/test/wallet.js b/wrappers/nodejs/test/wallet.js index 9a1b0ed03f..842cd9a01d 100644 --- a/wrappers/nodejs/test/wallet.js +++ b/wrappers/nodejs/test/wallet.js @@ -53,5 +53,10 @@ test('wallet', async function (t) { await indy.closeWallet(handle) await indy.deleteWallet(walletConfig, walletCredentials) + var key = await indy.generateWalletKey({}) + walletCredentials = {'key': key, 'key_derivation_method': 'RAW'} + await indy.createWallet(walletConfig, walletCredentials) + await indy.deleteWallet(walletConfig, walletCredentials) + pool.cleanup() }) diff --git a/wrappers/python/indy/wallet.py b/wrappers/python/indy/wallet.py index bf41ba4e70..05c78a5340 100644 --- a/wrappers/python/indy/wallet.py +++ b/wrappers/python/indy/wallet.py @@ -1,6 +1,7 @@ from .libindy import do_call, create_cb from ctypes import * +from typing import Optional import logging @@ -28,13 +29,16 @@ async def create_wallet(config: str, } :param credentials: Wallet credentials json { - "key": string, Passphrase used to derive wallet master key + "key": string, Key or passphrase used for wallet key derivation. + Look to key_derivation_method param for information about supported key derivation methods. "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. Can be optional if storage supports default configuration. For 'default' storage type should be empty. - "key_derivation_method": optional algorithm to use for master key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster + "key_derivation_method": optional Algorithm to use for wallet key derivation: + ARGON2I_MOD - derive secured wallet master key (used by default) + ARGON2I_INT - derive secured wallet master key (less secured but faster) + RAW - raw wallet key master provided (skip derivation). + RAW keys can be generated with generate_wallet_key call } :return: Error code """ @@ -86,18 +90,21 @@ async def open_wallet(config: str, } :param credentials: Wallet credentials json { - "key": string, Passphrase used to derive current wallet master key - "rekey": optional, If present than wallet master key will be rotated to a new one - derived from this passphrase. + "key": string, Key or passphrase used for wallet key derivation. + Look to key_derivation_method param for information about supported key derivation methods. + "rekey": optional, If present than wallet master key will be rotated to a new one. "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. Can be optional if storage supports default configuration. For 'default' storage type should be empty. - "key_derivation_method": optional algorithm to use for master key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster + "key_derivation_method": optional Algorithm to use for wallet key derivation: + ARGON2I_MOD - derive secured wallet master key (used by default) + ARGON2I_INT - derive secured wallet master key (less secured but faster) + RAW - raw wallet master key provided (skip derivation) "rekey_derivation_method": optional algorithm to use for master rekey derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster + ARGON2I_MOD - derive secured wallet master rekey (used by default) + ARGON2I_INT - derive secured wallet master rekey (less secured but faster) + RAW - raw wallet rekey master provided (skip derivation). + RAW keys can be generated with generate_wallet_key call } :return: Handle to opened wallet to use in methods that require wallet access. """ @@ -170,13 +177,16 @@ async def delete_wallet(config: str, } :param credentials: Wallet credentials json { - "key": string, Passphrase used to derive wallet master key + "key": string, Key or passphrase used for wallet key derivation. + Look to key_derivation_method param for information about supported key derivation methods. "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. Can be optional if storage supports default configuration. For 'default' storage type should be empty. - "key_derivation_method": optional algorithm to use for master key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster + "key_derivation_method": optional Algorithm to use for wallet key derivation: + ARGON2I_MOD - derive secured wallet master key (used by default) + ARGON2I_INT - derive secured wallet master key (less secured but faster) + RAW - raw wallet key master provided (skip derivation). + RAW keys can be generated with generate_wallet_key call } :return: """ @@ -210,10 +220,13 @@ async def export_wallet(handle: int, :param export_config_json: JSON containing settings for input operation. { "path": path of the file that contains exported wallet content - "key": passphrase used to export key - "key_derivation_method": optional algorithm for учзщке key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster + "key": string, Key or passphrase used for wallet export key derivation. + Look to key_derivation_method param for information about supported key derivation methods. + "key_derivation_method": optional algorithm to use for export key derivation: + ARGON2I_MOD - derive secured wallet export key (used by default) + ARGON2I_INT - derive secured wallet export key (less secured but faster) + RAW - raw wallet export key provided (skip derivation). + RAW keys can be generated with generate_wallet_key call } :return: """ @@ -263,17 +276,20 @@ async def import_wallet(config: str, } :param credentials: Wallet credentials json { - "key": string, Passphrase used to derive wallet master key + "key": string, Key or passphrase used for wallet key derivation. + Look to key_derivation_method param for information about supported key derivation methods. "storage_credentials": optional Credentials for wallet storage. Storage type defines set of supported keys. Can be optional if storage supports default configuration. For 'default' storage type should be empty. - "key_derivation_method": optional algorithm to use for master key derivation: - ARAGON2I_MOD (used by default) - ARAGON2I_INT - less secured but faster + "key_derivation_method": optional Algorithm to use for wallet key derivation: + ARGON2I_MOD - derive secured wallet master key (used by default) + ARGON2I_INT - derive secured wallet master key (less secured but faster) + RAW - raw wallet key master provided (skip derivation). + RAW keys can be generated with generate_wallet_key call } :param import_config_json: JSON containing settings for input operationЖ { "path": path of the file that contains exported wallet content - "key": passphrase used to export key + "key": key used for export of the wallet } :return: Error code """ @@ -299,3 +315,36 @@ async def import_wallet(config: str, import_wallet.cb) logger.debug("import_wallet: <<<") + + +async def generate_wallet_key(config: Optional[str]) -> str: + """ + Generate wallet master key. + Returned key is compatible with "RAW" key derivation method. + It allows to avoid expensive key derivation for use cases when wallet keys can be stored in a secure enclave. + + :param config: (optional) key configuration json. + { + seed": optional Seed that allows deterministic key creation (if not set random one will be used). + } + :return: Error code + """ + + logger = logging.getLogger(__name__) + logger.debug("generate_wallet_key: >>> config: %r", + config) + + if not hasattr(generate_wallet_key, "cb"): + logger.debug("generate_wallet_key: Creating callback") + generate_wallet_key.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + + c_config = c_char_p(config.encode('utf-8')) if config is not None else None + + key = await do_call('indy_generate_wallet_key', + c_config, + generate_wallet_key.cb) + + res = key.decode() + + logger.debug("generate_wallet_key: <<< res: %r", res) + return res diff --git a/wrappers/python/setup.py b/wrappers/python/setup.py index 04184276f2..5872d76d04 100644 --- a/wrappers/python/setup.py +++ b/wrappers/python/setup.py @@ -2,7 +2,7 @@ setup( name='python3-indy', - version='1.6.2', + version='1.6.3', packages=['indy'], url='https://github.com/hyperledger/indy-sdk', license='MIT/Apache-2.0', diff --git a/wrappers/python/tests/conftest.py b/wrappers/python/tests/conftest.py index 6f06cbacab..1d60c1d313 100644 --- a/wrappers/python/tests/conftest.py +++ b/wrappers/python/tests/conftest.py @@ -149,7 +149,7 @@ def credentials(): logger = logging.getLogger(__name__) logger.debug("credentials: >>>") - res = '{"key":"key", "key_derivation_method": "ARAGON2I_INT"}' + res = '{"key":"key", "key_derivation_method": "ARGON2I_INT"}' logger.debug("credentials: <<< res: %r", res) return res @@ -305,13 +305,13 @@ def pool_genesis_txn_data(pool_genesis_txn_count, pool_ip): assert 0 < pool_genesis_txn_count <= 4 res = "\n".join([ - '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","client_ip":"{}","client_port":9702,"node_ip":"{}","node_port":9701,"services":["VALIDATOR"]}},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}},"metadata":{{"from":"Th7MpTaRZVRYnPiabds81Y"}},"type":"0"}},"txnMetadata":{{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}},"ver":"1"}}'.format( + '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node1","blskey":"4N8aUNHSgjQVgkpm8nhNEfDf6txHznoYREg9kirmJrkivgL4oSEimFF6nsQ6M41QvhM2Z33nves5vfSn9n1UwNFJBYtWVnHYMATn76vLuL3zU88KyeAYcHfsih3He6UHcXDxcaecHVz6jhCYz1P2UZn2bDVruL5wXpehgBfBaLKm3Ba","blskey_pop":"RahHYiCvoNCtPTrVtP7nMC5eTYrsUA8WjXbdhNc8debh1agE9bGiJxWBXYNFbnJXoXhWFMvyqhqhRoq737YQemH5ik9oL7R4NTTCz2LEZhkgLJzB3QRQqJyBNyv7acbdHrAT8nQ9UkLbaVL9NBpnWXBTw4LEMePaSHEw66RzPNdAX1","client_ip":"{}","client_port":9702,"node_ip":"{}","node_port":9701,"services":["VALIDATOR"]}},"dest":"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv"}},"metadata":{{"from":"Th7MpTaRZVRYnPiabds81Y"}},"type":"0"}},"txnMetadata":{{"seqNo":1,"txnId":"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62"}},"ver":"1"}}'.format( pool_ip, pool_ip), - '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","client_ip":"{}","client_port":9704,"node_ip":"{}","node_port":9703,"services":["VALIDATOR"]}},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}},"metadata":{{"from":"EbP4aYNeTHL6q385GuVpRV"}},"type":"0"}},"txnMetadata":{{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}},"ver":"1"}}'.format( + '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node2","blskey":"37rAPpXVoxzKhz7d9gkUe52XuXryuLXoM6P6LbWDB7LSbG62Lsb33sfG7zqS8TK1MXwuCHj1FKNzVpsnafmqLG1vXN88rt38mNFs9TENzm4QHdBzsvCuoBnPH7rpYYDo9DZNJePaDvRvqJKByCabubJz3XXKbEeshzpz4Ma5QYpJqjk","blskey_pop":"Qr658mWZ2YC8JXGXwMDQTzuZCWF7NK9EwxphGmcBvCh6ybUuLxbG65nsX4JvD4SPNtkJ2w9ug1yLTj6fgmuDg41TgECXjLCij3RMsV8CwewBVgVN67wsA45DFWvqvLtu4rjNnE9JbdFTc1Z4WCPA3Xan44K1HoHAq9EVeaRYs8zoF5","client_ip":"{}","client_port":9704,"node_ip":"{}","node_port":9703,"services":["VALIDATOR"]}},"dest":"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb"}},"metadata":{{"from":"EbP4aYNeTHL6q385GuVpRV"}},"type":"0"}},"txnMetadata":{{"seqNo":2,"txnId":"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc"}},"ver":"1"}}'.format( pool_ip, pool_ip), - '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","client_ip":"{}","client_port":9706,"node_ip":"{}","node_port":9705,"services":["VALIDATOR"]}},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"}},"metadata":{{"from":"4cU41vWW82ArfxJxHkzXPG"}},"type":"0"}},"txnMetadata":{{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"}},"ver":"1"}}'.format( + '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","blskey_pop":"QwDeb2CkNSx6r8QC8vGQK3GRv7Yndn84TGNijX8YXHPiagXajyfTjoR87rXUu4G4QLk2cF8NNyqWiYMus1623dELWwx57rLCFqGh7N4ZRbGDRP4fnVcaKg1BcUxQ866Ven4gw8y4N56S5HzxXNBZtLYmhGHvDtk6PFkFwCvxYrNYjh","client_ip":"{}","client_port":9706,"node_ip":"{}","node_port":9705,"services":["VALIDATOR"]}},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"}},"metadata":{{"from":"4cU41vWW82ArfxJxHkzXPG"}},"type":"0"}},"txnMetadata":{{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"}},"ver":"1"}}'.format( pool_ip, pool_ip), - '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","client_ip":"{}","client_port":9708,"node_ip":"{}","node_port":9707,"services":["VALIDATOR"]}},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"}},"metadata":{{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"}},"type":"0"}},"txnMetadata":{{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"}},"ver":"1"}}'.format( + '{{"reqSignature":{{}},"txn":{{"data":{{"data":{{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","blskey_pop":"RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP","client_ip":"{}","client_port":9708,"node_ip":"{}","node_port":9707,"services":["VALIDATOR"]}},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"}},"metadata":{{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"}},"type":"0"}},"txnMetadata":{{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"}},"ver":"1"}}'.format( pool_ip, pool_ip) ][0:pool_genesis_txn_count]) diff --git a/wrappers/python/tests/did/test_get_did_metadata.py b/wrappers/python/tests/did/test_get_did_metadata.py index d77bddc6b3..b4dceae772 100644 --- a/wrappers/python/tests/did/test_get_did_metadata.py +++ b/wrappers/python/tests/did/test_get_did_metadata.py @@ -39,7 +39,7 @@ async def test_get_did_metadata_works_for_invalid_handle(wallet_handle, metadata @pytest.mark.asyncio -async def test_get_did_metadata_works_for_not_found_did(wallet_handle, did_my1, metadata): +async def test_get_did_metadata_works_for_not_found_did(wallet_handle, did_my1): with pytest.raises(IndyError) as e: - await did.set_did_metadata(wallet_handle, did_my1, metadata) + await did.get_did_metadata(wallet_handle, did_my1) assert ErrorCode.WalletItemNotFound == e.value.error_code diff --git a/wrappers/python/tests/did/test_set_did_metadata.py b/wrappers/python/tests/did/test_set_did_metadata.py index a35047aa54..d248d7d1be 100644 --- a/wrappers/python/tests/did/test_set_did_metadata.py +++ b/wrappers/python/tests/did/test_set_did_metadata.py @@ -40,7 +40,5 @@ async def test_set_did_metadata_works_for_invalid_handle(wallet_handle, did_my1, @pytest.mark.asyncio -async def test_set_did_metadata_works_for_not_found_did(wallet_handle, did_my1, metadata): - with pytest.raises(IndyError) as e: - await did.set_did_metadata(wallet_handle, did_my1, metadata) - assert ErrorCode.WalletItemNotFound == e.value.error_code +async def test_set_did_metadata_works_for_unknown_did(wallet_handle, did_my1, metadata): + await did.set_did_metadata(wallet_handle, did_my1, metadata) diff --git a/wrappers/python/tests/wallet/test_generate_wallet_key.py b/wrappers/python/tests/wallet/test_generate_wallet_key.py new file mode 100644 index 0000000000..69bf4f0da1 --- /dev/null +++ b/wrappers/python/tests/wallet/test_generate_wallet_key.py @@ -0,0 +1,24 @@ +import json + +import pytest + +from indy import wallet + + +@pytest.mark.asyncio +async def test_generate_wallet_key_works(wallet_config): + key = await wallet.generate_wallet_key(None) + + credentials = {'key': key, 'key_derivation_method': 'RAW'} + await wallet.create_wallet(wallet_config, json.dumps(credentials)) + await wallet.delete_wallet(wallet_config, json.dumps(credentials)) + + +@pytest.mark.asyncio +async def test_generate_wallet_key_works_for_seed(wallet_config, seed_my1): + key = await wallet.generate_wallet_key(json.dumps({'seed': seed_my1})) + assert key == 'CwMHrEQJnwvuE8q9zbR49jyYtVxVBHNTjCPEPk1aV3cP' + + credentials = {'key': key, 'key_derivation_method': 'RAW'} + await wallet.create_wallet(wallet_config, json.dumps(credentials)) + await wallet.delete_wallet(wallet_config, json.dumps(credentials))