@simplito/privmx-webendpoint 2.2.9 → 2.3.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 (45) hide show
  1. package/FinalizationHelper.d.ts +18 -0
  2. package/FinalizationHelper.js +49 -0
  3. package/Types.d.ts +77 -21
  4. package/Types.js +3 -0
  5. package/api/ApiStatic.d.ts +16 -0
  6. package/api/ApiStatic.js +26 -0
  7. package/api/ConnectionNative.d.ts +7 -1
  8. package/api/ConnectionNative.js +24 -0
  9. package/api/CryptoApiNative.d.ts +14 -0
  10. package/api/CryptoApiNative.js +30 -0
  11. package/api/EventApiNative.d.ts +20 -0
  12. package/api/EventApiNative.js +36 -0
  13. package/api/ExtKeyNative.d.ts +23 -0
  14. package/api/ExtKeyNative.js +66 -0
  15. package/assets/driver-web-context.js +1 -1
  16. package/assets/endpoint-wasm-module.js +1 -1
  17. package/assets/endpoint-wasm-module.wasm +0 -0
  18. package/bundle/privmx-endpoint-web.js +1 -1
  19. package/extra/PrivmxClient.d.ts +133 -0
  20. package/extra/PrivmxClient.js +271 -0
  21. package/extra/PublicConnection.d.ts +70 -0
  22. package/extra/PublicConnection.js +118 -0
  23. package/extra/events.d.ts +2 -2
  24. package/extra/inbox.d.ts +3 -3
  25. package/extra/inbox.js +1 -1
  26. package/extra/index.d.ts +10 -8
  27. package/extra/index.js +6 -1
  28. package/index.d.ts +2 -2
  29. package/index.js +2 -1
  30. package/package.json +5 -1
  31. package/service/Connection.d.ts +27 -1
  32. package/service/Connection.js +29 -0
  33. package/service/CryptoApi.d.ts +48 -1
  34. package/service/CryptoApi.js +59 -1
  35. package/service/EndpointFactory.d.ts +9 -0
  36. package/service/EndpointFactory.js +24 -0
  37. package/service/EventApi.d.ts +40 -0
  38. package/service/EventApi.js +60 -0
  39. package/service/ExtKey.d.ts +103 -0
  40. package/service/ExtKey.js +167 -0
  41. package/service/UserVerifierInterface.d.ts +18 -0
  42. package/service/UserVerifierInterface.js +2 -0
  43. package/service/index.d.ts +2 -1
  44. package/service/index.js +3 -1
  45. package/assets/privmx-endpoint-web.js +0 -2
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PublicConnection = void 0;
4
+ const _1 = require(".");
5
+ const service_1 = require("../service");
6
+ /**
7
+ * @class PublicConnection
8
+ * @classdesc A client for interacting with the PrivMX Endpoint API as a guest. The scope is limited to sending an entries to inboxes.
9
+ * @example
10
+ * // Initialize the PrivMX client
11
+ * await PrivmxClient.setup('/path/to/privmx/assets');
12
+ *
13
+ * // Connect to the PrivMX bridge
14
+ * const solutionId = 'your-solution-id';
15
+ * const bridgeUrl = 'https://your-bridge-url.com';
16
+ * const inboxId = 'your-inbox-id'
17
+ * const client = await PrivmxClient.connectPublic(solutionId, bridgeUrl);
18
+ *
19
+ * // Send entry
20
+ * const encoder = new TextEncoder();
21
+ * const encodedData = encoder.encode(JSON.stringify({ message: 'Hello, PrivMX!' }));
22
+ *
23
+ * await client.sendEntry(inboxId, {
24
+ * data: encodedData
25
+ * })
26
+ *
27
+ * // Disconnect when done
28
+ * await client.disconnect();
29
+ */
30
+ class PublicConnection {
31
+ connection;
32
+ threadApi = null;
33
+ storeApi = null;
34
+ inboxApi = null;
35
+ /**
36
+ * @constructor
37
+ * @param {Connection} connection - The connection object.
38
+ */
39
+ constructor(connection) {
40
+ this.connection = connection;
41
+ }
42
+ /**
43
+ * @description Gets the connection object.
44
+ * @returns {Connection}
45
+ * @throws {Error} If there is no active connection.
46
+ */
47
+ getConnection() {
48
+ if (!this.connection) {
49
+ throw new Error('No active connection');
50
+ }
51
+ return this.connection;
52
+ }
53
+ /**
54
+ * @description Gets the Thread API.
55
+ * @returns {Promise<ThreadApi>}
56
+ */
57
+ getThreadApi() {
58
+ if (!this.threadApi) {
59
+ this.threadApi = (() => {
60
+ const connection = this.getConnection();
61
+ return service_1.EndpointFactory.createThreadApi(connection);
62
+ })();
63
+ }
64
+ return this.threadApi;
65
+ }
66
+ /**
67
+ * @description Gets the Store API.
68
+ * @returns {Promise<StoreApi>}
69
+ */
70
+ getStoreApi() {
71
+ if (!this.storeApi) {
72
+ this.storeApi = (async () => {
73
+ const connection = this.getConnection();
74
+ return service_1.EndpointFactory.createStoreApi(connection);
75
+ })();
76
+ }
77
+ return this.storeApi;
78
+ }
79
+ /**
80
+ * @description Gets the Inbox API.
81
+ * @returns {Promise<InboxApi>}
82
+ */
83
+ getInboxApi() {
84
+ if (!this.inboxApi) {
85
+ this.inboxApi = (async () => {
86
+ const connection = this.getConnection();
87
+ return service_1.EndpointFactory.createInboxApi(connection, await this.getThreadApi(), await this.getStoreApi());
88
+ })();
89
+ }
90
+ return this.inboxApi;
91
+ }
92
+ /**
93
+ * @description Disconnects from the PrivMX bridge.
94
+ * @returns {Promise<void>}
95
+ */
96
+ async disconnect() {
97
+ try {
98
+ await this.connection.disconnect();
99
+ this.threadApi = null;
100
+ this.storeApi = null;
101
+ this.inboxApi = null;
102
+ }
103
+ catch (e) {
104
+ console.error('Error during disconnection:', e);
105
+ }
106
+ }
107
+ /**
108
+ * @description Sends an entry to the specified inbox.
109
+ * @param {string} inboxId - The ID of the inbox to send the entry to.
110
+ * @param {InboxEntryPayload} payload - The payload of the entry to send.
111
+ * @returns {Promise<void>}
112
+ */
113
+ async sendEntry(inboxId, payload) {
114
+ const inboxApi = await this.getInboxApi();
115
+ return await _1.Inboxes.sendEntry(inboxApi, inboxId, payload);
116
+ }
117
+ }
118
+ exports.PublicConnection = PublicConnection;
package/extra/events.d.ts CHANGED
@@ -33,7 +33,7 @@ export interface EventPayload {
33
33
  threadId: string;
34
34
  };
