Skip to content

chore: Nonce::from_bytes() returns Self instead of Option<Self>#206

Closed
tvolk131 wants to merge 1 commit intoLLFourn:masterfrom
tvolk131:remove_nonce_from_bytes_option
Closed

chore: Nonce::from_bytes() returns Self instead of Option<Self>#206
tvolk131 wants to merge 1 commit intoLLFourn:masterfrom
tvolk131:remove_nonce_from_bytes_option

Conversation

@tvolk131
Copy link

@tvolk131 tvolk131 commented Feb 9, 2025

Point::from_slice() only returns None if it is passed a byte slice that isn't exactly 33 bytes long. Since Nonce::from_bytes() always passes in 33 bytes, we can guarantee to the caller that this never fails.

@nickfarrow
Copy link
Collaborator

Hey @tvolk131, I asked Lloyd about this one and it due to the fact that not every 33 byte array will render a valid Point, see Point::from_bytes. For example, the first byte must be either 0x02 or 0x03 to indicate that the y-coordinate is even/odd.

@LLFourn
Copy link
Owner

LLFourn commented May 20, 2025

Yes it's very important that not all 33 byte arrays are valid points because not all 32 byte arrays are valid x-coordinates on secp256k1 (around half are not!).

@LLFourn LLFourn closed this May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants