Exemple #1
0
 def runTest(self):
     "Check converting English strings to keys"
     for key, words in test_data:
         key = binascii.a2b_hex(key)
         self.assertEquals(RFC1751.english_to_key(words), key)
def buf_to_seed(seed_buf):
    """
    turn base58, RFC-1751, hexadecimal, or XUMM secret number seed buffer into seed bytes
    seed_buf --> base58, rippled RFC-1751, hexadecimal, or XUMM secret number seed buffers
    """
    # first try base58
    try:
        seedtry = base58.b58decode_check(seed_buf,
                                         alphabet=base58.RIPPLE_ALPHABET)
        if seedtry[:1] == XRPL_SEED_PREFIX and len(seedtry) == 17:
            seed_bytes = seedtry[1:]
            return seed_bytes
        else:
            raise ValueError
    except:
        pass

    # next try RFC-1751 (rippled format)
    try:
        seedtry = RFC1751.english_to_key(seed_buf)
        if len(seedtry) == 16:
            _RFC1751_format = input(
                'rippled API format? type True or False:  ').lower()
            if _RFC1751_format == "true" or _RFC1751_format == "t":
                seed_bytes = int.from_bytes(
                    seedtry, byteorder='little').to_bytes(16, byteorder='big')
            else:
                seed_bytes = seedtry
            return seed_bytes
        else:
            raise ValueError
    except:
        pass

    # next try hexadecimal
    try:
        bytetry = bytes.fromhex(seed_buf)
        if len(bytetry) == 16:
            seed_bytes = bytetry
            return seed_bytes
        else:
            raise ValueError
    except:
        pass

    # next try XUMM secret number
    try:
        if len(seed_buf) == 48:
            seed_bytes = b''
            for row in range(8):
                seed_bytes = seed_bytes + int(
                    seed_buf[row * 6:row * 6 + 5]).to_bytes(2, byteorder='big')
                if int(seed_buf[row * 6:row * 6 + 5]) * (
                        row * 2 + 1) % 9 != int(seed_buf[row * 6 + 5]):
                    raise ValueError
            return seed_bytes
        else:
            raise ValueError
    except:
        pass

    # if none of the above, raise error
    raise Exception(
        'input seed is not base58, RFC-1751, hexadecimal, or secret number')
Exemple #3
0
 def runTest (self):
     "Check converting English strings to keys"
     for key, words in test_data:
         key=binascii.a2b_hex(key)
         self.assertEqual(RFC1751.english_to_key(words), key)