This commit is contained in:
2026-08-16 06:34:14 +02:00
parent 158058e091
commit 350ced81e6
2 changed files with 70 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
export interface ClientMeta {}
export interface ServerMeta {
name: string;
description: string;
}
export type ClientMethod =
| {
method: "Initialized";
public_key: string;
signature: string;
timestamp: number;
hostname: string;
}
| {
method: "Error";
error: string;
};
export type ServerMethod =
| {
method: "Initialize";
public_key: string;
signature: string;
timestamp: number;
hostname: string;
}
| {
method: "Meta";
}
| {
method: "Error";
error: string;
};
+35
View File
@@ -0,0 +1,35 @@
import { ClientMethod, ServerMethod } from "./protocol";
export class EnclaveWebSocket {
public websocket: WebSocket;
onmessage: ((this: WebSocket, ev: MessageEvent) => any) | null;
public clientPublicKey: Uint8Array;
public clientSecretKey: Uint8Array;
public serverPublicKey: Uint8Array;
public constructor(url: string | URL) {
this.websocket = new WebSocket(url);
this.clientPublicKey = new Uint8Array();
this.clientSecretKey = new Uint8Array();
this.serverPublicKey = new Uint8Array();
this.onmessage = null;
}
public send(method: ServerMethod) {
this.websocket.send(JSON.stringify(method));
}
public async read(): Promise<ClientMethod> {
return new Promise((ok) => {
this.onmessage = (msg) => {
const data = JSON.parse(msg.data);
ok(data);
this.onmessage = null;
};
});
}
}