Skip to content

Commit

Permalink
Add cobuild_entry and cobuild_normal_entry
Browse files Browse the repository at this point in the history
  • Loading branch information
XuJiandong committed Mar 14, 2024
1 parent 10c97f0 commit 9ab9403
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 195 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ install:
ci:
capsule build --release
cd tests && cargo test && cd ..

debug:
capsule build --release
cd tests && RUST_LOG=debug cargo test -- --nocapture && cd ..
4 changes: 4 additions & 0 deletions ckb-transaction-cobuild/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = []
log = []

[dependencies]
blake2b-ref = "0.3.1"
ckb-std = { version = "0.14.3", default-features = false, features = ["ckb-types"] }
Expand Down
53 changes: 41 additions & 12 deletions ckb-transaction-cobuild/src/blake2b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,51 @@ pub const PERSONALIZATION_SIGHASH_ALL_ONLY: &[u8] = b"ckb-tcob-sgohash";
pub const PERSONALIZATION_OTX: &[u8] = b"ckb-tcob-otxhash";

/// return a blake2b instance with personalization for SighashAll
pub fn new_sighash_all_blake2b() -> Blake2b {
Blake2bBuilder::new(32)
.personal(PERSONALIZATION_SIGHASH_ALL)
.build()
pub fn new_sighash_all_blake2b() -> Blake2bStatistics {
Blake2bStatistics::new(
Blake2bBuilder::new(32)
.personal(PERSONALIZATION_SIGHASH_ALL)
.build(),
)
}

/// return a blake2b instance with personalization for SighashAllOnly
pub fn new_sighash_all_only_blake2b() -> Blake2b {
Blake2bBuilder::new(32)
.personal(PERSONALIZATION_SIGHASH_ALL_ONLY)
.build()
pub fn new_sighash_all_only_blake2b() -> Blake2bStatistics {
Blake2bStatistics::new(
Blake2bBuilder::new(32)
.personal(PERSONALIZATION_SIGHASH_ALL_ONLY)
.build(),
)
}

/// return a blake2b instance with personalization for OTX
pub fn new_otx_blake2b() -> Blake2b {
Blake2bBuilder::new(32)
.personal(PERSONALIZATION_OTX)
.build()
pub fn new_otx_blake2b() -> Blake2bStatistics {
Blake2bStatistics::new(
Blake2bBuilder::new(32)
.personal(PERSONALIZATION_OTX)
.build(),
)
}

pub struct Blake2bStatistics {
count: usize,
blake2b: Blake2b,
}

impl Blake2bStatistics {
pub fn new(blake2b: Blake2b) -> Self {
Self { count: 0, blake2b }
}

pub fn update(&mut self, data: &[u8]) {
self.blake2b.update(data);
self.count += data.len();
}

pub fn finalize(self, dst: &mut [u8]) {
self.blake2b.finalize(dst)
}
pub fn count(&self) -> usize {
self.count
}
}
Loading

0 comments on commit 9ab9403

Please sign in to comment.