35
35
  threadNewMessage: Types.Message;
36
- threadMessageUpdated: Types.Message;
36
+ threadUpdatedMessage: Types.Message;
37
37
  threadMessageDeleted: {
38
38
  threadId: string;
39
39
  messageId: string;
@@ -76,7 +76,7 @@ type EventHandler<E extends keyof EventPayload> = {
76
76
  event: E;
77
77
  callback: (event: GenericEvent<E>) => void;
78
78
  };
79
- export type OnMessageEventHandler = EventHandler<'threadMessageDeleted'> | EventHandler<'threadNewMessage'> | EventHandler<'threadMessageUpdated'>;
79
+ export type OnMessageEventHandler = EventHandler<'threadMessageDeleted'> | EventHandler<'threadNewMessage'> | EventHandler<'threadUpdatedMessage'>;
80
80
  export type OnThreadEventHandler = EventHandler<'threadCreated'> | EventHandler<'threadDeleted'> | EventHandler<'threadUpdated'> | EventHandler<'threadStatsChanged'>;
81
81
  export type OnFileEventHandler = EventHandler<'storeFileDeleted'> | EventHandler<'storeFileCreated'> | EventHandler<'storeFileUpdated'>;
82
82
  export type OnStoreEventHandler = EventHandler<'storeCreated'> | EventHandler<'storeStatsChanged'> | EventHandler<'storeUpdated'> | EventHandler<'storeDeleted'>;
package/extra/inbox.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Endpoint } from '..';
1
+ import { InboxApi } from '..';
2
2
  /**
3
3
  * Represents payload that is sent to an Inbox.
4
4
  */
