-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
Add decryptMessage
method
#1596
Conversation
Converted to a draft as I'm trying to add a test case as |
decryptMessage
method
3d98084
to
16ca6a7
Compare
16ca6a7
to
9d4c493
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment!
9d4c493
to
2575b44
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
const { importedAccountAddress } = | ||
await controller.importAccountWithStrategy( | ||
AccountImportStrategy.privateKey, | ||
[privateKey], | ||
); | ||
const message = 'Hello, encrypted world!'; | ||
const encryptedMessage = encrypt({ | ||
publicKey: await controller.getEncryptionPublicKey( | ||
importedAccountAddress, | ||
), | ||
data: message, | ||
version: 'x25519-xsalsa20-poly1305', | ||
}); | ||
|
||
const messageParams = { | ||
from: importedAccountAddress, | ||
data: encryptedMessage, | ||
}; | ||
|
||
const result = await controller.decryptMessage(messageParams); | ||
|
||
expect(result).toBe(message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also simplify this by taking inspiration from getEncryptionPublicKey
tests, with something like this:
const { importedAccountAddress } = | |
await controller.importAccountWithStrategy( | |
AccountImportStrategy.privateKey, | |
[privateKey], | |
); | |
const message = 'Hello, encrypted world!'; | |
const encryptedMessage = encrypt({ | |
publicKey: await controller.getEncryptionPublicKey( | |
importedAccountAddress, | |
), | |
data: message, | |
version: 'x25519-xsalsa20-poly1305', | |
}); | |
const messageParams = { | |
from: importedAccountAddress, | |
data: encryptedMessage, | |
}; | |
const result = await controller.decryptMessage(messageParams); | |
expect(result).toBe(message); | |
const { importedAccountAddress } = | |
await controller.importAccountWithStrategy( | |
AccountImportStrategy.privateKey, | |
[privateKey], | |
); | |
const result = await controller.decryptMessage({ | |
from: importedAccountAddress, | |
data: { | |
version: 'x25519-xsalsa20-poly1305', | |
nonce: 'wLwuCz6aY+IjdF34os94LbAer8H5TPck', | |
ephemPublicKey: 'B4cLIZfy4AU7xdM8DAO/0+VaIm8W2aY2xb7ciaPmpx8=', | |
ciphertext: | |
'4mNw0NlJfa+qWAsCza/iYk7uQtYcY/TBLLQnFsPsnS0E7ErjLU8J/ViK', | |
}, | |
}); | |
expect(result).toBe('My name is Satoshi Buterin'); |
This would also remove interdependency between unit tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikesposito PR got already merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops, it got merged while I was reviewing it 😄 nevermind!
feat: add decryptMessage method --------- Co-authored-by: Salah <[email protected]>
feat: add decryptMessage method --------- Co-authored-by: Salah <[email protected]>
Explanation
This PR adds the
decryptMessage
method needed by extension'sDecryptMessageController
.References
KeyringController
#1595Changelog
@metamask/keyring-controller
decryptMessage
methodChecklist