Remove FromStr impls for orchard keys for now, pending Unifed versions of those
Also modify the string encoding/decoding rountrip proptest to be just an exerciser of the keygen for now.
This commit is contained in:
parent
6d4ecff24b
commit
42999b2112
|
|
@ -0,0 +1,7 @@
|
||||||
|
# Seeds for failure cases proptest has generated in the past. It is
|
||||||
|
# automatically read and these particular cases re-run before any
|
||||||
|
# novel cases are generated.
|
||||||
|
#
|
||||||
|
# It is recommended to check this file in to source control so that
|
||||||
|
# everyone who runs the test benefits from these saved cases.
|
||||||
|
cc 8ba80e3da74dc90c627f620bed08c47e7a13bb2e7762aad6e8c8f362237aed1b # shrinks to spending_key = SpendingKey { network: Mainnet, bytes: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] }
|
||||||
|
|
@ -11,11 +11,10 @@ use std::{
|
||||||
convert::{From, Into, TryFrom, TryInto},
|
convert::{From, Into, TryFrom, TryInto},
|
||||||
fmt,
|
fmt,
|
||||||
io::{self, Write},
|
io::{self, Write},
|
||||||
str::FromStr,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use aes::Aes256;
|
use aes::Aes256;
|
||||||
use bech32::{self, FromBase32, ToBase32, Variant};
|
use bech32::{self, ToBase32, Variant};
|
||||||
use bitvec::prelude::*;
|
use bitvec::prelude::*;
|
||||||
use fpe::ff1::{BinaryNumeralString, FF1};
|
use fpe::ff1::{BinaryNumeralString, FF1};
|
||||||
use group::{Group, GroupEncoding};
|
use group::{Group, GroupEncoding};
|
||||||
|
|
@ -161,31 +160,6 @@ impl fmt::Display for SpendingKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for SpendingKey {
|
|
||||||
type Err = SerializationError;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
match bech32::decode(s) {
|
|
||||||
Ok((hrp, bytes, Variant::Bech32)) => {
|
|
||||||
let decoded = Vec::<u8>::from_base32(&bytes).unwrap();
|
|
||||||
|
|
||||||
let mut decoded_bytes = [0u8; 32];
|
|
||||||
decoded_bytes[..].copy_from_slice(&decoded[0..32]);
|
|
||||||
|
|
||||||
Ok(SpendingKey {
|
|
||||||
network: match hrp.as_str() {
|
|
||||||
sk_hrp::MAINNET => Network::Mainnet,
|
|
||||||
sk_hrp::TESTNET => Network::Testnet,
|
|
||||||
_ => return Err(SerializationError::Parse("unknown network")),
|
|
||||||
},
|
|
||||||
bytes: decoded_bytes,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
_ => Err(SerializationError::Parse("bech32 decoding error")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SpendingKey {
|
impl SpendingKey {
|
||||||
/// Generate a new `SpendingKey`.
|
/// Generate a new `SpendingKey`.
|
||||||
///
|
///
|
||||||
|
|
@ -493,30 +467,6 @@ impl From<FullViewingKey> for IncomingViewingKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for IncomingViewingKey {
|
|
||||||
type Err = SerializationError;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
match bech32::decode(s) {
|
|
||||||
Ok((hrp, bytes, Variant::Bech32)) => {
|
|
||||||
let decoded = Vec::<u8>::from_base32(&bytes).unwrap();
|
|
||||||
|
|
||||||
let mut scalar_bytes = [0u8; 32];
|
|
||||||
scalar_bytes[..].copy_from_slice(&decoded[0..32]);
|
|
||||||
|
|
||||||
Ok(IncomingViewingKey {
|
|
||||||
network: match hrp.as_str() {
|
|
||||||
ivk_hrp::MAINNET => Network::Mainnet,
|
|
||||||
_ => Network::Testnet,
|
|
||||||
},
|
|
||||||
scalar: pallas::Scalar::from_bytes(&scalar_bytes).unwrap(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
_ => Err(SerializationError::Parse("bech32 decoding error")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialEq<[u8; 32]> for IncomingViewingKey {
|
impl PartialEq<[u8; 32]> for IncomingViewingKey {
|
||||||
fn eq(&self, other: &[u8; 32]) -> bool {
|
fn eq(&self, other: &[u8; 32]) -> bool {
|
||||||
self.scalar.to_bytes() == *other
|
self.scalar.to_bytes() == *other
|
||||||
|
|
@ -588,33 +538,6 @@ impl fmt::Display for FullViewingKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for FullViewingKey {
|
|
||||||
type Err = SerializationError;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
match bech32::decode(s) {
|
|
||||||
Ok((hrp, bytes, Variant::Bech32)) => {
|
|
||||||
let mut decoded_bytes = io::Cursor::new(Vec::<u8>::from_base32(&bytes).unwrap());
|
|
||||||
|
|
||||||
let ak_bytes = decoded_bytes.read_32_bytes()?;
|
|
||||||
let nk_bytes = decoded_bytes.read_32_bytes()?;
|
|
||||||
let rivk_bytes = decoded_bytes.read_32_bytes()?;
|
|
||||||
|
|
||||||
Ok(FullViewingKey {
|
|
||||||
network: match hrp.as_str() {
|
|
||||||
fvk_hrp::MAINNET => Network::Mainnet,
|
|
||||||
_ => Network::Testnet,
|
|
||||||
},
|
|
||||||
spend_validating_key: SpendValidatingKey::from(ak_bytes),
|
|
||||||
nullifier_deriving_key: NullifierDerivingKey::from(nk_bytes),
|
|
||||||
ivk_commit_randomness: IvkCommitRandomness::try_from(rivk_bytes).unwrap(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
_ => Err(SerializationError::Parse("bech32 decoding error")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FullViewingKey {
|
impl FullViewingKey {
|
||||||
/// [4.2.3]: https://zips.z.cash/protocol/nu5.pdf#orchardkeycomponents
|
/// [4.2.3]: https://zips.z.cash/protocol/nu5.pdf#orchardkeycomponents
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,9 @@ impl Arbitrary for TransmissionKey {
|
||||||
proptest! {
|
proptest! {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn string_roundtrips(spending_key in any::<SpendingKey>()) {
|
fn generate_keys(spending_key in any::<SpendingKey>()) {
|
||||||
zebra_test::init();
|
zebra_test::init();
|
||||||
|
|
||||||
let sk_string = spending_key.to_string();
|
|
||||||
let spending_key_2: SpendingKey = sk_string.parse().unwrap();
|
|
||||||
prop_assert_eq![spending_key, spending_key_2];
|
|
||||||
|
|
||||||
let spend_authorizing_key = SpendAuthorizingKey::from(spending_key);
|
let spend_authorizing_key = SpendAuthorizingKey::from(spending_key);
|
||||||
|
|
||||||
let spend_validating_key = SpendValidatingKey::from(spend_authorizing_key);
|
let spend_validating_key = SpendValidatingKey::from(spend_authorizing_key);
|
||||||
|
|
@ -50,17 +46,9 @@ proptest! {
|
||||||
ivk_commit_randomness,
|
ivk_commit_randomness,
|
||||||
};
|
};
|
||||||
|
|
||||||
let fvk_string = full_viewing_key.to_string();
|
|
||||||
let full_viewing_key_2: FullViewingKey = fvk_string.parse().unwrap();
|
|
||||||
prop_assert_eq![full_viewing_key, full_viewing_key_2];
|
|
||||||
|
|
||||||
let diversifier_key = DiversifierKey::from(full_viewing_key);
|
let diversifier_key = DiversifierKey::from(full_viewing_key);
|
||||||
let incoming_viewing_key = IncomingViewingKey::from(full_viewing_key);
|
let incoming_viewing_key = IncomingViewingKey::from(full_viewing_key);
|
||||||
|
|
||||||
let ivk_string = incoming_viewing_key.to_string();
|
|
||||||
let incoming_viewing_key_2: IncomingViewingKey = ivk_string.parse().unwrap();
|
|
||||||
prop_assert_eq![incoming_viewing_key, incoming_viewing_key_2];
|
|
||||||
|
|
||||||
let _outgoing_viewing_key = OutgoingViewingKey::from(full_viewing_key);
|
let _outgoing_viewing_key = OutgoingViewingKey::from(full_viewing_key);
|
||||||
|
|
||||||
let diversifier = Diversifier::from(diversifier_key);
|
let diversifier = Diversifier::from(diversifier_key);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue