Skip to content

Commit

Permalink
Add addresses to encrypted data
Browse files Browse the repository at this point in the history
Added sender and receiver addresses to encrypted data so a view only wallet
will be able to identify the receiver when importing a change output.
  • Loading branch information
hansieodendaal committed Dec 3, 2024
1 parent 5eb49e0 commit 469e5f0
Show file tree
Hide file tree
Showing 16 changed files with 524 additions and 93 deletions.
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.

1 change: 1 addition & 0 deletions base_layer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ tempfile = "3.1.0"
toml = { version = "0.5" }
quickcheck = "1.0"
serial_test = "0.5"
static_assertions = "1.1.0"

[build-dependencies]
tari_common = { path = "../../common", features = [
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,7 @@ mod test {
Covenant::default(),
0.into(),
MicroMinotari(1200) - fee - MicroMinotari(10),
TariAddress::default(),
)
.await
.unwrap()
Expand Down Expand Up @@ -1255,6 +1256,7 @@ mod test {
Covenant::default(),
0.into(),
MicroMinotari(5000),
TariAddress::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -1367,6 +1369,7 @@ mod test {
Covenant::default(),
0.into(),
MicroMinotari(5000),
TariAddress::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -1467,6 +1470,7 @@ mod test {
Covenant::default(),
0.into(),
amount,
TariAddress::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -1507,6 +1511,7 @@ mod test {
Covenant::default(),
0.into(),
amount,
TariAddress::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -1552,6 +1557,7 @@ mod test {
Covenant::default(),
0.into(),
MicroMinotari(5000),
TariAddress::default(),
)
.await
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub(super) struct RecipientDetails {
pub recipient_covenant: Covenant,
pub recipient_minimum_value_promise: MicroMinotari,
pub recipient_ephemeral_public_key_nonce: TariKeyId,
pub recipient_address: TariAddress,
}

/// The SenderTransactionProtocolBuilder is a Builder that helps set up the initial state for the Sender party of a new
Expand All @@ -98,6 +99,7 @@ pub struct SenderTransactionInitializer<KM> {
change: Option<ChangeDetails>,
recipient: Option<RecipientDetails>,
recipient_text_message: Option<String>,
payment_id: Option<PaymentId>,
prevent_fee_gt_amount: bool,
tx_id: Option<TxId>,
kernel_features: KernelFeatures,
Expand Down Expand Up @@ -130,6 +132,7 @@ where KM: TransactionKeyManagerInterface
sender_custom_outputs: Vec::new(),
change: None,
recipient_text_message: None,
payment_id: None,
prevent_fee_gt_amount: true,
recipient: None,
kernel_features: KernelFeatures::empty(),
Expand Down Expand Up @@ -162,6 +165,7 @@ where KM: TransactionKeyManagerInterface
recipient_covenant: Covenant,
recipient_minimum_value_promise: MicroMinotari,
amount: MicroMinotari,
recipient_address: TariAddress,
) -> Result<&mut Self, KeyManagerServiceError> {
let recipient_ephemeral_public_key_nonce = self
.key_manager
Expand All @@ -179,6 +183,7 @@ where KM: TransactionKeyManagerInterface
recipient_minimum_value_promise,
recipient_ephemeral_public_key_nonce: recipient_ephemeral_public_key_nonce.key_id,
amount,
recipient_address,
};
self.recipient = Some(recipient_details);
Ok(self)
Expand Down Expand Up @@ -253,6 +258,12 @@ where KM: TransactionKeyManagerInterface
self
}

/// Provide a text message for receiver
pub fn with_payment_id(&mut self, payment_id: PaymentId) -> &mut Self {
self.payment_id = Some(payment_id);
self
}

/// This will select the desired kernel features to be signed by the receiver
pub fn with_kernel_features(&mut self, features: KernelFeatures) -> &mut Self {
self.kernel_features = features;
Expand Down Expand Up @@ -402,7 +413,19 @@ where KM: TransactionKeyManagerInterface
.own_address
.clone();

let payment_id = PaymentId::Address(address);
let payment_id = if let Some(recipient) = self.recipient.clone() {
PaymentId::ChangeData {
recipient_address: recipient.recipient_address,
amount: recipient.amount,
msg_and_id: vec![],
}
} else {
PaymentId::ChangeData {
recipient_address: address,
amount: total_to_self,
msg_and_id: vec![],
}
};

let encrypted_data = self
.key_manager
Expand Down Expand Up @@ -878,6 +901,7 @@ mod test {
Default::default(),
0.into(),
MicroMinotari(500),
TariAddress::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -927,6 +951,7 @@ mod test {
Default::default(),
0.into(),
MicroMinotari::zero(),
TariAddress::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -994,6 +1019,7 @@ mod test {
Default::default(),
0.into(),
MicroMinotari(2500),
TariAddress::default(),
)
.await
.unwrap();
Expand Down
35 changes: 31 additions & 4 deletions base_layer/wallet/src/output_manager_service/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ use tari_core::{
covenants::Covenant,
transactions::{
tari_amount::MicroMinotari,
transaction_components::{OutputFeatures, Transaction, TransactionOutput, WalletOutput, WalletOutputBuilder},
transaction_components::{
encrypted_data::PaymentId,
OutputFeatures,
Transaction,
TransactionOutput,
WalletOutput,
WalletOutputBuilder,
},
transaction_protocol::{sender::TransactionSenderMessage, TransactionMetadata},
ReceiverTransactionProtocol,
SenderTransactionProtocol,
Expand Down Expand Up @@ -92,6 +99,8 @@ pub enum OutputManagerRequest {
script: TariScript,
covenant: Covenant,
minimum_value_promise: MicroMinotari,
recipient_address: TariAddress,
payment_id: PaymentId,
},
CreatePayToSelfTransaction {
tx_id: TxId,
Expand Down Expand Up @@ -119,6 +128,7 @@ pub enum OutputManagerRequest {
ScrapeWallet {
tx_id: TxId,
fee_per_gram: MicroMinotari,
recipient_address: TariAddress,
},
CreateCoinJoin {
commitments: Vec<Commitment>,
Expand Down Expand Up @@ -167,8 +177,16 @@ impl fmt::Display for OutputManagerRequest {
v.metadata_signature.u_y().to_hex(),
v.metadata_signature.u_a().to_hex(),
),
ScrapeWallet { tx_id, fee_per_gram } => {
write!(f, "ScrapeWallet (tx_id: {}, fee_per_gram: {})", tx_id, fee_per_gram)
ScrapeWallet {
tx_id,
fee_per_gram,
recipient_address,
} => {
write!(
f,
"ScrapeWallet (tx_id: {}, fee_per_gram: {}, recipient_address {})",
tx_id, fee_per_gram, recipient_address
)
},
EncumberAggregateUtxo {
tx_id,
Expand Down Expand Up @@ -509,6 +527,8 @@ impl OutputManagerHandle {
script: TariScript,
covenant: Covenant,
minimum_value_promise: MicroMinotari,
recipient_address: TariAddress,
payment_id: PaymentId,
) -> Result<SenderTransactionProtocol, OutputManagerError> {
match self
.handle
Expand All @@ -523,6 +543,8 @@ impl OutputManagerHandle {
script,
covenant,
minimum_value_promise,
recipient_address,
payment_id,
})
.await??
{
Expand All @@ -535,10 +557,15 @@ impl OutputManagerHandle {
&mut self,
tx_id: TxId,
fee_per_gram: MicroMinotari,
recipient_address: TariAddress,
) -> Result<SenderTransactionProtocol, OutputManagerError> {
match self
.handle
.call(OutputManagerRequest::ScrapeWallet { tx_id, fee_per_gram })
.call(OutputManagerRequest::ScrapeWallet {
tx_id,
fee_per_gram,
recipient_address,
})
.await??
{
OutputManagerResponse::TransactionToSend(stp) => Ok(stp),
Expand Down
25 changes: 22 additions & 3 deletions base_layer/wallet/src/output_manager_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ where
script,
covenant,
minimum_value_promise,
recipient_address,
payment_id,
} => self
.prepare_transaction_to_send(
tx_id,
Expand All @@ -339,6 +341,8 @@ where
script,
covenant,
minimum_value_promise,
recipient_address,
payment_id,
)
.await
.map(OutputManagerResponse::TransactionToSend),
Expand Down Expand Up @@ -400,8 +404,12 @@ where
.await?,
))
},
OutputManagerRequest::ScrapeWallet { tx_id, fee_per_gram } => self
.scrape_wallet(tx_id, fee_per_gram)
OutputManagerRequest::ScrapeWallet {
tx_id,
fee_per_gram,
recipient_address,
} => self
.scrape_wallet(tx_id, fee_per_gram, recipient_address)
.await
.map(OutputManagerResponse::TransactionToSend),

Expand Down Expand Up @@ -965,6 +973,8 @@ where
recipient_script: TariScript,
recipient_covenant: Covenant,
recipient_minimum_value_promise: MicroMinotari,
recipient_address: TariAddress,
payment_id: PaymentId,
) -> Result<SenderTransactionProtocol, OutputManagerError> {
debug!(
target: LOG_TARGET,
Expand Down Expand Up @@ -1011,10 +1021,12 @@ where
recipient_covenant,
recipient_minimum_value_promise,
amount,
recipient_address,
)
.await?
.with_sender_address(self.resources.interactive_tari_address.clone())
.with_message(message)
.with_payment_id(payment_id)
.with_prevent_fee_gt_amount(self.resources.config.prevent_fee_gt_amount)
.with_lock_height(tx_meta.lock_height)
.with_kernel_features(tx_meta.kernel_features)
Expand Down Expand Up @@ -1408,6 +1420,7 @@ where
Covenant::default(),
minimum_value_promise,
amount,
recipient_address.clone(),
)
.await?
.with_change_data(
Expand Down Expand Up @@ -1740,6 +1753,7 @@ where
Covenant::default(),
minimum_value_promise,
amount,
recipient_address.clone(),
)
.await?
.with_change_data(
Expand Down Expand Up @@ -1818,7 +1832,10 @@ where
.await?;
let script = push_pubkey_script(&script_spending_key);
let payment_id = match payment_id {
PaymentId::Open(v) => PaymentId::AddressAndData(self.resources.interactive_tari_address.clone(), v),
PaymentId::Open(v) => PaymentId::AddressAndData {
sender_address: self.resources.interactive_tari_address.clone(),
id: v,
},
PaymentId::Empty => PaymentId::Address(self.resources.one_sided_tari_address.clone()),
_ => payment_id,
};
Expand Down Expand Up @@ -2831,6 +2848,7 @@ where
&mut self,
tx_id: TxId,
fee_per_gram: MicroMinotari,
recipient_address: TariAddress,
) -> Result<SenderTransactionProtocol, OutputManagerError> {
let default_features_and_scripts_size = self
.default_features_and_scripts_size()
Expand Down Expand Up @@ -2862,6 +2880,7 @@ where
Default::default(),
MicroMinotari::zero(),
accumulated_amount,
recipient_address,
)
.await?
.with_sender_address(self.resources.interactive_tari_address.clone())
Expand Down
Loading

0 comments on commit 469e5f0

Please sign in to comment.