mirror of https://github.com/zcash/orchard.git
Add decryption of the diversifier index for an address to the IVK.
Also correct a spelling error.
This commit is contained in:
parent
c4cd541e6c
commit
ae3cc78a56
|
@ -32,7 +32,7 @@ impl Address {
|
|||
Address { d, pk_d }
|
||||
}
|
||||
|
||||
pub(crate) fn diversifer(&self) -> Diversifier {
|
||||
pub(crate) fn diversifier(&self) -> Diversifier {
|
||||
self.d
|
||||
}
|
||||
|
||||
|
|
27
src/keys.rs
27
src/keys.rs
|
@ -406,12 +406,6 @@ impl FullViewingKey {
|
|||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct DiversifierKey([u8; 32]);
|
||||
|
||||
impl From<&FullViewingKey> for DiversifierKey {
|
||||
fn from(fvk: &FullViewingKey) -> Self {
|
||||
fvk.derive_dk_ovk().0
|
||||
}
|
||||
}
|
||||
|
||||
/// The index for a particular diversifier.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct DiversifierIndex([u8; 11]);
|
||||
|
@ -437,6 +431,13 @@ impl From<[u8; 11]> for DiversifierIndex {
|
|||
}
|
||||
}
|
||||
|
||||
impl DiversifierIndex {
|
||||
/// Returns the raw bytes of the diversifier index.
|
||||
pub fn to_bytes(&self) -> &[u8; 11] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DiversifierKey {
|
||||
/// Returns the diversifier at index 0.
|
||||
pub fn default_diversifier(&self) -> Diversifier {
|
||||
|
@ -556,7 +557,7 @@ pub struct IncomingViewingKey {
|
|||
impl From<&FullViewingKey> for IncomingViewingKey {
|
||||
fn from(fvk: &FullViewingKey) -> Self {
|
||||
IncomingViewingKey {
|
||||
dk: fvk.into(),
|
||||
dk: fvk.derive_dk_ovk().0,
|
||||
ivk: fvk.into(),
|
||||
}
|
||||
}
|
||||
|
@ -583,6 +584,18 @@ impl IncomingViewingKey {
|
|||
})
|
||||
}
|
||||
|
||||
/// Checks whether the given address was derived from this incoming viewing
|
||||
/// key, and returns the diversifier index used to derive the address if
|
||||
/// so. Returns `None` if the address was not derived from this key.
|
||||
pub fn diversifier_index(&self, addr: &Address) -> Option<DiversifierIndex> {
|
||||
let j = self.dk.diversifier_index(&addr.diversifier());
|
||||
if &self.address_at(j) == addr {
|
||||
Some(j)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the default payment address for this key.
|
||||
pub fn default_address(&self) -> Address {
|
||||
self.address(self.dk.default_diversifier())
|
||||
|
|
|
@ -149,7 +149,7 @@ impl Domain for OrchardDomain {
|
|||
) -> NotePlaintextBytes {
|
||||
let mut np = [0; NOTE_PLAINTEXT_SIZE];
|
||||
np[0] = 0x02;
|
||||
np[1..12].copy_from_slice(note.recipient().diversifer().as_array());
|
||||
np[1..12].copy_from_slice(note.recipient().diversifier().as_array());
|
||||
np[12..20].copy_from_slice(¬e.value().to_bytes());
|
||||
np[20..52].copy_from_slice(note.rseed().to_bytes());
|
||||
np[52..].copy_from_slice(memo);
|
||||
|
|
Loading…
Reference in New Issue