Skip to content

Commit bac3d7f

Browse files
committed
fix: remove uuidv4 and ed25519pubkey type
Signed-off-by: bkioshn <[email protected]>
1 parent f80bc08 commit bac3d7f

File tree

8 files changed

+23
-107
lines changed

8 files changed

+23
-107
lines changed

.config/dictionaries/project.dic

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ ureq
257257
userid
258258
utimensat
259259
UTXO
260-
uuidv
261260
vitss
262261
Vkey
263262
vkeywitness

rust/rbac-registration/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ bech32 = "0.11.0"
3131
dashmap = "6.1.0"
3232
blake2b_simd = "1.0.2"
3333
tracing = "0.1.40"
34+
ed25519-dalek = "2.1.1"
35+
uuid = "1.11.0"
3436

3537
c509-certificate = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git" , tag = "v0.0.3" }
3638
pallas = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use minicbor::{
1616
};
1717
use pallas::{crypto::hash::Hash, ledger::traverse::MultiEraTx};
1818
use strum_macros::FromRepr;
19-
use types::{tx_input_hash::TxInputHash, uuidv4::UuidV4};
19+
use types::tx_input_hash::TxInputHash;
20+
use uuid::Uuid;
2021
use validation::{
2122
validate_aux, validate_payment_key, validate_role_singing_key, validate_stake_public_key,
2223
validate_txn_inputs_hash,
@@ -37,7 +38,7 @@ pub const LABEL: u64 = 509;
3738
#[derive(Debug, PartialEq, Clone, Default)]
3839
pub struct Cip509 {
3940
/// `UUIDv4` Purpose .
40-
pub purpose: UuidV4, // (bytes .size 16)
41+
pub purpose: Uuid, // (bytes .size 16)
4142
/// Transaction inputs hash.
4243
pub txn_inputs_hash: TxInputHash, // bytes .size 16
4344
/// Optional previous transaction ID.
@@ -101,7 +102,7 @@ impl Decode<'_, ()> for Cip509 {
101102
match key {
102103
Cip509IntIdentifier::Purpose => {
103104
cip509_metadatum.purpose =
104-
UuidV4::try_from(decode_bytes(d, "CIP509 purpose")?).map_err(|_| {
105+
Uuid::try_from(decode_bytes(d, "CIP509 purpose")?).map_err(|_| {
105106
decode::Error::message("Invalid data size of Purpose")
106107
})?;
107108
},

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
//! Public key type for RBAC metadata
22
3+
use ed25519_dalek::VerifyingKey;
34
use minicbor::{decode, Decode, Decoder};
45

56
use super::tag::KeyTag;
6-
use crate::{
7-
cardano::cip509::types::ed25519_pubkey::Ed25519PublicKey,
8-
utils::decode_helper::{decode_bytes, decode_tag},
9-
};
7+
use crate::utils::decode_helper::{decode_bytes, decode_tag};
108

119
/// Enum of possible public key type.
1210
#[derive(Debug, PartialEq, Clone, Default)]
@@ -17,7 +15,7 @@ pub enum SimplePublicKeyType {
1715
/// Deleted indicates the key is deleted.
1816
Deleted,
1917
/// Ed25519 public key.
20-
Ed25519(Ed25519PublicKey),
18+
Ed25519(VerifyingKey),
2119
}
2220

2321
impl Decode<'_, ()> for SimplePublicKeyType {
@@ -32,7 +30,10 @@ impl Decode<'_, ()> for SimplePublicKeyType {
3230
let mut ed25519 = [0u8; 32];
3331
if bytes.len() == 32 {
3432
ed25519.copy_from_slice(&bytes);
35-
Ok(Self::Ed25519(ed25519.into()))
33+
let pubkey = VerifyingKey::from_bytes(&ed25519).map_err(|e| {
34+
decode::Error::message(format!("Failed to convert Ed25519 public key in SimplePublicKeyType {e}"))
35+
})?;
36+
Ok(Self::Ed25519(pubkey))
3637
} else {
3738
Err(decode::Error::message(format!(
3839
"Invalid length for Ed25519 key, got {}",

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

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//! Types use in CIP-509
22
33
pub mod cert_key_hash;
4-
pub mod ed25519_pubkey;
54
pub mod tx_input_hash;
6-
pub mod uuidv4;

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

Lines changed: 0 additions & 37 deletions
This file was deleted.

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::{collections::HashMap, sync::Arc};
88

99
use anyhow::bail;
1010
use c509_certificate::c509::C509;
11+
use ed25519_dalek::VerifyingKey;
1112
use pallas::{
1213
crypto::hash::Hash,
1314
ledger::{
@@ -20,6 +21,7 @@ use payment_history::PaymentHistory;
2021
use point_tx_idx::PointTxIdx;
2122
use role_data::RoleData;
2223
use tracing::error;
24+
use uuid::Uuid;
2325

2426
use crate::{
2527
cardano::cip509::{
@@ -28,7 +30,7 @@ use crate::{
2830
certs::{C509Cert, X509DerCert},
2931
pub_key::SimplePublicKeyType,
3032
},
31-
types::{cert_key_hash::CertKeyHash, ed25519_pubkey::Ed25519PublicKey, uuidv4::UuidV4},
33+
types::cert_key_hash::CertKeyHash,
3234
Cip509, Cip509Validation,
3335
},
3436
utils::general::decremented_index,
@@ -94,7 +96,7 @@ impl RegistrationChain {
9496

9597
/// Get a list of purpose for this registration chain.
9698
#[must_use]
97-
pub fn purpose(&self) -> &[UuidV4] {
99+
pub fn purpose(&self) -> &[Uuid] {
98100
&self.inner.purpose
99101
}
100102

@@ -112,7 +114,7 @@ impl RegistrationChain {
112114

113115
/// Get the map of index in array to point, transaction index, and public key.
114116
#[must_use]
115-
pub fn simple_keys(&self) -> &HashMap<usize, (PointTxIdx, Ed25519PublicKey)> {
117+
pub fn simple_keys(&self) -> &HashMap<usize, (PointTxIdx, VerifyingKey)> {
116118
&self.inner.simple_keys
117119
}
118120

@@ -141,15 +143,15 @@ struct RegistrationChainInner {
141143
/// The current transaction ID hash (32 bytes)
142144
current_tx_id_hash: Hash<32>,
143145
/// List of purpose for this registration chain
144-
purpose: Vec<UuidV4>,
146+
purpose: Vec<Uuid>,
145147

146148
// RBAC
147149
/// Map of index in array to point, transaction index, and x509 certificate.
148150
x509_certs: HashMap<usize, (PointTxIdx, Vec<u8>)>,
149151
/// Map of index in array to point, transaction index, and c509 certificate.
150152
c509_certs: HashMap<usize, (PointTxIdx, C509)>,
151153
/// Map of index in array to point, transaction index, and public key.
152-
simple_keys: HashMap<usize, (PointTxIdx, Ed25519PublicKey)>,
154+
simple_keys: HashMap<usize, (PointTxIdx, VerifyingKey)>,
153155
/// List of point, transaction index, and certificate key hash.
154156
revocations: Vec<(PointTxIdx, CertKeyHash)>,
155157

@@ -389,13 +391,13 @@ fn update_c509_certs(
389391
/// Process public keys for chain root.
390392
fn chain_root_public_keys(
391393
pub_keys: Option<Vec<SimplePublicKeyType>>, point_tx_idx: &PointTxIdx,
392-
) -> HashMap<usize, (PointTxIdx, Ed25519PublicKey)> {
394+
) -> HashMap<usize, (PointTxIdx, VerifyingKey)> {
393395
let mut map = HashMap::new();
394396
if let Some(key_list) = pub_keys {
395397
for (idx, key) in key_list.iter().enumerate() {
396398
// Chain root, expect only the public key not undefined or delete
397399
if let cip509::rbac::pub_key::SimplePublicKeyType::Ed25519(key) = key {
398-
map.insert(idx, (point_tx_idx.clone(), key.clone()));
400+
map.insert(idx, (point_tx_idx.clone(), *key));
399401
}
400402
}
401403
}
@@ -420,7 +422,7 @@ fn update_public_keys(
420422
cip509::rbac::pub_key::SimplePublicKeyType::Ed25519(key) => {
421423
new_inner
422424
.simple_keys
423-
.insert(idx, (point_tx_idx.clone(), key.clone()));
425+
.insert(idx, (point_tx_idx.clone(), *key));
424426
},
425427
}
426428
}

0 commit comments

Comments
 (0)