Skip to content

Commit a2cd8df

Browse files
committed
kamu-signing: IdentityConfig: use setty
1 parent cc7d8eb commit a2cd8df

14 files changed

Lines changed: 84 additions & 119 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/config-reference.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,26 +1294,22 @@ Supported algorithms: `ed25519`, `secp256k1`.
12941294
<thead><tr><th>Field</th><th>Type</th><th>Default</th><th>Description</th></tr></thead>
12951295
<tbody>
12961296
<tr>
1297-
<td><code>privateKey</code></td>
1297+
<td><code>ed25519PrivateKey</code></td>
12981298
<td><a href="#privatekey"><code>PrivateKey</code></a></td>
12991299
<td><code class="language-json">null</code></td>
13001300
<td>
13011301

1302-
To generate, use:
1302+
Root private key that corresponds to the `authority` and is used to sign
1303+
responses.
13031304

1305+
To generate, use:
13041306
```sh
1305-
dd if=/dev/urandom bs=1 count=32 status=none |
1306-
base64 -w0 |
1307-
tr '+/' '-_' |
1308-
tr -d '=' |
1309-
(echo -n u && cat)
1307+
od -vN 32 -An -tx1 /dev/urandom | tr -d ' \n' && echo
1308+
```
1309+
or
1310+
```sh
1311+
openssl rand -hex 32
13101312
```
1311-
1312-
The command above:
1313-
- Reads 32 random bytes
1314-
- base64-encodes them
1315-
- Converts default base64 encoding to base64url and removes padding
1316-
- Prepends a multibase prefix
13171313

13181314
</td>
13191315
</tr>
@@ -1325,6 +1321,15 @@ The command above:
13251321

13261322
Secp256k1 private key used to sign EIP-712 typed data.
13271323

1324+
To generate, use:
1325+
```sh
1326+
od -vN 32 -An -tx1 /dev/urandom | tr -d ' \n' && echo
1327+
```
1328+
or
1329+
```sh
1330+
openssl rand -hex 32
1331+
```
1332+
or
13281333
```sh
13291334
cast wallet new
13301335
```

resources/config-schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@
856856
"additionalProperties": false,
857857
"description": "Private keys are used to sign API responses.\nSupported algorithms: `ed25519`, `secp256k1`.",
858858
"properties": {
859-
"privateKey": {
859+
"ed25519PrivateKey": {
860860
"anyOf": [
861861
{
862862
"$ref": "#/$defs/PrivateKey"
@@ -866,7 +866,7 @@
866866
}
867867
],
868868
"combine": "replace",
869-
"description": "To generate, use:\n\n```sh\ndd if=/dev/urandom bs=1 count=32 status=none |\n base64 -w0 |\n tr '+/' '-_' |\n tr -d '=' |\n (echo -n u && cat)\n```\n\nThe command above:\n- Reads 32 random bytes\n- base64-encodes them\n- Converts default base64 encoding to base64url and removes padding\n- Prepends a multibase prefix"
869+
"description": "Root private key that corresponds to the `authority` and is used to sign\nresponses.\n\nTo generate, use:\n```sh\nod -vN 32 -An -tx1 /dev/urandom | tr -d ' \\n' && echo\n```\nor\n```sh\nopenssl rand -hex 32\n```"
870870
},
871871
"secp256k1PrivateKey": {
872872
"anyOf": [
@@ -878,7 +878,7 @@
878878
}
879879
],
880880
"combine": "replace",
881-
"description": "Secp256k1 private key used to sign EIP-712 typed data.\n\n```sh\ncast wallet new\n```"
881+
"description": "Secp256k1 private key used to sign EIP-712 typed data.\n\nTo generate, use:\n```sh\nod -vN 32 -An -tx1 /dev/urandom | tr -d ' \\n' && echo\n```\nor\n```sh\nopenssl rand -hex 32\n```\nor\n```sh\ncast wallet new\n```"
882882
}
883883
},
884884
"type": "object"

