diff --git a/services/identity/src/database.rs b/services/identity/src/database.rs --- a/services/identity/src/database.rs +++ b/services/identity/src/database.rs @@ -25,8 +25,8 @@ USERS_TABLE_USERNAME_INDEX, USERS_TABLE_USER_PUBLIC_KEY_ATTRIBUTE, USERS_TABLE_WALLET_ADDRESS_ATTRIBUTE, USERS_TABLE_WALLET_ADDRESS_INDEX, }; -use comm_opaque::Cipher; use crate::token::{AccessTokenData, AuthType}; +use comm_opaque::Cipher; #[derive(Clone)] pub struct DatabaseClient { @@ -138,6 +138,49 @@ .map_err(|e| Error::AwsSdk(e.into())) } + pub async fn add_user_to_users_table( + &self, + user_id: String, + device_id: String, + registration: ServerRegistration, + username: String, + user_public_key: String, + ) -> Result { + let item = HashMap::from([ + ( + USERS_TABLE_PARTITION_KEY.to_string(), + AttributeValue::S(user_id), + ), + ( + USERS_TABLE_USERNAME_ATTRIBUTE.to_string(), + AttributeValue::S(username), + ), + ( + USERS_TABLE_REGISTRATION_ATTRIBUTE.to_string(), + AttributeValue::B(Blob::new(registration.serialize())), + ), + ( + USERS_TABLE_DEVICES_ATTRIBUTE.to_string(), + AttributeValue::M(HashMap::from([( + device_id, + AttributeValue::M(HashMap::from([( + USERS_TABLE_USER_PUBLIC_KEY_ATTRIBUTE.to_string(), + AttributeValue::S(user_public_key), + )])), + )])), + ), + ]); + + self + .client + .put_item() + .table_name(USERS_TABLE) + .set_item(Some(item)) + .send() + .await + .map_err(|e| Error::AwsSdk(e.into())) + } + pub async fn get_access_token_data( &self, user_id: String, diff --git a/services/identity/src/service.rs b/services/identity/src/service.rs --- a/services/identity/src/service.rs +++ b/services/identity/src/service.rs @@ -1,5 +1,6 @@ use aws_sdk_dynamodb::Error as DynamoDBError; use chrono::Utc; +use comm_opaque::Cipher; use constant_time_eq::constant_time_eq; use futures_core::Stream; use opaque_ke::{ @@ -16,7 +17,6 @@ use tokio_stream::{wrappers::ReceiverStream, StreamExt}; use tonic::{Request, Response, Status}; use tracing::{error, info, instrument}; -use comm_opaque::Cipher; use crate::constants::MPSC_CHANNEL_BUFFER_CAPACITY; use crate::database::DatabaseClient;