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

Extract primitives and remove Profile #1016

Merged
merged 13 commits into from
Oct 19, 2023
4 changes: 0 additions & 4 deletions agency_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ edition.workspace = true
[lib]
doctest = false

[features]
test_utils = []
general_test = ["test_utils"]

[dependencies]
async-trait = "0.1.53"
env_logger = "0.9.0"
Expand Down
1 change: 0 additions & 1 deletion agency_client/src/messages/a2a_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ impl A2AMessageKinds {
}
}

#[cfg(feature = "general_test")]
#[cfg(test)]
mod test {
use serde_json::json;
Expand Down
3 changes: 0 additions & 3 deletions agency_client/src/messages/create_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ impl CreateKeyBuilder {
}
}

#[cfg(feature = "general_test")]
#[cfg(test)]
mod tests {
use super::*;
use crate::errors::error::AgencyClientErrorKind;

#[test]
#[cfg(feature = "general_test")]
fn test_create_key_set_values() {
let for_did = "11235yBzrpJQmNyZzgoTqB";
let for_verkey = "EkVTa7SCJ5SntpYyX7CSb2pcBhiVGT9kWSagA8a9T69A";
Expand All @@ -85,7 +83,6 @@ mod tests {
}

#[test]
#[cfg(feature = "general_test")]
fn test_create_key_set_invalid_did_errors() {
let for_did = "11235yBzrpJQmNyZzgoT";
let res = CreateKeyBuilder::create().for_did(for_did).unwrap_err();
Expand Down
1 change: 0 additions & 1 deletion agency_client/src/messages/update_com_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ impl UpdateComMethod {
}

#[cfg(test)]
#[cfg(feature = "general_test")]
mod tests {
use super::*;

Expand Down
1 change: 0 additions & 1 deletion agency_client/src/testing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ pub mod mocking;
#[rustfmt::skip]
pub mod test_constants;
pub mod test_settings;
#[cfg(feature = "test_utils")]
pub mod test_utils;
24 changes: 20 additions & 4 deletions agents/rust/aries-vcx-agent/src/agent/agent_struct.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;

use aries_vcx::core::profile::modular_libs_profile::ModularLibsProfile;
use aries_vcx::utils::devsetup::{DefaultIndyLedgerRead, DefaultIndyLedgerWrite};
use aries_vcx_core::{anoncreds::credx_anoncreds::IndyCredxAnonCreds, wallet::indy::IndySdkWallet};

use crate::{
agent::agent_config::AgentConfig,
Expand All @@ -14,7 +15,10 @@ use crate::{

#[derive(Clone)]
pub struct Agent {
pub(super) profile: Arc<ModularLibsProfile>,
pub(super) ledger_read: Arc<DefaultIndyLedgerRead>,
pub(super) ledger_write: Arc<DefaultIndyLedgerWrite>,
pub(super) anoncreds: IndyCredxAnonCreds,
pub(super) wallet: Arc<IndySdkWallet>,
pub(super) config: AgentConfig,
pub(super) connections: Arc<ServiceConnections>,
pub(super) schemas: Arc<ServiceSchemas>,
Expand All @@ -27,8 +31,20 @@ pub struct Agent {
}

impl Agent {
pub fn profile(&self) -> &ModularLibsProfile {
&self.profile
pub fn ledger_read(&self) -> &DefaultIndyLedgerRead {
&self.ledger_read
}

pub fn ledger_write(&self) -> &DefaultIndyLedgerWrite {
&self.ledger_write
}

pub fn anoncreds(&self) -> &IndyCredxAnonCreds {
&self.anoncreds
}

pub fn wallet(&self) -> &IndySdkWallet {
&self.wallet
}

pub fn agent_config(&self) -> AgentConfig {
Expand Down
56 changes: 36 additions & 20 deletions agents/rust/aries-vcx-agent/src/agent/init.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::sync::Arc;

use aries_vcx::{
core::profile::{ledger::VcxPoolConfig, modular_libs_profile::ModularLibsProfile, Profile},
global::settings::DEFAULT_LINK_SECRET_ALIAS,
global::settings::DEFAULT_LINK_SECRET_ALIAS, utils::devsetup::dev_build_profile_modular,
};
use aries_vcx_core::{
self,
Expand Down Expand Up @@ -66,52 +65,69 @@ impl Agent {

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

let pool_config = VcxPoolConfig {
genesis_file_path: init_config.pool_config.genesis_path,
indy_vdr_config: None,
response_cache_config: None,
};
let (ledger_read, ledger_write, anoncreds) =
dev_build_profile_modular(init_config.pool_config.genesis_path);
let ledger_read = Arc::new(ledger_read);
let ledger_write = Arc::new(ledger_write);

let indy_profile = ModularLibsProfile::init(wallet, pool_config).unwrap();
let profile = Arc::new(indy_profile);
let anoncreds = profile.anoncreds();
anoncreds
.prover_create_link_secret(DEFAULT_LINK_SECRET_ALIAS)
.prover_create_link_secret(wallet.as_ref(), DEFAULT_LINK_SECRET_ALIAS)
.await
.unwrap();

let connections = Arc::new(ServiceConnections::new(
Arc::clone(&profile),
ledger_read.clone(),
wallet.clone(),
init_config.service_endpoint,
));
let schemas = Arc::new(ServiceSchemas::new(
Arc::clone(&profile),
ledger_read.clone(),
ledger_write.clone(),
anoncreds,
wallet.clone(),
config_issuer.institution_did.clone(),
));
let cred_defs = Arc::new(ServiceCredentialDefinitions::new(Arc::clone(&profile)));
let cred_defs = Arc::new(ServiceCredentialDefinitions::new(
ledger_read.clone(),
ledger_write.clone(),
anoncreds,
wallet.clone(),
));
let rev_regs = Arc::new(ServiceRevocationRegistries::new(
Arc::clone(&profile),
ledger_write.clone(),
anoncreds,
wallet.clone(),
config_issuer.institution_did.clone(),
));
let issuer = Arc::new(ServiceCredentialsIssuer::new(
Arc::clone(&profile),
anoncreds,
wallet.clone(),
connections.clone(),
));
let holder = Arc::new(ServiceCredentialsHolder::new(
Arc::clone(&profile),
ledger_read.clone(),
anoncreds,
wallet.clone(),
connections.clone(),
));
let verifier = Arc::new(ServiceVerifier::new(
Arc::clone(&profile),
ledger_read.clone(),
anoncreds,
wallet.clone(),
connections.clone(),
));
let prover = Arc::new(ServiceProver::new(
Arc::clone(&profile),
ledger_read.clone(),
anoncreds,
wallet.clone(),
connections.clone(),
));

Ok(Self {
profile,
ledger_read,
ledger_write,
anoncreds,
wallet,
connections,
schemas,
cred_defs,
Expand Down
35 changes: 19 additions & 16 deletions agents/rust/aries-vcx-agent/src/services/connection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::{Arc, Mutex};

use aries_vcx::{
core::profile::{modular_libs_profile::ModularLibsProfile, Profile},
handlers::util::AnyInvitation,
messages::msg_fields::protocols::{
connection::{request::Request, response::Response},
Expand All @@ -10,7 +9,9 @@ use aries_vcx::{
protocols::connection::{
pairwise_info::PairwiseInfo, Connection, GenericConnection, State, ThinState,
},
utils::devsetup::DefaultIndyLedgerRead,
};
use aries_vcx_core::wallet::indy::IndySdkWallet;
use url::Url;

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

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

impl ServiceConnections {
pub fn new(profile: Arc<ModularLibsProfile>, service_endpoint: ServiceEndpoint) -> Self {
pub fn new(
ledger_read: Arc<DefaultIndyLedgerRead>,
wallet: Arc<IndySdkWallet>,
service_endpoint: ServiceEndpoint,
) -> Self {
Self {
profile,
service_endpoint,
connections: Arc::new(ObjectCache::new("connections")),
ledger_read,
wallet,
}
}

pub async fn create_invitation(
&self,
pw_info: Option<PairwiseInfo>,
) -> AgentResult<AnyInvitation> {
let pw_info = pw_info.unwrap_or(PairwiseInfo::create(self.profile.wallet()).await?);
let pw_info = pw_info.unwrap_or(PairwiseInfo::create(self.wallet.as_ref()).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 @@ -52,9 +59,9 @@ impl ServiceConnections {
}

pub async fn receive_invitation(&self, invite: AnyInvitation) -> AgentResult<String> {
let pairwise_info = PairwiseInfo::create(self.profile.wallet()).await?;
let pairwise_info = PairwiseInfo::create(self.wallet.as_ref()).await?;
let invitee = Connection::new_invitee("".to_owned(), pairwise_info)
.accept_invitation(self.profile.ledger_read(), invite)
.accept_invitation(self.ledger_read.as_ref(), invite)
.await?;

let thread_id = invitee.thread_id().to_owned();
Expand All @@ -69,7 +76,7 @@ impl ServiceConnections {
.await?;
let request = invitee.get_request().clone();
invitee
.send_message(self.profile.wallet(), &request.into(), &HttpClient)
.send_message(self.wallet.as_ref(), &request.into(), &HttpClient)
.await?;
self.connections.insert(thread_id, invitee.into())?;
Ok(())
Expand All @@ -94,7 +101,7 @@ impl ServiceConnections {

let inviter = inviter
.handle_request(
self.profile.wallet(),
self.wallet.as_ref(),
request,
self.service_endpoint.clone(),
vec![],
Expand All @@ -110,7 +117,7 @@ impl ServiceConnections {
let inviter: Connection<_, _> = self.connections.get(thread_id)?.try_into()?;
let response = inviter.get_connection_response_msg();
inviter
.send_message(self.profile.wallet(), &response.into(), &HttpClient)
.send_message(self.wallet.as_ref(), &response.into(), &HttpClient)
.await?;

self.connections.insert(thread_id, inviter.into())?;
Expand All @@ -121,7 +128,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.profile.wallet(), response)
.handle_response(self.wallet.as_ref(), response)
.await?;

self.connections.insert(thread_id, invitee.into())?;
Expand All @@ -132,11 +139,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.profile.wallet(),
&invitee.get_ack().into(),
&HttpClient,
)
.send_message(self.wallet.as_ref(), &invitee.get_ack().into(), &HttpClient)
.await?;

self.connections.insert(thread_id, invitee.into())?;
Expand Down
31 changes: 24 additions & 7 deletions agents/rust/aries-vcx-agent/src/services/credential_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,44 @@ use std::sync::{Arc, Mutex};

use aries_vcx::{
common::primitives::credential_definition::{CredentialDef, CredentialDefConfig},
core::profile::{modular_libs_profile::ModularLibsProfile, Profile},
utils::devsetup::{DefaultIndyLedgerRead, DefaultIndyLedgerWrite},
};
use aries_vcx_core::{anoncreds::credx_anoncreds::IndyCredxAnonCreds, wallet::indy::IndySdkWallet};

use crate::{
error::*,
storage::{object_cache::ObjectCache, Storage},
};

pub struct ServiceCredentialDefinitions {
profile: Arc<ModularLibsProfile>,
ledger_read: Arc<DefaultIndyLedgerRead>,
ledger_write: Arc<DefaultIndyLedgerWrite>,
anoncreds: IndyCredxAnonCreds,
wallet: Arc<IndySdkWallet>,
cred_defs: ObjectCache<CredentialDef>,
}

impl ServiceCredentialDefinitions {
pub fn new(profile: Arc<ModularLibsProfile>) -> Self {
pub fn new(
ledger_read: Arc<DefaultIndyLedgerRead>,
ledger_write: Arc<DefaultIndyLedgerWrite>,
anoncreds: IndyCredxAnonCreds,
wallet: Arc<IndySdkWallet>,
) -> Self {
Self {
profile,
cred_defs: ObjectCache::new("cred-defs"),
ledger_read,
ledger_write,
anoncreds,
wallet,
}
}

pub async fn create_cred_def(&self, config: CredentialDefConfig) -> AgentResult<String> {
let cd = CredentialDef::create(
self.profile.ledger_read(),
self.profile.anoncreds(),
self.wallet.as_ref(),
self.ledger_read.as_ref(),
&self.anoncreds,
"".to_string(),
config,
true,
Expand All @@ -38,7 +51,11 @@ impl ServiceCredentialDefinitions {
pub async fn publish_cred_def(&self, thread_id: &str) -> AgentResult<()> {
let cred_def = self.cred_defs.get(thread_id)?;
let cred_def = cred_def
.publish_cred_def(self.profile.ledger_read(), self.profile.ledger_write())
.publish_cred_def(
self.wallet.as_ref(),
self.ledger_read.as_ref(),
self.ledger_write.as_ref(),
)
.await?;
self.cred_defs.insert(thread_id, cred_def)?;
Ok(())
Expand Down
Loading
Loading