@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
|
@@ -12,16 +12,22 @@ 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");
|
|
21
|
+
const KvdbApiNative_1 = require("../api/KvdbApiNative");
|
|
19
22
|
const StoreApiNative_1 = require("../api/StoreApiNative");
|
|
20
23
|
const ThreadApiNative_1 = require("../api/ThreadApiNative");
|
|
24
|
+
const FinalizationHelper_1 = require("../FinalizationHelper");
|
|
21
25
|
const Connection_1 = require("./Connection");
|
|
22
26
|
const CryptoApi_1 = require("./CryptoApi");
|
|
27
|
+
const EventApi_1 = require("./EventApi");
|
|
23
28
|
const EventQueue_1 = require("./EventQueue");
|
|
24
29
|
const InboxApi_1 = require("./InboxApi");
|
|
30
|
+
const KvdbApi_1 = require("./KvdbApi");
|
|
25
31
|
const StoreApi_1 = require("./StoreApi");
|
|
26
32
|
const ThreadApi_1 = require("./ThreadApi");
|
|
27
33
|
/**
|
|
@@ -61,6 +67,8 @@ class EndpointFactory {
|
|
|
61
67
|
*/
|
|
62
68
|
static init(lib) {
|
|
63
69
|
this.api = new Api_1.Api(lib);
|
|
70
|
+
ApiStatic_1.ApiStatic.init(this.api);
|
|
71
|
+
FinalizationHelper_1.FinalizationHelper.init(lib);
|
|
64
72
|
}
|
|
65
73
|
/**
|
|
66
74
|
* Gets the EventQueue instance.
|
|
@@ -75,18 +83,25 @@ class EndpointFactory {
|
|
|
75
83
|
}
|
|
76
84
|
return this.eventQueueInstance;
|
|
77
85
|
}
|
|
86
|
+
static generateDefaultPKIVerificationOptions() {
|
|
87
|
+
return {
|
|
88
|
+
bridgeInstanceId: undefined,
|
|
89
|
+
bridgePubKey: undefined
|
|
90
|
+
};
|
|
91
|
+
}
|
|
78
92
|
/**
|
|
79
93
|
* Connects to the platform backend.
|
|
80
94
|
*
|
|
81
95
|
* @param {string} userPrivKey user's private key
|
|
82
96
|
* @param {string} solutionId ID of the Solution
|
|
83
97
|
* @param {string} bridgeUrl the Bridge Server URL
|
|
98
|
+
* @param {PKIVerificationOptions} [verificationOptions] PrivMX Bridge server instance verification options using a PKI server
|
|
84
99
|
* @returns {Connection} instance of Connection
|
|
85
100
|
*/
|
|
86
|
-
static async connect(userPrivKey, solutionId, bridgeUrl) {
|
|
101
|
+
static async connect(userPrivKey, solutionId, bridgeUrl, verificationOptions) {
|
|
87
102
|
const nativeApi = new ConnectionNative_1.ConnectionNative(this.api);
|
|
88
103
|
const ptr = await nativeApi.newConnection();
|
|
89
|
-
await nativeApi.connect(ptr, [userPrivKey, solutionId, bridgeUrl]);
|
|
104
|
+
await nativeApi.connect(ptr, [userPrivKey, solutionId, bridgeUrl, verificationOptions || this.generateDefaultPKIVerificationOptions()]);
|
|
90
105
|
return new Connection_1.Connection(nativeApi, ptr);
|
|
91
106
|
}
|
|
92
107
|
/**
|
|
@@ -94,13 +109,13 @@ class EndpointFactory {
|
|
|
94
109
|
*
|
|
95
110
|
* @param {string} solutionId ID of the Solution
|
|
96
111
|
* @param {string} bridgeUrl the Bridge Server URL
|
|
97
|
-
*
|
|
112
|
+
* @param {PKIVerificationOptions} [verificationOptions] PrivMX Bridge server instance verification options using a PKI server
|
|
98
113
|
* @returns {Connection} instance of Connection
|
|
99
114
|
*/
|
|
100
|
-
static async connectPublic(solutionId, bridgeUrl) {
|
|
115
|
+
static async connectPublic(solutionId, bridgeUrl, verificationOptions) {
|
|
101
116
|
const nativeApi = new ConnectionNative_1.ConnectionNative(this.api);
|
|
102
117
|
const ptr = await nativeApi.newConnection();
|
|
103
|
-
await nativeApi.connectPublic(ptr, [solutionId, bridgeUrl]);
|
|
118
|
+
await nativeApi.connectPublic(ptr, [solutionId, bridgeUrl, verificationOptions || this.generateDefaultPKIVerificationOptions()]);
|
|
104
119
|
return new Connection_1.Connection(nativeApi, ptr);
|
|
105
120
|
}
|
|
106
121
|
/**
|
|
@@ -158,6 +173,24 @@ class EndpointFactory {
|
|
|
158
173
|
await nativeApi.create(ptr, []);
|
|
159
174
|
return new InboxApi_1.InboxApi(nativeApi, ptr);
|
|
160
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Creates an instance of the Kvdb API.
|
|
178
|
+
*
|
|
179
|
+
* @param {Connection} connection instance of Connection
|
|
180
|
+
*
|
|
181
|
+
* @returns {KvdbApi} instance of KvdbApi
|
|
182
|
+
*/
|
|
183
|
+
static async createKvdbApi(connection) {
|
|
184
|
+
if ("kvdbs" in connection.apisRefs) {
|
|
185
|
+
throw new Error("KvdbApi already registered for given connection.");
|
|
186
|
+
}
|
|
187
|
+
const nativeApi = new KvdbApiNative_1.KvdbApiNative(this.api);
|
|
188
|
+
const ptr = await nativeApi.newApi(connection.servicePtr);
|
|
189
|
+
await nativeApi.create(ptr, []);
|
|
190
|
+
connection.apisRefs["kvdbs"] = { _apiServicePtr: ptr };
|
|
191
|
+
connection.nativeApisDeps["kvdbs"] = nativeApi;
|
|
192
|
+
return new KvdbApi_1.KvdbApi(nativeApi, ptr);
|
|
193
|
+
}
|
|
161
194
|
/**
|
|
162
195
|
* Creates an instance of the Crypto API.
|
|
163
196
|
*
|
|
@@ -169,5 +202,23 @@ class EndpointFactory {
|
|
|
169
202
|
await nativeApi.create(ptr, []);
|
|
170
203
|
return new CryptoApi_1.CryptoApi(nativeApi, ptr);
|
|
171
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Creates an instance of 'EventApi'.
|
|
207
|
+
*
|
|
208
|
+
* @param connection instance of 'Connection'
|
|
209
|
+
*
|
|
210
|
+
* @returns {EventApi} instance of EventApi
|
|
211
|
+
*/
|
|
212
|
+
static async createEventApi(connection) {
|
|
213
|
+
if ("events" in connection.apisRefs) {
|
|
214
|
+
throw new Error("EventApi already registered for given connection.");
|
|
215
|
+
}
|
|
216
|
+
const nativeApi = new EventApiNative_1.EventApiNative(this.api);
|
|
217
|
+
const ptr = await nativeApi.newApi(connection.servicePtr);
|
|
218
|
+
connection.apisRefs["events"] = { _apiServicePtr: ptr };
|
|
219
|
+
connection.nativeApisDeps["events"] = nativeApi;
|
|
220
|
+
await nativeApi.create(ptr, []);
|
|
221
|
+
return new EventApi_1.EventApi(nativeApi, ptr);
|
|
222
|
+
}
|
|
172
223
|
}
|
|
173
224
|
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
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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.EventApi = void 0;
|
|
14
|
+
const BaseApi_1 = require("./BaseApi");
|
|
15
|
+
class EventApi extends BaseApi_1.BaseApi {
|
|
16
|
+
native;
|
|
17
|
+
constructor(native, ptr) {
|
|
18
|
+
super(ptr);
|
|
19
|
+
this.native = native;
|
|
20
|
+
}
|
|
21
|
+
// /**
|
|
22
|
+
// * Creates an instance of 'EventApi'.
|
|
23
|
+
// *
|
|
24
|
+
// * @param connection instance of 'Connection'
|
|
25
|
+
// *
|
|
26
|
+
// * @return EventApi object
|
|
27
|
+
// */
|
|
28
|
+
// static EventApi create(core::Connection& connection);
|
|
29
|
+
// EventApi() = default;
|
|
30
|
+
/**
|
|
31
|
+
* Emits the custom event on the given Context and channel.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} contextId ID of the Context
|
|
34
|
+
* @param {string} channelName name of the Channel
|
|
35
|
+
* @param {Uint8Array} eventData event's data
|
|
36
|
+
* @param {UserWithPubKey[]} users list of UserWithPubKey objects which defines the recipients of the event
|
|
37
|
+
*/
|
|
38
|
+
async emitEvent(contextId, channelName, eventData, users) {
|
|
39
|
+
return this.native.emitEvent(this.servicePtr, [contextId, channelName, eventData, users]);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Subscribe for the custom events on the given channel.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} contextId ID of the Context
|
|
45
|
+
* @param {string} channelName name of the Channel
|
|
46
|
+
*/
|
|
47
|
+
async subscribeForCustomEvents(contextId, channelName) {
|
|
48
|
+
return this.native.subscribeForCustomEvents(this.servicePtr, [contextId, channelName]);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Unsubscribe from the custom events on the given channel.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} contextId ID of the Context
|
|
54
|
+
* @param {string} channelName name of the Channel
|
|
55
|
+
*/
|
|
56
|
+
async unsubscribeFromCustomEvents(contextId, channelName) {
|
|
57
|
+
return this.native.unsubscribeFromCustomEvents(this.servicePtr, [contextId, channelName]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.EventApi = EventApi;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ExtKeyNativePtr } from "../api/ExtKeyNative";
|
|
2
|
+
import { BaseApi } from "./BaseApi";
|
|
3
|
+
export declare class ExtKey extends BaseApi {
|
|
4
|
+
private native;
|
|
5
|
+
ptr: ExtKeyNativePtr;
|
|
6
|
+
private static freeExtKey;
|
|
7
|
+
/**
|
|
8
|
+
* Creates ExtKey from given seed.
|
|
9
|
+
* @param {Uint8Array} seed the seed used to generate Key
|
|
10
|
+
* @returns {ExtKey} object
|
|
11
|
+
*/
|
|
12
|
+
static fromSeed(seed: Uint8Array): Promise<ExtKey>;
|
|
13
|
+
/**
|
|
14
|
+
* Decodes ExtKey from Base58 format.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} base58 the ExtKey in Base58
|
|
17
|
+
* @returns {ExtKey} object
|
|
18
|
+
*/
|
|
19
|
+
static fromBase58(base58: string): Promise<ExtKey>;
|
|
20
|
+
/**
|
|
21
|
+
* Generates a new ExtKey.
|
|
22
|
+
*
|
|
23
|
+
* @returns {ExtKey} object
|
|
24
|
+
*/
|
|
25
|
+
static generateRandom(): Promise<ExtKey>;
|
|
26
|
+
/**
|
|
27
|
+
* //doc-gen:ignore
|
|
28
|
+
*/
|
|
29
|
+
private constructor();
|
|
30
|
+
static fromPtr(ptr: ExtKeyNativePtr): ExtKey;
|
|
31
|
+
/**
|
|
32
|
+
* Generates child ExtKey from a current ExtKey using BIP32.
|
|
33
|
+
*
|
|
34
|
+
* @param {number} index number from 0 to 2^31-1
|
|
35
|
+
|
|
36
|
+
* @returns {ExtKey} object
|
|
37
|
+
*/
|
|
38
|
+
derive(index: number): Promise<ExtKey>;
|
|
39
|
+
/**
|
|
40
|
+
* Generates hardened child ExtKey from a current ExtKey using BIP32.
|
|
41
|
+
*
|
|
42
|
+
* @param {number} index number from 0 to 2^31-1
|
|
43
|
+
|
|
44
|
+
* @returns {ExtKey} object
|
|
45
|
+
*/
|
|
46
|
+
deriveHardened(index: number): Promise<ExtKey>;
|
|
47
|
+
/**
|
|
48
|
+
* Converts ExtKey to Base58 string.
|
|
49
|
+
*
|
|
50
|
+
* @returns {string} ExtKey in Base58 format
|
|
51
|
+
*/
|
|
52
|
+
getPrivatePartAsBase58(): Promise<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Converts the public part of ExtKey to Base58 string.
|
|
55
|
+
*
|
|
56
|
+
* @returns {string} ExtKey in Base58 format
|
|
57
|
+
*/
|
|
58
|
+
getPublicPartAsBase58(): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Extracts ECC PrivateKey.
|
|
61
|
+
*
|
|
62
|
+
* @returns {string} ECC key in WIF format
|
|
63
|
+
*/
|
|
64
|
+
getPrivateKey(): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Extracts ECC PublicKey.
|
|
67
|
+
*
|
|
68
|
+
* @returns {string} ECC key in BASE58DER format
|
|
69
|
+
*/
|
|
70
|
+
getPublicKey(): Promise<string>;
|
|
71
|
+
/**
|
|
72
|
+
* Extracts raw ECC PrivateKey.
|
|
73
|
+
*
|
|
74
|
+
* @returns {Uint8Array} ECC PrivateKey
|
|
75
|
+
*/
|
|
76
|
+
getPrivateEncKey(): Promise<Uint8Array>;
|
|
77
|
+
/**
|
|
78
|
+
* Extracts ECC PublicKey Address.
|
|
79
|
+
*
|
|
80
|
+
* @returns {string} ECC Address in BASE58 format
|
|
81
|
+
*/
|
|
82
|
+
getPublicKeyAsBase58Address(): Promise<string>;
|
|
83
|
+
/**
|
|
84
|
+
* Gets the chain code of Extended Key.
|
|
85
|
+
*
|
|
86
|
+
* @returns {Uint8Array} Raw chain code
|
|
87
|
+
*/
|
|
88
|
+
getChainCode(): Promise<Uint8Array>;
|
|
89
|
+
/**
|
|
90
|
+
* Validates a signature of a message.
|
|
91
|
+
*
|
|
92
|
+
* @param {Uint8Array} message data used on validation
|
|
93
|
+
* @param {Uint8Array} signature signature of data to verify
|
|
94
|
+
* @returns {boolean} message validation result
|
|
95
|
+
*/
|
|
96
|
+
verifyCompactSignatureWithHash(message: Uint8Array, signature: Uint8Array): Promise<boolean>;
|
|
97
|
+
/**
|
|
98
|
+
* Checks if ExtKey is Private.
|
|
99
|
+
*
|
|
100
|
+
* @returns {boolean} true if ExtKey is private
|
|
101
|
+
*/
|
|
102
|
+
isPrivate(): Promise<boolean>;
|
|
103
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtKey = void 0;
|
|
4
|
+
const ApiStatic_1 = require("../api/ApiStatic");
|
|
5
|
+
const ExtKeyNative_1 = require("../api/ExtKeyNative");
|
|
6
|
+
const FinalizationHelper_1 = require("../FinalizationHelper");
|
|
7
|
+
const BaseApi_1 = require("./BaseApi");
|
|
8
|
+
class ExtKey extends BaseApi_1.BaseApi {
|
|
9
|
+
native;
|
|
10
|
+
ptr;
|
|
11
|
+
static async freeExtKey(ptr) {
|
|
12
|
+
const nativeApi = new ExtKeyNative_1.ExtKeyNative(ApiStatic_1.ApiStatic.getInstance());
|
|
13
|
+
await nativeApi.deleteExtKey(ptr);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates ExtKey from given seed.
|
|
17
|
+
* @param {Uint8Array} seed the seed used to generate Key
|
|
18
|
+
* @returns {ExtKey} object
|
|
19
|
+
*/
|
|
20
|
+
static async fromSeed(seed) {
|
|
21
|
+
const ptr = await ExtKeyNative_1.ExtKeyNative.fromSeed([seed]);
|
|
22
|
+
const native = new ExtKeyNative_1.ExtKeyNative(ApiStatic_1.ApiStatic.getInstance());
|
|
23
|
+
const extKey = new ExtKey(native, ptr);
|
|
24
|
+
const fh = FinalizationHelper_1.FinalizationHelper.getInstance();
|
|
25
|
+
fh.register(extKey, { ptr: ptr, onFree: () => this.freeExtKey(ptr) });
|
|
26
|
+
return extKey;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Decodes ExtKey from Base58 format.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} base58 the ExtKey in Base58
|
|
32
|
+
* @returns {ExtKey} object
|
|
33
|
+
*/
|
|
34
|
+
static async fromBase58(base58) {
|
|
35
|
+
const ptr = await ExtKeyNative_1.ExtKeyNative.fromBase58([base58]);
|
|
36
|
+
const native = new ExtKeyNative_1.ExtKeyNative(ApiStatic_1.ApiStatic.getInstance());
|
|
37
|
+
const extKey = new ExtKey(native, ptr);
|
|
38
|
+
const fh = FinalizationHelper_1.FinalizationHelper.getInstance();
|
|
39
|
+
fh.register(extKey, { ptr: ptr, onFree: () => this.freeExtKey(ptr) });
|
|
40
|
+
return extKey;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Generates a new ExtKey.
|
|
44
|
+
*
|
|
45
|
+
* @returns {ExtKey} object
|
|
46
|
+
*/
|
|
47
|
+
static async generateRandom() {
|
|
48
|
+
const ptr = await ExtKeyNative_1.ExtKeyNative.generateRandom([]);
|
|
49
|
+
const native = new ExtKeyNative_1.ExtKeyNative(ApiStatic_1.ApiStatic.getInstance());
|
|
50
|
+
const extKey = new ExtKey(native, ptr);
|
|
51
|
+
const fh = FinalizationHelper_1.FinalizationHelper.getInstance();
|
|
52
|
+
fh.register(extKey, { ptr: ptr, onFree: () => this.freeExtKey(ptr) });
|
|
53
|
+
return extKey;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* //doc-gen:ignore
|
|
57
|
+
*/
|
|
58
|
+
constructor(native, ptr) {
|
|
59
|
+
super(ptr);
|
|
60
|
+
this.native = native;
|
|
61
|
+
this.ptr = ptr;
|
|
62
|
+
}
|
|
63
|
+
static fromPtr(ptr) {
|
|
64
|
+
const native = new ExtKeyNative_1.ExtKeyNative(ApiStatic_1.ApiStatic.getInstance());
|
|
65
|
+
return new ExtKey(native, ptr);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Generates child ExtKey from a current ExtKey using BIP32.
|
|
69
|
+
*
|
|
70
|
+
* @param {number} index number from 0 to 2^31-1
|
|
71
|
+
|
|
72
|
+
* @returns {ExtKey} object
|
|
73
|
+
*/
|
|
74
|
+
async derive(index) {
|
|
75
|
+
const ptr = await this.native.derive(this.servicePtr, [index]);
|
|
76
|
+
const extKey = new ExtKey(this.native, ptr);
|
|
77
|
+
const fh = FinalizationHelper_1.FinalizationHelper.getInstance();
|
|
78
|
+
fh.register(extKey, { ptr: ptr, onFree: () => ExtKey.freeExtKey(ptr) });
|
|
79
|
+
return extKey;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Generates hardened child ExtKey from a current ExtKey using BIP32.
|
|
83
|
+
*
|
|
84
|
+
* @param {number} index number from 0 to 2^31-1
|
|
85
|
+
|
|
86
|
+
* @returns {ExtKey} object
|
|
87
|
+
*/
|
|
88
|
+
async deriveHardened(index) {
|
|
89
|
+
const extKeyPtr = await this.native.deriveHardened(this.servicePtr, [index]);
|
|
90
|
+
return new ExtKey(this.native, extKeyPtr);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Converts ExtKey to Base58 string.
|
|
94
|
+
*
|
|
95
|
+
* @returns {string} ExtKey in Base58 format
|
|
96
|
+
*/
|
|
97
|
+
async getPrivatePartAsBase58() {
|
|
98
|
+
return this.native.getPrivatePartAsBase58(this.servicePtr, []);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Converts the public part of ExtKey to Base58 string.
|
|
102
|
+
*
|
|
103
|
+
* @returns {string} ExtKey in Base58 format
|
|
104
|
+
*/
|
|
105
|
+
async getPublicPartAsBase58() {
|
|
106
|
+
return this.native.getPublicPartAsBase58(this.servicePtr, []);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Extracts ECC PrivateKey.
|
|
110
|
+
*
|
|
111
|
+
* @returns {string} ECC key in WIF format
|
|
112
|
+
*/
|
|
113
|
+
async getPrivateKey() {
|
|
114
|
+
return this.native.getPrivateKey(this.servicePtr, []);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Extracts ECC PublicKey.
|
|
118
|
+
*
|
|
119
|
+
* @returns {string} ECC key in BASE58DER format
|
|
120
|
+
*/
|
|
121
|
+
async getPublicKey() {
|
|
122
|
+
return this.native.getPublicKey(this.servicePtr, []);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Extracts raw ECC PrivateKey.
|
|
126
|
+
*
|
|
127
|
+
* @returns {Uint8Array} ECC PrivateKey
|
|
128
|
+
*/
|
|
129
|
+
async getPrivateEncKey() {
|
|
130
|
+
return this.native.getPrivateEncKey(this.servicePtr, []);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Extracts ECC PublicKey Address.
|
|
134
|
+
*
|
|
135
|
+
* @returns {string} ECC Address in BASE58 format
|
|
136
|
+
*/
|
|
137
|
+
async getPublicKeyAsBase58Address() {
|
|
138
|
+
return this.native.getPublicKeyAsBase58Address(this.servicePtr, []);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Gets the chain code of Extended Key.
|
|
142
|
+
*
|
|
143
|
+
* @returns {Uint8Array} Raw chain code
|
|
144
|
+
*/
|
|
145
|
+
async getChainCode() {
|
|
146
|
+
return this.native.getChainCode(this.servicePtr, []);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Validates a signature of a message.
|
|
150
|
+
*
|
|
151
|
+
* @param {Uint8Array} message data used on validation
|
|
152
|
+
* @param {Uint8Array} signature signature of data to verify
|
|
153
|
+
* @returns {boolean} message validation result
|
|
154
|
+
*/
|
|
155
|
+
async verifyCompactSignatureWithHash(message, signature) {
|
|
156
|
+
return this.native.verifyCompactSignatureWithHash(this.servicePtr, [message, signature]);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Checks if ExtKey is Private.
|
|
160
|
+
*
|
|
161
|
+
* @returns {boolean} true if ExtKey is private
|
|
162
|
+
*/
|
|
163
|
+
async isPrivate() {
|
|
164
|
+
return this.native.isPrivate(this.servicePtr, []);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.ExtKey = ExtKey;
|
package/service/InboxApi.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare class InboxApi extends BaseApi {
|
|
|
23
23
|
* the created Inbox
|
|
24
24
|
* @param {Uint8Array} publicMeta public (unencrypted) metadata
|
|
25
25
|
* @param {Uint8Array} privateMeta private (encrypted) metadata
|
|
26
|
-
* @param {FilesConfig} filesConfig
|
|
26
|
+
* @param {FilesConfig} filesConfig to override default file configuration
|
|
27
27
|
* @param {ContainerWithoutItemPolicy} policies Inbox policies
|
|
28
28
|
* @returns {string} ID of the created Inbox
|
|
29
29
|
*/
|
|
@@ -37,7 +37,7 @@ export declare class InboxApi extends BaseApi {
|
|
|
37
37
|
* the created Inbox
|
|
38
38
|
* @param {Uint8Array} publicMeta public (unencrypted) metadata
|
|
39
39
|
* @param {Uint8Array} privateMeta private (encrypted) metadata
|
|
40
|
-
* @param {FilesConfig} filesConfig
|
|
40
|
+
* @param {FilesConfig} filesConfig to override default files configuration
|
|
41
41
|
* @param {number} version current version of the updated Inbox
|
|
42
42
|
* @param {boolean} force force update (without checking version)
|
|
43
43
|
* @param {boolean} forceGenerateNewKey force to regenerate a key for the Inbox
|
|
@@ -48,15 +48,15 @@ export declare class InboxApi extends BaseApi {
|
|
|
48
48
|
* Gets a single Inbox by given Inbox ID.
|
|
49
49
|
*
|
|
50
50
|
* @param {string} inboxId ID of the Inbox to get
|
|
51
|
-
* @returns {Inbox}
|
|
51
|
+
* @returns {Inbox} containing information about the Inbox
|
|
52
52
|
*/
|
|
53
53
|
getInbox(inboxId: string): Promise<Inbox>;
|
|
54
54
|
/**
|
|
55
55
|
* Gets s list of Inboxes in given Context.
|
|
56
56
|
*
|
|
57
57
|
* @param {string} contextId ID of the Context to get Inboxes from
|
|
58
|
-
* @param {PagingQuery} pagingQuery
|
|
59
|
-
* @returns {PagingList<Inbox>}
|
|
58
|
+
* @param {PagingQuery} pagingQuery with list query parameters
|
|
59
|
+
* @returns {PagingList<Inbox>} containing list of Inboxes
|
|
60
60
|
*/
|
|
61
61
|
listInboxes(contextId: string, pagingQuery: PagingQuery): Promise<PagingList<Inbox>>;
|
|
62
62
|
/**
|
|
@@ -64,7 +64,7 @@ export declare class InboxApi extends BaseApi {
|
|
|
64
64
|
* You do not have to be logged in to call this function.
|
|
65
65
|
*
|
|
66
66
|
* @param {string} inboxId ID of the Inbox to get
|
|
67
|
-
* @returns {InboxPublicView}
|
|
67
|
+
* @returns {InboxPublicView} containing public accessible information about the Inbox
|
|
68
68
|
*/
|
|
69
69
|
getInboxPublicView(inboxId: string): Promise<InboxPublicView>;
|
|
70
70
|
/**
|
|
@@ -95,15 +95,15 @@ export declare class InboxApi extends BaseApi {
|
|
|
95
95
|
* Gets an entry from an Inbox.
|
|
96
96
|
*
|
|
97
97
|
* @param {string} inboxEntryId ID of an entry to read from the Inbox
|
|
98
|
-
* @returns {InboxEntry}
|
|
98
|
+
* @returns {InboxEntry} containing data of the selected entry stored in the Inbox
|
|
99
99
|
*/
|
|
100
100
|
readEntry(inboxEntryId: string): Promise<InboxEntry>;
|
|
101
101
|
/**
|
|
102
102
|
* Gets list of entries in given Inbox.
|
|
103
103
|
*
|
|
104
104
|
* @param {string} inboxId ID of the Inbox
|
|
105
|
-
* @param {PagingQuery} pagingQuery
|
|
106
|
-
* @returns {PagingList<InboxEntry>}
|
|
105
|
+
* @param {PagingQuery} pagingQuery with list query parameters
|
|
106
|
+
* @returns {PagingList<InboxEntry>} containing list of entries
|
|
107
107
|
*/
|
|
108
108
|
listEntries(inboxId: string, pagingQuery: PagingQuery): Promise<PagingList<InboxEntry>>;
|
|
109
109
|
/**
|
package/service/InboxApi.js
CHANGED
|
@@ -27,7 +27,7 @@ class InboxApi extends BaseApi_1.BaseApi {
|
|
|
27
27
|
* the created Inbox
|
|
28
28
|
* @param {Uint8Array} publicMeta public (unencrypted) metadata
|
|
29
29
|
* @param {Uint8Array} privateMeta private (encrypted) metadata
|
|
30
|
-
* @param {FilesConfig} filesConfig
|
|
30
|
+
* @param {FilesConfig} filesConfig to override default file configuration
|
|
31
31
|
* @param {ContainerWithoutItemPolicy} policies Inbox policies
|
|
32
32
|
* @returns {string} ID of the created Inbox
|
|
33
33
|
*/
|
|
@@ -51,7 +51,7 @@ class InboxApi extends BaseApi_1.BaseApi {
|
|
|
51
51
|
* the created Inbox
|
|
52
52
|
* @param {Uint8Array} publicMeta public (unencrypted) metadata
|
|
53
53
|
* @param {Uint8Array} privateMeta private (encrypted) metadata
|
|
54
|
-
* @param {FilesConfig} filesConfig
|
|
54
|
+
* @param {FilesConfig} filesConfig to override default files configuration
|
|
55
55
|
* @param {number} version current version of the updated Inbox
|
|
56
56
|
* @param {boolean} force force update (without checking version)
|
|
57
57
|
* @param {boolean} forceGenerateNewKey force to regenerate a key for the Inbox
|
|
@@ -75,7 +75,7 @@ class InboxApi extends BaseApi_1.BaseApi {
|
|
|
75
75
|
* Gets a single Inbox by given Inbox ID.
|
|
76
76
|
*
|
|
77
77
|
* @param {string} inboxId ID of the Inbox to get
|
|
78
|
-
* @returns {Inbox}
|
|
78
|
+
* @returns {Inbox} containing information about the Inbox
|
|
79
79
|
*/
|
|
80
80
|
async getInbox(inboxId) {
|
|
81
81
|
return this.native.getInbox(this.servicePtr, [inboxId]);
|
|
@@ -84,8 +84,8 @@ class InboxApi extends BaseApi_1.BaseApi {
|
|
|
84
84
|
* Gets s list of Inboxes in given Context.
|
|
85
85
|
*
|
|
86
86
|
* @param {string} contextId ID of the Context to get Inboxes from
|
|
87
|
-
* @param {PagingQuery} pagingQuery
|
|
88
|
-
* @returns {PagingList<Inbox>}
|
|
87
|
+
* @param {PagingQuery} pagingQuery with list query parameters
|
|
88
|
+
* @returns {PagingList<Inbox>} containing list of Inboxes
|
|
89
89
|
*/
|
|
90
90
|
async listInboxes(contextId, pagingQuery) {
|
|
91
91
|
return this.native.listInboxes(this.servicePtr, [contextId, pagingQuery]);
|
|
@@ -95,7 +95,7 @@ class InboxApi extends BaseApi_1.BaseApi {
|
|
|
95
95
|
* You do not have to be logged in to call this function.
|
|
96
96
|
*
|
|
97
97
|
* @param {string} inboxId ID of the Inbox to get
|
|
98
|
-
* @returns {InboxPublicView}
|
|
98
|
+
* @returns {InboxPublicView} containing public accessible information about the Inbox
|
|
99
99
|
*/
|
|
100
100
|
async getInboxPublicView(inboxId) {
|
|
101
101
|
return this.native.getInboxPublicView(this.servicePtr, [inboxId]);
|
|
@@ -139,7 +139,7 @@ class InboxApi extends BaseApi_1.BaseApi {
|
|
|
139
139
|
* Gets an entry from an Inbox.
|
|
140
140
|
*
|
|
141
141
|
* @param {string} inboxEntryId ID of an entry to read from the Inbox
|
|
142
|
-
* @returns {InboxEntry}
|
|
142
|
+
* @returns {InboxEntry} containing data of the selected entry stored in the Inbox
|
|
143
143
|
*/
|
|
144
144
|
async readEntry(inboxEntryId) {
|
|
145
145
|
return this.native.readEntry(this.servicePtr, [inboxEntryId]);
|
|
@@ -148,8 +148,8 @@ class InboxApi extends BaseApi_1.BaseApi {
|
|
|
148
148
|
* Gets list of entries in given Inbox.
|
|
149
149
|
*
|
|
150
150
|
* @param {string} inboxId ID of the Inbox
|
|
151
|
-
* @param {PagingQuery} pagingQuery
|
|
152
|
-
* @returns {PagingList<InboxEntry>}
|
|
151
|
+
* @param {PagingQuery} pagingQuery with list query parameters
|
|
152
|
+
* @returns {PagingList<InboxEntry>} containing list of entries
|
|
153
153
|
*/
|
|
154
154
|
async listEntries(inboxId, pagingQuery) {
|
|
155
155
|
return this.native.listEntries(this.servicePtr, [inboxId, pagingQuery]);
|