From b221f35f151ee97ebb88558d1233b87c39d93bb1 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 8 Mar 2024 19:57:34 +0000 Subject: [PATCH 1/2] Add tests for `IncomingViewingKey` encoding --- src/zip32.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/zip32.rs b/src/zip32.rs index ef7e460..c2b7ea6 100644 --- a/src/zip32.rs +++ b/src/zip32.rs @@ -1050,6 +1050,25 @@ mod tests { assert_eq!(dfvk_parsed.to_bytes(), dfvk_bytes); } + #[test] + fn ivk_round_trip() { + let ivk = { + let extsk = ExtendedSpendingKey::master(&[]); + #[allow(deprecated)] + let extfvk = extsk.to_extended_full_viewing_key(); + DiversifiableFullViewingKey::from(extfvk).to_external_ivk() + }; + + // Check value -> bytes -> parsed round trip. + let ivk_bytes = ivk.to_bytes(); + let ivk_parsed = IncomingViewingKey::from_bytes(&ivk_bytes).unwrap(); + assert_eq!(ivk_parsed.dk, ivk.dk); + assert_eq!(ivk_parsed.ivk.0, ivk.ivk.0); + + // Check bytes -> parsed -> bytes round trip. + assert_eq!(ivk_parsed.to_bytes(), ivk_bytes); + } + #[test] fn address() { let seed = [0; 32]; @@ -1818,6 +1837,16 @@ mod tests { internal_xfvk.write(&mut ser).unwrap(); assert_eq!(&ser[..], &tv.internal_xfvk[..]); assert_eq!(FvkFingerprint::from(&internal_xfvk.fvk).0, tv.internal_fp); + + let dfvk = xfvk.to_diversifiable_full_viewing_key(); + let ivk = dfvk.to_external_ivk(); + let ivk_bytes = ivk.to_bytes(); + assert_eq!(&ivk_bytes[..32], tv.dk); + assert_eq!(&ivk_bytes[32..], tv.ivk); + + let ivk_rt = IncomingViewingKey::from_bytes(&ivk_bytes).unwrap(); + assert_eq!(ivk.dk, ivk_rt.dk); + assert_eq!(ivk.ivk.0, ivk_rt.ivk.0); } } } From 291a1ac1c289cd3cc020379b80d3c4d34077b22f Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 8 Mar 2024 19:57:52 +0000 Subject: [PATCH 2/2] sapling-crypto 0.1.2 --- CHANGELOG.md | 3 ++- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77cfd7e..b49d725 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ and this library adheres to Rust's notion of ## [Unreleased] -## Added +## [0.1.2] - 2024-03-08 +### Added - `sapling_crypto::zip32::IncomingViewingKey` - `sapling_crypto::zip32::DiversifiableFullViewingKey::to_external_ivk` diff --git a/Cargo.lock b/Cargo.lock index 9966cba..ac22240 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1271,7 +1271,7 @@ dependencies = [ [[package]] name = "sapling-crypto" -version = "0.1.1" +version = "0.1.2" dependencies = [ "aes", "bellman", diff --git a/Cargo.toml b/Cargo.toml index 8b6d4e4..262e846 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sapling-crypto" -version = "0.1.1" +version = "0.1.2" authors = [ "Sean Bowe ", "Jack Grigg ",