mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-09-08 02:50:38 +00:00
Redsign qortal-ui repo
This commit is contained in:
8
crypto/api/wallet/base58PublicKeyToAddress.js
Normal file
8
crypto/api/wallet/base58PublicKeyToAddress.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import publicKeyToAddress from './publicKeyToAddress'
|
||||
import Base58 from '../deps/Base58.js'
|
||||
|
||||
export const base58PublicKeyToAddress = (base58pubkey, qora = false) => {
|
||||
const decodePubKey = Base58.decode(base58pubkey)
|
||||
const address = publicKeyToAddress(decodePubKey, qora)
|
||||
return address
|
||||
}
|
35
crypto/api/wallet/publicKeyToAddress.js
Normal file
35
crypto/api/wallet/publicKeyToAddress.js
Normal file
@@ -0,0 +1,35 @@
|
||||
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
|
10
crypto/api/wallet/validateAddress.js
Normal file
10
crypto/api/wallet/validateAddress.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import Base58 from '../deps/Base58.js'
|
||||
|
||||
export const validateAddress = (address) => {
|
||||
const decodePubKey = Base58.decode(address)
|
||||
|
||||
if (!(decodePubKey instanceof Uint8Array && decodePubKey.length == 25)) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user