Skip to content

Commit

Permalink
Merge branch 'main' into nain/mediator-client
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas committed Oct 24, 2023
2 parents e020eba + dbaac13 commit 23fd9fa
Show file tree
Hide file tree
Showing 144 changed files with 4,031 additions and 1,987 deletions.
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Join the chat at https://chat.hyperledger.org/channel/aries](https://img.shields.io/badge/Chat%20on-Hyperledger%20Chat-blue)](https://chat.hyperledger.org/channel/aries)

The repository contains
- Rust library `aries-vcx` implementing Aries protocols,
- collection of supporting projects.
The repository contains a set of crates to build [Aries](https://github.com/hyperledger/aries-rfcs/) / [DIDComm](https://didcomm.org/) applications in Rust.

## If you are Rust 🦀 developer
You can build your Rust project on top of
- [`aries-vcx`](aries_vcx) - ready to go Rust library to work with Aries protocols for didcomm, VC issuance and verification.
## Aries components
- [`aries_vcx`](aries_vcx) - Library implementing DIDComm protocols, with focus on verifiable credential issuance and verification.
- [`messages`](messages) - Library for building and parsing Aries messages.
- `aries_vcx_core` - Interfaces for interaction with ledgers, wallets and credentials.
- [`agents`](agents/rust) - Aries agents built on top of `aries_vcx`.

## General components
- `did_parser` - Building and parsing [DIDs](https://w3c.github.io/did-core/).
- `did_doc` - Building and parsing DID Documents.
- `did_peer`, `did_sov`, `did_web`, `did_key` - DID resolvers for different [DID methods](https://w3c.github.io/did-spec-registries/#did-methods).

Additionally, `aries-vcx` is built on top of smaller Rust crates which are part of this repo:
- [`aries_vcx_core`](aries_vcx_core) - foundational APIs to interact with ledger, wallet and anoncreds.
- [`messages`](messages) - crate for building and parsing Aries messages
- [`did_doc`](diddoc) - crate to work with DIDDocs

## If you are mobile 📱 developer
Aries-vcx can be used to build native mobile applications. You can write part of your mobile backend in Rust on top of
`aries-vcx` crate. Then expose FFI API for iOS/android environments.
- There's POC in progress [`uniffi_aries_vcx`](./uniffi_aries_vcx) using UniFFI library to autogenerate Swift and Kotlin wrappers.
## Mobile 📱
- [`uniffi_aries_vcx`](./uniffi_aries_vcx) - UniFFI wrapper for `aries_vcx` and sample mobile app
- [`simple_message_relay`](./tools/simple_message_relay) - simple implementation of message relay service for development / testing purposes

# Reach out 👋
- Ask a question on [discord](https://discord.com/channels/905194001349627914/955480822675308604)
Expand Down
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;
4 changes: 4 additions & 0 deletions agents/rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Rust agents
This directory contains some of Rust agents built on top of the `aries_vcx` crate:
- `aries-vcx-agent` - aries agent library providing used to build our cross-framework testing [backchannel](https://github.com/hyperledger/aries-agent-test-harness/tree/main/aries-backchannels/aries-vcx)

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
Loading

0 comments on commit 23fd9fa

Please sign in to comment.