# Path: keepkeylib/ckd_public.py
# PRIME_DERIVATION_FLAG = 0x80000000
#     I64 = hmac.HMAC(key=node.chain_code, msg=data, digestmod=hashlib.sha512).digest()
# def point_to_pubkey(point):
# def sec_to_public_pair(pubkey):
#     def public_pair_for_x(generator, x, is_even):
# def is_prime(n):
# def fingerprint(pubkey):
# def get_address(public_node, address_type):
# def public_ckd(public_node, n):
# def get_subnode(node, i):
# def serialize(node, version=0x0488B21E):
# def deserialize(xpub):
# 
# Path: keepkeylib/client.py
# class CallException(Exception):
#     def __init__(self, code, message):
#         super(CallException, self).__init__()
#         self.args = [code, message]
# 
# Path: keepkeylib/tools.py
# def parse_path(nstr):
#     """
#     Convert BIP32 path string to list of uint32 integers with hardened flags.
#     Several conventions are supported to set the hardened flag: -1, 1', 1h
#     e.g.: "0/1h/1" -> [0, 0x80000001, 1]
#     :param nstr: path string
#     :return: list of integers
#     """
#     if not nstr:
#         return []
# 
#     n = nstr.split('/')
# 
#     # m/a/b/c => a/b/c
#     if n[0] == 'm':
#         n = n[1:]
# 
#     # coin_name/a/b/c => 44'/SLIP44_constant'/a/b/c
#     #if n[0] in slip44:
#     #    coin_id = slip44[n[0]]
#     #    n[0:1] = ['44h', '{}h'.format(coin_id)]
# 
#     def str_to_harden(x):
#         if x.startswith('-'):
#             return H_(abs(int(x)))
#         elif x.endswith(('h', "'")):
#             return H_(int(x[:-1]))
#         else:
#             return int(x)
# 
#     try:
#         return list(str_to_harden(x) for x in n)
#     except Exception:
#         raise ValueError('Invalid BIP32 path', nstr)
# 
# Path: keepkeylib/tx_api.py
# def pack_varint(n):
#     def __init__(self, network, url):
#     def fetch_json(self, url, resource, resourceid):
#     def get_tx(self, txhash):
#     def __init__(self, network, url, zcash=None):
#     def get_tx(self, txhash):
#     def get_raw_tx(self, txhash):
# class TxApi(object):
# class TxApiInsight(TxApi):


import common
import unittest
from binascii import hexlify, unhexlify
from keepkeylib import ckd_public as bip32
from common import KeepKeyTest
from keepkeylib import messages_pb2 as proto
from keepkeylib import types_pb2 as proto_types
from keepkeylib.client import CallException
from keepkeylib.tools import parse_path
from keepkeylib import tx_api
      inp2 = proto_types.TxInputType(
                       # amount=50.00000001,
                       address_n=parse_path("m/49'/1'/0'/0/1"),
                       prev_hash=PREVHASH_2,
                       amount=5000000001,
                       prev_index=1,
                       script_type=proto_types.SPENDP2SHWITNESS,
                       )
      inp3 = proto_types.TxInputType(
                       # amount=0.00000001,
                       address_n=parse_path("m/49'/1'/0'/0/2"),
                       prev_hash=PREVHASH_3,
                       amount=1,
                       prev_index=1,
                       script_type=proto_types.SPENDP2SHWITNESS,
                       )
      inp4 = proto_types.TxInputType(
                       # amount=,
                       address_n=parse_path("m/49'/1'/0'/0/3"),
                       prev_hash=PREVHASH_4,
                       amount=20000000000,
                       prev_index=1,
                       script_type=proto_types.SPENDP2SHWITNESS,
                       )

      out = proto_types.TxOutputType(address='2NA62MxEdTcBhSBN51QjD4LEam2J34ufotY',
                        amount=2000000000,
                        script_type=proto_types.PAYTOADDRESS,
                        )


