diff options
Diffstat (limited to 'utils.js')
-rw-r--r-- | utils.js | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/utils.js b/utils.js new file mode 100644 index 0000000..ed21d46 --- /dev/null +++ b/utils.js @@ -0,0 +1,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('') +} |