Use enum to represent activity parameters during the signing process

This commit is contained in:
silverpill 2022-11-07 16:44:00 +00:00
parent fbcba1b99d
commit a6032386da
3 changed files with 35 additions and 21 deletions

View file

@ -168,11 +168,10 @@ paths:
schema: schema:
type: object type: object
properties: properties:
internal_activity_id: params:
description: Internal activity ID. description: Activity parameters
type: string $ref: '#/components/schemas/ActivityParameters'
format: uuid message:
activity:
description: Canonical representation of activity. description: Canonical representation of activity.
type: string type: string
example: '{"type":"Update"}' example: '{"type":"Update"}'
@ -184,10 +183,9 @@ paths:
schema: schema:
type: object type: object
properties: properties:
internal_activity_id: params:
description: Internal activity ID. description: Activity parameters
type: string $ref: '#/components/schemas/ActivityParameters'
format: uuid
signer: signer:
description: Signer's identifier (DID) description: Signer's identifier (DID)
type: string type: string
@ -1178,6 +1176,14 @@ components:
note: note:
description: Profile bio. description: Profile bio.
type: string type: string
ActivityParameters:
type: object
properties:
type:
description: Activity type
type: string
enum:
- update
Attachment: Attachment:
type: object type: object
properties: properties:

View file

@ -262,15 +262,21 @@ impl AccountUpdateData {
} }
} }
#[derive(Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum ActivityParams {
Update { internal_activity_id: Uuid },
}
#[derive(Serialize)] #[derive(Serialize)]
pub struct UnsignedUpdate { pub struct UnsignedActivity {
pub internal_activity_id: Uuid, pub params: ActivityParams,
pub activity: String, // canonical representation pub message: String, // canonical representation
} }
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct SignedUpdate { pub struct SignedActivity {
pub internal_activity_id: Uuid, pub params: ActivityParams,
pub signer: String, pub signer: String,
pub signature: String, pub signature: String,
} }

View file

@ -88,6 +88,7 @@ use super::types::{
Account, Account,
AccountCreateData, AccountCreateData,
AccountUpdateData, AccountUpdateData,
ActivityParams,
ApiSubscription, ApiSubscription,
FollowData, FollowData,
FollowListQueryParams, FollowListQueryParams,
@ -97,9 +98,9 @@ use super::types::{
RelationshipQueryParams, RelationshipQueryParams,
SearchAcctQueryParams, SearchAcctQueryParams,
SearchDidQueryParams, SearchDidQueryParams,
SignedUpdate, SignedActivity,
StatusListQueryParams, StatusListQueryParams,
UnsignedUpdate, UnsignedActivity,
}; };
#[post("")] #[post("")]
@ -246,9 +247,9 @@ async fn get_unsigned_update(
).map_err(|_| HttpError::InternalError)?; ).map_err(|_| HttpError::InternalError)?;
let canonical_json = canonicalize_object(&activity) let canonical_json = canonicalize_object(&activity)
.map_err(|_| HttpError::InternalError)?; .map_err(|_| HttpError::InternalError)?;
let data = UnsignedUpdate { let data = UnsignedActivity {
internal_activity_id, params: ActivityParams::Update { internal_activity_id },
activity: canonical_json, message: canonical_json,
}; };
Ok(HttpResponse::Ok().json(data)) Ok(HttpResponse::Ok().json(data))
} }
@ -258,7 +259,7 @@ async fn send_signed_update(
auth: BearerAuth, auth: BearerAuth,
config: web::Data<Config>, config: web::Data<Config>,
db_pool: web::Data<Pool>, db_pool: web::Data<Pool>,
data: web::Json<SignedUpdate>, data: web::Json<SignedActivity>,
) -> Result<HttpResponse, HttpError> { ) -> Result<HttpResponse, HttpError> {
let db_client = &mut **get_database_client(&db_pool).await?; let db_client = &mut **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?;
@ -267,11 +268,12 @@ async fn send_signed_update(
if !current_user.profile.identity_proofs.any(&signer) { if !current_user.profile.identity_proofs.any(&signer) {
return Err(ValidationError("unknown signer").into()); return Err(ValidationError("unknown signer").into());
}; };
let ActivityParams::Update { internal_activity_id } = data.params;
let mut outgoing_activity = prepare_signed_update_person( let mut outgoing_activity = prepare_signed_update_person(
db_client, db_client,
&config.instance(), &config.instance(),
&current_user, &current_user,
data.internal_activity_id, internal_activity_id,
).await.map_err(|_| HttpError::InternalError)?; ).await.map_err(|_| HttpError::InternalError)?;
let canonical_json = canonicalize_object(&outgoing_activity.activity) let canonical_json = canonicalize_object(&outgoing_activity.activity)
.map_err(|_| HttpError::InternalError)?; .map_err(|_| HttpError::InternalError)?;