Skip to content

Commit

Permalink
refactor: use BaseWallet instead of a specific wallet type, closes #1117
Browse files Browse the repository at this point in the history


Signed-off-by: Ondrej Prazak <ondrej.prazak@absa.africa>

Signed-off-by: Ondrej Prazak <ondrej.prazak@absa.africa>
  • Loading branch information
Ondrej Prazak committed Feb 7, 2024
1 parent 7f15000 commit 21162fc
Show file tree
Hide file tree
Showing 81 changed files with 1,343 additions and 1,237 deletions.
4 changes: 3 additions & 1 deletion aries/agents/rust/aries-vcx-agent/src/agent/agent_config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use aries_vcx_core::wallet::indy::{IssuerConfig, WalletConfig};
use aries_vcx_core::wallet::{
base_wallet::issuer_config::IssuerConfig, indy::wallet_config::WalletConfig,
};

#[derive(Clone)]
pub struct AgentConfig {
Expand Down
6 changes: 3 additions & 3 deletions aries/agents/rust/aries-vcx-agent/src/agent/agent_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use aries_vcx_core::{
anoncreds::credx_anoncreds::IndyCredxAnonCreds,
ledger::indy_vdr_ledger::{DefaultIndyLedgerRead, DefaultIndyLedgerWrite},
wallet::indy::IndySdkWallet,
wallet::base_wallet::BaseWallet,
};

use crate::{
Expand All @@ -22,7 +22,7 @@ pub struct Agent {
pub(super) ledger_read: Arc<DefaultIndyLedgerRead>,
pub(super) ledger_write: Arc<DefaultIndyLedgerWrite>,
pub(super) anoncreds: IndyCredxAnonCreds,
pub(super) wallet: Arc<IndySdkWallet>,
pub(super) wallet: Arc<dyn BaseWallet>,
pub(super) config: AgentConfig,
pub(super) connections: Arc<ServiceConnections>,
pub(super) schemas: Arc<ServiceSchemas>,
Expand All @@ -49,7 +49,7 @@ impl Agent {
&self.anoncreds
}

pub fn wallet(&self) -> &IndySdkWallet {
pub fn wallet(&self) -> &Arc<dyn BaseWallet> {
&self.wallet
}

Expand Down
25 changes: 8 additions & 17 deletions aries/agents/rust/aries-vcx-agent/src/agent/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ use aries_vcx_core::{
self,
anoncreds::{base_anoncreds::BaseAnonCreds, credx_anoncreds::IndyCredxAnonCreds},
ledger::indy_vdr_ledger::DefaultIndyLedgerRead,
wallet::indy::{
wallet::{create_and_open_wallet, wallet_configure_issuer},
IndySdkWallet, WalletConfig,
},
wallet::{base_wallet::ManageWallet, indy::wallet_config::WalletConfig},
};
use did_peer::resolver::PeerDidResolver;
use did_resolver_registry::ResolverRegistry;
Expand Down Expand Up @@ -68,13 +65,13 @@ impl Agent {
rekey_derivation_method: None,
};

let wallet_handle = create_and_open_wallet(&config_wallet).await.unwrap();
let config_issuer = wallet_configure_issuer(wallet_handle, &init_config.enterprise_seed)
config_wallet.create_wallet().await.unwrap();
let wallet = config_wallet.open_wallet().await.unwrap();
let config_issuer = wallet
.configure_issuer(&init_config.enterprise_seed)
.await
.unwrap();

let wallet = Arc::new(IndySdkWallet::new(wallet_handle));

use aries_vcx_core::ledger::indy_vdr_ledger::{build_ledger_components, VcxPoolConfig};

info!("dev_build_profile_modular >>");
Expand All @@ -91,14 +88,14 @@ impl Agent {
let ledger_write = Arc::new(ledger_write);

anoncreds
.prover_create_link_secret(wallet.as_ref(), DEFAULT_LINK_SECRET_ALIAS)
.prover_create_link_secret(&wallet, DEFAULT_LINK_SECRET_ALIAS)
.await
.unwrap();

// TODO: This setup should be easier
// The default issuer did can't be used - its verkey is not in base58 - TODO: double-check
let (public_did, _verkey) = add_new_did(
wallet.as_ref(),
&wallet,
ledger_write.as_ref(),
&config_issuer.institution_did.parse()?,
None,
Expand All @@ -107,13 +104,7 @@ impl Agent {
let endpoint = EndpointDidSov::create()
.set_service_endpoint(init_config.service_endpoint.clone())
.set_types(Some(vec![DidSovServiceType::DidCommunication]));
write_endpoint(
wallet.as_ref(),
ledger_write.as_ref(),
&public_did,
&endpoint,
)
.await?;
write_endpoint(&wallet, ledger_write.as_ref(), &public_did, &endpoint).await?;

let did_peer_resolver = PeerDidResolver::new();
let did_sov_resolver: DidSovResolver<Arc<DefaultIndyLedgerRead>, DefaultIndyLedgerRead> =
Expand Down
33 changes: 12 additions & 21 deletions aries/agents/rust/aries-vcx-agent/src/services/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use aries_vcx::{
pairwise_info::PairwiseInfo, Connection, GenericConnection, State, ThinState,
},
};
use aries_vcx_core::{ledger::indy_vdr_ledger::DefaultIndyLedgerRead, wallet::indy::IndySdkWallet};
use aries_vcx_core::{
ledger::indy_vdr_ledger::DefaultIndyLedgerRead, wallet::base_wallet::BaseWallet,
};
use url::Url;

use crate::{
Expand All @@ -23,15 +25,15 @@ pub type ServiceEndpoint = Url;

pub struct ServiceConnections {
ledger_read: Arc<DefaultIndyLedgerRead>,
wallet: Arc<IndySdkWallet>,
wallet: Arc<dyn BaseWallet>,
service_endpoint: ServiceEndpoint,
connections: Arc<ObjectCache<GenericConnection>>,
}

impl ServiceConnections {
pub fn new(
ledger_read: Arc<DefaultIndyLedgerRead>,
wallet: Arc<IndySdkWallet>,
wallet: Arc<dyn BaseWallet>,
service_endpoint: ServiceEndpoint,
) -> Self {
Self {
Expand All @@ -46,7 +48,7 @@ impl ServiceConnections {
&self,
pw_info: Option<PairwiseInfo>,
) -> AgentResult<AnyInvitation> {
let pw_info = pw_info.unwrap_or(PairwiseInfo::create(self.wallet.as_ref()).await?);
let pw_info = pw_info.unwrap_or(PairwiseInfo::create(&self.wallet).await?);
let inviter = Connection::new_inviter("".to_owned(), pw_info)
.create_invitation(vec![], self.service_endpoint.clone());
let invite = inviter.get_invitation().clone();
Expand All @@ -58,7 +60,7 @@ impl ServiceConnections {
}

pub async fn receive_invitation(&self, invite: AnyInvitation) -> AgentResult<String> {
let pairwise_info = PairwiseInfo::create(self.wallet.as_ref()).await?;
let pairwise_info = PairwiseInfo::create(&self.wallet).await?;
let invitee = Connection::new_invitee("".to_owned(), pairwise_info)
.accept_invitation(self.ledger_read.as_ref(), invite)
.await?;
Expand All @@ -75,7 +77,7 @@ impl ServiceConnections {
.await?;
let request = invitee.get_request().clone();
invitee
.send_message(self.wallet.as_ref(), &request.into(), &VcxHttpClient)
.send_message(&self.wallet, &request.into(), &VcxHttpClient)
.await?;
self.connections.insert(thread_id, invitee.into())?;
Ok(())
Expand All @@ -99,12 +101,7 @@ impl ServiceConnections {
}?;

let inviter = inviter
.handle_request(
self.wallet.as_ref(),
request,
self.service_endpoint.clone(),
vec![],
)
.handle_request(&self.wallet, request, self.service_endpoint.clone(), vec![])
.await?;

self.connections.insert(thread_id, inviter.into())?;
Expand All @@ -116,7 +113,7 @@ impl ServiceConnections {
let inviter: Connection<_, _> = self.connections.get(thread_id)?.try_into()?;
let response = inviter.get_connection_response_msg();
inviter
.send_message(self.wallet.as_ref(), &response.into(), &VcxHttpClient)
.send_message(&self.wallet, &response.into(), &VcxHttpClient)
.await?;

self.connections.insert(thread_id, inviter.into())?;
Expand All @@ -126,9 +123,7 @@ impl ServiceConnections {

pub async fn accept_response(&self, thread_id: &str, response: Response) -> AgentResult<()> {
let invitee: Connection<_, _> = self.connections.get(thread_id)?.try_into()?;
let invitee = invitee
.handle_response(self.wallet.as_ref(), response)
.await?;
let invitee = invitee.handle_response(&self.wallet, response).await?;

self.connections.insert(thread_id, invitee.into())?;

Expand All @@ -138,11 +133,7 @@ impl ServiceConnections {
pub async fn send_ack(&self, thread_id: &str) -> AgentResult<()> {
let invitee: Connection<_, _> = self.connections.get(thread_id)?.try_into()?;
invitee
.send_message(
self.wallet.as_ref(),
&invitee.get_ack().into(),
&VcxHttpClient,
)
.send_message(&self.wallet, &invitee.get_ack().into(), &VcxHttpClient)
.await?;

self.connections.insert(thread_id, invitee.into())?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use aries_vcx::common::primitives::credential_definition::{CredentialDef, Creden
use aries_vcx_core::{
anoncreds::credx_anoncreds::IndyCredxAnonCreds,
ledger::indy_vdr_ledger::{DefaultIndyLedgerRead, DefaultIndyLedgerWrite},
wallet::indy::IndySdkWallet,
wallet::base_wallet::BaseWallet,
};

use crate::{
Expand All @@ -16,7 +16,7 @@ pub struct ServiceCredentialDefinitions {
ledger_read: Arc<DefaultIndyLedgerRead>,
ledger_write: Arc<DefaultIndyLedgerWrite>,
anoncreds: IndyCredxAnonCreds,
wallet: Arc<IndySdkWallet>,
wallet: Arc<dyn BaseWallet>,
cred_defs: ObjectCache<CredentialDef>,
}

Expand All @@ -25,7 +25,7 @@ impl ServiceCredentialDefinitions {
ledger_read: Arc<DefaultIndyLedgerRead>,
ledger_write: Arc<DefaultIndyLedgerWrite>,
anoncreds: IndyCredxAnonCreds,
wallet: Arc<IndySdkWallet>,
wallet: Arc<dyn BaseWallet>,
) -> Self {
Self {
cred_defs: ObjectCache::new("cred-defs"),
Expand All @@ -38,7 +38,7 @@ impl ServiceCredentialDefinitions {

pub async fn create_cred_def(&self, config: CredentialDefConfig) -> AgentResult<String> {
let cd = CredentialDef::create(
self.wallet.as_ref(),
&self.wallet,
self.ledger_read.as_ref(),
&self.anoncreds,
"".to_string(),
Expand All @@ -53,7 +53,7 @@ impl ServiceCredentialDefinitions {
let cred_def = self.cred_defs.get(thread_id)?;
let cred_def = cred_def
.publish_cred_def(
self.wallet.as_ref(),
&self.wallet,
self.ledger_read.as_ref(),
self.ledger_write.as_ref(),
)
Expand Down
16 changes: 9 additions & 7 deletions aries/agents/rust/aries-vcx-agent/src/services/did_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use aries_vcx::{
},
transport::Transport,
};
use aries_vcx_core::{ledger::indy_vdr_ledger::DefaultIndyLedgerRead, wallet::indy::IndySdkWallet};
use aries_vcx_core::{
ledger::indy_vdr_ledger::DefaultIndyLedgerRead, wallet::base_wallet::BaseWallet,
};
use did_resolver_registry::ResolverRegistry;

use super::connection::ServiceEndpoint;
Expand All @@ -26,7 +28,7 @@ use crate::{

pub struct ServiceDidExchange {
ledger_read: Arc<DefaultIndyLedgerRead>,
wallet: Arc<IndySdkWallet>,
wallet: Arc<dyn BaseWallet>,
resolver_registry: Arc<ResolverRegistry>,
service_endpoint: ServiceEndpoint,
did_exchange: Arc<ObjectCache<GenericDidExchange>>,
Expand All @@ -36,7 +38,7 @@ pub struct ServiceDidExchange {
impl ServiceDidExchange {
pub fn new(
ledger_read: Arc<DefaultIndyLedgerRead>,
wallet: Arc<IndySdkWallet>,
wallet: Arc<dyn BaseWallet>,
resolver_registry: Arc<ResolverRegistry>,
service_endpoint: ServiceEndpoint,
public_did: String,
Expand Down Expand Up @@ -72,7 +74,7 @@ impl ServiceDidExchange {
let ddo_their = requester.their_did_doc();
let ddo_our = requester.our_did_document();
let encryption_envelope =
pairwise_encrypt(ddo_our, ddo_their, self.wallet.as_ref(), &request.into()).await?;
pairwise_encrypt(ddo_our, ddo_their, &self.wallet, &request.into()).await?;
VcxHttpClient
.send_message(encryption_envelope.0, get_their_endpoint(ddo_their)?)
.await?;
Expand Down Expand Up @@ -101,7 +103,7 @@ impl ServiceDidExchange {
let invitation_key =
resolve_key_from_invitation(&invitation, &self.resolver_registry).await?;
let (responder, response) = GenericDidExchange::handle_request(
self.wallet.as_ref(),
&self.wallet,
self.resolver_registry.clone(),
request,
self.service_endpoint.clone(),
Expand All @@ -113,7 +115,7 @@ impl ServiceDidExchange {
let ddo_their = responder.their_did_doc();
let ddo_our = responder.our_did_document();
let encryption_envelope =
pairwise_encrypt(ddo_our, ddo_their, self.wallet.as_ref(), &response.into()).await?;
pairwise_encrypt(ddo_our, ddo_their, &self.wallet, &response.into()).await?;
VcxHttpClient
.send_message(encryption_envelope.0, get_their_endpoint(ddo_their)?)
.await?;
Expand All @@ -130,7 +132,7 @@ impl ServiceDidExchange {
let ddo_their = requester.their_did_doc();
let ddo_our = requester.our_did_document();
let encryption_envelope =
pairwise_encrypt(ddo_our, ddo_their, self.wallet.as_ref(), &complete.into()).await?;
pairwise_encrypt(ddo_our, ddo_their, &self.wallet, &complete.into()).await?;
VcxHttpClient
.send_message(encryption_envelope.0, get_their_endpoint(ddo_their)?)
.await?;
Expand Down
Loading

0 comments on commit 21162fc

Please sign in to comment.