Skip to content

Commit

Permalink
remove duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
jleni committed May 8, 2024
1 parent 5722889 commit 1968039
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 240 deletions.
7 changes: 1 addition & 6 deletions app/rust/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,6 @@ pub const ZIP32_COIN_TYPE: u32 = 0x8000_0085;

/// ZIP32 Child components
pub enum Zip32ChildComponents {
AkNk = 0,
Dk = 2,
AkNsk = 3,
AskNsk = 4,
DkAkNk = 5,
Ovk,
FullViewingKey,
AskNskDk,
}
18 changes: 18 additions & 0 deletions app/rust/src/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ pub fn sapling_nsk_to_nk(nsk: &NskBytes) -> NkBytes {
AffinePoint::from(nk).to_bytes()
}

#[inline(never)]
pub fn sapling_asknsk_to_ivk(ask: &AskBytes, nsk: &NskBytes) -> IvkBytes {
let ak = sapling_ask_to_ak(ask);
let nk = sapling_nsk_to_nk(nsk);

let h = Blake2sParams::new()
.hash_length(32)
.personal(CRH_IVK_PERSONALIZATION)
.to_state()
.update(&ak)
.update(&nk)
.finalize();

let mut x: [u8; 32] = *h.as_array();
x[31] &= 0b0000_0111; //check this
x
}

#[inline(never)]
pub fn sapling_aknk_to_ivk(ak: &AkBytes, nk: &NkBytes) -> IvkBytes {
let h = Blake2sParams::new()
Expand Down
8 changes: 8 additions & 0 deletions app/rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,11 @@ create_ztruct! {
pub chain_code: Zip32MasterChainCode,
}
}

create_ztruct! {
pub struct SaplingAskNskDk {
pub ask: AskBytes,
pub nsk: NskBytes,
pub dk: DkBytes,
}
}

0 comments on commit 1968039

Please sign in to comment.