Cleanups and prepping for encryption

This cleans up some types, moves some typing to loading and saving keys,
uses clearer object names, and passes a crypto system into chatter.

This lays the groundwork for adding encryption.
This commit is contained in:
Teknique
2023-08-02 21:12:26 -07:00
parent 9a65f1b1bf
commit 04354d79c9
2 changed files with 44 additions and 31 deletions

View File

@@ -3,6 +3,8 @@
import json
from pathlib import Path
import veilid
KEYFILE = Path(".demokeys")
@@ -10,14 +12,19 @@ def read_keys() -> dict:
"""Load the stored keys from disk."""
try:
keydata = KEYFILE.read_text()
raw = KEYFILE.read_text()
except FileNotFoundError:
return {
"self": None,
"peers": {},
}
return json.loads(keydata)
keys = json.loads(raw)
if keys["self"] is not None:
keys["self"] = veilid.KeyPair(keys["self"])
for name, pubkey in keys["peers"].items():
keys["peers"][name] = veilid.PublicKey(pubkey)
return keys
def write_keys(keydata: dict):