<blockquote>
  <p>So how we can verify this transaction is valid without having the public-key?</p>
</blockquote>

<p>The signature includes the public key corresponding to the private key that made the signature.</p>

<blockquote>
  <p>If we attach the public-key with the message then why spending time finding hash of public-key in the first place?</p>
</blockquote>

<p>It's not clear what you mean by "the public key". Whose public key are you talking about? Bob's public key isn't in the message.</p>

<blockquote>
  <p>Are we storing the public keys in some centralized database?</p>
</blockquote>

<p>When a public key is submitted with a signature, the public key is in the transaction. The transaction is included in a block, and that block is part of the blockchain forever.</p>

<blockquote>
  <p>If the recipient provides the public-key and verifies the transaction is valid how others can validate that was a valid transaction?</p>
</blockquote>

<p>It's not clear what you mean by "that". To validate a transaction, you just have to make sure it's entitled to claim the funds it tries to claim. You don't particularly care what it does with those funds, just that it has the right to decide what to do with them. So you don't need to know much about the recipients -- only enough to identify them when they come to claim their funds. The hash of their public key does that.</p>

CC BY-SA 3.0
2016-11-12T19:19:06.723Z
"The signature includes the public key ..."
I understand, it is the <SCRIPTSIG> of a tx-in? That is, `<SCRIPTSIG>` is composed of signature, "01" (OP_SIGHASHALL) and then the pubkey.
pebwindkraft
CC BY-SA 3.0
2016-10-26T09:06:47.293Z
2016-10-26T09:06:47.293Z
David Schwartz
<p>I am new to bitcoin and I am trying to understand <em>Pay-to-Public-Key-Hash (P2PKH)</em> from the book: <a href="http://uplib.fr/w/images/8/83/Mastering_Bitcoin-Antonopoulos.pdf" rel="nofollow noreferrer">Mastering Bitcoin: Unlocking Digital Cryptocurrencies</a> (p. 127). I understand that digital keys (which are derived from private-keys) are not actually stored in the network, but are instead stored by users in a wallet.</p>

<p><strong>For example</strong>:
Alice wants to send Bob 1-BTC:</p>

<pre><code>---------------------------------------------------------
| Sender:    Hash(alice-public-key)                     |
| Receiver:  Hash(bob-public-key)                       |
| Amount:    1-BTC                                      |
| Signature: Hash(Encrypt_{alice-private-key}(Message)) |
---------------------------------------------------------
</code></pre>

<p><strong>Question</strong>:</p>

<ul>
<li>So how can we verify this transaction is valid without having the
public-key?</li>
<li>If we attach the public-key with the message then why spending
time finding hash of public-key in the first place?</li>
<li>Are we storing
the public keys in some centralized database?</li>
<li>If the recipient provides the public-key and verifies the transaction
is valid how can others validate that was a valid transaction?</li>
</ul>

CC BY-SA 3.0
2018-02-08T00:04:42.337Z
I would add "what is `Message` that is contained in your example?"
Rafael Eyng
<p2pk><p2pkh>
Trying to understand Pay-to-Public-Key-Hash
Node.JS
# Trying to understand Pay-to-Public-Key-Hash

(Asked by: username_0 on 2016-10-26)

I am new to bitcoin and I am trying to understand *Pay-to-Public-Key-Hash (P2PKH)* from the book: [Mastering Bitcoin: Unlocking Digital Cryptocurrencies](http://uplib.fr/w/images/8/83/Mastering_Bitcoin-Antonopoulos.pdf) (p. 127). I understand that digital keys (which are derived from private-keys) are not actually stored in the network, but are instead stored by users in a wallet.

**For example**:
Alice wants to send Bob 1-BTC:

```
---------------------------------------------------------
| Sender:    Hash(alice-public-key)                     |
| Receiver:  Hash(bob-public-key)                       |
| Amount:    1-BTC                                      |
| Signature: Hash(Encrypt_{alice-private-key}(Message)) |
---------------------------------------------------------

```

**Question**:

* So how can we verify this transaction is valid without having the
  public-key?
* If we attach the public-key with the message then why spending
  time finding hash of public-key in the first place?
* Are we storing
  the public keys in some centralized database?
* If the recipient provides the public-key and verifies the transaction
  is valid how can others validate that was a valid transaction?

**Tags:** p2pk, p2pkh

> **Comments:**
> **username_1**: I would add "what is `Message` that is contained in your example?"  

---

## 1 answers

### Answer by username_2 on 2016-10-26. Score: 2 | Accepted answer

> So how we can verify this transaction is valid without having the public-key?

The signature includes the public key corresponding to the private key that made the signature.

> If we attach the public-key with the message then why spending time finding hash of public-key in the first place?

It's not clear what you mean by "the public key". Whose public key are you talking about? Bob's public key isn't in the message.

> Are we storing the public keys in some centralized database?

When a public key is submitted with a signature, the public key is in the transaction. The transaction is included in a block, and that block is part of the blockchain forever.

> If the recipient provides the public-key and verifies the transaction is valid how others can validate that was a valid transaction?

It's not clear what you mean by "that". To validate a transaction, you just have to make sure it's entitled to claim the funds it tries to claim. You don't particularly care what it does with those funds, just that it has the right to decide what to do with them. So you don't need to know much about the recipients -- only enough to identify them when they come to claim their funds. The hash of their public key does that.

> **Comments:**
> **username_3**: "The signature includes the public key ..." I understand, it is the <SCRIPTSIG> of a tx-in? That is, `<SCRIPTSIG>` is composed of signature, "01" (OP_SIGHASHALL) and then the pubkey.  

---