resources/di.puml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ class "GetDatasetUpstreamDependenciesUseCaseImpl"
269269
class "GithubAuthenticationConfig" <<singleton>>
270270
class "GqlConfig" <<singleton>>
271271
class "HttpSourceConfig" <<singleton>>
272+
class "IdentityConfig" <<singleton>>
272273
class "Interact" <<singleton>>
273274
class "IpfsClient" <<singleton>>
274275
class "IpfsGateway" <<singleton>>
@@ -1082,7 +1083,7 @@ class "WsSmartTransferProtocolClient"
10821083
"SignEip712UseCaseImpl" --> "DatasetActionAuthorizer"
10831084
"SignEip712UseCaseImpl" --> "CurrentAccountSubject"
10841085
"SignEip712UseCaseImpl" --> "DidSecretEncryptionConfig"
1085-
"SignEip712UseCaseImpl" "?" --> "IdentityConfig"
1086+
"SignEip712UseCaseImpl" --> "IdentityConfig"
10861087
"TaskEventStore" <|-- "SqliteTaskEventStore"
10871088
"SqliteTaskEventStore" --> "TransactionRefT"
10881089
"WebhookDeliveryRepository" <|-- "SqliteWebhookDeliveryRepository"

src/adapter/http/src/data/query_handler.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ pub async fn query_handler_impl(
179179
) -> Result<Json<QueryResponse>, ApiError> {
180180
tracing::debug!(request = ?body, "Query");
181181

182+
let query_svc = catalog.get_one::<dyn QueryService>().unwrap();
183+
let identity_config = catalog
184+
.get_one::<kamu_signing::entities::IdentityConfig>()
185+
.unwrap();
186+
187+
let Some(ed25519_private_key) = &identity_config.ed25519_private_key else {
188+
return Err(ApiError::not_implemented(ResponseSigningNotConfigured));
189+
};
190+
182191
// Automatically add `Input` if proof is requested, as proof depends on input
183192
// for verifiability
184193
if body.include.contains(&Include::Proof) {
@@ -189,11 +198,6 @@ pub async fn query_handler_impl(
189198
body.include.insert(Include::Schema);
190199
}
191200

192-
let identity = catalog
193-
.get_one::<kamu_signing::entities::IdentityConfig>()
194-
.ok();
195-
let query_svc = catalog.get_one::<dyn QueryService>().unwrap();
196-
197201
let res = query_svc
198202
.sql_statement(&body.query, body.to_options())
199203
.await
@@ -257,7 +261,7 @@ pub async fn query_handler_impl(
257261
commitment: None,
258262
proof: None,
259263
}
260-
} else if let Some(identity) = identity {
264+
} else {
261265
use odf::metadata::ed25519::Signer;
262266

263267
let sub_queries = Vec::new();
@@ -273,9 +277,7 @@ pub async fn query_handler_impl(
273277
)),
274278
};
275279

276-
let signature = identity
277-
.ed25519_private_key
278-
.sign(&to_canonical_json(&commitment));
280+
let signature = ed25519_private_key.sign(&to_canonical_json(&commitment));
279281

280282
QueryResponse {
281283
input,
@@ -284,12 +286,10 @@ pub async fn query_handler_impl(
284286
commitment: Some(commitment),
285287
proof: Some(Proof {
286288
r#type: kamu_signing::common::ProofType::Ed25519Signature2020,
287-
verification_method: identity.ed25519_private_key.verifying_key(),
289+
verification_method: ed25519_private_key.verifying_key(),
288290
proof_value: signature.into(),
289291
}),
290292
}
291-
} else {
292-
Err(ApiError::not_implemented(ResponseSigningNotConfigured))?
293293
};
294294

295295
Ok(Json(response))

