@merajah/baileys 1.0.9 → 4.2.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.
Files changed (204) hide show
  1. package/lib/cache.js +1 -0
  2. package/lib/converter.js +1 -0
  3. package/lib/extra.js +1 -0
  4. package/lib/index.js +32 -22
  5. package/lib/serialize.js +1 -0
  6. package/lib/wrapper.js +1 -0
  7. package/package.json +21 -108
  8. package/readme.md +64 -42
  9. package/WAProto/index.js +0 -169661
  10. package/lib/Defaults/baileys-version.json +0 -3
  11. package/lib/Defaults/index.d.ts +0 -53
  12. package/lib/Defaults/index.js +0 -147
  13. package/lib/Defaults/phonenumber-mcc.json +0 -223
  14. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  15. package/lib/Signal/Group/ciphertext-message.js +0 -15
  16. package/lib/Signal/Group/group-session-builder.d.ts +0 -14
  17. package/lib/Signal/Group/group-session-builder.js +0 -64
  18. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  19. package/lib/Signal/Group/group_cipher.js +0 -96
  20. package/lib/Signal/Group/index.d.ts +0 -11
  21. package/lib/Signal/Group/index.js +0 -57
  22. package/lib/Signal/Group/keyhelper.d.ts +0 -10
  23. package/lib/Signal/Group/keyhelper.js +0 -55
  24. package/lib/Signal/Group/queue-job.d.ts +0 -1
  25. package/lib/Signal/Group/queue-job.js +0 -57
  26. package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
  27. package/lib/Signal/Group/sender-chain-key.js +0 -34
  28. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
  29. package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
  30. package/lib/Signal/Group/sender-key-message.d.ts +0 -18
  31. package/lib/Signal/Group/sender-key-message.js +0 -69
  32. package/lib/Signal/Group/sender-key-name.d.ts +0 -17
  33. package/lib/Signal/Group/sender-key-name.js +0 -51
  34. package/lib/Signal/Group/sender-key-record.d.ts +0 -30
  35. package/lib/Signal/Group/sender-key-record.js +0 -53
  36. package/lib/Signal/Group/sender-key-state.d.ts +0 -38
  37. package/lib/Signal/Group/sender-key-state.js +0 -99
  38. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  39. package/lib/Signal/Group/sender-message-key.js +0 -29
  40. package/lib/Signal/libsignal.d.ts +0 -3
  41. package/lib/Signal/libsignal.js +0 -174
  42. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
  43. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  44. package/lib/Socket/Client/index.d.ts +0 -3
  45. package/lib/Socket/Client/index.js +0 -19
  46. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  47. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  48. package/lib/Socket/Client/web-socket-client.d.ts +0 -12
  49. package/lib/Socket/Client/web-socket-client.js +0 -62
  50. package/lib/Socket/business.d.ts +0 -171
  51. package/lib/Socket/business.js +0 -260
  52. package/lib/Socket/chats.d.ts +0 -267
  53. package/lib/Socket/chats.js +0 -970
  54. package/lib/Socket/groups.d.ts +0 -115
  55. package/lib/Socket/groups.js +0 -317
  56. package/lib/Socket/index.d.ts +0 -173
  57. package/lib/Socket/index.js +0 -11
  58. package/lib/Socket/manager.d.ts +0 -253
  59. package/lib/Socket/manager.js +0 -480
  60. package/lib/Socket/messages-recv.d.ts +0 -161
  61. package/lib/Socket/messages-recv.js +0 -1110
  62. package/lib/Socket/messages-send.d.ts +0 -149
  63. package/lib/Socket/messages-send.js +0 -909
  64. package/lib/Socket/newsletter.js +0 -357
  65. package/lib/Socket/registration.d.ts +0 -267
  66. package/lib/Socket/registration.js +0 -166
  67. package/lib/Socket/socket.d.ts +0 -43
  68. package/lib/Socket/socket.js +0 -680
  69. package/lib/Socket/usync.d.ts +0 -36
  70. package/lib/Socket/usync.js +0 -70
  71. package/lib/Store/index.d.ts +0 -3
  72. package/lib/Store/index.js +0 -10
  73. package/lib/Store/make-cache-manager-store.d.ts +0 -13
  74. package/lib/Store/make-cache-manager-store.js +0 -83
  75. package/lib/Store/make-in-memory-store.d.ts +0 -118
  76. package/lib/Store/make-in-memory-store.js +0 -427
  77. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  78. package/lib/Store/make-ordered-dictionary.js +0 -81
  79. package/lib/Store/object-repository.d.ts +0 -10
  80. package/lib/Store/object-repository.js +0 -27
  81. package/lib/Types/Auth.d.ts +0 -110
  82. package/lib/Types/Auth.js +0 -2
  83. package/lib/Types/Call.d.ts +0 -13
  84. package/lib/Types/Call.js +0 -2
  85. package/lib/Types/Chat.d.ts +0 -102
  86. package/lib/Types/Chat.js +0 -4
  87. package/lib/Types/Contact.d.ts +0 -19
  88. package/lib/Types/Contact.js +0 -2
  89. package/lib/Types/Events.d.ts +0 -157
  90. package/lib/Types/Events.js +0 -2
  91. package/lib/Types/GroupMetadata.d.ts +0 -55
  92. package/lib/Types/GroupMetadata.js +0 -2
  93. package/lib/Types/Label.d.ts +0 -35
  94. package/lib/Types/Label.js +0 -27
  95. package/lib/Types/LabelAssociation.d.ts +0 -29
  96. package/lib/Types/LabelAssociation.js +0 -9
  97. package/lib/Types/Message.d.ts +0 -273
  98. package/lib/Types/Message.js +0 -9
  99. package/lib/Types/Newsletter.d.ts +0 -103
  100. package/lib/Types/Newsletter.js +0 -38
  101. package/lib/Types/Product.d.ts +0 -78
  102. package/lib/Types/Product.js +0 -2
  103. package/lib/Types/Signal.d.ts +0 -57
  104. package/lib/Types/Signal.js +0 -2
  105. package/lib/Types/Socket.d.ts +0 -111
  106. package/lib/Types/Socket.js +0 -2
  107. package/lib/Types/State.d.ts +0 -27
  108. package/lib/Types/State.js +0 -2
  109. package/lib/Types/USync.d.ts +0 -25
  110. package/lib/Types/USync.js +0 -2
  111. package/lib/Types/index.d.ts +0 -57
  112. package/lib/Types/index.js +0 -42
  113. package/lib/Utils/auth-utils.d.ts +0 -18
  114. package/lib/Utils/auth-utils.js +0 -206
  115. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  116. package/lib/Utils/baileys-event-stream.js +0 -63
  117. package/lib/Utils/business.d.ts +0 -22
  118. package/lib/Utils/business.js +0 -234
  119. package/lib/Utils/chat-utils.d.ts +0 -71
  120. package/lib/Utils/chat-utils.js +0 -729
  121. package/lib/Utils/crypto.d.ts +0 -41
  122. package/lib/Utils/crypto.js +0 -151
  123. package/lib/Utils/decode-wa-message.d.ts +0 -19
  124. package/lib/Utils/decode-wa-message.js +0 -198
  125. package/lib/Utils/event-buffer.d.ts +0 -35
  126. package/lib/Utils/event-buffer.js +0 -514
  127. package/lib/Utils/generics.d.ts +0 -92
  128. package/lib/Utils/generics.js +0 -428
  129. package/lib/Utils/history.d.ts +0 -15
  130. package/lib/Utils/history.js +0 -96
  131. package/lib/Utils/index.d.ts +0 -17
  132. package/lib/Utils/index.js +0 -33
  133. package/lib/Utils/link-preview.d.ts +0 -21
  134. package/lib/Utils/link-preview.js +0 -93
  135. package/lib/Utils/logger.d.ts +0 -4
  136. package/lib/Utils/logger.js +0 -7
  137. package/lib/Utils/lt-hash.d.ts +0 -12
  138. package/lib/Utils/lt-hash.js +0 -51
  139. package/lib/Utils/make-mutex.d.ts +0 -7
  140. package/lib/Utils/make-mutex.js +0 -43
  141. package/lib/Utils/messages-media.d.ts +0 -116
  142. package/lib/Utils/messages-media.js +0 -819
  143. package/lib/Utils/messages.d.ts +0 -77
  144. package/lib/Utils/messages.js +0 -816
  145. package/lib/Utils/noise-handler.d.ts +0 -21
  146. package/lib/Utils/noise-handler.js +0 -155
  147. package/lib/Utils/process-message.d.ts +0 -41
  148. package/lib/Utils/process-message.js +0 -321
  149. package/lib/Utils/signal.d.ts +0 -32
  150. package/lib/Utils/signal.js +0 -153
  151. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  152. package/lib/Utils/use-multi-file-auth-state.js +0 -119
  153. package/lib/Utils/validate-connection.d.ts +0 -11
  154. package/lib/Utils/validate-connection.js +0 -231
  155. package/lib/WABinary/constants.d.ts +0 -30
  156. package/lib/WABinary/constants.js +0 -40
  157. package/lib/WABinary/decode.d.ts +0 -7
  158. package/lib/WABinary/decode.js +0 -252
  159. package/lib/WABinary/encode.d.ts +0 -3
  160. package/lib/WABinary/encode.js +0 -265
  161. package/lib/WABinary/generic-utils.d.ts +0 -17
  162. package/lib/WABinary/generic-utils.js +0 -198
  163. package/lib/WABinary/index.d.ts +0 -5
  164. package/lib/WABinary/index.js +0 -21
  165. package/lib/WABinary/jid-utils.d.ts +0 -31
  166. package/lib/WABinary/jid-utils.js +0 -62
  167. package/lib/WABinary/types.d.ts +0 -18
  168. package/lib/WABinary/types.js +0 -2
  169. package/lib/WAM/BinaryInfo.d.ts +0 -17
  170. package/lib/WAM/BinaryInfo.js +0 -13
  171. package/lib/WAM/constants.d.ts +0 -38
  172. package/lib/WAM/constants.js +0 -15350
  173. package/lib/WAM/encode.d.ts +0 -3
  174. package/lib/WAM/encode.js +0 -155
  175. package/lib/WAM/index.d.ts +0 -3
  176. package/lib/WAM/index.js +0 -19
  177. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  178. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
  179. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  180. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
  181. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  182. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
  183. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  184. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
  185. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  186. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
  187. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  188. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
  189. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  190. package/lib/WAUSync/Protocols/index.js +0 -20
  191. package/lib/WAUSync/USyncQuery.d.ts +0 -28
  192. package/lib/WAUSync/USyncQuery.js +0 -89
  193. package/lib/WAUSync/USyncUser.d.ts +0 -12
  194. package/lib/WAUSync/USyncUser.js +0 -26
  195. package/lib/WAUSync/index.d.ts +0 -3
  196. package/lib/WAUSync/index.js +0 -19
  197. package/lib/baileys.d.ts +0 -68
  198. package/lib/baileys.js +0 -266
  199. package/lib/extra/loader.d.ts +0 -16
  200. package/lib/extra/loader.js +0 -37
  201. package/lib/extra/raw.d.ts +0 -43
  202. package/lib/extra/raw.js +0 -131
  203. package/lib/index.d.ts +0 -14
  204. package/require.js +0 -13
