@heavstaltech/baileys 2.3.4 → 3.2.4
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 +226 -53
- package/WAProto/index.js +14270 -302
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +118 -79
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
- package/lib/Signal/libsignal.js +51 -29
- package/lib/Socket/business.d.ts +43 -42
- package/lib/Socket/chats.d.ts +222 -36
- package/lib/Socket/chats.js +186 -153
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +7 -7
- package/lib/Socket/groups.js +37 -35
- package/lib/Socket/index.d.ts +52 -51
- package/lib/Socket/index.js +1 -0
- package/lib/Socket/messages-recv.d.ts +37 -34
- package/lib/Socket/messages-recv.js +175 -37
- package/lib/Socket/messages-send.d.ts +12 -18
- package/lib/Socket/messages-send.js +396 -574
- package/lib/Socket/newsletter.d.ts +28 -26
- package/lib/Socket/newsletter.js +140 -25
- package/lib/Socket/registration.d.ts +52 -49
- package/lib/Socket/registration.js +7 -7
- package/lib/Socket/socket.d.ts +0 -1
- package/lib/Socket/socket.js +47 -198
- package/lib/Socket/usync.d.ts +10 -11
- package/lib/Store/make-cache-manager-store.d.ts +1 -2
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Store/make-in-memory-store.js +1 -5
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -12
- package/lib/Types/Events.d.ts +2 -17
- package/lib/Types/GroupMetadata.d.ts +2 -3
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +10 -170
- package/lib/Types/Newsletter.d.ts +97 -86
- package/lib/Types/Newsletter.js +38 -32
- package/lib/Types/Socket.d.ts +2 -7
- package/lib/Types/index.d.ts +0 -9
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +14 -35
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +12 -11
- package/lib/Utils/chat-utils.js +36 -52
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +26 -74
- package/lib/Utils/decode-wa-message.d.ts +0 -17
- package/lib/Utils/decode-wa-message.js +17 -53
- package/lib/Utils/event-buffer.js +7 -10
- package/lib/Utils/generics.d.ts +17 -13
- package/lib/Utils/generics.js +79 -58
- package/lib/Utils/history.d.ts +2 -6
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/logger.d.ts +3 -1
- package/lib/Utils/lt-hash.js +12 -12
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +28 -25
- package/lib/Utils/messages-media.js +201 -103
- package/lib/Utils/messages.js +36 -473
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/noise-handler.js +14 -19
- package/lib/Utils/process-message.d.ts +5 -5
- package/lib/Utils/process-message.js +23 -75
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +26 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +66 -242
- package/lib/Utils/validate-connection.d.ts +1 -1
- package/lib/Utils/validate-connection.js +88 -64
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.js +11 -23
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +147 -134
- package/lib/WABinary/generic-utils.d.ts +5 -2
- package/lib/WABinary/generic-utils.js +125 -37
- package/lib/WABinary/jid-utils.d.ts +1 -1
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +12 -0
- package/package.json +102 -98
- package/WAProto/index.d.ts +0 -50383
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -12
- package/lib/Utils/use-single-file-auth-state.js +0 -75
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -3,8 +3,7 @@ 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 = void 0;
|
|
7
|
-
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
6
|
+
exports.initAuthCreds = exports.addTransactionCapability = exports.makeCacheableSignalKeyStore = void 0;
|
|
8
7
|
const crypto_1 = require("crypto");
|
|
9
8
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
10
9
|
const uuid_1 = require("uuid");
|
|
@@ -19,30 +18,9 @@ const generics_1 = require("./generics");
|
|
|
19
18
|
*/
|
|
20
19
|
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
21
20
|
const cache = _cache || new node_cache_1.default({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
}
|
|
21
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
22
|
+
useClones: false,
|
|
23
|
+
deleteOnExpire: true,
|
|
46
24
|
});
|
|
47
25
|
function getUniqueId(type, id) {
|
|
48
26
|
return `${type}.${id}`;
|
|
@@ -52,7 +30,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
52
30
|
const data = {};
|
|
53
31
|
const idsToFetch = [];
|
|
54
32
|
for (const id of ids) {
|
|
55
|
-
const item = cache.get(getUniqueId(type, id)
|
|
33
|
+
const item = cache.get(getUniqueId(type, id));
|
|
56
34
|
if (typeof item !== 'undefined') {
|
|
57
35
|
data[id] = item;
|
|
58
36
|
}
|
|
@@ -61,7 +39,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
61
39
|
}
|
|
62
40
|
}
|
|
63
41
|
if (idsToFetch.length) {
|
|
64
|
-
logger
|
|
42
|
+
logger.trace({ items: idsToFetch.length }, 'loading from store');
|
|
65
43
|
const fetched = await store.get(type, idsToFetch);
|
|
66
44
|
for (const id of idsToFetch) {
|
|
67
45
|
const item = fetched[id];
|
|
@@ -81,7 +59,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
81
59
|
keys += 1;
|
|
82
60
|
}
|
|
83
61
|
}
|
|
84
|
-
logger
|
|
62
|
+
logger.trace({ keys }, 'updated cache');
|
|
85
63
|
await store.set(data);
|
|
86
64
|
},
|
|
87
65
|
async clear() {
|
|
@@ -91,6 +69,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
91
69
|
}
|
|
92
70
|
};
|
|
93
71
|
}
|
|
72
|
+
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
94
73
|
/**
|
|
95
74
|
* Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
|
|
96
75
|
* this allows batch read & write operations & improves the performance of the lib
|
|
@@ -134,7 +113,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
134
113
|
},
|
|
135
114
|
set: data => {
|
|
136
115
|
if (isInTransaction()) {
|
|
137
|
-
logger
|
|
116
|
+
logger.trace({ types: Object.keys(data) }, 'caching in transaction');
|
|
138
117
|
for (const key in data) {
|
|
139
118
|
transactionCache[key] = transactionCache[key] || {};
|
|
140
119
|
Object.assign(transactionCache[key], data[key]);
|
|
@@ -151,14 +130,14 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
151
130
|
let result;
|
|
152
131
|
transactionsInProgress += 1;
|
|
153
132
|
if (transactionsInProgress === 1) {
|
|
154
|
-
logger
|
|
133
|
+
logger.trace('entering transaction');
|
|
155
134
|
}
|
|
156
135
|
try {
|
|
157
136
|
result = await work();
|
|
158
137
|
// commit if this is the outermost transaction
|
|
159
138
|
if (transactionsInProgress === 1) {
|
|
160
139
|
if (Object.keys(mutations).length) {
|
|
161
|
-
logger
|
|
140
|
+
logger.trace('committing transaction');
|
|
162
141
|
// retry mechanism to ensure we've some recovery
|
|
163
142
|
// in case a transaction fails in the first attempt
|
|
164
143
|
let tries = maxCommitRetries;
|
|
@@ -166,17 +145,17 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
166
145
|
tries -= 1;
|
|
167
146
|
try {
|
|
168
147
|
await state.set(mutations);
|
|
169
|
-
logger
|
|
148
|
+
logger.trace({ dbQueriesInTransaction }, 'committed transaction');
|
|
170
149
|
break;
|
|
171
150
|
}
|
|
172
151
|
catch (error) {
|
|
173
|
-
logger
|
|
152
|
+
logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
|
|
174
153
|
await (0, generics_1.delay)(delayBetweenTriesMs);
|
|
175
154
|
}
|
|
176
155
|
}
|
|
177
156
|
}
|
|
178
157
|
else {
|
|
179
|
-
logger
|
|
158
|
+
logger.trace('no mutations in transaction');
|
|
180
159
|
}
|
|
181
160
|
}
|
|
182
161
|
}
|
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: string | undefined;
|
|
6
6
|
};
|
|
7
7
|
export declare const parseCollectionsNode: (node: BinaryNode) => {
|
|
8
8
|
collections: CatalogCollection[];
|
package/lib/Utils/business.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
|
|
4
|
-
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
|
3
|
+
exports.uploadingNecessaryImages = exports.uploadingNecessaryImagesOfProduct = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
|
|
5
4
|
const boom_1 = require("@hapi/boom");
|
|
6
5
|
const crypto_1 = require("crypto");
|
|
7
6
|
const WABinary_1 = require("../WABinary");
|
|
@@ -189,6 +188,7 @@ async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, time
|
|
|
189
188
|
};
|
|
190
189
|
return product;
|
|
191
190
|
}
|
|
191
|
+
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
|
192
192
|
/**
|
|
193
193
|
* Uploads images not already uploaded to WA's servers
|
|
194
194
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { AxiosRequestConfig } from 'axios';
|
|
2
3
|
import type { Logger } from 'pino';
|
|
3
4
|
import { proto } from '../../WAProto';
|
|
@@ -13,7 +14,7 @@ export declare const encodeSyncdPatch: ({ type, index, syncAction, apiVersion, o
|
|
|
13
14
|
state: LTHashState;
|
|
14
15
|
}>;
|
|
15
16
|
export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation | proto.ISyncdRecord)[], initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
|
|
16
|
-
hash:
|
|
17
|
+
hash: Buffer;
|
|
17
18
|
indexValueMap: {
|
|
18
19
|
[indexMacBase64: string]: {
|
|
19
20
|
valueMac: Uint8Array | Buffer;
|
|
@@ -21,47 +22,47 @@ export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation
|
|
|
21
22
|
};
|
|
22
23
|
}>;
|
|
23
24
|
export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchName, initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
|
|
24
|
-
hash:
|
|
25
|
+
hash: Buffer;
|
|
25
26
|
indexValueMap: {
|
|
26
27
|
[indexMacBase64: string]: {
|
|
27
28
|
valueMac: Uint8Array | Buffer;
|
|
28
29
|
};
|
|
29
30
|
};
|
|
30
31
|
}>;
|
|
31
|
-
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<
|
|
32
|
+
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<any>) => Promise<{
|
|
32
33
|
critical_block: {
|
|
33
34
|
patches: proto.ISyncdPatch[];
|
|
34
35
|
hasMorePatches: boolean;
|
|
35
|
-
snapshot?: proto.ISyncdSnapshot;
|
|
36
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
|
36
37
|
};
|
|
37
38
|
critical_unblock_low: {
|
|
38
39
|
patches: proto.ISyncdPatch[];
|
|
39
40
|
hasMorePatches: boolean;
|
|
40
|
-
snapshot?: proto.ISyncdSnapshot;
|
|
41
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
|
41
42
|
};
|
|
42
43
|
regular_high: {
|
|
43
44
|
patches: proto.ISyncdPatch[];
|
|
44
45
|
hasMorePatches: boolean;
|
|
45
|
-
snapshot?: proto.ISyncdSnapshot;
|
|
46
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
|
46
47
|
};
|
|
47
48
|
regular_low: {
|
|
48
49
|
patches: proto.ISyncdPatch[];
|
|
49
50
|
hasMorePatches: boolean;
|
|
50
|
-
snapshot?: proto.ISyncdSnapshot;
|
|
51
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
|
51
52
|
};
|
|
52
53
|
regular: {
|
|
53
54
|
patches: proto.ISyncdPatch[];
|
|
54
55
|
hasMorePatches: boolean;
|
|
55
|
-
snapshot?: proto.ISyncdSnapshot;
|
|
56
|
+
snapshot?: proto.ISyncdSnapshot | undefined;
|
|
56
57
|
};
|
|
57
58
|
}>;
|
|
58
|
-
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<
|
|
59
|
-
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<
|
|
59
|
+
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<Buffer>;
|
|
60
|
+
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<proto.SyncdMutations>;
|
|
60
61
|
export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
|
|
61
62
|
state: LTHashState;
|
|
62
63
|
mutationMap: ChatMutationMap;
|
|
63
64
|
}>;
|
|
64
|
-
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<
|
|
65
|
+
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<any>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
|
|
65
66
|
state: LTHashState;
|
|
66
67
|
mutationMap: ChatMutationMap;
|
|
67
68
|
}>;
|
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 =
|
|
13
|
-
const expanded =
|
|
12
|
+
const mutationKeys = (keydata) => {
|
|
13
|
+
const expanded = (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: () => {
|
|
73
73
|
const hashArrayBuffer = new Uint8Array(hash).buffer;
|
|
74
|
-
const result =
|
|
74
|
+
const result = 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 =
|
|
117
|
+
const keyValue = 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,
|
|
124
|
+
Object.assign(state, 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
|
|
187
|
+
return 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 =
|
|
205
|
+
const mainKey = 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 =
|
|
289
|
+
const result = 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,7 +305,8 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
305
305
|
indexValueMap: { ...initial.indexValueMap }
|
|
306
306
|
};
|
|
307
307
|
const mutationMap = {};
|
|
308
|
-
for (
|
|
308
|
+
for (let i = 0; i < syncds.length; i++) {
|
|
309
|
+
const syncd = syncds[i];
|
|
309
310
|
const { version, keyId, snapshotMac } = syncd;
|
|
310
311
|
if (syncd.externalMutations) {
|
|
311
312
|
logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
|
|
@@ -331,7 +332,7 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
331
332
|
if (!keyEnc) {
|
|
332
333
|
throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
333
334
|
}
|
|
334
|
-
const result =
|
|
335
|
+
const result = mutationKeys(keyEnc.keyData);
|
|
335
336
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
336
337
|
if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
|
|
337
338
|
throw new boom_1.Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
|
|
@@ -417,31 +418,25 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
417
418
|
operation: OP.SET
|
|
418
419
|
};
|
|
419
420
|
}
|
|
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
|
-
}
|
|
435
421
|
else if ('clear' in mod) {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
422
|
+
if (mod.clear === 'all') {
|
|
423
|
+
throw new boom_1.Boom('not supported');
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
const key = mod.clear.messages[0];
|
|
427
|
+
patch = {
|
|
428
|
+
syncAction: {
|
|
429
|
+
deleteMessageForMeAction: {
|
|
430
|
+
deleteMedia: false,
|
|
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
|
+
}
|
|
445
440
|
}
|
|
446
441
|
else if ('pin' in mod) {
|
|
447
442
|
patch = {
|
|
@@ -496,22 +491,6 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
496
491
|
operation: OP.SET,
|
|
497
492
|
};
|
|
498
493
|
}
|
|
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
|
-
}
|
|
515
494
|
else if ('addChatLabel' in mod) {
|
|
516
495
|
patch = {
|
|
517
496
|
syncAction: {
|
|
@@ -654,7 +633,12 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
654
633
|
});
|
|
655
634
|
}
|
|
656
635
|
else if (action === null || action === void 0 ? void 0 : action.contactAction) {
|
|
657
|
-
ev.emit('contacts.upsert', [{
|
|
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
|
+
}]);
|
|
658
642
|
}
|
|
659
643
|
else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
|
|
660
644
|
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,9 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { KeyPair } from '../Types';
|
|
2
3
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
3
|
-
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) =>
|
|
4
|
+
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array | Buffer;
|
|
4
5
|
export declare const Curve: {
|
|
5
6
|
generateKeyPair: () => KeyPair;
|
|
6
|
-
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) =>
|
|
7
|
+
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer;
|
|
7
8
|
sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
|
|
8
9
|
verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
|
|
9
10
|
};
|
|
@@ -16,25 +17,25 @@ export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) =>
|
|
|
16
17
|
* encrypt AES 256 GCM;
|
|
17
18
|
* where the tag tag is suffixed to the ciphertext
|
|
18
19
|
* */
|
|
19
|
-
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array):
|
|
20
|
+
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
|
|
20
21
|
/**
|
|
21
22
|
* decrypt AES 256 GCM;
|
|
22
23
|
* where the auth tag is suffixed to the ciphertext
|
|
23
24
|
* */
|
|
24
|
-
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array):
|
|
25
|
-
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array):
|
|
26
|
-
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array):
|
|
25
|
+
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
|
|
26
|
+
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
|
|
27
|
+
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
|
|
27
28
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
28
|
-
export declare function aesDecrypt(buffer: Buffer, key: Buffer):
|
|
29
|
+
export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer;
|
|
29
30
|
/** decrypt AES 256 CBC */
|
|
30
|
-
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer):
|
|
31
|
-
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer):
|
|
32
|
-
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer):
|
|
33
|
-
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'):
|
|
34
|
-
export declare function sha256(buffer: Buffer):
|
|
35
|
-
export declare function md5(buffer: Buffer):
|
|
31
|
+
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
|
|
32
|
+
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer;
|
|
33
|
+
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
|
|
34
|
+
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer;
|
|
35
|
+
export declare function sha256(buffer: Buffer): Buffer;
|
|
36
|
+
export declare function md5(buffer: Buffer): Buffer;
|
|
36
37
|
export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
|
|
37
38
|
salt?: Buffer;
|
|
38
39
|
info?: string;
|
|
39
|
-
}):
|
|
40
|
-
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer):
|
|
40
|
+
}): Buffer;
|
|
41
|
+
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Buffer;
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -15,48 +15,22 @@ 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) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
})();
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
35
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
27
|
};
|
|
38
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
29
|
+
exports.derivePairingCodeKey = exports.hkdf = exports.md5 = exports.sha256 = exports.hmacSign = exports.aesEncrypWithIV = exports.aesEncrypt = exports.aesDecryptWithIV = exports.aesDecrypt = exports.aesDecryptCTR = exports.aesEncryptCTR = exports.aesDecryptGCM = exports.aesEncryptGCM = exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
|
53
30
|
const crypto_1 = require("crypto");
|
|
54
|
-
const
|
|
55
|
-
//const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
|
31
|
+
const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
|
56
32
|
const libsignal = __importStar(require("libsignal"));
|
|
57
|
-
const util_1 = require("util");
|
|
58
33
|
const Defaults_1 = require("../Defaults");
|
|
59
|
-
//const pbkdf2Promise = (0, util_1.promisify)(crypto_1.pbkdf2);
|
|
60
34
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
61
35
|
const generateSignalPubKey = (pubKey) => (pubKey.length === 33
|
|
62
36
|
? pubKey
|
|
@@ -103,6 +77,7 @@ function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
|
103
77
|
cipher.setAAD(additionalData);
|
|
104
78
|
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
105
79
|
}
|
|
80
|
+
exports.aesEncryptGCM = aesEncryptGCM;
|
|
106
81
|
/**
|
|
107
82
|
* decrypt AES 256 GCM;
|
|
108
83
|
* where the auth tag is suffixed to the ciphertext
|
|
@@ -117,83 +92,60 @@ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
|
117
92
|
decipher.setAuthTag(tag);
|
|
118
93
|
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
119
94
|
}
|
|
95
|
+
exports.aesDecryptGCM = aesDecryptGCM;
|
|
120
96
|
function aesEncryptCTR(plaintext, key, iv) {
|
|
121
97
|
const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
|
122
98
|
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
123
99
|
}
|
|
100
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
|
124
101
|
function aesDecryptCTR(ciphertext, key, iv) {
|
|
125
102
|
const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
|
126
103
|
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
127
104
|
}
|
|
105
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
|
128
106
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
129
107
|
function aesDecrypt(buffer, key) {
|
|
130
108
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
|
131
109
|
}
|
|
110
|
+
exports.aesDecrypt = aesDecrypt;
|
|
132
111
|
/** decrypt AES 256 CBC */
|
|
133
112
|
function aesDecryptWithIV(buffer, key, IV) {
|
|
134
113
|
const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
|
|
135
114
|
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
136
115
|
}
|
|
116
|
+
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
137
117
|
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
138
118
|
function aesEncrypt(buffer, key) {
|
|
139
119
|
const IV = (0, crypto_1.randomBytes)(16);
|
|
140
120
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
141
121
|
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
142
122
|
}
|
|
123
|
+
exports.aesEncrypt = aesEncrypt;
|
|
143
124
|
// encrypt AES 256 CBC with a given IV
|
|
144
125
|
function aesEncrypWithIV(buffer, key, IV) {
|
|
145
126
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
146
127
|
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
147
128
|
}
|
|
129
|
+
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
148
130
|
// sign HMAC using SHA 256
|
|
149
131
|
function hmacSign(buffer, key, variant = 'sha256') {
|
|
150
132
|
return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
|
|
151
133
|
}
|
|
134
|
+
exports.hmacSign = hmacSign;
|
|
152
135
|
function sha256(buffer) {
|
|
153
136
|
return (0, crypto_1.createHash)('sha256').update(buffer).digest();
|
|
154
137
|
}
|
|
138
|
+
exports.sha256 = sha256;
|
|
155
139
|
function md5(buffer) {
|
|
156
140
|
return (0, crypto_1.createHash)('md5').update(buffer).digest();
|
|
157
141
|
}
|
|
142
|
+
exports.md5 = md5;
|
|
158
143
|
// HKDF key expansion
|
|
159
|
-
|
|
160
|
-
|
|
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);
|
|
144
|
+
function hkdf(buffer, expandedLength, info) {
|
|
145
|
+
return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
|
|
180
146
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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);
|
|
147
|
+
exports.hkdf = hkdf;
|
|
148
|
+
function derivePairingCodeKey(pairingCode, salt) {
|
|
149
|
+
return (0, crypto_1.pbkdf2Sync)(pairingCode, salt, 2 << 16, 32, 'sha256');
|
|
198
150
|
}
|
|
199
|
-
|
|
151
|
+
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
@@ -2,23 +2,6 @@ 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
|
-
};
|
|
22
5
|
/**
|
|
23
6
|
* Decode the received node as a message.
|
|
24
7
|
* @note this will only parse the message, not decrypt it
|