Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3720896
D6943.id23391.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D6943.id23391.diff
View Options
diff --git a/keyserver/addons/rust-node-addon/src/identity_client/login_user.rs b/keyserver/addons/rust-node-addon/src/identity_client/login_user.rs
--- a/keyserver/addons/rust-node-addon/src/identity_client/login_user.rs
+++ b/keyserver/addons/rust-node-addon/src/identity_client/login_user.rs
@@ -1,5 +1,73 @@
use super::*;
+#[napi]
+#[instrument(skip_all)]
+async fn login_user_wallet(
+ user_id: String,
+ signing_public_key: String,
+ siwe_message: String,
+ siwe_signature: String,
+ mut session_initialization_info: HashMap<String, String>,
+ social_proof: String,
+) -> Result<String> {
+ let channel = Channel::from_static(&IDENTITY_SERVICE_SOCKET_ADDR)
+ .connect()
+ .await
+ .map_err(|_| {
+ Error::new(
+ Status::GenericFailure,
+ "Unable to connect to identity service".to_string(),
+ )
+ })?;
+ let token: MetadataValue<_> = AUTH_TOKEN
+ .parse()
+ .map_err(|_| Error::from_status(Status::GenericFailure))?;
+ let mut identity_client =
+ IdentityServiceClient::with_interceptor(channel, |mut req: Request<()>| {
+ req.metadata_mut().insert("authorization", token.clone());
+ Ok(req)
+ });
+
+ // Create a LoginRequest channel and use ReceiverStream to turn the
+ // MPSC receiver into a Stream for outbound messages
+ let (tx, rx) = mpsc::channel(1);
+ let stream = ReceiverStream::new(rx);
+ let request = Request::new(stream);
+
+ // `response` is the Stream for inbound messages
+ let mut response = identity_client
+ .login_user(request)
+ .await
+ .map_err(|_| Error::from_status(Status::GenericFailure))?
+ .into_inner();
+
+ // Start wallet login on client and send initial login request to Identity
+ // service
+ session_initialization_info.insert("socialProof".to_string(), social_proof);
+ let login_request = LoginRequest {
+ data: Some(WalletLoginRequest(WalletLoginRequestStruct {
+ user_id,
+ signing_public_key,
+ siwe_message,
+ siwe_signature,
+ session_initialization_info: Some(SessionInitializationInfo {
+ info: session_initialization_info,
+ }),
+ })),
+ };
+ if let Err(e) = tx.send(login_request).await {
+ error!("Response was dropped: {}", e);
+ return Err(Error::from_status(Status::GenericFailure));
+ }
+
+ // Return access token
+ let message = response.message().await.map_err(|e| {
+ error!("Received an error from inbound message stream: {}", e);
+ Error::from_status(Status::GenericFailure)
+ })?;
+ handle_wallet_login_response(message)
+}
+
#[napi]
#[instrument(skip_all)]
async fn login_user_pake(
@@ -134,3 +202,16 @@
Err(handle_unexpected_response(message))
}
}
+
+fn handle_wallet_login_response(
+ message: Option<LoginResponse>,
+) -> Result<String, Status> {
+ if let Some(LoginResponse {
+ data: Some(WalletLoginResponse(WalletLoginResponseStruct { access_token })),
+ }) = message
+ {
+ Ok(access_token)
+ } else {
+ Err(handle_unexpected_response(message))
+ }
+}
diff --git a/keyserver/addons/rust-node-addon/src/identity_client/mod.rs b/keyserver/addons/rust-node-addon/src/identity_client/mod.rs
--- a/keyserver/addons/rust-node-addon/src/identity_client/mod.rs
+++ b/keyserver/addons/rust-node-addon/src/identity_client/mod.rs
@@ -9,7 +9,9 @@
use identity::identity_service_client::IdentityServiceClient;
use identity::{
login_request::Data::PakeLoginRequest,
+ login_request::Data::WalletLoginRequest,
login_response::Data::PakeLoginResponse as LoginPakeLoginResponse,
+ login_response::Data::WalletLoginResponse,
pake_login_request::Data::PakeCredentialFinalization as LoginPakeCredentialFinalization,
pake_login_request::Data::PakeCredentialRequestAndUserId,
pake_login_response::Data::AccessToken,
@@ -26,7 +28,8 @@
PakeRegistrationRequestAndUserId as PakeRegistrationRequestAndUserIdStruct,
PakeRegistrationUploadAndCredentialRequest as PakeRegistrationUploadAndCredentialRequestStruct,
RegistrationRequest, RegistrationResponse as RegistrationResponseMessage,
- SessionInitializationInfo,
+ SessionInitializationInfo, WalletLoginRequest as WalletLoginRequestStruct,
+ WalletLoginResponse as WalletLoginResponseStruct,
};
use lazy_static::lazy_static;
use napi::bindgen_prelude::*;
diff --git a/lib/types/rust-binding-types.js b/lib/types/rust-binding-types.js
--- a/lib/types/rust-binding-types.js
+++ b/lib/types/rust-binding-types.js
@@ -29,6 +29,14 @@
password: string,
sessionInitializationInfo: SignedIdentityKeysBlob,
) => Promise<string>,
+ +loginUserWallet: (
+ userId: string,
+ signingPublicKey: string,
+ siweMessage: string,
+ siweSignature: string,
+ sessionInitializationInfo: SignedIdentityKeysBlob,
+ socialProof: string,
+ ) => Promise<string>,
+deleteUser: (userId: string) => Promise<boolean>,
+TunnelbrokerClient: Class<TunnelbrokerClientClass>,
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 9, 12:56 PM (8 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2835124
Default Alt Text
D6943.id23391.diff (4 KB)
Attached To
Mode
D6943: [keyserver] add loginUserWallet function
Attached
Detach File
Event Timeline
Log In to Comment