orchard/src/address.rs

41 lines
1.1 KiB
Rust
Raw Normal View History

2021-03-12 16:04:13 -08:00
use pasta_curves::pallas;
use crate::{
keys::{DiversifiedTransmissionKey, Diversifier},
spec::diversify_hash,
};
2021-01-20 10:54:00 -08:00
/// A shielded payment address.
///
/// # Examples
///
/// ```
/// use orchard::keys::{SpendingKey, FullViewingKey};
///
/// let sk = SpendingKey::from_bytes([7; 32]).unwrap();
/// let address = FullViewingKey::from(&sk).default_address();
/// ```
2021-01-20 10:54:00 -08:00
#[derive(Debug)]
pub struct Address {
d: Diversifier,
pk_d: DiversifiedTransmissionKey,
2021-03-05 15:25:45 -08:00
}
impl Address {
pub(crate) fn from_parts(d: Diversifier, pk_d: DiversifiedTransmissionKey) -> Self {
2021-03-12 16:04:13 -08:00
// We assume here that pk_d is correctly-derived from d. We ensure this for
// internal APIs. For parsing from raw byte encodings, we assume that users aren't
// modifying internals of encoded address formats. If they do, that can result in
// lost funds, but we can't defend against that from here.
2021-03-05 15:25:45 -08:00
Address { d, pk_d }
}
2021-03-12 16:04:13 -08:00
pub(crate) fn g_d(&self) -> pallas::Point {
diversify_hash(self.d.as_array())
}
pub(crate) fn pk_d(&self) -> &DiversifiedTransmissionKey {
&self.pk_d
}
2021-01-20 10:54:00 -08:00
}