Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 1x 1x 1x 5x 5x 5x 76x 1x 3x 3x 3x | import base64url from 'base64url'
import { encode } from 'base64-arraybuffer'
export async function getRandomString (length: number): Promise<string> {
const numBytes = Math.floor(length / 2)
const array = new Uint8Array(numBytes)
window.crypto.getRandomValues(array)
return ([...array].map(x => x.toString(16).padStart(2, '0')).join(''))
}
export async function createHash (payload: string): Promise<string> {
const data = new TextEncoder().encode(payload)
const digest = await window.crypto.subtle.digest('SHA-256', data)
return base64url.fromBase64(encode(digest))
}
|