src/adapter/http/tests/tests/test_data_query.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ impl Harness {
4242

4343
let ed25519_private_key = odf::metadata::PrivateKey::from_bytes(&[123; _]);
4444
let identity_config = kamu_signing::entities::IdentityConfig {
45-
ed25519_private_key: ed25519_private_key.clone(),
46-
secp256k1_private_key: kamu_signing::utils::Secp256k1Signer::from_bytes(
47-
&[124; _].into(),
48-
)
49-
.unwrap(),
45+
ed25519_private_key: Some(ed25519_private_key.clone()),
46+
secp256k1_private_key: Some(
47+
kamu_signing::utils::Secp256k1Signer::from_bytes(&[124; _].into()).unwrap(),
48+
),
5049
};
5150

5251
let catalog = dill::CatalogBuilder::new()

src/app/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ kamu-auth-web3-services = { workspace = true }
132132
kamu-auth-web3-sqlite = { workspace = true }
133133

134134
kamu-signing = { workspace = true, default-features = false, features = [
135-
"schemars"
135+
"schemars",
136136
] }
137137
kamu-signing-services = { workspace = true }
138138

src/app/cli/src/app.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,10 +830,7 @@ pub fn register_config_in_catalog(
830830
catalog_builder.add_value(config.source.ethereum.to_infra_cfg());
831831

832832
// Identity configuration
833-
if let Some(identity_config) = config.identity.to_infra_cfg() {
834-
catalog_builder.add_value(identity_config);
835-
}
836-
//
833+
catalog_builder.add_value(config.identity.clone());
837834

838835
// IPFS configuration
839836
catalog_builder.add_value(odf::dataset::IpfsGateway {

src/app/cli/src/services/config/models.rs

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub struct CLIConfig {
4747

4848
/// UNSTABLE: Identity configuration
4949
#[config(default)]
50-
pub identity: IdentityConfig,
50+
pub identity: kamu_signing::entities::IdentityConfig,
5151

5252
/// Messaging outbox agent configuration
5353
#[config(default)]
@@ -555,56 +555,6 @@ pub struct AwsSecretDatabasePasswordPolicyConfig {
555555
pub secret_name: String,
556556
}
557557

558-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
559-
// Identity
560-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
561-
562-
/// Private keys are used to sign API responses.
563-
/// Supported algorithms: `ed25519`, `secp256k1`.
564-
#[derive(setty::Config, setty::Default)]
565-
pub struct IdentityConfig {
566-
/// To generate, use:
567-
///
568-
/// ```sh
569-
/// dd if=/dev/urandom bs=1 count=32 status=none |
570-
/// base64 -w0 |
571-
/// tr '+/' '-_' |
572-
/// tr -d '=' |
573-
/// (echo -n u && cat)
574-
/// ```
575-
///
576-
/// The command above:
577-
/// - Reads 32 random bytes
578-
/// - base64-encodes them
579-
/// - Converts default base64 encoding to base64url and removes padding
580-
/// - Prepends a multibase prefix
581-
#[config(combine(replace))]
582-
pub private_key: Option<odf::metadata::PrivateKey>,
583-
584-
/// Secp256k1 private key used to sign EIP-712 typed data.
585-
///
586-
/// ```sh
587-
/// cast wallet new
588-
/// ```
589-
#[config(combine(replace))]
590-
pub secp256k1_private_key: Option<kamu_signing::utils::Secp256k1Signer>,
591-
}
592-
593-
impl IdentityConfig {
594-
pub fn to_infra_cfg(&self) -> Option<kamu_signing::entities::IdentityConfig> {
595-
if let Some(ed25519_private_key) = &self.private_key
596-
&& let Some(secp256k1_private_key) = &self.secp256k1_private_key
597-
{
598-
Some(kamu_signing::entities::IdentityConfig {
599-
ed25519_private_key: ed25519_private_key.clone(),
600-
secp256k1_private_key: secp256k1_private_key.clone(),
601-
})
602-
} else {
603-
None
604-
}
605-
}
606-
}
607-
608558
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
609559
// Search
610560
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

src/domain/signing/domain/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ odf = { workspace = true }
3737
async-trait = { version = "0.1", default-features = false }
3838
bon = { version = "3", default-features = false }
3939
serde = { version = "1", features = ["derive"], default-features = false }
40+
setty = { version = "1.0", default-features = false }
4041
thiserror = { version = "2", default-features = false }
4142

4243
# Optional

0 commit comments

Comments
 (0)