user1983: 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

user4469: 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


user5020: There 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.

1983: <p>Is there a way to do this programmatically? I have an</p>
<p><code>Address ShelleyAddr</code></p>
<p>obtained from</p>
<p><code>deserialiseFromBech32 AsShelleyAddress</code></p>
<p>and need its</p>
<p><code>Plutus.V1.Ledger.Crypto.PubKeyHash</code></p>
 4469: <p>This compiles with a recent version of <code>cardano-node</code> and <code>plutus</code>:</p>
<pre><code>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 -&gt; PubKeyHash
addrToPkh (ShelleyAddress net (ScriptHashObj sh) sr) = transKeyHash sh
addrToPkh (ShelleyAddress net (KeyHashObj kh) sr) = transKeyHash kh
</code></pre>
 5020: <p>There is now the function <code>shelleyPayAddrToPlutusPubKHash</code> in <code>cardano-api</code> which returns <code>Maybe PubKeyHash</code> because in the case of a script credential there is no corresponding public key hash.</p>
