Page MenuHomePhabricator

D6690.id23137.diff
No OneTemporary

D6690.id23137.diff

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
@@ -3,24 +3,15 @@
import invariant from 'invariant';
import { createRequire } from 'module';
+import type { RustNativeBindingAPI } from 'lib/types/rust-binding-types.js';
+
const { platform, arch } = process;
const importMetaURL = import.meta.url;
invariant(importMetaURL, 'import.meta.url should be set');
const require = createRequire(importMetaURL);
-type RustAPI = {
- +registerUser: (
- userId: string,
- deviceId: string,
- username: string,
- password: string,
- userPublicKey: string,
- ) => Promise<string>,
- +deleteUser: (userId: string) => Promise<boolean>,
-};
-
-async function getRustAPI(): Promise<RustAPI> {
+async function getRustAPI(): Promise<RustNativeBindingAPI> {
let nativeBinding = null;
if (platform === 'darwin' && arch === 'x64') {
// $FlowFixMe
@@ -39,11 +30,10 @@
}
if (!nativeBinding) {
- throw new Error('Failed to load native binding');
+ throw new Error('Failed to load Rust native binding');
}
- const { registerUser, deleteUser } = nativeBinding;
- return { registerUser, deleteUser };
+ return nativeBinding;
}
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,28 @@
+// @flow
+
+type tunnelbrokerOnReceiveCallback = (
+ err: Error | null,
+ payload: string,
+) => mixed;
+
+declare class TunnelbrokerClientClass {
+ constructor(
+ deviceId: string,
+ onReceiveCallback: tunnelbrokerOnReceiveCallback,
+ ): TunnelbrokerClientClass;
+ publish(toDeviceId: string, payload: string): Promise<void>;
+}
+
+type RustNativeBindingAPI = {
+ +registerUser: (
+ userId: string,
+ deviceId: string,
+ username: string,
+ password: string,
+ userPublicKey: string,
+ ) => Promise<string>,
+ +deleteUser: (userId: string) => Promise<boolean>,
+ +TunnelbrokerClient: Class<TunnelbrokerClientClass>,
+};
+
+export type { RustNativeBindingAPI };

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 6:04 PM (20 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2678268
Default Alt Text
D6690.id23137.diff (2 KB)

Event Timeline