angularsockets 1.0.1 → 1.0.2
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/README.md +1880 -36
- package/WAProto/index.d.ts +50383 -0
- package/WAProto/index.js +37203 -11791
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -6
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +79 -101
- package/lib/Signal/libsignal.js +29 -51
- package/lib/Socket/Client/web-socket-client.js +0 -2
- package/lib/Socket/business.d.ts +42 -43
- package/lib/Socket/chats.d.ts +9 -8
- package/lib/Socket/chats.js +107 -21
- package/lib/Socket/groups.d.ts +7 -7
- package/lib/Socket/groups.js +24 -25
- package/lib/Socket/index.d.ts +51 -52
- package/lib/Socket/messages-recv.d.ts +34 -37
- package/lib/Socket/messages-recv.js +37 -175
- package/lib/Socket/messages-send.d.ts +16 -10
- package/lib/Socket/messages-send.js +540 -346
- package/lib/Socket/newsletter.d.ts +26 -28
- package/lib/Socket/newsletter.js +4 -4
- package/lib/Socket/registration.d.ts +49 -52
- package/lib/Socket/registration.js +7 -7
- package/lib/Socket/socket.d.ts +1 -0
- package/lib/Socket/socket.js +36 -23
- package/lib/Socket/usync.d.ts +11 -10
- package/lib/Store/make-cache-manager-store.d.ts +2 -1
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Store/make-in-memory-store.js +5 -1
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +0 -1
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +12 -7
- package/lib/Types/Events.d.ts +17 -2
- package/lib/Types/GroupMetadata.d.ts +3 -2
- package/lib/Types/Label.d.ts +11 -0
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +170 -10
- package/lib/Types/Newsletter.js +3 -3
- package/lib/Types/Socket.d.ts +7 -2
- package/lib/Types/index.d.ts +9 -0
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +35 -14
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +11 -12
- package/lib/Utils/chat-utils.js +52 -36
- package/lib/Utils/crypto.d.ts +15 -16
- package/lib/Utils/crypto.js +74 -26
- package/lib/Utils/decode-wa-message.d.ts +17 -0
- package/lib/Utils/decode-wa-message.js +53 -17
- package/lib/Utils/event-buffer.js +10 -7
- package/lib/Utils/generics.d.ts +13 -17
- package/lib/Utils/generics.js +26 -15
- package/lib/Utils/history.d.ts +6 -2
- package/lib/Utils/history.js +4 -6
- package/lib/Utils/logger.d.ts +1 -3
- package/lib/Utils/lt-hash.js +12 -12
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +25 -28
- package/lib/Utils/messages-media.js +47 -57
- package/lib/Utils/messages.js +461 -44
- package/lib/Utils/noise-handler.d.ts +4 -5
- package/lib/Utils/noise-handler.js +19 -14
- package/lib/Utils/process-message.d.ts +5 -5
- package/lib/Utils/process-message.js +75 -23
- package/lib/Utils/signal.d.ts +2 -1
- package/lib/Utils/signal.js +43 -35
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -1
- package/lib/Utils/use-multi-file-auth-state.js +251 -36
- package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-single-file-auth-state.js +75 -0
- package/lib/Utils/validate-connection.d.ts +1 -1
- package/lib/Utils/validate-connection.js +1 -1
- package/lib/WABinary/decode.d.ts +1 -2
- package/lib/WABinary/decode.js +23 -11
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +46 -22
- package/lib/WABinary/generic-utils.d.ts +2 -4
- package/lib/WABinary/generic-utils.js +2 -10
- package/lib/WABinary/jid-utils.d.ts +1 -1
- package/lib/WAM/BinaryInfo.d.ts +2 -11
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/USyncUser.d.ts +0 -2
- package/lib/index.js +0 -6
- package/package.json +96 -104
- package/engine-requirements.js +0 -10
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/ciphertext-message.js +0 -15
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group-session-builder.js +0 -64
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.js +0 -96
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/index.js +0 -57
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/keyhelper.js +0 -55
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-chain-key.js +0 -34
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-message.js +0 -69
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-name.js +0 -51
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-record.js +0 -53
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-key-state.js +0 -99
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Socket/dugong.d.ts +0 -175
- package/lib/Socket/dugong.js +0 -342
- package/lib/index.d.ts +0 -12
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.initAuthCreds = exports.addTransactionCapability =
|
|
6
|
+
exports.initAuthCreds = exports.addTransactionCapability = void 0;
|
|
7
|
+
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
7
8
|
const crypto_1 = require("crypto");
|
|
8
9
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
9
10
|
const uuid_1 = require("uuid");
|
|
@@ -18,9 +19,30 @@ const generics_1 = require("./generics");
|
|
|
18
19
|
*/
|
|
19
20
|
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
20
21
|
const cache = _cache || new node_cache_1.default({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
23
|
+
useClones: false,
|
|
24
|
+
deleteOnExpire: true,
|
|
25
|
+
checkperiod: 120
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
cache.on('expired', async (key) => {
|
|
29
|
+
const [type, id] = key.split('.');
|
|
30
|
+
const item = cache.get(key, { noUpdate: true });
|
|
31
|
+
if (item) {
|
|
32
|
+
try {
|
|
33
|
+
await store.set({
|
|
34
|
+
[type]: {
|
|
35
|
+
[id]: item
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
cache.del(key);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
logger?.error({
|
|
41
|
+
key
|
|
42
|
+
}, 'Failed to persist expired cache item');
|
|
43
|
+
cache.ttl(key, 60);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
24
46
|
});
|
|
25
47
|
function getUniqueId(type, id) {
|
|
26
48
|
return `${type}.${id}`;
|
|
@@ -30,7 +52,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
30
52
|
const data = {};
|
|
31
53
|
const idsToFetch = [];
|
|
32
54
|
for (const id of ids) {
|
|
33
|
-
const item = cache.get(getUniqueId(type, id));
|
|
55
|
+
const item = cache.get(getUniqueId(type, id), { noUpdate: true });
|
|
34
56
|
if (typeof item !== 'undefined') {
|
|
35
57
|
data[id] = item;
|
|
36
58
|
}
|
|
@@ -39,7 +61,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
39
61
|
}
|
|
40
62
|
}
|
|
41
63
|
if (idsToFetch.length) {
|
|
42
|
-
logger
|
|
64
|
+
logger?.trace({ items: idsToFetch.length }, 'loading from store');
|
|
43
65
|
const fetched = await store.get(type, idsToFetch);
|
|
44
66
|
for (const id of idsToFetch) {
|
|
45
67
|
const item = fetched[id];
|
|
@@ -59,7 +81,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
59
81
|
keys += 1;
|
|
60
82
|
}
|
|
61
83
|
}
|
|
62
|
-
logger
|
|
84
|
+
logger?.trace({ keys }, 'updated cache');
|
|
63
85
|
await store.set(data);
|
|
64
86
|
},
|
|
65
87
|
async clear() {
|
|
@@ -69,7 +91,6 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
69
91
|
}
|
|
70
92
|
};
|
|
71
93
|
}
|
|
72
|
-
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
73
94
|
/**
|
|
74
95
|
* Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
|
|
75
96
|
* this allows batch read & write operations & improves the performance of the lib
|
|
@@ -113,7 +134,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
113
134
|
},
|
|
114
135
|
set: data => {
|
|
115
136
|
if (isInTransaction()) {
|
|
116
|
-
logger
|
|
137
|
+
logger?.trace({ types: Object.keys(data) }, 'caching in transaction');
|
|
117
138
|
for (const key in data) {
|
|
118
139
|
transactionCache[key] = transactionCache[key] || {};
|
|
119
140
|
Object.assign(transactionCache[key], data[key]);
|
|
@@ -130,14 +151,14 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
130
151
|
let result;
|
|
131
152
|
transactionsInProgress += 1;
|
|
132
153
|
if (transactionsInProgress === 1) {
|
|
133
|
-
logger
|
|
154
|
+
logger?.trace('entering transaction');
|
|
134
155
|
}
|
|
135
156
|
try {
|
|
136
157
|
result = await work();
|
|
137
158
|
// commit if this is the outermost transaction
|
|
138
159
|
if (transactionsInProgress === 1) {
|
|
139
160
|
if (Object.keys(mutations).length) {
|
|
140
|
-
logger
|
|
161
|
+
logger?.trace('committing transaction');
|
|
141
162
|
// retry mechanism to ensure we've some recovery
|
|
142
163
|
// in case a transaction fails in the first attempt
|
|
143
164
|
let tries = maxCommitRetries;
|
|
@@ -145,17 +166,17 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
145
166
|
tries -= 1;
|
|
146
167
|
try {
|
|
147
168
|
await state.set(mutations);
|
|
148
|
-
logger
|
|
169
|
+
logger?.trace({ dbQueriesInTransaction }, 'committed transaction');
|
|
149
170
|
break;
|
|
150
171
|
}
|
|
151
172
|
catch (error) {
|
|
152
|
-
logger
|
|
173
|
+
logger?.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
|
|
153
174
|
await (0, generics_1.delay)(delayBetweenTriesMs);
|
|
154
175
|
}
|
|
155
176
|
}
|
|
156
177
|
}
|
|
157
178
|
else {
|
|
158
|
-
logger
|
|
179
|
+
logger?.trace('no mutations in transaction');
|
|
159
180
|
}
|
|
160
181
|
}
|
|
161
182
|
}
|
package/lib/Utils/business.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { CatalogCollection, OrderDetails, Product, ProductCreate, ProductUpdate,
|
|
|
2
2
|
import { BinaryNode } from '../WABinary';
|
|
3
3
|
export declare const parseCatalogNode: (node: BinaryNode) => {
|
|
4
4
|
products: Product[];
|
|
5
|
-
nextPageCursor:
|
|
5
|
+
nextPageCursor: any;
|
|
6
6
|
};
|
|
7
7
|
export declare const parseCollectionsNode: (node: BinaryNode) => {
|
|
8
8
|
collections: CatalogCollection[];
|
package/lib/Utils/business.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uploadingNecessaryImages = exports.
|
|
3
|
+
exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
|
|
4
|
+
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
|
4
5
|
const boom_1 = require("@hapi/boom");
|
|
5
6
|
const crypto_1 = require("crypto");
|
|
6
7
|
const WABinary_1 = require("../WABinary");
|
|
@@ -188,7 +189,6 @@ async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, time
|
|
|
188
189
|
};
|
|
189
190
|
return product;
|
|
190
191
|
}
|
|
191
|
-
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
|
192
192
|
/**
|
|
193
193
|
* Uploads images not already uploaded to WA's servers
|
|
194
194
|
*/
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { AxiosRequestConfig } from 'axios';
|
|
3
2
|
import type { Logger } from 'pino';
|
|
4
3
|
import { proto } from '../../WAProto';
|
|
@@ -14,7 +13,7 @@ export declare const encodeSyncdPatch: ({ type, index, syncAction, apiVersion, o
|
|
|
14
13
|
state: LTHashState;
|
|
15
14
|
}>;
|
|
16
15
|
export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation | proto.ISyncdRecord)[], initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
|
|
17
|
-
hash:
|
|
16
|
+
hash: any;
|
|
18
17
|
indexValueMap: {
|
|
19
18
|
[indexMacBase64: string]: {
|
|
20
19
|
valueMac: Uint8Array | Buffer;
|
|
@@ -22,47 +21,47 @@ export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation
|
|
|
22
21
|
};
|
|
23
22
|
}>;
|
|
24
23
|
export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchName, initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
|
|
25
|
-
hash:
|
|
24
|
+
hash: any;
|
|
26
25
|
indexValueMap: {
|
|
27
26
|
[indexMacBase64: string]: {
|
|
28
27
|
valueMac: Uint8Array | Buffer;
|
|
29
28
|
};
|
|
30
29
|
};
|
|
31
30
|
}>;
|
|
32
|
-
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<
|
|
31
|
+
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<{}>) => Promise<{
|
|
33
32
|
critical_block: {
|
|
34
33
|
patches: proto.ISyncdPatch[];
|
|
35
34
|
hasMorePatches: boolean;
|
|
36
|
-
snapshot?: proto.ISyncdSnapshot
|
|
35
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
37
36
|
};
|
|
38
37
|
critical_unblock_low: {
|
|
39
38
|
patches: proto.ISyncdPatch[];
|
|
40
39
|
hasMorePatches: boolean;
|
|
41
|
-
snapshot?: proto.ISyncdSnapshot
|
|
40
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
42
41
|
};
|
|
43
42
|
regular_high: {
|
|
44
43
|
patches: proto.ISyncdPatch[];
|
|
45
44
|
hasMorePatches: boolean;
|
|
46
|
-
snapshot?: proto.ISyncdSnapshot
|
|
45
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
47
46
|
};
|
|
48
47
|
regular_low: {
|
|
49
48
|
patches: proto.ISyncdPatch[];
|
|
50
49
|
hasMorePatches: boolean;
|
|
51
|
-
snapshot?: proto.ISyncdSnapshot
|
|
50
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
52
51
|
};
|
|
53
52
|
regular: {
|
|
54
53
|
patches: proto.ISyncdPatch[];
|
|
55
54
|
hasMorePatches: boolean;
|
|
56
|
-
snapshot?: proto.ISyncdSnapshot
|
|
55
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
57
56
|
};
|
|
58
57
|
}>;
|
|
59
|
-
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<
|
|
60
|
-
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<
|
|
58
|
+
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<any>;
|
|
59
|
+
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<proto.SyncdMutations>;
|
|
61
60
|
export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
|
|
62
61
|
state: LTHashState;
|
|
63
62
|
mutationMap: ChatMutationMap;
|
|
64
63
|
}>;
|
|
65
|
-
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<
|
|
64
|
+
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<{}>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
|
|
66
65
|
state: LTHashState;
|
|
67
66
|
mutationMap: ChatMutationMap;
|
|
68
67
|
}>;
|
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -9,8 +9,8 @@ const crypto_1 = require("./crypto");
|
|
|
9
9
|
const generics_1 = require("./generics");
|
|
10
10
|
const lt_hash_1 = require("./lt-hash");
|
|
11
11
|
const messages_media_1 = require("./messages-media");
|
|
12
|
-
const mutationKeys = (keydata) => {
|
|
13
|
-
const expanded = (0, crypto_1.hkdf)(keydata, 160, { info: 'WhatsApp Mutation Keys' });
|
|
12
|
+
const mutationKeys = async (keydata) => {
|
|
13
|
+
const expanded = await (0, crypto_1.hkdf)(keydata, 160, { info: 'WhatsApp Mutation Keys' });
|
|
14
14
|
return {
|
|
15
15
|
indexKey: expanded.slice(0, 32),
|
|
16
16
|
valueEncryptionKey: expanded.slice(32, 64),
|
|
@@ -69,9 +69,9 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
|
|
|
69
69
|
subBuffs.push(new Uint8Array(prevOp.valueMac).buffer);
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
|
-
finish: () => {
|
|
72
|
+
finish: async () => {
|
|
73
73
|
const hashArrayBuffer = new Uint8Array(hash).buffer;
|
|
74
|
-
const result = lt_hash_1.LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
|
|
74
|
+
const result = await lt_hash_1.LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
|
|
75
75
|
const buffer = Buffer.from(result);
|
|
76
76
|
return {
|
|
77
77
|
hash: buffer,
|
|
@@ -114,14 +114,14 @@ const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation
|
|
|
114
114
|
version: apiVersion
|
|
115
115
|
});
|
|
116
116
|
const encoded = WAProto_1.proto.SyncActionData.encode(dataProto).finish();
|
|
117
|
-
const keyValue = mutationKeys(key.keyData);
|
|
117
|
+
const keyValue = await mutationKeys(key.keyData);
|
|
118
118
|
const encValue = (0, crypto_1.aesEncrypt)(encoded, keyValue.valueEncryptionKey);
|
|
119
119
|
const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey);
|
|
120
120
|
const indexMac = (0, crypto_1.hmacSign)(indexBuffer, keyValue.indexKey);
|
|
121
121
|
// update LT hash
|
|
122
122
|
const generator = makeLtHashGenerator(state);
|
|
123
123
|
generator.mix({ indexMac, valueMac, operation });
|
|
124
|
-
Object.assign(state, generator.finish());
|
|
124
|
+
Object.assign(state, await generator.finish());
|
|
125
125
|
state.version += 1;
|
|
126
126
|
const snapshotMac = generateSnapshotMac(state.hash, state.version, type, keyValue.snapshotMacKey);
|
|
127
127
|
const patch = {
|
|
@@ -184,7 +184,7 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
|
|
|
184
184
|
operation: operation
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
|
-
return ltGenerator.finish();
|
|
187
|
+
return await ltGenerator.finish();
|
|
188
188
|
async function getKey(keyId) {
|
|
189
189
|
const base64Key = Buffer.from(keyId).toString('base64');
|
|
190
190
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
@@ -202,7 +202,7 @@ const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onM
|
|
|
202
202
|
if (!mainKeyObj) {
|
|
203
203
|
throw new boom_1.Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } });
|
|
204
204
|
}
|
|
205
|
-
const mainKey = mutationKeys(mainKeyObj.keyData);
|
|
205
|
+
const mainKey = await mutationKeys(mainKeyObj.keyData);
|
|
206
206
|
const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32));
|
|
207
207
|
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, (0, generics_1.toNumber)(msg.version.version), name, mainKey.patchMacKey);
|
|
208
208
|
if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
|
|
@@ -286,7 +286,7 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
|
|
|
286
286
|
if (!keyEnc) {
|
|
287
287
|
throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
288
288
|
}
|
|
289
|
-
const result = mutationKeys(keyEnc.keyData);
|
|
289
|
+
const result = await mutationKeys(keyEnc.keyData);
|
|
290
290
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
291
291
|
if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
|
|
292
292
|
throw new boom_1.Boom(`failed to verify LTHash at ${newState.version} of ${name} from snapshot`);
|
|
@@ -305,8 +305,7 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
305
305
|
indexValueMap: { ...initial.indexValueMap }
|
|
306
306
|
};
|
|
307
307
|
const mutationMap = {};
|
|
308
|
-
for (
|
|
309
|
-
const syncd = syncds[i];
|
|
308
|
+
for (const syncd of syncds) {
|
|
310
309
|
const { version, keyId, snapshotMac } = syncd;
|
|
311
310
|
if (syncd.externalMutations) {
|
|
312
311
|
logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
|
|
@@ -332,7 +331,7 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
332
331
|
if (!keyEnc) {
|
|
333
332
|
throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
334
333
|
}
|
|
335
|
-
const result = mutationKeys(keyEnc.keyData);
|
|
334
|
+
const result = await mutationKeys(keyEnc.keyData);
|
|
336
335
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
337
336
|
if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
|
|
338
337
|
throw new boom_1.Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
|
|
@@ -418,25 +417,31 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
418
417
|
operation: OP.SET
|
|
419
418
|
};
|
|
420
419
|
}
|
|
420
|
+
else if ('deleteForMe' in mod) {
|
|
421
|
+
const { timestamp, key, deleteMedia } = mod.deleteForMe;
|
|
422
|
+
patch = {
|
|
423
|
+
syncAction: {
|
|
424
|
+
deleteMessageForMeAction: {
|
|
425
|
+
deleteMedia,
|
|
426
|
+
messageTimestamp: timestamp
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
|
|
430
|
+
type: 'regular_high',
|
|
431
|
+
apiVersion: 3,
|
|
432
|
+
operation: OP.SET
|
|
433
|
+
};
|
|
434
|
+
}
|
|
421
435
|
else if ('clear' in mod) {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
messageTimestamp: key.timestamp
|
|
432
|
-
}
|
|
433
|
-
},
|
|
434
|
-
index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
|
|
435
|
-
type: 'regular_high',
|
|
436
|
-
apiVersion: 3,
|
|
437
|
-
operation: OP.SET
|
|
438
|
-
};
|
|
439
|
-
}
|
|
436
|
+
patch = {
|
|
437
|
+
syncAction: {
|
|
438
|
+
clearChatAction: {} // add message range later
|
|
439
|
+
},
|
|
440
|
+
index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
|
|
441
|
+
type: 'regular_high',
|
|
442
|
+
apiVersion: 6,
|
|
443
|
+
operation: OP.SET
|
|
444
|
+
};
|
|
440
445
|
}
|
|
441
446
|
else if ('pin' in mod) {
|
|
442
447
|
patch = {
|
|
@@ -491,6 +496,22 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
491
496
|
operation: OP.SET,
|
|
492
497
|
};
|
|
493
498
|
}
|
|
499
|
+
else if ('addLabel' in mod) {
|
|
500
|
+
patch = {
|
|
501
|
+
syncAction: {
|
|
502
|
+
labelEditAction: {
|
|
503
|
+
name: mod.addLabel.name,
|
|
504
|
+
color: mod.addLabel.color,
|
|
505
|
+
predefinedId: mod.addLabel.predefinedId,
|
|
506
|
+
deleted: mod.addLabel.deleted
|
|
507
|
+
}
|
|
508
|
+
},
|
|
509
|
+
index: ['label_edit', mod.addLabel.id],
|
|
510
|
+
type: 'regular',
|
|
511
|
+
apiVersion: 3,
|
|
512
|
+
operation: OP.SET,
|
|
513
|
+
};
|
|
514
|
+
}
|
|
494
515
|
else if ('addChatLabel' in mod) {
|
|
495
516
|
patch = {
|
|
496
517
|
syncAction: {
|
|
@@ -633,12 +654,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
633
654
|
});
|
|
634
655
|
}
|
|
635
656
|
else if (action === null || action === void 0 ? void 0 : action.contactAction) {
|
|
636
|
-
ev.emit('contacts.upsert', [{
|
|
637
|
-
id: id,
|
|
638
|
-
name: action.contactAction.fullName,
|
|
639
|
-
lid: action.contactAction.lidJid || undefined,
|
|
640
|
-
jid: (0, WABinary_1.isJidUser)(id) ? id : undefined
|
|
641
|
-
}]);
|
|
657
|
+
ev.emit('contacts.upsert', [{ id, name: action.contactAction.fullName }]);
|
|
642
658
|
}
|
|
643
659
|
else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
|
|
644
660
|
const name = (_b = action === null || action === void 0 ? void 0 : action.pushNameSetting) === null || _b === void 0 ? void 0 : _b.name;
|
package/lib/Utils/crypto.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { KeyPair } from '../Types';
|
|
3
2
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
4
|
-
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) =>
|
|
3
|
+
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => any;
|
|
5
4
|
export declare const Curve: {
|
|
6
5
|
generateKeyPair: () => KeyPair;
|
|
7
|
-
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) =>
|
|
6
|
+
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => any;
|
|
8
7
|
sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
|
|
9
8
|
verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
|
|
10
9
|
};
|
|
@@ -17,25 +16,25 @@ export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) =>
|
|
|
17
16
|
* encrypt AES 256 GCM;
|
|
18
17
|
* where the tag tag is suffixed to the ciphertext
|
|
19
18
|
* */
|
|
20
|
-
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array):
|
|
19
|
+
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): any;
|
|
21
20
|
/**
|
|
22
21
|
* decrypt AES 256 GCM;
|
|
23
22
|
* where the auth tag is suffixed to the ciphertext
|
|
24
23
|
* */
|
|
25
|
-
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array):
|
|
26
|
-
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array):
|
|
27
|
-
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array):
|
|
24
|
+
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): any;
|
|
25
|
+
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): any;
|
|
26
|
+
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): any;
|
|
28
27
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
29
|
-
export declare function aesDecrypt(buffer: Buffer, key: Buffer):
|
|
28
|
+
export declare function aesDecrypt(buffer: Buffer, key: Buffer): any;
|
|
30
29
|
/** decrypt AES 256 CBC */
|
|
31
|
-
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer):
|
|
32
|
-
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer):
|
|
33
|
-
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer):
|
|
34
|
-
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'):
|
|
35
|
-
export declare function sha256(buffer: Buffer):
|
|
36
|
-
export declare function md5(buffer: Buffer):
|
|
30
|
+
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): any;
|
|
31
|
+
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): any;
|
|
32
|
+
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): any;
|
|
33
|
+
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): any;
|
|
34
|
+
export declare function sha256(buffer: Buffer): any;
|
|
35
|
+
export declare function md5(buffer: Buffer): any;
|
|
37
36
|
export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
|
|
38
37
|
salt?: Buffer;
|
|
39
38
|
info?: string;
|
|
40
|
-
}):
|
|
41
|
-
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer):
|
|
39
|
+
}): any;
|
|
40
|
+
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<any>;
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -15,22 +15,48 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
39
|
+
exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
|
40
|
+
exports.aesEncryptGCM = aesEncryptGCM;
|
|
41
|
+
exports.aesDecryptGCM = aesDecryptGCM;
|
|
42
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
|
43
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
|
44
|
+
exports.aesDecrypt = aesDecrypt;
|
|
45
|
+
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
46
|
+
exports.aesEncrypt = aesEncrypt;
|
|
47
|
+
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
48
|
+
exports.hmacSign = hmacSign;
|
|
49
|
+
exports.sha256 = sha256;
|
|
50
|
+
exports.md5 = md5;
|
|
51
|
+
exports.hkdf = hkdf;
|
|
52
|
+
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
30
53
|
const crypto_1 = require("crypto");
|
|
31
|
-
const
|
|
54
|
+
const crypto_2 = globalThis.crypto ?? crypto_1.webcrypto ?? crypto_1;
|
|
55
|
+
//const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
|
32
56
|
const libsignal = __importStar(require("libsignal"));
|
|
57
|
+
const util_1 = require("util");
|
|
33
58
|
const Defaults_1 = require("../Defaults");
|
|
59
|
+
//const pbkdf2Promise = (0, util_1.promisify)(crypto_1.pbkdf2);
|
|
34
60
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
35
61
|
const generateSignalPubKey = (pubKey) => (pubKey.length === 33
|
|
36
62
|
? pubKey
|
|
@@ -77,7 +103,6 @@ function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
|
77
103
|
cipher.setAAD(additionalData);
|
|
78
104
|
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
79
105
|
}
|
|
80
|
-
exports.aesEncryptGCM = aesEncryptGCM;
|
|
81
106
|
/**
|
|
82
107
|
* decrypt AES 256 GCM;
|
|
83
108
|
* where the auth tag is suffixed to the ciphertext
|
|
@@ -92,60 +117,83 @@ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
|
92
117
|
decipher.setAuthTag(tag);
|
|
93
118
|
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
94
119
|
}
|
|
95
|
-
exports.aesDecryptGCM = aesDecryptGCM;
|
|
96
120
|
function aesEncryptCTR(plaintext, key, iv) {
|
|
97
121
|
const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
|
98
122
|
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
99
123
|
}
|
|
100
|
-
exports.aesEncryptCTR = aesEncryptCTR;
|
|
101
124
|
function aesDecryptCTR(ciphertext, key, iv) {
|
|
102
125
|
const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
|
103
126
|
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
104
127
|
}
|
|
105
|
-
exports.aesDecryptCTR = aesDecryptCTR;
|
|
106
128
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
107
129
|
function aesDecrypt(buffer, key) {
|
|
108
130
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
|
109
131
|
}
|
|
110
|
-
exports.aesDecrypt = aesDecrypt;
|
|
111
132
|
/** decrypt AES 256 CBC */
|
|
112
133
|
function aesDecryptWithIV(buffer, key, IV) {
|
|
113
134
|
const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
|
|
114
135
|
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
115
136
|
}
|
|
116
|
-
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
117
137
|
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
118
138
|
function aesEncrypt(buffer, key) {
|
|
119
139
|
const IV = (0, crypto_1.randomBytes)(16);
|
|
120
140
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
121
141
|
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
122
142
|
}
|
|
123
|
-
exports.aesEncrypt = aesEncrypt;
|
|
124
143
|
// encrypt AES 256 CBC with a given IV
|
|
125
144
|
function aesEncrypWithIV(buffer, key, IV) {
|
|
126
145
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
127
146
|
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
128
147
|
}
|
|
129
|
-
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
130
148
|
// sign HMAC using SHA 256
|
|
131
149
|
function hmacSign(buffer, key, variant = 'sha256') {
|
|
132
150
|
return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
|
|
133
151
|
}
|
|
134
|
-
exports.hmacSign = hmacSign;
|
|
135
152
|
function sha256(buffer) {
|
|
136
153
|
return (0, crypto_1.createHash)('sha256').update(buffer).digest();
|
|
137
154
|
}
|
|
138
|
-
exports.sha256 = sha256;
|
|
139
155
|
function md5(buffer) {
|
|
140
156
|
return (0, crypto_1.createHash)('md5').update(buffer).digest();
|
|
141
157
|
}
|
|
142
|
-
exports.md5 = md5;
|
|
143
158
|
// HKDF key expansion
|
|
144
|
-
function hkdf(buffer, expandedLength, info) {
|
|
145
|
-
|
|
159
|
+
async function hkdf(buffer, expandedLength, info) {
|
|
160
|
+
// Ensure we have a Uint8Array for the key material
|
|
161
|
+
const inputKeyMaterial = buffer instanceof Uint8Array
|
|
162
|
+
? buffer
|
|
163
|
+
: new Uint8Array(buffer);
|
|
164
|
+
// Set default values if not provided
|
|
165
|
+
const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
|
|
166
|
+
const infoBytes = info.info
|
|
167
|
+
? new TextEncoder().encode(info.info)
|
|
168
|
+
: new Uint8Array(0);
|
|
169
|
+
// Import the input key material
|
|
170
|
+
const importedKey = await crypto_2.subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits']);
|
|
171
|
+
// Derive bits using HKDF
|
|
172
|
+
const derivedBits = await crypto_2.subtle.deriveBits({
|
|
173
|
+
name: 'HKDF',
|
|
174
|
+
hash: 'SHA-256',
|
|
175
|
+
salt: salt,
|
|
176
|
+
info: infoBytes
|
|
177
|
+
}, importedKey, expandedLength * 8 // Convert bytes to bits
|
|
178
|
+
);
|
|
179
|
+
return Buffer.from(derivedBits);
|
|
146
180
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
181
|
+
async function derivePairingCodeKey(pairingCode, salt) {
|
|
182
|
+
// Convert inputs to formats Web Crypto API can work with
|
|
183
|
+
const encoder = new TextEncoder();
|
|
184
|
+
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
185
|
+
const saltBuffer = salt instanceof Uint8Array ? salt : new Uint8Array(salt);
|
|
186
|
+
// Import the pairing code as key material
|
|
187
|
+
const keyMaterial = await crypto_2.subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, ['deriveBits']);
|
|
188
|
+
// Derive bits using PBKDF2 with the same parameters
|
|
189
|
+
// 2 << 16 = 131,072 iterations
|
|
190
|
+
const derivedBits = await crypto_2.subtle.deriveBits({
|
|
191
|
+
name: 'PBKDF2',
|
|
192
|
+
salt: saltBuffer,
|
|
193
|
+
iterations: 2 << 16,
|
|
194
|
+
hash: 'SHA-256'
|
|
195
|
+
}, keyMaterial, 32 * 8 // 32 bytes * 8 = 256 bits
|
|
196
|
+
);
|
|
197
|
+
return Buffer.from(derivedBits);
|
|
150
198
|
}
|
|
151
|
-
|
|
199
|
+
|
|
@@ -2,6 +2,23 @@ import { Logger } from 'pino';
|
|
|
2
2
|
import { proto } from '../../WAProto';
|
|
3
3
|
import { SignalRepository } from '../Types';
|
|
4
4
|
import { BinaryNode } from '../WABinary';
|
|
5
|
+
export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
|
|
6
|
+
export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
|
|
7
|
+
export declare const NACK_REASONS: {
|
|
8
|
+
ParsingError: number;
|
|
9
|
+
UnrecognizedStanza: number;
|
|
10
|
+
UnrecognizedStanzaClass: number;
|
|
11
|
+
UnrecognizedStanzaType: number;
|
|
12
|
+
InvalidProtobuf: number;
|
|
13
|
+
InvalidHostedCompanionStanza: number;
|
|
14
|
+
MissingMessageSecret: number;
|
|
15
|
+
SignalErrorOldCounter: number;
|
|
16
|
+
MessageDeletedOnPeer: number;
|
|
17
|
+
UnhandledError: number;
|
|
18
|
+
UnsupportedAdminRevoke: number;
|
|
19
|
+
UnsupportedLIDGroup: number;
|
|
20
|
+
DBOperationFailed: number;
|
|
21
|
+
};
|
|
5
22
|
/**
|
|
6
23
|
* Decode the received node as a message.
|
|
7
24
|
* @note this will only parse the message, not decrypt it
|