Generate Btc Addr From Private Key

Posted By admin On 14.12.20
  1. import ctypes
  2. from base58 import encode as base58_encode
  3. ################################################################################
  4. ################################################################################
  5. ssl_library = ctypes.cdll.LoadLibrary('libssl.so')
  6. def gen_ecdsa_pair():
  7. NID_secp256k1 =714
  8. k = ssl_library.EC_KEY_new_by_curve_name(NID_secp256k1)
  9. if ssl_library.EC_KEY_generate_key(k)!=1:
  10. bignum_private_key = ssl_library.EC_KEY_get0_private_key(k)
  11. size =(ssl_library.BN_num_bits(bignum_private_key)+7)//8
  12. storage = ctypes.create_string_buffer(size)
  13. ssl_library.BN_bn2bin(bignum_private_key, storage)
  14. #print('Pubkey size is {} bytes'.format(size))
  15. ssl_library.i2o_ECPublicKey(k, ctypes.byref(ctypes.pointer(storage)))
  16. return public_key, private_key
  17. def ecdsa_get_coordinates(public_key):
  18. y =bytes(public_key[33:65])
  19. assertisinstance(public_key,bytes)
  20. x, y = ecdsa_get_coordinates(public_key)
  21. s = b'x04' + x + y
  22. #print('0x04 + x + y:', '.join(['{:02X}'.format(i) for i in s]))
  23. hasher = hashlib.sha256()
  24. r = hasher.digest()
  25. #print('SHA256(0x04 + x + y):', '.join(['{:02X}'.format(i) for i in r]))
  26. hasher = hashlib.new('ripemd160')
  27. r = hasher.digest()
  28. #print('RIPEMD160(SHA256(0x04 + x + y)):', '.join(['{:02X}'.format(i) for i in r]))
  29. # Since '1' is a zero byte, it won't be present in the output address.
  30. src =bytes([version]) + src
  31. hasher.update(src)
  32. #print('SHA256(0x00 + r):', '.join(['{:02X}'.format(i) for i in r]))
  33. hasher = hashlib.sha256()
  34. r = hasher.digest()
  35. #print('SHA256(SHA256(0x00 + r)):', '.join(['{:02X}'.format(i) for i in r]))
  36. checksum = r[:4]
  37. #print('src + checksum:', '.join(['{:02X}'.format(i) for i in s]))
  38. return base58_encode(int.from_bytes(s,'big'))
  39. deftest():
  40. hex_private_key ='.join(['{:02x}'.format(i)for i in private_key])
  41. print('ECDSA private key (random number / secret exponent) = {}'.format(hex_private_key))
  42. print('ECDSA public key = {}'.format('.join(['{:02x}'.format(i)for i in public_key])))
  43. print('Bitcoin private key (Base58Check) = {}'.format(base58_check(private_key, version=128)))
  44. addr = generate_address(public_key)
  45. print('Bitcoin Address: {} (length={})'.format(addr,len(addr)))
  46. if __name__ '__main__':

Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more Create Bitcoin-Address in PHP. Whether two private keys can generate the same public key is another question. I think the answer is yes, but I am not sure on that. The public key in uncompressed form consists of two 256-bit numbers, which are X and Y coordinates on an elliptic curve. From a private key to a public key. As Wikipedia tells us a ECDSA private key is just the scalar product of a private key (the secret exponent) and the curve – secp256k1 for Bitcoin – base point. How to do that is complex, but let’s just take it for granted, as you’ll either use a librarty for this or research further by yourself.

Latest version

Released:

Python library created for teaching and researching purposes.

Project description

Generate Public Address From Private Key Bitcoin

bitcoin_tools is a Python library created for teaching and researching purposes. It's main objective is twofold. First itaims to ease the understanding of Bitcoin transaction creation, by using well-documented and easy to understandpython code. Second, it aims to provide a tool able to create custom transactions / scripts. Either scriptSig andscriptPubKey can be built from human readable strings created using Script syntax. Finally, tools for accessing andanalysing interesting data such as the utxo set are also provided, along with several examples.

Generate Btc Addr From Private Keyboard

bitcoin_tools allows you to:

  • Bitcoin keys creation and management.
  • Creation of Bitcoin transactions from scratch.
  • Customize any field of your transaction.
  • Transaction serialization / deserialization.
  • Creation of standard and custom scripts (scriptSig and scriptPubKey).
  • Transaction analysis from hex encoded transactions.

Additionally, bitcoin_tools contains STATUS anSTatistical Analysis Tool for Utxo Set under analysis/status

Dependencies

Refer to DEPENCENCIES.md

Installation

Refer to INSTALL.md

Some trouble getting started with the repo?

Refer to FAQ.md

Still not working?

Feel free to open an issue.

Addr

Examples

Down below you can find some examples of how to use some of the library functions. More examples can be found inexamples/

Key management and Bitcoin address generation

Raw transaction building

Raw tx analysis

Using STATUS to dump the UTXOs LevelDB

Support

If you find this repository useful, show us some love, give us a star!

Small Bitcoin donations to the following address are also welcome:

Disclaimer

This library allow you to modify any transaction field as you pleased. However, some modifications can make yourtransactions non-standard, or even non-spendable. We totally discourage the use of the library outside the testnet ifyou are not sure about what you are doing, specially when dealing with non-standard scripts. A bad use of the librarycan lead you to lose some of your bitcoins.

Release historyRelease notifications

0.2.3 Bitbucket generate ssh key ubuntu.

0.2.2 Service primary key avoid auto generate.

0.2.1

0.2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for python-bitcoin-tools, version 0.2.3
Filename, sizeFile typePython versionUpload dateHashes
Filename, size python_bitcoin_tools-0.2.3-py2-none-any.whl (55.0 kB) File type Wheel Python version py2 Upload dateHashes
Filename, size python_bitcoin_tools-0.2.3.tar.gz (44.4 kB) File type Source Python version None Upload dateHashes
Close

Hashes for python_bitcoin_tools-0.2.3-py2-none-any.whl

Hashes for python_bitcoin_tools-0.2.3-py2-none-any.whl
AlgorithmHash digest
SHA256c78bc5c0380f565b6c3a7a0c2b9174029159ad86ad335101c88f6679e1d0e504
MD5d322802d8433db4eff0cf7a6397eb129
BLAKE2-256148d7691f016f88847d609ac383a5f986660ea303fc81dd52619d53291025914
Close

Hashes for python_bitcoin_tools-0.2.3.tar.gz

Hashes for python_bitcoin_tools-0.2.3.tar.gz
AlgorithmHash digest
SHA256c11d8250d4916dae77affb7a72f655903865817b65e7c3731357fdecb31307e5
MD518d1b8f604cfa4af872d9acc4c5abc0c
BLAKE2-25625dbafc529ec76931bff1ee240c2faa11ea0bd9a6c481e95b2f6a47bc89a94e6