update for beem: reworking wallet and key handling
hive-139531·@holger80·
0.000 HBDupdate for beem: reworking wallet and key handling
## Repository https://github.com/holgern/beem<center>  </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)*
👍 elleok, laissez-faire, ronak10, crypticat, everyoung, lizanomadsoul, manncpt, jnmarteau, opt2o, thehealthylife, payger, globalschool, tinyhousecryptos, techslut, swedishdragon76, abandi, natur-pur, online-24-7, onealfa, crokkon, executive-board, awesome-gadgets, dera123, saboin, maxuvv, ravensavage, imtase, baiboua, akioexzgamer, yuza, paopaoza, ten-years-before, puza, steementertainer, steembasicincome, gerber, nealmcspadden, amico, steem.leo, mice-k, steemcityrewards, dcityrewards, hivecur, ezzy, exyle, deathwing, emrebeyler, anikys3reasure, sbi-tokens, qwertm, dpend.active, daan, d-pend, shitsignals, felander, accelerator, yogacoach, roleerob, pataty69, purefood, chronocrypto, unconditionalove, cadawg, bestboom, sbi2, freddio, nateaguila, swisswitness, gallerani, dlike, triptolemus, bobby.madagascar, ldp, determine, permaculturedude, sm-silva, milu-the-dog, freddio.sport, zaku-pal, zaku-leo, asteroids, one.life, maxuvd, maxuve, blocktvnews, folklure, sketching, netaterra, dune69, mys, caladan, blockbrothers, followjohngalt, battlegames, steemindian, triplea.bot, dappcoder, therealyme, huaren.news, ribary, staryao, sbi3, goodreader, whd, rafalski, fbslo, warnas, beleg, gorbisan, munhenhos, arkmy, reverendrum, mannaman, danpendergraft, infinite-love, flyingbolt, hungryharish, searchbot, piratedice, sbi4, mistia, pfdm, sbi5, sbi6, ew-and-patterns, benedict08, erikah, sbi7, tipsybosphorus, gerbo, abh12345, revisesociology, b00m, mermaidvampire, jimcustodio, spamfarmer, plankton.token, hivelander, philnewton, tobias-g, sbi8, florino, sbi9, abitcoinskeptic, ilovecanada, triviummethod, therealwolf, nobyeni, sbi10, firefuture, jpphotography, nerdtopiade, slobberchops, ticketyboo, ticketywoof, borbina, onetin84, smartsteem, casberp, whack.science, satren, tombstone, djennyfloro, robertoueti, wiseagent, matheusggr, tmarisco, fireguardian, hranhuk, mynotsofitlife, eraizel, pagliozzo, deividluchi, kitty-kitty, jussara, epicdice, unitedpeople, markkujantunen, lelon, avel692, pocoto, mcoinz79, carlpei, brucutu, brucutu2, borran, tarazkp, hasmez, tubiska, gagago, thrasher666, brucutu1, iamjohn, babytarazkp, stevescoins, nokodemion, cyrillo, carioca, blockchainpeople, gamer00, frankydoodle, izzynoel, daath, dalz, moneytron, cpt-sparrow, maxer27, ronavel, themarkymark, kibela, anech512, danielsaori, buildawhale, upmyvote, ipromote, agent14, sharker, makerhacks, ronaldoavelino, solarwarrior, onepercentbetter, blacklux, offgridlife, isnochys, itchyfeetdonica, forecasteem, em3di, bubke, kimzwarch, daisyphotography, chrismadcboy2016, sudefteri, aiyumi, ataliba, alitavirgen, kahvesizlik, codingdefined, realgoodcontent, akifane, urdreamscometrue, cultus-forex, broxi, fractalnode, lemouth, syedumair, fw206, merlion, besheda, hungrybear, gunthertopp, tipu, omstavan, lesmouths-travel, votebetting, mxzn, techken, happy-soul, julialee66, stefannikolov, steemitcuration, kryptogames, dachcolony, jalentakesphotos, eikejanssen, matschi, dreimaldad, rufruf, richie.rich, sparschwein, hongdangmu, votum, tabea, condeas, helpyou, digital.mine, actifit-peter, monster.oo7, spicywoman, skepticology, mytechtrail, dollarbills, jerrybanfield, bronkong, anli, andrepol, candyboy, maxpatternman, inteligente, kr-coffeesteem, re2pair, detetive, freebornsociety, raspibot, likwid, gadrian, fourfourfun, backinblackdevil, promobot, steemprotect, furioslosi, a-bot, flemingfarm, peter2017, jacekw, superlao, gadrian-sp, imbartley, ctl001, fengchao, liverpool-fan, cst90, losi, leeyh, sm-skynet, blue.rabbit, arcange, flugschwein, leeyh2, leeyh3, leeyh5, steempearls, ladyinblack, sashas, properfraction, linuxbot, smon-joa, kingscrown, eunsik, szf, justyy, buzzbeergeek, leighscotford, steemitcitizen, patricklancaster, ericandryan, dadview, adventureevryday, mdosev, gringo211985, lauchmelder, raphaelle, alinalazareva, evernoticethat, oadissin, hamsa.quality, pladozero, actifit-devil, samujaeger, bartheek, curationvoter, eva-julia, jacuzzi, curationhelper, meins0815, steem-meetup-ffb, meins0816, sniem5180, mein2070, crimo, naltedtirt, longer, funnyman, holycow2019, vaansteam, agromeror, mammasitta, massivevibration, onartbali, linnyplant, tonalddrump, saltiberra, edb, udabeu, gerdtrudroepke, tokenindustry, commonlaw, kissi, captain.kirk, ssc-token, korinkrafting, gitplait, tykee, bala41288, drsensor, kiddarko, detlev, nascimentoab, steemcleaners, logic, hivewatchers, cryptocurator, beehivetrader, lrekt01, morellys2004, muscara, maxsieg, jeanpi1908, j-p-bs, steempty, fminerten, archonapp, edicted, hextech, daan007, peterpanpan, scorer, elrosso, rashid001, landshutbrauhaus, jphamer1, androshchuk, dhaneshpk, abrockman, fooblic, techtek, titusfrost, gulf41, soriful12, espoem, blocktrades, tomatom, frassman, memepress, jancharlest, sayago, emperorhassy, goodcontentbot, kggymlife, kgswallet, mr-critic.aaa, bilpcoinbpc, termitemusic, gabrielatravels, celinavisaez, lionsuit, jkramer, oluwoleolaide, shaotech, jexus77, scholaris, ttg, tudors, kabolo, steempower-001, oaldamster, schlafhacking, rafaelaquino, the.rocket.panda, inertia, santigs, davidesimoncini, softworld, mehmetfix, daring-celt, kaeserotor, cardboard, cfminer, grecki-bazar-ewy, pl-kuchnia, famegirl, tokita, idkpdx, goumao, wf9877, afiqsejuk, russellstockley, sampraise, tiababi, bluewall, santoninoatocha, chitty, maryincryptoland, timcliff, sonder-an, norbu, waqasrizvi, cam1lo, rocksg, marian0, contagio, pvinny69, perazart, romiferns, sadvil, potplucker, pichat, ace108, hellohive, medro-martin, skuld2000, astrolabio, egplus, minigame, mini.supporter, waytolifecare, futurecurrency, yuriy4, khan.dayyanz, bengiles, ericahan, rryblogs, tazi, gmf, theshaki, fingolfin, judasp, actnearn, proctologic, poweroflife, kyawkyawaung123, vishal2, invest.crypto, ssjsasha, steam77, ogst0311, safar01, v4vapid, primeradue, enki, atanas007, reza-shamim, sanaee, masummim50, donald.porter, samscalet, olassy, pyramidone, kotturinn, karianna, versofuster, phasewalker, marryiv, luzrojasdg, xxxthorxxx, rxhector, olamhen, crysis, denizcakmak, circa, improbableliason, jammer1982, wongbraling, abu.hair, linares, sleepingcowboy, stuntman.mike, afrikanprince, zakia, skohieone, godlovermel25, apnigrich, sohaggazi420, tamsguitar, yoogyart, alequintrel, tong023960, boholtamsi, sorianos, uwelang, itstushar21, rdmzlars, italy.art, petru.lesanu, enver.tiler, afrikablr, athproduction, tradingideas, marlians.spt, ibc, cgbooth, mangle, jishan5, diegor, ixindamix, patronpass, plusvault, leynedayana, picciridda2, katrin-lux, sekhet, yehey, shares, branding, broadcast, automation, council, pesos, petscorner, holger80, dein-problem, fullnodeupdate, nuthman, herbacianymag, niki25, cesinfenianos, mare123, ssekulji, binkyprod, jewel-lover, arabisouri, ahmedsy, mrsyria, marymi, irynochka, one-eye, doodie1996, azirgraff, maskur2840, andrewmusic,