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

chore(core): verify sync envelope if signed #507

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 7 additions & 5 deletions python/src/uagents/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@ async def send_exchange_envelope(
success = resp.status == 200
if success:
if sync:
# If the message is synchronous but not verified, return the envelope
env = Envelope.model_validate(await resp.json())
if env.signature is None:
return env
Archento marked this conversation as resolved.
Show resolved Hide resolved
if env.signature and not env.verify():
Archento marked this conversation as resolved.
Show resolved Hide resolved
errors.append(
"Received response envelope that failed verification"
)
continue
Archento marked this conversation as resolved.
Show resolved Hide resolved
return await dispatch_sync_response_envelope(env)
return MsgStatus(
status=DeliveryStatus.DELIVERED,
Expand Down Expand Up @@ -365,7 +367,7 @@ async def send_sync_message(

def enclose_response(
message: Model, sender: str, session: UUID4, target: str = ""
) -> str:
) -> JsonStr:
"""
Enclose a response message within an envelope.

Expand All @@ -390,7 +392,7 @@ def enclose_response_raw(
sender: str,
session: UUID4,
target: str = "",
) -> str:
) -> JsonStr:
"""
Enclose a raw response message within an envelope.

Expand Down
6 changes: 3 additions & 3 deletions python/src/uagents/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ async def _api_resolve(self, destination: str) -> Tuple[Optional[str], List[str]

if response.status_code != 200:
if response.status_code != 404:
LOGGER.warning(
f"Failed to resolve agent {address} from {self._almanac_api_url},"
f"querying Almanac contract..."
LOGGER.debug(
Archento marked this conversation as resolved.
Show resolved Hide resolved
f"Failed to resolve agent {address} from {self._almanac_api_url}, "
f"resolving via Almanac contract..."
)
return None, []

Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def test_message_success_unsigned(self):
]
)

async def test_message_success_sync(self):
async def test_message_success_sync_unsigned(self):
message = Message(message="hello")
reply = Message(message="hey")
user = generate_user_address()
Expand Down
Loading