Skip to content

Commit 9bb741c

Browse files
authored
wip (#3601)
1 parent f4298a2 commit 9bb741c

File tree

4 files changed

+43
-40
lines changed

4 files changed

+43
-40
lines changed

catalyst-gateway/bin/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ repository.workspace = true
1515
workspace = true
1616

1717
[dependencies]
18-
cardano-chain-follower = { version = "0.0.16", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-chain-follower/v0.0.16" }
19-
rbac-registration = { version = "0.0.12", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "rbac-registration/v0.0.12" }
20-
catalyst-signed-doc = { version = "0.0.8", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-signed-doc/v0.0.8" }
18+
cardano-chain-follower = { version = "0.0.17", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-chain-follower/v0.0.17" }
19+
rbac-registration = { version = "0.0.13", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "rbac-registration/v0.0.13" }
20+
catalyst-signed-doc = { version = "0.0.9", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-signed-doc/v0.0.9" }
2121
catalyst-signed-doc-v1 = { package = "catalyst-signed-doc", version = "0.0.4", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-signed-doc/v.0.0.4" }
2222
c509-certificate = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "c509-certificate-v0.0.3" }
23-
catalyst-types = { version = "0.0.8", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types/v0.0.8" }
23+
catalyst-types = { version = "0.0.9", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types/v0.0.9" }
2424

2525
clap = { version = "4.5.20", features = ["derive", "env"] }
2626
tracing = { version = "0.1.40", features = ["log"] }

catalyst-gateway/bin/src/rbac/get_chain.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@ use crate::{
2323
/// Returns the latest (including the volatile part) registration chain by the given
2424
/// Catalyst ID.
2525
pub async fn latest_rbac_chain(id: &CatalystId) -> Result<Option<ChainInfo>> {
26-
let id = id.as_short_id();
27-
2826
let volatile_session =
2927
CassandraSession::get(false).context("Failed to get volatile Cassandra session")?;
3028
// Get the persistent part of the chain and volatile registrations. Both of these parts
3129
// can be non-existing.
3230
let (chain, volatile_regs) = try_join(
33-
persistent_rbac_chain(&id),
34-
indexed_regs(&volatile_session, &id),
31+
persistent_rbac_chain(id),
32+
indexed_regs(&volatile_session, id),
3533
)
3634
.await?;
3735

@@ -70,14 +68,11 @@ pub async fn latest_rbac_chain(id: &CatalystId) -> Result<Option<ChainInfo>> {
7068
/// Returns only the persistent part of a registration chain by the given Catalyst ID.
7169
pub async fn persistent_rbac_chain(id: &CatalystId) -> Result<Option<RegistrationChain>> {
7270
let session = CassandraSession::get(true).context("Failed to get Cassandra session")?;
73-
74-
let id = id.as_short_id();
75-
76-
if let Some(chain) = cached_persistent_rbac_chain(&session, &id) {
71+
if let Some(chain) = cached_persistent_rbac_chain(&session, id) {
7772
return Ok(Some(chain));
7873
}
7974

80-
let regs = indexed_regs(&session, &id).await?;
75+
let regs = indexed_regs(&session, id).await?;
8176
let chain = build_rbac_chain(regs).await?.inspect(|c| {
8277
cache_persistent_rbac_chain(id.clone(), c.clone());
8378
});

catalyst-gateway/bin/src/service/api/documents/common/mod.rs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! A module for placing common structs, functions, and variables across the `document`
22
//! endpoint module not specified to a specific endpoint.
33
4-
use std::collections::HashMap;
5-
64
use catalyst_signed_doc::CatalystSignedDocument;
75

86
use crate::{
@@ -157,16 +155,23 @@ impl catalyst_signed_doc_v1::providers::CatalystSignedDocumentProvider for DocPr
157155
// TODO: make the struct to support multi sigs validation
158156
/// A struct which implements a
159157
/// `catalyst_signed_doc::providers::CatalystSignedDocumentProvider` trait
160-
pub(crate) struct VerifyingKeyProvider(
161-
HashMap<catalyst_signed_doc::CatalystId, ed25519_dalek::VerifyingKey>,
162-
);
158+
pub(crate) struct VerifyingKeyProvider {
159+
/// A user's `CatalystId` from the corresponding `CatalystRBACTokenV1`
160+
kid: catalyst_signed_doc::CatalystId,
161+
/// A corresponding `VerifyingKey` derived from the `CatalystRBACTokenV1`
162+
pk: ed25519_dalek::VerifyingKey,
163+
}
163164

164165
impl catalyst_signed_doc::providers::CatalystIdProvider for VerifyingKeyProvider {
165166
async fn try_get_registered_key(
166167
&self,
167168
kid: &catalyst_signed_doc::CatalystId,
168169
) -> anyhow::Result<Option<ed25519_dalek::VerifyingKey>> {
169-
Ok(self.0.get(kid).copied())
170+
if &self.kid == kid {
171+
Ok(Some(self.pk))
172+
} else {
173+
Ok(None)
174+
}
170175
}
171176
}
172177

@@ -203,39 +208,38 @@ impl VerifyingKeyProvider {
203208
anyhow::bail!("Multi-signature document is currently unsupported");
204209
}
205210

206-
if kids
207-
.iter()
208-
.any(|kid| kid.as_short_id() != token.catalyst_id().as_short_id())
209-
{
211+
let [kid] = kids else {
212+
anyhow::bail!("Multi-signature document is currently unsupported");
213+
};
214+
215+
if kid != token.catalyst_id() {
210216
anyhow::bail!("RBAC Token CatID does not match with the document KIDs");
211217
}
212218

213219
let Some(reg_chain) = token.reg_chain().await? else {
214220
anyhow::bail!("Failed to retrieve a registration from corresponding Catalyst ID");
215221
};
216222

217-
let result = kids.iter().map(|kid| {
218-
if !kid.is_signature_key() {
219-
anyhow::bail!("Invalid KID {kid}: KID must be a signing key not an encryption key");
220-
}
223+
if !kid.is_signature_key() {
224+
anyhow::bail!("Invalid KID {kid}: KID must be a signing key not an encryption key");
225+
}
221226

222-
let (kid_role_index, kid_rotation) = kid.role_and_rotation();
223-
let (latest_pk, rotation) = reg_chain
224-
.get_latest_signing_pk_for_role(&kid_role_index)
225-
.ok_or_else(|| {
227+
let (kid_role_index, kid_rotation) = kid.role_and_rotation();
228+
let (latest_pk, rotation) = reg_chain
229+
.get_latest_signing_pk_for_role(&kid_role_index)
230+
.ok_or_else(|| {
226231
anyhow::anyhow!(
227232
"Failed to get last signing key for the proposer role for {kid} Catalyst ID"
228233
)
229234
})?;
230235

231-
if rotation != kid_rotation {
232-
anyhow::bail!("Invalid KID {kid}: KID's rotation ({kid_rotation}) is not the latest rotation ({rotation})");
233-
}
236+
if rotation != kid_rotation {
237+
anyhow::bail!("Invalid KID {kid}: KID's rotation ({kid_rotation}) is not the latest rotation ({rotation})");
238+
}
234239

235-
Ok((kid.clone(), latest_pk))
240+
Ok(Self {
241+
kid: kid.clone(),
242+
pk: latest_pk,
236243
})
237-
.collect::<Result<_, _>>()?;
238-
239-
Ok(Self(result))
240244
}
241245
}

catalyst-gateway/bin/src/service/api/documents/put_document/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub(crate) async fn endpoint(
7676

7777
// validate document signatures
7878
let verifying_key_provider =
79-
match VerifyingKeyProvider::try_from_kids(&mut token, &doc.kids()).await {
79+
match VerifyingKeyProvider::try_from_kids(&mut token, &doc.authors()).await {
8080
Ok(value) => value,
8181
Err(err) if err.is::<CassandraSessionError>() => {
8282
return AllResponses::service_unavailable(&err, RetryAfterOption::Default)
@@ -194,7 +194,11 @@ async fn store_document_in_db(
194194
doc: &catalyst_signed_doc::CatalystSignedDocument,
195195
doc_bytes: Vec<u8>,
196196
) -> anyhow::Result<bool> {
197-
let authors = doc.authors().iter().map(ToString::to_string).collect();
197+
let authors = doc
198+
.authors()
199+
.iter()
200+
.map(|v| v.as_short_id().to_string())
201+
.collect();
198202

199203
let doc_meta_json = doc.doc_meta().to_json()?;
200204

0 commit comments

Comments
 (0)