diff options
author | theia | 2022-08-05 14:29:00 -0400 |
---|---|---|
committer | theia | 2022-08-05 14:29:00 -0400 |
commit | 375637fd8e84e628c5ed565f651c43ebf2c37869 (patch) | |
tree | c90b8a14dfcfcf12b3b8e6e62a47a892fd472834 | |
parent | ac98f1499e4c38c89f555338a2edf8203d28bb8b (diff) |
removed utils
-rw-r--r-- | auth.js | 20 | ||||
-rw-r--r-- | graffiti.js | 7 | ||||
-rw-r--r-- | utils.js | 11 |
3 files changed, 18 insertions, 20 deletions
@@ -1,14 +1,12 @@ -import { randomString, sha256 } from './utils.js' - export default { async logIn(graffitiURL) { // Generate a random client secret and state - const clientSecret = randomString() - const state = randomString() + const clientSecret = this.randomString() + const state = this.randomString() // The client ID is the secret's hex hash - const clientID = await sha256(clientSecret) + const clientID = await this.sha256(clientSecret) // Store the client secret as a local variable window.localStorage.setItem('graffitiClientSecret', clientSecret) @@ -116,4 +114,16 @@ export default { return url }, + randomString() { + return Math.random().toString(36).substr(2) + }, + + async 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('') + } + } diff --git a/graffiti.js b/graffiti.js index 0180a87..1b3365e 100644 --- a/graffiti.js +++ b/graffiti.js @@ -1,5 +1,4 @@ import Auth from './auth.js' -import { randomString } from './utils.js' export default class { @@ -53,7 +52,7 @@ export default class { async request(msg) { // Create a random message ID - const messageID = randomString() + const messageID = Auth.randomString() // Create a listener for the reply const dataPromise = new Promise(resolve => { @@ -150,7 +149,7 @@ export default class { queryID=null) { // Create a random query ID - if (!queryID) queryID = randomString() + if (!queryID) queryID = Auth.randomString() // Send the request await this.request({ @@ -210,7 +209,7 @@ export default class { } // Pre-generate the object's ID if it does not already exist - if (!object._id) object._id = randomString() + if (!object._id) object._id = Auth.randomString() } // Utility function to get a universally unique string diff --git a/utils.js b/utils.js deleted file mode 100644 index ed21d46..0000000 --- a/utils.js +++ /dev/null @@ -1,11 +0,0 @@ -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('') -} |