From e4b6b36a7d20ef621280ce85b33fbc39d3afd937 Mon Sep 17 00:00:00 2001 From: "Rene V. Vergara" Date: Tue, 7 Jan 2025 16:25:45 -0500 Subject: [PATCH] rvv001 - Issue 0122 - Generate Viewing Keys The Viewing Keys deriving functions are now integrated to the CLI.hs module (TUI). --- src/Zenith/CLI.hs | 59 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/src/Zenith/CLI.hs b/src/Zenith/CLI.hs index 87807fc..3565887 100644 --- a/src/Zenith/CLI.hs +++ b/src/Zenith/CLI.hs @@ -96,7 +96,7 @@ import Text.Wrap , defaultWrapSettings , wrapTextToLines ) -import ZcashHaskell.Keys (generateWalletSeedPhrase) +import ZcashHaskell.Keys (generateWalletSeedPhrase, deriveUfvk, deriveUivk) import ZcashHaskell.Orchard ( getSaplingFromUA , isValidUnifiedAddress @@ -122,6 +122,9 @@ import Zenith.Types , ValidAddressAPI(..) , ZcashNetDB(..) , ZenithStatus(..) + , OrchardSpendingKeyDB(..) + , SaplingSpendingKeyDB(..) + , TransparentSpendingKeyDB(..) ) import Zenith.Utils ( displayTaz @@ -1761,24 +1764,52 @@ appEvent (BT.VtyEvent e) = do BT.modify $ set dialogBox ViewingKeyMenu ev -> return () -- + -- Open viewing key display form + -- ViewingKeyMenu -> do case e of + -- + -- Full viewing key display + -- V.EvKey (V.KChar 'f') [] -> do - BT.modify $ set vkName "Full" - BT.modify $ - set - vkData - "VKFull->ztestsapling1tgjr4zppwk4ne8xy6gdq4z2gwq7dmf5jq8z2ctpn8nlmtse0a74fa5z0m8z383gmpgqz6q6duu4" - BT.modify $ set dialogBox ViewingKeyShow + selAccount <- + do case L.listSelectedElement $ s ^. accounts of + Nothing -> do + let fAcc = + L.listSelectedElement $ L.listMoveToBeginning $ s ^. accounts + case fAcc of + Nothing -> throw $ userError "Failed to select account" + Just (_j, w1) -> return w1 + Just (_k, w) -> return w + let osk = getOrchSK $ zcashAccountOrchSpendKey $ entityVal selAccount + let ssk = getSapSK $ zcashAccountSapSpendKey $ entityVal selAccount + let tsk = getTranSK $ zcashAccountTPrivateKey $ entityVal selAccount + fvk <- liftIO $ deriveUfvk (s ^. network) osk ssk tsk + BT.modify $ set vkName "Full" + BT.modify $ set vkData fvk + BT.modify $ set dialogBox ViewingKeyShow + -- + -- Incoming viewing key display + -- V.EvKey (V.KChar 'i') [] -> do - BT.modify $ set vkName "Incomming" - BT.modify $ - set - vkData - "VKIncoming->ztestsapling1tgjr4zppwk4ne8xy6gdq4z2gwq7dmf5jq8z2ctpn8nlmtse0a74fa5z0m8z383gmpgqz6q6duu4" - BT.modify $ set dialogBox ViewingKeyShow + selAccount <- + do case L.listSelectedElement $ s ^. accounts of + Nothing -> do + let fAcc = + L.listSelectedElement $ L.listMoveToBeginning $ s ^. accounts + case fAcc of + Nothing -> throw $ userError "Failed to select account" + Just (_j, w1) -> return w1 + Just (_k, w) -> return w + let osk = getOrchSK $ zcashAccountOrchSpendKey $ entityVal selAccount + let ssk = getSapSK $ zcashAccountSapSpendKey $ entityVal selAccount + let tsk = getTranSK $ zcashAccountTPrivateKey $ entityVal selAccount + ivk <- liftIO $ deriveUivk (s ^. network) osk ssk tsk + BT.modify $ set vkName "Incomming" + BT.modify $ set vkData ivk + BT.modify $ set dialogBox ViewingKeyShow V.EvKey (V.KChar 'e') [] -> - BT.modify $ set dialogBox Blank + BT.modify $ set dialogBox Blank ev -> return () -- -- Payment URI Form Events