I am building a web app where I have to keep track of a private key associated with each user. For the sake of this discussion let's assume that it's an exchange and users can send their ETH to this address and ignore all the complexities of cold storage.
So far I have managed to cobble together this code for web3.py:
from web3 import *
web3 = Web3(IPCProvider(ipc_path='/path/to/geth.ipc'))
random_private_key = '0x71a7f0e2ef1b7ff501b65a1650d48b8d5521fadc9539eec146d4faa6f5ca9ccc'
random_password = 'qwertyuiop'
address = web3.personal.importRawKey(random_private_key, random_password)
# address -> '0x930198a4bdd322ee3305fcf0bcb106064b38754b'
# web3.eth.accounts -> [..., '0x930198a4bdd322ee3305fcf0bcb106064b38754b']
What is the correct way to generate and store these private keys? In the above example I just pulled something from the internet and modified it a bit.
My plan is to generate random private keys, dump them in a DB and import them whenever ETH from those accounts have to be transferred. Since there is no web3.personal.deleteAccount
I'd have to delete the json file from the keystore after I've finished the transfer and call importRawKey
again if I need to make a transfer.
I am not sure if my plan is a good one and am looking for feedback or better ways to handle this.