Skip to content

Commit

Permalink
Merge #2624
Browse files Browse the repository at this point in the history
2624: Address derivation for shared wallets r=paweljakubas a=paweljakubas

# Issue Number

ADP-866

# Overview

- [x] Adding Shared style
- [x] Accommodate new cardano-addresses, align code, change MutableAccount -> Stake
- [x] Deal with prefixes of shared wallet vs shelley wallet by adding SharedWalletKeys
- [x] Align all unit tests
- [x] Align all integration tests plus add test checking newly added validation in cardano-addresses
- [x] Add integration testing 
- [x] Enable receiving hashed verification keys, now only verification keys are present which needs to be hashed to be used in script
- [x] Sneak SharedKey in shared wallet rather than ShelleyKey  
- [x] Removed MultisigScript from Role and refactored ParentContext


# Comments

[Rendered API docs](https://redocly.github.io/redoc/?url=https://raw.githubusercontent.com/input-output-hk/cardano-wallet/paweljakubas/adp-866/add-shared-style/specifications/api/swagger.yaml)

Co-authored-by: Pawel Jakubas <pawel.jakubas@iohk.io>
Co-authored-by: IOHK <devops+stack-project@iohk.io>
Co-authored-by: Piotr Stachyra <piotr.stachyra@iohk.io>
Co-authored-by: Rodney Lorrimar <rodney.lorrimar@iohk.io>
  • Loading branch information
5 people committed May 12, 2021
2 parents 6814c0e + 61c5934 commit b4e4002
Show file tree
Hide file tree
Showing 50 changed files with 7,113 additions and 5,434 deletions.
2 changes: 1 addition & 1 deletion lib/cli/test/unit/Cardano/CLISpec.hs
Expand Up @@ -529,7 +529,7 @@ spec = do
, ""
, "Available options:"
, " -h,--help Show this help text"
, " STYLE Byron | Icarus | Shelley"
, " STYLE Byron | Icarus | Shelley | Shared"
, ""
, "The recovery phrase is read from stdin."
, ""
Expand Down
88 changes: 67 additions & 21 deletions lib/core-integration/src/Test/Integration/Framework/DSL.hs
Expand Up @@ -78,6 +78,8 @@ module Test.Integration.Framework.DSL
, deleteSharedWallet
, getSharedWallet
, patchSharedWallet
, getSharedWalletKey
, postAccountKeyShared

-- * Wallet helpers
, listFilteredWallets
Expand Down Expand Up @@ -213,6 +215,7 @@ import Cardano.Mnemonic
)
import Cardano.Wallet.Api.Types
( AddressAmount
, ApiAccountKeyShared
, ApiAddress
, ApiBlockReference (..)
, ApiByronWallet
Expand All @@ -228,6 +231,7 @@ import Cardano.Wallet.Api.Types
, ApiTransaction
, ApiTxId (ApiTxId)
, ApiUtxoStatistics (..)
, ApiVerificationKeyShared
, ApiWallet
, ApiWalletDelegation (..)
, ApiWalletDelegationNext (..)
Expand Down Expand Up @@ -264,10 +268,10 @@ import Cardano.Wallet.Primitive.AddressDerivation.Icarus
( IcarusKey )
import Cardano.Wallet.Primitive.AddressDerivation.Shelley
( ShelleyKey )
import Cardano.Wallet.Primitive.AddressDiscovery.Script
( CredentialType (..) )
import Cardano.Wallet.Primitive.AddressDiscovery.Sequential
( coinTypeAda )
import Cardano.Wallet.Primitive.AddressDiscovery.SharedState
( CredentialType (..) )
import Cardano.Wallet.Primitive.SyncProgress
( SyncProgress (..) )
import Cardano.Wallet.Primitive.Types
Expand Down Expand Up @@ -409,6 +413,7 @@ import Web.HttpApiData
import qualified Cardano.Wallet.Api.Link as Link
import qualified Cardano.Wallet.Primitive.AddressDerivation.Byron as Byron
import qualified Cardano.Wallet.Primitive.AddressDerivation.Icarus as Icarus
import qualified Cardano.Wallet.Primitive.AddressDerivation.Shared as Shared
import qualified Cardano.Wallet.Primitive.AddressDerivation.Shelley as Shelley
import qualified Cardano.Wallet.Primitive.Types as W
import qualified Cardano.Wallet.Primitive.Types.TokenBundle as TokenBundle
Expand Down Expand Up @@ -830,7 +835,7 @@ accPubKeyFromMnemonics mnemonic1 mnemonic2 ix passphrase =
T.decodeUtf8 $ serializeXPub $ publicKey $
deriveAccountPrivateKey passphrase rootXPrv (Index $ 2147483648 + ix)
where
rootXPrv = Shelley.generateKeyFromSeed (mnemonic1, mnemonic2) passphrase
rootXPrv = Shared.generateKeyFromSeed (mnemonic1, mnemonic2) passphrase

genXPubs :: Int -> IO [(XPub,Text)]
genXPubs num =
Expand Down Expand Up @@ -1411,12 +1416,12 @@ deleteSharedWallet
=> Context
-> ApiSharedWallet
-> m (HTTP.Status, Either RequestException Value)
deleteSharedWallet ctx (ApiSharedWallet (Left w)) =
request @Aeson.Value ctx
(Link.deleteSharedWallet w) Default Empty
deleteSharedWallet ctx (ApiSharedWallet (Right w)) =
request @Aeson.Value ctx
(Link.deleteSharedWallet w) Default Empty
deleteSharedWallet ctx = \case
ApiSharedWallet (Left wal') -> r wal'
ApiSharedWallet (Right wal') -> r wal'
where
r :: forall w. HasType (ApiT WalletId) w => w -> m (HTTP.Status, Either RequestException Value)
r w = request @Aeson.Value ctx (Link.deleteSharedWallet w) Default Empty

getSharedWallet
:: forall m.
Expand All @@ -1426,12 +1431,50 @@ getSharedWallet
=> Context
-> ApiSharedWallet
-> m (HTTP.Status, Either RequestException ApiSharedWallet)
getSharedWallet ctx (ApiSharedWallet (Left w)) = do
let link = Link.getSharedWallet w
request @ApiSharedWallet ctx link Default Empty
getSharedWallet ctx (ApiSharedWallet (Right w)) = do
let link = Link.getSharedWallet w
request @ApiSharedWallet ctx link Default Empty
getSharedWallet ctx = \case
ApiSharedWallet (Left wal') -> r wal'
ApiSharedWallet (Right wal') -> r wal'
where
r :: forall w. HasType (ApiT WalletId) w => w -> m (HTTP.Status, Either RequestException ApiSharedWallet)
r w = request @ApiSharedWallet ctx (Link.getSharedWallet w) Default Empty

getSharedWalletKey
:: forall m.
( MonadIO m
, MonadUnliftIO m
)
=> Context
-> ApiSharedWallet
-> Role
-> DerivationIndex
-> Maybe Bool
-> m (HTTP.Status, Either RequestException ApiVerificationKeyShared)
getSharedWalletKey ctx wal role ix 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 ApiVerificationKeyShared)
r w = request @ApiVerificationKeyShared ctx (Link.getSharedWalletKey w role ix hashed) Default Empty

postAccountKeyShared
:: forall m.
( MonadIO m
, MonadUnliftIO m
)
=> Context
-> ApiSharedWallet
-> DerivationIndex
-> Headers
-> Payload
-> m (HTTP.Status, Either RequestException ApiAccountKeyShared)
postAccountKeyShared ctx wal ix headers payload =
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.postAccountKeyShared w ix) headers payload

patchEndpointEnding :: CredentialType -> Text
patchEndpointEnding = \case
Expand All @@ -1448,12 +1491,15 @@ patchSharedWallet
-> CredentialType
-> Payload
-> m (HTTP.Status, Either RequestException ApiSharedWallet)
patchSharedWallet ctx (ApiSharedWallet (Left w)) cred payload = do
let endpoint = "v2/shared-wallets" </> w ^. walletId </> patchEndpointEnding cred
request @ApiSharedWallet ctx ("PATCH", endpoint) Default payload
patchSharedWallet ctx (ApiSharedWallet (Right w)) cred payload = do
let endpoint = "v2/shared-wallets" </> w ^. walletId </> patchEndpointEnding cred
request @ApiSharedWallet ctx ("PATCH", endpoint) Default payload
patchSharedWallet ctx wal cred payload =
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 ApiSharedWallet)
r w =
let endpoint = "v2/shared-wallets" </> w ^. walletId </> patchEndpointEnding cred
in request @ApiSharedWallet ctx ("PATCH", endpoint) Default payload

fixtureRawTx
:: Context
Expand Down
25 changes: 25 additions & 0 deletions lib/core-integration/src/Test/Integration/Framework/TestData.hs
Expand Up @@ -85,6 +85,11 @@ module Test.Integration.Framework.TestData
, errMsg403NoSuchCosigner
, errMsg403CannotUpdateThisCosigner
, errMsg403CreateIllegal
, errMsg400ScriptWrongCoeffcient
, errMsg400ScriptIllFormed
, errMsg400ScriptDuplicateKeys
, errMsg400ScriptTimelocksContradictory
, errMsg400ScriptNotUniformRoles
) where

import Prelude
Expand Down Expand Up @@ -542,3 +547,23 @@ errMsg403CreateIllegal = mconcat
, "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."
]

errMsg400ScriptWrongCoeffcient :: String
errMsg400ScriptWrongCoeffcient =
"At least's coefficient is 0 (which is not recommended)."

errMsg400ScriptIllFormed :: String
errMsg400ScriptIllFormed =
"The script is ill-formed and is not going to be accepted by the ledger."

errMsg400ScriptDuplicateKeys :: String
errMsg400ScriptDuplicateKeys =
"The list inside a script has duplicate keys (which is not recommended)."

errMsg400ScriptTimelocksContradictory :: String
errMsg400ScriptTimelocksContradictory =
"The timelocks used are contradictory when used with 'all' (which is not recommended)."

errMsg400ScriptNotUniformRoles :: String
errMsg400ScriptNotUniformRoles =
"All keys of a script must have the same role: either payment or delegation."

0 comments on commit b4e4002

Please sign in to comment.