Skip to content

Commit 5af0227

Browse files
committed
Add SharedKey::from_non_zero_poly
For better ergonomics
1 parent 26f2629 commit 5af0227

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## UNRELEASED
44

5+
- Add `SharedKey::from_non_zero_poly`
56
- Change `poly::scalar::to_point_poly` to make it less opinionated
67
- Add From/TryFrom conversions for `Scalar` to all unsigned integer types
78
- Upgrade to bincode v2

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> {

0 commit comments

Comments
 (0)