Cleanup and update

This commit is contained in:
Michał Sałaban 2019-01-03 18:03:33 +00:00
parent d0a2d35176
commit d9c68a86c6
5 changed files with 30 additions and 22 deletions

View File

@ -1,12 +1,18 @@
from binascii import hexlify, unhexlify
import re
import struct
from sha3 import keccak_256
import struct
import sys
from . import base58
from . import ed25519
from . import numbers
if sys.version_info < (3,): # pragma: no cover
_str_types = (str, bytes, unicode)
else: # pragma: no cover
_str_types = (str, bytes)
_ADDR_REGEX = re.compile(r'^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{95}$')
_IADDR_REGEX = re.compile(r'^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{106}$')
@ -58,7 +64,7 @@ class BaseAddress(object):
def __eq__(self, other):
if isinstance(other, BaseAddress):
return str(self) == str(other)
if isinstance(other, str):
if isinstance(other, _str_types):
return str(self) == other
return super(BaseAddress, self).__eq__(other)

View File

@ -9,7 +9,7 @@ import operator as _oper
import sys as _sys
# Set up byte handling for Python 2 or 3
if _sys.version_info.major == 2:
if _sys.version_info.major == 2: # pragma: no cover
int2byte = chr
range = xrange
@ -18,7 +18,7 @@ if _sys.version_info.major == 2:
def intlist2bytes(l):
return b"".join(chr(c) for c in l)
else:
else: # pragma: no cover
indexbytes = _oper.getitem
intlist2bytes = bytes
int2byte = _oper.methodcaller("to_bytes", 1, "big")
@ -27,9 +27,6 @@ b = 256
q = 2**255 - 19
l = 2**252 + 27742317777372353535851937790883648493
def H(m):
return hashlib.sha512(m).digest()
def expmod(b, e, m):
if e == 0: return 1
t = expmod(b, e//2, m)**2 % m
@ -103,16 +100,6 @@ def encodepoint(P):
def bit(h, i):
return (indexbytes(h, i//8) >> (i%8)) & 1
def publickey(sk):
h = H(sk)
a = 2**(b-2) + sum(2**i * bit(h, i) for i in range(3, b-2))
A = scalarmult(B, a)
return encodepoint(A)
def Hint(m):
h = H(m)
return sum(2**i * bit(h, i) for i in range(2*b))
def isoncurve(P):
x = P[0]
y = P[1]
@ -130,6 +117,19 @@ def decodepoint(s):
return P
# These are unused but let's keep them
#def H(m):
# return hashlib.sha512(m).digest()
#
#def Hint(m):
# h = H(m)
# return sum(2**i * bit(h, i) for i in range(2*b))
#
#def publickey(sk):
# h = H(sk)
# a = 2**(b-2) + sum(2**i * bit(h, i) for i in range(3, b-2))
# A = scalarmult(B, a)
# return encodepoint(A)
#
#def signature(m, sk, pk):
# h = H(sk)
# a = 2**(b-2) + sum(2**i * bit(h, i) for i in range(3, b-2))

View File

@ -3,10 +3,10 @@ import sys
PICONERO = Decimal('0.000000000001')
if sys.version_info < (3,):
if sys.version_info < (3,): # pragma: no cover
_integer_types = (int, long,)
_str_types = (str, bytes, unicode)
else:
else: # pragma: no cover
_integer_types = (int,)
_str_types = (str, bytes)

View File

@ -86,9 +86,9 @@ class Transaction(object):
return self.hash
if sys.version_info < (3,):
if sys.version_info < (3,): # pragma: no cover
_str_types = (str, bytes, unicode)
else:
else: # pragma: no cover
_str_types = (str, bytes)

View File

@ -42,13 +42,15 @@ setup(
author_email = 'michal@salaban.info',
license = 'BSD-3-Clause',
classifiers = [
'Development Status :: 2 - Pre-Alpha',
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Software Development :: Libraries :: Python Modules',
],
keywords = 'monero cryptocurrency',
test_suite='tests',