-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38e0447
commit fbdd7f3
Showing
13 changed files
with
220 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Deterministic bitcoin commitments library. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Written in 2019-2023 by | ||
// Dr Maxim Orlovsky <[email protected]> | ||
// | ||
// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use bc::opcodes::OP_RETURN; | ||
use bc::ScriptPubkey; | ||
use commit_verify::mpc::Commitment; | ||
use commit_verify::{EmbedCommitProof, EmbedCommitVerify, EmbedVerifyError}; | ||
|
||
use crate::opret::{Opret, OpretError, OpretProof}; | ||
|
||
impl EmbedCommitProof<Commitment, ScriptPubkey, Opret> for OpretProof { | ||
fn restore_original_container( | ||
&self, | ||
commit_container: &ScriptPubkey, | ||
) -> Result<ScriptPubkey, EmbedVerifyError<OpretError>> { | ||
if !commit_container.is_op_return() { | ||
return Err(OpretError::NoOpretOutput.into()); | ||
} | ||
if commit_container.len() != 34 { | ||
return Err(OpretError::InvalidOpretScript.into()); | ||
} | ||
Ok(ScriptPubkey::from_unsafe(vec![OP_RETURN])) | ||
} | ||
} | ||
|
||
impl EmbedCommitVerify<Commitment, Opret> for ScriptPubkey { | ||
type Proof = OpretProof; | ||
type CommitError = OpretError; | ||
|
||
fn embed_commit(&mut self, msg: &Commitment) -> Result<Self::Proof, Self::CommitError> { | ||
if !self.is_op_return() { | ||
return Err(OpretError::NoOpretOutput); | ||
} | ||
if self.len() != 1 { | ||
return Err(OpretError::InvalidOpretScript); | ||
} | ||
*self = ScriptPubkey::op_return(msg.as_slice()); | ||
Ok(OpretProof::default()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Deterministic bitcoin commitments library. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Written in 2019-2023 by | ||
// Dr Maxim Orlovsky <[email protected]> | ||
// | ||
// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use bc::Tx; | ||
use commit_verify::mpc::Commitment; | ||
use commit_verify::{EmbedCommitProof, EmbedCommitVerify, EmbedVerifyError}; | ||
|
||
use super::{Opret, OpretError, OpretProof}; | ||
|
||
impl EmbedCommitProof<Commitment, Tx, Opret> for OpretProof { | ||
fn restore_original_container( | ||
&self, | ||
commit_container: &Tx, | ||
) -> Result<Tx, EmbedVerifyError<OpretError>> { | ||
let mut tx = commit_container.clone(); | ||
for txout in &mut tx.outputs { | ||
if txout.script_pubkey.is_op_return() { | ||
*txout = self.restore_original_container(txout)?; | ||
return Ok(tx); | ||
} | ||
} | ||
Err(OpretError::NoOpretOutput.into()) | ||
} | ||
} | ||
|
||
impl EmbedCommitVerify<Commitment, Opret> for Tx { | ||
type Proof = OpretProof; | ||
type CommitError = OpretError; | ||
|
||
fn embed_commit(&mut self, msg: &Commitment) -> Result<Self::Proof, Self::CommitError> { | ||
for txout in &mut self.outputs { | ||
if txout.script_pubkey.is_op_return() { | ||
return txout.script_pubkey.embed_commit(msg); | ||
} | ||
} | ||
Err(OpretError::NoOpretOutput) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Deterministic bitcoin commitments library. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Written in 2019-2023 by | ||
// Dr Maxim Orlovsky <[email protected]> | ||
// | ||
// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use bc::TxOut; | ||
use commit_verify::mpc::Commitment; | ||
use commit_verify::{EmbedCommitProof, EmbedCommitVerify, EmbedVerifyError}; | ||
|
||
use crate::opret::{Opret, OpretError, OpretProof}; | ||
|
||
impl EmbedCommitProof<Commitment, TxOut, Opret> for OpretProof { | ||
fn restore_original_container( | ||
&self, | ||
commit_container: &TxOut, | ||
) -> Result<TxOut, EmbedVerifyError<OpretError>> { | ||
let mut txout = commit_container.clone(); | ||
txout.script_pubkey = self.restore_original_container(&txout.script_pubkey)?; | ||
Ok(txout) | ||
} | ||
} | ||
|
||
impl EmbedCommitVerify<Commitment, Opret> for TxOut { | ||
type Proof = OpretProof; | ||
type CommitError = OpretError; | ||
|
||
fn embed_commit(&mut self, msg: &Commitment) -> Result<Self::Proof, Self::CommitError> { | ||
self.script_pubkey.embed_commit(msg) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.