-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8e697e3
Showing
279 changed files
with
76,219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2021 Valory AG | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
|
||
"""AEA Local package registry.""" |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Signing Protocol | ||
|
||
## Description | ||
|
||
This is a protocol for communication between a skill and a decision maker. | ||
|
||
## Specification | ||
|
||
```yaml | ||
--- | ||
name: signing | ||
author: open_aea | ||
version: 1.0.0 | ||
description: A protocol for communication between skills and decision maker. | ||
license: Apache-2.0 | ||
aea_version: '>=1.0.0, <2.0.0' | ||
protocol_specification_id: open_aea/signing:1.0.0 | ||
speech_acts: | ||
sign_transaction: | ||
terms: ct:Terms | ||
raw_transaction: ct:RawTransaction | ||
sign_message: | ||
terms: ct:Terms | ||
raw_message: ct:RawMessage | ||
signed_transaction: | ||
signed_transaction: ct:SignedTransaction | ||
signed_message: | ||
signed_message: ct:SignedMessage | ||
error: | ||
error_code: ct:ErrorCode | ||
... | ||
--- | ||
ct:ErrorCode: | | ||
enum ErrorCodeEnum { | ||
UNSUCCESSFUL_MESSAGE_SIGNING = 0; | ||
UNSUCCESSFUL_TRANSACTION_SIGNING = 1; | ||
} | ||
ErrorCodeEnum error_code = 1; | ||
ct:RawMessage: | | ||
bytes raw_message = 1; | ||
ct:RawTransaction: | | ||
bytes raw_transaction = 1; | ||
ct:SignedMessage: | | ||
bytes signed_message = 1; | ||
ct:SignedTransaction: | | ||
bytes signed_transaction = 1; | ||
ct:Terms: | | ||
bytes terms = 1; | ||
... | ||
--- | ||
initiation: [sign_transaction, sign_message] | ||
reply: | ||
sign_transaction: [signed_transaction, error] | ||
sign_message: [signed_message, error] | ||
signed_transaction: [] | ||
signed_message: [] | ||
error: [] | ||
termination: [signed_transaction, signed_message, error] | ||
roles: {skill, decision_maker} | ||
end_states: [successful, failed] | ||
keep_terminal_state_dialogues: false | ||
... | ||
``` | ||
|
||
## Links |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2023 open_aea | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
|
||
""" | ||
This module contains the support resources for the signing protocol. | ||
It was created with protocol buffer compiler version `libprotoc 3.19.4` and aea protocol generator version `1.0.0`. | ||
""" | ||
|
||
from packages.open_aea.protocols.signing.message import SigningMessage | ||
from packages.open_aea.protocols.signing.serialization import SigningSerializer | ||
|
||
|
||
SigningMessage.serializer = SigningSerializer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2020 open_aea | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
|
||
"""This module contains class representations corresponding to every custom type in the protocol specification.""" | ||
|
||
from enum import Enum | ||
from typing import Any | ||
|
||
from aea.helpers.transaction.base import RawMessage as BaseRawMessage | ||
from aea.helpers.transaction.base import RawTransaction as BaseRawTransaction | ||
from aea.helpers.transaction.base import SignedMessage as BaseSignedMessage | ||
from aea.helpers.transaction.base import SignedTransaction as BaseSignedTransaction | ||
from aea.helpers.transaction.base import Terms as BaseTerms | ||
|
||
|
||
class ErrorCode(Enum): | ||
"""This class represents an instance of ErrorCode.""" | ||
|
||
UNSUCCESSFUL_MESSAGE_SIGNING = 0 | ||
UNSUCCESSFUL_TRANSACTION_SIGNING = 1 | ||
|
||
@staticmethod | ||
def encode(error_code_protobuf_object: Any, error_code_object: "ErrorCode") -> None: | ||
""" | ||
Encode an instance of this class into the protocol buffer object. | ||
The protocol buffer object in the error_code_protobuf_object argument is matched with the instance of this class in the 'error_code_object' argument. | ||
:param error_code_protobuf_object: the protocol buffer object whose type corresponds with this class. | ||
:param error_code_object: an instance of this class to be encoded in the protocol buffer object. | ||
""" | ||
error_code_protobuf_object.error_code = error_code_object.value | ||
|
||
@classmethod | ||
def decode(cls, error_code_protobuf_object: Any) -> "ErrorCode": | ||
""" | ||
Decode a protocol buffer object that corresponds with this class into an instance of this class. | ||
A new instance of this class is created that matches the protocol buffer object in the 'error_code_protobuf_object' argument. | ||
:param error_code_protobuf_object: the protocol buffer object whose type corresponds with this class. | ||
:return: A new instance of this class that matches the protocol buffer object in the 'error_code_protobuf_object' argument. | ||
""" | ||
enum_value_from_pb2 = error_code_protobuf_object.error_code | ||
return ErrorCode(enum_value_from_pb2) | ||
|
||
|
||
RawMessage = BaseRawMessage | ||
RawTransaction = BaseRawTransaction | ||
SignedMessage = BaseSignedMessage | ||
SignedTransaction = BaseSignedTransaction | ||
Terms = BaseTerms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# -*- coding: utf-8 -*- | ||
# ------------------------------------------------------------------------------ | ||
# | ||
# Copyright 2023 open_aea | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
|
||
""" | ||
This module contains the classes required for signing dialogue management. | ||
- SigningDialogue: The dialogue class maintains state of a dialogue and manages it. | ||
- SigningDialogues: The dialogues class keeps track of all dialogues. | ||
""" | ||
|
||
from abc import ABC | ||
from typing import Callable, Dict, FrozenSet, Type, cast | ||
|
||
from aea.common import Address | ||
from aea.protocols.base import Message | ||
from aea.protocols.dialogue.base import Dialogue, DialogueLabel, Dialogues | ||
|
||
from packages.open_aea.protocols.signing.message import SigningMessage | ||
|
||
|
||
class SigningDialogue(Dialogue): | ||
"""The signing dialogue class maintains state of a dialogue and manages it.""" | ||
|
||
INITIAL_PERFORMATIVES: FrozenSet[Message.Performative] = frozenset( | ||
{ | ||
SigningMessage.Performative.SIGN_TRANSACTION, | ||
SigningMessage.Performative.SIGN_MESSAGE, | ||
} | ||
) | ||
TERMINAL_PERFORMATIVES: FrozenSet[Message.Performative] = frozenset( | ||
{ | ||
SigningMessage.Performative.SIGNED_TRANSACTION, | ||
SigningMessage.Performative.SIGNED_MESSAGE, | ||
SigningMessage.Performative.ERROR, | ||
} | ||
) | ||
VALID_REPLIES: Dict[Message.Performative, FrozenSet[Message.Performative]] = { | ||
SigningMessage.Performative.ERROR: frozenset(), | ||
SigningMessage.Performative.SIGN_MESSAGE: frozenset( | ||
{ | ||
SigningMessage.Performative.SIGNED_MESSAGE, | ||
SigningMessage.Performative.ERROR, | ||
} | ||
), | ||
SigningMessage.Performative.SIGN_TRANSACTION: frozenset( | ||
{ | ||
SigningMessage.Performative.SIGNED_TRANSACTION, | ||
SigningMessage.Performative.ERROR, | ||
} | ||
), | ||
SigningMessage.Performative.SIGNED_MESSAGE: frozenset(), | ||
SigningMessage.Performative.SIGNED_TRANSACTION: frozenset(), | ||
} | ||
|
||
class Role(Dialogue.Role): | ||
"""This class defines the agent's role in a signing dialogue.""" | ||
|
||
DECISION_MAKER = "decision_maker" | ||
SKILL = "skill" | ||
|
||
class EndState(Dialogue.EndState): | ||
"""This class defines the end states of a signing dialogue.""" | ||
|
||
SUCCESSFUL = 0 | ||
FAILED = 1 | ||
|
||
def __init__( | ||
self, | ||
dialogue_label: DialogueLabel, | ||
self_address: Address, | ||
role: Dialogue.Role, | ||
message_class: Type[SigningMessage] = SigningMessage, | ||
) -> None: | ||
""" | ||
Initialize a dialogue. | ||
:param dialogue_label: the identifier of the dialogue | ||
:param self_address: the address of the entity for whom this dialogue is maintained | ||
:param role: the role of the agent this dialogue is maintained for | ||
:param message_class: the message class used | ||
""" | ||
Dialogue.__init__( | ||
self, | ||
dialogue_label=dialogue_label, | ||
message_class=message_class, | ||
self_address=self_address, | ||
role=role, | ||
) | ||
|
||
|
||
class SigningDialogues(Dialogues, ABC): | ||
"""This class keeps track of all signing dialogues.""" | ||
|
||
END_STATES = frozenset( | ||
{SigningDialogue.EndState.SUCCESSFUL, SigningDialogue.EndState.FAILED} | ||
) | ||
|
||
_keep_terminal_state_dialogues = False | ||
|
||
def __init__( | ||
self, | ||
self_address: Address, | ||
role_from_first_message: Callable[[Message, Address], Dialogue.Role], | ||
dialogue_class: Type[SigningDialogue] = SigningDialogue, | ||
) -> None: | ||
""" | ||
Initialize dialogues. | ||
:param self_address: the address of the entity for whom dialogues are maintained | ||
:param dialogue_class: the dialogue class used | ||
:param role_from_first_message: the callable determining role from first message | ||
""" | ||
Dialogues.__init__( | ||
self, | ||
self_address=self_address, | ||
end_states=cast(FrozenSet[Dialogue.EndState], self.END_STATES), | ||
message_class=SigningMessage, | ||
dialogue_class=dialogue_class, | ||
role_from_first_message=role_from_first_message, | ||
) |
Oops, something went wrong.