generated from ApeWorX/project-template
-
-
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
1 parent
23ac881
commit 2b4ce5d
Showing
3 changed files
with
70 additions
and
5 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
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,56 @@ | ||
import botocore | ||
from typing import Any, Optional | ||
|
||
from pydantic import ( | ||
BaseModel, | ||
Field, | ||
) | ||
from hexbytes import HexBytes | ||
|
||
from ape.types import SignableMessage | ||
|
||
from eip712.messages import EIP712Message | ||
|
||
|
||
class Transaction(BaseModel): | ||
nonce: int | ||
to: str | ||
value: int | ||
data: str = Field(default='0x00') | ||
gas: int = Field(default=160000) | ||
gas_price: str = Field(alias='gasPrice', default='0x0918400000') | ||
|
||
|
||
class Message(BaseModel): | ||
msg: Any | ||
key_id: str | ||
client: botocore.client.KMS | ||
|
||
def sign(self) -> Optional[Any]: | ||
message = None | ||
if isinstance(self.msg, str): | ||
message = self.msg | ||
|
||
elif isinstance(self.msg, int): | ||
message = HexBytes(self.msg).hex() | ||
|
||
elif isinstance(self.msg, bytes): | ||
message = self.msg.hex() | ||
|
||
elif isinstance(self.msg, SignableMessage): | ||
message = self.msg.body | ||
|
||
elif isinstance(self.msg, EIP712Message): | ||
message = self.msg._body_ | ||
|
||
if not message: | ||
return None | ||
|
||
response = self.client.sign( | ||
KeyId=self.key_id, | ||
Message=self.msg, | ||
MessageType='DIGEST', | ||
SigningAlgorithm='ECDSA_SHA_256', | ||
) | ||
return response | ||
|