Page MenuHomePhabricator

D10902.diff
No OneTemporary

D10902.diff

diff --git a/services/identity/src/client_service.rs b/services/identity/src/client_service.rs
--- a/services/identity/src/client_service.rs
+++ b/services/identity/src/client_service.rs
@@ -36,7 +36,9 @@
validate_add_reserved_usernames_message,
validate_remove_reserved_username_message,
};
-use crate::siwe::{is_valid_ethereum_address, parse_and_verify_siwe_message};
+use crate::siwe::{
+ is_valid_ethereum_address, parse_and_verify_siwe_message, SocialProof,
+};
use crate::token::{AccessTokenData, AuthType};
pub use crate::grpc_services::protos::unauth::identity_client_service_server::{
@@ -407,10 +409,6 @@
let flattened_device_key_upload =
construct_flattened_device_key_upload(&message)?;
- let social_proof = message
- .social_proof()?
- .ok_or_else(|| tonic::Status::invalid_argument("malformed payload"))?;
-
let login_time = chrono::Utc::now();
let user_id = match self
.client
@@ -450,6 +448,13 @@
));
}
+ let social_proof =
+ SocialProof::new(message.siwe_message, message.siwe_signature);
+ let serialized_social_proof = serde_json::to_string(&social_proof)
+ .map_err(|_| {
+ tonic::Status::invalid_argument("invalid_social_proof")
+ })?;
+
// User doesn't exist yet and wallet address isn't reserved, so we
// should add a new user in DDB
self
@@ -457,7 +462,7 @@
.add_wallet_user_to_users_table(
flattened_device_key_upload.clone(),
wallet_address,
- social_proof,
+ serialized_social_proof,
None,
code_version,
login_time,
@@ -541,9 +546,10 @@
let flattened_device_key_upload =
construct_flattened_device_key_upload(&message)?;
- let social_proof = message
- .social_proof()?
- .ok_or_else(|| tonic::Status::invalid_argument("malformed payload"))?;
+ let social_proof =
+ SocialProof::new(message.siwe_message, message.siwe_signature);
+ let serialized_social_proof = serde_json::to_string(&social_proof)
+ .map_err(|_| tonic::Status::invalid_argument("invalid_social_proof"))?;
let login_time = chrono::Utc::now();
self
@@ -551,7 +557,7 @@
.add_wallet_user_to_users_table(
flattened_device_key_upload.clone(),
wallet_address,
- social_proof,
+ serialized_social_proof,
Some(user_id.clone()),
code_version,
login_time,
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
@@ -103,7 +103,6 @@
fn one_time_content_prekeys(&self) -> Result<Vec<String>, Status>;
fn one_time_notif_prekeys(&self) -> Result<Vec<String>, Status>;
fn device_type(&self) -> Result<i32, Status>;
- fn social_proof(&self) -> Result<Option<String>, Status>;
}
impl<T: DeviceKeyUploadData> DeviceKeyUploadActions for T {
@@ -174,13 +173,6 @@
.map(|upload| upload.device_type)
.ok_or_else(|| Status::invalid_argument("unexpected message data"))
}
- fn social_proof(&self) -> Result<Option<String>, Status> {
- self
- .device_key_upload()
- .and_then(|upload| upload.device_key_info.as_ref())
- .map(|info| info.social_proof.clone())
- .ok_or_else(|| Status::invalid_argument("unexpected message data"))
- }
}
impl TryFrom<DBIdentifier> for IdentityInfo {
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
@@ -1,5 +1,6 @@
use chrono::Utc;
use regex::Regex;
+use serde::Serialize;
use siwe::Message;
use tonic::Status;
use tracing::error;
@@ -39,6 +40,12 @@
ethereum_address_regex.is_match(candidate)
}
+#[derive(derive_more::Constructor, Serialize)]
+pub struct SocialProof {
+ message: String,
+ signature: String,
+}
+
#[cfg(test)]
mod tests {
use super::*;

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 3:05 PM (20 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2576502
Default Alt Text
D10902.diff (3 KB)

Event Timeline