Skip to content

key: Rename public key types#5879

Open
mpbagot wants to merge 3 commits intorust-bitcoin:masterfrom
mpbagot:feature/key-renames
Open

key: Rename public key types#5879
mpbagot wants to merge 3 commits intorust-bitcoin:masterfrom
mpbagot:feature/key-renames

Conversation

@mpbagot
Copy link
Copy Markdown
Contributor

@mpbagot mpbagot commented Mar 23, 2026

As has been mentioned before, the public key types PublicKey and CompressedPublicKey don't correctly convey the intended usages for the types. The optionally-compressed PublicKey type is intended to be used for legacy transactions, replaced almost entirely by the CompressedPublicKey. To this end, both of the types should be renamed to better outline their usage, rather than their implementation.

  • Patch 1 renames CompressedPublicKey to FullPublicKey, leaving the old name as a deprecated alias.
  • Patch 2 adjusts a function in the sign-tx-segwit-v0 example to use FullPublicKey for WPubkeyHash generation.
  • Patch 3 renames PublicKey to LegacyPublicKey, leaving the old name as a deprecated alias.

@github-actions github-actions bot added C-bitcoin PRs modifying the bitcoin crate C-hashes PRs modifying the hashes crate C-units PRs modifying the units crate C-consensus_encoding PRs modifying the consensus-encoding crate test C-primitives C-p2p C-network labels Mar 23, 2026
@mpbagot mpbagot marked this pull request as ready for review March 23, 2026 05:39
@mpbagot mpbagot force-pushed the feature/key-renames branch from ef9007e to a1d15f8 Compare March 23, 2026 15:33
@github-actions github-actions bot removed C-hashes PRs modifying the hashes crate C-units PRs modifying the units crate C-consensus_encoding PRs modifying the consensus-encoding crate test C-primitives C-p2p C-network labels Mar 23, 2026
Comment on lines +186 to +188
#[deprecated(since = "TBD", note = "use `FullPublicKey` instead")]
#[doc(hidden)]
pub type CompressedPublicKey = FullPublicKey;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why did you create this alias twice instead of re-exporting the other one? (Here and also in key module)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Two reasons:

  • If you re-export the alias that is marked as deprecated, it throws a lint warning on the pub use statement.
  • I was following the precedent of BlockInterval. It is defined in both lib.rs and block.rs in bitcoin, presumably to avoid the above lint error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No worries, @apoelstra git blame says 4e4601b was you. Do you remember doing this intentionally?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No, I don't remember. I suspect I was trying to dance around the compiler's stupid broken deprecation logic somehow.

@tcharding
Copy link
Copy Markdown
Member

I wonder if we should keep the re-exports of the deprecated keys everywhere so that users of the old names get the deprecation warning but their code still builds?

@tcharding
Copy link
Copy Markdown
Member

Reviewed: a1d15f8

@mpbagot mpbagot force-pushed the feature/key-renames branch from a1d15f8 to ae5d512 Compare March 26, 2026 03:43
@github-actions github-actions bot added the test label Mar 26, 2026
@mpbagot mpbagot force-pushed the feature/key-renames branch from ae5d512 to 9566a19 Compare March 26, 2026 12:47
@tcharding
Copy link
Copy Markdown
Member

Reviewed: 9566a19

Note to self: Waiting on resolution of "should we use two separate type alias'"

Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 9566a19 woops I was on the wrong branch.

@apoelstra
Copy link
Copy Markdown
Member

9566a19 needs rebase

mpbagot added 3 commits March 31, 2026 13:31
The CompressedPublicKey represents an always compressed ECDSA public
key. This key type is the standard for almost all transactions in
modern Bitcoin. As such, it should be renamed to better clarify
its purpose.

Rename CompressedPublicKey to FullPublicKey.
Deprecate CompressedPublicKey.
The senders_keys function in sign-tx-segwit uses a LegacyPublicKey
to generate the WPubkeyHash. Since a FullPublicKey can generate the
same hash without the fallibility, it's better for the example to use
it here.

Replace PublicKey with FullPublicKey in senders_keys function in
sign-tx-segwit-v0 example.
The optionally-compressed PublicKey type is no longer used in Bitcoin
outside of legacy transaction handling. Since the name PublicKey
implies a general purpose public key type, it should be renamed to
clarify the niche use compared to the typical compressed public key
type, FullPublicKey.

Rename PublicKey to LegacyPublicKey.
Deprecate PublicKey.
@mpbagot mpbagot force-pushed the feature/key-renames branch from 9566a19 to 25941bc Compare March 31, 2026 02:35
Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 25941bc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-bitcoin PRs modifying the bitcoin crate test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants