# 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)


import unittest
import common
import binascii
import keepkeylib.ckd_public as bip32
import keepkeylib.types_pb2 as proto_types
import keepkeylib.messages_eos_pb2 as eos_proto
import keepkeylib.eos as eos
from keepkeylib.tools import parse_path


EOS_ACCOUNT_0_PATH   = parse_path("m/44'/194'/0'/0/0")
EOS_ACCOUNT_0_PUBKEY = '4u6Sfnzj4Sh2pEQnkXyZQJqH3PkKjGByDCbsqqmyq6PttM9KyB'
EOS_ACCOUNT_1_PATH   = parse_path("m/44'/194'/1'/0/0")
EOS_ACCOUNT_1_PUBKEY = '7UuNeTf13nfcG85rDB7AHGugZi4C4wJ4ft12QRotqNfxdV2NvP'
ACCOUNT_NONE_PATH    = []
ACCOUNT_NONE_PUBKEY  = '8hhFGcdMry96GpvyxnAGFsnyaNHzXu3Hw61Fy1CnmJUQDQBhqk'

class TestMsgEosGetPublicKey(common.KeepKeyTest):

    def test(self):
        self.setup_mnemonic_nopin_nopassphrase()
        vec = [
            (EOS_ACCOUNT_0_PATH, False, True,  'EOS' + EOS_ACCOUNT_0_PUBKEY),
            (EOS_ACCOUNT_1_PATH, False, True,  'EOS' + EOS_ACCOUNT_1_PUBKEY),
            (ACCOUNT_NONE_PATH,  False, True,  'EOS' + ACCOUNT_NONE_PUBKEY),
            (EOS_ACCOUNT_0_PATH, False, False, 'EOS_K1_' + EOS_ACCOUNT_0_PUBKEY),
            (EOS_ACCOUNT_1_PATH, False, False, 'EOS_K1_' + EOS_ACCOUNT_1_PUBKEY),
            (ACCOUNT_NONE_PATH,  False, False,  'EOS_K1_' + ACCOUNT_NONE_PUBKEY),
        ]

        for path, show, legacy, wif in vec:
            res = self.client.eos_get_public_key(path, show, legacy)
            self.assertEqual(res.wif_public_key, wif)

    def test_trezor(self):
        self.setup_mnemonic_abandon()

        derivation_paths = [

# 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: tests/test_msg_eos_getpublickey.py
import unittest
import common
import binascii
import keepkeylib.ckd_public as bip32
import keepkeylib.types_pb2 as proto_types
import keepkeylib.messages_eos_pb2 as eos_proto
import keepkeylib.eos as eos
from keepkeylib.tools import parse_path



EOS_ACCOUNT_0_PATH   = parse_path("m/44'/194'/0'/0/0")
EOS_ACCOUNT_0_PUBKEY = '4u6Sfnzj4Sh2pEQnkXyZQJqH3PkKjGByDCbsqqmyq6PttM9KyB'
EOS_ACCOUNT_1_PATH   = parse_path("m/44'/194'/1'/0/0")
EOS_ACCOUNT_1_PUBKEY = '7UuNeTf13nfcG85rDB7AHGugZi4C4wJ4ft12QRotqNfxdV2NvP'
ACCOUNT_NONE_PATH    = []
ACCOUNT_NONE_PUBKEY  = '8hhFGcdMry96GpvyxnAGFsnyaNHzXu3Hw61Fy1CnmJUQDQBhqk'

class TestMsgEosGetPublicKey(common.KeepKeyTest):

    def test(self):
        self.setup_mnemonic_nopin_nopassphrase()
        vec = [
            (EOS_ACCOUNT_0_PATH, False, True,  'EOS' + EOS_ACCOUNT_0_PUBKEY),
            (EOS_ACCOUNT_1_PATH, False, True,  'EOS' + EOS_ACCOUNT_1_PUBKEY),
            (ACCOUNT_NONE_PATH,  False, True,  'EOS' + ACCOUNT_NONE_PUBKEY),
            (EOS_ACCOUNT_0_PATH, False, False, 'EOS_K1_' + EOS_ACCOUNT_0_PUBKEY),
            (EOS_ACCOUNT_1_PATH, False, False, 'EOS_K1_' + EOS_ACCOUNT_1_PUBKEY),
            (ACCOUNT_NONE_PATH,  False, False,  'EOS_K1_' + ACCOUNT_NONE_PUBKEY),
        ]

        for path, show, legacy, wif in vec:
            res = self.client.eos_get_public_key(path, show, legacy)
            self.assertEqual(res.wif_public_key, wif)

    def test_trezor(self):
        self.setup_mnemonic_abandon()

        derivation_paths = [

            [0x80000000 | 44, 0x80000000 | 194, 0x80000000, 0, 0],