How can I generate a simple dash address from a public key?

How many address formats are there in dash?


How many address formats are there in dash?

Dash seems to be pretty similar to bitcoin when it comes to address and transaction formats. You have your typical P2PK, P2PKH, P2SH.

Here is how to generate a standard P2PKH address (and therefore also a P2PK address).

var bip39 = require('bip39');
var hdkey = require('hdkey');
var createHash = require('create-hash');
var bs58check = require('bs58check');

//const mnemonic = bip39.generateMnemonic(); //generates string
const mnemonic = 'thunder purchase pave tower lecture upgrade supreme half kid fitness tray shove'
const seed = bip39.mnemonicToSeedSync(mnemonic); //creates seed buffer
console.log('mnemonic: ' + mnemonic);

const root = hdkey.fromMasterSeed(seed);
const masterPrivateKey = root.privateKey.toString('hex');
//console.log('extended public key root:  ' + root.publicExtendedKey)

const addrnode = root.derive("m/44'/5'/0'/0/0");
console.log('addrnodePublicKey: '+ addrnode._publicKey.toString('hex'))
console.log('addernodePrivateKey: ' + addrnode._privateKey.toString('hex'))

const step1 = addrnode._publicKey;
const step2 = createHash('sha256').update(step1).digest();
const step3 = createHash('rmd160').update(step2).digest();

var step4 = Buffer.allocUnsafe(21);
step4.writeUInt8(0x4c, 0); 
step3.copy(step4, 1); //step4 now holds the extended RIPMD-160 result
const step9 = bs58check.encode(step4);
console.log('\n\n\nmnemonic: ',mnemonic,  '\npath: ', path, '\naddernodePrivateKey: ' , addrnode._privateKey.toString('hex'), '\naddrnodePublicKey: ', addrnode._publicKey.toString('hex'), '\nBase58Check: ' + step9);

Notice the only difference between this and deriving a bitcoin address is the version bytes is not 0x00 but instead 0x4c & the derivation path coin index of 5 instead of 0.


Let's assume the private key is one of the worst low entropy private keys for demonstrative purposes is 0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff.

1. Dash P2PKH Address Calculation:

% echo 0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff | bx ec-to-public | bx ec-to-address -v 76


2. Dash Single Signature P2SH Address Calculation:

% echo 0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff | bx ec-to-public 020d47568a5e517067a2836c3823fbc58169a7662bfae934a4d41da3e23c98d816

% echo "[020d47568a5e517067a2836c3823fbc58169a7662bfae934a4d41da3e23c98d816] checksig" | bx script-to-address -v 16


Wonder where the 76 and 16 version numbers came from?
See the Dash row within https://github.com/libbitcoin/libbitcoin-system/wiki/Altcoin-Version-Mappings#bip44-altcoin-version-mapping-table.

Not the answer you're looking for? Browse other questions tagged or ask your own question.