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 @@ -128,6 +128,7 @@ +address: string, +message: string, +signature: string, + +nonceTimestamp: number, }; export type IdentityWalletRegisterInput = { diff --git a/native/account/siwe-panel.react.js b/native/account/siwe-panel.react.js --- a/native/account/siwe-panel.react.js +++ b/native/account/siwe-panel.react.js @@ -1,6 +1,7 @@ // @flow import BottomSheet from '@gorhom/bottom-sheet'; +import invariant from 'invariant'; import * as React from 'react'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import WebView from 'react-native-webview'; @@ -46,6 +47,11 @@ legacySiweAuthActionTypes, ); +type NonceInfo = { + +nonce: string, + +nonceTimestamp: number, +}; + type Props = { +onClosed: () => mixed, +onClosing: () => mixed, @@ -77,7 +83,7 @@ state => legacySiweAuthLoadingStatusSelector(state) === 'loading', ); - const [nonce, setNonce] = React.useState(null); + const [nonceInfo, setNonceInfo] = React.useState(null); const [primaryIdentityPublicKey, setPrimaryIdentityPublicKey] = React.useState(null); @@ -92,7 +98,7 @@ const generateNonce = async (nonceFunction: () => Promise) => { try { const response = await nonceFunction(); - setNonce(response); + setNonceInfo({ nonce: response, nonceTimestamp: Date.now() }); } catch (e) { Alert.alert( UnknownErrorAlertDetails.title, @@ -168,6 +174,7 @@ const closeBottomSheet = bottomSheetRef.current?.close; const { closing, onSuccessfulWalletSignature } = props; + const nonceTimestamp = nonceInfo?.nonceTimestamp; const handleMessage = React.useCallback( async (event: WebViewMessageEvent) => { const data: SIWEWebViewMessage = JSON.parse(event.nativeEvent.data); @@ -176,7 +183,13 @@ if (address && signature) { nonceNotNeededRef.current = true; closeBottomSheet?.(); - await onSuccessfulWalletSignature({ address, message, signature }); + invariant(nonceTimestamp, 'nonceTimestamp should be set'); + await onSuccessfulWalletSignature({ + address, + message, + signature, + nonceTimestamp, + }); } } else if (data.type === 'siwe_closed') { nonceNotNeededRef.current = true; @@ -194,6 +207,7 @@ onClosing, closeBottomSheet, walletConnectModalHeight, + nonceTimestamp, ], ); const prevClosingRef = React.useRef(); @@ -205,6 +219,7 @@ prevClosingRef.current = closing; }, [closing, closeBottomSheet]); + const nonce = nonceInfo?.nonce; const source = React.useMemo( () => ({ uri: commSIWE,