diff --git a/keyserver/addons/opaque-ke-node/src/lib.rs b/keyserver/addons/opaque-ke-node/src/lib.rs --- a/keyserver/addons/opaque-ke-node/src/lib.rs +++ b/keyserver/addons/opaque-ke-node/src/lib.rs @@ -8,7 +8,8 @@ use opaque_ke::hash::Hash; use opaque_ke::slow_hash::SlowHash; use opaque_ke::{ - ClientRegistration, ClientRegistrationFinishParameters, RegistrationRequest, + ClientLogin, ClientLoginStartParameters, ClientRegistration, + ClientRegistrationFinishParameters, CredentialRequest, RegistrationRequest, RegistrationResponse, RegistrationUpload, }; use rand::rngs::OsRng; @@ -50,6 +51,13 @@ impl Finalize for ClientRegistrationFinishResult {} +struct ClientLoginStartResult { + message: CredentialRequest, + state: ClientLogin, +} + +impl Finalize for ClientLoginStartResult {} + fn client_register_start( mut cx: FunctionContext, ) -> JsResult> { @@ -126,6 +134,48 @@ )) } +fn client_login_start( + mut cx: FunctionContext, +) -> JsResult> { + let password = cx.argument::(0)?; + let mut client_rng = OsRng; + let client_login = ClientLogin::::start( + &mut client_rng, + password.value(&mut cx).as_bytes(), + ClientLoginStartParameters::default(), + ) + .or_else(|err| cx.throw_error(err.to_string()))?; + Ok(cx.boxed(ClientLoginStartResult { + message: client_login.message, + state: client_login.state, + })) +} + +fn get_login_start_message_array( + mut cx: FunctionContext, +) -> JsResult { + let client_login_start_result = + cx.argument::>(0)?; + let login_start_message_vec = + client_login_start_result + .message + .serialize() + .or_else(|err| cx.throw_error(err.to_string()))?; + Ok(JsArrayBuffer::external(&mut cx, login_start_message_vec)) +} + +fn get_login_start_state_array( + mut cx: FunctionContext, +) -> JsResult { + let client_login_start_result = + cx.argument::>(0)?; + let login_start_message_vec = client_login_start_result + .state + .serialize() + .or_else(|err| cx.throw_error(err.to_string()))?; + Ok(JsArrayBuffer::external(&mut cx, login_start_message_vec)) +} + #[neon::main] fn main(mut cx: ModuleContext) -> NeonResult<()> { cx.export_function("clientRegisterStart", client_register_start)?; @@ -142,5 +192,11 @@ "getRegistrationFinishMessageArray", get_registration_finish_message_array, )?; + cx.export_function("clientLoginStart", client_login_start)?; + cx.export_function( + "getLoginStartMessageArray", + get_login_start_message_array, + )?; + cx.export_function("getLoginStartStateArray", get_login_start_state_array)?; Ok(()) }