Skip to content

Commit

Permalink
Use a sequence of bytes (representing AriesMessage) as input for Encr…
Browse files Browse the repository at this point in the history
…yptionEnvelope::create (#1007)

* Use a sequence of bytes (representing AriesMessage) as input for EncryptionEnvelope::create

Signed-off-by: Naian <126972030+nain-F49FF806@users.noreply.github.com>
  • Loading branch information
nain-F49FF806 authored Oct 4, 2023
1 parent 34c35de commit 77c8d8f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
8 changes: 7 additions & 1 deletion aries_vcx/src/protocols/connection/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,13 @@ impl GenericConnection {
AriesVcxErrorKind::NotReady,
"No DidDoc present",
))?;
EncryptionEnvelope::create(wallet, message, Some(sender_verkey), did_doc).await
EncryptionEnvelope::create(
wallet,
json!(message).to_string().as_bytes(),
Some(sender_verkey),
did_doc,
)
.await
}

pub async fn send_message<T>(
Expand Down
8 changes: 7 additions & 1 deletion aries_vcx/src/protocols/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ where
message: &AriesMessage,
) -> VcxResult<EncryptionEnvelope> {
let sender_verkey = &self.pairwise_info().pw_vk;
EncryptionEnvelope::create(wallet, message, Some(sender_verkey), self.their_did_doc()).await
EncryptionEnvelope::create(
wallet,
json!(message).to_string().as_bytes(),
Some(sender_verkey),
self.their_did_doc(),
)
.await
}

pub fn remote_did(&self) -> &str {
Expand Down
10 changes: 5 additions & 5 deletions aries_vcx/src/utils/encryption_envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ use crate::{errors::error::prelude::*, global::settings, utils::constants};
pub struct EncryptionEnvelope(pub Vec<u8>);

impl EncryptionEnvelope {
/// Create an Encryption Envelope from a plaintext AriesMessage encoded as sequence of bytes.
/// If did_doc includes routing_keys, then also wrap in appropriate layers of forward message.
pub async fn create(
wallet: &impl BaseWallet,
message: &AriesMessage,
message: &[u8],
pw_verkey: Option<&str>,
did_doc: &AriesDidDoc,
) -> VcxResult<EncryptionEnvelope> {
Expand All @@ -41,12 +43,10 @@ impl EncryptionEnvelope {

async fn encrypt_for_pairwise(
wallet: &impl BaseWallet,
message: &AriesMessage,
message: &[u8],
pw_verkey: Option<&str>,
did_doc: &AriesDidDoc,
) -> VcxResult<Vec<u8>> {
let message = json!(message).to_string();

let receiver_keys = json!(did_doc.recipient_keys()?).to_string();

debug!(
Expand All @@ -55,7 +55,7 @@ impl EncryptionEnvelope {
);

wallet
.pack_message(pw_verkey, &receiver_keys, message.as_bytes())
.pack_message(pw_verkey, &receiver_keys, message)
.await
.map_err(|err| err.into())
}
Expand Down
13 changes: 10 additions & 3 deletions aries_vcx/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ pub async fn send_message(
message,
&did_doc
);
let EncryptionEnvelope(envelope) =
EncryptionEnvelope::create(wallet, &message, Some(&sender_verkey), &did_doc).await?;

let EncryptionEnvelope(envelope) = EncryptionEnvelope::create(
wallet,
json!(message).to_string().as_bytes(),
Some(&sender_verkey),
&did_doc,
)
.await?;

// TODO: Extract from agency client
agency_client::httpclient::post_message(
Expand All @@ -81,7 +87,8 @@ pub async fn send_message_anonymously(
&did_doc
);
let EncryptionEnvelope(envelope) =
EncryptionEnvelope::create(wallet, message, None, did_doc).await?;
EncryptionEnvelope::create(wallet, json!(message).to_string().as_bytes(), None, did_doc)
.await?;

agency_client::httpclient::post_message(
envelope,
Expand Down

0 comments on commit 77c8d8f

Please sign in to comment.