Skip to content

Commit 3220b6e

Browse files
authored
Merge branch 'main' into fix/cardano-bc-types-base-change
2 parents 1b2b089 + 38d0eb7 commit 3220b6e

File tree

20 files changed

+1501
-6
lines changed

20 files changed

+1501
-6
lines changed

.config/dictionaries/project.dic

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ dbsync
5858
dcbor
5959
decompressor
6060
delegators
61+
displaydoc
6162
dleq
6263
dlog
6364
dockerhub
@@ -254,6 +255,7 @@ Traceback
254255
txmonitor
255256
txns
256257
typenum
258+
uncategorized
257259
unfinalized
258260
unixfs
259261
unlinkat

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ permissions:
1313

1414
jobs:
1515
ci:
16-
uses: input-output-hk/catalyst-forge/.github/workflows/ci.yml@ci/v1.5.0
16+
uses: input-output-hk/catalyst-forge/.github/workflows/ci.yml@ci/v1.5.1
1717
with:
1818
forge_version: 0.8.0
1919

.github/workflows/generate-allure-report.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ jobs:
2626
- uses: actions/checkout@v4
2727

2828
- name: Install Forge
29-
uses: input-output-hk/catalyst-forge/actions/install@ci/v1.5.0
29+
uses: input-output-hk/catalyst-forge/actions/install@ci/v1.5.1
3030
with:
3131
version: 0.8.0
3232
if: always()
3333

3434
- name: Setup CI
35-
uses: input-output-hk/catalyst-forge/actions/setup@ci/v1.5.0
35+
uses: input-output-hk/catalyst-forge/actions/setup@ci/v1.5.1
3636

3737
- name: Get catalyst libs unit test report
38-
uses: input-output-hk/catalyst-forge/actions/run@ci/v1.5.0
38+
uses: input-output-hk/catalyst-forge/actions/run@ci/v1.5.1
3939
if: always()
4040
continue-on-error: true
4141
with:

