diff --git a/keyserver/addons/rust-node-addon/rust-binding-types.js b/keyserver/addons/rust-node-addon/rust-binding-types.js index 3f3715d6a..671122fb9 100644 --- a/keyserver/addons/rust-node-addon/rust-binding-types.js +++ b/keyserver/addons/rust-node-addon/rust-binding-types.js @@ -1,27 +1,28 @@ // @flow import type { SignedIdentityKeysBlob } from 'lib/types/crypto-types.js'; type tunnelbrokerOnReceiveCallback = ( err: Error | null, payload: string, ) => mixed; declare class TunnelbrokerClientClass { constructor( deviceId: string, onReceiveCallback: tunnelbrokerOnReceiveCallback, ): TunnelbrokerClientClass; publish(toDeviceId: string, payload: string): Promise; } type RustNativeBindingAPI = { +registerUser: ( username: string, password: string, signedIdentityKeysBlob: SignedIdentityKeysBlob, ) => Promise, + +addReservedUsername: (message: string, signature: string) => Promise, +TunnelbrokerClient: Class, }; export type { RustNativeBindingAPI }; diff --git a/keyserver/addons/rust-node-addon/src/identity_client/add_reserved_username.rs b/keyserver/addons/rust-node-addon/src/identity_client/add_reserved_username.rs new file mode 100644 index 000000000..8e6d6cfaa --- /dev/null +++ b/keyserver/addons/rust-node-addon/src/identity_client/add_reserved_username.rs @@ -0,0 +1,23 @@ +use super::*; + +#[napi] +#[instrument(skip_all)] +pub async fn add_reserved_username( + message: String, + signature: String, +) -> Result<()> { + // Set up the gRPC client that will be used to talk to the Identity service + let channel = get_identity_service_channel().await?; + let mut identity_client = IdentityClientServiceClient::new(channel); + + let add_reserved_username_request = + AddReservedUsernameRequest { message, signature }; + + identity_client + .add_reserved_username(add_reserved_username_request) + .await + .map_err(|_| Error::from_status(Status::GenericFailure))? + .into_inner(); + + Ok(()) +} diff --git a/keyserver/addons/rust-node-addon/src/identity_client/mod.rs b/keyserver/addons/rust-node-addon/src/identity_client/mod.rs index 7c3cc3387..633c4ad24 100644 --- a/keyserver/addons/rust-node-addon/src/identity_client/mod.rs +++ b/keyserver/addons/rust-node-addon/src/identity_client/mod.rs @@ -1,61 +1,62 @@ +pub mod add_reserved_username; pub mod register_user; pub mod identity_client { tonic::include_proto!("identity.client"); } use identity_client::identity_client_service_client::IdentityClientServiceClient; use identity_client::{ - DeviceKeyUpload, IdentityKeyInfo, RegistrationFinishRequest, - RegistrationStartRequest, + AddReservedUsernameRequest, DeviceKeyUpload, IdentityKeyInfo, + RegistrationFinishRequest, RegistrationStartRequest, }; use lazy_static::lazy_static; use napi::bindgen_prelude::*; use serde::{Deserialize, Serialize}; use std::env::var; use tonic::{metadata::MetadataValue, transport::Channel, Request}; use tracing::instrument; lazy_static! { static ref IDENTITY_SERVICE_CONFIG: IdentityServiceConfig = { let config_json_string = var("COMM_JSONCONFIG_secrets_identity_service_config"); match config_json_string { Ok(json) => serde_json::from_str(&json).unwrap(), Err(_) => IdentityServiceConfig::default(), } }; } #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] struct IdentityServiceConfig { identity_socket_addr: String, identity_auth_token: String, } impl Default for IdentityServiceConfig { fn default() -> Self { Self { identity_socket_addr: "https://[::1]:50054".to_string(), identity_auth_token: "test".to_string(), } } } async fn get_identity_service_channel() -> Result { Channel::from_static(&IDENTITY_SERVICE_CONFIG.identity_socket_addr) .connect() .await .map_err(|_| { Error::new( Status::GenericFailure, "Unable to connect to identity service".to_string(), ) }) } #[napi(object)] pub struct SignedIdentityKeysBlob { pub payload: String, pub signature: String, }