Skip to content

Commit

Permalink
Fix hw_wallet overwrites previous signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 committed Jun 12, 2024
1 parent cc5b9f1 commit 29be0a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/safe_cli/operators/hw_wallets/hw_wallet_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ def delete_accounts(self, addresses: List[ChecksumAddress]) -> Set:
self.wallets = self.wallets.difference(accounts_to_remove)
return accounts_to_remove

def sign_eip712(self, eip712_message: Dict, wallets: List[HwWallet]) -> HexBytes:
def sign_eip712(
self, eip712_message: Dict, wallets: List[HwWallet]
) -> List[SafeSignature]:
"""
Sign an EIP712 message
Expand All @@ -136,7 +138,7 @@ def sign_eip712(self, eip712_message: Dict, wallets: List[HwWallet]) -> HexBytes
signature = wallet.sign_typed_hash(domain_hash, message_hash)
safe_signatures.append(SafeSignatureEOA(signature, eip712_message_hash))

return SafeSignature.export_signatures(safe_signatures)
return safe_signatures

def sign_safe_tx(self, safe_tx: SafeTx, wallets: List[HwWallet]) -> SafeTx:
"""
Expand All @@ -146,8 +148,14 @@ def sign_safe_tx(self, safe_tx: SafeTx, wallets: List[HwWallet]) -> SafeTx:
:param wallets:
:return: SafeTx with signature.
"""
signatures = self.sign_eip712(safe_tx.eip712_structured_data, wallets)
safe_tx.signatures = signatures
hw_wallet_signatures = self.sign_eip712(safe_tx.eip712_structured_data, wallets)
# Update signatures
signatures = (
SafeSignature.parse_signature(safe_tx.signatures, safe_tx.safe_tx_hash)
+ hw_wallet_signatures
)

safe_tx.signatures = SafeSignature.export_signatures(signatures)
return safe_tx

def execute_safe_tx(
Expand Down
4 changes: 3 additions & 1 deletion src/safe_cli/operators/safe_tx_service_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,9 @@ def remove_proposed_transaction(self, safe_tx_hash: bytes):
if isinstance(signer, LocalAccount):
signature = signer.signHash(message_hash).signature
else:
signature = self.hw_wallet_manager.sign_eip712(eip712_message, [signer])
signature = self.hw_wallet_manager.sign_eip712(
eip712_message, [signer]
)[0].signature

if len(safe_tx.signers) >= self.safe.retrieve_threshold():
print_formatted_text(
Expand Down

0 comments on commit 29be0a2

Please sign in to comment.