.github/workflows/semantic_pull_request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
rust
1919
rust/c509-certificate
2020
rust/cardano-chain-follower
21+
rust/catalyst-types
2122
rust/catalyst-voting
2223
rust/immutable-ledger
2324
rust/vote-tx-v1

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ members = [
1010
"cbork-cddl-parser",
1111
"cbork-utils",
1212
"catalyst-voting",
13-
"catalyst-voting",
13+
"catalyst-types",
1414
"immutable-ledger",
1515
"vote-tx-v1",
1616
"vote-tx-v2",

rust/Earthfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ COPY_SRC:
99
Cargo.toml clippy.toml deny.toml rustfmt.toml \
1010
.cargo .config \
1111
c509-certificate \
12+
catalyst-types \
1213
cardano-blockchain-types \
1314
cardano-chain-follower \
1415
catalyst-voting vote-tx-v1 vote-tx-v2 \
@@ -55,7 +56,7 @@ build:
5556
DO rust-ci+EXECUTE \
5657
--cmd="/scripts/std_build.py" \
5758
--args1="--libs=c509-certificate --libs=cardano-blockchain-types --libs=cardano-chain-follower --libs=hermes-ipfs" \
58-
--args2="--libs=cbork-cddl-parser --libs=cbork-abnf-parser --libs=cbork-utils" \
59+
--args2="--libs=cbork-cddl-parser --libs=cbork-abnf-parser --libs=cbork-utils --libs=catalyst-types" \
5960
--args3="--libs=catalyst-voting --libs=immutable-ledger --libs=vote-tx-v1 --libs=vote-tx-v2" \
6061
--args4="--bins=cbork/cbork --libs=rbac-registration --libs=signed_doc" \
6162
--args5="--cov_report=$HOME/build/coverage-report.info" \

rust/catalyst-types/Cargo.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[package]
2+
name = "catalyst-types"
3+
version = "0.0.1"
4+
edition.workspace = true
5+
license.workspace = true
6+
authors.workspace = true
7+
homepage.workspace = true
8+
repository.workspace = true
9+
10+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
11+
12+
[lints]
13+
workspace = true
14+
15+
[lib]
16+
name = "catalyst_types"
17+
18+
[dependencies]
19+
blake2b_simd = "1.0.2"
20+
coset = "0.3.8"
21+
displaydoc = "0.2.5"
22+
ed25519-dalek = "2.1.1"
23+
fluent-uri = "0.3.2"
24+
hex = "0.4.3"
25+
minicbor = { version = "0.25.1", features = ["std"] }
26+
num-traits = "0.2.19"
27+
orx-concurrent-vec = "3.1.0"
28+
pallas-crypto = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
29+
serde = { version = "1.0.217", features = ["derive"] }
30+
thiserror = "2.0.9"
31+
base64-url = "3.0.0"
32+
uuid = { version = "1.11.0", features = ["v4", "v7", "serde"] }
33+
34+
[dev-dependencies]
35+
ed25519-dalek = { version = "2.1.1", features = ["rand_core"] }
36+
rand = "0.8.5"

rust/catalyst-types/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Catalyst Types
2+
3+
This library is designed to streamline the organization and sharing of types across multiple crates.
4+
It provides a centralized location for reusable, enhanced types that are not specific to a particular domain, such as Cardano.
5+
6+
## Purpose
7+
8+
* To enhance types that can be utilized across different libraries or projects.
9+
* To provide utility functions related to types and conversion between types.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//! Conversion functions
2+
3+
use displaydoc::Display;
4+
use thiserror::Error;
5+
6+
/// Errors that can occur when converting bytes to an Ed25519 verifying key.
7+
#[derive(Display, Debug, Error)]
8+
pub enum VKeyFromBytesError {
9+
/// Invalid byte length: expected {expected} bytes, got {actual}
10+
InvalidLength {
11+
/// The expected number of bytes (must be 32).
12+
expected: usize,
13+
/// The actual number of bytes in the provided input.
14+
actual: usize,
15+
},
16+
/// Failed to parse Ed25519 public key: {source}
17+
ParseError {
18+
/// The underlying error from `ed25519_dalek`.
19+
#[from]
20+
source: ed25519_dalek::SignatureError,
21+
},
22+
}
23+
24+
/// Convert an `<T>` to `<R>` (saturate if out of range).
25+
/// Note can convert any int to float, or f32 to f64 as well.
26+
/// can not convert from float to int, or f64 to f32.
27+
pub fn from_saturating<
28+
R: Copy + num_traits::identities::Zero + num_traits::Bounded,
29+
T: Copy
30+
+ TryInto<R>
31+
+ std::ops::Sub<Output = T>
32+
+ std::cmp::PartialOrd<T>
33+
+ num_traits::identities::Zero,
34+
>(
35+
value: T,
36+
) -> R {
37+
match value.try_into() {
38+
Ok(value) => value,
39+
Err(_) => {
40+
// If we couldn't convert, its out of range for the destination type.
41+
if value > T::zero() {
42+
// If the number is positive, its out of range in the positive direction.
43+
R::max_value()
44+
} else {
45+
// Otherwise its out of range in the negative direction.
46+
R::min_value()
47+
}
48+
},
49+
}
50+
}
51+
52+
/// Try and convert a byte array into an Ed25519 verifying key.
53+
///
54+
/// # Errors
55+
///
56+
/// Fails if the bytes are not a valid ED25519 Public Key
57+
pub fn vkey_from_bytes(bytes: &[u8]) -> Result<ed25519_dalek::VerifyingKey, VKeyFromBytesError> {
58+
if bytes.len() != ed25519_dalek::PUBLIC_KEY_LENGTH {
59+
return Err(VKeyFromBytesError::InvalidLength {
60+
expected: ed25519_dalek::PUBLIC_KEY_LENGTH,
61+
actual: bytes.len(),
62+
});
63+
}
64+
65+
let mut ed25519 = [0u8; ed25519_dalek::PUBLIC_KEY_LENGTH];
66+
ed25519.copy_from_slice(bytes); // Can't panic because we already validated its size.
67+
68+
ed25519_dalek::VerifyingKey::from_bytes(&ed25519)
69+
.map_err(|source| VKeyFromBytesError::ParseError { source })
70+
}

0 commit comments

Comments
 (0)