Address Conversion

The hashes used in P2PKH and P2SH outputsP2SH outputs - A Dash payment address comprising a hashed script, allowing the spender to create a standard pubkey script that Pays To Script Hash (P2SH). The script can be almost any valid pubkey script. are commonly encoded as Dash addressesaddresses - A 20-byte hash formatted using base58check to produce either a P2PKH or P2SH Dash address. Currently the most common way users exchange payment information.. This is the procedure to encode those hashes and decode the addresses.

Conversion Process

First, get your hash. For P2PKH, you RIPEMD-160(SHA256()) hash a ECDSA public keypublic key - The public portion of a keypair which can be used to verify signatures made with the private portion of the keypair. derived from your 256-bit ECDSA private keyprivate key - The private portion of a keypair which can create signatures that other people can verify using the public key. (random data). For P2SH, you RIPEMD-160(SHA256()) hash a redeem scriptredeem script - A script similar in function to a pubkey script. One copy of it is hashed to create a P2SH address (used in an actual pubkey script) and another copy is placed in the spending signature script to enforce its conditions. serialized in the format used in raw transactionsraw transactions - Complete transactions in their binary format; often represented using hexadecimal. Sometimes called raw format because of the various Dash Core commands with "raw" in their names. (described in a following sub-section). Taking the resulting hash:

  1. Add an addressaddress - A 20-byte hash formatted using base58check to produce either a P2PKH or P2SH Dash address. Currently the most common way users exchange payment information. version byte in front of the hash. The version bytes commonly used by Dash are:

    • 0x4c for P2PKH addressesP2PKH addresses - A Dash payment address comprising a hashed public key, allowing the spender to create a standard pubkey script that Pays To PubKey Hash (P2PKH). on the main Dash network (mainnetmainnet - The original and main network for Dash transactions, where duffs have real economic value.)

    • 0x8c for P2PKH addressesP2PKH addresses - A Dash payment address comprising a hashed public key, allowing the spender to create a standard pubkey script that Pays To PubKey Hash (P2PKH). on the Dash testing network (testnettestnet - A global testing environment in which developers can obtain and spend duffs that have no real-world value on a network that is very similar to the Dash mainnet.)

    • 0x10 for P2SH addressesP2SH addresses - A Dash payment address comprising a hashed script, allowing the spender to create a standard pubkey script that Pays To Script Hash (P2SH). The script can be almost any valid pubkey script. on mainnetmainnet - The original and main network for Dash transactions, where duffs have real economic value.

    • 0x13 for P2SH addressesP2SH addresses - A Dash payment address comprising a hashed script, allowing the spender to create a standard pubkey script that Pays To Script Hash (P2SH). The script can be almost any valid pubkey script. on testnettestnet - A global testing environment in which developers can obtain and spend duffs that have no real-world value on a network that is very similar to the Dash mainnet.

  2. Create a copy of the version and hash; then hash that twice with SHA256: SHA256(SHA256(version . hash))

  3. Extract the first four bytes from the double-hashed copy. These are used as a checksum to ensure the base hash gets transmitted correctly.

  4. Append the checksum to the version and hash, and encode it as a base58base58 - The method used in Dash for converting 160-bit hashes into P2PKH and P2SH addresses. Also used in other parts of Dash, such as encoding private keys for backup in WIP format. Not the same as other base58 implementations. string: BASE58(version . hash . checksum)

Example Code

Dash's base58 encoding, called Base58CheckBase58Check - The method used in Dash for converting 160-bit hashes into P2PKH and P2SH addresses. Also used in other parts of Dash, such as encoding private keys for backup in WIP format. Not the same as other base58 implementations. may not match other implementations. Tier Nolan provided the following example encoding algorithm to the Bitcoin Wiki Base58Check encoding page under the Creative Commons Attribution 3.0 license:

code_string = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
x = convert_bytes_to_big_integer(hash_result)

output_string = ""

while(x > 0)
   {
       (x, remainder) = divide(x, 58)
       output_string.append(code_string[remainder])
   }

repeat(number_of_leading_zero_bytes_in_hash)
   {
   output_string.append(code_string[0]);
   }

output_string.reverse();

Dash's own code can be traced using the base58 header file.

To convert addresses back into hashes, reverse the base58 encoding, extract the checksum, repeat the steps to create the checksum and compare it against the extracted checksum, and then remove the version byte.


Did this page help you?