Skip to content

Commit 5c5ccd5

Browse files
author
Andres D. Molins
committed
Refactor: Apply the .hex() quick fix on the ETHAccount class instead on the base one as other chains can be affected.
1 parent 6c597bb commit 5c5ccd5

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/aleph/sdk/chains/common.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ async def sign_message(self, message: Dict) -> Dict:
7474
signature = await self.sign_raw(get_verification_buffer(message))
7575
message["signature"] = signature.hex()
7676

77-
if not str(message["signature"]).startswith("0x"):
78-
message["signature"] = "0x" + message["signature"]
79-
8077
return message
8178

8279
@abstractmethod

src/aleph/sdk/chains/ethereum.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import base64
33
from decimal import Decimal
44
from pathlib import Path
5-
from typing import Awaitable, Optional, Union
5+
from typing import Awaitable, Dict, Optional, Union
66

77
from aleph_message.models import Chain
88
from eth_account import Account # type: ignore
@@ -80,6 +80,22 @@ async def sign_raw(self, buffer: bytes) -> bytes:
8080
sig = self._account.sign_message(msghash)
8181
return sig["signature"]
8282

83+
async def sign_message(self, message: Dict) -> Dict:
84+
"""
85+
Returns a signed message from an aleph.im message.
86+
Args:
87+
message: Message to sign
88+
Returns:
89+
Dict: Signed message
90+
"""
91+
signed_message = await super().sign_message(message)
92+
93+
# Apply that fix as seems that sometimes the .hex() method doesn't add the 0x str at the beginning
94+
if not str(signed_message["signature"]).startswith("0x"):
95+
signed_message["signature"] = "0x" + signed_message["signature"]
96+
97+
return signed_message
98+
8399
def connect_chain(self, chain: Optional[Chain] = None):
84100
self.chain = chain
85101
if self.chain:

0 commit comments

Comments
 (0)