Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add metadata to agent attestation and remove location #548

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions python/src/uagents/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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()
Expand All @@ -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()
Expand Down
9 changes: 0 additions & 9 deletions python/src/uagents/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
22 changes: 22 additions & 0 deletions python/tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading