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.

36 lines
1.1 KiB

import Base58 from '../deps/Base58.js'
3 years ago
import BROKEN_RIPEMD160 from '../deps/broken-ripemd160.js'
import RIPEMD160 from '../deps/ripemd160.js'
3 years ago
import utils from '../deps/utils.js'
11 months ago
import {ADDRESS_VERSION} from '../constants.js'
import {Buffer} from 'buffer'
import {Sha256} from 'asmcrypto.js'
3 years ago
const repeatSHA256 = (passphrase, hashes) => {
let hash = passphrase
for (let i = 0; i < hashes; i++) {
hash = new Sha256().process(hash).finish().result
}
return hash
3 years ago
}
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
3 years ago
let address = new Uint8Array()
3 years ago
address = utils.appendBuffer(address, [ADDRESS_VERSION])
address = utils.appendBuffer(address, publicKeyHash)
3 years ago
const checkSum = repeatSHA256(address, 2)
address = utils.appendBuffer(address, checkSum.subarray(0, 4))
3 years ago
address = Base58.encode(address)
3 years ago
return address
3 years ago
}
export default publicKeyToAddress