With Bitcoin one public key can give two different addresses. It will depend if the public key has been hashed first or not.
const bs58check = require('bs58check')
const RIPEMD160 = require('ripemd160')
const crypto = require('crypto')
function hashing (buf) {
let hash = crypto.createHash('sha256').update(buf).digest()
hash = new RIPEMD160().update(hash).digest()
return hash
}
function pubkeyToPubkeyHash (pubkey) {
return hashing(pubkey)
}
function pubkeyToAddress (pubkey, hash = false) {
let pubKeyHash = pubkey
if (!hash) {
pubKeyHash = pubkeyToPubkeyHash(pubkey)
}
networkByte = Buffer.from("6f", 'hex') // '6f' is for regtest and testnet '00' is for mainnet
const temp = Buffer.concat([networkByte, pubKeyHash])
return bs58check.encode(temp)