<p>While exact implementations between wallets might differ, the general approach is usually similar to the following:</p>

<ol>
<li>A wallet generates a private key (or a set of keys) based on an HD wallet, or just individual random keys</li>
<li>The public keys for private keys generated in 1. are calculated, and used to create the desired address scripts (p2pkh, p2sh (wrapped segwit/multisig), p2wpkh, p2wsh).</li>
<li>The wallet stores the private key, along with a mapping to which address script uses that key.</li>
<li>The wallet constantly scans the mempool and new blocks for outputs that send Bitcoin to the address scripts calculated in 2. When it discovers such an output, it adds the coins to the wallet balance and informs the user.</li>
</ol>

<p>There are implementation specific variations on this (for example, an HD wallet may not store individual private keys, and store a mapping of the derivation path from the root key and the address script instead).</p>

<p>For an actual example, let's say our wallet has the private key for the address <code>1F1tAaz5x1HUXrCNLbtMDqcw6o5GNn4xqX</code>. The HASH160 for the public key of this address is <code>99bc78ba577a95a11f1a344d4d2ae55f2f857b98</code>, and the locking script is <code>76a91499bc78ba577a95a11f1a344d4d2ae55f2f857b9888ac</code>. This locking script is what appears in the actual bitcoin transaction that sends coins to this address.</p>

<p>The wallet will store the private key, and make a note that the private key corresponds to that locking script. It will then scan the bitcoin blockchain for transactions which have an output that matches that locking script.</p>

CC BY-SA 4.0
2019-10-30T01:09:07.093Z
can any wallet identify that wallets transactions or can only that wallet do this?
Patrick W. McMahon
CC BY-SA 4.0
2019-10-30T01:26:24.183Z
Everyone can see the locking scripts, but determining which locking scripts all belong to the same wallet is non-trivial and is the subject of research. Entire companies exist around trying to figure that out.
Raghav Sood
CC BY-SA 4.0
2019-10-30T01:27:52.273Z
So there's no way of having a private address that other wallets can confirm a transaction came from it?
Patrick W. McMahon
CC BY-SA 4.0
2019-10-30T01:31:36.310Z
Bitcoin has no concept of a private address. The origin and destination of a transaction is always visible. At best, you could attempt to make sure that no one can link a Bitcoin address to you as a person, but that is difficult, and links can be discovered years in the future as new methods are found even if you succeed for the moment
Raghav Sood
CC BY-SA 4.0
2019-10-30T01:33:31.900Z
What if you had a special new transaction and the wallets needed to only accept it as valid if the sender was from a set address without knowing the private address; is this possible?
Patrick W. McMahon
CC BY-SA 4.0
2019-10-30T01:39:56.837Z
That's not how bitcoin works - you cannot chose when to accept Bitcoin. You could build a wallet that hides transactions that come from addresses you don't want, but you cannot prevent the transactions from actually taking place
Raghav Sood
CC BY-SA 4.0
2019-10-30T01:41:37.800Z
What if you added new types of transactions that could only be valid from set sender addresses
Patrick W. McMahon
CC BY-SA 4.0
2019-10-30T01:43:17.563Z
Sure, but that requires a fork of the Bitcoin blockchain, and you'd be hard pressed to get the community to agree to such a drastic measure.
Raghav Sood
CC BY-SA 4.0
2019-10-30T01:04:24.000Z
2019-10-30T01:04:24.000Z
Raghav Sood
<blockquote>
  <p>As the wallet can generate many public addresses from a private address. </p>
</blockquote>

<p>I'm assuming by 'private address', you actually mean 'private key'.</p>

<p>Each private key effectively maps to one Bitcoin address, so for each new address your wallet creates, it will also first create a private key that the address is derived from. If your wallet is a hierarchical deterministic wallet, then it will have a 'master seed', but this seed is then used to derive subsequent private keys (and their corresponding public keys and addresses). </p>

<p>A wallet can watch the network for transactions that create UTXOs which are spendable by a key the wallet controls. How exactly this is accomplished can vary depending on the wallet architecture (full-node vs light wallet, etc). </p>

CC BY-SA 4.0
2019-10-30T09:42:40.127Z
Is there a way for all wallets on the network to determine a let's say special new type of transaction came from a verified list of wallets that are permitted by the network to make a special transaction while invalidating this transaction if coming from wallets not on the list. And at the same time no wallets knowing the private keys of these wallets on the list?
Patrick W. McMahon
CC BY-SA 4.0
2019-10-30T09:49:37.810Z
No, your comment doesn't accurately reflect the way the bitcoin network functions. There is no way to restrict who can send money to a certain address.
chytrik
CC BY-SA 4.0
2019-10-30T03:42:57.267Z
2019-10-30T03:42:57.267Z
chytrik
<p>Public address is a 20Byte data. Private key is a 32Byte data.</p>

