Skip to content

Commit

Permalink
feat: sign transactions in working state
Browse files Browse the repository at this point in the history
  • Loading branch information
johnson2427 committed Apr 25, 2024
1 parent 42481b2 commit da00f0a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
27 changes: 14 additions & 13 deletions ape_aws_kms/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

from typing import Iterator, List, Optional

from eth_account.messages import _hash_eip191_message
from eth_account.messages import _hash_eip191_message, encode_defunct
from eth_account._utils.legacy_transactions import serializable_unsigned_transaction_from_dict
from eth_pydantic_types import HexBytes
from eth_utils import keccak, to_checksum_address

from ape.api.accounts import AccountContainerAPI, AccountAPI, TransactionAPI
from ape.types import AddressType, MessageSignature, SignableMessage
from ape.utils import cached_property

from .utils import SECP256_K1_N, AliasResponse
from .utils import SECP256_K1_N, AliasResponse, transaction


class AwsAccountContainer(AccountContainerAPI):
Expand Down Expand Up @@ -102,14 +103,14 @@ def sign_message(
raise ValueError("Signature failed to verify")

def sign_transaction(self, txn: TransactionAPI, **signer_options) -> Optional[TransactionAPI]:
"""
To be implemented
EIP-191 -> Describing a text based message to sign
EIP-712 -> Subclass of EIP-191 messages. First byte is a specific value
implemented in the EIP712 Package
Break EIP-712 down further into a raw hash
Through EthAccount?
"""
unsigned_txn = serializable_unsigned_transaction_from_dict(
dict(
nonce=txn.nonce,
gasPrice=txn.max_priority_fee,
gas=txn.max_fee,
to=txn.receiver,
value=txn.value,
data=txn.data
)
).hash()
return self.sign_message(encode_defunct(unsigned_txn))
22 changes: 15 additions & 7 deletions ape_aws_kms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,30 @@

from pydantic import BaseModel, Field

from ape_ethereum.transactions import DynamicFeeTransaction


SECP256_K1_N = int("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", 16)

txn = {
"chain_id": 11155111,
"nonce": 0,
"value": 1,
"data": '0x00',
"receiver": "0xa5D3241A1591061F2a4bB69CA0215F66520E67cf",
"type": 2,
"max_fee": 100000000000,
"max_priority_fee": 300000000000,
}

def create_signable_message(msg):
"""
To be removed, used for testing
"""
return encode_defunct(text=msg)
transaction = DynamicFeeTransaction(**txn)


def create_transaction_message(value):
def create_signable_message(msg):
"""
To be removed, used for testing
"""
print(value)
return encode_defunct(text=msg)


class AliasResponse(BaseModel):
Expand Down

0 comments on commit da00f0a

Please sign in to comment.