mirror of https://github.com/zcash/zip32.git
Expose underlying ExpandedSpendingKey and FullViewingKey for writing
This commit is contained in:
parent
599079fafe
commit
80130f5656
46
src/lib.rs
46
src/lib.rs
|
@ -58,14 +58,14 @@ impl OutgoingViewingKey {
|
||||||
|
|
||||||
/// A Sapling expanded spending key
|
/// A Sapling expanded spending key
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct ExpandedSpendingKey<E: JubjubEngine> {
|
pub struct ExpandedSpendingKey<E: JubjubEngine> {
|
||||||
ask: E::Fs,
|
ask: E::Fs,
|
||||||
nsk: E::Fs,
|
nsk: E::Fs,
|
||||||
ovk: OutgoingViewingKey,
|
ovk: OutgoingViewingKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Sapling full viewing key
|
/// A Sapling full viewing key
|
||||||
struct FullViewingKey<E: JubjubEngine> {
|
pub struct FullViewingKey<E: JubjubEngine> {
|
||||||
vk: ViewingKey<E>,
|
vk: ViewingKey<E>,
|
||||||
ovk: OutgoingViewingKey,
|
ovk: OutgoingViewingKey,
|
||||||
}
|
}
|
||||||
|
@ -110,17 +110,18 @@ impl<E: JubjubEngine> ExpandedSpendingKey<E> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
|
||||||
|
self.ask.into_repr().write_le(&mut writer)?;
|
||||||
|
self.nsk.into_repr().write_le(&mut writer)?;
|
||||||
|
writer.write_all(&self.ovk.0)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn to_bytes(&self) -> [u8; 96] {
|
fn to_bytes(&self) -> [u8; 96] {
|
||||||
let mut result = [0u8; 96];
|
let mut result = [0u8; 96];
|
||||||
self.ask
|
self.write(&mut result[..])
|
||||||
.into_repr()
|
.expect("should be able to serialize an ExpandedSpendingKey");
|
||||||
.write_le(&mut result[..32])
|
|
||||||
.expect("length is 32 bytes");
|
|
||||||
self.nsk
|
|
||||||
.into_repr()
|
|
||||||
.write_le(&mut result[32..64])
|
|
||||||
.expect("length is 32 bytes");
|
|
||||||
(&mut result[64..]).copy_from_slice(&self.ovk.0);
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,17 +191,18 @@ impl<E: JubjubEngine> FullViewingKey<E> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
|
||||||
|
self.vk.ak.write(&mut writer)?;
|
||||||
|
self.vk.nk.write(&mut writer)?;
|
||||||
|
writer.write_all(&self.ovk.0)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn to_bytes(&self) -> [u8; 96] {
|
fn to_bytes(&self) -> [u8; 96] {
|
||||||
let mut result = [0u8; 96];
|
let mut result = [0u8; 96];
|
||||||
self.vk
|
self.write(&mut result[..])
|
||||||
.ak
|
.expect("should be able to serialize a FullViewingKey");
|
||||||
.write(&mut result[..32])
|
|
||||||
.expect("length is 32 bytes");
|
|
||||||
self.vk
|
|
||||||
.nk
|
|
||||||
.write(&mut result[32..64])
|
|
||||||
.expect("length is 32 bytes");
|
|
||||||
(&mut result[64..]).copy_from_slice(&self.ovk.0);
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -348,7 +350,7 @@ pub struct ExtendedSpendingKey {
|
||||||
parent_fvk_tag: FVKTag,
|
parent_fvk_tag: FVKTag,
|
||||||
child_index: ChildIndex,
|
child_index: ChildIndex,
|
||||||
chain_code: ChainCode,
|
chain_code: ChainCode,
|
||||||
expsk: ExpandedSpendingKey<Bls12>,
|
pub expsk: ExpandedSpendingKey<Bls12>,
|
||||||
dk: DiversifierKey,
|
dk: DiversifierKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,7 +360,7 @@ pub struct ExtendedFullViewingKey {
|
||||||
parent_fvk_tag: FVKTag,
|
parent_fvk_tag: FVKTag,
|
||||||
child_index: ChildIndex,
|
child_index: ChildIndex,
|
||||||
chain_code: ChainCode,
|
chain_code: ChainCode,
|
||||||
fvk: FullViewingKey<Bls12>,
|
pub fvk: FullViewingKey<Bls12>,
|
||||||
dk: DiversifierKey,
|
dk: DiversifierKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue