stacks-network / pybitcoin Goto Github PK
View Code? Open in Web Editor NEWA Bitcoin python library for private + public keys, addresses, transactions, & RPC
License: MIT License
A Bitcoin python library for private + public keys, addresses, transactions, & RPC
License: MIT License
BitcoinPublicKey("wrong")
result: ValueError: Public key is not in proper format
BitcoinPrivateKey("wrong")
result: AssertionError
Explanation:
Unless there are some reasons why this has been implemented this way, I believe BitcoinPrivateKey
should follow the same behavior of BitcoinPublicKey
.
try/exception of invalid keys should look the same, while (as it is now) different exceptions are being presented.
Reason:
While the file publickey.py
presents a get_public_key_format
function (which handles invalid formats with a ValueError), its counterpart get_privkey_format
in main.py
leaves this job to the function b58check_to_bin
.
Possible solution:
the call to b58check_to_bin
in get_privkey_format
should be wrapped in a try block, the AssertionError
should be caught and a ValueError
should be raised instead.
Impact:
I have not considered the impact of such a change nor possible regressions.
In most wallets, you can derive a new address from a private key. You should be able to get a practically infinite number of addresses from a private key. Is there any parameter similar to this in the library?
>>> from pybitcoin import BitcoinPrivateKey
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/alex/.local/lib/python3.6/site-packages/pybitcoin/__init__.py", line 10, in <module>
import services
ModuleNotFoundError: No module named 'services'
>>> from pybitcoin import BitcoinPrivateKey
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/alex/.local/lib/python3.6/site-packages/pybitcoin/__init__.py", line 10, in <module>
import services
ModuleNotFoundError: No module named 'services'
Ubuntu 14.04
python 2.7.8
pybitcoin==0.8.2
>>> from pybitcoin.rpc import NamecoindClient
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pybitcoin/rpc/__init__.py", line 14, in <module>
from .namecoind_client import NamecoindClient
File "/usr/local/lib/python2.7/dist-packages/pybitcoin/rpc/namecoind_client.py", line 20, in <module>
ssl._create_default_https_context = ssl._create_unverified_context
AttributeError: 'module' object has no attribute '_create_unverified_context'
When I run
python unit_tests.py
I got the following error:
Traceback (most recent call last): File "unit_tests.py", line 38, in <module> from settings import BITCOIND_RPC_PASSWORD, BITCOIND_RPC_USERNAME, \ ImportError: cannot import name BITCOIND_RPC_PASSWORD
I looked into the scripts and it seems fine, how to fix this error? Thank you.
i need to compressed keys for bitcoin and i can not find any method in the documentation to get compressed key from pybitcoin. anyone jst help me, urgent
I have public keys in the form of 2 integers being x,y, in normal integer format. I don't see how to convert that to use public_key.address() or the other commands. public_key.to_hex() seems to be something that would work, but it doesn't specify what format the public_key needs to be in (assuming I'm even knowledgeable enough to convert my x,y coordinates into what it requires). Am I merely ignorant about the existence of this feature, or am I asking for it to be added? Idk
Upon trying to import and use any of the coinkit functionality, I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "coinkit/__init__.py", line 14, in <module>
from .b58check import b58check_encode, b58check_decode, b58check_unpack, \
File "coinkit/b58check.py", line 14, in <module>
from characters.charset import change_charset
ImportError: No module named characters.charset
I haven't been able to identify a package to install that contains this module. Any help would be appreciated.
I am running CrunchBang Linux (a Debian derivative).
Hi,
I am using BitcoinKeypair to generated address for new users in my bitcoin exchange ( https://github.com/pinhopro/bitex )
but when I try to get information from the new address created I get this message from blockchain:
"No free outputs to spend"
$ cat test.py
from coinkit.keypair import BitcoinKeypair
keypair = BitcoinKeypair()
$ python2.7 test.py
1Dw8sfTPJRf389sfD4ejqs5uQVCNWJU7aw
$ curl http://blockchain.info/unspent?address=1Dw8sfTPJRf389sfD4ejqs5uQVCNWJU7aw
FeathercoinPrivateKey('e2ee135cc175081810bbaa603df551f657c8e8a37aca1321883fc588022f95d6').public_key().to_hex()
the result: 04edb297ba63c35998ec23cfca60666bb4d0d1c3e810b93d2d20c94e3a129774407b719ecf902de8a20c6d99ed0ad0d8c5af178640fdcb0c5dee26c41d39306998
This length is 130.
CPubKey vchPubKey;
pwalletMain->GetPubKey(keyID, vchPubKey)
LogPrintf("addressbookpage vchPubKey=%s\n", HexStr(vchPubKey).c_str());
the result:
02edb297ba63c35998ec23cfca60666bb4d0d1c3e810b93d2d20c94e3a12977440
This length is 65.
secp256k1 tell me , PUBLIC_KEY_SIZE = 65
Why your public key size is 130 ? How to make it with Qt wallet code ?
When I import a coinkit lib, i have found this issue ...
(from pip install coinkit in debian 7)
Traceback (most recent call last):
File "bbb.py", line 8, in
from lib.wallet import Wallet
File "/home/mat/_/_/***.py", line 1, in
from coinkit import BitcoinKeypair
File "/usr/local/lib/python2.7/dist-packages/coinkit/init.py", line 12, in
from .b58check import b58check_encode, b58check_decode, b58check_unpack,
File "/usr/local/lib/python2.7/dist-packages/coinkit/b58check.py", line 14, in
from characters.charset import change_charset
ImportError: No module named characters.charset
What else ? :)
pip install pybitcoin is broken by pip install bitcoin
I installed this on in the latest python for windows. I installed the coinkit and characters modules. I then attempted to utilize the simple walkthroughs in the readme and they throw an error on almost every method. Here is an example of the type of errors I am getting:
>>> from coinkit import NamecoinKeypair
>>> keypair = NamecoinKeypair()
>>> keypair.private_key()
b'0f1a40850d0e53164314111b24161d2dc4a90d843fcaa85944af54d64162b2ca'
>>> keypair.publickey()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NamecoinKeypair' object has no attribute 'publickey'
>>> keypair.public_key()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\yousir\Desktop\coinkit-master\coinkit\keypair.py", line 102, in
public_key
return binascii.hexlify(self._bin_public_key())
File "C:\Users\yousir\Desktop\coinkit-master\coinkit\keypair.py", line 82, in
_bin_public_key
return '\x04' + self._ecdsa_public_key.to_string()
TypeError: Can't convert 'bytes' object to str implicitly
hello, I am trying to install this, so I can
from pybitcoin import BitcoinPrivateKey
I am on Mac. Can someone tell me how to install it? thanks
In an effort to better wrangle Blockstack's packages, especially in light of interfacing with multiple blockchains, I propose doing the following:
blockstack-virtualchain would also subsume blockstack-utxo.
This will allow us to run Blockstack Server on testnet.
BTC address: '1DcKRUKGKt5bwi3mtFNNEuufp6DFxEBR9C'
Private Key: 'fb8c80c0d5af5c14e3b19265bf4c1fef00a457933b2022d145694a541549acaf'
I have a private key and I want to get the BTC address, this is what I do:
from pybitcoin import BitcoinPrivateKey
private_key = BitcoinPrivateKey('fb8c80c0d5af5c14e3b19265bf4c1fef00a457933b2022d145694a541549acaf')
private_key.public_key().address()
output: '1DBkszCUoFuXEJE1ynbteVLYZcuUjjKChS'
what I am doing wrong?
I have successfully run the setup.py however when I try to run wallet.py
I received the following error:
: line 8: $'\n pybitcoin\n ~~~~~\n\n ©️ (c) 2014 by Halfmoon Labs\n :license: MIT, see LICENSE for more details.\n': command not found
from: can't read /var/mail/inspect
from: can't read /var/mail/.keypair
from: can't read /var/mail/.passphrases
./wallet.py: line 16: syntax error near unexpected token (' ./wallet.py: line 16:
def is_cryptocurrency_keypair_class(cls):'
_pubkeyhash_version_byte = 52 in NamecoinPrivateKey
_pubkeyhash_version_byte = 48 in LitecoinPrivateKey
I hope to add Feathercoin, How to find its value?
_pubkeyhash_version_byte = ?? in FeathercoinPrivateKey
get_unspents("19SbDasdasdNEkwRqnBAv7Ewumy7XcCau9Wp4BH9")
Expected behavior:
result: [ ]
Actual behavior:
result: Exception('Invalid response from blockchain.info.')
Reson:
blockchain.info returns non-JSON response "No free outputs to spend" if the address is valid but with no unspents. The file "blockchain_info.py" (at lines 49 to 53) doesn't check for non-JSON responses but blatantly returns error if it cannot parse JSON content.
Proposed fix:
at line 50:
if r.content == "No free outputs to spend": return [ ]
in serialize_sign_and_broadcast() in transactions/network.py, sign_transaction() is only called on the first input (index 0):
def serialize_sign_and_broadcast(inputs, outputs, private_key,
blockchain_client=BlockchainInfoClient()):
# extract the private key object
private_key_obj = get_private_key_obj(private_key)
# serialize the transaction
unsigned_tx = serialize_transaction(inputs, outputs)
# sign the unsigned transaction with the private key
signed_tx = sign_transaction(unsigned_tx, 0, private_key_obj.to_hex())
# dispatch the signed transction to the network
response = broadcast_transaction(signed_tx, blockchain_client)
# return the response
return response
therefore transactions that require multiple inputs become invalid
Encountered the pubkey bug and had to upgrade, got a couple of import errors.
In keypair.py: from .hash160 import bin_hash160
In network.py: from ..services import blockchain_info, blockcypher_com, chain_com
List is accessed using round brackets
Passing in an address and getting back the coin type and if it is test or main net.
This does not work:
i = int('0140faf3bac00007fb24bfb2c9cd55dd15de5b892c06317c6cacedbd6a25f802', 16)
key = BitcoinPrivateKey(private_key=i)
The is_int function from utilitybelt only checks for isinstance(value, int)
it should instead check for isinstance(value, (int, long))
Hi, i have an issue generating a bitcoin address with custom secret exponent, i tried with keypair = BitcoinKeypair.secret_exponent("1")
or
x = 1
keypair = BitcoinKeypair.secret_exponent(x)
i got the following error TypeError: unbound method secret_exponent() must be called with BitcoinKeypair instance as first argument (got str instance instead)
Anyone can help me please?
Thank you
Is it safe to use /dev/urandom in random_secrect_exponent
? It provides much more data than /dev/random. The problem is I need to generate 50 wallets at one time and /dev/random is too slow for that.
I can make pull request that adds new option to BitcoinPrivateKey
constructor to allow to use /dev/urandom instead of default /dev/random.
Python 3.5.2 (default, Jul 17 2016, 00:00:00)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pybitcoin import LitecoinPrivateKey
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<...>/site-packages/pybitcoin/__init__.py", line 10, in <module>
import services
ImportError: No module named 'services'
See: https://www.python.org/dev/peps/pep-0328/#rationale-for-absolute-imports
I want to use this library to make op_return transactions and add recepient address and an ammount, but as I see there is no way to do it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.