示例#1
0
文件: format.py 项目: UFOCoins/ufobit
def get_version(address):
    version = b58decode_check(address)[:1]

    if version == MAIN_PUBKEY_HASH:
        return 'main'
    elif version == TEST_PUBKEY_HASH:
        return 'test'
    else:
        raise ValueError('{} does not correspond to a mainnet nor '
                         'testnet address.'.format(version))
示例#2
0
文件: format.py 项目: UFOCoins/ufobit
def wif_checksum_check(wif):

    try:
        decoded = b58decode_check(wif)
    except ValueError:
        return False

    if decoded[:1] in (MAIN_PRIVATE_KEY, TEST_PRIVATE_KEY):
        return True

    return False
示例#3
0
文件: format.py 项目: UFOCoins/ufobit
def wif_to_bytes(wif):

    private_key = b58decode_check(wif)

    version = private_key[:1]

    if version == MAIN_PRIVATE_KEY:
        version = 'main'
    elif version == TEST_PRIVATE_KEY:
        version = 'test'
    else:
        raise ValueError('{} does not correspond to a mainnet nor '
                         'testnet address.'.format(version))

    # Remove version byte and, if present, compression flag.
    if len(wif) == 52 and private_key[-1] == 1:
        private_key, compressed = private_key[1:-1], True
    else:
        private_key, compressed = private_key[1:], False

    return private_key, compressed, version
示例#4
0
文件: format.py 项目: UFOCoins/ufobit
def address_to_public_key_hash(address):
    # Raise ValueError if we cannot identify the address.
    get_version(address)
    return b58decode_check(address)[1:]
示例#5
0
 def test_b58decode_check_failure(self):
     with pytest.raises(ValueError):
         b58decode_check(BITCOIN_ADDRESS[:-1])
示例#6
0
 def test_b58decode_check_success(self):
     assert b58decode_check(
         BITCOIN_ADDRESS) == MAIN_PUBKEY_HASH + PUBKEY_HASH