<p>They are unequivocal.</p>

CC BY-SA 4.0
2019-10-30T13:23:34.023Z
2019-10-30T13:23:34.023Z
Denis Leonov
<p>As the wallet can generate many public addresses from a private address. How does the wallet know that any transaction from or to the wallet is for that private wallet if the in and out can be any number of public addresses. </p>

<address>
How can the wallet identify public addresses are linked to a private address
Patrick W. McMahon
# How can the wallet identify public addresses are linked to a private address

(Asked by: username_0 on 2019-10-30)

As the wallet can generate many public addresses from a private address. How does the wallet know that any transaction from or to the wallet is for that private wallet if the in and out can be any number of public addresses.

**Tags:** address


---

## 3 answers

### Answer by username_1 on 2019-10-30. Score: 2 | Accepted answer

While exact implementations between wallets might differ, the general approach is usually similar to the following:

1. A wallet generates a private key (or a set of keys) based on an HD wallet, or just individual random keys
2. The public keys for private keys generated in 1. are calculated, and used to create the desired address scripts (p2pkh, p2sh (wrapped segwit/multisig), p2wpkh, p2wsh).
3. The wallet stores the private key, along with a mapping to which address script uses that key.
4. The wallet constantly scans the mempool and new blocks for outputs that send Bitcoin to the address scripts calculated in 2. When it discovers such an output, it adds the coins to the wallet balance and informs the user.

There are implementation specific variations on this (for example, an HD wallet may not store individual private keys, and store a mapping of the derivation path from the root key and the address script instead).

For an actual example, let's say our wallet has the private key for the address `1F1tAaz5x1HUXrCNLbtMDqcw6o5GNn4xqX`. The HASH160 for the public key of this address is `99bc78ba577a95a11f1a344d4d2ae55f2f857b98`, and the locking script is `76a91499bc78ba577a95a11f1a344d4d2ae55f2f857b9888ac`. This locking script is what appears in the actual bitcoin transaction that sends coins to this address.

The wallet will store the private key, and make a note that the private key corresponds to that locking script. It will then scan the bitcoin blockchain for transactions which have an output that matches that locking script.

> **Comments:**
> **username_0**: can any wallet identify that wallets transactions or can only that wallet do this?  
> **username_1**: Everyone can see the locking scripts, but determining which locking scripts all belong to the same wallet is non-trivial and is the subject of research. Entire companies exist around trying to figure that out.  
> **username_0**: So there's no way of having a private address that other wallets can confirm a transaction came from it?  
> **username_1**: Bitcoin has no concept of a private address. The origin and destination of a transaction is always visible. At best, you could attempt to make sure that no one can link a Bitcoin address to you as a person, but that is difficult, and links can be discovered years in the future as new methods are found even if you succeed for the moment  
> **username_0**: What if you had a special new transaction and the wallets needed to only accept it as valid if the sender was from a set address without knowing the private address; is this possible?  
> **username_1**: That's not how bitcoin works - you cannot chose when to accept Bitcoin. You could build a wallet that hides transactions that come from addresses you don't want, but you cannot prevent the transactions from actually taking place  
> **username_0**: What if you added new types of transactions that could only be valid from set sender addresses  
> **username_1**: Sure, but that requires a fork of the Bitcoin blockchain, and you'd be hard pressed to get the community to agree to such a drastic measure.  

---

### Answer by username_2 on 2019-10-30. Score: 0

> As the wallet can generate many public addresses from a private address.

I'm assuming by 'private address', you actually mean 'private key'.

Each private key effectively maps to one Bitcoin address, so for each new address your wallet creates, it will also first create a private key that the address is derived from. If your wallet is a hierarchical deterministic wallet, then it will have a 'master seed', but this seed is then used to derive subsequent private keys (and their corresponding public keys and addresses).

A wallet can watch the network for transactions that create UTXOs which are spendable by a key the wallet controls. How exactly this is accomplished can vary depending on the wallet architecture (full-node vs light wallet, etc).

> **Comments:**
> **username_0**: Is there a way for all wallets on the network to determine a let's say special new type of transaction came from a verified list of wallets that are permitted by the network to make a special transaction while invalidating this transaction if coming from wallets not on the list. And at the same time no wallets knowing the private keys of these wallets on the list?  
> **username_2**: No, your comment doesn't accurately reflect the way the bitcoin network functions. There is no way to restrict who can send money to a certain address.  

---

### Answer by username_3 on 2019-10-30. Score: 0

Public address is a 20Byte data. Private key is a 32Byte data.

They are unequivocal.


---

