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 @@ -2,6 +2,7 @@ import '@rainbow-me/rainbowkit/dist/index.css'; +import olm from '@matrix-org/olm'; import { ConnectButton, darkTheme, @@ -28,8 +29,8 @@ } from 'lib/utils/action-utils'; import { createSIWEMessage, + getSIWEStatementForPublicKey, siweMessageSigningExplanationStatements, - siweStatementWithoutPublicKey, } from 'lib/utils/siwe-utils.js'; import Button from '../components/button.react'; @@ -55,6 +56,10 @@ const logInExtraInfo = useSelector(webLogInExtraInfoSelector); const [siweNonce, setSIWENonce] = React.useState(null); + const [ + primaryIdentityPublicKey, + setPrimaryIdentityPublicKey, + ] = React.useState(null); const [ hasSIWEButtonBeenClicked, setHasSIWEButtonBeenClicked, @@ -78,6 +83,16 @@ ); }, [dispatchActionPromise, getSIWENonceCall, siweNonceShouldBeFetched]); + React.useEffect(() => { + (async () => { + await olm.init(); + const account = new olm.Account(); + account.create(); + const { ed25519 } = JSON.parse(account.identity_keys()); + setPrimaryIdentityPublicKey(ed25519); + })(); + }, []); + const siweButtonColor = React.useMemo( () => ({ backgroundColor: 'white', color: 'black' }), [], @@ -108,23 +123,21 @@ const onSignInButtonClick = React.useCallback(async () => { invariant(siweNonce, 'nonce must be present during SIWE attempt'); - const message = createSIWEMessage( - address, - siweStatementWithoutPublicKey, - siweNonce, + invariant( + primaryIdentityPublicKey, + 'primaryIdentityPublicKey must be present during SIWE attempt', ); + const statement = getSIWEStatementForPublicKey(primaryIdentityPublicKey); + const message = createSIWEMessage(address, statement, siweNonce); const signature = await signer.signMessage(message); attemptSIWEAuth(message, signature); - }, [address, attemptSIWEAuth, signer, siweNonce]); + }, [address, attemptSIWEAuth, primaryIdentityPublicKey, signer, siweNonce]); let siweLoginForm; - if (signer && !siweNonce) { + if (signer && (!siweNonce || !primaryIdentityPublicKey)) { siweLoginForm = (
- +
); } else if (signer) { @@ -133,6 +146,7 @@
+

{primaryIdentityPublicKey}

{siweMessageSigningExplanationStatements[0]}

{siweMessageSigningExplanationStatements[1]}