Page MenuHomePhabricator

D5887.id19442.diff
No OneTemporary

D5887.id19442.diff

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

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)

Event Timeline