HomePhabricator

[electrum] refactor private key class to better abstract ecdsa library usage

Description

[electrum] refactor private key class to better abstract ecdsa library usage

Summary:
The goal of this refactoring is to better encapsulate internals of the ecdsa library in a single module (in anticipation for removing that dependency later), and improve the general code quality.

The ECKey class is renamed into ECPrivkey and now inherits ECPubkey. The code of the ECPrivkey is massaged into a better shape. The constructor now checks that the key is exactly 32 bytes, and for creating a key from a shorter amount of data (used for wallet file encryption) a special classmethod from_arbitrary_size_secret is introduced with the previous behavior of normalizing the shorter key data to 32 bytes.

The MySigningKey class, which is a wrapper around ecdsa.SigningKey, is now an implementation details of ecc.py, and is no longer used in transaction.py and unit tests.

This diff is a big chunck of what remains to be split out of D16301.

Depends on D16678

Test Plan:
python test_runner.py

Run the GUI, sign and verify a message, check that the sig is still identical to the one generated before this diff.
Sign, send and receive a transaction.

Reviewers: #bitcoin_abc, bytesofman, Fabien

Reviewed By: #bitcoin_abc, bytesofman, Fabien

Subscribers: Fabien, bytesofman

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

Details

Provenance
PiRKAuthored on Aug 23 2024, 15:57
PiRKPushed on Sep 3 2024, 06:19
Reviewer
Restricted Project
Differential Revision
D16676: [electrum] refactor private key class to better abstract ecdsa library usage
Parents
rABC28620bdc2b3c: [electrum] regenerate protobuf files
Branches
Unknown
Tags
Unknown