Post
Topic
Board Development & Technical Discussion
Re: Generating a Bitcoin address with Node JS **UPDATED**
by
Entontothekeseczi
on 06/12/2020, 17:25:13 UTC
Code:
const hdkey = HDkey.fromMasterSeed(seed)

const addrnode = hdkey.derive("m/44'/0'/0'/0")

console.log("\x1b[32m%s\x1b[0m",'PRIVATE EXTENDED : ', addrnode.privateExtendedKey)

const child = addrnode.derive("m/0");
const step1 = child._publicKey

console.log("\x1b[32m%s\x1b[0m",'PUBLIC EXTENDED : ', step1.toString('hex'))

//SHA256 of the public key
const step2 = createHash('sha256').update(step1).digest()

// RIPEDMD-160 of the SHA256 Hash
const step3 = createHash('rmd160').update(step2).digest()

// He we must add the network byte in front of that RIPEDMD result
// 0x00 for mainnet and 0x6f for testnet
var step4 = Buffer.allocUnsafe(21)
step4.writeUInt8(0x00, 0)
step3.copy(step4, 1)

// Return the bitcoins address
var step9 = bs58check.encode(step4)


resolve(step9)