Change identity proof API to avoid key-to-DID converion at client side

This commit is contained in:
silverpill 2022-11-10 10:48:25 +00:00
parent efb51c1be6
commit 99f7b334d1
3 changed files with 34 additions and 8 deletions

View file

@ -150,13 +150,21 @@ paths:
get: get:
summary: Get unsigned data for identity proof. summary: Get unsigned data for identity proof.
parameters: parameters:
- name: did - name: proof_type
in: query in: query
description: Identifier (DID). description: Type of identity proof.
required: true required: true
schema: schema:
type: string type: string
example: 'did:pkh:eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8a' enum:
- ethereum
- name: signer
in: query
description: Information about the signer.
required: true
schema:
type: string
example: '0xb9c5714089478a327f09197987f16f9e5d936e8a'
responses: responses:
200: 200:
description: Successful operation description: Successful operation
@ -165,6 +173,10 @@ paths:
schema: schema:
type: object type: object
properties: properties:
did:
description: Signer ID (DID).
type: string
example: did:pkh:eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8a
claim: claim:
description: Identity claim serialized as compact JSON. description: Identity claim serialized as compact JSON.
type: string type: string

View file

@ -274,11 +274,13 @@ pub struct SignedUpdate {
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct IdentityClaimQueryParams { pub struct IdentityClaimQueryParams {
pub did: String, pub proof_type: String,
pub signer: String,
} }
#[derive(Serialize)] #[derive(Serialize)]
pub struct IdentityClaim { pub struct IdentityClaim {
pub did: Did,
pub claim: String, pub claim: String,
} }

View file

@ -24,7 +24,11 @@ use crate::ethereum::identity::{
ETHEREUM_EIP191_PROOF, ETHEREUM_EIP191_PROOF,
verify_eip191_identity_proof, verify_eip191_identity_proof,
}; };
use crate::identity::{claims::create_identity_claim, did::Did}; use crate::identity::{
claims::create_identity_claim,
did::Did,
did_pkh::DidPkh,
};
use crate::json_signatures::{ use crate::json_signatures::{
canonicalization::canonicalize_object, canonicalization::canonicalize_object,
create::{add_integrity_proof, IntegrityProof}, create::{add_integrity_proof, IntegrityProof},
@ -293,12 +297,20 @@ async fn get_identity_claim(
) -> Result<HttpResponse, HttpError> { ) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?; let db_client = &**get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?; let current_user = get_current_user(db_client, auth.token()).await?;
let did = match query_params.proof_type.as_str() {
"ethereum" => {
let did_pkh = DidPkh::from_address(
&Currency::Ethereum,
&query_params.signer,
);
Did::Pkh(did_pkh)
},
_ => return Err(ValidationError("unknown proof type").into()),
};
let actor_id = current_user.profile.actor_id(&config.instance_url()); let actor_id = current_user.profile.actor_id(&config.instance_url());
let did = query_params.did.parse::<Did>()
.map_err(|_| ValidationError("invalid DID"))?;
let claim = create_identity_claim(&actor_id, &did) let claim = create_identity_claim(&actor_id, &did)
.map_err(|_| HttpError::InternalError)?; .map_err(|_| HttpError::InternalError)?;
let response = IdentityClaim { claim }; let response = IdentityClaim { did, claim };
Ok(HttpResponse::Ok().json(response)) Ok(HttpResponse::Ok().json(response))
} }