diff --git a/python/src/uagents/registration.py b/python/src/uagents/registration.py index c44d94ea..72868a9a 100644 --- a/python/src/uagents/registration.py +++ b/python/src/uagents/registration.py @@ -3,7 +3,7 @@ import json import logging from abc import ABC, abstractmethod -from typing import List, Optional +from typing import Dict, List, Optional, Union import aiohttp from cosmpy.aerial.client import LedgerClient @@ -20,7 +20,7 @@ ) from uagents.crypto import Identity from uagents.network import AlmanacContract, InsufficientFundsError, add_testnet_funds -from uagents.types import AgentEndpoint, AgentGeoLocation +from uagents.types import AgentEndpoint class AgentRegistrationPolicy(ABC): @@ -36,8 +36,8 @@ class AgentRegistrationAttestation(BaseModel): agent_address: str protocols: List[str] endpoints: List[AgentEndpoint] + metadata: Optional[Dict[str, Union[str, Dict[str, str]]]] = None signature: Optional[str] = None - location: Optional[AgentGeoLocation] = None def sign(self, identity: Identity): digest = self._build_digest() @@ -55,6 +55,7 @@ def _build_digest(self) -> bytes: agent_address=self.agent_address, protocols=sorted(self.protocols), endpoints=sorted(self.endpoints, key=lambda x: x.url), + metadata=self.metadata, ) sha256 = hashlib.sha256() diff --git a/python/src/uagents/types.py b/python/src/uagents/types.py index 31216894..1379dad9 100644 --- a/python/src/uagents/types.py +++ b/python/src/uagents/types.py @@ -42,15 +42,6 @@ class AgentEndpoint(BaseModel): weight: int -class AgentGeoLocation(BaseModel): - # Latitude and longitude of the agent - latitude: float - longitude: float - - # Radius around the agent location, expressed in meters - radius: float - - class AgentInfo(BaseModel): agent_address: str endpoints: List[AgentEndpoint] diff --git a/python/tests/test_registration.py b/python/tests/test_registration.py index 0ecadabe..d390ca76 100644 --- a/python/tests/test_registration.py +++ b/python/tests/test_registration.py @@ -32,6 +32,28 @@ def test_attestation_signature(): assert attestation.verify() +def test_attestation_signature_with_metadata(): + identity = Identity.generate() + + # create a dummy attestation + attestation = AgentRegistrationAttestation( + agent_address=identity.address, + protocols=["foo", "bar", "baz"], + endpoints=[ + {"url": "https://foobar.com", "weight": 1}, + {"url": "https://barbaz.com", "weight": 1}, + ], + metadata={"foo": "bar", "baz": "42", "qux": {"a": "b", "c": "d"}}, + ) + + # sign the attestation with the identity + attestation.sign(identity) + assert attestation.signature is not None + + # verify the attestation + assert attestation.verify() + + def test_recovery_of_attestation(): identity = Identity.generate()