@aseppxyzz12/baileys 1.1.8
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/LICENSE +25 -0
- package/README.md +2579 -0
- package/WAProto/AICommon/AICommon.js +19396 -0
- package/WAProto/AICommon/AICommon.proto +820 -0
- package/WAProto/Adv/Adv.js +1137 -0
- package/WAProto/Adv/Adv.proto +42 -0
- package/WAProto/BotMetadata/BotMetadata.js +8975 -0
- package/WAProto/BotMetadata/BotMetadata.proto +484 -0
- package/WAProto/Cert/Cert.js +893 -0
- package/WAProto/Cert/Cert.proto +30 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.js +673 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.proto +9 -0
- package/WAProto/CompanionReg/CompanionReg.js +2457 -0
- package/WAProto/CompanionReg/CompanionReg.proto +103 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.js +846 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +38 -0
- package/WAProto/E2E/E2E.js +78728 -0
- package/WAProto/E2E/E2E.proto +1970 -0
- package/WAProto/Ephemeral/Ephemeral.js +143 -0
- package/WAProto/Ephemeral/Ephemeral.proto +7 -0
- package/WAProto/HistorySync/HistorySync.js +95931 -0
- package/WAProto/HistorySync/HistorySync.proto +229 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +414 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +13 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +980 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +38 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +81185 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +88 -0
- package/WAProto/MmsRetry/MmsRetry.js +310 -0
- package/WAProto/MmsRetry/MmsRetry.proto +19 -0
- package/WAProto/Protocol/Protocol.js +399 -0
- package/WAProto/Protocol/Protocol.proto +22 -0
- package/WAProto/Reporting/Reporting.js +535 -0
- package/WAProto/Reporting/Reporting.proto +22 -0
- package/WAProto/ServerSync/ServerSync.js +1830 -0
- package/WAProto/ServerSync/ServerSync.proto +70 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +3267 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +95 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1140 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +44 -0
- package/WAProto/StatusAttributions/StatusAttributions.js +1604 -0
- package/WAProto/StatusAttributions/StatusAttributions.proto +89 -0
- package/WAProto/SyncAction/SyncAction.js +17424 -0
- package/WAProto/SyncAction/SyncAction.proto +663 -0
- package/WAProto/UserPassword/UserPassword.js +544 -0
- package/WAProto/UserPassword/UserPassword.proto +28 -0
- package/WAProto/VnameCert/VnameCert.js +1466 -0
- package/WAProto/VnameCert/VnameCert.proto +65 -0
- package/WAProto/Wa6/Wa6.js +4601 -0
- package/WAProto/Wa6/Wa6.proto +241 -0
- package/WAProto/Web/Web.js +90819 -0
- package/WAProto/Web/Web.proto +605 -0
- package/WAProto/index.js +30 -0
- package/engine-requirements.js +9 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -0
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Function/Download/tiktok.js +19 -0
- package/lib/Function/Tools/bypass.js +19 -0
- package/lib/Function/index.js +13 -0
- package/lib/Signal/Group/ciphertext-message.js +14 -0
- package/lib/Signal/Group/group-session-builder.js +46 -0
- package/lib/Signal/Group/group_cipher.js +104 -0
- package/lib/Signal/Group/index.js +42 -0
- package/lib/Signal/Group/keyhelper.js +21 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +78 -0
- package/lib/Signal/Group/sender-key-name.js +49 -0
- package/lib/Signal/Group/sender-key-record.js +45 -0
- package/lib/Signal/Group/sender-key-state.js +100 -0
- package/lib/Signal/Group/sender-message-key.js +28 -0
- package/lib/Signal/libsignal.js +364 -0
- package/lib/Signal/lid-mapping.js +164 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +31 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.js +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/Client/websocket.js +67 -0
- package/lib/Socket/business.js +291 -0
- package/lib/Socket/chats.js +874 -0
- package/lib/Socket/community.js +454 -0
- package/lib/Socket/dugong.js +658 -0
- package/lib/Socket/groups.js +357 -0
- package/lib/Socket/index.js +13 -0
- package/lib/Socket/messages-recv.js +1509 -0
- package/lib/Socket/messages-send.js +1505 -0
- package/lib/Socket/mex.js +54 -0
- package/lib/Socket/newsletter.js +171 -0
- package/lib/Socket/registration.js +167 -0
- package/lib/Socket/rich-content.js +279 -0
- package/lib/Socket/socket.js +905 -0
- package/lib/Socket/username.js +157 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.js +37 -0
- package/lib/Store/keyed-db.js +114 -0
- package/lib/Store/make-cache-manager-store.js +77 -0
- package/lib/Store/make-in-memory-store.js +423 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +26 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +4 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Mex.js +40 -0
- package/lib/Types/MexUpdates.js +15 -0
- package/lib/Types/Newsletter.js +32 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +9 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +60 -0
- package/lib/Utils/auth-utils.js +256 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/bot-toolkit.js +455 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +233 -0
- package/lib/Utils/chat-utils.js +904 -0
- package/lib/Utils/companion-reg-client-utils.js +41 -0
- package/lib/Utils/crypto.js +144 -0
- package/lib/Utils/decode-wa-message.js +305 -0
- package/lib/Utils/event-buffer.js +555 -0
- package/lib/Utils/generics.js +411 -0
- package/lib/Utils/history.js +100 -0
- package/lib/Utils/identity-change-handler.js +53 -0
- package/lib/Utils/index.js +57 -0
- package/lib/Utils/link-preview.js +76 -0
- package/lib/Utils/logger.js +4 -0
- package/lib/Utils/lt-hash.js +45 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/message-composer.js +289 -0
- package/lib/Utils/message-retry-manager.js +134 -0
- package/lib/Utils/messages-media.js +806 -0
- package/lib/Utils/messages.js +1908 -0
- package/lib/Utils/noise-handler.js +157 -0
- package/lib/Utils/offline-node-processor.js +42 -0
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +814 -0
- package/lib/Utils/reporting-utils.js +264 -0
- package/lib/Utils/signal.js +183 -0
- package/lib/Utils/stanza-ack.js +36 -0
- package/lib/Utils/sync-action-utils.js +52 -0
- package/lib/Utils/tc-token-utils.js +167 -0
- package/lib/Utils/use-multi-file-auth-state.js +104 -0
- package/lib/Utils/validate-connection.js +229 -0
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1308 -0
- package/lib/WABinary/decode.js +233 -0
- package/lib/WABinary/encode.js +212 -0
- package/lib/WABinary/generic-utils.js +124 -0
- package/lib/WABinary/index.js +36 -0
- package/lib/WABinary/jid-utils.js +101 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +12 -0
- package/lib/WAM/constants.js +20491 -0
- package/lib/WAM/encode.js +148 -0
- package/lib/WAM/index.js +34 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +38 -0
- package/lib/WAUSync/USyncQuery.js +97 -0
- package/lib/WAUSync/USyncUser.js +33 -0
- package/lib/WAUSync/index.js +34 -0
- package/lib/index.js +113 -0
- package/lib/messages-send.js +1496 -0
- package/package.json +100 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { Boom: Boom } = require("@hapi/boom");
|
|
4
|
+
const { proto: proto } = require("../../WAProto");
|
|
5
|
+
const {
|
|
6
|
+
NOISE_MODE: NOISE_MODE,
|
|
7
|
+
WA_CERT_DETAILS: WA_CERT_DETAILS,
|
|
8
|
+
} = require("../Defaults/constants");
|
|
9
|
+
const { decodeBinaryNode: decodeBinaryNode } = require("../WABinary");
|
|
10
|
+
const {
|
|
11
|
+
aesDecryptGCM: aesDecryptGCM,
|
|
12
|
+
aesEncryptGCM: aesEncryptGCM,
|
|
13
|
+
Curve: Curve,
|
|
14
|
+
hkdf: hkdf,
|
|
15
|
+
sha256: sha256,
|
|
16
|
+
} = require("./crypto");
|
|
17
|
+
const generateIV = (counter) => {
|
|
18
|
+
const iv = new ArrayBuffer(12);
|
|
19
|
+
new DataView(iv).setUint32(8, counter);
|
|
20
|
+
return new Uint8Array(iv);
|
|
21
|
+
};
|
|
22
|
+
const makeNoiseHandler = ({
|
|
23
|
+
keyPair: { private: privateKey, public: publicKey },
|
|
24
|
+
NOISE_HEADER: NOISE_HEADER,
|
|
25
|
+
logger: logger,
|
|
26
|
+
routingInfo: routingInfo,
|
|
27
|
+
}) => {
|
|
28
|
+
logger = logger.child({ class: "ns" });
|
|
29
|
+
const authenticate = (data) => {
|
|
30
|
+
if (!isFinished) {
|
|
31
|
+
hash = sha256(Buffer.concat([hash, data]));
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const encrypt = (plaintext) => {
|
|
35
|
+
const result = aesEncryptGCM(plaintext, encKey, generateIV(writeCounter), hash);
|
|
36
|
+
writeCounter += 1;
|
|
37
|
+
authenticate(result);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
const decrypt = (ciphertext) => {
|
|
41
|
+
const iv = generateIV(isFinished ? readCounter : writeCounter);
|
|
42
|
+
const result = aesDecryptGCM(ciphertext, decKey, iv, hash);
|
|
43
|
+
if (isFinished) {
|
|
44
|
+
readCounter += 1;
|
|
45
|
+
} else {
|
|
46
|
+
writeCounter += 1;
|
|
47
|
+
}
|
|
48
|
+
authenticate(ciphertext);
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
const localHKDF = async (data) => {
|
|
52
|
+
const key = await hkdf(Buffer.from(data), 64, { salt: salt, info: "" });
|
|
53
|
+
return [key.slice(0, 32), key.slice(32)];
|
|
54
|
+
};
|
|
55
|
+
const mixIntoKey = async (data) => {
|
|
56
|
+
const [write, read] = await localHKDF(data);
|
|
57
|
+
salt = write;
|
|
58
|
+
encKey = read;
|
|
59
|
+
decKey = read;
|
|
60
|
+
readCounter = 0;
|
|
61
|
+
writeCounter = 0;
|
|
62
|
+
};
|
|
63
|
+
const finishInit = async () => {
|
|
64
|
+
const [write, read] = await localHKDF(new Uint8Array(0));
|
|
65
|
+
encKey = write;
|
|
66
|
+
decKey = read;
|
|
67
|
+
hash = Buffer.from([]);
|
|
68
|
+
readCounter = 0;
|
|
69
|
+
writeCounter = 0;
|
|
70
|
+
isFinished = true;
|
|
71
|
+
};
|
|
72
|
+
const data = Buffer.from(NOISE_MODE);
|
|
73
|
+
let hash = data.byteLength === 32 ? data : sha256(data);
|
|
74
|
+
let salt = hash;
|
|
75
|
+
let encKey = hash;
|
|
76
|
+
let decKey = hash;
|
|
77
|
+
let readCounter = 0;
|
|
78
|
+
let writeCounter = 0;
|
|
79
|
+
let isFinished = false;
|
|
80
|
+
let sentIntro = false;
|
|
81
|
+
let inBytes = Buffer.alloc(0);
|
|
82
|
+
authenticate(NOISE_HEADER);
|
|
83
|
+
authenticate(publicKey);
|
|
84
|
+
return {
|
|
85
|
+
encrypt: encrypt,
|
|
86
|
+
decrypt: decrypt,
|
|
87
|
+
authenticate: authenticate,
|
|
88
|
+
mixIntoKey: mixIntoKey,
|
|
89
|
+
finishInit: finishInit,
|
|
90
|
+
processHandshake: async ({ serverHello: serverHello }, noiseKey) => {
|
|
91
|
+
authenticate(serverHello.ephemeral);
|
|
92
|
+
await mixIntoKey(Curve.sharedKey(privateKey, serverHello.ephemeral));
|
|
93
|
+
const decStaticContent = decrypt(serverHello.static);
|
|
94
|
+
await mixIntoKey(Curve.sharedKey(privateKey, decStaticContent));
|
|
95
|
+
const certDecoded = decrypt(serverHello.payload);
|
|
96
|
+
const { intermediate: certIntermediate } = proto.CertChain.decode(certDecoded);
|
|
97
|
+
const { issuerSerial: issuerSerial } = proto.CertChain.NoiseCertificate.Details.decode(
|
|
98
|
+
certIntermediate.details
|
|
99
|
+
);
|
|
100
|
+
if (issuerSerial !== WA_CERT_DETAILS.SERIAL) {
|
|
101
|
+
throw new Boom("certification match failed", { statusCode: 400 });
|
|
102
|
+
}
|
|
103
|
+
const keyEnc = encrypt(noiseKey.public);
|
|
104
|
+
await mixIntoKey(Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
|
|
105
|
+
return keyEnc;
|
|
106
|
+
},
|
|
107
|
+
encodeFrame: (data) => {
|
|
108
|
+
if (isFinished) {
|
|
109
|
+
data = encrypt(data);
|
|
110
|
+
}
|
|
111
|
+
let header;
|
|
112
|
+
if (routingInfo) {
|
|
113
|
+
header = Buffer.alloc(7);
|
|
114
|
+
header.write("ED", 0, "utf8");
|
|
115
|
+
header.writeUint8(0, 2);
|
|
116
|
+
header.writeUint8(1, 3);
|
|
117
|
+
header.writeUint8(routingInfo.byteLength >> 16, 4);
|
|
118
|
+
header.writeUint16BE(routingInfo.byteLength & 65535, 5);
|
|
119
|
+
header = Buffer.concat([header, routingInfo, NOISE_HEADER]);
|
|
120
|
+
} else {
|
|
121
|
+
header = Buffer.from(NOISE_HEADER);
|
|
122
|
+
}
|
|
123
|
+
const introSize = sentIntro ? 0 : header.length;
|
|
124
|
+
const frame = Buffer.alloc(introSize + 3 + data.byteLength);
|
|
125
|
+
if (!sentIntro) {
|
|
126
|
+
frame.set(header);
|
|
127
|
+
sentIntro = true;
|
|
128
|
+
}
|
|
129
|
+
frame.writeUInt8(data.byteLength >> 16, introSize);
|
|
130
|
+
frame.writeUInt16BE(65535 & data.byteLength, introSize + 1);
|
|
131
|
+
frame.set(data, introSize + 3);
|
|
132
|
+
return frame;
|
|
133
|
+
},
|
|
134
|
+
decodeFrame: async (newData, onFrame) => {
|
|
135
|
+
const getBytesSize = () => {
|
|
136
|
+
if (inBytes.length >= 3) {
|
|
137
|
+
return (inBytes.readUInt8() << 16) | inBytes.readUInt16BE(1);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
inBytes = Buffer.concat([inBytes, newData]);
|
|
141
|
+
logger.trace(`recv ${newData.length} bytes, total recv ${inBytes.length} bytes`);
|
|
142
|
+
let size = getBytesSize();
|
|
143
|
+
while (size && inBytes.length >= size + 3) {
|
|
144
|
+
let frame = inBytes.slice(3, size + 3);
|
|
145
|
+
inBytes = inBytes.slice(size + 3);
|
|
146
|
+
if (isFinished) {
|
|
147
|
+
const result = decrypt(frame);
|
|
148
|
+
frame = await decodeBinaryNode(result);
|
|
149
|
+
}
|
|
150
|
+
logger.trace({ msg: frame?.attrs?.id }, "recv frame");
|
|
151
|
+
onFrame(frame);
|
|
152
|
+
size = getBytesSize();
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
module.exports = { makeNoiseHandler: makeNoiseHandler };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Ported & adapted from PouCode fork for AsepXyz Baileys
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.makeOfflineNodeProcessor = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a processor for offline stanza nodes that:
|
|
7
|
+
* - Queues nodes for sequential processing
|
|
8
|
+
* - Yields to the event loop periodically to avoid blocking
|
|
9
|
+
* - Catches handler errors to prevent the processing loop from crashing
|
|
10
|
+
*/
|
|
11
|
+
function makeOfflineNodeProcessor(nodeProcessorMap, deps, batchSize = 10) {
|
|
12
|
+
const nodes = [];
|
|
13
|
+
let isProcessing = false;
|
|
14
|
+
const enqueue = (type, node) => {
|
|
15
|
+
nodes.push({ type, node });
|
|
16
|
+
if (isProcessing) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
isProcessing = true;
|
|
20
|
+
const promise = async () => {
|
|
21
|
+
let processedInBatch = 0;
|
|
22
|
+
while (nodes.length && deps.isWsOpen()) {
|
|
23
|
+
const { type, node } = nodes.shift();
|
|
24
|
+
const nodeProcessor = nodeProcessorMap.get(type);
|
|
25
|
+
if (!nodeProcessor) {
|
|
26
|
+
deps.onUnexpectedError(new Error(`unknown offline node type: ${type}`), 'processing offline node');
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
await nodeProcessor(node).catch(err => deps.onUnexpectedError(err, `processing offline ${type}`));
|
|
30
|
+
processedInBatch++;
|
|
31
|
+
if (processedInBatch >= batchSize) {
|
|
32
|
+
processedInBatch = 0;
|
|
33
|
+
await deps.yieldToEventLoop();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
isProcessing = false;
|
|
37
|
+
};
|
|
38
|
+
promise().catch(error => deps.onUnexpectedError(error, 'processing offline nodes'));
|
|
39
|
+
};
|
|
40
|
+
return { enqueue };
|
|
41
|
+
}
|
|
42
|
+
exports.makeOfflineNodeProcessor = makeOfflineNodeProcessor;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { default: PQueue } = require("p-queue");
|
|
4
|
+
class PreKeyManager {
|
|
5
|
+
constructor(store, logger) {
|
|
6
|
+
this.store = store;
|
|
7
|
+
this.logger = logger;
|
|
8
|
+
this.queues = new Map();
|
|
9
|
+
}
|
|
10
|
+
getQueue(keyType) {
|
|
11
|
+
if (!this.queues.has(keyType)) {
|
|
12
|
+
this.queues.set(keyType, new PQueue({ concurrency: 1 }));
|
|
13
|
+
}
|
|
14
|
+
return this.queues.get(keyType);
|
|
15
|
+
}
|
|
16
|
+
async processOperations(data, keyType, transactionCache, mutations, isInTransaction) {
|
|
17
|
+
const keyData = data[keyType];
|
|
18
|
+
if (!keyData) return;
|
|
19
|
+
return this.getQueue(keyType).add(async () => {
|
|
20
|
+
transactionCache[keyType] = transactionCache[keyType] || {};
|
|
21
|
+
mutations[keyType] = mutations[keyType] || {};
|
|
22
|
+
const deletions = [];
|
|
23
|
+
const updates = {};
|
|
24
|
+
for (const keyId in keyData) {
|
|
25
|
+
if (keyData[keyId] === null) {
|
|
26
|
+
deletions.push(keyId);
|
|
27
|
+
} else {
|
|
28
|
+
updates[keyId] = keyData[keyId];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (Object.keys(updates).length > 0) {
|
|
32
|
+
Object.assign(transactionCache[keyType], updates);
|
|
33
|
+
Object.assign(mutations[keyType], updates);
|
|
34
|
+
}
|
|
35
|
+
if (deletions.length > 0) {
|
|
36
|
+
await this.processDeletions(
|
|
37
|
+
keyType,
|
|
38
|
+
deletions,
|
|
39
|
+
transactionCache,
|
|
40
|
+
mutations,
|
|
41
|
+
isInTransaction
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async processDeletions(keyType, ids, transactionCache, mutations, isInTransaction) {
|
|
47
|
+
if (isInTransaction) {
|
|
48
|
+
for (const keyId of ids) {
|
|
49
|
+
if (transactionCache[keyType]?.[keyId]) {
|
|
50
|
+
transactionCache[keyType][keyId] = null;
|
|
51
|
+
mutations[keyType][keyId] = null;
|
|
52
|
+
} else {
|
|
53
|
+
this.logger.warn(
|
|
54
|
+
`Skipping deletion of non-existent ${keyType} in transaction: ${keyId}`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
const existingKeys = await this.store.get(keyType, ids);
|
|
60
|
+
for (const keyId of ids) {
|
|
61
|
+
if (existingKeys[keyId]) {
|
|
62
|
+
transactionCache[keyType][keyId] = null;
|
|
63
|
+
mutations[keyType][keyId] = null;
|
|
64
|
+
} else {
|
|
65
|
+
this.logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async validateDeletions(data, keyType) {
|
|
71
|
+
const keyData = data[keyType];
|
|
72
|
+
if (!keyData) return;
|
|
73
|
+
return this.getQueue(keyType).add(async () => {
|
|
74
|
+
const deletionIds = Object.keys(keyData).filter((id) => keyData[id] === null);
|
|
75
|
+
if (deletionIds.length === 0) return;
|
|
76
|
+
const existingKeys = await this.store.get(keyType, deletionIds);
|
|
77
|
+
for (const keyId of deletionIds) {
|
|
78
|
+
if (!existingKeys[keyId]) {
|
|
79
|
+
this.logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
|
|
80
|
+
delete data[keyType][keyId];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
module.exports = { PreKeyManager: PreKeyManager };
|