@simplito/privmx-webendpoint 2.2.9 → 2.5.1
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.
- package/FinalizationHelper.d.ts +18 -0
- package/FinalizationHelper.js +49 -0
- package/Types.d.ts +178 -21
- package/Types.js +7 -0
- package/api/ApiStatic.d.ts +16 -0
- package/api/ApiStatic.js +26 -0
- package/api/ConnectionNative.d.ts +9 -3
- package/api/ConnectionNative.js +24 -0
- package/api/CryptoApiNative.d.ts +14 -0
- package/api/CryptoApiNative.js +30 -0
- package/api/EventApiNative.d.ts +20 -0
- package/api/EventApiNative.js +36 -0
- package/api/ExtKeyNative.d.ts +23 -0
- package/api/ExtKeyNative.js +66 -0
- package/api/KvdbApiNative.d.ts +33 -0
- package/api/KvdbApiNative.js +75 -0
- package/assets/driver-web-context.js +1 -1
- package/assets/endpoint-wasm-module.js +1 -1
- package/assets/endpoint-wasm-module.wasm +0 -0
- package/bundle/privmx-endpoint-web.js +1 -1
- package/extra/PrivmxClient.d.ts +139 -0
- package/extra/PrivmxClient.js +285 -0
- package/extra/PublicConnection.d.ts +70 -0
- package/extra/PublicConnection.js +118 -0
- package/extra/events.d.ts +2 -2
- package/extra/inbox.d.ts +3 -3
- package/extra/inbox.js +1 -1
- package/extra/index.d.ts +10 -8
- package/extra/index.js +6 -1
- package/index.d.ts +2 -2
- package/index.js +3 -1
- package/package.json +5 -1
- package/service/Connection.d.ts +29 -3
- package/service/Connection.js +31 -2
- package/service/CryptoApi.d.ts +48 -1
- package/service/CryptoApi.js +59 -1
- package/service/EndpointFactory.d.ts +24 -3
- package/service/EndpointFactory.js +56 -5
- package/service/EventApi.d.ts +40 -0
- package/service/EventApi.js +60 -0
- package/service/ExtKey.d.ts +103 -0
- package/service/ExtKey.js +167 -0
- package/service/InboxApi.d.ts +9 -9
- package/service/InboxApi.js +9 -9
- package/service/KvdbApi.d.ts +142 -0
- package/service/KvdbApi.js +208 -0
- package/service/StoreApi.d.ts +6 -6
- package/service/StoreApi.js +6 -6
- package/service/ThreadApi.d.ts +6 -6
- package/service/ThreadApi.js +6 -6
- package/service/UserVerifierInterface.d.ts +18 -0
- package/service/UserVerifierInterface.js +2 -0
- package/service/index.d.ts +3 -1
- package/service/index.js +5 -1
- 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
|
-
|
|
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<'
|
|
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 {
|
|
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 {
|
|
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:
|
|
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 {
|
|
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
|
|
2
|
-
import * as Events from
|
|
3
|
-
import { EventManager, ThreadEventsManager, StoreEventsManager, InboxEventsManager, BaseEventManager } from
|
|
4
|
-
import * as Utils from
|
|
5
|
-
import * as Generics from
|
|
6
|
-
import * as Inboxes from
|
|
7
|
-
import { FileUploader, StreamReader, downloadFile } from
|
|
8
|
-
|
|
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, KvdbApi, 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, KvdbApi, 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.KvdbApi = 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");
|
|
@@ -18,8 +18,10 @@ Object.defineProperty(exports, "EventQueue", { enumerable: true, get: function (
|
|
|
18
18
|
Object.defineProperty(exports, "StoreApi", { enumerable: true, get: function () { return service_1.StoreApi; } });
|
|
19
19
|
Object.defineProperty(exports, "ThreadApi", { enumerable: true, get: function () { return service_1.ThreadApi; } });
|
|
20
20
|
Object.defineProperty(exports, "InboxApi", { enumerable: true, get: function () { return service_1.InboxApi; } });
|
|
21
|
+
Object.defineProperty(exports, "KvdbApi", { enumerable: true, get: function () { return service_1.KvdbApi; } });
|
|
21
22
|
Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return service_1.Connection; } });
|
|
22
23
|
Object.defineProperty(exports, "CryptoApi", { enumerable: true, get: function () { return service_1.CryptoApi; } });
|
|
23
24
|
Object.defineProperty(exports, "BaseApi", { enumerable: true, get: function () { return service_1.BaseApi; } });
|
|
25
|
+
Object.defineProperty(exports, "ExtKey", { enumerable: true, get: function () { return service_1.ExtKey; } });
|
|
24
26
|
const Types = require("./Types");
|
|
25
27
|
exports.Types = Types;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplito/privmx-webendpoint",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
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",
|
package/service/Connection.d.ts
CHANGED
|
@@ -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
|
};
|
|
@@ -32,14 +39,33 @@ export declare class Connection extends BaseApi {
|
|
|
32
39
|
/**
|
|
33
40
|
* Gets a list of Contexts available for the user.
|
|
34
41
|
*
|
|
35
|
-
* @param pagingQuery
|
|
36
|
-
* @returns {PagingList<Context>}
|
|
42
|
+
* @param pagingQuery with list query parameters
|
|
43
|
+
* @returns {PagingList<Context>} 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
|
}
|
package/service/Connection.js
CHANGED
|
@@ -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);
|
|
@@ -31,12 +37,22 @@ class Connection extends BaseApi_1.BaseApi {
|
|
|
31
37
|
/**
|
|
32
38
|
* Gets a list of Contexts available for the user.
|
|
33
39
|
*
|
|
34
|
-
* @param pagingQuery
|
|
35
|
-
* @returns {PagingList<Context>}
|
|
40
|
+
* @param pagingQuery with list query parameters
|
|
41
|
+
* @returns {PagingList<Context>} containing a list of Contexts
|
|
36
42
|
*/
|
|
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]) {
|
package/service/CryptoApi.d.ts
CHANGED
|
@@ -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
|
}
|
package/service/CryptoApi.js
CHANGED
|
@@ -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;
|
|
@@ -8,10 +8,13 @@ This software is Licensed under the PrivMX Free License.
|
|
|
8
8
|
See the License for the specific language governing permissions and
|
|
9
9
|
limitations under the License.
|
|
10
10
|
*/
|
|
11
|
+
import { PKIVerificationOptions } from "../Types";
|
|
11
12
|
import { Connection } from "./Connection";
|
|
12
13
|
import { CryptoApi } from "./CryptoApi";
|
|
14
|
+
import { EventApi } from "./EventApi";
|
|
13
15
|
import { EventQueue } from "./EventQueue";
|
|
14
16
|
import { InboxApi } from "./InboxApi";
|
|
17
|
+
import { KvdbApi } from "./KvdbApi";
|
|
15
18
|
import { StoreApi } from "./StoreApi";
|
|
16
19
|
import { ThreadApi } from "./ThreadApi";
|
|
17
20
|
/**
|
|
@@ -37,24 +40,26 @@ export declare class EndpointFactory {
|
|
|
37
40
|
* @returns {EventQueue} instance of EventQueue
|
|
38
41
|
*/
|
|
39
42
|
static getEventQueue(): Promise<EventQueue>;
|
|
43
|
+
private static generateDefaultPKIVerificationOptions;
|
|
40
44
|
/**
|
|
41
45
|
* Connects to the platform backend.
|
|
42
46
|
*
|
|
43
47
|
* @param {string} userPrivKey user's private key
|
|
44
48
|
* @param {string} solutionId ID of the Solution
|
|
45
49
|
* @param {string} bridgeUrl the Bridge Server URL
|
|
50
|
+
* @param {PKIVerificationOptions} [verificationOptions] PrivMX Bridge server instance verification options using a PKI server
|
|
46
51
|
* @returns {Connection} instance of Connection
|
|
47
52
|
*/
|
|
48
|
-
static connect(userPrivKey: string, solutionId: string, bridgeUrl: string): Promise<Connection>;
|
|
53
|
+
static connect(userPrivKey: string, solutionId: string, bridgeUrl: string, verificationOptions?: PKIVerificationOptions): Promise<Connection>;
|
|
49
54
|
/**
|
|
50
55
|
* Connects to the Platform backend as a guest user.
|
|
51
56
|
*
|
|
52
57
|
* @param {string} solutionId ID of the Solution
|
|
53
58
|
* @param {string} bridgeUrl the Bridge Server URL
|
|
54
|
-
*
|
|
59
|
+
* @param {PKIVerificationOptions} [verificationOptions] PrivMX Bridge server instance verification options using a PKI server
|
|
55
60
|
* @returns {Connection} instance of Connection
|
|
56
61
|
*/
|
|
57
|
-
static connectPublic(solutionId: string, bridgeUrl: string): Promise<Connection>;
|
|
62
|
+
static connectPublic(solutionId: string, bridgeUrl: string, verificationOptions?: PKIVerificationOptions): Promise<Connection>;
|
|
58
63
|
/**
|
|
59
64
|
* Creates an instance of the Thread API.
|
|
60
65
|
*
|
|
@@ -80,10 +85,26 @@ export declare class EndpointFactory {
|
|
|
80
85
|
* @returns {InboxApi} instance of InboxApi
|
|
81
86
|
*/
|
|
82
87
|
static createInboxApi(connection: Connection, threadApi: ThreadApi, storeApi: StoreApi): Promise<InboxApi>;
|
|
88
|
+
/**
|
|
89
|
+
* Creates an instance of the Kvdb API.
|
|
90
|
+
*
|
|
91
|
+
* @param {Connection} connection instance of Connection
|
|
92
|
+
*
|
|
93
|
+
* @returns {KvdbApi} instance of KvdbApi
|
|
94
|
+
*/
|
|
95
|
+
static createKvdbApi(connection: Connection): Promise<KvdbApi>;
|
|
83
96
|
/**
|
|
84
97
|
* Creates an instance of the Crypto API.
|
|
85
98
|
*
|
|
86
99
|
* @returns {CryptoApi} instance of CryptoApi
|
|
87
100
|
*/
|
|
88
101
|
static createCryptoApi(): Promise<CryptoApi>;
|
|
102
|
+
/**
|
|
103
|
+
* Creates an instance of 'EventApi'.
|
|
104
|
+
*
|
|
105
|
+
* @param connection instance of 'Connection'
|
|
106
|
+
*
|
|
107
|
+
* @returns {EventApi} instance of EventApi
|
|
108
|
+
*/
|
|
109
|
+
static createEventApi(connection: Connection): Promise<EventApi>;
|
|
89
110
|
}
|