<p>This depends largely on which type of address you want to generate. First, you will need to encode your public key into compressed form. This is done by taking the x-coordinate, and prepending <code>0x02</code> if the y-coordinate is even, or <code>0x03</code> if the y-coordinate is odd.</p>
<p>A legacy P2PKH address (starting with a <code>1</code>) is generated by the following process:</p>
<ol>
<li>Taking the compressed form of your public key.</li>
<li>Hash it with SHA-256 and then hash the resulting 256-bit hash with RIPEMD-160 to get a 160-bit hash value. Call this result <code>hash</code>.</li>
<li>Prepend the version byte (<code>0x00</code> for Bitcoin mainnet - this gives the 1 at the start of the address). So we have <code>version || hash</code>.</li>
<li>Hash <code>version || hash</code> twice with SHA-256 and take the first four bytes of the result as a checksum.</li>
<li>Encode <code>version || hash || checksum</code> in <a href="https://en.bitcoin.it/wiki/Base58Check_encoding" rel="nofollow noreferrer">Bitcoin's Base58 encoding
format</a>.</li>
</ol>
<p>This is described on the bitcoin wiki <a href="https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses" rel="nofollow noreferrer">here</a>.</p>
<p>If you want to create a P2WPKH Bech32 address (starting with <code>bc1</code>), the process is simpler. The witness version is <code>0x00</code> and the witness program is a push of the <code>RIPEMD-160(SHA-256(compressed public key))</code> hash. To push a 20-byte hash like this, we use <code>0x14</code> (which is 20 in hex). So the total scriptPubKey is <code>0x0014{20-byte hash}</code> (as described in <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#P2WPKH" rel="nofollow noreferrer">BIP-141</a>). You then simply encode this scriptPubKey using Bech32 encoding as defined in <a href="https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki" rel="nofollow noreferrer">BIP-173</a>.</p>
<p>There are other types of address too, of course, including P2SH, P2WSH, and P2TR (as well as P2SH wrapped segwit v0 addresses). These all deal with scripts too though, rather than just single keys.</p>

CC BY-SA 4.0
2021-12-15T00:28:47.227Z
2021-12-15T00:28:47.227Z
meshcollider
<p>I have my x (0xca668a8b5f71e8724aada4b5343c28702a481787855cc42228b8fff97fe94d6a) and y (0x19dd3a603a55b3d8c5f62cbe177b9b63693fb8c91d76845bafc843a7aa19ea55) coordinates generated by ecdsa with a private key. But don't know yet how to get the public address from (x,y) coordinates and a compressed bitcoin address ?</p>

<cryptography><ecdsa>
How to get public key and bitcoin compressed address from the coordinates (x,y) generated by ECDSA?
harsh
# How to get public key and bitcoin compressed address from the coordinates (x,y) generated by ECDSA?

(Asked by: username_0 on 2021-12-14)

I have my x (0xca668a8b5f71e8724aada4b5343c28702a481787855cc42228b8fff97fe94d6a) and y (0x19dd3a603a55b3d8c5f62cbe177b9b63693fb8c91d76845bafc843a7aa19ea55) coordinates generated by ecdsa with a private key. But don't know yet how to get the public address from (x,y) coordinates and a compressed bitcoin address ?

**Tags:** cryptography, ecdsa


---

## 1 answers

### Answer by username_1 on 2021-12-15. Score: 3

This depends largely on which type of address you want to generate. First, you will need to encode your public key into compressed form. This is done by taking the x-coordinate, and prepending `0x02` if the y-coordinate is even, or `0x03` if the y-coordinate is odd.

A legacy P2PKH address (starting with a `1`) is generated by the following process:

1. Taking the compressed form of your public key.
2. Hash it with SHA-256 and then hash the resulting 256-bit hash with RIPEMD-160 to get a 160-bit hash value. Call this result `hash`.
3. Prepend the version byte (`0x00` for Bitcoin mainnet - this gives the 1 at the start of the address). So we have `version || hash`.
4. Hash `version || hash` twice with SHA-256 and take the first four bytes of the result as a checksum.
5. Encode `version || hash || checksum` in [Bitcoin's Base58 encoding
   format](https://en.bitcoin.it/wiki/Base58Check_encoding).

This is described on the bitcoin wiki [here](https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses).

If you want to create a P2WPKH Bech32 address (starting with `bc1`), the process is simpler. The witness version is `0x00` and the witness program is a push of the `RIPEMD-160(SHA-256(compressed public key))` hash. To push a 20-byte hash like this, we use `0x14` (which is 20 in hex). So the total scriptPubKey is `0x0014{20-byte hash}` (as described in [BIP-141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#P2WPKH)). You then simply encode this scriptPubKey using Bech32 encoding as defined in [BIP-173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki).

There are other types of address too, of course, including P2SH, P2WSH, and P2TR (as well as P2SH wrapped segwit v0 addresses). These all deal with scripts too though, rather than just single keys.


---

