Skip to content

Commit 7a36d06

Browse files
committed
add support for uncompressed keys
1 parent 8b0106b commit 7a36d06

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ For more information, see [Python API Docs](https://block.io/api/simple/python).
3838

3939
## Windows Users, Please Note:
4040

41-
You can install it like so on Windows: "pip install block-io==1.1.2"
41+
You can install it like so on Windows: "pip install block-io==1.1.3"
4242

4343
Now regarding the vcvarsall.bat error -- that error is due to the fact that pycrypto library is being compiled when you're trying to install the block-io library.
4444

@@ -55,7 +55,7 @@ Once this is done, go to C:\Python3.4\Lib\distutils, and create a file calls "di
5555
compiler=mingw32
5656

5757

58-
Now exit your Command Prompt or Python IDE, go to Command Prompt again, type "pip install block-io==1.1.2".
58+
Now exit your Command Prompt or Python IDE, go to Command Prompt again, type "pip install block-io==1.1.3".
5959

6060

6161
## Contributing

block_io/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ class BlockIo(object):
1818

1919
class Key:
2020

21-
def __init__(self, privkey, pubkey = None):
21+
def __init__(self, privkey, pubkey = None, compressed = True):
2222
self.private_key = SigningKey.from_string(privkey, SECP256k1, sha256)
23-
self.public_key = BlockIo.Helper.compress_pubkey(self.private_key.get_verifying_key().to_string())
23+
24+
if (compressed):
25+
# use the compressed public key
26+
self.public_key = BlockIo.Helper.compress_pubkey(self.private_key.get_verifying_key().to_string())
27+
else:
28+
# use the uncompressed public key
29+
self.public_key = unhexlify('04' + hexlify(self.private_key.get_verifying_key().to_string()))
2430

2531
def sign(self, data_to_sign):
2632
der_sig = self.private_key.sign_digest_deterministic(data_to_sign, sha256, util.sigencode_der_canonize)
@@ -49,6 +55,9 @@ def from_wif(privkey):
4955
# Invalid checksum!
5056
raise Exception("Invalid Private Key provided. Must be in Wallet Import Format.")
5157

58+
# is this a compressed WIF or not?
59+
is_compressed = len(hexlify(extended_key_bytes)) == 68 and hexlify(extended_key_bytes)[-2:] == "01"
60+
5261
# Drop the network bytes
5362
extended_key_bytes = extended_key_bytes[1:]
5463

@@ -57,7 +66,7 @@ def from_wif(privkey):
5766
if (len(private_key) == 33):
5867
private_key = extended_key_bytes[:-1]
5968

60-
return BlockIo.Key(private_key)
69+
return BlockIo.Key(private_key, None, is_compressed)
6170

6271
class Helper:
6372

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup
22

33
setup(name='block-io',
4-
version='1.1.2',
4+
version='1.1.3',
55
description='The easiest way to integrate Bitcoin, Dogecoin and Litecoin in your applications. Sign up at Block.io for your API key.',
66
url='https://github.com/BlockIo/block_io-python',
77
author='Atif Nazir',

0 commit comments

Comments
 (0)