Skip to content

Commit

Permalink
Merge #2663
Browse files Browse the repository at this point in the history
2663: Improve shared wallets r=paweljakubas a=paweljakubas

# Issue Number

<!-- Put here a reference to the issue that this PR relates to and which requirements it tackles. Jira issues of the form ADP- will be auto-linked. -->
adp-934

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- [x] Adding "incomplete" to status for pending shared wallets
- [x] comprehensive validation of script templates when posting them
- [x] integration testing of validation of script templates
- [x] add GET /shared-wallets/wid/keys and whole infrastructure
- [x] add GET /wallets/wid/keys
- [x] unite ApiVerificationKeyShelley and ApiVerificationKeyShared and hence enable with/without hashing capability for shelley style
- [x] better reuse of code in Api.Link
- [x] test new endpoints

# Comments
Prerequisite : IntersectMBO/cardano-addresses#131

<!-- Additional comments or screenshots to attach if any -->

<!--
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Jira will detect and link to this PR once created, but you can also link this PR in the description of the corresponding ticket
 ✓ Acknowledge any changes required to the Wiki
 ✓ Finally, in the PR description delete any empty sections and all text commented in <!--, so that this text does not appear in merge commit messages.
-->


Co-authored-by: Pawel Jakubas <[email protected]>
Co-authored-by: IOHK <[email protected]>
Co-authored-by: Rodney Lorrimar <[email protected]>
  • Loading branch information
4 people authored May 25, 2021
2 parents e054c8b + 7bda368 commit 66f74c4
Show file tree
Hide file tree
Showing 22 changed files with 5,815 additions and 2,291 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-addresses
tag: 7e062438fae15cf1025ab780adbe6ed26ac3e6e6
tag: 9fe7084c9c53b9edf3eba34ee8459c896734ac7a
subdir: command-line
core

Expand Down
31 changes: 27 additions & 4 deletions lib/core-integration/src/Test/Integration/Framework/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ module Test.Integration.Framework.DSL
, patchSharedWallet
, getSharedWalletKey
, postAccountKeyShared
, getAccountKeyShared

-- * Wallet helpers
, listFilteredWallets
Expand Down Expand Up @@ -160,6 +161,8 @@ module Test.Integration.Framework.DSL
, triggerMaintenanceAction
, verifyMaintenanceAction
, genXPubs
, hexText
, fromHexText
, accPubKeyFromMnemonics

-- * Delegation helpers
Expand Down Expand Up @@ -242,6 +245,7 @@ import Cardano.Wallet.Api.Types
, DecodeStakeAddress (..)
, EncodeAddress (..)
, Iso8601Time (..)
, KeyFormat
, SettingsPutData (..)
, WalletStyle (..)
, insertedAt
Expand Down Expand Up @@ -855,9 +859,11 @@ genXPubs num =
xpubFromText :: Text -> Maybe XPub
xpubFromText = fmap eitherToMaybe fromHexText >=> xpubFromBytes

fromHexText :: Text -> Either String ByteString
fromHexText = fromHex . T.encodeUtf8
fromHexText :: Text -> Either String ByteString
fromHexText = fromHex . T.encodeUtf8

hexText :: ByteString -> Text
hexText = T.decodeLatin1 . hex

getTxId :: (ApiTransaction n) -> String
getTxId tx = T.unpack $ toUrlPiece $ ApiTxId (tx ^. #id)
Expand Down Expand Up @@ -1457,7 +1463,7 @@ getSharedWalletKey ctx wal role ix hashed =
ApiSharedWallet (Right wal') -> r wal'
where
r :: forall w. HasType (ApiT WalletId) w => w -> m (HTTP.Status, Either RequestException ApiVerificationKeyShared)
r w = request @ApiVerificationKeyShared ctx (Link.getSharedWalletKey w role ix hashed) Default Empty
r w = request @ApiVerificationKeyShared ctx (Link.getWalletKey @'Shared w role ix hashed) Default Empty

postAccountKeyShared
:: forall m.
Expand All @@ -1476,7 +1482,24 @@ postAccountKeyShared ctx wal ix headers payload =
ApiSharedWallet (Right wal') -> r wal'
where
r :: forall w. HasType (ApiT WalletId) w => w -> m (HTTP.Status, Either RequestException ApiAccountKeyShared)
r w = request @ApiAccountKeyShared ctx (Link.postAccountKeyShared w ix) headers payload
r w = request @ApiAccountKeyShared ctx (Link.postAccountKey @'Shared w ix) headers payload

getAccountKeyShared
:: forall m.
( MonadIO m
, MonadUnliftIO m
)
=> Context
-> ApiSharedWallet
-> Maybe KeyFormat
-> m (HTTP.Status, Either RequestException ApiAccountKeyShared)
getAccountKeyShared ctx wal hashed =
case wal of
ApiSharedWallet (Left wal') -> r wal'
ApiSharedWallet (Right wal') -> r wal'
where
r :: forall w. HasType (ApiT WalletId) w => w -> m (HTTP.Status, Either RequestException ApiAccountKeyShared)
r w = request @ApiAccountKeyShared ctx (Link.getAccountKey @'Shared w hashed) Default Empty

patchEndpointEnding :: CredentialType -> Text
patchEndpointEnding = \case
Expand Down
38 changes: 35 additions & 3 deletions lib/core-integration/src/Test/Integration/Framework/TestData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ module Test.Integration.Framework.TestData
, errMsg400ScriptDuplicateKeys
, errMsg400ScriptTimelocksContradictory
, errMsg400ScriptNotUniformRoles
, errMsg403TemplateInvalidNoCosignerInScript
, errMsg403TemplateInvalidUnknownCosigner
, errMsg403TemplateInvalidDuplicateXPub
, errMsg403TemplateInvalidScript
) where

import Prelude
Expand Down Expand Up @@ -546,9 +550,37 @@ errMsg403CannotUpdateThisCosigner = mconcat

errMsg403CreateIllegal :: String
errMsg403CreateIllegal = mconcat
[ "It looks like you've tried to create a shared wallet "
, "with a missing account key in the script template(s). This cannot be done "
, "as the wallet's account key must be always present for each script template."
[ "It looks like you've tried to create a shared wallet with a template "
, "script for payment credential that does not pass validation. The problem "
, "is: The wallet's account key must be always present for the script template."
]

errMsg403TemplateInvalidNoCosignerInScript :: String
errMsg403TemplateInvalidNoCosignerInScript = mconcat
[ "It looks like you've tried to create a shared wallet with a template "
, "script for payment credential that does not pass validation. "
, "The problem is: The list inside a script is empty or only contains timelocks (which is not recommended)."
]

errMsg403TemplateInvalidUnknownCosigner :: String
errMsg403TemplateInvalidUnknownCosigner = mconcat
[ "It looks like you've tried to create a shared wallet with a template"
, " script for payment credential that does not pass validation. The problem is:"
, " The specified cosigner must be present in the script of the template."
]

errMsg403TemplateInvalidDuplicateXPub :: String
errMsg403TemplateInvalidDuplicateXPub = mconcat
[ "It looks like you've tried to create a shared wallet with a template"
, " script for payment credential that does not pass validation. The problem is:"
, " The cosigners in a script template must stand behind an unique extended public key."
]

errMsg403TemplateInvalidScript :: String -> String
errMsg403TemplateInvalidScript reason = mconcat
[ "It looks like you've tried to create a shared wallet with a template"
, " script for payment credential that does not pass validation. The problem is: "
, reason
]

errMsg400ScriptWrongCoeffcient :: String
Expand Down
Loading

0 comments on commit 66f74c4

Please sign in to comment.