Skip to content

Commit 57b09ec

Browse files
authored
Merge branch 'main' into fix/signed-doc-meta-fields
2 parents 0d4fb77 + 3017ece commit 57b09ec

File tree

9 files changed

+73
-98
lines changed

9 files changed

+73
-98
lines changed

rust/cardano-blockchain-types/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cardano-blockchain-types"
33
description = "Common Cardano Blockchain data types for use in both applications and crates"
4-
keywords = ["cardano", "catalyst",]
4+
keywords = ["cardano", "catalyst", ]
55
version = "0.0.1"
66
authors = [
77
"Steven Johnson <[email protected]>"
@@ -20,8 +20,8 @@ workspace = true
2020
[dependencies]
2121
pallas = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
2222
# pallas-hardano = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
23-
cbork-utils = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.11" }
24-
catalyst-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250108-00" }
23+
cbork-utils = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250127-00" }
24+
catalyst-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250127-00" }
2525

2626
ouroboros = "0.18.4"
2727
tracing = "0.1.41"

rust/cardano-blockchain-types/src/metadata/cip36/key_registration.rs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
//! <https://cips.cardano.org/cip/CIP-36>
66
//! <https://github.com/cardano-foundation/CIPs/blob/master/CIP-0036/schema.cddl>
77
8-
use catalyst_types::problem_report::ProblemReport;
8+
use catalyst_types::{
9+
cbor_utils::{report_duplicated_key, report_missing_keys},
10+
problem_report::ProblemReport,
11+
};
912
use cbork_utils::decode_helper::{decode_array_len, decode_bytes, decode_helper, decode_map_len};
1013
use ed25519_dalek::VerifyingKey;
1114
use minicbor::{decode, Decode, Decoder};
@@ -88,7 +91,13 @@ impl Decode<'_, ProblemReport> for Cip36KeyRegistration {
8891
let key: u16 = decode_helper(d, "key in CIP36 Key Registration", err_report)?;
8992

9093
if let Some(key) = Cip36KeyRegistrationKeys::from_repr(key) {
91-
if check_is_key_exist(&found_keys, &key, index, err_report) {
94+
if report_duplicated_key(
95+
&found_keys,
96+
&key,
97+
index,
98+
"CIP36 Key Registration",
99+
err_report,
100+
) {
92101
continue;
93102
}
94103
match key {
@@ -127,37 +136,17 @@ impl Decode<'_, ProblemReport> for Cip36KeyRegistration {
127136
Cip36KeyRegistrationKeys::PaymentAddr,
128137
Cip36KeyRegistrationKeys::Nonce,
129138
];
130-
131-
for key in &required_keys {
132-
if !found_keys.contains(key) {
133-
err_report.missing_field(
134-
&format!("{key:?}"),
135-
"Missing required key in CIP36 Key Registration",
136-
);
137-
}
138-
}
139+
report_missing_keys(
140+
&found_keys,
141+
&required_keys,
142+
"CIP36 Key Registration",
143+
err_report,
144+
);
139145

140146
Ok(cip36_key_registration)
141147
}
142148
}
143149

144-
/// Helper function for checking whether the key is already in the `found_keys` or not.
145-
/// True if exist, false if not.
146-
fn check_is_key_exist(
147-
found_keys: &[Cip36KeyRegistrationKeys], key: &Cip36KeyRegistrationKeys, index: u64,
148-
err_report: &ProblemReport,
149-
) -> bool {
150-
if found_keys.contains(key) {
151-
err_report.duplicate_field(
152-
format!("{key:?}").as_str(),
153-
format!("Redundant key found in item {} in RBAC map", index + 1).as_str(),
154-
format!("CIP36 Key Registration {key:?}").as_str(),
155-
);
156-
return true;
157-
}
158-
false
159-
}
160-
161150
/// Helper function for decoding the voting key.
162151
///
163152
/// # Returns

rust/cardano-blockchain-types/src/metadata/cip36/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,71 +227,85 @@ impl Cip36 {
227227

228228
/// Get the `is_cip36` flag from the registration.
229229
/// True if it is CIP-36 format, false if CIP-15 format.
230+
#[must_use]
230231
pub fn is_cip36(&self) -> Option<bool> {
231232
self.key_registration.is_cip36
232233
}
233234

234235
/// Get the voting public keys from the registration.
236+
#[must_use]
235237
pub fn voting_pks(&self) -> &Vec<VotingPubKey> {
236238
&self.key_registration.voting_pks
237239
}
238240

239241
/// Get the stake public key from the registration.
242+
#[must_use]
240243
pub fn stake_pk(&self) -> Option<&VerifyingKey> {
241244
self.key_registration.stake_pk.as_ref()
242245
}
243246

244247
/// Get the payment address from the registration.
248+
#[must_use]
245249
pub fn payment_address(&self) -> Option<&ShelleyAddress> {
246250
self.key_registration.payment_addr.as_ref()
247251
}
248252

249253
/// Get the nonce from the registration.
254+
#[must_use]
250255
pub fn nonce(&self) -> Option<u64> {
251256
self.key_registration.nonce
252257
}
253258

254259
/// Get the purpose from the registration.
260+
#[must_use]
255261
pub fn purpose(&self) -> u64 {
256262
self.key_registration.purpose
257263
}
258264

259265
/// Get the raw nonce from the registration.
266+
#[must_use]
260267
pub fn raw_nonce(&self) -> Option<u64> {
261268
self.key_registration.raw_nonce
262269
}
263270

264271
/// Is the payment address in the registration payable?
272+
#[must_use]
265273
pub fn is_payable(&self) -> Option<bool> {
266274
self.key_registration.is_payable
267275
}
268276

269277
/// Get the signature from the registration witness.
278+
#[must_use]
270279
pub fn signature(&self) -> Option<ed25519_dalek::Signature> {
271280
self.registration_witness.signature
272281
}
273282

274283
/// Get the slot number of this CIP-36 registration.
284+
#[must_use]
275285
pub fn slot(&self) -> Slot {
276286
self.slot
277287
}
278288

279289
/// Get the network of this CIP-36 registration.
290+
#[must_use]
280291
pub fn network(&self) -> Network {
281292
self.network
282293
}
283294

284295
/// Get the transaction index of this CIP-36 registration.
296+
#[must_use]
285297
pub fn txn_idx(&self) -> TxnIndex {
286298
self.txn_idx
287299
}
288300

289301
/// Get the Catalyst strict flag.
302+
#[must_use]
290303
pub fn is_strict_catalyst(&self) -> bool {
291304
self.is_catalyst_strict
292305
}
293306

294307
/// Is the CIP-36 registration valid?
308+
#[must_use]
295309
pub fn is_valid(&self) -> bool {
296310
// Check everything
297311
self.is_valid_signature
@@ -302,26 +316,31 @@ impl Cip36 {
302316
}
303317

304318
/// Is the signature valid?
319+
#[must_use]
305320
pub fn is_valid_signature(&self) -> bool {
306321
self.is_valid_signature
307322
}
308323

309324
/// Is the payment address network tag match the provided network?
325+
#[must_use]
310326
pub fn is_valid_payment_address_network(&self) -> bool {
311327
self.is_valid_payment_address_network
312328
}
313329

314330
/// Is the voting keys valid?
331+
#[must_use]
315332
pub fn is_valid_voting_keys(&self) -> bool {
316333
self.is_valid_voting_keys
317334
}
318335

319336
/// Is the purpose valid?
337+
#[must_use]
320338
pub fn is_valid_purpose(&self) -> bool {
321339
self.is_valid_purpose
322340
}
323341

324342
/// Get the error report.
343+
#[must_use]
325344
pub fn err_report(&self) -> &ProblemReport {
326345
&self.err_report
327346
}

rust/rbac-registration/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ uuid = "1.11.0"
3232

3333
c509-certificate = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "v0.0.3" }
3434
pallas = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
35-
cbork-utils = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250124-00" }
36-
cardano-blockchain-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250124-00" }
37-
catalyst-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250124-00" }
35+
cbork-utils = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250127-00" }
36+
cardano-blockchain-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250127-00" }
37+
catalyst-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250127-00" }

rust/rbac-registration/src/cardano/cip509/cip509.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{borrow::Cow, collections::HashMap};
77
use anyhow::{anyhow, Context};
88
use cardano_blockchain_types::{MetadatumLabel, MultiEraBlock, TxnIndex};
99
use catalyst_types::{
10+
cbor_utils::{report_duplicated_key, report_missing_keys},
1011
hashes::{Blake2b256Hash, BLAKE_2B256_SIZE},
1112
problem_report::ProblemReport,
1213
uuid::UuidV4,
@@ -28,19 +29,16 @@ use strum_macros::FromRepr;
2829
use tracing::warn;
2930
use uuid::Uuid;
3031

31-
use crate::{
32-
cardano::cip509::{
33-
decode_context::DecodeContext,
34-
rbac::Cip509RbacMetadata,
35-
types::{PaymentHistory, RoleNumber, TxInputHash, ValidationSignature},
36-
utils::Cip0134UriSet,
37-
validation::{
38-
validate_aux, validate_role_data, validate_stake_public_key, validate_txn_inputs_hash,
39-
},
40-
x509_chunks::X509Chunks,
41-
Payment, PointTxnIdx, RoleData,
32+
use crate::cardano::cip509::{
33+
decode_context::DecodeContext,
34+
rbac::Cip509RbacMetadata,
35+
types::{PaymentHistory, RoleNumber, TxInputHash, ValidationSignature},
36+
utils::Cip0134UriSet,
37+
validation::{
38+
validate_aux, validate_role_data, validate_stake_public_key, validate_txn_inputs_hash,
4239
},
43-
utils::decode_helper::{report_duplicated_key, report_missing_keys},
40+
x509_chunks::X509Chunks,
41+
Payment, PointTxnIdx, RoleData,
4442
};
4543

4644
/// A x509 metadata envelope.
@@ -294,7 +292,8 @@ impl Decode<'_, DecodeContext<'_, '_>> for Cip509 {
294292
// Consume the key. This should never fail because we used `probe` above.
295293
let _: u8 = decode_helper(d, context, &mut ())?;
296294

297-
if report_duplicated_key(&found_keys, &key, index, context, decode_context.report) {
295+
if report_duplicated_key(&found_keys, &key, index, "Cip509", decode_context.report)
296+
{
298297
continue;
299298
}
300299
found_keys.push(key);

rust/rbac-registration/src/cardano/cip509/rbac/metadata.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22
33
use std::collections::{HashMap, HashSet};
44

5-
use catalyst_types::problem_report::ProblemReport;
5+
use catalyst_types::{cbor_utils::report_duplicated_key, problem_report::ProblemReport};
66
use cbork_utils::decode_helper::{
77
decode_any, decode_array_len, decode_bytes, decode_helper, decode_map_len,
88
};
99
use minicbor::{decode, Decode, Decoder};
1010
use strum_macros::FromRepr;
1111

12-
use crate::{
13-
cardano::cip509::{
14-
decode_context::DecodeContext,
15-
rbac::{role_data::CborRoleData, C509Cert, SimplePublicKeyType, X509DerCert},
16-
utils::Cip0134UriSet,
17-
CertKeyHash, RoleData, RoleNumber,
18-
},
19-
utils::decode_helper::report_duplicated_key,
12+
use crate::cardano::cip509::{
13+
decode_context::DecodeContext,
14+
rbac::{role_data::CborRoleData, C509Cert, SimplePublicKeyType, X509DerCert},
15+
utils::Cip0134UriSet,
16+
CertKeyHash, RoleData, RoleNumber,
2017
};
2118

2219
/// Cip509 RBAC metadata.
@@ -94,7 +91,13 @@ impl Decode<'_, DecodeContext<'_, '_>> for Cip509RbacMetadata {
9491
for index in 0..map_len {
9592
let key: u16 = decode_helper(d, "key in Cip509RbacMetadata", &mut ())?;
9693
if let Some(key) = Cip509RbacMetadataInt::from_repr(key) {
97-
if report_duplicated_key(&found_keys, &key, index, context, decode_context.report) {
94+
if report_duplicated_key(
95+
&found_keys,
96+
&key,
97+
index,
98+
"Cip509RbacMetadata",
99+
decode_context.report,
100+
) {
98101
continue;
99102
}
100103
found_keys.push(key);

rust/rbac-registration/src/cardano/cip509/rbac/role_data.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
33
use std::collections::HashMap;
44

5-
use catalyst_types::problem_report::ProblemReport;
5+
use catalyst_types::{
6+
cbor_utils::{report_duplicated_key, report_missing_keys},
7+
problem_report::ProblemReport,
8+
};
69
use cbork_utils::decode_helper::{decode_any, decode_array_len, decode_helper, decode_map_len};
710
use minicbor::{decode, Decode, Decoder};
811
use strum_macros::FromRepr;
912

10-
use crate::{
11-
cardano::cip509::{KeyLocalRef, RoleNumber},
12-
utils::decode_helper::{report_duplicated_key, report_missing_keys},
13-
};
13+
use crate::cardano::cip509::{KeyLocalRef, RoleNumber};
1414

1515
/// Role data as encoded in CBOR.
1616
#[allow(clippy::module_name_repetitions)]
@@ -61,7 +61,7 @@ impl Decode<'_, ProblemReport> for CborRoleData {
6161
for index in 0..map_len {
6262
let key: u8 = decode_helper(d, "key in RoleData", &mut ())?;
6363
if let Some(key) = RoleDataInt::from_repr(key) {
64-
if report_duplicated_key(&found_keys, &key, index, context, report) {
64+
if report_duplicated_key(&found_keys, &key, index, "RoleData", report) {
6565
continue;
6666
}
6767
found_keys.push(key);

rust/rbac-registration/src/utils/decode_helper.rs

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//! Utility functions for the RBAC registration module.
22
3-
pub mod decode_helper;
4-
53
#[cfg(test)]
64
pub mod test;

0 commit comments

Comments
 (0)