Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3245878
D6690.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D6690.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 15, 8:32 PM (22 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2495364
Default Alt Text
D6690.diff (2 KB)
Attached To
Mode
D6690: [keyserver] Unifying API interface and adding Tunnelbroker types
Attached
Detach File
Event Timeline
Log In to Comment