@simplito/privmx-webendpoint 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/Types.d.ts +407 -0
  2. package/Types.js +27 -0
  3. package/api/Api.d.ts +20 -0
  4. package/api/Api.js +48 -0
  5. package/api/BaseNative.d.ts +20 -0
  6. package/api/BaseNative.js +35 -0
  7. package/api/ConnectionNative.d.ts +24 -0
  8. package/api/ConnectionNative.js +51 -0
  9. package/api/CryptoApiNative.d.ts +25 -0
  10. package/api/CryptoApiNative.js +54 -0
  11. package/api/EventQueueNative.d.ts +20 -0
  12. package/api/EventQueueNative.js +37 -0
  13. package/api/IdGenerator.d.ts +14 -0
  14. package/api/IdGenerator.js +21 -0
  15. package/api/InboxApiNative.d.ts +38 -0
  16. package/api/InboxApiNative.js +90 -0
  17. package/api/StoreApiNative.d.ts +37 -0
  18. package/api/StoreApiNative.js +87 -0
  19. package/api/ThreadApiNative.d.ts +31 -0
  20. package/api/ThreadApiNative.js +69 -0
  21. package/assets/endpoint-wasm-module.js +20 -0
  22. package/{webAssets → assets}/endpoint-wasm-module.wasm +0 -0
  23. package/bundle/privmx-endpoint-web.js +2 -0
  24. package/bundle/privmx-endpoint-web.js.LICENSE.txt +10 -0
  25. package/bundle.d.ts +12 -0
  26. package/bundle.js +16 -0
  27. package/extra/__tests__/__mocks__/constants.d.ts +36 -0
  28. package/extra/__tests__/__mocks__/constants.js +42 -0
  29. package/extra/__tests__/__mocks__/mockContainerSubscriber.d.ts +12 -0
  30. package/extra/__tests__/__mocks__/mockContainerSubscriber.js +25 -0
  31. package/extra/__tests__/__mocks__/mockEventAPIs.d.ts +30 -0
  32. package/extra/__tests__/__mocks__/mockEventAPIs.js +70 -0
  33. package/extra/__tests__/__mocks__/mockEventQueue.d.ts +13 -0
  34. package/extra/__tests__/__mocks__/mockEventQueue.js +45 -0
  35. package/extra/__tests__/__mocks__/utils.d.ts +8 -0
  36. package/extra/__tests__/__mocks__/utils.js +21 -0
  37. package/extra/__tests__/eventsManager.test.d.ts +1 -0
  38. package/extra/__tests__/eventsManager.test.js +73 -0
  39. package/extra/__tests__/inboxEventManager.test.d.ts +1 -0
  40. package/extra/__tests__/inboxEventManager.test.js +56 -0
  41. package/extra/__tests__/storeEventManager.test.d.ts +1 -0
  42. package/extra/__tests__/storeEventManager.test.js +56 -0
  43. package/extra/__tests__/threadEventManager.test.d.ts +1 -0
  44. package/extra/__tests__/threadEventManager.test.js +60 -0
  45. package/extra/__tests__/utils.test.d.ts +1 -0
  46. package/extra/__tests__/utils.test.js +52 -0
  47. package/extra/events.d.ts +234 -0
  48. package/extra/events.js +270 -0
  49. package/extra/files.d.ts +120 -0
  50. package/extra/files.js +216 -0
  51. package/extra/generics.d.ts +19 -0
  52. package/extra/generics.js +2 -0
  53. package/extra/inbox.d.ts +38 -0
  54. package/extra/inbox.js +35 -0
  55. package/extra/index.d.ts +8 -0
  56. package/extra/index.js +23 -0
  57. package/extra/utils.d.ts +24 -0
  58. package/extra/utils.js +68 -0
  59. package/index.d.ts +14 -0
  60. package/index.js +25 -0
  61. package/package.json +45 -3
  62. package/service/BaseApi.d.ts +16 -0
  63. package/service/BaseApi.js +29 -0
  64. package/service/Connection.d.ts +45 -0
  65. package/service/Connection.js +57 -0
  66. package/service/CryptoApi.d.ts +83 -0
  67. package/service/CryptoApi.js +113 -0
  68. package/service/EndpointFactory.d.ts +89 -0
  69. package/service/EndpointFactory.js +173 -0
  70. package/service/EventQueue.d.ts +20 -0
  71. package/service/EventQueue.js +37 -0
  72. package/service/InboxApi.d.ts +183 -0
  73. package/service/InboxApi.js +262 -0
  74. package/service/StoreApi.d.ts +170 -0
  75. package/service/StoreApi.js +246 -0
  76. package/service/ThreadApi.d.ts +124 -0
  77. package/service/ThreadApi.js +186 -0
  78. package/service/index.d.ts +9 -0
  79. package/service/index.js +19 -0
  80. package/README.md +0 -13
  81. package/webAssets/LICENSE.md +0 -76
  82. package/webAssets/endpoint-wasm-module.js +0 -20
  83. package/webAssets/privmx-endpoint-web.js +0 -2
  84. /package/{webAssets → assets}/driver-web-context.js +0 -0
  85. /package/{webAssets → assets}/endpoint-wasm-module.worker.js +0 -0
