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

in #hive-13953129 days ago




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


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:

This is a text message from holger80!
-----BEGIN META-----

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


Could verify message!

when successful.


I merged new changes of 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



Let's check : https://live.blockcypher.com/btc/address/19HWfZyax16TwFHjpDCBMzExQg9TKHTQ9f/

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:

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 or on PeakD


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.

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

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?

Fantastic tools that will bring better user experience to the Hive ecosystem. Big ups to the developers

Nice tool to check out, decrypting and encrypting the message. The best part no need to send fees.

I will play around.

Posted via OnlinebuzZ.com

Bello, Nice to meet you?

I have picked your post for my daily hive voting initiative, Keep it up and Hive On!!

Hi @holger80, you have received a small bonus upvote from MAXUV.
This is to inform you that you now have new MPATH tokens in your Hive-Engine wallet.
Please read this post for more information.
Thanks for being a member of both MAXUV and MPATH!