Skip to content

Commit

Permalink
Merge branch 'main' into libvcx/credx
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrik-Stas authored Oct 3, 2023
2 parents d54f28a + 725797b commit 8a7a3ba
Show file tree
Hide file tree
Showing 97 changed files with 1,798 additions and 1,345 deletions.
8 changes: 4 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,6 @@
use std::sync::Arc;

use aries_vcx::core::profile::profile::Profile;
use aries_vcx::core::profile::vdrtools_profile::VdrtoolsProfile;

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

#[derive(Clone)]
pub struct Agent {
pub(super) profile: Arc<dyn Profile>,
pub(super) profile: Arc<VdrtoolsProfile>,
pub(super) config: AgentConfig,
pub(super) connections: Arc<ServiceConnections>,
pub(super) schemas: Arc<ServiceSchemas>,
Expand All @@ -27,8 +27,8 @@ pub struct Agent {
}

impl Agent {
pub fn profile(&self) -> Arc<dyn Profile> {
Arc::clone(&self.profile)
pub fn profile(&self) -> &VdrtoolsProfile {
&self.profile
}

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

use aries_vcx::{
core::profile::{
ledger::{build_ledger_components, VcxPoolConfig},
profile::Profile,
vdrtools_profile::VdrtoolsProfile,
},
core::profile::{ledger::VcxPoolConfig, profile::Profile, vdrtools_profile::VdrtoolsProfile},
global::settings::{init_issuer_config, DEFAULT_LINK_SECRET_ALIAS},
};
use aries_vcx_core::{
ledger::base_ledger::{
AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite,
},
self,
anoncreds::base_anoncreds::BaseAnonCreds,
wallet::indy::{
wallet::{create_and_open_wallet, wallet_configure_issuer},
IndySdkWallet, WalletConfig,
Expand Down Expand Up @@ -76,22 +71,10 @@ impl Agent {
indy_vdr_config: None,
response_cache_config: None,
};
let (ledger_read, ledger_write) =
build_ledger_components(wallet.clone(), pool_config).unwrap();
let anoncreds_ledger_read: Arc<dyn AnoncredsLedgerRead> = ledger_read.clone();
let anoncreds_ledger_write: Arc<dyn AnoncredsLedgerWrite> = ledger_write.clone();
let indy_ledger_read: Arc<dyn IndyLedgerRead> = ledger_read.clone();
let indy_ledger_write: Arc<dyn IndyLedgerWrite> = ledger_write.clone();

let indy_profile = VdrtoolsProfile::init(
wallet,
anoncreds_ledger_read,
anoncreds_ledger_write,
indy_ledger_read,
indy_ledger_write,
);
let profile: Arc<dyn Profile> = Arc::new(indy_profile);
let anoncreds = profile.inject_anoncreds();
let indy_profile = VdrtoolsProfile::init(wallet, pool_config).unwrap();
let profile = Arc::new(indy_profile);
let anoncreds = profile.anoncreds();
anoncreds
.prover_create_link_secret(DEFAULT_LINK_SECRET_ALIAS)
.await
Expand Down
22 changes: 11 additions & 11 deletions agents/rust/aries-vcx-agent/src/services/connection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::{Arc, Mutex};

use aries_vcx::{
core::profile::profile::Profile,
core::profile::{profile::Profile, vdrtools_profile::VdrtoolsProfile},
handlers::util::AnyInvitation,
messages::msg_fields::protocols::{
connection::{request::Request, response::Response},
Expand All @@ -22,13 +22,13 @@ use crate::{
pub type ServiceEndpoint = Url;

pub struct ServiceConnections {
profile: Arc<dyn Profile>,
profile: Arc<VdrtoolsProfile>,
service_endpoint: ServiceEndpoint,
connections: Arc<ObjectCache<GenericConnection>>,
}

impl ServiceConnections {
pub fn new(profile: Arc<dyn Profile>, service_endpoint: ServiceEndpoint) -> Self {
pub fn new(profile: Arc<VdrtoolsProfile>, service_endpoint: ServiceEndpoint) -> Self {
Self {
profile,
service_endpoint,
Expand All @@ -40,7 +40,7 @@ impl ServiceConnections {
&self,
pw_info: Option<PairwiseInfo>,
) -> AgentResult<AnyInvitation> {
let pw_info = pw_info.unwrap_or(PairwiseInfo::create(&self.profile.inject_wallet()).await?);
let pw_info = pw_info.unwrap_or(PairwiseInfo::create(self.profile.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 @@ -52,9 +52,9 @@ impl ServiceConnections {
}

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

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

let inviter = inviter
.handle_request(
&self.profile.inject_wallet(),
self.profile.wallet(),
request,
self.service_endpoint.clone(),
vec![],
Expand All @@ -110,7 +110,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.inject_wallet(), &response.into(), &HttpClient)
.send_message(self.profile.wallet(), &response.into(), &HttpClient)
.await?;

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

self.connections.insert(thread_id, invitee.into())?;
Expand All @@ -133,7 +133,7 @@ impl ServiceConnections {
let invitee: Connection<_, _> = self.connections.get(thread_id)?.try_into()?;
invitee
.send_message(
&self.profile.inject_wallet(),
self.profile.wallet(),
&invitee.get_ack().into(),
&HttpClient,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::{Arc, Mutex};

use aries_vcx::{
common::primitives::credential_definition::{CredentialDef, CredentialDefConfig},
core::profile::profile::Profile,
core::profile::{profile::Profile, vdrtools_profile::VdrtoolsProfile},
};

use crate::{
Expand All @@ -11,12 +11,12 @@ use crate::{
};

pub struct ServiceCredentialDefinitions {
profile: Arc<dyn Profile>,
profile: Arc<VdrtoolsProfile>,
cred_defs: ObjectCache<CredentialDef>,
}

impl ServiceCredentialDefinitions {
pub fn new(profile: Arc<dyn Profile>) -> Self {
pub fn new(profile: Arc<VdrtoolsProfile>) -> Self {
Self {
profile,
cred_defs: ObjectCache::new("cred-defs"),
Expand All @@ -25,8 +25,8 @@ impl ServiceCredentialDefinitions {

pub async fn create_cred_def(&self, config: CredentialDefConfig) -> AgentResult<String> {
let cd = CredentialDef::create(
&self.profile.inject_anoncreds_ledger_read(),
&self.profile.inject_anoncreds(),
self.profile.ledger_read(),
self.profile.anoncreds(),
"".to_string(),
config,
true,
Expand All @@ -38,10 +38,7 @@ 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.inject_anoncreds_ledger_read(),
&self.profile.inject_anoncreds_ledger_write(),
)
.publish_cred_def(self.profile.ledger_read(), self.profile.ledger_write())
.await?;
self.cred_defs.insert(thread_id, cred_def)?;
Ok(())
Expand Down
31 changes: 17 additions & 14 deletions agents/rust/aries-vcx-agent/src/services/holder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use aries_vcx::{
core::profile::profile::Profile,
core::profile::{profile::Profile, vdrtools_profile::VdrtoolsProfile},
handlers::issuance::holder::Holder,
messages::{
msg_fields::protocols::cred_issuance::v1::{
Expand Down Expand Up @@ -36,13 +36,16 @@ impl HolderWrapper {
}

pub struct ServiceCredentialsHolder {
profile: Arc<dyn Profile>,
profile: Arc<VdrtoolsProfile>,
creds_holder: ObjectCache<HolderWrapper>,
service_connections: Arc<ServiceConnections>,
}

impl ServiceCredentialsHolder {
pub fn new(profile: Arc<dyn Profile>, service_connections: Arc<ServiceConnections>) -> Self {
pub fn new(
profile: Arc<VdrtoolsProfile>,
service_connections: Arc<ServiceConnections>,
) -> Self {
Self {
profile,
service_connections,
Expand All @@ -66,12 +69,12 @@ impl ServiceCredentialsHolder {
propose_credential: ProposeCredentialV1,
) -> AgentResult<String> {
let connection = self.service_connections.get_by_id(connection_id)?;
let wallet = self.profile.inject_wallet();
let wallet = self.profile.wallet();

let mut holder = Holder::create("")?;
holder.set_proposal(propose_credential.clone())?;
connection
.send_message(&wallet, &propose_credential.into(), &HttpClient)
.send_message(wallet, &propose_credential.into(), &HttpClient)
.await?;

self.creds_holder.insert(
Expand Down Expand Up @@ -105,16 +108,16 @@ impl ServiceCredentialsHolder {
(None, None) => return Err(AgentError::from_kind(AgentErrorKind::InvalidArguments)),
};
let connection = self.service_connections.get_by_id(&connection_id)?;
let wallet = self.profile.inject_wallet();
let wallet = self.profile.wallet();
let pw_did = connection.pairwise_info().pw_did.to_string();

let send_closure: SendClosure = Box::new(|msg: AriesMessage| {
Box::pin(async move { connection.send_message(&wallet, &msg, &HttpClient).await })
Box::pin(async move { connection.send_message(wallet, &msg, &HttpClient).await })
});
let msg_response = holder
.prepare_credential_request(
&self.profile.inject_anoncreds_ledger_read(),
&self.profile.inject_anoncreds(),
self.profile.ledger_read(),
self.profile.anoncreds(),
pw_did,
)
.await?;
Expand All @@ -133,12 +136,12 @@ impl ServiceCredentialsHolder {
let mut holder = self.get_holder(thread_id)?;
let connection_id = self.get_connection_id(thread_id)?;
let connection = self.service_connections.get_by_id(&connection_id)?;
let wallet = self.profile.inject_wallet();
let wallet = self.profile.wallet();

holder
.process_credential(
&self.profile.inject_anoncreds_ledger_read(),
&self.profile.inject_anoncreds(),
self.profile.ledger_read(),
self.profile.anoncreds(),
msg_issue_credential.clone(),
)
.await?;
Expand All @@ -147,7 +150,7 @@ impl ServiceCredentialsHolder {
Some(msg_response) => {
let send_closure: SendClosure = Box::new(|msg: AriesMessage| {
Box::pin(
async move { connection.send_message(&wallet, &msg, &HttpClient).await },
async move { connection.send_message(wallet, &msg, &HttpClient).await },
)
});
send_closure(msg_response).await?;
Expand All @@ -165,7 +168,7 @@ impl ServiceCredentialsHolder {

pub async fn is_revokable(&self, thread_id: &str) -> AgentResult<bool> {
self.get_holder(thread_id)?
.is_revokable(&self.profile.inject_anoncreds_ledger_read())
.is_revokable(self.profile.ledger_read())
.await
.map_err(|err| err.into())
}
Expand Down
23 changes: 12 additions & 11 deletions agents/rust/aries-vcx-agent/src/services/issuer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use aries_vcx::{
core::profile::profile::Profile,
core::profile::{profile::Profile, vdrtools_profile::VdrtoolsProfile},
handlers::{issuance::issuer::Issuer, util::OfferInfo},
messages::{
msg_fields::protocols::cred_issuance::v1::{
Expand Down Expand Up @@ -36,13 +36,16 @@ impl IssuerWrapper {
}

pub struct ServiceCredentialsIssuer {
profile: Arc<dyn Profile>,
profile: Arc<VdrtoolsProfile>,
creds_issuer: ObjectCache<IssuerWrapper>,
service_connections: Arc<ServiceConnections>,
}

impl ServiceCredentialsIssuer {
pub fn new(profile: Arc<dyn Profile>, service_connections: Arc<ServiceConnections>) -> Self {
pub fn new(
profile: Arc<VdrtoolsProfile>,
service_connections: Arc<ServiceConnections>,
) -> Self {
Self {
profile,
service_connections,
Expand Down Expand Up @@ -86,13 +89,13 @@ impl ServiceCredentialsIssuer {
};
let connection = self.service_connections.get_by_id(&connection_id)?;
issuer
.build_credential_offer_msg(&self.profile.inject_anoncreds(), offer_info, None)
.build_credential_offer_msg(self.profile.anoncreds(), offer_info, None)
.await?;

let wallet = self.profile.inject_wallet();
let wallet = self.profile.wallet();

let send_closure: SendClosure = Box::new(|msg: AriesMessage| {
Box::pin(async move { connection.send_message(&wallet, &msg, &HttpClient).await })
Box::pin(async move { connection.send_message(wallet, &msg, &HttpClient).await })
});

let credential_offer = issuer.get_credential_offer_msg()?;
Expand Down Expand Up @@ -140,15 +143,13 @@ impl ServiceCredentialsIssuer {
} = self.creds_issuer.get(thread_id)?;
let connection = self.service_connections.get_by_id(&connection_id)?;

let wallet = self.profile.inject_wallet();
let wallet = self.profile.wallet();

let send_closure: SendClosure = Box::new(|msg: AriesMessage| {
Box::pin(async move { connection.send_message(&wallet, &msg, &HttpClient).await })
Box::pin(async move { connection.send_message(wallet, &msg, &HttpClient).await })
});

issuer
.build_credential(&self.profile.inject_anoncreds())
.await?;
issuer.build_credential(self.profile.anoncreds()).await?;
match issuer.get_state() {
IssuerState::Failed => {
let problem_report = issuer.get_problem_report()?;
Expand Down
Loading

0 comments on commit 8a7a3ba

Please sign in to comment.