From e47d57f5c9c46f05740328f8ef9601f6d697cf34 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 13 Dec 2024 18:21:52 +0000 Subject: [PATCH] pczt: Add output field for storing the user-facing address This is necessary in order for Signers to display the address encoding that a user is expecting to confirm. Co-authored-by: Kris Nuttycombe --- src/builder.rs | 1 + src/pczt.rs | 8 ++++++++ src/pczt/parse.rs | 2 ++ src/pczt/updater.rs | 5 +++++ 4 files changed, 16 insertions(+) diff --git a/src/builder.rs b/src/builder.rs index 91a6cd4..6665563 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -516,6 +516,7 @@ impl PreparedOutputInfo { // TODO: Save this? ock: None, zip32_derivation: None, + user_address: None, proprietary: BTreeMap::new(), } } diff --git a/src/pczt.rs b/src/pczt.rs index 2bbeafc..d478b44 100644 --- a/src/pczt.rs +++ b/src/pczt.rs @@ -265,6 +265,13 @@ pub struct Output { /// The ZIP 32 derivation path at which the spending key can be found for the output. pub(crate) zip32_derivation: Option, + /// The user-facing address to which this output is being sent, if any. + /// + /// - This is set by an Updater. + /// - Signers must parse this address (if present) and confirm that it contains + /// `recipient` (either directly, or e.g. as a receiver within a Unified Address). + pub(crate) user_address: Option, + /// Proprietary fields related to the note being created. pub(crate) proprietary: BTreeMap>, } @@ -283,6 +290,7 @@ impl fmt::Debug for Output { .field("rseed", &self.rseed) .field("rcv", &self.rcv) .field("zip32_derivation", &self.zip32_derivation) + .field("user_address", &self.user_address) .field("proprietary", &self.proprietary) .finish_non_exhaustive() } diff --git a/src/pczt/parse.rs b/src/pczt/parse.rs index ec79051..4ac77db 100644 --- a/src/pczt/parse.rs +++ b/src/pczt/parse.rs @@ -180,6 +180,7 @@ impl Output { rcv: Option<[u8; 32]>, ock: Option<[u8; 32]>, zip32_derivation: Option, + user_address: Option, proprietary: BTreeMap>, ) -> Result { let cv = ValueCommitment::from_bytes_not_small_order(&cv) @@ -232,6 +233,7 @@ impl Output { rcv, ock, zip32_derivation, + user_address, proprietary, }) } diff --git a/src/pczt/updater.rs b/src/pczt/updater.rs index 2f05998..71c7d7a 100644 --- a/src/pczt/updater.rs +++ b/src/pczt/updater.rs @@ -86,6 +86,11 @@ impl<'a> OutputUpdater<'a> { self.0.zip32_derivation = Some(derivation); } + /// Sets the user-facing address that the new note is being sent to. + pub fn set_user_address(&mut self, user_address: String) { + self.0.user_address = Some(user_address); + } + /// Stores the given proprietary value at the given key. pub fn set_proprietary(&mut self, key: String, value: Vec) { self.0.proprietary.insert(key, value);