generated from ApeWorX/project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
60dd0b4
commit 4899525
Showing
2 changed files
with
33 additions
and
76 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
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 |
---|---|---|
@@ -1,56 +1,29 @@ | ||
import botocore | ||
from typing import Any, Optional | ||
from datetime import datetime | ||
from eth_account.messages import encode_defunct | ||
|
||
from pydantic import ( | ||
BaseModel, | ||
Field, | ||
) | ||
from hexbytes import HexBytes | ||
from pydantic import BaseModel, Field | ||
|
||
from ape.types import SignableMessage | ||
|
||
from eip712.messages import EIP712Message | ||
SECP256_K1_N = int("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", 16) | ||
|
||
|
||
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') | ||
def create_signable_message(msg): | ||
""" | ||
To be removed, used for testing | ||
""" | ||
return encode_defunct(text=msg) | ||
|
||
|
||
class Message(BaseModel): | ||
msg: Any | ||
key_id: str | ||
client: botocore.client.KMS | ||
def create_transaction_message(value): | ||
""" | ||
To be removed, used for testing | ||
""" | ||
print(value) | ||
|
||
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 | ||
|
||
class AliasResponse(BaseModel): | ||
alias: str = Field(alias="AliasName") | ||
arn: str = Field(alias="AliasArn") | ||
key_id: str = Field(alias="TargetKeyId") | ||
creation: datetime = Field(alias="CreationDate") | ||
last_updated: datetime = Field(alias="LastUpdatedDate") |