-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(metamask): Add support for
personal_sign
- Loading branch information
1 parent
489621c
commit 36a26be
Showing
11 changed files
with
154 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './connectToDapp' | ||
export * from './personalSign' |
20 changes: 20 additions & 0 deletions
20
wallets/metamask/src/pages/NotificationPage/actions/personalSign.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { BrowserContext } from '@playwright/test' | ||
import { getNotificationPage } from '../../../utils/getNotificationPage' | ||
import Selectors from '../selectors' | ||
|
||
const signPersonalMessage = 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 notificationPage = await getNotificationPage(context, extensionId) | ||
|
||
await notificationPage.locator(Selectors.SignaturePage.rejectButton).click() | ||
} | ||
|
||
export const personalSign = { | ||
sign: signPersonalMessage, | ||
reject: rejectPersonalMessage | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
wallets/metamask/src/pages/NotificationPage/selectors/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import SignaturePage from './signaturePage' | ||
|
||
export default { | ||
SignaturePage | ||
} |
6 changes: 6 additions & 0 deletions
6
wallets/metamask/src/pages/NotificationPage/selectors/signaturePage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createDataTestSelector } from '../../../utils/selectors/createDataTestSelector' | ||
|
||
export default { | ||
signButton: `.request-signature__footer ${createDataTestSelector('request-signature__sign')}`, | ||
rejectButton: '.request-signature__footer button.btn-secondary' | ||
} |
33 changes: 33 additions & 0 deletions
33
wallets/metamask/test/e2e/metamask/confirmSignature.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { testWithSynpress } from 'fixtures' | ||
import { MetaMask, unlockForFixture } from '../../../src' | ||
|
||
import connectedSetup from '../wallet-setup/connected.setup' | ||
|
||
const test = testWithSynpress(connectedSetup, unlockForFixture) | ||
|
||
const { describe, expect } = test | ||
|
||
describe('MetaMask.confirmSignature', () => { | ||
test('should confirm `personal_sign`', 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('#personalSign').click() | ||
|
||
await metamask.confirmSignature() | ||
|
||
await expect(page.locator('#personalSignResult')).toHaveText( | ||
'0xf95b3efc808585303e20573e960993cde30c7f5a0f1c25cfab0379d5a14311d17898199814c8ebe66ec80b2b11690f840bde539f862ff4f04468d2a40f15178a1b' | ||
) | ||
|
||
await page.locator('#personalSignVerify').click() | ||
|
||
await expect(page.locator('#personalSignVerifySigUtilResult')).toHaveText( | ||
'0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' | ||
) | ||
await expect(page.locator('#personalSignVerifyECRecoverResult')).toHaveText( | ||
'0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
wallets/metamask/test/e2e/metamask/rejectSignature.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { testWithSynpress } from 'fixtures' | ||
import { MetaMask, unlockForFixture } from '../../../src' | ||
|
||
import connectedSetup from '../wallet-setup/connected.setup' | ||
|
||
const test = testWithSynpress(connectedSetup, unlockForFixture) | ||
|
||
const { describe, expect } = test | ||
|
||
describe('MetaMask.rejectSignature', () => { | ||
test('should reject `personal_sign`', 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('#personalSign').click() | ||
|
||
await metamask.rejectSignature() | ||
|
||
await expect(page.locator('#personalSign')).toHaveText( | ||
'Error: MetaMask Message Signature: User denied message signature.' | ||
) | ||
await expect(page.locator('#personalSignResult')).toHaveText('') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { defineWalletSetup } from 'core' | ||
import { getExtensionId } from 'fixtures' | ||
import { MetaMask } from '../../../src' | ||
|
||
const SEED_PHRASE = 'test test test test test test test test test test test junk' | ||
|
||
const PASSWORD = 'Tester@1234' | ||
|
||
export default defineWalletSetup(PASSWORD, async (context, walletPage) => { | ||
const extensionId = await getExtensionId(context, 'MetaMask') | ||
|
||
const metamask = new MetaMask(context, walletPage, PASSWORD, extensionId) | ||
|
||
await metamask.importWallet(SEED_PHRASE) | ||
|
||
const page = await context.newPage() | ||
|
||
await page.goto('https://metamask.github.io/test-dapp/') | ||
|
||
await page.locator('#connectButton').click() | ||
|
||
await metamask.connectToDapp() | ||
|
||
await page.close() | ||
}) |