Skip to content

Commit 9ab9403

Browse files
committed
Add cobuild_entry and cobuild_normal_entry
1 parent 10c97f0 commit 9ab9403

File tree

9 files changed

+365
-195
lines changed

9 files changed

+365
-195
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ install:
1919
ci:
2020
capsule build --release
2121
cd tests && cargo test && cd ..
22+
23+
debug:
24+
capsule build --release
25+
cd tests && RUST_LOG=debug cargo test -- --nocapture && cd ..

ckb-transaction-cobuild/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ edition = "2021"
55

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

8+
[features]
9+
default = []
10+
log = []
11+
812
[dependencies]
913
blake2b-ref = "0.3.1"
1014
ckb-std = { version = "0.14.3", default-features = false, features = ["ckb-types"] }

ckb-transaction-cobuild/src/blake2b.rs

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,51 @@ pub const PERSONALIZATION_SIGHASH_ALL_ONLY: &[u8] = b"ckb-tcob-sgohash";
55
pub const PERSONALIZATION_OTX: &[u8] = b"ckb-tcob-otxhash";
66

77
/// return a blake2b instance with personalization for SighashAll
8-
pub fn new_sighash_all_blake2b() -> Blake2b {
9-
Blake2bBuilder::new(32)
10-
.personal(PERSONALIZATION_SIGHASH_ALL)
11-
.build()
8+
pub fn new_sighash_all_blake2b() -> Blake2bStatistics {
9+
Blake2bStatistics::new(
10+
Blake2bBuilder::new(32)
11+
.personal(PERSONALIZATION_SIGHASH_ALL)
12+
.build(),
13+
)
1214
}
1315

1416
/// return a blake2b instance with personalization for SighashAllOnly
15-
pub fn new_sighash_all_only_blake2b() -> Blake2b {
16-
Blake2bBuilder::new(32)
17-
.personal(PERSONALIZATION_SIGHASH_ALL_ONLY)
18-
.build()
17+
pub fn new_sighash_all_only_blake2b() -> Blake2bStatistics {
18+
Blake2bStatistics::new(
19+
Blake2bBuilder::new(32)
20+
.personal(PERSONALIZATION_SIGHASH_ALL_ONLY)
21+
.build(),
22+
)
1923
}
2024

2125
/// return a blake2b instance with personalization for OTX
22-
pub fn new_otx_blake2b() -> Blake2b {
23-
Blake2bBuilder::new(32)
24-
.personal(PERSONALIZATION_OTX)
25-
.build()
26+
pub fn new_otx_blake2b() -> Blake2bStatistics {
27+
Blake2bStatistics::new(
28+
Blake2bBuilder::new(32)
29+
.personal(PERSONALIZATION_OTX)
30+
.build(),
31+
)
32+
}
33+
34+
pub struct Blake2bStatistics {
35+
count: usize,
36+
blake2b: Blake2b,
37+
}
38+
39+
impl Blake2bStatistics {
40+
pub fn new(blake2b: Blake2b) -> Self {
41+
Self { count: 0, blake2b }
42+
}
43+
44+
pub fn update(&mut self, data: &[u8]) {
45+
self.blake2b.update(data);
46+
self.count += data.len();
47+
}
48+
49+
pub fn finalize(self, dst: &mut [u8]) {
50+
self.blake2b.finalize(dst)
51+
}
52+
pub fn count(&self) -> usize {
53+
self.count
54+
}
2655
}

0 commit comments

Comments
 (0)