<p>It's an issue with Plutus core. Even though <strong>PubKeyHash</strong> is part of <strong>IsString</strong> type class, we can't use OverloadedStrings mechanism in on-chain code for certain types. Basically, the problem is this:</p>
<blockquote>
<p>Unfortunately, due to the technical reasons plutus plugin doesn't
support OverloadedStrings with newtypes.</p>
</blockquote>
<p>Please, check this issue.</p>
<p><a href="https://github.com/input-output-hk/plutus/issues/4404" rel="nofollow noreferrer">https://github.com/input-output-hk/plutus/issues/4404</a></p>
<p>Same thing apply for <code>PubKeyHash</code> and <code>LedgerBytes</code>.</p>
<p>A solution might be to have a parameterized validator script with <code>PubKeyHash</code>. This way, you can build <code>PubkeyHash</code> offchain using <strong>OverloadedStrings</strong> and pass it to the validator.</p>

CC BY-SA 4.0
2022-02-25T21:00:37.057Z
Thank you! Parameterized validator script with PubKeyHash works like a charm. Indeed a fascinating issue.
Martin Drozdík
CC BY-SA 4.0
2022-02-25T21:30:27.860Z
@MartinDrozdík You’re welcome. glad to help!
kindofdev
CC BY-SA 4.0
2022-02-25T19:26:16.517Z
2022-02-25T19:26:16.517Z
kindofdev
<p>A user provides me with his wallet pub key as BultinByteString (or Haskell string, fine either way). From that, I need to get the PubKeyHash, but I am not sure how to hash it or if I need to hash it at all.</p>
<p>Then, I need to use it in the PubKeyHash in Ledger.Constraints.MustBeSignedBy in my state machine. Kinda like that:</p>
<pre><code>Constraints.mustBeSignedBy &quot;35dedd2982a03cf39e7dce03c839994ffdec2ec6b04f1cf2d40e61a3&quot;
</code></pre>
<p>or</p>
<pre><code>Constraints.mustBeSignedBy PubKeyHash { getPubKeyHash = &quot;35dedd2982a03cf39e7dce03c839994ffdec2ec6b04f1cf2d40e61a3&quot; }
</code></pre>
<p>The problem is when I put some PubKeyHash in the constraint (like above), the compiler spits out 5000 long error starting with:</p>
<pre><code>GHC Core to PLC plugin: E042:Error: Unsupported feature: Use of fromString on type other than builtin strings or bytestrings: Plutus.V1.Ledger.Crypto.PubKeyHash
Context: Compiling expr: Data.String.fromString
                           @ Plutus.V1.Ledger.Crypto.PubKeyHash
                           Plutus.V1.Ledger.Crypto.$fIsStringPubKeyHash
                           (GHC.CString.unpackCString#
                              &quot;a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2&quot;#)
</code></pre>
<p>Can the string be translated into the PubKeyHash? Can it be somehow fixed? Is it me, or is it a Plutus bug?</p>
<p><em>Edit:</em></p>
<p>Tried new code:</p>
<pre><code>Constraints.mustBeSignedBy $ pubKeyHash (PubKey {
                            getPubKey = LedgerBytes { 
                                    getLedgerBytes = &quot;35dedd2982a03cf39e7dce03c839994ffdec2ec6b04f1cf2d40e61a3&quot; 
                                }
                        })
</code></pre>
<p>Got new error:</p>
<pre><code> GHC Core to PLC plugin: E042:Error: Unsupported feature: Type constructor: GHC.Prim.Char#
Context: Compiling type: GHC.Prim.Char#
Context: Compiling data constructor type: GHC.Types.C#
Context: Compiling type: GHC.Types.Char
Context: Compiling type: GHC.Base.String
Context: Compiling type: GHC.Base.String
                         -&gt; Plutus.V1.Ledger.Bytes.LedgerBytes
Context: Compiling definition of: Plutus.V1.Ledger.Bytes.$fIsStringLedgerBytes_$cfromString
Context: Compiling expr: Plutus.V1.Ledger.Bytes.$fIsStringLedgerBytes_$cfromString
Context: Compiling expr: Plutus.V1.Ledger.Bytes.$fIsStringLedgerBytes_$cfromString
...
</code></pre>

CC BY-SA 4.0
2022-02-25T18:10:56.650Z
Did you add OverloadedStrings pragma?
kindofdev
CC BY-SA 4.0
2022-02-25T18:32:18.647Z
Yes, I do have that pragma at the beginning of my file. No other issues with strings occurred in my state machine contract.
Martin Drozdík
<plutus><statemachines>
Get public key into PubKeyHash and use it in mustBeSignedBy
# Get public key into PubKeyHash and use it in mustBeSignedBy

(Asked by: username_0 on 2022-02-25)

A user provides me with his wallet pub key as BultinByteString (or Haskell string, fine either way). From that, I need to get the PubKeyHash, but I am not sure how to hash it or if I need to hash it at all.
Then, I need to use it in the PubKeyHash in Ledger.Constraints.MustBeSignedBy in my state machine. Kinda like that:
Constraints.mustBeSignedBy "35dedd2982a03cf39e7dce03c839994ffdec2ec6b04f1cf2d40e61a3"

or
Constraints.mustBeSignedBy PubKeyHash { getPubKeyHash = "35dedd2982a03cf39e7dce03c839994ffdec2ec6b04f1cf2d40e61a3" }

The problem is when I put some PubKeyHash in the constraint (like above), the compiler spits out 5000 long error starting with:
GHC Core to PLC plugin: E042:Error: Unsupported feature: Use of fromString on type other than builtin strings or bytestrings: Plutus.V1.Ledger.Crypto.PubKeyHash
Context: Compiling expr: Data.String.fromString
                           @ Plutus.V1.Ledger.Crypto.PubKeyHash
                           Plutus.V1.Ledger.Crypto.$fIsStringPubKeyHash
                           (GHC.CString.unpackCString#
                              "a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2"#)

Can the string be translated into the PubKeyHash? Can it be somehow fixed? Is it me, or is it a Plutus bug?
Edit:
Tried new code:
Constraints.mustBeSignedBy $ pubKeyHash (PubKey {
                            getPubKey = LedgerBytes { 
                                    getLedgerBytes = "35dedd2982a03cf39e7dce03c839994ffdec2ec6b04f1cf2d40e61a3" 
                                }
                        })

Got new error:
 GHC Core to PLC plugin: E042:Error: Unsupported feature: Type constructor: GHC.Prim.Char#
Context: Compiling type: GHC.Prim.Char#
Context: Compiling data constructor type: GHC.Types.C#
Context: Compiling type: GHC.Types.Char
Context: Compiling type: GHC.Base.String
Context: Compiling type: GHC.Base.String
                         -> Plutus.V1.Ledger.Bytes.LedgerBytes
Context: Compiling definition of: Plutus.V1.Ledger.Bytes.$fIsStringLedgerBytes_$cfromString
Context: Compiling expr: Plutus.V1.Ledger.Bytes.$fIsStringLedgerBytes_$cfromString
Context: Compiling expr: Plutus.V1.Ledger.Bytes.$fIsStringLedgerBytes_$cfromString
...

**Tags:** plutus, statemachines
> **Comments:**
> **username_1**: Did you add OverloadedStrings pragma?  
> **username_0**: Yes, I do have that pragma at the beginning of my file. No other issues with strings occurred in my state machine contract.  

---

## 1 answers

### Answer by username_1 on 2022-02-25. Score: 1 | Accepted answer

It's an issue with Plutus core. Even though **PubKeyHash** is part of **IsString** type class, we can't use OverloadedStrings mechanism in on-chain code for certain types. Basically, the problem is this:

> Unfortunately, due to the technical reasons plutus plugin doesn't
> support OverloadedStrings with newtypes.

Please, check this issue.

<https://github.com/input-output-hk/plutus/issues/4404>

Same thing apply for `PubKeyHash` and `LedgerBytes`.

A solution might be to have a parameterized validator script with `PubKeyHash`. This way, you can build `PubkeyHash` offchain using **OverloadedStrings** and pass it to the validator.

> **Comments:**
> **username_0**: Thank you! Parameterized validator script with PubKeyHash works like a charm. Indeed a fascinating issue.  
> **username_1**: @MartinDrozdík You’re welcome. glad to help!  

---