@@ -28,11 +28,11 @@ export interface InboxEntryPayload {
28
28
  /**
29
29
  * Sends an entry to the specified inbox.
30
30
  *
31
- * @param {Awaited<ReturnType<typeof Endpoint.createInboxApi>>} inboxApi - The API instance used to interact with the inbox.
31
+ * @param {InboxApi} inboxApi - The API instance used to interact with the inbox.
32
32
  * @param {string} inboxId - The ID of the target inbox where the entry will be sent.
33
33
  * @param {InboxEntryPayload} payload - The data payload for the inbox entry, including files, metadata, and other information.
34
34
  *
35
35
  * @returns {Promise<void>} A promise that resolves when the entry has been successfully sent.
36
36
  *
37
37
  */
38
- export declare function sendEntry(inboxApi: Awaited<ReturnType<typeof Endpoint.createInboxApi>>, inboxId: string, payload: InboxEntryPayload): Promise<void>;
38
+ export declare function sendEntry(inboxApi: InboxApi, inboxId: string, payload: InboxEntryPayload): Promise<void>;
package/extra/inbox.js CHANGED
@@ -5,7 +5,7 @@ const files_1 = require("./files");
5
5
  /**
6
6
  * Sends an entry to the specified inbox.
7
7
  *
8
- * @param {Awaited<ReturnType<typeof Endpoint.createInboxApi>>} inboxApi - The API instance used to interact with the inbox.
8
+ * @param {InboxApi} inboxApi - The API instance used to interact with the inbox.
9
9
  * @param {string} inboxId - The ID of the target inbox where the entry will be sent.
10
10
  * @param {InboxEntryPayload} payload - The data payload for the inbox entry, including files, metadata, and other information.
11
11
  *
package/extra/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- import * as Files from "./files";
2
- import * as Events from "./events";
3
- import { EventManager, ThreadEventsManager, StoreEventsManager, InboxEventsManager, BaseEventManager } from "./events";
4
- import * as Utils from "./utils";
5
- import * as Generics from "./generics";
6
- import * as Inboxes from "./inbox";
7
- import { FileUploader, StreamReader, downloadFile } from "./files";
8
- export { Files, Inboxes, Events, Utils, Generics, FileUploader, downloadFile, EventManager, ThreadEventsManager, StoreEventsManager, InboxEventsManager, BaseEventManager, StreamReader };
1
+ import * as Files from './files';
2
+ import * as Events from './events';
3
+ import { EventManager, ThreadEventsManager, StoreEventsManager, InboxEventsManager, BaseEventManager, ConnectionEventsManager, Channel, EventPayload, GenericEvent } from './events';
4
+ import * as Utils from './utils';
5
+ import * as Generics from './generics';
6
+ import * as Inboxes from './inbox';
7
+ import { FileUploader, StreamReader, downloadFile } from './files';
8
+ import { PrivmxClient } from './PrivmxClient';
9
+ import { PublicConnection } from './PublicConnection';
10
+ export { Files, Inboxes, Events, Utils, Generics, FileUploader, downloadFile, EventManager, ThreadEventsManager, StoreEventsManager, InboxEventsManager, BaseEventManager, StreamReader, PrivmxClient, PublicConnection, Channel, ConnectionEventsManager, EventPayload, GenericEvent, };
package/extra/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StreamReader = exports.BaseEventManager = exports.InboxEventsManager = exports.StoreEventsManager = exports.ThreadEventsManager = exports.EventManager = exports.downloadFile = exports.FileUploader = exports.Generics = exports.Utils = exports.Events = exports.Inboxes = exports.Files = void 0;
3
+ exports.ConnectionEventsManager = exports.PublicConnection = exports.PrivmxClient = exports.StreamReader = exports.BaseEventManager = exports.InboxEventsManager = exports.StoreEventsManager = exports.ThreadEventsManager = exports.EventManager = exports.downloadFile = exports.FileUploader = exports.Generics = exports.Utils = exports.Events = exports.Inboxes = exports.Files = void 0;
4
4
  const Files = require("./files");
5
5
  exports.Files = Files;
6
6
  const Events = require("./events");
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "ThreadEventsManager", { enumerable: true, get: f
11
11
  Object.defineProperty(exports, "StoreEventsManager", { enumerable: true, get: function () { return events_1.StoreEventsManager; } });
12
12
  Object.defineProperty(exports, "InboxEventsManager", { enumerable: true, get: function () { return events_1.InboxEventsManager; } });
13
13
  Object.defineProperty(exports, "BaseEventManager", { enumerable: true, get: function () { return events_1.BaseEventManager; } });
14
+ Object.defineProperty(exports, "ConnectionEventsManager", { enumerable: true, get: function () { return events_1.ConnectionEventsManager; } });
14
15
  const Utils = require("./utils");
15
16
  exports.Utils = Utils;
16
17
  const Generics = require("./generics");
@@ -21,3 +22,7 @@ const files_1 = require("./files");
21
22
  Object.defineProperty(exports, "FileUploader", { enumerable: true, get: function () { return files_1.FileUploader; } });
22
23
  Object.defineProperty(exports, "StreamReader", { enumerable: true, get: function () { return files_1.StreamReader; } });
23
24
  Object.defineProperty(exports, "downloadFile", { enumerable: true, get: function () { return files_1.downloadFile; } });
25
+ const PrivmxClient_1 = require("./PrivmxClient");
26
+ Object.defineProperty(exports, "PrivmxClient", { enumerable: true, get: function () { return PrivmxClient_1.PrivmxClient; } });
27
+ const PublicConnection_1 = require("./PublicConnection");
28
+ Object.defineProperty(exports, "PublicConnection", { enumerable: true, get: function () { return PublicConnection_1.PublicConnection; } });
package/index.d.ts CHANGED
@@ -9,6 +9,6 @@ See the License for the specific language governing permissions and
9
9
  limitations under the License.
10
10
  */
11
11
  import { EndpointFactory } from "./service/EndpointFactory";
12
- import { EventQueue, StoreApi, ThreadApi, InboxApi, Connection, CryptoApi, BaseApi } from "./service";
12
+ import { EventQueue, StoreApi, ThreadApi, InboxApi, Connection, CryptoApi, BaseApi, ExtKey } from "./service";
13
13
  import * as Types from "./Types";
14
- export { EndpointFactory as Endpoint, Types, EventQueue, StoreApi, ThreadApi, InboxApi, CryptoApi, Connection, BaseApi, };
14
+ export { EndpointFactory as Endpoint, Types, EventQueue, StoreApi, ThreadApi, InboxApi, CryptoApi, Connection, BaseApi, ExtKey };
package/index.js CHANGED
@@ -10,7 +10,7 @@ See the License for the specific language governing permissions and
10
10
  limitations under the License.
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.BaseApi = exports.Connection = exports.CryptoApi = exports.InboxApi = exports.ThreadApi = exports.StoreApi = exports.EventQueue = exports.Types = exports.Endpoint = void 0;
13
+ exports.ExtKey = exports.BaseApi = exports.Connection = exports.CryptoApi = exports.InboxApi = exports.ThreadApi = exports.StoreApi = exports.EventQueue = exports.Types = exports.Endpoint = void 0;
14
14
  const EndpointFactory_1 = require("./service/EndpointFactory");
15
15
  Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return EndpointFactory_1.EndpointFactory; } });
