diff --git a/services/identity/src/database/device_list.rs b/services/identity/src/database/device_list.rs --- a/services/identity/src/database/device_list.rs +++ b/services/identity/src/database/device_list.rs @@ -14,6 +14,7 @@ DynamoDBError, TryFromAttribute, }, }; +use serde::Serialize; use tracing::{debug, error, warn}; use crate::{ @@ -36,16 +37,21 @@ // We omit the content and notif one-time key count attributes from this struct // because they are internal helpers and are not provided by users -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize)] +#[serde(rename_all = "camelCase")] pub struct DeviceRow { + #[serde(skip)] pub user_id: String, + #[serde(skip)] pub device_id: String, + #[serde(rename = "identityKeyInfo")] pub device_key_info: IdentityKeyInfo, pub content_prekey: Prekey, pub notif_prekey: Prekey, pub platform_details: PlatformDetails, /// Timestamp of last login (access token generation) + #[serde(skip)] pub login_time: DateTime, } @@ -61,26 +67,38 @@ pub last_primary_signature: Option, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize)] +#[serde(rename_all = "camelCase")] pub struct IdentityKeyInfo { pub key_payload: String, pub key_payload_signature: String, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize)] +#[serde(rename_all = "camelCase")] pub struct Prekey { pub prekey: String, pub prekey_signature: String, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize)] +#[serde(rename_all = "camelCase")] pub struct PlatformDetails { + #[serde(serialize_with = "serialize_device_type")] device_type: DeviceType, code_version: u64, state_version: Option, major_desktop_version: Option, } +fn serialize_device_type( + device_type: &DeviceType, + s: S, +) -> Result { + let v = device_type.as_str_name().to_lowercase(); + v.serialize(s) +} + /// A struct representing device list update payload /// issued by the primary device. /// For the JSON payload, see [`crate::device_list::SignedDeviceList`] diff --git a/services/identity/src/ddb_utils.rs b/services/identity/src/ddb_utils.rs --- a/services/identity/src/ddb_utils.rs +++ b/services/identity/src/ddb_utils.rs @@ -9,6 +9,7 @@ }, database::{AttributeExtractor, AttributeMap}, }; +use serde::Serialize; use std::collections::{HashMap, HashSet}; use std::iter::IntoIterator; @@ -160,13 +161,18 @@ transactions } +#[derive(Serialize)] pub struct DBIdentity { pub identifier: Identifier, + #[serde(rename = "farcasterID")] pub farcaster_id: Option, } +#[derive(Serialize)] +#[serde(rename_all = "camelCase")] pub enum Identifier { Username(String), + #[serde(rename = "ethereumIdentity")] WalletAddress(EthereumIdentity), } @@ -179,6 +185,8 @@ } } +#[derive(Serialize)] +#[serde(rename_all = "camelCase")] pub struct EthereumIdentity { pub wallet_address: String, pub social_proof: SocialProof, diff --git a/services/identity/src/grpc_utils.rs b/services/identity/src/grpc_utils.rs --- a/services/identity/src/grpc_utils.rs +++ b/services/identity/src/grpc_utils.rs @@ -1,6 +1,6 @@ use base64::{engine::general_purpose, Engine as _}; use ed25519_dalek::{PublicKey, Signature, Verifier}; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use tonic::Status; use tracing::warn; @@ -84,9 +84,13 @@ Ok(()) } +#[derive(Serialize)] pub struct DeviceKeysInfo { + #[serde(flatten)] pub device_info: DeviceRow, + #[serde(skip_serializing_if = "Option::is_none")] pub content_one_time_key: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub notif_one_time_key: Option, } diff --git a/services/identity/src/siwe.rs b/services/identity/src/siwe.rs --- a/services/identity/src/siwe.rs +++ b/services/identity/src/siwe.rs @@ -6,6 +6,7 @@ database::{AttributeExtractor, AttributeMap, TryFromAttribute}, }; use regex::Regex; +use serde::Serialize; use siwe::Message; use tonic::Status; use tracing::error; @@ -61,7 +62,7 @@ ethereum_address_regex.is_match(candidate) } -#[derive(derive_more::Constructor)] +#[derive(derive_more::Constructor, Serialize)] pub struct SocialProof { pub message: String, pub signature: String,