Skip to content

Commit

Permalink
impl readAccountPubKey in Cardano.Wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas authored and KtorZ committed Jan 28, 2021
1 parent 59d76b0 commit 9faf741
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 40 deletions.
49 changes: 14 additions & 35 deletions lib/core/src/Cardano/Wallet.hs
Expand Up @@ -156,7 +156,7 @@ module Cardano.Wallet
, ErrWrongPassphrase (..)
, ErrSignMetadataWith (..)
, ErrDerivePublicKey(..)
, ErrGetAccountPublicKey(..)
, ErrReadAccountPublicKey(..)
, ErrInvalidDerivationIndex(..)

-- * Logging
Expand Down Expand Up @@ -1949,42 +1949,27 @@ derivePublicKey ctx wid role_ ix = db & \DBLayer{..} -> do
readPublicAccountKey
:: forall ctx s k n.
( HasDBLayer s k ctx
, HardDerivation k
, WalletKey k
, s ~ SeqState n k
)
=> ctx
-> WalletId
-> Passphrase "raw"
-> DerivationIndex
-> ExceptT ErrGetAccountPublicKey IO (k 'AccountK XPub)
readPublicAccountKey ctx _wid _pwd ix = db & \DBLayer{..} -> do
_accIx <- withExceptT ErrGetAccountPublicKeyInvalidIndex $ guardHardIndex ix
undefined
{--
-> ExceptT ErrReadAccountPublicKey IO (k 'AccountK XPub)
readPublicAccountKey ctx wid pwd ix = db & \DBLayer{..} -> do
acctIx <- withExceptT ErrReadAccountPublicKeyInvalidIndex $ guardHardIndex ix

_cp <- mapExceptT atomically
$ withExceptT ErrGetAccountPublicKeyNoSuchWallet
$ withExceptT ErrReadAccountPublicKeyNoSuchWallet
$ withNoSuchWallet wid
$ readCheckpoint (PrimaryKey wid)

withRootKey @ctx @s @k ctx wid pwd ErrSignMetadataWithRootKey
withRootKey @ctx @s @k ctx wid pwd ErrReadAccountPublicKeyRootKey
$ \rootK scheme -> do
let encPwd = preparePassphrase scheme pwd
let DerivationPrefix (_, _, acctIx) = derivationPrefix (getState cp)
let acctK = deriveAccountPrivateKey encPwd rootK acctIx
let addrK = deriveAddressPrivateKey encPwd acctK role_ addrIx
let msg = serialiseToCBOR metadata
pure $ Signature $ BA.convert $ CC.sign encPwd (getRawKey addrK) msg
where
db = ctx ^. dbLayer @s @k
cp <- mapExceptT atomically
$ withExceptT ErrGetAccountPublicKeyNoSuchWallet
$ withNoSuchWallet wid
$ readCheckpoint (PrimaryKey wid)
let acctK = Seq.accountPubKey $ Seq.externalPool $ getState cp
return acctK
--}
pure $ publicKey $ deriveAccountPrivateKey encPwd rootK acctIx
where
db = ctx ^. dbLayer @s @k

Expand Down Expand Up @@ -2028,26 +2013,20 @@ data ErrDerivePublicKey
-- ^ User provided a derivation index outside of the 'Soft' domain
deriving (Eq, Show)

data ErrGetAccountPublicKey
= ErrGetAccountPublicKeyNoSuchWallet ErrNoSuchWallet
data ErrReadAccountPublicKey
= ErrReadAccountPublicKeyNoSuchWallet ErrNoSuchWallet
-- ^ The wallet doesn't exist?
| ErrGetAccountPublicKeyInvalidIndex (ErrInvalidDerivationIndex 'Hardened 'AccountK)
| ErrReadAccountPublicKeyInvalidIndex (ErrInvalidDerivationIndex 'Hardened 'AccountK)
-- ^ User provided a derivation index outside of the 'Hard' domain
| ErrGetAccountPublicKeyRootKey ErrWithRootKey
| ErrReadAccountPublicKeyRootKey ErrWithRootKey
-- ^ The wallet exists, but there's no root key attached to it
deriving (Eq, Show)

{--
data ErrInvalidDerivationIndex
= ErrIndexTooHigh (Index 'Soft 'AddressK) DerivationIndex
deriving (Eq, Show)
--}
data ErrInvalidDerivationIndex derivation level
= ErrIndexTooHigh (Index derivation level) DerivationIndex
| ErrIndexTooLow (Index derivation level) DerivationIndex
deriving (Eq, Show)


-- | Errors that can occur when listing UTxO statistics.
newtype ErrListUTxOStatistics
= ErrListUTxOStatisticsNoSuchWallet ErrNoSuchWallet
Expand Down
11 changes: 6 additions & 5 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Expand Up @@ -113,7 +113,6 @@ import Cardano.Wallet
, ErrDecodeSignedTx (..)
, ErrDerivePublicKey (..)
, ErrFetchRewards (..)
, ErrGetAccountPublicKey (..)
, ErrGetTransaction (..)
, ErrImportAddress (..)
, ErrImportRandomAddress (..)
Expand All @@ -127,6 +126,7 @@ import Cardano.Wallet
, ErrNotASequentialWallet (..)
, ErrPostTx (..)
, ErrQuitStakePool (..)
, ErrReadAccountPublicKey (..)
, ErrReadRewardAccount (..)
, ErrRemoveTx (..)
, ErrSelectAssets (..)
Expand Down Expand Up @@ -1857,6 +1857,7 @@ postAccountPublicKey
:: forall ctx s k n.
( s ~ SeqState n k
, ctx ~ ApiLayer s k
, HardDerivation k
, WalletKey k
)
=> ctx
Expand Down Expand Up @@ -2723,11 +2724,11 @@ instance LiftHandler ErrSignMetadataWith where
ErrSignMetadataWithNoSuchWallet e -> handler e
ErrSignMetadataWithInvalidIndex e -> handler e

instance LiftHandler ErrGetAccountPublicKey where
instance LiftHandler ErrReadAccountPublicKey where
handler = \case
ErrGetAccountPublicKeyRootKey e -> handler e
ErrGetAccountPublicKeyNoSuchWallet e -> handler e
ErrGetAccountPublicKeyInvalidIndex e -> handler e
ErrReadAccountPublicKeyRootKey e -> handler e
ErrReadAccountPublicKeyNoSuchWallet e -> handler e
ErrReadAccountPublicKeyInvalidIndex e -> handler e

instance LiftHandler ErrDerivePublicKey where
handler = \case
Expand Down

0 comments on commit 9faf741

Please sign in to comment.