mirror of https://github.com/zcash/orchard.git
Implement IncomingViewingKey::to_bytes
This commit is contained in:
parent
b4a82211ce
commit
77cf4c9831
18
src/keys.rs
18
src/keys.rs
|
@ -305,6 +305,16 @@ impl DiversifierKey {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Diversifier(enc.to_bytes_le().try_into().unwrap())
|
Diversifier(enc.to_bytes_le().try_into().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the raw bytes of the diversifier key
|
||||||
|
pub fn to_bytes(&self) -> &[u8; 32] {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Construct a diversifier key from bytes
|
||||||
|
pub fn from_bytes(bytes: [u8; 32]) -> Self {
|
||||||
|
DiversifierKey(bytes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A diversifier that can be used to derive a specific [`Address`] from a
|
/// A diversifier that can be used to derive a specific [`Address`] from a
|
||||||
|
@ -398,6 +408,14 @@ impl From<&FullViewingKey> for IncomingViewingKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IncomingViewingKey {
|
impl IncomingViewingKey {
|
||||||
|
/// Serializes an Orchard incoming viewing key to its raw encoding
|
||||||
|
pub fn to_bytes(&self) -> [u8; 64] {
|
||||||
|
let mut result = [0u8; 64];
|
||||||
|
result.copy_from_slice(self.dk.to_bytes());
|
||||||
|
result[32..].copy_from_slice(&self.ivk.0.to_bytes());
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
/// Parses an Orchard incoming viewing key from its raw encoding.
|
/// Parses an Orchard incoming viewing key from its raw encoding.
|
||||||
pub fn from_bytes(bytes: &[u8; 64]) -> CtOption<Self> {
|
pub fn from_bytes(bytes: &[u8; 64]) -> CtOption<Self> {
|
||||||
NonZeroPallasBase::from_bytes(bytes[32..].try_into().unwrap()).map(|ivk| {
|
NonZeroPallasBase::from_bytes(bytes[32..].try_into().unwrap()).map(|ivk| {
|
||||||
|
|
|
@ -73,6 +73,10 @@ impl NonZeroPallasBase {
|
||||||
pallas::Base::from_bytes(bytes).and_then(NonZeroPallasBase::from_base)
|
pallas::Base::from_bytes(bytes).and_then(NonZeroPallasBase::from_base)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn to_bytes(&self) -> [u8; 32] {
|
||||||
|
self.0.to_bytes()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn from_base(b: pallas::Base) -> CtOption<Self> {
|
pub(crate) fn from_base(b: pallas::Base) -> CtOption<Self> {
|
||||||
CtOption::new(NonZeroPallasBase(b), !b.ct_is_zero())
|
CtOption::new(NonZeroPallasBase(b), !b.ct_is_zero())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue