From 7a44e3279b5747819022c4d8f4474fa79b2d9746 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 13 Dec 2024 18:18:57 +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 de05aa7de..7e7a1129d 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -390,6 +390,7 @@ impl OutputInfo { // Signers can check `out_ciphertext`. ock: None, zip32_derivation: None, + user_address: None, proprietary: BTreeMap::new(), } } diff --git a/src/pczt.rs b/src/pczt.rs index ccdde32fb..3fcf72fe9 100644 --- a/src/pczt.rs +++ b/src/pczt.rs @@ -260,6 +260,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>, } @@ -273,6 +280,7 @@ impl fmt::Debug for Output { .field("value", &self.value) .field("rseed", &self.rseed) .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 1fede313b..eb0c66861 100644 --- a/src/pczt/parse.rs +++ b/src/pczt/parse.rs @@ -216,6 +216,7 @@ impl Output { rseed: Option<[u8; 32]>, ock: Option<[u8; 32]>, zip32_derivation: Option, + user_address: Option, proprietary: BTreeMap>, ) -> Result { let cmx = ExtractedNoteCommitment::from_bytes(&cmx) @@ -264,6 +265,7 @@ impl Output { rseed, ock, zip32_derivation, + user_address, proprietary, }) } diff --git a/src/pczt/updater.rs b/src/pczt/updater.rs index 761852092..5c2e00713 100644 --- a/src/pczt/updater.rs +++ b/src/pczt/updater.rs @@ -55,6 +55,11 @@ impl<'a> ActionUpdater<'a> { self.0.output.zip32_derivation = Some(derivation); } + /// Sets the user-facing address that the new note is being sent to. + pub fn set_output_user_address(&mut self, user_address: String) { + self.0.output.user_address = Some(user_address); + } + /// Stores the given output-specific proprietary value at the given key. pub fn set_output_proprietary(&mut self, key: String, value: Vec) { self.0.output.proprietary.insert(key, value);