diff --git a/keyserver/addons/rust-node-addon/index.js b/keyserver/addons/rust-node-addon/index.js --- a/keyserver/addons/rust-node-addon/index.js +++ b/keyserver/addons/rust-node-addon/index.js @@ -1,18 +1,10 @@ // @flow -const { platform, arch } = process; +import type { RustNativeBindingAPI } from '../../src/lib/types/rust-binding-types.js'; -type RustAPI = { - +registerUser: ( - userId: string, - deviceId: string, - username: string, - password: string, - userPublicKey: string, - ) => Promise, -}; +const { platform, arch } = process; -async function getRustAPI(): Promise { +async function getRustAPI(): Promise { let nativeBinding = null; if (platform === 'darwin' && arch === 'x64') { // $FlowFixMe @@ -31,11 +23,10 @@ } if (!nativeBinding) { - throw new Error('Failed to load native binding'); + throw new Error('Failed to load Rust native binding'); } - const { registerUser } = nativeBinding.default; - return { registerUser }; + return nativeBinding.default; } export { getRustAPI }; diff --git a/lib/types/rust-binding-types.js b/lib/types/rust-binding-types.js new file mode 100644 --- /dev/null +++ b/lib/types/rust-binding-types.js @@ -0,0 +1,30 @@ +// @flow + +type tunnelBrokerOnReceiveCallback = ( + err: Error | null, + payload: string, +) => any; + +interface TunnelbrokerClientClass { + new( + deviceId: string, + onReceiveCallback: tunnelBrokerOnReceiveCallback, + ): TunnelbrokerClientClass; + publish(toDeviceId: string, payload: string): Promise; +} + +type RustNativeBindingAPI = { + +registerUser: ( + userId: string, + deviceId: string, + username: string, + password: string, + userPublicKey: string, + ) => Promise, + +TunnelbrokerClient: ( + deviceId: string, + onReceiveCallback: tunnelBrokerOnReceiveCallback, + ) => TunnelbrokerClientClass, +}; + +export type { RustNativeBindingAPI };