예제 #1
0
    def test_input_greater_243(self):
        # noinspection SpellCheckingInspection
        inp = (
          'G9JYBOMPUXHYHKSNRNMMSSZCSHOFYOYNZRSZMAAYWDYEIMVVOGKPJB'
          'VBM9TDPULSFUNMTVXRKFIDOHUXXVYDLFSZYZTWQYTE9SPYYWYTXJYQ'
          '9IFGYOLZXWZBKWZN9QOOTBQMWMUBLEWUEEASRHRTNIQWJQNDWRYLCA'
        )

        trits = trytes_to_trits(inp)

        kerl = Kerl()
        kerl.absorb(trits)
        trits_out = []
        kerl.squeeze(trits_out, length=486)

        trytes_out = trits_to_trytes(trits_out)

        # noinspection SpellCheckingInspection
        self.assertEqual(
          trytes_out,

          'LUCKQVACOGBFYSPPVSSOXJEKNSQQRQKPZC9NXFSMQNRQCGGUL9OHVV'
          'KBDSKEQEBKXRNUJSRXYVHJTXBPDWQGNSCDCBAIRHAQCOWZEBSNHIJI'
          'GPZQITIBJQ9LNTDIBTCQ9EUWKHFLGFUVGGUWJONK9GBCDUIMAYMMQX',
        )
예제 #2
0
파일: pykerl_test.py 프로젝트: lzpap/pyota
    def test_generate_multi_trytes_and_hash(self):
        filepath =\
          join(
            dirname(__file__),
            'test_vectors/generate_multi_trytes_and_hash.csv',
          )

        with open(filepath, 'r') as f:
            reader = DictReader(f)
            for count, line in enumerate(reader):
                trytes = line['multiTrytes']
                hashes = line['Kerl_hash']

                trits = trytes_to_trits(trytes)

                kerl = Kerl()
                kerl.absorb(trits)
                trits_out = []
                kerl.squeeze(trits_out)

                trytes_out = trits_to_trytes(trits_out)

                self.assertEqual(
                    hashes,
                    trytes_out,
                    msg='line {count}: {hashes} != {trytes}'.format(
                        count=count + 2,
                        hashes=hashes,
                        trytes=trytes_out,
                    ),
                )
예제 #3
0
    def test_generate_multi_trytes_and_hash(self):
        filepath =\
          join(
            dirname(__file__),
            'test_vectors/generate_multi_trytes_and_hash.csv',
          )

        with open(filepath,'r') as f:
            reader = DictReader(f)
            for count, line in enumerate(reader):
                trytes = line['multiTrytes']
                hashes = line['Kerl_hash']

                trits = trytes_to_trits(trytes)

                kerl = Kerl()
                kerl.absorb(trits)
                trits_out = []
                kerl.squeeze(trits_out)

                trytes_out = trits_to_trytes(trits_out)

                self.assertEqual(
                  hashes,
                  trytes_out,

                  msg =
                    'line {count}: {hashes} != {trytes}'.format(
                      count = count + 2,
                      hashes = hashes,
                      trytes = trytes_out,
                    ),
                )
