Skip to content

Commit

Permalink
introduce EncryptMetadataMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Apr 17, 2024
1 parent cc6520e commit 0a4bb5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 17 additions & 2 deletions lib/api/src/Cardano/Wallet/Api/Types.hs
Expand Up @@ -193,6 +193,7 @@ module Cardano.Wallet.Api.Types
, ApiDecodeTransactionPostData (..)
, fromApiDecodeTransactionPostData
, toApiDecodeTransactionPostData
, EncryptMetadataMethod (..)

-- * API Types (Byron)
, ApiByronWallet (..)
Expand Down Expand Up @@ -1237,8 +1238,22 @@ data ApiMultiDelegationAction
deriving (Eq, Generic, Show)
deriving anyclass NFData

newtype ApiEncryptMetadata = ApiEncryptMetadata
{ passphrase :: ApiT (Passphrase "lenient") }
data EncryptMetadataMethod = AES256CBC
deriving (Eq, Generic, Show)
deriving anyclass NFData

instance ToJSON EncryptMetadataMethod where
toJSON AES256CBC = "base"
instance FromJSON EncryptMetadataMethod where
parseJSON = withText "base" $ \txt ->
if txt == "base" then
pure AES256CBC
else
fail "'base' is expected."

data ApiEncryptMetadata = ApiEncryptMetadata
{ passphrase :: ApiT (Passphrase "lenient")
, enc :: Maybe EncryptMetadataMethod }
deriving (Eq, Generic, Show)
deriving (FromJSON, ToJSON) via DefaultRecord ApiEncryptMetadata
deriving anyclass NFData
Expand Down
3 changes: 2 additions & 1 deletion lib/unit/test/unit/Cardano/Wallet/Api/TypesSpec.hs
Expand Up @@ -245,6 +245,7 @@ import Cardano.Wallet.Api.Types
, ByronWalletFromXPrvPostData (..)
, ByronWalletPostData (..)
, ByronWalletPutPassphraseData (..)
, EncryptMetadataMethod (..)
, Iso8601Time (..)
, KeyFormat (..)
, NtpSyncingStatus (..)
Expand Down Expand Up @@ -2048,7 +2049,7 @@ instance Arbitrary TxMetadataWithSchema where
<*> arbitrary

instance Arbitrary ApiEncryptMetadata where
arbitrary = ApiEncryptMetadata <$> arbitrary
arbitrary = ApiEncryptMetadata <$> arbitrary <*> pure (Just AES256CBC)

instance Arbitrary DRepID where
arbitrary = do
Expand Down

0 comments on commit 0a4bb5b

Please sign in to comment.