@@ -53,6 +53,7 @@ module Cardano.Api.Address
5353 , StakeExtendedKey
5454
5555 -- * Conversion functions
56+ , shelleyPayAddrToPaymentKeyHash
5657 , shelleyPayAddrToPlutusPubKHash
5758
5859 -- * Internal conversion functions
@@ -113,6 +114,7 @@ import Data.Bifunctor (first)
113114import Data.ByteString.Base58 qualified as Base58
114115import Data.Char (isAsciiLower , isAsciiUpper , isDigit )
115116import Data.Either.Combinators (rightToMaybe )
117+ import Data.Maybe (isJust )
116118import Data.Text (Text )
117119import Data.Text qualified as Text
118120import Data.Text.Encoding qualified as Text
@@ -612,10 +614,13 @@ makeStakeAddress nw sc =
612614-- | Is the UTxO at the address only spendable via a key witness.
613615isKeyAddress :: AddressInEra era -> Bool
614616isKeyAddress (AddressInEra ByronAddressInAnyEra _) = True
615- isKeyAddress (AddressInEra (ShelleyAddressInEra _) (ShelleyAddress _ pCred _)) =
617+ isKeyAddress (AddressInEra (ShelleyAddressInEra _) addr) = isJust $ shelleyPayAddrToPaymentKeyHash addr
618+
619+ shelleyPayAddrToPaymentKeyHash :: Address ShelleyAddr -> Maybe (Hash PaymentKey )
620+ shelleyPayAddrToPaymentKeyHash (ShelleyAddress _ pCred _) =
616621 case fromShelleyPaymentCredential pCred of
617- PaymentCredentialByKey _ -> True
618- PaymentCredentialByScript _ -> False
622+ PaymentCredentialByKey key -> Just key
623+ PaymentCredentialByScript _ -> Nothing
619624
620625-- | Converts a Shelley payment address to a Plutus public key hash.
621626shelleyPayAddrToPlutusPubKHash :: Address ShelleyAddr -> Maybe PlutusAPI. PubKeyHash
0 commit comments