Address-Generation

如何生成破折號地址?

  • July 7, 2021

如何從公鑰生成簡單的破折號地址?

破折號中有多少種地址格式?

破折號中有多少種地址格式?

在地址和交易格式方面,Dash 似乎與比特幣非常相似。你有典型的 P2PK、P2PKH、P2SH。

以下是如何生成標準 P2PKH 地址(因此也是 P2PK 地址)。

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);

請注意,這與派生比特幣地址之間的唯一區別是版本字節不是 0x00 而是 0x4c 以及派生路徑硬幣索引為 5 而不是 0。

引用自:https://bitcoin.stackexchange.com/questions/77317