Skip to content

Commit

Permalink
feat: replace BaseWallet with BaseWallet2
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Prazak <[email protected]>
  • Loading branch information
Ondrej Prazak committed Dec 29, 2023
1 parent f410503 commit 2f63acc
Show file tree
Hide file tree
Showing 76 changed files with 1,762 additions and 594 deletions.
4 changes: 2 additions & 2 deletions aries/agents/rust/aries-vcx-agent/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use aries_vcx::{
messages::AriesMessage,
utils::{encryption_envelope::EncryptionEnvelope, from_did_doc_sov_to_legacy},
};
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::wallet2::BaseWallet2;
use serde_json::json;
use url::Url;

Expand Down Expand Up @@ -32,7 +32,7 @@ pub fn get_their_endpoint(did_document: &DidDocumentSov) -> AgentResult<Url> {
pub async fn pairwise_encrypt(
our_did_doc: &DidDocumentSov,
their_did_doc: &DidDocumentSov,
wallet: &impl BaseWallet,
wallet: &impl BaseWallet2,
message: &AriesMessage,
) -> AgentResult<EncryptionEnvelope> {
let sender_verkey = our_did_doc
Expand Down
4 changes: 2 additions & 2 deletions aries/agents/rust/mediator/client-tui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::VecDeque;

use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::wallet2::BaseWallet2;
use mediator::{
aries_agent::{client::transports::AriesReqwest, ArcAgent},
persistence::MediatorPersistence,
Expand All @@ -9,7 +9,7 @@ use messages::msg_fields::protocols::out_of_band::invitation::Invitation as OOBI
use serde_json::{json, Value};

pub async fn handle_register(
agent: ArcAgent<impl BaseWallet + 'static, impl MediatorPersistence>,
agent: ArcAgent<impl BaseWallet2 + 'static, impl MediatorPersistence>,
oob_invite: OOBInvitation,
) -> Result<Value, String> {
let mut aries_transport = AriesReqwest {
Expand Down
12 changes: 6 additions & 6 deletions aries/agents/rust/mediator/client-tui/src/tui.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::wallet2::BaseWallet2;
use client_tui::handle_register;
use cursive::{
direction::Orientation,
Expand All @@ -17,7 +17,7 @@ use log::info;
use mediator::{aries_agent::Agent, persistence::MediatorPersistence};
use messages::msg_fields::protocols::out_of_band::invitation::Invitation as OOBInvitation;

pub async fn init_tui<T: BaseWallet + 'static, P: MediatorPersistence>(agent: Agent<T, P>) {
pub async fn init_tui<T: BaseWallet2 + 'static, P: MediatorPersistence>(agent: Agent<T, P>) {
let mut cursive = Cursive::new();
cursive.add_global_callback(Key::Esc, |s| s.quit());
cursive.set_user_data(Arc::new(agent));
Expand All @@ -29,7 +29,7 @@ pub async fn init_tui<T: BaseWallet + 'static, P: MediatorPersistence>(agent: Ag
cursive.run()
}

pub fn endpoints_ui<T: BaseWallet + 'static, P: MediatorPersistence>() -> Panel<LinearLayout> {
pub fn endpoints_ui<T: BaseWallet2 + 'static, P: MediatorPersistence>() -> Panel<LinearLayout> {
let mut endpoint_selector = SelectView::new();
// Set available endpoints
endpoint_selector.add_item_str("/client/register");
Expand All @@ -52,7 +52,7 @@ pub fn endpoints_ui<T: BaseWallet + 'static, P: MediatorPersistence>() -> Panel<
make_standard(endpoint_selector, Orientation::Vertical).title("Select endpoint")
}

pub fn client_register_ui<T: BaseWallet + 'static, P: MediatorPersistence>() -> Panel<LinearLayout>
pub fn client_register_ui<T: BaseWallet2 + 'static, P: MediatorPersistence>() -> Panel<LinearLayout>
{
let input = TextArea::new().with_name("oob_text_area");
let input = ResizedView::new(
Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn client_register_ui<T: BaseWallet + 'static, P: MediatorPersistence>() ->
make_standard(ui, Orientation::Horizontal).title("Register client using Out Of Band Invitation")
}

pub fn client_register_connect_cb<T: BaseWallet + 'static, P: MediatorPersistence>(
pub fn client_register_connect_cb<T: BaseWallet2 + 'static, P: MediatorPersistence>(
s: &mut Cursive,
) {
let oob_text_area = s.find_name::<TextArea>("oob_text_area").unwrap();
Expand Down Expand Up @@ -120,7 +120,7 @@ fn make_standard(view: impl View, orientation: Orientation) -> Panel<LinearLayou
// contact_selector_ui(s)
// }

pub fn contact_selector_ui<T: BaseWallet + 'static, P: MediatorPersistence>(
pub fn contact_selector_ui<T: BaseWallet2 + 'static, P: MediatorPersistence>(
s: &mut Cursive,
) -> Panel<LinearLayout> {
let mut contact_selector = SelectView::new();
Expand Down
11 changes: 7 additions & 4 deletions aries/agents/rust/mediator/src/aries_agent/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use aries_vcx::{
},
utils::encryption_envelope::EncryptionEnvelope,
};
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::wallet2::BaseWallet2;
use messages::{
msg_fields::protocols::{
connection::{response::Response, Connection},
Expand All @@ -31,15 +31,15 @@ use super::Agent;
use crate::utils::prelude::*;

// client role utilities
impl<T: BaseWallet + 'static, P: MediatorPersistence> Agent<T, P> {
impl<T: BaseWallet2 + 'static, P: MediatorPersistence> Agent<T, P> {
/// Starting from a new connection object, tries to create connection request object for the
/// specified OOB invite endpoint
pub async fn gen_connection_request(
&self,
oob_invite: OOBInvitation,
) -> Result<(InviteeConnection<ClientRequestSent>, EncryptionEnvelope), String> {
// Generate keys
let (pw_did, pw_vk) = self
let did_data = self
.wallet
.create_and_store_my_did(None, None)
.await
Expand All @@ -48,7 +48,10 @@ impl<T: BaseWallet + 'static, P: MediatorPersistence> Agent<T, P> {
let mock_ledger = MockLedger {}; // not good. to be dealt later
let client_conn = InviteeConnection::<ClientInit>::new_invitee(
"foo".into(),
PairwiseInfo { pw_did, pw_vk },
PairwiseInfo {
pw_did: did_data.did,
pw_vk: did_data.verkey,
},
)
.accept_invitation(&mock_ledger, AnyInvitation::Oob(oob_invite.clone()))
.await
Expand Down
30 changes: 14 additions & 16 deletions aries/agents/rust/mediator/src/aries_agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ use aries_vcx::{
};
use aries_vcx_core::{
errors::error::AriesVcxCoreError,
wallet::{
base_wallet::BaseWallet,
indy::{wallet::create_and_open_wallet, IndySdkWallet, WalletConfig},
structs_io::UnpackMessageOutput,
},
wallet::indy::{wallet::create_and_open_wallet, IndySdkWallet, WalletConfig},
wallet2::{BaseWallet2, UnpackedMessage},
WalletHandle,
};
use diddoc_legacy::aries::{diddoc::AriesDidDoc, service::AriesService};
Expand All @@ -34,15 +31,15 @@ pub mod client;
pub mod utils;

#[derive(Clone)]
pub struct Agent<T: BaseWallet, P: MediatorPersistence> {
pub struct Agent<T: BaseWallet2, P: MediatorPersistence> {
wallet: Arc<T>,
persistence: Arc<P>,
service: Option<AriesService>,
}

pub type ArcAgent<T, P> = Arc<Agent<T, P>>;

pub struct AgentBuilder<T: BaseWallet> {
pub struct AgentBuilder<T: BaseWallet2> {
_type_wallet: PhantomData<T>,
}
/// Constructors
Expand Down Expand Up @@ -77,8 +74,8 @@ impl AgentBuilder<IndySdkWallet> {
}

// Utils
impl<T: BaseWallet + 'static, P: MediatorPersistence> Agent<T, P> {
pub fn get_wallet_ref(&self) -> Arc<impl BaseWallet> {
impl<T: BaseWallet2 + 'static, P: MediatorPersistence> Agent<T, P> {
pub fn get_wallet_ref(&self) -> Arc<impl BaseWallet2> {
self.wallet.clone()
}
pub fn get_persistence_ref(&self) -> Arc<impl MediatorPersistence> {
Expand All @@ -92,12 +89,12 @@ impl<T: BaseWallet + 'static, P: MediatorPersistence> Agent<T, P> {
routing_keys: Vec<String>,
service_endpoint: url::Url,
) -> Result<(), AriesVcxCoreError> {
let (_, vk) = self.wallet.create_and_store_my_did(None, None).await?;
let did_data = self.wallet.create_and_store_my_did(None, None).await?;
let service = AriesService {
id: "#inline".to_owned(),
type_: "did-communication".to_owned(),
priority: 0,
recipient_keys: vec![vk],
recipient_keys: vec![did_data.verkey],
routing_keys,
service_endpoint,
};
Expand All @@ -122,7 +119,7 @@ impl<T: BaseWallet + 'static, P: MediatorPersistence> Agent<T, P> {
Err("No service to create invite for".to_owned())
}
}
pub async fn unpack_didcomm(&self, didcomm_msg: &[u8]) -> Result<UnpackMessageOutput, String> {
pub async fn unpack_didcomm(&self, didcomm_msg: &[u8]) -> Result<UnpackedMessage, String> {
let unpacked = self
.wallet
.unpack_message(didcomm_msg)
Expand Down Expand Up @@ -170,7 +167,7 @@ impl<T: BaseWallet + 'static, P: MediatorPersistence> Agent<T, P> {
.thread
.map(|t| t.thid)
.unwrap_or(request.id);
let (did, vk) = self
let did_data = self
.wallet
.create_and_store_my_did(None, None)
.await
Expand All @@ -188,8 +185,8 @@ impl<T: BaseWallet + 'static, P: MediatorPersistence> Agent<T, P> {
self.wallet.as_ref(),
thread_id,
old_vk.clone(),
did,
vk.clone(),
did_data.did,
did_data.verkey.clone(),
self.service.as_ref().unwrap().service_endpoint.clone(),
self.service.as_ref().unwrap().routing_keys.clone(),
)
Expand All @@ -209,7 +206,8 @@ impl<T: BaseWallet + 'static, P: MediatorPersistence> Agent<T, P> {
let auth_pubkey = their_keys
.first()
.ok_or("No recipient key for client :/ ?".to_owned())?;
self.create_account(auth_pubkey, &vk, &their_diddoc).await?;
self.create_account(auth_pubkey, &did_data.verkey, &their_diddoc)
.await?;
Ok(packed_response_envelope)
}

Expand Down
4 changes: 2 additions & 2 deletions aries/agents/rust/mediator/src/aries_agent/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use aries_vcx::{
common::signing::sign_connection_response, errors::error::VcxResult, transport::Transport,
};
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::wallet2::BaseWallet2;
use axum::async_trait;
use diddoc_legacy::aries::diddoc::AriesDidDoc;
use messages::{
Expand All @@ -16,7 +16,7 @@ use uuid::Uuid;
use crate::utils::structs::VerKey;

pub async fn build_response_content(
wallet: &impl BaseWallet,
wallet: &impl BaseWallet2,
thread_id: String,
old_recipient_vk: VerKey,
new_recipient_did: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use aries_vcx_core::wallet2::BaseWallet2;
use messages::msg_fields::protocols::connection::Connection;

use super::{unhandled_aries_message, utils::prelude::*, ArcAgent};

pub async fn handle_aries_connection<T: BaseWallet + 'static, P: MediatorPersistence>(
pub async fn handle_aries_connection<T: BaseWallet2 + 'static, P: MediatorPersistence>(
agent: ArcAgent<T, P>,
connection: Connection,
) -> Result<EncryptionEnvelope, String> {
Expand Down
3 changes: 2 additions & 1 deletion aries/agents/rust/mediator/src/didcomm_handlers/forward.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use aries_vcx_core::wallet2::BaseWallet2;
use messages::msg_fields::protocols::{notification::ack::Ack, routing::Forward};

use super::{utils::prelude::*, ArcAgent};
use crate::mediation::forward::handle_forward;

pub async fn handle_routing_forward(
agent: ArcAgent<impl BaseWallet + 'static, impl MediatorPersistence>,
agent: ArcAgent<impl BaseWallet2 + 'static, impl MediatorPersistence>,
forward: Forward,
) -> Result<Ack, String> {
info!("{:?}", forward);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use aries_vcx_core::wallet2::BaseWallet2;
use messages::msg_fields::protocols::coordinate_mediation::{
CoordinateMediation, MediateGrant, MediateGrantContent, MediateGrantDecorators,
};
Expand All @@ -6,7 +7,7 @@ use uuid::Uuid;
use super::utils::prelude::*;

pub async fn handle_mediation_coord(
agent: &ArcAgent<impl BaseWallet + 'static, impl MediatorPersistence>,
agent: &ArcAgent<impl BaseWallet2 + 'static, impl MediatorPersistence>,
coord_msg: CoordinateMediation,
auth_pubkey: &str,
) -> Result<CoordinateMediation, String> {
Expand Down
3 changes: 2 additions & 1 deletion aries/agents/rust/mediator/src/didcomm_handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::fmt::Debug;

use aries_vcx_core::wallet2::BaseWallet2;
use axum::{body::Bytes, extract::State, Json};
use messages::AriesMessage;
use serde::{Deserialize, Serialize};
Expand All @@ -26,7 +27,7 @@ pub fn unhandled_aries_message(message: impl Debug) -> String {
format!("Don't know how to handle this message type {:#?}", message)
}

pub async fn handle_aries<T: BaseWallet + 'static, P: MediatorPersistence>(
pub async fn handle_aries<T: BaseWallet2 + 'static, P: MediatorPersistence>(
State(agent): State<ArcAgent<T, P>>,
didcomm_msg: Bytes,
) -> Result<Json<Value>, String> {
Expand Down
3 changes: 2 additions & 1 deletion aries/agents/rust/mediator/src/didcomm_handlers/pickup.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use aries_vcx_core::wallet2::BaseWallet2;
use messages::msg_fields::protocols::pickup::Pickup;

use super::utils::prelude::*;

pub async fn handle_pickup_protocol(
agent: &ArcAgent<impl BaseWallet + 'static, impl MediatorPersistence>,
agent: &ArcAgent<impl BaseWallet2 + 'static, impl MediatorPersistence>,
pickup_message: Pickup,
auth_pubkey: &str,
) -> Result<Pickup, String> {
Expand Down
2 changes: 1 addition & 1 deletion aries/agents/rust/mediator/src/didcomm_handlers/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod prelude {
pub use std::sync::Arc;

pub use aries_vcx::utils::encryption_envelope::EncryptionEnvelope;
pub use aries_vcx_core::wallet::base_wallet::BaseWallet;
pub use aries_vcx_core::wallet2::BaseWallet2;

pub use crate::{aries_agent::ArcAgent, persistence::MediatorPersistence, utils::prelude::*};
}
10 changes: 5 additions & 5 deletions aries/agents/rust/mediator/src/http_routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::wallet2::BaseWallet2;
use axum::{
body::Bytes,
extract::State,
Expand All @@ -19,7 +19,7 @@ use crate::{

pub async fn oob_invite_qr(
headers: HeaderMap,
State(agent): State<ArcAgent<impl BaseWallet + 'static, impl MediatorPersistence>>,
State(agent): State<ArcAgent<impl BaseWallet2 + 'static, impl MediatorPersistence>>,
) -> Response {
let Json(oob_json) = oob_invite_json(State(agent)).await;
let preferred_mimetype = headers
Expand Down Expand Up @@ -48,14 +48,14 @@ pub async fn oob_invite_qr(
}

pub async fn oob_invite_json(
State(agent): State<ArcAgent<impl BaseWallet + 'static, impl MediatorPersistence>>,
State(agent): State<ArcAgent<impl BaseWallet2 + 'static, impl MediatorPersistence>>,
) -> Json<Value> {
let oob = agent.get_oob_invite().unwrap();
Json(serde_json::to_value(oob).unwrap())
}

pub async fn handle_didcomm(
State(agent): State<ArcAgent<impl BaseWallet + 'static, impl MediatorPersistence>>,
State(agent): State<ArcAgent<impl BaseWallet2 + 'static, impl MediatorPersistence>>,
didcomm_msg: Bytes,
) -> Result<Json<Value>, String> {
didcomm_handlers::handle_aries(State(agent), didcomm_msg).await
Expand All @@ -66,7 +66,7 @@ pub async fn readme() -> Html<String> {
}

pub async fn build_router(
agent: Agent<impl BaseWallet + 'static, impl MediatorPersistence>,
agent: Agent<impl BaseWallet2 + 'static, impl MediatorPersistence>,
) -> Router {
Router::default()
.route("/", get(readme))
Expand Down
Loading

0 comments on commit 2f63acc

Please sign in to comment.