Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to sign message #341

Merged
merged 3 commits into from
Jan 17, 2024
Merged

Add support to sign message #341

merged 3 commits into from
Jan 17, 2024

Conversation

moisses89
Copy link
Member

@moisses89 moisses89 commented Jan 12, 2024

Close #280

Description

This PR adds support to sign message on-chain and off -chain with Safe Transaction Service.

@moisses89 moisses89 requested a review from Uxio0 as a code owner January 12, 2024 12:03
@moisses89 moisses89 marked this pull request as draft January 12, 2024 12:03
@moisses89 moisses89 changed the title Add sign_message Add support to sign message Jan 12, 2024
@moisses89 moisses89 force-pushed the add_sign_messages branch 2 times, most recently from 7501afc to 3162c8e Compare January 12, 2024 16:25
if eip712_message_path:
try:
message = json.load(open(eip712_message_path, "r"))
message_bytes = b"".join(eip712_encode(message))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I sign the hash of EIP712 or the string hash following EIP191? I'm asking because is the way that the transaction service accepts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not understanding. You need to sign self.safe.get_message_hash(message_bytes)

@moisses89
Copy link
Member Author

This PR cannot be merged because have dependencies with:

@moisses89 moisses89 marked this pull request as ready for review January 12, 2024 16:35
if eip712_message_path:
try:
message = json.load(open(eip712_message_path, "r"))
message_bytes = b"".join(eip712_encode(message))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not understanding. You need to sign self.safe.get_message_hash(message_bytes)

safe_tx = self.hw_wallet_manager.sign_eip712(
safe_tx, selected_ledger_accounts
)
if len(hw_wallets_signers) > 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if len(hw_wallets_signers) > 0:
if len(hw_wallets_signers):

+ signatures[65 * signer_pos :]
)

if len(hw_wallet_signers) > 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if len(hw_wallet_signers) > 0:
if len(hw_wallet_signers):

signature_dict["v"], signature_dict["r"], signature_dict["s"]
)
signers.append(eoa_signer.address)
signer_pos = sorted(signers, key=lambda x: int(x, 16)).index(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can build SafeSignature objects and then use the new method export_signatures on safe-eth-py

@@ -368,6 +372,13 @@ def remove_delegate(args):
parser_approve_hash.add_argument("sender", type=check_ethereum_address)
parser_approve_hash.set_defaults(func=approve_hash)

# Sign message
parser_sign_message = subparsers.add_parser("sign_message")
group = parser_sign_message.add_mutually_exclusive_group(required=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

b"".join(eip712_encode(message))
)
safe_operator.sign_message(eip712_message_path=eip712_path)
self.assertTrue(safe_operator.safe.retrieve_is_message_signed(message_hash))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify this is False before signing the message

@coveralls
Copy link

Coverage Status

coverage: 94.912% (+1.3%) from 93.638%
when pulling f634d2b on add_sign_messages
into 37aeca1 on master.

@moisses89 moisses89 merged commit 0c1b04b into master Jan 17, 2024
13 checks passed
@moisses89 moisses89 deleted the add_sign_messages branch January 17, 2024 10:19
@github-actions github-actions bot locked and limited conversation to collaborators Jan 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support signing messages
3 participants