-
-
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: Encrypt/decrypt using MetaMask (#1109)
## Motivation and context Implemented encrypt/decrypt functionalities using MetaMask. ## Does it fix any issue? https://linear.app/synpress/issue/SYN-63/encryptdecrypt - [x] I have performed a self-review of my code. - [x] If it is a core feature, I have added thorough e2e tests. **⚠️ 👆 Delete any section you see irrelevant before submitting the pull request 👆⚠️ ** --- <details open="true"><summary>Generated summary</summary> > ### TL;DR > This pull request adds new methods to MetaMask class for adding new tokens, providing public encryption keys, and decrypting messages. It also includes new actions for encryption in the NotificationPage. > > ### What changed > - Added new methods `addNewToken()`, `providePublicEncryptionKey()`, and `decrypt()` to the MetaMask class. > - Added new actions for encryption in the NotificationPage. > - Created new files for encryption actions in the NotificationPage. > > ### How to test > 1. Click on the 'getEncryptionKeyButton' button to provide a public encryption key. > 2. Verify that the encryption key is displayed correctly. > 3. Encrypt and decrypt a message by following the steps provided in the test cases. > > ### Why make this change > - This change introduces new functionality to MetaMask for handling encryption tasks. > - The addition of encryption actions in the NotificationPage enhances the security features of the application. > - These changes improve the overall user experience and security of MetaMask. </details>
- Loading branch information
Showing
7 changed files
with
88 additions
and
11 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 type { Page } from '@playwright/test' | ||
import Selectors from '../selectors' | ||
|
||
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
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') | ||
}) |