I have two bitcoin addresses:
One is compressed, one is not.
How can I test which is which? (Preferably using python 2.7)
Thanks in advance :)
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.Sign up to join this community
You cannot determine (from only a base58check address) if the corresponding public key is compressed.
A "normal" pay-to-public-key-hash (P2PKH) is a cryptographic hash of either a compressed or an uncompressed public key. Because hashes cannot be feasibly reversed, you cannot tell if the public key, before being hashed, was compressed or uncompressed.
More specifically, a public key in Bitcoin is a pair integers (x,y). For uncompressed public keys, these integers are encoded as 256-bit unsigned big-endian ints, concatenated together, and then prepended with a single 0x04 byte. The result is 65 bytes long.
For compressed public keys, only the x coordinate is encoded (like above, as 256-bit unsigned big-endian int). It turns out that the y coordinate can only be one of two values, one even and one odd. Instead of prepending a single 0x04 byte, a single 0x02 or 0x03 byte is prepended depending on y's value (0x02 for even, 0x03 for odd). The result is 33 bytes long.
Finally, these bytes (from one of the two paragraphs above) go through the address conversion process described here in the bitcoin.org Developer Guide, which includes taking an irreversible cryptographic hash (actually, two hashes).
Note that in order to redeem a UTXO associated with a P2PKH address, the redeemer must create a transaction which includes the unhashed public key, either compressed or uncompressed. If such a tx exists in the blockchain, it can be connected to its "normal" base58check address. This is one of the reasons why address reuse is discouraged: once you redeem a UTXO, you "reveal" your public key, which is slightly more sensitive than your bitcoin address.
Given just the address itself, no, there is no way to tell if it was generated from a compressed or an uncompressed public key. This is calculated from the base58 encoding of the RIPEMD(SHA256(public_key_bytes)). Since the hash isn't reversible, without the public key already in hand, you won't be able to get any more information.
Just look at the base58 decoded data:
$ decodeBase58 12T15tvMGaymMX97X9KxVzyLF323r8v6Hg 000FE302E0D96D9F9AA71738A426A9696EB49AD458679BAFD3 $ decodeBase58 1D8VSXHFAWNhAbruwUMbNp4hsXAnRNkYvX 00850C296420DC9B02CE237ED630B89815E0803EA3BED0F344
The version byte is 0x00 in both, then there's the 20 bytes of the hash, and a 4 byte checksum. None of this reveals any information about what information was hashed.