Skip to content

Commit 2cfa633

Browse files
authored
Merge pull request #122 from LNP-BP/stl
Strict type library updates
2 parents 46a79d2 + d31990c commit 2cfa633

24 files changed

+171
-148
lines changed

Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ license = "Apache-2.0"
2222

2323
[package]
2424
name = "client_side_validation"
25-
version = "0.10.1"
25+
version = "0.10.2"
2626
description = "Client-side validation foundation library"
2727
keywords = ["lnp-bp", "smart-contracts", "blockchain"]
2828
categories = ["cryptography"]
@@ -40,13 +40,14 @@ name = "client_side_validation"
4040
path = "src/lib.rs"
4141

4242
[dependencies]
43-
commit_verify = { version = "0.10.1", path = "./commit_verify", default-features = false }
43+
commit_verify = { version = "0.10.2", path = "./commit_verify", default-features = false }
4444
single_use_seals = { version = "0.10.0", path = "./single_use_seals" }
4545
serde_crate = { package = "serde", version = "1", features = ["derive"], optional = true }
4646

4747
[features]
4848
default = ["derive"]
49-
all = ["serde", "rand", "async"]
49+
all = ["serde", "rand", "async", "stl"]
50+
stl = ["commit_verify/stl"]
5051
async = ["single_use_seals/async"]
5152
rand = ["commit_verify/rand"]
5253
derive = ["commit_verify/derive"]

commit_verify/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "commit_verify"
3-
version = "0.10.1"
3+
version = "0.10.2"
44
description = "Commit-verify API for client-side validation"
55
keywords = ["lnp-bp", "smart-contracts", "blockchain", "commitments"]
66
categories = ["cryptography"]
@@ -22,10 +22,10 @@ name = "commit-stl"
2222
required-features = ["stl"]
2323

2424
[dependencies]
25-
amplify = { version = "4.0.0-beta.20", features = ["hex", "apfloat"] }
26-
commit_encoding_derive = { version = "0.10.0-beta.1", path = "derive" }
27-
strict_encoding = "2.0.0"
28-
strict_types = { version = "1.0.0-rc.1", optional = true }
25+
amplify = { version = "4.0.0", features = ["hex", "apfloat"] }
26+
commit_encoding_derive = { version = "0.10.0", path = "derive" }
27+
strict_encoding = "2.2.0"
28+
strict_types = { version = "1.2.0", optional = true }
2929
rand = { version = "0.8.5", optional = true }
3030
serde_crate = { version = "1.0", package = "serde", optional = true }
3131

commit_verify/derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "commit_encoding_derive"
3-
version = "0.10.0-beta.1"
3+
version = "0.10.0"
44
description = "Commitment encoding derivation macros"
55
keywords = ["commitments", "proc-macro"]
66
categories = ["development-tools", "encoding"]

commit_verify/derive/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@
2222
// Coding conventions
2323
#![recursion_limit = "256"]
2424

25-
//! Derivation macros for strict encoding. To learn more about the strict
26-
//! encoding please check `strict_encoding` crate.
25+
//! Derivation macros for commit encoding. To learn more about the strict
26+
//! commit please check `commit_verify` crate.
2727
//!
2828
//! # Derivation macros
2929
//!
30-
//! Library exports derivation macros `#[derive(`[`StrictEncode`]`)]`,
31-
//! `#[derive(`[`StrictDecode`]`)]`, which can be added on top of any structure
32-
//! you'd like to support string encoding (see Example section below).
30+
//! Library exports derivation macros `#[derive(`[`CommitEncode`]`)]`,
31+
//! which can be added on top of any structure you'd like to support commitment
32+
//! encoding.
3333
//!
3434
//! Encoding/decoding implemented by both of these macros may be configured at
35-
//! type and individual field level using `#[strict_type(...)]` attributes.
35+
//! type and individual field level using `#[commit_encode(...)]` attributes.
3636
//!
3737
//! # Attribute
3838
//!
39-
//! [`StrictEncode`] and [`StrictDecode`] behavior can be customized with
40-
//! `#[strict_encoding(...)]` attribute, which accepts different arguments
41-
//! depending to which part of the data type it is applied.
39+
//! [`CommitEncode`] behavior can be customized with `#[commit_encoding(...)]`
40+
//! attribute, which accepts different arguments depending to which part of the
41+
//! data type it is applied.
4242
//!
4343
//! ## Attribute arguments at type declaration level
4444
//!
45-
//! Derivation macros accept `#[strict_encoding()]` attribute with the following
45+
//! Derivation macros accept `#[commit_encoding()]` attribute with the following
4646
//! arguments:
4747
4848
#[macro_use]

commit_verify/derive/src/params.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl TryFrom<&Path> for StrategyAttr {
7474
}
7575

