Skip to content

Commit 32d70f8

Browse files
Feat/eip1271 support (#445)
* chore: add signature detection * chore: bump packages * chore: log signMessage error * chore: throw error * chore: move Toaster to main instead of app to show errors * chore: remove redundant log --------- Co-authored-by: Chris Smith <1979423+chris13524@users.noreply.github.com>
1 parent 133c675 commit 32d70f8

File tree

7 files changed

+196
-126
lines changed

7 files changed

+196
-126
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"@sentry/react": "^7.93.0",
2323
"@tanstack/react-query": "^5.20.1",
2424
"@walletconnect/core": "2.11.0",
25-
"@walletconnect/identity-keys": "^1.0.1",
26-
"@walletconnect/notify-client": "^0.16.5",
25+
"@walletconnect/identity-keys": "^2.0.1",
26+
"@walletconnect/notify-client": "^1.1.0",
2727
"@walletconnect/notify-message-decrypter": "^0.1.0",
2828
"@web3modal/wagmi": "4.0.10",
2929
"classnames": "^2.3.2",
@@ -43,7 +43,7 @@
4343
"rxjs": "^7.6.0",
4444
"viem": "2.7.8",
4545
"vite-plugin-pwa": "^0.16.7",
46-
"wagmi": "2.5.5"
46+
"wagmi": "^2.5.7"
4747
},
4848
"devDependencies": {
4949
"@playwright/test": "^1.40.1",

src/App.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Fragment, useContext } from 'react'
22

33
import { AnimatePresence, LazyMotion, domAnimation, m } from 'framer-motion'
4-
import { Toaster } from 'react-hot-toast'
54
import { Outlet, useLocation } from 'react-router-dom'
65

76
import MobileFooter from '@/components/layout/MobileFooter'
@@ -30,16 +29,6 @@ const App = () => {
3029
</m.div>
3130
</LazyMotion>
3231
<MobileFooter />
33-
<Toaster
34-
toastOptions={{
35-
position: 'bottom-right',
36-
duration: 5000,
37-
style: {
38-
border: '1px solid rgba(0, 0, 0, 0.1)',
39-
borderRadius: '1em'
40-
}
41-
}}
42-
/>
4332
</AuthProtectedPage>
4433
)
4534
}

src/main.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
44
import { createWeb3Modal } from '@web3modal/wagmi/react'
55
import ReactDOM from 'react-dom/client'
66
import { BrowserRouter } from 'react-router-dom'
7+
import { Toaster } from 'react-hot-toast'
78
import { WagmiProvider } from 'wagmi'
89

910
import { PRIVACY_POLICY_URL, TERMS_OF_SERVICE_URL } from '@/constants/web3Modal'
@@ -53,5 +54,15 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
5354
</SettingsContextProvider>
5455
</QueryClientProvider>
5556
</WagmiProvider>
57+
<Toaster
58+
toastOptions={{
59+
position: 'bottom-right',
60+
duration: 5000,
61+
style: {
62+
border: '1px solid rgba(0, 0, 0, 0.1)',
63+
borderRadius: '1em'
64+
}
65+
}}
66+
/>
5667
</React.StrictMode>
5768
)

src/utils/signature.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { getBytecode } from '@wagmi/core'
2+
import { wagmiConfig } from './wagmiConfig';
3+
4+
5+
export const isSmartContractWallet = async (address: `0x${string}`) => {
6+
const bytecode = await getBytecode(wagmiConfig, {
7+
address
8+
})
9+
10+
const nonContractBytecode = !bytecode || bytecode === '0x' || bytecode === '0x0' || bytecode === '0x00';
11+
12+
return !nonContractBytecode;
13+
}

src/w3iProxy/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { wagmiConfig } from '@/utils/wagmiConfig'
1313
import W3iAuthFacade from '@/w3iProxy/w3iAuthFacade'
1414
import type W3iChatFacade from '@/w3iProxy/w3iChatFacade'
1515
import W3iNotifyFacade from '@/w3iProxy/w3iNotifyFacade'
16+
import { showErrorMessageToast } from '@/utils/toasts'
1617

1718
export type W3iChatClient = Omit<W3iChatFacade, 'initState'>
1819
export type W3iNotifyClient = Omit<W3iNotifyFacade, 'initState'>
@@ -102,7 +103,16 @@ class Web3InboxProxy {
102103
this.dappOrigin = dappOrigin
103104

104105
this.signMessage = async (message: string) => {
105-
return signMessage(wagmiConfig, { message })
106+
try {
107+
const signed = await signMessage(wagmiConfig, {
108+
message
109+
})
110+
111+
return signed
112+
} catch (e: any) {
113+
showErrorMessageToast("Failed to sign message. Consider using different wallet.")
114+
throw new Error(`Failed to sign message. ${e.message}`)
115+
}
106116
}
107117
}
108118

@@ -171,7 +181,7 @@ class Web3InboxProxy {
171181
}
172182

173183
if (this.core) {
174-
this.identityKeys = new IdentityKeys(this.core)
184+
this.identityKeys = new IdentityKeys(this.core, this.projectId)
175185
}
176186

177187
if (this.authProvider === 'internal') {

src/w3iProxy/notifyProviders/internalNotifyProvider.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
userEnabledNotification
1515
} from '@/utils/notifications'
1616
import { W3iNotifyProvider } from '@/w3iProxy/notifyProviders/types'
17+
import { isSmartContractWallet } from '@/utils/signature'
1718

1819
export default class InternalNotifyProvider implements W3iNotifyProvider {
1920
private notifyClient: NotifyClient | undefined
@@ -156,9 +157,14 @@ export default class InternalNotifyProvider implements W3iNotifyProvider {
156157
})
157158
})(preparedRegistration.message)
158159

160+
const [,,address] = props.account.split(':')
161+
162+
const isEip1271Signature = await isSmartContractWallet(address as `0x${string}`);
163+
159164
const identityKey = await this.notifyClient.register({
160165
registerParams: preparedRegistration.registerParams,
161-
signature
166+
signature,
167+
signatureType: isEip1271Signature? 'eip1271' : 'eip191'
162168
})
163169

164170
return identityKey

0 commit comments

Comments
 (0)