-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.d.ts
156 lines (139 loc) · 4.16 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
export function createMessageConnector(): GlobalInputMessageConnector;
interface ConnectResult {
type: "device" | "mobile" | "pairing" | "error";
connectionCode?: string;
codeData?: CodeData;
initData?: InitData;
permission?: PermissionResultMessage;
error?: string;
}
declare class GlobalInputMessageConnector {
client: string;
session: string;
isConnected(): boolean;
disconnect(): void;
setCodeAES(codeAES: string): void;
setSecurityGroup(securityGroup: string): void;
connect(opts: ConnectOptions, encryptedCode?: string): Promise<ConnectResult>;
sendInputMessage(value: FieldValue, index?: number, fieldId?: string): void;
sendValue(fieldId: string | null | undefined, value: FieldValue, index?: number): void;
sendInitData(initData: InitData): void;
buildOptionsFromInputCodedata(codedata: CodeData, options?: ConnectOptions): ConnectOptions;
buildInputCodeData(data?: CodeData): string;
buildPairingData(data?: CodeData): string;
processCodeData(encryptedCodeData?: string, options?: CodeProcessors): void;
/*
encryptedCodeData=[Type][EncryptedContent]
switch(Type):
case 'C': use the static shared encryption key to decrypt.
case 'A': use the dynamic encryption key to decrypt.
case 'N': the content is not encrypted
*/
}
type FieldValue = string | number | object | null | undefined;
export interface Sender {
client: string;
session: string;
}
interface ConnectOptions {
initData?: InitData;
url?: string;
apikey?: string;
securityGroup?: string;
connectSession?: string;
aes?: string;
onInput?: (message: InputMessage) => void;
onRegistered?: (connectionCode: string) => void;
onRegisterFailed?: () => void;
onSenderConnected?: (sender: Sender, senders: Sender[]) => void;
onSenderDisconnected?: (sender: Sender, senders: Sender[]) => void;
onInputPermission?: (permissionMessage: PermissionRequestMessage, senders: Sender[], allow: () => void, deny: (reason?: string) => void) => void;
onInputPermissionResult?: (message: PermissionResultMessage) => void;
onInputCodeData?: (codedata: CodeData) => void;
onError?: (message: string) => void;
onSocket?:(socket: any) => void;
}
interface InputMessage {
client: string;
data: {
value: FieldValue;
index?: number;
id?: number;
fieldId: string;
};
initData?: InitData;
}
interface CodeProcessors {
onInputCodeData?: (codedata: CodeData) => void;
onPairing?: (codedata: CodeData) => void;
onError?: (message: string) => void;
}
interface InitData {
id?: string;
action?: string;
dataType?: string;
key?: string;
form: {
id?: string;
title?: string;
label?: string;
domain?: string;
fields: FormField[];
views?: {
viewIds: {
[id: string]: object;
}
};
}
}
interface FormField {
id?: string;
type?: string;
label?: string;
value?: FieldValue;
nLines?: number;
icon?: string;
viewId?: string;
iconText?: string | object;
operations?: FormOperation;
options?: object[];
index?: number;
minimumValue?: number;
maximumValue?: number;
step?: number;
items?: object[];
selectType?: string;
style?: object;
}
interface FormOperation {
onInput: (value: FieldValue) => void;
}
interface PermissionResultMessage {
allow: boolean;
client?: string;
connectSession?: string;
initData?: InitData;
securityGroup?: string;
session?: string;
reason?: string;
}
interface PermissionRequestMessage {
client?: string;
connectSession?: string;
data?: object;
time?: number;
securityGroup?: string;
session?: string;
}
interface CodeData {
session?: string;
url?: string;
aes?: string;
apikey?: string;
securityGroup?: string;
action?: string;
codeAES?: string;
}
export function generateRandomString(length?: number): string;
export function encrypt(content: string, password: string): string;
export function decrypt(content: string, password: string): string;