Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(metamask): Add support for eth_signTypedData #991

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions wallets/metamask/src/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ export class MetaMask {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
}
await this.notificationPage.signPersonalMessage(this.extensionId)
await this.notificationPage.signSimpleMessage(this.extensionId)
}

async rejectSignature() {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
}
await this.notificationPage.rejectPersonalMessage(this.extensionId)
await this.notificationPage.rejectSimpleMessage(this.extensionId)
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './connectToDapp'
export * from './personalSign'
export * from './signSimpleMessage'
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import type { BrowserContext } from '@playwright/test'
import { getNotificationPage } from '../../../utils/getNotificationPage'
import Selectors from '../selectors'

const signPersonalMessage = async (context: BrowserContext, extensionId: string) => {
const signMessage = async (context: BrowserContext, extensionId: string) => {
const notificationPage = await getNotificationPage(context, extensionId)

await notificationPage.locator(Selectors.SignaturePage.signButton).click()
}

const rejectPersonalMessage = async (context: BrowserContext, extensionId: string) => {
const rejectMessage = async (context: BrowserContext, extensionId: string) => {
const notificationPage = await getNotificationPage(context, extensionId)

await notificationPage.locator(Selectors.SignaturePage.rejectButton).click()
}

export const personalSign = {
sign: signPersonalMessage,
reject: rejectPersonalMessage
// Used for:
// - `personal_sign`
// - `eth_signTypedData`
export const signSimpleMessage = {
sign: signMessage,
reject: rejectMessage
}
10 changes: 5 additions & 5 deletions wallets/metamask/src/pages/NotificationPage/page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Page } from '@playwright/test'
import { connectToDapp, personalSign } from './actions'
import { connectToDapp, signSimpleMessage } from './actions'

export class NotificationPage {
readonly page: Page
Expand All @@ -12,11 +12,11 @@ export class NotificationPage {
await connectToDapp(this.page.context(), extensionId)
}

async signPersonalMessage(extensionId: string) {
await personalSign.sign(this.page.context(), extensionId)
async signSimpleMessage(extensionId: string) {
await signSimpleMessage.sign(this.page.context(), extensionId)
}

async rejectPersonalMessage(extensionId: string) {
await personalSign.reject(this.page.context(), extensionId)
async rejectSimpleMessage(extensionId: string) {
await signSimpleMessage.reject(this.page.context(), extensionId)
}
}
18 changes: 18 additions & 0 deletions wallets/metamask/test/e2e/metamask/confirmSignature.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,21 @@ test('should confirm `personal_sign`', async ({ context, metamaskPage, page, ext
'0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
)
})

test('should confirm `eth_signTypedData`', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

await page.locator('#signTypedData').click()

await metamask.confirmSignature()

await expect(page.locator('#signTypedDataResult')).toHaveText(
'0xd75eece0d337f4e425f87bd112c849561956afe4f154cdd07d1d4cba7a979b481ba6ceede5c0eb9daa66bec4eea6e7ecfee5496274ef2a93b69abd97531519b21c'
)

await page.locator('#signTypedDataVerify').click()

await expect(page.locator('#signTypedDataVerifyResult')).toHaveText('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266')
})
14 changes: 14 additions & 0 deletions wallets/metamask/test/e2e/metamask/rejectSignature.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,17 @@ test('should reject `personal_sign`', async ({ context, metamaskPage, page, exte
)
await expect(page.locator('#personalSignResult')).toHaveText('')
})

test('should reject `eth_signTypedData`', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

await page.locator('#signTypedData').click()

await metamask.rejectSignature()

await expect(page.locator('#signTypedDataResult')).toHaveText(
'Error: MetaMask Message Signature: User denied message signature.'
)
})