mikelodder7 / vsss-rs

Verifiable Secret Sharing Schemes
Apache License 2.0
77 stars 12 forks source link

Proper way to construct a WrappedScalar #12

Open apyrgio opened 1 year ago

apyrgio commented 1 year ago

The secp256k1::WrappedScalar has the following constructors:

From<k256::arithmetic::scalar::Scalar>>
From<u64>>

The problems with these constructors are:

There also some other constructors (e.g., from_be_bytes_reduced), but it's not clear how one can use them (not a fault of this repo, the elliptic_curves is a bit lacking in this regard).

Why is the above a problem? Consider someone running the examples in this repo:

use k256::{NonZeroScalar, SecretKey};
[...]

let sk = SecretKey::random(&mut osrng);
let secret = WrappedScalar(*sk.to_nonzero_scalar());

Rust will complain that the Scalar type that vsss_rs expects (0.11) is different from the provided k256::Scalar type (0.12). The only way I've found to circumvent this limitation is to use an older version of k256 (0.11), specifically for importing a k256::SecretKey, which will produce a proper k256::Scalar type (0.11).

This is of course a bit esoteric, and prone to breakage. A better suggestion would be to re-export k256::SecretKey from this module (as k256 already does for the elliptic_curves::SecretKey), and let library consumers use that.

Do you agree, do you perhaps have a better suggestion?