Test coverage and detailed comments for LNPBPS-0001-related code
// along with this software.
// If not, see <https://opensource.org/licenses/MIT>.
-///! Implementation of different cryptographic commitment primitives, focused around LNPBPS-0001
-///! (collision-resistant elliptic curve-based commitments). Also covers more standard hash
-///! commitments. In the future, with the addition of new LNPBPS for cryptographic commitments the
-///! support must be extended to cover sign-to-contract scheme, Schnorr's signatures etc
-///!
-///! To use, first implement `Committable` trait for the data structure to which you'd like commit to.
-///! Define which of the provided commitment schemes you plan to use and consruct corresponding
-///! `CommitmentSource` type containing all data necessary for constructing the actual commitment,
-///! for instance implementing trait `From` for CommitmentSource-derived type on some source data
-///! type. Then use corresponding `CommitmentEngine` to produce `RevealData`-typed structure.
-///! From the reveal data you can both generate the actual commitment with `commit` function or
-///! verify existing commitment with `verify` function.
+//! Implementation of different cryptographic commitment primitives, focused around LNPBPS-0001
+//! (collision-resistant elliptic curve-based commitments). Also covers more standard hash
+//! commitments. In the future, with the addition of new LNPBPS for cryptographic commitments the
+//! support must be extended to cover sign-to-contract scheme, Schnorr's signatures etc
+//!
+//! To use, first implement `Committable` trait for the data structure to which you'd like commit to.
+//! Define which of the provided commitment schemes you plan to use and consruct corresponding
+//! `CommitmentSource` type containing all data necessary for constructing the actual commitment,
+//! for instance implementing trait `From` for CommitmentSource-derived type on some source data
+//! type. Then use corresponding `CommitmentEngine` to produce `RevealData`-typed structure.
+//! From the reveal data you can both generate the actual commitment with `commit` function or
+//! verify existing commitment with `verify` function.
/// In order to commit to some data the data structure must implement this trait
pub trait Committable<CS: CommitmentSource> {}
@@ -35,11 +35,16 @@ pub trait CommitTarget {}
/// Trait for preparing structured data for commitment and verification from some source data
pub trait CommitmentEngine<CT: CommitTarget, CS: CommitmentSource, RD: RevealData<CT>> {
+ /// Creates data in form of `RevealData` that is used for both commit and verify procedures.
+ /// Takes `CommitmentSource`-enabled data source.
fn reveal(&self, src: &CS) -> RD;
}
/// Trait that must be implemented by a structured data that have to be committed to
pub trait RevealData<CT: CommitTarget>: Sized {
+ /// Commits to it's content returning the actual commitment supporting `CommitTarget` trait
fn commit(&self) -> CT;
+
+ /// Verifies the provided commitment against it's own data
fn verify(&self, commit: CT) -> bool;
}
