gifted-baileys 1.5.0 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1429 -684
  3. package/WAProto/WAProto.proto +969 -88
  4. package/WAProto/index.d.ts +13199 -1260
  5. package/WAProto/index.js +124901 -74525
  6. package/lib/Defaults/baileys-version.json +1 -1
  7. package/lib/Defaults/index.d.ts +2 -2
  8. package/lib/Defaults/index.js +6 -5
  9. package/lib/Defaults/phonenumber-mcc.json +221 -221
  10. package/lib/Signal/libsignal.js +18 -9
  11. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -2
  12. package/lib/Socket/Client/index.d.ts +2 -3
  13. package/lib/Socket/Client/index.js +2 -3
  14. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -1
  15. package/lib/Socket/Client/types.d.ts +17 -0
  16. package/lib/Socket/Client/types.js +13 -0
  17. package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
  18. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +2 -2
  19. package/lib/Socket/business.d.ts +64 -29
  20. package/lib/Socket/business.js +1 -0
  21. package/lib/Socket/chats.d.ts +10 -8
  22. package/lib/Socket/chats.js +114 -97
  23. package/lib/Socket/groups.d.ts +10 -8
  24. package/lib/Socket/groups.js +4 -2
  25. package/lib/Socket/index.d.ts +70 -35
  26. package/lib/Socket/messages-recv.d.ts +63 -29
  27. package/lib/Socket/messages-recv.js +374 -155
  28. package/lib/Socket/messages-send.d.ts +48 -12
  29. package/lib/Socket/messages-send.js +445 -87
  30. package/lib/Socket/newsletter.d.ts +132 -0
  31. package/lib/Socket/newsletter.js +236 -0
  32. package/lib/Socket/registration.d.ts +73 -41
  33. package/lib/Socket/registration.js +7 -7
  34. package/lib/Socket/socket.d.ts +2 -0
  35. package/lib/Socket/socket.js +56 -15
  36. package/lib/Socket/usync.d.ts +37 -0
  37. package/lib/Socket/usync.js +70 -0
  38. package/lib/Store/make-cache-manager-store.d.ts +2 -1
  39. package/lib/Store/make-in-memory-store.d.ts +2 -1
  40. package/lib/Store/make-in-memory-store.js +40 -46
  41. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  42. package/lib/Types/Auth.d.ts +2 -1
  43. package/lib/Types/Call.d.ts +1 -1
  44. package/lib/Types/Chat.d.ts +12 -7
  45. package/lib/Types/Events.d.ts +17 -2
  46. package/lib/Types/GroupMetadata.d.ts +6 -2
  47. package/lib/Types/Label.d.ts +11 -0
  48. package/lib/Types/Label.js +1 -1
  49. package/lib/Types/LabelAssociation.js +1 -1
  50. package/lib/Types/Message.d.ts +184 -12
  51. package/lib/Types/Newsletter.d.ts +92 -0
  52. package/lib/Types/Newsletter.js +32 -0
  53. package/lib/Types/Socket.d.ts +7 -2
  54. package/lib/Types/USync.d.ts +25 -0
  55. package/lib/Types/USync.js +2 -0
  56. package/lib/Types/index.d.ts +10 -0
  57. package/lib/Types/index.js +2 -1
  58. package/lib/Utils/auth-utils.js +5 -3
  59. package/lib/Utils/business.d.ts +1 -1
  60. package/lib/Utils/business.js +2 -2
  61. package/lib/Utils/chat-utils.d.ts +11 -12
  62. package/lib/Utils/chat-utils.js +41 -20
  63. package/lib/Utils/crypto.d.ts +15 -16
  64. package/lib/Utils/crypto.js +35 -23
  65. package/lib/Utils/decode-wa-message.d.ts +17 -0
  66. package/lib/Utils/decode-wa-message.js +65 -13
  67. package/lib/Utils/generics.d.ts +11 -17
  68. package/lib/Utils/generics.js +47 -13
  69. package/lib/Utils/history.d.ts +6 -2
  70. package/lib/Utils/history.js +3 -0
  71. package/lib/Utils/link-preview.js +1 -1
  72. package/lib/Utils/logger.d.ts +1 -3
  73. package/lib/Utils/make-mutex.d.ts +2 -2
  74. package/lib/Utils/messages-media.d.ts +31 -25
  75. package/lib/Utils/messages-media.js +95 -53
  76. package/lib/Utils/messages.d.ts +2 -1
  77. package/lib/Utils/messages.js +515 -34
  78. package/lib/Utils/noise-handler.d.ts +6 -6
  79. package/lib/Utils/noise-handler.js +16 -3
  80. package/lib/Utils/process-message.js +4 -3
  81. package/lib/Utils/signal.d.ts +2 -1
  82. package/lib/Utils/signal.js +11 -19
  83. package/lib/Utils/use-multi-file-auth-state.js +11 -3
  84. package/lib/Utils/validate-connection.js +16 -2
  85. package/lib/WABinary/decode.d.ts +1 -2
  86. package/lib/WABinary/decode.js +17 -7
  87. package/lib/WABinary/encode.d.ts +1 -2
  88. package/lib/WABinary/encode.js +33 -17
  89. package/lib/WABinary/generic-utils.d.ts +2 -3
  90. package/lib/WABinary/generic-utils.js +2 -2
  91. package/lib/WABinary/jid-utils.d.ts +4 -2
  92. package/lib/WABinary/jid-utils.js +4 -1
  93. package/lib/WAM/BinaryInfo.d.ts +8 -0
  94. package/lib/WAM/BinaryInfo.js +13 -0
  95. package/lib/WAM/constants.d.ts +38 -0
  96. package/lib/WAM/constants.js +15350 -0
  97. package/lib/WAM/encode.d.ts +2 -0
  98. package/lib/WAM/encode.js +155 -0
  99. package/lib/WAM/index.d.ts +3 -0
  100. package/lib/WAM/index.js +19 -0
  101. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  102. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  103. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  104. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  105. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  106. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  107. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  108. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  109. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  110. package/lib/WAUSync/Protocols/index.js +20 -0
  111. package/lib/WAUSync/USyncQuery.d.ts +26 -0
  112. package/lib/WAUSync/USyncQuery.js +79 -0
  113. package/lib/WAUSync/USyncUser.d.ts +10 -0
  114. package/lib/WAUSync/USyncUser.js +22 -0
  115. package/lib/WAUSync/index.d.ts +3 -0
  116. package/lib/WAUSync/index.js +19 -0
  117. package/lib/gifted +1 -0
  118. package/lib/index.js +2 -0
  119. package/package.json +10 -7
  120. package/lib/index.d.ts +0 -10
