Qortal UI - Main Code Repository A User Interface for the Qortal Blockchain Project. Truly decentralized web hosting, application hosting, communications, data storage, and full infrastructure for the future global decentralized digital world.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

35 lines
1.1 KiB

import Base58 from '../deps/Base58.js'
import BROKEN_RIPEMD160 from '../deps/broken-ripemd160.js'
import RIPEMD160 from '../deps/ripemd160.js'
import utils from '../deps/utils.js'
import { ADDRESS_VERSION } from '../constants.js'
import { Buffer } from 'buffer'
import { Sha256 } from 'asmcrypto.js'
const repeatSHA256 = (passphrase, hashes) => {
let hash = passphrase
for (let i = 0; i < hashes; i++) {
hash = new Sha256().process(hash).finish().result
}
return hash
}
const publicKeyToAddress = (publicKey, qora = false) => {
const publicKeySha256 = new Sha256().process(publicKey).finish().result
const _publicKeyHash = qora ? new BROKEN_RIPEMD160().digest(publicKeySha256) : new RIPEMD160().update(Buffer.from(publicKeySha256)).digest('hex')
const publicKeyHash = qora ? _publicKeyHash : _publicKeyHash
let address = new Uint8Array()
address = utils.appendBuffer(address, [ADDRESS_VERSION])
address = utils.appendBuffer(address, publicKeyHash)
const checkSum = repeatSHA256(address, 2)
address = utils.appendBuffer(address, checkSum.subarray(0, 4))
address = Base58.encode(address)
return address
}
export default publicKeyToAddress