diff --git a/Jenkinsfile b/Jenkinsfile index a4cca4660c..2f538ae78a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,6 +8,7 @@ try { notifyingSuccess() } catch (err) { notifyingFailure(err) + throw err } def testing() { @@ -30,12 +31,10 @@ def publishing() { } parallel([ - 'liblindy-to-cargo' : { publishingLibindyToCargo() }, - 'libindy-rpm-files' : { publishingLibindyRpmFiles() }, - 'libindy-deb-files' : { publishingLibindyDebFiles() }, - 'libindy-win-files' : { publishingLibindyWinFiles() }, - 'python-wrapper-deb-files': { publishingPythonWrapperDebFiles() }, - 'python-wrapper-to-pipy' : { publishingPythonWrapperToPipy() } + 'libindy-rpm-files' : { publishingLibindyRpmFiles() }, + 'libindy-deb-files' : { publishingLibindyDebFiles() }, + 'libindy-win-files' : { publishingLibindyWinFiles() }, + 'python-wrapper-to-pipy': { publishingPythonWrapperToPipy() } ]) } } @@ -54,15 +53,16 @@ def notifyingFailure(err) { node('ubuntu-master') { sendNotification.fail([slack: env.BRANCH_NAME == 'master']) } - throw err } -def openPool(env_name, network_name) { +def openPool(env_name, network_name, pool_ver, plenum_ver, anoncreds_ver, node_ver) { echo "${env_name} Test: Create docker network (${network_name}) for nodes pool and test image" sh "docker network create --subnet=10.0.0.0/8 ${network_name}" - echo "${env_name} Test: Build docker image for nodes pool" - def poolEnv = dockerHelpers.build('indy_pool', 'ci/indy-pool.dockerfile ci', '--build-arg pool_ip=10.0.0.2') + echo "${env_name} Test: Build docker image for nodes pool ver. ${pool_ver}" + echo "${env_name} Test: Building nodes pool for versions: plenum ${plenum_ver}, anoncreds ${anoncreds_ver}, node ${node_ver}" + def poolEnv = dockerHelpers.build("indy_pool_${pool_ver}", 'ci/indy-pool.dockerfile ci', + "--build-arg pool_ip=10.0.0.2 --build-arg indy_plenum_ver=${plenum_ver} --build-arg indy_anoncreds_ver=${anoncreds_ver} --build-arg indy_node_ver=${node_ver}") echo "${env_name} Test: Run nodes pool" return poolEnv.run("--ip=\"10.0.0.2\" --network=${network_name}") } @@ -100,11 +100,9 @@ def libindyTest(file, env_name, run_interoperability_tests, network_name) { echo "${env_name} Test: Checkout csm" checkout scm - sh "cp -r ci libindy" + poolInst = openPool(env_name, network_name, '105', '1.0.95', '1.0.25', '1.0.105') dir('libindy') { - poolInst = openPool(env_name, network_name) - echo "${env_name} Test: Build docker image" def testEnv = dockerHelpers.build('libindy', file) @@ -152,7 +150,7 @@ def libindyWindowsTesting() { dir('libindy') { echo "Windows Test: Download prebuilt dependencies" - bat 'wget -O prebuilt.zip "https://repo.evernym.com/deb/windows-bins/indy-sdk-deps/indy-sdk-deps.zip"' + bat 'wget -O prebuilt.zip "https://repo.evernym.com/libindy/windows/deps/indy-sdk-deps.zip"' bat 'unzip prebuilt.zip -d prebuilt' echo "Windows Test: Build" @@ -220,11 +218,9 @@ def javaWrapperUbuntuTesting() { echo "${env_name} Test: Checkout csm" checkout scm - sh "cp -r ci wrappers/java" + poolInst = openPool(env_name, network_name, '84', '1.0.82', '1.0.25', '1.0.84') dir('wrappers/java') { - poolInst = openPool("Ubuntu Java", network_name) - echo "${env_name} Test: Build docker image" def testEnv = dockerHelpers.build('java-indy-sdk', 'ci/java.dockerfile ci') @@ -252,12 +248,9 @@ def pythonWrapperUbuntuTesting() { echo "${env_name} Test: Checkout csm" checkout scm - sh "cp -r ci wrappers/python" + poolInst = openPool(env_name, network_name, '84', '1.0.82', '1.0.25', '1.0.84') dir('wrappers/python') { - - poolInst = openPool(env_name, network_name) - echo "${env_name} Test: Build docker image" def testEnv = dockerHelpers.build('python-indy-sdk', 'ci/python.dockerfile ci') @@ -278,43 +271,6 @@ def pythonWrapperUbuntuTesting() { } } -def publishingLibindyToCargo() { - node('ubuntu') { - stage('Publish Libindy to Cargo') { - try { - echo 'Publish to Cargo: Checkout csm' - checkout scm - - sh "cp -r ci libindy" - - dir('libindy') { - echo 'Publish to Cargo: Build docker image' - def testEnv = dockerHelpers.build('indy-sdk') - - testEnv.inside { - echo 'Update version' - - sh 'chmod -R 777 ci' - sh "ci/libindy-update-package-version.sh $env.BUILD_NUMBER" - - withCredentials([string(credentialsId: 'cargoSecretKey', variable: 'SECRET')]) { - sh 'cargo login $SECRET' - } - - sh 'cargo package --allow-dirty' - - sh 'cargo publish --allow-dirty' - } - } - } - finally { - echo 'Publish to cargo: Cleanup' - step([$class: 'WsCleanup']) - } - } - } -} - def publishingLibindyRpmFiles() { node('ubuntu') { stage('Publish Libindy RPM Files') { @@ -322,8 +278,6 @@ def publishingLibindyRpmFiles() { echo 'Publish Rpm files: Checkout csm' checkout scm - sh "cp -r ci libindy" - commit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim() dir('libindy') { @@ -355,9 +309,6 @@ def publishingLibindyDebFiles() { echo 'Publish Deb files: Checkout csm' checkout scm - sh "cp -r ci libindy" - sh "cp -r debian libindy" - commit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim() dir('libindy') { @@ -393,7 +344,7 @@ def publishingLibindyWinFiles() { dir('libindy') { echo "Publish Windows files: Download prebuilt dependencies" - bat 'wget -O prebuilt.zip "https://repo.evernym.com/deb/windows-bins/indy-sdk-deps/indy-sdk-deps.zip"' + bat 'wget -O prebuilt.zip "https://repo.evernym.com/libindy/windows/deps/indy-sdk-deps.zip"' bat 'unzip prebuilt.zip -d prebuilt' echo "Publish Windows files: Build" @@ -408,47 +359,14 @@ def publishingLibindyWinFiles() { ]) { bat "cargo build --release" } - } - withCredentials([file(credentialsId: 'EvernymRepoSSHKey', variable: 'evernym_repo_key')]) { - sh "./ci/libindy-win-zip-and-upload.sh $commit '${evernym_repo_key}' $env.BUILD_NUMBER" - } - } - finally { - echo 'Publish Windows files: Cleanup' - step([$class: 'WsCleanup']) - } - } - } -} - -def publishingPythonWrapperDebFiles() { - node('ubuntu') { - stage('Publish Python Wrapper DEB Files') { - try { - echo 'Publish Python Wrapper Deb files: Checkout csm' - checkout scm - - sh "cp -r ci wrappers/python" - - dir('wrappers/python') { - - echo 'Publish Python Wrapper Deb: Build docker image' - def testEnv = dockerHelpers.build('python-indy-sdk', 'ci/python.dockerfile ci') - - testEnv.inside('-u 0:0') { - sh 'chmod -R 777 ci' - - sh "ci/python-wrapper-update-package-version.sh $env.BUILD_NUMBER" - - withCredentials([file(credentialsId: 'EvernymRepoSSHKey', variable: 'evernym_repo_key')]) { - sh "./ci/python-wrapper-deb-build-and-upload.sh $evernym_repo_key" - } + withCredentials([file(credentialsId: 'EvernymRepoSSHKey', variable: 'evernym_repo_key')]) { + sh "./ci/libindy-win-zip-and-upload.sh $commit '${evernym_repo_key}' $env.BUILD_NUMBER" } } } finally { - echo 'Publish Python Wrapper Deb: Cleanup' + echo 'Publish Windows files: Cleanup' step([$class: 'WsCleanup']) } } @@ -462,23 +380,23 @@ def publishingPythonWrapperToPipy() { echo 'Publish Deb files: Checkout csm' checkout scm - echo 'Publish Deb: Build docker image' - def testEnv = dockerHelpers.build('python-indy-sdk', 'ci/python.dockerfile ci') + dir('wrappers/python') { + echo 'Publish Deb: Build docker image' + def testEnv = dockerHelpers.build('python-indy-sdk', 'ci/python.dockerfile ci') - testEnv.inside('-u 0:0') { + testEnv.inside('-u 0:0') { - withCredentials([file(credentialsId: 'pypi_credentials', variable: 'credentialsFile')]) { - sh 'cp $credentialsFile ./wrappers/python/' - sh "cp -r ci wrappers/python" + withCredentials([file(credentialsId: 'pypi_credentials', variable: 'credentialsFile')]) { + sh 'cp $credentialsFile ./' - sh "chmod -R 777 ci" - sh "ci/python-wrapper-update-package-version.sh $env.BUILD_NUMBER" + sh "chmod -R 777 ci" + sh "ci/python-wrapper-update-package-version.sh $env.BUILD_NUMBER" - sh ''' - cd wrappers/python - python3.6 setup.py sdist - python3.6 -m twine upload dist/* --config-file .pypirc - ''' + sh ''' + python3.6 setup.py sdist + python3.6 -m twine upload dist/* --config-file .pypirc + ''' + } } } } diff --git a/README.md b/README.md index 34864a8daa..bcb68b871c 100644 --- a/README.md +++ b/README.md @@ -14,5 +14,18 @@ us on [Jira's Rocket.Chat](chat.hyperledger.org) at #indy-sdk to discuss. * [Ubuntu based distro (Ubuntu 16.04)](doc/ubuntu-build.md) * [RHEL based distro (Amazon Linux 2017.03)](doc/rhel-build.md) * [Windows](doc/windows-build.md) -* [iOS](doc/ios-build.md) * [MacOS](doc/mac-build.md) + +## Wrappers documentation +* [.Net](wrappers/dotnet/README.md) +* [Java](wrappers/java/README.md) +* [Python](wrappers/python/README.md) +* [iOS](wrappers/ios/ios-build.md) + +## Binaries +Builded binaries can be downloaded from https://repo.evernym.com/libindy: +* ubuntu/{master,stable,rc} - Ubuntu deb packages +* windows/{master,stable,rc} - Windows zip-archive with all required DLLs (include libindy itself) and headers +* windows/deps/ - Windows zip archive with dependencies (DLLs and headers) to build libindy from sources +* ios/stable/ - Pods for iOS +* rhel/{master,stable,rc} - RHEL rpms diff --git a/Specs/libindy-core/0.1.1/libindy-core.podspec.json b/Specs/libindy-core/0.1.1/libindy-core.podspec.json index bd0164b1b4..29af039626 100644 --- a/Specs/libindy-core/0.1.1/libindy-core.podspec.json +++ b/Specs/libindy-core/0.1.1/libindy-core.podspec.json @@ -15,7 +15,7 @@ "ios": "10.0" }, "source": { - "http": "https://repo.evernym.com/deb/pods-ios/libindy-core/0.1.1/libindy-core-ios.tar.gz" + "http": "https://repo.evernym.com/libindy/ios/stable/libindy-core/0.1.1/libindy-core-ios.tar.gz" }, "source_files": "*.h", "vendored_libraries": "*.a", diff --git a/Specs/milagro/3.0.0/milagro.podspec.json b/Specs/milagro/3.0.0/milagro.podspec.json index e4e9e96df6..8f7b4b3781 100644 --- a/Specs/milagro/3.0.0/milagro.podspec.json +++ b/Specs/milagro/3.0.0/milagro.podspec.json @@ -16,7 +16,7 @@ "osx": "10.7" }, "source": { - "http": "https://repo.evernym.com/deb/pods-ios/milagro/3.0.0/milagro-crypto-c-3.0.0-ios.tar.gz" + "http": "https://repo.evernym.com/libindy/ios/stable/milagro/3.0.0/milagro-crypto-c-3.0.0-ios.tar.gz" }, "source_files": [ "src/*.{h,hpp,c,cc,cpp}", diff --git a/ci/indy-pool.dockerfile b/ci/indy-pool.dockerfile index 7fb6952b24..59378dfe55 100755 --- a/ci/indy-pool.dockerfile +++ b/ci/indy-pool.dockerfile @@ -25,10 +25,14 @@ RUN echo "deb https://repo.sovrin.org/deb xenial master" >> /etc/apt/sources.lis RUN useradd -ms /bin/bash -u $uid sovrin +ARG indy_plenum_ver=1.0.95 +ARG indy_anoncreds_ver=1.0.25 +ARG indy_node_ver=1.0.105 + RUN apt-get update -y && apt-get install -y \ - indy-plenum=1.0.82 \ - indy-anoncreds=1.0.25 \ - indy-node=1.0.84 + indy-plenum=${indy_plenum_ver} \ + indy-anoncreds=${indy_anoncreds_ver} \ + indy-node=${indy_node_ver} RUN echo '[supervisord]\n\ logfile = /tmp/supervisord.log\n\ diff --git a/ci/libindy-update-package-version.sh b/ci/libindy-update-package-version.sh deleted file mode 100755 index 16bd37a3d5..0000000000 --- a/ci/libindy-update-package-version.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -x - -if [ "$1" = "--help" ] ; then - echo "Usage: $0 " -fi - -suffix="$1" - -sed -i -E "s/version = \"([0-9,.]+).*\"/version = \"\1-$suffix\"/" Cargo.toml \ No newline at end of file diff --git a/ci/python-wrapper-deb-build-and-upload.sh b/ci/python-wrapper-deb-build-and-upload.sh deleted file mode 100755 index a54e9ab50d..0000000000 --- a/ci/python-wrapper-deb-build-and-upload.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash - -if [ "$1" = "--help" ] ; then - echo "Usage: $0 " -fi - -key="$1" - -mkdir /home/indy/debs - -version=$(grep -Po "(?<=version=')([0-9]|\.|-)*" setup.py) -license=$(grep -Po "(?<=license=').[^\']*" setup.py) -description=$(grep -Po "(?<=description=').[^\']*" setup.py) - -[ -z $key ] && exit 1 -[ -z $version ] && exit 2 - -echo "Building...." - -fpm --input-type "python" \ - --output-type "deb" \ - --verbose \ - --architecture "amd64" \ - --name "python-indy-sdk" \ - --license license \ - --python-package-name-prefix "python3" \ - --directories description \ - --python-bin "/usr/bin/python3.6" \ - --exclude "*.pyc" \ - --exclude "*.pyo" \ - --maintainer "Hyperledger " \ - --package "/home/indy/debs" \ - . - -echo "Uploading...." - -cat < RL: 2. indy_agent_listen RL -> RS: Start listening RL -> RA: Listener handle (cb) +RA -> RL: 3. indy_add_identity \ncan be performed multiply times for same listener and different DID +RL -> RW: Check my_did in wallet +RL -> RL: Start accepting incomming connections for the DID +RL -> RA: Add identity result (cb) + === Establish connection == SA -> SL: 3. indy_create_and_store_my_did diff --git a/doc/windows-build.md b/doc/windows-build.md index 137c6072e4..79b8d1d179 100644 --- a/doc/windows-build.md +++ b/doc/windows-build.md @@ -3,7 +3,7 @@ ## Get/build dependencies All prebuilt can be downloaded from -https://repo.evernym.com/deb/windows-bins/indy-sdk-deps/ +https://repo.evernym.com/libindy/windows/deps/ ### Binary deps diff --git a/libindy/Cargo.lock b/libindy/Cargo.lock index 466e13bb2b..93224d3616 100644 --- a/libindy/Cargo.lock +++ b/libindy/Cargo.lock @@ -13,6 +13,7 @@ dependencies = [ "milagro-crypto 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.9.16 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "rmp-serde 0.13.6 (registry+https://github.com/rust-lang/crates.io-index)", "rusqlite 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "rust-base58 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -337,6 +338,25 @@ name = "regex-syntax" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "rmp" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rmp-serde" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rmp 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rusqlite" version = "0.10.1" @@ -560,6 +580,8 @@ dependencies = [ "checksum redox_syscall 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "8312fba776a49cf390b7b62f3135f9b294d8617f7a7592cfd0ac2492b658cd7b" "checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b" "checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db" +"checksum rmp 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7ce560a5728f4eec697f07f8d7fa20608893d44b4f5b8f9f5f51a2987f3cffe2" +"checksum rmp-serde 0.13.6 (registry+https://github.com/rust-lang/crates.io-index)" = "87dcd56d8d769ad197d1010b81723f16faa940bbcfed46fc3f1bdffb80c576ed" "checksum rusqlite 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "22edc5fcb280a732f7bf0203dd455b752a334d7015c742cb5b17ed2919c78eda" "checksum rust-base58 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b313b91fcdc6719ad41fa2dad2b7e810b03833fae4bf911950e15529a5f04439" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" diff --git a/libindy/Cargo.toml b/libindy/Cargo.toml index 3216e5bb7b..55d3d4473e 100644 --- a/libindy/Cargo.toml +++ b/libindy/Cargo.toml @@ -46,6 +46,7 @@ rust-base58 = {version = "0.0.4", optional = true} serde = "1.0" serde_json = "1.0" serde_derive = "1.0" +rmp-serde = "0.13.6" sodiumoxide = {version = "0.0.14", optional = true} time = "0.1.36" zmq-pw = "0.9.8" diff --git a/libindy/build-libindy-core-ios.sh b/libindy/build-libindy-core-ios.sh index dc2c6d034f..89a44d993f 100644 --- a/libindy/build-libindy-core-ios.sh +++ b/libindy/build-libindy-core-ios.sh @@ -34,13 +34,13 @@ cd $CUR_DIR echo "Uploading...." cat <>(); + let values = strvals.iter().map(|x| String::from(*x).as_bytes().to_vec()).collect::>(); let tree = MerkleTree::from_vec(values.clone()).unwrap(); let root_hash = tree.root_hash(); @@ -326,7 +326,7 @@ mod tests { #[test] fn serialize_works() { let strvals = vec![ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ]; - let values = strvals.iter().map(|x| String::from(*x)).collect::>(); + let values = strvals.iter().map(|x| String::from(*x).as_bytes().to_vec()).collect::>(); let mt = MerkleTree::from_vec(values.clone()).unwrap(); let serialized = serde_json::to_string(&mt).unwrap(); println!("serialize mt: h={}, c={}, rhash={}", mt.height, mt.count, serialized); @@ -355,7 +355,7 @@ mod tests { r#"{"data":{"alias":"Node7","client_ip":"10.0.0.2","client_port":9714,"node_ip":"10.0.0.2","node_port":9713,"services":["VALIDATOR"]},"dest":"BM8dTooz5uykCbYSAAFwKNkYfT4koomBHsSWHTDtkjhW","identifier":"6pYGZXnqXLxLAhrEBhVjyvuhnV2LUgM9iw1gHds8JDqT","txnId":"e5f11aa7ec7091ca6c31a826eec885da7fcaa47611d03fdc3562b48247f179cf","type":"0"}"#, r#"{"data":{"alias":"Node8","client_ip":"10.0.0.2","client_port":9716,"node_ip":"10.0.0.2","node_port":9715,"services":["VALIDATOR"]},"dest":"98VysG35LxrutKTNXvhaztPFHnx5u9kHtT7PnUGqDa8x","identifier":"B4xQBURedpCS3r6v8YxTyz5RYh3Nh5Jt2MxsmtAUr1rH","txnId":"2b01e69f89514be94ebf24bfa270abbe1c5abc72415801da3f0d58e71aaa33a2","type":"0"}"#, ]; - let all_values: Vec = all_str_values.iter().map(|x| String::from(*x)).collect::>(); + let all_values: Vec> = all_str_values.iter().map(|x| String::from(*x).as_bytes().to_vec()).collect::>(); let mt_full = MerkleTree::from_vec(all_values.clone()).unwrap(); let full_root_hash = mt_full.root_hash(); let mut start_values = all_values.clone(); diff --git a/libindy/src/services/ledger/merkletree/tree.rs b/libindy/src/services/ledger/merkletree/tree.rs index b3699ced2e..68343c226a 100644 --- a/libindy/src/services/ledger/merkletree/tree.rs +++ b/libindy/src/services/ledger/merkletree/tree.rs @@ -8,7 +8,7 @@ pub use services::ledger::merkletree::proof::{ Positioned }; -pub type TreeLeafData = String; +pub type TreeLeafData = Vec; /// Binary Tree where leaves hold a stand-alone value. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] diff --git a/libindy/src/services/ledger/mod.rs b/libindy/src/services/ledger/mod.rs index cf296c7807..1038df814b 100644 --- a/libindy/src/services/ledger/mod.rs +++ b/libindy/src/services/ledger/mod.rs @@ -136,9 +136,9 @@ impl LedgerService { Base58::decode(&identifier)?; let req_id = LedgerService::get_req_id(); - SchemaOperationData::from_json(&data) + let data = SchemaOperationData::from_json(&data) .map_err(|err| CommonError::InvalidStructure(format!("Invalid data json: {}", err.to_string())))?; - let operation = SchemaOperation::new(data.to_string()); + let operation = SchemaOperation::new(data); let request = Request::new(req_id, identifier.to_string(), operation); @@ -168,9 +168,9 @@ impl LedgerService { let req_id = LedgerService::get_req_id(); - ClaimDefOperationData::from_json(&data) + let data = ClaimDefOperationData::from_json(&data) .map_err(|err| CommonError::InvalidStructure(format!("Invalid data json: {}", err.to_string())))?; - let operation = ClaimDefOperation::new(_ref, signature_type.to_string(), data.to_string()); + let operation = ClaimDefOperation::new(_ref, signature_type.to_string(), data); let request = Request::new(req_id, identifier.to_string(), operation); @@ -346,12 +346,11 @@ mod tests { fn build_schema_request_works_for_correct_data() { let ledger_service = LedgerService::new(); let identifier = "identifier"; - let data = r#"{"name":"name", "version":"1.0", "keys":["name","male"]}"#; + let data = r#"{"name":"name", "version":"1.0", "attr_names":["name","male"]}"#; - let expected_result = r#""operation":{"type":"101","data":"{\"name\":\"name\", \"version\":\"1.0\", \"keys\":[\"name\",\"male\"]"#; + let expected_result = r#""operation":{"type":"101","data":{"name":"name","version":"1.0","attr_names":["name","male"]"#; let schema_request = ledger_service.build_schema_request(identifier, data); - assert!(schema_request.is_ok()); let schema_request = schema_request.unwrap(); assert!(schema_request.contains(expected_result)); } @@ -360,7 +359,7 @@ mod tests { fn build_get_schema_request_works_for_wrong_data() { let ledger_service = LedgerService::new(); let identifier = "identifier"; - let data = r#"{"name":"name","keys":["name","male"]}"#; + let data = r#"{"name":"name","attr_names":["name","male"]}"#; let get_schema_request = ledger_service.build_get_schema_request(identifier, identifier, data); assert!(get_schema_request.is_err()); diff --git a/libindy/src/services/ledger/types.rs b/libindy/src/services/ledger/types.rs index 25c9a983ec..884c2da334 100644 --- a/libindy/src/services/ledger/types.rs +++ b/libindy/src/services/ledger/types.rs @@ -1,3 +1,5 @@ +extern crate serde_json; + use services::anoncreds::types::{PublicKey, RevocationPublicKey}; use utils::json::{JsonEncodable, JsonDecodable}; use services::ledger::constants::{ @@ -144,11 +146,11 @@ impl JsonEncodable for GetAttribOperation {} pub struct SchemaOperation { #[serde(rename = "type")] pub _type: String, - pub data: String + pub data: SchemaOperationData, } impl SchemaOperation { - pub fn new(data: String) -> SchemaOperation { + pub fn new(data: SchemaOperationData) -> SchemaOperation { SchemaOperation { data: data, _type: SCHEMA.to_string() @@ -162,7 +164,7 @@ impl JsonEncodable for SchemaOperation {} pub struct SchemaOperationData { name: String, version: String, - keys: Vec + attr_names: Vec } impl SchemaOperationData { @@ -170,7 +172,7 @@ impl SchemaOperationData { SchemaOperationData { name: name, version: version, - keys: keys + attr_names: keys } } } @@ -234,14 +236,14 @@ impl<'a> JsonDecodable<'a> for GetSchemaOperationData {} pub struct ClaimDefOperation { #[serde(rename = "ref")] pub _ref: i32, - pub data: String, + pub data: ClaimDefOperationData, #[serde(rename = "type")] pub _type: String, pub signature_type: String } impl ClaimDefOperation { - pub fn new(_ref: i32, signature_type: String, data: String) -> ClaimDefOperation { + pub fn new(_ref: i32, signature_type: String, data: ClaimDefOperationData) -> ClaimDefOperation { ClaimDefOperation { _ref: _ref, signature_type: signature_type, @@ -256,6 +258,7 @@ impl JsonEncodable for ClaimDefOperation {} #[derive(Serialize, PartialEq, Debug, Deserialize)] pub struct ClaimDefOperationData { pub primary: PublicKey, + #[serde(serialize_with = "empty_map_instead_of_null")] //FIXME pub revocation: Option } @@ -268,6 +271,19 @@ impl ClaimDefOperationData { } } +//FIXME workaround for ledger: serialize required dictionary as empty instead of using null +extern crate serde; +use self::serde::Serializer; +use self::serde::ser::SerializeMap; +fn empty_map_instead_of_null(x: &Option, s: S) -> Result + where S: Serializer { + if let &Some(ref x) = x { + s.serialize_some(&x) + } else { + s.serialize_map(None)?.end() + } +} +//FIXME impl JsonEncodable for ClaimDefOperationData {} diff --git a/libindy/src/services/pool/catchup.rs b/libindy/src/services/pool/catchup.rs index 7b6fe9a7c9..eea13b9c0b 100644 --- a/libindy/src/services/pool/catchup.rs +++ b/libindy/src/services/pool/catchup.rs @@ -1,3 +1,5 @@ +extern crate rmp_serde; + use std::cmp; use std::collections::{BinaryHeap, HashMap}; @@ -11,7 +13,6 @@ use super::{ }; use super::rust_base58::{FromBase58, ToBase58}; use super::types::*; -use utils::json::JsonEncodable; enum CatchupStepResult { Finished, @@ -105,7 +106,7 @@ impl CatchupHandler { fn check_nodes_responses_on_status(&mut self) -> Result { if self.pending_catchup.is_some() { - return Ok(CatchupProgress::InProgress) + return Ok(CatchupProgress::InProgress); } let mut votes: HashMap<(String, usize), usize> = HashMap::new(); for node_vote in &self.nodes_votes { @@ -217,9 +218,9 @@ impl CatchupHandler { let mut temp_mt = process.merkle_tree.clone(); while !first_resp.txns.is_empty() { let key = first_resp.min_tx().to_string(); - if let Ok(new_gen_tx) = first_resp.txns.remove(&key).unwrap().to_json() { - trace!("append to tree {}", new_gen_tx); - temp_mt.append(new_gen_tx)?; + let new_gen_tx = first_resp.txns.remove(&key).unwrap(); + if let Ok(new_get_txn_bytes) = new_gen_tx.to_msg_pack() { + temp_mt.append(new_get_txn_bytes)?; } else { return Ok(CatchupStepResult::FailedAtNode(node_idx)); } diff --git a/libindy/src/services/pool/mod.rs b/libindy/src/services/pool/mod.rs index 2de4d4dfc7..63f326e265 100644 --- a/libindy/src/services/pool/mod.rs +++ b/libindy/src/services/pool/mod.rs @@ -5,6 +5,7 @@ extern crate byteorder; extern crate rust_base58; extern crate serde_json; extern crate zmq_pw as zmq; +extern crate rmp_serde; use self::byteorder::{ByteOrder, LittleEndian}; use self::rust_base58::FromBase58; @@ -257,7 +258,7 @@ impl PoolWorker { let ctx: zmq::Context = zmq::Context::new(); let key_pair = zmq::CurveKeyPair::new()?; for gen_txn in &merkle_tree { - let gen_txn: GenTransaction = GenTransaction::from_json(gen_txn) + let gen_txn: GenTransaction = rmp_serde::decode::from_slice(gen_txn.as_slice()) .map_err(|e| CommonError::InvalidState(format!("MerkleTree contains invalid data {}", e)))?; @@ -413,7 +414,9 @@ impl PoolWorker { let reader = io::BufReader::new(&f); for line in reader.lines() { let line: String = line.map_err(map_err_trace!())?; - mt.append(line).map_err(map_err_trace!())?; + let genesis_txn: serde_json::Value = serde_json::from_str(line.as_str()).unwrap(); /* FIXME resolve unwrap */ + let bytes = rmp_serde::encode::to_vec_named(&genesis_txn).unwrap(); /* FIXME resolve unwrap */ + mt.append(bytes).map_err(map_err_trace!())?; } Ok(mt) } @@ -422,7 +425,7 @@ impl PoolWorker { fn get_f(cnt: usize) -> usize { return cnt / 2; /* FIXME ugly hack to work with pool instability, remove after pool will be fixed */ if cnt < 4 { - return 0 + return 0; } (cnt - 1) / 3 } @@ -909,7 +912,7 @@ mod tests { let merkle_tree = PoolWorker::_restore_merkle_tree("test").unwrap(); assert_eq!(merkle_tree.count(), 4, "test restored MT size"); - assert_eq!(merkle_tree.root_hash_hex(), "1285070cf01debc1155cef8dfd5ba54c05abb919a4c08c8632b079fb1e1e5e7c", "test restored MT root hash"); + assert_eq!(merkle_tree.root_hash_hex(), "7c7e209a5bee34e467f7a2b6e233b8c61b74ddfd099bd9ad8a9a764cdf671981", "test restored MT root hash"); } #[test] @@ -917,7 +920,7 @@ mod tests { let mut pw: PoolWorker = Default::default(); let (gt, handle) = nodes_emulator::start(); let mut merkle_tree: MerkleTree = MerkleTree::from_vec(Vec::new()).unwrap(); - merkle_tree.append(gt.to_json().unwrap()).unwrap(); + merkle_tree.append(gt.to_msg_pack().unwrap()).unwrap(); pw.connect_to_known_nodes(Some(&merkle_tree)).unwrap(); @@ -954,7 +957,7 @@ mod tests { let poll_items = pw.get_zmq_poll_items().unwrap(); - assert_eq!(poll_items.len(), pw.handler.nodes().len() + 1 ); + assert_eq!(poll_items.len(), pw.handler.nodes().len() + 1); //TODO compare poll items } @@ -1043,7 +1046,7 @@ mod tests { fn catchup_handler_start_catchup_works() { let mut ch: CatchupHandler = Default::default(); let (gt, handle) = nodes_emulator::start(); - ch.merkle_tree.append(gt.to_json().unwrap()).unwrap(); + ch.merkle_tree.append(gt.to_msg_pack().unwrap()).unwrap(); let mut rn: RemoteNode = RemoteNode::new(>).unwrap(); rn.connect(&zmq::Context::new(), &zmq::CurveKeyPair::new().unwrap()).unwrap(); ch.nodes.push(rn); diff --git a/libindy/src/services/pool/types.rs b/libindy/src/services/pool/types.rs index b3bcfc80b6..95b8ed91f0 100644 --- a/libindy/src/services/pool/types.rs +++ b/libindy/src/services/pool/types.rs @@ -1,4 +1,5 @@ extern crate serde_json; +extern crate rmp_serde; use std::cmp; use std::cmp::Eq; @@ -34,6 +35,12 @@ impl JsonEncodable for GenTransaction {} impl<'a> JsonDecodable<'a> for GenTransaction {} +impl GenTransaction { + pub fn to_msg_pack(&self) -> Result, rmp_serde::encode::Error> { + rmp_serde::to_vec_named(self) + } +} + #[allow(non_snake_case)] #[derive(Serialize, Deserialize, Debug)] pub struct LedgerStatus { diff --git a/libindy/src/utils/test.rs b/libindy/src/utils/test.rs index cea1f48789..6e9d500d8f 100644 --- a/libindy/src/utils/test.rs +++ b/libindy/src/utils/test.rs @@ -25,6 +25,7 @@ impl TestUtils { } } +#[cfg(test)] macro_rules! assert_match { ($pattern:pat, $var:expr) => ( assert!(match $var { diff --git a/libindy/tests/ledger.rs b/libindy/tests/ledger.rs index cb9b25c224..3e6e7a35ee 100644 --- a/libindy/tests/ledger.rs +++ b/libindy/tests/ledger.rs @@ -522,9 +522,9 @@ mod high_cases { #[cfg(feature = "local_nodes_pool")] fn indy_build_schema_requests_works_for_correct_data_json() { let identifier = "identifier"; - let data = r#"{"name":"name", "version":"1.0", "keys":["name","male"]}"#; + let data = r#"{"name":"name", "version":"1.0", "attr_names":["name","male"]}"#; - let expected_result = "\"operation\":{\"type\":\"101\",\"data\":\"{\\\"name\\\":\\\"name\\\", \\\"version\\\":\\\"1.0\\\", \\\"keys\\\":[\\\"name\\\",\\\"male\\\"]"; + let expected_result = r#""operation":{"type":"101","data":{"name":"name","version":"1.0","attr_names":["name","male"]"#; let schema_request = LedgerUtils::build_schema_request(identifier, data).unwrap(); @@ -557,7 +557,7 @@ mod high_cases { let schema_data = "{\"name\":\"gvt2\",\ \"version\":\"2.0\",\ - \"keys\": [\"name\", \"male\"]}"; + \"attr_names\": [\"name\", \"male\"]}"; let schema_request = LedgerUtils::build_schema_request(&my_did.clone(), schema_data).unwrap(); let res = PoolUtils::send_request(pool_handle, &schema_request); @@ -586,7 +586,7 @@ mod high_cases { let schema_data = "{\"name\":\"gvt2\",\ \"version\":\"2.0\",\ - \"keys\": [\"name\", \"male\"]}"; + \"attr_names\": [\"name\", \"male\"]}"; let schema_request = LedgerUtils::build_schema_request(&my_did.clone(), schema_data).unwrap(); let schema_response = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &schema_request).unwrap(); @@ -693,7 +693,7 @@ mod high_cases { let schema_seq_no = 1; let data = r#"{"primary":{"n":"1","s":"2","rms":"3","r":{"name":"1"},"rctxt":"1","z":"1"}}"#; - let expected_result = r#""identifier":"identifier","operation":{"ref":1,"data":"{\"primary\":{\"n\":\"1\",\"s\":\"2\",\"rms\":\"3\",\"r\":{\"name\":\"1\"},\"rctxt\":\"1\",\"z\":\"1\"}}","type":"102","signature_type":"CL""#; + let expected_result = r#""identifier":"identifier","operation":{"ref":1,"data":{"primary":{"n":"1","s":"2","rms":"3","r":{"name":"1"},"rctxt":"1","z":"1"},"revocation":{}},"type":"102","signature_type":"CL""#; let claim_def_request = LedgerUtils::build_claim_def_txn(identifier, schema_seq_no, signature_type, data).unwrap(); assert!(claim_def_request.contains(expected_result)); @@ -729,7 +729,7 @@ mod high_cases { let schema_data = "{\"name\":\"gvt2\",\ \"version\":\"2.0\",\ - \"keys\": [\"name\", \"male\"]}"; + \"attr_names\": [\"name\", \"male\"]}"; let schema_request = LedgerUtils::build_schema_request(&my_did.clone(), schema_data).unwrap(); LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &schema_request).unwrap(); @@ -774,7 +774,7 @@ mod high_cases { let schema_data = "{\"name\":\"gvt2\",\ \"version\":\"2.0\",\ - \"keys\": [\"name\", \"male\"]}"; + \"attr_names\": [\"name\", \"male\"]}"; let schema_request = LedgerUtils::build_schema_request(&my_did.clone(), schema_data).unwrap(); LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &schema_request).unwrap(); @@ -806,8 +806,7 @@ mod high_cases { let get_claim_def_response = PoolUtils::send_request(pool_handle, &get_claim_def_request).unwrap(); info!("get_claim_def_response {}", get_claim_def_response); - let get_claim_def_response: Result, _> = serde_json::from_str(&get_claim_def_response); - assert!(get_claim_def_response.is_ok()); + let _: Reply = serde_json::from_str(&get_claim_def_response).unwrap(); TestUtils::cleanup_storage(); } @@ -844,7 +843,7 @@ mod high_cases { let schema_data = SchemaData { name: "gvt3".to_string(), version: "3.0".to_string(), - keys: keys + attr_names: keys }; let schema_data_json = serde_json::to_string(&schema_data).unwrap(); let schema_request = LedgerUtils::build_schema_request(&my_did.clone(), &schema_data_json).unwrap(); @@ -862,12 +861,9 @@ mod high_cases { let get_txn_response: Reply = serde_json::from_str(&get_txn_response).unwrap(); - let get_txn_schema_result: SchemaResult = serde_json::from_str(&get_txn_response.result.data.unwrap()).unwrap(); - assert!(get_txn_schema_result.data.is_some()); + let get_txn_schema_result: SchemaResult = serde_json::from_value(get_txn_response.result.data.unwrap()).unwrap(); - let get_txn_schema_data: SchemaData = serde_json::from_str(&get_txn_schema_result.data.unwrap()).unwrap(); - - assert_eq!(schema_data, get_txn_schema_data); + assert_eq!(schema_data, get_txn_schema_result.data.unwrap()); TestUtils::cleanup_storage(); } @@ -889,7 +885,7 @@ mod high_cases { let schema_data = SchemaData { name: "gvt3".to_string(), version: "3.0".to_string(), - keys: keys + attr_names: keys }; let schema_data_json = serde_json::to_string(&schema_data).unwrap(); let schema_request = LedgerUtils::build_schema_request(&my_did.clone(), &schema_data_json).unwrap(); @@ -1256,7 +1252,7 @@ mod medium_cases { let schema_data = "{\"name\":\"gvt2\",\ \"version\":\"2.0\",\ - \"keys\": [\"name\", \"male\"]}"; + \"attr_names\": [\"name\", \"male\"]}"; let schema_request = LedgerUtils::build_schema_request(&my_did.clone(), schema_data).unwrap(); let res = LedgerUtils::sign_and_submit_request(pool_handle, wallet_handle, &my_did, &schema_request); diff --git a/libindy/tests/utils/mod.rs b/libindy/tests/utils/mod.rs index 40a55baa44..50599da3f7 100644 --- a/libindy/tests/utils/mod.rs +++ b/libindy/tests/utils/mod.rs @@ -13,6 +13,7 @@ pub mod anoncreds; pub mod types; #[macro_use] +#[allow(unused_macros)] #[path = "../../src/utils/test.rs"] pub mod test; diff --git a/libindy/tests/utils/types.rs b/libindy/tests/utils/types.rs index c26401ab73..69028f1c63 100644 --- a/libindy/tests/utils/types.rs +++ b/libindy/tests/utils/types.rs @@ -1,3 +1,5 @@ +extern crate serde_json; + use std::collections::{HashMap, HashSet}; use std::cell::RefCell; @@ -16,7 +18,7 @@ pub struct ClaimDefinitionData { #[serde(rename = "primary")] pub public_key: PublicKey, #[serde(rename = "revocation")] - pub public_key_revocation: Option, + pub public_key_revocation: Option, } #[derive(Debug, Deserialize, PartialEq, Serialize, Eq)] @@ -92,7 +94,7 @@ pub struct GetSchemaReplyResult { #[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)] pub struct GetSchemaResultData { - pub keys: HashSet, + pub attr_names: HashSet, pub name: String, pub origin: String, pub version: String @@ -123,7 +125,7 @@ pub struct GetTxnResult { pub seq_no: Option, #[serde(rename = "type")] pub _type: String, - pub data: Option + pub data: Option } #[derive(Debug, Serialize, Deserialize)] @@ -135,7 +137,7 @@ pub struct SchemaResult { pub seq_no: i32, #[serde(rename = "type")] pub _type: String, - pub data: Option + pub data: Option } #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -149,7 +151,7 @@ pub struct Schema { pub struct SchemaData { pub name: String, pub version: String, - pub keys: HashSet + pub attr_names: HashSet } diff --git a/wrappers/dotnet/readme.md b/wrappers/dotnet/README.md similarity index 100% rename from wrappers/dotnet/readme.md rename to wrappers/dotnet/README.md diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/IndyIntegrationTestBase.cs b/wrappers/dotnet/indy-sdk-dotnet-test/IndyIntegrationTestBase.cs index f7bf580669..2220e6419b 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/IndyIntegrationTestBase.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/IndyIntegrationTestBase.cs @@ -11,9 +11,9 @@ public abstract class IndyIntegrationTestBase protected HashSet _openedPools = new HashSet(); [TestInitialize] - public void SetUp() + public async Task SetUp() { - InitHelper.Init(); + await InitHelper.InitAsync(); StorageUtils.CleanupStorage(); } @@ -22,12 +22,8 @@ public async Task TearDown() { foreach (var pool in _openedPools) { - try - { + if(pool != null) await pool.CloseAsync(); - } - catch (IndyException) - { } } _openedPools.Clear(); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/InitHelper.cs b/wrappers/dotnet/indy-sdk-dotnet-test/InitHelper.cs index 462847056b..69c473e5ee 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/InitHelper.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/InitHelper.cs @@ -14,13 +14,13 @@ class InitHelper [DllImport("kernel32.dll", SetLastError = true)] static extern bool SetDllDirectory(string lpPathName); - public static void Init() + public static async Task InitAsync() { if (_isInitialized) return; LoadIndyDll(); - RegisterWalletType(); + await RegisterWalletTypeAsync(); _isInitialized = true; } @@ -34,9 +34,9 @@ private static void LoadIndyDll() SetDllDirectory(dir); } - private static void RegisterWalletType() + private static async Task RegisterWalletTypeAsync() { - Wallet.RegisterWalletTypeAsync("inmem", new InMemWalletType()).Wait(); + await Wallet.RegisterWalletTypeAsync("inmem", new InMemWalletType()); } } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/PoolUtils.cs b/wrappers/dotnet/indy-sdk-dotnet-test/PoolUtils.cs index 31d0fb1614..d48ca2e125 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/PoolUtils.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/PoolUtils.cs @@ -61,15 +61,15 @@ public static void CreatePoolLedgerConfig(string poolName, int nodesCnt) var path = Path.GetFullPath(genesisTxnFile).Replace('\\', '/'); var createPoolLedgerConfig = string.Format("{{\"genesis_txn\":\"{0}\"}}", path); - Pool.CreatePoolLedgerConfigAsync(poolName, createPoolLedgerConfig).Wait(); + Pool.CreatePoolLedgerConfigAsync(poolName, createPoolLedgerConfig); } - public static Pool CreateAndOpenPoolLedger() + public static async Task CreateAndOpenPoolLedgerAsync() { var poolName = PoolUtils.CreatePoolLedgerConfig(); var openPoolLedgerConfig = "{\"refreshOnOpen\":true}"; - return Pool.OpenPoolLedgerAsync(poolName, openPoolLedgerConfig).Result; + return await Pool.OpenPoolLedgerAsync(poolName, openPoolLedgerConfig); } } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentAddIdentityTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentAddIdentityTest.cs index 6cd757adbf..ccd94c9c8d 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentAddIdentityTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentAddIdentityTest.cs @@ -1,6 +1,7 @@ using Indy.Sdk.Dotnet.Test.Wrapper.AgentTests; using Indy.Sdk.Dotnet.Wrapper; using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading.Tasks; namespace Indy.Sdk.Dotnet.Test.Wrapper.AgentTests { @@ -8,32 +9,32 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.AgentTests public class AgentAddIdentityTest : AgentIntegrationTestBase { [TestMethod] - public void TestAgentAddIdentityWorks() + public async Task TestAgentAddIdentityWorks() { var endpoint = "127.0.0.1:9601"; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); - var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result; + var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver); - activeListener.AddIdentityAsync(_pool, _wallet, myDidResult.Did).Wait(); + await activeListener.AddIdentityAsync(_pool, _wallet, myDidResult.Did); } [TestMethod] - public void TestAgentAddIdentityWorksForMultiplyKeys() + public async Task TestAgentAddIdentityWorksForMultiplyKeys() { var endpoint = "127.0.0.1:9602"; - var myDid1 = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; - var myDid2 = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var myDid1 = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); + var myDid2 = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); CreateAndStoreMyDidResult[] didResults = { myDid1, myDid2 }; - var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result; + var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver); foreach (var didResult in didResults) { - activeListener.AddIdentityAsync(_pool, _wallet, didResult.Did).Wait(); + await activeListener.AddIdentityAsync(_pool, _wallet, didResult.Did); } } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentCloseConnectionTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentCloseConnectionTest.cs index 539e6b9efe..8d8d022c4a 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentCloseConnectionTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentCloseConnectionTest.cs @@ -31,20 +31,20 @@ public async Task TestAgentCloseConnectionWorksForOutgoing() { var endpoint = "127.0.0.1:9603"; - var myDid = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var myDid = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}", myDid.Did, myDid.Pk, myDid.VerKey, endpoint); - Signus.StoreTheirDidAsync(_wallet, identityJson).Wait(); + await Signus.StoreTheirDidAsync(_wallet, identityJson); - var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result; + var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver); - activeListener.AddIdentityAsync(_pool, _wallet, myDid.Did).Wait(); + await activeListener.AddIdentityAsync(_pool, _wallet, myDid.Did); - var connection = Agent.AgentConnectAsync(_pool, _wallet, myDid.Did, myDid.Did, _messageObserver).Result; + var connection = await Agent.AgentConnectAsync(_pool, _wallet, myDid.Did, myDid.Did, _messageObserver); - connection.CloseAsync().Wait(); + await connection.CloseAsync(); var ex = await Assert.ThrowsExceptionAsync(() => connection.SendAsync("msg") @@ -58,21 +58,21 @@ public async Task TestAgentCloseConnectionWorksForIncoming() { var endpoint = "127.0.0.1:9613"; - var myDid = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var myDid = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}", myDid.Did, myDid.Pk, myDid.VerKey, endpoint); - Signus.StoreTheirDidAsync(_wallet, identityJson).Wait(); + await Signus.StoreTheirDidAsync(_wallet, identityJson); - var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result; + var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver); - activeListener.AddIdentityAsync(_pool, _wallet, myDid.Did).Wait(); + await activeListener.AddIdentityAsync(_pool, _wallet, myDid.Did); - var connection = Agent.AgentConnectAsync(_pool, _wallet, myDid.Did, myDid.Did, _messageObserver).Result; + var connection = await Agent.AgentConnectAsync(_pool, _wallet, myDid.Did, myDid.Did, _messageObserver); - var serverToClientConnection = _serverToClientConnectionTaskCompletionSource.Task.Result; - serverToClientConnection.CloseAsync().Wait(); + var serverToClientConnection = await _serverToClientConnectionTaskCompletionSource.Task; + await serverToClientConnection.CloseAsync(); var ex = await Assert.ThrowsExceptionAsync(() => diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentCloseListenerTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentCloseListenerTest.cs index ef49260b6a..c8f2e2677b 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentCloseListenerTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentCloseListenerTest.cs @@ -31,21 +31,21 @@ public async Task TestAgentCloseConnectionWorksForOutgoing() { var endpoint = "127.0.0.1:9604"; - var myDid = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var myDid = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}", myDid.Did, myDid.Pk, myDid.VerKey, endpoint); - Signus.StoreTheirDidAsync(_wallet, identityJson).Wait(); + await Signus.StoreTheirDidAsync(_wallet, identityJson); - var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result; + var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver); - activeListener.AddIdentityAsync(_pool, _wallet, myDid.Did).Wait(); + await activeListener.AddIdentityAsync(_pool, _wallet, myDid.Did); - Agent.AgentConnectAsync(_pool, _wallet, myDid.Did, myDid.Did, _messageObserver).Wait(); + await Agent.AgentConnectAsync(_pool, _wallet, myDid.Did, myDid.Did, _messageObserver); - var serverToClientConnection = _serverToClientConnectionTaskCompletionSource.Task.Result; - activeListener.CloseAsync().Wait(); + var serverToClientConnection = await _serverToClientConnectionTaskCompletionSource.Task; + await activeListener.CloseAsync(); var ex = await Assert.ThrowsExceptionAsync(() => serverToClientConnection.SendAsync("msg") diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentConnectTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentConnectTest.cs index 5d268dcd11..9c9017245e 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentConnectTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentConnectTest.cs @@ -1,5 +1,6 @@ using Indy.Sdk.Dotnet.Wrapper; using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading.Tasks; namespace Indy.Sdk.Dotnet.Test.Wrapper.AgentTests { @@ -7,66 +8,66 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.AgentTests public class AgentConnectTest : AgentIntegrationTestBase { [TestMethod] - public void TestAgentConnectWorksForRemoteData() + public async Task TestAgentConnectWorksForRemoteData() { var endpoint = "127.0.0.1:9605"; var listenerWalletName = "listenerWallet"; var trusteeWalletName = "trusteeWallet"; - Wallet.CreateWalletAsync(_poolName, listenerWalletName, "default", null, null).Wait(); - var listenerWallet = Wallet.OpenWalletAsync(listenerWalletName, null, null).Result; + await Wallet.CreateWalletAsync(_poolName, listenerWalletName, "default", null, null); + var listenerWallet = await Wallet.OpenWalletAsync(listenerWalletName, null, null); - Wallet.CreateWalletAsync(_poolName, trusteeWalletName, "default", null, null).Wait(); - var trusteeWallet = Wallet.OpenWalletAsync(trusteeWalletName, null, null).Result; + await Wallet.CreateWalletAsync(_poolName, trusteeWalletName, "default", null, null); + var trusteeWallet = await Wallet.OpenWalletAsync(trusteeWalletName, null, null); var senderWallet = trusteeWallet; - var createMyDidResult = Signus.CreateAndStoreMyDidAsync(listenerWallet, "{}").Result; + var createMyDidResult = await Signus.CreateAndStoreMyDidAsync(listenerWallet, "{}"); var listenerDid = createMyDidResult.Did; var listenerVerkey = createMyDidResult.VerKey; var listenerPk = createMyDidResult.Pk; var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(trusteeWallet, trusteeDidJson).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(trusteeWallet, trusteeDidJson); var trusteeDid = trusteeDidResult.Did; var senderDid = trusteeDid; - var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, listenerDid, listenerVerkey, null, null).Result; - Ledger.SignAndSubmitRequestAsync(_pool, trusteeWallet, trusteeDid, nymRequest).Wait(); + var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, listenerDid, listenerVerkey, null, null); + await Ledger.SignAndSubmitRequestAsync(_pool, trusteeWallet, trusteeDid, nymRequest); - var attribRequest = Ledger.BuildAttribRequestAsync(listenerDid, listenerDid, null, - string.Format("{{\"endpoint\":{{\"ha\":\"{0}\",\"verkey\":\"{1}\"}}}}", endpoint, listenerPk), null).Result; - Ledger.SignAndSubmitRequestAsync(_pool, listenerWallet, listenerDid, attribRequest).Wait(); + var attribRequest = await Ledger.BuildAttribRequestAsync(listenerDid, listenerDid, null, + string.Format("{{\"endpoint\":{{\"ha\":\"{0}\",\"verkey\":\"{1}\"}}}}", endpoint, listenerPk), null); + await Ledger.SignAndSubmitRequestAsync(_pool, listenerWallet, listenerDid, attribRequest); - var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result; + var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver); - activeListener.AddIdentityAsync(_pool, listenerWallet, listenerDid).Wait(); + await activeListener.AddIdentityAsync(_pool, listenerWallet, listenerDid); - Agent.AgentConnectAsync(_pool, senderWallet, senderDid, listenerDid, _messageObserver).Wait(); + await Agent.AgentConnectAsync(_pool, senderWallet, senderDid, listenerDid, _messageObserver); - listenerWallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(listenerWalletName, null).Wait(); + await listenerWallet.CloseAsync(); + await Wallet.DeleteWalletAsync(listenerWalletName, null); - trusteeWallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(trusteeWalletName, null).Wait(); + await trusteeWallet.CloseAsync(); + await Wallet.DeleteWalletAsync(trusteeWalletName, null); } [TestMethod] - public void TestAgentConnectWorksForAllDataInWalletPresent() + public async Task TestAgentConnectWorksForAllDataInWalletPresent() { var endpoint = "127.0.0.1:9606"; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}", myDidResult.Did, myDidResult.Pk, myDidResult.VerKey, endpoint); - Signus.StoreTheirDidAsync(_wallet, identityJson).Wait(); + await Signus.StoreTheirDidAsync(_wallet, identityJson); - var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result; + var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver); - activeListener.AddIdentityAsync(_pool, _wallet, myDidResult.Did).Wait(); + await activeListener.AddIdentityAsync(_pool, _wallet, myDidResult.Did); - Agent.AgentConnectAsync(_pool, _wallet, myDidResult.Did, myDidResult.Did, _messageObserver).Wait(); + await Agent.AgentConnectAsync(_pool, _wallet, myDidResult.Did, myDidResult.Did, _messageObserver); } } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentIntegrationTestBase.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentIntegrationTestBase.cs index b0242d77f6..70a475daa7 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentIntegrationTestBase.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentIntegrationTestBase.cs @@ -1,6 +1,7 @@ using Indy.Sdk.Dotnet.Wrapper; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; +using System.Threading.Tasks; using static Indy.Sdk.Dotnet.Wrapper.Agent; namespace Indy.Sdk.Dotnet.Test.Wrapper.AgentTests @@ -30,27 +31,31 @@ public abstract class AgentIntegrationTestBase }; [TestInitialize] - public void SetUp() + public async Task SetUp() { - InitHelper.Init(); + await InitHelper.InitAsync(); StorageUtils.CleanupStorage(); _poolName = PoolUtils.CreatePoolLedgerConfig(); var config2 = "{}"; - _pool = Pool.OpenPoolLedgerAsync(_poolName, config2).Result; + _pool = await Pool.OpenPoolLedgerAsync(_poolName, config2); - Wallet.CreateWalletAsync(_poolName, _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; + await Wallet.CreateWalletAsync(_poolName, _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); } [TestCleanup] - public void TearDown() + public async Task TearDown() { - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); + if(_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); + + if(_pool != null) + await _pool.CloseAsync(); - _pool.CloseAsync().Wait(); StorageUtils.CleanupStorage(); } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentListenTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentListenTest.cs index cd7d93b304..1b0745596a 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentListenTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentListenTest.cs @@ -1,5 +1,6 @@ using Indy.Sdk.Dotnet.Wrapper; using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading.Tasks; namespace Indy.Sdk.Dotnet.Test.Wrapper.AgentTests { @@ -7,19 +8,19 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.AgentTests public class AgentListenTest : AgentIntegrationTestBase { [TestMethod] - public void TestAgentListenWorks() + public async Task TestAgentListenWorks() { var endpoint = "127.0.0.1:9607"; var didJson = "{\"seed\":\"sovrin_agent_connect_works_for_a\"}"; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, didJson).Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, didJson); var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}", myDidResult.Did, myDidResult.Pk, myDidResult.VerKey, endpoint); - Signus.StoreTheirDidAsync(_wallet, identityJson).Wait(); + await Signus.StoreTheirDidAsync(_wallet, identityJson); - Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Wait(); + await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver); } } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentRemoveIdentityTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentRemoveIdentityTest.cs index bba5d3047f..c80d76b1c0 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentRemoveIdentityTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentRemoveIdentityTest.cs @@ -1,5 +1,6 @@ using Indy.Sdk.Dotnet.Wrapper; using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading.Tasks; namespace Indy.Sdk.Dotnet.Test.Wrapper.AgentTests { @@ -7,17 +8,17 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.AgentTests public class AgentRemoveIdentityTest : AgentIntegrationTestBase { [TestMethod] - public void TestAgentRemoveIdentityWorks() + public async Task TestAgentRemoveIdentityWorks() { var endpoint = "127.0.0.1:9608"; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); - var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result; + var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver); - activeListener.AddIdentityAsync(_pool, _wallet, myDidResult.Did).Wait(); + await activeListener.AddIdentityAsync(_pool, _wallet, myDidResult.Did); - activeListener.RemoveIdentityAsync(_wallet, myDidResult.Did).Wait(); + await activeListener.RemoveIdentityAsync(_wallet, myDidResult.Did); } } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentSendTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentSendTest.cs index f5c362f987..7e347804de 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentSendTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AgentTests/AgentSendTest.cs @@ -37,33 +37,33 @@ public class AgentSendTest : AgentIntegrationTestBase }; [TestMethod] - public void TestAgentSendWorks() + public async Task TestAgentSendWorks() { var endpoint = "127.0.0.1:9609"; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}", myDidResult.Did, myDidResult.Pk, myDidResult.VerKey, endpoint); - Signus.StoreTheirDidAsync(_wallet, identityJson).Wait(); + await Signus.StoreTheirDidAsync(_wallet, identityJson); - var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result; + var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver); - activeListener.AddIdentityAsync(_pool, _wallet, myDidResult.Did).Wait(); + await activeListener.AddIdentityAsync(_pool, _wallet, myDidResult.Did); - var clientToServerConnection = Agent.AgentConnectAsync(_pool, _wallet, myDidResult.Did, myDidResult.Did, _messageObserver).Result; + var clientToServerConnection = await Agent.AgentConnectAsync(_pool, _wallet, myDidResult.Did, myDidResult.Did, _messageObserver); var clientToServerMessage = "msg_from_client"; var serverToClientMessage = "msg_from_server"; - clientToServerConnection.SendAsync(clientToServerMessage).Wait(); + await clientToServerConnection.SendAsync(clientToServerMessage); - Assert.AreEqual(clientToServerMessage, clientToServerMsgFuture.Task.Result); + Assert.AreEqual(clientToServerMessage, await clientToServerMsgFuture.Task); - var serverToClientConnection = serverToClientConnectionFuture.Task.Result; - serverToClientConnection.SendAsync(serverToClientMessage).Wait(); + var serverToClientConnection = await serverToClientConnectionFuture.Task; + await serverToClientConnection.SendAsync(serverToClientMessage); - Assert.AreEqual(serverToClientMessage, serverToClientMsgFuture.Task.Result); + Assert.AreEqual(serverToClientMessage, await serverToClientMsgFuture.Task); } } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/AnonCredsIntegrationTestBase.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/AnonCredsIntegrationTestBase.cs index 7daad6e62a..57a28f8e33 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/AnonCredsIntegrationTestBase.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/AnonCredsIntegrationTestBase.cs @@ -1,6 +1,6 @@ using Indy.Sdk.Dotnet.Wrapper; using Microsoft.VisualStudio.TestTools.UnitTesting; - +using System.Threading.Tasks; namespace Indy.Sdk.Dotnet.Test.Wrapper.AnonCredsTests { @@ -26,12 +26,20 @@ public abstract class AnonCredsIntegrationTestBase "\"issuer_did\":\"{0}\",\"schema_seq_no\":{1}}}"; [TestInitialize] - public void SetUp() + public async Task SetUp() + { + await InitHelper.InitAsync(); + } + + [ClassCleanup] + public static async Task CloseCommonWallet() { - InitHelper.Init(); + if (_commonWallet != null) + await _commonWallet.CloseAsync(); + } - - protected void InitCommonWallet() + + protected async Task InitCommonWallet() { if (_walletOpened) return; @@ -40,20 +48,20 @@ protected void InitCommonWallet() var walletName = "anoncredsCommonWallet"; - Wallet.CreateWalletAsync("default", walletName, "default", null, null).Wait(); - _commonWallet = Wallet.OpenWalletAsync(walletName, null, null).Result; + await Wallet.CreateWalletAsync("default", walletName, "default", null, null); + _commonWallet = await Wallet.OpenWalletAsync(walletName, null, null); - _claimDef = AnonCreds.IssuerCreateAndStoreClaimDefAsync(_commonWallet, _issuerDid, _schema, null, false).Result; + _claimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(_commonWallet, _issuerDid, _schema, null, false); - AnonCreds.ProverStoreClaimOfferAsync(_commonWallet, string.Format(_claimOfferTemplate, _issuerDid, 1)).Wait(); - AnonCreds.ProverStoreClaimOfferAsync(_commonWallet, string.Format(_claimOfferTemplate, _issuerDid, 2)).Wait(); - AnonCreds.ProverStoreClaimOfferAsync(_commonWallet, string.Format(_claimOfferTemplate, _issuerDid2, 2)).Wait(); + await AnonCreds.ProverStoreClaimOfferAsync(_commonWallet, string.Format(_claimOfferTemplate, _issuerDid, 1)); + await AnonCreds.ProverStoreClaimOfferAsync(_commonWallet, string.Format(_claimOfferTemplate, _issuerDid, 2)); + await AnonCreds.ProverStoreClaimOfferAsync(_commonWallet, string.Format(_claimOfferTemplate, _issuerDid2, 2)); - AnonCreds.ProverCreateMasterSecretAsync(_commonWallet, _masterSecretName).Wait(); + await AnonCreds.ProverCreateMasterSecretAsync(_commonWallet, _masterSecretName); var claimOffer = string.Format("{{\"issuer_did\":\"{0}\",\"schema_seq_no\":{1}}}", _issuerDid, 1); - var claimRequest = AnonCreds.ProverCreateAndStoreClaimReqAsync(_commonWallet, "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", claimOffer, _claimDef, _masterSecretName).Result; + var claimRequest = await AnonCreds.ProverCreateAndStoreClaimReqAsync(_commonWallet, "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", claimOffer, _claimDef, _masterSecretName); var claim = "{\"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + @@ -61,10 +69,10 @@ protected void InitCommonWallet() " \"age\":[\"28\",\"28\"]\n" + " }"; - var createClaimResult = AnonCreds.IssuerCreateClaimAsync(_commonWallet, claimRequest, claim, -1, -1).Result; + var createClaimResult = await AnonCreds.IssuerCreateClaimAsync(_commonWallet, claimRequest, claim, -1, -1); var claimJson = createClaimResult.ClaimJson; - AnonCreds.ProverStoreClaimAsync(_commonWallet, claimJson).Wait(); + await AnonCreds.ProverStoreClaimAsync(_commonWallet, claimJson); _walletOpened = true; } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/IssuerCreateAndStoreClaimDefinitionTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/IssuerCreateAndStoreClaimDefinitionTest.cs index 3e34121d59..f003f78ca9 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/IssuerCreateAndStoreClaimDefinitionTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/IssuerCreateAndStoreClaimDefinitionTest.cs @@ -23,28 +23,25 @@ public class IssuerCreateAndStoreClaimDefinitionTest : AnonCredsIntegrationTestB " }"; [TestInitialize] - public void CreateWallet() + public async Task CreateWallet() { - Wallet.CreateWalletAsync("default", _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; + await Wallet.CreateWalletAsync("default", _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); } [TestCleanup] - public void DeleteWallet() + public async Task DeleteWallet() { - try - { - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); - } - catch(Exception) - { } + if(_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); } [TestMethod] - public void TestIssuerCreateAndStoreClaimDefWorks() + public async Task TestIssuerCreateAndStoreClaimDefWorks() { - var claimDef = AnonCreds.IssuerCreateAndStoreClaimDefAsync(_wallet, _issuerDid, _gvtSchemaJson, null, false).Result; + var claimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(_wallet, _issuerDid, _gvtSchemaJson, null, false); Assert.IsNotNull(claimDef); var claimDefObject = JObject.Parse(claimDef); @@ -90,9 +87,9 @@ public async Task TestIssuerCreateAndStoreClaimDefWorksForEmptyKeys() } [TestMethod] - public void TestIssuerCreateAndStoreClaimDefWorksForCorrectCryptoType() + public async Task TestIssuerCreateAndStoreClaimDefWorksForCorrectCryptoType() { - var claimDef = AnonCreds.IssuerCreateAndStoreClaimDefAsync(_wallet, _issuerDid, _gvtSchemaJson, "CL", false).Result; + var claimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(_wallet, _issuerDid, _gvtSchemaJson, "CL", false); Assert.IsNotNull(claimDef); var claimDefObject = JObject.Parse(claimDef); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/IssuerCreateClaimTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/IssuerCreateClaimTest.cs index 11a05cff1e..e007d1f403 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/IssuerCreateClaimTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/IssuerCreateClaimTest.cs @@ -10,21 +10,10 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.AnonCredsTests [TestClass] public class IssuerCreateClaimTest : AnonCredsIntegrationTestBase { - [ClassCleanup] - public static void CloseCommonWallet() - { - try - { - _commonWallet.CloseAsync().Wait(); - } - catch (Exception) - { } - } - [TestMethod] - public void TestIssuerCreateAndStoreClaimWorks() + public async Task TestIssuerCreateAndStoreClaimWorks() { - InitCommonWallet(); + await InitCommonWallet(); var claimRequest = string.Format(_claimRequestTemplate, _issuerDid, 1); @@ -34,7 +23,7 @@ public void TestIssuerCreateAndStoreClaimWorks() " \"age\":[\"28\",\"28\"]\n" + " }"; - var createClaimResult = AnonCreds.IssuerCreateClaimAsync(_commonWallet, claimRequest, claim, -1, -1).Result; + var createClaimResult = await AnonCreds.IssuerCreateClaimAsync(_commonWallet, claimRequest, claim, -1, -1); Assert.IsNotNull(createClaimResult); var claimJson = createClaimResult.ClaimJson; @@ -50,7 +39,7 @@ public void TestIssuerCreateAndStoreClaimWorks() [TestMethod] public async Task TestIssuerCreateAndStoreClaimWorksForClaimDoesNotCorrespondToClaimRequest() { - InitCommonWallet(); + await InitCommonWallet(); var claimRequest = string.Format(_claimRequestTemplate, _issuerDid, 1); @@ -68,7 +57,7 @@ public async Task TestIssuerCreateAndStoreClaimWorksForClaimDoesNotCorrespondToC [TestMethod] public async Task TestIssuerCreateAndStoreClaimReqWorksForInvalidClaim() { - InitCommonWallet(); + await InitCommonWallet(); String claimRequest = string.Format(_claimRequestTemplate, _issuerDid, 1); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverCreateAndStoreClaimReqTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverCreateAndStoreClaimReqTest.cs index f63e38c5aa..b134c81b7a 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverCreateAndStoreClaimReqTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverCreateAndStoreClaimReqTest.cs @@ -9,31 +9,20 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.AnonCredsTests [TestClass] public class ProverCreateAndStoreClaimReqTest : AnonCredsIntegrationTestBase { - [ClassCleanup] - public static void CloseCommonWallet() - { - try - { - _commonWallet.CloseAsync().Wait(); - } - catch (Exception) - { } - } - [TestMethod] - public void TestProverCreateAndStoreClaimReqWorks() + public async Task TestProverCreateAndStoreClaimReqWorks() { - InitCommonWallet(); + await InitCommonWallet(); var claimOffer = string.Format(_claimOfferTemplate, _issuerDid, 1); - AnonCreds.ProverCreateAndStoreClaimReqAsync(_commonWallet, _proverDid, claimOffer, _claimDef, _masterSecretName).Wait(); + await AnonCreds.ProverCreateAndStoreClaimReqAsync(_commonWallet, _proverDid, claimOffer, _claimDef, _masterSecretName); } [TestMethod] public async Task TestProverCreateAndStoreClaimReqWorksForClaimDefDoesNotCorrespondToClaimOfferDifferentIssuer() { - InitCommonWallet(); + await InitCommonWallet(); var claimOffer = string.Format(_claimOfferTemplate, "acWziYqKpYi6ov5FcYDi1e3", 1); @@ -47,7 +36,7 @@ public async Task TestProverCreateAndStoreClaimReqWorksForClaimDefDoesNotCorresp [TestMethod] public async Task TestProverCreateAndStoreClaimReqWorksForClaimDefDoesNotCorrespondToClaimOfferDifferentSchema() { - InitCommonWallet(); + await InitCommonWallet(); var claimOffer = string.Format(_claimOfferTemplate, _issuerDid, 2); @@ -61,7 +50,7 @@ public async Task TestProverCreateAndStoreClaimReqWorksForClaimDefDoesNotCorresp [TestMethod] public async Task TestProverCreateAndStoreClaimReqWorksForInvalidClaimOffer() { - InitCommonWallet(); + await InitCommonWallet(); var claimOffer = string.Format("{{\"issuer_did\":\"{0}\"}}", _issuerDid); @@ -75,7 +64,7 @@ public async Task TestProverCreateAndStoreClaimReqWorksForInvalidClaimOffer() [TestMethod] public async Task TestProverCreateAndStoreClaimReqWorksForInvalidMasterSecret() { - InitCommonWallet(); + await InitCommonWallet(); var claimOffer = string.Format(_claimOfferTemplate, _issuerDid, 2); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverCreateMasterSecretTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverCreateMasterSecretTest.cs index 9d94cdfe08..8ea6a74c50 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverCreateMasterSecretTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverCreateMasterSecretTest.cs @@ -14,34 +14,31 @@ public class ProverCreateMasterSecretTest : AnonCredsIntegrationTestBase [TestInitialize] - public void CreateWallet() + public async Task CreateWallet() { - Wallet.CreateWalletAsync("default", _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; + await Wallet.CreateWalletAsync("default", _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); } [TestCleanup] - public void DeleteWallet() + public async Task DeleteWallet() { - try - { - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); - } - catch (Exception) - { } + if (_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); } [TestMethod] - public void TestProverCreateMasterSecretWorks() + public async Task TestProverCreateMasterSecretWorks() { - AnonCreds.ProverCreateMasterSecretAsync(_wallet, "master_secret_name").Wait(); + await AnonCreds.ProverCreateMasterSecretAsync(_wallet, "master_secret_name"); } [TestMethod] public async Task TestProverCreateMasterSecretWorksForDuplicate() { - AnonCreds.ProverCreateMasterSecretAsync(_wallet, "master_secret_name_duplicate").Wait(); + await AnonCreds.ProverCreateMasterSecretAsync(_wallet, "master_secret_name_duplicate"); var ex = await Assert.ThrowsExceptionAsync(() => AnonCreds.ProverCreateMasterSecretAsync(_wallet, "master_secret_name_duplicate") diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverCreateProofTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverCreateProofTest.cs index 2cfac5a67c..7e962aab29 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverCreateProofTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverCreateProofTest.cs @@ -10,22 +10,10 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.AnonCredsTests [TestClass] public class ProverCreateProofTest : AnonCredsIntegrationTestBase { - [ClassCleanup] - public static void CloseCommonWallet() - { - try - { - _commonWallet.CloseAsync().Wait(); - } - catch (Exception) - { } - - } - [TestMethod] - public void TestProverCreateProofWorks() + public async Task TestProverCreateProofWorks() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + @@ -34,7 +22,7 @@ public void TestProverCreateProofWorks() " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + " }"; - var claimsJson = AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest).Result; + var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); @@ -52,8 +40,8 @@ public void TestProverCreateProofWorks() var claimDefsJson = string.Format("{{\"{0}\":{1}}}", claimUuid, _claimDef); var revocRegsJson = "{}"; - var proofJson = AnonCreds.ProverCreateProofAsync(_commonWallet, proofRequest, requestedClaimsJson, schemasJson, - _masterSecretName, claimDefsJson, revocRegsJson).Result; + var proofJson = await AnonCreds.ProverCreateProofAsync(_commonWallet, proofRequest, requestedClaimsJson, schemasJson, + _masterSecretName, claimDefsJson, revocRegsJson); Assert.IsNotNull(proofJson); } @@ -61,9 +49,9 @@ public void TestProverCreateProofWorks() [TestMethod] public async Task TestProverCreateProofWorksForUsingNotSatisfyClaim() { - InitCommonWallet(); + await InitCommonWallet(); - var claimsJson = AnonCreds.ProverGetClaimsAsync(_commonWallet, "{}").Result; + var claimsJson = await AnonCreds.ProverGetClaimsAsync(_commonWallet, "{}"); var claims = JArray.Parse(claimsJson); @@ -96,7 +84,7 @@ public async Task TestProverCreateProofWorksForUsingNotSatisfyClaim() [TestMethod] public async Task TestProverCreateProofWorksForInvalidMasterSecret() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + @@ -105,7 +93,7 @@ public async Task TestProverCreateProofWorksForInvalidMasterSecret() " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + " }"; - var claimsJson = AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest).Result; + var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); @@ -122,7 +110,6 @@ public async Task TestProverCreateProofWorksForInvalidMasterSecret() var schemasJson = string.Format("{{\"{0}\":{1}}}", claimUuid, _schema); var claimDefsJson = string.Format("{{\"{0}\":{1}}}", claimUuid, _claimDef); var revocRegsJson = "{}"; - var ex = await Assert.ThrowsExceptionAsync(() => AnonCreds.ProverCreateProofAsync(_commonWallet, proofRequest, requestedClaimsJson, schemasJson, "wrong_master_secret", claimDefsJson, revocRegsJson) @@ -135,7 +122,7 @@ public async Task TestProverCreateProofWorksForInvalidMasterSecret() [TestMethod] public async Task TestProverCreateProofWorksForInvalidSchemas() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + @@ -144,7 +131,7 @@ public async Task TestProverCreateProofWorksForInvalidSchemas() " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + " }"; - var claimsJson = AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest).Result; + var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); @@ -162,7 +149,6 @@ public async Task TestProverCreateProofWorksForInvalidSchemas() var claimDefsJson = string.Format("{{\"{0}\":{1}}}", claimUuid, _claimDef); var revocRegsJson = "{}"; - var ex = await Assert.ThrowsExceptionAsync(() => AnonCreds.ProverCreateProofAsync(_commonWallet, proofRequest, requestedClaimsJson, schemasJson, _masterSecretName, claimDefsJson, revocRegsJson) @@ -174,7 +160,7 @@ public async Task TestProverCreateProofWorksForInvalidSchemas() [TestMethod] public async Task TestProverCreateProofWorksForInvalidRequestedClaimsJson() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + @@ -183,7 +169,7 @@ public async Task TestProverCreateProofWorksForInvalidRequestedClaimsJson() " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + " }"; - var claimsJson = AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest).Result; + var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); @@ -199,7 +185,6 @@ public async Task TestProverCreateProofWorksForInvalidRequestedClaimsJson() var claimDefsJson = string.Format("{{\"{0}\":{1}}}", claimUuid, _claimDef); var revocRegsJson = "{}"; - var ex = await Assert.ThrowsExceptionAsync(() => AnonCreds.ProverCreateProofAsync(_commonWallet, proofRequest, requestedClaimsJson, schemasJson, "wrong_master_secret", claimDefsJson, revocRegsJson) diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverGetClaimOfferTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverGetClaimOfferTest.cs index a3b44ea786..bca26d8079 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverGetClaimOfferTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverGetClaimOfferTest.cs @@ -10,37 +10,25 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.AnonCredsTests [TestClass] public class ProverGetClaimOfferTest : AnonCredsIntegrationTestBase { - [ClassCleanup] - public static void CloseCommonWallet() - { - try - { - _commonWallet.CloseAsync().Wait(); - } - catch (Exception) - { } - - } - [TestMethod] - public void TestsProverGetClaimOffersWorksForEmptyFilter() + public async Task TestsProverGetClaimOffersWorksForEmptyFilter() { - InitCommonWallet(); + await InitCommonWallet(); - var claimOffers = AnonCreds.ProverGetClaimOffersAsync(_commonWallet, "{}").Result; + var claimOffers = await AnonCreds.ProverGetClaimOffersAsync(_commonWallet, "{}"); var claimOffersArray = JArray.Parse(claimOffers); Assert.AreEqual(3, claimOffersArray.Count); } [TestMethod] - public void TestsProverGetClaimOffersWorksForFilterByIssuer() + public async Task TestsProverGetClaimOffersWorksForFilterByIssuer() { - InitCommonWallet(); + await InitCommonWallet(); var filter = string.Format("{{\"issuer_did\":\"{0}\"}}", _issuerDid); - var claimOffers = AnonCreds.ProverGetClaimOffersAsync(_commonWallet, filter).Result; + var claimOffers = await AnonCreds.ProverGetClaimOffersAsync(_commonWallet, filter); var claimOffersArray = JArray.Parse(claimOffers); Assert.AreEqual(2, claimOffersArray.Count); @@ -50,13 +38,13 @@ public void TestsProverGetClaimOffersWorksForFilterByIssuer() } [TestMethod] - public void TestsProverGetClaimOffersWorksForFilterBySchema() + public async Task TestsProverGetClaimOffersWorksForFilterBySchema() { - InitCommonWallet(); + await InitCommonWallet(); var filter = string.Format("{{\"schema_seq_no\":{0}}}", 2); - var claimOffers = AnonCreds.ProverGetClaimOffersAsync(_commonWallet, filter).Result; + var claimOffers = await AnonCreds.ProverGetClaimOffersAsync(_commonWallet, filter); var claimOffersArray = JArray.Parse(claimOffers); Assert.AreEqual(2, claimOffersArray.Count); @@ -66,13 +54,13 @@ public void TestsProverGetClaimOffersWorksForFilterBySchema() } [TestMethod] - public void TestsProverGetClaimOffersWorksForFilterByIssuerAndSchema() + public async Task TestsProverGetClaimOffersWorksForFilterByIssuerAndSchema() { - InitCommonWallet(); + await InitCommonWallet(); var filter = string.Format("{{\"issuer_did\":\"{0}\",\"schema_seq_no\":{1}}}", _issuerDid, 1); - var claimOffers = AnonCreds.ProverGetClaimOffersAsync(_commonWallet, filter).Result; + var claimOffers = await AnonCreds.ProverGetClaimOffersAsync(_commonWallet, filter); var claimOffersArray = JArray.Parse(claimOffers); Assert.AreEqual(1, claimOffersArray.Count); @@ -81,13 +69,13 @@ public void TestsProverGetClaimOffersWorksForFilterByIssuerAndSchema() } [TestMethod] - public void TestsProverGetClaimOffersWorksForNoResult() + public async Task TestsProverGetClaimOffersWorksForNoResult() { - InitCommonWallet(); + await InitCommonWallet(); var filter = string.Format("{{\"schema_seq_no\":{0}}}", 3); - var claimOffers = AnonCreds.ProverGetClaimOffersAsync(_commonWallet, filter).Result; + var claimOffers = await AnonCreds.ProverGetClaimOffersAsync(_commonWallet, filter); var claimOffersArray = JArray.Parse(claimOffers); Assert.AreEqual(0, claimOffersArray.Count); @@ -96,7 +84,7 @@ public void TestsProverGetClaimOffersWorksForNoResult() [TestMethod] public async Task TestProverGetClaimOffersWorksForInvalidFilterJson() { - InitCommonWallet(); + await InitCommonWallet(); var filter = string.Format("{{\"schema_seq_no\":\"{0}\"}}", 1); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverGetClaimsForProofRequestTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverGetClaimsForProofRequestTest.cs index f11576c633..78a5e6e182 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverGetClaimsForProofRequestTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverGetClaimsForProofRequestTest.cs @@ -10,22 +10,10 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.AnonCredsTests [TestClass] public class ProverGetClaimsForProofRequestTest : AnonCredsIntegrationTestBase { - [ClassCleanup] - public static void CloseCommonWallet() - { - try - { - _commonWallet.CloseAsync().Wait(); - } - catch (Exception) - { } - - } - [TestMethod] - public void TestProverGetClaimsForProofRequestWorksForRevealedAttribute() + public async Task TestProverGetClaimsForProofRequestWorksForRevealedAttribute() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + @@ -34,7 +22,7 @@ public void TestProverGetClaimsForProofRequestWorksForRevealedAttribute() " \"requested_predicates\":{}\n" + " }"; - var claimsJson = AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest).Result; + var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); @@ -43,9 +31,9 @@ public void TestProverGetClaimsForProofRequestWorksForRevealedAttribute() } [TestMethod] - public void TestProverGetClaimsForProofRequestWorksForNotFoundAttribute() + public async Task TestProverGetClaimsForProofRequestWorksForNotFoundAttribute() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + @@ -54,7 +42,7 @@ public void TestProverGetClaimsForProofRequestWorksForNotFoundAttribute() " \"requested_predicates\":{}\n" + " }"; - var claimsJson = AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest).Result; + var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); @@ -63,9 +51,9 @@ public void TestProverGetClaimsForProofRequestWorksForNotFoundAttribute() } [TestMethod] - public void TestProverGetClaimsForProofRequestWorksForSatisfyPredicate() + public async Task TestProverGetClaimsForProofRequestWorksForSatisfyPredicate() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + @@ -74,7 +62,7 @@ public void TestProverGetClaimsForProofRequestWorksForSatisfyPredicate() " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + " }"; - var claimsJson = AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest).Result; + var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); @@ -83,9 +71,9 @@ public void TestProverGetClaimsForProofRequestWorksForSatisfyPredicate() } [TestMethod] - public void TestProverGetClaimsForProofRequestWorksForNotSatisfyPredicate() + public async Task TestProverGetClaimsForProofRequestWorksForNotSatisfyPredicate() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + @@ -94,7 +82,7 @@ public void TestProverGetClaimsForProofRequestWorksForNotSatisfyPredicate() " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":58}}\n" + " }"; - var claimsJson = AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest).Result; + var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); @@ -103,9 +91,9 @@ public void TestProverGetClaimsForProofRequestWorksForNotSatisfyPredicate() } [TestMethod] - public void TestProverGetClaimsForProofRequestWorksForMultipleAttributesAndPredicates() + public async Task TestProverGetClaimsForProofRequestWorksForMultipleAttributesAndPredicates() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + @@ -119,7 +107,7 @@ public void TestProverGetClaimsForProofRequestWorksForMultipleAttributesAndPredi " \"predicate2_uuid\":{\"attr_name\":\"height\",\"p_type\":\"GE\",\"value\":160}\n" + " }}"; - var claimsJson = AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest).Result; + var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); @@ -137,9 +125,9 @@ public void TestProverGetClaimsForProofRequestWorksForMultipleAttributesAndPredi } [TestMethod] - public void TestProverGetClaimsForProofRequestWorksForEmptyRequest() + public async Task TestProverGetClaimsForProofRequestWorksForEmptyRequest() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + @@ -148,7 +136,7 @@ public void TestProverGetClaimsForProofRequestWorksForEmptyRequest() " \"requested_predicates\":{}\n" + " }"; - var claimsJson = AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest).Result; + var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); @@ -157,9 +145,9 @@ public void TestProverGetClaimsForProofRequestWorksForEmptyRequest() } [TestMethod] - public void TestProverGetClaimsForProofRequestWorksForRevealedAttributeWithOtherSchema() + public async Task TestProverGetClaimsForProofRequestWorksForRevealedAttributeWithOtherSchema() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + @@ -168,7 +156,7 @@ public void TestProverGetClaimsForProofRequestWorksForRevealedAttributeWithOther " \"requested_predicates\":{}\n" + " }"; - var claimsJson = AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest).Result; + var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); @@ -177,9 +165,9 @@ public void TestProverGetClaimsForProofRequestWorksForRevealedAttributeWithOther } [TestMethod] - public void TestProverGetClaimsForProofRequestWorksForRevealedAttributeBySpecificIssuer() + public async Task TestProverGetClaimsForProofRequestWorksForRevealedAttributeBySpecificIssuer() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + @@ -188,7 +176,7 @@ public void TestProverGetClaimsForProofRequestWorksForRevealedAttributeBySpecifi " \"requested_predicates\":{}\n" + " }"; - var claimsJson = AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest).Result; + var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); @@ -197,9 +185,9 @@ public void TestProverGetClaimsForProofRequestWorksForRevealedAttributeBySpecifi } [TestMethod] - public void TestProverGetClaimsForProofRequestWorksForSatisfyPredicateByIssuerAndSchema() + public async Task TestProverGetClaimsForProofRequestWorksForSatisfyPredicateByIssuerAndSchema() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + @@ -208,7 +196,7 @@ public void TestProverGetClaimsForProofRequestWorksForSatisfyPredicateByIssuerAn " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18,\"schema_seq_no\":1,\"issuer_did\":\"NcYxiDXkpYi6ov5FcYDi1e\"}}\n" + " }"; - var claimsJson = AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest).Result; + var claimsJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_commonWallet, proofRequest); var claims = JObject.Parse(claimsJson); @@ -219,7 +207,7 @@ public void TestProverGetClaimsForProofRequestWorksForSatisfyPredicateByIssuerAn [TestMethod] public async Task TestProverGetClaimsForProofRequestWorksForInvalidProofRequest() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + @@ -237,7 +225,7 @@ public async Task TestProverGetClaimsForProofRequestWorksForInvalidProofRequest( [TestMethod] public async Task TestProverGetClaimsForProofRequestWorksForInvalidPredicateType() { - InitCommonWallet(); + await InitCommonWallet(); var proofRequest = "{\"nonce\":\"123432421212\",\n" + " \"name\":\"proof_req_1\",\n" + diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverGetClaimsTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverGetClaimsTest.cs index 4bc096363f..04ae8562fa 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverGetClaimsTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverGetClaimsTest.cs @@ -10,24 +10,12 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.AnonCredsTests [TestClass] public class ProverGetClaimsTest : AnonCredsIntegrationTestBase { - [ClassCleanup] - public static void CloseCommonWallet() - { - try - { - _commonWallet.CloseAsync().Wait(); - } - catch (Exception) - { } - - } - [TestMethod] - public void TestProverGetClaimsWorksForEmptyFilter() + public async Task TestProverGetClaimsWorksForEmptyFilter() { - InitCommonWallet(); + await InitCommonWallet(); - var claims = AnonCreds.ProverGetClaimsAsync(_commonWallet, "{}").Result; + var claims = await AnonCreds.ProverGetClaimsAsync(_commonWallet, "{}"); var claimsArray = JArray.Parse(claims); @@ -35,13 +23,13 @@ public void TestProverGetClaimsWorksForEmptyFilter() } [TestMethod] - public void TestProverGetClaimsWorksForFilterByIssuer() + public async Task TestProverGetClaimsWorksForFilterByIssuer() { - InitCommonWallet(); + await InitCommonWallet(); var filter = string.Format("{{\"issuer_did\":\"{0}\"}}", _issuerDid); - var claims = AnonCreds.ProverGetClaimsAsync(_commonWallet, filter).Result; + var claims = await AnonCreds.ProverGetClaimsAsync(_commonWallet, filter); var claimsArray = JArray.Parse(claims); @@ -49,13 +37,13 @@ public void TestProverGetClaimsWorksForFilterByIssuer() } [TestMethod] - public void TestProverGetClaimsWorksForFilterByIssuerAndSchema() + public async Task TestProverGetClaimsWorksForFilterByIssuerAndSchema() { - InitCommonWallet(); + await InitCommonWallet(); var filter = string.Format("{{\"issuer_did\":\"{0}\", \"schema_seq_no\":{1}}}", _issuerDid, 1); - var claims = AnonCreds.ProverGetClaimsAsync(_commonWallet, filter).Result; + var claims = await AnonCreds.ProverGetClaimsAsync(_commonWallet, filter); var claimsArray = JArray.Parse(claims); @@ -63,13 +51,13 @@ public void TestProverGetClaimsWorksForFilterByIssuerAndSchema() } [TestMethod] - public void TestProverGetClaimsWorksForEmptyResult() + public async Task TestProverGetClaimsWorksForEmptyResult() { - InitCommonWallet(); + await InitCommonWallet(); var filter = string.Format("{{\"schema_seq_no\":{0}}}", 10); - var claims = AnonCreds.ProverGetClaimsAsync(_commonWallet, filter).Result; + var claims = await AnonCreds.ProverGetClaimsAsync(_commonWallet, filter); var claimsArray = JArray.Parse(claims); @@ -80,7 +68,7 @@ public void TestProverGetClaimsWorksForEmptyResult() [TestMethod] public async Task TestProverGetClaimsForProofRequestWorksForInvalidPredicateType() { - InitCommonWallet(); + await InitCommonWallet(); var filter = string.Format("{{\"schema_seq_no\":\"{0}\"}}", 1); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverStoreClaimOfferTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverStoreClaimOfferTest.cs index 1aa3b6eaa0..4b9ed12290 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverStoreClaimOfferTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverStoreClaimOfferTest.cs @@ -13,31 +13,28 @@ public class ProverStoreClaimOfferTest : AnonCredsIntegrationTestBase private string _walletName = "storeClaimOfferWallet"; [TestInitialize] - public void CreateWallet() + public async Task CreateWallet() { - Wallet.CreateWalletAsync("default", _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; + await Wallet.CreateWalletAsync("default", _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); } [TestCleanup] - public void DeleteWallet() + public async Task DeleteWallet() { - try - { - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); - } - catch (Exception) - { } + if(_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); } [TestMethod] - public void TestProverStoreClaimOfferWorks() + public async Task TestProverStoreClaimOfferWorks() { var claimOffer = "{\"issuer_did\":\"NcYxiDXkpYi6ov5FcYDi1e\",\"schema_seq_no\":1 }"; - AnonCreds.ProverStoreClaimOfferAsync(_wallet, claimOffer).Wait(); + await AnonCreds.ProverStoreClaimOfferAsync(_wallet, claimOffer); } @@ -54,7 +51,7 @@ public async Task TestProverStoreClaimOfferWorksForInvalidJson() } [TestMethod] - public async Task testProverStoreClaimOfferWorksForInvalidIssuerDid() + public async Task TestProverStoreClaimOfferWorksForInvalidIssuerDid() { var claimOffer = "{\"issuer_did\":\"invalid_base58_string\",\"schema_seq_no\":1}"; diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverStoreClaimTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverStoreClaimTest.cs index dda31a0286..1b3d6a9d8e 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverStoreClaimTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/ProverStoreClaimTest.cs @@ -9,32 +9,20 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.AnonCredsTests [TestClass] public class ProverStoreClaimTest : AnonCredsIntegrationTestBase { - [ClassCleanup] - public static void CloseCommonWallet() - { - try - { - _commonWallet.CloseAsync().Wait(); - } - catch (Exception) - { } - - } - [TestMethod] - public void TestProverStoreClaimWorks() + public async Task TestProverStoreClaimWorks() { - InitCommonWallet(); + await InitCommonWallet(); var proverWalletName = "proverWallet"; - Wallet.CreateWalletAsync("default", proverWalletName, "default", null, null).Wait(); - var proverWallet = Wallet.OpenWalletAsync(proverWalletName, null, null).Result; + await Wallet.CreateWalletAsync("default", proverWalletName, "default", null, null); + var proverWallet = await Wallet.OpenWalletAsync(proverWalletName, null, null); - AnonCreds.ProverCreateMasterSecretAsync(proverWallet, _masterSecretName).Wait(); + await AnonCreds.ProverCreateMasterSecretAsync(proverWallet, _masterSecretName); var claimOffer = string.Format(_claimOfferTemplate, _issuerDid, 1); - var claimRequest = AnonCreds.ProverCreateAndStoreClaimReqAsync(proverWallet, _proverDid, claimOffer, _claimDef, _masterSecretName).Result; + var claimRequest = await AnonCreds.ProverCreateAndStoreClaimReqAsync(proverWallet, _proverDid, claimOffer, _claimDef, _masterSecretName); var claim = "{\"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + @@ -42,19 +30,19 @@ public void TestProverStoreClaimWorks() " \"age\":[\"28\",\"28\"]\n" + " }"; - var createClaimResult = AnonCreds.IssuerCreateClaimAsync(_commonWallet, claimRequest, claim, -1, -1).Result; + var createClaimResult = await AnonCreds.IssuerCreateClaimAsync(_commonWallet, claimRequest, claim, -1, -1); var claimJson = createClaimResult.ClaimJson; - AnonCreds.ProverStoreClaimAsync(proverWallet, claimJson).Wait(); + await AnonCreds.ProverStoreClaimAsync(proverWallet, claimJson); - proverWallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(proverWalletName, null).Wait(); + await proverWallet.CloseAsync(); + await Wallet.DeleteWalletAsync(proverWalletName, null); } [TestMethod] public async Task TestProverStoreClaimWorksWithoutClaim() { - InitCommonWallet(); + await InitCommonWallet(); var claimJson = string.Format("{{\"claim\":{{\"sex\":[\"male\",\"1\"],\"age\":[\"28\",\"28\"],\"name\":[\"Alex\",\"1\"],\"height\":[\"175\",\"175\"]}},\n" + " \"issuer_did\":\"{0}\",\n" + @@ -73,11 +61,11 @@ public async Task TestProverStoreClaimWorksWithoutClaim() [TestMethod] public async Task TestProverStoreClaimWorksForInvalidClaimJson() { - InitCommonWallet(); + await InitCommonWallet(); var claimOffer = string.Format(_claimOfferTemplate, _issuerDid, 1); - AnonCreds.ProverCreateAndStoreClaimReqAsync(_commonWallet, _proverDid, claimOffer, _claimDef, _masterSecretName).Wait(); + await AnonCreds.ProverCreateAndStoreClaimReqAsync(_commonWallet, _proverDid, claimOffer, _claimDef, _masterSecretName); var claimJson = "{\"claim\":{\"sex\":[\"male\",\"1\"],\"age\":[\"28\",\"28\"],\"name\":[\"Alex\",\"1\"],\"height\":[\"175\",\"175\"]},\n" + " \"issuer_did\":1,\"\n" + diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/VerifierVerifyProofTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/VerifierVerifyProofTest.cs index 52f101013d..63026ec949 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/VerifierVerifyProofTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/AnonCredsTests/VerifierVerifyProofTest.cs @@ -27,11 +27,11 @@ public class VerifierVerifyProofTest : AnonCredsIntegrationTestBase [TestMethod] - public void TestVerifierVerifyProofWorksForCorrectProof() + public async Task TestVerifierVerifyProofWorksForCorrectProof() { var proofJson = "{\"proofs\":{\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\":{\"proof\":{\"primary_proof\":{\"eq_proof\":{\"revealed_attrs\":{\"name\":\"1139481716457488690172217916278103335\"},\"a_prime\":\"47629821806628155353444789773246165920681315271529392722265555946090524267165563309836167110610840740533588118152308411732923636370660640410661034994521654033599863817144282118006097899736622728860229305231675970853294584911572355833537271010861501353858292189045263114095480601737776505186511389129055847562085611741257601964074827979121349153316235245772819207422031038042586202074331681302501661153569340935741290924699468188826629478130140797677338573924284871118002193526319478550852287453975107498037063076866410320160118555629090040954555043934303307652160345244864713226315470541231435958298648179413077988340\",\"e\":\"13427639393364185909415877973872458621259927563729922146828001652769380799419438410309469022979920689628523901764614163117469683925816443\",\"v\":\"852136445143816932026946294488424887907102968158908948827421962603492187508454543239422067899916472317305416590471170842186669606584356963437132366711335927890209765986844538775191207999204354235774464468525274918097404114453069375363594310105209141774763909570100638835926337238009617444858777301355087706167735590386774813901740600054753028260344014744801229032610106838480523182317262113911183640784111960909501662169298536941919854667754097841344375972975021196106884215734228415868248724905018661498061287694439466570946597514142085096419985189064172035527690786158872698717583830848410994616274586162550376126607414773916066374234063208380831144157533076866210628625236440222547584539349936639548061601416341705483504386186280800509889531835172071717956251546280392606775903107774727736794828168898273891724336881907672405328368540895104468091907771325910937575557566831844131159128453840354307814975621978196047820\",\"m\":{\"age\":\"1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662\",\"height\":\"7064132689652704067914104576495132313294680087958177180391515757079548676035445873279966783996928425154050462229933823707574545166617858646442019030600136959459527533262821184869\",\"sex\":\"16084497853957041205729191269508720470626311156190485518484640641677445098603656354458362520541393995692536218820724164533958162674375198846036330444513484319280148335515891811530\"},\"m1\":\"154906224259819061652290487122980839849626068919893070220438585977323162319993111920906032317552959103520053742608858935542877608981244065301675821390065831113115709272412144796159984624494428122971995557415296140268002332169405587907128359886810433617416529821500995701094400375272097687818064435577784795275\",\"m2\":\"13805395408072590464827983892588030341708765524663545700917462089376137940485022437657208204460048097312372685954050370540389593952001973312378647790917367330461398089529292217752\"},\"ge_proofs\":[{\"u\":{\"1\":\"7698818972783845439601187851976452936638792889455287252542709653271706844173743185409084669157965935169942655008606334521674712818637940377261656468700786810566551698412412949418\",\"0\":\"11703047052430512223413711314521545616119146623040600935686474696241801697819280425232876917607198335376453682738553665221410353412906194951254558355994401995990233992518110582450\",\"3\":\"13210777821918317858818819091924507295018522783042111457450035423463340571245465760486275059291363621513532153389441883097799049597687545496359999443320001567152794884095192951040\",\"2\":\"15219471780524079156861690098171693383497641272226737821992208834301871102152362116211452788300889697214391366996966539871625433480959011635688106136537800706217506402845296449689\"},\"r\":{\"1\":\"46043242109380749151527145850513330956077996622769158245225343392397735706292106535150958053995712629189143692293204979798837951212291825184346767969751978730000071952944305252032332015837054475531407691352179423131405515518588355918925056889302269768343499864256747177988825578647189563088068257214198650437730618330249172716051559993880468542083352885474175039320848153156858562341041960950299312991459780503345784440261679263045723337629951517601461685539857683027034345542399365706329805317943096391758978877658949910614447086409173234155028671453929715706057153381022697673192590033507204548864311227048268516889390503318015295207078022755834130221198717787608473222789491216667698651180077661375273569115943192\",\"0\":\"135472587547410377947826119498467634347118057359097899596599164976338466445104141784869016998150489852448547539824768048351359572626675997498079394825940306636285481821620973655797996638210760710325933304918452142858879806106214845499670718704532018129553348815327362843246706518826311676917538452317818631484884032929252959289913274829848084561421467966320595980172006456003183536232790787521924655750157145207798486087511869939940023266736153366338179116840490184005332351004990854691988404031259910319601383696749511809898297656135548118786342107367065232798999979296280467063561892962526945512167505847049907450058650930480352253243357594344686769208712964458923557777584158831146374282687397585726706489164423632\",\"DELTA\":\"93540839493959971552865423901789226093328763011922445919928571946113703515842729132879472109395228387208764738970926484618949870591214627692618668077375153559192701474693025462226656116549337248146652482501255820930607033869432220667968682424554711616471973627651716863421554516577716366331699848682958681216261888139409101603059124344125075525791543312721162515584942523419876134808829569829529457617639955678189490257208141837196965948342373022812790844435050648360150869293836349223060722858500537182872294143846213258360218898475766641125493477502149553491502593654061863323857297998048614447925371606038801933864960337435890254277043261512846682042139570000962051463878026338583242360548041329046695667868842400\",\"3\":\"1227675452527605924725300993571504188580051470857656204064614533296779844072852823820754766175236321050062349182891221840452517985644028521499240739391613871973822807731772613052644168369405390658793869751915172749739844553410726807277698347769400977274750672880389943392076308065414059539317340070691852044062594715307024113666759844200606183662256825096857658837519571386467051003466014468855293015652584667669998830524947537781865745830650392641812221679438090257444660715937570193098993118585554478799821072396238689063767016402460690760792908977364175126682041704095200572282644311025594681667826054722587271200221036938804846621444065128275082392082327596239358623150786484106872933657139420542280145197712634108\",\"2\":\"596248147592834822582469335300585333722415132713749620075902332764163096347819006925876158892694742461036531935093982309708492066217459300117157420442081698140277277546563570823996272914068575482008392971932777453900260626542725308060927710122631763045025742980634216666560934260634907599194353151523256914796667535940073668465664206971169038864484235442207811974981191879443614478897291543702607764944403808380921189291059195014621592027660463072969363556421687131446107696579365265893962197300447027501604372738056016734644378437907931412654753728514905671605635291285742886484416973884856055084605172305967034292646171874483670469193852404511746786039743401185954843446037600121496137915619789351744485264614840070\"},\"mj\":\"1117601261519431120446925325460734824239475567013636538481947258329666056692767097795046086413732472111811628751812987521644198549167671875326968410921589186689138994171774838662\",\"alpha\":\"76727612740067576380015106087224381023260815407331375101920043509817863645705120013304683427627332447210083684516403565749916480947649443674885388155460323163682547865307733144184097845709556309570345707127872162476432029772452433292049079349274445907295491125915363620615679995457134810061392296263970553630102299601689685622244925494554558218277670233361938142224820526392365740420502452466959099546877778248089664282581792213376636587293479012783947088070052463503335266180110771978445892744225891676396288437005847308189508347446490710626231658457908472341606549292437553353163031111068977301305043175839949352742711874426231072729977019365761072816602400121302646283352164756787266537474728685656685493249314400351742964904006326192403855909148605656818024621453179832395687665671245528217931951331393482249182516107670379946496778373\",\"t\":{\"1\":\"37203689290881948278188715497642400459048942241931994079434400288578680362970117779048886269388440270597283202033458042171954610700745461571112086648991639439510380585728148682202768590972068041537531136529323260832899360551065706810590032715173070285762675403853992183366951113799098912676809373169763887110420539387555392787590966452796271491986622992160642135480293110112269570862265489120557014181468118619500321000966443141863893743211690388599242584469856365803370202569641902205925191670838354052104480074127555862332399641076324738839120815544432811566503174551735326387678621283249883091766325861497740614317\",\"3\":\"58486787977689017034592833190899828017343431922483563651969628402499947729293364026001243898136737211851089198526360764391403150763769829047179796728616126204105160762333590343947446892105646111520243793053992399512412375936746396187319527051818920531870855183738837254656664620975569939859368862778444291640228229744805843388153451336792379036403300211151424879060241580540910888241769468335914016289938374111481091198264912969768783884602931940994543804730631920434719776196148182987249363641941951160704928605829395517074202388967815738516252602903999010405305463910751219873354588685197134114358234107748126140977\",\"0\":\"60771874648036182010335841594233428920565254732600738082343398028553347795361460295011584446745121430144172025428394361648540904134739046923992231536160801306934272250969829886396340824213814702904457884984387666505055153957942221822193548673145705543973635530652570436109428474727638128773540793530691399549837156239786231362112148914687724325416768262058486101761972044802628459748878200584371058300150212485731451700436345975266860685549673168984700174294811561393162860595319582236734968601457003780816977537443267217411297266600994916897237305128142313335280264655603445636393371224354539882875937093696844430903\",\"DELTA\":\"32816484171372208266594641116109072545171919234551585018140151846920408763078147655907777031259225522515086979967895258126318315788662577171150780535509410112003001556402222994276811926864642497249250763185467678044678144507739529818566125668667424447792097244624010084189629269472698722402896445274092470014229247479740671263651727480322483037149584904549203417226525624083290572692241241259382947122018271686649224741832992966652878170311798126004447080305528487720923103595513611363001766063956060990267107048028416069435287244770875463867263571308182619338433913487209319707428378896314619624990311543563016697299\",\"2\":\"36428320569485697540634597755814766104888687488985202673924762266313135133244610404742081973550848160712054769198012193456278135847215508952327879544434490828380496286187725750283788811367824465072001959950807751252194618152990469069074061195618692339915840384087350671392595652921761835083158086795163935060896053332506433434451836095710383871272788002621913967538399141417857031787255744141437237474972197102809365346359345477248611632307159641948507043668113827177494748159094045928919209335044052792843664865311991178972383241855607627188111601119780878072683890170539599447876998109080150992209773901144245398001\"},\"predicate\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}]},\"non_revoc_proof\":null},\"schema_seq_no\":1,\"revoc_reg_seq_no\":null,\"issuer_did\":\"did\"}},\"aggregated_proof\":{\"c_hash\":\"33103550379681684069592829341967479618752165928802550870585275205292715916069\",\"c_list\":[[1,121,77,5,144,154,14,192,190,190,145,180,128,71,22,60,168,20,46,163,139,194,71,165,220,188,121,76,25,146,231,114,65,54,69,68,19,200,250,192,47,123,157,132,74,50,28,69,226,195,243,118,45,63,237,197,216,202,206,101,33,56,225,200,128,3,89,12,182,38,113,221,165,119,228,201,156,201,172,136,59,64,51,72,164,198,49,228,223,117,80,64,166,226,37,8,29,146,186,80,210,119,76,252,4,255,62,218,112,163,164,147,247,190,108,76,140,191,76,217,214,184,152,179,193,149,15,70,197,46,90,60,255,247,197,219,252,73,76,0,125,104,114,22,182,161,110,36,162,103,27,42,88,18,161,237,198,43,177,189,181,86,135,207,71,114,0,26,175,12,199,125,25,124,178,87,36,208,251,15,191,127,202,148,152,43,142,92,191,7,89,153,130,195,223,248,176,109,97,164,126,162,181,124,237,130,155,197,66,59,40,197,72,84,32,100,64,55,227,60,214,143,200,200,89,115,236,172,145,56,100,73,20,242,233,95,130,58,112,153,120,115,119,42,199,30,205,88,223,42,196,184,41,19,100,19,244],[1,225,103,238,42,147,91,191,110,69,154,53,57,156,124,43,174,155,76,202,193,98,128,38,207,126,66,70,161,96,109,127,174,44,203,198,177,238,118,117,89,227,170,155,44,251,35,119,219,29,100,173,26,144,95,50,177,4,40,234,117,174,210,192,172,57,160,198,42,199,212,243,240,114,59,91,207,68,57,38,198,2,73,18,16,209,182,145,206,71,17,69,222,49,36,120,72,117,169,107,238,208,235,216,24,183,201,81,15,83,242,45,136,184,166,26,142,136,228,58,229,235,88,169,238,134,205,96,85,9,122,53,147,100,183,114,92,54,125,178,125,75,127,116,50,88,109,152,22,4,121,252,190,18,190,130,143,138,59,231,38,131,176,54,19,194,218,67,144,122,91,43,86,73,233,48,193,30,183,183,191,238,216,167,101,28,185,43,118,64,242,16,62,239,177,27,109,144,67,221,175,202,4,92,130,74,24,20,151,15,227,225,142,71,145,46,192,248,87,57,183,142,253,52,20,56,153,220,234,25,67,116,225,179,211,116,161,37,64,34,48,155,1,1,159,157,37,31,202,19,229,152,23,138,183,126,55],[1,38,181,193,191,72,2,239,34,83,49,36,179,160,82,112,172,98,255,63,60,22,177,249,67,215,220,198,181,7,49,254,133,243,221,214,47,64,229,82,11,94,175,57,86,152,229,192,184,96,136,116,226,123,128,217,23,244,19,204,36,44,123,208,88,24,217,120,145,139,25,233,227,5,119,90,47,147,1,115,92,39,119,194,167,17,229,39,163,167,237,14,116,234,106,252,216,54,33,233,21,54,183,130,144,161,177,142,177,240,51,73,21,202,188,103,244,153,204,219,123,231,139,135,189,155,143,28,4,180,44,148,0,27,103,26,13,203,31,32,166,67,84,87,23,72,234,236,20,1,84,70,86,76,192,164,235,124,86,128,78,230,119,155,95,121,125,20,244,181,121,250,169,9,67,85,213,177,139,111,187,183,114,165,249,177,161,181,175,46,226,66,86,84,124,86,69,143,217,158,161,30,107,133,44,239,89,209,24,150,1,238,122,144,138,179,121,114,90,13,212,209,60,126,37,62,177,180,131,222,168,2,201,156,169,220,224,53,8,203,220,215,163,104,195,184,73,35,241,182,177,80,41,253,230,90,173],[1,32,145,96,219,241,190,19,195,129,219,50,148,152,107,12,189,225,103,171,149,252,193,243,136,132,195,44,19,20,247,140,160,91,230,78,31,242,85,213,65,185,1,91,12,69,118,80,26,135,102,131,4,108,130,230,83,91,176,249,196,56,128,127,82,72,106,49,211,94,133,40,86,72,42,187,199,216,191,223,208,206,121,118,15,167,255,228,57,206,158,217,64,205,212,178,8,248,129,183,221,98,70,54,37,55,47,81,120,59,186,238,165,0,70,173,137,193,232,180,125,211,237,182,249,191,173,107,129,164,148,231,116,225,66,66,71,156,39,248,164,253,234,140,205,177,140,117,47,21,15,242,31,113,118,91,143,89,213,86,143,135,21,46,35,199,214,107,111,65,65,19,26,171,130,16,19,102,145,210,210,61,51,169,148,169,118,182,106,107,253,100,214,232,52,103,180,96,249,254,71,6,11,119,48,129,213,223,205,93,20,117,26,187,32,151,212,137,203,17,237,208,150,72,23,225,235,122,188,34,105,115,0,160,168,251,191,22,242,238,207,74,142,154,66,94,149,191,215,194,134,6,165,244,167,233,241],[1,207,77,250,146,127,242,229,44,172,182,201,183,242,32,242,182,129,233,10,8,180,23,191,163,21,238,158,5,27,216,146,253,173,127,99,95,168,209,132,242,196,242,34,25,25,249,211,51,236,164,153,175,61,65,150,82,251,174,102,186,47,195,82,44,90,252,184,74,89,251,177,254,108,151,136,230,220,93,224,173,247,244,116,132,59,170,215,194,30,87,84,166,147,57,156,201,207,132,203,222,191,253,15,19,228,173,81,156,4,51,121,227,159,50,18,148,129,205,42,42,227,252,138,62,176,115,227,253,52,125,110,178,167,132,244,14,116,195,194,172,44,45,63,38,121,215,136,68,230,21,108,133,159,197,179,94,78,233,107,236,114,92,165,248,22,124,161,23,142,236,224,175,233,134,25,97,150,131,61,220,203,104,154,199,247,146,47,205,56,209,0,133,132,18,103,136,8,202,37,29,100,105,12,232,74,33,6,255,202,96,170,52,229,244,4,235,2,201,125,86,168,179,224,130,81,54,221,185,184,187,141,0,114,98,38,70,225,228,60,157,53,210,238,60,216,215,154,48,73,3,157,192,245,81,170,49],[1,3,244,229,158,71,18,146,198,202,27,2,231,37,13,145,243,84,112,220,61,174,4,175,104,200,64,146,193,20,174,126,42,157,168,76,165,21,50,216,82,211,180,73,244,54,227,200,19,157,25,228,81,37,64,201,19,138,175,50,246,169,11,45,74,194,131,236,127,177,41,242,130,55,112,182,98,22,99,48,153,83,161,250,65,89,3,97,6,5,171,54,223,87,98,103,23,200,212,177,140,155,151,252,125,45,176,55,92,41,56,2,252,32,149,60,3,168,209,193,23,168,230,182,72,193,230,224,5,15,58,63,93,196,33,93,76,188,30,70,31,136,64,204,223,2,230,210,243,255,135,193,52,132,248,160,22,18,164,71,77,80,112,229,120,116,210,225,2,19,139,35,0,214,5,246,9,106,136,204,0,148,97,21,222,153,57,177,162,11,243,252,7,242,34,239,245,50,104,74,221,92,73,13,142,10,184,250,246,167,240,46,230,86,207,181,12,133,81,119,143,164,88,114,223,243,179,208,175,84,161,27,11,225,36,37,177,112,85,81,184,163,223,159,36,9,247,20,13,230,215,108,117,35,99,117,211]]},\"requested_proof\":{\"revealed_attrs\":{\"attr1_uuid\":[\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\",\"Alex\",\"1139481716457488690172217916278103335\"]},\"unrevealed_attrs\":{},\"self_attested_attrs\":{},\"predicates\":{\"predicate1_uuid\":\"claim::277478db-bf57-42c3-8530-b1b13cfe0bfd\"}}}"; - var valid = AnonCreds.VerifierVerifyProofAsync(_proofRequest, proofJson, _schemasJson, _claimDefsJson, _revocRegsJson).Result; + var valid = await AnonCreds.VerifierVerifyProofAsync(_proofRequest, proofJson, _schemasJson, _claimDefsJson, _revocRegsJson); Assert.IsTrue(valid); } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/AgentDemoTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/AgentDemoTest.cs index 926dccd54b..5b6c6fa323 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/AgentDemoTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/AgentDemoTest.cs @@ -31,7 +31,7 @@ public class AgentDemoTest : IndyIntegrationTestBase private static TaskCompletionSource _clientToServerMsgFuture = new TaskCompletionSource(); [TestMethod] - public void TestAgentDemo() + public async Task TestAgentDemo() { var endpoint = "127.0.0.1:9801"; var listenerWalletName = "listenerWallet"; @@ -40,19 +40,19 @@ public void TestAgentDemo() //1. Create and Open Pool var poolName = PoolUtils.CreatePoolLedgerConfig(); - var pool = Pool.OpenPoolLedgerAsync(poolName, "{}").Result; + var pool = await Pool.OpenPoolLedgerAsync(poolName, "{}"); //2. Create and Open Listener Wallet - Wallet.CreateWalletAsync(poolName, listenerWalletName, "default", null, null).Wait(); - var listenerWallet = Wallet.OpenWalletAsync(listenerWalletName, null, null).Result; + await Wallet.CreateWalletAsync(poolName, listenerWalletName, "default", null, null); + var listenerWallet = await Wallet.OpenWalletAsync(listenerWalletName, null, null); //3. Create and Open Trustee Wallet - Wallet.CreateWalletAsync(poolName, trusteeWalletName, "default", null, null).Wait(); - var trusteeWallet = Wallet.OpenWalletAsync(trusteeWalletName, null, null).Result; + await Wallet.CreateWalletAsync(poolName, trusteeWalletName, "default", null, null); + var trusteeWallet = await Wallet.OpenWalletAsync(trusteeWalletName, null, null); var senderWallet = trusteeWallet; //4. Create My Did - var createMyDidResult = Signus.CreateAndStoreMyDidAsync(listenerWallet, "{}").Result; + var createMyDidResult = await Signus.CreateAndStoreMyDidAsync(listenerWallet, "{}"); var listenerDid = createMyDidResult.Did; var listenerVerkey = createMyDidResult.VerKey; var listenerPk = createMyDidResult.Pk; @@ -60,49 +60,49 @@ public void TestAgentDemo() //5. Create Their Did from Trustee seed var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(trusteeWallet, trusteeDidJson).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(trusteeWallet, trusteeDidJson); var trusteeDid = trusteeDidResult.Did; var senderDid = trusteeDid; // 6. Prepare and Send NYM request with signing - var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, listenerDid, listenerVerkey, null, null).Result; - Ledger.SignAndSubmitRequestAsync(pool, trusteeWallet, trusteeDid, nymRequest).Wait(); + var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, listenerDid, listenerVerkey, null, null); + await Ledger.SignAndSubmitRequestAsync(pool, trusteeWallet, trusteeDid, nymRequest); // 7. Prepare and Send Attrib for listener (will be requested from ledger and used by sender at start connection) var rawJson = string.Format("{{\"endpoint\":{{\"ha\":\"{0}\",\"verkey\":\"{1}\"}}}}", endpoint, listenerPk); - var attribRequest = Ledger.BuildAttribRequestAsync(listenerDid, listenerDid, null, rawJson, null).Result; - Ledger.SignAndSubmitRequestAsync(pool, listenerWallet, listenerDid, attribRequest).Wait(); + var attribRequest = await Ledger.BuildAttribRequestAsync(listenerDid, listenerDid, null, rawJson, null); + await Ledger.SignAndSubmitRequestAsync(pool, listenerWallet, listenerDid, attribRequest); // 8. start listener on endpoint - var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result; + var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver); // 9. Allow listener accept incoming connection for specific DID (listener_did) - activeListener.AddIdentityAsync(pool, listenerWallet, listenerDid).Wait(); + await activeListener.AddIdentityAsync(pool, listenerWallet, listenerDid); // 10. Initiate connection from sender to listener - var connection = Agent.AgentConnectAsync(pool, senderWallet, senderDid, listenerDid, _messageObserver).Result; + var connection = await Agent.AgentConnectAsync(pool, senderWallet, senderDid, listenerDid, _messageObserver); // 11. Send test message from sender to listener - connection.SendAsync("test").Wait(); + await connection.SendAsync("test"); - Assert.AreEqual(message, _clientToServerMsgFuture.Task.Result); + Assert.AreEqual(message, await _clientToServerMsgFuture.Task); // 12. Close connection - connection.CloseAsync().Wait(); + await connection.CloseAsync(); // 13. Close listener - activeListener.CloseAsync().Wait(); + await activeListener.CloseAsync(); // 14. Close and delete Issuer Wallet - listenerWallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(listenerWalletName, null).Wait(); + await listenerWallet.CloseAsync(); + await Wallet.DeleteWalletAsync(listenerWalletName, null); // 15. Close and delete Prover Wallet - trusteeWallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(trusteeWalletName, null).Wait(); + await trusteeWallet.CloseAsync(); + await Wallet.DeleteWalletAsync(trusteeWalletName, null); //16. Close Pool - pool.CloseAsync().Wait(); + await pool.CloseAsync(); } } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/AnonCredsDemoTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/AnonCredsDemoTest.cs index ec99baf9f5..5e2b203bfe 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/AnonCredsDemoTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/AnonCredsDemoTest.cs @@ -15,37 +15,42 @@ public class AnonCredsDemoTest : IndyIntegrationTestBase private String _poolName; [TestInitialize] - public void CreateWallet() + public async Task CreateWallet() { //1. Create and Open Pool _poolName = PoolUtils.CreatePoolLedgerConfig(); - _pool = Pool.OpenPoolLedgerAsync(_poolName, "{}").Result; + _pool = await Pool.OpenPoolLedgerAsync(_poolName, "{}"); //2. Issuer Create and Open Wallet - Wallet.CreateWalletAsync(_poolName, "issuerWallet", "default", null, null).Wait(); - _issuerWallet = Wallet.OpenWalletAsync("issuerWallet", null, null).Result; + await Wallet.CreateWalletAsync(_poolName, "issuerWallet", "default", null, null); + _issuerWallet = await Wallet.OpenWalletAsync("issuerWallet", null, null); //3. Prover Create and Open Wallet - Wallet.CreateWalletAsync(_poolName, "proverWallet", "default", null, null).Wait(); - _proverWallet = Wallet.OpenWalletAsync("proverWallet", null, null).Result; + await Wallet.CreateWalletAsync(_poolName, "proverWallet", "default", null, null); + _proverWallet = await Wallet.OpenWalletAsync("proverWallet", null, null); } [TestCleanup] - public void DeleteWallet() + public async Task DeleteWallet() { - _issuerWallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync("issuerWallet", null).Wait(); + if(_issuerWallet != null) + await _issuerWallet.CloseAsync(); - _proverWallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync("proverWallet", null).Wait(); + await Wallet.DeleteWalletAsync("issuerWallet", null); - _pool.CloseAsync().Wait(); + if(_proverWallet != null) + await _proverWallet.CloseAsync(); + + await Wallet.DeleteWalletAsync("proverWallet", null); + + if(_pool != null) + await _pool.CloseAsync(); } [TestMethod] - public void TestAnonCredsDemo() + public async Task TestAnonCredsDemo() { //4. Issuer create ClaimDef var schemaJson = "{\n" + @@ -58,20 +63,20 @@ public void TestAnonCredsDemo() " }"; var issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; - var claimDef = AnonCreds.IssuerCreateAndStoreClaimDefAsync(_issuerWallet, issuerDid, schemaJson, null, false).Result; + var claimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(_issuerWallet, issuerDid, schemaJson, null, false); Assert.IsNotNull(claimDef); //5. Prover create Master Secret var masterSecret = "masterSecretName"; - AnonCreds.ProverCreateMasterSecretAsync(_proverWallet, masterSecret).Wait(); + await AnonCreds.ProverCreateMasterSecretAsync(_proverWallet, masterSecret); //6. Prover store Claim Offer var claimOffer = string.Format("{{\"issuer_did\":\"{0}\", \"schema_seq_no\":{1}}}", issuerDid, 1); - AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer).Wait(); + await AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer); //7. Prover get Claim Offers var claimOfferFilter = string.Format("{{\"issuer_did\":\"{0}\"}}", issuerDid); - var claimOffersJson = AnonCreds.ProverGetClaimOffersAsync(_proverWallet, claimOfferFilter).Result; + var claimOffersJson = await AnonCreds.ProverGetClaimOffersAsync(_proverWallet, claimOfferFilter); var claimOffersObject = JArray.Parse(claimOffersJson); Assert.AreEqual(claimOffersObject.Count, 1); @@ -81,7 +86,7 @@ public void TestAnonCredsDemo() //8. Prover create ClaimReq var proverDid = "BzfFCYk"; - var claimReq = AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, claimOfferJson, claimDef, masterSecret).Result; + var claimReq = await AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, claimOfferJson, claimDef, masterSecret); Assert.IsNotNull(claimReq); //9. Issuer create Claim @@ -92,12 +97,12 @@ public void TestAnonCredsDemo() " \"age\":[\"28\",\"28\"]\n" + " }"; - var createClaimResult = AnonCreds.IssuerCreateClaimAsync(_issuerWallet, claimReq, claimAttributesJson, -1, -1).Result; + var createClaimResult = await AnonCreds.IssuerCreateClaimAsync(_issuerWallet, claimReq, claimAttributesJson, -1, -1); Assert.IsNotNull(createClaimResult); var claimJson = createClaimResult.ClaimJson; //10. Prover store Claim - AnonCreds.ProverStoreClaimAsync(_proverWallet, claimJson).Wait(); + await AnonCreds.ProverStoreClaimAsync(_proverWallet, claimJson); //11. Prover gets Claims for Proof Request var proofRequestJson = "{\n" + @@ -109,7 +114,7 @@ public void TestAnonCredsDemo() " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}}\n" + " }"; - var claimsForProofJson = AnonCreds.ProverGetClaimsForProofReqAsync(_proverWallet, proofRequestJson).Result; + var claimsForProofJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_proverWallet, proofRequestJson); Assert.IsNotNull(claimsForProofJson); var claimsForProof = JObject.Parse(claimsForProofJson); @@ -137,8 +142,8 @@ public void TestAnonCredsDemo() var revocRegsJson = "{}"; - var proofJson = AnonCreds.ProverCreateProofAsync(_proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, - masterSecret, claimDefsJson, revocRegsJson).Result; + var proofJson = await AnonCreds.ProverCreateProofAsync(_proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, + masterSecret, claimDefsJson, revocRegsJson); Assert.IsNotNull(proofJson); var proof = JObject.Parse(proofJson); @@ -151,12 +156,12 @@ public void TestAnonCredsDemo() Assert.AreEqual(selfAttestedValue, proof["requested_proof"]["self_attested_attrs"].Value("self1")); - Boolean valid = AnonCreds.VerifierVerifyProofAsync(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson).Result; + Boolean valid = await AnonCreds.VerifierVerifyProofAsync(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson); Assert.IsTrue(valid); } [TestMethod] - public void TestAnonCredsWorksForMultipleIssuerSingleProver() + public async Task TestAnonCredsWorksForMultipleIssuerSingleProver() { var issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; var issuerDid2 = "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW"; @@ -164,8 +169,8 @@ public void TestAnonCredsWorksForMultipleIssuerSingleProver() var issuerGvtWallet = _issuerWallet; //1. Issuer2 Create and Open Wallet - Wallet.CreateWalletAsync(_poolName, "issuer2Wallet", "default", null, null).Wait(); - var issuerXyzWallet = Wallet.OpenWalletAsync("issuer2Wallet", null, null).Result; + await Wallet.CreateWalletAsync(_poolName, "issuer2Wallet", "default", null, null); + var issuerXyzWallet = await Wallet.OpenWalletAsync("issuer2Wallet", null, null); //2. Issuer create ClaimDef var gvtSchemaJson = "{\n" + @@ -177,7 +182,7 @@ public void TestAnonCredsWorksForMultipleIssuerSingleProver() " }\n" + " }"; - var gvtClaimDef = AnonCreds.IssuerCreateAndStoreClaimDefAsync(issuerGvtWallet, issuerDid, gvtSchemaJson, null, false).Result; + var gvtClaimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(issuerGvtWallet, issuerDid, gvtSchemaJson, null, false); //3. Issuer create ClaimDef var xyzSchemaJson = "{\n" + @@ -189,22 +194,22 @@ public void TestAnonCredsWorksForMultipleIssuerSingleProver() " }\n" + " }"; - var xyzClaimDef = AnonCreds.IssuerCreateAndStoreClaimDefAsync(issuerXyzWallet, issuerDid2, xyzSchemaJson, null, false).Result; + var xyzClaimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(issuerXyzWallet, issuerDid2, xyzSchemaJson, null, false); //4. Prover create Master Secret var masterSecret = "masterSecretName"; - AnonCreds.ProverCreateMasterSecretAsync(_proverWallet, masterSecret).Wait(); + await AnonCreds.ProverCreateMasterSecretAsync(_proverWallet, masterSecret); //5. Prover store Claim Offer received from Issuer1 var claimOffer = string.Format("{{\"issuer_did\":\"{0}\", \"schema_seq_no\":{1}}}", issuerDid, 1); - AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer).Wait(); + await AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer); //6. Prover store Claim Offer received from Issuer2 var claimOffer2 = string.Format("{{\"issuer_did\":\"{0}\", \"schema_seq_no\":{1}}}", issuerDid2, 2); - AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer2).Wait(); + await AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer2); //7. Prover get Claim Offers - var claimOffersJson = AnonCreds.ProverGetClaimOffersAsync(_proverWallet, "{}").Result; + var claimOffersJson = await AnonCreds.ProverGetClaimOffersAsync(_proverWallet, "{}"); var claimOffersObject = JArray.Parse(claimOffersJson); Assert.AreEqual(2, claimOffersObject.Count); @@ -218,7 +223,7 @@ public void TestAnonCredsWorksForMultipleIssuerSingleProver() //8. Prover create ClaimReq for GVT Claim Offer var proverDid = "BzfFCYk"; - var gvtClaimReq = AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, gvtClaimOffer, gvtClaimDef, masterSecret).Result; + var gvtClaimReq = await AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, gvtClaimOffer, gvtClaimDef, masterSecret); //9. Issuer create Claim var gvtClaimAttributesJson = "{\n" + @@ -228,14 +233,14 @@ public void TestAnonCredsWorksForMultipleIssuerSingleProver() " \"age\":[\"28\",\"28\"]\n" + " }"; - var gvtCreateClaimResult = AnonCreds.IssuerCreateClaimAsync(issuerGvtWallet, gvtClaimReq, gvtClaimAttributesJson, -1, -1).Result; + var gvtCreateClaimResult = await AnonCreds.IssuerCreateClaimAsync(issuerGvtWallet, gvtClaimReq, gvtClaimAttributesJson, -1, -1); var gvtClaimJson = gvtCreateClaimResult.ClaimJson; //10. Prover store Claim - AnonCreds.ProverStoreClaimAsync(_proverWallet, gvtClaimJson).Wait(); + await AnonCreds.ProverStoreClaimAsync(_proverWallet, gvtClaimJson); //11. Prover create ClaimReq for GVT Claim Offer - var xyzClaimReq = AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, xyzClaimOffer, xyzClaimDef, masterSecret).Result; + var xyzClaimReq = await AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, xyzClaimOffer, xyzClaimDef, masterSecret); //12. Issuer create Claim var xyzClaimAttributesJson = "{\n" + @@ -243,11 +248,11 @@ public void TestAnonCredsWorksForMultipleIssuerSingleProver() " \"period\":[\"8\",\"8\"]\n" + " }"; - var xyzCreateClaimResult = AnonCreds.IssuerCreateClaimAsync(issuerXyzWallet, xyzClaimReq, xyzClaimAttributesJson, -1, -1).Result; + var xyzCreateClaimResult = await AnonCreds.IssuerCreateClaimAsync(issuerXyzWallet, xyzClaimReq, xyzClaimAttributesJson, -1, -1); var xyzClaimJson = xyzCreateClaimResult.ClaimJson; //13. Prover store Claim - AnonCreds.ProverStoreClaimAsync(_proverWallet, xyzClaimJson).Wait(); + await AnonCreds.ProverStoreClaimAsync(_proverWallet, xyzClaimJson); //14. Prover gets Claims for Proof Request var proofRequestJson = "{\n" + @@ -261,7 +266,7 @@ public void TestAnonCredsWorksForMultipleIssuerSingleProver() " }"; - var claimsForProofJson = AnonCreds.ProverGetClaimsForProofReqAsync(_proverWallet, proofRequestJson).Result; + var claimsForProofJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_proverWallet, proofRequestJson); Assert.IsNotNull(claimsForProofJson); var claimsForProof = JObject.Parse(claimsForProofJson); @@ -294,8 +299,8 @@ public void TestAnonCredsWorksForMultipleIssuerSingleProver() var revocRegsJson = "{}"; - var proofJson = AnonCreds.ProverCreateProofAsync(_proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, - masterSecret, claimDefsJson, revocRegsJson).Result; + var proofJson = await AnonCreds.ProverCreateProofAsync(_proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, + masterSecret, claimDefsJson, revocRegsJson); Assert.IsNotNull(proofJson); var proof = JObject.Parse(proofJson); @@ -307,16 +312,16 @@ public void TestAnonCredsWorksForMultipleIssuerSingleProver() Assert.AreEqual("partial", proof["requested_proof"]["revealed_attrs"]["attr2_uuid"].Value(1)); - Boolean valid = AnonCreds.VerifierVerifyProofAsync(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson).Result; + Boolean valid = await AnonCreds.VerifierVerifyProofAsync(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson); Assert.IsTrue(valid); //18. Close and delete Issuer2 Wallet - issuerXyzWallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync("issuer2Wallet", null).Wait(); + await issuerXyzWallet.CloseAsync(); + await Wallet.DeleteWalletAsync("issuer2Wallet", null); } [TestMethod] - public void TestAnonCredsWorksForSingleIssuerSingleProverMultipleClaims() + public async Task TestAnonCredsWorksForSingleIssuerSingleProverMultipleClaims() { var issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; @@ -330,7 +335,7 @@ public void TestAnonCredsWorksForSingleIssuerSingleProverMultipleClaims() " }\n" + " }"; - var gvtClaimDef = AnonCreds.IssuerCreateAndStoreClaimDefAsync(_issuerWallet, issuerDid, gvtSchemaJson, null, false).Result; + var gvtClaimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(_issuerWallet, issuerDid, gvtSchemaJson, null, false); //2. Issuer create ClaimDef var xyzSchemaJson = "{\n" + @@ -342,22 +347,22 @@ public void TestAnonCredsWorksForSingleIssuerSingleProverMultipleClaims() " }\n" + " }"; - var xyzClaimDef = AnonCreds.IssuerCreateAndStoreClaimDefAsync(_issuerWallet, issuerDid, xyzSchemaJson, null, false).Result; + var xyzClaimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(_issuerWallet, issuerDid, xyzSchemaJson, null, false); //3. Prover create Master Secret var masterSecret = "masterSecretName"; - AnonCreds.ProverCreateMasterSecretAsync(_proverWallet, masterSecret).Wait(); + await AnonCreds.ProverCreateMasterSecretAsync(_proverWallet, masterSecret); //4. Prover store Claim Offer received from Issuer var claimOffer = string.Format("{{\"issuer_did\":\"{0}\", \"schema_seq_no\":{1}}}", issuerDid, 1); - AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer).Wait(); + await AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer); //5. Prover store Claim Offer received from Issuer var claimOffer2 = string.Format("{{\"issuer_did\":\"{0}\", \"schema_seq_no\":{1}}}", issuerDid, 2); - AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer2).Wait(); + await AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer2); //6. Prover get Claim Offers - var claimOffersJson = AnonCreds.ProverGetClaimOffersAsync(_proverWallet, "{}").Result; + var claimOffersJson = await AnonCreds.ProverGetClaimOffersAsync(_proverWallet, "{}"); var claimOffersObject = JArray.Parse(claimOffersJson); Assert.AreEqual(2, claimOffersObject.Count); @@ -371,7 +376,7 @@ public void TestAnonCredsWorksForSingleIssuerSingleProverMultipleClaims() //7. Prover create ClaimReq for GVT Claim Offer var proverDid = "BzfFCYk"; - var gvtClaimReq = AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, gvtClaimOffer, gvtClaimDef, masterSecret).Result; + var gvtClaimReq = await AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, gvtClaimOffer, gvtClaimDef, masterSecret); //8. Issuer create Claim var gvtClaimAttributesJson = "{\n" + @@ -381,14 +386,14 @@ public void TestAnonCredsWorksForSingleIssuerSingleProverMultipleClaims() " \"age\":[\"28\",\"28\"]\n" + " }"; - var gvtCreateClaimResult = AnonCreds.IssuerCreateClaimAsync(_issuerWallet, gvtClaimReq, gvtClaimAttributesJson, -1, -1).Result; + var gvtCreateClaimResult = await AnonCreds.IssuerCreateClaimAsync(_issuerWallet, gvtClaimReq, gvtClaimAttributesJson, -1, -1); var gvtClaimJson = gvtCreateClaimResult.ClaimJson; //9. Prover store Claim - AnonCreds.ProverStoreClaimAsync(_proverWallet, gvtClaimJson).Wait(); + await AnonCreds.ProverStoreClaimAsync(_proverWallet, gvtClaimJson); //10. Prover create ClaimReq for GVT Claim Offer - var xyzClaimReq = AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, xyzClaimOffer, xyzClaimDef, masterSecret).Result; + var xyzClaimReq = await AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, xyzClaimOffer, xyzClaimDef, masterSecret); //11. Issuer create Claim var xyzClaimAttributesJson = "{\n" + @@ -396,11 +401,11 @@ public void TestAnonCredsWorksForSingleIssuerSingleProverMultipleClaims() " \"period\":[\"8\",\"8\"]\n" + " }"; - var xyzCreateClaimResult = AnonCreds.IssuerCreateClaimAsync(_issuerWallet, xyzClaimReq, xyzClaimAttributesJson, -1, -1).Result; + var xyzCreateClaimResult = await AnonCreds.IssuerCreateClaimAsync(_issuerWallet, xyzClaimReq, xyzClaimAttributesJson, -1, -1); var xyzClaimJson = xyzCreateClaimResult.ClaimJson; //12. Prover store Claim - AnonCreds.ProverStoreClaimAsync(_proverWallet, xyzClaimJson).Wait(); + await AnonCreds.ProverStoreClaimAsync(_proverWallet, xyzClaimJson); //13. Prover gets Claims for Proof Request var proofRequestJson = "{\n" + @@ -413,7 +418,7 @@ public void TestAnonCredsWorksForSingleIssuerSingleProverMultipleClaims() " }"; - var claimsForProofJson = AnonCreds.ProverGetClaimsForProofReqAsync(_proverWallet, proofRequestJson).Result; + var claimsForProofJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_proverWallet, proofRequestJson); Assert.IsNotNull(claimsForProofJson); var claimsForProof = JObject.Parse(claimsForProofJson); @@ -442,8 +447,8 @@ public void TestAnonCredsWorksForSingleIssuerSingleProverMultipleClaims() var revocRegsJson = "{}"; - var proofJson = AnonCreds.ProverCreateProofAsync(_proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, - masterSecret, claimDefsJson, revocRegsJson).Result; + var proofJson = await AnonCreds.ProverCreateProofAsync(_proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, + masterSecret, claimDefsJson, revocRegsJson); Assert.IsNotNull(proofJson); var proof = JObject.Parse(proofJson); @@ -452,7 +457,7 @@ public void TestAnonCredsWorksForSingleIssuerSingleProverMultipleClaims() Assert.AreEqual("Alex", proof["requested_proof"]["revealed_attrs"]["attr1_uuid"][1]); - Boolean valid = AnonCreds.VerifierVerifyProofAsync(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson).Result; + var valid = await AnonCreds.VerifierVerifyProofAsync(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson); Assert.IsTrue(valid); } @@ -470,21 +475,21 @@ public async Task TestVerifyProofWorksForProofDoesNotCorrespondToProofRequest() " }"; var issuerDid = "NcYxiDXkpYi6ov5FcYDi1e"; - var claimDef = AnonCreds.IssuerCreateAndStoreClaimDefAsync(_issuerWallet, issuerDid, schemaJson, null, false).Result; + var claimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(_issuerWallet, issuerDid, schemaJson, null, false); Assert.IsNotNull(claimDef); //2. Prover create Master Secret var masterSecret = "masterSecretName"; - AnonCreds.ProverCreateMasterSecretAsync(_proverWallet, masterSecret).Wait(); + await AnonCreds.ProverCreateMasterSecretAsync(_proverWallet, masterSecret); //3. Prover store Claim Offer var claimOffer = string.Format("{{\"issuer_did\":\"{0}\", \"schema_seq_no\":{1}}}", issuerDid, 1); - AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer).Wait(); + await AnonCreds.ProverStoreClaimOfferAsync(_proverWallet, claimOffer); //4. Prover get Claim Offers var claimOfferFilter = string.Format("{{\"issuer_did\":\"{0}\"}}", issuerDid); - var claimOffersJson = AnonCreds.ProverGetClaimOffersAsync(_proverWallet, claimOfferFilter).Result; + var claimOffersJson = await AnonCreds.ProverGetClaimOffersAsync(_proverWallet, claimOfferFilter); var claimOffersObject = JArray.Parse(claimOffersJson); @@ -495,7 +500,7 @@ public async Task TestVerifyProofWorksForProofDoesNotCorrespondToProofRequest() //5. Prover create ClaimReq var proverDid = "BzfFCYk"; - var claimReq = AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, claimOfferJson, claimDef, masterSecret).Result; + var claimReq = await AnonCreds.ProverCreateAndStoreClaimReqAsync(_proverWallet, proverDid, claimOfferJson, claimDef, masterSecret); Assert.IsNotNull(claimReq); @@ -507,13 +512,13 @@ public async Task TestVerifyProofWorksForProofDoesNotCorrespondToProofRequest() " \"age\":[\"28\",\"28\"]\n" + " }"; - var createClaimResult = AnonCreds.IssuerCreateClaimAsync(_issuerWallet, claimReq, claimAttributesJson, -1, -1).Result; + var createClaimResult = await AnonCreds.IssuerCreateClaimAsync(_issuerWallet, claimReq, claimAttributesJson, -1, -1); Assert.IsNotNull(createClaimResult); var claimJson = createClaimResult.ClaimJson; //7. Prover store Claim - AnonCreds.ProverStoreClaimAsync(_proverWallet, claimJson).Wait(); + await AnonCreds.ProverStoreClaimAsync(_proverWallet, claimJson); //8. Prover gets Claims for Proof Request var proofRequestJson = "{\n" + @@ -524,7 +529,7 @@ public async Task TestVerifyProofWorksForProofDoesNotCorrespondToProofRequest() " \"requested_predicates\":{}\n" + " }"; - var claimsForProofJson = AnonCreds.ProverGetClaimsForProofReqAsync(_proverWallet, proofRequestJson).Result; + var claimsForProofJson = await AnonCreds.ProverGetClaimsForProofReqAsync(_proverWallet, proofRequestJson); Assert.IsNotNull(claimsForProofJson); @@ -541,17 +546,16 @@ public async Task TestVerifyProofWorksForProofDoesNotCorrespondToProofRequest() var requestedClaimsJson = string.Format("{{\n" + " \"self_attested_attributes\":{{\"self1\":\"{0}\"}},\n" + " \"requested_attrs\":{{\"attr1_uuid\":[\"{1}\", true],\n" + - " \"attr2_uuid\":[\"{2}\", false]}},\n" + - " \"requested_predicates\":{{\"predicate1_uuid\":\"{3}\"}}\n" + - " }}", selfAttestedValue, claimUuid, claimUuid, claimUuid); + " \"requested_predicates\":{{}}\n" + + " }}", selfAttestedValue, claimUuid); var schemasJson = string.Format("{{\"{0}\":{1}}}", claimUuid, schemaJson); var claimDefsJson = string.Format("{{\"{0}\":{1}}}", claimUuid, claimDef); var revocRegsJson = "{}"; //TODO: Not sure why this call is failing... - var proofJson = AnonCreds.ProverCreateProofAsync(_proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, - masterSecret, claimDefsJson, revocRegsJson).Result; + var proofJson = await AnonCreds.ProverCreateProofAsync(_proverWallet, proofRequestJson, requestedClaimsJson, schemasJson, + masterSecret, claimDefsJson, revocRegsJson); Assert.IsNotNull(proofJson); @@ -562,9 +566,6 @@ public async Task TestVerifyProofWorksForProofDoesNotCorrespondToProofRequest() proof["requested_proof"]["revealed_attrs"]["attr1_uuid"][1]); - Assert.IsNotNull(proof["requested_proof"]["unrevealed_attrs"]["attr2_uuid"]); - - Assert.AreEqual(selfAttestedValue, proof["requested_proof"]["self_attested_attrs"].Value("self1")); proofRequestJson = "{\n" + @@ -572,14 +573,14 @@ public async Task TestVerifyProofWorksForProofDoesNotCorrespondToProofRequest() " \"name\":\"proof_req_1\",\n" + " \"version\":\"0.1\",\n" + " \"requested_attrs\":{\"attr1_uuid\":{\"schema_seq_no\":1,\"name\":\"name\"}},\n" + - " \"requested_predicates\":{}\n" + + " \"requested_predicates\":{\"predicate1_uuid\":{\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}\n" + " }"; var ex = await Assert.ThrowsExceptionAsync(() => AnonCreds.VerifierVerifyProofAsync(proofRequestJson, proofJson, schemasJson, claimDefsJson, revocRegsJson) - ); + ); Assert.AreEqual(ErrorCode.CommonInvalidStructure, ex.ErrorCode); - } + } } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/LedgerDemoTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/LedgerDemoTest.cs index 3dd590803e..2b14058b53 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/LedgerDemoTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/LedgerDemoTest.cs @@ -1,6 +1,7 @@ using Indy.Sdk.Dotnet.Wrapper; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json.Linq; +using System.Threading.Tasks; namespace Indy.Sdk.Dotnet.Test.Wrapper.DemoTests { @@ -8,23 +9,23 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.DemoTests public class LedgerDemoTest : IndyIntegrationTestBase { [TestMethod] - public void TestLedgerDemo() + public async Task TestLedgerDemo() { // 1. Create ledger config from genesis txn file var poolName = PoolUtils.CreatePoolLedgerConfig(); - var pool = Pool.OpenPoolLedgerAsync(poolName, "{}").Result; + var pool = await Pool.OpenPoolLedgerAsync(poolName, "{}"); // 2. Create and Open My Wallet - Wallet.CreateWalletAsync(poolName, "myWallet", "default", null, null).Wait(); - var myWallet = Wallet.OpenWalletAsync("myWallet", null, null).Result; + await Wallet.CreateWalletAsync(poolName, "myWallet", "default", null, null); + var myWallet = await Wallet.OpenWalletAsync("myWallet", null, null); // 3. Create and Open Trustee Wallet - Wallet.CreateWalletAsync(poolName, "theirWallet", "default", null, null).Wait(); - var trusteeWallet = Wallet.OpenWalletAsync("theirWallet", null, null).Result; + await Wallet.CreateWalletAsync(poolName, "theirWallet", "default", null, null); + var trusteeWallet = await Wallet.OpenWalletAsync("theirWallet", null, null); // 4. Create My Did - var createMyDidResult = Signus.CreateAndStoreMyDidAsync(myWallet, "{}").Result; + var createMyDidResult = await Signus.CreateAndStoreMyDidAsync(myWallet, "{}"); Assert.IsNotNull(createMyDidResult); var myDid = createMyDidResult.Did; var myVerkey = createMyDidResult.VerKey; @@ -32,16 +33,16 @@ public void TestLedgerDemo() // 5. Create Did from Trustee1 seed var theirDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var createTheirDidResult = Signus.CreateAndStoreMyDidAsync(trusteeWallet, theirDidJson).Result; + var createTheirDidResult = await Signus.CreateAndStoreMyDidAsync(trusteeWallet, theirDidJson); Assert.IsNotNull(createTheirDidResult); var trusteeDid = createTheirDidResult.Did; // 6. Build Nym Request - var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerkey, null, null).Result; + var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerkey, null, null); Assert.IsNotNull(nymRequest); // 7. Trustee Sign Nym Request - var nymResponseJson = Ledger.SignAndSubmitRequestAsync(pool, trusteeWallet, trusteeDid, nymRequest).Result; + var nymResponseJson = await Ledger.SignAndSubmitRequestAsync(pool, trusteeWallet, trusteeDid, nymRequest); Assert.IsNotNull(nymResponseJson); var nymResponse = JObject.Parse(nymResponseJson); @@ -50,15 +51,15 @@ public void TestLedgerDemo() Assert.AreEqual(myVerkey, nymResponse["result"].Value("verkey")); // 8. Close and delete My Wallet - myWallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync("myWallet", null).Wait(); + await myWallet.CloseAsync(); + await Wallet.DeleteWalletAsync("myWallet", null); // 9. Close and delete Their Wallet - trusteeWallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync("theirWallet", null).Wait(); + await trusteeWallet.CloseAsync(); + await Wallet.DeleteWalletAsync("theirWallet", null); // 10. Close Pool - pool.CloseAsync().Wait(); + await pool.CloseAsync(); } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/SignusDemoTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/SignusDemoTest.cs index 4fe269b9eb..b6c1b075fc 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/SignusDemoTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/DemoTests/SignusDemoTest.cs @@ -2,6 +2,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; +using System.Text; +using System.Threading.Tasks; namespace Indy.Sdk.Dotnet.Test.Wrapper.DemoTests { @@ -9,62 +11,62 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.DemoTests public class SignusDemoTest : IndyIntegrationTestBase { [TestMethod] - public void TestSignusDemo() + public async Task TestSignusDemo() { //1. Create and Open Pool var poolName = PoolUtils.CreatePoolLedgerConfig(); - var pool = Pool.OpenPoolLedgerAsync(poolName, "{}").Result; + var pool = await Pool.OpenPoolLedgerAsync(poolName, "{}"); //2. Create and Open My Wallet - Wallet.CreateWalletAsync(poolName, "myWallet", "default", null, null).Wait(); - var myWallet = Wallet.OpenWalletAsync("myWallet", null, null).Result; + await Wallet.CreateWalletAsync(poolName, "myWallet", "default", null, null); + var myWallet = await Wallet.OpenWalletAsync("myWallet", null, null); // 3. Create and Open Trustee Wallet - Wallet.CreateWalletAsync(poolName, "theirWallet", "default", null, null).Wait(); - var theirWallet = Wallet.OpenWalletAsync("theirWallet", null, null).Result; + await Wallet.CreateWalletAsync(poolName, "theirWallet", "default", null, null); + var theirWallet = await Wallet.OpenWalletAsync("theirWallet", null, null); //4. Create My Did - var createMyDidResult = Signus.CreateAndStoreMyDidAsync(myWallet, "{}").Result; + var createMyDidResult = await Signus.CreateAndStoreMyDidAsync(myWallet, "{}"); Assert.IsNotNull(createMyDidResult); //5. Create Their Did - var createTheirDidResult = Signus.CreateAndStoreMyDidAsync(theirWallet, "{}").Result; + var createTheirDidResult = await Signus.CreateAndStoreMyDidAsync(theirWallet, "{}"); Assert.IsNotNull(createTheirDidResult); var theirDid = createTheirDidResult.Did; var theirVerkey = createTheirDidResult.VerKey; // 6. Store Their DID var identityJson = string.Format("{{\"did\":\"{0}\", \"verkey\":\"{1}\"}}", theirDid, theirVerkey); - Signus.StoreTheirDidAsync(myWallet, identityJson).Wait(); + await Signus.StoreTheirDidAsync(myWallet, identityJson); // 7. Their sign message - var msg = "{\n" + + var msgBytes = Encoding.UTF8.GetBytes("{\n" + " \"reqId\":1495034346617224651,\n" + " \"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\",\n" + " \"operation\":{\n" + " \"type\":\"1\",\n" + " \"dest\":\"4efZu2SXufS556yss7W5k6Po37jt4371RM4whbPKBKdB\"\n" + " }\n" + - " }"; + " }"); - var signedMessage = Signus.SignAsync(theirWallet, theirDid, msg).Result; - Assert.IsNotNull(signedMessage); + var signatureBytes = await Signus.SignAsync(theirWallet, theirDid, msgBytes); + Assert.IsNotNull(signatureBytes); // 8. I verify message - Boolean valid = Signus.VerifySignatureAsync(myWallet, pool, theirDid, signedMessage).Result; + Boolean valid = await Signus.VerifySignatureAsync(myWallet, pool, theirDid, msgBytes, signatureBytes); Assert.IsTrue(valid); // 9. Close and delete My Wallet - myWallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync("myWallet", null).Wait(); + await myWallet.CloseAsync(); + await Wallet.DeleteWalletAsync("myWallet", null); // 10. Close and delete Their Wallet - theirWallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync("theirWallet", null).Wait(); + await theirWallet.CloseAsync(); + await Wallet.DeleteWalletAsync("theirWallet", null); //11. Close Pool - pool.CloseAsync().Wait(); + await pool.CloseAsync(); } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/AttribRequestTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/AttribRequestTest.cs index 7e6b429e89..49d80ae754 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/AttribRequestTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/AttribRequestTest.cs @@ -17,25 +17,29 @@ public class AttribRequestTest : IndyIntegrationTestBase [TestInitialize] - public void OpenPool() + public async Task OpenPool() { string poolName = PoolUtils.CreatePoolLedgerConfig(); - _pool = Pool.OpenPoolLedgerAsync(poolName, null).Result; + _pool = await Pool.OpenPoolLedgerAsync(poolName, null); - Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; + await Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); } [TestCleanup] - public void ClosePool() + public async Task ClosePool() { - _pool.CloseAsync().Wait(); - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); + if(_pool != null) + await _pool.CloseAsync(); + + if(_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); } [TestMethod] - public void TestBuildAttribRequestWorksForRawData() + public async Task TestBuildAttribRequestWorksForRawData() { string expectedResult = string.Format("\"identifier\":\"{0}\"," + "\"operation\":{{" + @@ -44,7 +48,7 @@ public void TestBuildAttribRequestWorksForRawData() "\"raw\":\"{2}\"" + "}}", _identifier, _dest, _endpoint); - string attribRequest = Ledger.BuildAttribRequestAsync(_identifier, _dest, null, _endpoint, null).Result; + string attribRequest = await Ledger.BuildAttribRequestAsync(_identifier, _dest, null, _endpoint, null); Assert.IsTrue(attribRequest.Replace("\\", "").Contains(expectedResult)); } @@ -60,7 +64,7 @@ public async Task TestBuildAttribRequestWorksForMissedAttribute() } [TestMethod] - public void TestBuildGetAttribRequestWorks() + public async Task TestBuildGetAttribRequestWorks() { string raw = "endpoint"; @@ -71,7 +75,7 @@ public void TestBuildGetAttribRequestWorks() "\"raw\":\"{2}\"" + "}}", _identifier, _dest, raw); - string attribRequest = Ledger.BuildGetAttribRequestAsync(_identifier, _dest, raw).Result; + string attribRequest = await Ledger.BuildGetAttribRequestAsync(_identifier, _dest, raw); Assert.IsTrue(attribRequest.Contains(expectedResult)); } @@ -81,10 +85,10 @@ public async Task TestSendAttribRequestWorksWithoutSignature() { var json = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, json).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, json); var trusteeDid = trusteeDidResult.Did; - var attribRequest = Ledger.BuildAttribRequestAsync(trusteeDid, trusteeDid, null, _endpoint, null).Result; + var attribRequest = await Ledger.BuildAttribRequestAsync(trusteeDid, trusteeDid, null, _endpoint, null); var ex = await Assert.ThrowsExceptionAsync(() => Ledger.SubmitRequestAsync(_pool, attribRequest) @@ -94,25 +98,25 @@ public async Task TestSendAttribRequestWorksWithoutSignature() } [TestMethod] - public void TestAttribRequestWorks() + public async Task TestAttribRequestWorks() { var trusteeJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, trusteeJson).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeJson); var trusteeDid = trusteeDidResult.Did; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); var myDid = myDidResult.Did; var myVerkey = myDidResult.VerKey; - var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerkey, null, null).Result; - Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest).Wait(); + var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerkey, null, null); + await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest); - var attribRequest = Ledger.BuildAttribRequestAsync(myDid, myDid, null, _endpoint, null).Result; - Ledger.SignAndSubmitRequestAsync(_pool, _wallet, myDid, attribRequest).Wait(); + var attribRequest = await Ledger.BuildAttribRequestAsync(myDid, myDid, null, _endpoint, null); + await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, myDid, attribRequest); - var getAttribRequest = Ledger.BuildGetAttribRequestAsync(myDid, myDid, "endpoint").Result; - var getAttribResponse = Ledger.SubmitRequestAsync(_pool, getAttribRequest).Result; + var getAttribRequest = await Ledger.BuildGetAttribRequestAsync(myDid, myDid, "endpoint"); + var getAttribResponse = await Ledger.SubmitRequestAsync(_pool, getAttribRequest); var jsonObject = JObject.Parse(getAttribResponse); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/ClaimDefRequestTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/ClaimDefRequestTest.cs index a77ef98468..a284fe1774 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/ClaimDefRequestTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/ClaimDefRequestTest.cs @@ -38,45 +38,52 @@ public class ClaimDefRequestTest : IndyIntegrationTestBase private string _signature_type = "CL"; [TestInitialize] - public void OpenPool() + public async Task OpenPool() { string poolName = PoolUtils.CreatePoolLedgerConfig(); - _pool = Pool.OpenPoolLedgerAsync(poolName, null).Result; + _pool = await Pool.OpenPoolLedgerAsync(poolName, null); - Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; + await Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); } [TestCleanup] - public void ClosePool() + public async Task ClosePool() { - _pool.CloseAsync().Wait(); - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); + if (_pool != null) + await _pool.CloseAsync(); + + if(_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); } [TestMethod] - public void TestBuildClaimDefRequestWorks() + public async Task TestBuildClaimDefRequestWorks() { var schema_seq_no = 1; - var data = "{\"primary\":{\"n\":\"1\",\"s\":\"2\",\"rms\":\"3\",\"r\":{\"name\":\"1\"},\"rctxt\":\"1\",\"z\":\"1\"}}"; + var dataTemplate = "{{\"primary\":{{\"n\":\"1\",\"s\":\"2\",\"rms\":\"3\",\"r\":{{\"name\":\"1\"}},\"rctxt\":\"1\",\"z\":\"1\"}}{0}}}"; + var data = string.Format(dataTemplate, string.Empty); + + var expectedData = string.Format(dataTemplate, ",\"revocation\":{}"); var expectedResult = string.Format("\"identifier\":\"{0}\"," + "\"operation\":{{" + "\"ref\":{1}," + - "\"data\":\"{2}\"," + + "\"data\":{2}," + "\"type\":\"102\"," + "\"signature_type\":\"{3}\"" + - "}}", _identifier, schema_seq_no, data, _signature_type); + "}}", _identifier, schema_seq_no, expectedData, _signature_type); - var claimDefRequest = Ledger.BuildClaimDefTxnAsync(_identifier, schema_seq_no, _signature_type, data).Result; + var claimDefRequest = await Ledger.BuildClaimDefTxnAsync(_identifier, schema_seq_no, _signature_type, data); Assert.IsTrue(claimDefRequest.Replace("\\", "").Contains(expectedResult)); } [TestMethod] - public void TestBuildGetClaimDefRequestWorks() + public async Task TestBuildGetClaimDefRequestWorks() { var reference = 1; @@ -88,7 +95,7 @@ public void TestBuildGetClaimDefRequestWorks() "\"origin\":\"{3}\"" + "}}", _identifier, reference, _signature_type, _identifier); - var getClaimDefRequest = Ledger.BuildGetClaimDefTxnAsync(_identifier, reference, _signature_type, _identifier).Result; + var getClaimDefRequest = await Ledger.BuildGetClaimDefTxnAsync(_identifier, reference, _signature_type, _identifier); Assert.IsTrue(getClaimDefRequest.Replace("\\", "").Contains(expectedResult)); @@ -108,30 +115,30 @@ public async Task TestBuildClaimDefRequestWorksForInvalidJson() } [TestMethod] - public void TestClaimDefRequestWorks() + public async Task TestClaimDefRequestWorks() { var trusteeJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, trusteeJson).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeJson); var trusteeDid = trusteeDidResult.Did; var myJson = "{}"; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, myJson).Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, myJson); var myDid = myDidResult.Did; var myVerkey = myDidResult.VerKey; - var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerkey, null, null).Result; - Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest).Wait(); + var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerkey, null, null); + await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest); - var schemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\",\"keys\": [\"name\", \"male\"]}"; + var schemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\",\"attr_names\": [\"name\", \"male\"]}"; - var schemaRequest = Ledger.BuildSchemaRequestAsync(myDid, schemaData).Result; - Ledger.SignAndSubmitRequestAsync(_pool, _wallet, myDid, schemaRequest).Wait(); + var schemaRequest = await Ledger.BuildSchemaRequestAsync(myDid, schemaData); + await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, myDid, schemaRequest); var getSchemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\"}"; - var getSchemaRequest = Ledger.BuildGetSchemaRequestAsync(myDid, myDid, getSchemaData).Result; - var getSchemaResponse = Ledger.SubmitRequestAsync(_pool, getSchemaRequest).Result; + var getSchemaRequest = await Ledger.BuildGetSchemaRequestAsync(myDid, myDid, getSchemaData); + var getSchemaResponse = await Ledger.SubmitRequestAsync(_pool, getSchemaRequest); var schemaObj = JObject.Parse(getSchemaResponse); @@ -143,11 +150,11 @@ public void TestClaimDefRequestWorks() var claimDefJson = claimDefObj["data"]; - var claimDefRequest = Ledger.BuildClaimDefTxnAsync(myDid, schemaSeqNo, _signatureType, claimDefObj["data"].ToString()).Result; - var claimDefResponse = Ledger.SignAndSubmitRequestAsync(_pool, _wallet, myDid, claimDefRequest).Result; + var claimDefRequest = await Ledger.BuildClaimDefTxnAsync(myDid, schemaSeqNo, _signatureType, claimDefObj["data"].ToString()); + var claimDefResponse = await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, myDid, claimDefRequest); - var getClaimDefRequest = Ledger.BuildGetClaimDefTxnAsync(myDid, schemaSeqNo, _signatureType, claimDefObj["origin"].ToString()).Result; - var getClaimDefResponse = Ledger.SubmitRequestAsync(_pool, getClaimDefRequest).Result; + var getClaimDefRequest = await Ledger.BuildGetClaimDefTxnAsync(myDid, schemaSeqNo, _signatureType, claimDefObj["origin"].ToString()); + var getClaimDefResponse = await Ledger.SubmitRequestAsync(_pool, getClaimDefRequest); var getClaimDefResponseObj = JObject.Parse(getClaimDefResponse); @@ -177,22 +184,22 @@ public async Task TestClaimDefRequestWorksWithoutSignature() { var trusteeJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, trusteeJson).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeJson); var trusteeDid = trusteeDidResult.Did; var myJson = "{}"; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, myJson).Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, myJson); var myDid = myDidResult.Did; var myVerkey = myDidResult.VerKey; - var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerkey, null, null).Result; - Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest).Wait(); + var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerkey, null, null); + await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest); - var schemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\",\"keys\": [\"name\", \"male\"]}"; + var schemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\",\"attr_names\": [\"name\", \"male\"]}"; - var schemaRequest = Ledger.BuildSchemaRequestAsync(myDid, schemaData).Result; - var schemaResponse = Ledger.SignAndSubmitRequestAsync(_pool, _wallet, myDid, schemaRequest).Result; + var schemaRequest = await Ledger.BuildSchemaRequestAsync(myDid, schemaData); + var schemaResponse = await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, myDid, schemaRequest); var schemaObj = JObject.Parse(schemaResponse); @@ -204,7 +211,7 @@ public async Task TestClaimDefRequestWorksWithoutSignature() var claimDefJson = claimDefObj["data"].ToString(); - var claimDefRequest = Ledger.BuildClaimDefTxnAsync(myDid, schemaSeqNo, _signatureType, claimDefJson).Result; + var claimDefRequest = await Ledger.BuildClaimDefTxnAsync(myDid, schemaSeqNo, _signatureType, claimDefJson); var ex = await Assert.ThrowsExceptionAsync(() => Ledger.SubmitRequestAsync(_pool, claimDefRequest) diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/GetTxnRequestTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/GetTxnRequestTest.cs index e174ece23e..4d6bbd475a 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/GetTxnRequestTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/GetTxnRequestTest.cs @@ -1,6 +1,7 @@ using Indy.Sdk.Dotnet.Wrapper; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json.Linq; +using System.Threading.Tasks; namespace Indy.Sdk.Dotnet.Test.Wrapper.LedgerTests { @@ -12,25 +13,29 @@ public class GetTxnRequestTest : IndyIntegrationTestBase private string _walletName = "ledgerWallet"; [TestInitialize] - public void OpenPool() + public async Task OpenPool() { string poolName = PoolUtils.CreatePoolLedgerConfig(); - _pool = Pool.OpenPoolLedgerAsync(poolName, null).Result; + _pool = await Pool.OpenPoolLedgerAsync(poolName, null); - Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; + await Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); } [TestCleanup] - public void ClosePool() + public async Task ClosePool() { - _pool.CloseAsync().Wait(); - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); + if (_pool != null) + await _pool.CloseAsync(); + + if (_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); } [TestMethod] - public void TestBuildGetTxnRequestWorks() + public async Task TestBuildGetTxnRequestWorks() { var identifier = "Th7MpTaRZVRYnPiabds81Y"; var data = 1; @@ -41,58 +46,58 @@ public void TestBuildGetTxnRequestWorks() "\"data\":{1}" + "}}", identifier, data); - var getTxnRequest = Ledger.BuildGetTxnRequestAsync(identifier, data).Result; + var getTxnRequest = await Ledger.BuildGetTxnRequestAsync(identifier, data); Assert.IsTrue(getTxnRequest.Replace("\\", "").Contains(expectedResult)); } [TestMethod] //This test fails here and in the Java version. - public void TestGetTxnRequestWorks() + public async Task TestGetTxnRequestWorks() { var didJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var didResult = Signus.CreateAndStoreMyDidAsync(_wallet, didJson).Result; + var didResult = await Signus.CreateAndStoreMyDidAsync(_wallet, didJson); var did = didResult.Did; - var schemaData = "{\"name\":\"gvt2\",\"version\":\"3.0\",\"keys\": [\"name\", \"male\"]}"; + var schemaData = "{\"name\":\"gvt2\",\"version\":\"3.0\",\"attr_names\": [\"name\", \"male\"]}"; - var schemaRequest = Ledger.BuildSchemaRequestAsync(did, schemaData).Result; - var schemaResponse = Ledger.SignAndSubmitRequestAsync(_pool, _wallet, did, schemaRequest).Result; + var schemaRequest = await Ledger.BuildSchemaRequestAsync(did, schemaData); + var schemaResponse = await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, did, schemaRequest); var schemaResponseObj = JObject.Parse(schemaResponse); var seqNo = schemaResponseObj["result"].Value("seqNo"); - var getTxnRequest = Ledger.BuildGetTxnRequestAsync(did, seqNo).Result; - var getTxnResponse = Ledger.SubmitRequestAsync(_pool, getTxnRequest).Result; + var getTxnRequest = await Ledger.BuildGetTxnRequestAsync(did, seqNo); + var getTxnResponse = await Ledger.SubmitRequestAsync(_pool, getTxnRequest); var getTxnResponseObj = JObject.Parse(getTxnResponse); - var schemaTransaction = getTxnResponseObj["result"].Value("data"); - var schemaTransactionObj = JObject.Parse(schemaTransaction); + var returnedSchemaData = getTxnResponseObj["result"]["data"]["data"]; + var expectedSchemaData = JToken.Parse(schemaData); - Assert.AreEqual(schemaData, schemaTransactionObj.Value("data")); + Assert.IsTrue(JToken.DeepEquals(expectedSchemaData, returnedSchemaData)); } [TestMethod] - public void TestGetTxnRequestWorksForInvalidSeqNo() + public async Task TestGetTxnRequestWorksForInvalidSeqNo() { var didJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var didResult = Signus.CreateAndStoreMyDidAsync(_wallet, didJson).Result; + var didResult = await Signus.CreateAndStoreMyDidAsync(_wallet, didJson); var did = didResult.Did; - var schemaData = "{\"name\":\"gvt2\",\"version\":\"3.0\",\"keys\": [\"name\", \"male\"]}"; + var schemaData = "{\"name\":\"gvt2\",\"version\":\"3.0\",\"attr_names\": [\"name\", \"male\"]}"; - var schemaRequest = Ledger.BuildSchemaRequestAsync(did, schemaData).Result; - var schemaResponse = Ledger.SignAndSubmitRequestAsync(_pool, _wallet, did, schemaRequest).Result; + var schemaRequest = await Ledger.BuildSchemaRequestAsync(did, schemaData); + var schemaResponse = await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, did, schemaRequest); var schemaResponseObj = JObject.Parse(schemaResponse); var seqNo = (int)schemaResponseObj["result"]["seqNo"] + 1; - var getTxnRequest = Ledger.BuildGetTxnRequestAsync(did, seqNo).Result; - var getTxnResponse = Ledger.SubmitRequestAsync(_pool, getTxnRequest).Result; + var getTxnRequest = await Ledger.BuildGetTxnRequestAsync(did, seqNo); + var getTxnResponse = await Ledger.SubmitRequestAsync(_pool, getTxnRequest); var getTxnResponseObj = JObject.Parse(getTxnResponse); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/NodeRequestTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/NodeRequestTest.cs index ece3c4e794..b86ad0c951 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/NodeRequestTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/NodeRequestTest.cs @@ -14,25 +14,29 @@ public class NodeRequestTest : IndyIntegrationTestBase private string _dest = "Th7MpTaRZVRYnPiabds81Y"; [TestInitialize] - public void OpenPool() + public async Task OpenPool() { string poolName = PoolUtils.CreatePoolLedgerConfig(); - _pool = Pool.OpenPoolLedgerAsync(poolName, null).Result; + _pool = await Pool.OpenPoolLedgerAsync(poolName, null); - Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; + await Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); } [TestCleanup] - public void ClosePool() + public async Task ClosePool() { - _pool.CloseAsync().Wait(); - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); + if (_pool != null) + await _pool.CloseAsync(); + + if (_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); } [TestMethod] - public void TestBuildNodeRequestWorks() + public async Task TestBuildNodeRequestWorks() { var data = "{\"node_ip\":\"10.0.0.100\"," + "\"node_port\":910," + @@ -48,7 +52,7 @@ public void TestBuildNodeRequestWorks() "\"data\":{2}" + "}}", _identifier, _dest, data); - var nodeRequest = Ledger.BuildNodeRequestAsync(_identifier, _dest, data).Result; + var nodeRequest = await Ledger.BuildNodeRequestAsync(_identifier, _dest, data); Assert.IsTrue(nodeRequest.Replace("\\", "").Contains(expectedResult)); } @@ -57,7 +61,7 @@ public void TestBuildNodeRequestWorks() public async Task TestSendNodeRequestWorksWithoutSignature() { var didJson = "{\"seed\":\"000000000000000000000000Steward1\"}"; - var didResult = Signus.CreateAndStoreMyDidAsync(_wallet, didJson).Result; + var didResult = await Signus.CreateAndStoreMyDidAsync(_wallet, didJson); var did = didResult.Did; var data = "{\"node_ip\":\"10.0.0.100\"," + @@ -67,7 +71,8 @@ public async Task TestSendNodeRequestWorksWithoutSignature() "\"alias\":\"some\"," + "\"services\":[\"VALIDATOR\"]}"; - var nodeRequest = Ledger.BuildNodeRequestAsync(did, did, data).Result; + var nodeRequest = await Ledger.BuildNodeRequestAsync(did, did, data); + var ex = await Assert.ThrowsExceptionAsync(() => Ledger.SubmitRequestAsync(_pool, nodeRequest) ); @@ -113,7 +118,7 @@ public async Task TestSendNodeRequestWorksForWrongRole() { var didJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var didResult = Signus.CreateAndStoreMyDidAsync(_wallet, didJson).Result; + var didResult = await Signus.CreateAndStoreMyDidAsync(_wallet, didJson); var did = didResult.Did; var data = "{\"node_ip\":\"10.0.0.100\"," + @@ -123,7 +128,7 @@ public async Task TestSendNodeRequestWorksForWrongRole() "\"alias\":\"some\"," + "\"services\":[\"VALIDATOR\"]}"; - var nodeRequest = Ledger.BuildNodeRequestAsync(did, did, data).Result; + var nodeRequest = await Ledger.BuildNodeRequestAsync(did, did, data); var ex = await Assert.ThrowsExceptionAsync(() => Ledger.SignAndSubmitRequestAsync(_pool, _wallet, did, nodeRequest) @@ -134,21 +139,21 @@ public async Task TestSendNodeRequestWorksForWrongRole() [TestMethod] [Ignore] - public void TestSendNodeRequestWorksForNewSteward() + public async Task TestSendNodeRequestWorksForNewSteward() { var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson); var trusteeDid = trusteeDidResult.Did; var myDidJson = "{}"; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, myDidJson).Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, myDidJson); var myDid = myDidResult.Did; var myVerkey = myDidResult.VerKey; var role = "STEWARD"; - var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerkey, null, role).Result; - Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest).Wait(); + var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerkey, null, role); + await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest); var data = "{\"node_ip\":\"10.0.0.100\"," + "\"node_port\":910," + @@ -159,8 +164,8 @@ public void TestSendNodeRequestWorksForNewSteward() var dest = "A5iWQVT3k8Zo9nXj4otmeqaUziPQPCiDqcydXkAJBk1Y"; - var nodeRequest = Ledger.BuildNodeRequestAsync(myDid, dest, data).Result; - Ledger.SignAndSubmitRequestAsync(_pool, _wallet, myDid, nodeRequest).Wait(); + var nodeRequest = await Ledger.BuildNodeRequestAsync(myDid, dest, data); + await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, myDid, nodeRequest); } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/NymRequestTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/NymRequestTest.cs index 569860b526..20b2e6dff6 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/NymRequestTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/NymRequestTest.cs @@ -17,36 +17,40 @@ public class NymRequestTest : IndyIntegrationTestBase [TestInitialize] - public void OpenPool() + public async Task OpenPool() { string poolName = PoolUtils.CreatePoolLedgerConfig(); - _pool = Pool.OpenPoolLedgerAsync(poolName, null).Result; + _pool = await Pool.OpenPoolLedgerAsync(poolName, null); - Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; + await Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); } [TestCleanup] - public void ClosePool() + public async Task ClosePool() { - _pool.CloseAsync().Wait(); - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); + if (_pool != null) + await _pool.CloseAsync(); + + if (_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); } [TestMethod] - public void TestBuildNymRequestWorksForOnlyRequiredFields() + public async Task TestBuildNymRequestWorksForOnlyRequiredFields() { var expectedResult = string.Format("\"identifier\":\"{0}\",\"operation\":{{\"type\":\"1\",\"dest\":\"{1}\"}}", _identifier, _dest); - var nymRequest = Ledger.BuildNymRequestAsync(_identifier, _dest, null, null, null).Result; + var nymRequest = await Ledger.BuildNymRequestAsync(_identifier, _dest, null, null, null); Assert.IsTrue(nymRequest.Contains(expectedResult)); } [TestMethod] - public void TestBuildNymRequestWorksForOnlyOptionalFields() + public async Task TestBuildNymRequestWorksForOnlyOptionalFields() { var verkey = "Anfh2rjAcxkE249DcdsaQl"; var role = "STEWARD"; @@ -61,17 +65,17 @@ public void TestBuildNymRequestWorksForOnlyOptionalFields() "\"role\":\"2\"" + "}}", _identifier, _dest, verkey, alias); - var nymRequest = Ledger.BuildNymRequestAsync(_identifier, _dest, verkey, alias, role).Result; + var nymRequest = await Ledger.BuildNymRequestAsync(_identifier, _dest, verkey, alias, role); Assert.IsTrue(nymRequest.Contains(expectedResult)); } [TestMethod] - public void TestBuildGetNymRequestWorks() + public async Task TestBuildGetNymRequestWorks() { var expectedResult = String.Format("\"identifier\":\"{0}\",\"operation\":{{\"type\":\"105\",\"dest\":\"{1}\"}}", _identifier, _dest); - var nymRequest = Ledger.BuildGetNymRequestAsync(_identifier, _dest).Result; + var nymRequest = await Ledger.BuildGetNymRequestAsync(_identifier, _dest); Assert.IsTrue(nymRequest.Contains(expectedResult)); } @@ -79,10 +83,10 @@ public void TestBuildGetNymRequestWorks() [TestMethod] public async Task TestNymRequestWorksWithoutSignature() { - var didResult = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var didResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); var did = didResult.Did; - var nymRequest = Ledger.BuildNymRequestAsync(did, did, null, null, null).Result; + var nymRequest = await Ledger.BuildNymRequestAsync(did, did, null, null, null); var ex = await Assert.ThrowsExceptionAsync(() => Ledger.SubmitRequestAsync(_pool, nymRequest) @@ -92,49 +96,49 @@ public async Task TestNymRequestWorksWithoutSignature() } [TestMethod] - public void TestSendNymRequestsWorksForOnlyRequiredFields() + public async Task TestSendNymRequestsWorksForOnlyRequiredFields() { var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson); var trusteeDid = trusteeDidResult.Did; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); var myDid = myDidResult.Did; - var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, myDid, null, null, null).Result; - var nymResponse = Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest).Result; + var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, null, null, null); + var nymResponse = await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest); Assert.IsNotNull(nymResponse); } [TestMethod] - public void TestSendNymRequestsWorksForOptionalFields() + public async Task TestSendNymRequestsWorksForOptionalFields() { var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson); var trusteeDid = trusteeDidResult.Did; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); var myDid = myDidResult.Did; var myVerKey = myDidResult.VerKey; var role = "STEWARD"; var alias = "some_alias"; - var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerKey, alias, role).Result; - var nymResponse = Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest).Result; + var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerKey, alias, role); + var nymResponse = await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest); Assert.IsNotNull(nymResponse); } [TestMethod] - public void TestGetNymRequestWorks() + public async Task TestGetNymRequestWorks() { var didJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var didResult = Signus.CreateAndStoreMyDidAsync(_wallet, didJson).Result; + var didResult = await Signus.CreateAndStoreMyDidAsync(_wallet, didJson); var did = didResult.Did; - var getNymRequest = Ledger.BuildGetNymRequestAsync(did, did).Result; - var getNymResponse = Ledger.SubmitRequestAsync(_pool, getNymRequest).Result; + var getNymRequest = await Ledger.BuildGetNymRequestAsync(did, did); + var getNymResponse = await Ledger.SubmitRequestAsync(_pool, getNymRequest); var getNymResponseObj = JObject.Parse(getNymResponse); @@ -145,21 +149,21 @@ public void TestGetNymRequestWorks() public async Task TestSendNymRequestsWorksForWrongSignerRole() { var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson); var trusteeDid = trusteeDidResult.Did; var myDidJson = "{}"; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, myDidJson).Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, myDidJson); var myDid = myDidResult.Did; - var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, myDid, null, null, null).Result; - Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest).Wait(); + var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, null, null, null); + await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest); var myDidJson2 = "{}"; - var myDidResult2 = Signus.CreateAndStoreMyDidAsync(_wallet, myDidJson2).Result; + var myDidResult2 = await Signus.CreateAndStoreMyDidAsync(_wallet, myDidJson2); var myDid2 = myDidResult2.Did; - var nymRequest2 = Ledger.BuildNymRequestAsync(myDid, myDid2, null, null, null).Result; + var nymRequest2 = await Ledger.BuildNymRequestAsync(myDid, myDid2, null, null, null); var ex = await Assert.ThrowsExceptionAsync(() => Ledger.SignAndSubmitRequestAsync(_pool, _wallet, myDid, nymRequest2) @@ -172,14 +176,14 @@ public async Task TestSendNymRequestsWorksForWrongSignerRole() public async Task TestSendNymRequestsWorksForUnknownSigner() { var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee9\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson); var trusteeDid = trusteeDidResult.Did; var myDidJson = "{}"; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, myDidJson).Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, myDidJson); var myDid = myDidResult.Did; - var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, myDid, null, null, null).Result; + var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, null, null, null); var ex = await Assert.ThrowsExceptionAsync(() => Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest) @@ -189,21 +193,21 @@ public async Task TestSendNymRequestsWorksForUnknownSigner() } [TestMethod] - public void TestNymRequestsWorks() + public async Task TestNymRequestsWorks() { var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson); var trusteeDid = trusteeDidResult.Did; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); var myDid = myDidResult.Did; var myVerKey = myDidResult.VerKey; - var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerKey, null, null).Result; - Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest).Wait(); + var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerKey, null, null); + await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest); - var getNymRequest = Ledger.BuildGetNymRequestAsync(myDid, myDid).Result; - var getNymResponse = Ledger.SubmitRequestAsync(_pool, getNymRequest).Result; + var getNymRequest = await Ledger.BuildGetNymRequestAsync(myDid, myDid); + var getNymResponse = await Ledger.SubmitRequestAsync(_pool, getNymRequest); var getNymResponseObj = JObject.Parse(getNymResponse); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/RequestTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/RequestTest.cs index 299ca076b8..80d75c157f 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/RequestTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/RequestTest.cs @@ -13,28 +13,30 @@ public class RequestTest : IndyIntegrationTestBase private string _walletName = "ledgerWallet"; [TestInitialize] - public void OpenPool() + public async Task OpenPool() { var poolName = PoolUtils.CreatePoolLedgerConfig(); - _pool = Pool.OpenPoolLedgerAsync(poolName, null).Result; + _pool = await Pool.OpenPoolLedgerAsync(poolName, null); - Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; + await Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); } [TestCleanup] - public void ClosePool() + public async Task ClosePool() { - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); + if (_pool != null) + await _pool.CloseAsync(); + if (_wallet != null) + await _wallet.CloseAsync(); - _pool.CloseAsync().Wait(); + await Wallet.DeleteWalletAsync(_walletName, null);; } [TestMethod] - public void TestSubmitRequestWorks() + public async Task TestSubmitRequestWorks() { var request = "{\"reqId\":1491566332010860,\n" + " \"identifier\":\"Th7MpTaRZVRYnPiabds81Y\",\n" + @@ -44,7 +46,7 @@ public void TestSubmitRequestWorks() " },\n" + " \"signature\":\"4o86XfkiJ4e2r3J6Ufoi17UU3W5Zi9sshV6FjBjkVw4sgEQFQov9dxqDEtLbAJAWffCWd5KfAk164QVo7mYwKkiV\"}"; - var response = Ledger.SubmitRequestAsync(_pool, request).Result; + var response = await Ledger.SubmitRequestAsync(_pool, request); var responseObject = JObject.Parse(response); @@ -57,17 +59,17 @@ public void TestSubmitRequestWorks() } [TestMethod] - public void TestSignAndSubmitRequestWorks() + public async Task TestSignAndSubmitRequestWorks() { var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson); var trusteeDid = trusteeDidResult.Did; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); var myDid = myDidResult.Did; - var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, myDid, null, null, null).Result; - var nymResponse = Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest).Result; + var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, null, null, null); + var nymResponse = await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, trusteeDid, nymRequest); Assert.IsNotNull(nymResponse); } [TestMethod] @@ -75,13 +77,13 @@ public async Task TestSignAndSubmitRequestWorksForNotFoundSigner() { var trusteeDidJson = "{\"seed\":\"00000000000000000000UnknowSigner\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeDidJson); var signerDid = trusteeDidResult.Did; - var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); var myDid = myDidResult.Did; - var nymRequest = Ledger.BuildNymRequestAsync(signerDid, myDid, null, null, null).Result; + var nymRequest = await Ledger.BuildNymRequestAsync(signerDid, myDid, null, null, null); var ex = await Assert.ThrowsExceptionAsync(() => Ledger.SignAndSubmitRequestAsync(_pool, _wallet, signerDid, nymRequest) @@ -95,17 +97,17 @@ public async Task TestSignAndSubmitRequestWorksForIncompatibleWalletAndPool() { var walletName = "incompatibleWallet"; - Wallet.CreateWalletAsync("otherPoolName", walletName, "default", null, null).Wait(); - var wallet = Wallet.OpenWalletAsync(walletName, null, null).Result; + await Wallet.CreateWalletAsync("otherPoolName", walletName, "default", null, null); + var wallet = await Wallet.OpenWalletAsync(walletName, null, null); var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(wallet, trusteeDidJson).Result; + var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(wallet, trusteeDidJson); var trusteeDid = trusteeDidResult.Did; - var myDidResult = Signus.CreateAndStoreMyDidAsync(wallet, "{}").Result; + var myDidResult = await Signus.CreateAndStoreMyDidAsync(wallet, "{}"); var myDid = myDidResult.Did; - var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, myDid, null, null, null).Result; + var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, null, null, null); var ex = await Assert.ThrowsExceptionAsync(() => Ledger.SignAndSubmitRequestAsync(_pool, wallet, trusteeDid, nymRequest) diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/SchemaRequestTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/SchemaRequestTest.cs index 6d25fa6ad9..595b9cfd41 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/SchemaRequestTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/SchemaRequestTest.cs @@ -14,41 +14,45 @@ public class SchemaRequestTest : IndyIntegrationTestBase private string _identifier = "Th7MpTaRZVRYnPiabds81Y"; [TestInitialize] - public void OpenPool() + public async Task OpenPool() { string poolName = PoolUtils.CreatePoolLedgerConfig(); - _pool = Pool.OpenPoolLedgerAsync(poolName, null).Result; + _pool = await Pool.OpenPoolLedgerAsync(poolName, null); - Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; + await Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); } [TestCleanup] - public void ClosePool() + public async Task ClosePool() { - _pool.CloseAsync().Wait(); - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); + if(_pool != null) + await _pool.CloseAsync(); + + if(_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); } [TestMethod] - public void TestBuildSchemaRequestWorks() + public async Task TestBuildSchemaRequestWorks() { - var data = "{\"name\":\"name\", \"version\":\"1.0\", \"keys\":[\"name\",\"male\"]}"; + var data = "{\"name\":\"name\",\"version\":\"1.0\",\"attr_names\":[\"name\",\"male\"]}"; var expectedResult = string.Format("\"identifier\":\"{0}\"," + "\"operation\":{{" + "\"type\":\"101\"," + - "\"data\":\"{1}\"" + + "\"data\":{1}" + "}}", _identifier, data); - var schemaRequest = Ledger.BuildSchemaRequestAsync(_identifier, data).Result; + var schemaRequest = await Ledger.BuildSchemaRequestAsync(_identifier, data); Assert.IsTrue(schemaRequest.Replace("\\", "").Contains(expectedResult)); } [TestMethod] - public void TestBuildGetSchemaRequestWorks() + public async Task TestBuildGetSchemaRequestWorks() { var data = "{\"name\":\"name\",\"version\":\"1.0\"}"; @@ -59,7 +63,7 @@ public void TestBuildGetSchemaRequestWorks() "\"data\":{2}" + "}}", _identifier, _identifier, data); - var getSchemaRequest = Ledger.BuildGetSchemaRequestAsync(_identifier, _identifier, data).Result; + var getSchemaRequest = await Ledger.BuildGetSchemaRequestAsync(_identifier, _identifier, data); Assert.IsTrue(getSchemaRequest.Contains(expectedResult)); } @@ -68,14 +72,14 @@ public void TestBuildGetSchemaRequestWorks() public async Task TestBuildSchemaRequestWorksWithoutSignature() { var didJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var didResult = Signus.CreateAndStoreMyDidAsync(_wallet, didJson).Result; + var didResult = await Signus.CreateAndStoreMyDidAsync(_wallet, didJson); var did = didResult.Did; var schemaData = "{\"name\":\"gvt2\",\n" + " \"version\":\"2.0\",\n" + - " \"keys\": [\"name\", \"male\"]}"; + " \"attr_names\": [\"name\", \"male\"]}"; - var schemaRequest = Ledger.BuildSchemaRequestAsync(did, schemaData).Result; + var schemaRequest = await Ledger.BuildSchemaRequestAsync(did, schemaData); var ex = await Assert.ThrowsExceptionAsync(() => Ledger.SubmitRequestAsync(_pool, schemaRequest) @@ -85,20 +89,20 @@ public async Task TestBuildSchemaRequestWorksWithoutSignature() } [TestMethod] //Name of this test is bad. - public void TestSchemaRequestWorks() + public async Task TestSchemaRequestWorks() { var didJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var didResult = Signus.CreateAndStoreMyDidAsync(_wallet, didJson).Result; + var didResult = await Signus.CreateAndStoreMyDidAsync(_wallet, didJson); var did = didResult.Did; - var schemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\",\"keys\": [\"name\", \"male\"]}"; + var schemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\",\"attr_names\": [\"name\", \"male\"]}"; - var schemaRequest = Ledger.BuildSchemaRequestAsync(did, schemaData).Result; - Ledger.SignAndSubmitRequestAsync(_pool, _wallet, did, schemaRequest).Wait(); + var schemaRequest = await Ledger.BuildSchemaRequestAsync(did, schemaData); + await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, did, schemaRequest); var getSchemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\"}"; - var getSchemaRequest = Ledger.BuildGetSchemaRequestAsync(did, did, getSchemaData).Result; - var getSchemaResponse = Ledger.SubmitRequestAsync(_pool, getSchemaRequest).Result; + var getSchemaRequest = await Ledger.BuildGetSchemaRequestAsync(did, did, getSchemaData); + var getSchemaResponse = await Ledger.SubmitRequestAsync(_pool, getSchemaRequest); var getSchemaResponseObject = JObject.Parse(getSchemaResponse); @@ -108,15 +112,15 @@ public void TestSchemaRequestWorks() } [TestMethod] - public void TestGetSchemaRequestsWorksForUnknownSchema() + public async Task TestGetSchemaRequestsWorksForUnknownSchema() { var didJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; - var didResult = Signus.CreateAndStoreMyDidAsync(_wallet, didJson).Result; + var didResult = await Signus.CreateAndStoreMyDidAsync(_wallet, didJson); var did = didResult.Did; var getSchemaData = "{\"name\":\"schema_name\",\"version\":\"2.0\"}"; - var getSchemaRequest = Ledger.BuildGetSchemaRequestAsync(did, did, getSchemaData).Result; - var getSchemaResponse = Ledger.SubmitRequestAsync(_pool, getSchemaRequest).Result; + var getSchemaRequest = await Ledger.BuildGetSchemaRequestAsync(did, did, getSchemaData); + var getSchemaResponse = await Ledger.SubmitRequestAsync(_pool, getSchemaRequest); var getSchemaResponseObject = JObject.Parse(getSchemaResponse); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/SignRequestTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/SignRequestTest.cs new file mode 100644 index 0000000000..3101d91ae0 --- /dev/null +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/LedgerTests/SignRequestTest.cs @@ -0,0 +1,82 @@ +using Indy.Sdk.Dotnet.Wrapper; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Indy.Sdk.Dotnet.Test.Wrapper.LedgerTests +{ + [TestClass] + public class SignRequestTest : IndyIntegrationTestBase + { + private Wallet _wallet; + private string _did; + private string _walletName = "ledgerWallet"; + + [TestInitialize] + public async Task CreateWalletWhitDid() + { + await Wallet.CreateWalletAsync("default", _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); + + var result = await Signus.CreateAndStoreMyDidAsync(_wallet, "{\"seed\":\"000000000000000000000000Trustee1\"}"); + _did = result.Did; + } + + [TestCleanup] + public async Task DeleteWallet() + { + if(_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); + } + + [TestMethod] + public async Task TestSignWorks() + { + var msg = "{\n" + + " \"reqId\":1496822211362017764,\n" + + " \"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\",\n" + + " \"operation\":{\n" + + " \"type\":\"1\",\n" + + " \"dest\":\"VsKV7grR1BUE29mG2Fm2kX\",\n" + + " \"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"\n" + + " }\n" + + " }"; + + var expectedSignature = "\"signature\":\"65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW\""; + + var signedMessage = await Ledger.SignRequestAsync(_wallet, _did, msg); + + Assert.IsTrue(signedMessage.Contains(expectedSignature)); + } + + [TestMethod] + public async Task TestSignWorksForUnknowDid() + { + var msg = "{\"reqId\":1496822211362017764}"; + + var ex = await Assert.ThrowsExceptionAsync(() => + Ledger.SignRequestAsync(_wallet, "8wZcEriaNLNKtteJvx7f8i", msg) + ); + + Assert.AreEqual(ErrorCode.WalletNotFoundError, ex.ErrorCode); + + } + + [TestMethod] + public async Task TestSignWorksForInvalidMessageFormat() + { + var msg = "\"reqId\":1496822211362017764"; + + var ex = await Assert.ThrowsExceptionAsync(() => + Ledger.SignRequestAsync(_wallet, _did, msg) + ); + + Assert.AreEqual(ErrorCode.CommonInvalidStructure, ex.ErrorCode); + } + } +} diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/ClosePoolTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/ClosePoolTest.cs index 0c5a0357f6..f796ef48e7 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/ClosePoolTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/ClosePoolTest.cs @@ -8,24 +8,24 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.PoolTests public class ClosePoolTest : IndyIntegrationTestBase { [TestMethod] - public void TestClosePoolWorks() + public async Task TestClosePoolWorks() { - var pool = PoolUtils.CreateAndOpenPoolLedger(); + var pool = await PoolUtils.CreateAndOpenPoolLedgerAsync(); Assert.IsNotNull(pool); _openedPools.Add(pool); - pool.CloseAsync().Wait(); + await pool.CloseAsync(); _openedPools.Remove(pool); } [TestMethod] public async Task TestClosePoolWorksForTwice() { - var pool = PoolUtils.CreateAndOpenPoolLedger(); + var pool = await PoolUtils.CreateAndOpenPoolLedgerAsync(); Assert.IsNotNull(pool); _openedPools.Add(pool); - pool.CloseAsync().Wait(); + await pool.CloseAsync(); _openedPools.Remove(pool); var ex = await Assert.ThrowsExceptionAsync(() => @@ -36,16 +36,16 @@ public async Task TestClosePoolWorksForTwice() } [TestMethod] - public void TestClosePoolWorksForReopenAfterClose() + public async Task TestClosePoolWorksForReopenAfterClose() { var poolName = PoolUtils.CreatePoolLedgerConfig(); - var pool = Pool.OpenPoolLedgerAsync(poolName, null).Result; + var pool = await Pool.OpenPoolLedgerAsync(poolName, null); Assert.IsNotNull(pool); - pool.CloseAsync().Wait(); + await pool.CloseAsync(); - pool = Pool.OpenPoolLedgerAsync(poolName, null).Result; + pool = await Pool.OpenPoolLedgerAsync(poolName, null); _openedPools.Add(pool); } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/CreatePoolTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/CreatePoolTest.cs index c825595c56..0507274566 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/CreatePoolTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/CreatePoolTest.cs @@ -9,14 +9,14 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.PoolTests public class CreatePoolTest : IndyIntegrationTestBase { [TestMethod] - public void TestCreatePoolWorksForNullConfig() + public async Task TestCreatePoolWorksForNullConfig() { var txnFile = "testCreatePoolWorks.txn"; try { File.Create(txnFile).Dispose(); - Pool.CreatePoolLedgerConfigAsync("testCreatePoolWorks", null).Wait(); + await Pool.CreatePoolLedgerConfigAsync("testCreatePoolWorks", null); } finally { @@ -25,14 +25,14 @@ public void TestCreatePoolWorksForNullConfig() } [TestMethod] - public void TestCreatePoolWorksForConfigJSON() + public async Task TestCreatePoolWorksForConfigJSON() { var genesisTxnFile = PoolUtils.CreateGenesisTxnFile("genesis.txn"); var path = Path.GetFullPath(genesisTxnFile).Replace('\\', '/'); var configJson = string.Format("{{\"genesis_txn\":\"{0}\"}}", path); - Pool.CreatePoolLedgerConfigAsync("testCreatePoolWorks", configJson).Wait(); + await Pool.CreatePoolLedgerConfigAsync("testCreatePoolWorks", configJson); } [TestMethod] @@ -61,8 +61,7 @@ public async Task TestCreatePoolWorksForTwice() var configJson = string.Format("{{\"genesis_txn\":\"{0}\"}}", path); - - Pool.CreatePoolLedgerConfigAsync("pool1", configJson).Wait(); + await Pool.CreatePoolLedgerConfigAsync("pool1", configJson); var ex = await Assert.ThrowsExceptionAsync(() => Pool.CreatePoolLedgerConfigAsync("pool1", configJson) diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/DeletePoolTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/DeletePoolTest.cs index c1a250f465..86fde971f3 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/DeletePoolTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/DeletePoolTest.cs @@ -8,17 +8,17 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.PoolTests public class DeletePoolTest : IndyIntegrationTestBase { [TestMethod] - public void TestDeletePoolWorks() + public async Task TestDeletePoolWorks() { var poolName = PoolUtils.CreatePoolLedgerConfig(); - Pool.DeletePoolLedgerConfigAsync(poolName).Wait(); + await Pool.DeletePoolLedgerConfigAsync(poolName); } [TestMethod] public async Task TestDeletePoolWorksForOpened() { var poolName = PoolUtils.CreatePoolLedgerConfig(); - var pool = Pool.OpenPoolLedgerAsync(poolName, null).Result; + var pool = await Pool.OpenPoolLedgerAsync(poolName, null); Assert.IsNotNull(pool); _openedPools.Add(pool); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/OpenPoolTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/OpenPoolTest.cs index d78d1d8cde..67f6c52497 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/OpenPoolTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/OpenPoolTest.cs @@ -8,10 +8,10 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.PoolTests public class OpenPoolTest : IndyIntegrationTestBase { [TestMethod] - public void TestOpenPoolWorksForNullConfig() + public async Task TestOpenPoolWorksForNullConfig() { var poolName = PoolUtils.CreatePoolLedgerConfig(); - var pool = Pool.OpenPoolLedgerAsync(poolName, null).Result; + var pool = await Pool.OpenPoolLedgerAsync(poolName, null); Assert.IsNotNull(pool); @@ -19,12 +19,12 @@ public void TestOpenPoolWorksForNullConfig() } [TestMethod] - public void TestOpenPoolWorksForConfig() + public async Task TestOpenPoolWorksForConfig() { var poolName = PoolUtils.CreatePoolLedgerConfig(); var config = "{\"refreshOnOpen\":true,\"autoRefreshTime\":false,\"networkTimeout\":false}"; - var pool = Pool.OpenPoolLedgerAsync(poolName, config).Result; + var pool = await Pool.OpenPoolLedgerAsync(poolName, config); Assert.IsNotNull(pool); @@ -35,7 +35,7 @@ public void TestOpenPoolWorksForConfig() public async Task TestOpenPoolWorksForTwice() { var poolName = PoolUtils.CreatePoolLedgerConfig(); - var pool = Pool.OpenPoolLedgerAsync(poolName, null).Result; + var pool = await Pool.OpenPoolLedgerAsync(poolName, null); Assert.IsNotNull(pool); _openedPools.Add(pool); @@ -49,22 +49,22 @@ public async Task TestOpenPoolWorksForTwice() } [TestMethod] - public void TestOpenPoolWorksForTwoNodes() + public async Task TestOpenPoolWorksForTwoNodes() { var poolName = PoolUtils.CreatePoolLedgerConfig(2); - var pool = Pool.OpenPoolLedgerAsync(poolName, null).Result; + var pool = await Pool.OpenPoolLedgerAsync(poolName, null); Assert.IsNotNull(pool); _openedPools.Add(pool); } [TestMethod] - public void TestOpenPoolWorksForThreeNodes() + public async Task TestOpenPoolWorksForThreeNodes() { var poolName = PoolUtils.CreatePoolLedgerConfig(3); - var pool = Pool.OpenPoolLedgerAsync(poolName, null).Result; + var pool = await Pool.OpenPoolLedgerAsync(poolName, null); Assert.IsNotNull(pool); _openedPools.Add(pool); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/RefreshPoolTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/RefreshPoolTest.cs index e8edf1d93c..232e514b84 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/RefreshPoolTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/PoolTests/RefreshPoolTest.cs @@ -1,4 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Threading.Tasks; namespace Indy.Sdk.Dotnet.Test.Wrapper.PoolTests { @@ -6,14 +7,14 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.PoolTests public class RefreshPoolTest : IndyIntegrationTestBase { [TestMethod] - public void TestRefreshPoolWorks() + public async Task TestRefreshPoolWorks() { - var pool = PoolUtils.CreateAndOpenPoolLedger(); + var pool = await PoolUtils.CreateAndOpenPoolLedgerAsync(); Assert.IsNotNull(pool); _openedPools.Add(pool); - pool.RefreshAsync().Wait(); + await pool.RefreshAsync(); } } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/CreateMyDidTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/CreateMyDidTest.cs index f4e8582f68..080e2fe846 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/CreateMyDidTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/CreateMyDidTest.cs @@ -16,25 +16,27 @@ public class CreateMyDidTest : IndyIntegrationTestBase private string _existsCryptoType = "ed25519"; [TestInitialize] - public void CreateWallet() + public async Task CreateWallet() { - Wallet.CreateWalletAsync("default", _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; + await Wallet.CreateWalletAsync("default", _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); } [TestCleanup] - public void DeleteWallet() + public async Task DeleteWallet() { - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); + if(_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); } [TestMethod] - public void TestCreateMyDidWorksForEmptyJson() + public async Task TestCreateMyDidWorksForEmptyJson() { var json = "{}"; - var result = Signus.CreateAndStoreMyDidAsync(_wallet, json).Result; + var result = await Signus.CreateAndStoreMyDidAsync(_wallet, json); Assert.IsNotNull(result); Assert.AreEqual(16, Base58CheckEncoding.DecodePlain(result.Did).Length); @@ -42,11 +44,11 @@ public void TestCreateMyDidWorksForEmptyJson() } [TestMethod] - public void TestCreateMyDidWorksForSeed() + public async Task TestCreateMyDidWorksForSeed() { var json = string.Format("{{\"seed\":\"{0}\"}}", _seed); - var result = Signus.CreateAndStoreMyDidAsync(_wallet, json).Result; + var result = await Signus.CreateAndStoreMyDidAsync(_wallet, json); Assert.IsNotNull(result); var expectedDid = "NcYxiDXkpYi6ov5FcYDi1e"; @@ -56,11 +58,11 @@ public void TestCreateMyDidWorksForSeed() } [TestMethod] - public void TestCreateMyDidWorksAsCid() + public async Task TestCreateMyDidWorksAsCid() { var json = string.Format("{{\"seed\":\"{0}\",\"cid\":true}}", _seed); - var result = Signus.CreateAndStoreMyDidAsync(_wallet, json).Result; + var result = await Signus.CreateAndStoreMyDidAsync(_wallet, json); Assert.IsNotNull(result); Assert.AreEqual(_expectedVerkey, result.Did); @@ -68,22 +70,22 @@ public void TestCreateMyDidWorksAsCid() } [TestMethod] - public void TestCreateMyDidWorksForPassedDid() + public async Task TestCreateMyDidWorksForPassedDid() { var json = string.Format("{{\"did\":\"{0}\",\"cid\":false}}", _did); - var result = Signus.CreateAndStoreMyDidAsync(_wallet, json).Result; + var result = await Signus.CreateAndStoreMyDidAsync(_wallet, json); Assert.IsNotNull(result); Assert.AreEqual(_did, result.Did); } [TestMethod] - public void TestCreateMyDidWorksForCorrectCryptoType() + public async Task TestCreateMyDidWorksForCorrectCryptoType() { var json = string.Format("{{\"crypto_type\":\"{0}\"}}", _existsCryptoType); - var result = Signus.CreateAndStoreMyDidAsync(_wallet, json).Result; + var result = await Signus.CreateAndStoreMyDidAsync(_wallet, json); Assert.IsNotNull(result); } @@ -112,11 +114,11 @@ public async Task TestCreateMyDidWorksForInvalidCryptoType() } [TestMethod] - public void TestCreateMyDidWorksForAllParams() + public async Task TestCreateMyDidWorksForAllParams() { var json = string.Format("{{\"did\":\"{0}\",\"seed\":\"{1}\",\"crypto_type\":\"{2}\",\"cid\":true}}", _did, _seed, _existsCryptoType); - var result = Signus.CreateAndStoreMyDidAsync(_wallet, json).Result; + var result = await Signus.CreateAndStoreMyDidAsync(_wallet, json); Assert.IsNotNull(result); Assert.AreEqual(_did, result.Did); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/DecryptTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/DecryptTest.cs new file mode 100644 index 0000000000..2988a38e06 --- /dev/null +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/DecryptTest.cs @@ -0,0 +1,118 @@ +using Indy.Sdk.Dotnet.Wrapper; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Indy.Sdk.Dotnet.Test.Wrapper.SignusTests +{ + [TestClass] + public class DecryptTest : IndyIntegrationTestBase + { + private Pool _pool; + private Wallet _wallet; + private string _trusteeDid; + private string _trusteeVerkey; + private string _myDid; + private string _myVerkey; + private string _walletName = "signusWallet"; + private byte[] _msg = Encoding.UTF8.GetBytes("{\"reqId\":1496822211362017764}"); + private byte[] _encryptedMessage = (byte[]) (Array) new sbyte[] { -105, 30, 89, 75, 76, 28, -59, -45, 105, -46, 20, 124, -85, -13, 109, 29, -88, -82, -8, -6, -50, -84, -53, -48, -49, 56, 124, 114, 82, 126, 74, 99, -72, -78, -117, 96, 60, 119, 50, -40, 121, 21, 57, -68, 89 }; + private byte[] _nonce = (byte[])(Array) new sbyte[] { -14, 102, -41, -57, 1, 4, 75, -46, -91, 87, 14, 41, -39, 48, 42, -126, -121, 84, -58, 59, -27, 51, -32, -23 }; + private string _identityJsonTemplate = "{{\"did\":\"{0}\",\"verkey\":\"{1}\"}}"; + + [TestInitialize] + public async Task CreateWalletWithDid() + { + var poolName = PoolUtils.CreatePoolLedgerConfig(); + + _pool = await Pool.OpenPoolLedgerAsync(poolName, "{}"); + + await Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); + + var trusteeJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; + + var trusteeNym = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeJson); + _trusteeDid = trusteeNym.Did; + _trusteeVerkey = trusteeNym.VerKey; + + var otherDid = "{\"seed\":\"00000000000000000000000000000My1\"}"; + + var myNym = await Signus.CreateAndStoreMyDidAsync(_wallet, otherDid); + _myDid = myNym.Did; + _myVerkey = myNym.VerKey; + } + + [TestCleanup] + public async Task DeleteWallet() + { + if(_pool != null) + await _pool.CloseAsync(); + + if (_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); + } + + [TestMethod] + public async Task TestDecryptWorks() + { + var identityJson = string.Format(_identityJsonTemplate, _trusteeDid, _trusteeVerkey); + await Signus.StoreTheirDidAsync(_wallet, identityJson); + + var decryptedMessage = await Signus.DecryptAsync(_wallet, _myDid, _trusteeDid, _encryptedMessage, _nonce); + Assert.IsTrue(_msg.SequenceEqual(decryptedMessage)); + + } + + [TestMethod] + public async Task TestDecryptWorksForOtherCoder() + { + var identityJson = string.Format(_identityJsonTemplate, _trusteeDid, _trusteeVerkey); + await Signus.StoreTheirDidAsync(_wallet, identityJson); + + identityJson = string.Format(_identityJsonTemplate, _myDid, _myVerkey); + await Signus.StoreTheirDidAsync(_wallet, identityJson); + + var encryptResult = await Signus.EncryptAsync(_wallet, _pool, _myDid, _myDid, _msg); + + var ex = await Assert.ThrowsExceptionAsync(() => + Signus.DecryptAsync(_wallet, _myDid, _trusteeDid, encryptResult.EncryptedMsg, encryptResult.Nonce) + ); + + Assert.AreEqual(ErrorCode.CommonInvalidStructure, ex.ErrorCode); + } + + [TestMethod] + public async Task TestDecryptWorksForNonceNotCorrespondMessage() + { + var identityJson = string.Format(_identityJsonTemplate, _trusteeDid, _trusteeVerkey); + await Signus.StoreTheirDidAsync(_wallet, identityJson); + + var nonce = (byte[])(Array)new sbyte[] { 46, 33, -4, 67, 1, 44, 57, -46, -91, 87, 14, 41, -39, 48, 42, -126, -121, 84, -58, 59, -27, 51, -32, -23 }; + + var ex = await Assert.ThrowsExceptionAsync(() => + Signus.DecryptAsync(_wallet, _myDid, _trusteeDid, _encryptedMessage, nonce) + ); + + Assert.AreEqual(ErrorCode.CommonInvalidStructure, ex.ErrorCode); + } + + [TestMethod] + public async Task TestDecryptWorksForUnknownMyDid() + { + var identityJson = string.Format(_identityJsonTemplate, _trusteeDid, _trusteeVerkey); + await Signus.StoreTheirDidAsync(_wallet, identityJson); + + var ex = await Assert.ThrowsExceptionAsync(() => + Signus.DecryptAsync(_wallet, "unknowDid", _trusteeDid, _encryptedMessage, _nonce) + ); + + Assert.AreEqual(ErrorCode.WalletNotFoundError, ex.ErrorCode); + } + } +} diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/EncryptTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/EncryptTest.cs new file mode 100644 index 0000000000..d38fa409b8 --- /dev/null +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/EncryptTest.cs @@ -0,0 +1,111 @@ +using Indy.Sdk.Dotnet.Wrapper; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Indy.Sdk.Dotnet.Test.Wrapper.SignusTests +{ + [TestClass] + public class EncryptTest : IndyIntegrationTestBase + { + private Pool _pool; + private Wallet _wallet; + private string _trusteeDid; + private string _trusteeVerkey; + private string _did; + private string _verkey; + private string _walletName = "signusWallet"; + private byte[] _msg = Encoding.UTF8.GetBytes("{\"reqId\":1496822211362017764}"); + + [TestInitialize] + public async Task Before() + { + var poolName = PoolUtils.CreatePoolLedgerConfig(); + + _pool = await Pool.OpenPoolLedgerAsync(poolName, "{}"); + + await Wallet.CreateWalletAsync(poolName, _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); + + var trusteeJson = "{\"seed\":\"000000000000000000000000Trustee1\"}"; + var result = await Signus.CreateAndStoreMyDidAsync(_wallet, trusteeJson); + _trusteeDid = result.Did; + _trusteeVerkey = result.VerKey; + + var otherDid = "{\"seed\":\"00000000000000000000000000000My1\"}"; + var nym = await Signus.CreateAndStoreMyDidAsync(_wallet, otherDid); + _did = nym.Did; + _verkey = nym.VerKey; + + var nymRequest = await Ledger.BuildNymRequestAsync(_trusteeDid, _did, _verkey, null, null); + await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, _trusteeDid, nymRequest); + } + + [TestCleanup] + public async Task After() + { + if (_pool != null) + await _pool.CloseAsync(); + + if (_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); + } + + [TestMethod] + public async Task TestEncryptWorksForPkCachedInWallet() + { + var identityJson = string.Format("{{\"did\":\"{0}\",\"verkey\":\"{1}\"}}", _did, _verkey); + await Signus.StoreTheirDidAsync(_wallet, identityJson); + + var encryptResult = await Signus.EncryptAsync(_wallet, _pool, _trusteeDid, _did, _msg); + Assert.IsNotNull(encryptResult); + } + + [TestMethod] + public async Task TestEncryptWorksForGetPkFromLedger() + { + var identityJson = string.Format("{{\"did\":\"{0}\"}}", _did); + await Signus.StoreTheirDidAsync(_wallet, identityJson); + + var encryptResult = await Signus.EncryptAsync(_wallet, _pool, _trusteeDid, _did, _msg); + Assert.IsNotNull(encryptResult); + } + + [TestMethod] + public async Task TestEncryptWorksForGetNymFromLedger() + { + var encryptResult = await Signus.EncryptAsync(_wallet, _pool, _trusteeDid, _did, _msg); + Assert.IsNotNull(encryptResult); + } + + [TestMethod] + public async Task TestEncryptWorksForUnknownMyDid() + { + var identityJson = string.Format("{{\"did\":\"{0}\",\"verkey\":\"{1}\"}}", _trusteeDid, _trusteeVerkey); + await Signus.StoreTheirDidAsync(_wallet, identityJson); + + var ex = await Assert.ThrowsExceptionAsync(() => + Signus.EncryptAsync(_wallet, _pool, "unknownDid", _trusteeDid, _msg) + ); + + Assert.AreEqual(ErrorCode.WalletNotFoundError, ex.ErrorCode); + } + + [TestMethod] + public async Task TestEncryptWorksForNotFoundNym() + { + var nym = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); + + var ex = await Assert.ThrowsExceptionAsync(() => + Signus.EncryptAsync(_wallet, _pool, _trusteeDid, nym.Did, _msg) + ); + + Assert.AreEqual(ErrorCode.CommonInvalidState, ex.ErrorCode); + } + } +} diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/ReplaceKeysTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/ReplaceKeysTest.cs index c6dce8574c..4d593c5b72 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/ReplaceKeysTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/ReplaceKeysTest.cs @@ -14,28 +14,30 @@ public class ReplaceKeysTest : IndyIntegrationTestBase private string _verKey; [TestInitialize] - public void CreateWalletWithDid() + public async Task CreateWalletWithDid() { - Wallet.CreateWalletAsync("default", _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; + await Wallet.CreateWalletAsync("default", _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); - var result = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result; + var result = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}"); _did = result.Did; _verKey = result.VerKey; } [TestCleanup] - public void DeleteWallet() + public async Task DeleteWallet() { - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); + if(_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); } [TestMethod] - public void TestReplaceKeysWorksForEmptyJson() + public async Task TestReplaceKeysWorksForEmptyJson() { - var result = Signus.ReplaceKeysAsync(_wallet, _did, "{}").Result; + var result = await Signus.ReplaceKeysAsync(_wallet, _did, "{}"); Assert.IsNotNull(result); Assert.AreEqual(32, Base58CheckEncoding.DecodePlain(result.VerKey).Length); @@ -52,17 +54,17 @@ public async Task TestReplaceKeysWorksForInvalidDid() } [TestMethod] - public void TestReplaceKeysWorksForNotExistsDid() + public async Task TestReplaceKeysWorksForNotExistsDid() { - var result = Signus.ReplaceKeysAsync(_wallet, "8wZcEriaNLNKtteJvx7f8i", "{}").Result; + var result = await Signus.ReplaceKeysAsync(_wallet, "8wZcEriaNLNKtteJvx7f8i", "{}"); Assert.IsNotNull(result); } [TestMethod] - public void TestReplaceKeysWorksForSeed() + public async Task TestReplaceKeysWorksForSeed() { - var result = Signus.ReplaceKeysAsync(_wallet, _did, "{\"seed\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}").Result; + var result = await Signus.ReplaceKeysAsync(_wallet, _did, "{\"seed\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}"); Assert.IsNotNull(result); Assert.AreEqual("CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", result.VerKey); diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/SignTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/SignTest.cs index b10a282467..e45db1fd78 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/SignTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/SignTest.cs @@ -1,6 +1,8 @@ using Indy.Sdk.Dotnet.Wrapper; using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Text; using System.Threading.Tasks; +using System.Linq; namespace Indy.Sdk.Dotnet.Test.Wrapper.SignusTests { @@ -9,68 +11,47 @@ public class SignTest : IndyIntegrationTestBase { private Wallet _wallet; private string _walletName = "signusWallet"; - private string _did; [TestInitialize] - public void CreateWalletWithDid() + public async Task CreateWallet() { - Wallet.CreateWalletAsync("default", _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; - - var result = Signus.CreateAndStoreMyDidAsync(_wallet, "{\"seed\":\"000000000000000000000000Trustee1\"}").Result; - - _did = result.Did; + await Wallet.CreateWalletAsync("default", _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); } [TestCleanup] - public void DeleteWallet() + public async Task DeleteWallet() { - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); + if(_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); } [TestMethod] - public void TestSignWorks() + public async Task TestSignWorks() { - var msg = "{\n" + - " \"reqId\":1496822211362017764,\n" + - " \"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\",\n" + - " \"operation\":{\n" + - " \"type\":\"1\",\n" + - " \"dest\":\"VsKV7grR1BUE29mG2Fm2kX\",\n" + - " \"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"\n" + - " }\n" + - " }"; - - var expectedSignature = "\"signature\":\"65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW\""; + var result = await Signus.CreateAndStoreMyDidAsync(_wallet, "{\"seed\":\"000000000000000000000000Trustee1\"}"); + var did = result.Did; + + var msg = Encoding.UTF8.GetBytes("{\"reqId\":1496822211362017764}"); - var signedMessage = Signus.SignAsync(_wallet, _did, msg).Result; + var expectedSignatureBytes = new byte[] { 20, 191, 100, 213, 101, 12, 197, 198, 203, 49, 89, 220, 205, 192, 224, 221, 97, 77, 220, 190, 90, 60, 142, 23, 16, 240, 189, 129, 45, 148, 245, 8, 102, 95, 95, 249, 100, 89, 41, 227, 213, 25, 100, 1, 232, 188, 245, 235, 186, 21, 52, 176, 236, 11, 99, 70, 155, 159, 89, 215, 197, 239, 138, 5 }; + var signatureBytes = await Signus.SignAsync(_wallet, did, msg); - Assert.IsTrue(signedMessage.Contains(expectedSignature)); + Assert.IsTrue(expectedSignatureBytes.SequenceEqual(signatureBytes)); } [TestMethod] public async Task TestSignWorksForUnknownDid() { - var msg = "{\"reqId\":1496822211362017764}"; + var msg = Encoding.UTF8.GetBytes("{\"reqId\":1496822211362017764}"); var ex = await Assert.ThrowsExceptionAsync(() => Signus.SignAsync(_wallet, "8wZcEriaNLNKtteJvx7f8i", msg) ); Assert.AreEqual(ErrorCode.WalletNotFoundError, ex.ErrorCode); - } - - [TestMethod] - public async Task TestSignWorksForInvalidMessageFormat() - { - var msg = "reqId:1495034346617224651"; - - var ex = await Assert.ThrowsExceptionAsync(() => - Signus.SignAsync(_wallet, _did, msg) - ); - - Assert.AreEqual(ErrorCode.CommonInvalidStructure, ex.ErrorCode); - } + } } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/StoreTheirDidTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/StoreTheirDidTest.cs index 34eaa031fa..72560bc322 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/StoreTheirDidTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/StoreTheirDidTest.cs @@ -13,23 +13,25 @@ public class StoreTheirDidTest : IndyIntegrationTestBase private string _verkey = "GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa"; [TestInitialize] - public void CreateWallet() + public async Task CreateWallet() { - Wallet.CreateWalletAsync("default", _walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result; + await Wallet.CreateWalletAsync("default", _walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(_walletName, null, null); } [TestCleanup] - public void DeleteWallet() + public async Task DeleteWallet() { - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(_walletName, null).Wait(); + if (_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(_walletName, null); } [TestMethod] - public void TestStoreTheirDidWorks() + public async Task TestStoreTheirDidWorks() { - Signus.StoreTheirDidAsync(_wallet, string.Format("{{\"did\":\"{0}\"}}", _did)).Wait(); + await Signus.StoreTheirDidAsync(_wallet, string.Format("{{\"did\":\"{0}\"}}", _did)); } [TestMethod] @@ -43,11 +45,11 @@ public async Task TestCreateMyDidWorksForInvalidIdentityJson() } [TestMethod] - public void TestStoreTheirDidWorksWithVerkey() + public async Task TestStoreTheirDidWorksWithVerkey() { var json = string.Format("{{\"did\":\"{0}\", \"verkey\":\"{1}\"}}", _did, _verkey); - Signus.StoreTheirDidAsync(_wallet, json).Wait(); + await Signus.StoreTheirDidAsync(_wallet, json); } [TestMethod] @@ -61,13 +63,13 @@ public async Task TestStoreTheirDidWorksWithoutDid() } [TestMethod] - public void TestStoreTheirDidWorksForCorrectCryptoType() + public async Task TestStoreTheirDidWorksForCorrectCryptoType() { var json = string.Format("{{\"did\":\"{0}\", " + "\"verkey\":\"{1}\", " + "\"crypto_type\": \"ed25519\"}}", _did, _verkey); - Signus.StoreTheirDidAsync(_wallet, json).Wait(); + await Signus.StoreTheirDidAsync(_wallet, json); } [TestMethod] diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/VerifyTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/VerifyTest.cs index f35a97be62..25addfba73 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/VerifyTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/SignusTests/VerifyTest.cs @@ -1,5 +1,6 @@ using Indy.Sdk.Dotnet.Wrapper; using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Text; using System.Threading.Tasks; namespace Indy.Sdk.Dotnet.Test.Wrapper.SignusTests @@ -16,18 +17,18 @@ public class VerifyTest : IndyIntegrationTestBase private string _newDid; [TestInitialize] - public void CreateWalletWithDid() + public async Task CreateWalletWithDid() { var poolName = PoolUtils.CreatePoolLedgerConfig(); - _pool = Pool.OpenPoolLedgerAsync(poolName, "{}").Result; + _pool = await Pool.OpenPoolLedgerAsync(poolName, "{}"); - Wallet.CreateWalletAsync(poolName, walletName, "default", null, null).Wait(); - _wallet = Wallet.OpenWalletAsync(walletName, null, null).Result; + await Wallet.CreateWalletAsync(poolName, walletName, "default", null, null); + _wallet = await Wallet.OpenWalletAsync(walletName, null, null); var json = "{\"seed\":\"000000000000000000000000Trustee1\",\"cid\":false}"; - var result = Signus.CreateAndStoreMyDidAsync(_wallet, json).Result; + var result = await Signus.CreateAndStoreMyDidAsync(_wallet, json); Assert.IsNotNull(result); _trusteeDid = result.Did; @@ -35,135 +36,88 @@ public void CreateWalletWithDid() } [TestCleanup] - public void DeleteWallet() + public async Task DeleteWallet() { - _wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(walletName, null).Wait(); - _pool.CloseAsync().Wait(); + if(_pool != null) + await _pool.CloseAsync(); + + if (_wallet != null) + await _wallet.CloseAsync(); + + await Wallet.DeleteWalletAsync(walletName, null); } - private void CreateNewNymWithDidInLedger() + private async Task CreateNewNymWithDidInLedgerAsync() { var json = "{\"seed\":\"00000000000000000000000000000My1\"}"; - var result = Signus.CreateAndStoreMyDidAsync(_wallet, json).Result; + var result = await Signus.CreateAndStoreMyDidAsync(_wallet, json); _newDid = result.Did; var newVerkey = result.VerKey; - var nymRequest = Ledger.BuildNymRequestAsync(_trusteeDid, _newDid, newVerkey, null, null).Result; - Ledger.SignAndSubmitRequestAsync(_pool, _wallet, _trusteeDid, nymRequest).Wait(); + var nymRequest = await Ledger.BuildNymRequestAsync(_trusteeDid, _newDid, newVerkey, null, null); + await Ledger.SignAndSubmitRequestAsync(_pool, _wallet, _trusteeDid, nymRequest); } [TestMethod] - public void TestVerifyWorksForVerkeyCachedInWallet() + public async Task TestVerifyWorksForVerkeyCachedInWallet() { _identityJson = string.Format("{{\"did\":\"{0}\",\"verkey\":\"{1}\"}}", _trusteeDid, _trusteeVerkey); - Signus.StoreTheirDidAsync(_wallet, _identityJson).Wait(); - - var msg = "{\n" + - " \"reqId\":1496822211362017764,\n" + - " \"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\",\n" + - " \"operation\":{\n" + - " \"type\":\"1\",\n" + - " \"dest\":\"VsKV7grR1BUE29mG2Fm2kX\",\n" + - " \"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"\n" + - " },\n" + - " \"signature\":\"65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW\"\n" + - " }"; - - var valid = Signus.VerifySignatureAsync(_wallet, _pool, _trusteeDid, msg).Result; - Assert.IsTrue(valid); - } + await Signus.StoreTheirDidAsync(_wallet, _identityJson); - [TestMethod] - public void TestVerifyWorksForGetVerkeyFromLedger() - { - CreateNewNymWithDidInLedger(); - Signus.StoreTheirDidAsync(_wallet, string.Format("{{\"did\":\"{0}\"}}", _newDid)).Wait(); - - var msg = "{\"reqId\":1496822211362017764,\n" + - "\"signature\":\"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai\"}"; + var msg = Encoding.UTF8.GetBytes("{\"reqId\":1496822211362017764}"); + var signatureBytes = new byte[] { 20, 191, 100, 213, 101, 12, 197, 198, 203, 49, 89, 220, 205, 192, 224, 221, 97, 77, 220, 190, 90, 60, 142, 23, 16, 240, 189, 129, 45, 148, 245, 8, 102, 95, 95, 249, 100, 89, 41, 227, 213, 25, 100, 1, 232, 188, 245, 235, 186, 21, 52, 176, 236, 11, 99, 70, 155, 159, 89, 215, 197, 239, 138, 5 }; - var valid = Signus.VerifySignatureAsync(_wallet, _pool, _newDid, msg).Result; + var valid = await Signus.VerifySignatureAsync(_wallet, _pool, _trusteeDid, msg, signatureBytes); Assert.IsTrue(valid); } [TestMethod] - public void TestVerifyWorksForGetNymFromLedger() + public async Task TestVerifyWorksForGetVerkeyFromLedger() { - CreateNewNymWithDidInLedger(); + await CreateNewNymWithDidInLedgerAsync(); + await Signus.StoreTheirDidAsync(_wallet, string.Format("{{\"did\":\"{0}\"}}", _newDid)); - var msg = "{\"reqId\":1496822211362017764,\n" + - "\"signature\":\"tibTuE59pZn1sCeZpNL5rDzpkpqV3EkDmRpFTizys9Gr3ZieLdGEGyq4h8jsVWW9zSaXSRnfYcVb1yTjUJ7vJai\"}"; + var msgBytes = Encoding.UTF8.GetBytes("{\"reqId\":1496822211362017764}"); + var signatureBytes = new byte[] { 169, 215, 8, 225, 7, 107, 110, 9, 193, 162, 202, 214, 162, 66, 238, 211, 63, 209, 12, 196, 8, 211, 55, 27, 120, 94, 204, 147, 53, 104, 103, 61, 60, 249, 237, 127, 103, 46, 220, 223, 10, 95, 75, 53, 245, 210, 241, 151, 191, 41, 48, 30, 9, 16, 78, 252, 157, 206, 210, 145, 125, 133, 109, 11 }; - var valid = Signus.VerifySignatureAsync(_wallet, _pool, _newDid, msg).Result; + var valid = await Signus.VerifySignatureAsync(_wallet, _pool, _newDid, msgBytes, signatureBytes); Assert.IsTrue(valid); } - [TestMethod] - public async Task TestVerifyWorksForInvalidMessageFormat() + public async Task TestVerifyWorksForGetNymFromLedger() { - var msg = "\"signature\":\"65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW\""; - + await CreateNewNymWithDidInLedgerAsync(); - var ex = await Assert.ThrowsExceptionAsync(() => - Signus.VerifySignatureAsync(_wallet, _pool, _trusteeDid, msg) - ); + var msgBytes = Encoding.UTF8.GetBytes("{\"reqId\":1496822211362017764}"); + var signatureBytes = new byte[] { 169, 215, 8, 225, 7, 107, 110, 9, 193, 162, 202, 214, 162, 66, 238, 211, 63, 209, 12, 196, 8, 211, 55, 27, 120, 94, 204, 147, 53, 104, 103, 61, 60, 249, 237, 127, 103, 46, 220, 223, 10, 95, 75, 53, 245, 210, 241, 151, 191, 41, 48, 30, 9, 16, 78, 252, 157, 206, 210, 145, 125, 133, 109, 11 }; - Assert.AreEqual(ErrorCode.CommonInvalidStructure, ex.ErrorCode); - } - - [TestMethod] - public async Task TestVerifyWorksForMessageWithoutSignature() - { - var msg = "{\n" + - " \"reqId\":1496822211362017764,\n" + - " \"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\",\n" + - " \"operation\":{\n" + - " \"type\":\"1\",\n" + - " \"dest\":\"VsKV7grR1BUE29mG2Fm2kX\",\n" + - " \"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"\n" + - " },\n" + - " }"; - - var ex = await Assert.ThrowsExceptionAsync(() => - Signus.VerifySignatureAsync(_wallet, _pool, _trusteeDid, msg) - ); - - Assert.AreEqual(ErrorCode.CommonInvalidStructure, ex.ErrorCode); + var valid = await Signus.VerifySignatureAsync(_wallet, _pool, _newDid, msgBytes, signatureBytes); + Assert.IsTrue(valid); } - + [TestMethod] - public void TestVerifyWorksForOtherSigner() + public async Task TestVerifyWorksForOtherSigner() { _identityJson = string.Format("{{\"did\":\"{0}\", \"verkey\":\"{1}\"}}", _trusteeDid, _trusteeVerkey); - Signus.StoreTheirDidAsync(_wallet, _identityJson).Wait(); + await Signus.StoreTheirDidAsync(_wallet, _identityJson); var createDidJson = "{\"seed\":\"000000000000000000000000Steward1\"}"; - var result = Signus.CreateAndStoreMyDidAsync(_wallet, createDidJson).Result; + var result = await Signus.CreateAndStoreMyDidAsync(_wallet, createDidJson); var stewardDid = result.Did; var stewardVerkey = result.VerKey; _identityJson = string.Format("{{\"did\":\"{0}\", \"verkey\":\"{1}\"}}", stewardDid, stewardVerkey); - Signus.StoreTheirDidAsync(_wallet, _identityJson).Wait(); - - var msg = "{\n" + - " \"reqId\":1496822211362017764,\n" + - " \"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\",\n" + - " \"operation\":{\n" + - " \"type\":\"1\",\n" + - " \"dest\":\"VsKV7grR1BUE29mG2Fm2kX\",\n" + - " \"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"\n" + - " }\n" + - " }"; + await Signus.StoreTheirDidAsync(_wallet, _identityJson); - var signedMessage = Signus.SignAsync(_wallet, _trusteeDid, msg).Result; + var msgBytes = Encoding.UTF8.GetBytes("{\"reqId\":1496822211362017764}"); + var signatureBytes = await Signus.SignAsync(_wallet, _trusteeDid, msgBytes); - var valid = Signus.VerifySignatureAsync(_wallet, _pool, stewardDid, signedMessage).Result; + var valid = await Signus.VerifySignatureAsync(_wallet, _pool, stewardDid, msgBytes, signatureBytes); Assert.IsFalse(valid); } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/CloseWalletTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/CloseWalletTest.cs index e991d15063..6ec871512a 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/CloseWalletTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/CloseWalletTest.cs @@ -8,16 +8,16 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.WalletTests public class CloseWalletTest : IndyIntegrationTestBase { [TestMethod] - public void TestCloseWalletWorks() + public async Task TestCloseWalletWorks() { var walletName = "closeWalletWorks"; - Wallet.CreateWalletAsync("default", walletName, "default", null, null).Wait(); + await Wallet.CreateWalletAsync("default", walletName, "default", null, null); - var wallet = Wallet.OpenWalletAsync(walletName, null, null).Result; + var wallet = await Wallet.OpenWalletAsync(walletName, null, null); Assert.IsNotNull(wallet); - wallet.CloseAsync().Wait(); + await wallet.CloseAsync(); } [TestMethod] @@ -25,13 +25,13 @@ public async Task TestCloseWalletWorksForTwice() { var walletName = "closeWalletWorksForTwice"; - Wallet.CreateWalletAsync("default", walletName, "default", null, null).Wait(); + await Wallet.CreateWalletAsync("default", walletName, "default", null, null); - var wallet = Wallet.OpenWalletAsync(walletName, null, null).Result; + var wallet = await Wallet.OpenWalletAsync(walletName, null, null); Assert.IsNotNull(wallet); - wallet.CloseAsync().Wait(); + await wallet.CloseAsync(); var ex = await Assert.ThrowsExceptionAsync(() => wallet.CloseAsync() @@ -41,15 +41,15 @@ public async Task TestCloseWalletWorksForTwice() } [TestMethod] - public void TestCloseWalletWorksForPlugged() + public async Task TestCloseWalletWorksForPlugged() { var type = "inmem"; var walletName = "testCloseWalletWorksForPlugged"; - Wallet.CreateWalletAsync("default", walletName, type, null, null).Wait(); + await Wallet.CreateWalletAsync("default", walletName, type, null, null); - var wallet = Wallet.OpenWalletAsync(walletName, null, null).Result; - wallet.CloseAsync().Wait(); + var wallet = await Wallet.OpenWalletAsync(walletName, null, null); + await wallet.CloseAsync(); } } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/CreateWalletTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/CreateWalletTest.cs index e14b29d847..72dcc9dd6a 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/CreateWalletTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/CreateWalletTest.cs @@ -8,21 +8,21 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.WalletTests public class CreateWalletTest : IndyIntegrationTestBase { [TestMethod] - public void TestCreateWalletWorks() + public async Task TestCreateWalletWorks() { - Wallet.CreateWalletAsync("default", "createWalletWorks", "default", null, null).Wait(); + await Wallet.CreateWalletAsync("default", "createWalletWorks", "default", null, null); } [TestMethod] - public void TestCreateWalletWorksForEmptyType() + public async Task TestCreateWalletWorksForEmptyType() { - Wallet.CreateWalletAsync("default", "createWalletWorks", null, null, null).Wait(); + await Wallet.CreateWalletAsync("default", "createWalletWorks", null, null, null); } [TestMethod] - public void TestCreateWalletWorksForConfigJson() + public async Task TestCreateWalletWorksForConfigJson() { - Wallet.CreateWalletAsync("default", "createWalletWorks", null, "{\"freshness_time\":1000}", null).Wait(); + await Wallet.CreateWalletAsync("default", "createWalletWorks", null, "{\"freshness_time\":1000}", null); } [TestMethod] @@ -52,7 +52,7 @@ public async Task TestCreateWalletWorksForDuplicateName() var walletName = "deleteWalletWorks"; var type = "default"; - Wallet.CreateWalletAsync(poolName, walletName, type, null, null).Wait(); + await Wallet.CreateWalletAsync(poolName, walletName, type, null, null); var ex = await Assert.ThrowsExceptionAsync(() => Wallet.CreateWalletAsync(poolName, walletName, type, null, null) @@ -62,9 +62,9 @@ public async Task TestCreateWalletWorksForDuplicateName() } [TestMethod] - public void TestCreateWalletWorksForPlugged() + public async Task TestCreateWalletWorksForPlugged() { - Wallet.CreateWalletAsync("default", "createWalletWorks", "default", null, null).Wait(); + await Wallet.CreateWalletAsync("default", "createWalletWorks", "default", null, null); } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/DeleteWalletTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/DeleteWalletTest.cs index ca893de08a..ff2de71d9a 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/DeleteWalletTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/DeleteWalletTest.cs @@ -8,31 +8,31 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.WalletTests public class DeleteWalletTest : IndyIntegrationTestBase { [TestMethod] - public void TestDeleteWalletWorks() + public async Task TestDeleteWalletWorks() { var poolName = "default"; var walletName = "deleteWalletWorks"; var type = "default"; - Wallet.CreateWalletAsync(poolName, walletName, type, null, null).Wait(); - Wallet.DeleteWalletAsync(walletName, null).Wait(); - Wallet.CreateWalletAsync(poolName, walletName, type, null, null).Wait(); + await Wallet.CreateWalletAsync(poolName, walletName, type, null, null); + await Wallet.DeleteWalletAsync(walletName, null); + await Wallet.CreateWalletAsync(poolName, walletName, type, null, null); } [TestMethod] - public void TestDeleteWalletWorksForClosed() + public async Task TestDeleteWalletWorksForClosed() { var poolName = "default"; var walletName = "deleteWalletWorks"; - Wallet.CreateWalletAsync(poolName, walletName, null, null, null).Wait(); + await Wallet.CreateWalletAsync(poolName, walletName, null, null, null); - var wallet = Wallet.OpenWalletAsync(walletName, null, null).Result; + var wallet = await Wallet.OpenWalletAsync(walletName, null, null); Assert.IsNotNull(wallet); - wallet.CloseAsync().Wait(); - Wallet.DeleteWalletAsync(walletName, null).Wait(); - Wallet.CreateWalletAsync(poolName, walletName, null, null, null).Wait(); + await wallet.CloseAsync(); + await Wallet.DeleteWalletAsync(walletName, null); + await Wallet.CreateWalletAsync(poolName, walletName, null, null, null); } [TestMethod] @@ -41,8 +41,8 @@ public async Task TestDeleteWalletWorksForOpened() { var walletName = "deleteWalletWorksForOpened"; - Wallet.CreateWalletAsync("default", walletName, null, null, null).Wait(); - var wallet = Wallet.OpenWalletAsync(walletName, null, null).Result; + await Wallet.CreateWalletAsync("default", walletName, null, null, null); + var wallet = await Wallet.OpenWalletAsync(walletName, null, null); var ex = await Assert.ThrowsExceptionAsync(() => Wallet.DeleteWalletAsync(walletName, null) @@ -56,16 +56,15 @@ public async Task TestDeleteWalletWorksForTwice() { var walletName = "deleteWalletWorksForTwice"; + await Wallet.CreateWalletAsync("default", walletName, null, null, null); - Wallet.CreateWalletAsync("default", walletName, null, null, null).Wait(); - - var wallet = Wallet.OpenWalletAsync(walletName, null, null).Result; + var wallet = await Wallet.OpenWalletAsync(walletName, null, null); Assert.IsNotNull(wallet); - wallet.CloseAsync().Wait(); + await wallet.CloseAsync(); - Wallet.DeleteWalletAsync(walletName, null).Wait(); + await Wallet.DeleteWalletAsync(walletName, null); var ex = await Assert.ThrowsExceptionAsync(() => Wallet.DeleteWalletAsync(walletName, null) @@ -86,15 +85,15 @@ public async Task TestDeleteWalletWorksForNotCreated() } [TestMethod] - public void TestDeleteWalletWorksForPlugged() + public async Task TestDeleteWalletWorksForPlugged() { var type = "inmem"; var poolName = "default"; var walletName = "wallet"; - Wallet.CreateWalletAsync(poolName, walletName, type, null, null).Wait(); - Wallet.DeleteWalletAsync(walletName, null).Wait(); - Wallet.CreateWalletAsync(poolName, walletName, type, null, null).Wait(); + await Wallet.CreateWalletAsync(poolName, walletName, type, null, null); + await Wallet.DeleteWalletAsync(walletName, null); + await Wallet.CreateWalletAsync(poolName, walletName, type, null, null); } } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/InMemWallet.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/InMemWallet.cs index 91804c8d7f..5e6d169a25 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/InMemWallet.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/InMemWallet.cs @@ -17,10 +17,8 @@ public InMemWallet(TimeSpan freshnessDuration) _freshnessDuration = freshnessDuration; } - public bool IsOpen { get; set; } - public override ErrorCode Set(string key, string value) { var record = new WalletRecord() { Value = value, TimeCreated = DateTime.Now }; diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/OpenWalletTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/OpenWalletTest.cs index caca2343ec..79e58ceb57 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/OpenWalletTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/OpenWalletTest.cs @@ -8,23 +8,23 @@ namespace Indy.Sdk.Dotnet.Test.Wrapper.WalletTests public class OpenWalletTest : IndyIntegrationTestBase { [TestMethod] - public void TestOpenWalletWorks() + public async Task TestOpenWalletWorks() { var walletName = "openWalletWorks"; - Wallet.CreateWalletAsync("default", walletName, "default", null, null).Wait(); - Wallet wallet = Wallet.OpenWalletAsync(walletName, null, null).Result; + await Wallet.CreateWalletAsync("default", walletName, "default", null, null); + var wallet = await Wallet.OpenWalletAsync(walletName, null, null); Assert.IsNotNull(wallet); } [TestMethod] - public void TestOpenWalletWorksForConfig() + public async Task TestOpenWalletWorksForConfig() { var walletName = "openWalletWorksForConfig"; - Wallet.CreateWalletAsync("default", walletName, "default", null, null).Wait(); - Wallet wallet = Wallet.OpenWalletAsync(walletName, "{\"freshness_time\":1000}", null).Result; + await Wallet.CreateWalletAsync("default", walletName, "default", null, null); + var wallet = await Wallet.OpenWalletAsync(walletName, "{\"freshness_time\":1000}", null); Assert.IsNotNull(wallet); } @@ -44,9 +44,9 @@ public async Task TestOpenWalletWorksForTwice() { var walletName = "openWalletWorksForTwice"; - Wallet.CreateWalletAsync("default", walletName, "default", null, null).Wait(); + await Wallet.CreateWalletAsync("default", walletName, "default", null, null); - var wallet1 = Wallet.OpenWalletAsync(walletName, null, null).Result; + var wallet1 = Wallet.OpenWalletAsync(walletName, null, null); var ex = await Assert.ThrowsExceptionAsync(() => Wallet.OpenWalletAsync(walletName, null, null) @@ -66,14 +66,14 @@ public async Task TestOpenWalletWorksForNotCreated() } [TestMethod] - public void TestOpenWalletWorksForPlugged() + public async Task TestOpenWalletWorksForPlugged() { var type = "inmem"; var poolName = "default"; var walletName = "testOpenWalletWorksForPlugged"; - Wallet.CreateWalletAsync(poolName, walletName, type, null, null).Wait(); - var wallet = Wallet.OpenWalletAsync(walletName, null, null).Result; + await Wallet.CreateWalletAsync(poolName, walletName, type, null, null); + var wallet = await Wallet.OpenWalletAsync(walletName, null, null); Assert.IsNotNull(wallet); } } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/RegisterWalletTypeTest.cs b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/RegisterWalletTypeTest.cs index 68ccfdcc2d..fe59d3a95e 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/RegisterWalletTypeTest.cs +++ b/wrappers/dotnet/indy-sdk-dotnet-test/Wrapper/WalletTests/RegisterWalletTypeTest.cs @@ -22,28 +22,28 @@ public class RegisterWalletTypeTest : IndyIntegrationTestBase [TestMethod] [Ignore] - public void Test() + public async Task TestExerciseCustomWallet() { - Wallet.RegisterWalletTypeAsync("inmem", new InMemWalletType()).Wait(); + await Wallet.RegisterWalletTypeAsync("inmem", new InMemWalletType()); var walletName = "registerWalletTypeWorks"; - Wallet.CreateWalletAsync("default", walletName, "inmem", null, null).Wait(); + await Wallet.CreateWalletAsync("default", walletName, "inmem", null, null); - var wallet = Wallet.OpenWalletAsync(walletName, null, null).Result; + var wallet = await Wallet.OpenWalletAsync(walletName, null, null); Assert.IsNotNull(wallet); - var claimDef = AnonCreds.IssuerCreateAndStoreClaimDefAsync(wallet, _issuerDid, _schema, null, false).Result; + var claimDef = await AnonCreds.IssuerCreateAndStoreClaimDefAsync(wallet, _issuerDid, _schema, null, false); - AnonCreds.ProverStoreClaimOfferAsync(wallet, string.Format(_claimOfferTemplate, _issuerDid, 1)).Wait(); - AnonCreds.ProverStoreClaimOfferAsync(wallet, string.Format(_claimOfferTemplate, _issuerDid, 2)).Wait(); - AnonCreds.ProverStoreClaimOfferAsync(wallet, string.Format(_claimOfferTemplate, _issuerDid2, 2)).Wait(); + await AnonCreds.ProverStoreClaimOfferAsync(wallet, string.Format(_claimOfferTemplate, _issuerDid, 1)); + await AnonCreds.ProverStoreClaimOfferAsync(wallet, string.Format(_claimOfferTemplate, _issuerDid, 2)); + await AnonCreds.ProverStoreClaimOfferAsync(wallet, string.Format(_claimOfferTemplate, _issuerDid2, 2)); - AnonCreds.ProverCreateMasterSecretAsync(wallet, _masterSecretName).Wait(); + await AnonCreds.ProverCreateMasterSecretAsync(wallet, _masterSecretName); var claimOffer = string.Format("{{\"issuer_did\":\"{0}\",\"schema_seq_no\":{1}}}", _issuerDid, 1); - var claimRequest = AnonCreds.ProverCreateAndStoreClaimReqAsync(wallet, "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", claimOffer, claimDef, _masterSecretName).Result; + var claimRequest = await AnonCreds.ProverCreateAndStoreClaimReqAsync(wallet, "CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW", claimOffer, claimDef, _masterSecretName); var claim = "{\"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],\n" + " \"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],\n" + @@ -51,24 +51,23 @@ public void Test() " \"age\":[\"28\",\"28\"]\n" + " }"; - var createClaimResult = AnonCreds.IssuerCreateClaimAsync(wallet, claimRequest, claim, -1, -1).Result; + var createClaimResult = await AnonCreds.IssuerCreateClaimAsync(wallet, claimRequest, claim, -1, -1); var claimJson = createClaimResult.ClaimJson; - AnonCreds.ProverStoreClaimAsync(wallet, claimJson).Wait(); - + await AnonCreds.ProverStoreClaimAsync(wallet, claimJson); var filter = string.Format("{{\"issuer_did\":\"{0}\"}}", _issuerDid); - var claimOffers = AnonCreds.ProverGetClaimOffersAsync(wallet, filter).Result; + var claimOffers = await AnonCreds.ProverGetClaimOffersAsync(wallet, filter); - wallet.CloseAsync().Wait(); + await wallet.CloseAsync(); } [TestMethod] [Ignore] //Not a valid test since the wallet type is registered on init! - public void TestRegisterWalletTypeWorks() + public async Task TestRegisterWalletTypeWorks() { - Wallet.RegisterWalletTypeAsync("inmem", new InMemWalletType()).Wait(); + await Wallet.RegisterWalletTypeAsync("inmem", new InMemWalletType()); } [TestMethod] @@ -77,8 +76,8 @@ public async Task TestRegisterWalletTypeDoesNotWorkForTwiceWithSameName() var type = "inmem"; var ex = await Assert.ThrowsExceptionAsync(() => - Wallet.RegisterWalletTypeAsync(type, new InMemWalletType()) - ); + Wallet.RegisterWalletTypeAsync(type, new InMemWalletType()) + ); Assert.AreEqual(ErrorCode.WalletTypeAlreadyRegisteredError, ex.ErrorCode); } diff --git a/wrappers/dotnet/indy-sdk-dotnet-test/indy-sdk-dotnet-test.csproj b/wrappers/dotnet/indy-sdk-dotnet-test/indy-sdk-dotnet-test.csproj index f8aec060d3..06ca70a369 100644 --- a/wrappers/dotnet/indy-sdk-dotnet-test/indy-sdk-dotnet-test.csproj +++ b/wrappers/dotnet/indy-sdk-dotnet-test/indy-sdk-dotnet-test.csproj @@ -97,6 +97,9 @@ + + + diff --git a/wrappers/dotnet/indy-sdk-dotnet/IndyNativeMethods.cs b/wrappers/dotnet/indy-sdk-dotnet/IndyNativeMethods.cs index d8a7024f94..989b13a5da 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/IndyNativeMethods.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/IndyNativeMethods.cs @@ -260,6 +260,8 @@ public static class IndyNativeMethods /// The request that can be signed and submitted to the ledger. internal delegate void BuildRequestResultDelegate(int command_handle, int err, string request_json); + + /// /// Signs and submits request message to validator pool. /// @@ -283,7 +285,27 @@ public static class IndyNativeMethods /// 0 if the command was initiated successfully. Any non-zero result indicates an error. [DllImport("indy.dll", CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] internal static extern int indy_submit_request(int command_handle, IntPtr pool_handle, string request_json, SubmitRequestResultDelegate cb); + + /// + /// Signs a request. + /// + /// The handle for the command that will be passed to the callback. + /// wallet handle. + /// The DID of the submitter. + /// The request to sign. + /// The function that will be called when the asynchronous call is complete. + /// 0 if the command was initiated successfully. Any non-zero result indicates an error. + [DllImport("indy.dll", CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] + internal static extern int indy_sign_request(int command_handle, IntPtr wallet_handle, string submitter_did, string request_json, SignRequestResultDelegate cb); + /// + /// Delegate for callbacks used by functions that sign requests. + /// + /// The handle for the command that initiated the callback. + /// The outcome of execution of the command. + /// The signed request data. + internal delegate void SignRequestResultDelegate(int command_handle, int err, string signed_request_json); + /// /// Builds a request to get a DDO. /// @@ -482,19 +504,21 @@ public static class IndyNativeMethods /// The handle for the command that will be passed to the callback. /// wallet handle (created by open_wallet). /// signing DID - /// a message to be signed + /// The message to be signed. + /// The length of the message array. /// The function that will be called when the asynchronous call is complete. /// 0 if the command was initiated successfully. Any non-zero result indicates an error. [DllImport("indy.dll", CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int indy_sign(int command_handle, IntPtr wallet_handle, string did, string msg, SignResultDelegate cb); + internal static extern int indy_sign(int command_handle, IntPtr wallet_handle, string did, byte[] msg_raw, int msg_len, SignResultDelegate cb); /// /// Delegate for the function called back to by the sovrin_sign function. /// /// The handle for the command that initiated the callback. /// The outcome of execution of the command. - /// a signature string - internal delegate void SignResultDelegate(int command_handle, int err, string signature); + /// The raw signature bytes. + /// The length of the signature byte array. + internal delegate void SignResultDelegate(int command_handle, int err, IntPtr signature_raw, int signature_len); /// /// Verify a signature created by a key associated with a DID. @@ -503,11 +527,14 @@ public static class IndyNativeMethods /// wallet handle (created by open_wallet). /// pool handle. /// DID that signed the message - /// The signed message + /// The message + /// The length of the message array. + /// The signature. + /// The length of the signature array. /// The function that will be called when the asynchronous call is complete. /// 0 if the command was initiated successfully. Any non-zero result indicates an error. [DllImport("indy.dll", CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int indy_verify_signature(int command_handle, IntPtr wallet_handle, IntPtr pool_handle, string did, string signed_msg, VerifySignatureResultDelegate cb); + internal static extern int indy_verify_signature(int command_handle, IntPtr wallet_handle, IntPtr pool_handle, string did, byte[] msg_raw, int msg_len, byte[] signature_raw, int signature_len, VerifySignatureResultDelegate cb); /// /// Delegate for the function called back to by the sovrin_verify_signature function. @@ -525,20 +552,23 @@ public static class IndyNativeMethods /// /// encrypting DID /// encrypting DID (??) - /// encrypting DID + /// The message to encrypt. + /// The length of the message byte array. /// The function that will be called when the asynchronous call is complete. /// 0 if the command was initiated successfully. Any non-zero result indicates an error. [DllImport("indy.dll", CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int indy_encrypt(int command_handle, IntPtr wallet_handle, IntPtr pool_handle, string my_did, string did, string msg, EncryptResultDelegate cb); + internal static extern int indy_encrypt(int command_handle, IntPtr wallet_handle, IntPtr pool_handle, string my_did, string did, byte[] msg_raw, int msg_len, EncryptResultDelegate cb); /// /// Delegate for the function called back to by the sovrin_encrypt function. /// /// The handle for the command that initiated the callback. /// The outcome of execution of the command. - /// The encrypted message. - /// The nonce - internal delegate void EncryptResultDelegate(int command_handle, int err, string encrypted_msg, string nonce); + /// The encrypted message as an array of bytes. + /// The length of the encrypted message byte array. + /// The nonce as an array of bytes. + /// The length of the nonce byte array. + internal delegate void EncryptResultDelegate(int command_handle, int err, IntPtr encrypted_msg_raw, int encrypted_msg_len, IntPtr nonce_raw, int nonce_len); /// /// Decrypts a message encrypted by a public key associated with my DID. @@ -547,20 +577,23 @@ public static class IndyNativeMethods /// wallet handle (created by open_wallet). /// DID /// DID that signed the message - /// encrypted message - /// nonce that encrypted message + /// encrypted message as a byte array. + /// The length of the message byte array. + /// nonce that encrypted message as a byte array. + /// The length of the nonce byte array. /// The function that will be called when the asynchronous call is complete. /// 0 if the command was initiated successfully. Any non-zero result indicates an error. [DllImport("indy.dll", CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] - internal static extern int indy_decrypt(int command_handle, IntPtr wallet_handle, string my_did, string did, string encrypted_msg, string nonce, DecryptResultDelegate cb); + internal static extern int indy_decrypt(int command_handle, IntPtr wallet_handle, string my_did, string did, byte[] encrypted_msg_raw, int encrypted_msg_len, byte[] nonce_raw, int nonce_len, DecryptResultDelegate cb); /// /// Delegate for the function called back to by the sovrin_decrypt function. /// /// The handle for the command that initiated the callback. /// The outcome of execution of the command. - /// The decrypted message. - internal delegate void DecryptResultDelegate(int command_handle, int err, string decrypted_msg); + /// The decrypted message as an array of bytes. + /// The length of the decrypted message byte array. + internal delegate void DecryptResultDelegate(int command_handle, int err, IntPtr decrypted_msg_raw, int decrypted_msg_len); // anoncreds.rs diff --git a/wrappers/dotnet/indy-sdk-dotnet/Wrapper/Ledger.cs b/wrappers/dotnet/indy-sdk-dotnet/Wrapper/Ledger.cs index e39cb91175..894719dd25 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/Wrapper/Ledger.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/Wrapper/Ledger.cs @@ -35,6 +35,44 @@ public sealed class Ledger : AsyncWrapperBase }; + /// + /// Gets the callback to use when the command for SignRequestAsync has completed. + /// + private static SignRequestResultDelegate _signRequestCallback = (xCommandHandle, err, signature) => + { + var taskCompletionSource = RemoveTaskCompletionSource(xCommandHandle); + + if (!CheckCallback(taskCompletionSource, err)) + return; + + taskCompletionSource.SetResult(signature); + }; + + + /// + /// Signs a request. + /// + /// The wallet to use for signing. + /// The DID of the submitter. + /// The request JSON to sign. + /// An asynchronous task that returns the signed message. + public static Task SignRequestAsync(Wallet wallet, string submitterDid, string requestJson) + { + var taskCompletionSource = new TaskCompletionSource(); + var commandHandle = AddTaskCompletionSource(taskCompletionSource); + + int result = IndyNativeMethods.indy_sign_request( + commandHandle, + wallet.Handle, + submitterDid, + requestJson, + _signRequestCallback); + + CheckResult(result); + + return taskCompletionSource.Task; + } + /// /// Signs and submits a request to the ledger. /// @@ -44,7 +82,7 @@ public sealed class Ledger : AsyncWrapperBase /// The request to sign and submit. /// An asynchronous Task that returns the submit result. public static Task SignAndSubmitRequestAsync(Pool pool, Wallet wallet, string submitterDid, string requstJson) - { + { var taskCompletionSource = new TaskCompletionSource(); var commandHandle = AddTaskCompletionSource(taskCompletionSource); @@ -53,7 +91,7 @@ public static Task SignAndSubmitRequestAsync(Pool pool, Wallet wallet, s pool.Handle, wallet.Handle, submitterDid, - requstJson, + requstJson, _submitRequestCallback ); @@ -357,9 +395,9 @@ public static Task BuildGetTxnRequestAsync(string submitterDid, int data data, _buildRequestCallback); - CheckResult(result); + CheckResult(result); - return taskCompletionSource.Task; + return taskCompletionSource.Task; + } } } -} diff --git a/wrappers/dotnet/indy-sdk-dotnet/Wrapper/Signus.cs b/wrappers/dotnet/indy-sdk-dotnet/Wrapper/Signus.cs index 55c2539c15..60e14f0977 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/Wrapper/Signus.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/Wrapper/Signus.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Runtime.InteropServices; +using System.Threading.Tasks; using static Indy.Sdk.Dotnet.IndyNativeMethods; namespace Indy.Sdk.Dotnet.Wrapper @@ -41,16 +42,20 @@ public sealed class Signus : AsyncWrapperBase /// /// Gets the callback to use when the command for SignAsync has completed. /// - private static SignResultDelegate _signCallback = (xCommandHandle, err, signature) => + private static SignResultDelegate _signCallback = (xCommandHandle, err, signature_raw, signature_len) => { - var taskCompletionSource = RemoveTaskCompletionSource(xCommandHandle); + var taskCompletionSource = RemoveTaskCompletionSource(xCommandHandle); if (!CheckCallback(taskCompletionSource, err)) return; - taskCompletionSource.SetResult(signature); + var bytes = new byte[signature_len]; + Marshal.Copy(signature_raw, bytes, 0, signature_len); + + taskCompletionSource.SetResult(bytes); }; + /// /// Gets the callback to use when the command for VerifySignatureAsync has completed. /// @@ -67,14 +72,20 @@ public sealed class Signus : AsyncWrapperBase /// /// Gets the callback to use when the command for EncryptAsync has completed. /// - private static EncryptResultDelegate _encryptCallback = (xCommandHandle, err, encryptedMsg, nonce) => + private static EncryptResultDelegate _encryptCallback = (xCommandHandle, err, encrypted_msg_raw, encrypted_msg_len, nonce, nonce_len) => { var taskCompletionSource = RemoveTaskCompletionSource(xCommandHandle); if (!CheckCallback(taskCompletionSource, err)) return; - var callbackResult = new EncryptResult(encryptedMsg, nonce); + var encryptedMessageBytes = new byte[encrypted_msg_len]; + Marshal.Copy(encrypted_msg_raw, encryptedMessageBytes, 0, encrypted_msg_len); + + var nonceBytes = new byte[nonce_len]; + Marshal.Copy(nonce, nonceBytes, 0, nonce_len); + + var callbackResult = new EncryptResult(encryptedMessageBytes, nonceBytes); taskCompletionSource.SetResult(callbackResult); }; @@ -82,14 +93,17 @@ public sealed class Signus : AsyncWrapperBase /// /// Gets the callback to use when the command for DecryptAsync has completed. /// - private static DecryptResultDelegate _decryptCallback = (xCommandHandle, err, decryptedMsg) => + private static DecryptResultDelegate _decryptCallback = (xCommandHandle, err, decrypted_msg_raw, decrypted_msg_len) => { - var taskCompletionSource = RemoveTaskCompletionSource(xCommandHandle); + var taskCompletionSource = RemoveTaskCompletionSource(xCommandHandle); if (!CheckCallback(taskCompletionSource, err)) return; - taskCompletionSource.SetResult(decryptedMsg); + var decryptedMsgBytes = new byte[decrypted_msg_len]; + Marshal.Copy(decrypted_msg_raw, decryptedMsgBytes, 0, decrypted_msg_len); + + taskCompletionSource.SetResult(decryptedMsgBytes); }; @@ -168,9 +182,9 @@ public static Task StoreTheirDidAsync(Wallet wallet, string identityJson) /// The did to sign with. /// The message to sign. /// An asynchronous task that returns the signed message. - public static Task SignAsync(Wallet wallet, string did, string msg) + public static Task SignAsync(Wallet wallet, string did, byte[] msg) { - var taskCompletionSource = new TaskCompletionSource(); + var taskCompletionSource = new TaskCompletionSource(); var commandHandle = AddTaskCompletionSource(taskCompletionSource); var commandResult = IndyNativeMethods.indy_sign( @@ -178,6 +192,7 @@ public static Task SignAsync(Wallet wallet, string did, string msg) wallet.Handle, did, msg, + msg.Length, _signCallback ); @@ -186,15 +201,17 @@ public static Task SignAsync(Wallet wallet, string did, string msg) return taskCompletionSource.Task; } + /// /// Verifies a signed message. /// /// The wallet containing the DID of the signed message. /// The ledger pool to verify the message against. /// The did the message is associated with. - /// The signed message to verify. + /// The message to verify. + /// The signature to verify. /// An asynchronous task that returns true if the message is valid, otherwise false. - public static Task VerifySignatureAsync(Wallet wallet, Pool pool, string did, string signedMsg) + public static Task VerifySignatureAsync(Wallet wallet, Pool pool, string did, byte[] msg, byte[]signature) { var taskCompletionSource = new TaskCompletionSource(); var commandHandle = AddTaskCompletionSource(taskCompletionSource); @@ -204,7 +221,10 @@ public static Task VerifySignatureAsync(Wallet wallet, Pool pool, string d wallet.Handle, pool.Handle, did, - signedMsg, + msg, + msg.Length, + signature, + signature.Length, _verifySignatureCallback ); @@ -222,7 +242,7 @@ public static Task VerifySignatureAsync(Wallet wallet, Pool pool, string d /// The did to encrypt for. /// The message to encrypt. /// An asynchronous task that returns an EncryptResult. - public static Task EncryptAsync(Wallet wallet, Pool pool, string my_did, string did, string msg) + public static Task EncryptAsync(Wallet wallet, Pool pool, string my_did, string did, byte[] msg) { var taskCompletionSource = new TaskCompletionSource(); var commandHandle = AddTaskCompletionSource(taskCompletionSource); @@ -234,6 +254,7 @@ public static Task EncryptAsync(Wallet wallet, Pool pool, string my_did, did, msg, + msg.Length, _encryptCallback); CheckResult(commandResult); @@ -250,9 +271,9 @@ public static Task EncryptAsync(Wallet wallet, Pool pool, string /// The message to decrypt. /// The nonce. /// An asynchronous task that returns the decrypted message. - public static Task DecryptAsync(Wallet wallet, string my_did, string did, string encryptedMsg, string nonce) + public static Task DecryptAsync(Wallet wallet, string my_did, string did, byte[] encryptedMsg, byte[] nonce) { - var taskCompletionSource = new TaskCompletionSource(); + var taskCompletionSource = new TaskCompletionSource(); var commandHandle = AddTaskCompletionSource(taskCompletionSource); var commandResult = IndyNativeMethods.indy_decrypt( @@ -261,7 +282,9 @@ public static Task DecryptAsync(Wallet wallet, string my_did, string did my_did, did, encryptedMsg, + encryptedMsg.Length, nonce, + nonce.Length, _decryptCallback ); diff --git a/wrappers/dotnet/indy-sdk-dotnet/Wrapper/SignusResults.cs b/wrappers/dotnet/indy-sdk-dotnet/Wrapper/SignusResults.cs index dfc697322b..3eab92af36 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/Wrapper/SignusResults.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/Wrapper/SignusResults.cs @@ -73,7 +73,7 @@ public class EncryptResult /// /// The encrypted message. /// The nonce. - internal EncryptResult(string encryptedMsg, string nonce) + internal EncryptResult(byte[] encryptedMsg, byte[] nonce) { EncryptedMsg = encryptedMsg; Nonce = nonce; @@ -82,12 +82,12 @@ internal EncryptResult(string encryptedMsg, string nonce) /// /// Gets the encrypted message. /// - public string EncryptedMsg { get; } + public byte[] EncryptedMsg { get; } /// /// Gets the nonce. /// - public string Nonce { get; } + public byte[] Nonce { get; } } } diff --git a/wrappers/dotnet/indy-sdk-dotnet/Wrapper/Wallet.cs b/wrappers/dotnet/indy-sdk-dotnet/Wrapper/Wallet.cs index 6c85446a41..c2491a81bd 100644 --- a/wrappers/dotnet/indy-sdk-dotnet/Wrapper/Wallet.cs +++ b/wrappers/dotnet/indy-sdk-dotnet/Wrapper/Wallet.cs @@ -14,7 +14,7 @@ public sealed class Wallet : AsyncWrapperBase, IDisposable /// /// Wallet type registrations by type name. /// - private static IDictionary _registeredWalletTypes = new ConcurrentDictionary(); + private static ConcurrentBag _registeredWalletTypes = new ConcurrentBag(); /// /// Gets the callback to use when a wallet open command has completed. @@ -36,11 +36,11 @@ public sealed class Wallet : AsyncWrapperBase, IDisposable /// The type type. /// An asynchronous Task with no return value. public static Task RegisterWalletTypeAsync(string xType, WalletType walletType) - { + { var taskCompletionSource = new TaskCompletionSource(); var commandHandle = AddTaskCompletionSource(taskCompletionSource); - _registeredWalletTypes[xType] = walletType; + _registeredWalletTypes.Add(walletType); var result = IndyNativeMethods.indy_register_wallet_type( commandHandle, diff --git a/doc/ios-build.md b/wrappers/ios/ios-build.md similarity index 100% rename from doc/ios-build.md rename to wrappers/ios/ios-build.md diff --git a/ci/java.dockerfile b/wrappers/java/ci/java.dockerfile similarity index 78% rename from ci/java.dockerfile rename to wrappers/java/ci/java.dockerfile index dd62913b89..1f979dfbb8 100755 --- a/ci/java.dockerfile +++ b/wrappers/java/ci/java.dockerfile @@ -11,7 +11,7 @@ RUN apt-get install -y \ gdebi \ apt-utils -ADD https://repo.evernym.com/deb/indy-sdk/0.1.1-116/indy-sdk_0.1.1_amd64.deb . +ADD https://repo.evernym.com/libindy/ubuntu/master/0.1.1-119/indy-sdk_0.1.1_amd64.deb . RUN gdebi -n indy-sdk_0.1.1_amd64.deb 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 e187e70a2a..9e3d365f48 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 @@ -58,10 +58,10 @@ public interface API extends Library { public int indy_create_and_store_my_did(int command_handle, int wallet_handle, String did_json, Callback cb); public int indy_replace_keys(int command_handle, int wallet_handle, String did, String identity_json, Callback cb); public int indy_store_their_did(int command_handle, int wallet_handle, String identity_json, Callback cb); - public int indy_sign(int command_handle, int wallet_handle, String did, String msg, Callback cb); - public int indy_verify_signature(int command_handle, int wallet_handle, int pool_handle, String did, String msg, String signature, Callback cb); - public int indy_encrypt(int command_handle, int wallet_handle, int pool_handle, String myDid, String did, String msg, Callback cb); - public int indy_decrypt(int command_handle, int wallet_handle, String myDid, String did, String encrypted_msg, String nonce, Callback cb); + public int indy_sign(int command_handle, int wallet_handle, String did, byte[] message_raw, int message_len, Callback cb); + public int indy_verify_signature(int command_handle, int wallet_handle, int pool_handle, String did, byte[] message_raw, int message_len, byte[] signature_raw, int signature_len, Callback cb); + public int indy_encrypt(int command_handle, int wallet_handle, int pool_handle, String my_did, String did, byte[] message_raw, int message_len, Callback cb); + public int indy_decrypt(int command_handle, int wallet_handle, String myDid, String did, byte[] encrypted_msg_raw, int encrypted_msg_len, byte[] nonce_raw, int nonce_len, Callback cb); // anoncreds.rs diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java index efe059384b..4a23dc1b2d 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/Signus.java @@ -7,11 +7,12 @@ import org.hyperledger.indy.sdk.LibIndy; import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; -import org.hyperledger.indy.sdk.signus.SignusResults.ReplaceKeysResult; import org.hyperledger.indy.sdk.signus.SignusResults.EncryptResult; +import org.hyperledger.indy.sdk.signus.SignusResults.ReplaceKeysResult; import org.hyperledger.indy.sdk.wallet.Wallet; import com.sun.jna.Callback; +import com.sun.jna.Pointer; /** * signus.rs API @@ -84,12 +85,13 @@ public void callback(int xcommand_handle, int err) { private static Callback signCb = new Callback() { @SuppressWarnings({"unused", "unchecked"}) - public void callback(int xcommand_handle, int err, String signature) { + public void callback(int xcommand_handle, int err, Pointer signature_raw, int signature_len) { - CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); if (! checkCallback(future, err)) return; - String result = signature; + byte[] result = new byte[signature_len]; + signature_raw.read(0, result, 0, signature_len); future.complete(result); } }; @@ -116,11 +118,17 @@ public void callback(int xcommand_handle, int err, boolean valid) { private static Callback encryptCb = new Callback() { @SuppressWarnings({"unused", "unchecked"}) - public void callback(int xcommand_handle, int err, String encryptedMsg, String nonce) { + 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; + byte[] encryptedMsg = new byte[encrypted_msg_len]; + encrypted_msg_raw.read(0, encryptedMsg, 0, encrypted_msg_len); + + byte[] nonce = new byte[nonce_len]; + nonce_raw.read(0, nonce, 0, nonce_len); + EncryptResult result = new EncryptResult(encryptedMsg, nonce); future.complete(result); } @@ -132,12 +140,13 @@ public void callback(int xcommand_handle, int err, String encryptedMsg, String n private static Callback decryptCb = new Callback() { @SuppressWarnings({"unused", "unchecked"}) - public void callback(int xcommand_handle, int err, String decryptedMsg) { + public void callback(int xcommand_handle, int err, Pointer decrypted_msg_raw, int decrypted_msg_len) { - CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); + CompletableFuture future = (CompletableFuture) removeFuture(xcommand_handle); if (! checkCallback(future, err)) return; - String result = decryptedMsg; + byte[] result = new byte[decrypted_msg_len]; + decrypted_msg_raw.read(0, result, 0, decrypted_msg_len); future.complete(result); } }; @@ -238,16 +247,16 @@ public static CompletableFuture storeTheirDid( * * @param wallet The wallet. * @param did signing DID - * @param msg a message to be signed + * @param message a message to be signed * @return A future that resolves to a a signature string. * @throws IndyException Thrown if an error occurs when calling the underlying SDK. */ - public static CompletableFuture sign( + public static CompletableFuture sign( Wallet wallet, String did, - String msg) throws IndyException { + byte[] message) throws IndyException { - CompletableFuture future = new CompletableFuture(); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -256,7 +265,8 @@ public static CompletableFuture sign( commandHandle, walletHandle, did, - msg, + message, + message.length, signCb); checkResult(result); @@ -270,7 +280,7 @@ public static CompletableFuture sign( * @param wallet The wallet. * @param pool The pool. * @param did DID that signed the message - * @param msg message + * @param message message * @param signature a signature to be verified * @return A future that resolves to true if signature is valid, otherwise false. * @throws IndyException Thrown if an error occurs when calling the underlying SDK. @@ -279,8 +289,8 @@ public static CompletableFuture verifySignature( Wallet wallet, Pool pool, String did, - String msg, - String signature) throws IndyException { + byte[] message, + byte[] signature) throws IndyException { CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); @@ -293,8 +303,10 @@ public static CompletableFuture verifySignature( walletHandle, poolHandle, did, - msg, + message, + message.length, signature, + signature.length, verifySignatureCb); checkResult(result); @@ -309,7 +321,7 @@ public static CompletableFuture verifySignature( * @param pool The pool. * @param myDid encrypting DID * @param did encrypting DID - * @param msg a message to be signed + * @param message a message to be signed * @return A future that resolves to a JSON string containing an encrypted message and nonce. * @throws IndyException Thrown if an error occurs when calling the underlying SDK. */ @@ -318,7 +330,7 @@ public static CompletableFuture encrypt( Pool pool, String myDid, String did, - String msg) throws IndyException { + byte[] message) throws IndyException { CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); @@ -332,7 +344,8 @@ public static CompletableFuture encrypt( poolHandle, myDid, did, - msg, + message, + message.length, encryptCb); checkResult(result); @@ -351,14 +364,14 @@ public static CompletableFuture encrypt( * @return A future that resolves to a JSON string containing the decrypted message. * @throws IndyException Thrown if an error occurs when calling the underlying SDK. */ - public static CompletableFuture decrypt( + public static CompletableFuture decrypt( Wallet wallet, String myDid, String did, - String encryptedMsg, - String nonce) throws IndyException { + byte[] encryptedMsg, + byte[] nonce) throws IndyException { - CompletableFuture future = new CompletableFuture(); + CompletableFuture future = new CompletableFuture(); int commandHandle = addFuture(future); int walletHandle = wallet.getWalletHandle(); @@ -369,7 +382,9 @@ public static CompletableFuture decrypt( myDid, did, encryptedMsg, + encryptedMsg.length, nonce, + nonce.length, decryptCb); checkResult(result); diff --git a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/SignusResults.java b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/SignusResults.java index 5a534b18db..60e79003b4 100644 --- a/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/SignusResults.java +++ b/wrappers/java/src/main/java/org/hyperledger/indy/sdk/signus/SignusResults.java @@ -72,21 +72,21 @@ public static class ReplaceKeysResult extends IndyJava.Result { */ public static class EncryptResult extends IndyJava.Result { - private String encryptedMessage, nonce; - EncryptResult(String encryptedMessage, String nonce) { this.encryptedMessage = encryptedMessage; this.nonce = nonce; } + private byte[] encryptedMessage, nonce; + EncryptResult(byte[] encryptedMessage, byte[] nonce) { this.encryptedMessage = encryptedMessage; this.nonce = nonce; } /** * Gets the encrypted message. * * @return The encrypted message. */ - public String getEncryptedMessage() { return this.encryptedMessage; } + public byte[] getEncryptedMessage() { return this.encryptedMessage; } /** * Gets the nonce. * * @return The nonce. */ - public String getNonce() { return this.nonce; } + public byte[] getNonce() { return this.nonce; } } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/SignusDemoTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/SignusDemoTest.java index fb75863105..63d011468f 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/SignusDemoTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/demo/SignusDemoTest.java @@ -4,6 +4,7 @@ import org.hyperledger.indy.sdk.pool.Pool; import org.hyperledger.indy.sdk.pool.PoolJSONParameters; import org.hyperledger.indy.sdk.signus.Signus; +import org.hyperledger.indy.sdk.signus.SignusResults; import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; import org.hyperledger.indy.sdk.utils.PoolUtils; import org.hyperledger.indy.sdk.wallet.Wallet; @@ -63,11 +64,10 @@ public void testSignusDemo() throws Exception { " }\n" + " }"; - String signature = Signus.sign(theirWallet, theirDid, msg).get(); - assertNotNull(signature); + byte[] signature = Signus.sign(theirWallet, theirDid, msg.getBytes()).get(); // 8. I verify message - Boolean valid = Signus.verifySignature(myWallet, pool, theirDid, msg, signature).get(); + Boolean valid = Signus.verifySignature(myWallet, pool, theirDid, msg.getBytes(), signature).get(); assertTrue(valid); // 9. Close and delete My Wallet diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/DecryptTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/DecryptTest.java index 07e2daeeec..8bcdd1ffaf 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/DecryptTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/DecryptTest.java @@ -12,10 +12,12 @@ import org.junit.Before; import org.junit.Test; +import java.util.Arrays; import java.util.concurrent.ExecutionException; import static org.hyperledger.indy.sdk.utils.PoolUtils.DEFAULT_POOL_NAME; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public class DecryptTest extends IndyIntegrationTest { @@ -26,9 +28,9 @@ public class DecryptTest extends IndyIntegrationTest { private String myDid; private String myVerkey; private String walletName = "signusWallet"; - private String msg = "{\"reqId\":1496822211362017764}"; - private String encrypted_message = "4SWFzd3sx7xNemZEtktt3s558Fa28fGbauAZv9NRQjQhHq9bwT8uBnACQJAKzZ"; - private String nonce = "Dd3vSQgDdADJGoxb6BPcWU6wkEMqSeFwv"; + private byte[] msg = "{\"reqId\":1496822211362017764}".getBytes(); + private byte[] encryptedMessage = {-105, 30, 89, 75, 76, 28, -59, -45, 105, -46, 20, 124, -85, -13, 109, 29, -88, -82, -8, -6, -50, -84, -53, -48, -49, 56, 124, 114, 82, 126, 74, 99, -72, -78, -117, 96, 60, 119, 50, -40, 121, 21, 57, -68, 89}; + private byte[] nonce = {-14, 102, -41, -57, 1, 4, 75, -46, -91, 87, 14, 41, -39, 48, 42, -126, -121, 84, -58, 59, -27, 51, -32, -23}; private String identityJsonTemplate = "{\"did\":\"%s\",\"verkey\":\"%s\"}"; @Before @@ -69,8 +71,9 @@ public void testDecryptWorks() throws Exception { String identityJson = String.format(identityJsonTemplate, trusteeDid, trusteeVerkey); Signus.storeTheirDid(wallet, identityJson).get(); - String decryptedMessage = Signus.decrypt(wallet, myDid, trusteeDid, encrypted_message, nonce).get(); - assertEquals(msg, decryptedMessage); + byte[] decryptedMessage = Signus.decrypt(wallet, myDid, trusteeDid, encryptedMessage, nonce).get(); + assertTrue(Arrays.equals(msg, decryptedMessage)); + } @Test @@ -97,9 +100,9 @@ public void testDecryptWorksForNonceNotCorrespondMessage() throws Exception { String identityJson = String.format(identityJsonTemplate, trusteeDid, trusteeVerkey); Signus.storeTheirDid(wallet, identityJson).get(); - String nonce = "acS2SQgDdfE3Goxa1AhcWCa4kEMqSelv7"; + byte[] nonce = {46, 33, -4, 67, 1, 44, 57, -46, -91, 87, 14, 41, -39, 48, 42, -126, -121, 84, -58, 59, -27, 51, -32, -23}; - Signus.decrypt(wallet, myDid, trusteeDid, encrypted_message, nonce).get(); + Signus.decrypt(wallet, myDid, trusteeDid, encryptedMessage, nonce).get(); } @Test @@ -110,6 +113,6 @@ public void testDecryptWorksForUnknownMyDid() throws Exception { String identityJson = String.format(identityJsonTemplate, trusteeDid, trusteeVerkey); Signus.storeTheirDid(wallet, identityJson).get(); - Signus.decrypt(wallet, "unknowDid", trusteeDid, encrypted_message, nonce).get(); + Signus.decrypt(wallet, "unknowDid", trusteeDid, encryptedMessage, nonce).get(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/EncryptTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/EncryptTest.java index 5d45bb3fb4..2663b73e82 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/EncryptTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/EncryptTest.java @@ -26,7 +26,7 @@ public class EncryptTest extends IndyIntegrationTest { private String did; private String verkey; private String walletName = "signusWallet"; - private String msg = "{\"reqId\":1496822211362017764}"; + private byte[] msg = "{\"reqId\":1496822211362017764}".getBytes(); @Before public void before() throws Exception { diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java index 01d8382260..8b66d7d14f 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/SignTest.java @@ -6,12 +6,13 @@ import org.hyperledger.indy.sdk.signus.SignusResults.CreateAndStoreMyDidResult; import org.hyperledger.indy.sdk.wallet.Wallet; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.junit.After; import org.junit.Before; import org.junit.Test; +import java.util.Arrays; import java.util.concurrent.ExecutionException; public class SignTest extends IndyIntegrationTest { @@ -19,6 +20,7 @@ public class SignTest extends IndyIntegrationTest { private Wallet wallet; private String walletName = "signusWallet"; + private byte[] msg = "{\"reqId\":1496822211362017764}".getBytes(); @Before public void createWalletWhitDid() throws Exception { @@ -36,18 +38,17 @@ public void deleteWallet() throws Exception { public void testSignWorks() throws Exception { SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, TRUSTEE_SEED, null, null); + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(this.wallet, didJson.toJson()).get(); - String did = result.getDid(); - String msg = "{\"reqId\":1496822211362017764}"; + byte[] expectedSignature = {- 87, - 41, 8, - 31, 7, 107, 110, 9, - 63, - 94, - 54, - 42, - 94, 66, - 18, - 45, 63, - 47, 12, - 60, 8, - 45, 55, 27, 120, 94, + - 52, - 109, 53, 104, 103, 61, 60, - 7, - 19, 127, 103, 46, - 36, - 33, 10, 95, 75, 53, - 11, - 46, - 15, - 105, - 65, 41, 48, 30, 9, 16, 78, - 4, + - 99, - 50, - 46, - 111, 125, - 123, 109, 11}; - String expectedSignature = "R4Rj68n4HZosQqEc3oMUbQh7MtG8tH7WmXE2Mok8trHJ67CrzyqahZn5ziJy4nebRtq6Qi6fVH9JkvVCM85XjFa"; + byte[] signature = Signus.sign(this.wallet, result.getDid(), msg).get(); - String signedMessage = Signus.sign(this.wallet, did, msg).get(); - - assertEquals(expectedSignature, signedMessage); + assertTrue(Arrays.equals(expectedSignature, signature)); } @Test @@ -55,8 +56,6 @@ public void testSignWorksForUnknowDid() throws Exception { thrown.expect(ExecutionException.class); thrown.expectCause(new ErrorCodeMatcher(ErrorCode.WalletNotFoundError)); - String msg = "{\"reqId\":1496822211362017764}"; - Signus.sign(this.wallet, "8wZcEriaNLNKtteJvx7f8i", msg).get(); } } diff --git a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java index 8b2916852a..dc188bc660 100644 --- a/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java +++ b/wrappers/java/src/test/java/org/hyperledger/indy/sdk/signus/VerifyTest.java @@ -11,6 +11,8 @@ import org.junit.Before; import org.junit.Test; +import java.io.UnsupportedEncodingException; + import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -22,8 +24,13 @@ public class VerifyTest extends IndyIntegrationTest { private String trusteeDid; private String trusteeVerkey; private String identityJson; - private String newDid; + private String myDid; + private String myVerkey; private String walletName = "signusWallet"; + private byte[] msg = "{\"reqId\":1496822211362017764}".getBytes(); + private byte[] signature = {-87, -41, 8, -31, 7, 107, 110, 9, -63, -94, -54, -42, -94, 66, -18, -45, 63, -47, 12, -60, 8, -45, 55, 27, 120, 94, -52, -109, 53, 104, + 103, 61, 60, -7, -19, 127, 103, 46, -36, -33, 10, 95, 75, 53, -11, -46, -15, -105, -65, 41, 48, 30, 9, 16, 78, -4, -99, -50, -46, -111, 125, -123, 109, 11}; + @Before public void createWalletWithDid() throws Exception { @@ -43,6 +50,16 @@ public void createWalletWithDid() throws Exception { trusteeDid = result.getDid(); trusteeVerkey = result.getVerkey(); + + SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson2 = + new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); + + CreateAndStoreMyDidResult result2 = Signus.createAndStoreMyDid(wallet, didJson2.toJson()).get(); + myDid = result2.getDid(); + myVerkey = result2.getVerkey(); + + String nymRequest = Ledger.buildNymRequest(trusteeDid, myDid, myVerkey, null, null).get(); + Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); } @After @@ -52,52 +69,27 @@ public void deleteWallet() throws Exception { pool.closePoolLedger().get(); } - private void createNewNymWithDidInLedger() throws Exception { - SignusJSONParameters.CreateAndStoreMyDidJSONParameter didJson = - new SignusJSONParameters.CreateAndStoreMyDidJSONParameter(null, "00000000000000000000000000000My1", null, null); - - CreateAndStoreMyDidResult result = Signus.createAndStoreMyDid(wallet, didJson.toJson()).get(); - newDid = result.getDid(); - String newVerkey = result.getVerkey(); - - String nymRequest = Ledger.buildNymRequest(trusteeDid, newDid, newVerkey, null, null).get(); - Ledger.signAndSubmitRequest(pool, wallet, trusteeDid, nymRequest).get(); - } - @Test public void testVerifyWorksForVerkeyCachedInWallet() throws Exception { - identityJson = String.format("{\"did\":\"%s\",\"verkey\":\"%s\"}", trusteeDid, trusteeVerkey); + identityJson = String.format("{\"did\":\"%s\",\"verkey\":\"%s\"}", myDid, myVerkey); Signus.storeTheirDid(wallet, identityJson).get(); - String msg = "{\"reqId\":1496822211362017764}"; - - String signature = "R4Rj68n4HZosQqEc3oMUbQh7MtG8tH7WmXE2Mok8trHJ67CrzyqahZn5ziJy4nebRtq6Qi6fVH9JkvVCM85XjFa"; - - Boolean valid = Signus.verifySignature(wallet, pool, trusteeDid, msg, signature).get(); + Boolean valid = Signus.verifySignature(wallet, pool, myDid, msg, signature).get(); assertTrue(valid); } @Test public void testVerifyWorksForGetVerkeyFromLedger() throws Exception { - createNewNymWithDidInLedger(); - Signus.storeTheirDid(wallet, String.format("{\"did\":\"%s\"}", newDid)).get(); + Signus.storeTheirDid(wallet, String.format("{\"did\":\"%s\"}", myDid)).get(); - String msg = "{\"reqId\":1496822211362017764}"; - - String signature = "4Pwx83PGrDNPa1wonqLnQkzBEeFwMt8a8AKM3s86RMTW2ty6XV8Zk98Tg4UfYYXoEs3cCp4wUxGNvAfvurUDb24A"; - Boolean valid = Signus.verifySignature(wallet, pool, newDid, msg, signature).get(); + Boolean valid = Signus.verifySignature(wallet, pool, myDid, msg, signature).get(); assertTrue(valid); } @Test public void testVerifyWorksForGetNymFromLedger() throws Exception { - createNewNymWithDidInLedger(); - String msg = "{\"reqId\":1496822211362017764}"; - - String signature = "4Pwx83PGrDNPa1wonqLnQkzBEeFwMt8a8AKM3s86RMTW2ty6XV8Zk98Tg4UfYYXoEs3cCp4wUxGNvAfvurUDb24A"; - - Boolean valid = Signus.verifySignature(wallet, pool, newDid, msg, signature).get(); + Boolean valid = Signus.verifySignature(wallet, pool, myDid, msg, signature).get(); assertTrue(valid); } @@ -120,9 +112,9 @@ public void testVerifyWorksForOtherSigner() throws Exception { String msg = "{\"reqId\":1496822211362017764}"; - String signature = Signus.sign(wallet, trusteeDid, msg).get(); + byte[] signature = Signus.sign(wallet, trusteeDid, msg.getBytes()).get(); - Boolean valid = Signus.verifySignature(wallet, pool, stewardDid, msg, signature).get(); + Boolean valid = Signus.verifySignature(wallet, pool, stewardDid, msg.getBytes(), signature).get(); assertFalse(valid); } diff --git a/wrappers/python/README.md b/wrappers/python/README.md new file mode 100644 index 0000000000..2df1f4e604 --- /dev/null +++ b/wrappers/python/README.md @@ -0,0 +1,36 @@ + + +## Indy SDK for Python + +This is a Python wrapper for [Indy](https://www.hyperledger.org/projects/indy). It is implemented using a foreign function interface (FFI) to a native library written in Rust. Indy is the +open-source codebase behind the Sovrin network for self-sovereign digital identity. + +This Python wrapper currently requires python 3.6. + +Pull requests welcome! + +### How to build + +- Install native "indy" library: + * Ubuntu: https://repo.evernym.com/libindy/ubuntu/ + * Windows: https://repo.evernym.com/libindy/windows/ + +- Clone indy-sdk repo from https://github.com/hyperledger/indy-sdk + +- Move to python wrapper directory +``` + cd wrappers/python +``` +- Create virtual env if you want + +- Install dependencies with pip install + +Then run + +- Start local nodes pool on 127.0.0.1:9701-9708 with Docker (for now just follow same point in platform-specific instructions for libindy) + +- Execute tests with pytest + + +### Example use +For the main workflow examples check tests in demo folder: https://github.com/hyperledger/indy-sdk/tree/master/wrappers/python/tests/demo diff --git a/ci/python-wrapper-update-package-version.sh b/wrappers/python/ci/python-wrapper-update-package-version.sh similarity index 100% rename from ci/python-wrapper-update-package-version.sh rename to wrappers/python/ci/python-wrapper-update-package-version.sh diff --git a/ci/python.dockerfile b/wrappers/python/ci/python.dockerfile similarity index 86% rename from ci/python.dockerfile rename to wrappers/python/ci/python.dockerfile index 606b21643c..1ab8b4e7e1 100755 --- a/ci/python.dockerfile +++ b/wrappers/python/ci/python.dockerfile @@ -18,7 +18,7 @@ RUN apt-get update && \ python3.6 \ python3-pip -ADD https://repo.evernym.com/deb/indy-sdk/0.1.1-116/indy-sdk_0.1.1_amd64.deb . +ADD https://repo.evernym.com/libindy/ubuntu/master/0.1.1-119/indy-sdk_0.1.1_amd64.deb . RUN gdebi -n indy-sdk_0.1.1_amd64.deb diff --git a/wrappers/python/indy/libindy.py b/wrappers/python/indy/libindy.py index 4313269840..94a8e6b8df 100644 --- a/wrappers/python/indy/libindy.py +++ b/wrappers/python/indy/libindy.py @@ -34,11 +34,16 @@ def do_call(name: str, *args): return future -def create_cb(cb_type: CFUNCTYPE): +def create_cb(cb_type: CFUNCTYPE, transform_fn=None): logger = logging.getLogger(__name__) logger.debug("create_cb: >>> cb_type: %s", cb_type) - res = cb_type(_indy_callback) + def _cb(command_handle: int, err: int, *args): + if transform_fn: + args = transform_fn(*args) + _indy_callback(command_handle, err, *args) + + res = cb_type(_cb) logger.debug("create_cb: <<< res: %s", res) return res diff --git a/wrappers/python/indy/signus.py b/wrappers/python/indy/signus.py index fd3b8514b3..1325a6571d 100644 --- a/wrappers/python/indy/signus.py +++ b/wrappers/python/indy/signus.py @@ -85,10 +85,10 @@ async def replace_keys(wallet_handle: int, c_identity_json = c_char_p(identity_json.encode('utf-8')) verkey, pk = await do_call('indy_replace_keys', - c_wallet_handle, - c_did, - c_identity_json, - replace_keys.cb) + c_wallet_handle, + c_did, + c_identity_json, + replace_keys.cb) res = (verkey.decode(), pk.decode()) @@ -136,7 +136,7 @@ async def store_their_did(wallet_handle: int, async def sign(wallet_handle: int, did: str, - msg: str) -> str: + msg: bytes) -> bytes: """ Signs a message by a signing key associated with my DID. The DID with a signing key must be already created and stored in a secured wallet (see create_and_store_my_identity) @@ -153,31 +153,33 @@ async def sign(wallet_handle: int, did, msg) + def transform_cb(arr_ptr: POINTER(c_uint8), arr_len: c_uint32): + return bytes(arr_ptr[:arr_len]), + if not hasattr(sign, "cb"): logger.debug("sign: Creating callback") - sign.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + sign.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, POINTER(c_uint8), c_uint32), transform_cb) c_wallet_handle = c_int32(wallet_handle) c_did = c_char_p(did.encode('utf-8')) - c_msg = c_char_p(msg.encode('utf-8')) + c_msg_len = c_uint32(len(msg)) - res = await do_call('indy_sign', - c_wallet_handle, - c_did, - c_msg, - sign.cb) - - res = res.decode() + signature = await do_call('indy_sign', + c_wallet_handle, + c_did, + msg, + c_msg_len, + sign.cb) - logger.debug("sign: <<< res: %r", res) - return res + logger.debug("sign: <<< res: %r", signature) + return signature async def verify_signature(wallet_handle: int, pool_handle: int, did: str, - msg: str, - signature: str) -> bool: + msg: bytes, + signature: bytes) -> bool: """ Verify a signature created by a key associated with a DID. If a secure wallet doesn't contain a verkey associated with the given DID, @@ -209,15 +211,17 @@ async def verify_signature(wallet_handle: int, c_wallet_handle = c_int32(wallet_handle) c_pool_handle = c_int32(pool_handle) c_did = c_char_p(did.encode('utf-8')) - c_msg = c_char_p(msg.encode('utf-8')) - c_signature = c_char_p(signature.encode('utf-8')) + c_msg_len = c_uint32(len(msg)) + c_signature_len = c_uint32(len(signature)) res = await do_call('indy_verify_signature', c_wallet_handle, c_pool_handle, c_did, - c_msg, - c_signature, + msg, + c_msg_len, + signature, + c_signature_len, verify_signature.cb) logger.debug("verify_signature: <<< res: %r", res) @@ -228,7 +232,7 @@ async def encrypt(wallet_handle: int, pool_handle: int, my_did: str, did: str, - msg: str) -> (str, str): + msg: bytes) -> (bytes, bytes): """ Encrypts a message by a public key associated with a DID. If a secure wallet doesn't contain a public key associated with the given DID, @@ -253,25 +257,29 @@ async def encrypt(wallet_handle: int, did, msg) + def transform_cb(arr_ptr: POINTER(c_uint8), arr_len: c_uint32, arr_ptr2: POINTER(c_uint8), arr_len2: c_uint32): + return bytes(arr_ptr[:arr_len]), bytes(arr_ptr2[:arr_len2]) + if not hasattr(encrypt, "cb"): logger.debug("encrypt: Creating callback") - encrypt.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p, c_char_p)) + encrypt.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, POINTER(c_uint8), c_uint32, POINTER(c_uint8), + c_uint32), transform_cb) c_wallet_handle = c_int32(wallet_handle) c_pool_handle = c_int32(pool_handle) c_my_did = c_char_p(my_did.encode('utf-8')) c_did = c_char_p(did.encode('utf-8')) - c_msg = c_char_p(msg.encode('utf-8')) + c_msg_len = c_uint32(len(msg)) encrypted_message, nonce = await do_call('indy_encrypt', - c_wallet_handle, - c_pool_handle, - c_my_did, - c_did, - c_msg, - encrypt.cb) - - res = (encrypted_message.decode(), nonce.decode()) + c_wallet_handle, + c_pool_handle, + c_my_did, + c_did, + msg, + c_msg_len, + encrypt.cb) + res = (encrypted_message, nonce) logger.debug("encrypt: <<< res: %r", res) return res @@ -280,8 +288,8 @@ async def encrypt(wallet_handle: int, async def decrypt(wallet_handle: int, my_did: str, did: str, - encrypted_msg: str, - nonce: str) -> str: + encrypted_msg: bytes, + nonce: bytes) -> bytes: """ Decrypts a message encrypted by a public key associated with my DID. The DID with a secret key must be already created and @@ -303,25 +311,28 @@ async def decrypt(wallet_handle: int, encrypted_msg, nonce) + def transform_cb(arr_ptr: POINTER(c_uint8), arr_len: c_uint32): + return bytes(arr_ptr[:arr_len]), + if not hasattr(decrypt, "cb"): logger.debug("decrypt: Creating callback") - decrypt.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, c_char_p)) + decrypt.cb = create_cb(CFUNCTYPE(None, c_int32, c_int32, POINTER(c_uint8), c_uint32), transform_cb) c_wallet_handle = c_int32(wallet_handle) c_my_did = c_char_p(my_did.encode('utf-8')) c_did = c_char_p(did.encode('utf-8')) - c_encrypted_msg = c_char_p(encrypted_msg.encode('utf-8')) - c_nonce = c_char_p(nonce.encode('utf-8')) + c_encrypted_msg_len = c_uint32(len(encrypted_msg)) + c_nonce_len = c_uint32(len(nonce)) decrypted_message = await do_call('indy_decrypt', - c_wallet_handle, - c_my_did, - c_did, - c_encrypted_msg, - c_nonce, - decrypt.cb) - - decrypted_message = decrypted_message.decode() + c_wallet_handle, + c_my_did, + c_did, + encrypted_msg, + c_encrypted_msg_len, + nonce, + c_nonce_len, + decrypt.cb) logger.debug("decrypt: <<< res: %r", decrypted_message) return decrypted_message diff --git a/wrappers/python/tests/signus/test_decrypt.py b/wrappers/python/tests/signus/test_decrypt.py index 03c2aba421..0a954ec2ca 100644 --- a/wrappers/python/tests/signus/test_decrypt.py +++ b/wrappers/python/tests/signus/test_decrypt.py @@ -5,8 +5,11 @@ from indy import IndyError, signus from indy.error import ErrorCode -message = '{"reqId":1496822211362017764}' -encrypted_message = "4SWFzd3sx7xNemZEtktt3s558Fa28fGbauAZv9NRQjQhHq9bwT8uBnACQJAKzZ" +message = '{"reqId":1496822211362017764}'.encode('utf-8') +encrypted_message = bytes([187, 227, 10, 29, 46, 178, 12, 179, 197, 69, 171, 70, 228, 204, 52, 22, 199, 54, 62, 13, 115, 5, + 216, 66, 20, 131, 121, 29, 251, 224, 253, 201, 75, + 73, 225, 237, 219, 133, 35, 217, 131, 135, 232, 129, 32]) +nonce = bytes([242, 246, 53, 153, 106, 37, 185, 65, 212, 14, 109, 131, 200, 169, 94, 110, 51, 47, 101, 89, 0, 171, 105, 183]) @pytest.mark.asyncio @@ -16,7 +19,6 @@ async def test_decrypt_works(wallet_handle, identity_my1, identity_trustee1): await signus.store_their_did(wallet_handle, json.dumps({"did": trustee_did, "verkey": trustee__verkey})) - nonce = "Dd3vSQgDdADJGoxb6BPcWU6wkEMqSeFwv" decrypted_message = await signus.decrypt(wallet_handle, my_did, trustee_did, encrypted_message, nonce) assert message == decrypted_message @@ -29,10 +31,10 @@ async def test_decrypt_works_for_other_coder(pool_handle, wallet_handle, identit await signus.store_their_did(wallet_handle, json.dumps({"did": trustee_did, "verkey": trustee__verkey})) await signus.store_their_did(wallet_handle, json.dumps({"did": my_did, "verkey": my_verkey})) - (encrypted_msg, nonce) = await signus.encrypt(wallet_handle, pool_handle, my_did, my_did, message) + (encrypted_msg, local_nonce) = await signus.encrypt(wallet_handle, pool_handle, my_did, my_did, message) with pytest.raises(IndyError) as e: - await signus.decrypt(wallet_handle, my_did, trustee_did, encrypted_msg, nonce) + await signus.decrypt(wallet_handle, my_did, trustee_did, encrypted_msg, local_nonce) assert ErrorCode.CommonInvalidStructure == e.value.error_code @@ -42,10 +44,11 @@ async def test_decrypt_works_for_nonce_not_correspond_message(wallet_handle, ide (my_did, _) = identity_my1 await signus.store_their_did(wallet_handle, json.dumps({"did": trustee_did, "verkey": trustee__verkey})) - nonce = "acS2SQgDdfE3Goxa1AhcWCa4kEMqSelv7" + local_nonce = bytes( + [1, 2, 3, 4, 5, 6, 7, 65, 212, 14, 109, 131, 200, 169, 94, 110, 51, 47, 101, 89, 0, 171, 105, 183]) with pytest.raises(IndyError) as e: - await signus.decrypt(wallet_handle, my_did, trustee_did, encrypted_message, nonce) + await signus.decrypt(wallet_handle, my_did, trustee_did, encrypted_message, local_nonce) assert ErrorCode.CommonInvalidStructure == e.value.error_code @@ -55,7 +58,6 @@ async def test_decrypt_works_for_invalid_wallet_handle(wallet_handle, identity_m (my_did, _) = identity_my1 await signus.store_their_did(wallet_handle, json.dumps({"did": trustee_did, "verkey": trustee__verkey})) - nonce = "Dd3vSQgDdADJGoxb6BPcWU6wkEMqSeFwv" with pytest.raises(IndyError) as e: await signus.decrypt(wallet_handle + 1, my_did, trustee_did, encrypted_message, nonce) diff --git a/wrappers/python/tests/signus/test_encrypt.py b/wrappers/python/tests/signus/test_encrypt.py index 6b2e8db432..8b892208e5 100644 --- a/wrappers/python/tests/signus/test_encrypt.py +++ b/wrappers/python/tests/signus/test_encrypt.py @@ -7,7 +7,7 @@ from indy import IndyError, signus from indy.error import ErrorCode -message = '{"reqId":1496822211362017764}' +message = '{"reqId":1496822211362017764}'.encode('utf-8') @pytest.mark.asyncio diff --git a/wrappers/python/tests/signus/test_sign.py b/wrappers/python/tests/signus/test_sign.py index 6a8fb6179b..44467949b5 100644 --- a/wrappers/python/tests/signus/test_sign.py +++ b/wrappers/python/tests/signus/test_sign.py @@ -5,13 +5,17 @@ import json import pytest +message = '{"reqId":1496822211362017764}'.encode('utf-8') + @pytest.mark.asyncio -async def test_sign_works(wallet_handle, seed_trustee1): - (did, _, _) = await signus.create_and_store_my_did(wallet_handle, json.dumps({"seed": seed_trustee1})) +async def test_sign_works(wallet_handle, seed_my1): + (did, _, _) = await signus.create_and_store_my_did(wallet_handle, json.dumps({"seed": seed_my1})) - message = '{"reqId":1496822211362017764}' - expected_signature = "R4Rj68n4HZosQqEc3oMUbQh7MtG8tH7WmXE2Mok8trHJ67CrzyqahZn5ziJy4nebRtq6Qi6fVH9JkvVCM85XjFa" + expected_signature = bytes( + [169, 215, 8, 225, 7, 107, 110, 9, 193, 162, 202, 214, 162, 66, 238, 211, 63, 209, 12, 196, 8, 211, 55, 27, 120, + 94, 204, 147, 53, 104, 103, 61, 60, 249, 237, 127, 103, 46, 220, 223, 10, 95, 75, 53, 245, 210, 241, 151, 191, + 41, 48, 30, 9, 16, 78, 252, 157, 206, 210, 145, 125, 133, 109, 11]) signature = await signus.sign(wallet_handle, did, message) assert signature == expected_signature @@ -20,7 +24,7 @@ async def test_sign_works(wallet_handle, seed_trustee1): @pytest.mark.asyncio async def test_sign_works_for_unknown_did(wallet_handle): with pytest.raises(IndyError) as e: - await signus.sign(wallet_handle, '8wZcEriaNLNKtteJvx7f8i', json.dumps({"reqId": 1496822211362017764})) + await signus.sign(wallet_handle, 'unknownDid', message) assert ErrorCode.WalletNotFoundError == e.value.error_code @@ -28,5 +32,5 @@ async def test_sign_works_for_unknown_did(wallet_handle): async def test_sign_works_for_invalid_handle(wallet_handle): with pytest.raises(IndyError) as e: (did, _, _) = await signus.create_and_store_my_did(wallet_handle, '{}') - await signus.sign(wallet_handle + 1, did, json.dumps({"reqId": 1496822211362017764})) + await signus.sign(wallet_handle + 1, did, message) assert ErrorCode.WalletInvalidHandle == e.value.error_code diff --git a/wrappers/python/tests/signus/test_verify_signature.py b/wrappers/python/tests/signus/test_verify_signature.py index 9eb82044d0..948cf5c4a4 100644 --- a/wrappers/python/tests/signus/test_verify_signature.py +++ b/wrappers/python/tests/signus/test_verify_signature.py @@ -7,17 +7,20 @@ from indy import IndyError, ledger, signus, wallet from indy.error import ErrorCode +message = '{"reqId":1496822211362017764}'.encode('utf-8') +signature = bytes( + [169, 215, 8, 225, 7, 107, 110, 9, 193, 162, 202, 214, 162, 66, 238, 211, 63, 209, 12, 196, 8, 211, 55, 27, 120, 94, + 204, 147, 53, 104, 103, 61, 60, 249, 237, 127, 103, 46, 220, 223, 10, 95, 75, 53, 245, 210, 241, 151, 191, 41, 48, + 30, 9, 16, 78, 252, 157, 206, 210, 145, 125, 133, 109, 11]) -@pytest.mark.asyncio -async def test_verify_works_for_verkey_cached_in_wallet(pool_handle, wallet_handle, identity_trustee1): - (trustee_did, trustee__verkey) = identity_trustee1 - await signus.store_their_did(wallet_handle, json.dumps({"did": trustee_did, "verkey": trustee__verkey})) +@pytest.mark.asyncio +async def test_verify_works_for_verkey_cached_in_wallet(pool_handle, wallet_handle, identity_my1): + (my_did, my__verkey) = identity_my1 - message = '{"reqId":1496822211362017764}' - signature = 'R4Rj68n4HZosQqEc3oMUbQh7MtG8tH7WmXE2Mok8trHJ67CrzyqahZn5ziJy4nebRtq6Qi6fVH9JkvVCM85XjFa' + await signus.store_their_did(wallet_handle, json.dumps({"did": my_did, "verkey": my__verkey})) - valid = await signus.verify_signature(wallet_handle, pool_handle, trustee_did, message, signature) + valid = await signus.verify_signature(wallet_handle, pool_handle, my_did, message, signature) assert valid @@ -27,9 +30,6 @@ async def test_verify_works_for_get_verkey_from_ledger(pool_handle, wallet_handl await signus.store_their_did(wallet_handle, json.dumps({"did": my_did})) - message = '{"reqId":1496822211362017764}' - signature = "4Pwx83PGrDNPa1wonqLnQkzBEeFwMt8a8AKM3s86RMTW2ty6XV8Zk98Tg4UfYYXoEs3cCp4wUxGNvAfvurUDb24A" - valid = await signus.verify_signature(wallet_handle, pool_handle, my_did, message, signature) assert valid @@ -37,7 +37,8 @@ async def test_verify_works_for_get_verkey_from_ledger(pool_handle, wallet_handl # noinspection PyUnusedLocal @pytest.mark.asyncio @pytest.mark.parametrize("wallet_runtime_config", ['{"freshness_time":1}']) -async def test_verify_works_for_expired_nym(wallet_handle, pool_handle, identity_trustee1, identity_my1, wallet_runtime_config): +async def test_verify_works_for_expired_nym(wallet_handle, pool_handle, identity_trustee1, identity_my1, + wallet_runtime_config): (trustee_did, _) = identity_trustee1 (my_did, my_verkey) = identity_my1 @@ -46,9 +47,6 @@ async def test_verify_works_for_expired_nym(wallet_handle, pool_handle, identity await signus.store_their_did(wallet_handle, json.dumps({"did": my_did, 'verkey': my_verkey})) - message = '{"reqId":1496822211362017764}' - signature = "4Pwx83PGrDNPa1wonqLnQkzBEeFwMt8a8AKM3s86RMTW2ty6XV8Zk98Tg4UfYYXoEs3cCp4wUxGNvAfvurUDb24A" - await asyncio.sleep(2) valid = await signus.verify_signature(wallet_handle, pool_handle, my_did, message, signature) @@ -60,11 +58,7 @@ async def test_verify_works_for_invalid_wallet(pool_handle, wallet_handle, ident (my_did, _) = identity_my1 with pytest.raises(IndyError) as e: - message = '{"reqId":1496822211362017764}' - signature = "4Pwx83PGrDNPa1wonqLnQkzBEeFwMt8a8AKM3s86RMTW2ty6XV8Zk98Tg4UfYYXoEs3cCp4wUxGNvAfvurUDb24A" - await signus.verify_signature(wallet_handle + 1, pool_handle, my_did, message, signature) - assert ErrorCode.WalletInvalidHandle == e.value.error_code @@ -73,11 +67,7 @@ async def test_verify_works_for_invalid_pool(pool_handle, wallet_handle, identit (my_did, _) = identity_my1 with pytest.raises(IndyError) as e: - message = '{"reqId":1496822211362017764}' - signature = "4Pwx83PGrDNPa1wonqLnQkzBEeFwMt8a8AKM3s86RMTW2ty6XV8Zk98Tg4UfYYXoEs3cCp4wUxGNvAfvurUDb24A" - await signus.verify_signature(wallet_handle, pool_handle + 1, my_did, message, signature) - assert ErrorCode.PoolLedgerInvalidPoolHandle == e.value.error_code @@ -90,10 +80,9 @@ async def test_verify_works_for_other_signer(pool_handle, wallet_handle, identit await signus.store_their_did(wallet_handle, json.dumps({"did": steward_did, "verkey": steward_verkey})) - message = '{"reqId":1496822211362017764}' - signature = await signus.sign(wallet_handle, trustee_did, message) + local_signature = await signus.sign(wallet_handle, trustee_did, message) - valid = await signus.verify_signature(wallet_handle, pool_handle, steward_did, message, signature) + valid = await signus.verify_signature(wallet_handle, pool_handle, steward_did, message, local_signature) assert not valid @@ -110,10 +99,6 @@ async def test_verify_works_for_get_nym_from_ledger_with_incompatible_wallet(poo await signus.store_their_did(wallet_handle, json.dumps({"did": did})) - message = '{"reqId":1496822211362017764}' - signature = "4Pwx83PGrDNPa1wonqLnQkzBEeFwMt8a8AKM3s86RMTW2ty6XV8Zk98Tg4UfYYXoEs3cCp4wUxGNvAfvurUDb24A" - with pytest.raises(IndyError) as e: await signus.verify_signature(wallet_handle, pool_handle, did, message, signature) - assert ErrorCode.WalletIncompatiblePoolError == e.value.error_code