Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements and fixes for primitive types #4 #56

Merged
merged 31 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3b5825a
primitives: move sighashes module from PSBT crate
dr-orlovsky Oct 5, 2023
f6bf571
primitives: move WitnessScript and RedeemScript from PSBT crate
dr-orlovsky Oct 5, 2023
da86413
primitives: move Witness, Wtxid & WitnessScript into segwit module
dr-orlovsky Oct 5, 2023
aff9ff1
primitives: rename consensus into coding module
dr-orlovsky Oct 5, 2023
5039b71
stl: rename Bitcoin into BP Tx library
dr-orlovsky Oct 5, 2023
4d8a411
primitives: add explicit taproot module exports
dr-orlovsky Oct 5, 2023
250f119
stl: rename Bitcoin into Tx library
dr-orlovsky Oct 5, 2023
d4d1979
primitives: enforce witness program length at type level
dr-orlovsky Oct 5, 2023
a1850fc
stl: add Bitcoin Consensus library
dr-orlovsky Oct 5, 2023
99c21f3
primitives: move VarInt into coding module
dr-orlovsky Oct 5, 2023
afa8e4e
primitives: add todo list
dr-orlovsky Oct 5, 2023
9783505
primitives: use NonStandardValue instead of NonStandardSighashType
dr-orlovsky Oct 5, 2023
2bf569e
primitives: add ByteStr type
dr-orlovsky Oct 5, 2023
64a77f3
primitives: make TapMerklePath max size match consensus rule
dr-orlovsky Oct 5, 2023
873ebc8
primitives: add taproot ControlBlock and Parity structures
dr-orlovsky Oct 5, 2023
1c0095f
primitives: implement IntoIterator for TapMerklePath
dr-orlovsky Oct 5, 2023
7d87b3b
primitives: refactor LeafVer convertors to match conventions
dr-orlovsky Oct 5, 2023
6c82fe6
primitives: add TapScript::as_script_bytes method
dr-orlovsky Oct 5, 2023
e2823eb
primitives: implement consensus encoding for taproot data
dr-orlovsky Oct 5, 2023
9baa1e8
primitives: fix taproot error export
dr-orlovsky Oct 5, 2023
f1cdb38
primitives: implement AsRef and serde for ByteStr
dr-orlovsky Oct 5, 2023
a23d9e7
chore: update to new amplify ByteArray APIs
dr-orlovsky Oct 6, 2023
8efffe9
primitives: implement consensus decoding for ControlBlock
dr-orlovsky Oct 6, 2023
b757924
primitives: add LeafScript constructors
dr-orlovsky Oct 6, 2023
808a86e
primitives: move TaprootPk and OutputPk from bp-std
dr-orlovsky Oct 6, 2023
7c10f61
primitives: return output key parity
dr-orlovsky Oct 6, 2023
fc16f58
primitives: add TaprootPk::from(PublicKey)
dr-orlovsky Oct 6, 2023
a211574
primitives: add ControlBlock constructor
dr-orlovsky Oct 6, 2023
2798bf7
primitives: fix consensus encoding of control block data
dr-orlovsky Oct 6, 2023
49b7d80
stl: reverse previous changes
dr-orlovsky Oct 7, 2023
d324a25
primitives: document difference between forms of taproot public keys
dr-orlovsky Oct 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading