create account

update for beem: message signing, improved address handling and fixed memo encryption/decryption by holger80

View this thread on: hive.blogpeakd.comecency.com
· @holger80 ·
$84.64
update for beem: message signing, improved address handling and fixed memo encryption/decryption

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

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

* add participation_rate to Blockchain
* beembase.transactions is deprecated
* get_block_params added to TransactionBuilder
* add Prefix class for PasswordKey, Brainkey, Address, PublicKey, PrivateKey, Base58
* New Class BitcoinAddress
* Address class has now from_pubkey class method
* Message class improved
* beempy message can be used to sign and to verify a message
* decryption of long messages fixed
* varint decoding added to memo decryption
* beempy encrypt / decrypt can be used to encrypt/decrypt a memo text with your memo key
  
## Sign and verify a message
I can now sign a message with my private memo key and everyone can verify the signature.
Assuming I would like to sign the following message with my memo key:
```
This is a text message from holger80!
```

I can do this by storing the message into a text file and run
```
beempy message -a holger80 my_message.txt
```
The message is read and signed and the following result is stored in the text file:

```
-----BEGIN HIVE SIGNED MESSAGE-----
This is a text message from holger80!
-----BEGIN META-----
account=holger80
memokey=STM6MQBLaX9Q15CK3prXoWK4C6EqtsL7C4rqq1h6BQjxvfk9tuT3N
block=44092995
timestamp=2020-06-07T20:26:54
-----BEGIN SIGNATURE-----
203020dbdde48c910ccf565413c6b44eeb7d8908c70169ce27be99d8907cf35e661e5e08abd77309b6bab4dceb9a3c6f48c0bc3ba27445b957a47b3019ec810cc1
-----END HIVE SIGNED MESSAGE-----
```
Any receiver of my signed message can now verify that the message was not modified and that it's  signed with the memo key from my account.
```
beempy message --verify my_message.txt
```
returns
```
Could verify message!
```
when successful.

