Generate Btc Addr From Private Key
Posted By admin On 14.12.20- import ctypes
- from base58 import encode as base58_encode
- ################################################################################
- ################################################################################
- ssl_library = ctypes.cdll.LoadLibrary('libssl.so')
- def gen_ecdsa_pair():
- NID_secp256k1 =714
- k = ssl_library.EC_KEY_new_by_curve_name(NID_secp256k1)
- if ssl_library.EC_KEY_generate_key(k)!=1:
- bignum_private_key = ssl_library.EC_KEY_get0_private_key(k)
- size =(ssl_library.BN_num_bits(bignum_private_key)+7)//8
- storage = ctypes.create_string_buffer(size)
- ssl_library.BN_bn2bin(bignum_private_key, storage)
- #print('Pubkey size is {} bytes'.format(size))
- ssl_library.i2o_ECPublicKey(k, ctypes.byref(ctypes.pointer(storage)))
- return public_key, private_key
- def ecdsa_get_coordinates(public_key):
- y =bytes(public_key[33:65])
- assertisinstance(public_key,bytes)
- x, y = ecdsa_get_coordinates(public_key)
- s = b'x04' + x + y
- #print('0x04 + x + y:', '.join(['{:02X}'.format(i) for i in s]))
- hasher = hashlib.sha256()
- r = hasher.digest()
- #print('SHA256(0x04 + x + y):', '.join(['{:02X}'.format(i) for i in r]))
- hasher = hashlib.new('ripemd160')
- r = hasher.digest()
- #print('RIPEMD160(SHA256(0x04 + x + y)):', '.join(['{:02X}'.format(i) for i in r]))
- # Since '1' is a zero byte, it won't be present in the output address.
- src =bytes([version]) + src
- hasher.update(src)
- #print('SHA256(0x00 + r):', '.join(['{:02X}'.format(i) for i in r]))
- hasher = hashlib.sha256()
- r = hasher.digest()
- #print('SHA256(SHA256(0x00 + r)):', '.join(['{:02X}'.format(i) for i in r]))
- checksum = r[:4]
- #print('src + checksum:', '.join(['{:02X}'.format(i) for i in s]))
- return base58_encode(int.from_bytes(s,'big'))
- deftest():
- hex_private_key ='.join(['{:02x}'.format(i)for i in private_key])
- print('ECDSA private key (random number / secret exponent) = {}'.format(hex_private_key))
- print('ECDSA public key = {}'.format('.join(['{:02x}'.format(i)for i in public_key])))
- print('Bitcoin private key (Base58Check) = {}'.format(base58_check(private_key, version=128)))
- addr = generate_address(public_key)
- print('Bitcoin Address: {} (length={})'.format(addr,len(addr)))
- 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 versionReleased:
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
andscriptPubKey
). - 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.
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.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size python_bitcoin_tools-0.2.3-py2-none-any.whl (55.0 kB) | File type Wheel | Python version py2 | Upload date | Hashes |
Filename, size python_bitcoin_tools-0.2.3.tar.gz (44.4 kB) | File type Source | Python version None | Upload date | Hashes |
Hashes for python_bitcoin_tools-0.2.3-py2-none-any.whl
Algorithm | Hash digest |
---|---|
SHA256 | c78bc5c0380f565b6c3a7a0c2b9174029159ad86ad335101c88f6679e1d0e504 |
MD5 | d322802d8433db4eff0cf7a6397eb129 |
BLAKE2-256 | 148d7691f016f88847d609ac383a5f986660ea303fc81dd52619d53291025914 |
Hashes for python_bitcoin_tools-0.2.3.tar.gz
Algorithm | Hash digest |
---|---|
SHA256 | c11d8250d4916dae77affb7a72f655903865817b65e7c3731357fdecb31307e5 |
MD5 | 18d1b8f604cfa4af872d9acc4c5abc0c |
BLAKE2-256 | 25dbafc529ec76931bff1ee240c2faa11ea0bd9a6c481e95b2f6a47bc89a94e6 |