forked from opentensor/bittensor-charter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsign_charter.py
49 lines (37 loc) · 1.38 KB
/
sign_charter.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
import bittensor
from bittensor import Keypair
import json
charter_file = "./charter.md"
output_file = "./signatures.json"
name = input("Your entity's descriptive name (e.g. Opentensor Foundation):\n")
url = input("Your validator url (e.g. www.opentensor.org ) [Optional]:\n")
mnemonic = input(
"The mnemonic of your validator's hotkey "
"( default location: ~/.bittensor/wallets/<coldkey>/hotkeys/<validator> )\n"
)
keypair = Keypair.create_from_mnemonic(mnemonic)
signature_entry = dict()
signature_entry[keypair.ss58_address] = {
"name": name,
"url": url,
}
def sign_charter(keypair):
# First load the charter text file
charter = ""
with open (charter_file, "r") as file:
charter = file.read()
# Now sign it with wallet hotkey
signature = keypair.sign(charter)
signature_entry[keypair.ss58_address]["signature"] = signature.hex()
if keypair.verify(charter, signature):
with open(output_file, "r") as file:
signatures = json.loads(file.read())
signatures.update(signature_entry)
with open(output_file, "w") as file:
file.write(json.dumps(signatures, indent=4, ensure_ascii=False))
return signature_entry
return None
# Load the wallet using the supplied
signature = sign_charter(keypair)
if signature:
print("Signature: \n {}. Saved in file {}".format(signature, output_file))