Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ cardano-cli query protocol-parameters --testnet-magic 42 --out-file protocol.jso
```

5. Create a `signing-keys` folder under your projects root with the necessary signig key file(s).
The files should be named in the following format: `signing-key-PUBKEYHASH.skey`
The files should be named in the following format: `signing-key-PUBKEYHASHHEX.skey` and `verification-key-PUBKEYHASHHEX.vkey`

Use the cardano-cli to find out the pub key hash for your key:

Expand Down
9 changes: 8 additions & 1 deletion src/BotPlutusInterface/Collateral.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import BotPlutusInterface.Types (
ContractEnvironment (ceCollateral),
PABConfig (pcOwnPubKeyHash),
collateralValue,
pcOwnStakePubKeyHash,
unCollateralVar,
)
import Cardano.Prelude (Void)
Expand Down Expand Up @@ -54,7 +55,13 @@ mkCollateralTx :: PABConfig -> Either Constraints.MkTxError Constraints.Unbalanc
mkCollateralTx pabConf = Constraints.mkTx @Void mempty txc
where
txc :: Constraints.TxConstraints Void Void
txc = Constraints.mustPayToPubKey (PaymentPubKeyHash $ pcOwnPubKeyHash pabConf) (collateralValue pabConf)
txc =
maybe -- pay to either a base or enterprise address
Constraints.mustPayToPubKey
(flip Constraints.mustPayToPubKeyAddress)
(pcOwnStakePubKeyHash pabConf)
(PaymentPubKeyHash $ pcOwnPubKeyHash pabConf)
(collateralValue pabConf)

-- | Middleware to run `chain-index` queries and filter out collateral output from response.
withCollateralHandling ::
Expand Down
37 changes: 23 additions & 14 deletions src/BotPlutusInterface/Files.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import Data.ByteString.Lazy qualified as LazyByteString
import Data.ByteString.Short qualified as ShortByteString
import Data.Either.Combinators (mapLeft)
import Data.Kind (Type)
import Data.List (sortOn, unzip4)
import Data.List (isPrefixOf, sortOn, unzip4)
import Data.Map (Map)
import Data.Map qualified as Map
import Data.Maybe (catMaybes, mapMaybe)
Expand Down Expand Up @@ -211,21 +211,30 @@ readPrivateKeys ::
Eff effs (Either Text (Map PubKeyHash DummyPrivKey))
readPrivateKeys pabConf = do
files <- listDirectory @w $ Text.unpack pabConf.pcSigningKeyFileDir

privKeys <-
catMaybes
<$> mapM
( \filename ->
let fullPath = Text.unpack pabConf.pcSigningKeyFileDir </> filename
in case takeExtension filename of
".vkey" -> Just <$> readVerificationKey @w fullPath
".skey" -> Just <$> readSigningKey @w fullPath
_ -> pure Nothing
)
files

privKeys <- catMaybes <$> mapM readKey files
pure $ toPrivKeyMap <$> sequence privKeys
where
readKey filename =
let fullPath = Text.unpack pabConf.pcSigningKeyFileDir </> filename
in case takeExtension filename of
".vkey" ->
guardPaymentKey paymentVKeyPrefix filename
<$> readVerificationKey @w fullPath
".skey" ->
guardPaymentKey paymentSKeyPrefix filename
<$> readSigningKey @w fullPath
_ -> pure Nothing

paymentVKeyPrefix = "verification-key"
paymentSKeyPrefix = "signing-key"

{- this filtering ensures that only payment keys are read,
it allows to store other types of keys in the same drirectory if required
by altering filename prefix
-}
guardPaymentKey prefix filename =
if prefix `isPrefixOf` filename then Just else const Nothing

toPrivKeyMap :: [DummyPrivKey] -> Map PubKeyHash DummyPrivKey
toPrivKeyMap =
foldl
Expand Down
2 changes: 1 addition & 1 deletion test/Spec/MockContract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ toSigningKeyFile signingKeyFileDir sKey =

toVerificationKeyFile :: FilePath -> VerificationKey PaymentKey -> (FilePath, MockFile)
toVerificationKeyFile signingKeyFileDir vKey =
( signingKeyFileDir ++ "/signing-key-" ++ show (Ledger.pubKeyHash (vkeyToPubKey vKey)) ++ ".vkey"
( signingKeyFileDir ++ "/verification-key-" ++ show (Ledger.pubKeyHash (vkeyToPubKey vKey)) ++ ".vkey"
, TextEnvelopeFile $ serialiseToTextEnvelope Nothing vKey
)

Expand Down