diff --git a/landing/siwe.react.js b/landing/siwe.react.js --- a/landing/siwe.react.js +++ b/landing/siwe.react.js @@ -25,7 +25,10 @@ import { publicProvider } from 'wagmi/providers/public'; import type { SIWEWebViewMessage } from 'lib/types/siwe-types'; -import { siweStatement } from 'lib/utils/siwe-utils.js'; +import { + getSIWEStatementForPublicKey, + siweStatementWithoutPublicKey, +} from 'lib/utils/siwe-utils.js'; import { SIWEContext } from './siwe-context.js'; import css from './siwe.css'; @@ -70,9 +73,14 @@ window.ReactNativeWebView?.postMessage?.(JSON.stringify(message)); } -async function signInWithEthereum(address: string, signer, nonce: string) { +async function signInWithEthereum( + address: string, + signer, + nonce: string, + statement: string, +) { invariant(nonce, 'nonce must be present in signInWithEthereum'); - const message = createSiweMessage(address, siweStatement, nonce); + const message = createSiweMessage(address, statement, nonce); const signature = await signer.signMessage(message); postMessageToNativeWebView({ type: 'siwe_success', @@ -85,11 +93,16 @@ function SIWE(): React.Node { const { address } = useAccount(); const { data: signer } = useSigner(); - const { siweNonce } = React.useContext(SIWEContext); + const { siweNonce, siwePrimaryIdentityPublicKey } = React.useContext( + SIWEContext, + ); const onClick = React.useCallback(() => { invariant(siweNonce, 'nonce must be present during SIWE attempt'); - signInWithEthereum(address, signer, siweNonce); - }, [address, signer, siweNonce]); + const statement = siwePrimaryIdentityPublicKey + ? getSIWEStatementForPublicKey(siwePrimaryIdentityPublicKey) + : siweStatementWithoutPublicKey; + signInWithEthereum(address, signer, siweNonce, statement); + }, [address, signer, siweNonce, siwePrimaryIdentityPublicKey]); const { openConnectModal } = useConnectModal(); const hasNonce = siweNonce !== null && siweNonce !== undefined; diff --git a/lib/utils/siwe-utils.js b/lib/utils/siwe-utils.js --- a/lib/utils/siwe-utils.js +++ b/lib/utils/siwe-utils.js @@ -20,7 +20,7 @@ return primaryIdentityPublicKeyRegex.test(candidate); } -const siweStatement: string = +const siweStatementWithoutPublicKey: string = 'By continuing, I accept the Comm Terms of Service: https://comm.app/terms'; const expectedDomain = isDev ? 'localhost:3000' : 'comm.app'; @@ -29,7 +29,10 @@ // Verify that the SIWEMessage is a well formed Comm SIWE Auth message. function isValidSIWEMessage(candidate: SIWEMessage): boolean { return ( - candidate.statement === siweStatement && + (candidate.statement === siweStatementWithoutPublicKey || + (candidate.statement !== null && + candidate.statement !== undefined && + isValidSIWEStatementWithPublicKey(candidate.statement))) && candidate.version === '1' && candidate.chainId === 1 && candidate.domain === expectedDomain && @@ -44,7 +47,7 @@ isValidPrimaryIdentityPublicKey(publicKey), 'publicKey must be well formed in getSIWEStatementForPublicKey', ); - return `Device IdPubKey: ${publicKey} ${siweStatement}`; + return `Device IdPubKey: ${publicKey} ${siweStatementWithoutPublicKey}`; } const siweStatementWithPublicKeyRegex = /^Device IdPubKey: [a-zA-Z0-9+/]{43} By continuing, I accept the Comm Terms of Service: https:\/\/comm.app\/terms$/; @@ -69,7 +72,7 @@ } export { - siweStatement, + siweStatementWithoutPublicKey, isValidSIWENonce, isValidEthereumAddress, isValidPrimaryIdentityPublicKey,