@@ -1,20 +1,20 @@
1
- /// <reference types="node" />
2
1
  import { Logger } from 'pino';
3
2
  import { proto } from '../../WAProto';
4
3
  import { KeyPair } from '../Types';
5
4
  import { BinaryNode } from '../WABinary';
6
- export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, }: {
5
+ export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }: {
7
6
  keyPair: KeyPair;
8
7
  NOISE_HEADER: Uint8Array;
9
8
  mobile: boolean;
10
9
  logger: Logger;
10
+ routingInfo?: Buffer | undefined;
11
11
  }) => {
12
- encrypt: (plaintext: Uint8Array) => Buffer;
13
- decrypt: (ciphertext: Uint8Array) => Buffer;
12
+ encrypt: (plaintext: Uint8Array) => any;
13
+ decrypt: (ciphertext: Uint8Array) => any;
14
14
  authenticate: (data: Uint8Array) => void;
15
15
  mixIntoKey: (data: Uint8Array) => void;
16
16
  finishInit: () => void;
17
- processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Buffer;
18
- encodeFrame: (data: Buffer | Uint8Array) => Buffer;
17
+ processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => any;
18
+ encodeFrame: (data: Buffer | Uint8Array) => any;
19
19
  decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => void;
20
20
  };
@@ -11,7 +11,7 @@ const generateIV = (counter) => {
11
11
  new DataView(iv).setUint32(8, counter);
12
12
  return new Uint8Array(iv);
13
13
  };
