From 1b8da6b12d6f7813817aeb498031e861758fe463 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 10 Jul 2018 23:58:06 +0100 Subject: [PATCH] ZIP 32 structures --- Cargo.toml | 5 +++++ src/lib.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 16375d037..f97aee520 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/lib.rs b/src/lib.rs index 31e1bb209..e696dd37a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { + ask: E::Fs, + nsk: E::Fs, + ovk: OutgoingViewingKey, +} + +/// A Sapling full viewing key +struct FullViewingKey { + vk: ViewingKey, + 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, + 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, + dk: DiversifierKey, +} + #[cfg(test)] mod tests { #[test]