Skip to content

Commit bf9f556

Browse files
committed
Add rustdocs describing fixed width serde
We recently added fixed width serialization for some types however serialization is only fixed width when data is serialized with the `bincode` crate. Add rustdocs describing fixed width serde to `SecretKey`, `PublicKey`, and `XOnlyPublicKey` (`KeyPair` is already done).
1 parent c28808c commit bf9f556

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/key.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ use crate::schnorr;
3535

3636
/// Secret 256-bit key used as `x` in an ECDSA signature.
3737
///
38+
/// # Serde support
39+
///
40+
/// Implements de/serialization with the `serde` feature enabled. We treat the byte value as a tuple
41+
/// of 32 `u8`s for non-human-readable formats. This representation is optimal for for some formats
42+
/// (e.g. [`bincode`]) however other formats may be less optimal (e.g. [`cbor`]).
43+
///
3844
/// # Examples
3945
///
4046
/// Basic usage:
@@ -47,6 +53,8 @@ use crate::schnorr;
4753
/// let secret_key = SecretKey::new(&mut rand::thread_rng());
4854
/// # }
4955
/// ```
56+
/// [`bincode`]: https://docs.rs/bincode
57+
/// [`cbor`]: https://docs.rs/cbor
5058
pub struct SecretKey([u8; constants::SECRET_KEY_SIZE]);
5159
impl_array_newtype!(SecretKey, u8, constants::SECRET_KEY_SIZE);
5260
impl_display_secret!(SecretKey);
@@ -70,6 +78,12 @@ pub const ONE_KEY: SecretKey = SecretKey([0, 0, 0, 0, 0, 0, 0, 0,
7078

7179
/// A Secp256k1 public key, used for verification of signatures.
7280
///
81+
/// # Serde support
82+
///
83+
/// Implements de/serialization with the `serde` feature enabled. We treat the byte value as a tuple
84+
/// of 33 `u8`s for non-human-readable formats. This representation is optimal for for some formats
85+
/// (e.g. [`bincode`]) however other formats may be less optimal (e.g. [`cbor`]).
86+
///
7387
/// # Examples
7488
///
7589
/// Basic usage:
@@ -83,6 +97,8 @@ pub const ONE_KEY: SecretKey = SecretKey([0, 0, 0, 0, 0, 0, 0, 0,
8397
/// let public_key = PublicKey::from_secret_key(&secp, &secret_key);
8498
/// # }
8599
/// ```
100+
/// [`bincode`]: https://docs.rs/bincode
101+
/// [`cbor`]: https://docs.rs/cbor
86102
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
87103
#[repr(transparent)]
88104
pub struct PublicKey(ffi::PublicKey);
@@ -1029,6 +1045,12 @@ impl<'de> serde::Deserialize<'de> for KeyPair {
10291045

10301046
/// An x-only public key, used for verification of Schnorr signatures and serialized according to BIP-340.
10311047
///
1048+
/// # Serde support
1049+
///
1050+
/// Implements de/serialization with the `serde` feature enabled. We treat the byte value as a tuple
1051+
/// of 32 `u8`s for non-human-readable formats. This representation is optimal for for some formats
1052+
/// (e.g. [`bincode`]) however other formats may be less optimal (e.g. [`cbor`]).
1053+
///
10321054
/// # Examples
10331055
///
10341056
/// Basic usage:
@@ -1042,6 +1064,8 @@ impl<'de> serde::Deserialize<'de> for KeyPair {
10421064
/// let xonly = XOnlyPublicKey::from_keypair(&key_pair);
10431065
/// # }
10441066
/// ```
1067+
/// [`bincode`]: https://docs.rs/bincode
1068+
/// [`cbor`]: https://docs.rs/cbor
10451069
#[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, Hash)]
10461070
pub struct XOnlyPublicKey(ffi::XOnlyPublicKey);
10471071

0 commit comments

Comments
 (0)