pub struct Address { /* private fields */ }
Expand description
A Zcash Sapling address and associated key data.
Sapling addresses rely on zero-knowledge proofs to validate transactions without revealing transaction details publicly. Each address can have associated keys:
- Spending Keys: Allow full control (viewing and spending)
- Viewing Keys: Allow monitoring transactions without spending capability
- Diversifiers: Enable generating multiple unique addresses from the same key material
§Data Preservation
During wallet migration, the following components are preserved:
- Address strings: The canonical string representation (e.g., “zs1…”)
- Incoming Viewing Keys (IVKs): Preserved for transaction monitoring capability
- Spending Keys: Preserved for spending capability when available
- Diversifiers: Preserved to maintain address derivation capability
- HD paths: Preserved to maintain hierarchical wallet structure
Note: Full Viewing Keys (FVKs) are not stored separately because they can be derived from spending keys when needed, and source wallets typically don’t store them separately.
§Examples
// Create a new Sapling shielded address
let mut address = sapling::Address::new("zs1exampleaddress".to_string());
// Associate an incoming viewing key (for monitoring transactions)
let ivk = SaplingIncomingViewingKey::new([0u8; 32]);
address.set_incoming_viewing_key(ivk);
// For addresses with spending capability, add a spending key
let spending_key = SaplingExtendedSpendingKey::new([0u8; 169]);
address.set_spending_key(spending_key);
// Set the diversifier if available
let diversifier_index = Blob::new([0; 11]);
address.set_diversifier_index(diversifier_index);
// Set HD derivation path information
address.set_hd_derivation_path("m/32'/1'/0'/0/5".to_string());
Implementations§
Source§impl Address
impl Address
pub fn new(address: String) -> Self
pub fn address(&self) -> &str
pub fn set_address(&mut self, address: String)
Sourcepub fn incoming_viewing_key(&self) -> Option<&SaplingIncomingViewingKey>
pub fn incoming_viewing_key(&self) -> Option<&SaplingIncomingViewingKey>
Returns the Incoming Viewing Key (IVK) associated with this address, if available.
The IVK enables viewing incoming transactions without granting spending capability. During wallet migration, IVKs are preserved exactly as they exist in the source wallet.
§Returns
Some(&SaplingIncomingViewingKey)
if an IVK is associated with this addressNone
if no IVK is available (common for addresses without viewing capability)
Sourcepub fn set_incoming_viewing_key(&mut self, ivk: SaplingIncomingViewingKey)
pub fn set_incoming_viewing_key(&mut self, ivk: SaplingIncomingViewingKey)
Associates an Incoming Viewing Key (IVK) with this shielded address.
This method is primarily used during wallet migration to preserve viewing capability for existing addresses. An IVK enables the wallet to scan the blockchain for incoming transactions without revealing transaction details publicly.
§Parameters
ivk
: The 32-byte Sapling Incoming Viewing Key to associate with this address
pub fn full_viewing_key(&self) -> Option<&SaplingExtendedFullViewingKey>
pub fn set_full_viewing_key(&mut self, key: SaplingExtendedFullViewingKey)
pub fn spending_key(&self) -> Option<&SaplingExtendedSpendingKey>
pub fn set_spending_key(&mut self, key: SaplingExtendedSpendingKey)
pub fn diversifier_index(&self) -> Option<&Blob<11>>
pub fn set_diversifier_index(&mut self, d: Blob<11>)
Sourcepub fn hd_derivation_path(&self) -> Option<&str>
pub fn hd_derivation_path(&self) -> Option<&str>
Get the HD derivation path for this address, if available
Sourcepub fn set_hd_derivation_path(&mut self, path: String)
pub fn set_hd_derivation_path(&mut self, path: String)
Set the HD derivation path for this address
Trait Implementations§
impl StructuralPartialEq for Address
Auto Trait Implementations§
impl Freeze for Address
impl RefUnwindSafe for Address
impl Send for Address
impl Sync for Address
impl Unpin for Address
impl UnwindSafe for Address
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> EnvelopeEncodable for T
impl<T> EnvelopeEncodable for T
Source§fn into_envelope(self) -> Envelope
fn into_envelope(self) -> Envelope
Converts the value into an envelope by using its Into<Envelope>
implementation.
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more