7676
impl StrategyAttr {
77-
pub fn to_ident(&self) -> Ident {
77+
pub fn to_ident(self) -> Ident {
7878
match self {
7979
StrategyAttr::CommitEncoding => {
8080
panic!("StrategyAttr::CommitEncoding must be derived manually")

commit_verify/derive/tests/base.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ fn strategy_transparent() -> common::Result {
5353
struct ShortLen(u16);
5454

5555
verify_commit(ShortLen(0), [0, 0]);
56+
#[allow(clippy::mixed_case_hex_literals)]
5657
verify_commit(ShortLen(0xFFde), [0xde, 0xFF]);
5758

5859
Ok(())
@@ -69,6 +70,7 @@ fn strategy_into_u8() -> common::Result {
6970
B,
7071
C,
7172
}
73+
#[allow(clippy::from_over_into)]
7274
impl Into<u8> for Prim {
7375
fn into(self) -> u8 { self as u8 }
7476
}

commit_verify/src/bin/commit-stl.rs

Lines changed: 16 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,67 +12,23 @@
1212
// You should have received a copy of the Apache 2.0 License along with this
1313
// software. If not, see <https://opensource.org/licenses/Apache-2.0>.
1414

15-
#[macro_use]
16-
extern crate amplify;
17-
#[macro_use]
18-
extern crate strict_types;
15+
use commit_verify::stl;
16+
use strict_types::typelib::parse_args;
1917

20-
use std::io::stdout;
21-
use std::{env, fs, io};
22-
23-
use amplify::num::u24;
24-
use commit_verify::{mpc, LIB_NAME_COMMIT_VERIFY};
25-
use strict_encoding::{StrictEncode, StrictWriter};
26-
use strict_types::typelib::LibBuilder;
27-
28-
fn main() -> Result<(), Box<dyn std::error::Error>> {
29-
let args: Vec<String> = env::args().collect();
30-
31-
let lib = LibBuilder::new(libname!(LIB_NAME_COMMIT_VERIFY))
32-
.process::<mpc::MerkleTree>()?
33-
.process::<mpc::MerkleBlock>()?
34-
.process::<mpc::MerkleProof>()?
35-
.compile(none!())?;
36-
let id = lib.id();
37-
38-
let ext = match args.get(1).map(String::as_str) {
39-
Some("--stl") => "stl",
40-
Some("--asc") => "asc.stl",
41-
Some("--sty") => "sty",
42-
_ => "sty",
43-
};
44-
let filename = args
45-
.get(2)
46-
.cloned()
47-
.unwrap_or_else(|| format!("stl/CommitVerify.{ext}"));
48-
let mut file = match args.len() {
49-
1 => Box::new(stdout()) as Box<dyn io::Write>,
50-
2 | 3 => Box::new(fs::File::create(filename)?) as Box<dyn io::Write>,
51-
_ => panic!("invalid argument count"),
52-
};
53-
match ext {
54-
"stl" => {
55-
lib.strict_encode(StrictWriter::with(u24::MAX.into_usize(), file))?;
56-
}
57-
"asc.stl" => {
58-
writeln!(file, "{lib:X}")?;
59-
}
60-
_ => {
61-
writeln!(
62-
file,
63-
"{{-
64-
Id: {id:+}
65-
Name: CommitVerify
66-
Description: Types for client-side-validation commits and verification
18+
fn main() {
19+
let lib = stl::commit_verify_stl();
20+
let (format, dir) = parse_args();
21+
lib.serialize(
22+
format,
23+
dir,
24+
"0.1.0",
25+
Some(
26+
"
27+
Description: Client-side-validation deterministic commitments
6728
Author: Dr Maxim Orlovsky <orlovsky@lnp-bp.org>
6829
Copyright (C) 2023 LNP/BP Standards Association. All rights reserved.
69-
License: Apache-2.0
70-
-}}
71-
"
72-
)?;
73-
writeln!(file, "{lib}")?;
74-
}
75-
}
76-
77-
Ok(())
30+
License: Apache-2.0",
31+
),
32+
)
33+
.expect("unable to write to the file");
7834
}

commit_verify/src/convolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ where
7373
where
7474
Self: VerifyEq,
7575
{
76-
let original = self.restore_original(&commitment);
76+
let original = self.restore_original(commitment);
7777
let suppl = self.extract_supplement();
7878
let (commitment_prime, proof) = original.convolve_commit(suppl, msg)?;
7979
Ok(commitment.verify_eq(&commitment_prime) && self.verify_eq(&proof))

commit_verify/src/embed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ where
155155
{
156156
let mut container_prime = proof.restore_original_container(self)?;
157157
let proof_prime = container_prime.embed_commit(msg)?;
158-
Ok(proof_prime.verify_eq(&proof) && self.verify_eq(&container_prime))
158+
Ok(proof_prime.verify_eq(proof) && self.verify_eq(&container_prime))
159159
}
160160

161161
/// Phantom method used to add `Protocol` generic parameter to the trait.
@@ -264,7 +264,7 @@ pub(crate) mod test_helpers {
264264
acc.iter().for_each(|commitment| {
265265
// Testing that verification against other commitments
266266
// returns `false`
267-
assert!(!SUPPLEMENT.verify(msg, &commitment).unwrap());
267+
assert!(!SUPPLEMENT.verify(msg, commitment).unwrap());
268268
});
269269

270270
// Detecting collision: each message should produce a unique

0 commit comments

Comments
 (0)