예제 #4
0
    def test_output_greater_243(self):
        # noinspection SpellCheckingInspection
        inp = ('9MIDYNHBWMBCXVDEFOFWINXTERALUKYYPPHKP9JJ'
               'FGJEIUY9MUDVNFZHMMWZUYUSWAIOWEVTHNWMHANBH')

        trits = trytes_to_trits(inp)
        print_var_type_n_val(
            var001=trits, pointer="#XCVBNbvcSDF23458765")  #XCVBNbvcSDF23458765
        # Value:
        # # [0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, -1, 0, -1, -1, -1, -1, 0, 1, -1, 1, 0, -1, -1, 0, 1, 1, 1, -1, 1, 0, 0, 1, 0, 0, -1, 0, 1, 1, -1, 1, 1, 0, -1, -1, 1, 0, -1, 1, 0, -1, -1, 0, -1, 1, -1, -1, 0, 0, 0, 1, -1, -1, -1, 0, -1, 0, -1, 1, -1, -1, -1, 1, 0, 0, -1, 1, 0, 0, 0, 1, 1, 0, 1, -1, -1, 1, 1, 1, -1, 0, 1, -1, 0, 1, -1, -1, 1, -1, -1, -1, 0, 1, -1, 1, 1, 1, -1, -1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, -1, 1, 1, -1, 1, 1, 0, 1, -1, -1, 1, 0, 0, 1, 0, 1, -1, 1, -1, 0, 0, 0, 0, 1, 1, 1, 0, 1, -1, 1, 1, 0, 1, 1, -1, -1, -1, -1, 0, -1, 1, -1, 0, 0, -1, 0, 1, 1, 1, 1, 1, 1, 1, -1, -1, 0, -1, 0, 0, 0, 1, -1, 1, -1, 0, 0, 1, -1, 1, 0, -1, -1, -1, 0, 1, 0, 0, 0, 0, 1, 0, -1, -1, -1, -1, 0, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1, 0, 1, -1, -1, -1, -1, -1, 0, 1, 1, 1, -1, 0, 1, 1, 0, 0, -1, -1, -1, -1, 1, 0, -1, 0, 1]

        # Type: <class 'list'>

        kerl = Kerl()
        print_var_type_n_val(var001=kerl,
                             pointer="#SDFG345tredff")  #SDFG345tredff
        # Value:
        # # <iota.crypto.kerl.pykerl.Kerl object at 0x0000018FAA7C6780>

        # Type: <class 'iota.crypto.kerl.pykerl.Kerl'>
        kerl.absorb(trits)
        print_var_type_n_val(
            var001=kerl,
            pointer="#ERERdfgfdrtre2345665777")  #ERERdfgfdrtre2345665777
        # Value:
        # # <iota.crypto.kerl.pykerl.Kerl object at 0x0000018FAA7C6780>

        # Type: <class 'iota.crypto.kerl.pykerl.Kerl'>
        trits_out = []
        kerl.squeeze(trits_out, length=486)
        print_var_type_n_val(var001=kerl, pointer="#2345gDFRER")  #2345gDFRER
        # Value:
        # # <iota.crypto.kerl.pykerl.Kerl object at 0x0000018FAA7C6780>

        # Type: <class 'iota.crypto.kerl.pykerl.Kerl'>

        trytes_out = trits_to_trytes(trits_out)
        print_var_type_n_val(var001=trytes_out,
                             pointer="#23458765SDFfffFGH")  #23458765SDFfffFGH
        # Value: G9JYBOMPUXHYHKSNRNMMSSZCSHOFYOYNZRSZMAAYWDYEIMVVOGKPJBVBM9TDPULSFUNMTVXRKFIDOHUXXVYDLFSZYZTWQYTE9SPYYWYTXJYQ9IFGYOLZXWZBKWZN9QOOTBQMWMUBLEWUEEASRHRTNIQWJQNDWRYLCA
        # Type: <class 'str'>
        # noinspection SpellCheckingInspection
        self.assertEqual(
            trytes_out,
            'G9JYBOMPUXHYHKSNRNMMSSZCSHOFYOYNZRSZMAAYWDYEIMVVOGKPJB'
            'VBM9TDPULSFUNMTVXRKFIDOHUXXVYDLFSZYZTWQYTE9SPYYWYTXJYQ'
            '9IFGYOLZXWZBKWZN9QOOTBQMWMUBLEWUEEASRHRTNIQWJQNDWRYLCA',
        )
예제 #5
0
    def test_correct_first(self):
        inp = ('EMIDYNHBWMBCXVDEFOFWINXTERALUKYYPPHKP9JJ'
               'FGJEIUY9MUDVNFZHMMWZUYUSWAIOWEVTHNWMHANBH')

        trits = trytes_to_trits(inp)

        kerl = Kerl()
        kerl.absorb(trits)
        trits_out = []
        kerl.squeeze(trits_out)

        trytes_out = trits_to_trytes(trits_out)

        self.assertEqual(
            trytes_out,
            'EJEAOOZYSAWFPZQESYDHZCGYNSTWXUMVJOVDWUNZ'
            'JXDGWCLUFGIMZRMGCAZGKNPLBRLGUNYWKLJTYEAQX',
        )
