diff --git a/skale/wallets/sgx_wallet.py b/skale/wallets/sgx_wallet.py index a0a16ed6..fb380fef 100644 --- a/skale/wallets/sgx_wallet.py +++ b/skale/wallets/sgx_wallet.py @@ -17,11 +17,18 @@ # You should have received a copy of the GNU Affero General Public License # along with SKALE.py. If not, see . +import logging + from sgx import SgxClient +from web3 import Web3 + from skale.utils.web3_utils import get_eth_nonce from skale.wallets.common import BaseWallet +logger = logging.getLogger(__name__) + + class SgxWallet(BaseWallet): def __init__(self, sgx_endpoint, web3, key_name=None, path_to_cert=None): self.sgx_client = SgxClient(sgx_endpoint, path_to_cert=path_to_cert) @@ -42,7 +49,15 @@ def sign_and_send(self, tx_dict) -> str: return self._web3.eth.sendRawTransaction(signed_tx.rawTransaction).hex() def sign_hash(self, unsigned_hash: str): - return self.sgx_client.sign_hash(unsigned_hash, self._key_name, self._web3.eth.chainId) + if unsigned_hash.startswith('0x'): + unsigned_hash = unsigned_hash[2:] + + body = bytes.fromhex(unsigned_hash) + header = b'\x19Ethereum Signed Message:\n32' + normalized_hash = header + body + hash_to_sign = Web3.keccak(hexstr='0x' + normalized_hash.hex()) + chain_id = None + return self.sgx_client.sign_hash(hash_to_sign, self._key_name, chain_id) @property def address(self): diff --git a/tests/contracts/delegation/token_state_test.py b/tests/contracts/delegation/token_state_test.py new file mode 100644 index 00000000..22387385 --- /dev/null +++ b/tests/contracts/delegation/token_state_test.py @@ -0,0 +1,4 @@ +def test_get_and_update_locked_amount(skale): + res = skale.token_state.get_and_update_locked_amount( + skale.wallet.address) + assert res > 0 diff --git a/tests/wallets/sgx_test.py b/tests/wallets/sgx_test.py index d9320b2c..0c21b291 100644 --- a/tests/wallets/sgx_test.py +++ b/tests/wallets/sgx_test.py @@ -45,11 +45,11 @@ def sign(self, transaction_dict, key_name): def sign_hash(self, message, key_name, chain_id): return AttributeDict({ - 'messageHash': HexBytes('0x0'), + 'messageHash': HexBytes('0x31323331'), 'r': 123, 's': 123, 'v': 27, - 'signature': HexBytes('0x0') + 'signature': HexBytes('0x6161616161613131313131') }) @@ -127,9 +127,9 @@ def test_sgx_sign_hash(): new=SgxClient): web3 = init_web3(ENDPOINT) wallet = SgxWallet('TEST_ENDPOINT', web3, key_name='TEST_KEY') - unsigned_hash = '0x0' + unsigned_hash = '0x31323331' signed_message = wallet.sign_hash(unsigned_hash) - assert signed_message.signature == HexBytes('0x0') + assert signed_message.signature == HexBytes('0x6161616161613131313131') def test_sgx_key_init():