dbc/opret/
mod.rs

1// Deterministic bitcoin commitments library.
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Written in 2019-2024 by
6//     Dr Maxim Orlovsky <orlovsky@lnp-bp.org>
7//
8// Copyright (C) 2019-2024 LNP/BP Standards Association. All rights reserved.
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14//     http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21
22//! ScriptPubkey-based OP_RETURN commitments.
23
24mod tx;
25mod txout;
26mod spk;
27
28use bc::Tx;
29use commit_verify::mpc::Commitment;
30use commit_verify::{CommitmentProtocol, EmbedCommitVerify, EmbedVerifyError};
31use strict_encoding::{StrictDeserialize, StrictSerialize};
32
33use crate::LIB_NAME_BPCORE;
34
35/// Marker non-instantiable enum defining LNPBP-12 taproot OP_RETURN (`opret`) protocol.
36pub enum OpretFirst {}
37
38impl CommitmentProtocol for OpretFirst {}
39
40/// Errors during tapret commitment.
41#[derive(Clone, Eq, PartialEq, Debug, Display, Error, From)]
42#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(rename_all = "camelCase"))]
43#[display(doc_comments)]
44pub enum OpretError {
45    /// transaction doesn't contain OP_RETURN output.
46    NoOpretOutput,
47
48    /// first OP_RETURN output inside the transaction already contains some
49    /// data.
50    InvalidOpretScript,
51}
52
53/// Empty type for use inside [`crate::Anchor`] for opret commitment scheme.
54#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default)]
55#[derive(StrictType, StrictEncode, StrictDecode)]
56#[strict_type(lib = LIB_NAME_BPCORE)]
57#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(rename_all = "camelCase"))]
58pub struct OpretProof(());
59
60impl StrictSerialize for OpretProof {}
61impl StrictDeserialize for OpretProof {}
62
63impl OpretProof {
64    /// Verifies opret commitment againsy the proof.
65    pub fn verify(&self, msg: &Commitment, tx: &Tx) -> Result<(), EmbedVerifyError<OpretError>> {
66        tx.verify(msg, self)
67    }
68}