14
- const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, }) => {
14
+ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }) => {
15
15
  logger = logger.child({ class: 'ns' });
16
16
  const authenticate = (data) => {
17
17
  if (!isFinished) {
@@ -101,10 +101,23 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
101
101
  if (isFinished) {
102
102
  data = encrypt(data);
103
103
  }
104
- const introSize = sentIntro ? 0 : NOISE_HEADER.length;
104
+ let header;
105
+ if (routingInfo) {
106
+ header = Buffer.alloc(7);
107
+ header.write('ED', 0, 'utf8');
108
+ header.writeUint8(0, 2);
109
+ header.writeUint8(1, 3);
110
+ header.writeUint8(routingInfo.byteLength >> 16, 4);
111
+ header.writeUint16BE(routingInfo.byteLength & 65535, 5);
112
+ header = Buffer.concat([header, routingInfo, NOISE_HEADER]);
113
+ }
114
+ else {
115
+ header = Buffer.from(NOISE_HEADER);
116
+ }
117
+ const introSize = sentIntro ? 0 : header.length;
105
118
  const frame = Buffer.alloc(introSize + 3 + data.byteLength);
106
119
  if (!sentIntro) {
107
- frame.set(NOISE_HEADER);
120
+ frame.set(header);
108
121
  sentIntro = true;
109
122
  }
110
123
  frame.writeUInt8(data.byteLength >> 16, introSize);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decryptPollVote = exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
3
+ exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
4
+ exports.decryptPollVote = decryptPollVote;
4
5
  const WAProto_1 = require("../../WAProto");
5
6
  const Types_1 = require("../Types");
6
7
  const messages_1 = require("../Utils/messages");
@@ -101,7 +102,6 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
101
102
  return Buffer.from(txt);
102
103
  }
103
104
  }
104
- exports.decryptPollVote = decryptPollVote;
105
105
  const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }) => {
106
106
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
107
107
  const meId = creds.me.id;
@@ -217,7 +217,8 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
217
217
  let participants;
218
218
  const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
219
219
  const emitGroupUpdate = (update) => {
220
- ev.emit('groups.update', [{ id: jid, ...update }]);
220
+ var _a;
221
+ ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
221
222
  };
222
223
  const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
223
224
  switch (message.messageStubType) {
@@ -1,6 +1,7 @@
1
1
  import { SignalRepository } from '../Types';
2
2
  import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth';
3
3
  import { BinaryNode, JidWithDevice } from '../WABinary';
4
+ import { USyncQueryResultList } from '../WAUSync';
4
5
  export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
5
6
  export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
6
7
  [id: string]: KeyPair;
@@ -15,7 +16,7 @@ export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: n
15
16
  export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
16
17
  export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
17
18
  export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>;
18
- export declare const extractDeviceJids: (result: BinaryNode, myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
19
+ export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
19
20
  /**
20
21
  * get the next N keys for upload or processing
21
22
  * @param count number of pre-keys to get or generate
@@ -85,27 +85,19 @@ const parseAndInjectE2ESessions = async (node, repository) => {
85
85
  };
86
86
  exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
87
87
  const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
88
- var _a;
89
88
  const { user: myUser, device: myDevice } = (0, WABinary_1.jidDecode)(myJid);
90
89
  const extracted = [];
91
- for (const node of result.content) {
92
- const list = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'list')) === null || _a === void 0 ? void 0 : _a.content;
93
- if (list && Array.isArray(list)) {
94
- for (const item of list) {
95
- const { user } = (0, WABinary_1.jidDecode)(item.attrs.jid);
96
- const devicesNode = (0, WABinary_1.getBinaryNodeChild)(item, 'devices');
97
- const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(devicesNode, 'device-list');
98
- if (Array.isArray(deviceListNode === null || deviceListNode === void 0 ? void 0 : deviceListNode.content)) {
99
- for (const { tag, attrs } of deviceListNode.content) {
100
- const device = +attrs.id;
101
- if (tag === 'device' && // ensure the "device" tag
102
- (!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
103
- (myUser !== user || myDevice !== device) && // either different user or if me user, not this device
104
- (device === 0 || !!attrs['key-index']) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
105
- ) {
106
- extracted.push({ user, device });
107
- }
108
- }
90
+ for (const userResult of result) {
91
+ const { devices, id } = userResult;
92
+ const { user } = (0, WABinary_1.jidDecode)(id);
93
+ const deviceList = devices === null || devices === void 0 ? void 0 : devices.deviceList;
94
+ if (Array.isArray(deviceList)) {
95
+ for (const { id: device, keyIndex } of deviceList) {
96
+ if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
97
+ (myUser !== user || myDevice !== device) && // either different user or if me user, not this device
98
+ (device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
99
+ ) {
100
+ extracted.push({ user, device });
109
101
  }
110
102
  }
111
103
  }
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.useMultiFileAuthState = void 0;
4
7
  const promises_1 = require("fs/promises");
@@ -6,6 +9,8 @@ const path_1 = require("path");
6
9
  const WAProto_1 = require("../../WAProto");
7
10
  const auth_utils_1 = require("./auth-utils");
8
11
  const generics_1 = require("./generics");
12
+ const async_lock_1 = __importDefault(require("async-lock"));
13
+ const fileLock = new async_lock_1.default({ maxPending: Infinity });
9
14
  /**
10
15
  * stores the full authentication state in a single folder.
11
16
  * Far more efficient than singlefileauthstate
@@ -15,11 +20,13 @@ const generics_1 = require("./generics");
15
20
  * */
16
21
  const useMultiFileAuthState = async (folder) => {
17
22
  const writeData = (data, file) => {
18
- return (0, promises_1.writeFile)((0, path_1.join)(folder, fixFileName(file)), JSON.stringify(data, generics_1.BufferJSON.replacer));
23
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
24
+ return fileLock.acquire(filePath, () => (0, promises_1.writeFile)((0, path_1.join)(filePath), JSON.stringify(data, generics_1.BufferJSON.replacer)));
19
25
  };
20
26
  const readData = async (file) => {
21
27
  try {
22
- const data = await (0, promises_1.readFile)((0, path_1.join)(folder, fixFileName(file)), { encoding: 'utf-8' });
28
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
29
+ const data = await fileLock.acquire(filePath, () => (0, promises_1.readFile)(filePath, { encoding: 'utf-8' }));
23
30
  return JSON.parse(data, generics_1.BufferJSON.reviver);
24
31
  }
25
32
  catch (error) {
@@ -28,7 +35,8 @@ const useMultiFileAuthState = async (folder) => {
28
35
  };
29
36
  const removeData = async (file) => {
30
37
  try {
31
- await (0, promises_1.unlink)((0, path_1.join)(folder, fixFileName(file)));
38
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
39
+ await fileLock.acquire(filePath, () => (0, promises_1.unlink)(filePath));
32
40
  }
33
41
  catch (_a) {
34
42
  }
@@ -12,10 +12,10 @@ const signal_1 = require("./signal");
12
12
  const getUserAgent = (config) => {
13
13
  var _a, _b;
14
14
  const osVersion = config.mobile ? '15.3.1' : '0.1';
15
- const version = config.mobile ? [2, 22, 24] : config.version;
15
+ const version = config.mobile ? [2, 24, 6] : config.version;
16
16
  const device = config.mobile ? 'iPhone_7' : 'Desktop';
17
17
  const manufacturer = config.mobile ? 'Apple' : '';
18
- const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.MACOS;
18
+ const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB;
19
19
  const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {};
20
20
  return {
21
21
  appVersion: {
@@ -36,12 +36,26 @@ const getUserAgent = (config) => {
36
36
  ...phoneId
37
37
  };
38
38
  };
39
+ const PLATFORM_MAP = {
40
+ 'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
41
+ 'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
42
+ };
43
+ const getWebInfo = (config) => {
44
+ let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
45
+ if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
46
+ webSubPlatform = PLATFORM_MAP[config.browser[0]];
47
+ }
48
+ return { webSubPlatform };
49
+ };
39
50
  const getClientPayload = (config) => {
40
51
  const payload = {
41
52
  connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
42
53
  connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
43
54
  userAgent: getUserAgent(config),
44
55
  };
56
+ if (!config.mobile) {
57
+ payload.webInfo = getWebInfo(config);
58
+ }
45
59
  return payload;
46
60
  };
47
61
  const generateMobileNode = (config) => {
@@ -1,7 +1,6 @@
1
- /// <reference types="node" />
2
1
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
3
2
  export declare const decompressingIfRequired: (buffer: Buffer) => Buffer;
4
- export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, 'DOUBLE_BYTE_TOKENS' | 'SINGLE_BYTE_TOKENS' | 'TAGS'>, indexRef?: {
3
+ export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, "DOUBLE_BYTE_TOKENS" | "SINGLE_BYTE_TOKENS" | "TAGS">, indexRef?: {
5
4
  index: number;
6
5
  }) => BinaryNode;
7
6
  export declare const decodeBinaryNode: (buff: Buffer) => BinaryNode;
@@ -15,13 +15,23 @@ 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 (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
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
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
27
37
  const zlib_1 = require("zlib");
@@ -1,3 +1,2 @@
1
- /// <reference types="node" />
2
1
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
3
- export declare const encodeBinaryNode: ({ tag, attrs, content }: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) => Buffer;
2
+ export declare const encodeBinaryNode: (node: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, "TAGS" | "TOKEN_MAP">, buffer?: number[]) => Buffer;
@@ -15,18 +15,33 @@ 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 (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
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
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.encodeBinaryNode = void 0;
27
37
  const constants = __importStar(require("./constants"));
28
38
  const jid_utils_1 = require("./jid-utils");
29
- const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0]) => {
39
+ const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
40
+ const encoded = encodeBinaryNodeInner(node, opts, buffer);
41
+ return Buffer.from(encoded);
42
+ };
43
+ exports.encodeBinaryNode = encodeBinaryNode;
44
+ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
30
45
  const { TAGS, TOKEN_MAP } = opts;
31
46
  const pushByte = (value) => buffer.push(value & 0xff);
32
47
  const pushInt = (value, n, littleEndian = false) => {
@@ -35,7 +50,11 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
35
50
  buffer.push((value >> (curShift * 8)) & 0xff);
36
51
  }
37
52
  };
38
- const pushBytes = (bytes) => (bytes.forEach(b => buffer.push(b)));
53
+ const pushBytes = (bytes) => {
54
+ for (const b of bytes) {
55
+ buffer.push(b);
56
+ }
57
+ };
39
58
  const pushInt16 = (value) => {
40
59
  pushBytes([(value >> 8) & 0xff, value & 0xff]);
41
60
  };
@@ -137,8 +156,7 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
137
156
  if (str.length > TAGS.PACKED_MAX) {
138
157
  return false;
139
158
  }
140
- for (let i = 0; i < str.length; i++) {
141
- const char = str[i];
159
+ for (const char of str) {
142
160
  const isInNibbleRange = char >= '0' && char <= '9';
143
161
  if (!isInNibbleRange && char !== '-' && char !== '.') {
144
162
  return false;
@@ -150,10 +168,9 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
150
168
  if (str.length > TAGS.PACKED_MAX) {
151
169
  return false;
152
170
  }
153
- for (let i = 0; i < str.length; i++) {
154
- const char = str[i];
171
+ for (const char of str) {
155
172
  const isInNibbleRange = char >= '0' && char <= '9';
156
- if (!isInNibbleRange && !(char >= 'A' && char <= 'F') && !(char >= 'a' && char <= 'f')) {
173
+ if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
157
174
  return false;
158
175
  }
159
176
  }
@@ -214,7 +231,7 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
214
231
  else if (Array.isArray(content)) {
215
232
  writeListStart(content.length);
216
233
  for (const item of content) {
217
- (0, exports.encodeBinaryNode)(item, opts, buffer);
234
+ encodeBinaryNodeInner(item, opts, buffer);
218
235
  }
219
236
  }
220
237
  else if (typeof content === 'undefined') {
@@ -223,6 +240,5 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
223
240
  else {
224
241
  throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
225
242
  }
226
- return Buffer.from(buffer);
243
+ return buffer;
227
244
  };
228
- exports.encodeBinaryNode = encodeBinaryNode;
@@ -1,11 +1,10 @@
1
- /// <reference types="node" />
2
1
  import { proto } from '../../WAProto';
3
2
  import { BinaryNode } from './types';
4
3
  export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[];
5
4
  export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
6
5
  export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined;
7
- export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array | Buffer | undefined;
8
- export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined;
6
+ export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => string | Uint8Array<ArrayBufferLike> | BinaryNode[] | undefined;
7
+ export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => any;
9
8
  export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
10
9
  export declare const assertNodeErrorFree: (node: BinaryNode) => void;
11
10
  export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: string) => {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.binaryNodeToString = exports.getBinaryNodeMessages = exports.reduceBinaryNodeToDictionary = exports.assertNodeErrorFree = exports.getBinaryNodeChildUInt = exports.getBinaryNodeChildString = exports.getBinaryNodeChildBuffer = exports.getBinaryNodeChild = exports.getAllBinaryNodeChildren = exports.getBinaryNodeChildren = void 0;
3
+ exports.getBinaryNodeMessages = exports.reduceBinaryNodeToDictionary = exports.assertNodeErrorFree = exports.getBinaryNodeChildUInt = exports.getBinaryNodeChildString = exports.getBinaryNodeChildBuffer = exports.getBinaryNodeChild = exports.getAllBinaryNodeChildren = exports.getBinaryNodeChildren = void 0;
4
+ exports.binaryNodeToString = binaryNodeToString;
4
5
  const boom_1 = require("@hapi/boom");
5
6
  const WAProto_1 = require("../../WAProto");
6
7
  // some extra useful utilities
@@ -107,4 +108,3 @@ function binaryNodeToString(node, i = 0) {
107
108
  const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
108
109
  return tag + content;
109
110
  }
110
- exports.binaryNodeToString = binaryNodeToString;
@@ -3,7 +3,7 @@ export declare const OFFICIAL_BIZ_JID = "16505361212@c.us";
3
3
  export declare const SERVER_JID = "server@c.us";
4
4
  export declare const PSA_WID = "0@c.us";
5
5
  export declare const STORIES_JID = "status@broadcast";
6
- export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid';
6
+ export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' | 'newsletter';
7
7
  export type JidWithDevice = {
8
8
  user: string;
9
9
  device?: number;
@@ -25,5 +25,7 @@ export declare const isJidBroadcast: (jid: string | undefined) => boolean | unde
25
25
  /** is the jid a group */
26
26
  export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
27
27
  /** is the jid the status broadcast */
28
- export declare const isJidStatusBroadcast: (jid: string) => boolean;
28
+ export declare const isJidStatusBroadcast: (jid: string) => jid is "status@broadcast";
29
+ /** is the jid the newsletter */
30
+ export declare const isJidNewsLetter: (jid: string | undefined) => boolean | undefined;
29
31
  export declare const jidNormalizedUser: (jid: string | undefined) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jidNormalizedUser = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
3
+ exports.jidNormalizedUser = exports.isJidNewsLetter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
4
4
  exports.S_WHATSAPP_NET = '@s.whatsapp.net';
5
5
  exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
6
6
  exports.SERVER_JID = 'server@c.us';
@@ -48,6 +48,9 @@ exports.isJidGroup = isJidGroup;
48
48
  /** is the jid the status broadcast */
49
49
  const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
50
50
  exports.isJidStatusBroadcast = isJidStatusBroadcast;
51
+ /** is the jid the newsletter */
52
+ const isJidNewsLetter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('newsletter'));
53
+ exports.isJidNewsLetter = isJidNewsLetter;
51
54
  const jidNormalizedUser = (jid) => {
52
55
  const result = (0, exports.jidDecode)(jid);
53
56
  if (!result) {
@@ -0,0 +1,8 @@
1
+ import { EventInputType } from './constants';
2
+ export declare class BinaryInfo {
3
+ protocolVersion: number;
4
+ sequence: number;
5
+ events: EventInputType[];
6
+ buffer: Buffer[];
7
+ constructor(options?: Partial<BinaryInfo>);
8
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BinaryInfo = void 0;
4
+ class BinaryInfo {
5
+ constructor(options = {}) {
6
+ this.protocolVersion = 5;
7
+ this.sequence = 0;
8
+ this.events = [];
9
+ this.buffer = [];
10
+ Object.assign(this, options);
11
+ }
12
+ }
13
+ exports.BinaryInfo = BinaryInfo;
@@ -0,0 +1,38 @@
1
+ export declare const WEB_EVENTS: Event[];
2
+ export declare const WEB_GLOBALS: Global[];
3
+ export declare const FLAG_BYTE = 8, FLAG_GLOBAL = 0, FLAG_EVENT = 1, FLAG_FIELD = 2, FLAG_EXTENDED = 4;
4
+ export type Event = {
5
+ name: string;
6
+ id: number;
7
+ props: {
8
+ [key: string]: [number, string | {
9
+ [key: string]: number;
10
+ }];
11
+ };
12
+ weight: number;
13
+ wamChannel: string;
14
+ privateStatsIdInt: number;
15
+ };
16
+ export type Global = {
17
+ name: string;
18
+ id: number;
19
+ type: string | {
20
+ [key: string]: number;
21
+ };
22
+ validator?: string;
23
+ channels: string[];
24
+ };
25
+ type EventByName<T extends Event['name']> = Extract<Event, {
26
+ name: T;
27
+ }>;
28
+ export type EventInputType = {
29
+ [key in Event['name']]: {
30
+ props: {
31
+ [k in keyof EventByName<key>['props']]: any;
32
+ };
33
+ globals: {
34
+ [x: string]: any;
35
+ };
36
+ };
37
+ } & {};
38
+ export {};