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:
type: object
properties:
internal_activity_id:
description: Internal activity ID.
type: string
format: uuid
activity:
params:
description: Activity parameters
$ref: '#/components/schemas/ActivityParameters'
message:
description: Canonical representation of activity.
type: string
example: '{"type":"Update"}'
@ -184,10 +183,9 @@ paths:
schema:
type: object
properties:
internal_activity_id:
description: Internal activity ID.
type: string
format: uuid
params:
description: Activity parameters
$ref: '#/components/schemas/ActivityParameters'
signer:
description: Signer's identifier (DID)
type: string
@ -1178,6 +1176,14 @@ components:
note:
description: Profile bio.
type: string
ActivityParameters:
type: object
properties:
type:
description: Activity type
type: string
enum:
- update
Attachment:
type: object
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)]
pub struct UnsignedUpdate {
pub internal_activity_id: Uuid,
pub activity: String, // canonical representation
pub struct UnsignedActivity {
pub params: ActivityParams,
pub message: String, // canonical representation
}
#[derive(Deserialize)]
pub struct SignedUpdate {
pub internal_activity_id: Uuid,
pub struct SignedActivity {
pub params: ActivityParams,
pub signer: String,
pub signature: String,
}

View file

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