def MnemonicsToIotaSeed(recovery_words,
                        passphrase='',
                        bip44_account=0x00000000,
                        bip44_page_index=0x00000000):
    """Recover an IOTA seed from the ledger Nano S recovery phrase

    Keyword arguments:
    recovery_words -- a list of 24 words (your ledger recovery phrase)
    passphrase -- a string containing the passphrase (only if set in ledger, not your pin number!)
    bip44_account -- an integer containing BIP44 path 'Account'
    bip44_page_index -- an integer containing BIP44 path 'Page index'
    """
    print("\nCalculating your IOTA seed...")

    master_seed = mnemonic.Mnemonic.to_seed(mnemonic=' '.join(recovery_words),
                                            passphrase=passphrase)
    bip32_root_key = bip32utils.BIP32Key.fromEntropy(master_seed)

    bip44_purpose_key = bip32_root_key.ChildKey(0x8000002C)  # Purpose
    bip44_coin_type_key = bip44_purpose_key.ChildKey(0x8000107A)  # CoinType
    bip44_account_key = bip44_coin_type_key.ChildKey(0x80000000 +
                                                     bip44_account)  # Account
    bip44_page_index_key = bip44_account_key.ChildKey(
        0x80000000 + bip44_page_index)  # Page index

    if (sys.version_info.major >= 3):
        priv_key = bytearray(bip44_page_index_key.PrivateKey())
        chain_code = bytearray(bip44_page_index_key.C)
    else:
        priv_key = bytearray.fromhex(
            bip44_page_index_key.PrivateKey().encode('hex'))
        chain_code = bytearray.fromhex(bip44_page_index_key.C.encode('hex'))

    trits_out = []

    kerl = Kerl()
    kerl.k.update(priv_key[0:32] + chain_code[0:16] + priv_key[16:32] +
                  chain_code[0:32])
    kerl.squeeze(trits_out)

    iota_seed = conv.trits_to_trytes(trits_out)

    print("Seed: %s, Length: %d" % (iota_seed, len(iota_seed)))
예제 #7
0
    def test_output_greater_243(self):
        inp = ('9MIDYNHBWMBCXVDEFOFWINXTERALUKYYPPHKP9JJ'
               'FGJEIUY9MUDVNFZHMMWZUYUSWAIOWEVTHNWMHANBH')

        trits = trytes_to_trits(inp)

        kerl = Kerl()
        kerl.absorb(trits)
        trits_out = []
        kerl.squeeze(trits_out, length=486)

        trytes_out = trits_to_trytes(trits_out)

        self.assertEqual(
            trytes_out,
            'G9JYBOMPUXHYHKSNRNMMSSZCSHOFYOYNZRSZMAAYWDYEIMVVOGKPJB'
            'VBM9TDPULSFUNMTVXRKFIDOHUXXVYDLFSZYZTWQYTE9SPYYWYTXJYQ'
            '9IFGYOLZXWZBKWZN9QOOTBQMWMUBLEWUEEASRHRTNIQWJQNDWRYLCA',
        )
예제 #8
0
    def test_input_greater_243(self):
        inp = ('G9JYBOMPUXHYHKSNRNMMSSZCSHOFYOYNZRSZMAAYWDYEIMVVOGKPJB'
               'VBM9TDPULSFUNMTVXRKFIDOHUXXVYDLFSZYZTWQYTE9SPYYWYTXJYQ'
               '9IFGYOLZXWZBKWZN9QOOTBQMWMUBLEWUEEASRHRTNIQWJQNDWRYLCA')

        trits = trytes_to_trits(inp)

        kerl = Kerl()
        kerl.absorb(trits)
        trits_out = []
        kerl.squeeze(trits_out, length=486)

        trytes_out = trits_to_trytes(trits_out)

        self.assertEqual(
            trytes_out,
            'LUCKQVACOGBFYSPPVSSOXJEKNSQQRQKPZC9NXFSMQNRQCGGUL9OHVV'
            'KBDSKEQEBKXRNUJSRXYVHJTXBPDWQGNSCDCBAIRHAQCOWZEBSNHIJI'
            'GPZQITIBJQ9LNTDIBTCQ9EUWKHFLGFUVGGUWJONK9GBCDUIMAYMMQX',
        )
