minor cleanups
This commit is contained in:
parent
b001c1a792
commit
5b02ceb87c
6 changed files with 30 additions and 24 deletions
|
|
@ -62,14 +62,14 @@ class backend:
|
|||
0x02 depending on whether they're greater or less than the midpoint of the curve.
|
||||
"""
|
||||
def privnum2pubkey(numpriv,compressed=False):
|
||||
pko = self.ecdsa.SigningKey.from_secret_exponent(numpriv,curve=self.ecdsa.SECP256k1)
|
||||
# pubkey = x (32 bytes) + y (32 bytes) (unsigned big-endian)
|
||||
pubkey = pko.get_verifying_key().to_string()
|
||||
pk = self.ecdsa.SigningKey.from_secret_exponent(numpriv,curve=self.ecdsa.SECP256k1)
|
||||
# vk_bytes = x (32 bytes) + y (32 bytes) (unsigned big-endian)
|
||||
vk_bytes = pk.verifying_key.to_string()
|
||||
if compressed: # discard Y coord, replace with appropriate version byte
|
||||
# even y: <0, odd y: >0 -- https://bitcointalk.org/index.php?topic=129652.0
|
||||
return (b'\x02',b'\x03')[pubkey[-1] & 1] + pubkey[:32]
|
||||
return (b'\x03' if vk_bytes[-1] & 1 else b'\x02') + vk_bytes[:32]
|
||||
else:
|
||||
return b'\x04' + pubkey
|
||||
return b'\x04' + vk_bytes
|
||||
|
||||
return PubKey(
|
||||
s = privnum2pubkey( int.from_bytes(privkey,'big'), compressed=privkey.compressed ),
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ from .cfg import gv,gc
|
|||
|
||||
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
|
||||
|
||||
digits = '0123456789'
|
||||
hexdigits = '0123456789abcdefABCDEF'
|
||||
hexdigits_uc = '0123456789ABCDEF'
|
||||
hexdigits_lc = '0123456789abcdef'
|
||||
|
|
@ -347,12 +348,8 @@ def secs_to_hms(secs):
|
|||
def secs_to_ms(secs):
|
||||
return '{:02d}:{:02d}'.format(secs//60, secs % 60)
|
||||
|
||||
def is_int(s):
|
||||
try:
|
||||
int(str(s))
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
def is_int(s): # actually is_nonnegative_int()
|
||||
return set(str(s)) <= set(digits)
|
||||
|
||||
def check_int_between(val,imin,imax,desc):
|
||||
if not imin <= int(val) <= imax:
|
||||
|
|
|
|||
|
|
@ -265,7 +265,8 @@ init_tests() {
|
|||
a $gentest_py --coin=ltc --type=bech32 1 $REFDIR/litecoin/ltcwallet-bech32.dump
|
||||
a $gentest_py --coin=ltc --type=compressed --testnet=1 1 $REFDIR/litecoin/ltcwallet-testnet.dump
|
||||
- # libsecp256k1 vs python-ecdsa:
|
||||
- $gentest_py 1:2 $rounds100x
|
||||
- $gentest_py --type=legacy 1:2 $rounds100x
|
||||
- $gentest_py --type=compressed 1:2 $rounds100x
|
||||
- $gentest_py --type=segwit 1:2 $rounds100x
|
||||
- $gentest_py --type=bech32 1:2 $rounds100x
|
||||
- $gentest_py --testnet=1 1:2 $rounds100x
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ sample_text_hexdump = (
|
|||
kafile_opts = ['-p1','-Ptest/ref/keyaddrfile_password']
|
||||
|
||||
from test.unit_tests_d.ut_baseconv import unit_test as ut_baseconv
|
||||
from test.unit_tests_d.ut_bip39 import unit_test as ut_bip39
|
||||
from test.unit_tests_d.ut_bip39 import unit_tests as ut_bip39
|
||||
from test.unit_tests_d.ut_xmrseed import unit_test as ut_xmrseed
|
||||
|
||||
btc_wif1 = '5HwzecKMWD82ppJK3qMKpC7ohXXAwcyAN5VgdJ9PLFaAzpBG4sX'
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ if not os.getenv('MMGEN_DEVTOOLS'):
|
|||
init_dev()
|
||||
|
||||
from mmgen.cfg import Config,gc
|
||||
from mmgen.color import green,gray
|
||||
from mmgen.color import green,gray,brown
|
||||
from mmgen.util import msg,gmsg,ymsg,Msg,async_run
|
||||
|
||||
from test.include.common import set_globals,end_msg
|
||||
|
|
@ -147,7 +147,7 @@ def run_test(test,subtest=None):
|
|||
|
||||
def run_subtest(t,subtest):
|
||||
subtest_disp = subtest.replace('_','-')
|
||||
msg(f'Running unit subtest {test}.{subtest_disp}')
|
||||
msg(brown(f'Running unit subtest {test}.{subtest_disp}'))
|
||||
|
||||
if getattr(t,'silence_output',False):
|
||||
t._silence()
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@ test/unit_tests_d/ut_bip39: BIP39 unit test for the MMGen suite
|
|||
"""
|
||||
|
||||
from mmgen.util import msg,msg_r
|
||||
from mmgen.color import blue,orange,purple
|
||||
from mmgen.bip39 import bip39
|
||||
|
||||
from ..include.common import cfg,qmsg,vmsg
|
||||
from ..include.common import cfg,qmsg,vmsg,vmsg_r
|
||||
|
||||
class unit_test:
|
||||
class unit_tests:
|
||||
|
||||
vectors = (
|
||||
( "00000000000000000000000000000000",
|
||||
|
|
@ -85,12 +87,10 @@ class unit_test:
|
|||
)
|
||||
)
|
||||
|
||||
def run_test(self,name,ut):
|
||||
def conversion(self,name,ut):
|
||||
|
||||
msg_r('Testing BIP39 conversion routines...')
|
||||
qmsg('')
|
||||
|
||||
from mmgen.bip39 import bip39
|
||||
vmsg('')
|
||||
qmsg(blue('Testing BIP39 conversion routines'))
|
||||
|
||||
b = bip39()
|
||||
b.check_wordlist(cfg)
|
||||
|
|
@ -111,8 +111,15 @@ class unit_test:
|
|||
res = b.tohex( v[1].split() )
|
||||
assert res == chk, f'mismatch:\nres: {res}\nchk: {chk}'
|
||||
|
||||
qmsg('OK')
|
||||
vmsg('')
|
||||
qmsg('Checking error handling:')
|
||||
|
||||
return True
|
||||
|
||||
def errors(self,name,ut):
|
||||
|
||||
vmsg('')
|
||||
qmsg(blue('Testing error handling'))
|
||||
|
||||
good_mn = "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong".split()
|
||||
bad_len_mn = "zoo zoo zoo".split()
|
||||
|
|
@ -121,6 +128,7 @@ class unit_test:
|
|||
bad_seed = 'deadbeef'
|
||||
good_seed = 'deadbeef' * 4
|
||||
|
||||
b = bip39()
|
||||
th = b.tohex
|
||||
fh = b.fromhex
|
||||
bad_data = (
|
||||
|
|
@ -137,7 +145,7 @@ class unit_test:
|
|||
|
||||
ut.process_bad_data(bad_data)
|
||||
|
||||
qmsg('OK')
|
||||
vmsg('')
|
||||
msg('OK')
|
||||
|
||||
return True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue