1use bc::opcodes::OP_RETURN;
23use bc::ScriptPubkey;
24use commit_verify::mpc::Commitment;
25use commit_verify::{EmbedCommitProof, EmbedCommitVerify, EmbedVerifyError};
26
27use crate::opret::{OpretError, OpretFirst, OpretProof};
28
29impl EmbedCommitProof<Commitment, ScriptPubkey, OpretFirst> for OpretProof {
30 fn restore_original_container(
31 &self,
32 commit_container: &ScriptPubkey,
33 ) -> Result<ScriptPubkey, EmbedVerifyError<OpretError>> {
34 if !commit_container.is_op_return() {
35 return Err(OpretError::NoOpretOutput.into());
36 }
37 if commit_container.len() != 34 {
38 return Err(OpretError::InvalidOpretScript.into());
39 }
40 Ok(ScriptPubkey::from_checked(vec![OP_RETURN]))
41 }
42}
43
44impl EmbedCommitVerify<Commitment, OpretFirst> for ScriptPubkey {
45 type Proof = OpretProof;
46 type CommitError = OpretError;
47
48 fn embed_commit(&mut self, msg: &Commitment) -> Result<Self::Proof, Self::CommitError> {
49 if !self.is_op_return() {
50 return Err(OpretError::NoOpretOutput);
51 }
52 if self.len() != 1 {
53 return Err(OpretError::InvalidOpretScript);
54 }
55 *self = ScriptPubkey::op_return(msg.as_slice());
56 Ok(OpretProof::default())
57 }
58}