Implement byte array conversions for XOnlyPublicKey#892
Conversation
|
Needs rebase. |
5a7fe06 to
9240493
Compare
Adds `to_byte_array`, `from_byte_array`, and `parse_from_byte_array` to XOnlyPublicKey. The implementation wraps `secp256k1_xonly_pubkey_parse` to ensure the provided x-coordinate represents a valid point on the curve. The `from_byte_array` method uses a `debug_assert` to satisfy the `bytes_rtt_test` macro requirements, while `parse_from_byte_array` in conjunction with `TryFrom<[u8; 32]>` provides a fallible interface for production use.
9240493 to
b6d9709
Compare
|
This is confused slop. |
|
Creating an Which for this case, could produce keys not on the curve, and the error would not be propagated to the caller. that's why I did the If the caller is sure/certain he has valid bytes array, he could use Real time the These were the factors put into consideration while implementing this. |
Description
This PR adds byte array conversion support for
XOnlyPublicKey. Since Schnorr public keys (x-only) must represent valid points on the Secp256k1 curve, the implementation includes both fallible and infallible (asserting) constructors to support different use cases and testing requirements.Changes
XOnlyPublicKey::to_byte_array: Alias toserialize()method.XOnlyPublicKey::try_from_byte_array: A safe, fallible constructor that returnsError::InvalidPublicKeyif parsing fails.XOnlyPublicKey::from_byte_array: An infallible constructor that usesdebug_assert_eq!on the FFI return value, allowing it to conform to thebytes_rtt_test!macro.rtt_cforXOnlyPublicKey.Child #885
References #859