From 99f7b334d1de85364cd28bc03dee347576acd35a Mon Sep 17 00:00:00 2001 From: silverpill Date: Thu, 10 Nov 2022 10:48:25 +0000 Subject: [PATCH] Change identity proof API to avoid key-to-DID converion at client side --- docs/openapi.yaml | 18 +++++++++++++++--- src/mastodon_api/accounts/types.rs | 4 +++- src/mastodon_api/accounts/views.rs | 20 ++++++++++++++++---- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 19aaaac..76a03c0 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -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 diff --git a/src/mastodon_api/accounts/types.rs b/src/mastodon_api/accounts/types.rs index c2e9d0b..ec6a7bc 100644 --- a/src/mastodon_api/accounts/types.rs +++ b/src/mastodon_api/accounts/types.rs @@ -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, } diff --git a/src/mastodon_api/accounts/views.rs b/src/mastodon_api/accounts/views.rs index f773a29..3b213b9 100644 --- a/src/mastodon_api/accounts/views.rs +++ b/src/mastodon_api/accounts/views.rs @@ -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 { 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::() - .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)) }