3.11 Better document API expectations

This commit is contained in:
Luke Parker
2023-07-19 23:51:21 -04:00
parent df67b7d94c
commit 6f9d02fdf8
3 changed files with 11 additions and 3 deletions

View File

@@ -37,8 +37,9 @@ pub fn x_only(key: &ProjectivePoint) -> XOnlyPublicKey {
XOnlyPublicKey::from_slice(&x(key)).expect("x_only was passed a point which was infinity or odd") XOnlyPublicKey::from_slice(&x(key)).expect("x_only was passed a point which was infinity or odd")
} }
/// Make a point even by adding the generator until it is even. Returns the even point and the /// Make a point even by adding the generator until it is even.
/// amount of additions required. ///
/// Returns the even point and the amount of additions required.
pub fn make_even(mut key: ProjectivePoint) -> (ProjectivePoint, u64) { pub fn make_even(mut key: ProjectivePoint) -> (ProjectivePoint, u64) {
let mut c = 0; let mut c = 0;
while key.to_encoded_point(true).tag() == Tag::CompressedOddY { while key.to_encoded_point(true).tag() == Tag::CompressedOddY {
@@ -51,6 +52,8 @@ pub fn make_even(mut key: ProjectivePoint) -> (ProjectivePoint, u64) {
/// A BIP-340 compatible HRAm for use with the modular-frost Schnorr Algorithm. /// A BIP-340 compatible HRAm for use with the modular-frost Schnorr Algorithm.
/// ///
/// If passed an odd nonce, it will have the generator added until it is even. /// If passed an odd nonce, it will have the generator added until it is even.
///
/// If the key is odd, this will panic.
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct Hram; pub struct Hram;

View File

@@ -24,12 +24,17 @@ mod send;
pub use send::*; pub use send::*;
/// Tweak keys to ensure they're usable with Bitcoin. /// Tweak keys to ensure they're usable with Bitcoin.
///
/// Taproot keys, which these keys are used as, must be even. This offsets the keys until they're
/// even.
pub fn tweak_keys(keys: &ThresholdKeys<Secp256k1>) -> ThresholdKeys<Secp256k1> { pub fn tweak_keys(keys: &ThresholdKeys<Secp256k1>) -> ThresholdKeys<Secp256k1> {
let (_, offset) = make_even(keys.group_key()); let (_, offset) = make_even(keys.group_key());
keys.offset(Scalar::from(offset)) keys.offset(Scalar::from(offset))
} }
/// Return the Taproot address for a public key. /// Return the Taproot address for a public key.
///
/// If the key is odd, this will return None.
pub fn address(network: Network, key: ProjectivePoint) -> Option<Address> { pub fn address(network: Network, key: ProjectivePoint) -> Option<Address> {
if key.to_encoded_point(true).tag() != Tag::CompressedEvenY { if key.to_encoded_point(true).tag() != Tag::CompressedEvenY {
return None; return None;

View File

@@ -245,7 +245,7 @@ impl SignableTransaction {
/// A FROST signing machine to produce a Bitcoin transaction. /// A FROST signing machine to produce a Bitcoin transaction.
/// ///
/// This does not support caching its preprocess. When sign is called, the message must be empty. /// This does not support caching its preprocess. When sign is called, the message must be empty.
/// This will panic if it isn't. /// This will panic if either `cache` is called or the message isn't empty.
pub struct TransactionMachine { pub struct TransactionMachine {
tx: SignableTransaction, tx: SignableTransaction,
sigs: Vec<AlgorithmMachine<Secp256k1, Schnorr<RecommendedTranscript>>>, sigs: Vec<AlgorithmMachine<Secp256k1, Schnorr<RecommendedTranscript>>>,