Page MenuHomePhabricator

D6690.id22714.diff
No OneTemporary

D6690.id22714.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
@@ -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<string>,
-};
+const { platform, arch } = process;
-async function getRustAPI(): Promise<RustAPI> {
+async function getRustAPI(): Promise<RustNativeBindingAPI> {
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<void>;
+}
+
+type RustNativeBindingAPI = {
+ +registerUser: (
+ userId: string,
+ deviceId: string,
+ username: string,
+ password: string,
+ userPublicKey: string,
+ ) => Promise<string>,
+ +TunnelbrokerClient: (
+ deviceId: string,
+ onReceiveCallback: tunnelBrokerOnReceiveCallback,
+ ) => TunnelbrokerClientClass,
+};
+
+export type { RustNativeBindingAPI };

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 5:07 PM (20 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2678099
Default Alt Text
D6690.id22714.diff (1 KB)

Event Timeline