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

feat: replace BaseWallet with BaseWallet2 #1093

Merged
merged 8 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions aries/agents/rust/mediator/src/aries_agent/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<T: BaseWallet + 'static, P: MediatorPersistence> Agent<T, P> {
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().into(),
pw_vk: did_data.verkey().base58(),
},
)
.accept_invitation(&mock_ledger, AnyInvitation::Oob(oob_invite.clone()))
.await
Expand Down
13 changes: 7 additions & 6 deletions aries/agents/rust/mediator/src/aries_agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,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().base58()],
routing_keys,
service_endpoint,
};
Expand Down Expand Up @@ -170,7 +170,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 +188,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().into(),
did_data.verkey().base58(),
self.service.as_ref().unwrap().service_endpoint.clone(),
self.service.as_ref().unwrap().routing_keys.clone(),
)
Expand All @@ -209,7 +209,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().base58(), &their_diddoc)
.await?;
Ok(packed_response_envelope)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use messages::msg_fields::protocols::connection::Connection;

use super::{unhandled_aries_message, utils::prelude::*, ArcAgent};
Expand Down
1 change: 1 addition & 0 deletions aries/agents/rust/mediator/src/didcomm_handlers/forward.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use messages::msg_fields::protocols::{notification::ack::Ack, routing::Forward};

use super::{utils::prelude::*, ArcAgent};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use messages::msg_fields::protocols::coordinate_mediation::{
CoordinateMediation, MediateGrant, MediateGrantContent, MediateGrantDecorators,
};
Expand Down
1 change: 1 addition & 0 deletions 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::wallet::base_wallet::BaseWallet;
use axum::{body::Bytes, extract::State, Json};
use messages::AriesMessage;
use serde::{Deserialize, Serialize};
Expand Down
1 change: 1 addition & 0 deletions aries/agents/rust/mediator/src/didcomm_handlers/pickup.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use messages::msg_fields::protocols::pickup::Pickup;

use super::utils::prelude::*;
Expand Down
16 changes: 8 additions & 8 deletions aries/agents/rust/mediator/tests/mediator-coord-protocol.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod common;

