@msssystems/mss-link-sdk 0.2.15 → 0.2.17
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.
|
@@ -8,6 +8,7 @@ export interface MssLinkWasmClient extends WasmMssClient {
|
|
|
8
8
|
getSenderKeyDistribution(groupId: string): Promise<SenderKeyDistribution | undefined>;
|
|
9
9
|
storeReceivedSenderKeyDistribution(distJson: SenderKeyDistribution): Promise<void>;
|
|
10
10
|
rotateGroupSenderKey(groupId: string): Promise<SenderKeyDistribution>;
|
|
11
|
+
hasReceivedSenderKey(groupId: string, senderId: string): Promise<boolean>;
|
|
11
12
|
encryptSenderKeyDistribution(recipientId: string, distJson: SenderKeyDistribution): Promise<string>;
|
|
12
13
|
decryptSenderKeyDistribution(senderId: string, encryptedBlob: string): Promise<SenderKeyDistribution>;
|
|
13
14
|
}
|
|
@@ -17,6 +17,7 @@ export declare class MessagesCryptoClient {
|
|
|
17
17
|
getSenderKeyDistribution(groupId: string): Promise<SenderKeyDistribution | undefined>;
|
|
18
18
|
storeReceivedSenderKeyDistribution(distJson: SenderKeyDistribution): Promise<void>;
|
|
19
19
|
rotateGroupSenderKey(groupId: string): Promise<SenderKeyDistribution>;
|
|
20
|
+
hasReceivedSenderKey(groupId: string, senderId: string): Promise<boolean>;
|
|
20
21
|
encryptSenderKeyDistribution(recipientId: string, distJson: SenderKeyDistribution): Promise<string>;
|
|
21
22
|
decryptSenderKeyDistribution(senderId: string, encryptedBlob: string): Promise<SenderKeyDistribution>;
|
|
22
23
|
}
|
|
@@ -31,7 +31,7 @@ export class MessagesCryptoClient {
|
|
|
31
31
|
}
|
|
32
32
|
async handleSessionHealing(client, messages) {
|
|
33
33
|
for (const message of messages) {
|
|
34
|
-
// Case 1: Decryption failed -> request peer to reset session
|
|
34
|
+
// Case 1: Decryption failed -> request peer to reset session.
|
|
35
35
|
if (message.deliveryState === 'FAILED' &&
|
|
36
36
|
(message.plaintext === '[Ошибка дешифровки]' ||
|
|
37
37
|
message.plaintext === '[Ошибка дешифровки]')) {
|
|
@@ -39,20 +39,39 @@ export class MessagesCryptoClient {
|
|
|
39
39
|
continue;
|
|
40
40
|
if (this.groupChatIds.has(message.chatId))
|
|
41
41
|
continue;
|
|
42
|
+
// Deduplicate: only heal each failed message once per browser session.
|
|
43
|
+
// Without this guard, every syncMessages() call re-triggers healSession()
|
|
44
|
+
// for the same messageId because the failed placeholder stays in IDB,
|
|
45
|
+
// creating an infinite loop of SESSION_RESET messages.
|
|
46
|
+
const healedKey = `healed:${message.messageId}`;
|
|
47
|
+
if (typeof window !== 'undefined' && localStorage.getItem(healedKey)) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
42
50
|
console.warn(`[E2EE] Decryption failed for message ${message.messageId} from ${message.senderId}. Triggering auto-heal...`);
|
|
43
51
|
try {
|
|
44
52
|
await client.healSession(message.chatId, message.senderId);
|
|
53
|
+
if (typeof window !== 'undefined') {
|
|
54
|
+
localStorage.setItem(healedKey, '1');
|
|
55
|
+
}
|
|
45
56
|
}
|
|
46
57
|
catch (e) {
|
|
47
58
|
console.error('[E2EE] Failed to heal session:', e);
|
|
48
59
|
}
|
|
49
60
|
}
|
|
50
|
-
// Case 2: Received SESSION_RESET request from peer -> clear local session state
|
|
61
|
+
// Case 2: Received SESSION_RESET request from peer -> clear local session state.
|
|
51
62
|
if (message.kind === 'SYSTEM' &&
|
|
52
63
|
message.plaintext.includes('SESSION_RESET')) {
|
|
64
|
+
// Deduplicate: handle SESSION_RESET only once per message.
|
|
65
|
+
const resetKey = `reset-handled:${message.messageId}`;
|
|
66
|
+
if (typeof window !== 'undefined' && localStorage.getItem(resetKey)) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
53
69
|
console.warn(`[E2EE] Received SESSION_RESET request from ${message.senderId}. Clearing local session state...`);
|
|
54
70
|
try {
|
|
55
71
|
await client.deleteSession(message.senderId);
|
|
72
|
+
if (typeof window !== 'undefined') {
|
|
73
|
+
localStorage.setItem(resetKey, '1');
|
|
74
|
+
}
|
|
56
75
|
}
|
|
57
76
|
catch (e) {
|
|
58
77
|
console.error('[E2EE] Failed to handle incoming SESSION_RESET:', e);
|
|
@@ -98,6 +117,15 @@ export class MessagesCryptoClient {
|
|
|
98
117
|
throw normalizeLocalCryptoError(error);
|
|
99
118
|
}
|
|
100
119
|
}
|
|
120
|
+
async hasReceivedSenderKey(groupId, senderId) {
|
|
121
|
+
try {
|
|
122
|
+
await this.engine.ensureReady();
|
|
123
|
+
return this.engine.runWithClient((client) => client.hasReceivedSenderKey(groupId, senderId));
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
throw normalizeLocalCryptoError(error);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
101
129
|
async encryptSenderKeyDistribution(recipientId, distJson) {
|
|
102
130
|
try {
|
|
103
131
|
await this.engine.ensureReady();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@msssystems/mss-link-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.17",
|
|
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.
|
|
80
|
+
"@msssystems/mss-crypto-wasm": "^0.1.29",
|
|
81
81
|
"@nestjs/common": "^11.0.1",
|
|
82
82
|
"@nestjs/core": "^11.0.1",
|
|
83
83
|
"@types/express": "^5.0.0",
|