예제 #9
0
    def test_correct_first(self):
        # noinspection SpellCheckingInspection
        inp = (
          'EMIDYNHBWMBCXVDEFOFWINXTERALUKYYPPHKP9JJ'
          'FGJEIUY9MUDVNFZHMMWZUYUSWAIOWEVTHNWMHANBH'
        )

        trits = trytes_to_trits(inp)

        kerl = Kerl()
        kerl.absorb(trits)
        trits_out = []
        kerl.squeeze(trits_out)

        trytes_out = trits_to_trytes(trits_out)

        # noinspection SpellCheckingInspection
        self.assertEqual(
          trytes_out,

          'EJEAOOZYSAWFPZQESYDHZCGYNSTWXUMVJOVDWUNZ'
          'JXDGWCLUFGIMZRMGCAZGKNPLBRLGUNYWKLJTYEAQX',
        )
예제 #10
0
    def test_correct_first(self):
        # noinspection SpellCheckingInspection
        inp = ('EMIDYNHBWMBCXVDEFOFWINXTERALUKYYPPHKP9JJ'
               'FGJEIUY9MUDVNFZHMMWZUYUSWAIOWEVTHNWMHANBH')

        trits = trytes_to_trits(inp)
        print_var_type_n_val(
            var001=trits,
            pointer="#SDFGHhgfdAZER1234765555")  #SDFGHhgfdAZER1234765555
        # Value:
        # # [-1, -1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, -1, 0, -1, -1, -1, -1, 0, 1, -1, 1, 0, -1, -1, 0, 1, 1, 1, -1, 1, 0, 0, 1, 0, 0, -1, 0, 1, 1, -1, 1, 1, 0, -1, -1, 1, 0, -1, 1, 0, -1, -1, 0, -1, 1, -1, -1, 0, 0, 0, 1, -1, -1, -1, 0, -1, 0, -1, 1, -1, -1, -1, 1, 0, 0, -1, 1, 0, 0, 0, 1, 1, 0, 1, -1, -1, 1, 1, 1, -1, 0, 1, -1, 0, 1, -1, -1, 1, -1, -1, -1, 0, 1, -1, 1, 1, 1, -1, -1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, -1, 1, 1, -1, 1, 1, 0, 1, -1, -1, 1, 0, 0, 1, 0, 1, -1, 1, -1, 0, 0, 0, 0, 1, 1, 1, 0, 1, -1, 1, 1, 0, 1, 1, -1, -1, -1, -1, 0, -1, 1, -1, 0, 0, -1, 0, 1, 1, 1, 1, 1, 1, 1, -1, -1, 0, -1, 0, 0, 0, 1, -1, 1, -1, 0, 0, 1, -1, 1, 0, -1, -1, -1, 0, 1, 0, 0, 0, 0, 1, 0, -1, -1, -1, -1, 0, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1, 0, 1, -1, -1, -1, -1, -1, 0, 1, 1, 1, -1, 0, 1, 1, 0, 0, -1, -1, -1, -1, 1, 0, -1, 0, 1]

        # Type: <class 'list'>
        # print('trits001: ', trits)
        # # [-1, -1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, -1, 0, -1, -1, -1, -1, 0, 1, -1, 1, 0, -1, -1, 0, 1, 1, 1, -1, 1, 0, 0, 1, 0, 0, -1, 0, 1, 1, -1, 1, 1, 0, -1, -1, 1, 0, -1, 1, 0, -1, -1, 0, -1, 1, -1, -1, 0, 0, 0, 1, -1, -1, -1, 0, -1, 0, -1, 1, -1, -1, -1, 1, 0, 0, -1, 1, 0, 0, 0, 1, 1, 0, 1, -1, -1, 1, 1, 1, -1, 0, 1, -1, 0, 1, -1, -1, 1, -1, -1, -1, 0, 1, -1, 1, 1, 1, -1, -1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, -1, 1, 1, -1, 1, 1, 0, 1, -1, -1, 1, 0, 0, 1, 0, 1, -1, 1, -1, 0, 0, 0, 0, 1, 1, 1, 0, 1, -1, 1, 1, 0, 1, 1, -1, -1, -1, -1, 0, -1, 1, -1, 0, 0, -1, 0, 1, 1, 1, 1, 1, 1, 1, -1, -1, 0, -1, 0, 0, 0, 1, -1, 1, -1, 0, 0, 1, -1, 1, 0, -1, -1, -1, 0, 1, 0, 0, 0, 0, 1, 0, -1, -1, -1, -1, 0, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1, 0, 1, -1, -1, -1, -1, -1, 0, 1, 1, 1, -1, 0, 1, 1, 0, 0, -1, -1, -1, -1, 1, 0, -1, 0, 1]
        kerl = Kerl()
        kerl.absorb(trits)
        # print('kerl001: ', kerl)
        # # <iota.crypto.kerl.pykerl.Kerl object at 0x000002740CFA5BA8>
        trits_out = []
        kerl.squeeze(trits_out)
        # print('kerl002: ', kerl)
        # # <iota.crypto.kerl.pykerl.Kerl object at 0x000002740CFA5BA8>

        trytes_out = trits_to_trytes(trits_out)
        print_var_type_n_val(
            var001=trytes_out,
            pointer="#QSEZEzZERTYsder23434")  #QSEZEzZERTYsder23434
        # Value: EJEAOOZYSAWFPZQESYDHZCGYNSTWXUMVJOVDWUNZJXDGWCLUFGIMZRMGCAZGKNPLBRLGUNYWKLJTYEAQX
        # Type: <class 'str'>

        # noinspection SpellCheckingInspection
        self.assertEqual(
            trytes_out,
            'EJEAOOZYSAWFPZQESYDHZCGYNSTWXUMVJOVDWUNZ'
            'JXDGWCLUFGIMZRMGCAZGKNPLBRLGUNYWKLJTYEAQX',
        )
