mirror of https://github.com/zcash/orchard.git
Add raw address serialization and parsing.
This commit is contained in:
parent
e33cd4ade4
commit
1fd00e6236
|
@ -1,3 +1,7 @@
|
|||
use std::convert::TryInto;
|
||||
|
||||
use subtle::CtOption;
|
||||
|
||||
use crate::{
|
||||
keys::{DiversifiedTransmissionKey, Diversifier},
|
||||
spec::{diversify_hash, NonIdentityPallasPoint},
|
||||
|
@ -39,6 +43,24 @@ impl Address {
|
|||
pub(crate) fn pk_d(&self) -> &DiversifiedTransmissionKey {
|
||||
&self.pk_d
|
||||
}
|
||||
|
||||
/// Serialize this address to its "raw" encoding as defined in
|
||||
/// https://zips.z.cash/protocol/protocol.pdf#orchardpaymentaddrencoding
|
||||
pub fn to_raw_address_bytes(&self) -> [u8; 43] {
|
||||
let mut result = [0u8; 43];
|
||||
result[..11].copy_from_slice(self.d.as_array());
|
||||
result[11..].copy_from_slice(&self.pk_d.to_bytes());
|
||||
result
|
||||
}
|
||||
|
||||
/// Parse an address from its "raw" encoding as defined in
|
||||
/// https://zips.z.cash/protocol/protocol.pdf#orchardpaymentaddrencoding
|
||||
pub fn from_raw_address_bytes(bytes: &[u8; 43]) -> CtOption<Self> {
|
||||
DiversifiedTransmissionKey::from_bytes(bytes[11..].try_into().unwrap()).map(|pk_d| {
|
||||
let d = Diversifier::from_bytes(bytes[..11].try_into().unwrap());
|
||||
Self::from_parts(d, pk_d)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Generators for property testing.
|
||||
|
|
17
src/keys.rs
17
src/keys.rs
|
@ -10,8 +10,7 @@ use group::{prime::PrimeCurveAffine, Curve, GroupEncoding};
|
|||
use halo2::arithmetic::FieldExt;
|
||||
use pasta_curves::pallas;
|
||||
use rand::RngCore;
|
||||
use subtle::ConstantTimeEq;
|
||||
use subtle::CtOption;
|
||||
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
|
||||
use zcash_note_encryption::EphemeralKeyBytes;
|
||||
|
||||
use crate::{
|
||||
|
@ -510,6 +509,20 @@ impl DiversifiedTransmissionKey {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for DiversifiedTransmissionKey {
|
||||
fn default() -> Self {
|
||||
DiversifiedTransmissionKey(NonIdentityPallasPoint::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl ConditionallySelectable for DiversifiedTransmissionKey {
|
||||
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
|
||||
DiversifiedTransmissionKey(NonIdentityPallasPoint::conditional_select(
|
||||
&a.0, &b.0, choice,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/// An ephemeral secret key used to encrypt an output note on-chain.
|
||||
///
|
||||
/// `esk` is "ephemeral" in the sense that each secret key is only used once. In
|
||||
|
|
Loading…
Reference in New Issue