Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getPublicAccountID(accountPublicKeyBytes, prefix = "xrb") {
const accountHex = uint8ToHex(accountPublicKeyBytes)
const keyBytes = uint4ToUint8(hexToUint4(accountHex)) // For some reason here we go from u, to hex, to 4, to 8??
const checksum = uint5ToString(
uint4ToUint5(uint8ToUint4(blake.blake2b(keyBytes, null, 5).reverse()))
)
const account = uint5ToString(uint4ToUint5(hexToUint4(`0${accountHex}`)))
return `${prefix}_${account}${checksum}`
}
function getPublicAccountID(accountPublicKeyBytes, prefix = 'nano') {
const accountHex = util.uint8.toHex(accountPublicKeyBytes);
const keyBytes = util.uint4.toUint8(util.hex.toUint4(accountHex)); // For some reason here we go from u, to hex, to 4, to 8??
const checksum = util.uint5.toString(util.uint4.toUint5(util.uint8.toUint4(blake.blake2b(keyBytes, null, 5).reverse())));
const account = util.uint5.toString(util.uint4.toUint5(util.hex.toUint4(`0${accountHex}`)));
return `${prefix}_${account}${checksum}`;
}
export function simpleHash(payload: Buffer, length: number) : Buffer {
return Buffer.from(blakejs.blake2b(payload, null, length)); // Same as libsodium.crypto_generichash
}
export default function blake2bAsU8a (data: Uint8Array | string, bitLength: number = 512, key: Uint8Array | null = null): Uint8Array {
return blakejs.blake2b(data, key, bitLength / 8);
}
function addressHash(input) {
const serializedInput = cbor.encode(input)
const firstHash = Buffer.from(sha3.sha3_256(serializedInput), 'hex')
return Buffer.from(blakejs.blake2b(firstHash, null, 28))
}
function accountFromHexKey (hex) {
let key_bytes = uint4_uint8( hex_uint4 (hex) );
let checksum = uint5_string( uint4_uint5( uint8_uint4( blake.blake2b(key_bytes, null, 5).reverse() ) ) );
let c_account = uint5_string( uint4_uint5( hex_uint4 ('0' + hex) ) );
return 'xrb_' + c_account + checksum;
}
function hashBlake2b256(input) {
return Buffer.from(blakejs.blake2b(cbor.encode(input), null, 32))
}
function chainCodeFor(x) {
let r = encode(x)
if (r.length <= 32) {
r = [...r]
while (r.length < 32) {
r.push(0)
}
r = new Uint8Array(r)
} else {
r = blake2b(r)
}
return r
}