Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3502832
D5887.id19442.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D5887.id19442.diff
View Options
diff --git a/keyserver/src/creators/siwe-nonce-creator.js b/keyserver/src/creators/siwe-nonce-creator.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/creators/siwe-nonce-creator.js
@@ -0,0 +1,18 @@
+// @flow
+
+import { dbQuery, SQL } from '../database/database.js';
+
+async function createSIWENonceEntry(
+ walletAddress: string,
+ nonce: string,
+): Promise<void> {
+ const time = Date.now();
+ const query = SQL`
+ INSERT INTO siwe_nonces(ethereum_address, nonce, creation_time)
+ VALUES ${[[walletAddress, nonce, time]]}
+ ON DUPLICATE KEY UPDATE nonce=${nonce}, creation_time=${time}
+ `;
+ await dbQuery(query);
+}
+
+export { createSIWENonceEntry };
diff --git a/keyserver/src/responders/siwe-nonce-responders.js b/keyserver/src/responders/siwe-nonce-responders.js
--- a/keyserver/src/responders/siwe-nonce-responders.js
+++ b/keyserver/src/responders/siwe-nonce-responders.js
@@ -9,6 +9,7 @@
} from 'lib/types/siwe-types.js';
import { tShape } from 'lib/utils/validation-utils';
+import { createSIWENonceEntry } from '../creators/siwe-nonce-creator.js';
import type { Viewer } from '../session/viewer.js';
import { validateInput } from '../utils/validation-utils.js';
@@ -21,6 +22,9 @@
): Promise<SIWENonceResponse> {
const request: SIWENonceRequest = input;
await validateInput(viewer, siweNonceRequestInputValidator, request);
+ const { walletAddress } = request;
+ const generatedNonce = generateNonce();
+ await createSIWENonceEntry(walletAddress, generatedNonce);
return { nonce: generateNonce() };
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 21, 5:09 AM (18 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2686032
Default Alt Text
D5887.id19442.diff (1 KB)
Attached To
Mode
D5887: [keyserver] Introduce `createSIWENonceEntry` to persist nonce in DB
Attached
Detach File
Event Timeline
Log In to Comment