Ejemplo n.º 1
0
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(),
        }))
Ejemplo n.º 2
0
def handle_wallet_balance(args):
    cfg = load_wallet_config(args)
    root_key = binascii.unhexlify(cfg['root_key'])
    hdpass = derive_hdpassphase(xpriv_to_xpub(root_key))

    # iterate utxo.
    print('Searching for utxo...')
    store = Storage(args.root)
    txouts = []
    for txin, txout in store.iter_utxo():
        if Address.decode(txout.addr).get_derive_path(hdpass):
            txouts.append(txout)

    balance = sum(out.c for out in txouts)
    print('balance:', balance)
    print('details:')
    for out in txouts:
        print(base58.b58encode(out.addr), out.c)
Ejemplo n.º 3
0
def handle_wallet_import(args):
    'interactive'
    import urllib.request
    import ssl

    ctx = ssl.create_default_context()
    ctx.check_hostname = False
    ctx.verify_mode = ssl.CERT_NONE

    try:
        rsp = urllib.request.urlopen('https://127.0.0.1:8090/api/v1/wallets',
                                     context=ctx)
    except urllib.error.URLError:
        print('Please open Daedalus wallet.')
        return
    data = json.loads(rsp.read())

    # load secrets
    import cbor
    import appdirs
    root = appdirs.user_data_dir('Daedalus')
    path = os.path.join(root, 'Secrets-1.0', 'secret.key')
    secrets = {}
    for item in cbor.load(open(path, 'rb'))[2]:
        xpriv = item[0]
        wid = AddressContent.pubkey(xpriv_to_xpub(xpriv)) \
                            .address() \
                            .encode_base58() \
                            .decode()
        secrets[wid] = xpriv

    candidates = []
    for item in data['data']:
        if item['id'] in secrets:
            candidates.append((item['id'], item['name']))

    for i, (wid, name) in enumerate(candidates):
        print('[%d] %s' % (i + 1, name))

    index = int(input('Select wallet [1]:') or 1) - 1
    if create_wallet_with_xpriv(args, candidates[index][1],
                                secrets[candidates[index][0]]):
        print('imported', candidates[index][1])