# Path: keepkeylib/ckd_public.py
# PRIME_DERIVATION_FLAG = 0x80000000
#     I64 = hmac.HMAC(key=node.chain_code, msg=data, digestmod=hashlib.sha512).digest()
# def point_to_pubkey(point):
# def sec_to_public_pair(pubkey):
#     def public_pair_for_x(generator, x, is_even):
# def is_prime(n):
# def fingerprint(pubkey):
# def get_address(public_node, address_type):
# def public_ckd(public_node, n):
# def get_subnode(node, i):
# def serialize(node, version=0x0488B21E):
# def deserialize(xpub):
# 
# Path: keepkeylib/client.py
# class CallException(Exception):
#     def __init__(self, code, message):
#         super(CallException, self).__init__()
#         self.args = [code, message]
# 
# Path: keepkeylib/tools.py
# def parse_path(nstr):
#     """
#     Convert BIP32 path string to list of uint32 integers with hardened flags.
#     Several conventions are supported to set the hardened flag: -1, 1', 1h
#     e.g.: "0/1h/1" -> [0, 0x80000001, 1]
#     :param nstr: path string
#     :return: list of integers
#     """
#     if not nstr:
#         return []
# 
#     n = nstr.split('/')
# 
#     # m/a/b/c => a/b/c
#     if n[0] == 'm':
#         n = n[1:]
# 
#     # coin_name/a/b/c => 44'/SLIP44_constant'/a/b/c
#     #if n[0] in slip44:
#     #    coin_id = slip44[n[0]]
#     #    n[0:1] = ['44h', '{}h'.format(coin_id)]
# 
#     def str_to_harden(x):
#         if x.startswith('-'):
#             return H_(abs(int(x)))
#         elif x.endswith(('h', "'")):
#             return H_(int(x[:-1]))
#         else:
#             return int(x)
# 
#     try:
#         return list(str_to_harden(x) for x in n)
#     except Exception:
#         raise ValueError('Invalid BIP32 path', nstr)
# 
# Path: keepkeylib/tx_api.py
# def pack_varint(n):
#     def __init__(self, network, url):
#     def fetch_json(self, url, resource, resourceid):
#     def get_tx(self, txhash):
#     def __init__(self, network, url, zcash=None):
#     def get_tx(self, txhash):
#     def get_raw_tx(self, txhash):
# class TxApi(object):
# class TxApiInsight(TxApi):


# Path: tests/test_vuln20007.py
import common
import unittest
from binascii import hexlify, unhexlify
from keepkeylib import ckd_public as bip32
from common import KeepKeyTest
from keepkeylib import messages_pb2 as proto
from keepkeylib import types_pb2 as proto_types
from keepkeylib.client import CallException
from keepkeylib.tools import parse_path
from keepkeylib import tx_api

      inp2 = proto_types.TxInputType(
                       # amount=50.00000001,
                       address_n=parse_path("m/49'/1'/0'/0/1"),
                       prev_hash=PREVHASH_2,
                       amount=5000000001,
                       prev_index=1,
                       script_type=proto_types.SPENDP2SHWITNESS,
                       )
      inp3 = proto_types.TxInputType(
                       # amount=0.00000001,
                       address_n=parse_path("m/49'/1'/0'/0/2"),
                       prev_hash=PREVHASH_3,
                       amount=1,
                       prev_index=1,
                       script_type=proto_types.SPENDP2SHWITNESS,
                       )
      inp4 = proto_types.TxInputType(
                       # amount=,
                       address_n=parse_path("m/49'/1'/0'/0/3"),
                       prev_hash=PREVHASH_4,
                       amount=20000000000,
                       prev_index=1,
                       script_type=proto_types.SPENDP2SHWITNESS,
                       )

      out = proto_types.TxOutputType(address='2NA62MxEdTcBhSBN51QjD4LEam2J34ufotY',
                        amount=2000000000,
                        script_type=proto_types.PAYTOADDRESS,
                        )


      self.client.set_tx_api(tx_api.TxApiTestnet)