diff --git a/landing/package.json b/landing/package.json --- a/landing/package.json +++ b/landing/package.json @@ -59,7 +59,6 @@ "react-router": "^5.2.0", "react-router-dom": "^5.2.0", "react-text-loop": "^2.3.0", - "siwe": "^1.1.6", "wagmi": "^0.6.0" } } diff --git a/landing/siwe.react.js b/landing/siwe.react.js --- a/landing/siwe.react.js +++ b/landing/siwe.react.js @@ -11,7 +11,6 @@ import invariant from 'invariant'; import _merge from 'lodash/fp/merge'; import * as React from 'react'; -import { SiweMessage } from 'siwe'; import '@rainbow-me/rainbowkit/dist/index.css'; import { useAccount, @@ -29,6 +28,7 @@ getSIWEStatementForPublicKey, siweStatementWithoutPublicKey, siweMessageSigningExplanationStatements, + createSIWEMessage, } from 'lib/utils/siwe-utils.js'; import { SIWEContext } from './siwe-context.js'; @@ -54,22 +54,6 @@ provider, }); -function createSiweMessage(address: string, statement: string, nonce: string) { - invariant(nonce, 'nonce must be present in createSiweMessage'); - const domain = window.location.host; - const origin = window.location.origin; - const message = new SiweMessage({ - domain, - address, - statement, - uri: origin, - version: '1', - chainId: '1', - nonce, - }); - return message.prepareMessage(); -} - function postMessageToNativeWebView(message: SIWEWebViewMessage) { window.ReactNativeWebView?.postMessage?.(JSON.stringify(message)); } @@ -81,7 +65,7 @@ statement: string, ) { invariant(nonce, 'nonce must be present in signInWithEthereum'); - const message = createSiweMessage(address, statement, nonce); + const message = createSIWEMessage(address, statement, nonce); const signature = await signer.signMessage(message); postMessageToNativeWebView({ type: 'siwe_success', diff --git a/lib/package.json b/lib/package.json --- a/lib/package.json +++ b/lib/package.json @@ -41,6 +41,7 @@ "simple-markdown": "^0.7.2", "string-hash": "^1.1.3", "tcomb": "^3.2.29", + "siwe": "^1.1.6", "tinycolor2": "^1.4.1", "tokenize-text": "^1.1.3", "url-parse-lax": "^3.0.0", 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 @@ -1,6 +1,7 @@ // @flow import invariant from 'invariant'; +import { SiweMessage } from 'siwe'; import type { SIWEMessage } from '../types/siwe-types.js'; import { isDev } from './dev-utils.js'; @@ -23,9 +24,28 @@ const siweStatementWithoutPublicKey: string = 'By continuing, I accept the Comm Terms of Service: https://comm.app/terms'; +function createSIWEMessage( + address: string, + statement: string, + nonce: string, +): string { + invariant(nonce, 'nonce must be present in createSiweMessage'); + const domain = window.location.host; + const origin = window.location.origin; + const message = new SiweMessage({ + domain, + address, + statement, + uri: origin, + version: '1', + chainId: '1', + nonce, + }); + return message.prepareMessage(); +} + const expectedDomain = isDev ? 'localhost:3000' : 'comm.app'; const expectedURI = isDev ? 'http://localhost:3000' : 'https://comm.app'; - // Verify that the SIWEMessage is a well formed Comm SIWE Auth message. function isValidSIWEMessage(candidate: SIWEMessage): boolean { return ( @@ -85,6 +105,7 @@ isValidSIWENonce, isValidEthereumAddress, isValidPrimaryIdentityPublicKey, + createSIWEMessage, isValidSIWEMessage, getSIWEStatementForPublicKey, isValidSIWEStatementWithPublicKey,