def preprocess_key(cls,hexpriv,pubkey_type): # Key must be non-zero and less than group order of secp256k1 curve if 0 < int(hexpriv,16) < cls.secp256k1_ge: return hexpriv else: # chance of this is less than 1 in 2^127 pk = int(hexpriv,16) if pk == 0: # chance of this is 1 in 2^256 ydie(3,'Private key is zero!') elif pk == cls.secp256k1_ge: # ditto ydie(3,'Private key == secp256k1_ge!') else: ymsg('Warning: private key is greater than secp256k1 group order!:\n {}'.format(hexpriv)) return '{:064x}'.format(pk % cls.secp256k1_ge).encode()
def launch(what): def my_dec(a): try: return a.decode('utf8') except: sys.stderr.write( "Argument {!r} is not a valid UTF-8 string".format(a)) sys.exit(2) import sys sys.argv = map(my_dec, sys.argv) if what in ('walletgen', 'walletchk', 'walletconv', 'passchg'): what = 'wallet' if what == 'keygen': what = 'addrgen' try: import termios except: # Windows __import__('mmgen.main_' + what) else: import os, atexit if sys.stdin.isatty(): fd = sys.stdin.fileno() old = termios.tcgetattr(fd) def at_exit(): termios.tcsetattr(fd, termios.TCSADRAIN, old) atexit.register(at_exit) try: __import__('mmgen.main_' + what) except KeyboardInterrupt: sys.stderr.write('\nUser interrupt\n') except EOFError: sys.stderr.write('\nEnd of file\n') except Exception as e: if os.getenv('MMGEN_TRACEBACK'): raise else: try: m = u'{}'.format(e[0]) except: try: m = u'{!r}'.format(e[0]) except: m = u'{!r}'.format(e) from mmgen.util import ydie ydie(2, u'\nERROR: ' + m)
def preprocess_key(cls, hexpriv, pubkey_type): # Key must be non-zero and less than group order of secp256k1 curve if 0 < int(hexpriv, 16) < cls.secp256k1_ge: return hexpriv else: # chance of this is less than 1 in 2^127 pk = int(hexpriv, 16) if pk == 0: # chance of this is 1 in 2^256 ydie(3, 'Private key is zero!') elif pk == cls.secp256k1_ge: # ditto ydie(3, 'Private key == secp256k1_ge!') else: ymsg( 'Warning: private key is greater than secp256k1 group order!:\n {}' .format(hexpriv)) return '{:064x}'.format(pk % cls.secp256k1_ge).encode()