Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function calcBlockSha256Hash(blockHeader) {
const headerBin = module.exports.fromHex(blockHeader).slice(0, 80);
return `0x${Buffer.from(sha256.array(sha256.arrayBuffer(headerBin))).reverse().toString('hex')}`;
}
export async function generateSeeds(context: WhiteListContext) {
feedbackModule.setTask(i18n.t("feedback_msg.task.new_key").toString())
feedbackModule.setStep(i18n.t("feedback_msg.step.generating_new_key").toString())
const mnemonic = generateMnemonic()
const seed = mnemonicToSeedSync(mnemonic)
const privateKeyUint8ArrayFromSeed = CryptoUtils.generatePrivateKeyFromSeed(new Uint8Array(sha256.array(seed)))
const privateKeyB64 = CryptoUtils.Uint8ArrayToB64(privateKeyUint8ArrayFromSeed)
const publicKey = await plasmaModule.getPublicAddrePriaKeyUint8Array({ privateKey: privateKeyUint8ArrayFromSeed })
feedbackModule.endTask()
context.state.seed.mnemonic = mnemonic
context.state.seed.publicAddress = publicKey
}
const hashDelegateTransaction = (unsignedTransaction: IDelegateCandidate): string => {
const { timestamp, fee, senderAddress, amount, delegateKey } = unsignedTransaction;
const byteArray = [
...toByteArray(timestamp),
...toByteArray(fee),
...toByteArray(senderAddress),
...toByteArray(delegateKey),
...toByteArray(amount),
];
return sha256(sha256.array(byteArray));
};
const hashTransaction = (unsignedTransaction: IUnsignedTransaction): string => {
const { timestamp, fee, senderAddress, amount, recipientAddress, data } = unsignedTransaction;
let byteArray = [
...toByteArray(timestamp),
...toByteArray(fee),
...toByteArray(senderAddress),
...toByteArray(amount)
];
if (recipientAddress) {
byteArray = [...byteArray, ...toByteArray(recipientAddress)]
}
if (data) {
byteArray = [...byteArray, ...toByteArray(data)]
}
return sha256(sha256.array(byteArray));
};