def handle_genaddress(args): cfg = load_wallet_config(args) root_key = binascii.unhexlify(cfg['root_key']) path = [FIRST_HARDEN_INDEX, FIRST_HARDEN_INDEX + args.index] passphase = input_passphase() addr = derive_address_lagacy(root_key, passphase, path, DERIVATION_V1) print(addr.address().encode_base58().decode())
def handle_sign(args): passphase = input_passphase() cfg = load_wallet_config(args) root_xpriv = binascii.unhexlify(cfg['root_key']) root_xpub = xpriv_to_xpub(root_xpriv) hdpass = derive_hdpassphase(root_xpub) addr = Address.decode_base58(args.addr) path = addr.get_derive_path(hdpass) if path is None: print('the address don\'t belong to this wallet') return xpriv = derive_key(root_xpriv, passphase, path, DERIVATION_V1) xpub = xpriv_to_xpub(xpriv) if not addr.verify_pubkey(xpub): print('the passphase is wrong') return sig = encrypted_sign(xpriv, passphase, args.message.encode('utf-8')) print( json.dumps({ 'xpub': binascii.hexlify(xpub).decode(), 'addr': args.addr, 'msg': args.message, 'sig': binascii.hexlify(sig).decode(), }))
def create_wallet_with_mnemonic(args, words, recover): # generate seed and mnemonic. passphase = input_passphase() xpriv = gen_root_xpriv(mnemonic_to_seed(words, args.language), passphase) return create_wallet_with_xpriv(args, args.name, xpriv)