Skip to content

Commit

Permalink
make sign metadata endpoint consistent with others (move 'signatures'…
Browse files Browse the repository at this point in the history
… after wallet id)
  • Loading branch information
KtorZ committed Oct 22, 2020
1 parent e022bd1 commit 1eaac55
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 18 deletions.
22 changes: 11 additions & 11 deletions lib/core/src/Cardano/Wallet/Api.hs
Expand Up @@ -28,10 +28,10 @@ module Cardano.Wallet.Api
, PutWallet
, PutWalletPassphrase
, GetUTxOsStatistics
, SignMetadata

, WalletKeys
, GetWalletKey
, SignMetadata

, Addresses
, ListAddresses
Expand Down Expand Up @@ -242,7 +242,6 @@ type Wallets =
:<|> PutWallet
:<|> PutWalletPassphrase
:<|> GetUTxOsStatistics
:<|> SignMetadata

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/deleteWallet
type DeleteWallet = "wallets"
Expand Down Expand Up @@ -283,22 +282,14 @@ type GetUTxOsStatistics = "wallets"
:> "utxos"
:> Get '[JSON] ApiUtxoStatistics

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/signMetadata
type SignMetadata = "wallets"
:> Capture "walletId" (ApiT WalletId)
:> Capture "role" (ApiT AccountingStyle)
:> Capture "index" (ApiT DerivationIndex)
:> "signatures"
:> ReqBody '[JSON] ApiWalletSignData
:> Post '[OctetStream] ByteString

{-------------------------------------------------------------------------------
Wallet Keys
See also: https://input-output-hk.github.io/cardano-wallet/api/#tag/WalletKeys
-------------------------------------------------------------------------------}

type WalletKeys =
GetWalletKey
:<|> SignMetadata

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/getWalletKey
type GetWalletKey = "wallets"
Expand All @@ -308,6 +299,15 @@ type GetWalletKey = "wallets"
:> Capture "index" (ApiT DerivationIndex)
:> Get '[JSON] ApiVerificationKey

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/signMetadata
type SignMetadata = "wallets"
:> Capture "walletId" (ApiT WalletId)
:> "signatures"
:> Capture "role" (ApiT AccountingStyle)
:> Capture "index" (ApiT DerivationIndex)
:> ReqBody '[JSON] ApiWalletSignData
:> Post '[OctetStream] ByteString

{-------------------------------------------------------------------------------
Addresses
Expand Down
1 change: 0 additions & 1 deletion lib/core/src/Cardano/Wallet/Api/Client.hs
Expand Up @@ -223,7 +223,6 @@ walletClient =
:<|> _putWallet
:<|> _putWalletPassphrase
:<|> _getWalletUtxoStatistics
:<|> _signMetadata
= client (Proxy @("v2" :> Wallets))
in
WalletClient
Expand Down
14 changes: 14 additions & 0 deletions lib/core/src/Cardano/Wallet/Api/Link.hs
Expand Up @@ -50,6 +50,7 @@ module Cardano.Wallet.Api.Link

-- * WalletKeys
, getWalletKey
, signMetadata

-- * Addresses
, postRandomAddress
Expand Down Expand Up @@ -275,6 +276,19 @@ getWalletKey w role_ index =
where
wid = w ^. typed @(ApiT WalletId)

signMetadata
:: forall w.
( HasType (ApiT WalletId) w
)
=> w
-> AccountingStyle
-> DerivationIndex
-> (Method, Text)
signMetadata w role_ index =
endpoint @Api.SignMetadata (\mk -> mk wid (ApiT role_) (ApiT index))
where
wid = w ^. typed @(ApiT WalletId)

--
-- Addresses
--
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Expand Up @@ -366,7 +366,7 @@ import Data.Generics.Internal.VL.Lens
import Data.Generics.Labels
()
import Data.List
( isInfixOf, isPrefixOf, isSubsequenceOf, isSuffixOf, sortOn )
( isInfixOf, isPrefixOf, isSubsequenceOf, sortOn )
import Data.List.NonEmpty
( NonEmpty (..) )
import Data.Map.Strict
Expand Down Expand Up @@ -2796,7 +2796,7 @@ instance LiftHandler (Request, ServerError) where
let cType =
-- FIXME: Ugly and not really scalable nor maintainable.
if ["wallets"] `isPrefixOf` pathInfo req
&& ["signatures"] `isSuffixOf` pathInfo req
&& ["signatures"] `isInfixOf` pathInfo req
then "application/octet-stream"
else "application/json"
in apiError err' NotAcceptable $ mconcat
Expand Down
2 changes: 1 addition & 1 deletion lib/core/test/unit/Cardano/Wallet/Api/Malformed.hs
Expand Up @@ -199,7 +199,7 @@ instance Malformed (PathParam (ApiT AccountingStyle)) where
msgMalformed =
"Unable to decode the given text value. Please specify \
\one of the following values: utxo_external, utxo_internal, \
\mutable_account."
\mutable_account, multisig_script."

instance Wellformed (PathParam (ApiT DerivationIndex)) where
wellformed = PathParam <$>
Expand Down
6 changes: 5 additions & 1 deletion lib/jormungandr/src/Cardano/Wallet/Jormungandr/Api/Server.hs
Expand Up @@ -57,6 +57,7 @@ import Cardano.Wallet.Api.Server
, delegationFee
, deleteTransaction
, deleteWallet
, derivePublicKey
, getMigrationInfo
, getNetworkClock
, getNetworkInformation
Expand Down Expand Up @@ -149,7 +150,7 @@ server
-> Server (Api n ApiStakePool)
server byron icarus jormungandr spl ntp =
wallets
:<|> (\ _ _ -> throwError err501)
:<|> walletKeys
:<|> addresses
:<|> coinSelections
:<|> transactions
Expand All @@ -172,6 +173,9 @@ server byron icarus jormungandr spl ntp =
:<|> putWallet jormungandr mkShelleyWallet
:<|> putWalletPassphrase jormungandr
:<|> getUTxOsStatistics jormungandr

walletKeys :: Server WalletKeys
walletKeys = derivePublicKey jormungandr
:<|> signMetadata jormungandr

addresses :: Server (Addresses n)
Expand Down
2 changes: 1 addition & 1 deletion lib/shelley/src/Cardano/Wallet/Shelley/Api/Server.hs
Expand Up @@ -193,10 +193,10 @@ server byron icarus shelley spl ntp =
:<|> putWallet shelley mkShelleyWallet
:<|> putWalletPassphrase shelley
:<|> getUTxOsStatistics shelley
:<|> signMetadata shelley

walletKeys :: Server WalletKeys
walletKeys = derivePublicKey shelley
:<|> signMetadata shelley

addresses :: Server (Addresses n)
addresses = listAddresses shelley (normalizeDelegationAddress @_ @ShelleyKey @n)
Expand Down
2 changes: 1 addition & 1 deletion specifications/api/swagger.yaml
Expand Up @@ -2367,7 +2367,7 @@ x-tagGroups:
- Experimental

paths:
/wallets/{walletId}/{role}/{index}/signatures:
/wallets/{walletId}/signatures/{role}/{index}:
post:
operationId: signMetadata
tags: ["Experimental"]
Expand Down

0 comments on commit 1eaac55

Please sign in to comment.