Skip to content

Commit 674cddc

Browse files
authored
feat(cat-gateway): Bumping to the latest cat-libs (#3544)
* wip * wip * fix * add `admin_keys` catalyst signed docs settings * wip * wip * wip * wip * fix * fix lint * fix
1 parent 0567f56 commit 674cddc

File tree

9 files changed

+154
-21
lines changed

9 files changed

+154
-21
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.14", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-chain-follower/v0.0.14" }
19-
rbac-registration = { version = "0.0.10", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "rbac-registration/v0.0.10" }
20-
catalyst-signed-doc = { version = "0.0.7", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-signed-doc/v0.0.7" }
18+
cardano-chain-follower = { version = "0.0.15", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-chain-follower/v0.0.15" }
19+
rbac-registration = { version = "0.0.11", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "rbac-registration/v0.0.11" }
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" }
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.7", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types/v0.0.7" }
23+
catalyst-types = { version = "0.0.8", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-types/v0.0.8" }
2424

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

catalyst-gateway/bin/src/db/event/signed_docs/tests/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ async fn filter_by_type(
189189
}
190190
}
191191

192-
/// Pre-seeded Fund 14 documents `V3__signed_documents.sql` and
193-
/// `old_format_signed_doc.sql`
194-
const PRE_SEED_DATA: usize = 43;
192+
/// Pre-seeded documents `V3__signed_documents.sql`, `old_format_signed_doc.sql` and
193+
/// `test_signed_documents.sql`
194+
const PRE_SEED_DATA: usize = 45;
195195

196196
async fn filter_all(docs: &[FullSignedDoc]) {
197197
let filter = DocsQueryFilter::all();

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ impl catalyst_signed_doc::providers::CatalystSignedDocumentProvider for Validati
4949
self.doc_provider.try_get_last_doc(id).await
5050
}
5151

52+
async fn try_get_first_doc(
53+
&self,
54+
id: catalyst_signed_doc::UuidV7,
55+
) -> anyhow::Result<Option<CatalystSignedDocument>> {
56+
self.doc_provider.try_get_first_doc(id).await
57+
}
58+
5259
fn future_threshold(&self) -> Option<std::time::Duration> {
5360
self.doc_provider.future_threshold()
5461
}
@@ -58,12 +65,14 @@ impl catalyst_signed_doc::providers::CatalystSignedDocumentProvider for Validati
5865
}
5966
}
6067

61-
impl catalyst_signed_doc::providers::VerifyingKeyProvider for ValidationProvider {
62-
async fn try_get_key(
68+
impl catalyst_signed_doc::providers::CatalystIdProvider for ValidationProvider {
69+
async fn try_get_registered_key(
6370
&self,
6471
kid: &catalyst_signed_doc::CatalystId,
6572
) -> anyhow::Result<Option<ed25519_dalek::VerifyingKey>> {
66-
self.verifying_key_provider.try_get_key(kid).await
73+
self.verifying_key_provider
74+
.try_get_registered_key(kid)
75+
.await
6776
}
6877
}
6978

@@ -96,6 +105,17 @@ impl catalyst_signed_doc::providers::CatalystSignedDocumentProvider for DocProvi
96105
}
97106
}
98107

