Skip to content

Commit

Permalink
Merge pull request #1654 from zcash/pczt-user-address
Browse files Browse the repository at this point in the history
pczt: Add output field for storing the user-facing address
  • Loading branch information
nuttycom authored Dec 13, 2024
2 parents e933473 + 3d1e322 commit 554e4e5
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 66 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,5 @@ debug = true
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(zcash_unstable, values("zfuture"))'] }

[patch.crates-io]
orchard = { git = "https://github.com/zcash/orchard.git", rev = "3d951b4201a63f3c07cba8b179dd9abde142cf33" }
sapling-crypto = { git = "https://github.com/zcash/sapling-crypto.git", rev = "231f81911628499a8877be57e66e60c09e55bdea" }
orchard = { git = "https://github.com/zcash/orchard.git", rev = "7a44e3279b5747819022c4d8f4474fa79b2d9746" }
sapling-crypto = { git = "https://github.com/zcash/sapling-crypto.git", rev = "e47d57f5c9c46f05740328f8ef9601f6d697cf34" }
12 changes: 12 additions & 0 deletions pczt/src/orchard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ 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).
#[getset(get = "pub")]
pub(crate) user_address: Option<String>,

/// Proprietary fields related to the note being created.
#[getset(get = "pub")]
pub(crate) proprietary: BTreeMap<String, Vec<u8>>,
Expand Down Expand Up @@ -335,6 +343,7 @@ impl Bundle {
rseed: output_rseed,
ock,
zip32_derivation: output_zip32_derivation,
user_address,
proprietary: output_proprietary,
},
rcv,
Expand Down Expand Up @@ -367,6 +376,7 @@ impl Bundle {
&& merge_optional(&mut lhs.output.rseed, output_rseed)
&& merge_optional(&mut lhs.output.ock, ock)
&& merge_optional(&mut lhs.output.zip32_derivation, output_zip32_derivation)
&& merge_optional(&mut lhs.output.user_address, user_address)
&& merge_map(&mut lhs.output.proprietary, output_proprietary)
&& merge_optional(&mut lhs.rcv, rcv))
{
Expand Down Expand Up @@ -430,6 +440,7 @@ impl Bundle {
)
})
.transpose()?,
action.output.user_address,
action.output.proprietary,
)?;

Expand Down Expand Up @@ -521,6 +532,7 @@ impl Bundle {
.collect(),
}
}),
user_address: output.user_address().clone(),
proprietary: output.proprietary().clone(),
},
rcv: action.rcv().as_ref().map(|rcv| rcv.to_bytes()),
Expand Down
12 changes: 12 additions & 0 deletions pczt/src/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ 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).
#[getset(get = "pub")]
pub(crate) user_address: Option<String>,

/// Proprietary fields related to the note being spent.
#[getset(get = "pub")]
pub(crate) proprietary: BTreeMap<String, Vec<u8>>,
Expand Down Expand Up @@ -391,6 +399,7 @@ impl Bundle {
rcv,
ock,
zip32_derivation,
user_address,
proprietary,
} = rhs;

Expand All @@ -410,6 +419,7 @@ impl Bundle {
&& merge_optional(&mut lhs.rcv, rcv)
&& merge_optional(&mut lhs.ock, ock)
&& merge_optional(&mut lhs.zip32_derivation, zip32_derivation)
&& merge_optional(&mut lhs.user_address, user_address)
&& merge_map(&mut lhs.proprietary, proprietary))
{
return None;
Expand Down Expand Up @@ -481,6 +491,7 @@ impl Bundle {
)
})
.transpose()?,
output.user_address,
output.proprietary,
)
})
Expand Down Expand Up @@ -561,6 +572,7 @@ impl Bundle {
seed_fingerprint: *z.seed_fingerprint(),
derivation_path: z.derivation_path().iter().map(|i| i.index()).collect(),
}),
user_address: output.user_address().clone(),
proprietary: output.proprietary().clone(),
})
.collect();
Expand Down
12 changes: 12 additions & 0 deletions pczt/src/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ pub struct Output {
#[serde_as(as = "BTreeMap<[_; 33], _>")]
pub(crate) bip32_derivation: BTreeMap<[u8; 33], 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).
#[getset(get = "pub")]
pub(crate) user_address: Option<String>,

/// Proprietary fields related to the note being spent.
#[getset(get = "pub")]
pub(crate) proprietary: BTreeMap<String, Vec<u8>>,
Expand Down Expand Up @@ -267,6 +275,7 @@ impl Bundle {
script_pubkey,
redeem_script,
bip32_derivation,
user_address,
proprietary,
} = rhs;

Expand All @@ -276,6 +285,7 @@ impl Bundle {

if !(merge_optional(&mut lhs.redeem_script, redeem_script)
&& merge_map(&mut lhs.bip32_derivation, bip32_derivation)
&& merge_optional(&mut lhs.user_address, user_address)
&& merge_map(&mut lhs.proprietary, proprietary))
{
return None;
Expand Down Expand Up @@ -346,6 +356,7 @@ impl Bundle {
.map(|v| (k, v))
})
.collect::<Result<_, _>>()?,
output.user_address,
output.proprietary,
)
})
Expand Down Expand Up @@ -430,6 +441,7 @@ impl Bundle {
)
})
.collect(),
user_address: output.user_address().clone(),
proprietary: output.proprietary().clone(),
})
.collect();
Expand Down
Loading

0 comments on commit 554e4e5

Please sign in to comment.