create account

update for beem: support for Ledger Nano (S/X) has been added by holger80

View this thread on: hive.blogpeakd.comecency.com
· @holger80 · (edited)
$131.44
update for beem: support for Ledger Nano (S/X) has been added

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

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

The newest beem version can be installed by:

```
pip install -U beem
```
If you want to use Ledger Nano, then you need also:

```
pip install -U ledgerblue
```

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.7
* Fix update_account_jsonmetadata and add posting_json_metadata property to Account
* Add Ledger Nano S support
* beempy -u activates ledger signing
* beempy -u listkeys shows pubkey from ledger
* beempy -u listaccounts searches for accounts that have pubkey derived from attached ledger
* beempy -u keygen creates pubkey lists that can be used for newaccount and changekeys
* new option use_ledger and path for Hive
* Allow role selection in keygen


## Changelog for versions 0.23.6
* `beempy --key key_list.json command` can be used to set keys in beempy without using the wallet.

## Using the Ledger Nano for signing

beem/beepy is the first library/application that supports signing of operation with the ledger Nano S/X hardware wallet. It uses the [Hive wallet application for ledger Nano S/X](https://peakd.com/hive-139531/@netuoso/hive-application-for-the-ledger-nano-s-x-hardware-wallet) from @netuoso.

Uploading the app to a Nano X is not yet possible.

You need to install the Hive app to your ledger Nano. You can download it from [ledger-hive-app](https://github.com/netuoso/ledger-app-hive) by @netuoso.
Please read the readme on how to install the app to your ledger.

When you sucessfully could install the Hive app to your ledger, you need to select it and enter `Open application`.


You need also install ledgerblue
```
pip install -U ledgerblue
```

You can test if everything works with
```
beempy -u listkeys
```
The `-u` or `--use-ledger` parameter activates ledger support for all beempy commands.
If you see
```
ledgerblue.commException.CommException: Exception : Invalid status 6d00 (Unexpected state of device: verify that the right application is opened?)
```
your setup is not correct. If you see
```
+-------------------------------------------------------+
| Available Key for 48'/13'/0'/0'/0'                    |
+-------------------------------------------------------+
| STM...                                                | 
+-------------------------------------------------------+
```
everything is set up.

## Changing your keys
You need to change your keys to the public keys that your ledger provides before using the ledger for signing. It is also possible to change only the owner key.

As private keys will not leave your hardware wallet, you cannot put them into keychain or peakd as before. You can only sign operations on apps that support the ledger. 

When you lose your ledger and your recovery phrase, you lose the ability to sign with that role. E.g. when you changed your owner key, and you lost your ledger and the recovery phrase, you cannot change your account keys anymore.

In the current state (lack of ledger support by other apps), i recommend to change only the owner key.

## Setting the path
The pubkeys that are provided by the ledger are derived from the given path.
A  path for hive consists of 

```
48'/13'/role number'/account index'/key sequence'
```
The role number is 0 for owner, 1 for active, 4 for posting and 3 for memo.

You need to assign an account index number to your account. You are starting with 0 and when you plan to use a second account, you need to increase this index. The key index starts with 0 for each role and account index. Whenever you change your keys, you need to increase the key sequence index.

### Changing your owner, active and posting key
It is not recommended to change the memo key (no encryption support for ledger yet on beem yet), this is the maximum setup. Changing your owner, active and posting key means at this moment (when more app add support for ledger, this will change):

* all operation can only be broadcasted by beem/beempy
* Voting, transferring on a mobile device is not possible
* keychain usage is not possible
* peakd, hive.blog cannot be used for voting or any other operation
* hive-engine or any dapp cannot be longer used

At first, three new pubkeys needs to be obtained from the ledger:
```
beempy -u keygen --account 3 --role owner,active,posting
```

This beempy command creates three pubkeys for the account index 3 derived from the following paths: 

* ` 48'/13'/0'/3'/0'`
* ` 48'/13'/1'/3'/0'`
* ` 48'/13'/4'/3'/0'`

You can save the pubkeys to a json for easier key changing by:

```
beempy -u keygen --account 3 --role owner,active,posting --export-pub beembot.json
```

In both cases you will be asked to approve the shown pubkeys on your ledger Nano.

We can now change the keys with
```
beempy changekeys --import-pub beembot.json beembot
```

## Changing your owner and active key
This involves changing your owner and active key.

* all operation that need an active key can only be broadcasted by beem/beempy. 
* transferring Hive/HBD on a mobile device is not possible
* keychain usage is not possible for operation needing an active key
* hive-engine or any dapps that are using custom_json signed with an active key cannot be longer used.

```
beempy -u keygen  --role owner,active --export-pub account_pubkeys.json
```
You can set the account index with `--account`.
Changing the keys can be done with `beempy changekeys` as shown above.

## Changing your owner key
This changes only the owner key. Active and posting keys are still managed with private keys as before. Until ledger is not supported by keychain or on mobile, this is the most likely use-case now.

* Changing your keys needs to be done with beem/beempy

```
beempy -u keygen --role owner --export-pub account_pubkeys.json
```
You can set the account index with `--account`.
Changing the keys can be done with `beempy changekeys` as shown above.

You may need to change the default path. When you used `--account 2`, you need to set
```
beempy set default_path "48'/13'/0'/2'/0'"
```

Whenever you use `beempy -u`, this path is used for signing.

## Checking if changing keys was successfully
The following command checks if a derived pubkey from the ledger is set somewhere in Hive using `getAccountFromPublicKey` from the wallet class. 
```
beempy -u listaccounts
```
returns then
```
+---------+---------+-------------------------------------------------------+------------------+
| Name    | Type    | Available Key                                         | Path             |
+---------+---------+-------------------------------------------------------+------------------+
| beembot | owner   | STM7UYXcqJsZqoroPKoziDmB3XHSVfnLbLJ9TWSVsD4zC7YHsdgo5 | 48'/13'/0'/3'/0' |
| beembot | active  | STM7a1bcn9Anx7F2dKZGEkbVRFbCHT9exx42SSKd4JicJW82VQtAc | 48'/13'/1'/3'/0' |
| beembot | posting | STM7cvheXK2FTEAkWe1U7SD2W6H6H3a6uJ28ors37rxcE5evP5fji | 48'/13'/4'/3'/0' |
+---------+---------+-------------------------------------------------------+------------------+
```

## Set the path
As we have used an account index > 0, we must change the default path. At the moment, only one path can be stored in default_path.
```
beempy set default_path "48'/13'/0'/3'/0'"
```
We will now sign all transactions with the owner key, until the path is changed or set for a transaction with `--path`.

You can check which pubkey is returned for the actually set `default_path` with
```
beempy -u listkeys
```
The shown pubkey can checked with
```
beempy info STM...
```

## Using the ledger to sign transactions

We can now sign all transactions by the ledger, when `-u` or `--use-ledger` is set.

```
beempy -u transfer -a beembot holger80 0.001 HIVE "test with ledger"
```
This is now signed with the owner key, as default_path is `"48'/13'/0'/3'/0'"`.
We can sign the same trx with the active by setting the path to `"48'/13'/1'/3'/0'"`:
```
beempy -u --path "48'/13'/1'/3'/0'" transfer -a beembot holger80 0.001 HIVE "test with ledger"
```

## Building and signing a transaction in python

```
from beem import Hive
from beem.transactionbuilder import TransactionBuilder
from beembase import operations
hive = Hive(use_ledger=True, path="48'/13'/1'/3'/0'")

tx = TransactionBuilder(blockchain_instance=hive)

transfer_dict = {"from": 'beembot', "to": 'holger80',
                 "amount": '0.001 HIVE', "memo": 'test with ledger'}
op = operations.Transfer(**transfer_dict)
tx.appendOps(op)
tx.sign()
tx.broadcast()

```

It is also possible to use the predefined broadcast function
```
from beem import Hive
from beem.account import Account
hive = Hive(use_ledger=True, path="48'/13'/1'/3'/0'")
account = Account("beembot", blockchain_instance=hive)
account.transfer("holger80", 0.001, "HIVE", "test with ledger")
```

Sending all four transfers had worked:
![](https://images.hive.blog/DQmQP4epEqsc67hw44vAv7ZYphUJjjGJRcrYaEk4gCpR576/image)
I was asked everytime to check the transfer op and had to validate every field.


## Advantages for changing the owner key
Letting the ledger signing with the owner key has some advantages:

* beempy can be used without entering any keys, as I can sign all operations with the owner key
* Each operation must be reviewed on the ledger before broadcasting
* The owner key cannot be accidentally pasted
* When I lose the keys to my hive account, I can easily create new keys, as the owner key is stored in the ledger.
* My owner key is protected against pishing and hacking.

I just need to take good care of the ledger device and the recovery words.

## Roadmap
For the next release, I will work on multisigning with ledger as one signer (at the moment, only one signer is possible when using ledger). Also, a better path handling is needed. At the moment, only one default_path can be set. Something like storing the path for all used keys, depending on roles and accounts in a database would be useful. Parallel storage of keys and paths would also nice.

___

*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 346 others
👎  ,
properties (23)
authorholger80
permlinkupdate-for-beem-support-for-ledger-nano-sx-has-been-added
categoryhive-139531
json_metadata"{"community": "hive-139531", "app": "beempy/0.23.8", "tags": ["development", "beem", "python", "ledger"]}"
created2020-05-12 19:23:15
last_update2020-05-16 19:23:51
depth0
children13
last_payout2020-05-19 19:23:15
cashout_time1969-12-31 23:59:59
total_payout_value71.154 HBD
curator_payout_value60.290 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length10,729
author_reputation358,857,509,568,825
root_title"update for beem: support for Ledger Nano (S/X) has been added"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,335,507
net_rshares218,832,709,217,129
author_curate_reward""
vote details (412)
@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-support-for-ledger-nano-sx-has-been-added-20200518t000200
categoryhive-139531
json_metadata""
created2020-05-18 00:02:03
last_update2020-05-18 00:02:03
depth1
children0
last_payout2020-05-25 00:02: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_length86
author_reputation86,901,300,608,582
root_title"update for beem: support for Ledger Nano (S/X) has been added"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,435,397
net_rshares0
@gitplait ·
You never cease to amaze us with your awesome works. We really appreciate your contribution to the growth of Hive. This nice publication will be featured in our Gitplait-elite publication today.
properties (22)
authorgitplait
permlinkqa9f4k
categoryhive-139531
json_metadata{"app":"hiveblog/0.1"}
created2020-05-13 07:51:09
last_update2020-05-13 07:51:09
depth1
children0
last_payout2020-05-20 07:51:09
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_length194
author_reputation911,220,543,569
root_title"update for beem: support for Ledger Nano (S/X) has been added"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,344,053
net_rshares0
@holger80 ·
$0.68
#posh https://twitter.com/holger80_/status/1260293595518697474
👍  , , ,
properties (23)
authorholger80
permlinkre-holger80-qa8hdy
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.05.2"}
created2020-05-12 19:42:00
last_update2020-05-12 19:42:00
depth1
children0
last_payout2020-05-19 19:42:00
cashout_time1969-12-31 23:59:59
total_payout_value0.338 HBD
curator_payout_value0.338 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length62
author_reputation358,857,509,568,825
root_title"update for beem: support for Ledger Nano (S/X) has been added"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,335,771
net_rshares1,738,060,474,728
author_curate_reward""
vote details (4)
@howo ·
THIS IS AWESOME !

You managed this in such a short amount of time I'm impressed. I can't wait to receive my ledger to test it ! 
properties (22)
authorhowo
permlinkre-holger80-qa9v44
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.05.2"}
created2020-05-13 13:36:06
last_update2020-05-13 13:36:06
depth1
children0
last_payout2020-05-20 13:36: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_length129
author_reputation515,737,821,338,631
root_title"update for beem: support for Ledger Nano (S/X) has been added"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,348,214
net_rshares0
@littleksroad ·
support
properties (22)
authorlittleksroad
permlinkqa9uhh
categoryhive-139531
json_metadata{"app":"hiveblog/0.1"}
created2020-05-13 13:22:30
last_update2020-05-13 13:22:30
depth1
children0
last_payout2020-05-20 13:22:30
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_length7
author_reputation75,907,335,963,103
root_title"update for beem: support for Ledger Nano (S/X) has been added"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,348,058
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-support-for-ledger-nano-sx-has-been-added-20200512t192546z
categoryhive-139531
json_metadata"{"app": "rewarding/0.1.0"}"
created2020-05-12 19:25:48
last_update2020-05-12 19:25:48
depth1
children0
last_payout2020-05-19 19:25:48
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: support for Ledger Nano (S/X) has been added"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,335,538
net_rshares0
@netuoso ·
$1.29
THIS IS ABSOLUTELY FUCKING AMAZING!

I have tested it and found a minor issue. Submitted a PR on the repo for you to review. Otherwise, it works and it works damn well! Your implementation is such beauty and you did it in like 2 days. I am impressed!

It is quite rewarding to see this thing live and working so well! Hive has the best fucking community around.
👍  , , ,
👎  
properties (23)
authornetuoso
permlinkre-holger80-qa8n2x
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.05.2"}
created2020-05-12 21:44:57
last_update2020-05-12 21:44:57
depth1
children2
last_payout2020-05-19 21:44:57
cashout_time1969-12-31 23:59:59
total_payout_value0.963 HBD
curator_payout_value0.331 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length361
author_reputation151,901,967,807,285
root_title"update for beem: support for Ledger Nano (S/X) has been added"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,337,814
net_rshares4,335,791,242,060
author_curate_reward""
vote details (5)
@holger80 ·
$1.01
Thanks,
I published 0.23.8 which includes your PR.
👍  , , , ,
properties (23)
authorholger80
permlinkre-netuoso-qa8ohx
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.05.2"}
created2020-05-12 22:15:48
last_update2020-05-12 22:15:48
depth2
children0
last_payout2020-05-19 22:15:48
cashout_time1969-12-31 23:59:59
total_payout_value0.506 HBD
curator_payout_value0.506 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length50
author_reputation358,857,509,568,825
root_title"update for beem: support for Ledger Nano (S/X) has been added"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,338,376
net_rshares2,490,593,399,283
author_curate_reward""
vote details (5)
@tykee ·
@netuoso is "F" excited. It's all over the texts. Great work @holger80
properties (22)
authortykee
permlinkqa9aoh
categoryhive-139531
json_metadata{"users":["netuoso","holger80"],"app":"hiveblog/0.1"}
created2020-05-13 06:14:42
last_update2020-05-13 06:14:42
depth2
children0
last_payout2020-05-20 06:14: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_reputation233,202,435,251,808
root_title"update for beem: support for Ledger Nano (S/X) has been added"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,343,095
net_rshares0
@nulledgh0st ·
$0.13
Amazing work @holger80 - I am going to give this a try today. Thanks a million for building this out!
👍  
properties (23)
authornulledgh0st
permlinkre-holger80-2020512t132653332z
categoryhive-139531
json_metadata{"tags":["development","beem","python","ledger"],"app":"esteem/2.2.7-surfer","format":"markdown+html","community":"esteem.app"}
created2020-05-12 20:26:54
last_update2020-05-12 20:26:54
depth1
children0
last_payout2020-05-19 20:26:54
cashout_time1969-12-31 23:59:59
total_payout_value0.062 HBD
curator_payout_value0.065 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length101
author_reputation28,154,041,116,036
root_title"update for beem: support for Ledger Nano (S/X) has been added"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,336,441
net_rshares378,640,875,591
author_curate_reward""
vote details (1)
@stranger27 ·
Thank you for amazing work! I know it is not related to current topic, but could you, please make a post or explain how to claim pending rewards using hiveengine or beem? It is quite clear how to stake tokens but in order to do it one should claim them first. I wreck my brain in order to solve it but so far with no result.
properties (22)
authorstranger27
permlinkqabket
categoryhive-139531
json_metadata{"app":"hiveblog/0.1"}
created2020-05-14 11:40:06
last_update2020-05-14 11:40:06
depth1
children0
last_payout2020-05-21 11:40: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_length324
author_reputation49,275,349,388,874
root_title"update for beem: support for Ledger Nano (S/X) has been added"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,365,600
net_rshares0
@themarkymark ·
https://media.giphy.com/media/rl0FOxdz7CcxO/giphy.gif
👎  
properties (23)
authorthemarkymark
permlinkre-holger80-qa8n2h
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.05.2"}
created2020-05-12 21:44:39
last_update2020-05-12 21:44:39
depth1
children1
last_payout2020-05-19 21:44:39
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_length53
author_reputation1,778,537,713,099,540
root_title"update for beem: support for Ledger Nano (S/X) has been added"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,337,807
net_rshares-148,368,524,726
author_curate_reward""
vote details (1)
@raymondelaparra ·
Excelent
👍  
properties (23)
authorraymondelaparra
permlinkql1r0m
categoryhive-139531
json_metadata{"app":"hiveblog/0.1"}
created2020-12-09 00:38:12
last_update2020-12-09 00:38:12
depth2
children0
last_payout2020-12-16 00:38:12
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_length8
author_reputation71,178,692,953,480
root_title"update for beem: support for Ledger Nano (S/X) has been added"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,873,380
net_rshares8,124,163,565
author_curate_reward""
vote details (1)