Skip to content

Commit

Permalink
postPolicyPublicKey with optional param plus cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Mar 28, 2022
1 parent 83bc1f3 commit cf83f21
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3670,7 +3670,7 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
(_, policyKeyHashPayload) <-
unsafeRequest @ApiPolicyKey ctx policyWithHash Empty

let postPolicyKey = Link.postPolicyKey @'Shelley wa
let postPolicyKey = Link.postPolicyKey @'Shelley wa (Just True)
let passwdPayload = Json [json| {
"passphrase": #{fixturePassphrase}
} |]
Expand Down
1 change: 1 addition & 0 deletions lib/core/src/Cardano/Wallet/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ type GetPolicyKey = "wallets"
type PostPolicyKey = "wallets"
:> Capture "walletId" (ApiT WalletId)
:> "policy-key"
:> QueryParam "hash" Bool
:> ReqBody '[JSON] ApiPostPolicyKeyData
:> PostAccepted '[JSON] ApiPolicyKey

Expand Down
5 changes: 3 additions & 2 deletions lib/core/src/Cardano/Wallet/Api/Link.hs
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,10 @@ postPolicyKey
, HasType (ApiT WalletId) w
)
=> w
-> Maybe Bool
-> (Method, Text)
postPolicyKey w = discriminate @style
(endpoint @Api.PostPolicyKey (wid &))
postPolicyKey w hashed = discriminate @style
(endpoint @Api.PostPolicyKey (\mk -> mk wid hashed))
(notSupported "Byron")
(notSupported "Shared")
where
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ import Cardano.Wallet.Api.Types
, ApiNetworkClock (..)
, ApiNetworkInformation
, ApiNetworkParameters (..)
, ApiPostPolicyKeyData (..)
, ApiNullStakeKey (..)
, ApiOurStakeKey (..)
, ApiPaymentDestination (..)
Expand All @@ -251,6 +250,7 @@ import Cardano.Wallet.Api.Types
, ApiPolicyScript (..)
, ApiPoolId (..)
, ApiPostAccountKeyDataWithPurpose (..)
, ApiPostPolicyKeyData (..)
, ApiPostRandomAddressData (..)
, ApiPutAddressesData (..)
, ApiRedeemer (..)
Expand Down Expand Up @@ -3370,15 +3370,15 @@ postPolicyKey
)
=> ctx
-> ApiT WalletId
-> Maybe Bool
-> ApiPostPolicyKeyData
-> Handler ApiPolicyKey
postPolicyKey ctx (ApiT wid) apiPassphrase =
postPolicyKey ctx (ApiT wid) hashed apiPassphrase =
withWorkerCtx @_ @s @ShelleyKey ctx wid liftE liftE $ \wrk -> do
k <- liftHandler $ W.writePolicyPublicKey @_ @s @n wrk wid pwd
pure $ uncurry ApiPolicyKey (computeKeyPayload hashed (getRawKey k))
where
pwd = getApiT (apiPassphrase ^. #passphrase)
hashed = Just True

{-------------------------------------------------------------------------------
Helpers
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1227,8 +1227,8 @@ data ApiPolicyScript = ApiPolicyScript
deriving (Eq, Generic, Show)
deriving anyclass NFData

data ApiPostPolicyKeyData = ApiPostPolicyKeyData
{ passphrase :: !(ApiT (Passphrase "raw"))
newtype ApiPostPolicyKeyData = ApiPostPolicyKeyData
{ passphrase :: (ApiT (Passphrase "raw"))
}
deriving (Eq, Generic, Show)
deriving anyclass NFData
Expand Down
15 changes: 11 additions & 4 deletions specifications/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6047,13 +6047,20 @@ paths:
/wallets/{walletId}/policy-key:
post:
operationId: postPolicyKey
tags: ["Transactions"]
summary: Create
tags: ["Keys"]
summary: Create Policy Key
description: |
<p align="right">status: <strong>stable</strong></p>
Create policy key for the wallet. Used for public account key derived
wallets or already instantiated mnemonic wallets to set policy public key
Create policy key for the wallet.
In order to be able to mint/burn assets with `POST Construct` endpoint there needs to be
a policy key set for the wallet. Invoking this endpoint would be required for all wallets instantiated
before introducing mint/burn feature prior to making a mint/burn transaction from them.
To get a hash of the policy key instead of the policy key,
use query parameter `hash=true`.
parameters:
- *parametersWalletId
requestBody:
Expand Down

0 comments on commit cf83f21

Please sign in to comment.