@msssystems/mss-link-sdk 0.1.11 → 0.2.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/dist/client/browser-client.d.ts +16 -0
- package/dist/client/browser-client.js +35 -0
- package/dist/client/index.d.ts +3 -20
- package/dist/client/index.js +3 -20
- package/dist/client/mss-link-client.d.ts +12 -0
- package/dist/client/mss-link-client.js +17 -0
- package/dist/client/wasm-client.types.d.ts +1 -1
- package/dist/contracts/chat.contract.d.ts +189 -0
- package/dist/contracts/user-search.contract.d.ts +9 -0
- package/dist/core/http-client.d.ts +24 -0
- package/dist/core/http-client.js +80 -0
- package/dist/{client → core}/local-crypto-health.contracts.d.ts +1 -1
- package/dist/{client → core}/local-crypto-health.js +1 -1
- package/dist/core/wasm-crypto-engine.d.ts +34 -0
- package/dist/core/wasm-crypto-engine.js +75 -0
- package/dist/errors/api-error.d.ts +6 -0
- package/dist/errors/api-error.js +11 -0
- package/dist/errors/sdk-error.d.ts +3 -0
- package/dist/errors/sdk-error.js +6 -0
- package/dist/modules/chats/chats.client.d.ts +11 -0
- package/dist/modules/chats/chats.client.js +25 -0
- package/dist/modules/media/media-crypto.client.d.ts +10 -0
- package/dist/modules/media/media-crypto.client.js +90 -0
- package/dist/{client → modules/messages}/message-decryption-state.js +1 -1
- package/dist/{client → modules/messages}/message-decryption.contracts.d.ts +1 -1
- package/dist/modules/messages/messages-crypto.client.d.ts +14 -0
- package/dist/modules/messages/messages-crypto.client.js +34 -0
- package/dist/modules/messages/messages.client.d.ts +8 -0
- package/dist/modules/messages/messages.client.js +24 -0
- package/dist/{client → modules/storage}/drive-file-runtime.contracts.d.ts +2 -2
- package/dist/{client → modules/storage}/drive-file-runtime.d.ts +1 -1
- package/dist/{client → modules/storage}/drive-key-wrapping.contracts.d.ts +12 -0
- package/dist/modules/storage/drive-key-wrapping.d.ts +3 -0
- package/dist/{client → modules/storage}/drive-key-wrapping.js +30 -0
- package/dist/modules/storage/drive-sharing.contracts.js +1 -0
- package/dist/modules/storage/storage-crypto.client.d.ts +13 -0
- package/dist/modules/storage/storage-crypto.client.js +73 -0
- package/dist/modules/storage/storage-metadata-crypto.contracts.js +1 -0
- package/package.json +1 -1
- package/dist/client/drive-key-wrapping.d.ts +0 -2
- package/dist/client/mss-link-browser-client.d.ts +0 -45
- package/dist/client/mss-link-browser-client.js +0 -256
- /package/dist/{client/drive-file-runtime.contracts.js → contracts/chat.contract.js} +0 -0
- /package/dist/{client/drive-key-wrapping.contracts.js → contracts/user-search.contract.js} +0 -0
- /package/dist/{client → core}/api-base-url.d.ts +0 -0
- /package/dist/{client → core}/api-base-url.js +0 -0
- /package/dist/{client → core}/local-crypto-health.contracts.js +0 -0
- /package/dist/{client → core}/local-crypto-health.d.ts +0 -0
- /package/dist/{client → core}/wasm-call-queue.d.ts +0 -0
- /package/dist/{client → core}/wasm-call-queue.js +0 -0
- /package/dist/{client → errors}/decryption-errors.d.ts +0 -0
- /package/dist/{client → errors}/decryption-errors.js +0 -0
- /package/dist/{client → modules/media}/media-crypto.contracts.d.ts +0 -0
- /package/dist/{client → modules/media}/media-crypto.contracts.js +0 -0
- /package/dist/{client → modules/media}/media-message-metadata.d.ts +0 -0
- /package/dist/{client → modules/media}/media-message-metadata.js +0 -0
- /package/dist/{client → modules/media}/media-message.contracts.d.ts +0 -0
- /package/dist/{client → modules/media}/media-message.contracts.js +0 -0
- /package/dist/{client → modules/messages}/message-decryption-state.d.ts +0 -0
- /package/dist/{client → modules/messages}/message-decryption.contracts.js +0 -0
- /package/dist/{client → modules/messages}/message.contracts.d.ts +0 -0
- /package/dist/{client → modules/messages}/message.contracts.js +0 -0
- /package/dist/{client → modules/messages}/message.mapper.d.ts +0 -0
- /package/dist/{client → modules/messages}/message.mapper.js +0 -0
- /package/dist/{client/drive-sharing.contracts.js → modules/storage/drive-file-runtime.contracts.js} +0 -0
- /package/dist/{client → modules/storage}/drive-file-runtime.js +0 -0
- /package/dist/{client/storage-metadata-crypto.contracts.js → modules/storage/drive-key-wrapping.contracts.js} +0 -0
- /package/dist/{client → modules/storage}/drive-sharing.contracts.d.ts +0 -0
- /package/dist/{client → modules/storage}/drive-sharing.d.ts +0 -0
- /package/dist/{client → modules/storage}/drive-sharing.js +0 -0
- /package/dist/{client → modules/storage}/storage-metadata-crypto.contracts.d.ts +0 -0
- /package/dist/{client → modules/storage}/storage-metadata-crypto.d.ts +0 -0
- /package/dist/{client → modules/storage}/storage-metadata-crypto.js +0 -0
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { normalizeProductApiBaseUrl } from './api-base-url';
|
|
2
|
-
import { normalizeLocalCryptoError } from './decryption-errors';
|
|
3
|
-
import { checkLocalCryptoHealth } from './local-crypto-health';
|
|
4
|
-
import { buildMediaMessageMetadataPayload, extractMediaAssetIds, serializeMediaMessageMetadata, } from './media-message-metadata';
|
|
5
|
-
import { mapLocalSdkMessage } from './message.mapper';
|
|
6
|
-
import { buildDecryptedDriveFileMetadata, buildDecryptedDriveFolderMetadata, buildEncryptedDriveFileMetadata, buildEncryptedDriveFolderMetadata, normalizeDriveFileMetadataInput, normalizeDriveFolderMetadataInput, normalizeEncryptedDriveFileMetadataInput, normalizeEncryptedDriveFolderMetadataInput, } from './storage-metadata-crypto';
|
|
7
|
-
import { createDriveWrappedItemKeyForRecipient } from './drive-key-wrapping';
|
|
8
|
-
import { WasmCallQueue } from './wasm-call-queue';
|
|
9
|
-
const DEFAULT_DEVICE_ID = 1;
|
|
10
|
-
const DEFAULT_REGISTRATION_ID = 1;
|
|
11
|
-
const DEFAULT_SIGNED_PREKEY_ID = 1;
|
|
12
|
-
const DEFAULT_ONE_TIME_PREKEY_COUNT = 10;
|
|
13
|
-
const DEFAULT_MIN_ONE_TIME_PREKEYS = 5;
|
|
14
|
-
const DEFAULT_REPLENISH_ONE_TIME_PREKEYS = 10;
|
|
15
|
-
export class MssLinkBrowserClient {
|
|
16
|
-
userId;
|
|
17
|
-
apiBaseUrl;
|
|
18
|
-
deviceId;
|
|
19
|
-
registrationId;
|
|
20
|
-
signedPrekeyId;
|
|
21
|
-
initialOneTimePrekeyCount;
|
|
22
|
-
minOneTimePrekeys;
|
|
23
|
-
replenishOneTimePrekeys;
|
|
24
|
-
queue = new WasmCallQueue();
|
|
25
|
-
wasmClient = null;
|
|
26
|
-
wasmModulePromise = null;
|
|
27
|
-
accessToken;
|
|
28
|
-
constructor(options) {
|
|
29
|
-
this.userId = options.userId;
|
|
30
|
-
this.apiBaseUrl = normalizeProductApiBaseUrl(options.apiBaseUrl);
|
|
31
|
-
this.accessToken = options.accessToken ?? null;
|
|
32
|
-
this.deviceId = options.deviceId ?? DEFAULT_DEVICE_ID;
|
|
33
|
-
this.registrationId =
|
|
34
|
-
options.registrationId ?? DEFAULT_REGISTRATION_ID;
|
|
35
|
-
this.signedPrekeyId =
|
|
36
|
-
options.signedPrekeyId ?? DEFAULT_SIGNED_PREKEY_ID;
|
|
37
|
-
this.initialOneTimePrekeyCount =
|
|
38
|
-
options.initialOneTimePrekeyCount ??
|
|
39
|
-
DEFAULT_ONE_TIME_PREKEY_COUNT;
|
|
40
|
-
this.minOneTimePrekeys =
|
|
41
|
-
options.minOneTimePrekeys ?? DEFAULT_MIN_ONE_TIME_PREKEYS;
|
|
42
|
-
this.replenishOneTimePrekeys =
|
|
43
|
-
options.replenishOneTimePrekeys ??
|
|
44
|
-
DEFAULT_REPLENISH_ONE_TIME_PREKEYS;
|
|
45
|
-
}
|
|
46
|
-
setAccessToken(accessToken) {
|
|
47
|
-
this.accessToken = accessToken;
|
|
48
|
-
this.wasmClient?.setAccessToken(accessToken);
|
|
49
|
-
}
|
|
50
|
-
async ensureReady() {
|
|
51
|
-
try {
|
|
52
|
-
await this.runWithClient(async (client) => {
|
|
53
|
-
await client.ensureDeviceRegistered(this.registrationId, this.signedPrekeyId, this.initialOneTimePrekeyCount);
|
|
54
|
-
await client.replenishOneTimePreKeys(this.minOneTimePrekeys, this.replenishOneTimePrekeys);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
throw normalizeLocalCryptoError(error);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
async getLocalCryptoHealth() {
|
|
62
|
-
return checkLocalCryptoHealth(() => this.ensureReady());
|
|
63
|
-
}
|
|
64
|
-
async sendMessage(params) {
|
|
65
|
-
try {
|
|
66
|
-
await this.ensureReady();
|
|
67
|
-
return this.runWithClient((client) => client.sendMessage(params.chatId, params.targetUserId, params.text, params.kind ?? 'TEXT'));
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
throw normalizeLocalCryptoError(error);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
async sendMediaMessage(params) {
|
|
74
|
-
try {
|
|
75
|
-
await this.ensureReady();
|
|
76
|
-
const payload = buildMediaMessageMetadataPayload(params.attachments, params.caption);
|
|
77
|
-
const metadataJson = serializeMediaMessageMetadata(payload);
|
|
78
|
-
const mediaAssetIds = extractMediaAssetIds(params.attachments);
|
|
79
|
-
return this.runWithClient((client) => client.sendMediaMessage(params.chatId, params.targetUserId, metadataJson, mediaAssetIds));
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
throw normalizeLocalCryptoError(error);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async encryptMediaBlob(input) {
|
|
86
|
-
try {
|
|
87
|
-
const plaintext = new Uint8Array(await input.blob.arrayBuffer());
|
|
88
|
-
const encrypted = await this.queue.run(async () => {
|
|
89
|
-
const module = await this.loadWasmModule();
|
|
90
|
-
return module.encryptMediaBytes(plaintext);
|
|
91
|
-
});
|
|
92
|
-
const encryptedBytes = new Uint8Array(encrypted.ciphertext);
|
|
93
|
-
return {
|
|
94
|
-
encryptedBlob: new Blob([encryptedBytes], {
|
|
95
|
-
type: 'application/octet-stream',
|
|
96
|
-
}),
|
|
97
|
-
encryption: {
|
|
98
|
-
schema: 'mss.link.media-encryption.v1',
|
|
99
|
-
algorithm: 'AES-256-GCM',
|
|
100
|
-
keyId: input.assetId,
|
|
101
|
-
nonce: encrypted.nonce,
|
|
102
|
-
wrappedKey: encrypted.key,
|
|
103
|
-
},
|
|
104
|
-
attachment: {
|
|
105
|
-
assetId: input.assetId,
|
|
106
|
-
mimeType: input.mimeType,
|
|
107
|
-
size: input.size,
|
|
108
|
-
...(input.originalName ? { originalName: input.originalName } : {}),
|
|
109
|
-
...(input.uploadedAt ? { uploadedAt: input.uploadedAt } : {}),
|
|
110
|
-
encryption: {
|
|
111
|
-
schema: 'mss.link.media-encryption.v1',
|
|
112
|
-
algorithm: 'AES-256-GCM',
|
|
113
|
-
keyId: input.assetId,
|
|
114
|
-
nonce: encrypted.nonce,
|
|
115
|
-
wrappedKey: encrypted.key,
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
throw normalizeLocalCryptoError(error);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async decryptMediaBlob(input) {
|
|
125
|
-
const encryption = input.metadata.encryption;
|
|
126
|
-
if (!encryption) {
|
|
127
|
-
return {
|
|
128
|
-
blob: input.encryptedBlob,
|
|
129
|
-
mimeType: input.metadata.mimeType,
|
|
130
|
-
...(input.metadata.originalName
|
|
131
|
-
? { fileName: input.metadata.originalName }
|
|
132
|
-
: {}),
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
try {
|
|
136
|
-
const ciphertext = new Uint8Array(await input.encryptedBlob.arrayBuffer());
|
|
137
|
-
const plaintext = await this.queue.run(async () => {
|
|
138
|
-
const module = await this.loadWasmModule();
|
|
139
|
-
return module.decryptMediaBytes(ciphertext, encryption.wrappedKey, encryption.nonce);
|
|
140
|
-
});
|
|
141
|
-
return {
|
|
142
|
-
blob: new Blob([new Uint8Array(plaintext)], {
|
|
143
|
-
type: input.metadata.mimeType,
|
|
144
|
-
}),
|
|
145
|
-
mimeType: input.metadata.mimeType,
|
|
146
|
-
...(input.metadata.originalName
|
|
147
|
-
? { fileName: input.metadata.originalName }
|
|
148
|
-
: {}),
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
throw normalizeLocalCryptoError(error);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
async encryptDriveFolderMetadata(input) {
|
|
156
|
-
try {
|
|
157
|
-
const metadata = normalizeDriveFolderMetadataInput(input);
|
|
158
|
-
const encryptedName = await this.queue.run(async () => {
|
|
159
|
-
const module = await this.loadWasmModule();
|
|
160
|
-
return module.encryptStorageMetadata(metadata.name);
|
|
161
|
-
});
|
|
162
|
-
return buildEncryptedDriveFolderMetadata(encryptedName);
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
throw normalizeLocalCryptoError(error);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
async decryptDriveFolderMetadata(input) {
|
|
169
|
-
try {
|
|
170
|
-
const metadata = normalizeEncryptedDriveFolderMetadataInput(input);
|
|
171
|
-
const name = await this.queue.run(async () => {
|
|
172
|
-
const module = await this.loadWasmModule();
|
|
173
|
-
return module.decryptStorageMetadata(metadata.encryptedName);
|
|
174
|
-
});
|
|
175
|
-
return buildDecryptedDriveFolderMetadata(name);
|
|
176
|
-
}
|
|
177
|
-
catch (error) {
|
|
178
|
-
throw normalizeLocalCryptoError(error);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
async encryptDriveFileMetadata(input) {
|
|
182
|
-
try {
|
|
183
|
-
const metadata = normalizeDriveFileMetadataInput(input);
|
|
184
|
-
const [encryptedName, encryptedMimeType] = await this.queue.run(async () => {
|
|
185
|
-
const module = await this.loadWasmModule();
|
|
186
|
-
return [
|
|
187
|
-
module.encryptStorageMetadata(metadata.name),
|
|
188
|
-
module.encryptStorageMetadata(metadata.mimeType),
|
|
189
|
-
];
|
|
190
|
-
});
|
|
191
|
-
return buildEncryptedDriveFileMetadata(encryptedName, encryptedMimeType);
|
|
192
|
-
}
|
|
193
|
-
catch (error) {
|
|
194
|
-
throw normalizeLocalCryptoError(error);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
async decryptDriveFileMetadata(input) {
|
|
198
|
-
try {
|
|
199
|
-
const metadata = normalizeEncryptedDriveFileMetadataInput(input);
|
|
200
|
-
const [name, mimeType] = await this.queue.run(async () => {
|
|
201
|
-
const module = await this.loadWasmModule();
|
|
202
|
-
return [
|
|
203
|
-
module.decryptStorageMetadata(metadata.encryptedName),
|
|
204
|
-
module.decryptStorageMetadata(metadata.encryptedMimeType),
|
|
205
|
-
];
|
|
206
|
-
});
|
|
207
|
-
return buildDecryptedDriveFileMetadata(name, mimeType);
|
|
208
|
-
}
|
|
209
|
-
catch (error) {
|
|
210
|
-
throw normalizeLocalCryptoError(error);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
createDriveWrappedItemKeyForRecipient(input) {
|
|
214
|
-
return createDriveWrappedItemKeyForRecipient(input);
|
|
215
|
-
}
|
|
216
|
-
async syncMessages() {
|
|
217
|
-
try {
|
|
218
|
-
await this.runWithClient((client) => client.syncMessages());
|
|
219
|
-
}
|
|
220
|
-
catch (error) {
|
|
221
|
-
throw normalizeLocalCryptoError(error);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
async getLocalMessages(chatId) {
|
|
225
|
-
try {
|
|
226
|
-
const rawMessages = await this.runWithClient((client) => client.getLocalMessages(chatId));
|
|
227
|
-
return rawMessages.map((message) => mapLocalSdkMessage(message));
|
|
228
|
-
}
|
|
229
|
-
catch (error) {
|
|
230
|
-
throw normalizeLocalCryptoError(error);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
reset() {
|
|
234
|
-
this.wasmClient?.free();
|
|
235
|
-
this.wasmClient = null;
|
|
236
|
-
this.wasmModulePromise = null;
|
|
237
|
-
}
|
|
238
|
-
async runWithClient(callback) {
|
|
239
|
-
return this.queue.run(async () => callback(await this.getClient()));
|
|
240
|
-
}
|
|
241
|
-
async getClient() {
|
|
242
|
-
if (typeof window === 'undefined') {
|
|
243
|
-
throw new Error('MSS Link browser client is available only in browser context.');
|
|
244
|
-
}
|
|
245
|
-
if (!this.wasmClient) {
|
|
246
|
-
const sdkModule = await this.loadWasmModule();
|
|
247
|
-
this.wasmClient = new sdkModule.WasmMssClient(this.userId, this.deviceId, this.apiBaseUrl);
|
|
248
|
-
this.wasmClient.setAccessToken(this.accessToken);
|
|
249
|
-
}
|
|
250
|
-
return this.wasmClient;
|
|
251
|
-
}
|
|
252
|
-
loadWasmModule() {
|
|
253
|
-
this.wasmModulePromise ??= import('@msssystems/mss-crypto-wasm').then((module) => module);
|
|
254
|
-
return this.wasmModulePromise;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/{client/drive-sharing.contracts.js → modules/storage/drive-file-runtime.contracts.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|