@hbmodsofc/baileys 1.5.2 → 1.7.7
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 +1 -1
- package/WAProto/index.js +19671 -152026
- package/lib/Defaults/index.d.ts +12 -8
- package/lib/Defaults/index.js +90 -124
- package/lib/Signal/Group/group_cipher.d.ts +0 -1
- package/lib/Signal/Group/group_cipher.js +28 -39
- package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
- package/lib/Signal/Group/sender-chain-key.js +9 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +3 -3
- package/lib/Signal/Group/sender-key-message.js +3 -3
- package/lib/Signal/Group/sender-key-state.d.ts +4 -4
- package/lib/Signal/Group/sender-key-state.js +47 -16
- package/lib/Signal/libsignal.d.ts +7 -3
- package/lib/Signal/libsignal.js +224 -39
- package/lib/Signal/lid-mapping.d.ts +26 -0
- package/lib/Signal/lid-mapping.js +146 -0
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +1 -3
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +10 -16
- package/lib/Socket/business.d.ts +94 -78
- package/lib/Socket/business.js +130 -11
- package/lib/Socket/chats.d.ts +63 -233
- package/lib/Socket/chats.js +234 -184
- package/lib/Socket/communities.d.ts +232 -0
- package/lib/Socket/communities.js +402 -0
- package/lib/Socket/groups.d.ts +62 -41
- package/lib/Socket/groups.js +76 -64
- package/lib/Socket/index.d.ts +129 -83
- package/lib/Socket/index.js +13 -6
- package/lib/Socket/messages-recv.d.ts +59 -48
- package/lib/Socket/messages-recv.js +516 -371
- package/lib/Socket/messages-send.d.ts +86 -67
- package/lib/Socket/messages-send.js +1091 -1
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.d.ts +76 -64
- package/lib/Socket/newsletter.js +184 -1
- package/lib/Socket/socket.d.ts +19 -13
- package/lib/Socket/socket.js +805 -1
- package/lib/Types/Auth.d.ts +4 -10
- package/lib/Types/Bussines.d.ts +24 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +29 -9
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.d.ts +5 -1
- package/lib/Types/Events.d.ts +55 -14
- package/lib/Types/GroupMetadata.d.ts +15 -5
- 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 +75 -49
- package/lib/Types/Message.js +10 -7
- package/lib/Types/Newsletter.d.ts +129 -98
- package/lib/Types/Newsletter.js +33 -38
- package/lib/Types/Product.d.ts +1 -1
- package/lib/Types/Signal.d.ts +29 -1
- package/lib/Types/Socket.d.ts +48 -22
- package/lib/Types/State.d.ts +13 -2
- package/lib/Types/State.js +12 -0
- package/lib/Types/USync.d.ts +1 -1
- package/lib/Types/index.d.ts +10 -3
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +378 -102
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/business.d.ts +2 -2
- package/lib/Utils/business.js +19 -13
- package/lib/Utils/chat-utils.d.ts +21 -22
- package/lib/Utils/chat-utils.js +201 -154
- package/lib/Utils/crypto.d.ts +18 -19
- package/lib/Utils/crypto.js +78 -37
- package/lib/Utils/decode-wa-message.d.ts +34 -7
- package/lib/Utils/decode-wa-message.js +138 -66
- package/lib/Utils/event-buffer.d.ts +6 -8
- package/lib/Utils/event-buffer.js +81 -43
- package/lib/Utils/generics.d.ts +27 -27
- package/lib/Utils/generics.js +128 -133
- package/lib/Utils/history.d.ts +9 -5
- package/lib/Utils/history.js +17 -23
- package/lib/Utils/index.d.ts +2 -0
- package/lib/Utils/index.js +2 -0
- package/lib/Utils/lidToJid-test.d.ts +11 -0
- package/lib/Utils/lidToJid-test.js +27 -0
- package/lib/Utils/link-preview.d.ts +4 -4
- package/lib/Utils/link-preview.js +40 -12
- package/lib/Utils/logger.d.ts +11 -3
- package/lib/Utils/lt-hash.d.ts +8 -8
- package/lib/Utils/lt-hash.js +23 -24
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/make-mutex.js +3 -2
- package/lib/Utils/message-retry-manager.d.ts +81 -0
- package/lib/Utils/message-retry-manager.js +152 -0
- package/lib/Utils/messages-media.d.ts +37 -41
- package/lib/Utils/messages-media.js +252 -368
- package/lib/Utils/messages.d.ts +13 -15
- package/lib/Utils/messages.js +274 -261
- package/lib/Utils/noise-handler.d.ts +13 -15
- package/lib/Utils/noise-handler.js +20 -26
- package/lib/Utils/process-message.d.ts +9 -8
- package/lib/Utils/process-message.js +157 -93
- package/lib/Utils/signal.d.ts +6 -5
- package/lib/Utils/signal.js +37 -29
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
- package/lib/Utils/use-multi-file-auth-state.js +12 -7
- package/lib/Utils/validate-connection.d.ts +5 -6
- package/lib/Utils/validate-connection.js +39 -97
- 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 +28 -14
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +134 -147
- package/lib/WABinary/generic-utils.d.ts +4 -7
- package/lib/WABinary/generic-utils.js +40 -125
- package/lib/WABinary/jid-utils.d.ts +13 -8
- package/lib/WABinary/jid-utils.js +27 -16
- package/lib/WAM/BinaryInfo.d.ts +2 -11
- package/lib/WAM/constants.d.ts +3 -2
- package/lib/WAM/constants.js +2252 -2359
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAM/encode.js +8 -11
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +3 -4
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -5
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +5 -5
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -6
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
- package/lib/WAUSync/USyncQuery.d.ts +2 -2
- package/lib/WAUSync/USyncQuery.js +19 -15
- package/lib/WAUSync/USyncUser.d.ts +5 -5
- package/lib/WAUSync/index.d.ts +1 -1
- package/lib/WAUSync/index.js +1 -1
- package/package.json +102 -102
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/hbmods.d.ts +0 -253
- package/lib/Socket/hbmods.js +0 -1
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Socket/usync.js +0 -70
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
package/lib/Defaults/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { proto } from '../../WAProto';
|
|
4
|
-
import type { MediaType, SocketConfig } from '../Types';
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import type { SocketConfig } from '../Types';
|
|
5
3
|
export declare const UNAUTHORIZED_CODES: number[];
|
|
6
4
|
export declare const DEFAULT_ORIGIN = "https://web.whatsapp.com";
|
|
5
|
+
export declare const CALL_VIDEO_PREFIX = "https://call.whatsapp.com/video/";
|
|
6
|
+
export declare const CALL_AUDIO_PREFIX = "https://call.whatsapp.com/voice/";
|
|
7
7
|
export declare const DEF_CALLBACK_PREFIX = "CB:";
|
|
8
8
|
export declare const DEF_TAG_PREFIX = "TAG:";
|
|
9
9
|
export declare const PHONE_CONNECTION_CB = "CB:Pong";
|
|
10
10
|
export declare const WA_DEFAULT_EPHEMERAL: number;
|
|
11
11
|
export declare const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
|
|
12
|
-
export declare const DICT_VERSION =
|
|
13
|
-
export declare const KEY_BUNDLE_TYPE: Buffer
|
|
14
|
-
export declare const NOISE_WA_HEADER: Buffer
|
|
12
|
+
export declare const DICT_VERSION = 3;
|
|
13
|
+
export declare const KEY_BUNDLE_TYPE: Buffer<ArrayBuffer>;
|
|
14
|
+
export declare const NOISE_WA_HEADER: Buffer<ArrayBuffer>;
|
|
15
15
|
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
16
16
|
export declare const URL_REGEX: RegExp;
|
|
17
17
|
export declare const WA_CERT_DETAILS: {
|
|
@@ -41,10 +41,14 @@ export declare const MEDIA_HKDF_KEY_MAPPING: {
|
|
|
41
41
|
'product-catalog-image': string;
|
|
42
42
|
'payment-bg-image': string;
|
|
43
43
|
ptv: string;
|
|
44
|
+
'biz-cover-photo': string;
|
|
44
45
|
};
|
|
45
|
-
export
|
|
46
|
+
export type MediaType = keyof typeof MEDIA_HKDF_KEY_MAPPING;
|
|
47
|
+
export declare const MEDIA_KEYS: MediaType[];
|
|
46
48
|
export declare const MIN_PREKEY_COUNT = 5;
|
|
47
49
|
export declare const INITIAL_PREKEY_COUNT = 30;
|
|
50
|
+
export declare const UPLOAD_TIMEOUT = 30000;
|
|
51
|
+
export declare const MIN_UPLOAD_INTERVAL = 5000;
|
|
48
52
|
export declare const DEFAULT_CACHE_TTLS: {
|
|
49
53
|
SIGNAL_STORE: number;
|
|
50
54
|
MSG_RETRY: number;
|
package/lib/Defaults/index.js
CHANGED
|
@@ -1,147 +1,113 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
3
4
|
};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
exports.MEDIA_HKDF_KEY_MAPPING =
|
|
12
|
-
exports.MEDIA_PATH_MAP =
|
|
13
|
-
exports.DEFAULT_CONNECTION_CONFIG =
|
|
14
|
-
exports.PROCESSABLE_HISTORY_TYPES =
|
|
15
|
-
exports.WA_CERT_DETAILS =
|
|
16
|
-
exports.URL_REGEX =
|
|
17
|
-
exports.NOISE_WA_HEADER =
|
|
18
|
-
exports.KEY_BUNDLE_TYPE =
|
|
19
|
-
exports.DICT_VERSION =
|
|
20
|
-
exports.NOISE_MODE =
|
|
21
|
-
exports.WA_DEFAULT_EPHEMERAL =
|
|
22
|
-
exports.PHONE_CONNECTION_CB =
|
|
23
|
-
exports.DEF_TAG_PREFIX =
|
|
24
|
-
exports.DEF_CALLBACK_PREFIX =
|
|
25
|
-
exports.DEFAULT_ORIGIN =
|
|
26
|
-
exports.UNAUTHORIZED_CODES =
|
|
27
|
-
void 0;
|
|
28
|
-
|
|
29
|
-
const crypto_1 = require("crypto");
|
|
30
|
-
const WAProto_1 = require("../../WAProto"),
|
|
31
|
-
libsignal_1 = require("../Signal/libsignal"),
|
|
32
|
-
Utils_1 = require("../Utils"),
|
|
33
|
-
logger_1 = __importDefault(require("../Utils/logger")),
|
|
34
|
-
baileys_version_json_1 = require("./baileys-version.json"),
|
|
35
|
-
phonenumber_mcc_json_1 = __importDefault(require("./phonenumber-mcc.json"));
|
|
36
|
-
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_CACHE_TTLS = exports.MIN_UPLOAD_INTERVAL = exports.UPLOAD_TIMEOUT = exports.INITIAL_PREKEY_COUNT = exports.MIN_PREKEY_COUNT = exports.MEDIA_KEYS = exports.MEDIA_HKDF_KEY_MAPPING = exports.MEDIA_PATH_MAP = exports.DEFAULT_CONNECTION_CONFIG = exports.PROCESSABLE_HISTORY_TYPES = exports.WA_CERT_DETAILS = exports.URL_REGEX = exports.NOISE_WA_HEADER = exports.KEY_BUNDLE_TYPE = exports.DICT_VERSION = exports.NOISE_MODE = exports.WA_DEFAULT_EPHEMERAL = exports.PHONE_CONNECTION_CB = exports.DEF_TAG_PREFIX = exports.DEF_CALLBACK_PREFIX = exports.CALL_AUDIO_PREFIX = exports.CALL_VIDEO_PREFIX = exports.DEFAULT_ORIGIN = exports.UNAUTHORIZED_CODES = void 0;
|
|
7
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
8
|
+
const libsignal_1 = require("../Signal/libsignal");
|
|
9
|
+
const Utils_1 = require("../Utils");
|
|
10
|
+
const logger_1 = __importDefault(require("../Utils/logger"));
|
|
11
|
+
const version = [2, 3000, 1023223821];
|
|
37
12
|
exports.UNAUTHORIZED_CODES = [401, 403, 419];
|
|
38
|
-
exports.
|
|
39
|
-
exports.
|
|
40
|
-
exports.
|
|
41
|
-
exports.
|
|
42
|
-
exports.
|
|
43
|
-
exports.
|
|
44
|
-
exports.
|
|
45
|
-
exports.
|
|
46
|
-
exports.
|
|
47
|
-
const WA_VERSION = '2.25.23.24';
|
|
48
|
-
const WA_VERSION_HASH = (0, crypto_1.createHash)('md5').update(WA_VERSION).digest('hex');
|
|
49
|
-
exports.MOBILE_TOKEN = Buffer.from('0a1mLfGUIBVrMKF1RdvLI5lkRBvof6vn0fD2QRSM' + WA_VERSION_HASH);
|
|
50
|
-
exports.MOBILE_REGISTRATION_ENDPOINT = 'https://v.whatsapp.net/v2';
|
|
51
|
-
exports.MOBILE_USERAGENT = `WhatsApp/${WA_VERSION} iOS/17.5.1 Device/Apple-iPhone_13`;
|
|
52
|
-
exports.REGISTRATION_PUBLIC_KEY = Buffer.from([
|
|
53
|
-
5, 142, 140, 15, 116, 195, 235, 197, 215, 166, 134, 92, 108, 60, 132, 56, 86, 176, 97, 33, 204, 232, 234, 119, 77,
|
|
54
|
-
34, 251, 111, 18, 37, 18, 48, 45,
|
|
55
|
-
]);
|
|
56
|
-
exports.NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\x00\x00\x00\x00";
|
|
57
|
-
exports.DICT_VERSION = 2;
|
|
13
|
+
exports.DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
|
14
|
+
exports.CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/';
|
|
15
|
+
exports.CALL_AUDIO_PREFIX = 'https://call.whatsapp.com/voice/';
|
|
16
|
+
exports.DEF_CALLBACK_PREFIX = 'CB:';
|
|
17
|
+
exports.DEF_TAG_PREFIX = 'TAG:';
|
|
18
|
+
exports.PHONE_CONNECTION_CB = 'CB:Pong';
|
|
19
|
+
exports.WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
|
|
20
|
+
exports.NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0';
|
|
21
|
+
exports.DICT_VERSION = 3;
|
|
58
22
|
exports.KEY_BUNDLE_TYPE = Buffer.from([5]);
|
|
59
|
-
exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]);
|
|
60
|
-
|
|
61
|
-
exports.MOBILE_NOISE_HEADER = Buffer.concat([Buffer.from('WA'), Buffer.from(exports.PROTOCOL_VERSION)]);
|
|
62
|
-
|
|
23
|
+
exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]); // last is "DICT_VERSION"
|
|
24
|
+
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
|
|
63
25
|
exports.URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
|
|
64
|
-
exports.WA_CERT_DETAILS = {
|
|
65
|
-
|
|
26
|
+
exports.WA_CERT_DETAILS = {
|
|
27
|
+
SERIAL: 0
|
|
28
|
+
};
|
|
66
29
|
exports.PROCESSABLE_HISTORY_TYPES = [
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
30
|
+
index_js_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
31
|
+
index_js_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
|
|
32
|
+
index_js_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
|
|
33
|
+
index_js_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
|
|
34
|
+
index_js_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND
|
|
72
35
|
];
|
|
73
|
-
|
|
74
36
|
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
75
|
-
version:
|
|
76
|
-
browser: Utils_1.Browsers(
|
|
77
|
-
waWebSocketUrl:
|
|
78
|
-
connectTimeoutMs:
|
|
79
|
-
keepAliveIntervalMs:
|
|
80
|
-
logger: logger_1.default.child({ class:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
defaultQueryTimeoutMs: 6E4,
|
|
37
|
+
version: version,
|
|
38
|
+
browser: Utils_1.Browsers.ubuntu('Chrome'),
|
|
39
|
+
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
40
|
+
connectTimeoutMs: 20000,
|
|
41
|
+
keepAliveIntervalMs: 30000,
|
|
42
|
+
logger: logger_1.default.child({ class: 'baileys' }),
|
|
43
|
+
emitOwnEvents: true,
|
|
44
|
+
defaultQueryTimeoutMs: 60000,
|
|
84
45
|
customUploadHosts: [],
|
|
85
46
|
retryRequestDelayMs: 250,
|
|
86
47
|
maxMsgRetryCount: 5,
|
|
87
|
-
fireInitQueries:
|
|
88
|
-
auth:
|
|
89
|
-
markOnlineOnConnect:
|
|
90
|
-
syncFullHistory:
|
|
91
|
-
patchMessageBeforeSending:
|
|
92
|
-
shouldSyncHistoryMessage: () =>
|
|
93
|
-
shouldIgnoreJid: () =>
|
|
48
|
+
fireInitQueries: true,
|
|
49
|
+
auth: undefined,
|
|
50
|
+
markOnlineOnConnect: true,
|
|
51
|
+
syncFullHistory: false,
|
|
52
|
+
patchMessageBeforeSending: msg => msg,
|
|
53
|
+
shouldSyncHistoryMessage: () => true,
|
|
54
|
+
shouldIgnoreJid: () => false,
|
|
94
55
|
linkPreviewImageThumbnailWidth: 192,
|
|
95
|
-
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs:
|
|
96
|
-
generateHighQualityLinkPreview:
|
|
56
|
+
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
57
|
+
generateHighQualityLinkPreview: false,
|
|
58
|
+
enableAutoSessionRecreation: true,
|
|
59
|
+
enableRecentMessageCache: true,
|
|
97
60
|
options: {},
|
|
98
|
-
appStateMacVerification: {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
61
|
+
appStateMacVerification: {
|
|
62
|
+
patch: false,
|
|
63
|
+
snapshot: false
|
|
64
|
+
},
|
|
65
|
+
countryCode: 'US',
|
|
66
|
+
getMessage: async () => undefined,
|
|
67
|
+
cachedGroupMetadata: async () => undefined,
|
|
102
68
|
makeSignalRepository: libsignal_1.makeLibSignalRepository
|
|
103
69
|
};
|
|
104
|
-
|
|
105
70
|
exports.MEDIA_PATH_MAP = {
|
|
106
|
-
image:
|
|
107
|
-
video:
|
|
108
|
-
document:
|
|
109
|
-
audio:
|
|
110
|
-
sticker:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
71
|
+
image: '/mms/image',
|
|
72
|
+
video: '/mms/video',
|
|
73
|
+
document: '/mms/document',
|
|
74
|
+
audio: '/mms/audio',
|
|
75
|
+
sticker: '/mms/image',
|
|
76
|
+
'thumbnail-link': '/mms/image',
|
|
77
|
+
'product-catalog-image': '/product/image',
|
|
78
|
+
'md-app-state': '',
|
|
79
|
+
'md-msg-hist': '/mms/md-app-state',
|
|
80
|
+
'biz-cover-photo': '/pps/biz-cover-photo'
|
|
115
81
|
};
|
|
116
|
-
|
|
117
82
|
exports.MEDIA_HKDF_KEY_MAPPING = {
|
|
118
|
-
audio:
|
|
119
|
-
document:
|
|
120
|
-
gif:
|
|
121
|
-
image:
|
|
122
|
-
ppic:
|
|
123
|
-
product:
|
|
124
|
-
ptt:
|
|
125
|
-
sticker:
|
|
126
|
-
video:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
ptv:
|
|
83
|
+
audio: 'Audio',
|
|
84
|
+
document: 'Document',
|
|
85
|
+
gif: 'Video',
|
|
86
|
+
image: 'Image',
|
|
87
|
+
ppic: '',
|
|
88
|
+
product: 'Image',
|
|
89
|
+
ptt: 'Audio',
|
|
90
|
+
sticker: 'Image',
|
|
91
|
+
video: 'Video',
|
|
92
|
+
'thumbnail-document': 'Document Thumbnail',
|
|
93
|
+
'thumbnail-image': 'Image Thumbnail',
|
|
94
|
+
'thumbnail-video': 'Video Thumbnail',
|
|
95
|
+
'thumbnail-link': 'Link Thumbnail',
|
|
96
|
+
'md-msg-hist': 'History',
|
|
97
|
+
'md-app-state': 'App State',
|
|
98
|
+
'product-catalog-image': '',
|
|
99
|
+
'payment-bg-image': 'Payment Background',
|
|
100
|
+
ptv: 'Video',
|
|
101
|
+
'biz-cover-photo': 'Image'
|
|
136
102
|
};
|
|
137
|
-
|
|
138
103
|
exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
|
|
139
104
|
exports.MIN_PREKEY_COUNT = 5;
|
|
140
105
|
exports.INITIAL_PREKEY_COUNT = 30;
|
|
141
|
-
|
|
106
|
+
exports.UPLOAD_TIMEOUT = 30000; // 30 seconds
|
|
107
|
+
exports.MIN_UPLOAD_INTERVAL = 5000; // 5 seconds minimum between uploads
|
|
142
108
|
exports.DEFAULT_CACHE_TTLS = {
|
|
143
|
-
SIGNAL_STORE:
|
|
144
|
-
MSG_RETRY:
|
|
145
|
-
CALL_OFFER:
|
|
146
|
-
USER_DEVICES:
|
|
109
|
+
SIGNAL_STORE: 5 * 60, // 5 minutes
|
|
110
|
+
MSG_RETRY: 60 * 60, // 1 hour
|
|
111
|
+
CALL_OFFER: 5 * 60, // 5 minutes
|
|
112
|
+
USER_DEVICES: 5 * 60 // 5 minutes
|
|
147
113
|
};
|
|
@@ -8,7 +8,6 @@ export declare class GroupCipher {
|
|
|
8
8
|
private readonly senderKeyStore;
|
|
9
9
|
private readonly senderKeyName;
|
|
10
10
|
constructor(senderKeyStore: SenderKeyStore, senderKeyName: SenderKeyName);
|
|
11
|
-
private queueJob;
|
|
12
11
|
encrypt(paddedPlaintext: Uint8Array | string): Promise<Uint8Array>;
|
|
13
12
|
decrypt(senderKeyMessageBytes: Uint8Array): Promise<Uint8Array>;
|
|
14
13
|
private getSenderKey;
|
|
@@ -1,55 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.GroupCipher = void 0;
|
|
7
4
|
const crypto_1 = require("libsignal/src/crypto");
|
|
8
|
-
const queue_job_1 = __importDefault(require("./queue-job"));
|
|
9
5
|
const sender_key_message_1 = require("./sender-key-message");
|
|
10
6
|
class GroupCipher {
|
|
11
7
|
constructor(senderKeyStore, senderKeyName) {
|
|
12
8
|
this.senderKeyStore = senderKeyStore;
|
|
13
9
|
this.senderKeyName = senderKeyName;
|
|
14
10
|
}
|
|
15
|
-
queueJob(awaitable) {
|
|
16
|
-
return (0, queue_job_1.default)(this.senderKeyName.toString(), awaitable);
|
|
17
|
-
}
|
|
18
11
|
async encrypt(paddedPlaintext) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return senderKeyMessage.serialize();
|
|
34
|
-
});
|
|
12
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
|
|
13
|
+
if (!record) {
|
|
14
|
+
throw new Error('No SenderKeyRecord found for encryption');
|
|
15
|
+
}
|
|
16
|
+
const senderKeyState = record.getSenderKeyState();
|
|
17
|
+
if (!senderKeyState) {
|
|
18
|
+
throw new Error('No session to encrypt message');
|
|
19
|
+
}
|
|
20
|
+
const iteration = senderKeyState.getSenderChainKey().getIteration();
|
|
21
|
+
const senderKey = this.getSenderKey(senderKeyState, iteration === 0 ? 0 : iteration + 1);
|
|
22
|
+
const ciphertext = await this.getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext);
|
|
23
|
+
const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(senderKeyState.getKeyId(), senderKey.getIteration(), ciphertext, senderKeyState.getSigningKeyPrivate());
|
|
24
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
|
|
25
|
+
return senderKeyMessage.serialize();
|
|
35
26
|
}
|
|
36
27
|
async decrypt(senderKeyMessageBytes) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return plaintext;
|
|
52
|
-
});
|
|
28
|
+
const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
|
|
29
|
+
if (!record) {
|
|
30
|
+
throw new Error('No SenderKeyRecord found for decryption');
|
|
31
|
+
}
|
|
32
|
+
const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(null, null, null, null, senderKeyMessageBytes);
|
|
33
|
+
const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId());
|
|
34
|
+
if (!senderKeyState) {
|
|
35
|
+
throw new Error('No session found to decrypt message');
|
|
36
|
+
}
|
|
37
|
+
senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic());
|
|
38
|
+
const senderKey = this.getSenderKey(senderKeyState, senderKeyMessage.getIteration());
|
|
39
|
+
const plaintext = await this.getPlainText(senderKey.getIv(), senderKey.getCipherKey(), senderKeyMessage.getCipherText());
|
|
40
|
+
await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
|
|
41
|
+
return plaintext;
|
|
53
42
|
}
|
|
54
43
|
getSenderKey(senderKeyState, iteration) {
|
|
55
44
|
let senderChainKey = senderKeyState.getSenderChainKey();
|
|
@@ -4,7 +4,7 @@ export declare class SenderChainKey {
|
|
|
4
4
|
private readonly CHAIN_KEY_SEED;
|
|
5
5
|
private readonly iteration;
|
|
6
6
|
private readonly chainKey;
|
|
7
|
-
constructor(iteration: number, chainKey:
|
|
7
|
+
constructor(iteration: number, chainKey: Uint8Array | Buffer);
|
|
8
8
|
getIteration(): number;
|
|
9
9
|
getSenderMessageKey(): SenderMessageKey;
|
|
10
10
|
getNext(): SenderChainKey;
|
|
@@ -8,11 +8,18 @@ class SenderChainKey {
|
|
|
8
8
|
this.MESSAGE_KEY_SEED = Buffer.from([0x01]);
|
|
9
9
|
this.CHAIN_KEY_SEED = Buffer.from([0x02]);
|
|
10
10
|
this.iteration = iteration;
|
|
11
|
-
if (chainKey
|
|
11
|
+
if (Buffer.isBuffer(chainKey)) {
|
|
12
12
|
this.chainKey = chainKey;
|
|
13
13
|
}
|
|
14
|
+
else if (chainKey instanceof Uint8Array) {
|
|
15
|
+
this.chainKey = Buffer.from(chainKey);
|
|
16
|
+
}
|
|
17
|
+
else if (chainKey && typeof chainKey === 'object') {
|
|
18
|
+
// backported from @MartinSchere (#1741)
|
|
19
|
+
this.chainKey = Buffer.from(Object.values(chainKey)); // temp fix // backported from @MartinSchere (#1741)
|
|
20
|
+
}
|
|
14
21
|
else {
|
|
15
|
-
this.chainKey = Buffer.
|
|
22
|
+
this.chainKey = Buffer.alloc(0);
|
|
16
23
|
}
|
|
17
24
|
}
|
|
18
25
|
getIteration() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SenderKeyDistributionMessage = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_js_1 = require("../../../WAProto/index.js");
|
|
5
5
|
const ciphertext_message_1 = require("./ciphertext-message");
|
|
6
6
|
class SenderKeyDistributionMessage extends ciphertext_message_1.CiphertextMessage {
|
|
7
7
|
constructor(id, iteration, chainKey, signatureKey, serialized) {
|
|
@@ -9,7 +9,7 @@ class SenderKeyDistributionMessage extends ciphertext_message_1.CiphertextMessag
|
|
|
9
9
|
if (serialized) {
|
|
10
10
|
try {
|
|
11
11
|
const message = serialized.slice(1);
|
|
12
|
-
const distributionMessage =
|
|
12
|
+
const distributionMessage = index_js_1.proto.SenderKeyDistributionMessage.decode(message);
|
|
13
13
|
this.serialized = serialized;
|
|
14
14
|
this.id = distributionMessage.id;
|
|
15
15
|
this.iteration = distributionMessage.iteration;
|
|
@@ -32,7 +32,7 @@ class SenderKeyDistributionMessage extends ciphertext_message_1.CiphertextMessag
|
|
|
32
32
|
this.iteration = iteration;
|
|
33
33
|
this.chainKey = chainKey;
|
|
34
34
|
this.signatureKey = signatureKey;
|
|
35
|
-
const message =
|
|
35
|
+
const message = index_js_1.proto.SenderKeyDistributionMessage.encode(index_js_1.proto.SenderKeyDistributionMessage.create({
|
|
36
36
|
id,
|
|
37
37
|
iteration,
|
|
38
38
|
chainKey,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SenderKeyMessage = void 0;
|
|
4
4
|
const curve_1 = require("libsignal/src/curve");
|
|
5
|
-
const
|
|
5
|
+
const index_js_1 = require("../../../WAProto/index.js");
|
|
6
6
|
const ciphertext_message_1 = require("./ciphertext-message");
|
|
7
7
|
class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
|
|
8
8
|
constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
|
|
@@ -12,7 +12,7 @@ class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
|
|
|
12
12
|
const version = serialized[0];
|
|
13
13
|
const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
|
|
14
14
|
const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
|
|
15
|
-
const senderKeyMessage =
|
|
15
|
+
const senderKeyMessage = index_js_1.proto.SenderKeyMessage.decode(message);
|
|
16
16
|
this.serialized = serialized;
|
|
17
17
|
this.messageVersion = (version & 0xff) >> 4;
|
|
18
18
|
this.keyId = senderKeyMessage.id;
|
|
@@ -26,7 +26,7 @@ class SenderKeyMessage extends ciphertext_message_1.CiphertextMessage {
|
|
|
26
26
|
else {
|
|
27
27
|
const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256;
|
|
28
28
|
const ciphertextBuffer = Buffer.from(ciphertext);
|
|
29
|
-
const message =
|
|
29
|
+
const message = index_js_1.proto.SenderKeyMessage.encode(index_js_1.proto.SenderKeyMessage.create({
|
|
30
30
|
id: keyId,
|
|
31
31
|
iteration: iteration,
|
|
32
32
|
ciphertext: ciphertextBuffer
|
|
@@ -21,10 +21,10 @@ interface SenderKeyStateStructure {
|
|
|
21
21
|
export declare class SenderKeyState {
|
|
22
22
|
private readonly MAX_MESSAGE_KEYS;
|
|
23
23
|
private readonly senderKeyStateStructure;
|
|
24
|
-
constructor(id?: number | null, iteration?: number | null, chainKey?: Uint8Array | null, signatureKeyPair?: {
|
|
25
|
-
public: Uint8Array;
|
|
26
|
-
private: Uint8Array;
|
|
27
|
-
} | null, signatureKeyPublic?: Uint8Array | null, signatureKeyPrivate?: Uint8Array | null, senderKeyStateStructure?: SenderKeyStateStructure | null);
|
|
24
|
+
constructor(id?: number | null, iteration?: number | null, chainKey?: Uint8Array | null | string, signatureKeyPair?: {
|
|
25
|
+
public: Uint8Array | string;
|
|
26
|
+
private: Uint8Array | string;
|
|
27
|
+
} | null, signatureKeyPublic?: Uint8Array | string | null, signatureKeyPrivate?: Uint8Array | string | null, senderKeyStateStructure?: SenderKeyStateStructure | null);
|
|
28
28
|
getKeyId(): number;
|
|
29
29
|
getSenderChainKey(): SenderChainKey;
|
|
30
30
|
setSenderChainKey(chainKey: SenderChainKey): void;
|
|
@@ -6,8 +6,22 @@ const sender_message_key_1 = require("./sender-message-key");
|
|
|
6
6
|
class SenderKeyState {
|
|
7
7
|
constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
|
|
8
8
|
this.MAX_MESSAGE_KEYS = 2000;
|
|
9
|
+
const toBuffer = (val) => {
|
|
10
|
+
if (!val)
|
|
11
|
+
return Buffer.alloc(0);
|
|
12
|
+
if (typeof val === 'string')
|
|
13
|
+
return Buffer.from(val, 'base64');
|
|
14
|
+
if (val instanceof Uint8Array || Array.isArray(val))
|
|
15
|
+
return Buffer.from(val);
|
|
16
|
+
return Buffer.alloc(0);
|
|
17
|
+
};
|
|
9
18
|
if (senderKeyStateStructure) {
|
|
10
|
-
this.senderKeyStateStructure =
|
|
19
|
+
this.senderKeyStateStructure = {
|
|
20
|
+
...senderKeyStateStructure,
|
|
21
|
+
senderMessageKeys: Array.isArray(senderKeyStateStructure.senderMessageKeys)
|
|
22
|
+
? senderKeyStateStructure.senderMessageKeys
|
|
23
|
+
: []
|
|
24
|
+
};
|
|
11
25
|
}
|
|
12
26
|
else {
|
|
13
27
|
if (signatureKeyPair) {
|
|
@@ -17,17 +31,12 @@ class SenderKeyState {
|
|
|
17
31
|
chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey;
|
|
18
32
|
const senderChainKeyStructure = {
|
|
19
33
|
iteration: iteration || 0,
|
|
20
|
-
seed: chainKey
|
|
34
|
+
seed: chainKey ? toBuffer(chainKey) : Buffer.alloc(0)
|
|
21
35
|
};
|
|
22
36
|
const signingKeyStructure = {
|
|
23
|
-
public:
|
|
24
|
-
|
|
25
|
-
: signatureKeyPublic || Buffer.alloc(0)
|
|
37
|
+
public: toBuffer(signatureKeyPublic),
|
|
38
|
+
private: signatureKeyPrivate ? toBuffer(signatureKeyPrivate) : undefined
|
|
26
39
|
};
|
|
27
|
-
if (signatureKeyPrivate) {
|
|
28
|
-
signingKeyStructure.private =
|
|
29
|
-
typeof signatureKeyPrivate === 'string' ? Buffer.from(signatureKeyPrivate, 'base64') : signatureKeyPrivate;
|
|
30
|
-
}
|
|
31
40
|
this.senderKeyStateStructure = {
|
|
32
41
|
senderKeyId: id || 0,
|
|
33
42
|
senderChainKey: senderChainKeyStructure,
|
|
@@ -49,23 +58,45 @@ class SenderKeyState {
|
|
|
49
58
|
};
|
|
50
59
|
}
|
|
51
60
|
getSigningKeyPublic() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
let key = this.senderKeyStateStructure.senderSigningKey.public;
|
|
62
|
+
// normalize into Buffer
|
|
63
|
+
if (!Buffer.isBuffer(key)) {
|
|
64
|
+
if (key instanceof Uint8Array) {
|
|
65
|
+
key = Buffer.from(key);
|
|
66
|
+
}
|
|
67
|
+
else if (typeof key === 'string') {
|
|
68
|
+
key = Buffer.from(key, 'base64');
|
|
69
|
+
}
|
|
70
|
+
else if (key && typeof key === 'object') {
|
|
71
|
+
return Buffer.from(Object.values(key)); // temp fix // inspired by @MartinSchere 's #1741
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
key = Buffer.from(key || []);
|
|
75
|
+
}
|
|
55
76
|
}
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
const publicKey = key;
|
|
78
|
+
if (publicKey.length === 32) {
|
|
79
|
+
const fixed = Buffer.alloc(33);
|
|
80
|
+
fixed[0] = 0x05;
|
|
81
|
+
publicKey.copy(fixed, 1);
|
|
82
|
+
return fixed;
|
|
58
83
|
}
|
|
59
|
-
return
|
|
84
|
+
return publicKey;
|
|
60
85
|
}
|
|
61
86
|
getSigningKeyPrivate() {
|
|
62
87
|
const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
|
|
63
88
|
if (!privateKey) {
|
|
64
89
|
return undefined;
|
|
65
90
|
}
|
|
66
|
-
if (privateKey
|
|
91
|
+
if (Buffer.isBuffer(privateKey)) {
|
|
67
92
|
return privateKey;
|
|
68
93
|
}
|
|
94
|
+
else if (privateKey instanceof Uint8Array) {
|
|
95
|
+
return Buffer.from(privateKey);
|
|
96
|
+
}
|
|
97
|
+
else if (privateKey && typeof privateKey === 'object') {
|
|
98
|
+
return Buffer.from(Object.values(privateKey)); // temp fix // inspired by @MartinSchere 's #1741
|
|
99
|
+
}
|
|
69
100
|
else if (typeof privateKey === 'string') {
|
|
70
101
|
return Buffer.from(privateKey, 'base64');
|
|
71
102
|
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import { SignalAuthState } from '../Types';
|
|
2
|
-
import {
|
|
3
|
-
export declare function makeLibSignalRepository(auth: SignalAuthState
|
|
1
|
+
import type { SignalAuthState } from '../Types';
|
|
2
|
+
import type { SignalRepositoryWithLIDStore } from '../Types/Signal';
|
|
3
|
+
export declare function makeLibSignalRepository(auth: SignalAuthState, onWhatsAppFunc?: (...jids: string[]) => Promise<{
|
|
4
|
+
jid: string;
|
|
5
|
+
exists: boolean;
|
|
6
|
+
lid: string;
|
|
7
|
+
}[] | undefined>): SignalRepositoryWithLIDStore;
|