eth-account
eth-account copied to clipboard
Feature Request: Interactive Account
Use case: local developer keys (for debugging on public networks with low-fund accounts)
Create an account where user provides an encrypted keystore, and Account.decrypt
is used whenever the publicKey is required, providing a password to unlock the keystore for a 1-time sign operation. Optional functionality would be to cache this password for a given time period (similar to the personal_unlockAccount
API), for which the user can accept or decline using [y/N].
For better user experience feedback, perhaps debug print the message or transaction to be signed before asking for the password or to use the cached password.
This may be more broadly useful setting dev experience expectations as a baseclass for hardware wallet interactions (#31), as the interactive prompt could delegate to the hardware signer instead.
I was actually looking for the same feature. Basically like pyethapp
was providing:
https://github.com/ethereum/pyethapp/blob/v1.5.0/pyethapp/accounts.py#L26
My use case is, I want to play with "read-only" accounts without providing the password to decrypt the private key upfront.
Say I'm listing all the user accounts and simply want to show their public address. But I still want to carry around the account object rather than checking pub address "manually" with json.loads()
. For instance:
for account in AccountsService.accounts:
print(account.address)
By default the accounts are loaded in the locked
state. But when the user/dev provides the password for the private key it gets unlocked. The unenrcypted keyfile is kept in RAM so we can later sign without being asked again.
Here's a first pass at a new Keystore
API:
from eth_account import Keystore # or maybe from eth_keystore import Keystore?
locked_accounts = {}
for keydict in Keystore.load('~/.mykeystorefiles'):
locked_accounts[keydict['address']] = keydict
Which means you can easily enumerate the addresses:
for addr in locked_accounts:
print(addr)
It's straightforward to keep a cache of unlocked accounts:
import getpass
unlocked_accounts = {}
addr = ... # to unlock
unlocked_accounts[addr] = Account.decrypt(locked_accounts[addr], getpass.getpass())
Edit: just realized that this is more a response to the second comment than the OP. Will return to address OP later...
Thank you @carver for your feedback. Yes sorry I realised I hijacked the issue. I thought it was related, but misread it.
Regarding the Keystore.load()
that returns a dict
, I'm not too sure about it, this operation is already available via json.load()
. As for dealing with unlocked cache ourselves, my point was more to provide an object-oriented/object-friendly design to deal with this. So the idea is to cache that state in the object itself.
It's probably best to open a new issue to discuss, @AndreMiras
I was actually looking for the same feature. Basically like
pyethapp
was providing: https://github.com/ethereum/pyethapp/blob/v1.5.0/pyethapp/accounts.py#L26My use case is, I want to play with "read-only" accounts without providing the password to decrypt the private key upfront. Say I'm listing all the user accounts and simply want to show their public address. But I still want to carry around the account object rather than checking pub address "manually" with
json.loads()
. For instance:for account in AccountsService.accounts: print(account.address)
By default the accounts are loaded in the
locked
state. But when the user/dev provides the password for the private key it gets unlocked. The unenrcypted keyfile is kept in RAM so we can later sign without being asked again.
I see this is pretty old, but I just wound up writing a thin layer on top of this that might do what you want. It does lazy loading of json files and lazy decrypting of accounts. It also allows you to name them and associate them with different chains. I couldn't find anything that existed, but maybe I missed it. Check out https://github.com/pydefi/chained-accounts if you still have a need.