@msssystems/mss-link-sdk 0.2.5 → 0.2.7

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.
@@ -13,7 +13,7 @@ export class BrowserMssLinkClient extends MssLinkClient {
13
13
  this.cryptoEngine = new WasmCryptoEngine({
14
14
  userId: options.userId,
15
15
  apiBaseUrl: options.baseUrl,
16
- accessToken: typeof options.token === 'string' ? options.token : undefined,
16
+ accessToken: options.token,
17
17
  deviceId: options.deviceId,
18
18
  registrationId: options.registrationId,
19
19
  signedPrekeyId: options.signedPrekeyId,
@@ -3,6 +3,7 @@ import type { WasmEncryptedMediaBytes } from '../modules/media/media-crypto.cont
3
3
  export interface MssLinkWasmClient extends WasmMssClient {
4
4
  sendMediaMessage(chatId: string, targetUserId: string, metadataJson: string, mediaAssetIds: string[]): Promise<string>;
5
5
  healSession(chatId: string, targetUserId: string): Promise<string>;
6
+ deleteSession(targetUserId: string): Promise<void>;
6
7
  }
7
8
  export type WasmMssClientConstructor = new (userId: string, deviceId: number, apiBaseUrl: string) => MssLinkWasmClient;
8
9
  export interface MssCryptoWasmModule {
@@ -3,7 +3,7 @@ import type { MssCryptoWasmModule, WasmMssClientInstance } from '../client/wasm-
3
3
  export interface WasmCryptoEngineOptions {
4
4
  userId: string;
5
5
  apiBaseUrl: string;
6
- accessToken?: string | undefined;
6
+ accessToken?: string | (() => string | Promise<string>) | undefined;
7
7
  deviceId?: number | undefined;
8
8
  registrationId?: number | undefined;
9
9
  signedPrekeyId?: number | undefined;
@@ -25,7 +25,7 @@ export declare class WasmCryptoEngine {
25
25
  private wasmModulePromise;
26
26
  private accessToken;
27
27
  constructor(options: WasmCryptoEngineOptions);
28
- setAccessToken(accessToken: string | null): void;
28
+ setAccessToken(accessToken: string | (() => string | Promise<string>) | null): void;
29
29
  getLocalCryptoHealth(): Promise<import("./local-crypto-health.contracts").LocalCryptoHealth>;
30
30
  ensureReady(): Promise<void>;
31
31
  reset(): void;
@@ -36,7 +36,14 @@ export class WasmCryptoEngine {
36
36
  }
37
37
  setAccessToken(accessToken) {
38
38
  this.accessToken = accessToken;
39
- this.wasmClient?.setAccessToken(accessToken);
39
+ if (typeof accessToken === 'string' || accessToken === null) {
40
+ this.wasmClient?.setAccessToken(accessToken);
41
+ }
42
+ else if (this.wasmClient) {
43
+ Promise.resolve(accessToken()).then((tokenStr) => {
44
+ this.wasmClient?.setAccessToken(tokenStr);
45
+ }).catch(() => { });
46
+ }
40
47
  }
41
48
  async getLocalCryptoHealth() {
42
49
  const { checkLocalCryptoHealth } = await import('./local-crypto-health');
@@ -68,8 +75,9 @@ export class WasmCryptoEngine {
68
75
  if (!this.wasmClient) {
69
76
  const sdkModule = await this.loadWasmModule();
70
77
  this.wasmClient = new sdkModule.WasmMssClient(this.userId, this.deviceId, this.apiBaseUrl);
71
- this.wasmClient.setAccessToken(this.accessToken);
72
78
  }
79
+ const tokenStr = typeof this.accessToken === 'function' ? await this.accessToken() : this.accessToken;
80
+ this.wasmClient.setAccessToken(tokenStr);
73
81
  return this.wasmClient;
74
82
  }
75
83
  loadWasmModule() {
@@ -27,6 +27,7 @@ export class MessagesCryptoClient {
27
27
  }
28
28
  async handleSessionHealing(client, messages) {
29
29
  for (const message of messages) {
30
+ // Case 1: Decryption failed -> request peer to reset session
30
31
  if (message.deliveryState === 'FAILED' &&
31
32
  (message.plaintext === '[Ошибка дешифровки]' ||
32
33
  message.plaintext === '[Ошибка дешифровки]')) {
@@ -40,6 +41,17 @@ export class MessagesCryptoClient {
40
41
  console.error('[E2EE] Failed to heal session:', e);
41
42
  }
42
43
  }
44
+ // Case 2: Received SESSION_RESET request from peer -> clear local session state
45
+ if (message.kind === 'SYSTEM' &&
46
+ message.plaintext.includes('SESSION_RESET')) {
47
+ console.warn(`[E2EE] Received SESSION_RESET request from ${message.senderId}. Clearing local session state...`);
48
+ try {
49
+ await client.deleteSession(message.senderId);
50
+ }
51
+ catch (e) {
52
+ console.error('[E2EE] Failed to handle incoming SESSION_RESET:', e);
53
+ }
54
+ }
43
55
  }
44
56
  }
45
57
  async getLocalMessages(chatId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@msssystems/mss-link-sdk",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Official managed application SDK for MSS ecosystem",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -77,7 +77,7 @@
77
77
  }
78
78
  },
79
79
  "devDependencies": {
80
- "@msssystems/mss-crypto-wasm": "^0.1.17",
80
+ "@msssystems/mss-crypto-wasm": "^0.1.21",
81
81
  "@nestjs/common": "^11.0.1",
82
82
  "@nestjs/core": "^11.0.1",
83
83
  "@types/express": "^5.0.0",