reverseqr

qr codes working in both directions
git clone https://tongong.net/git/reverseqr.git
Log | Files | Refs | README

navigation.js (508B)


      1 function generateId() {
      2     let arr = new Uint8Array(32);
      3     window.crypto.getRandomValues(arr);
      4     return Array.from(arr)
      5         .flatMap(e => [e % 16, e >> 4])
      6         .map(e => "0123456789abcdef"[e])
      7         .join("");
      8 }
      9 
     10 function isIdValid(id) {
     11     if (id.length != 64) return false;
     12     return id.split("").every(e => "0123456789abcdef".includes(e));
     13 }
     14 
     15 function splitId(id) {
     16     return [id.substring(0,32), id.substring(32,64)];
     17 }
     18 
     19 module.exports = {
     20     generateId,
     21     isIdValid,
     22     splitId,
     23 }