예제 #1
0
def test_pubkey_to_bech32_address():
    """Test vectors from here: https://iancoleman.io/bip39/"""
    address = pubkey_to_bech32_address(
        bytes.fromhex(
            '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'
        ),
        witver=0,
    )
    assert address == 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4'
    address = pubkey_to_bech32_address(
        bytes.fromhex(
            '037ff51223cb6fddbfc2c90f0ce5bbb3ee1f846f319858940856b1724f7fa1e15c'
        ),
        witver=0,
    )
    assert address == 'bc1qc3qcxs025ka9l6qn0q5cyvmnpwrqw2z49qwrx5'
    address = pubkey_to_bech32_address(
        bytes.fromhex(
            '02192dce4b382adecdcf74a366fc1f39dd1b88d0829eb058d746702c1d2626ab55'
        ),
        witver=0,
    )
    assert address == 'bc1q96nd0va09tdalp7f232ukhj6lp4s5m2g3s2hdy'
    address = pubkey_to_bech32_address(
        bytes.fromhex(
            '03ad84bf691e9d7ddb44d7e9311857af575b686e71506d2c9e8e1d2d11d4f115c1'
        ),
        witver=0,
    )
    assert address == 'bc1q7zxvguxdazzjd4m7d7ahlt03nnakc9fhxhskd5'
예제 #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,
         )
예제 #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')