2

These public keys are easy enough for anyone to obtain from a Bitcoin address.

Source: https://youtu.be/h7baD335hCw?t=598

... What? Aren't the receive addresses in fact the "public keys"?

1
  • 1
    Adress are the hash of public keys. Payment can be made to public keys too. Jan 25, 2021 at 0:41

1 Answer 1

6

No. There are multiple kinds of addresses in common use:

A Pay to Public Key Hash (P2PKH) address, beginning with a 1... uses a Hash160 (Sha256 followed by RipeMD160) of the public key. The public key is not revealed until this output is spent, as the spending transaction will include the public key in its scriptSig.

A Pay to Script Hash (P2SH) address, beginning with a 3... uses the Hash160 of the redeemScript, which is not part of the scriptPubKey. The redeemScript is part of the scriptSig which spends the output.

The hashes of the above two are then encoded using Base58Check to generate the address.

There are also Pay to Witness Public Key Hash (P2WPKH) and Pay to Witness Script Hash (P2WSH) versions, which are for post-segwit transactions where the witness is a separate part of the spending transaction. These both begin with bc1..., with the difference between the two being the length of the hash. These are both encoded using the bech32 encoding to give the final address. The publicKey again, is part of the spending transaction, but is instead included in the extra witness field rather than the scriptSig.

There does exist a legacy P2PK (Pay to Public Key) output type, but this is seldom used. In this, the public key was included directly in the scriptPubKey.

In the others besides P2PK, the public key is not revealed until an output is spent. There is no way to know a public key from the hash alone, as the hash is a one-way function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.