[−][src]Trait lnpbp::commit_verify::EmbedCommitVerify
Trait for embed-commit-verify scheme, where some data structure (named container) may commit to existing message (producing commitment data structure) in such way that the original message can't be restored from the commitment, however the fact of the commitment may be deterministically checked when the message is revealed against the original container.
To use embed-commit-verify scheme one needs to implement this trait for the commitment data structure and provide it (through associated types) with the used container type.
Operations with embed-commit-verify scheme may be represented in form of
EmbedCommit: (Container, Message) -> Commitment
and
Verify: (Commitment, Container, Message) -> bool
; the original container
is required for the verification procedure.
This trait is heavily used in deterministic bitcoin commitments [crate::dbc] module implementations
Associated Types
type Container: Clone
[src]
External container type that will be used to host commitment to a message
type Error: Error
[src]
Error type that may be reported during [commit_embed] procedure
Required methods
pub fn embed_commit(
container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
[src]
container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
Creates a commitment and embeds it into the provided container returning
Self
containing both message commitment and all additional data
required to reconstruct the original container
Provided methods
pub fn verify(
&self,
container: &Self::Container,
msg: &MSG
) -> Result<bool, Self::Error>
[src]
&self,
container: &Self::Container,
msg: &MSG
) -> Result<bool, Self::Error>
Verifies commitment against the message; default implementation just
reconstructs the original container with [container] function,
repeats the commitment to the message and check it against the self
.
Verification is a failable procedure returning bool. The difference
between returning Ok(false)
and Err(_)
is the following:
Err(_)
: validation was not possible due to container data structure- related error or some internal error during the validation process. It is undefined whether the message corresponds to the commitment.Ok(false)
: validation was performed completely; the message does not correspond to the commitmentOk(true)
: validation was performed completely; the message does correspond to the commitment
Implementors
impl<MSG> EmbedCommitVerify<MSG> for KeysetCommitment where
MSG: AsRef<[u8]>,
[src]
MSG: AsRef<[u8]>,
type Container = KeysetContainer
type Error = Error
pub fn embed_commit(
keyset_container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
[src]
keyset_container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
impl<MSG> EmbedCommitVerify<MSG> for LockscriptCommitment where
MSG: AsRef<[u8]>,
[src]
MSG: AsRef<[u8]>,
type Container = LockscriptContainer
type Error = Error
pub fn embed_commit(
container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
[src]
container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
Function implements commitment procedure according to LNPBP-2.
LNPBP-2 Specification extract:
- The provided script MUST be parsed with Miniscript parser; if the parser fails the procedure MUST fail.
- Iterate over all branches of the abstract syntax tree generated by
the Miniscript parser, running the following algorithm for each node:
- if a public key hash is met (
pk_h
Miniscript command) and it can't be resolved against known public keys or other public keys extracted from the script, fail the procedure; - if a public key is found (
pk
) add it to the list of the collected public keys; - for all other types of Miniscript commands iterate over their branches.
- if a public key hash is met (
- Select unique public keys (i.e. if some public key is repeated in different parts of the script/in different script branches, pick a single instance of it). Compressed and uncompressed versions of the same public key must be treaded as the same public key under this procedure.
- If no public keys were found fail the procedure; return the collected keys otherwise.
NB: SUBJECT TO CHANGE UPON RELEASE
By "miniscript" we mean usage of rust-miniscript
library at commit
a5ba1219feb8b5a289c8f12176d632635eb8a959
which may be found on
https://github.com/LNP-BP/rust-miniscript/commit/a5ba1219feb8b5a289c8f12176d632635eb8a959
impl<MSG> EmbedCommitVerify<MSG> for PubkeyCommitment where
MSG: AsRef<[u8]>,
[src]
MSG: AsRef<[u8]>,
type Container = PubkeyContainer
type Error = Error
pub fn embed_commit(
pubkey_container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
[src]
pubkey_container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
impl<MSG> EmbedCommitVerify<MSG> for SpkCommitment where
MSG: AsRef<[u8]>,
[src]
MSG: AsRef<[u8]>,
type Container = SpkContainer
type Error = Error
pub fn embed_commit(
container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
[src]
container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
impl<MSG> EmbedCommitVerify<MSG> for TaprootCommitment where
MSG: AsRef<[u8]>,
[src]
MSG: AsRef<[u8]>,
type Container = TaprootContainer
type Error = Error
pub fn embed_commit(
container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
[src]
container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
impl<MSG> EmbedCommitVerify<MSG> for TxCommitment where
MSG: AsRef<[u8]>,
[src]
MSG: AsRef<[u8]>,
type Container = TxContainer
type Error = Error
pub fn embed_commit(
container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
[src]
container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
impl<MSG> EmbedCommitVerify<MSG> for TxoutCommitment where
MSG: AsRef<[u8]>,
[src]
MSG: AsRef<[u8]>,
type Container = TxoutContainer
type Error = Error
pub fn embed_commit(
container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>
[src]
container: &mut Self::Container,
msg: &MSG
) -> Result<Self, Self::Error>