Merge pull request #6 from jaicis/py3convert
Solved encode-decode, pack-unpack, new address creation issues
This commit is contained in:
commit
907479801f
15
python3_requirements.txt
Normal file
15
python3_requirements.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
certifi==2019.9.11
|
||||
chardet==3.0.4
|
||||
docutils==0.15.2
|
||||
idna==2.8
|
||||
Kivy==1.11.1
|
||||
Kivy-Garden==0.1.4
|
||||
kivymd==0.100.2
|
||||
Pillow==6.1.0
|
||||
pkg-resources==0.0.0
|
||||
pydenticon==0.3.1
|
||||
Pygments==2.4.2
|
||||
qrcode==6.1
|
||||
requests==2.22.0
|
||||
six==1.12.0
|
||||
urllib3==1.25.6
|
|
@ -157,13 +157,13 @@ class addressGenerator(StoppableThread):
|
|||
# An excellent way for us to store our keys
|
||||
# is in Wallet Import Format. Let us convert now.
|
||||
# https://en.bitcoin.it/wiki/Wallet_import_format
|
||||
privSigningKey = '\x80'.encode('utf-8') + potentialPrivSigningKey
|
||||
privSigningKey = '\x80'.encode('utf-8')[1:] + potentialPrivSigningKey
|
||||
checksum = hashlib.sha256(hashlib.sha256(
|
||||
privSigningKey).digest()).digest()[0:4]
|
||||
privSigningKeyWIF = arithmetic.changebase(
|
||||
privSigningKey + checksum, 256, 58)
|
||||
|
||||
privEncryptionKey = '\x80'.encode('utf-8') + potentialPrivEncryptionKey
|
||||
privEncryptionKey = '\x80'.encode('utf-8')[1:] + potentialPrivEncryptionKey
|
||||
checksum = hashlib.sha256(hashlib.sha256(
|
||||
privEncryptionKey).digest()).digest()[0:4]
|
||||
privEncryptionKeyWIF = arithmetic.changebase(
|
||||
|
|
|
@ -15,8 +15,8 @@ def makeCryptor(privkey):
|
|||
"""Return a private pyelliptic.ECC() instance"""
|
||||
private_key = a.changebase(privkey, 16, 256, minlen=32)
|
||||
public_key = pointMult(private_key)
|
||||
privkey_bin = '\x02\xca\x00\x20'.encode('utf-8') + private_key
|
||||
pubkey_bin = '\x02\xca\x00\x20'.encode('utf-8') + public_key[1:-32] + '\x00\x20'.encode('utf-8') + public_key[-32:]
|
||||
privkey_bin = '\x02\xca\x00\x20'.encode('raw_unicode_escape') + private_key
|
||||
pubkey_bin = '\x02\xca\x00\x20'.encode('raw_unicode_escape') + public_key[1:-32] + '\x00\x20'.encode('utf-8') + public_key[-32:]
|
||||
cryptor = pyelliptic.ECC(curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin)
|
||||
return cryptor
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# pylint: disable=missing-docstring,too-many-function-args
|
||||
0# pylint: disable=missing-docstring,too-many-function-args
|
||||
|
||||
import hashlib
|
||||
import re
|
||||
|
@ -26,33 +26,27 @@ def get_code_string(base):
|
|||
elif base == 10:
|
||||
return '0123456789'
|
||||
elif base == 16:
|
||||
return "0123456789abcdef"
|
||||
return ("0123456789abcdef").encode()
|
||||
elif base == 58:
|
||||
return "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
||||
elif base == 256:
|
||||
'''raw_unicode_escape is used because in the python3 after range(161) its genreate the'
|
||||
the speical character so avoiding that function we have used the raw_unicode method '''
|
||||
return ''.join([chr(x) for x in range(256)]).encode('raw_unicode_escape')
|
||||
return bytes(range(0, 256))
|
||||
else:
|
||||
raise ValueError("Invalid base!")
|
||||
|
||||
|
||||
def encode(val, base, minlen=0):
|
||||
code_string = get_code_string(base)
|
||||
result = ''
|
||||
# result = str.encode(result)
|
||||
count = 0
|
||||
result = str.encode('') if type(code_string) == bytes else ''
|
||||
while val > 0:
|
||||
count += 1
|
||||
print(f'code_string[int(val) % base:int(val) % base + 1] -{code_string[int(val) % base:int(val) % base + 1]}')
|
||||
print(f'result-{result}')
|
||||
result = code_string[int(val) % base:int(val) % base + 1] + result
|
||||
val = int(val / base)
|
||||
result = code_string[val % base:val % base + 1] + result
|
||||
val = val // base
|
||||
if len(result) < minlen:
|
||||
result = code_string[0] * (minlen - len(result)) + result
|
||||
return result
|
||||
|
||||
|
||||
def decode(string, base):
|
||||
code_string = get_code_string(base)
|
||||
result = 0
|
||||
|
@ -60,7 +54,7 @@ def decode(string, base):
|
|||
string = string.lower()
|
||||
while string:
|
||||
result *= base
|
||||
result += code_string.find(string[0])
|
||||
result += code_string.find(string[0:1])
|
||||
string = string[1:]
|
||||
return result
|
||||
|
||||
|
|
|
@ -64,7 +64,6 @@ class ECC(object):
|
|||
self.curve = OpenSSL.get_curve(curve)
|
||||
else:
|
||||
self.curve = curve
|
||||
|
||||
if pubkey_x is not None and pubkey_y is not None:
|
||||
self._set_keys(pubkey_x, pubkey_y, raw_privkey)
|
||||
elif pubkey is not None:
|
||||
|
@ -137,19 +136,18 @@ class ECC(object):
|
|||
i += 2
|
||||
pubkey_x = pubkey[i:i + tmplen]
|
||||
i += tmplen
|
||||
i += int(tmplen / 3)
|
||||
tmplen = unpack('!H', pubkey[i:i + 2])[0]
|
||||
i += 2
|
||||
pubkey_y = pubkey[i:i + tmplen]
|
||||
i += tmplen
|
||||
return curve, pubkey_x, pubkey_y, int(i)
|
||||
return curve, pubkey_x, pubkey_y, i
|
||||
|
||||
@staticmethod
|
||||
def _decode_privkey(privkey):
|
||||
i = 0
|
||||
curve = unpack('!H', privkey[i:i + 2])[0]
|
||||
i += 2
|
||||
tmplen = pack('!s', privkey[i:i + 1])[0]
|
||||
tmplen = unpack('!H', privkey[i:i + 2])[0]
|
||||
i += 2
|
||||
privkey = privkey[i:i + tmplen]
|
||||
i += tmplen
|
||||
|
@ -297,7 +295,6 @@ class ECC(object):
|
|||
if (OpenSSL.EC_KEY_set_private_key(key, priv_key)) == 0:
|
||||
raise Exception(
|
||||
"[OpenSSL] EC_KEY_set_private_key FAIL ...")
|
||||
|
||||
group = OpenSSL.EC_KEY_get0_group(key)
|
||||
pub_key = OpenSSL.EC_POINT_new(group)
|
||||
|
||||
|
|
|
@ -674,13 +674,12 @@ def loadOpenSSL():
|
|||
elif 'win32' in sys.platform or 'win64' in sys.platform:
|
||||
libdir.append(path.join(sys._MEIPASS, 'libeay32.dll'))
|
||||
else:
|
||||
|
||||
libdir.extend([
|
||||
path.join(sys._MEIPASS, 'libcrypto.so'),
|
||||
path.join(sys._MEIPASS, 'libssl.so'),
|
||||
path.join(sys._MEIPASS, 'libcrypto.so.1.1.0'),
|
||||
path.join(sys._MEIPASS, 'libssl.so.1.1.0'),
|
||||
path.join(sys._MEIPASS, 'libcrypto.so.1.0.2'),
|
||||
path.join(sys._MEIPASS, 'libcrypto.so.1.0.2'),
|
||||
path.join(sys._MEIPASS, 'libssl.so.1.0.2'),
|
||||
path.join(sys._MEIPASS, 'libcrypto.so.1.0.1'),
|
||||
path.join(sys._MEIPASS, 'libssl.so.1.0.1'),
|
||||
|
@ -703,6 +702,7 @@ def loadOpenSSL():
|
|||
libdir.append('libssl.so')
|
||||
libdir.append('libcrypto.so.1.0.0')
|
||||
libdir.append('libssl.so.1.0.0')
|
||||
libdir.append('libcrypto.so.1.0.2')
|
||||
if 'linux' in sys.platform or 'darwin' in sys.platform or 'bsd' in sys.platform:
|
||||
try:
|
||||
libdir.append(find_library('ssl'))
|
||||
|
|
|
@ -89,27 +89,23 @@ def isAddressInMyAddressBookSubscriptionsListOrWhitelist(address):
|
|||
return True
|
||||
return False
|
||||
|
||||
|
||||
def decodeWalletImportFormat(WIFstring):
|
||||
fullString = arithmetic.changebase(WIFstring, 58, 256)
|
||||
privkey = fullString[:-4]
|
||||
if fullString[-4:] != \
|
||||
hashlib.sha256(hashlib.sha256(privkey).digest()).digest()[:4]:
|
||||
if fullString[-4:] != hashlib.sha256(hashlib.sha256(privkey).digest()).digest()[:4]:
|
||||
logger.critical(
|
||||
'Major problem! When trying to decode one of your'
|
||||
' private keys, the checksum failed. Here are the first'
|
||||
' 6 characters of the PRIVATE key: %s',
|
||||
str(WIFstring)[:6]
|
||||
' 6 characters of the PRIVATE key: {}'.format(str(WIFstring)[:6])
|
||||
)
|
||||
os._exit(0)
|
||||
# return ""
|
||||
elif privkey[0] == '\x80': # checksum passed
|
||||
if privkey[0:1] == '\x80'.encode()[1:]: # checksum passed
|
||||
return privkey[1:]
|
||||
|
||||
logger.critical(
|
||||
'Major problem! When trying to decode one of your private keys,'
|
||||
' the checksum passed but the key doesn\'t begin with hex 80.'
|
||||
' Here is the PRIVATE key: %s', WIFstring
|
||||
' Here is the PRIVATE key: {}'.format(WIFstring)
|
||||
)
|
||||
os._exit(0)
|
||||
|
||||
|
|
Reference in New Issue
Block a user