diff --git a/keyserver/src/deleters/siwe-nonce-deleters.js b/keyserver/src/deleters/siwe-nonce-deleters.js --- a/keyserver/src/deleters/siwe-nonce-deleters.js +++ b/keyserver/src/deleters/siwe-nonce-deleters.js @@ -1,12 +1,12 @@ // @flow -import { dbQuery, SQL } from '../database/database.js'; +import { legacyKeyserverSIWENonceLifetime } from 'lib/types/siwe-types.js'; -// 30 minutes = 30min * 60sec * 1000ms -export const nonceLifetime = 30 * 60 * 1000; +import { dbQuery, SQL } from '../database/database.js'; async function deleteStaleSIWENonceEntries(): Promise { - const earliestValidCreationTime = Date.now() - nonceLifetime; + const earliestValidCreationTime = + Date.now() - legacyKeyserverSIWENonceLifetime; const query = SQL` DELETE FROM siwe_nonces WHERE creation_time < ${earliestValidCreationTime} @@ -17,7 +17,8 @@ async function checkAndInvalidateSIWENonceEntry( nonce: string, ): Promise { - const earliestValidCreationTime = Date.now() - nonceLifetime; + const earliestValidCreationTime = + Date.now() - legacyKeyserverSIWENonceLifetime; const query = SQL` DELETE FROM siwe_nonces WHERE nonce = ${nonce} AND creation_time > ${earliestValidCreationTime} diff --git a/lib/types/siwe-types.js b/lib/types/siwe-types.js --- a/lib/types/siwe-types.js +++ b/lib/types/siwe-types.js @@ -149,3 +149,6 @@ +message: string, +signature: string, }; + +export const legacyKeyserverSIWENonceLifetime = 30 * 60 * 1000; // 30 minutes +export const identitySIWENonceLifetime = 2 * 60 * 1000; // 2 minutes diff --git a/native/account/registration/ethereum-utils.js b/native/account/registration/ethereum-utils.js --- a/native/account/registration/ethereum-utils.js +++ b/native/account/registration/ethereum-utils.js @@ -4,7 +4,12 @@ import * as React from 'react'; import { ENSCacheContext } from 'lib/components/ens-cache-provider.react.js'; -import type { SIWEResult } from 'lib/types/siwe-types.js'; +import { + type SIWEResult, + identitySIWENonceLifetime, + legacyKeyserverSIWENonceLifetime, +} from 'lib/types/siwe-types.js'; +import { usingCommServicesAccessToken } from 'lib/utils/services-utils.js'; import { RegistrationContext } from './registration-context.js'; import { @@ -57,4 +62,11 @@ ); } -export { useGetEthereumAccountFromSIWEResult }; +function siweNonceExpired(nonceTimestamp: number): boolean { + const nonceLifetime = usingCommServicesAccessToken + ? identitySIWENonceLifetime + : legacyKeyserverSIWENonceLifetime; + return Date.now() > nonceTimestamp + nonceLifetime; +} + +export { useGetEthereumAccountFromSIWEResult, siweNonceExpired };