summaryrefslogtreecommitdiff
path: root/static/main.js
blob: e00efd4ba3432323898d52f2b8f0b6e8a3629487 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
// Generate random token string 

const KEY_LENGTH = 20;
const ALPHABET_BASE58 = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';

function genToken() {
  const rand_buffer = Array.from(window.crypto.getRandomValues(new Uint32Array(KEY_LENGTH)));
  const rand_chars = rand_buffer.map(elem => ALPHABET_BASE58.charAt(Math.round(elem/4294967295*58)));
  const token = rand_chars.join("");

  document.getElementById("tokenField").value = token;
}