Skip to content

Commit 35af4a7

Browse files
authored
Merge pull request #228 from LLFourn/to_point_poly_flexible
Make to_point_poly more flexible
2 parents 6abb5e7 + 5af0227 commit 35af4a7

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## UNRELEASED
44

5+
- Add `SharedKey::from_non_zero_poly`
6+
- Change `poly::scalar::to_point_poly` to make it less opinionated
57
- Add From/TryFrom conversions for `Scalar` to all unsigned integer types
68
- Upgrade to bincode v2
79
- MSRV 1.63 -> 1.85

schnorr_fun/src/frost/shared_key.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl<T: PointType, Z: ZeroChoice> SharedKey<T, Z> {
233233
}
234234
}
235235

236-
impl SharedKey<Normal> {
236+
impl SharedKey {
237237
/// Convert the key into a [BIP340] "x-only" SharedKey.
238238
///
239239
/// This is the [BIP340] compatible version of the key which you can put in a segwitv1 output.
@@ -248,6 +248,18 @@ impl SharedKey<Normal> {
248248

249249
SharedKey::from_inner(self.point_polynomial)
250250
}
251+
252+
/// Creates a non-zero `SharedKey` from a known `NonZero` first coefficient the other coefficients in `rest`.
253+
pub fn from_non_zero_poly<Z>(
254+
first_coef: Point,
255+
rest: impl IntoIterator<Item = Point<Normal, Public, Z>>,
256+
) -> Self {
257+
let mut poly = vec![first_coef.mark_zero()];
258+
for point in rest.into_iter() {
259+
poly.push(point.mark_zero());
260+
}
261+
Self::from_inner(poly)
262+
}
251263
}
252264

253265
impl SharedKey<Normal, Zero> {

secp256kfun/src/point.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ impl<T, S, Z> AsRef<backend::Point> for Point<T, S, Z> {
7979
}
8080
}
8181

82+
impl<T, S, Z> AsRef<Point<T, S, Z>> for Point<T, S, Z> {
83+
fn as_ref(&self) -> &Point<T, S, Z> {
84+
self
85+
}
86+
}
87+
8288
impl<T: Copy, S, Z> Copy for Point<T, S, Z> {}
8389

8490
impl Point<Normal, Public, NonZero> {

secp256kfun/src/poly.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ pub mod scalar {
3535
/// .collect::<Vec<_>>();
3636
/// let point_poly = poly::scalar::to_point_poly(&secret_poly);
3737
/// ```
38-
pub fn to_point_poly(scalar_poly: &[Scalar]) -> Vec<Point> {
39-
scalar_poly.iter().map(|a| g!(a * G).normalize()).collect()
38+
pub fn to_point_poly<S: Secrecy, Z: ZeroChoice>(
39+
scalar_poly: impl IntoIterator<Item = impl AsRef<Scalar<S, Z>>>,
40+
) -> Vec<Point<Normal, Public, Z>> {
41+
scalar_poly
42+
.into_iter()
43+
.map(|a| g!(a.as_ref() * G).normalize())
44+
.collect()
4045
}
4146

4247
/// Generate a [`Scalar`] polynomial with `length` coefficients.

secp256kfun/src/scalar.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ impl<S, Z> AsRef<backend::Scalar> for Scalar<S, Z> {
5959
}
6060
}
6161

62+
impl<S, Z> AsRef<Scalar<S, Z>> for Scalar<S, Z> {
63+
fn as_ref(&self) -> &Scalar<S, Z> {
64+
self
65+
}
66+
}
67+
6268
impl<S, Z> Clone for Scalar<S, Z> {
6369
fn clone(&self) -> Self {
6470
*self

0 commit comments

Comments
 (0)