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:
summary: Get unsigned data for identity proof.
parameters:
- name: did
- name: proof_type
in: query
description: Identifier (DID).
description: Type of identity proof.
required: true
schema:
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:
200:
description: Successful operation
@ -165,6 +173,10 @@ paths:
schema:
type: object
properties:
did:
description: Signer ID (DID).
type: string
example: did:pkh:eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8a
claim:
description: Identity claim serialized as compact JSON.
type: string

View file

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

View file

@ -24,7 +24,11 @@ use crate::ethereum::identity::{
ETHEREUM_EIP191_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::{
canonicalization::canonicalize_object,
create::{add_integrity_proof, IntegrityProof},
@ -293,12 +297,20 @@ async fn get_identity_claim(
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).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 did = query_params.did.parse::<Did>()
.map_err(|_| ValidationError("invalid DID"))?;
let claim = create_identity_claim(&actor_id, &did)
.map_err(|_| HttpError::InternalError)?;
let response = IdentityClaim { claim };
let response = IdentityClaim { did, claim };
Ok(HttpResponse::Ok().json(response))
}