예제 #1
0
    def decode(txt):
        """Decodes txt into a big-endian bytearray."""
        if not isinstance(txt, str):
            raise TypeError('a string is required')

        if not txt:
            raise Base58Error('string cannot be empty')

        value = 0
        for c in txt:
            value = value * 58 + Base58.char_value(c)

        result = int_to_bytes(value)

        # Prepend leading zero bytes if necessary
        count = 0
        for c in txt:
            if c != '1':
                break
            count += 1
        if count:
            result = bytes(count) + result

        return result
예제 #2
0
def test_int_to_bytes():
    assert util.int_to_bytes(456789) == b'\x06\xf8U'
예제 #3
0
def _exponent_to_bytes(exponent):
    '''Convert an exponent to 32 big-endian bytes'''
    return (bytes(32) + int_to_bytes(exponent))[-32:]