[][src]Function lnpbp::lnpbp1::commit

pub fn commit(
    keyset: &mut BTreeSet<PublicKey>,
    target_pubkey: &mut PublicKey,
    protocol_tag: &Hash,
    message: &impl AsRef<[u8]>
) -> Result<Hmac<Hash>, Error>

Function performs commitment procedure according to LNPBP-1.

Parameters

  • A set of public keys for committing during the LNPBP-1 procedure
  • Target public key for tweaking. Must be a part of the keyset, otherwise function will fail with Error::NotKeysetMember
  • Protocol-specific tag in form of 32-byte hash
  • Message to commit to, which must be representable as a byte slice using AsRef::as_ref()

Returns

Function mutates two of its parameters,

  • target_pubkey, with a tweaked version of the public key containing commitment to the message and the rest of keyset,
  • keyset, by replacing original target_pubkey with its tweaked version and returns tweaking_factor as a return parameter wrapped into Result::Ok.

If the function fails with any error, value for target_pubkey and keyset is undefined and must be discarded.

Errors

Function may fail because of one of the following circumstances:

  • If target_pubkey is not a part of keyset (Error::NotKeysetMember)
  • If keyset deliberately constructed in a way that sum of some of its keys is equivalent to negation of some other keys. In this case function fails with Error::SumInfiniteResult
  • With negligible probability because of elliptic curve Secp256k1 point addition overflow; in this case function returns either Error::SumInfiniteResult, if it happens during summation of public keys from the keyset, or Error::InvalidTweak, if it happens during tweaking factor addition to the target_pubkey.

Protocol:

Please refer to the original document for the verification: https://github.com/LNP-BP/LNPBPs/blob/master/lnpbp-0001.md