Skip to content

Commit

Permalink
final polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Jun 8, 2021
1 parent 7dfdd8b commit d66fa2e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
21 changes: 9 additions & 12 deletions lib/core/src/Cardano/Wallet.hs
Expand Up @@ -449,7 +449,7 @@ import Data.List
import Data.List.NonEmpty
( NonEmpty (..) )
import Data.Maybe
( fromJust, fromMaybe, isJust, mapMaybe )
( fromMaybe, mapMaybe )
import Data.Proxy
( Proxy )
import Data.Quantity
Expand Down Expand Up @@ -1308,11 +1308,11 @@ selectionToUnsignedTx wdrl sel s =
-> t a
-> t (a, NonEmpty DerivationIndex)
qualifyAddresses getAddress hasAddresses =
case traverse withDerivationPath hasAddresses of
Just as -> as
Nothing -> error
"selectionToUnsignedTx: unable to find derivation path of a \
\known input or change address. This is impossible."
fromMaybe
(error
"selectionToUnsignedTx: unable to find derivation path of a known \
\input or change address. This is impossible.")
(traverse withDerivationPath hasAddresses)
where
withDerivationPath hasAddress =
(hasAddress,) <$> fst (isOurs (getAddress hasAddress) s)
Expand Down Expand Up @@ -2347,11 +2347,9 @@ getAccountPublicKeyAtIndex
getAccountPublicKeyAtIndex ctx wid pwd ix purposeM = db & \DBLayer{..} -> do
acctIx <- withExceptT ErrReadAccountPublicKeyInvalidAccountIndex $ guardHardIndex ix

when (isJust purposeM) $ do
purposeGuarded <- runExceptT $ guardHardIndex (fromJust purposeM)
case purposeGuarded of
Left err -> throwE $ ErrReadAccountPublicKeyInvalidPurposeIndex err
Right _ -> pure ()
purpose <- maybe (pure (getPurpose @k))
(withExceptT ErrReadAccountPublicKeyInvalidPurposeIndex . guardHardIndex)
purposeM

_cp <- mapExceptT atomically
$ withExceptT ErrReadAccountPublicKeyNoSuchWallet
Expand All @@ -2365,7 +2363,6 @@ getAccountPublicKeyAtIndex ctx wid pwd ix purposeM = db & \DBLayer{..} -> do
pure $ liftRawKey $ toXPub xprv
where
db = ctx ^. dbLayer @IO @s @k
purpose = maybe (getPurpose @k) (Index . getDerivationIndex) purposeM

guardSoftIndex
:: Monad m
Expand Down
7 changes: 5 additions & 2 deletions specifications/api/swagger.yaml
Expand Up @@ -4676,8 +4676,11 @@ paths:
description: |
<p align="right">status: <strong>stable</strong></p>
Derive an account public key for any account index. For this key derivation to be possible,
the wallet must have been created from mnemonic. In request body, arbitrary purpose can be specified.
Omitting the purpose segment means default purpose, ie., 1852H, will be used.
the wallet must have been created from mnemonic.
It is possible to use the optional `purpose` field to override that branch of the derivation path
with different hardened derivation index. If that field is omitted, the default purpose
for Cardano wallets (`1852H`) will be used.
<b>Note:</b> Only _Hardened_ indexes are supported by this endpoint.
parameters:
Expand Down

0 comments on commit d66fa2e

Please sign in to comment.