How to securely send the private key from the client to the server? #3504
Replies: 2 comments 15 replies
-
Asking for user's private key is a trustful suggestion and defeats purpose of web3, for a trustless solution, you may have the client side application sign the transactions with a high base fee per gas (200 gwei) and a nominal priority fee per gas (1.5 gwei), the gas charged for the user is just the actual base fee at the time + priority fee. Your server can keep the txs and broadcast them later (without the user's privatekey).
If the above suggestion does not work for some reason, and you need to have the private key sent, you can ensure that the requests are made using If you do not want to rely on traditional SSL security, you can do Diffie–Hellman Key Exchange using ethers.js's computeSharedSecret util (docs) and use the shared secret + ricmoo's AES. This needs an ethereum wallet on the server (does not need any ether on it, just for encryption and decryption). |
Beta Was this translation helpful? Give feedback.
-
Do. Not. Do. This. The entire point of crypto is to let the user control their data. If you send the private key over the wire, that is lost. Forever. It could have been intercepted. You could log it in a log file and not realize it. Your server could be compromised and it saved to a database or forwarded to another host the attacker controls. You do not want to be in the business of managing a customers private key. Ever. In any way, shape or form. You can design your contract to accept a signed message, or use approve patterns or have the user accept multiple pop-ups. There are plenty of existing techniques that address this. But your dapp should never have access to the users private key. For general purpose secure data transfer, see @zemse solutions. You should definitely layer ECDH in, since users can opt out of security over https. But do not ask the user for their private key. Do not put it in local storage. Do not send it over the wire. You will be responsible for people losing their funds and assets if you do. Don’t. Do. it. :p |
Beta Was this translation helpful? Give feedback.
-
I am developing a Dapp with ethers.js. The application automates a series of transactions for users, to do this I understand that there is no other way than to use the users' private key, without the user having to accept every single client side transaction.
I use ajax to make a post call to the nodejs server, here I process a series of operations.
I do not in any way save the users private key in my server / database, it is not my interest to do so. I optionally give the possibility to save the private key in the user's localstorage so as not to have it entered every time.
My fear is that the private key may somehow be intercepted during the sending process to the server. I don't see any other possible risks at the moment.
What can be a way to increase security in the submission process? Maybe there is a functional client-side encryption and server-side decryption method with ethers.js?
Beta Was this translation helpful? Give feedback.
All reactions