From 00e4bc7e703cce89401cf52d2cae2dd09dae49e9 Mon Sep 17 00:00:00 2001 From: redshiftzero Date: Tue, 10 Dec 2024 15:22:12 -0500 Subject: [PATCH] crypto: truncated addresses are renamed to transparent addresses --- crates/core/keys/src/address.rs | 8 ++++---- crates/core/keys/src/keys/ivk.rs | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/core/keys/src/address.rs b/crates/core/keys/src/address.rs index 76457c5d73..b0ee856526 100644 --- a/crates/core/keys/src/address.rs +++ b/crates/core/keys/src/address.rs @@ -23,7 +23,7 @@ pub use view::AddressView; use crate::{fmd, ka, keys::Diversifier}; -pub const TRUNCATED_ADDRESS_BECH32_PREFIX: &str = "ptrunc"; +pub const TRANSPARENT_ADDRESS_BECH32_PREFIX: &str = "tpenumbra"; /// The length of an [`Address`] in bytes. pub const ADDRESS_LEN_BYTES: usize = 80; @@ -321,11 +321,11 @@ impl std::str::FromStr for Address { type Err = anyhow::Error; fn from_str(s: &str) -> Result { - if s.starts_with(TRUNCATED_ADDRESS_BECH32_PREFIX) { + if s.starts_with(TRANSPARENT_ADDRESS_BECH32_PREFIX) { let dzero = Diversifier([0u8; 16]); let pk_dzero_bytes: [u8; 32] = - bech32str::decode(s, TRUNCATED_ADDRESS_BECH32_PREFIX, bech32str::Bech32)? + bech32str::decode(s, TRANSPARENT_ADDRESS_BECH32_PREFIX, bech32str::Bech32)? .try_into() .map_err(|bytes: Vec| { anyhow::anyhow!("wrong length {}, expected 32", bytes.len()) @@ -335,7 +335,7 @@ impl std::str::FromStr for Address { let ck_id = fmd::ClueKey([0u8; 32]); Self::from_components(dzero, pk_dzero, ck_id) - .ok_or_else(|| anyhow::anyhow!("could not reconstruct truncated address")) + .ok_or_else(|| anyhow::anyhow!("could not reconstruct transparent address")) } else if s.starts_with(bech32str::compat_address::BECH32_PREFIX) { pb::Address { inner: bech32str::decode( diff --git a/crates/core/keys/src/keys/ivk.rs b/crates/core/keys/src/keys/ivk.rs index 0c63dfe81c..962d29ea65 100644 --- a/crates/core/keys/src/keys/ivk.rs +++ b/crates/core/keys/src/keys/ivk.rs @@ -45,19 +45,19 @@ impl IncomingViewingKey { ) } - /// Derive the (encoding of the) truncated address for the given IVK. + /// Derive the (encoding of the) transparent address for the given IVK. /// /// This intentionally returns a `String` rather than an `Address`, as it's not /// safe to truncate arbitrary addresses. - pub fn truncated_address(&self) -> String { - // The truncated address uses an all-zero diversifier. + pub fn transparent_address(&self) -> String { + // The transparent address uses an all-zero diversifier. let dzero = Diversifier([0u8; 16]); let g_dzero = dzero.diversified_generator(); let pk_dzero = self.ivk.diversified_public(&g_dzero); let encoding = bech32str::encode( &pk_dzero.0, - crate::address::TRUNCATED_ADDRESS_BECH32_PREFIX, + crate::address::TRANSPARENT_ADDRESS_BECH32_PREFIX, bech32str::Bech32, ); @@ -206,17 +206,17 @@ mod test { use super::*; #[test] - fn truncated_address_generation_and_parsing() { + fn transparent_address_generation_and_parsing() { let rng = rand::rngs::OsRng; let spend_key = SpendKey::from_seed_phrase_bip44(SeedPhrase::generate(rng), &Bip44Path::new(0)); let ivk = spend_key.full_viewing_key().incoming(); - let truncated_address_str = ivk.truncated_address(); + let transparent_address_str = ivk.transparent_address(); - let reconstructed: Address = truncated_address_str + let reconstructed: Address = transparent_address_str .parse() - .expect("can parse truncated address"); + .expect("can parse transparent address"); assert!(ivk.views_address(&reconstructed)); @@ -234,7 +234,7 @@ mod test { // The clue keys should not match, as the clue key is zeroed out assert_ne!(reconstructed.clue_key(), actual_address.clue_key()); - println!("Truncated address: {}", truncated_address_str); + println!("Transparent address: {}", transparent_address_str); println!("Reconstructed address: {}", reconstructed); println!("Address index: {:?}", address_index); println!("Actual address for index: {}", actual_address);