user2248: In the Plutus Pionner Lectures, Lars instructed us to use txSignedBy in order to ensure that a user signed the transaction. The function tries to find a public key hash in the txInfoSignatories list, if it's able to find, it returns True.
Everything was working in the emulator, but now, when I tried to manually build and sign the transaction with cardano-cli, the transaction doesn't appear to add the public key hash from the user who signed it to txInfoSignatories and the script validation fails. My question is: how do I add the user pubkeyhash to txInfoSignatories with cardano-cli? No information regarding the signature appears when I execute cardano-cli transaction build -- help

user4880: @georgeos answer was correct, but from node version 1.32 there is
--required-signer-hash HASH
                           Hash of the verification key (zero or more) whose
                           signature is required.

(so you don't need to know users signing key, just pass the PubKeyHash)

user1231: ------ UPDATE------
Since version 1.31 of cardano-cli, there is the following option to sign the transaction when it is built, so you can avoid that error from the script:
--required-signer FILE   Input filepath of the signing key (zero or more)
                         whose signature is required.

-----------------------
It's related to this bug: Cli to pass required signer (reqSignerHashes) to plutus script for txInfoSignatories
In a near future, there will be a --required-signer option in cardano-cli
As a workaround try to combine toPubKeyHash and txOutAddress function to get the PubKeyHash from any output.
info :: TxInfo
info = scriptContextTxInfo ctx

txOuts :: [TxOut]
txOuts = txInfoOutputs info

outPubKeyHash :: Maybe PubKeyHash
outPubKeyHash = toPubKeyHash $ txOutAddress $ head txOuts


2248: <p>In the Plutus Pionner Lectures, Lars instructed us to use <a href="https://staging.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/Plutus-V1-Ledger-Contexts.html#v:txSignedBy" rel="nofollow noreferrer"><code>txSignedBy</code></a> in order to ensure that a user signed the transaction. The function tries to find a public key hash in the <a href="https://staging.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/Plutus-V1-Ledger-Api.html#t:TxInfo" rel="nofollow noreferrer"><code>txInfoSignatories</code></a> list, if it's able to find, it returns True.</p>
<p>Everything was working in the emulator, but now, when I tried to manually build and sign the transaction with cardano-cli, the transaction doesn't appear to add the public key hash from the user who signed it to <code>txInfoSignatories</code> and the script validation fails. My question is: how do I add the user pubkeyhash to <code>txInfoSignatories</code> with cardano-cli? No information regarding the signature appears when I execute <code>cardano-cli transaction build -- help</code></p>
 4880: <p>@georgeos answer was correct, but from node version 1.32 there is</p>
<pre><code>--required-signer-hash HASH
                           Hash of the verification key (zero or more) whose
                           signature is required.
</code></pre>
<p>(so you don't need to know users signing key, just pass the PubKeyHash)</p>
 1231: <p><strong>------ UPDATE------</strong></p>
<p>Since version 1.31 of <code>cardano-cli</code>, there is the following option to sign the transaction when it is built, so you can avoid that error from the script:</p>
<pre><code>--required-signer FILE   Input filepath of the signing key (zero or more)
                         whose signature is required.
</code></pre>
<p><strong>-----------------------</strong></p>
<p>It's related to this bug: <a href="https://github.com/input-output-hk/cardano-node/issues/3106" rel="nofollow noreferrer">Cli to pass required signer (reqSignerHashes) to plutus script for txInfoSignatories</a></p>
<p>In a near future, there will be a <code>--required-signer</code> option in cardano-cli</p>
<p>As a workaround try to combine <code>toPubKeyHash</code> and <code>txOutAddress</code> function to get the PubKeyHash from any output.</p>
<pre><code>info :: TxInfo
info = scriptContextTxInfo ctx

txOuts :: [TxOut]
txOuts = txInfoOutputs info

outPubKeyHash :: Maybe PubKeyHash
outPubKeyHash = toPubKeyHash $ txOutAddress $ head txOuts
</code></pre>
