Exemple #1
0
def metadata_for_text(text):
    d = {}
    try:
        data = a2b_hashed_base58(text)
        d["as_base58"] = (data, )
    except EncodingError:
        try:
            data = a2b_hashed_base58_grs(text)
            d["as_base58"] = (data, )
        except EncodingError:
            d["as_base58"] = None

    try:
        hrp, data = segwit_addr.bech32_decode(text)
        if None not in [hrp, data]:
            d["as_bech32"] = (hrp, data)
        else:
            d["as_bech32"] = None
    except (TypeError, KeyError):
        pass

    try:
        prefix, rest = text.split(":", 1)
        data = rest
        d["as_colon"] = (prefix, data)
    except ValueError:
        d["as_colon"] = None

    d["as_text"] = (text, )
    return d
Exemple #2
0
def metadata_for_text(text):
    d = {}
    try:
        data = a2b_hashed_base58(text)
        d["as_base58"] = (data,)
    except EncodingError:
        d["as_base58"] = None

    try:
        hrp, data = segwit_addr.bech32_decode(text)
        if None not in [hrp, data]:
            d["as_bech32"] = (hrp, data)
        else:
            d["as_bech32"] = None
    except (TypeError, KeyError):
        pass

    try:
        prefix, rest = text.split(":", 1)
        data = rest
        d["as_colon"] = (prefix, data)
    except ValueError:
        d["as_colon"] = None

    d["as_text"] = (text, )
    return d
Exemple #3
0
def main():
    wallet = {}
    db = Database(expandvars(filepath))
    for row in db['main'].rows:
        key = fmt_key(row['key'])
        value = fmt_key(row['value'])

        ktxt = key.split(',')[0].strip()
        kbin = key.split(',')[-1].strip()
        data = {kbin: value}
        if kbin != ktxt:
            data = {ktxt: data}
        if wallet.get(ktxt, False):
            wallet[ktxt].update(data[ktxt])
        else:
            wallet.update(data)
    # print(dumps(wallet, indent=2))

    assert wallet["walletdescriptor"] and wallet["walletdescriptorkey"]
    for dkey in wallet["walletdescriptor"].keys():
        for kkey in wallet["walletdescriptorkey"].keys():
            if kkey.startswith(dkey):
                print()
                desc = wallet["walletdescriptor"][dkey].split('#')[0]
                der = wallet["walletdescriptorkey"][kkey]
                assert der.startswith('d63081d30201010420')
                m = search('\(([A-z0-9]*)/', desc)
                pub = m.group(1)
                path = '/'.join(desc.split('/')[1:-1])
                sec = bytes.fromhex('00') + bytes.fromhex(der)[9:][:32]
                tpub = a2b_hashed_base58(pub)
                blob = tpub[4:-33] + sec
                prv = tbtc.bip32_as_string(blob, as_private=True)
                hwif = tbtc.parse(prv).hwif()
                assert hwif == pub
                print(descsum_create(desc))
                desc = desc.replace(pub, prv)
                print(descsum_create(desc))
                if desc.startswith("pkh(tprv"):
                    print_p2pkh(prv, path)
                elif desc.startswith("sh(wpkh(tprv"):
                    print_p2sh_segwit(prv, path)
                if desc.startswith("wpkh(tprv"):
                    print_segwit(prv, path)
                if desc.startswith("tr(tprv"):
                    print_p2tr(prv, path)
Exemple #4
0
def b58(args, parser):
    for arg in args.input:
        blob, is_hex_input = parse_arg(arg, args.b)

        if is_hex_input:
            print(b2h(blob))
            print(b2a_base58(blob))
            print(b2a_hashed_base58(blob))
        else:
            print(b2h(blob))
            print(b2a_base58(blob))
            try:
                blob = a2b_hashed_base58(arg)
                print("valid hashed b58")
                print("contents: ", b2h(blob))
            except Exception:
                print("not hashed b58")
Exemple #5
0
def b58(args, parser):
    for arg in args.input:
        blob, is_hex_input = parse_arg(arg, args.b)

        if is_hex_input:
            print(b2h(blob))
            print(b2a_base58(blob))
            print(b2a_hashed_base58(blob))
        else:
            print(b2h(blob))
            print(b2a_base58(blob))
            try:
                blob = a2b_hashed_base58(arg)
                print("valid hashed b58")
                print("contents: ", b2h(blob))
            except Exception:
                print("not hashed b58")
Exemple #6
0
 def do_test(as_text, as_bin):
     self.assertEqual(as_text, b2a_hashed_base58(as_bin))
     self.assertEqual(as_bin, a2b_hashed_base58(as_text))
     self.assertTrue(is_hashed_base58_valid(as_text))
     bogus_text = as_text[:-1] + chr(1 + ord(as_text[-1]))
     self.assertFalse(is_hashed_base58_valid(bogus_text))
def change_prefix(address, new_prefix):
    return b2a_hashed_base58(new_prefix + a2b_hashed_base58(address)[1:])
Exemple #8
0
 def add_address(self, address):
     the_hash160 = a2b_hashed_base58(address)[1:]
     self.add_item(the_hash160)
Exemple #9
0
 def do_test(as_text, as_bin):
     self.assertEqual(as_text, b2a_hashed_base58(as_bin))
     self.assertEqual(as_bin, a2b_hashed_base58(as_text))
     self.assertTrue(is_hashed_base58_valid(as_text))
     bogus_text = as_text[:-1] + chr(1+ord(as_text[-1]))
     self.assertFalse(is_hashed_base58_valid(bogus_text))
def validate(address, magic_bytes):
    try:
        return a2b_hashed_base58(address)[:1] in bytes(
            map(int, magic_bytes.split(',')))
    except EncodingError:
        return False
def change_prefix(address, new_prefix):
    return b2a_hashed_base58(new_prefix + a2b_hashed_base58(address)[1:])
Exemple #12
0
 def add_address(self, address):
     the_hash160 = a2b_hashed_base58(address)[1:]
     self.add_item(the_hash160)