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 for signing transaction files and adding the generated signature as a witness #89

Open
mitchmindtree opened this issue Feb 20, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@mitchmindtree
Copy link
Contributor

mitchmindtree commented Feb 20, 2023

The new forc tx command allows for constructing transactions and outputting them to a file in a serialized form. Similarly, we anticipate adding support for writing transactions generated from forc deploy or forc run to file (see FuelLabs/sway#4130).

It would be great if we could use forc wallet to sign a potentially unsigned transaction and automatically add the generated signature as a witness. This would likely help a lot with shell-oriented workflows and testing.

This should look something like the following:

  1. Read and deserialize the transaction file into memory.
  2. Calculate the transaction ID (with cleared witnesses and necessary serialization format).
  3. Sign the transaction ID.
  4. Append the signature to the transaction's list of witnesses.
  5. Serialize the transaction to the same format it was deserialized from.
  6. Write the updated transaction to a new file <original-tx-path>-signed.<extension> (or overwrite the existing?).
  7. Output the new signature along with its index in the list of witnesses to stdout.

cc @nfurfaro @simonr0204 in case you have any other thoughts/ideas to add!

@mitchmindtree mitchmindtree added the enhancement New feature or request label Feb 20, 2023
mitchmindtree added a commit that referenced this issue Feb 21, 2023
… or `hex` subcommands (#88)

This PR allows the user to sign arbitrary data. Here are some examples
taken from the help output:

```console
    # Sign an arbitrary string.
    forc wallet account 3 sign string "blah blah blah"

    # Sign the contents of a file.
    forc wallet account 3 sign file /path/to/data-to-sign

    # Sign a hex-encoded byte string.
    forc wallet account 3 sign hex "0xDEADBEEF"
```

This PR also re-introduces the `forc wallet sign` subcommand. This
re-uses the existing logic for signing via the account subcommand,
though provides the additional option of signing with a private key.
Some examples:

```console
    # You can also use the `sign` subcommand directly. The following gives the same result.
    forc wallet sign --account 3 string "blah blah blah"

    # Sign directly with a private key provided via interactive prompt.
    forc wallet sign --private-key string "blah blah blah"
```

Notably, this PR also removes the old `forc wallet sign-private` command
in favour of using `forc wallet sign --private-key` in order to try and
provide a more uniform interface.

The `sign tx` subcommand has been renamed to `sign tx-id` in
anticipation of supporting signing transaction *files* in the future.
See #89.

The `sign` command also now allows for specifying the full private key
or account password via command line arguments
(`--private-key-non-interactive <key>` and `--password-non-interactive
<pw>` respectively), however these should likely only be used for
testing in non-interactive environments. As a result, we don't highlight
them as options in the help output, and we provide `WARNING`s about
their use in their argument help output.

Closes #75.
@nfurfaro
Copy link

@mitchmindtree this looks great, I don't really have anything to add.
I definitely look forward to item number 7, I see it being useful in my chess-game played mostly offchain, as I'll need the
raw signatures for that.

@nfurfaro
Copy link

nfurfaro commented Apr 26, 2023

To make this a bit more generic, we could support signing in general.
For example, a user may want to use their private key to sign arbitrary messages, not necessarily just transactions. This could be an option, i.e: forc sign --tx <transaction> or forc sign --raw <raw data/msg>.

If we do take this approach, is forc tx still the best name for the command/plugin?

Edit: I just discovered forc-wallet sign !

Sign some data (e.g. a transaction ID, a file, a string, or a hex-string) using either a
wallet account or a private key

@zees-dev
Copy link
Contributor

Since signing seems to be supported by the forc-wallet; has the issue been addressed?

@kayagokalp
Copy link
Member

I think this is more specific to signing a transaction that is generated from forc-tx. AFAIK we still do not support that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants