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.
|
2021-03-05 16:57:30 -08:00
|
|
|
///
|
|
|
|
/// # 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)]
|
2021-01-21 04:16:50 -08:00
|
|
|
pub struct Address {
|
|
|
|
d: Diversifier,
|
2021-03-05 17:03:53 -08:00
|
|
|
pk_d: DiversifiedTransmissionKey,
|
2021-03-05 15:25:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Address {
|
2021-03-05 17:03:53 -08:00
|
|
|
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
|
|
|
}
|