Skip to content

Commit

Permalink
add genSalt and use it in constructTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Apr 25, 2024
1 parent 173e2e3 commit 244c0b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,9 @@ import Control.Tracer
import Cryptography.Cipher.AES256CBC
( CipherMode (..)
)
import Cryptography.Core
( genSalt
)
import Cryptography.Hash.Core
( SHA256 (..)
)
Expand Down Expand Up @@ -2748,8 +2751,9 @@ constructTransaction api argGenChange knownPools poolStatus apiWalletId body = d
liftHandler $ throwE ErrConstructTxWrongPayload

metadata <- case (body ^. #encryptMetadata, body ^. #metadata) of
(Just apiEncrypt, Just metadataWithSchema) ->
case toMetadataEncrypted apiEncrypt metadataWithSchema Nothing of
(Just apiEncrypt, Just metadataWithSchema) -> do
salt <- liftIO $ genSalt 8
case toMetadataEncrypted apiEncrypt metadataWithSchema (Just salt) of
Left err ->
liftHandler $ throwE err
Right meta ->
Expand Down
9 changes: 9 additions & 0 deletions lib/crypto-primitives/src/Cryptography/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ module Cryptography.Core
, eitherCryptoError

, MonadRandom (..)
, genSalt
) where

import Prelude

import Crypto.Error
( CryptoError (..)
, CryptoFailable (..)
Expand All @@ -14,3 +17,9 @@ import Crypto.Error
import Crypto.Random.Types
( MonadRandom (..)
)
import Data.ByteString
( ByteString
)

genSalt :: MonadRandom m => Int -> m ByteString
genSalt = getRandomBytes

0 comments on commit 244c0b0

Please sign in to comment.