refactor: update dependencies and remove unused code
- Added new dependencies: `adler2`, `crc32fast`, `flate2`, `miniz_oxide`, and `libredox`. - Updated existing dependencies: `tokio-rustls` to version 0.26.4 and `filetime` to version 0.2.27. - Removed the `backup.rs` file as it is no longer needed. - Introduced tests for configuration and credential management. - Enhanced the `identity` module to generate W3C compliant DID documents. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
2a867b32a8
commit
6fee6befed
@@ -57,13 +57,15 @@ impl RpcHandler {
|
||||
)
|
||||
.await?;
|
||||
|
||||
let status = if credentials::is_revoked(&vc) { "revoked" } else { "active" };
|
||||
|
||||
Ok(serde_json::json!({
|
||||
"id": vc.id,
|
||||
"issuer": vc.issuer,
|
||||
"subject": vc.subject,
|
||||
"subject": vc.credential_subject.id,
|
||||
"type": vc.credential_type,
|
||||
"issued_at": vc.issued_at,
|
||||
"status": vc.status,
|
||||
"issued_at": vc.issuance_date,
|
||||
"status": status,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -97,10 +99,12 @@ impl RpcHandler {
|
||||
})
|
||||
})?;
|
||||
|
||||
let status = if credentials::is_revoked(vc) { "revoked" } else { "active" };
|
||||
|
||||
Ok(serde_json::json!({
|
||||
"id": vc.id,
|
||||
"valid": valid,
|
||||
"status": vc.status,
|
||||
"status": status,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -118,15 +122,17 @@ impl RpcHandler {
|
||||
let items: Vec<serde_json::Value> = creds
|
||||
.into_iter()
|
||||
.map(|c| {
|
||||
let status = if credentials::is_revoked(&c) { "revoked" } else { "active" };
|
||||
serde_json::json!({
|
||||
"@context": c.context,
|
||||
"id": c.id,
|
||||
"issuer": c.issuer,
|
||||
"subject": c.subject,
|
||||
"type": c.credential_type,
|
||||
"claims": c.claims,
|
||||
"issued_at": c.issued_at,
|
||||
"expires_at": c.expires_at,
|
||||
"status": c.status,
|
||||
"issuer": c.issuer,
|
||||
"credentialSubject": c.credential_subject,
|
||||
"issuanceDate": c.issuance_date,
|
||||
"expirationDate": c.expiration_date,
|
||||
"proof": c.proof,
|
||||
"status": status,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
@@ -147,4 +153,86 @@ impl RpcHandler {
|
||||
credentials::revoke_credential(&self.config.data_dir, id).await?;
|
||||
Ok(serde_json::json!({ "ok": true }))
|
||||
}
|
||||
|
||||
/// Create a Verifiable Presentation bundling selected credentials.
|
||||
pub(super) async fn handle_identity_create_presentation(
|
||||
&self,
|
||||
params: Option<serde_json::Value>,
|
||||
) -> Result<serde_json::Value> {
|
||||
let params = params.ok_or_else(|| anyhow::anyhow!("Missing params"))?;
|
||||
let holder_id = params
|
||||
.get("holder_id")
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or_else(|| anyhow::anyhow!("Missing holder_id"))?;
|
||||
let credential_ids: Vec<&str> = params
|
||||
.get("credential_ids")
|
||||
.and_then(|v| v.as_array())
|
||||
.ok_or_else(|| anyhow::anyhow!("Missing credential_ids array"))?
|
||||
.iter()
|
||||
.filter_map(|v| v.as_str())
|
||||
.collect();
|
||||
|
||||
if credential_ids.is_empty() {
|
||||
return Err(anyhow::anyhow!("credential_ids must not be empty"));
|
||||
}
|
||||
|
||||
let manager = IdentityManager::new(&self.config.data_dir).await?;
|
||||
let holder_record = manager.get(holder_id).await?;
|
||||
let holder_did = holder_record.did.clone();
|
||||
|
||||
let store = credentials::load_credentials(&self.config.data_dir).await?;
|
||||
|
||||
let data_dir = self.config.data_dir.clone();
|
||||
let sign_id = holder_id.to_string();
|
||||
|
||||
let vp = credentials::create_presentation(
|
||||
&holder_did,
|
||||
&credential_ids,
|
||||
&store.credentials,
|
||||
|bytes| {
|
||||
let hex_msg = hex::encode(bytes);
|
||||
tokio::task::block_in_place(|| {
|
||||
let rt = tokio::runtime::Handle::current();
|
||||
rt.block_on(async {
|
||||
let mgr = IdentityManager::new(&data_dir).await?;
|
||||
mgr.sign(&sign_id, hex_msg.as_bytes()).await
|
||||
})
|
||||
})
|
||||
},
|
||||
)?;
|
||||
|
||||
Ok(serde_json::to_value(&vp)?)
|
||||
}
|
||||
|
||||
/// Verify a Verifiable Presentation: check holder proof and all embedded credentials.
|
||||
pub(super) async fn handle_identity_verify_presentation(
|
||||
&self,
|
||||
params: Option<serde_json::Value>,
|
||||
) -> Result<serde_json::Value> {
|
||||
let params = params.ok_or_else(|| anyhow::anyhow!("Missing params"))?;
|
||||
let presentation = params
|
||||
.get("presentation")
|
||||
.ok_or_else(|| anyhow::anyhow!("Missing presentation"))?;
|
||||
|
||||
let vp: credentials::VerifiablePresentation =
|
||||
serde_json::from_value(presentation.clone())?;
|
||||
|
||||
let data_dir = self.config.data_dir.clone();
|
||||
let result = credentials::verify_presentation(&vp, |did, bytes, signature| {
|
||||
let hex_msg = hex::encode(bytes);
|
||||
tokio::task::block_in_place(|| {
|
||||
let rt = tokio::runtime::Handle::current();
|
||||
rt.block_on(async {
|
||||
let mgr = IdentityManager::new(&data_dir).await?;
|
||||
mgr.verify(did, hex_msg.as_bytes(), signature).await
|
||||
})
|
||||
})
|
||||
})?;
|
||||
|
||||
Ok(serde_json::json!({
|
||||
"valid": result.valid,
|
||||
"holder_valid": result.holder_valid,
|
||||
"credentials": result.credentials,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user