-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: Encrypt/decrypt using MetaMask
- Loading branch information
Showing
5 changed files
with
84 additions
and
9 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
10 changes: 10 additions & 0 deletions
10
wallets/metamask/src/pages/NotificationPage/actions/encryption.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,10 @@ | ||
import Selectors from '../selectors' | ||
import type { Page } from '@playwright/test' | ||
|
||
export async function providePublicEncryptionKey(notificationPage: Page) { | ||
await notificationPage.locator(Selectors.ActionFooter.confirmActionButton).click() | ||
} | ||
|
||
export async function decryptMessage(notificationPage: Page) { | ||
await notificationPage.locator(Selectors.ActionFooter.confirmActionButton).click() | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { testWithMetaMask } from '../testWithMetaMask' | ||
|
||
const test = testWithMetaMask | ||
|
||
const { expect } = test | ||
|
||
test('should provide public encryption key', async ({ page, metamask }) => { | ||
await page.locator('#getEncryptionKeyButton').click() | ||
await metamask.providePublicEncryptionKey() | ||
|
||
await expect(page.locator('#encryptionKeyDisplay')).toHaveText('mtrHp1WHZM9rxF2Ilot9Hie5XmQcKCf7oDQ1DpGkTSI=') | ||
}) | ||
|
||
test('should encrypt and decrypt a message', async ({ page, metamask }) => { | ||
await page.locator('#getEncryptionKeyButton').click() | ||
await metamask.providePublicEncryptionKey() | ||
await expect(page.locator('#encryptionKeyDisplay')).toHaveText('mtrHp1WHZM9rxF2Ilot9Hie5XmQcKCf7oDQ1DpGkTSI=') | ||
|
||
// `fill` does not trigger buttons validation, so we use `type` instead | ||
await page.locator('#encryptMessageInput').type('Hello, world') | ||
|
||
await page.locator('#encryptButton').click() | ||
|
||
const encryptedMessage = await page.locator('#ciphertextDisplay').textContent() | ||
|
||
expect(encryptedMessage).toContain('0x7b') | ||
|
||
await page.locator('#decryptButton').click() | ||
await metamask.decrypt() | ||
|
||
const decryptedMessage = await page.locator('#cleartextDisplay').textContent() | ||
|
||
expect(decryptedMessage).toEqual('Hello, world') | ||
}) |