Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import and Export wallet functionality for web app #711

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
2 changes: 0 additions & 2 deletions desktop/desktop.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ library
exposed-modules:
Desktop.Crypto.BIP
, Desktop.Frontend
, Desktop.ImportExport
, Desktop.Orphans
, Desktop.Setup
, Desktop.Storage.File
, Desktop.Syslog
, Desktop.WalletApi
Expand Down
3 changes: 0 additions & 3 deletions desktop/src/Desktop/Crypto/BIP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ data BIPStorage a where
BIPStorage_RootKey :: BIPStorage Crypto.XPrv
deriving instance Show (BIPStorage a)

bipMetaPrefix :: StoreKeyMetaPrefix
bipMetaPrefix = StoreKeyMetaPrefix "BIPStorage_Meta"

-- | Check the validity of the password by signing and verifying a message
passwordRoundTripTest :: Crypto.XPrv -> Password -> Bool
passwordRoundTripTest xprv (Password pass) =
Expand Down
47 changes: 13 additions & 34 deletions desktop/src/Desktop/Frontend.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import Control.Monad ((<=<), guard, void, when)
import Control.Monad.Fix (MonadFix)
import Control.Monad.Trans (lift)
import Control.Monad.IO.Class
import Data.Bifunctor (first, second)
import Data.Bifunctor (second)
import Data.Dependent.Sum
import Data.Functor.Compose
import Data.Functor.Identity
import Data.GADT.Compare.TH
import Data.Maybe (isJust)
import Data.Proxy (Proxy(..))
import Data.Text (Text)
import Data.Time (NominalDiffTime, getCurrentTime, addUTCTime)
import Data.Traversable (for)
Expand All @@ -53,9 +54,9 @@ import Common.Route
import Common.Wallet
import Frontend.AppCfg
import Desktop.Crypto.BIP
import Desktop.Orphans ()
import Frontend.ModuleExplorer.Impl (loadEditorFromLocalStorage)
import Frontend.Log (defaultLogger)
import Frontend.Wallet (genZeroKeyPrefix, _unPublicKeyPrefix)
import Frontend.Storage
import Frontend.UI.Modal.Impl (showModalBrutal)
import Frontend.UI.Dialogs.LogoutConfirmation (uiIdeLogoutConfirmation)
Expand All @@ -69,10 +70,10 @@ import Frontend.VersionedStore (StoreFrontend(..))
import Frontend.Storage (runBrowserStorageT)
import Frontend.Crypto.Password
import Frontend.Setup.Common
import Frontend.Setup.ImportExport
import Frontend.Setup.Password
import Frontend.Setup.Setup
import Frontend.Setup.Widgets
import Desktop.Setup
import Desktop.ImportExport
import Desktop.Storage.File
import Desktop.WalletApi

Expand Down Expand Up @@ -161,7 +162,11 @@ bipWallet fileFFI signingReq mkAppCfg = do
-> WalletExists
-> RoutedT t (R FrontendRoute) m (Event t (DSum LockScreen Identity))
runSetup0 mPrv walletExists = do
keyAndPass <- runSetup (liftFileFFI lift fileFFI) (isJust mPrv) walletExists
let pwCheck k p= pure $ passwordRoundTripTest k p
runF k (Password p) = runBIPCryptoT (pure (k, p))
importWidgetApis = ImportWidgetApis BIPStorage_RootKey pwCheck runF

keyAndPass <- runSetup (liftFileFFI lift fileFFI) (isJust mPrv) walletExists importWidgetApis
performEvent $ flip push keyAndPass $ \case
Right (x, Password p, newWallet) -> pure $ Just $ do
setItemStorage localStorage BIPStorage_RootKey x
Expand Down Expand Up @@ -228,35 +233,9 @@ bipWallet fileFFI signingReq mkAppCfg = do
-- the new root
, _changePassword_updateKeys = ((second Password) <$> updates, changePasswordDesktopAction)
}
, _enabledSettings_exportWallet = Just $ ExportWallet
{ _exportWallet_requestExport = \ePw -> do
let bOldPw = (\(Identity (_,oldPw)) -> oldPw) <$> current details
runExport oldPw newPw = do
pfx <- genZeroKeyPrefix
doExport txLogger pfx oldPw newPw

logExport = do
ts <- liftIO getCurrentTime
sender <- genZeroKeyPrefix
liftIO $ _transactionLogger_walletEvent txLogger
WalletEvent_Export
(_unPublicKeyPrefix sender)
ts

eExport <- performEvent $ runExport
<$> (Password <$> bOldPw)
<@> (Password <$> ePw)

let (eErrExport, eGoodExport) = fanEither eExport

eFileDone <- _fileFFI_deliverFile frontendFileFFI eGoodExport
eLogExportDone <- performEvent $ (\r -> r <$ logExport) <$> eFileDone

pure $ leftmost
[ Left <$> eErrExport
, first ExportWalletError_FileNotWritable <$> eLogExportDone
]
}
, _enabledSettings_exportWallet =
let details' = fmap (\(k, p) -> (k, Password p)) <$> details
in Just $ mkExportWallet txLogger frontendFileFFI details' (Proxy :: Proxy (BIPStorage Crypto.XPrv))
, _enabledSettings_transactionLog = True
}

Expand Down
210 changes: 0 additions & 210 deletions desktop/src/Desktop/Setup.hs

This file was deleted.

2 changes: 2 additions & 0 deletions frontend/frontend.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ library
, Frontend.Routes
, Frontend.Setup.Browser
, Frontend.Setup.Common
, Frontend.Setup.ImportExport
, Frontend.Setup.Password
, Frontend.Setup.Setup
, Frontend.Setup.Widgets
, Frontend.Storage
, Frontend.Storage.Class
Expand Down
Loading