diff --git a/web/account/siwe.react.js b/web/account/siwe.react.js --- a/web/account/siwe.react.js +++ b/web/account/siwe.react.js @@ -9,6 +9,7 @@ RainbowKitProvider, useConnectModal, } from '@rainbow-me/rainbowkit'; +import invariant from 'invariant'; import _merge from 'lodash/fp/merge'; import * as React from 'react'; import { FaEthereum } from 'react-icons/fa'; @@ -16,6 +17,7 @@ chain, configureChains, createClient, + useAccount, useSigner, WagmiConfig, } from 'wagmi'; @@ -31,7 +33,11 @@ useDispatchActionPromise, useServerCall, } from 'lib/utils/action-utils'; -import { siweMessageSigningExplanationStatements } from 'lib/utils/siwe-utils.js'; +import { + createSIWEMessage, + siweMessageSigningExplanationStatements, + siweStatementWithoutPublicKey, +} from 'lib/utils/siwe-utils.js'; import Button from '../components/button.react'; import LoadingIndicator from '../loading-indicator.react'; @@ -58,11 +64,24 @@ provider, }); +async function signInWithEthereum( + address: string, + signer, + nonce: string, + statement: string, +) { + invariant(nonce, 'nonce must be present during SIWE attempt'); + const message = createSIWEMessage(address, statement, nonce); + const signature = await signer.signMessage(message); + console.log(signature); +} + const getSIWENonceLoadingStatusSelector = createLoadingStatusSelector( getSIWENonceActionTypes, ); function SIWE(): React.Node { const { openConnectModal } = useConnectModal(); + const { address } = useAccount(); const { data: signer } = useSigner(); const dispatchActionPromise = useDispatchActionPromise(); const getSIWENonceCall = useServerCall(getSIWENonce); @@ -91,6 +110,16 @@ [], ); + const onSignInButtonClick = React.useCallback(() => { + invariant(siweNonce, 'nonce must be present during SIWE attempt'); + signInWithEthereum( + address, + signer, + siweNonce, + siweStatementWithoutPublicKey, + ); + }, [address, signer, siweNonce]); + let siweLoginForm; if (signer && !siweNonce) { siweLoginForm = ( @@ -109,7 +138,7 @@
{siweMessageSigningExplanationStatements[0]}
{siweMessageSigningExplanationStatements[1]}
-