-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add encryption capabilities #102
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
Conversation
b4e09ae
to
fca207d
Compare
b3678b7
to
949b10d
Compare
@metamaskbot publish-preview |
This enforces total key independence between signing and encryption
cb05551
to
4a5aa93
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 pretty damn good to me! Waiting for your feedback on mobile tests, and also left some comments!
For the moment this snap can't be tested on our mobile app as we don't have SIP30 support there and some methods and params are missing. BUT I did run some benchmarks of the ERC1024 code directly in the mobile app:
These numbers are from a modern android device (pixel 9). Edit: I also later tested on a Nokia 6 (2017), and the numbers for encryption/decryption are about 10 times larger. For the old phone, the react-native experience in general is very slow as every user action takes about 2-4 seconds to process so I would argue we're still in relatively acceptable ranges with the performance of the encryption. |
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.
Awesome!
What's new
This preinstalled snap allows an instance of MetaMask to sign messages using an SRP derived key.
We really need an SRP bound encryption system too.
This PR introduces an ERC1024 compatible encryption system, to be compatible1 with the existing but deprecated
eth_getEncryptionPublicKey
/eth_decrypt
implementation in MetaMask.Example usage
Alice, the user of this functionality would call the
getPublicEncryptionKey
method and obtain a hex encoded X25519 public key, which they would broadcast to Bob.Bob would then use a piece of code similar to:
.. and obtain an object such as:
Bob would send this object to Alice who can then call the
decryptMessage
method of the snap to get the message.Implementation details
The encryption secret key is derived from the SRP-bound entropy using an additional salt, to avoid key reuse between signing and encryption. The entropy vs origin logic is the same as for the signing functionality. Each origin gets different keys and origins can't decrypt each other's messages.
The encryption layer is implemented using the pre-existing
@noble/ciphers
/@noble/curves
dependencies.The tests for the encryption layer represent the vast majority of additions to this PR.
Technically, the new ERC1024 implementation can be replaced with
@metamask/eth-sig-util
, however, that library is designed for nodejs and throws some warnings when used in a snap.We could also pull that out as an independent library.
Related issues
Fixes #101
link back to jira
Footnotes
The compatibility is on the data format, not on the actual public key, so messages encrypted for the snap will not be decryptable by any of the MM accounts, nor vice-versa. ↩