Download this file
| 1 | // Slide, block and asset ids (spec §2.2): 12 characters of lowercase |
| 2 | // base32, drawn from the platform's CSPRNG. The browser mints an id |
| 3 | // before it calls applyOps, because the core never draws entropy and an |
| 4 | // add_slide / add_block / duplicate_slide without ids is refused. |
| 5 | // generate.mjs never calls this: a vector's ids come from its data file |
| 6 | // so the vector is the same bytes every run. |
| 7 | |
| 8 | const ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567' |
| 9 | export const ID_LENGTH = 12 |
| 10 | |
| 11 | export function newID () { |
| 12 | const bytes = new Uint8Array(ID_LENGTH) |
| 13 | globalThis.crypto.getRandomValues(bytes) |
| 14 | let out = '' |
| 15 | for (const b of bytes) out += ALPHABET[b & 31] |
| 16 | return out |
| 17 | } |
| 18 | |