alipclutch-baileys 8.3.0 → 8.4.1
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 +3 -1
- package/README.md +10 -9
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.d.ts +55057 -0
- package/WAProto/index.js +56887 -17535
- package/WAProto/index.ts.ts +53473 -0
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/index.d.ts +16 -7
- package/lib/Defaults/index.js +90 -119
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/types.d.ts +0 -1
- package/lib/Socket/Client/types.js +0 -1
- package/lib/Socket/Client/websocket.d.ts +0 -1
- package/lib/Socket/Client/websocket.js +0 -1
- package/lib/Socket/business.d.ts +59 -58
- package/lib/Socket/chats.d.ts +45 -230
- package/lib/Socket/chats.js +139 -238
- package/lib/Socket/groups.d.ts +41 -32
- package/lib/Socket/groups.js +38 -23
- package/lib/Socket/index.d.ts +63 -64
- package/lib/Socket/index.js +2 -3
- package/lib/Socket/messages-recv.js +9 -65
- package/lib/Socket/messages-send.d.ts +49 -47
- package/lib/Socket/messages-send.js +584 -395
- package/lib/Socket/newsletter.d.ts +39 -37
- package/lib/Socket/newsletter.js +88 -123
- package/lib/Socket/setup.js +433 -0
- package/lib/Socket/{dugong.d.ts → setup.ts} +17 -52
- package/lib/Socket/socket.d.ts +10 -10
- package/lib/Socket/socket.js +62 -38
- package/lib/Socket/usync.d.ts +3 -4
- package/lib/Socket/usync.js +0 -1
- package/lib/Store/index.d.ts +1 -2
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.d.ts +24 -24
- package/lib/Store/make-in-memory-store.js +26 -14
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +0 -7
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +14 -7
- package/lib/Types/Contact.d.ts +5 -1
- package/lib/Types/Events.d.ts +44 -2
- package/lib/Types/GroupMetadata.d.ts +11 -2
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +148 -21
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.d.ts +73 -97
- package/lib/Types/Newsletter.js +18 -38
- package/lib/Types/Socket.d.ts +17 -9
- package/lib/Types/index.d.ts +8 -1
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +6 -13
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +15 -16
- package/lib/Utils/chat-utils.js +36 -35
- package/lib/Utils/crypto.d.ts +15 -16
- package/lib/Utils/crypto.js +71 -29
- package/lib/Utils/decode-wa-message.d.ts +22 -6
- package/lib/Utils/decode-wa-message.js +65 -56
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +11 -7
- package/lib/Utils/generics.d.ts +17 -20
- package/lib/Utils/generics.js +95 -75
- package/lib/Utils/history.d.ts +4 -0
- package/lib/Utils/history.js +4 -6
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +34 -1
- package/lib/Utils/logger.d.ts +10 -3
- package/lib/Utils/lt-hash.d.ts +2 -2
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +28 -24
- package/lib/Utils/messages-media.js +272 -111
- package/lib/Utils/messages.d.ts +13 -10
- package/lib/Utils/messages.js +323 -50
- package/lib/Utils/noise-handler.d.ts +10 -12
- package/lib/Utils/noise-handler.js +18 -23
- package/lib/Utils/process-message.d.ts +5 -4
- package/lib/Utils/process-message.js +108 -25
- package/lib/Utils/signal.d.ts +2 -1
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -1
- package/lib/Utils/use-multi-file-auth-state.js +51 -6
- package/lib/Utils/validate-connection.d.ts +3 -4
- package/lib/Utils/validate-connection.js +90 -66
- package/lib/WABinary/constants.d.ts +24 -27
- package/lib/WABinary/constants.js +1276 -13
- package/lib/WABinary/decode.d.ts +3 -4
- package/lib/WABinary/decode.js +26 -13
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +137 -152
- package/lib/WABinary/generic-utils.d.ts +1 -4
- package/lib/WABinary/generic-utils.js +37 -125
- package/lib/WABinary/jid-utils.d.ts +11 -5
- package/lib/WABinary/jid-utils.js +28 -5
- package/lib/WABinary/jid-utils.js.bak +83 -0
- package/lib/WAM/BinaryInfo.d.ts +2 -11
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +27 -15
- package/package.json +18 -31
- package/engine-requirements.js +0 -10
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/dugong.js +0 -483
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-cache-manager-store.js +0 -83
package/lib/Types/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export * from './Auth';
|
|
2
2
|
export * from './GroupMetadata';
|
|
3
|
+
export * from './Newsletter';
|
|
3
4
|
export * from './Chat';
|
|
4
5
|
export * from './Contact';
|
|
5
6
|
export * from './State';
|
|
6
7
|
export * from './Message';
|
|
7
|
-
export * from './Newsletter';
|
|
8
8
|
export * from './Socket';
|
|
9
9
|
export * from './Events';
|
|
10
10
|
export * from './Product';
|
|
@@ -15,6 +15,13 @@ import { SocketConfig } from './Socket';
|
|
|
15
15
|
export type UserFacingSocketConfig = Partial<SocketConfig> & {
|
|
16
16
|
auth: AuthenticationState;
|
|
17
17
|
};
|
|
18
|
+
export type BrowsersMap = {
|
|
19
|
+
ubuntu(browser: string): [string, string, string];
|
|
20
|
+
macOS(browser: string): [string, string, string];
|
|
21
|
+
baileys(browser: string): [string, string, string];
|
|
22
|
+
windows(browser: string): [string, string, string];
|
|
23
|
+
appropriate(browser: string): [string, string, string];
|
|
24
|
+
};
|
|
18
25
|
export declare enum DisconnectReason {
|
|
19
26
|
connectionClosed = 428,
|
|
20
27
|
connectionLost = 408,
|
package/lib/Types/index.js
CHANGED
|
@@ -17,11 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.DisconnectReason = void 0;
|
|
18
18
|
__exportStar(require("./Auth"), exports);
|
|
19
19
|
__exportStar(require("./GroupMetadata"), exports);
|
|
20
|
+
__exportStar(require("./Newsletter"), exports);
|
|
20
21
|
__exportStar(require("./Chat"), exports);
|
|
21
22
|
__exportStar(require("./Contact"), exports);
|
|
22
23
|
__exportStar(require("./State"), exports);
|
|
23
24
|
__exportStar(require("./Message"), exports);
|
|
24
|
-
__exportStar(require("./Newsletter"), exports);
|
|
25
25
|
__exportStar(require("./Socket"), exports);
|
|
26
26
|
__exportStar(require("./Events"), exports);
|
|
27
27
|
__exportStar(require("./Product"), exports);
|
|
@@ -39,4 +39,4 @@ var DisconnectReason;
|
|
|
39
39
|
DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
|
|
40
40
|
DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
|
|
41
41
|
DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
|
|
42
|
-
})(DisconnectReason
|
|
42
|
+
})(DisconnectReason || (exports.DisconnectReason = DisconnectReason = {}));
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { Logger } from 'pino';
|
|
2
1
|
import type { AuthenticationCreds, CacheStore, SignalKeyStore, SignalKeyStoreWithTransaction, TransactionCapabilityOptions } from '../Types';
|
|
2
|
+
import { ILogger } from './logger';
|
|
3
3
|
/**
|
|
4
4
|
* Adds caching capability to a SignalKeyStore
|
|
5
5
|
* @param store the store to add caching to
|
|
6
6
|
* @param logger to log trace events
|
|
7
7
|
* @param _cache cache store to use
|
|
8
8
|
*/
|
|
9
|
-
export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logger
|
|
9
|
+
export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logger?: ILogger, _cache?: CacheStore): SignalKeyStore;
|
|
10
10
|
/**
|
|
11
11
|
* Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
|
|
12
12
|
* this allows batch read & write operations & improves the performance of the lib
|
|
@@ -14,5 +14,5 @@ export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logge
|
|
|
14
14
|
* @param logger logger to log events
|
|
15
15
|
* @returns SignalKeyStore with transaction capability
|
|
16
16
|
*/
|
|
17
|
-
export declare const addTransactionCapability: (state: SignalKeyStore, logger:
|
|
17
|
+
export declare const addTransactionCapability: (state: SignalKeyStore, logger: ILogger, { maxCommitRetries, delayBetweenTriesMs }: TransactionCapabilityOptions) => SignalKeyStoreWithTransaction;
|
|
18
18
|
export declare const initAuthCreds: () => AuthenticationCreds;
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -3,10 +3,10 @@ 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
|
-
const node_cache_1 = __importDefault(require("node-cache"));
|
|
9
|
-
const uuid_1 = require("uuid");
|
|
9
|
+
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
10
10
|
const Defaults_1 = require("../Defaults");
|
|
11
11
|
const crypto_2 = require("./crypto");
|
|
12
12
|
const generics_1 = require("./generics");
|
|
@@ -18,7 +18,7 @@ const generics_1 = require("./generics");
|
|
|
18
18
|
*/
|
|
19
19
|
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
20
20
|
const cache = _cache || new node_cache_1.default({
|
|
21
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
21
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
|
|
22
22
|
useClones: false,
|
|
23
23
|
deleteOnExpire: true,
|
|
24
24
|
});
|
|
@@ -39,7 +39,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
if (idsToFetch.length) {
|
|
42
|
-
logger.trace({ items: idsToFetch.length }, 'loading from store');
|
|
42
|
+
logger === null || logger === void 0 ? void 0 : logger.trace({ items: idsToFetch.length }, 'loading from store');
|
|
43
43
|
const fetched = await store.get(type, idsToFetch);
|
|
44
44
|
for (const id of idsToFetch) {
|
|
45
45
|
const item = fetched[id];
|
|
@@ -59,7 +59,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
59
59
|
keys += 1;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
logger.trace({ keys }, 'updated cache');
|
|
62
|
+
logger === null || logger === void 0 ? void 0 : logger.trace({ keys }, 'updated cache');
|
|
63
63
|
await store.set(data);
|
|
64
64
|
},
|
|
65
65
|
async clear() {
|
|
@@ -69,7 +69,6 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
73
72
|
/**
|
|
74
73
|
* Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
|
|
75
74
|
* this allows batch read & write operations & improves the performance of the lib
|
|
@@ -191,13 +190,7 @@ const initAuthCreds = () => {
|
|
|
191
190
|
accountSettings: {
|
|
192
191
|
unarchiveChats: false
|
|
193
192
|
},
|
|
194
|
-
// mobile creds
|
|
195
|
-
deviceId: Buffer.from((0, uuid_1.v4)().replace(/-/g, ''), 'hex').toString('base64url'),
|
|
196
|
-
phoneId: (0, uuid_1.v4)(),
|
|
197
|
-
identityId: (0, crypto_1.randomBytes)(20),
|
|
198
193
|
registered: false,
|
|
199
|
-
backupToken: (0, crypto_1.randomBytes)(20),
|
|
200
|
-
registration: {},
|
|
201
194
|
pairingCode: undefined,
|
|
202
195
|
lastPropHash: undefined,
|
|
203
196
|
routingInfo: undefined,
|
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,9 +1,8 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { AxiosRequestConfig } from 'axios';
|
|
3
|
-
import type { Logger } from 'pino';
|
|
4
2
|
import { proto } from '../../WAProto';
|
|
5
3
|
import { BaileysEventEmitter, ChatModification, ChatMutation, Contact, InitialAppStateSyncOptions, LTHashState, WAPatchCreate, WAPatchName } from '../Types';
|
|
6
4
|
import { BinaryNode } from '../WABinary';
|
|
5
|
+
import { ILogger } from './logger';
|
|
7
6
|
type FetchAppStateSyncKey = (keyId: string) => Promise<proto.Message.IAppStateSyncKeyData | null | undefined>;
|
|
8
7
|
export type ChatMutationMap = {
|
|
9
8
|
[index: string]: ChatMutation;
|
|
@@ -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: Buffer
|
|
16
|
+
hash: Buffer<any>;
|
|
18
17
|
indexValueMap: {
|
|
19
18
|
[indexMacBase64: string]: {
|
|
20
19
|
valueMac: Uint8Array | Buffer;
|
|
@@ -22,7 +21,7 @@ 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: Buffer
|
|
24
|
+
hash: Buffer<any>;
|
|
26
25
|
indexValueMap: {
|
|
27
26
|
[indexMacBase64: string]: {
|
|
28
27
|
valueMac: Uint8Array | Buffer;
|
|
@@ -30,42 +29,42 @@ export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchNam
|
|
|
30
29
|
};
|
|
31
30
|
}>;
|
|
32
31
|
export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<any>) => Promise<{
|
|
33
|
-
critical_block: {
|
|
34
|
-
patches: proto.ISyncdPatch[];
|
|
35
|
-
hasMorePatches: boolean;
|
|
36
|
-
snapshot?: proto.ISyncdSnapshot | undefined;
|
|
37
|
-
};
|
|
38
32
|
critical_unblock_low: {
|
|
39
33
|
patches: proto.ISyncdPatch[];
|
|
40
34
|
hasMorePatches: boolean;
|
|
41
|
-
snapshot?: proto.ISyncdSnapshot
|
|
35
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
42
36
|
};
|
|
43
37
|
regular_high: {
|
|
44
38
|
patches: proto.ISyncdPatch[];
|
|
45
39
|
hasMorePatches: boolean;
|
|
46
|
-
snapshot?: proto.ISyncdSnapshot
|
|
40
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
47
41
|
};
|
|
48
42
|
regular_low: {
|
|
49
43
|
patches: proto.ISyncdPatch[];
|
|
50
44
|
hasMorePatches: boolean;
|
|
51
|
-
snapshot?: proto.ISyncdSnapshot
|
|
45
|
+
snapshot?: proto.ISyncdSnapshot;
|
|
46
|
+
};
|
|
47
|
+
critical_block: {
|
|
48
|
+
patches: proto.ISyncdPatch[];
|
|
49
|
+
hasMorePatches: boolean;
|
|
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<any>) => Promise<Buffer
|
|
58
|
+
export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<Buffer<ArrayBuffer>>;
|
|
60
59
|
export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => 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<any>, minimumVersionNumber?: number, logger?:
|
|
64
|
+
export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<any>, minimumVersionNumber?: number, logger?: ILogger, validateMacs?: boolean) => Promise<{
|
|
66
65
|
state: LTHashState;
|
|
67
66
|
mutationMap: ChatMutationMap;
|
|
68
67
|
}>;
|
|
69
68
|
export declare const chatModificationToAppPatch: (mod: ChatModification, jid: string) => WAPatchCreate;
|
|
70
|
-
export declare const processSyncAction: (syncAction: ChatMutation, ev: BaileysEventEmitter, me: Contact, initialSyncOpts?: InitialAppStateSyncOptions, logger?:
|
|
69
|
+
export declare const processSyncAction: (syncAction: ChatMutation, ev: BaileysEventEmitter, me: Contact, initialSyncOpts?: InitialAppStateSyncOptions, logger?: ILogger) => void;
|
|
71
70
|
export {};
|
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.processSyncAction = exports.chatModificationToAppPatch = exports.decodePatches = exports.decodeSyncdSnapshot = exports.downloadExternalPatch = exports.downloadExternalBlob = exports.extractSyncdPatches = exports.decodeSyncdPatch = exports.decodeSyncdMutations = exports.encodeSyncdPatch = exports.newLTHashState = void 0;
|
|
4
4
|
const boom_1 = require("@hapi/boom");
|
|
5
5
|
const WAProto_1 = require("../../WAProto");
|
|
6
|
-
const LabelAssociation_1 = require("../Types/LabelAssociation");
|
|
7
6
|
const WABinary_1 = require("../WABinary");
|
|
7
|
+
const LabelAssociation_1 = require("../Types/LabelAssociation");
|
|
8
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`);
|
|
@@ -332,7 +332,7 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
|
332
332
|
if (!keyEnc) {
|
|
333
333
|
throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
334
334
|
}
|
|
335
|
-
const result = mutationKeys(keyEnc.keyData);
|
|
335
|
+
const result = await mutationKeys(keyEnc.keyData);
|
|
336
336
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
337
337
|
if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
|
|
338
338
|
throw new boom_1.Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
|
|
@@ -418,25 +418,31 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
|
418
418
|
operation: OP.SET
|
|
419
419
|
};
|
|
420
420
|
}
|
|
421
|
+
else if ('deleteForMe' in mod) {
|
|
422
|
+
const { timestamp, key, deleteMedia } = mod.deleteForMe;
|
|
423
|
+
patch = {
|
|
424
|
+
syncAction: {
|
|
425
|
+
deleteMessageForMeAction: {
|
|
426
|
+
deleteMedia,
|
|
427
|
+
messageTimestamp: timestamp
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
|
|
431
|
+
type: 'regular_high',
|
|
432
|
+
apiVersion: 3,
|
|
433
|
+
operation: OP.SET
|
|
434
|
+
};
|
|
435
|
+
}
|
|
421
436
|
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
|
-
}
|
|
437
|
+
patch = {
|
|
438
|
+
syncAction: {
|
|
439
|
+
clearChatAction: {} // add message range later
|
|
440
|
+
},
|
|
441
|
+
index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
|
|
442
|
+
type: 'regular_high',
|
|
443
|
+
apiVersion: 6,
|
|
444
|
+
operation: OP.SET
|
|
445
|
+
};
|
|
440
446
|
}
|
|
441
447
|
else if ('pin' in mod) {
|
|
442
448
|
patch = {
|
|
@@ -633,12 +639,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
633
639
|
});
|
|
634
640
|
}
|
|
635
641
|
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
|
-
}]);
|
|
642
|
+
ev.emit('contacts.upsert', [{ id, name: action.contactAction.fullName, lid: action.contactAction.lidJid || undefined, jid: (0, WABinary_1.isJidUser)(id) ? id : action.contactAction.pnJid }]);
|
|
642
643
|
}
|
|
643
644
|
else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
|
|
644
645
|
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) => Uint8Array | Buffer
|
|
3
|
+
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>;
|
|
5
4
|
export declare const Curve: {
|
|
6
5
|
generateKeyPair: () => KeyPair;
|
|
7
|
-
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer
|
|
6
|
+
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer<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): Buffer
|
|
19
|
+
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer<ArrayBuffer>;
|
|
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): 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
|
|
24
|
+
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer<ArrayBuffer>;
|
|
25
|
+
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer<ArrayBuffer>;
|
|
26
|
+
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer<ArrayBuffer>;
|
|
28
27
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
29
|
-
export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer
|
|
28
|
+
export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer<ArrayBuffer>;
|
|
30
29
|
/** decrypt AES 256 CBC */
|
|
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
|
|
30
|
+
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer<ArrayBuffer>;
|
|
31
|
+
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer<ArrayBuffer>;
|
|
32
|
+
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer<ArrayBuffer>;
|
|
33
|
+
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer<ArrayBufferLike>;
|
|
34
|
+
export declare function sha256(buffer: Buffer): Buffer<ArrayBufferLike>;
|
|
35
|
+
export declare function md5(buffer: Buffer): Buffer<ArrayBufferLike>;
|
|
37
36
|
export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
|
|
38
37
|
salt?: Buffer;
|
|
39
38
|
info?: string;
|
|
40
|
-
}): Buffer
|
|
41
|
-
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Buffer
|
|
39
|
+
}): Promise<Buffer>;
|
|
40
|
+
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<Buffer>;
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -15,22 +15,43 @@ 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
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
+
})();
|
|
28
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
36
|
+
exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
|
37
|
+
exports.aesEncryptGCM = aesEncryptGCM;
|
|
38
|
+
exports.aesDecryptGCM = aesDecryptGCM;
|
|
39
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
|
40
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
|
41
|
+
exports.aesDecrypt = aesDecrypt;
|
|
42
|
+
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
43
|
+
exports.aesEncrypt = aesEncrypt;
|
|
44
|
+
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
45
|
+
exports.hmacSign = hmacSign;
|
|
46
|
+
exports.sha256 = sha256;
|
|
47
|
+
exports.md5 = md5;
|
|
48
|
+
exports.hkdf = hkdf;
|
|
49
|
+
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
30
50
|
const crypto_1 = require("crypto");
|
|
31
|
-
const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
|
32
51
|
const libsignal = __importStar(require("libsignal"));
|
|
33
52
|
const Defaults_1 = require("../Defaults");
|
|
53
|
+
// insure browser & node compatibility
|
|
54
|
+
const { subtle } = globalThis.crypto;
|
|
34
55
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
35
56
|
const generateSignalPubKey = (pubKey) => (pubKey.length === 33
|
|
36
57
|
? pubKey
|
|
@@ -77,7 +98,6 @@ function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
|
77
98
|
cipher.setAAD(additionalData);
|
|
78
99
|
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
79
100
|
}
|
|
80
|
-
exports.aesEncryptGCM = aesEncryptGCM;
|
|
81
101
|
/**
|
|
82
102
|
* decrypt AES 256 GCM;
|
|
83
103
|
* where the auth tag is suffixed to the ciphertext
|
|
@@ -92,60 +112,82 @@ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
|
92
112
|
decipher.setAuthTag(tag);
|
|
93
113
|
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
94
114
|
}
|
|
95
|
-
exports.aesDecryptGCM = aesDecryptGCM;
|
|
96
115
|
function aesEncryptCTR(plaintext, key, iv) {
|
|
97
116
|
const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
|
98
117
|
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
99
118
|
}
|
|
100
|
-
exports.aesEncryptCTR = aesEncryptCTR;
|
|
101
119
|
function aesDecryptCTR(ciphertext, key, iv) {
|
|
102
120
|
const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
|
103
121
|
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
104
122
|
}
|
|
105
|
-
exports.aesDecryptCTR = aesDecryptCTR;
|
|
106
123
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
107
124
|
function aesDecrypt(buffer, key) {
|
|
108
125
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
|
109
126
|
}
|
|
110
|
-
exports.aesDecrypt = aesDecrypt;
|
|
111
127
|
/** decrypt AES 256 CBC */
|
|
112
128
|
function aesDecryptWithIV(buffer, key, IV) {
|
|
113
129
|
const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
|
|
114
130
|
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
115
131
|
}
|
|
116
|
-
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
117
132
|
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
118
133
|
function aesEncrypt(buffer, key) {
|
|
119
134
|
const IV = (0, crypto_1.randomBytes)(16);
|
|
120
135
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
121
136
|
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
122
137
|
}
|
|
123
|
-
exports.aesEncrypt = aesEncrypt;
|
|
124
138
|
// encrypt AES 256 CBC with a given IV
|
|
125
139
|
function aesEncrypWithIV(buffer, key, IV) {
|
|
126
140
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
127
141
|
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
128
142
|
}
|
|
129
|
-
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
130
143
|
// sign HMAC using SHA 256
|
|
131
144
|
function hmacSign(buffer, key, variant = 'sha256') {
|
|
132
145
|
return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
|
|
133
146
|
}
|
|
134
|
-
exports.hmacSign = hmacSign;
|
|
135
147
|
function sha256(buffer) {
|
|
136
148
|
return (0, crypto_1.createHash)('sha256').update(buffer).digest();
|
|
137
149
|
}
|
|
138
|
-
exports.sha256 = sha256;
|
|
139
150
|
function md5(buffer) {
|
|
140
151
|
return (0, crypto_1.createHash)('md5').update(buffer).digest();
|
|
141
152
|
}
|
|
142
|
-
exports.md5 = md5;
|
|
143
153
|
// HKDF key expansion
|
|
144
|
-
function hkdf(buffer, expandedLength, info) {
|
|
145
|
-
|
|
154
|
+
async function hkdf(buffer, expandedLength, info) {
|
|
155
|
+
// Ensure we have a Uint8Array for the key material
|
|
156
|
+
const inputKeyMaterial = buffer instanceof Uint8Array
|
|
157
|
+
? buffer
|
|
158
|
+
: new Uint8Array(buffer);
|
|
159
|
+
// Set default values if not provided
|
|
160
|
+
const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
|
|
161
|
+
const infoBytes = info.info
|
|
162
|
+
? new TextEncoder().encode(info.info)
|
|
163
|
+
: new Uint8Array(0);
|
|
164
|
+
// Import the input key material
|
|
165
|
+
const importedKey = await subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits']);
|
|
166
|
+
// Derive bits using HKDF
|
|
167
|
+
const derivedBits = await subtle.deriveBits({
|
|
168
|
+
name: 'HKDF',
|
|
169
|
+
hash: 'SHA-256',
|
|
170
|
+
salt: salt,
|
|
171
|
+
info: infoBytes
|
|
172
|
+
}, importedKey, expandedLength * 8 // Convert bytes to bits
|
|
173
|
+
);
|
|
174
|
+
return Buffer.from(derivedBits);
|
|
146
175
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
176
|
+
async function derivePairingCodeKey(pairingCode, salt) {
|
|
177
|
+
// Convert inputs to formats Web Crypto API can work with
|
|
178
|
+
const encoder = new TextEncoder();
|
|
179
|
+
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
180
|
+
const saltBuffer = salt instanceof Uint8Array ? salt : new Uint8Array(salt);
|
|
181
|
+
// Import the pairing code as key material
|
|
182
|
+
const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, ['deriveBits']);
|
|
183
|
+
// Derive bits using PBKDF2 with the same parameters
|
|
184
|
+
// 2 << 16 = 131,072 iterations
|
|
185
|
+
const derivedBits = await subtle.deriveBits({
|
|
186
|
+
name: 'PBKDF2',
|
|
187
|
+
salt: saltBuffer,
|
|
188
|
+
iterations: 2 << 16,
|
|
189
|
+
hash: 'SHA-256'
|
|
190
|
+
}, keyMaterial, 32 * 8 // 32 bytes * 8 = 256 bits
|
|
191
|
+
);
|
|
192
|
+
return Buffer.from(derivedBits);
|
|
150
193
|
}
|
|
151
|
-
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
@@ -1,18 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { SignalRepository } from '../Types';
|
|
1
|
+
import { ILogger } from './logger';
|
|
2
|
+
import { SignalRepository, WAMessage } from '../Types';
|
|
4
3
|
import { BinaryNode } from '../WABinary';
|
|
4
|
+
export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
|
|
5
|
+
export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
|
|
6
|
+
export declare const NACK_REASONS: {
|
|
7
|
+
ParsingError: number;
|
|
8
|
+
UnrecognizedStanza: number;
|
|
9
|
+
UnrecognizedStanzaClass: number;
|
|
10
|
+
UnrecognizedStanzaType: number;
|
|
11
|
+
InvalidProtobuf: number;
|
|
12
|
+
InvalidHostedCompanionStanza: number;
|
|
13
|
+
MissingMessageSecret: number;
|
|
14
|
+
SignalErrorOldCounter: number;
|
|
15
|
+
MessageDeletedOnPeer: number;
|
|
16
|
+
UnhandledError: number;
|
|
17
|
+
UnsupportedAdminRevoke: number;
|
|
18
|
+
UnsupportedLIDGroup: number;
|
|
19
|
+
DBOperationFailed: number;
|
|
20
|
+
};
|
|
5
21
|
/**
|
|
6
22
|
* Decode the received node as a message.
|
|
7
23
|
* @note this will only parse the message, not decrypt it
|
|
8
24
|
*/
|
|
9
25
|
export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
|
|
10
|
-
fullMessage:
|
|
26
|
+
fullMessage: WAMessage;
|
|
11
27
|
author: string;
|
|
12
28
|
sender: string;
|
|
13
29
|
};
|
|
14
|
-
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger:
|
|
15
|
-
fullMessage:
|
|
30
|
+
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger) => {
|
|
31
|
+
fullMessage: WAMessage;
|
|
16
32
|
category: string;
|
|
17
33
|
author: string;
|
|
18
34
|
decrypt(): Promise<void>;
|