diff --git a/keyserver/addons/rust-node-addon/rust-binding-types.js b/keyserver/addons/rust-node-addon/rust-binding-types.js --- a/keyserver/addons/rust-node-addon/rust-binding-types.js +++ b/keyserver/addons/rust-node-addon/rust-binding-types.js @@ -44,6 +44,13 @@ notifPrekey: string, notifPrekeySignature: string, ) => Promise, + +uploadOneTimeKeys: ( + userId: string, + deviceId: string, + accessToken: string, + contentOneTimePreKeys: $ReadOnlyArray, + notifOneTimePreKeys: $ReadOnlyArray, + ) => Promise, }; export type { RustNativeBindingAPI }; 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 @@ -4,6 +4,7 @@ pub mod prekey; pub mod register_user; pub mod remove_reserved_usernames; +pub mod upload_one_time_keys; pub mod identity_client { tonic::include_proto!("identity.client"); } diff --git a/keyserver/addons/rust-node-addon/src/identity_client/upload_one_time_keys.rs b/keyserver/addons/rust-node-addon/src/identity_client/upload_one_time_keys.rs new file mode 100644 --- /dev/null +++ b/keyserver/addons/rust-node-addon/src/identity_client/upload_one_time_keys.rs @@ -0,0 +1,40 @@ +use super::*; + +use identity_client::UploadOneTimeKeysRequest; +use tracing::{debug, error}; + +#[napi] +#[instrument(skip_all)] +pub async fn upload_one_time_keys( + user_id: String, + device_id: String, + access_token: String, + content_one_time_pre_keys: Vec, + notif_one_time_pre_keys: Vec, +) -> bool { + let channel = match get_identity_service_channel().await { + Ok(c) => c, + Err(e) => { + error!( + "Error when attempting to connection identity service: {}", + e + ); + return false; + } + }; + + let mut identity_client = IdentityClientServiceClient::new(channel); + + let upload_request = UploadOneTimeKeysRequest { + user_id, + device_id, + access_token, + content_one_time_pre_keys, + notif_one_time_pre_keys, + }; + + debug!("Sending one time keys to identity service"); + let result = identity_client.upload_one_time_keys(upload_request).await; + + result.is_ok() +}