forked from bitphage/golos-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_password.py
More file actions
executable file
·118 lines (93 loc) · 3.46 KB
/
change_password.py
File metadata and controls
executable file
·118 lines (93 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python
import sys
import json
import argparse
import logging
import yaml
from pprint import pprint
from golos import Steem
from golos.account import Account
from golosbase.account import PasswordKey, PublicKey
from golosbase import operations
import functions
log = logging.getLogger('functions')
key_types = [
'posting',
'active',
'owner',
'memo'
]
def main():
parser = argparse.ArgumentParser(
description='This script is for changing account keys. By default, random password are geneeated.',
epilog='Report bugs to: https://github.com/bitfag/golos-scripts/issues')
parser.add_argument('-d', '--debug', action='store_true',
help='enable debug output'),
parser.add_argument('-c', '--config', default='./common.yml',
help='specify custom path for config file')
parser.add_argument('account',
help='account name'),
parser.add_argument('-p', '--password',
help='manually specify a password'),
parser.add_argument('--broadcast', action='store_true', default=False,
help='broadcast transactions'),
args = parser.parse_args()
# create logger
if args.debug == True:
log.setLevel(logging.DEBUG)
else:
log.setLevel(logging.INFO)
handler = logging.StreamHandler()
formatter = logging.Formatter("%(asctime)s %(levelname)s: %(message)s")
handler.setFormatter(formatter)
log.addHandler(handler)
# parse config
with open(args.config, 'r') as ymlfile:
conf = yaml.load(ymlfile)
b = not args.broadcast
golos = Steem(nodes=conf['nodes_old'], no_broadcast=False, keys=conf['keys'])
account_name = args.account
account = Account(args.account, steemd_instance=golos)
# random password
if args.password:
password = args.password
else:
password = functions.generate_password()
print('password: {}\n'.format(password))
key = dict()
for key_type in key_types:
# PasswordKey object
k = PasswordKey(account_name, password, role=key_type)
privkey = k.get_private_key()
print('{} private: {}'.format(key_type, str(privkey))) # we need explicit str() conversion!
# pubkey with default prefix GPH
pubkey = k.get_public_key()
# pubkey with correct prefix
key[key_type] = format(pubkey, golos.chain_params["prefix"])
print('{} public: {}\n'.format(key_type, key[key_type]))
# prepare for json format
owner_key_authority = [[key['owner'], 1]]
active_key_authority = [[key['active'], 1]]
posting_key_authority = [[key['posting'], 1]]
owner_accounts_authority = []
active_accounts_authority = []
posting_accounts_authority = []
s = {
'account': account_name,
'memo_key': key['memo'],
'owner': {'account_auths': owner_accounts_authority,
'key_auths': owner_key_authority,
'weight_threshold': 1},
'active': {'account_auths': active_accounts_authority,
'key_auths': active_key_authority,
'weight_threshold': 1},
'posting': {'account_auths': posting_accounts_authority,
'key_auths': posting_key_authority,
'weight_threshold': 1},
'prefix': golos.chain_params["prefix"]
}
#pprint(s)
op = operations.AccountUpdate(**s)
golos.finalizeOp(op, args.account, "owner")
if __name__ == '__main__':
main()