- Deduplicate the message verifying code
The logic of verifying a message was duplicated in 2 places:
with the only difference being the result handling. Move the logic into
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:
Move the logic into
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