ZIP 32 structures

This commit is contained in:
Jack Grigg 2018-07-10 23:58:06 +01:00
parent 1e3f7739a3
commit 1b8da6b12d
No known key found for this signature in database
GPG Key ID: 1B8D649257DB0829
2 changed files with 69 additions and 0 deletions

View File

@ -12,3 +12,8 @@ homepage = "https://github.com/zcash-hackworks/zip32"
repository = "https://github.com/zcash-hackworks/zip32"
[dependencies]
pairing = "0.14.2"
[dependencies.sapling-crypto]
git = "https://github.com/zcash-hackworks/sapling-crypto"
rev = "21084bde2019c04bd34208e63c3560fe2c02fb0e"

View File

@ -1,3 +1,67 @@
extern crate pairing;
extern crate sapling_crypto;
use pairing::bls12_381::Bls12;
use sapling_crypto::{jubjub::JubjubEngine, primitives::ViewingKey};
// Sapling key components
/// An outgoing viewing key
struct OutgoingViewingKey([u8; 32]);
/// A Sapling expanded spending key
struct ExpandedSpendingKey<E: JubjubEngine> {
ask: E::Fs,
nsk: E::Fs,
ovk: OutgoingViewingKey,
}
/// A Sapling full viewing key
struct FullViewingKey<E: JubjubEngine> {
vk: ViewingKey<E>,
ovk: OutgoingViewingKey,
}
// ZIP 32 structures
/// A Sapling full viewing key fingerprint
struct FVKFingerprint([u8; 32]);
/// A Sapling full viewing key tag
struct FVKTag([u8; 4]);
/// A child index for a derived key
pub enum ChildIndex {
NonHardened(u32),
Hardened(u32), // Hardened(n) == n + (1 << 31) == n' in path notation
}
/// A chain code
struct ChainCode([u8; 32]);
/// A key used to derive diversifiers for a particular child key
struct DiversifierKey([u8; 32]);
/// A Sapling extended spending key
pub struct ExtendedSpendingKey {
depth: u8,
parent_fvk_tag: FVKTag,
child_index: ChildIndex,
chain_code: ChainCode,
xsk: ExpandedSpendingKey<Bls12>,
dk: DiversifierKey,
}
// A Sapling extended full viewing key
pub struct ExtendedFullViewingKey {
depth: u8,
parent_fvk_tag: FVKTag,
child_index: ChildIndex,
chain_code: ChainCode,
fvk: FullViewingKey<Bls12>,
dk: DiversifierKey,
}
#[cfg(test)]
mod tests {
#[test]