-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
90 lines (76 loc) · 2.35 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
declare module "safety-socket" {
/**
* Manages WebSocket connections and provides encryption, decryption, and other utilities.
*/
class SocketManager {
/**
* Creates a new SocketManager instance.
* @param clientApiKey - The client's API key.
*/
constructor(clientApiKey: string);
/**
* Connects to the WebSocket server.
* @returns Resolves to true if connected successfully.
*/
connect(): Promise<boolean>;
/**
* Closes the WebSocket connection and resets the event listeners.
* @returns Resolves when the socket is killed.
*/
kill(): Promise<void>;
/**
* Adds an event listener for a custom event.
* @param t - Event name.
* @param e - Event handler.
*/
on(t: string, e: (event: Event) => void): void;
/**
* Sends encrypted data to a peer.
* @param peerId - The peer's ID.
* @param dataString - The data to send.
*/
send(peerId: string, dataString: string): Promise<void>;
/**
* Gets the ID of the current socket instance.
* @returns The ID.
*/
readonly id: string;
/**
* Sets or gets the manual secret.
*/
manualSecret: string;
/**
* Checks if a secret exists for a given peer.
* @param peerId - The peer's ID.
* @returns Resolves to true if the secret exists.
*/
getSecretStatus(peerId: string): Promise<boolean>;
/**
* Creates a new secret for a given peer.
* @param peerId - The peer's ID.
* @returns Resolves to the created secret.
*/
makeSecret(peerId: string): Promise<string>;
/**
* Sets a secret for a peer.
* @param peerSecret - The secret to set.
* @returns Resolves when the secret is set.
*/
setSecret(peerSecret: string): Promise<void>;
}
/**
* Provides a safety layer over the SocketManager.
*/
export class SafetySocket {
/**
* Instance of SocketManager.
*/
manager: SocketManager;
/**
* Loads the SafetySocket and initializes the SocketManager.
* @param clientApiKey - The client's API key.
* @returns Resolves when the manager is loaded.
*/
load(clientApiKey: string): Promise<void>;
}
}