forked from Stork-Oracle/stork-external
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_keys.py
71 lines (57 loc) · 2.4 KB
/
generate_keys.py
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
#!/usr/bin/env python3
import argparse
import eth_account
import os
import random
import secrets
import string
import json
import base64
# local
import starknet
def main():
parser = argparse.ArgumentParser(description='Generate a keys.json file for the Stork Publisher Agent')
parser.add_argument('--oracle-id',
required=True,
help='The 5 character name for the publisher, e.g. "nahsr"')
parser.add_argument('--signature-types',
required=True,
nargs='+',
choices=["stark", "evm"],
help='The signature types you want to use for this publisher agent, space separated')
parser.add_argument('--pull-based-auth',
required=False,
help='The auth token for your pull-based price source, if using')
parser.add_argument('--output-path',
required=False,
default="/tmp/publisher-agent/",
help='The directory to write your key to')
args = parser.parse_args()
if len(args.oracle_id) != 5:
parser.error('oracle id must be exactly 5 characters long')
keys_dict = {
"OracleId": args.oracle_id,
}
if args.pull_based_auth:
keys_dict["PullBasedAuth"] = args.pull_based_auth
if "evm" in args.signature_types:
evm_private_token_hex = secrets.token_hex(32)
evm_private_key = "0x" + evm_private_token_hex
evm_account = eth_account.Account.from_key(evm_private_key)
evm_public_key = evm_account.address
keys_dict["EvmPrivateKey"] = evm_private_key
keys_dict["EvmPublicKey"] = evm_public_key
if "stark" in args.signature_types:
stark_private_key = starknet.get_random_private_key()
stark_public_key = starknet.private_to_stark_key(stark_private_key)
stark_private_key_hex = hex(stark_private_key)
stark_public_key_hex = hex(stark_public_key)
keys_dict["StarkPrivateKey"] = stark_private_key_hex
keys_dict["StarkPublicKey"] = stark_public_key_hex
os.makedirs(args.output_path, exist_ok=True)
out_filepath = os.path.join(args.output_path, f'keys.json')
with open(out_filepath, 'w') as f:
f.write(json.dumps(keys_dict, indent=2))
print(f'Wrote keys file to {out_filepath}')
if __name__ == "__main__":
main()