amiudmodz 4.0.0

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.
Files changed (100) hide show
  1. package/WAProto/index.js +169661 -0
  2. package/engine-requirements.js +10 -0
  3. package/lib/Defaults/baileys-version.json +3 -0
  4. package/lib/Defaults/index.js +156 -0
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/ciphertext-message.js +15 -0
  7. package/lib/Signal/Group/group-session-builder.js +64 -0
  8. package/lib/Signal/Group/group_cipher.js +96 -0
  9. package/lib/Signal/Group/index.js +57 -0
  10. package/lib/Signal/Group/keyhelper.js +55 -0
  11. package/lib/Signal/Group/queue-job.js +57 -0
  12. package/lib/Signal/Group/sender-chain-key.js +34 -0
  13. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  14. package/lib/Signal/Group/sender-key-message.js +69 -0
  15. package/lib/Signal/Group/sender-key-name.js +51 -0
  16. package/lib/Signal/Group/sender-key-record.js +53 -0
  17. package/lib/Signal/Group/sender-key-state.js +99 -0
  18. package/lib/Signal/Group/sender-message-key.js +29 -0
  19. package/lib/Signal/libsignal.js +177 -0
  20. package/lib/Signal/lid-mapping.js +185 -0
  21. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  22. package/lib/Socket/Client/index.js +19 -0
  23. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  24. package/lib/Socket/Client/web-socket-client.js +66 -0
  25. package/lib/Socket/business.js +260 -0
  26. package/lib/Socket/chats.js +1066 -0
  27. package/lib/Socket/groupStatus.js +637 -0
  28. package/lib/Socket/groups.js +317 -0
  29. package/lib/Socket/index.js +11 -0
  30. package/lib/Socket/messages-recv.js +1112 -0
  31. package/lib/Socket/messages-send.js +807 -0
  32. package/lib/Socket/newsletter.js +73 -0
  33. package/lib/Socket/registration.js +166 -0
  34. package/lib/Socket/socket.js +729 -0
  35. package/lib/Socket/usync.js +70 -0
  36. package/lib/Store/index.js +10 -0
  37. package/lib/Store/make-cache-manager-store.js +83 -0
  38. package/lib/Store/make-in-memory-store.js +427 -0
  39. package/lib/Store/make-ordered-dictionary.js +81 -0
  40. package/lib/Store/object-repository.js +27 -0
  41. package/lib/Types/Auth.js +2 -0
  42. package/lib/Types/Call.js +2 -0
  43. package/lib/Types/Chat.js +4 -0
  44. package/lib/Types/Contact.js +2 -0
  45. package/lib/Types/Events.js +2 -0
  46. package/lib/Types/GroupMetadata.js +2 -0
  47. package/lib/Types/Label.js +27 -0
  48. package/lib/Types/LabelAssociation.js +9 -0
  49. package/lib/Types/Message.js +9 -0
  50. package/lib/Types/Newsletter.js +38 -0
  51. package/lib/Types/Product.js +2 -0
  52. package/lib/Types/Signal.js +2 -0
  53. package/lib/Types/Socket.js +2 -0
  54. package/lib/Types/State.js +2 -0
  55. package/lib/Types/USync.js +2 -0
  56. package/lib/Types/index.js +42 -0
  57. package/lib/Utils/auth-utils.js +206 -0
  58. package/lib/Utils/baileys-event-stream.js +63 -0
  59. package/lib/Utils/business.js +234 -0
  60. package/lib/Utils/chat-utils.js +729 -0
  61. package/lib/Utils/crypto.js +151 -0
  62. package/lib/Utils/decode-wa-message.js +198 -0
  63. package/lib/Utils/event-buffer.js +525 -0
  64. package/lib/Utils/generics.js +502 -0
  65. package/lib/Utils/history.js +96 -0
  66. package/lib/Utils/index.js +33 -0
  67. package/lib/Utils/link-preview.js +93 -0
  68. package/lib/Utils/logger.js +7 -0
  69. package/lib/Utils/lt-hash.js +51 -0
  70. package/lib/Utils/make-mutex.js +43 -0
  71. package/lib/Utils/messages-media.js +814 -0
  72. package/lib/Utils/messages.js +819 -0
  73. package/lib/Utils/noise-handler.js +155 -0
  74. package/lib/Utils/process-message.js +321 -0
  75. package/lib/Utils/signal.js +153 -0
  76. package/lib/Utils/use-multi-file-auth-state.js +126 -0
  77. package/lib/Utils/validate-connection.js +222 -0
  78. package/lib/WABinary/constants.js +1304 -0
  79. package/lib/WABinary/decode.js +283 -0
  80. package/lib/WABinary/encode.js +263 -0
  81. package/lib/WABinary/generic-utils.js +198 -0
  82. package/lib/WABinary/index.js +21 -0
  83. package/lib/WABinary/jid-utils.js +62 -0
  84. package/lib/WABinary/types.js +2 -0
  85. package/lib/WAM/BinaryInfo.js +13 -0
  86. package/lib/WAM/constants.js +15350 -0
  87. package/lib/WAM/encode.js +155 -0
  88. package/lib/WAM/index.js +19 -0
  89. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  90. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  91. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  92. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  93. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  94. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  95. package/lib/WAUSync/Protocols/index.js +20 -0
  96. package/lib/WAUSync/USyncQuery.js +89 -0
  97. package/lib/WAUSync/USyncUser.js +26 -0
  98. package/lib/WAUSync/index.js +19 -0
  99. package/lib/index.js +39 -0
  100. package/package.json +93 -0
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMultiFileAuthState = void 0;
4
+ const async_mutex_1 = require("async-mutex");
5
+ const promises_1 = require("fs/promises");
6
+ const path_1 = require("path");
7
+ const WAProto_1 = require("../../WAProto");
8
+ const auth_utils_1 = require("./auth-utils");
9
+ const generics_1 = require("./generics");
10
+ const useMultiFileAuthState = async (folder) => {
11
+ const fileLocks = new Map();
12
+ const getFileLock = (path) => {
13
+ let mutex = fileLocks.get(path);
14
+ if (!mutex) {
15
+ mutex = new async_mutex_1.Mutex();
16
+ fileLocks.set(path, mutex);
17
+ }
18
+ return mutex;
19
+ };
20
+ const writeData = async (data, file) => {
21
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
22
+ const tempPath = filePath + '.tmp';
23
+ const mutex = getFileLock(filePath);
24
+ return mutex.acquire().then(async (release) => {
25
+ try {
26
+ await (0, promises_1.writeFile)(tempPath, JSON.stringify(data, generics_1.BufferJSON.replacer));
27
+ await (0, promises_1.rename)(tempPath, filePath);
28
+ }
29
+ catch (error) {
30
+
31
+ await (0, promises_1.unlink)(tempPath).catch(() => { });
32
+ throw error;
33
+ }
34
+ finally {
35
+ release();
36
+ }
37
+ });
38
+ };
39
+ const readData = async (file) => {
40
+ try {
41
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
42
+ const mutex = getFileLock(filePath);
43
+ return await mutex.acquire().then(async (release) => {
44
+ try {
45
+ const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
46
+ return JSON.parse(data, generics_1.BufferJSON.reviver);
47
+ }
48
+ finally {
49
+ release();
50
+ }
51
+ });
52
+ }
53
+ catch (error) {
54
+ if (error.code === 'ENOENT') {
55
+ return null;
56
+ }
57
+
58
+
59
+
60
+
61
+ return null;
62
+ }
63
+ };
64
+ const removeData = async (file) => {
65
+ try {
66
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
67
+ const mutex = getFileLock(filePath);
68
+ return mutex.acquire().then(async (release) => {
69
+ try {
70
+ await (0, promises_1.unlink)(filePath);
71
+ }
72
+ catch (_a) {
73
+ }
74
+ finally {
75
+ release();
76
+ }
77
+ });
78
+ }
79
+ catch (_a) {
80
+ }
81
+ };
82
+ const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
83
+ if (folderInfo) {
84
+ if (!folderInfo.isDirectory()) {
85
+ throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
86
+ }
87
+ }
88
+ else {
89
+ await (0, promises_1.mkdir)(folder, { recursive: true });
90
+ }
91
+ const fixFileName = (file) => { var _a; return (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '__')) === null || _a === void 0 ? void 0 : _a.replace(/:/g, '-'); };
92
+ const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
93
+ return {
94
+ state: {
95
+ creds,
96
+ keys: {
97
+ get: async (type, ids) => {
98
+ const data = {};
99
+ await Promise.all(ids.map(async (id) => {
100
+ let value = await readData(`${type}-${id}.json`);
101
+ if (type === 'app-state-sync-key' && value) {
102
+ value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
103
+ }
104
+ data[id] = value;
105
+ }));
106
+ return data;
107
+ },
108
+ set: async (data) => {
109
+ const tasks = [];
110
+ for (const category in data) {
111
+ for (const id in data[category]) {
112
+ const value = data[category][id];
113
+ const file = `${category}-${id}.json`;
114
+ tasks.push(value ? writeData(value, file) : removeData(file));
115
+ }
116
+ }
117
+ await Promise.all(tasks);
118
+ }
119
+ }
120
+ },
121
+ saveCreds: async () => {
122
+ return writeData(creds, 'creds.json');
123
+ }
124
+ };
125
+ };
126
+ exports.useMultiFileAuthState = useMultiFileAuthState;
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
4
+ const boom_1 = require("@hapi/boom");
5
+ const crypto_1 = require("crypto");
6
+ const WAProto_1 = require("../../WAProto");
7
+ const Defaults_1 = require("../Defaults");
8
+ const WABinary_1 = require("../WABinary");
9
+ const crypto_2 = require("./crypto");
10
+ const generics_1 = require("./generics");
11
+ const signal_1 = require("./signal");
12
+
13
+ const getUserAgent = (config) => {
14
+ return {
15
+ appVersion: {
16
+ primary: config.version[0],
17
+ secondary: config.version[1],
18
+ tertiary: config.version[2],
19
+ },
20
+ platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
21
+ releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
22
+ osVersion: '10.0.22631',
23
+ device: 'Desktop',
24
+ osBuildNumber: '10.0.22631',
25
+ localeLanguageIso6391: 'en',
26
+ localeCountryIso31661Alpha2: config.countryCode || 'US'
27
+ };
28
+ };
29
+
30
+ const PLATFORM_MAP = {
31
+ 'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
32
+ 'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
33
+ };
34
+
35
+ const getWebInfo = (config) => {
36
+ let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
37
+ if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
38
+ webSubPlatform = PLATFORM_MAP[config.browser[0]];
39
+ }
40
+ return { webSubPlatform };
41
+ };
42
+
43
+ const getClientPayload = (config) => {
44
+ const payload = {
45
+ connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
46
+ connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
47
+ userAgent: getUserAgent(config),
48
+ };
49
+ payload.webInfo = getWebInfo(config);
50
+ return payload;
51
+ };
52
+
53
+ const generateLoginNode = (userJid, config) => {
54
+ const { user, device } = (0, WABinary_1.jidDecode)(userJid);
55
+ const payload = {
56
+ ...getClientPayload(config),
57
+ passive: true,
58
+ pull: true,
59
+ username: +user,
60
+ device: device,
61
+ lidDbMigrated: false
62
+ };
63
+ return WAProto_1.proto.ClientPayload.fromObject(payload);
64
+ };
65
+ exports.generateLoginNode = generateLoginNode;
66
+
67
+ const getPlatformType = (platform) => {
68
+ const platformType = platform.toUpperCase();
69
+ return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.CHROME;
70
+ };
71
+
72
+ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
73
+ const appVersionBuf = (0, crypto_1.createHash)('md5')
74
+ .update(config.version.join('.'))
75
+ .digest();
76
+
77
+ const companion = {
78
+ os: config.browser[0],
79
+ platformType: getPlatformType(config.browser[1]),
80
+ requireFullSync: config.syncFullHistory,
81
+ historySyncConfig: {
82
+ storageQuotaMb: 10240,
83
+ inlineInitialPayloadInE2EeMsg: false,
84
+ supportBotUserAgentChatHistory: false,
85
+ supportCagReactionsAndPolls: true,
86
+ supportBizHostedMsg: true,
87
+ supportRecentSyncChunkMessageCountTuning: true,
88
+ supportHostedGroupMsg: true,
89
+ supportFbidBotChatHistory: false,
90
+ supportMessageAssociation: true,
91
+ supportGroupHistory: true,
92
+ },
93
+ version: {
94
+ primary: config.version[0],
95
+ secondary: config.version[1],
96
+ tertiary: config.version[2]
97
+ }
98
+ };
99
+
100
+ const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
101
+
102
+ const registerPayload = {
103
+ ...getClientPayload(config),
104
+ passive: false,
105
+ pull: false,
106
+ devicePairingData: {
107
+ buildHash: appVersionBuf,
108
+ deviceProps: companionProto,
109
+ eRegid: (0, generics_1.encodeBigEndian)(registrationId),
110
+ eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
111
+ eIdent: signedIdentityKey.public,
112
+ eSkeyId: (0, generics_1.encodeBigEndian)(signedPreKey.keyId, 3),
113
+ eSkeyVal: signedPreKey.keyPair.public,
114
+ eSkeySig: signedPreKey.signature,
115
+ },
116
+ };
117
+ return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
118
+ };
119
+ exports.generateRegistrationNode = generateRegistrationNode;
120
+
121
+ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
122
+ const msgId = stanza.attrs.id;
123
+ const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
124
+ const deviceIdentityNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device-identity');
125
+ const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
126
+ const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
127
+ const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
128
+
129
+ if (!deviceIdentityNode || !deviceNode) {
130
+ throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
131
+ }
132
+
133
+ const bizName = businessNode?.attrs.name;
134
+ const jid = deviceNode.attrs.jid;
135
+ const lid = deviceNode.attrs.lid;
136
+
137
+ const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
138
+
139
+ let hmacPrefix = Buffer.from([]);
140
+ if (accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED) {
141
+ hmacPrefix = Buffer.from([0x06, 0x05]);
142
+ }
143
+
144
+ const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
145
+ if (Buffer.compare(hmac, advSign) !== 0) {
146
+ throw new boom_1.Boom('Invalid account signature');
147
+ }
148
+
149
+ const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
150
+ const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
151
+
152
+ const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(deviceDetails);
153
+
154
+ const accountSignaturePrefix = deviceIdentity.deviceType === WAProto_1.proto.ADVEncryptionType.HOSTED
155
+ ? Buffer.from([0x06, 0x05])
156
+ : Buffer.from([0x06, 0x00]);
157
+ const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
158
+
159
+ if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
160
+ throw new boom_1.Boom('Failed to verify account signature');
161
+ }
162
+
163
+ const deviceMsg = Buffer.concat([
164
+ Buffer.from([0x06, 0x01]),
165
+ deviceDetails,
166
+ signedIdentityKey.public,
167
+ accountSignatureKey
168
+ ]);
169
+ account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
170
+
171
+ const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey);
172
+ const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
173
+
174
+ const reply = {
175
+ tag: 'iq',
176
+ attrs: {
177
+ to: WABinary_1.S_WHATSAPP_NET,
178
+ type: 'result',
179
+ id: msgId,
180
+ },
181
+ content: [
182
+ {
183
+ tag: 'pair-device-sign',
184
+ attrs: {},
185
+ content: [
186
+ {
187
+ tag: 'device-identity',
188
+ attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
189
+ content: accountEnc
190
+ }
191
+ ]
192
+ }
193
+ ]
194
+ };
195
+
196
+ const authUpdate = {
197
+ account,
198
+ me: { id: jid, name: bizName, lid },
199
+ signalIdentities: [
200
+ ...(signalIdentities || []),
201
+ identity
202
+ ],
203
+ platform: platformNode?.attrs.name
204
+ };
205
+
206
+ return {
207
+ creds: authUpdate,
208
+ reply
209
+ };
210
+ };
211
+ exports.configureSuccessfulPairing = configureSuccessfulPairing;
212
+
213
+ const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
214
+ account = { ...account };
215
+ if (!includeSignatureKey || !account.accountSignatureKey?.length) {
216
+ account.accountSignatureKey = null;
217
+ }
218
+ return WAProto_1.proto.ADVSignedDeviceIdentity
219
+ .encode(account)
220
+ .finish();
221
+ };
222
+ exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;