MMoSP003E- steem-python customize a tools for change keys

in hive-180932 •  last month 

Generally, we register our account from the official website steemit.com, which is relatively safe.

After the keys is lost (stolen), you can find steemit.com to help recover.

Of course, being able to recover means being changed by others. However, in the steem mechanism, if the last keys cannot be provided, it cannot be recovered.

Therefore, no matter where our account is obtained, change the keys twice in a row, and keep the keys changed twice, then we can only recover the keys ourselves, and others can't recover the keys.

We usually login to steemit.com and change the keys in the official online wallet, but it's more troublesome. It's better to change it directly with the command line tool

Demo for customize a tools for change keys(MMoSP003_customize_a_tools_for_change_keys.py):

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# 修改 steem 帐号密码
# python MMoSP003_customize_a_tools_for_change_keys acc wif
# acc:steem账户名
# wif:steem账户名旧的 owner private key

import sys
import json
import steem
import steembase
from steem.steemd import Steemd
from steem.instance import set_shared_steemd_instance
from steembase.account import PasswordKey, BrainKey
from steembase import operations

# 必须参数
try:
    acc = sys.argv[1]
    wif = sys.argv[2]
except Exception as e:
    sys.exit()
print('acc:', acc)
print('wif:', wif)

steemd_api_nodes = [
    'https://anyx.io',
    'https://api.steemit.com'
]
stm = Steemd(nodes=steemd_api_nodes)
set_shared_steemd_instance(stm)

# 生成一套新密码
bk = BrainKey()
brainkey = bk.get_brainkey()
print('brain key:', str(brainkey))
prikey = str(bk.get_private())
print('private key:', str(prikey))
pubkey = format(bk.get_public(), "STM")
print('public key:', str(pubkey))

# 获取整套密钥
posting_key = PasswordKey(acc, pubkey, role="posting")
active_key = PasswordKey(acc, pubkey, role="active")
memo_key = PasswordKey(acc, pubkey, role="memo")
owner_key = PasswordKey(acc, pubkey, role="owner")
# 提取整套密钥中的私钥
active_privkey = active_key.get_private_key()
posting_privkey = posting_key.get_private_key()
owner_privkey = owner_key.get_private_key()
memo_privkey = memo_key.get_private_key()
print('posting_privkey:', str(posting_privkey))
print('active_privkey:', str(active_privkey))
print('owner_privkey:', str(owner_privkey))
print('memo_privkey:', str(memo_privkey))
# 提取整套密钥中的公钥
# active_pubkey = active_key.get_public_key()
# owner_pubkey = owner_key.get_public_key()
# posting_pubkey = posting_key.get_public_key()
memo_pubkey = memo_key.get_public_key()
print('memo_pubkey:', str(memo_pubkey))

try:
    old_owner_key = str(PasswordKey(acc, wif, "owner").get_private_key())

    client = steem.Steem(nodes=steemd_api_nodes, keys=[old_owner_key])
    #client = steem.Steem(nodes=['https://testnet.steem.vc'], keys=[wif])

    new_pubkey = {}
    for role in ["owner", "active", "posting", "memo"]:
        private_key = PasswordKey(
            acc, pubkey, role).get_private_key()
        new_pubkey[role] = str(private_key.pubkey)

    new_data = {
        "account": acc,
        "json_metadata": {},
        "owner": {
            "key_auths": [
                [new_pubkey["owner"], 1]
            ],
            "account_auths": [],
            "weight_threshold": 1
        },
        "active": {
            "key_auths": [
                [new_pubkey["active"], 1]
            ],
            "account_auths": [],
            "weight_threshold": 1
        },
        "posting": {
            "key_auths": [
                [new_pubkey["posting"], 1]
            ],
            "account_auths": [],
            "weight_threshold": 1
        },
        "memo_key": new_pubkey["memo"]
    }
    print("New data:", new_data)

    op = operations.AccountUpdate(**new_data)
    result = client.commit.finalizeOp(op, acc, "owner")
    print("Result:", result)
except Exception as err:
    print(acc, " err:", err)

Run it:python MMoSP003_customize_a_tools_for_change_keys dappcoder ownerkey
Results consistent with expectations:
屏幕快照 2020-02-17 上午2.58.34.png

English list:

#esteem #hive-139531 #steemdevs #community #programming
MMoSP000E-< make money on steem-python > Preface
MMoSP001E- install steem python with anaconda
MMoSP002E - use steem-python make a robot that can automatically say hello to contents under the tag

中文列表

#cn #hive-180932 #chinese #hive-143316
MMoSP000C-《steem-python赚钱实战教程》序言
MMoSP001C- Anaconda 安装 steem-python 开发环境
MMoSP002C- steem-python 开发一个会自动问某个标签下内容的机器人
MMoSP003C- steem-python 定制修改密码的工具

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @dappcoder! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You distributed more than 900 upvotes. Your next target is to reach 1000 upvotes.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Do not miss the last post from @steemitboard:

Valentine's day challenge - Give a badge to your beloved!
Vote for @Steemitboard as a witness to get one more award and increased upvotes!