File tree Expand file tree Collapse file tree 3 files changed +25
-11
lines changed Expand file tree Collapse file tree 3 files changed +25
-11
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,20 @@ async def sign_message(self, message: Dict) -> Dict:
7171 Returns:
7272 Dict: Signed message
7373 """
74- raise NotImplementedError
74+ message = self ._setup_sender (message )
75+ sig = await self .sign_raw (get_verification_buffer (message ))
76+ message ["signature" ] = sig .hex ()
77+ return message
78+
79+ async def sign_raw (self , buffer : bytes ) -> bytes :
80+ """
81+ Returns a signed message from a raw buffer.
82+ Args:
83+ buffer: Buffer to sign
84+ Returns:
85+ bytes: Signed buffer
86+ """
87+
7588
7689 @abstractmethod
7790 def get_address (self ) -> str :
Original file line number Diff line number Diff line change @@ -23,16 +23,12 @@ class ETHAccount(BaseAccount):
2323 def __init__ (self , private_key : bytes ):
2424 self .private_key = private_key
2525 self ._account = Account .from_key (self .private_key )
26-
27- async def sign_message (self , message : Dict ) -> Dict :
28- """Sign a message inplace."""
29- message = self ._setup_sender (message )
30-
31- msghash = encode_defunct (text = get_verification_buffer (message ).decode ("utf-8" ))
26+
27+ async def sign_raw (self , buffer : bytes ) -> bytes :
28+ """Sign a raw buffer."""
29+ msghash = encode_defunct (text = buffer .decode ("utf-8" ))
3230 sig = self ._account .sign_message (msghash )
33-
34- message ["signature" ] = sig ["signature" ].hex ()
35- return message
31+ return sig ["signature" ]
3632
3733 def get_address (self ) -> str :
3834 return self ._account .address
Original file line number Diff line number Diff line change @@ -32,11 +32,16 @@ async def sign_message(self, message: Dict) -> Dict:
3232 verif = get_verification_buffer (message )
3333 sig = {
3434 "publicKey" : self .get_address (),
35- "signature" : encode (self ._signing_key . sign (verif ). signature ),
35+ "signature" : encode (self .sign_raw (verif )),
3636 }
3737 message ["signature" ] = json .dumps (sig )
3838 return message
3939
40+ async def sign_raw (self , buffer : bytes ) -> bytes :
41+ """Sign a raw buffer."""
42+ sig = self ._signing_key .sign (buffer )
43+ return sig .signature
44+
4045 def get_address (self ) -> str :
4146 return encode (self ._signing_key .verify_key )
4247
You can’t perform that action at this time.
0 commit comments