Commit 6d0bb257 authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate random to TS

parent 4f013030
/** @param {number} val */
function byteToHex(val) {
function byteToHex(val: number): string {
const str = val.toString(16);
return str.length === 1 ? '0' + str : str;
}
......@@ -7,10 +6,9 @@ function byteToHex(val) {
/**
* Generate a random hex string of `len` chars.
*
* @param {number} len - An even-numbered length string to generate.
* @return {string}
* @param len - An even-numbered length string to generate.
*/
export function generateHexString(len) {
export function generateHexString(len: number): string {
const bytes = new Uint8Array(len / 2);
window.crypto.getRandomValues(bytes);
return Array.from(bytes).map(byteToHex).join('');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment