Skip to content

Commit 04b74e0

Browse files
committed
relocate encryptPasswordWithScrypt to spec
nix patch
1 parent b777a0c commit 04b74e0

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

lib/core/cardano-wallet-core.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ test-suite unit
212212
, random
213213
, retry
214214
, safe
215+
, scrypt
215216
, servant
216217
, servant-server
217218
, servant-swagger

lib/core/src/Cardano/Wallet/Primitive/AddressDerivation.hs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ module Cardano.Wallet.Primitive.AddressDerivation
9494
, encryptPassphrase
9595
, checkPassphrase
9696
, preparePassphrase
97-
, encryptPasswordWithScrypt
9897
) where
9998

10099
import Prelude
@@ -556,20 +555,6 @@ checkPassphrase scheme received stored = do
556555
constantTimeEq (Hash a) (Hash b) =
557556
BA.convert @_ @ScrubbedBytes a == BA.convert @_ @ScrubbedBytes b
558557

559-
-- | Encrypt password using Scrypt function with the following parameters:
560-
-- logN = 14
561-
-- r = 8
562-
-- p = 1
563-
-- These parameters are in Scrypt.defaultParams
564-
encryptPasswordWithScrypt
565-
:: Passphrase "raw"
566-
-> IO ByteString
567-
encryptPasswordWithScrypt p =
568-
Scrypt.getEncryptedPass <$>
569-
Scrypt.encryptPassIO Scrypt.defaultParams (Scrypt.Pass $ BA.convert passwd)
570-
where
571-
(Passphrase passwd) = preparePassphrase EncryptWithScrypt p
572-
573558
-- | Indicate a failure when checking for a given 'Passphrase' match
574559
data ErrWrongPassphrase = ErrWrongPassphrase
575560
deriving stock (Show, Eq)

lib/core/test/unit/Cardano/Wallet/Primitive/AddressDerivationSpec.hs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import Cardano.Wallet.Primitive.AddressDerivation
4040
, XPrv
4141
, checkPassphrase
4242
, encryptPassphrase
43-
, encryptPasswordWithScrypt
4443
, getIndex
4544
, hex
4645
, preparePassphrase
@@ -103,6 +102,7 @@ import Test.Text.Roundtrip
103102
import qualified Cardano.Wallet.Primitive.AddressDerivation.Byron as Rnd
104103
import qualified Cardano.Wallet.Primitive.AddressDerivation.Icarus as Ica
105104
import qualified Cardano.Wallet.Primitive.AddressDerivation.Shelley as Seq
105+
import qualified Crypto.Scrypt as Scrypt
106106
import qualified Data.ByteArray as BA
107107
import qualified Data.ByteString as BS
108108
import qualified Data.ByteString.Char8 as B8
@@ -356,7 +356,7 @@ prop_passphraseFromScryptRoundtrip
356356
-> Property
357357
prop_passphraseFromScryptRoundtrip p = monadicIO $ liftIO $ do
358358
hp <- encryptPasswordWithScrypt p
359-
checkPassphrase EncryptWithScrypt p (Hash hp) `shouldBe` Right ()
359+
checkPassphrase EncryptWithScrypt p hp `shouldBe` Right ()
360360

361361
prop_passphraseFromScryptRoundtripFail
362362
:: Passphrase "raw"
@@ -365,7 +365,7 @@ prop_passphraseFromScryptRoundtripFail
365365
prop_passphraseFromScryptRoundtripFail p p' =
366366
p /= p' ==> monadicIO $ liftIO $ do
367367
hp <- encryptPasswordWithScrypt p
368-
checkPassphrase EncryptWithScrypt p' (Hash hp)
368+
checkPassphrase EncryptWithScrypt p' hp
369369
`shouldBe` Left ErrWrongPassphrase
370370

371371
-- | xPrvFromStrippedPubXPrv and unXPrvStripPub
@@ -623,3 +623,17 @@ genLegacyAddress range = do
623623

624624
instance Arbitrary SomeMnemonic where
625625
arbitrary = SomeMnemonic <$> genMnemonic @12
626+
627+
-- | Encrypt password using Scrypt function with the following parameters:
628+
-- logN = 14
629+
-- r = 8
630+
-- p = 1
631+
-- These parameters are in Scrypt.defaultParams
632+
encryptPasswordWithScrypt
633+
:: Passphrase "raw"
634+
-> IO (Hash "encryption")
635+
encryptPasswordWithScrypt p =
636+
Hash . Scrypt.getEncryptedPass <$>
637+
Scrypt.encryptPassIO Scrypt.defaultParams (Scrypt.Pass $ BA.convert passwd)
638+
where
639+
(Passphrase passwd) = preparePassphrase EncryptWithScrypt p

nix/.stack.nix/cardano-wallet-core.nix

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)