Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function toItxAddress(itx, type, role = types.RoleType.ROLE_TX) {
if (transactions.indexOf(type) === -1) {
throw new Error(`Unsupported itx type ${type}`);
}
const message = createMessage(type, itx);
// console.log({ message: message.toObject(), itx });
const itxBytes = message.serializeBinary();
const hash = Hasher.SHA3.hash256(itxBytes);
const address = fromHash(hash, role);
return address;
}
function toTetherAddress(hash) {
return fromHash(hash, types.RoleType.ROLE_TETHER);
}
function toSwapAddress(hash) {
return fromHash(hash, types.RoleType.ROLE_SWAP);
}
function toStakeAddress(sender, receiver) {
const senderBuffer = Buffer.from(sender);
const receiverBuffer = Buffer.from(receiver);
const buffer = Buffer.concat([senderBuffer, receiverBuffer]);
const hash = Hasher.SHA3.hash256(buffer);
return fromHash(hash, types.RoleType.ROLE_STAKE);
}
function toDelegateAddress(addr1, addr2) {
const addr1Buffer = Buffer.from(addr1);
const addr2Buffer = Buffer.from(addr2);
const buffer = Buffer.concat([addr1Buffer, addr2Buffer]);
const hash = Hasher.SHA3.hash256(buffer);
return fromHash(hash, types.RoleType.ROLE_DELEGATE);
}