Skip to content
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

Feature Request: Interactive Account #47

Open
fubuloubu opened this issue Oct 29, 2018 · 5 comments
Open

Feature Request: Interactive Account #47

fubuloubu opened this issue Oct 29, 2018 · 5 comments
Labels
p4 nice to have

Comments

@fubuloubu
Copy link
Contributor

fubuloubu commented Oct 29, 2018

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.

@fubuloubu fubuloubu changed the title Feature Request: Default Import Account Feature Request: Keyhandler Account Nov 2, 2018
@fubuloubu fubuloubu changed the title Feature Request: Keyhandler Account Feature Request: Interactive Account Nov 2, 2018
@AndreMiras
Copy link
Contributor

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.

@carver
Copy link
Contributor

carver commented Nov 6, 2018

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...

@AndreMiras
Copy link
Contributor

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.

@carver
Copy link
Contributor

carver commented Nov 12, 2018

It's probably best to open a new issue to discuss, @AndreMiras

carver added a commit to carver/eth-account that referenced this issue Jul 21, 2021
Better error if bump missing in make notes/release
@clamdad
Copy link

clamdad commented Jan 24, 2022

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.

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.

@pacrob pacrob added the p4 nice to have label Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4 nice to have
Projects
None yet
Development

No branches or pull requests

5 participants