@@ -59,7 +59,7 @@ import Data.ByteString.Lazy qualified as LazyByteString
5959import Data.ByteString.Short qualified as ShortByteString
6060import Data.Either.Combinators (mapLeft )
6161import Data.Kind (Type )
62- import Data.List (sortOn , unzip4 )
62+ import Data.List (isPrefixOf , sortOn , unzip4 )
6363import Data.Map (Map )
6464import Data.Map qualified as Map
6565import Data.Maybe (catMaybes , mapMaybe )
@@ -211,21 +211,30 @@ readPrivateKeys ::
211211 Eff effs (Either Text (Map PubKeyHash DummyPrivKey ))
212212readPrivateKeys pabConf = do
213213 files <- listDirectory @ w $ Text. unpack pabConf. pcSigningKeyFileDir
214-
215- privKeys <-
216- catMaybes
217- <$> mapM
218- ( \ filename ->
219- let fullPath = Text. unpack pabConf. pcSigningKeyFileDir </> filename
220- in case takeExtension filename of
221- " .vkey" -> Just <$> readVerificationKey @ w fullPath
222- " .skey" -> Just <$> readSigningKey @ w fullPath
223- _ -> pure Nothing
224- )
225- files
226-
214+ privKeys <- catMaybes <$> mapM readKey files
227215 pure $ toPrivKeyMap <$> sequence privKeys
228216 where
217+ readKey filename =
218+ let fullPath = Text. unpack pabConf. pcSigningKeyFileDir </> filename
219+ in case takeExtension filename of
220+ " .vkey" ->
221+ guardPaymentKey paymentVKeyPrefix filename
222+ <$> readVerificationKey @ w fullPath
223+ " .skey" ->
224+ guardPaymentKey paymentSKeyPrefix filename
225+ <$> readSigningKey @ w fullPath
226+ _ -> pure Nothing
227+
228+ paymentVKeyPrefix = " verification-key"
229+ paymentSKeyPrefix = " signing-key"
230+
231+ {- this filtering ensures that only payment keys are read,
232+ it allows to store other types of keys in the same drirectory if required
233+ by altering filename prefix
234+ -}
235+ guardPaymentKey prefix filename =
236+ if prefix `isPrefixOf` filename then Just else const Nothing
237+
229238 toPrivKeyMap :: [DummyPrivKey ] -> Map PubKeyHash DummyPrivKey
230239 toPrivKeyMap =
231240 foldl
0 commit comments