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

Add support for ECDSA public key serialization (compressed/uncompressed) #5218

Closed
2 tasks done
conr2d opened this issue Aug 2, 2024 · 2 comments
Closed
2 tasks done
Labels
I5-enhancement An additional feature request.

Comments

@conr2d
Copy link
Contributor

conr2d commented Aug 2, 2024

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Motivation

An ECDSA public key can be represented in either compressed (33 bytes) or uncompressed (65 bytes) form. While functions such as sp_io::crypto::secp256k1_ecdsa_recover() and sp_io::crypto::secp256k1_ecdsa_recover_compressed() facilitate public key recovery, there is currently no method available for converting a public key between these forms.

Request

Introduce a method to serialize an ECDSA public key into either compressed or uncompressed form.

Solution

Add a function to sp_io::crypto with the following signature:

fn secp256k1_pubkey_serialize(pubkey: &[u8], compressed: bool) -> Result<Vec<u8>, ()>;

This function will accept a public key and a boolean flag indicating whether the output should be in compressed form, returning the serialized public key accordingly.

Are you willing to help with this request?

Yes!

@conr2d conr2d added the I5-enhancement An additional feature request. label Aug 2, 2024
@burdges
Copy link

burdges commented Aug 3, 2024

I'm unsure how this comes up, but you should probably invoke an external rust crate like https://docs.rs/libsecp256k1 or https://docs.rs/secp256k1/ or https://docs.rs/k256 directly.

@conr2d
Copy link
Contributor Author

conr2d commented Aug 4, 2024

  • ecdsa_verify
  • ecdsa_verify_prehased
  • ecdsa_batch_verify
  • secp256k1_ecdsa_recover
  • secp256k1_ecdsa_recover_compressed

All of the above host functions can be implemented using a combination of verify_prehased, recovery_prehased, and serialize. I’m not fully aware of the rationale behind providing these specific functions, and I understand that the existing host functions cannot be removed due to the need to verify old blocks. However, it would have been preferable if these three functions had been provided from the beginning.

@conr2d conr2d closed this as not planned Won't fix, can't repro, duplicate, stale Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I5-enhancement An additional feature request.
Projects
None yet
Development

No branches or pull requests

2 participants