Skip to content

Conversation

@adrian-fjellberg
Copy link

Adds the ability to sign arbitrary messages using wallet accounts. The user can specify the elliptic curve to use for signing (secp256r1 or secp256k1). It generates a payload using salt and the provided message, then signs the payload with each available wallet account, displaying the address, public key, salt and signature.

Description

This PR introduces a new sign_message command to the Neo CLI, enabling message signing outside of transactions.
Previously, the CLI only supported signing serialized transaction data, which made it impossible to produce verifiable message signatures for use in external applications, authentication workflows, or dApp integrations.

With this change, users can now easily sign and verify arbitrary messages directly from their local wallet.

Change Log

  • Added the "sign_message" command to the Neo CLI.
  • Changed Neo.CLI.MainService to implement the "sign_message" command.
  • Added optional curve parameter (supports secp256r1 and secp256k1)
  • Implemented payload creation using salt + message for improved uniqueness

Fixes #4285

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Unit Testing
  • Run Application: manually tested sign_message on local CLI with both curves
  • Local Computer Tests
  • No Testing

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Adds the ability to sign arbitrary messages using wallet accounts. The user can specify the elliptic curve to use for signing (secp256r1 or secp256k1). It generates a payload using salt and the provided message, then signs the payload with each available wallet account, displaying the address, public key, salt and signature.
/// </summary>
/// <param name="message">Message to sign</param>
/// <param name="curve">Optional curve (secp256r1 or secp256k1)</param>
[ConsoleCommand("sign_message", Category = "Wallet Commands")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
[ConsoleCommand("sign_message", Category = "Wallet Commands")]
[ConsoleCommand("sign message", Category = "Wallet Commands")]

Copy link
Author

Choose a reason for hiding this comment

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

I treid this approach, but it seems like it then ran "sign" and "sign message" commands at the same time. And outputted errors.

I feel the naming of "sign_message" is not good, but it works.

I also considered renaming "sign" to "sign transaction" (or somthing of that nature), but I was afraid that could be considered a braking change.

Any suggestions for a better command name that would not be a breaking change?

Copy link
Member

Choose a reason for hiding this comment

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

We need to solve this issue before merging the code.

Copy link
Author

Choose a reason for hiding this comment

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

What if we call it "signmsg"?

Or do you want to fix the issue that both commands are run @erikzhang?

Copy link
Member

Choose a reason for hiding this comment

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

I prefer to fix it first.

var signature = Crypto.Sign(payload, key.PrivateKey, selectedCurve);

ConsoleHelper.Info("Address: ", account.Address);
ConsoleHelper.Info(" PublicKey: ", key.PublicKey.EncodePoint(true).ToHexString());
Copy link
Contributor

Choose a reason for hiding this comment

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

we dont really support secp256k1, the key you get is still p-256 pubkey.

Copy link
Author

Choose a reason for hiding this comment

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

Ok. I think I saw in the code for Crypto.Sign that both were supported so that is why I added it.

Do you want me tor remove the option to select curve and only use secp256r1?

Copy link
Member

Choose a reason for hiding this comment

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

We need a structured format that specifies the address, public key, and algorithm for signing. This also facilitates verification.

Copy link
Author

Choose a reason for hiding this comment

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

Some questions:

  1. Should we require the user specifiy either the public key or address for signing?

  2. If yes to question 1: If there is only one address in the open wallet, could we default to using this one? I think this will make signing more user friendly.

  3. For specifing the algorithim, do you mean the curve or padding, salt, etc.? Or both?

  4. Can we provide defaults for each option so that the command become user friendly?

Copy link
Member

Choose a reason for hiding this comment

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

I mean we need to define an output format including address, public key, and algorithm of the signature.

Comment on lines 562 to 568
w.Write((byte)0x01);
w.Write((byte)0x00);
w.Write((byte)0x01);
w.Write((byte)0xF0);
w.WriteVarBytes(paramBytes);
w.Write((ushort)0);
w.Flush();
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the meaning of this script, some standard?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, could you clarify it @adrian-fjellberg

Copy link
Author

Choose a reason for hiding this comment

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

It is to ensure that the message is not also a valid NEO transaction. I do not think it is a defined standard but it is the way both NEON wallet and NeoLine signs messages.

Do you want me to add comments to the code to clearify?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, its just some prefix.

Copy link
Author

Choose a reason for hiding this comment

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

I can add comments to the code.

@adrian-fjellberg
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add "sign_message" command to CLI for arbitrary message signing

6 participants