16
16
  const service_1 = require("./service");
@@ -21,5 +21,6 @@ Object.defineProperty(exports, "InboxApi", { enumerable: true, get: function ()
21
21
  Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return service_1.Connection; } });
22
22
  Object.defineProperty(exports, "CryptoApi", { enumerable: true, get: function () { return service_1.CryptoApi; } });
23
23
  Object.defineProperty(exports, "BaseApi", { enumerable: true, get: function () { return service_1.BaseApi; } });
24
+ Object.defineProperty(exports, "ExtKey", { enumerable: true, get: function () { return service_1.ExtKey; } });
24
25
  const Types = require("./Types");
25
26
  exports.Types = Types;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplito/privmx-webendpoint",
3
- "version": "2.2.9",
3
+ "version": "2.3.0",
4
4
  "description": "PrivMX Web Endpoint library",
5
5
  "author": "Simplito",
6
6
  "license": "PrivMX Free License",
@@ -32,6 +32,10 @@
32
32
  "type": "commonjs",
33
33
  "main": "index.js",
34
34
  "types": "index.d.ts",
35
+ "exports": {
36
+ ".": "./index.js",
37
+ "./extra": "./extra/index.js"
38
+ },
35
39
  "scripts": {
36
40
  "test": "echo \"Error: no test specified\" && exit 1",
37
41
  "compile": "tsc",
@@ -10,15 +10,22 @@ limitations under the License.
10
10
  */
11
11
  import { BaseApi } from "./BaseApi";
12
12
  import { ConnectionNative } from "../api/ConnectionNative";
13
- import { PagingQuery, PagingList, Context } from "../Types";
13
+ import { PagingQuery, PagingList, Context, UserInfo } from "../Types";
14
14
  import { BaseNative } from "../api/BaseNative";
15
+ import { UserVerifierInterface } from "./UserVerifierInterface";
15
16
  export declare class Connection extends BaseApi {
16
17
  private native;
18
+ /**
19
+ * //doc-gen:ignore
20
+ */
17
21
  apisRefs: {
18
22
  [apiId: string]: {
19
23
  _apiServicePtr: number;
20
24
  };
21
25
  };
26
+ /**
27
+ * //doc-gen:ignore
28
+ */
22
29
  nativeApisDeps: {
23
30
  [apiId: string]: BaseNative;
24
31
  };
@@ -36,10 +43,29 @@ export declare class Connection extends BaseApi {
36
43
  * @returns {PagingList<Context>} struct containing a list of Contexts
37
44
  */
38
45
  listContexts(pagingQuery: PagingQuery): Promise<PagingList<Context>>;
46
+ /**
47
+ * Gets a list of users of given context.
48
+ *
49
+ * @param contextId ID of the Context
50
+ *
51
+ * @returns a list of the UserInfo objects
52
+ */
53
+ getContextUsers(contextId: string): Promise<UserInfo[]>;
39
54
  /**
40
55
  * Disconnects from the Platform backend.
41
56
  *
42
57
  */
43
58
  disconnect(): Promise<void>;
59
+ /**
60
+ * Sets user's custom verification callback.
61
+ *
62
+ * The feature allows the developer to set up a callback for user verification.
63
+ * A developer can implement an interface and pass the implementation to the function.
64
+ * Each time data is read from the container, a callback will be triggered, allowing the developer to validate the sender in an external service,
65
+ * e.g. Developer's Application Server or PKI Server.
66
+ * @param verifier an implementation of the UserVerifierInterface
67
+ *
68
+ */
69
+ setUserVerifier(verifier: UserVerifierInterface): Promise<void>;
44
70
  private freeApis;
45
71
  }
@@ -14,7 +14,13 @@ exports.Connection = void 0;
14
14
  const BaseApi_1 = require("./BaseApi");
15
15
  class Connection extends BaseApi_1.BaseApi {
16
16
  native;
17
+ /**
18
+ * //doc-gen:ignore
19
+ */
17
20
  apisRefs = {};
21
+ /**
22
+ * //doc-gen:ignore
23
+ */
18
24
  nativeApisDeps = {};
19
25
  constructor(native, ptr) {
20
26
  super(ptr);
@@ -37,6 +43,16 @@ class Connection extends BaseApi_1.BaseApi {
37
43
  async listContexts(pagingQuery) {
38
44
  return this.native.listContexts(this.servicePtr, [pagingQuery]);
39
45
  }
46
+ /**
47
+ * Gets a list of users of given context.
48
+ *
49
+ * @param contextId ID of the Context
50
+ *
51
+ * @returns a list of the UserInfo objects
52
+ */
53
+ async getContextUsers(contextId) {
54
+ return this.native.getContextUsers(this.servicePtr, [contextId]);
55
+ }
40
56
  /**
41
57
  * Disconnects from the Platform backend.
42
58
  *
@@ -46,6 +62,19 @@ class Connection extends BaseApi_1.BaseApi {
46
62
  await this.freeApis();
47
63
  await this.native.deleteConnection(this.servicePtr);
48
64
  }
65
+ /**
66
+ * Sets user's custom verification callback.
67
+ *
68
+ * The feature allows the developer to set up a callback for user verification.
69
+ * A developer can implement an interface and pass the implementation to the function.
70
+ * Each time data is read from the container, a callback will be triggered, allowing the developer to validate the sender in an external service,
71
+ * e.g. Developer's Application Server or PKI Server.
72
+ * @param verifier an implementation of the UserVerifierInterface
73
+ *
74
+ */
75
+ setUserVerifier(verifier) {
76
+ return this.native.setUserVerifier(this.servicePtr, [this.servicePtr, verifier]);
77
+ }
49
78
  async freeApis() {
50
79
  for (const apiId in this.apisRefs) {
51
80
  if (this.nativeApisDeps[apiId]) {
@@ -10,6 +10,7 @@ limitations under the License.
10
10
  */
11
11
  import { BaseApi } from "./BaseApi";
12
12
  import { CryptoApiNative } from "../api/CryptoApiNative";
13
+ import { BIP39 } from "../Types";
13
14
  export declare class CryptoApi extends BaseApi {
14
15
  private native;
15
16
  constructor(native: CryptoApiNative, ptr: number);
@@ -51,7 +52,7 @@ export declare class CryptoApi extends BaseApi {
51
52
  *
52
53
  * @param {string} password the password used to generate the new key
53
54
  * @param {string} salt random string (additional input for the hashing function)
54
-
55
+
55
56
  * @returns {string} generated ECC key in WIF format
56
57
  */
57
58
  derivePrivateKey2(password: string, salt: string): Promise<string>;
@@ -89,4 +90,50 @@ export declare class CryptoApi extends BaseApi {
89
90
  * @returns {string} private key in WIF format
90
91
  */
91
92
  convertPEMKeytoWIFKey(pemKey: string): Promise<string>;
93
+ /**
94
+ * Generates ECC key and BIP-39 mnemonic from a password using BIP-39.
95
+ *
96
+ * @param {number} strength size of BIP-39 entropy, must be a multiple of 32
97
+ * @param {string} password the password used to generate the Key
98
+ * @returns {BIP39} object containing ECC Key and associated with it BIP-39 mnemonic and entropy
99
+ */
100
+ generateBip39(strength: number, password?: string): Promise<BIP39>;
101
+ /**
102
+ * Generates ECC key using BIP-39 mnemonic.
103
+ *
104
+ * @param {string} mnemonic the BIP-39 entropy used to generate the Key
105
+ * @param {string} password the password used to generate the Key
106
+ * @return BIP39_t object containing ECC Key and associated with it BIP-39 mnemonic and entropy
107
+ */
108
+ fromMnemonic(mnemonic: string, password?: string): Promise<BIP39>;
109
+ /**
110
+ * Generates ECC key using BIP-39 entropy.
111
+ *
112
+ * @param {Uint8Array} entropy the BIP-39 entropy used to generate the Key
113
+ * @param {string} password the password used to generate the Key
114
+ * @return {BIP39} object containing ECC Key and associated with it BIP-39 mnemonic and entropy
115
+ */
116
+ fromEntropy(entropy: Uint8Array, password?: string): Promise<BIP39>;
117
+ /**
118
+ * Converts BIP-39 entropy to mnemonic.
119
+ *
120
+ * @param {Uint8Array} entropy BIP-39 entropy
121
+ * @return {string} BIP-39 mnemonic
122
+ */
123
+ entropyToMnemonic(entropy: Uint8Array): Promise<string>;
124
+ /**
125
+ * Converts BIP-39 mnemonic to entropy.
126
+ *
127
+ * @param {string} mnemonic BIP-39 mnemonic
128
+ * @return {Uint8Array} BIP-39 entropy
129
+ */
130
+ mnemonicToEntropy(mnemonic: string): Promise<Uint8Array>;
131
+ /**
132
+ * Generates a seed used to generate a key using BIP-39 mnemonic with PBKDF2.
133
+ *
134
+ * @param {string} mnemonic BIP-39 mnemonic
135
+ * @param {string} password the password used to generate the seed
136
+ * @return {Uint8Array} generated seed
137
+ */
138
+ mnemonicToSeed(mnemonic: string, password?: string): Promise<Uint8Array>;
92
139
  }
@@ -64,7 +64,7 @@ class CryptoApi extends BaseApi_1.BaseApi {
64
64
  *
65
65
  * @param {string} password the password used to generate the new key
66
66
  * @param {string} salt random string (additional input for the hashing function)
67
-
67
+
68
68
  * @returns {string} generated ECC key in WIF format
69
69
  */
70
70
  async derivePrivateKey2(password, salt) {
@@ -120,5 +120,63 @@ class CryptoApi extends BaseApi_1.BaseApi {
120
120
  async convertPEMKeytoWIFKey(pemKey) {
121
121
  return this.native.convertPEMKeytoWIFKey(this.servicePtr, [pemKey]);
122
122
  }
123
+ /**
124
+ * Generates ECC key and BIP-39 mnemonic from a password using BIP-39.
125
+ *
126
+ * @param {number} strength size of BIP-39 entropy, must be a multiple of 32
127
+ * @param {string} password the password used to generate the Key
128
+ * @returns {BIP39} object containing ECC Key and associated with it BIP-39 mnemonic and entropy
129
+ */
130
+ async generateBip39(strength, password = "") {
131
+ return this.native.generateBip39(this.servicePtr, [strength, password]);
132
+ }
133
+ /**
134
+ * Generates ECC key using BIP-39 mnemonic.
135
+ *
136
+ * @param {string} mnemonic the BIP-39 entropy used to generate the Key
137
+ * @param {string} password the password used to generate the Key
138
+ * @return BIP39_t object containing ECC Key and associated with it BIP-39 mnemonic and entropy
139
+ */
140
+ async fromMnemonic(mnemonic, password = "") {
141
+ return this.native.fromMnemonic(this.servicePtr, [mnemonic, password]);
142
+ }
143
+ /**
144
+ * Generates ECC key using BIP-39 entropy.
145
+ *
146
+ * @param {Uint8Array} entropy the BIP-39 entropy used to generate the Key
147
+ * @param {string} password the password used to generate the Key
148
+ * @return {BIP39} object containing ECC Key and associated with it BIP-39 mnemonic and entropy
149
+ */
150
+ async fromEntropy(entropy, password = "") {
151
+ return this.native.fromEntropy(this.servicePtr, [entropy, password]);
152
+ }
153
+ /**
154
+ * Converts BIP-39 entropy to mnemonic.
155
+ *
156
+ * @param {Uint8Array} entropy BIP-39 entropy
157
+ * @return {string} BIP-39 mnemonic
158
+ */
159
+ async entropyToMnemonic(entropy) {
160
+ return this.native.entropyToMnemonic(this.servicePtr, [entropy]);
161
+ }
162
+ /**
163
+ * Converts BIP-39 mnemonic to entropy.
164
+ *
165
+ * @param {string} mnemonic BIP-39 mnemonic
166
+ * @return {Uint8Array} BIP-39 entropy
167
+ */
168
+ async mnemonicToEntropy(mnemonic) {
169
+ return this.native.mnemonicToEntropy(this.servicePtr, [mnemonic]);
170
+ }
171
+ /**
172
+ * Generates a seed used to generate a key using BIP-39 mnemonic with PBKDF2.
173
+ *
174
+ * @param {string} mnemonic BIP-39 mnemonic
175
+ * @param {string} password the password used to generate the seed
176
+ * @return {Uint8Array} generated seed
177
+ */
178
+ async mnemonicToSeed(mnemonic, password = "") {
179
+ return this.native.mnemonicToSeed(this.servicePtr, [mnemonic, password]);
180
+ }
123
181
  }
124
182
  exports.CryptoApi = CryptoApi;
@@ -10,6 +10,7 @@ limitations under the License.
10
10
  */
11
11
  import { Connection } from "./Connection";
12
12
  import { CryptoApi } from "./CryptoApi";
13
+ import { EventApi } from "./EventApi";
13
14
  import { EventQueue } from "./EventQueue";
14
15
  import { InboxApi } from "./InboxApi";
15
16
  import { StoreApi } from "./StoreApi";
@@ -86,4 +87,12 @@ export declare class EndpointFactory {
86
87
  * @returns {CryptoApi} instance of CryptoApi
87
88
  */
88
89
  static createCryptoApi(): Promise<CryptoApi>;
90
+ /**
91
+ * Creates an instance of 'EventApi'.
92
+ *
93
+ * @param connection instance of 'Connection'
94
+ *
95
+ * @returns {EventApi} instance of EventApi
96
+ */
97
+ static createEventApi(connection: Connection): Promise<EventApi>;
89
98
  }
@@ -12,14 +12,18 @@ limitations under the License.
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.EndpointFactory = void 0;
14
14
  const Api_1 = require("../api/Api");
15
+ const ApiStatic_1 = require("../api/ApiStatic");
15
16
  const ConnectionNative_1 = require("../api/ConnectionNative");
16
17
  const CryptoApiNative_1 = require("../api/CryptoApiNative");
18
+ const EventApiNative_1 = require("../api/EventApiNative");
17
19
  const EventQueueNative_1 = require("../api/EventQueueNative");
18
20
  const InboxApiNative_1 = require("../api/InboxApiNative");
19
21
  const StoreApiNative_1 = require("../api/StoreApiNative");
20
22
  const ThreadApiNative_1 = require("../api/ThreadApiNative");
23
+ const FinalizationHelper_1 = require("../FinalizationHelper");
21
24
  const Connection_1 = require("./Connection");
22
25
  const CryptoApi_1 = require("./CryptoApi");
26
+ const EventApi_1 = require("./EventApi");
23
27
  const EventQueue_1 = require("./EventQueue");
24
28
  const InboxApi_1 = require("./InboxApi");
25
29
  const StoreApi_1 = require("./StoreApi");
@@ -61,6 +65,8 @@ class EndpointFactory {
61
65
  */
62
66
  static init(lib) {
63
67
  this.api = new Api_1.Api(lib);
68
+ ApiStatic_1.ApiStatic.init(this.api);
69
+ FinalizationHelper_1.FinalizationHelper.init(lib);
64
70
  }
65
71
  /**
66
72
  * Gets the EventQueue instance.
@@ -169,5 +175,23 @@ class EndpointFactory {
169
175
  await nativeApi.create(ptr, []);
170
176
  return new CryptoApi_1.CryptoApi(nativeApi, ptr);
171
177
  }
178
+ /**
179
+ * Creates an instance of 'EventApi'.
180
+ *
181
+ * @param connection instance of 'Connection'
182
+ *
183
+ * @returns {EventApi} instance of EventApi
184
+ */
185
+ static async createEventApi(connection) {
186
+ if ("events" in connection.apisRefs) {
187
+ throw new Error("EventApi already registered for given connection.");
188
+ }
189
+ const nativeApi = new EventApiNative_1.EventApiNative(this.api);
190
+ const ptr = await nativeApi.newApi(connection.servicePtr);
191
+ connection.apisRefs["events"] = { _apiServicePtr: ptr };
192
+ connection.nativeApisDeps["events"] = nativeApi;
193
+ await nativeApi.create(ptr, []);
194
+ return new EventApi_1.EventApi(nativeApi, ptr);
195
+ }
172
196
  }
173
197
  exports.EndpointFactory = EndpointFactory;
@@ -0,0 +1,40 @@
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 { BaseApi } from "./BaseApi";
12
+ import { EventApiNative } from "../api/EventApiNative";
13
+ import { UserWithPubKey } from "../Types";
14
+ export declare class EventApi extends BaseApi {
15
+ private native;
16
+ constructor(native: EventApiNative, ptr: number);
17
+ /**
18
+ * Emits the custom event on the given Context and channel.
19
+ *
20
+ * @param {string} contextId ID of the Context
21
+ * @param {string} channelName name of the Channel
22
+ * @param {Uint8Array} eventData event's data
23
+ * @param {UserWithPubKey[]} users list of UserWithPubKey objects which defines the recipients of the event
24
+ */
25
+ emitEvent(contextId: string, channelName: string, eventData: Uint8Array, users: UserWithPubKey[]): Promise<void>;
26
+ /**
27
+ * Subscribe for the custom events on the given channel.
28
+ *
29
+ * @param {string} contextId ID of the Context
30
+ * @param {string} channelName name of the Channel
31
+ */
32
+ subscribeForCustomEvents(contextId: string, channelName: string): Promise<void>;
33
+ /**
34
+ * Unsubscribe from the custom events on the given channel.
35
+ *
36
+ * @param {string} contextId ID of the Context
37
+ * @param {string} channelName name of the Channel
38
+ */
39
+ unsubscribeFromCustomEvents(contextId: string, channelName: string): Promise<void>;
40
+ }