Skip to content

Commit

Permalink
Merge pull request #56 from BP-WG/primitives
Browse files Browse the repository at this point in the history
Improvements and fixes for primitive types #3
  • Loading branch information
dr-orlovsky authored Oct 7, 2023
2 parents 4f39d17 + d324a25 commit 60ac6b5
Show file tree
Hide file tree
Showing 23 changed files with 1,512 additions and 250 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ edition = "2021"
license = "Apache-2.0"

[workspace.dependencies]
amplify = "4.0.2"
amplify = "4.2.0"
strict_encoding = "2.5.0"
commit_verify = "0.10.5"
single_use_seals = "0.10.0"
Expand Down
4 changes: 2 additions & 2 deletions dbc/src/tapret/tapscript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ impl CommitVerify<TapretCommitment, Lnpbp12> for TapScript {

#[cfg(test)]
mod test {
use amplify::RawArray;
use amplify::ByteArray;
use commit_verify::{Digest, Sha256};

use super::*;

pub fn commitment() -> TapretCommitment {
let msg = Sha256::digest("test data");
TapretCommitment {
mpc: mpc::Commitment::from_raw_array(msg),
mpc: mpc::Commitment::from_byte_array(msg),
nonce: 8,
}
}
Expand Down
13 changes: 6 additions & 7 deletions dbc/src/tapret/xonlypk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use bc::{InternalPk, TapBranchHash, TapLeafHash, TapNodeHash, TapScript};
use bc::{InternalPk, OutputPk, TapBranchHash, TapLeafHash, TapNodeHash, TapScript};
use commit_verify::{mpc, CommitVerify, ConvolveCommit, ConvolveCommitProof};
use secp256k1::XOnlyPublicKey;

use super::{Lnpbp12, TapretNodePartner, TapretPathProof, TapretProof};
use crate::tapret::tapscript::TapretCommitment;
Expand All @@ -46,20 +45,20 @@ pub enum TapretKeyError {
impl ConvolveCommitProof<mpc::Commitment, InternalPk, Lnpbp12> for TapretProof {
type Suppl = TapretPathProof;

fn restore_original(&self, _: &XOnlyPublicKey) -> InternalPk { self.internal_pk }
fn restore_original(&self, _: &OutputPk) -> InternalPk { self.internal_pk }

fn extract_supplement(&self) -> &Self::Suppl { &self.path_proof }
}

impl ConvolveCommit<mpc::Commitment, TapretProof, Lnpbp12> for InternalPk {
type Commitment = XOnlyPublicKey;
type Commitment = OutputPk;
type CommitError = TapretKeyError;

fn convolve_commit(
&self,
supplement: &TapretPathProof,
msg: &mpc::Commitment,
) -> Result<(XOnlyPublicKey, TapretProof), Self::CommitError> {
) -> Result<(OutputPk, TapretProof), Self::CommitError> {
let tapret_commitment = TapretCommitment::with(*msg, supplement.nonce);
let script_commitment = TapScript::commit(&tapret_commitment);

Expand All @@ -80,7 +79,7 @@ impl ConvolveCommit<mpc::Commitment, TapretProof, Lnpbp12> for InternalPk {
TapLeafHash::with_tap_script(&script_commitment).into()
};

let output_key = self.to_output_key(Some(merkle_root));
let (output_key, _) = self.to_output_pk(Some(merkle_root));

let proof = TapretProof {
path_proof: supplement.clone(),
Expand Down Expand Up @@ -117,7 +116,7 @@ mod test {
let tapret_commitment = TapretCommitment::with(msg, path_proof.nonce);
let script_commitment = TapScript::commit(&tapret_commitment);
let script_leaf = TapLeafHash::with_tap_script(&script_commitment);
let real_key = internal_pk.to_output_key(Some(script_leaf));
let (real_key, _) = internal_pk.to_output_pk(Some(script_leaf));

assert_eq!(outer_key, real_key);

Expand Down
2 changes: 2 additions & 0 deletions primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ impl FromHex for BlockHash {
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(StrictType, StrictEncode, StrictDecode, StrictDumb)]
#[strict_type(lib = LIB_NAME_BITCOIN)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down
Loading

0 comments on commit 60ac6b5

Please sign in to comment.