From 5e60c275b2d8e1191759532f21ff8d0aa5010c94 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 22 Apr 2024 12:27:31 -0600 Subject: [PATCH] Allow transparent-only unified addresses and viewing keys. --- components/zcash_address/src/kind/unified.rs | 10 ++-------- components/zcash_address/src/kind/unified/fvk.rs | 5 +---- components/zcash_address/src/kind/unified/ivk.rs | 5 +---- zcash_keys/src/address.rs | 5 ++++- zcash_keys/src/keys.rs | 5 ++++- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/components/zcash_address/src/kind/unified.rs b/components/zcash_address/src/kind/unified.rs index 8d7042325..5600ad7a6 100644 --- a/components/zcash_address/src/kind/unified.rs +++ b/components/zcash_address/src/kind/unified.rs @@ -561,7 +561,6 @@ pub(crate) mod private { ) -> Result { assert!(u32::from(Typecode::P2SH) == u32::from(Typecode::P2PKH) + 1); - let mut only_transparent = true; let mut prev_code = None; // less than any Some for item in &items { let t = item.typecode(); @@ -576,16 +575,11 @@ pub(crate) mod private { return Err(ParseError::BothP2phkAndP2sh); } else { prev_code = t_code; - only_transparent = only_transparent && item.is_transparent_data_item(); } } - if only_transparent { - Err(ParseError::OnlyTransparent) - } else { - // All checks pass! - Ok(Self::from_inner(revision, items)) - } + // All checks pass! + Ok(Self::from_inner(revision, items)) } fn parse_internal>>(hrp: &str, buf: T) -> Result { diff --git a/components/zcash_address/src/kind/unified/fvk.rs b/components/zcash_address/src/kind/unified/fvk.rs index f12adcd96..643f78e40 100644 --- a/components/zcash_address/src/kind/unified/fvk.rs +++ b/components/zcash_address/src/kind/unified/fvk.rs @@ -357,9 +357,6 @@ mod tests { 0xf4, 0xf5, 0x16, 0xef, 0x5c, 0xe0, 0x26, 0xbc, 0x23, 0x73, 0x76, 0x3f, 0x4b, ]; - assert_eq!( - Ufvk::parse_internal(Ufvk::MAINNET_R0, &encoded[..]), - Err(ParseError::OnlyTransparent) - ); + assert_matches!(Ufvk::parse_internal(Ufvk::MAINNET_R0, &encoded[..]), Ok(_)); } } diff --git a/components/zcash_address/src/kind/unified/ivk.rs b/components/zcash_address/src/kind/unified/ivk.rs index 5abe1d20b..8d0c5c95e 100644 --- a/components/zcash_address/src/kind/unified/ivk.rs +++ b/components/zcash_address/src/kind/unified/ivk.rs @@ -339,9 +339,6 @@ mod tests { 0xbd, 0xfe, 0xa4, 0xb7, 0x47, 0x20, 0x92, 0x6, 0xf0, 0x0, 0xf9, 0x64, ]; - assert_eq!( - Uivk::parse_internal(Uivk::MAINNET_R0, &encoded[..]), - Err(ParseError::OnlyTransparent) - ); + assert_matches!(Uivk::parse_internal(Uivk::MAINNET_R0, &encoded[..]), Ok(_)); } } diff --git a/zcash_keys/src/address.rs b/zcash_keys/src/address.rs index 96353a085..e7b3ae966 100644 --- a/zcash_keys/src/address.rs +++ b/zcash_keys/src/address.rs @@ -278,7 +278,10 @@ impl UnifiedAddress { .chain(self.expiry_time.map(unified::MetadataItem::ExpiryTime)); let ua = unified::Address::try_from_items( - if self.expiry_height().is_some() || self.expiry_time().is_some() { + if self.expiry_height().is_some() + || self.expiry_time().is_some() + || !(self.has_orchard() || self.has_sapling()) + { Revision::R1 } else { Revision::R0 diff --git a/zcash_keys/src/keys.rs b/zcash_keys/src/keys.rs index 1c01c54ad..ddabe2887 100644 --- a/zcash_keys/src/keys.rs +++ b/zcash_keys/src/keys.rs @@ -855,7 +855,10 @@ impl UnifiedFullViewingKey { .chain(self.expiry_time.map(unified::MetadataItem::ExpiryTime)); zcash_address::unified::Ufvk::try_from_items( - if self.expiry_height().is_some() || self.expiry_time().is_some() { + if self.expiry_height().is_some() + || self.expiry_time().is_some() + || !(self.sapling.is_some() || self.orchard.is_some()) + { Revision::R1 } else { Revision::R0