user1983: Given the variable s from
import qualified Wallet.Emulator.Wallet as W
import qualified Ledger

-- Has value of "35dedd2982a03cf39e7dce03c839994ffdec2ec6b04f1cf2d40e61a3"
s :: String
s = show (Ledger.pubKeyHash $ W.walletPubKey $ W.Wallet 1)

How do I turn that back into a PubKeyHash?

user2681: module Main ( main) where

import           Data.String (IsString(fromString))
import           Data.Either (fromRight)
import           Data.Text (Text, pack)
import           Ledger (PubKeyHash(..), pubKeyHash) 
import           Ledger.Bytes (LedgerBytes(LedgerBytes), fromHex)
import qualified Wallet.Emulator.Wallet as W

main :: IO ()
main = do
    let pkh1 = pubKeyHash $ W.walletPubKey $ W.Wallet 1
    let pkh9 = pubKeyHash $ W.walletPubKey $ W.Wallet 9

    let s = show pkh1
    let eiPkh = pkhFromStr s

    let s' = show $ fromRight pkh9 eiPkh
    let eiPkh' = pkhFromStr s'

    let s'' = show $ fromRight pkh9 eiPkh'

    print s   
    print s'
    print s''


pkhFromStr :: String -> Either Text PubKeyHash   
pkhFromStr s =         
    case fromHex (fromString s) of 
        Right (LedgerBytes bytes) -> Right $ PubKeyHash bytes 
        Left msg -> Left $ pack ("Could not convert from hex to bytes: " <> msg)

The above code produces the following correct outputs.
"35dedd2982a03cf39e7dce03c839994ffdec2ec6b04f1cf2d40e61a3"
"35dedd2982a03cf39e7dce03c839994ffdec2ec6b04f1cf2d40e61a3"
"35dedd2982a03cf39e7dce03c839994ffdec2ec6b04f1cf2d40e61a3"


1983: <p>Given the variable <code>s</code> from</p>
<pre><code>import qualified Wallet.Emulator.Wallet as W
import qualified Ledger

-- Has value of &quot;35dedd2982a03cf39e7dce03c839994ffdec2ec6b04f1cf2d40e61a3&quot;
s :: String
s = show (Ledger.pubKeyHash $ W.walletPubKey $ W.Wallet 1)
</code></pre>
<p>How do I turn that back into a <code>PubKeyHash</code>?</p>
 2681: <pre><code>module Main ( main) where

import           Data.String (IsString(fromString))
import           Data.Either (fromRight)
import           Data.Text (Text, pack)
import           Ledger (PubKeyHash(..), pubKeyHash) 
import           Ledger.Bytes (LedgerBytes(LedgerBytes), fromHex)
import qualified Wallet.Emulator.Wallet as W

main :: IO ()
main = do
    let pkh1 = pubKeyHash $ W.walletPubKey $ W.Wallet 1
    let pkh9 = pubKeyHash $ W.walletPubKey $ W.Wallet 9

    let s = show pkh1
    let eiPkh = pkhFromStr s

    let s' = show $ fromRight pkh9 eiPkh
    let eiPkh' = pkhFromStr s'

    let s'' = show $ fromRight pkh9 eiPkh'

    print s   
    print s'
    print s''


pkhFromStr :: String -&gt; Either Text PubKeyHash   
pkhFromStr s =         
    case fromHex (fromString s) of 
        Right (LedgerBytes bytes) -&gt; Right $ PubKeyHash bytes 
        Left msg -&gt; Left $ pack (&quot;Could not convert from hex to bytes: &quot; &lt;&gt; msg)
</code></pre>
<p>The above code produces the following correct outputs.</p>
<pre><code>&quot;35dedd2982a03cf39e7dce03c839994ffdec2ec6b04f1cf2d40e61a3&quot;
&quot;35dedd2982a03cf39e7dce03c839994ffdec2ec6b04f1cf2d40e61a3&quot;
&quot;35dedd2982a03cf39e7dce03c839994ffdec2ec6b04f1cf2d40e61a3&quot;
</code></pre>
