Skip to content

Commit

Permalink
Replace scrypt with cryptonite for integration tests only
Browse files Browse the repository at this point in the history
I'm not too keen on changing the scrypt package in the main code, for
the time being. But we can replace this package in the integration
tests, without too much risk.
  • Loading branch information
rvl committed Jul 20, 2021
1 parent f3d4d11 commit 7ffca24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 0 additions & 1 deletion lib/core-integration/cardano-wallet-core-integration.cabal
Expand Up @@ -68,7 +68,6 @@ library
, resourcet
, retry
, say
, scrypt
, template-haskell
, text
, text-class
Expand Down
18 changes: 11 additions & 7 deletions lib/core-integration/src/Test/Integration/Framework/DSL.hs
Expand Up @@ -172,7 +172,7 @@ module Test.Integration.Framework.DSL
, delegating
, getSlotParams
, arbitraryStake

-- * CLI
, commandName
, command
Expand Down Expand Up @@ -326,6 +326,8 @@ import Control.Retry
( capDelay, constantDelay, retrying )
import Crypto.Hash
( Blake2b_160, Digest, digestFromByteString )
import Crypto.Random.Entropy
( getEntropy )
import Data.Aeson
( FromJSON, ToJSON, Value, (.=) )
import Data.Aeson.QQ
Expand Down Expand Up @@ -439,7 +441,7 @@ import qualified Cardano.Wallet.Primitive.Types.TokenQuantity as TokenQuantity
import qualified Codec.Binary.Bech32 as Bech32
import qualified Codec.CBOR.Encoding as CBOR
import qualified Codec.CBOR.Write as CBOR
import qualified Crypto.Scrypt as Scrypt
import qualified Crypto.KDF.Scrypt as Scrypt
import qualified Data.Aeson as Aeson
import qualified Data.ByteArray as BA
import qualified Data.ByteString as BS
Expand Down Expand Up @@ -1248,17 +1250,19 @@ emptyRandomWalletWithPasswd ctx rawPwd = do
$ hex
$ Byron.getKey
$ Byron.generateKeyFromSeed seed pwd
pwdH <- liftIO $ T.decodeUtf8 . hex <$> encryptPasswordWithScrypt pwd
pwdH <- liftIO $ T.decodeUtf8 . hex @ByteString <$> scrypt pwd
emptyByronWalletFromXPrvWith ctx "random" ("Random Wallet", key, pwdH)
where
encryptPasswordWithScrypt =
fmap Scrypt.getEncryptedPass
. Scrypt.encryptPassIO Scrypt.defaultParams
. Scrypt.Pass
scrypt = encryptPasswordWithScrypt
. CBOR.toStrictByteString
. CBOR.encodeBytes
. BA.convert

encryptPasswordWithScrypt :: (BA.ByteArrayAccess a, BA.ByteArray b) => a -> IO b
encryptPasswordWithScrypt pwd = Scrypt.generate params pwd <$> genSalt
where
params = Scrypt.Parameters 14 8 1 64
genSalt = getEntropy @ByteString 32

postWallet'
:: (MonadIO m, MonadUnliftIO m)
Expand Down

0 comments on commit 7ffca24

Please sign in to comment.