use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::wallet::base_wallet::DidWallet;
use messages::{
msg_fields::protocols::coordinate_mediation::{
keylist_update::{KeylistUpdateItem, KeylistUpdateItemAction},
Expand Down Expand Up @@ -69,14 +69,14 @@ async fn test_mediate_keylist_update_add() -> Result<()> {
let (agent, mut aries_transport, our_verkey, their_diddoc) =
gen_mediator_connected_agent().await?;
// prepare request message
let (_, new_vk) = agent
let did_data = agent
.get_wallet_ref()
.create_and_store_my_did(None, None)
.await?;
let keylist_update_request = KeylistUpdate::builder()
.content(KeylistUpdateContent {
updates: vec![KeylistUpdateItem {
recipient_key: new_vk,
recipient_key: did_data.verkey().base58(),
action: KeylistUpdateItemAction::Add,
}],
})
Expand Down Expand Up @@ -120,14 +120,14 @@ async fn test_mediate_keylist_query() -> Result<()> {
let (agent, mut aries_transport, our_verkey, their_diddoc) =
gen_mediator_connected_agent().await?;
// prepare request message: add key
let (_, new_vk) = agent
let did_data = agent
.get_wallet_ref()
.create_and_store_my_did(None, None)
.await?;
let keylist_update_request = KeylistUpdate::builder()
.content(KeylistUpdateContent {
updates: vec![KeylistUpdateItem {
recipient_key: new_vk,
recipient_key: did_data.verkey().base58(),
action: KeylistUpdateItemAction::Add,
}],
})
Expand Down Expand Up @@ -188,14 +188,14 @@ async fn test_mediate_keylist_update_remove() -> Result<()> {
let (agent, mut aries_transport, our_verkey, their_diddoc) =
gen_mediator_connected_agent().await?;
// prepare request message: add key
let (_, new_vk) = agent
let did_data = agent
.get_wallet_ref()
.create_and_store_my_did(None, None)
.await?;
let keylist_update_request = KeylistUpdate::builder()
.content(KeylistUpdateContent {
updates: vec![KeylistUpdateItem {
recipient_key: new_vk.clone(),
recipient_key: did_data.verkey().base58(),
action: KeylistUpdateItemAction::Add,
}],
})
Expand All @@ -220,7 +220,7 @@ async fn test_mediate_keylist_update_remove() -> Result<()> {
let keylist_update_request = KeylistUpdate::builder()
.content(KeylistUpdateContent {
updates: vec![KeylistUpdateItem {
recipient_key: new_vk,
recipient_key: did_data.verkey().base58(),
action: KeylistUpdateItemAction::Remove,
}],
})
Expand Down
9 changes: 3 additions & 6 deletions aries/aries_vcx/src/common/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,16 @@ pub async fn rotate_verkey_apply(
));
}

wallet
.replace_did_keys_apply(did)
.await
.map_err(|err| err.into())
Ok(wallet.replace_did_key_apply(did).await?)
}

pub async fn rotate_verkey(
wallet: &impl BaseWallet,
indy_ledger_write: &impl IndyLedgerWrite,
did: &str,
) -> VcxResult<()> {
let trustee_temp_verkey = wallet.replace_did_keys_start(did).await?;
rotate_verkey_apply(wallet, indy_ledger_write, did, &trustee_temp_verkey).await
let trustee_verkey = wallet.replace_did_key_start(did, None).await?;
rotate_verkey_apply(wallet, indy_ledger_write, did, &trustee_verkey.base58()).await
}

pub async fn get_verkey_from_ledger(
Expand Down
13 changes: 10 additions & 3 deletions aries/aries_vcx/src/common/ledger/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,21 @@ pub async fn add_new_did(
submitter_did: &str,
role: Option<&str>,
) -> VcxResult<(String, String)> {
let (did, verkey) = wallet.create_and_store_my_did(None, None).await?;
let did_data = wallet.create_and_store_my_did(None, None).await?;

let res = indy_ledger_write
.publish_nym(wallet, submitter_did, &did, Some(&verkey), None, role)
.publish_nym(
wallet,
submitter_did,
did_data.did(),
Some(&did_data.verkey().base58()),
None,
role,
)
.await?;
check_response(&res)?;

Ok((did, verkey))
Ok((did_data.did().into(), did_data.verkey().base58()))
}

pub async fn get_service(ledger: &impl IndyLedgerRead, did: &String) -> VcxResult<AriesService> {
Expand Down
14 changes: 12 additions & 2 deletions aries/aries_vcx/src/common/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use messages::msg_fields::protocols::connection::{
response::{ConnectionSignature, ResponseContent},
ConnectionData,
};
use public_key::{Key, KeyType};
use time;

use crate::{errors::error::prelude::*, utils::base64::URL_SAFE_LENIENT};
Expand All @@ -27,7 +28,9 @@ async fn get_signature_data(
let mut sig_data = now.to_be_bytes().to_vec();
sig_data.extend(data.as_bytes());

let signature = wallet.sign(key, &sig_data).await?;
let signature = wallet
.sign(&Key::from_base58(key, KeyType::Ed25519)?, &sig_data)
.await?;

Ok((signature, sig_data))
}
Expand Down Expand Up @@ -64,7 +67,14 @@ pub async fn decode_signed_connection_response(

let sig_data = base64url_decode(&response.connection_sig.sig_data)?;

if !wallet.verify(their_vk, &sig_data, &signature).await? {
if !wallet
.verify(
&Key::from_base58(their_vk, KeyType::Ed25519)?,
&sig_data,
&signature,
)
.await?
{
return Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidJson,
"ConnectionResponse signature is invalid for original Invite recipient key",
Expand Down
7 changes: 5 additions & 2 deletions aries/aries_vcx/src/protocols/connection/pairwise_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ pub struct PairwiseInfo {

impl PairwiseInfo {
pub async fn create(wallet: &impl BaseWallet) -> VcxResult<PairwiseInfo> {
let (pw_did, pw_vk) = wallet.create_and_store_my_did(None, None).await?;
Ok(PairwiseInfo { pw_did, pw_vk })
let did_data = wallet.create_and_store_my_did(None, None).await?;
Ok(PairwiseInfo {
pw_did: did_data.did().into(),
pw_vk: did_data.verkey().base58(),
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub async fn jws_sign_attach(
let b64_protected =
base64::engine::Engine::encode(&URL_SAFE_NO_PAD, protected_header.to_string());
let sign_input = format!("{}.{}", b64_protected, attach_base64).into_bytes();
let signed = wallet.sign(&verkey.base58(), &sign_input).await?;
let signed = wallet.sign(&verkey, &sign_input).await?;
let signature_base64 = base64::engine::Engine::encode(&URL_SAFE_NO_PAD, signed);

let jws = {
Expand Down
Loading
Loading