Tpayne101 commited on
Commit
0482082
·
verified ·
1 Parent(s): da34586

Create identity_core.py

Browse files
Files changed (1) hide show
  1. identity_core.py +29 -0
identity_core.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import uuid
2
+ import hashlib
3
+ import json
4
+ import os
5
+
6
+ class IdentityManager:
7
+ def __init__(self):
8
+ self.identity_file = "agent_identity.json"
9
+ self.agent_id = None
10
+ self.public_key = None
11
+ self._load_or_create_identity()
12
+
13
+ def _load_or_create_identity(self):
14
+ if os.path.exists(self.identity_file):
15
+ with open(self.identity_file, "r") as f:
16
+ data = json.load(f)
17
+ self.agent_id = data["agent_id"]
18
+ self.public_key = data["public_key"]
19
+ else:
20
+ self.agent_id = str(uuid.uuid4())
21
+ self.public_key = hashlib.sha256(self.agent_id.encode()).hexdigest()
22
+ with open(self.identity_file, "w") as f:
23
+ json.dump({
24
+ "agent_id": self.agent_id,
25
+ "public_key": self.public_key
26
+ }, f, indent=2)
27
+
28
+ def verify(self, other_id):
29
+ return other_id == self.public_key