package/Types.d.ts ADDED
@@ -0,0 +1,407 @@
1
+ /*!
2
+ PrivMX Web Endpoint.
3
+ Copyright © 2024 Simplito sp. z o.o.
4
+
5
+ This file is part of the PrivMX Platform (https://privmx.dev).
6
+ This software is Licensed under the PrivMX Free License.
7
+
8
+ See the License for the specific language governing permissions and
9
+ limitations under the License.
10
+ */
11
+ export type SortOrder = "desc" | "asc";
12
+ /**
13
+ * Holds Event details
14
+ *
15
+ * @type {Event}
16
+ *
17
+ * @param {string} type event type
18
+ * @param {string} channel channel
19
+ * @param {number} connectionId id of source connection
20
+ *
21
+ */
22
+ export interface Event {
23
+ type: string;
24
+ channel: string;
25
+ connectionId: number;
26
+ data?: unknown;
27
+ }
28
+ /**
29
+ * Contains query parameters for methods returning lists (PagingList)
30
+ *
31
+ * @type {PagingQuery}
32
+ *
33
+ * @param {number} skip number of elements to skip from result
34
+ * @param {number} limit limit of elements to return for query
35
+ * @param {SortOrder} sortOrder Order of elements in result. Use "asc" for ascending, "desc" for descening.
36
+ * @param {string} [lastId] id of the element from which query results should start
37
+ *
38
+ */
39
+ export interface PagingQuery {
40
+ skip: number;
41
+ limit: number;
42
+ sortOrder: SortOrder;
43
+ lastId?: string;
44
+ }
45
+ /**
46
+ * Contains results of listing methods
47
+ *
48
+ * @type {PagingList<T>}
49
+ *
50
+ * @param {number} totalAvailable total items available to get
51
+ * @param {T[]} readItems list of items read during single method call
52
+ *
53
+ */
54
+ export interface PagingList<T> {
55
+ totalAvailable: number;
56
+ readItems: T[];
57
+ }
58
+ /**
59
+ * Contains base Context information
60
+ *
61
+ * @type {Context}
62
+ *
63
+ * @param {string} userId ID of user requesting information
64
+ * @param {string} contextId ID of context
65
+ *
66
+ */
67
+ export interface Context {
68
+ userId: string;
69
+ contextId: string;
70
+ }
71
+ /**
72
+ * Contains ID of user and the corresponding public key
73
+ *
74
+ * @type {UserWithPubKey}
75
+ *
76
+ * @param {string} userId ID of the user
77
+ * @param {string} pubKey user's public key
78
+ *
79
+ */
80
+ export interface UserWithPubKey {
81
+ userId: string;
82
+ pubKey: string;
83
+ }
84
+ /**
85
+ * Holds all available information about a Thread.
86
+ *
87
+ * @type {Thread}
88
+ *
89
+ * @param {string} contextId ID of the Context
90
+ * @param {string} threadId ID ot the Thread
91
+ * @param {number} createDate Thread creation timestamp
92
+ * @param {string} author ID of the user who created the Thread
93
+ * @param {number} lastModificationDate Thread last modification timestamp
94
+ * @param {string} lastModifier ID of the user who last modified the Thread
95
+ * @param {string[]} users list of users (their IDs) with access to the Thread
96
+ * @param {string[]} managers list of users (their IDs) with management rights
97
+ * @param {number} version version number (changes on updates)
98
+ * @param {number} lastMsgDate timestamp of last posted message
99
+ * @param {Uint8Array} publicMeta Thread's public meta data
100
+ * @param {Uint8Array} privateMeta Thread's private mata data
101
+ * @param {ContainerPolicy} policy Thread's policies
102
+ * @param {number} messagesCount total number of messages in the Thread
103
+ * @param {number} statusCode status code of retrival and decryption of the Thread
104
+ *
105
+ */
106
+ export interface Thread {
107
+ contextId: string;
108
+ threadId: string;
109
+ createDate: number;
110
+ creator: string;
111
+ lastModificationDate: number;
112
+ lastModifier: string;
113
+ users: string[];
114
+ managers: string[];
115
+ version: number;
116
+ lastMsgDate: number;
117
+ publicMeta: Uint8Array;
118
+ privateMeta: Uint8Array;
119
+ policy: ContainerPolicy;
120
+ messagesCount: number;
121
+ statusCode: number;
122
+ }
123
+ /**
124
+ * Holds information about the Message.
125
+ *
126
+ * @type {Message}
127
+ *
128
+ * @param {ServerMessageInfo} info message's information created by server
129
+ * @param {Uint8Array} publicMeta message's public meta data
130
+ * @param {Uint8Array} privateMeta message's private mata data
131
+ * @param {Uint8Array} data message's data
132
+ * @param {string} authorPubKey public key of an author of the message
133
+ * @param {number} statusCode status code of retrival and decryption of the message
134
+ *
135
+ */
136
+ export interface Message {
137
+ info: ServerMessageInfo;
138
+ publicMeta: Uint8Array;
139
+ privateMeta: Uint8Array;
140
+ data: Uint8Array;
141
+ authorPubKey: string;
142
+ statusCode: number;
143
+ }
144
+ /**
145
+ * Holds message's information created by server
146
+ *
147
+ * @type {ServerMessageInfo}
148
+ *
149
+ * @param {string} threadId ID of the Thread
150
+ * @param {string} messageId ID of the message
151
+ * @param {number} createDate message's creation timestamp
152
+ * @param {string} author ID of the user who created the message
153
+ *
154
+ */
155
+ export interface ServerMessageInfo {
156
+ threadId: string;
157
+ messageId: string;
158
+ createDate: number;
159
+ author: string;
160
+ }
161
+ /**
162
+ * Holds all available information about a Store.
163
+ *
164
+ * @type {Store}
165
+ *
166
+ * @param {string} storeId ID ot the Store
167
+ * @param {string} contextId ID of the Context
168
+ * @param {number} createDate Store creation timestamp
169
+ * @param {string} creator ID of user who created the Store
170
+ * @param {number} lastModificationDate Thread last modification timestamp
171
+ * @param {number} lastFileDate timestamp of last created file
172
+ * @param {string} lastModifier ID of the user who last modified the Store
173
+ * @param {string[]} users list of users (their IDs) with access to the Store
174
+ * @param {string[]} managers list of users (their IDs) with management rights
175
+ * @param {number} version version number (changes on updates)
176
+ * @param {Uint8Array} publicMeta Store's public meta data
177
+ * @param {Uint8Array} privateMeta Store's private mata data
178
+ * @param {ContainerPolicy} policy Store's policies
179
+ * @param {number} filesCount total number of files in the Store
180
+ * @param {number} statusCode status code of retrival and decryption of the Store
181
+ *
182
+ */
183
+ export interface Store {
184
+ storeId: string;
185
+ contextId: string;
186
+ createDate: number;
187
+ creator: string;
188
+ lastModificationDate: number;
189
+ lastFileDate: number;
190
+ lastModifier: string;
191
+ users: string[];
192
+ managers: string[];
193
+ version: number;
194
+ publicMeta: Uint8Array;
195
+ privateMeta: Uint8Array;
196
+ policy: ContainerPolicy;
197
+ filesCount: number;
198
+ statusCode: number;
199
+ }
200
+ /**
201
+ * Holds information about the file.
202
+ *
203
+ * @type {File}
204
+ *
205
+ * @param {ServerFileInfo} info file's information created by server
206
+ * @param {Uint8Array} publicMeta file's public meta data
207
+ * @param {Uint8Array} privateMeta file's private mata data
208
+ * @param {number} size file's size
209
+ * @param {string} authorPubKey public key of an author of the file
210
+ * @param {number} tatusCode status code of retrival and decryption of the file
211
+ *
212
+ */
213
+ export interface File {
214
+ info: ServerFileInfo;
215
+ publicMeta: Uint8Array;
216
+ privateMeta: Uint8Array;
217
+ size: number;
218
+ authorPubKey: string;
219
+ statusCode: number;
220
+ }
221
+ /**
222
+ * Holds file's information created by server
223
+ *
224
+ * @type {ServerFileInfo}
225
+ *
226
+ * @param {string} storeId ID of the Store
227
+ * @param {string} fileId ID of the file
228
+ * @param {number} createDate file's creation timestamp
229
+ * @param {string} author ID of the user who created the file
230
+ *
231
+ */
232
+ export interface ServerFileInfo {
233
+ storeId: string;
234
+ fileId: string;
235
+ createDate: number;
236
+ author: string;
237
+ }
238
+ /**
239
+ * Holds all available information about an Inbox.
240
+ *
241
+ * @type {Inbox}
242
+ *
243
+ * @param {string} inboxId ID ot the Inbox
244
+ * @param {string} contextId ID of the Context
245
+ * @param {number} createDate Inbox creation timestamp
246
+ * @param {string} creator ID of user who created the Inbox
247
+ * @param {number} lastModificationDate Inbox last modification timestamp
248
+ * @param {string} lastModifier ID of the user who last modified the Inbox
249
+ * @param {string[]} users list of users (their IDs) with access to the Inbox
250
+ * @param {string[]} managers list of users (their IDs) with management rights
251
+ * @param {number} version version number (changes on updates)
252
+ * @param {Uint8Array} publicMeta Inbox' public meta data
253
+ * @param {Uint8Array} privateMeta Inbox' private mata data
254
+ * @param {FilesConfig} filesConfig Inbox' files configuration
255
+ * @param {ContainerWithoutItemPolicy} policy Inbox' policies
256
+ * @param {number} statusCode status code of retrival and decryption of the Inbox
257
+ *
258
+ */
259
+ export interface Inbox {
260
+ inboxId: string;
261
+ contextId: string;
262
+ createDate: number;
263
+ creator: string;
264
+ lastModificationDate: number;
265
+ lastModifier: string;
266
+ users: string[];
267
+ managers: string[];
268
+ version: number;
269
+ publicMeta: Uint8Array;
270
+ privateMeta: Uint8Array;
271
+ filesConfig?: FilesConfig;
272
+ policy: ContainerWithoutItemPolicy;
273
+ statusCode: number;
274
+ }
275
+ /**
276
+ * Holds Inbox' public information
277
+ *
278
+ * @type {InboxPublicView}
279
+ *
280
+ * @param {string} inboxId ID of the Inbox
281
+ * @param {number} version version of the Inbox
282
+ * @param {Uint8Array} publicMeta Inbox' public meta data
283
+ *
284
+ */
285
+ export interface InboxPublicView {
286
+ inboxId: string;
287
+ version: number;
288
+ publicMeta: Uint8Array;
289
+ }
290
+ /**
291
+ * Holds information about Inbox' entry
292
+ *
293
+ * @type {InboxEntry}
294
+ *
295
+ * @param {string} entryId ID of the entry
296
+ * @param {string} inboxId ID of the Inbox
297
+ * @param {Uint8Array} data entry data
298
+ * @param {File[]} files list of files attached to the entry
299
+ * @param {string} authorPubKey public key of the author of an entry
300
+ * @param {number} createDate Inbox entry creation timestamp
301
+ * @param {number} statusCode status code of retrival and decryption of the Inbox entry
302
+ */
303
+ export interface InboxEntry {
304
+ entryId: string;
305
+ inboxId: string;
306
+ data: Uint8Array;
307
+ files: File[];
308
+ authorPubKey: string;
309
+ createDate: number;
310
+ statusCode: number;
311
+ }
312
+ /**
313
+ * Holds Inbox files configuration
314
+ *
315
+ * @type {FilesConfig}
316
+ *
317
+ * @param {int64_t} minCount minimum numer of files required when sending inbox entry
318
+ * @param {int64_t} maxCount maximum numer of files allowed when sending inbox entry
319
+ * @param {int64_t} maxFileSize maximum file size allowed when sending inbox entry
320
+ * @param {int64_t} maxWholeUploadSize maximum size of all files in total allowed when sending inbox entry
321
+ *
322
+ */
323
+ export interface FilesConfig {
324
+ minCount: number;
325
+ maxCount: number;
326
+ maxFileSize: number;
327
+ maxWholeUploadSize: number;
328
+ }
329
+ /**
330
+ * Holds Container policies settings
331
+ *
332
+ * @type {ContainerWithoutItemPolicy}
333
+ *
334
+ * @param {PolicyEntry} get determine who can get a container
335
+ * @param {PolicyEntry} update determine who can update a container
336
+ * @param {PolicyEntry} delete determine who can delete a container
337
+ * @param {PolicyEntry} updatePolicy determine who can update the policy of a container
338
+ * @param {PolicyBooleanEntry} updaterCanBeRemovedFromManagers determine whether the updater can be removed from the list of managers
339
+ * @param {PolicyBooleanEntry} ownerCanBeRemovedFromManagers determine whether the owner can be removed from the list of managers
340
+ */
341
+ export interface ContainerWithoutItemPolicy {
342
+ get?: PolicyEntry;
343
+ update?: PolicyEntry;
344
+ delete?: PolicyEntry;
345
+ updatePolicy?: PolicyEntry;
346
+ updaterCanBeRemovedFromManagers?: PolicyBooleanEntry;
347
+ ownerCanBeRemovedFromManagers?: PolicyBooleanEntry;
348
+ }
349
+ /**
350
+ * Holds Container policies settings
351
+ *
352
+ * @type {ContainerPolicy}
353
+ *
354
+ * @param {ItemPolicy} item item policies
355
+ */
356
+ export interface ContainerPolicy extends ContainerWithoutItemPolicy {
357
+ item?: ItemPolicy;
358
+ }
359
+ /**
360
+ * @type {PolicyEntry}
361
+ */
362
+ export type PolicyEntry = "inherit" | "yes" | "no" | "default" | "none" | "all" | "user" | "owner" | "manager" | "itemOwner" | "itemOwner&user" | "itemOwner&user,manager" | "owner&user" | "manager&owner" | "itemOwner,manager" | "itemOwner,owner" | "itemOwner,manager,owner" | "manager,owner" | (string & {
363
+ __policyEntry: never;
364
+ });
365
+ /**
366
+ * @type {PolicyBooleanEntry}
367
+ */
368
+ export type PolicyBooleanEntry = "inherit" | "default" | "yes" | "no";
369
+ /**
370
+ * Holds Container's item policies settings
371
+ *
372
+ * @type {ContainerWithoutItemPolicy}
373
+ *
374
+ * @param {PolicyEntry} get determine who can get an item
375
+ * @param {PolicyEntry} listMy determine who can list items created by me
376
+ * @param {PolicyEntry} listAll determine who can list all items
377
+ * @param {PolicyEntry} create determine who can create an item
378
+ * @param {PolicyEntry} update determine who can update an item
379
+ * @param {PolicyEntry} delete determine who can delete an item
380
+ */
381
+ export interface ItemPolicy {
382
+ get?: PolicyEntry;
383
+ listMy?: PolicyEntry;
384
+ listAll?: PolicyEntry;
385
+ create?: PolicyEntry;
386
+ update?: PolicyEntry;
387
+ delete?: PolicyEntry;
388
+ }
389
+ /**
390
+ * Holds error details
391
+ *
392
+ * @type {Error}
393
+ *
394
+ * @param {number} code error code
395
+ * @param {string} name error name
396
+ * @param {string} scope error scope
397
+ * @param {string} description error description
398
+ * @param {string} full all available data about the error
399
+ *
400
+ */
401
+ export interface Error {
402
+ code: number;
403
+ name: string;
404
+ scope: string;
405
+ description: string;
406
+ full: string;
407
+ }
package/Types.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /*!
3
+ PrivMX Web Endpoint.
4
+ Copyright © 2024 Simplito sp. z o.o.
5
+
6
+ This file is part of the PrivMX Platform (https://privmx.dev).
7
+ This software is Licensed under the PrivMX Free License.
8
+
9
+ See the License for the specific language governing permissions and
10
+ limitations under the License.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ ;
14
+ ;
15
+ ;
16
+ ;
17
+ ;
18
+ ;
19
+ ;
20
+ ;
21
+ ;
22
+ ;
23
+ ;
24
+ ;
25
+ ;
26
+ ;
27
+ ;
package/api/Api.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ /*!
2
+ PrivMX Web Endpoint.
3
+ Copyright © 2024 Simplito sp. z o.o.
4
+
5
+ This file is part of the PrivMX Platform (https://privmx.dev).
6
+ This software is Licensed under the PrivMX Free License.
7
+
8
+ See the License for the specific language governing permissions and
9
+ limitations under the License.
10
+ */
11
+ export declare class Api {
12
+ lib: any;
13
+ private promises;
14
+ private taskIdGenerator;
15
+ constructor(lib: any);
16
+ runAsync<T>(func: (taskId: number) => void): Promise<T>;
17
+ private resolveResult;
18
+ private generateId;
19
+ private setResultsCallback;
20
+ }
package/api/Api.js ADDED
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /*!
3
+ PrivMX Web Endpoint.
4
+ Copyright © 2024 Simplito sp. z o.o.
5
+
6
+ This file is part of the PrivMX Platform (https://privmx.dev).
7
+ This software is Licensed under the PrivMX Free License.
8
+
9
+ See the License for the specific language governing permissions and
10
+ limitations under the License.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.Api = void 0;
14
+ const IdGenerator_1 = require("./IdGenerator");
15
+ class Api {
16
+ lib;
17
+ promises;
18
+ taskIdGenerator;
19
+ constructor(lib) {
20
+ this.lib = lib;
21
+ this.taskIdGenerator = new IdGenerator_1.IdGenerator();
22
+ this.promises = new Map();
23
+ this.setResultsCallback();
24
+ }
25
+ async runAsync(func) {
26
+ return new Promise((resolve, reject) => {
27
+ const taskId = this.generateId();
28
+ this.promises.set(taskId, { resolve, reject });
29
+ func(taskId);
30
+ });
31
+ }
32
+ resolveResult(result) {
33
+ if (result.status == true) {
34
+ this.promises.get(result.taskId).resolve(result.result);
35
+ }
36
+ else {
37
+ this.promises.get(result.taskId).reject(result.error);
38
+ }
39
+ this.promises.delete(result.taskId);
40
+ }
41
+ generateId() {
42
+ return this.taskIdGenerator.generateId();
43
+ }
44
+ setResultsCallback() {
45
+ this.lib.setResultsCallback((result) => this.resolveResult(result));
46
+ }
47
+ }
48
+ exports.Api = Api;
@@ -0,0 +1,20 @@
1
+ /*!
2
+ PrivMX Web Endpoint.
3
+ Copyright © 2024 Simplito sp. z o.o.
4
+
5
+ This file is part of the PrivMX Platform (https://privmx.dev).
6
+ This software is Licensed under the PrivMX Free License.
7
+
8
+ See the License for the specific language governing permissions and
9
+ limitations under the License.
10
+ */
11
+ import { Api } from "./Api";
12
+ export declare abstract class BaseNative {
13
+ protected _api: Api | null;
14
+ constructor(api: Api);
15
+ get api(): Api;
16
+ protected abstract newApi(connectionPtr: number, ...apisPtrs: number[]): Promise<number>;
17
+ abstract deleteApi(ptr: number): Promise<void>;
18
+ protected deleteApiRef(): void;
19
+ protected runAsync<T>(func: (taskId: number) => void): Promise<T>;
20
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ /*!
3
+ PrivMX Web Endpoint.
4
+ Copyright © 2024 Simplito sp. z o.o.
5
+
6
+ This file is part of the PrivMX Platform (https://privmx.dev).
7
+ This software is Licensed under the PrivMX Free License.
8
+
9
+ See the License for the specific language governing permissions and
10
+ limitations under the License.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.BaseNative = void 0;
14
+ class BaseNative {
15
+ _api;
16
+ constructor(api) {
17
+ this._api = api;
18
+ }
19
+ get api() {
20
+ if (!this._api) {
21
+ throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");
22
+ }
23
+ return this._api;
24
+ }
25
+ deleteApiRef() {
26
+ this._api = null;
27
+ }
28
+ async runAsync(func) {
29
+ if (!this.api) {
30
+ throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");
31
+ }
32
+ return this.api.runAsync(func);
33
+ }
34
+ }
35
+ exports.BaseNative = BaseNative;
@@ -0,0 +1,24 @@
1
+ /*!
2
+ PrivMX Web Endpoint.
3
+ Copyright © 2024 Simplito sp. z o.o.
4
+
5
+ This file is part of the PrivMX Platform (https://privmx.dev).
6
+ This software is Licensed under the PrivMX Free License.
7
+
8
+ See the License for the specific language governing permissions and
9
+ limitations under the License.
10
+ */
11
+ import { PagingQuery, PagingList, Context } from "../Types";
12
+ import { BaseNative } from "./BaseNative";
13
+ export declare class ConnectionNative extends BaseNative {
14
+ protected lastConnectionId: number;
15
+ protected newApi(_connectionPtr: number): Promise<number>;
16
+ deleteApi(ptr: number): Promise<void>;
17
+ newConnection(): Promise<number>;
18
+ deleteConnection(ptr: number): Promise<void>;
19
+ connect(ptr: number, args: [string, string, string]): Promise<void>;
20
+ connectPublic(ptr: number, args: [string, string]): Promise<void>;
21
+ getConnectionId(ptr: number, args: []): Promise<number>;
22
+ listContexts(ptr: number, args: [PagingQuery]): Promise<PagingList<Context>>;
23
+ disconnect(ptr: number, args: []): Promise<void>;
24
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /*!
3
+ PrivMX Web Endpoint.
4
+ Copyright © 2024 Simplito sp. z o.o.
5
+
6
+ This file is part of the PrivMX Platform (https://privmx.dev).
7
+ This software is Licensed under the PrivMX Free License.
8
+
9
+ See the License for the specific language governing permissions and
10
+ limitations under the License.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.ConnectionNative = void 0;
14
+ const BaseNative_1 = require("./BaseNative");
15
+ class ConnectionNative extends BaseNative_1.BaseNative {
16
+ lastConnectionId = -1;
17
+ async newApi(_connectionPtr) {
18
+ throw new Error("Use the newConnection() - specialized version of method instead.");
19
+ }
20
+ async deleteApi(ptr) {
21
+ await this.runAsync((taskId) => this.api.lib.Connection_deleteConnection(taskId, ptr));
22
+ this.deleteApiRef();
23
+ }
24
+ async newConnection() {
25
+ return this.runAsync((taskId) => this.api.lib.Connection_newConnection(taskId));
26
+ }
27
+ async deleteConnection(ptr) {
28
+ await this.runAsync((taskId) => this.api.lib.Connection_deleteConnection(taskId, ptr));
29
+ this.deleteApiRef();
30
+ }
31
+ async connect(ptr, args) {
32
+ await this.runAsync((taskId) => this.api.lib.Connection_connect(taskId, ptr, args));
33
+ await this.getConnectionId(ptr, []);
34
+ }
35
+ async connectPublic(ptr, args) {
36
+ return this.runAsync((taskId) => this.api.lib.Connection_connectPublic(taskId, ptr, args));
37
+ }
38
+ async getConnectionId(ptr, args) {
39
+ if (this.lastConnectionId < 0) {
40
+ this.lastConnectionId = await this.runAsync((taskId) => this.api.lib.Connection_getConnectionId(taskId, ptr, args));
41
+ }
42
+ return this.lastConnectionId;
43
+ }
44
+ async listContexts(ptr, args) {
45
+ return this.runAsync((taskId) => this.api.lib.Connection_listContexts(taskId, ptr, args));
46
+ }
47
+ async disconnect(ptr, args) {
48
+ await this.runAsync((taskId) => this.api.lib.Connection_disconnect(taskId, ptr, args));
49
+ }
50
+ }
51
+ exports.ConnectionNative = ConnectionNative;
@@ -0,0 +1,25 @@
1
+ /*!
2
+ PrivMX Web Endpoint.
3
+ Copyright © 2024 Simplito sp. z o.o.
4
+
5
+ This file is part of the PrivMX Platform (https://privmx.dev).
6
+ This software is Licensed under the PrivMX Free License.
7
+
8
+ See the License for the specific language governing permissions and
9
+ limitations under the License.
10
+ */
11
+ import { BaseNative } from "./BaseNative";
12
+ export declare class CryptoApiNative extends BaseNative {
13
+ newApi(): Promise<number>;
14
+ deleteApi(ptr: number): Promise<void>;
15
+ create(ptr: number, args: []): Promise<void>;
16
+ signData(ptr: number, args: [Uint8Array, string]): Promise<Uint8Array>;
17
+ generatePrivateKey(ptr: number, args: [string | undefined]): Promise<string>;
18
+ derivePrivateKey(ptr: number, args: [string, string]): Promise<string>;
19
+ derivePrivateKey2(ptr: number, args: [string, string]): Promise<string>;
20
+ derivePublicKey(ptr: number, args: [string]): Promise<string>;
21
+ generateKeySymmetric(ptr: number, args: []): Promise<Uint8Array>;
22
+ encryptDataSymmetric(ptr: number, args: [Uint8Array, Uint8Array]): Promise<Uint8Array>;
23
+ decryptDataSymmetric(ptr: number, args: [Uint8Array, Uint8Array]): Promise<Uint8Array>;
24
+ convertPEMKeytoWIFKey(ptr: number, args: [string]): Promise<string>;
25
+ }