예제 #11
0
    def test_output_greater_243(self):
        # noinspection SpellCheckingInspection
        inp = (
          '9MIDYNHBWMBCXVDEFOFWINXTERALUKYYPPHKP9JJ'
          'FGJEIUY9MUDVNFZHMMWZUYUSWAIOWEVTHNWMHANBH'
        )

        trits = trytes_to_trits(inp)

        kerl = Kerl()
        kerl.absorb(trits)
        trits_out = []
        kerl.squeeze(trits_out, length=486)

        trytes_out = trits_to_trytes(trits_out)

        # noinspection SpellCheckingInspection
        self.assertEqual(
          trytes_out,

          'G9JYBOMPUXHYHKSNRNMMSSZCSHOFYOYNZRSZMAAYWDYEIMVVOGKPJB'
          'VBM9TDPULSFUNMTVXRKFIDOHUXXVYDLFSZYZTWQYTE9SPYYWYTXJYQ'
          '9IFGYOLZXWZBKWZN9QOOTBQMWMUBLEWUEEASRHRTNIQWJQNDWRYLCA',
        )
예제 #12
0
    def test_generate_trytes_and_multi_squeeze(self):
        filepath =\
          join(
            dirname(__file__),
            'test_vectors/generate_trytes_and_multi_squeeze.csv',
          )

        with open(filepath, 'r') as f:
            reader = DictReader(f)
            for count, line in enumerate(reader):
                trytes = line['trytes']
                hashes1 = line['Kerl_squeeze1']
                hashes2 = line['Kerl_squeeze2']
                hashes3 = line['Kerl_squeeze3']

                trits = trytes_to_trits(trytes)
                # print(trits)
                # # [-1, 0, 1, 1, -1, 0, -1, 0, 0, 1, -1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, -1, -1, 1, -1, -1, -1, -1, 0, -1, 1, -1, 0, -1, 0, 1, 0, 1, 1, 0, 1, -1, 0, 0, -1, 1, 0, 1, -1, -1, 0, 1, 1, 0, 0, 1, 0, -1, -1, 0, 0, -1, 0, 0, -1, 0, 1, 1, 0, 0, 0, 0, -1, 0, -1, 1, -1, -1, -1, 0, 0, 1, 0, 0, 1, 1, -1, 1, 1, -1, 0, 1, -1, 1, 0, -1, 1, 0, 1, 1, -1, 0, 1, 0, 1, 1, -1, -1, -1, 1, 1, 1, -1, 0, 1, -1, 0, -1, -1, -1, -1, 1, 0, 0, 0, -1, -1, -1, -1, -1, -1, 0, 1, -1, -1, -1, 0, 1, 1, 0, -1, -1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, -1, 1, 0, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 0, -1, 1, 1, -1, 1, 0, 0, 0, 1, 1, 1, -1, -1, 0, 0, -1, -1, 1, -1, -1, 0, -1, -1, 1, 0, 0, 1, 1, -1, -1, 1, 1, -1, -1, 0, 1, 1, 1, -1, -1, -1, 0, -1, -1, -1, -1, 0, 1, 1, 1, -1, -1, 0, 0, 1, 0, -1, 0, 1, -1, 0, -1, 1, -1, 1, -1, -1, -1, 0, 0, 1, 1, 0, 1, 0]
                kerl = Kerl()
                kerl.absorb(trits)

                trits_out = []
                kerl.squeeze(trits_out)
                trytes_out = trits_to_trytes(trits_out)

                # print('hashes1: ', hashes1)
                # # IWDWJCUUE9EBBYAEDXPDNAKTJAVY9IFOUZBNRIHMZ9NWOGOL9GYKZZ9ZLXHAI9PVPSLEAUGX9TQKMIUAX
                # print('trytes_out: ', trytes_out)
                # # IWDWJCUUE9EBBYAEDXPDNAKTJAVY9IFOUZBNRIHMZ9NWOGOL9GYKZZ9ZLXHAI9PVPSLEAUGX9TQKMIUAX

                self.assertEqual(
                    hashes1,
                    trytes_out,
                    msg='line {count}: {hashes} != {trytes}'.format(
                        count=count + 2,
                        hashes=hashes1,
                        trytes=trytes_out,
                    ),
                )

                trits_out = []
                kerl.squeeze(trits_out)
                trytes_out = trits_to_trytes(trits_out)

                # print('line {count}: {hashes} != {trytes}'.format(
                #       count = count + 2,
                #       hashes = hashes2,
                #       trytes = trytes_out,
                #     ))
                # # ANLYSAFQ9RJKFEADAZDTLPMYCYSGTRIOUWFKZPWJIEQHDTREOPHSUMAGIZLVIRMZGAVKODZAYBUISSQNX != ANLYSAFQ9RJKFEADAZDTLPMYCYSGTRIOUWFKZPWJIEQHDTREOPHSUMAGIZLVIRMZGAVKODZAYBUISSQNX

                self.assertEqual(
                    hashes2,
                    trytes_out,
                    msg='line {count}: {hashes} != {trytes}'.format(
                        count=count + 2,
                        hashes=hashes2,
                        trytes=trytes_out,
                    ),
                )

                trits_out = []
                kerl.squeeze(trits_out)
                trytes_out = trits_to_trytes(trits_out)

                self.assertEqual(
                    hashes3,
                    trytes_out,
                    msg='line {count}: {hashes} != {trytes}'.format(
                        count=count + 2,
                        hashes=hashes3,
                        trytes=trytes_out,
                    ),
                )