From 5e1276a31baf502d5674f514c98c4ee67f9a403c Mon Sep 17 00:00:00 2001 From: hweawer Date: Wed, 28 Aug 2024 16:04:30 +0200 Subject: [PATCH] Splitting the signature, fixing the schema --- src/transport/msg_providers/data_bus.py | 37 +++++++++++++++++++++---- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/transport/msg_providers/data_bus.py b/src/transport/msg_providers/data_bus.py index 88be6b6f..c025fdde 100644 --- a/src/transport/msg_providers/data_bus.py +++ b/src/transport/msg_providers/data_bus.py @@ -4,6 +4,8 @@ from typing import List, Optional import variables +from eth_account.account import VRS +from eth_typing import HexStr from schema import Schema from transport.msg_providers.common import BaseMessageProvider from transport.msg_types.deposit import DepositMessage @@ -30,6 +32,13 @@ } +def signature_to_r_vs(signature: bytes) -> tuple[VRS, VRS]: + # 0 byte - 0x + r = signature[1:33] + _vs = signature[33:] + return HexStr('0x' + r.hex()), HexStr('0x' + _vs.hex()) + + class LogParser(abc.ABC): def __init__(self, w3: Web3, schema: str): self._w3 = w3 @@ -67,15 +76,19 @@ def __init__(self, w3: Web3): def _create_message(self, parsed_data: tuple, guardian: str) -> dict: deposit_root, nonce, block_number, block_hash, signature, staking_module_id, app = parsed_data + r, _vs = signature_to_r_vs(signature) return DepositMessage( type='deposit', - depositRoot=deposit_root, + depositRoot='0x' + deposit_root.hex(), nonce=nonce, blockNumber=block_number, - blockHash=block_hash, + blockHash='0x' + block_hash.hex(), guardianAddress=guardian, stakingModuleId=staking_module_id, - signature={'_vs': signature}, + signature={ + 'r': r, + '_vs': _vs, + }, app={'version': app[0]}, ) @@ -90,13 +103,17 @@ def __init__(self, w3: Web3): def _create_message(self, parsed_data: tuple, guardian: str) -> dict: nonce, block_number, block_hash, staking_module_id, signature, operator_ids, vetted_keys_by_operator, app = parsed_data + r, _vs = signature_to_r_vs(signature) return UnvetMessage( type='unvet', nonce=nonce, blockHash=block_hash, guardianAddress=guardian, stakingModuleId=staking_module_id, - signature={'_vs': signature}, + signature={ + 'r': '0x' + r.hex(), + '_vs': '0x' + _vs.hex(), + }, operatorIds=operator_ids, vettedKeysByOperator=vetted_keys_by_operator, ) @@ -128,12 +145,16 @@ def __init__(self, w3: Web3): def _create_message(self, parsed_data: tuple, guardian: str) -> dict: deposit_root, nonce, block_number, block_hash, signature, staking_module_id, app = parsed_data + r, _vs = signature_to_r_vs(signature) return PauseMessage( type='pause', blockNumber=block_number, guardianAddress=guardian, stakingModuleId=staking_module_id, - signature={'_vs': signature}, + signature={ + 'r': r, + '_vs': _vs, + }, ) @@ -146,11 +167,15 @@ def __init__(self, w3: Web3): def _create_message(self, parsed_data: tuple, guardian: str) -> dict: block_number, signature, app = parsed_data + r, _vs = signature_to_r_vs(signature) return PauseMessage( type='pause', blockNumber=block_number, guardianAddress=guardian, - signature={'_vs': signature}, + signature={ + 'r': r, + '_vs': _vs, + }, )