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

R4R: Implement command/REST endpoint for offline signing #1953 #2216

Merged
merged 2 commits into from
Sep 7, 2018

Conversation

alessio
Copy link
Contributor

@alessio alessio commented Sep 3, 2018

Add sign command to sign transactions generated with the --generate-only flag.

Closes: #1953

  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote tests
  • Updated relevant documentation (docs/)
  • Added entries in PENDING.md with issue #
  • rereviewed Files changed in the github PR explorer

For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@alessio alessio force-pushed the alessio/1953-generate-signature branch 2 times, most recently from a278464 to 4105de8 Compare September 3, 2018 00:34
@codecov
Copy link

codecov bot commented Sep 3, 2018

Codecov Report

Merging #2216 into develop will decrease coverage by 0.22%.
The diff coverage is 0%.

@@             Coverage Diff             @@
##           develop    #2216      +/-   ##
===========================================
- Coverage    63.95%   63.73%   -0.23%     
===========================================
  Files          140      140              
  Lines         8611     8641      +30     
===========================================
  Hits          5507     5507              
- Misses        2725     2755      +30     
  Partials       379      379

@alessio alessio force-pushed the alessio/1953-generate-signature branch 7 times, most recently from 5b12981 to c59dac6 Compare September 5, 2018 00:36
@alessio alessio changed the title WIP: Alessio/1953 generate signature Implement command/REST endpoint for offline signing #1953 Sep 5, 2018
Copy link
Member

@jackzampolin jackzampolin left a comment

Choose a reason for hiding this comment

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

Nothing from me really. Looks good!

client/lcd/lcd_test.go Outdated Show resolved Hide resolved
x/auth/client/cli/sign.go Show resolved Hide resolved
x/auth/client/rest/sign.go Outdated Show resolved Hide resolved
@alessio
Copy link
Contributor Author

alessio commented Sep 5, 2018

CLI tests are fixed now.

@alessio alessio added T: UX lcd and removed wip labels Sep 5, 2018
@alessio alessio force-pushed the alessio/1953-generate-signature branch from e53cbe4 to 0ada320 Compare September 5, 2018 01:29
@alessio alessio changed the title Implement command/REST endpoint for offline signing #1953 R4R: Implement command/REST endpoint for offline signing #1953 Sep 5, 2018
docs/sdk/clients.md Outdated Show resolved Hide resolved
@alessio alessio force-pushed the alessio/1953-generate-signature branch from 0ada320 to 052bb1f Compare September 5, 2018 15:53
Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

LGTM. Left a few minor comments regarding docs, but logic looks good. Thanks @alessio !

docs/sdk/clients.md Show resolved Hide resolved
x/auth/client/rest/query.go Show resolved Hide resolved
x/auth/client/cli/sign.go Show resolved Hide resolved
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

@alessio left some surface level feedback. I'll want to play around with this a bit later today before an approval 👍 otherwise, great job!

x/auth/client/cli/sign.go Outdated Show resolved Hide resolved
client/lcd/lcd_test.go Outdated Show resolved Hide resolved

// SignStdTx attach a signature to a StdTx and returns a copy of a it. If overwriteSigs is true,
// it replaces the signatures already attached if there's any with the given signature.
func SignStdTx(stdTx auth.StdTx, stdSignature auth.StdSignature, overwriteSigs bool) auth.StdTx {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we take an array/slice of signatures here instead to be more flexible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could work. I'll make it take a slice and either append or replace the sigs

x/auth/client/rest/sign.go Outdated Show resolved Hide resolved
@alessio alessio force-pushed the alessio/1953-generate-signature branch 2 times, most recently from b95da66 to 20a22ea Compare September 6, 2018 13:55
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

@alessio just a few more minor bits of feedback.

Also, I've also tested it and seems to be functional! But I have question. I can generate a tx with a --from and that would be the designated signer/account. Now, I can sign this generated tx JSON with a completely different signer. I know this allows for offline signing, but I think generating a tx with an intended signer and signing it with a completely different one would lead to a weird "UX". We should check the generated txs signer address against the signee address and at the very least print a warning if they don't match. Thoughts @jackzampolin @cwgoes?

Thank you!

x/auth/client/cli/sign.go Outdated Show resolved Hide resolved
x/auth/client/rest/sign.go Outdated Show resolved Hide resolved
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

One small remark @alessio, otherwise LGTM 👍


// Check whether the address is a signer
if !isTxSigner(sdk.AccAddress(addr), stdTx.GetSigners()) {
fmt.Fprintf(os.Stderr, "warning: the transaction is not supposed to be signed by the key '%v'\n", name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @alessio! I think something along the lines of the following might read better. Thoughts?

WARNING: The generated transaction's intended signer does not match the given signer: '%v'

@alessio
Copy link
Contributor Author

alessio commented Sep 6, 2018 via email

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Thanks @alessio -- tested ACK.

@alessio alessio force-pushed the alessio/1953-generate-signature branch from 13f76e4 to 21b00a8 Compare September 6, 2018 19:22
@jackzampolin
Copy link
Member

This looks great. Happy with how this has come together. LGTM!

@alessio alessio force-pushed the alessio/1953-generate-signature branch from 21b00a8 to 8e8208b Compare September 7, 2018 10:59
* Add sign CLI command to sign transactions generated with the
  --generate-only flag.
* Add /sign REST endpoint for Voyager support.

Redirect password prompt to STDERR to avoid messing up cli
commands output. As a rule of thumb, program's output should
always go to STDOUT, whilst errors&diagnostics go to STDERR
as per POSIX's philosophy and specs.
@alessio alessio force-pushed the alessio/1953-generate-signature branch from 8e8208b to e6a8a4d Compare September 7, 2018 11:58
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, a few tiny comments.

Makefile Outdated
@@ -179,7 +179,7 @@ test_cover:

test_lint:
gometalinter.v2 --config=tools/gometalinter.json ./...
!(gometalinter.v2 --disable-all --enable='errcheck' --vendor ./... | grep -v "client/")
!(gometalinter.v2 --disable-all --enable='errcheck' --vendor ./... | grep -v -e "client/" -e "fmt\.Fprintf")
Copy link
Contributor

Choose a reason for hiding this comment

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

This has since been fixed, and this is the wrong way to fix it anyways (the linter is right) - #2257

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, by definition linter is correct, but I wonder how helpful it would be to check errors reported by fprintf() :). I'll revert my changes nonetheless, thanks

client/lcd/lcd_test.go Show resolved Hide resolved
client/utils/utils.go Show resolved Hide resolved
cmd/gaia/cli_test/cli_test.go Outdated Show resolved Hide resolved
x/auth/client/rest/sign.go Outdated Show resolved Hide resolved
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

utACK 🎉

@cwgoes cwgoes merged commit 896d259 into develop Sep 7, 2018
@cwgoes cwgoes deleted the alessio/1953-generate-signature branch September 7, 2018 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants