Skip to content

Commit

Permalink
Add internal DiversifiedTransmissionKey type
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Mar 6, 2021
1 parent a61be5d commit 71542f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/address.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use halo2::pasta::pallas;

use crate::keys::Diversifier;
use crate::keys::{DiversifiedTransmissionKey, Diversifier};

/// A shielded payment address.
///
Expand All @@ -15,11 +13,11 @@ use crate::keys::Diversifier;
#[derive(Debug)]
pub struct Address {
d: Diversifier,
pk_d: pallas::Point,
pk_d: DiversifiedTransmissionKey,
}

impl Address {
pub(crate) fn from_parts(d: Diversifier, pk_d: pallas::Point) -> Self {
pub(crate) fn from_parts(d: Diversifier, pk_d: DiversifiedTransmissionKey) -> Self {
Address { d, pk_d }
}
}
18 changes: 16 additions & 2 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ impl From<&FullViewingKey> for IncomingViewingKey {
impl IncomingViewingKey {
/// Returns the payment address for this key corresponding to the given diversifier.
pub fn address(&self, d: Diversifier) -> Address {
let g_d = diversify_hash(&d.0);
Address::from_parts(d, ka_orchard(&self.0, &g_d))
let pk_d = DiversifiedTransmissionKey::derive(self, &d);
Address::from_parts(d, pk_d)
}
}

Expand All @@ -232,3 +232,17 @@ impl From<&FullViewingKey> for OutgoingViewingKey {
fvk.derive_dk_ovk().1
}
}

/// The diversified transmission key for a given payment address.
#[derive(Debug)]
pub(crate) struct DiversifiedTransmissionKey(pallas::Point);

impl DiversifiedTransmissionKey {
/// Defined in [Zcash Protocol Spec § 4.2.3: Orchard Key Components][§4.2.3].
///
/// [§4.2.3]: https://zips.z.cash/protocol/nu5.pdf#orchardkeycomponents
fn derive(ivk: &IncomingViewingKey, d: &Diversifier) -> Self {
let g_d = diversify_hash(&d.0);
DiversifiedTransmissionKey(ka_orchard(&ivk.0, &g_d))
}
}

0 comments on commit 71542f7

Please sign in to comment.