-
Notifications
You must be signed in to change notification settings - Fork 249
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
zcash_address: Add support for ZIP 316, Revision 1 #1135
base: main
Are you sure you want to change the base?
Conversation
87bcae5
to
3314d2a
Compare
3314d2a
to
e78a5ec
Compare
e78a5ec
to
776ec12
Compare
Returning to draft status to update the parsing of the HRP for ZIP 316, Revision 1 |
93225df
to
2833744
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes needed — see the "(blocking)" comments.
zcash_keys/src/address.rs
Outdated
/// Returns `None` if the receivers would produce an invalid Unified Address (namely, | ||
/// if no shielded receiver is provided). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Returns `None` if the receivers would produce an invalid Unified Address (namely, | |
/// if no shielded receiver is provided). | |
/// Returns `None` if the receivers would produce an invalid Unified Address (namely, | |
/// if no receiver is provided, or if there is only a transparent receiver and no expiry | |
/// height or time). |
zcash_keys/src/address.rs
Outdated
unknown_data: vec![], | ||
expiry_height, | ||
expiry_time, | ||
unknown_metadata: vec![], | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to allow creating a UA with only a transparent receiver plus expiration metadata, consistent with the suggested doc change.
if !(has_orchard || has_sapling || has_p2pkh) { | ||
panic!("At least one receiver must be requested.") | ||
} | ||
|
||
Self { | ||
has_orchard, | ||
has_sapling, | ||
has_p2pkh, | ||
expiry_height: None, | ||
expiry_time: None, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !(has_orchard || has_sapling || has_p2pkh) { | |
panic!("At least one receiver must be requested.") | |
} | |
Self { | |
has_orchard, | |
has_sapling, | |
has_p2pkh, | |
expiry_height: None, | |
expiry_time: None, | |
} | |
Self::new(has_orchard, has_sapling, has_p2pkh, None, None) | |
.expect("At least one shielded receiver must be requested") |
This ensures that the validity checking is consistent between new
and unsafe_new_without_expiry
. It's correct to panic in the case where only has_p2pkh
is true here, because we want to require expiry metadata in that case, and here there isn't any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also depends upon the resolution to #1135 (comment)
zcash_keys/src/keys.rs
Outdated
#[cfg(feature = "orchard")] | ||
orchard, | ||
#[cfg(feature = "sapling")] | ||
sapling, | ||
transparent, | ||
std::cmp::min(self.expiry_height, request.expiry_height), | ||
std::cmp::min(self.expiry_time, request.expiry_time), | ||
) | ||
.ok_or(AddressGenerationError::ShieldedReceiverRequired) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make sure that an invalid combination isn't representable as a UnifiedAddressRequest
, so that this error is impossible (and can be a panic if it does occur due to some inconsistency).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is certainly the wrong error to return at this point, but what the correct error is depends upon #1135 (comment)
let mut unknown_data = vec![]; | ||
let mut expiry_height = None; | ||
let mut expiry_time = None; | ||
let mut unknown_metadata = vec![]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unclear whether unified::Ufvk::decode(encoding)
enforces the requirement on the allowed receivers and metadata.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The decoding of Unified containers currently disallows transparent-only UAs; this needs to change but will depend upon the resolution of #1135 (comment).
zcash_keys/src/keys.rs
Outdated
unknown_data, | ||
expiry_height, | ||
expiry_time, | ||
unknown_metadata, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not check the requirement on the allowed receivers and metadata. It may be that an invalid combination can't occur here because of checks in unified::Ufvk::decode(encoding)
, but if so it's not obvious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes requested.
a509b72
to
94c9be9
Compare
94c9be9
to
478f2e3
Compare
5e60c27
to
fa225d4
Compare
pub enum MetadataTypecode { | ||
/// Expiration height metadata as specified in [ZIP 316, Revision 1](https://zips.z.cash/zip-0316) | ||
ExpiryHeight, | ||
/// Expiration height metadata as specified in [ZIP 316, Revision 1](https://zips.z.cash/zip-0316) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Expiration height metadata as specified in [ZIP 316, Revision 1](https://zips.z.cash/zip-0316) | |
/// Expiration time metadata as specified in [ZIP 316, Revision 1](https://zips.z.cash/zip-0316) |
fa225d4
to
a538659
Compare
Co-authored-by: Daira-Emma Hopwood <[email protected]>
a538659
to
2eba3a5
Compare
Closes #1153.