108+
async fn try_get_first_doc(
109+
&self,
110+
id: catalyst_signed_doc::UuidV7,
111+
) -> anyhow::Result<Option<CatalystSignedDocument>> {
112+
match FullSignedDoc::retrieve(&id.uuid(), Some(&id.uuid())).await {
113+
Ok(doc) => Ok(Some(doc.raw().try_into()?)),
114+
Err(err) if err.is::<NotFoundError>() => Ok(None),
115+
Err(err) => Err(err),
116+
}
117+
}
118+
99119
fn future_threshold(&self) -> Option<std::time::Duration> {
100120
let signed_doc_cfg = Settings::signed_doc_cfg();
101121
Some(signed_doc_cfg.future_threshold())
@@ -141,8 +161,8 @@ pub(crate) struct VerifyingKeyProvider(
141161
HashMap<catalyst_signed_doc::CatalystId, ed25519_dalek::VerifyingKey>,
142162
);
143163

144-
impl catalyst_signed_doc::providers::VerifyingKeyProvider for VerifyingKeyProvider {
145-
async fn try_get_key(
164+
impl catalyst_signed_doc::providers::CatalystIdProvider for VerifyingKeyProvider {
165+
async fn try_get_registered_key(
146166
&self,
147167
kid: &catalyst_signed_doc::CatalystId,
148168
) -> anyhow::Result<Option<ed25519_dalek::VerifyingKey>> {

catalyst-gateway/bin/src/settings/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static ENV_VARS: LazyLock<EnvVars> = LazyLock::new(|| {
200200
service_id: StringEnvVar::new("SERVICE_ID", calculate_service_uuid().into()),
201201
client_id_key: StringEnvVar::new("CLIENT_ID_KEY", CLIENT_ID_KEY_DEFAULT.into()),
202202
api_host_names: string_to_api_host_names(
203-
&StringEnvVar::new_optional("c", false)
203+
&StringEnvVar::new_optional("API_HOST_NAMES", false)
204204
.map(|v| v.as_string())
205205
.unwrap_or_default(),
206206
),

catalyst-gateway/bin/src/settings/signed_doc.rs

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//! Command line and environment variable settings for the Catalyst Signed Docs
22
3-
use std::time::Duration;
3+
use std::{collections::HashMap, str::FromStr, time::Duration};
4+
5+
use hex::FromHex;
6+
use itertools::Itertools;
47

58
use super::str_env_var::StringEnvVar;
69

@@ -18,6 +21,11 @@ pub(crate) struct EnvVars {
1821

1922
/// The Catalyst Signed Document threshold, document cannot be too far behind.
2023
past_threshold: Duration,
24+
25+
/// The Catalyst Signed Document Admin keys map from the `SIGNED_DOC_ADMIN_KEYS` env
26+
/// var. Each Admin key entry is a pair of `CatalystId` string and hex encoded
27+
/// `VerifyingKey` separated by ';' character.
28+
admin_keys: HashMap<catalyst_signed_doc::CatalystId, ed25519_dalek::VerifyingKey>,
2129
}
2230

2331
impl EnvVars {
@@ -29,9 +37,16 @@ impl EnvVars {
2937
let past_threshold =
3038
StringEnvVar::new_as_duration("SIGNED_DOC_PAST_THRESHOLD", DEFAULT_PAST_THRESHOLD);
3139

40+
let admin_keys = string_to_admin_keys(
41+
&StringEnvVar::new_optional("SIGNED_DOC_ADMIN_KEYS", false)
42+
.map(|v| v.as_string())
43+
.unwrap_or_default(),
44+
);
45+
3246
Self {
3347
future_threshold,
3448
past_threshold,
49+
admin_keys,
3550
}
3651
}
3752

@@ -46,4 +61,59 @@ impl EnvVars {
4661
pub(crate) fn past_threshold(&self) -> Duration {
4762
self.past_threshold
4863
}
64+
65+
/// The Catalyst Signed Document Admin keys map.
66+
#[allow(dead_code)]
67+
pub(crate) fn admin_keys(
68+
&self
69+
) -> &HashMap<catalyst_signed_doc::CatalystId, ed25519_dalek::VerifyingKey> {
70+
&self.admin_keys
71+
}
72+
}
73+
74+
/// Transform a string list of admin keys into a map.
75+
/// Each Admin key entry is a pair of `CatalystId` string and hex encoded
76+
/// `VerifyingKey` separated by ';' character.
77+
fn string_to_admin_keys(
78+
admin_keys: &str
79+
) -> HashMap<catalyst_signed_doc::CatalystId, ed25519_dalek::VerifyingKey> {
80+
admin_keys
81+
.split(',')
82+
// filters out at the beginning all empty entries, because they all would be invalid and
83+
// filtered out anyway
84+
.filter(|s| !s.is_empty())
85+
.filter_map(|s| {
86+
// split `CatalystId` and `VerifyingKey` by `;` character.
87+
let Some((id, key)) = s.split(';').collect_tuple() else {
88+
tracing::error!(entry = s, "Invalid admin key entry");
89+
return None;
90+
};
91+
92+
let id = catalyst_signed_doc::CatalystId::from_str(id)
93+
.inspect_err(|err| {
94+
tracing::error!(
95+
err = ?err,
96+
"Cannot parse Admin CatalystId entry, skipping the value..."
97+
);
98+
})
99+
.ok()?;
100+
101+
// Strip the prefix and convert to 32 bytes array
102+
let key = key
103+
.strip_prefix("0x")
104+
.ok_or(anyhow::anyhow!(
105+
"Admin key hex value does not start with '0x'"
106+
))
107+
.and_then(|s| Ok(Vec::from_hex(s)?))
108+
.and_then(|bytes| Ok(bytes.as_slice().try_into()?))
109+
.inspect_err(|err| {
110+
tracing::error!(
111+
err = ?err,
112+
"Cannot parse Admin VerifyingKey entry, skipping the value..."
113+
);
114+
})
115+
.ok()?;
116+
Some((id, key))
117+
})
118+
.collect()
49119
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
-- Catalyst Signed Documents test data
2+
3+
INSERT INTO signed_docs (
4+
id,
5+
ver,
6+
type,
7+
authors,
8+
metadata,
9+
payload,
10+
raw
11+
)
12+
VALUES
13+
-- Proposal Form Template document
14+
(
15+
'0199e71b-4025-7323-bc4a-d39e35762521',
16+
'0199e71b-4025-7323-bc4a-d39e35762521',
17+
'0ce8ab38-9258-4fbc-a62e-7faa6e58318f',
18+
ARRAY[]::TEXT [],
19+
'{"content-encoding":"br","content-type":"application/json","id":"0199e71b-4025-7323-bc4a-d39e35762521","type":"0ce8ab38-9258-4fbc-a62e-7faa6e58318f","ver":"0199e71b-4025-7323-bc4a-d39e35762521","parameters":[{"id":"0199e71b-401e-7160-9139-a398c4d7b8fa","ver":"0199e71b-401e-7160-9139-a398c4d7b8fa","cid":"0x"}]}', -- noqa: LT05
20+
'{}',
21+
DECODE('d8628458aea603776170706c69636174696f6e2f736368656d612b6a736f6e6a706172616d65746572738183d825500199e71b401e71609139a398c4d7b8fad825500199e71b401e71609139a398c4d7b8faa163636964d82a4063766572d825500199e71b40257323bc4ad39e35762521626964d825500199e71b40257323bc4ad39e3576252170636f6e74656e742d656e636f64696e676262726474797065d825500ce8ab3892584fbca62e7faa6e58318fa0468b00807b7d038183584ba104584769642e636174616c7973743a2f2f63617264616e6f2f485562336e69537751656a4c64366857596179684150567a63694a2d7150625a4a6457534e7837715f33672f3130352f30a05840a7844bd49c79c4a7f2425a52bc16f1a853d6110342b4bd0f7a87098fc02519c5c9ec5e1fece64e9b2249dea17f61a8fd1ab30bbd6e04324a4d77d6ab0e2cd501', 'hex') -- noqa: LT05
22+
),
23+
-- Brand Parameters document
24+
(
25+
'0199e71b-401e-7160-9139-a398c4d7b8fa',
26+
'0199e71b-401e-7160-9139-a398c4d7b8fa',
27+
'3e4808cc-c86e-467b-9702-d60baa9d1fca',
28+
ARRAY[]::TEXT [],
29+
'{"content-encoding":"br","content-type":"application/json","id":"0199e71b-401e-7160-9139-a398c4d7b8fa","type":"3e4808cc-c86e-467b-9702-d60baa9d1fca","ver":"0199e71b-401e-7160-9139-a398c4d7b8fa","template":[{"id":"0199e71b-401d-7362-848b-a4090b1f3862","ver":"0199e71b-401d-7362-848b-a4090b1f3862","cid":"0x"}]}', -- noqa: LT05
30+
'{}',
31+
DECODE('d8628458a5a670636f6e74656e742d656e636f64696e6762627203706170706c69636174696f6e2f6a736f6e626964d825500199e71b401e71609139a398c4d7b8fa6874656d706c6174658183d825500199e71b401d7362848ba4090b1f3862d825500199e71b401d7362848ba4090b1f3862a163636964d82a406474797065d825503e4808ccc86e467b9702d60baa9d1fca63766572d825500199e71b401e71609139a398c4d7b8faa0468b00807b7d038183584ba104584769642e636174616c7973743a2f2f63617264616e6f2f6150766c4b387269455659757a69767470456f4469356f35494a37576733537643354f796e716750484d772f3130352f30a0584014bee2346bd6c78b7a443c17805d985c290a2aad53ff5bb12e05b6b165349365d9255af3a13fe7bfdf3afbf5f7011e2de48906d83b315b3ff71fb0b1fe7b1a07', 'hex') -- noqa: LT05
32+
);

catalyst-gateway/tests/api_tests/Earthfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
VERSION 0.8
22

33
IMPORT github.com/input-output-hk/catalyst-ci/earthly/python:v3.5.20 AS python-ci
4-
IMPORT github.com/input-output-hk/catalyst-libs/rust:catalyst-signed-doc/v.0.0.6-refinery-fix AS cat-libs-rust
5-
IMPORT github.com/input-output-hk/catalyst-libs/rust:catalyst-signed-doc/v.0.0.4-refinery-fix AS dep-cat-libs-rust
4+
IMPORT github.com/input-output-hk/catalyst-libs/rust:catalyst-signed-doc/v0.0.8 AS cat-libs-rust
5+
IMPORT github.com/input-output-hk/catalyst-libs/rust:catalyst-signed-doc/v.0.0.4-fix-earthly-build AS dep-cat-libs-rust
66
IMPORT github.com/input-output-hk/catalyst-storage AS cat-storage
77

88
builder:

catalyst-gateway/tests/api_tests/utils/signed_doc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def build_and_sign(
6060
)
6161

6262

63-
CATEGORY_ID = "0194d490-30bf-7473-81c8-a0eaef369619"
64-
PROPOSAL_FORM_TEMPLATE_ID = "0194d492-1daa-75b5-b4a4-5cf331cd8d1a"
63+
BRAND_ID = "0199e71b-401e-7160-9139-a398c4d7b8fa"
64+
PROPOSAL_FORM_TEMPLATE_ID = "0199e71b-4025-7323-bc4a-d39e35762521"
6565

6666

6767
# return a Proposal document which is already published to the cat-gateway and the corresponding RoleID
@@ -87,7 +87,7 @@ def __proposal_doc_factory() -> tuple[SignedDocument, RoleID]:
8787
}
8888
],
8989
# referenced to the defined category id, comes from the 'templates/data.rs' file
90-
"parameters": [{"id": CATEGORY_ID, "ver": CATEGORY_ID, "cid": "0x"}],
90+
"parameters": [{"id": BRAND_ID, "ver": BRAND_ID, "cid": "0x"}],
9191
}
9292
with open("./test_data/signed_docs/proposal.json", "r") as proposal_json_file:
9393
proposal_json = json.load(proposal_json_file)

catalyst-gateway/tests/docker-compose.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ services:
1919
ports:
2020
- 5432:5432
2121
healthcheck:
22-
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_PASSWORD}"]
22+
test:
23+
[
24+
"CMD-SHELL",
25+
"pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_PASSWORD}",
26+
]
2327
interval: 10s
2428
timeout: 5s
2529
retries: 10
@@ -60,6 +64,7 @@ services:
6064
- DB_USER_PASSWORD=CHANGE_ME
6165

6266
- INIT_AND_DROP_DB=false
67+
- WITH_SEED_DATA=.
6368
- WITH_MIGRATIONS=true
6469
restart: "no"
6570
depends_on:
@@ -130,7 +135,13 @@ services:
130135
- "18090:18090"
131136
- "9999:9999"
132137
healthcheck:
133-
test: [ "CMD", "sh", "-c", "echo 'show info' | socat tcp:localhost:9999 stdio | grep -q ^Name" ]
138+
test:
139+
[
140+
"CMD",
141+
"sh",
142+
"-c",
143+
"echo 'show info' | socat tcp:localhost:9999 stdio | grep -q ^Name",
144+
]
134145
interval: 10s
135146
timeout: 3s
136147
retries: 3

0 commit comments

Comments
 (0)