HomePhabricator

refactor: deduplicate the message sign/verify code

Description

refactor: deduplicate the message sign/verify code

Summary:

  • Deduplicate the message verifying code

The logic of verifying a message was duplicated in 2 places:

src/qt/signverifymessagedialog.cpp

SignVerifyMessageDialog::on_verifyMessageButton_VM_clicked()

src/rpc/misc.cpp

verifymessage()

with the only difference being the result handling. Move the logic into
a dedicated

src/util/message.cpp

MessageVerify()

which returns a set of result codes, call it from the 2 places and just
handle the results differently in the callers.

  • Deduplicate the message signing code

The logic of signing a message was duplicated in 3 places:

src/qt/signverifymessagedialog.cpp

SignVerifyMessageDialog::on_signMessageButton_SM_clicked()

src/rpc/misc.cpp

signmessagewithprivkey()

src/wallet/rpcwallet.cpp

signmessage()

Move the logic into

src/util/message.cpp

MessageSign()

and call it from all the 3 places.

  • Refactor message hashing into a utility function

And add unit test for it.

The purpose of using a preamble or "magic" text as part of signing and
verifying a message was not given when the code was repeated in a few
locations. Make a test showing how it is used to prevent inadvertently
signing a transaction.

Backport of Core PR17577

Test Plan:

ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Subscribers: majcosta

Differential Revision: https://reviews.bitcoinabc.org/D8098

Details

Provenance
Vasil Dimov <vd@FreeBSD.org>Authored on Nov 19 2019, 14:49
deadalnixCommitted on Oct 24 2020, 23:35
deadalnixPushed on Oct 24 2020, 23:36
Reviewer
Restricted Project
Differential Revision
D8098: refactor: deduplicate the message sign/verify code
Parents
rABC1171c36d376c: Various nits in abc_wallet_standardness
Branches
Unknown
Tags
Unknown