Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on BaseWallet from IndyVdrLedger #853

Merged
merged 8 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion aries_vcx/src/core/profile/modular_libs_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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, IndyVdrLedgerConfig};
use aries_vcx_core::ledger::request_signer::base_wallet::BaseWalletRequestSigner;
use aries_vcx_core::ledger::request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter, LedgerPoolConfig};
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::ResponseParser;
Expand All @@ -24,10 +25,11 @@ impl ModularLibsProfile {
pub fn new(wallet: Arc<dyn BaseWallet>, ledger_pool_config: LedgerPoolConfig) -> VcxResult<Self> {
let anoncreds = Arc::new(IndyCredxAnonCreds::new(Arc::clone(&wallet)));
let ledger_pool = Arc::new(IndyVdrLedgerPool::new(ledger_pool_config)?);
let request_signer = Arc::new(BaseWalletRequestSigner::new(wallet.clone()));
let request_submitter = Arc::new(IndyVdrSubmitter::new(ledger_pool));
let response_parser = Arc::new(ResponseParser::new());
let config = IndyVdrLedgerConfig {
wallet: wallet.clone(),
request_signer,
request_submitter,
response_parser,
};
Expand Down
4 changes: 3 additions & 1 deletion aries_vcx/src/core/profile/vdr_proxy_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use aries_vcx_core::{
ledger::{
base_ledger::BaseLedger,
indy_vdr_ledger::{IndyVdrLedger, IndyVdrLedgerConfig},
request_signer::base_wallet::BaseWalletRequestSigner,
request_submitter::vdr_proxy::VdrProxySubmitter,
},
wallet::{base_wallet::BaseWallet, indy_wallet::IndySdkWallet},
Expand All @@ -24,10 +25,11 @@ impl VdrProxyProfile {
pub fn new(wallet_handle: WalletHandle, client: VdrProxyClient) -> Self {
let wallet = Arc::new(IndySdkWallet::new(wallet_handle));
let anoncreds = Arc::new(IndySdkAnonCreds::new(wallet_handle));
let request_signer = Arc::new(BaseWalletRequestSigner::new(wallet.clone()));
let request_submitter = Arc::new(VdrProxySubmitter::new(Arc::new(client)));
let response_parser = Arc::new(ResponseParser::new());
let config = IndyVdrLedgerConfig {
wallet: wallet.clone(),
request_signer,
request_submitter,
response_parser,
};
Expand Down
31 changes: 16 additions & 15 deletions aries_vcx_core/src/ledger/indy_vdr_ledger.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use indy_credx::ursa::cl::RevocationRegistryDelta as UrsaRevocationRegistryDelta;
use indy_ledger_response_parser::{ResponseParser, RevocationRegistryDeltaInfo, RevocationRegistryInfo};
use indy_vdr as vdr;
use std::fmt::{Debug, Formatter};
Expand All @@ -22,36 +21,39 @@ use crate::common::ledger::transactions::verify_transaction_can_be_endorsed;
use crate::errors::error::VcxCoreResult;
use crate::global::author_agreement::get_txn_author_agreement;
use crate::global::settings;
use crate::wallet::base_wallet::BaseWallet;

use super::base_ledger::BaseLedger;
use super::request_signer::RequestSigner;
use super::request_submitter::RequestSubmitter;

pub struct IndyVdrLedgerConfig<T>
pub struct IndyVdrLedgerConfig<T, U>
where
T: RequestSubmitter + Send + Sync,
U: RequestSigner + Send + Sync,
{
pub wallet: Arc<dyn BaseWallet>,
pub request_signer: Arc<U>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

pub request_submitter: Arc<T>,
pub response_parser: Arc<ResponseParser>,
}

pub struct IndyVdrLedger<T>
pub struct IndyVdrLedger<T, U>
where
T: RequestSubmitter + Send + Sync,
U: RequestSigner + Send + Sync,
{
wallet: Arc<dyn BaseWallet>,
request_signer: Arc<U>,
request_submitter: Arc<T>,
response_parser: Arc<ResponseParser>,
}

impl<T> IndyVdrLedger<T>
impl<T, U> IndyVdrLedger<T, U>
where
T: RequestSubmitter + Send + Sync,
U: RequestSigner + Send + Sync,
{
pub fn new(config: IndyVdrLedgerConfig<T>) -> Self {
pub fn new(config: IndyVdrLedgerConfig<T, U>) -> Self {
Self {
wallet: config.wallet,
request_signer: config.request_signer,
request_submitter: config.request_submitter,
response_parser: config.response_parser,
}
Expand All @@ -69,10 +71,7 @@ where
}

async fn _get_request_signature(&self, did: &str, request: &PreparedRequest) -> VcxCoreResult<Vec<u8>> {
let to_sign = request.get_signature_input()?;
let signer_verkey = self.wallet.key_for_local_did(did).await?;
let signature = self.wallet.sign(&signer_verkey, to_sign.as_bytes()).await?;
Ok(signature)
self.request_signer.sign(did, request).await
}

async fn _sign_and_submit_request(&self, submitter_did: &str, request: PreparedRequest) -> VcxCoreResult<String> {
Expand Down Expand Up @@ -194,19 +193,21 @@ where
}
}

impl<T> Debug for IndyVdrLedger<T>
impl<T, U> Debug for IndyVdrLedger<T, U>
where
T: RequestSubmitter + Send + Sync,
U: RequestSigner + Send + Sync,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "IndyVdrLedger instance")
}
}

#[async_trait]
impl<T> BaseLedger for IndyVdrLedger<T>
impl<T, U> BaseLedger for IndyVdrLedger<T, U>
where
T: RequestSubmitter + Send + Sync,
U: RequestSigner + Send + Sync,
{
async fn sign_and_submit_request(&self, submitter_did: &str, request_json: &str) -> VcxCoreResult<String> {
let request = PreparedRequest::from_request_json(request_json)?;
Expand Down
2 changes: 2 additions & 0 deletions aries_vcx_core/src/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ pub mod indy_ledger;
#[cfg(any(feature = "modular_libs", feature = "vdr_proxy_ledger"))]
pub mod indy_vdr_ledger;
#[cfg(any(feature = "modular_libs", feature = "vdr_proxy_ledger"))]
pub mod request_signer;
#[cfg(any(feature = "modular_libs", feature = "vdr_proxy_ledger"))]
pub mod request_submitter;
28 changes: 28 additions & 0 deletions aries_vcx_core/src/ledger/request_signer/base_wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::sync::Arc;

use async_trait::async_trait;
use indy_vdr::pool::PreparedRequest;

use crate::{errors::error::VcxCoreResult, wallet::base_wallet::BaseWallet};

use super::RequestSigner;

pub struct BaseWalletRequestSigner {
wallet: Arc<dyn BaseWallet>,
}

impl BaseWalletRequestSigner {
pub fn new(wallet: Arc<dyn BaseWallet>) -> Self {
Self { wallet }
}
}

#[async_trait]
impl RequestSigner for BaseWalletRequestSigner {
async fn sign(&self, did: &str, request: &PreparedRequest) -> VcxCoreResult<Vec<u8>> {
let to_sign = request.get_signature_input()?;
let signer_verkey = self.wallet.key_for_local_did(did).await?;
let signature = self.wallet.sign(&signer_verkey, to_sign.as_bytes()).await?;
Ok(signature)
}
}
11 changes: 11 additions & 0 deletions aries_vcx_core/src/ledger/request_signer/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub mod base_wallet;

use async_trait::async_trait;
use indy_vdr::pool::PreparedRequest;

use crate::errors::error::VcxCoreResult;

#[async_trait]
pub trait RequestSigner: Send + Sync {
async fn sign(&self, did: &str, request: &PreparedRequest) -> VcxCoreResult<Vec<u8>>;
}
2 changes: 1 addition & 1 deletion aries_vcx_core/src/ledger/request_submitter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ pub mod vdr_ledger;
pub mod vdr_proxy;

#[async_trait]
pub trait RequestSubmitter {
pub trait RequestSubmitter: Send + Sync {
async fn submit(&self, request: PreparedRequest) -> VcxCoreResult<String>;
}
4 changes: 3 additions & 1 deletion did_resolver_sov/src/reader/vdr_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::error::DidSovError;
use aries_vcx_core::{
ledger::{
indy_vdr_ledger::{IndyVdrLedger, IndyVdrLedgerConfig},
request_signer::base_wallet::BaseWalletRequestSigner,
request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter, LedgerPoolConfig},
},
wallet::{base_wallet::BaseWallet, indy_wallet::IndySdkWallet},
Expand All @@ -19,9 +20,10 @@ impl TryFrom<LedgerPoolConfig> for ConcreteAttrReader {
let wallet = Arc::new(IndySdkWallet::new(INVALID_WALLET_HANDLE)) as Arc<dyn BaseWallet>;
let ledger_pool = Arc::new(IndyVdrLedgerPool::new(pool_config)?);
let request_submitter = Arc::new(IndyVdrSubmitter::new(ledger_pool));
let request_signer = Arc::new(BaseWalletRequestSigner::new(wallet.clone()));
let response_parser = Arc::new(ResponseParser::new());
let config = IndyVdrLedgerConfig {
wallet: wallet.clone(),
request_signer,
request_submitter,
response_parser,
};
Expand Down