Is there a way to do this programmatically? I have an
Address ShelleyAddr
obtained from
deserialiseFromBech32 AsShelleyAddress
and need its
Plutus.V1.Ledger.Crypto.PubKeyHash
Cardano Stack Exchange is a question and answer site for users and developers of the Cardano cryptocurrency ecosystem. It only takes a minute to sign up.
Sign up to join this communityThere is now the function shelleyPayAddrToPlutusPubKHash
in cardano-api
which returns Maybe PubKeyHash
because in the case of a script credential there is no corresponding public key hash.
This compiles with a recent version of cardano-node
and plutus
:
import Plutus.V1.Ledger.Api (PubKeyHash)
import Cardano.Ledger.Alonzo.TxInfo (transKeyHash)
import Cardano.Api (ShelleyAddr)
import Cardano.Api.Shelley (Address (ShelleyAddress))
import Cardano.Ledger.Shelley.API (Credential (KeyHashObj, ScriptHashObj))
addrToPkh :: Address ShelleyAddr -> PubKeyHash
addrToPkh (ShelleyAddress net (ScriptHashObj sh) sr) = transKeyHash sh
addrToPkh (ShelleyAddress net (KeyHashObj kh) sr) = transKeyHash kh
AlonzoAddr
(via deserialiseFromBech32 AsAlonzoAddress
)? I am only using ShellyAddr
because that's what I found in the API.
cabal build
is giving me: unknown package: cardano-ledger-shelley
. Not sure what to do.
AlonzoAddr
is fine and to make it compile you need to add cardano-ledger-shelley
to your code's .cabal
file in the build-depends
section and maybe ensure you are having the https://github.com/input-output-hk/cardano-ledger-specs
as a source-repository-package
in cabal.project
(depends a bit on your workflow).
Nov 17, 2021 at 11:21
cabal
about it, such that .cabal
file is happy with having cardano-ledger-shelley
in its build-depends
section?