Skip to content

Commit 0c3ccb4

Browse files
committed
correct 64-byte restriction on passphrase hash
1 parent 12dae9d commit 0c3ccb4

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

lib/core/src/Cardano/Wallet/Api/Types.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ import Cardano.Wallet.Primitive.Types
149149
, WalletBalance (..)
150150
, WalletId (..)
151151
, WalletName (..)
152-
, hashFromText
153152
, isValidCoin
154153
, unsafeEpochNo
155154
)
@@ -397,7 +396,7 @@ data ByronWalletFromXPrvPostData = ByronWalletFromXPrvPostData
397396
-- ^ A root private key hex-encoded, encrypted using a given passphrase.
398397
-- The underlying key should contain: private key, chain code, and public key
399398
, passphraseHash :: !(ApiT (Hash "encryption"))
400-
-- ^ A hash of master passphrase. The hash should be a 64-byte output of a
399+
-- ^ A hash of master passphrase. The hash should be an output of a
401400
-- Scrypt function with the following parameters:
402401
-- - logN = 14
403402
-- - r = 8
@@ -685,7 +684,14 @@ instance ToText (ApiT XPrv) where
685684
. getApiT
686685

687686
instance FromText (ApiT (Hash "encryption")) where
688-
fromText = fmap ApiT . hashFromText 64
687+
fromText txt = case convertFromBase Base16 $ T.encodeUtf8 txt of
688+
Right bytes -> Right $ ApiT $ Hash bytes
689+
Left _ -> textDecodingError
690+
where
691+
textDecodingError = Left $ TextDecodingError $ unwords
692+
[ "Invalid encrypted passphrase:"
693+
, "expecting a hex-encoded value."
694+
]
689695

690696
{-------------------------------------------------------------------------------
691697
API Types: Byron

lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,8 @@ instance Arbitrary ByronWalletFromXPrvPostData where
10921092
arbitrary = do
10931093
n <- arbitrary
10941094
rootXPrv <- ApiT . unsafeXPrv . BS.pack <$> vectorOf 128 arbitrary
1095-
h <- ApiT . Hash . B8.pack <$> replicateM 64 arbitrary
1095+
bytesNumber <- choose (64,100)
1096+
h <- ApiT . Hash . B8.pack <$> replicateM bytesNumber arbitrary
10961097
pure $ ByronWalletFromXPrvPostData n rootXPrv h
10971098

10981099
instance Arbitrary SomeByronWalletPostData where

specifications/api/swagger.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,13 @@ x-walletPassphrase: &walletPassphrase
270270

271271
x-walletPassphraseHash: &walletPassphraseHash
272272
description: |
273-
A hash of master passphrase. The hash should be a 64-byte output of a Scrypt function with the following parameters:
273+
A hash of master passphrase. The hash should be an output of a Scrypt function with the following parameters:
274274
- logN = 14
275275
- r = 8
276276
- p = 1
277277
type: string
278278
format: hex
279-
minLength: 128
280-
maxLength: 128
281-
example: 3be2ead8e3c3be2ea67c41a6e898ceecddeecd88585d11d15d8733f7ad1adbaf3c1570d8e3c67c41a6e898ceecddeecd88585d11d15d8733f7ad1adbaf3c1570
279+
example: 31347c387c317c574342652b796362417576356c2b4258676a344a314c6343675375414c2f5653393661364e576a2b7550766655513d3d7c2f376738486c59723174734e394f6e4e753253302b6a65515a6b5437316b45414941366a515867386539493d
282280

283281
x-walletEncryptedRootPrivateKey: &walletEncryptedRootPrivateKey
284282
description: |

0 commit comments

Comments
 (0)