-
Notifications
You must be signed in to change notification settings - Fork 36
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
Message signing and verifying #343
Conversation
multiversx_sdk_cli/cli_wallet.py
Outdated
is_signed = verifier.verify(verifiable_message) | ||
|
||
if is_signed: | ||
show_message(f"""The message "{message}" was signed by {bech32_address}""") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add a prefix for these messages, such as "success" and "failed" (as in "verification failed". E.g:
SUCCESS: The messsage ...
Optional, we should ask for additional opinion on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added prefixes, we can still ask for some other opinions, maybe wait to see what the second reviewer thinks about this.
multiversx_sdk_cli/message.py
Outdated
|
||
def sign(self) -> None: | ||
hex_signature = self.account.sign_message(self.message.encode()) | ||
self.signature = bytes.fromhex(hex_signature) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "signable" message now becomes a "signed message".
Alternatively, could be SignedMessage(message, account)
and also do self.signature = ...
in the constructor. Not an actual improvement, though.
Or have this file renamed to sign_verify.py
and have a sign_message(message, account)
return a simple DTO called SignedMessage
(also defined in this file), that has the to_dictionary()
method, as well. Then, some parts of the verify logic can be moved here, too (for symmetry).
Optional, can also stay as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, great suggestion!
multiversx_sdk_cli/cli_wallet.py
Outdated
"Verify a previously message" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Verify a previously message" | |
) | |
"Verify a previously signed message" | |
) |
?
In this PR I've added two new sub-commands for the
wallet
command group:mxpy wallet sign-message
mxpy wallet verify-message
mxpy wallet sign-message
This command is used to sign a message. It requires the
--message
argument and you'll also need to pass in a wallet that will be used for signing the message.When running
mxpy wallet sign-message --message test --pem alice.pem
the output will look something like this:mxpy wallet verify-message
This command is used for verifying a previously signed message. It requires the
--address
argument which is thebech32
address of the signer, the--message
argument which represents the signed message(in readable format) and the--signature
argument which is the message signature hex encoded.To verify the message signed above we can run the following command:
The output will look like this:
In case the message was not signed by someone with that address the output will be: