summaryrefslogtreecommitdiff
path: root/utils.js
blob: ed21d468afd722840d5db1efea9e808097f57f98 (plain)
1
2
3
4
5
6
7
8
9
10
11
export function randomString() {
  return Math.random().toString(36).substr(2)
}

export async function sha256(input) {
  const encoder = new TextEncoder()
  const inputBytes = encoder.encode(input)
  const outputBuffer = await crypto.subtle.digest('SHA-256', inputBytes)
  const outputArray = Array.from(new Uint8Array(outputBuffer))
  return outputArray.map(b => b.toString(16).padStart(2, '0')).join('')
}