Impl From<(AuthorizingKey, NullifierDerivingKey)> for IncomingViewingKey
This commit is contained in:
parent
e508d09e9b
commit
16f1e3061f
|
@ -144,7 +144,7 @@ mod tests {
|
|||
let authorizing_key = sapling::AuthorizingKey::from(spend_authorizing_key);
|
||||
let nullifier_deriving_key = sapling::NullifierDerivingKey::from(proof_authorizing_key);
|
||||
let incoming_viewing_key =
|
||||
sapling::IncomingViewingKey::from_keys(authorizing_key, nullifier_deriving_key);
|
||||
sapling::IncomingViewingKey::from((authorizing_key, nullifier_deriving_key));
|
||||
|
||||
let diversifier = sapling::Diversifier::new(&mut OsRng);
|
||||
let transmission_key = sapling::TransmissionKey::from(incoming_viewing_key, diversifier);
|
||||
|
|
|
@ -514,6 +514,25 @@ impl From<[u8; 32]> for IncomingViewingKey {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<(AuthorizingKey, NullifierDerivingKey)> for IncomingViewingKey {
|
||||
/// For this invocation of Blake2s-256 as _CRH^ivk_.
|
||||
///
|
||||
/// https://zips.z.cash/protocol/protocol.pdf#saplingkeycomponents
|
||||
/// https://zips.z.cash/protocol/protocol.pdf#concreteprfs
|
||||
/// https://zips.z.cash/protocol/protocol.pdf#jubjub
|
||||
// TODO: return None if ivk = 0
|
||||
//
|
||||
// "If ivk = 0, discard this key and start over with a new
|
||||
// [spending key]." - [§4.2.2][ps]
|
||||
//
|
||||
// [ps]: https://zips.z.cash/protocol/protocol.pdf#saplingkeycomponents
|
||||
fn from((ask, nk): (AuthorizingKey, NullifierDerivingKey)) -> Self {
|
||||
let hash_bytes = crh_ivk(ask.into(), nk.to_bytes());
|
||||
|
||||
IncomingViewingKey::from(hash_bytes)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IncomingViewingKey> for [u8; 32] {
|
||||
fn from(ivk: IncomingViewingKey) -> [u8; 32] {
|
||||
ivk.scalar.to_bytes()
|
||||
|
@ -563,30 +582,6 @@ impl std::str::FromStr for IncomingViewingKey {
|
|||
}
|
||||
}
|
||||
|
||||
impl IncomingViewingKey {
|
||||
/// For this invocation of Blake2s-256 as _CRH^ivk_.
|
||||
///
|
||||
/// https://zips.z.cash/protocol/protocol.pdf#saplingkeycomponents
|
||||
/// https://zips.z.cash/protocol/protocol.pdf#concreteprfs
|
||||
/// https://zips.z.cash/protocol/protocol.pdf#jubjub
|
||||
// TODO: return None if ivk = 0
|
||||
//
|
||||
// "If ivk = 0, discard this key and start over with a new
|
||||
// [spending key]." - [§4.2.2][ps]
|
||||
//
|
||||
// [ps]: https://zips.z.cash/protocol/protocol.pdf#saplingkeycomponents
|
||||
//
|
||||
// TODO: won't let me name this `from(arg1, arg2)` when I have From impl'd above?
|
||||
pub fn from_keys(
|
||||
authorizing_key: AuthorizingKey,
|
||||
nullifier_deriving_key: NullifierDerivingKey,
|
||||
) -> Self {
|
||||
let hash_bytes = crh_ivk(authorizing_key.into(), nullifier_deriving_key.to_bytes());
|
||||
|
||||
IncomingViewingKey::from(hash_bytes)
|
||||
}
|
||||
}
|
||||
|
||||
/// A _Diversifier_, as described in [protocol specification §4.2.2][ps].
|
||||
///
|
||||
/// Combined with an _IncomingViewingKey_, produces a _diversified
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#[cfg(test)]
|
||||
use proptest::{array, prelude::*};
|
||||
#[cfg(test)]
|
||||
use proptest_derive::Arbitrary;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -45,7 +43,7 @@ mod tests {
|
|||
// [spending key]."
|
||||
// https://zips.z.cash/protocol/protocol.pdf#saplingkeycomponents
|
||||
let incoming_viewing_key =
|
||||
IncomingViewingKey::from_keys(authorizing_key, nullifier_deriving_key);
|
||||
IncomingViewingKey::from((authorizing_key, nullifier_deriving_key));
|
||||
|
||||
let diversifier = Diversifier::new(&mut OsRng);
|
||||
let _transmission_key = TransmissionKey::from(incoming_viewing_key, diversifier);
|
||||
|
@ -81,7 +79,7 @@ mod tests {
|
|||
test_vector.nk
|
||||
);
|
||||
let incoming_viewing_key =
|
||||
IncomingViewingKey::from_keys(authorizing_key, nullifier_deriving_key);
|
||||
IncomingViewingKey::from((authorizing_key, nullifier_deriving_key));
|
||||
assert_eq!(incoming_viewing_key.scalar.to_bytes(), test_vector.ivk);
|
||||
|
||||
// TODO: replace with _DefaultDiversifier_ with spending
|
||||
|
|
Loading…
Reference in New Issue