Exemple #1
0
def test_pubkey_to_base58_address():
    """Test vectors from here: https://iancoleman.io/bip39/"""
    address = pubkey_to_base58_address(
        bytes.fromhex(
            '03564213318d739994e4d9785bf40eac4edbfa21f0546040ce7e6859778dfce5d4'
        ), )
    assert address == '127NVqnjf8gB9BFAW2dnQeM6wqmy1gbGtv'
    address = pubkey_to_base58_address(
        bytes.fromhex(
            '0339a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c2'
        ), )
    assert address == '15mKKb2eos1hWa6tisdPwwDC1a5J1y9nma'
    address = pubkey_to_base58_address(
        bytes.fromhex(
            '035a784662a4a20a65bf6aab9ae98a6c068a81c52e4b032c0fb5400c706cfccc56'
        ), )
    assert address == '19Q2WoS5hSS6T8GjhK8KZLMgmWaq4neXrh'
    address = pubkey_to_base58_address(
        bytes.fromhex(
            '03501e454bf00751f24b1b489aa925215d66af2234e3891c3b21a52bedb3cd711c'
        ), )
    assert address == '1JQheacLPdM5ySCkrZkV66G2ApAXe1mqLj'
    address = pubkey_to_base58_address(
        bytes.fromhex(
            '0357bfe1e341d01c69fe5654309956cbea516822fba8a601743a012a7896ee8dc2'
        ), )
    assert address == '1NjxqbA9aZWnh17q1UW3rB4EPu79wDXj7x'
Exemple #2
0
 def generate_specific_address(self, addr_type: BTCAddressType) -> str:
     if addr_type == BTCAddressType.BASE58:
         return pubkey_to_base58_address(
             self.pubkey.format(COMPRESSED_PUBKEY))
     else:
         return pubkey_to_bech32_address(
             data=self.pubkey.format(COMPRESSED_PUBKEY),
             witver=0,
         )
Exemple #3
0
    def address(self) -> BTCAddress:
        if self.hint == 'xpub':
            return pubkey_to_base58_address(
                self.pubkey.format(COMPRESSED_PUBKEY))
        elif self.hint == 'zpub':
            return pubkey_to_bech32_address(
                data=self.pubkey.format(COMPRESSED_PUBKEY),
                witver=0,
            )

        raise AssertionError(f'Unknown hint {self.hint} ended up in an HDKey')