-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 web3.eth.encrypt and web3.eth.decrypt functions to JSON-RPC #1098
Changes from 7 commits
fd3b439
089ab7d
e49bdf8
0ee294a
fc9b5a8
b676508
e0f994b
b9664ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,102 @@ | ||||||||||||||||||||||||||||||
--- | ||||||||||||||||||||||||||||||
eip: 1024 | ||||||||||||||||||||||||||||||
title: Add web3.eth.encrypt and web3.eth.decrypt functions | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would make sense including "to JSON-RPC" here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
author: Tope Alabi <[email protected]> | ||||||||||||||||||||||||||||||
status: Draft | ||||||||||||||||||||||||||||||
type: Interface Track | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no 'interface track'. Please use a type and category from EIP 0. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still not fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
created: 2018-05-14 | ||||||||||||||||||||||||||||||
--- | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be an extension of the RPC protocol, so a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
### Abstract | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these sections seem to be indented one level too deep, it should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
This EIP proposes a cross-client method for requesting encryption/decryption. This method will include a version parameter, so that different encryption methods can be added under the same name. Nacl is a cryptographically complete and well audited library that works well for this by implementers are free to choose their crypto. Ethereum keypairs should not be used directly for encryption, instead we should derive an encryption keypair from the account's private key for decryption and generate a random ephemeral keypair for encryption. | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
Parity wallet already implements a compatible [encrypt/decrypt] https://wiki.parity.io/JSONRPC-parity-module#parity_decryptmessage method and the MetaMask version is on the way. Having a cross-client standard will enable a whole new wave of decentralized applications that will allow users to securely store their private data in public databases such as IPFS. | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(update to include Metamask impl as of July 2020) |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
### Motivation | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
Imagine an illegal immigrant named Martha. Martha moved to the United States illegally but then had 2 children there, so her children are citizens. One day Martha gets arrested and deported but her children get to stay. How will Martha pass power of Attorney, bank account info, identification docs, and other sensitive information to her children? Storing that data in a centralized database can be incriminating for Martha, so maybe decentralized databases like IPFS could help, but if the data is not encrypted anyone can see it, which kind of defeats the purpose. If Martha had access to a Dapp with end-to-end encryption connected to her identity, she could save her data in a decentralized, censor-proof database and still have confidence that only her children can access it. | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This motivation is bound to piss people off but it gets big ups from me. Nice imagination. Just wanted to leave that here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. But it's also a very legit scenario. |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
More casually, Martha can create a treasure hunt game, or a decentralized chat app etc. | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
### Specification | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const nacl = require('tweetnacl') | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||
Comment on lines
+24
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tl;dr=IMHO this is implementation specific, but is worth including here. An implementation of An alternative would be to bundle (parts of) the In the case that implementation specific lines do not belong in this section, here's a patch that removes it:
Suggested change
FWIW, I think that leaving it in there is probably a good thing because it aids in understanding the proceeding sections of the specifications, and is a reference to something mentioned in the abstract. addresses: https://github.com/ethereum/EIPs/pull/1098/files#r299563507 |
||||||||||||||||||||||||||||||
* Returns user's public Encryption key derived from privateKey Ethereum key | ||||||||||||||||||||||||||||||
* @param {Account} reciever - The Ethereum account that will be recieving/decrypting the data | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor nitpick: reciever, is usually spelt as "receiver" |
||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
web3.eth.getEncryptionPublicKey(reciever.privateKey) { /* implementation */ } | ||||||||||||||||||||||||||||||
Comment on lines
+29
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
addresses: https://github.com/ethereum/EIPs/pull/1098/files#r193246175 |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||
* Encrypts plain data. | ||||||||||||||||||||||||||||||
* @param {string} encryptionPublicKey - The encryption public key of the reciever | ||||||||||||||||||||||||||||||
* @param {string} version - A unique string identifying the encryption strategy. | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it make sense to define an enum, and use it here instead of a raw string? pros:
cons:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An enum would be a good idea when we have more than one option (as of now this is the only one). |
||||||||||||||||||||||||||||||
* @param {Object} data - The data to encrypt | ||||||||||||||||||||||||||||||
* @param {Function} callback - The function to call back when decryption is complete. | ||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
web3.eth.encrypt(encryptionPublicKey, version, data, callback) { /* implementation */ } | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||
* Decrypts some encrypted data. | ||||||||||||||||||||||||||||||
* @param {Account} reciever - The account that will decrypt the message | ||||||||||||||||||||||||||||||
* @param {Object} encryptedData - The data to decrypt | ||||||||||||||||||||||||||||||
* @param {Function} callback - The function to call back when decryption is complete. | ||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
web3.eth.decrypt = function decrypt (recievier.privatekey, encryptedData, callback) { /* implementation */ } | ||||||||||||||||||||||||||||||
Comment on lines
+42
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
**To Encrypt:** | ||||||||||||||||||||||||||||||
- Alice requests Bob's publicEncryptionKey | ||||||||||||||||||||||||||||||
- Bob generates his encryptionKeypair using nacl.box.keyPair.fromSecretKey(bob.ethereumPrivateKey) | ||||||||||||||||||||||||||||||
- Bob sends Alice his encryptionKeyPair.publicKey | ||||||||||||||||||||||||||||||
- Alice generates a random ephemeralKeyPair | ||||||||||||||||||||||||||||||
- Alice uses her ephemeralKeypair.secretKey and Bob's encryptionPublicKey to encrypt the data using nacl.box. She sends him an encrypted blob of the form: | ||||||||||||||||||||||||||||||
Comment on lines
+52
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||
{ version: 'x25519-xsalsa20-poly1305', | ||||||||||||||||||||||||||||||
nonce: '1dvWO7uOnBnO7iNDJ9kO9pTasLuKNlej', | ||||||||||||||||||||||||||||||
ephemPublicKey: 'FBH1/pAEHOOW14Lu3FWkgV3qOEcuL78Zy+qW1RwzMXQ=', | ||||||||||||||||||||||||||||||
ciphertext: 'f8kBcl/NCyf3sybfbwAKk/np2Bzt9lRVkZejr6uh5FgnNlH/ic62DZzy' } | ||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
**To Decrypt:** | ||||||||||||||||||||||||||||||
- Bob generates his encryptionPrivatekey using nacl.box.keyPair.fromSecretKey(bob.ethereumPrivateKey).secretKey | ||||||||||||||||||||||||||||||
- Bob passes his encryptionPrivateKey along with the encrypted blob to nacl.box.open(ciphertext, nonce, ephemPublicKey, myencryptionPrivatekey) | ||||||||||||||||||||||||||||||
Comment on lines
+67
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
### Rationale | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
These methods should require user confirmation. We include the versioning to allow different encryption/decryption types to be added under the same method name. For example, it might make sense to have a few kinds of decrypt methods, for different kinds of consent: | ||||||||||||||||||||||||||||||
- Consent to download a decrypted file. | ||||||||||||||||||||||||||||||
- Consent to return decrypted file to the current site. | ||||||||||||||||||||||||||||||
- Consent to return any number of decrypted messages to the current site over a certain period of time. (could enable chat apps) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
### Backwards Compatibility | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
Parity implements an encrypt/decrypt method with a different curve than the one which is intended in this proposal, but that it would be possible to add support for curves to this standard. | ||||||||||||||||||||||||||||||
https://wiki.parity.io/JSONRPC-parity-module#parity_decryptmessage | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
### Test Cases | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
`getEncryptionPublicKey(7e5374ec2ef0d91761a6e72fdf8f6ac665519bfdf6da0a2329cf0d804514b816)` should return a public encryption key of the form `"C5YMNdqE4kLgxQhJO1MfuQcHP5hjVSXzamzd/TxlR0U="` | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
`web3.eth.encrypt("C5YMNdqE4kLgxQhJO1MfuQcHP5hjVSXzamzd/TxlR0U=", 'x25519-xsalsa20-poly1305-v1', {data: 'My name is Satoshi Buterin'})` should return a blob of the form `{ version: 'x25519-xsalsa20-poly1305', | ||||||||||||||||||||||||||||||
nonce: '1dvWO7uOnBnO7iNDJ9kO9pTasLuKNlej', | ||||||||||||||||||||||||||||||
ephemPublicKey: 'FBH1/pAEHOOW14Lu3FWkgV3qOEcuL78Zy+qW1RwzMXQ=', | ||||||||||||||||||||||||||||||
ciphertext: 'f8kBcl/NCyf3sybfbwAKk/np2Bzt9lRVkZejr6uh5FgnNlH/ic62DZzy' }` | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
`web3.eth.decrypt('7e5374ec2ef0d91761a6e72fdf8f6ac665519bfdf6da0a2329cf0d804514b816', | ||||||||||||||||||||||||||||||
{ version: 'x25519-xsalsa20-poly1305', | ||||||||||||||||||||||||||||||
nonce: '1dvWO7uOnBnO7iNDJ9kO9pTasLuKNlej', | ||||||||||||||||||||||||||||||
ephemPublicKey: 'FBH1/pAEHOOW14Lu3FWkgV3qOEcuL78Zy+qW1RwzMXQ=', | ||||||||||||||||||||||||||||||
ciphertext: 'f8kBcl/NCyf3sybfbwAKk/np2Bzt9lRVkZejr6uh5FgnNlH/ic62DZzy' })` should return plain text/file of the form `{ data:'My name is Satoshi Buterin' }` | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
### Implementation | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
Parity wallet has already implemented a compatible encryption/decryption method. The Metamask version will be published soon. | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(update to include MetaMask's implementation as of July 2020) |
||||||||||||||||||||||||||||||
https://github.com/topealabi/eth-sig-util/blob/master/index.js | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
## Copyright | ||||||||||||||||||||||||||||||
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). |
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.
Where is this number coming from?
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.