diff options
author | theia | 2022-08-05 17:00:45 -0400 |
---|---|---|
committer | theia | 2022-08-05 17:00:45 -0400 |
commit | 6b636c909c2cb61bcb2f6f60fb911b94774c9cf1 (patch) | |
tree | 49043270c3cec35fb59beaec66d1a5a5fed874a1 | |
parent | 375637fd8e84e628c5ed565f651c43ebf2c37869 (diff) |
using crypto for random string
-rw-r--r-- | auth.js | 8 | ||||
-rw-r--r-- | graffiti.js | 6 |
2 files changed, 5 insertions, 9 deletions
@@ -2,8 +2,8 @@ export default { async logIn(graffitiURL) { // Generate a random client secret and state - const clientSecret = this.randomString() - const state = this.randomString() + const clientSecret = crypto.randomUUID() + const state = crypto.randomUUID() // The client ID is the secret's hex hash const clientID = await this.sha256(clientSecret) @@ -114,10 +114,6 @@ export default { return url }, - randomString() { - return Math.random().toString(36).substr(2) - }, - async sha256(input) { const encoder = new TextEncoder() const inputBytes = encoder.encode(input) diff --git a/graffiti.js b/graffiti.js index 1b3365e..94e1ebe 100644 --- a/graffiti.js +++ b/graffiti.js @@ -52,7 +52,7 @@ export default class { async request(msg) { // Create a random message ID - const messageID = Auth.randomString() + const messageID = crypto.randomUUID() // Create a listener for the reply const dataPromise = new Promise(resolve => { @@ -149,7 +149,7 @@ export default class { queryID=null) { // Create a random query ID - if (!queryID) queryID = Auth.randomString() + if (!queryID) queryID = crypto.randomUUID() // Send the request await this.request({ @@ -209,7 +209,7 @@ export default class { } // Pre-generate the object's ID if it does not already exist - if (!object._id) object._id = Auth.randomString() + if (!object._id) object._id = crypto.randomUUID() } // Utility function to get a universally unique string |