## Addresses
I merged new changes of [python-graphenelib](https://github.com/xeroc/python-graphenelib) to `beemgraphenebase.account` which handle public and private keys as well as address generation. Prefix (`STM` for hive) handling is now improved.

Did you know that each hive account has also 4 bitcoin addresses that are able to receive bitcoin? You could use the corresponding private key to move then received bitcoin. Let's check if there any bitcoin on the bitcoin address corresponding to my active key.

```
from beem.account import Account
from beemgraphenebase.account import BitcoinPublicKey
account = Account("holger80")
pub_key = account["active"]["key_auths"][0][0]
btc_address = BitcoinPublicKey(pub_key).address
print(str(btc_address))
```
returns
```
19HWfZyax16TwFHjpDCBMzExQg9TKHTQ9f
```
Let's check : https://live.blockcypher.com/btc/address/19HWfZyax16TwFHjpDCBMzExQg9TKHTQ9f/

![](https://images.hive.blog/DQmVueuELUwgs3wdSQGMyA6yF7RDWA49hgjvDyBF1nrZaY8/image)

Nothing there yet. It would be also possible to convert the private key into a segwit or bech32 address (but not with beem, as do not think this is very useful).

Bitcoin address generation is used in beem for encrypting  wifs for storing them in the beempy wallet according to BIP38. The bitcoin address is used in `beemgraphenebase.bip38` for `encrypt` and `decrypt` which is then used in `beem.wallet`.


## Encrypting / Decrypting memos
I finally fixed memo encryption / decryption in beem and added a new beempy command for easier memo encrytion/decryption. It is now possible to encrypt/decrypt long messages.

I estimated the length of the varint part of the encrypted message by
```
numBytes = 16 - len(cipher) % 16
n = 16 - numBytes
message = cipher[n:]
```
Before `n` was fixed to 2 (assuming that the varint has a length of 2), which did not work for long messages, as the varint has then 4 bytes or even more.

I fixed the memo decryption (prevously the first chars of a decrypted memo were wrong) by doing a varintdecode on the decrypted memo: 
```
n = varintdecode(message)
return '#' + message[len(message) - n:].decode("utf8")
```
which allows me to remove the varint (stores the message length) part at the beginning of the decrypted message correctly.


I can now decrypt the following long message beempy:
![](https://images.hive.blog/DQmXYqmmA5NzHwA2VMtTPDxvsPq9VDJu5B9yCpCiCKDuXqa/image)
The encrypted memo should be put into quotes:
```
beempy decrypt -a holger80 hive.revolution "#2BVUtjeRYh3en8QLHgLDRojcRWMZEiKLaqPkxD9gubLcfFyH3c3JmwgGGScoEAWVTDAgsVpvC4HtsEbmsKkQuMksK8UhXu5eG2sYk1rJg3ry42bn31D5bopjmk1nAXhxenTUbsBPmeW2AQtj4CJg3DtPeUc9JCUPKd5sEbYpN2oJks3fDqcVSx8xAtw3Hk51zkxxnwECKsQ1moricvjA4rTmexCxx2RLQ89NdzQxvzQdVooJcFKRWqF3RiMdihif7bExuKffTAeqonYfN6FynA1T4hjL3y1BpYAYdPYBigdxSzNuS6EcmqRXF7vGeVeGMqZjrDZ73odakLziAW15xqTQGQYbFdo1Y72Gpt49jdk5WqQSSecNAvagCN7qYXwLUteHg84nA7mQp2mLSy2uBsftK9Q53vHbDZbu9Ldo8arF4ijBj3YDkjj5TNQq6EB4adp5JTY4tCV6AWRgBEPVHDCvTXCMQBM85L9DK9fctCou8yr61daCyxUVnfiPA9SMvTJdk4sFz6AYF7t5ZJeuLzEVE1XNYDVDfSqXoLTdkHfJv8rHiqEPny4ZqWjQNrhgqaZUvxEE7Zqvkb5UXwgWnAmR6KEP5p1U3An1USjndThtYTsRWRenWvBHZj617eunGAghr5ikFxn2fn9gqBMmyLEC1tiX3KfyYPvwtoxvU7AQqkdQhgeAdGaNezx"
```
Returns now the correct beginning and is able to decrypt the memo (in previous beem versions, the decryption of this memo did not work at all):
```
#Hello comrade, ...
```


It is also possible to encrypt a message:
```
beempy encrypt -a holger80 beempy "#test1"
```
or more than one message:
```
beempy encrypt -a holger80 beempy "#test1" "#test2"
```

I can also encrypt a memo that is only decryptable by myself:
```
beempy encrypt -a holger80 holger80 "#test1" "#test2"
```

When using the `--text` flag, the memo text is read from the provided text file and overwritten by the encrypted/decrypted text. 
```
beempy encrypt -a holger80 --text beempy my-memo-text.txt
```
___

*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 356 others
👎  
properties (23)
authorholger80
permlinkupdate-for-beem-message-signing-improved-address-handling-and-fixed-memo-encryptiondecryption
categoryhive-139531
json_metadata"{"canonical_url": "https://hive.blog/hive-139531/@holger80/update-for-beem-message-signing-improved-address-handling-and-fixed-memo-encryptiondecryption", "community": "hive-139531", "app": "beempy/0.23.12", "links": ["https://images.hive.blog/DQmXYqmmA5NzHwA2VMtTPDxvsPq9VDJu5B9yCpCiCKDuXqa/image", "https://peakd.com/witnesses", "https://hivesigner.com/sign/account-witness-vote?witness=holger80&approve=1", "https://cdn.steemitimages.com/DQmcRrwLPSywSYMierfP6um6mejeMNGjN9Rxw7audJqTDgb/beem-logo", "https://discord.gg/4HM592V", "https://images.hive.blog/DQmVueuELUwgs3wdSQGMyA6yF7RDWA49hgjvDyBF1nrZaY8/image", "https://github.com/holgern/beem", "https://github.com/xeroc/python-graphenelib", "https://live.blockcypher.com/btc/address/19HWfZyax16TwFHjpDCBMzExQg9TKHTQ9f/"], "tags": ["development", "beem", "python", "sign", "memo"]}"
created2020-06-08 21:33:45
last_update2020-06-08 21:33:45
depth0
children12
last_payout2020-06-15 21:33:45
cashout_time1969-12-31 23:59:59
total_payout_value47.660 HBD
curator_payout_value36.979 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,536
author_reputation358,857,509,568,825
root_title"update for beem: message signing, improved address handling and fixed memo encryption/decryption"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,852,370
net_rshares180,965,279,205,590
author_curate_reward""
vote details (421)
@anri.rixardinh ·
Best signals, and trade bot! - https://kintum.io/
👍  
properties (23)
authoranri.rixardinh
permlinkqboerk
categoryhive-139531
json_metadata{"links":["https://kintum.io/"],"app":"hiveblog/0.1"}
created2020-06-09 20:40:33
last_update2020-06-09 20:40:33
depth1
children0
last_payout2020-06-16 20:40: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_length49
author_reputation-1,331,112,739,183
root_title"update for beem: message signing, improved address handling and fixed memo encryption/decryption"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,870,105
net_rshares2,487,216,310
author_curate_reward""
vote details (1)
@chitty ·
I have picked your post for my daily hive voting initiative, Keep it up and Hive On!!
properties (22)
authorchitty
permlinkre-update-for-beem-message-signing-improved-address-handling-and-fixed-memo-encryptiondecryption-20200610t000427
categoryhive-139531
json_metadata""
created2020-06-10 00:04:27
last_update2020-06-10 00:04:27
depth1
children0
last_payout2020-06-17 00:04:27
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_length86
author_reputation86,901,300,608,582
root_title"update for beem: message signing, improved address handling and fixed memo encryption/decryption"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,872,746
net_rshares0
@gadrian · (edited)
$0.05
I had no idea our hive accounts also have bitcoins addresses we can use. :)

Nice updates to beem/beempy!

One of the other days I was wondering if something like this would be helpful:

A feature in an API like beem to be able to retrieve account history entries from a local blockchain mirror, provided the block id needed is older than the last block on the local blockchain mirror. Otherwise, send a request to a seed node which provides account history for newer blocks.

How I believe it would help?
- more decentralization
- less pressure on Hive nodes, especially for intensive short term use.
- probably faster scripts if enough older transactions are needed (one case I found useful for is for delegations history)

Do you think it's worth the effort to implement such an extension to beem for account history?
👍  
properties (23)
authorgadrian
permlinkre-holger80-qbnj2i
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.05.5"}
created2020-06-09 09:15:54
last_update2020-06-09 09:22:24
depth1
children0
last_payout2020-06-16 09:15:54
cashout_time1969-12-31 23:59:59
total_payout_value0.026 HBD
curator_payout_value0.027 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length821
author_reputation643,198,674,069,287
root_title"update for beem: message signing, improved address handling and fixed memo encryption/decryption"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,860,094
net_rshares201,769,839,685
author_curate_reward""
vote details (1)
@maicodon ·
$0.05
Fantastic tools that will bring better user experience to the Hive ecosystem. Big ups to the developers
👍  
👎  
properties (23)
authormaicodon
permlinkqbny3e
categoryhive-139531
json_metadata{"app":"hiveblog/0.1"}
created2020-06-09 14:40:33
last_update2020-06-09 14:40:33
depth1
children0
last_payout2020-06-16 14:40:33
cashout_time1969-12-31 23:59:59
total_payout_value0.026 HBD
curator_payout_value0.027 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length103
author_reputation122,440,993,204
root_title"update for beem: message signing, improved address handling and fixed memo encryption/decryption"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,864,563
net_rshares201,570,937,637
author_curate_reward""
vote details (2)
@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-message-signing-improved-address-handling-and-fixed-memo-encryptiondecryption-20200608t213602z
categoryhive-139531
json_metadata"{"app": "rewarding/0.1.0"}"
created2020-06-08 21:36:03
last_update2020-06-08 21:36:03
depth1
children0
last_payout2020-06-15 21:36: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: message signing, improved address handling and fixed memo encryption/decryption"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,852,413
net_rshares0
@osakivolezka42 ·
Best signals, and trade bot! - https://kintum.io/
👍  ,
👎  
properties (23)
authorosakivolezka42
permlinkqbnoia
categoryhive-139531
json_metadata{"links":["https://kintum.io/"],"app":"hiveblog/0.1"}
created2020-06-09 11:13:24
last_update2020-06-09 11:13:24
depth1
children0
last_payout2020-06-16 11:13:24
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_length49
author_reputation-526,183,582,894
root_title"update for beem: message signing, improved address handling and fixed memo encryption/decryption"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,861,609
net_rshares-412,849,959,787
author_curate_reward""
vote details (3)
@rafaelaquino · (edited)
$0.05
Thank you for sharing so I can learn more about beem.
After making the script it didn't run and I got an error. And I didn't get the error until I realized that I hadn't updated. I had installed version 0.23.11 of your previous post and when I updated to version 0.23.12 it ran perfectly and threw me the address:1G2SsQGpXsc5TGdw1i5wZv8PssiqNZC1cs. Very happy and me because the script ran. Greetings
👍  
👎  
properties (23)
authorrafaelaquino
permlinkqbnzvi
categoryhive-139531
json_metadata{"app":"hiveblog/0.1"}
created2020-06-09 15:18:57
last_update2020-06-09 15:20:03
depth1
children0
last_payout2020-06-16 15:18:57
cashout_time1969-12-31 23:59:59
total_payout_value0.026 HBD
curator_payout_value0.027 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length400
author_reputation112,315,165,556,930
root_title"update for beem: message signing, improved address handling and fixed memo encryption/decryption"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,865,245
net_rshares201,966,020,122
author_curate_reward""
vote details (2)
@robertbeeh ·
Hi
properties (22)
authorrobertbeeh
permlinkre-holger80-202068t2094606z
categoryhive-139531
json_metadata{"tags":["development","beem","python","sign","memo"],"app":"esteem/2.2.5-mobile","format":"markdown+html","community":"hive-125125"}
created2020-06-08 23:09:06
last_update2020-06-08 23:09:06
depth1
children0
last_payout2020-06-15 23:09: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_length2
author_reputation-1,370,785,712
root_title"update for beem: message signing, improved address handling and fixed memo encryption/decryption"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,853,559
net_rshares0
@tngflx ·
$0.05
Hey man what you're doing is really awesome. I'm trying to do the same with dhive. Do you need to do serialization of buffer with decoding memo? I noticed you don't do any of that with beem.
👍  
👎  
properties (23)
authortngflx
permlinkre-holger80-qbo240
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.05.5"}
created2020-06-09 16:07:15
last_update2020-06-09 16:07:15
depth1
children1
last_payout2020-06-16 16:07:15
cashout_time1969-12-31 23:59:59
total_payout_value0.026 HBD
curator_payout_value0.027 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length190
author_reputation17,396,455,988,713
root_title"update for beem: message signing, improved address handling and fixed memo encryption/decryption"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,865,975
net_rshares202,003,218,127
author_curate_reward""
vote details (2)
@holger80 ·
$0.02
I'm doing this inside the Memo class, you can see it here:
https://github.com/holgern/beem/blob/87f462aa2fa86df40e38c9a46784fc45eab7effc/beembase/memo.py#L204

Have you checked the implementation if hive-js: https://gitlab.syncad.com/hive/hive-js/-/blob/master/src/auth/memo.js ?
👍  , , ,
properties (23)
authorholger80
permlinkre-tngflx-qbob2a
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.05.5"}
created2020-06-09 19:20:36
last_update2020-06-09 19:20:36
depth2
children0
last_payout2020-06-16 19:20:36
cashout_time1969-12-31 23:59:59
total_payout_value0.012 HBD
curator_payout_value0.011 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length279
author_reputation358,857,509,568,825
root_title"update for beem: message signing, improved address handling and fixed memo encryption/decryption"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,868,897
net_rshares92,382,727,915
author_curate_reward""
vote details (4)
@yehey · (edited)
$0.05
Nice tool to check out, decrypting and encrypting the message. The best part no need to send fees.

I will play around.



---

<center><sub>Posted via [OnlinebuzZ.com](https://onlinebuzz.com/@yehey/qbmosp)</sub></center>
👍  
👎  
properties (23)
authoryehey
permlinkqbmosp
categoryhive-139531
json_metadata{"app":"hiveblog/0.1","canonical_url":"https://onlinebuzz.com/@yehey/qbmosp","links":["https://onlinebuzz.com/@yehey/qbmosp"]}
created2020-06-08 22:22:00
last_update2020-06-08 22:26:33
depth1
children1
last_payout2020-06-15 22:22:00
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_length221
author_reputation22,184,787,552,504
root_title"update for beem: message signing, improved address handling and fixed memo encryption/decryption"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,853,000
net_rshares196,550,035,703
author_curate_reward""
vote details (2)
@robertbeeh ·
Bello, Nice to meet you?
properties (22)
authorrobertbeeh
permlinkre-yehey-202068t20101675z
categoryhive-139531
json_metadata{"tags":["esteem"],"app":"esteem/2.2.5-mobile","format":"markdown+html","community":"hive-125125"}
created2020-06-08 23:10:03
last_update2020-06-08 23:10:03
depth2
children0
last_payout2020-06-15 23:10: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_length24
author_reputation-1,370,785,712
root_title"update for beem: message signing, improved address handling and fixed memo encryption/decryption"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,853,573
net_rshares0