@@ -1,153 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids = exports.parseAndInjectE2ESessions = exports.xmppPreKey = exports.xmppSignedPreKey = exports.generateOrGetPreKeys = exports.getPreKeys = exports.createSignalIdentity = void 0;
4
- const Defaults_1 = require("../Defaults");
5
- const WABinary_1 = require("../WABinary");
6
- const crypto_1 = require("./crypto");
7
- const lodash_1 = require("lodash")
8
- const generics_1 = require("./generics");
9
- const createSignalIdentity = (wid, accountSignatureKey) => {
10
- return {
11
- identifier: { name: wid, deviceId: 0 },
12
- identifierKey: (0, crypto_1.generateSignalPubKey)(accountSignatureKey)
13
- };
14
- };
15
- exports.createSignalIdentity = createSignalIdentity;
16
- const getPreKeys = async ({ get }, min, limit) => {
17
- const idList = [];
18
- for (let id = min; id < limit; id++) {
19
- idList.push(id.toString());
20
- }
21
- return get('pre-key', idList);
22
- };
23
- exports.getPreKeys = getPreKeys;
24
- const generateOrGetPreKeys = (creds, range) => {
25
- const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
26
- const remaining = range - avaliable;
27
- const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
28
- const newPreKeys = {};
29
- if (remaining > 0) {
30
- for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
31
- newPreKeys[i] = crypto_1.Curve.generateKeyPair();
32
- }
33
- }
34
- return {
35
- newPreKeys,
36
- lastPreKeyId,
37
- preKeysRange: [creds.firstUnuploadedPreKeyId, range],
38
- };
39
- };
40
- exports.generateOrGetPreKeys = generateOrGetPreKeys;
41
- const xmppSignedPreKey = (key) => ({
42
- tag: 'skey',
43
- attrs: {},
44
- content: [
45
- { tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(key.keyId, 3) },
46
- { tag: 'value', attrs: {}, content: key.keyPair.public },
47
- { tag: 'signature', attrs: {}, content: key.signature }
48
- ]
49
- });
50
- exports.xmppSignedPreKey = xmppSignedPreKey;
51
- const xmppPreKey = (pair, id) => ({
52
- tag: 'key',
53
- attrs: {},
54
- content: [
55
- { tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(id, 3) },
56
- { tag: 'value', attrs: {}, content: pair.public }
57
- ]
58
- });
59
- exports.xmppPreKey = xmppPreKey;
60
- const parseAndInjectE2ESessions = async (node, repository) => {
61
- const extractKey = (key) => (key ? ({
62
- keyId: WABinary_1.getBinaryNodeChildUInt(key, 'id', 3),
63
- publicKey: crypto_1.generateSignalPubKey(WABinary_1.getBinaryNodeChildBuffer(key, 'value')),
64
- signature: WABinary_1.getBinaryNodeChildBuffer(key, 'signature')
65
- }) : undefined)
66
- const nodes = WABinary_1.getBinaryNodeChildren(WABinary_1.getBinaryNodeChild(node, 'list'), 'user')
67
- for (const node of nodes) {
68
- WABinary_1.assertNodeErrorFree(node)
69
- }
70
- // Most of the work in repository.injectE2ESession is CPU intensive, not IO
71
- // So Promise.all doesn't really help here,
72
- // but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
73
- // This way we chunk it in smaller parts and between those parts we can yield to the event loop
74
- // It's rare case when you need to E2E sessions for so many users, but it's possible
75
- const chunkSize = 100
76
- const chunks = lodash_1.chunk(nodes, chunkSize)
77
- for (const nodesChunk of chunks) {
78
- await Promise.all(nodesChunk.map(async (node) => {
79
- const signedKey = WABinary_1.getBinaryNodeChild(node, 'skey')
80
- const key = WABinary_1.getBinaryNodeChild(node, 'key')
81
- const identity = WABinary_1.getBinaryNodeChildBuffer(node, 'identity')
82
- const jid = node.attrs.jid
83
- const registrationId = WABinary_1.getBinaryNodeChildUInt(node, 'registration', 4)
84
- await repository.injectE2ESession({
85
- jid,
86
- session: {
87
- registrationId: registrationId,
88
- identityKey: crypto_1.generateSignalPubKey(identity),
89
- signedPreKey: extractKey(signedKey),
90
- preKey: extractKey(key)
91
- }
92
- })
93
- }))
94
- }
95
- }
96
- exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
97
- const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
98
- const { user: myUser, device: myDevice } = WABinary_1.jidDecode(myJid)
99
- const extracted = []
100
- for (const userResult of result) {
101
- const { devices, id } = userResult
102
- const { user } = WABinary_1.jidDecode(id)
103
- const deviceList = devices?.deviceList
104
- if (Array.isArray(deviceList)) {
105
- for (const { id: device, keyIndex } of deviceList) {
106
- if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
107
- (myUser !== user || myDevice !== device) && // either different user or if me user, not this device
108
- (device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
109
- ) {
110
- extracted.push({ user, device })
111
- }
112
- }
113
- }
114
- }
115
- return extracted
116
- }
117
- exports.extractDeviceJids = extractDeviceJids;
118
- /**
119
- * get the next N keys for upload or processing
120
- * @param count number of pre-keys to get or generate
121
- */
122
- const getNextPreKeys = async ({ creds, keys }, count) => {
123
- const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count);
124
- const update = {
125
- nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
126
- firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
127
- };
128
- await keys.set({ 'pre-key': newPreKeys });
129
- const preKeys = await (0, exports.getPreKeys)(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
130
- return { update, preKeys };
131
- };
132
- exports.getNextPreKeys = getNextPreKeys;
133
- const getNextPreKeysNode = async (state, count) => {
134
- const { creds } = state;
135
- const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count);
136
- const node = {
137
- tag: 'iq',
138
- attrs: {
139
- xmlns: 'encrypt',
140
- type: 'set',
141
- to: WABinary_1.S_WHATSAPP_NET,
142
- },
143
- content: [
144
- { tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
145
- { tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
146
- { tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
147
- { tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => (0, exports.xmppPreKey)(preKeys[+k], +k)) },
148
- (0, exports.xmppSignedPreKey)(creds.signedPreKey)
149
- ]
150
- };
151
- return { update, node };
152
- };
153
- exports.getNextPreKeysNode = getNextPreKeysNode;
@@ -1,13 +0,0 @@
1
- import { AuthenticationState } from '../Types';
2
- /**
3
- * stores the full authentication state in a single folder.
4
- * Far more efficient than singlefileauthstate
5
- *
6
- * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
7
- * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
8
- * */
9
- export declare const useMultiFileAuthState: (folder: string) => Promise<{
10
- state: AuthenticationState;
11
- saveCreds: () => Promise<void>;
12
- }>;
13
-
@@ -1,119 +0,0 @@
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 fileLocks = new Map();
11
- const getFileLock = (path) => {
12
- let mutex = fileLocks.get(path);
13
- if (!mutex) {
14
- mutex = new async_mutex_1.Mutex();
15
- fileLocks.set(path, mutex);
16
- }
17
- return mutex;
18
- };
19
- /**
20
- * stores the full authentication state in a single folder.
21
- * Far more efficient than singlefileauthstate
22
- *
23
- * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
24
- * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
25
- * */
26
- const useMultiFileAuthState = async (folder) => {
27
- const writeData = async (data, file) => {
28
- const filePath = (0, path_1.join)(folder, fixFileName(file));
29
- const mutex = getFileLock(filePath);
30
- return mutex.acquire().then(async (release) => {
31
- try {
32
- await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
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
- return null;
55
- }
56
- };
57
- const removeData = async (file) => {
58
- try {
59
- const filePath = (0, path_1.join)(folder, fixFileName(file));
60
- const mutex = getFileLock(filePath);
61
- return mutex.acquire().then(async (release) => {
62
- try {
63
- await (0, promises_1.unlink)(filePath);
64
- }
65
- catch (_a) {
66
- }
67
- finally {
68
- release();
69
- }
70
- });
71
- }
72
- catch (_a) {
73
- }
74
- };
75
- const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
76
- if (folderInfo) {
77
- if (!folderInfo.isDirectory()) {
78
- throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
79
- }
80
- }
81
- else {
82
- await (0, promises_1.mkdir)(folder, { recursive: true });
83
- }
84
- 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, '-'); };
85
- const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
86
- return {
87
- state: {
88
- creds,
89
- keys: {
90
- get: async (type, ids) => {
91
- const data = {};
92
- await Promise.all(ids.map(async (id) => {
93
- let value = await readData(`${type}-${id}.json`);
94
- if (type === 'app-state-sync-key' && value) {
95
- value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
96
- }
97
- data[id] = value;
98
- }));
99
- return data;
100
- },
101
- set: async (data) => {
102
- const tasks = [];
103
- for (const category in data) {
104
- for (const id in data[category]) {
105
- const value = data[category][id];
106
- const file = `${category}-${id}.json`;
107
- tasks.push(value ? writeData(value, file) : removeData(file));
108
- }
109
- }
110
- await Promise.all(tasks);
111
- }
112
- }
113
- },
114
- saveCreds: async () => {
115
- return writeData(creds, 'creds.json');
116
- }
117
- };
118
- };
119
- exports.useMultiFileAuthState = useMultiFileAuthState;
@@ -1,11 +0,0 @@
1
- import { proto } from '../../WAProto';
2
- import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types';
3
- import { BinaryNode } from '../WABinary';
4
- export declare const generateMobileNode: (config: SocketConfig) => proto.IClientPayload;
5
- export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
6
- export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
7
- export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
8
- creds: Partial<AuthenticationCreds>;
9
- reply: BinaryNode;
10
- };
11
- export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array;
@@ -1,231 +0,0 @@
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: '0.1',
23
- device: 'Desktop',
24
- osBuildNumber: '0.1',
25
- localeLanguageIso6391: 'en',
26
- mnc: '000',
27
- mcc: '000',
28
- localeCountryIso31661Alpha2: config.countryCode || 'US'
29
- };
30
- };
31
-
32
-
33
-
34
- const PLATFORM_MAP = {
35
- 'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
36
- 'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
37
- };
38
-
39
- const getWebInfo = (config) => {
40
- let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
41
- if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
42
- webSubPlatform = PLATFORM_MAP[config.browser[0]];
43
- }
44
- return { webSubPlatform };
45
- };
46
-
47
- const getClientPayload = (config) => {
48
- const payload = {
49
- connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
50
- connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
51
- userAgent: getUserAgent(config),
52
- };
53
- payload.webInfo = getWebInfo(config);
54
- return payload;
55
- };
56
-
57
- const generateLoginNode = (userJid, config) => {
58
- const { user, device } = (0, WABinary_1.jidDecode)(userJid);
59
- const payload = {
60
- ...getClientPayload(config),
61
- passive: true,
62
- pull: true,
63
- username: +user,
64
- device: device,
65
- lidDbMigrated: false
66
- };
67
- return WAProto_1.proto.ClientPayload.fromObject(payload);
68
- };
69
- exports.generateLoginNode = generateLoginNode;
70
-
71
- const getPlatformType = (platform) => {
72
- const platformType = platform.toUpperCase();
73
- return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.CHROME;
74
- };
75
-
76
- const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
77
- const appVersionBuf = (0, crypto_1.createHash)('md5')
78
- .update(config.version.join('.'))
79
- .digest();
80
-
81
- const companion = {
82
- os: config.browser[0],
83
- platformType: getPlatformType(config.browser[1]),
84
- requireFullSync: config.syncFullHistory,
85
- historySyncConfig: {
86
- storageQuotaMb: 10240,
87
- inlineInitialPayloadInE2EeMsg: true,
88
- recentSyncDaysLimit: undefined,
89
- supportCallLogHistory: false,
90
- supportBotUserAgentChatHistory: true,
91
- supportCagReactionsAndPolls: true,
92
- supportBizHostedMsg: true,
93
- supportRecentSyncChunkMessageCountTuning: true,
94
- supportHostedGroupMsg: true,
95
- supportFbidBotChatHistory: true,
96
- supportAddOnHistorySyncMigration: undefined,
97
- supportMessageAssociation: true,
98
- supportGroupHistory: false,
99
- onDemandReady: undefined,
100
- supportGuestChat: undefined
101
- },
102
- version: {
103
- primary: 10,
104
- secondary: 15,
105
- tertiary: 7
106
- }
107
- };
108
-
109
- const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
110
-
111
- const registerPayload = {
112
- ...getClientPayload(config),
113
- passive: false,
114
- pull: false,
115
- devicePairingData: {
116
- buildHash: appVersionBuf,
117
- deviceProps: companionProto,
118
- eRegid: (0, generics_1.encodeBigEndian)(registrationId),
119
- eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
120
- eIdent: signedIdentityKey.public,
121
- eSkeyId: (0, generics_1.encodeBigEndian)(signedPreKey.keyId, 3),
122
- eSkeyVal: signedPreKey.keyPair.public,
123
- eSkeySig: signedPreKey.signature,
124
- },
125
- };
126
- return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
127
- };
128
- exports.generateRegistrationNode = generateRegistrationNode;
129
-
130
- const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
131
- const msgId = stanza.attrs.id;
132
- const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
133
- const deviceIdentityNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device-identity');
134
- const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
135
- const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
136
- const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
137
-
138
- if (!deviceIdentityNode || !deviceNode) {
139
- throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
140
- }
141
-
142
- const bizName = businessNode?.attrs.name;
143
- const jid = deviceNode.attrs.jid;
144
- const lid = deviceNode.attrs.lid;
145
-
146
- const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
147
-
148
- let hmacPrefix = Buffer.from([]);
149
- if (accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED) {
150
- hmacPrefix = Buffer.from([0x06, 0x05]);
151
- }
152
-
153
- const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
154
- if (Buffer.compare(hmac, advSign) !== 0) {
155
- throw new boom_1.Boom('Invalid account signature');
156
- }
157
-
158
- const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
159
- const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
160
-
161
- const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(deviceDetails);
162
-
163
- const accountSignaturePrefix = deviceIdentity.deviceType === WAProto_1.proto.ADVEncryptionType.HOSTED
164
- ? Buffer.from([0x06, 0x05])
165
- : Buffer.from([0x06, 0x00]);
166
- const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
167
-
168
- if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
169
- throw new boom_1.Boom('Failed to verify account signature');
170
- }
171
-
172
- const deviceMsg = Buffer.concat([
173
- Buffer.from([0x06, 0x01]),
174
- deviceDetails,
175
- signedIdentityKey.public,
176
- accountSignatureKey
177
- ]);
178
- account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
179
-
180
- const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey);
181
- const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
182
-
183
- const reply = {
184
- tag: 'iq',
185
- attrs: {
186
- to: WABinary_1.S_WHATSAPP_NET,
187
- type: 'result',
188
- id: msgId,
189
- },
190
- content: [
191
- {
192
- tag: 'pair-device-sign',
193
- attrs: {},
194
- content: [
195
- {
196
- tag: 'device-identity',
197
- attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
198
- content: accountEnc
199
- }
200
- ]
201
- }
202
- ]
203
- };
204
-
205
- const authUpdate = {
206
- account,
207
- me: { id: jid, name: bizName, lid },
208
- signalIdentities: [
209
- ...(signalIdentities || []),
210
- identity
211
- ],
212
- platform: platformNode?.attrs.name
213
- };
214
-
215
- return {
216
- creds: authUpdate,
217
- reply
218
- };
219
- };
220
- exports.configureSuccessfulPairing = configureSuccessfulPairing;
221
-
222
- const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
223
- account = { ...account };
224
- if (!includeSignatureKey || !account.accountSignatureKey?.length) {
225
- account.accountSignatureKey = null;
226
- }
227
- return WAProto_1.proto.ADVSignedDeviceIdentity
228
- .encode(account)
229
- .finish();
230
- };
231
- exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
@@ -1,30 +0,0 @@
1
- export declare const TAGS: {
2
- LIST_EMPTY: number
3
- DICTIONARY_0: number
4
- DICTIONARY_1: number
5
- DICTIONARY_2: number
6
- DICTIONARY_3: number
7
- INTEROP_JID: number
8
- FB_JID: number
9
- AD_JID: number
10
- LIST_8: number
11
- LIST_16: number
12
- JID_PAIR: number
13
- HEX_8: number
14
- BINARY_8: number
15
- BINARY_20: number
16
- BINARY_32: number
17
- NIBBLE_8: number
18
- PACKED_MAX: number
19
- }
20
-
21
- export declare const DOUBLE_BYTE_TOKENS: string[][]
22
-
23
- export declare const SINGLE_BYTE_TOKENS: (string | null)[]
24
-
25
- export declare const TOKEN_MAP: {
26
- [token: string]: {
27
- dict?: number
28
- index: number
29
- }
30
- }