From 0743dadcd017b60a0ac7123d04f0d6e7ce1e8016 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 24 Sep 2019 11:14:13 -0700 Subject: [PATCH] Encode expanded spending keys --- zcash_client_backend/src/encoding.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/zcash_client_backend/src/encoding.rs b/zcash_client_backend/src/encoding.rs index 0bd1644..c27068c 100644 --- a/zcash_client_backend/src/encoding.rs +++ b/zcash_client_backend/src/encoding.rs @@ -13,6 +13,7 @@ use zcash_primitives::{ }; use zcash_primitives::{ legacy::TransparentAddress, + keys::ExpandedSpendingKey, zip32::{ExtendedFullViewingKey, ExtendedSpendingKey}, JUBJUB, }; @@ -38,6 +39,25 @@ where } } + +/// Writes an [`ExpandedSpendingKey`] as a Bech32-encoded string. +/// +/// # Examples +/// +/// ``` +/// use zcash_client_backend::{ +/// constants::testnet::{COIN_TYPE, HRP_SAPLING_EXPANDED_SPENDING_KEY}, +/// encoding::encode_expanded_spending_key, +/// keys::spending_key, +/// }; +/// +/// let expsk = spending_key(&[0; 32][..], COIN_TYPE, 0).expsk; +/// let encoded = encode_expanded_spending_key(HRP_SAPLING_EXPANDED_SPENDING_KEY, &expsk); +/// ``` +pub fn encode_expanded_spending_key(htp: &str, sk: &ExpandedSpendingKey) -> String { + bech32_encode(htp, |w| sk.write(w)) +} + /// Writes an [`ExtendedSpendingKey`] as a Bech32-encoded string. /// /// # Examples