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

pczt: Add output field for storing the user-facing address #148

Merged
merged 1 commit into from
Dec 13, 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 src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ impl PreparedOutputInfo {
// TODO: Save this?
ock: None,
zip32_derivation: None,
user_address: None,
proprietary: BTreeMap::new(),
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/pczt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Zip32Derivation>,

/// 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<String>,

/// Proprietary fields related to the note being created.
pub(crate) proprietary: BTreeMap<String, Vec<u8>>,
}
Expand All @@ -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()
}
Expand Down
2 changes: 2 additions & 0 deletions src/pczt/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ impl Output {
rcv: Option<[u8; 32]>,
ock: Option<[u8; 32]>,
zip32_derivation: Option<Zip32Derivation>,
user_address: Option<String>,
proprietary: BTreeMap<String, Vec<u8>>,
) -> Result<Self, ParseError> {
let cv = ValueCommitment::from_bytes_not_small_order(&cv)
Expand Down Expand Up @@ -232,6 +233,7 @@ impl Output {
rcv,
ock,
zip32_derivation,
user_address,
proprietary,
})
}
Expand Down
5 changes: 5 additions & 0 deletions src/pczt/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>) {
self.0.proprietary.insert(key, value);
Expand Down
Loading