create account

update for beem: reworking wallet and key handling by holger80

View this thread on: hive.blogpeakd.comecency.com
· @holger80 ·
$169.83
update for beem: reworking wallet and key handling
## Repository

https://github.com/holgern/beem<center>
![beem-logo](https://cdn.steemitimages.com/DQmcRrwLPSywSYMierfP6um6mejeMNGjN9Rxw7audJqTDgb/beem-logo)
</center>

[beem](https://github.com/holgern/beem) is a python library and command line tool for HIVE.  The current version is 0.24.0.

There is also a discord channel for beem: https://discord.gg/4HM592V

The newest beem version can be installed by:

```
pip install -U beem
```

Check that you are using hive nodes. The following command 

```
beempy updatenodes --hive
```

updates the nodelist and uses only hive nodes. After setting hive as default_chain, `beempy updatenodes` can be used.

The list of nodes can be checked with

```
beempy config
```

and

```
beempy currentnode
```

shows the currently connected node.

## Changelog for versions 0.24.0
* new beemstorage module
* Config is handled by SqliteConfigurationStore or InRamConfigurationStore
* Keys are handled by SqliteEncryptedKeyStore or InRamPlainKeyStore
* Move aes to beemgraphenebase
* Wallet.keys, Wallet.keyStorage, Wallet.token and Wallet.keyMap has been removed
* Wallet.store has now the Key Interface that handles key management
* Token handling has been removed from Wallet
* Token storage has been move from wallet to SteemConnect/HiveSigner
* handle virtual ops batch streaming fixed thanks to @crokkon 

## Accessing stored config
```
from beemstorage import SqliteConfigurationStore
config = SqliteConfigurationStore()
print(config.get("default_account"))
```
returns `holger80`. I can now change the value with:
```
config["default_account"] = "test"
```
This value is now available in all beem instances. A `beempy config` returns now:
```
+-----------------------+---------------------------------------------+
| Key                   | Value                                       |
+-----------------------+---------------------------------------------+
| default_account       | test                                        |
```
.

The new beemstorage structure makes it easy to access and to modify the config parameters stored inside the sqlite database.

## Accessing stored keys
```
from beemstorage import SqliteConfigurationStore, SqliteEncryptedKeyStore
config = SqliteConfigurationStore()
key_store = SqliteEncryptedKeyStore(config=config)
print(key_store.items())
```
returns the public key and the encrypted wif of all stored keys. Encryption of the first stored key is done by:

```
key_store.unlock("wallet_phrase")
print(key_store.decrypt(key_store.items()[0][1]))
```
where `wallet_phrase` is the set masterpassword.
Modifying items of the key_store object will change them for all beem instances on the same PC.


## Use Config and Key storage without writing to file system
It is now possible to use a Config and Key store which does not access the beem.sqlite file. 
```
from beem import Hive
from beem.storage import generate_config_store
from beemstorage import InRamConfigurationStore, InRamPlainKeyStore
config = generate_config_store(InRamConfigurationStore)()
key_store = InRamPlainKeyStore()
hive = Hive(config_store=config, key_store=key_store)
key_store.add("5K7iVnYgTpG9DVBswdEETBqieCS7MwqhqnyXVN16UQmPJHBReet", "STM7fyvenZ9sJ2SGz5ctNMGzCMii82DR5GSkgPtDhfBVkaYBy8Qfq")
print(hive.wallet.getPublicKeys())
```
return
```
['STM7fyvenZ9sJ2SGz5ctNMGzCMii82DR5GSkgPtDhfBVkaYBy8Qfq']
```

It is also possible to use the `keys` parameter in `Hive`:
```
from beem import Hive
from beem.storage import generate_config_store
from beemstorage import InRamConfigurationStore
config = generate_config_store(InRamConfigurationStore)()
key_store = InRamPlainKeyStore()
hive = Hive(config_store=config, keys=["5K7iVnYgTpG9DVBswdEETBqieCS7MwqhqnyXVN16UQmPJHBReet"])
print(hive.wallet.getPublicKeys())
```
returns
```
['STM7fyvenZ9sJ2SGz5ctNMGzCMii82DR5GSkgPtDhfBVkaYBy8Qfq']
```

The `generate_config_store` function fills the InRamConfigurationStore with default values.


## Creating your own config and key storage
It is now also possible to create new key and config storages. E.g. a config/key storage that uses a mongo or a postgres database.

The following methods needs to be implemented for creating a new storage class:

  * ``def setdefault(cls, key, value)``
  * ``def __init__(self, *args, **kwargs)``
  * ``def __setitem__(self, key, value)``
  * ``def __getitem__(self, key)``
  * ``def __iter__(self)``
  * ``def __len__(self)``
  * ``def __contains__(self, key)``

You can take a look at the [sqlite.py](https://github.com/holgern/beem/blob/master/beemstorage/sqlite.py#L173) file which is an implementation for sqlite.

## HiveSigner token storage

Token storage for access tokens from HiveSigner and SteemConnect has been moved from the Wallet class to HiveSigner/Steemconnect.

HiveSigner uses the same masterpassword than the incrypted key storage. You can create a wallet and set a master password with
```
beempy createwallet
```
The following code stores a valid access token into the token storage and uses the stored token in a `me` API request:
```
from beem.hivesigner import HiveSigner
hs = HiveSigner(blockchain_instance=None)
hs.unlock("abc123")
hs.setToken({"holger80": "ey..."})
ret = hs.me(username="holger80")
print(ret["scope"])
```
returns
```
['login']
```
As the token is now stored in the sqlite file, it is also possible to list it with
```
beempy listtoken
```
which returns
```
+----------+-----------+--------+
| name     | scope     | status |
+----------+-----------+--------+
| holger80 | ['login'] | ok     |
+----------+-----------+--------+
```

HiveSigner tokens which have a broader scope than login can be used to broadcast transactions.

___

*If you like what I do, consider casting a vote for me as witness on [Hivesigner](https://hivesigner.com/sign/account-witness-vote?witness=holger80&approve=1) or on [PeakD](https://peakd.com/witnesses)*
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 544 others
👎  
properties (23)
authorholger80
permlinkupdate-for-beem-reworking-wallet-and-key-handling
categoryhive-139531
json_metadata"{"canonical_url": "https://hive.blog/hive-139531/@holger80/update-for-beem-reworking-wallet-and-key-handling", "community": "hive-139531", "app": "beempy/0.24.0", "users": ["crokkon"], "links": ["https://github.com/holgern/beem", "https://github.com/holgern/beem/blob/master/beemstorage/sqlite.py#L173", "https://hivesigner.com/sign/account-witness-vote?witness=holger80&approve=1", "https://peakd.com/witnesses", "https://cdn.steemitimages.com/DQmcRrwLPSywSYMierfP6um6mejeMNGjN9Rxw7audJqTDgb/beem-logo", "https://discord.gg/4HM592V"], "tags": ["development", "beem", "python", "release"]}"
created2020-06-18 16:02:15
last_update2020-06-18 16:02:15
depth0
children12
last_payout2020-06-25 16:02:15
cashout_time1969-12-31 23:59:59
total_payout_value94.218 HBD
curator_payout_value75.615 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,857
author_reputation358,857,509,568,825
root_title"update for beem: reworking wallet and key handling"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,041,008
net_rshares373,924,611,295,648
author_curate_reward""
vote details (609)
@alnangloy11 ·
$0.05
Great article, this would be a great one. Thank you for sharing some of this.
👍  
👎  
properties (23)
authoralnangloy11
permlinkre-holger80-2020619t54624281z
categoryhive-139531
json_metadata{"tags":["development","beem","python","release"],"app":"esteem/2.2.5-mobile","format":"markdown+html","community":"hive-125125"}
created2020-06-18 21:46:24
last_update2020-06-18 21:46:24
depth1
children0
last_payout2020-06-25 21:46:24
cashout_time1969-12-31 23:59:59
total_payout_value0.025 HBD
curator_payout_value0.026 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length77
author_reputation3,241,894,491
root_title"update for beem: reworking wallet and key handling"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,046,341
net_rshares207,421,832,052
author_curate_reward""
vote details (2)
@chitty ·
$0.05
I have picked your post for my daily hive voting initiative, Keep it up and Hive On!!
👍  
👎  
properties (23)
authorchitty
permlinkre-update-for-beem-reworking-wallet-and-key-handling-20200619t000104
categoryhive-139531
json_metadata""
created2020-06-19 00:01:06
last_update2020-06-19 00:01:06
depth1
children0
last_payout2020-06-26 00:01:06
cashout_time1969-12-31 23:59:59
total_payout_value0.026 HBD
curator_payout_value0.026 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length86
author_reputation86,901,300,608,582
root_title"update for beem: reworking wallet and key handling"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,048,415
net_rshares207,012,996,272
author_curate_reward""
vote details (2)
@comandoyeya ·
$0.05
La verdad muy explicito lo que has publicado, lo pondre en practica, gracias por compartir.
👍  
👎  
properties (23)
authorcomandoyeya
permlinkqc5d6s
categoryhive-139531
json_metadata{"app":"hiveblog/0.1"}
created2020-06-19 00:25:42
last_update2020-06-19 00:25:42
depth1
children0
last_payout2020-06-26 00:25:42
cashout_time1969-12-31 23:59:59
total_payout_value0.026 HBD
curator_payout_value0.026 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length91
author_reputation579,902,986,648,394
root_title"update for beem: reworking wallet and key handling"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,048,767
net_rshares206,808,884,958
author_curate_reward""
vote details (2)
@contagio ·
$0.05
You do a great job. We want to thank you from our trenches and support you whenever we can You help to eliminate the plague. Receive our medieval thanks.
👍  ,
👎  
properties (23)
authorcontagio
permlinkre-holger80-qc5jda
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.05.5"}
created2020-06-19 02:39:15
last_update2020-06-19 02:39:15
depth1
children0
last_payout2020-06-26 02:39:15
cashout_time1969-12-31 23:59:59
total_payout_value0.026 HBD
curator_payout_value0.026 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length154
author_reputation18,328,394,939,930
root_title"update for beem: reworking wallet and key handling"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,050,255
net_rshares206,604,977,755
author_curate_reward""
vote details (3)
@gitplait-mod1 ·
The way the Hive community is growing the need of coding specialist will be increased. Nice way of giving lesson to young talent. Indeed learning about Beem and future will be great for young talent. Great effort.
Your post has been curated with @gitplait community account because this is the kind of publications we like to see in our community.

Join our Community on [Hive](https://hive.blog/trending/hive-103590) and Chat with us on [Discord](https://discord.com/invite/CWCj3rw).

[Gitplait
properties (22)
authorgitplait-mod1
permlinkqc4rzf
categoryhive-139531
json_metadata{"users":["gitplait"],"links":["https://hive.blog/trending/hive-103590","https://discord.com/invite/CWCj3rw"],"app":"hiveblog/0.1"}
created2020-06-18 16:47:45
last_update2020-06-18 16:47:45
depth1
children0
last_payout2020-06-25 16:47:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length495
author_reputation64,455,719,431
root_title"update for beem: reworking wallet and key handling"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,041,732
net_rshares0
@hivebuzz ·
Congratulations @holger80! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

<table><tr><td><img src="https://images.hive.blog/60x60/http://hivebuzz.me/badges/toppayoutday.png"></td><td>Your post got the highest payout of the day</td></tr>
</table>

<sub>_You can view [your badges on your board](https://hivebuzz.me/@holger80) And compare to others on the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



###### Support the HiveBuzz project. [Vote](https://hivesigner.com/sign/update_proposal_votes?proposal_ids=%5B%22109%22%5D&approve=true) for [our proposal](https://peakd.com/me/proposals/109)!
properties (22)
authorhivebuzz
permlinkhivebuzz-notify-holger80-20200620t003735000z
categoryhive-139531
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2020-06-20 00:37:33
last_update2020-06-20 00:37:33
depth1
children0
last_payout2020-06-27 00:37:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length764
author_reputation369,389,709,206,784
root_title"update for beem: reworking wallet and key handling"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,068,029
net_rshares0
@maxuvv ·
Hi @holger80, you have received a small bonus upvote from MAXUV.
This is to inform you that you now have [new MPATH tokens](https://hive-engine.com/?p=market&t=MPATH) in your Hive-Engine wallet.
Please [read this post](https://peakd.com/hive-167922/@mpath/mpath-weekly-report-and-token-distribution-26-april-2020) for more information.
Thanks for being a member of both MAXUV *and* MPATH!
properties (22)
authormaxuvv
permlinkre-update-for-beem-reworking-wallet-and-key-handling-20200618t160403z
categoryhive-139531
json_metadata"{"app": "rewarding/0.1.0"}"
created2020-06-18 16:04:03
last_update2020-06-18 16:04:03
depth1
children0
last_payout2020-06-25 16:04:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length393
author_reputation32,074,948,443
root_title"update for beem: reworking wallet and key handling"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,041,049
net_rshares0
@rafaelaquino ·
$0.05
Very interesting what you do. Thank you for sharing and keeping us informed of all the updates. Python is wonderful!
👍  
properties (23)
authorrafaelaquino
permlinkqc53j2
categoryhive-139531
json_metadata{"app":"hiveblog/0.1"}
created2020-06-18 20:57:03
last_update2020-06-18 20:57:03
depth1
children0
last_payout2020-06-25 20:57:03
cashout_time1969-12-31 23:59:59
total_payout_value0.026 HBD
curator_payout_value0.026 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length116
author_reputation111,190,733,966,082
root_title"update for beem: reworking wallet and key handling"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,045,644
net_rshares207,626,556,926
author_curate_reward""
vote details (1)
@spiffmyst ·
Thanks for sharing something like this it would be help to many person
properties (22)
authorspiffmyst
permlinkre-holger80-2020619t163440731z
categoryhive-139531
json_metadata{"tags":["development","beem","python","release"],"app":"esteem/2.2.5-mobile","format":"markdown+html","community":"hive-125125"}
created2020-06-19 15:34:42
last_update2020-06-19 15:34:42
depth1
children0
last_payout2020-06-26 15:34:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length70
author_reputation0
root_title"update for beem: reworking wallet and key handling"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,060,646
net_rshares0
@themarkymark ·
Glad to see these updates to Beem. Wish the other libraries got similar love. 
👍  
👎  ,
properties (23)
authorthemarkymark
permlinkre-holger80-qc58mi
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.05.5"}
created2020-06-18 22:47:06
last_update2020-06-18 22:47:06
depth1
children1
last_payout2020-06-25 22:47:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length78
author_reputation1,777,477,879,631,199
root_title"update for beem: reworking wallet and key handling"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,047,292
net_rshares-518,767,564,498
author_curate_reward""
vote details (3)
@tngflx ·
$0.11
On the way for dhive! https://peakd.com/hive-139531/@tngflx/contribution-to-dhive-added-memo-encryption-and-decrypt-feature
👍  
properties (23)
authortngflx
permlinkre-themarkymark-qc9qq0
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.05.5"}
created2020-06-21 09:08:24
last_update2020-06-21 09:08:24
depth2
children0
last_payout2020-06-28 09:08:24
cashout_time1969-12-31 23:59:59
total_payout_value0.054 HBD
curator_payout_value0.054 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length123
author_reputation17,396,455,988,713
root_title"update for beem: reworking wallet and key handling"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,091,262
net_rshares450,044,955,986
author_curate_reward""
vote details (1)
@yehey ·
$0.05
Another excellent tool. Cheers to you.
👍  
👎  
properties (23)
authoryehey
permlinkqc8psn
categoryhive-139531
json_metadata{"app":"hiveblog/0.1"}
created2020-06-20 19:50:45
last_update2020-06-20 19:50:45
depth1
children0
last_payout2020-06-27 19:50:45
cashout_time1969-12-31 23:59:59
total_payout_value0.024 HBD
curator_payout_value0.025 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length38
author_reputation22,184,787,552,504
root_title"update for beem: reworking wallet and key handling"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,081,919
net_rshares206,402,750,300
author_curate_reward""
vote details (2)