/
messaging.ts
330 lines (291 loc) · 6.79 KB
/
messaging.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/**
* Original work Copyright (c) 2020 Madfish Solutions
* Modified work Copyright (c) 2022 Signum Network
*/
/**
* @ignore
* @internal
*/
export type ExtensionMessage = ExtensionRequestArgs | ExtensionResponse;
/**
* @ignore
* @internal
*/
export type ExtensionRequestArgs =
| ExtensionGetCurrentPermissionRequest
| ExtensionPermissionRequest
| ExtensionSignRequest
| ExtensionSendEncryptedMessageRequest;
/**
* @ignore
* @internal
*/
export type ExtensionResponse =
| ExtensionGetCurrentPermissionResponse
| ExtensionPermissionResponse
| ExtensionSignResponse
| ExtensionSendEncryptedMessageResponse;
/**
* @ignore
* @internal
*/
interface ExtensionMessageBase {
type: ExtensionMessageType;
}
/**
* Request/Response Messages
*/
/**
* @ignore
* @internal
*/
export enum ExtensionMessageType {
GetCurrentPermissionRequest = 'GET_CURRENT_PERMISSION_REQUEST',
GetCurrentPermissionResponse = 'GET_CURRENT_PERMISSION_RESPONSE',
PermissionRequest = 'PERMISSION_REQUEST',
PermissionResponse = 'PERMISSION_RESPONSE',
SignRequest = 'SIGN_REQUEST',
SignResponse = 'SIGN_RESPONSE',
SendEncryptedMessageRequest = 'SEND_ENCRYPTED_MSG_REQUEST',
SendEncryptedMessageResponse = 'SEND_ENCRYPTED_MSG_RESPONSE'
}
/**
* @ignore
* @internal
*/
export interface ExtensionGetCurrentPermissionRequest
extends ExtensionMessageBase {
type: ExtensionMessageType.GetCurrentPermissionRequest;
}
/**
* @ignore
* @internal
*/
export interface ExtensionGetCurrentPermissionResponse
extends ExtensionMessageBase {
type: ExtensionMessageType.GetCurrentPermissionResponse;
permission: ExtensionPermission;
}
/**
* @ignore
* @internal
*/
export interface ExtensionPermissionRequest extends ExtensionMessageBase {
type: ExtensionMessageType.PermissionRequest;
network: string;
appMeta: ExtensionDAppMetadata;
force?: boolean;
}
/**
* @ignore
* @internal
*/
export interface ExtensionPermissionResponse extends ExtensionMessageBase {
type: ExtensionMessageType.PermissionResponse;
accountId: string;
publicKey: string;
availableNodeHosts: string[];
currentNodeHost: string;
}
/**
* @ignore
* @internal
*/
export interface ExtensionSignRequest extends ExtensionMessageBase {
type: ExtensionMessageType.SignRequest;
payload: string;
}
/**
* @ignore
* @internal
*/
export interface ExtensionSignResponse extends ExtensionMessageBase {
type: ExtensionMessageType.SignResponse;
transactionId: string;
fullHash: string;
}
/**
* @ignore
* @internal
*/
export interface ExtensionSendEncryptedMessageRequest extends ExtensionMessageBase {
type: ExtensionMessageType.SendEncryptedMessageRequest;
plainMessage: string;
messageIsText: boolean;
recipientPublicKey: string;
feeSigna?: string;
}
/**
* @ignore
* @internal
*/
export interface ExtensionSendEncryptedMessageResponse extends ExtensionMessageBase {
type: ExtensionMessageType.SendEncryptedMessageResponse;
transactionId: string;
fullHash: string;
}
/**
* @ignore
* @internal
*/
export enum ExtensionErrorType {
NotGranted = 'NOT_GRANTED',
NotFound = 'NOT_FOUND',
InvalidParams = 'INVALID_PARAMS',
InvalidNetwork = 'INVALID_NETWORK'
}
/**
* The permission object for a connection
* @module wallets
*/
export type ExtensionPermission = {
/**
* The currently selected node host in the extension
*/
currentNodeHost: string;
/**
* The currently available node hosts for the given network in the extension
*/
availableNodeHosts: string[];
/**
* The account id that is granted by this permission
*/
accountId: string;
/**
* The accounts public key that is granted by this permission
*/
publicKey: string;
} | null;
/**
* The response object for successfully signed transactions
* @module wallets
*/
export type ExtensionSigned = {
/**
* The transaction isd
*/
transactionId: string;
/**
* The transactions full hash
*/
fullHash: string;
} | null;
/**
* The response object for successfully sent encrypted messages
* @module wallets
*/
export type ExtensionSentEncryptedMessage = {
/**
* The transaction isd
*/
transactionId: string;
/**
* The transactions full hash
*/
fullHash: string;
} | null;
/**
* @ignore
* @internal
*/
export interface ExtensionDAppMetadata {
name: string;
}
/**
* @ignore
* @internal
*/
export interface PageMessage {
type: PageMessageType;
payload: any;
reqId?: string | number;
}
/**
* @ignore
* @internal
*/
export enum PageMessageType {
Request = 'SIGNUM_PAGE_REQUEST',
Response = 'SIGNUM_PAGE_RESPONSE',
ErrorResponse = 'SIGNUM_PAGE_ERROR_RESPONSE',
}
// Wallet Notifications
/**
* @ignore
* @internal
*/
export enum ExtensionNotificationType {
NetworkChanged= 'XT_DAPP_NETWORK_CHANGED',
AccountChanged= 'XT_DAPP_ACCOUNT_CHANGED',
PermissionRemoved= 'XT_DAPP_PERMISSION_REMOVED',
AccountRemoved= 'XT_DAPP_ACCOUNT_REMOVED',
}
/**
* @ignore
* @internal
*/
interface ExtensionNotificationBase {
type: ExtensionNotificationType;
}
/**
* The notification types
* @module wallets
*/
export type ExtensionNotification =
| ExtensionNotificationNetworkChanged
| ExtensionNotificationPermissionRemoved
| ExtensionNotificationAccountRemoved
| ExtensionNotificationAccountChanged;
/**
* The notification message structure for `onNetworkChanged` event
* @module wallets
*/
export interface ExtensionNotificationNetworkChanged
extends ExtensionNotificationBase {
type: ExtensionNotificationType.NetworkChanged;
/**
* The new network name
*/
networkName: string;
/**
* The new network host url
*/
networkHost: string;
}
/**
* The notification message structure for `onPermissionRemoved` event
* @module wallets
*/
export interface ExtensionNotificationPermissionRemoved
extends ExtensionNotificationBase {
type: ExtensionNotificationType.PermissionRemoved;
/**
* The url of the removed permission (representing the related application)
*/
url: string;
}
/**
* The notification message structure for `onPermissionRemoved` event
* @module wallets
*/
export interface ExtensionNotificationAccountRemoved
extends ExtensionNotificationBase {
type: ExtensionNotificationType.AccountRemoved;
/**
* The id of the account that was removed
*/
accountId: string;
}
/**
* The notification message structure for `onPermissionRemoved` event
* @module wallets
*/
export interface ExtensionNotificationAccountChanged
extends ExtensionNotificationBase {
type: ExtensionNotificationType.AccountChanged;
/**
* The id of the account that was removed
*/
accountId: string;
accountPublicKey: string;
}