-
Notifications
You must be signed in to change notification settings - Fork 2
/
sign.py
executable file
·48 lines (38 loc) · 1.51 KB
/
sign.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
#!/usr/bin/env python3
import ecc_ed25519
import sys, getopt
msg = ""
secret_key_path = "/etc/casper/validator_keys/secret_key.pem"
try:
opts, args = getopt.getopt(sys.argv[1:],"hm:k:",["message=","secretkey="])
except getopt.GetoptError:
print('sign.py -m YOURMESSAGE -k PATH-TO-YOUR-SECRET-KEY')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('sign.py -m YOURMESSAGE -k PATH-TO-YOUR-SECRET-KEY')
sys.exit()
elif opt in ("-m", "--message"):
msg = arg
elif opt in ("-k", "--secretkey"):
secret_key_path = arg
if msg == "":
print("Message can't be empty!")
sys.exit()
msg_as_bytes = str.encode(msg)
try:
signature = ecc_ed25519.get_signature_from_pem_file(msg_as_bytes, secret_key_path)
except FileNotFoundError:
print("ERROR: Couldn't access your private key at this location: ", secret_key_path)
print("Please make sure your secret_key.pem file is at the given location and is accessible by the current user.")
print("If you have your key at a different location, you can define its path by using the -k parameter.")
print("Usage: sign.py -m YOURMESSAGE -k PATH-TO-YOUR-SECRET-KEY")
sys.exit()
encoded_signature = signature.hex()
# Get public key hex from the secret PEM file for informational purposes
public_key_hex = ecc_ed25519.get_public_key_hex_from_pem_file(secret_key_path)
# Add prefix
public_key_hex = "01" + public_key_hex
print("Public Key:\n", public_key_hex)
print("Message:\n", msg)
print("Signature:\n", encoded_signature)