GitHub Action commited on
Commit ·
bcc313a
1
Parent(s): 4d4cac2
Sync from GitHub with Git LFS
Browse files- agents/init.py +10 -4
- agents/tools/storage.py +1 -1
agents/init.py
CHANGED
|
@@ -44,11 +44,15 @@ def init_identity(storage, config):
|
|
| 44 |
did = generate_did()
|
| 45 |
identity_id = did.split(":")[-1]
|
| 46 |
|
| 47 |
-
# 2. Сгенерировать ключи через
|
| 48 |
privkey, pubkey = generate_keypair(method="ed25519")
|
| 49 |
privkey, pubkey = privkey.decode(), pubkey.decode()
|
| 50 |
|
| 51 |
-
# 3.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
identity = {
|
| 53 |
"id": identity_id,
|
| 54 |
"name": config.get("agent_name", "Unnamed"),
|
|
@@ -60,14 +64,16 @@ def init_identity(storage, config):
|
|
| 60 |
}
|
| 61 |
storage.add_identity(identity)
|
| 62 |
|
| 63 |
-
#
|
| 64 |
config["agent_id"] = did
|
| 65 |
config["identity_agent"] = identity_id
|
| 66 |
config["pubkey"] = pubkey
|
| 67 |
config["privkey"] = privkey
|
|
|
|
|
|
|
| 68 |
|
| 69 |
save_config(CONFIG_PATH, config)
|
| 70 |
-
print(f"[+] Создана личность: {identity_id}")
|
| 71 |
else:
|
| 72 |
print("[=] agent_id уже задан, пропускаем генерацию DiD.")
|
| 73 |
|
|
|
|
| 44 |
did = generate_did()
|
| 45 |
identity_id = did.split(":")[-1]
|
| 46 |
|
| 47 |
+
# 2. Сгенерировать ключи через crypto
|
| 48 |
privkey, pubkey = generate_keypair(method="ed25519")
|
| 49 |
privkey, pubkey = privkey.decode(), pubkey.decode()
|
| 50 |
|
| 51 |
+
# 3. Выполнить PoW (для начальных адресов можно пока [] или config["local_addresses"])
|
| 52 |
+
addresses = config.get("local_addresses", [])
|
| 53 |
+
nonce, pow_hash = storage.generate_pow(identity_id, pubkey, addresses, difficulty=4)
|
| 54 |
+
|
| 55 |
+
# 4. Создать запись в identity
|
| 56 |
identity = {
|
| 57 |
"id": identity_id,
|
| 58 |
"name": config.get("agent_name", "Unnamed"),
|
|
|
|
| 64 |
}
|
| 65 |
storage.add_identity(identity)
|
| 66 |
|
| 67 |
+
# 5. Записать в config
|
| 68 |
config["agent_id"] = did
|
| 69 |
config["identity_agent"] = identity_id
|
| 70 |
config["pubkey"] = pubkey
|
| 71 |
config["privkey"] = privkey
|
| 72 |
+
config["pow_nonce"] = nonce
|
| 73 |
+
config["pow_hash"] = pow_hash
|
| 74 |
|
| 75 |
save_config(CONFIG_PATH, config)
|
| 76 |
+
print(f"[+] Создана личность: {identity_id}, PoW: {pow_hash[:8]}...")
|
| 77 |
else:
|
| 78 |
print("[=] agent_id уже задан, пропускаем генерацию DiD.")
|
| 79 |
|
agents/tools/storage.py
CHANGED
|
@@ -677,7 +677,7 @@ class Storage:
|
|
| 677 |
self.conn.commit()
|
| 678 |
return cursor.lastrowid
|
| 679 |
|
| 680 |
-
def generate_pow(peer_id, pubkey, addresses, difficulty=4):
|
| 681 |
nonce = 0
|
| 682 |
prefix = "0" * difficulty
|
| 683 |
while True:
|
|
|
|
| 677 |
self.conn.commit()
|
| 678 |
return cursor.lastrowid
|
| 679 |
|
| 680 |
+
def generate_pow(self, peer_id, pubkey, addresses, difficulty=4):
|
| 681 |
nonce = 0
|
| 682 |
prefix = "0" * difficulty
|
| 683 |
while True:
|