Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question on bitcoin address type from privtoaddr #49

Closed
RNBBarrett opened this issue Apr 24, 2023 · 2 comments
Closed

Question on bitcoin address type from privtoaddr #49

RNBBarrett opened this issue Apr 24, 2023 · 2 comments

Comments

@RNBBarrett
Copy link

Hi,

New to the bitcoin world so forgive me. Has a quick question on your library.

I understand there are many different types of bitcoin addresses P2PK, P2PKH, P2MS, P2SH, P2WPKH, P2WSH, P2TR.

I reused this code to make a simple brain wallet tester:

#generate the private key
Private_Key = sha256(myQuote)
b = Bitcoin()
#generate the public key
bitCoinAddress = b.privtoaddr(Private_Key)

Which type of bitcoin address does this result in?

What other methods does your library have for generating other address types?

Just getting started in this so interested in learning.

@primal100
Copy link
Owner

primal100 commented Apr 24, 2023

Hi @RNBBarrett

Yes this aspect of Bitcoin is very confusing.

The methods privtoaddr and pubtoaddr create a Pay-to-Public-Key-Hash (P2PKH) address (e.g. 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa) which is by the far the best most known address type. It's a hash of the public key.

When Bitcoin first started, it was actually all Pay-to-Public-Key (P2PK) where you paid directly to the public key (so just privtopub needed) so the earliest transactions were like this, even though explorers display the addresses in those transactions as a P2PKH address. It's still supported but nobody uses it anymore. P2PKH are easier for humans to deal with.

P2SH addresses which for Bitcoin begin with '3' encode scripts as address and are usually used for multisig. They can be created with mk_multsig_address.

P2SH-P2WPKH are also script addresses beginning with '3' but are used for Segregated Witness, primarily as a way to allow for backward compatibility with pre-segwit Bitcoin versions, but mostly aren't needed anymore. They are created with privtop2wpkh_p2sh and pubtop2w.

P2WPKH and P2WSH are native Segregated Witness addresses and scripts which begin with bc1.

PWPKH are regular native Segwit addresses and are created with privtosegwitaddress and pub_to_segwit_address.

P2WSH would usually be used for segwit multi-sig and are longer than P2WPKH. They can be created with mk_multsig_segwit_address.

Some of the segwit methods are missing from the Sync Coin api but are in the Asnyc Coin interface so are easy to add. I'll try to add them in the next few days.

@primal100
Copy link
Owner

The README has been updated with all functions in PR #54 and version 2.0.8 on Pypi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants