@genuxofficial/baileys 2.0.0 → 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 (108) hide show
  1. package/WAProto/WAProto.proto +4451 -0
  2. package/WAProto/index.d.ts +219 -2233
  3. package/WAProto/index.js +525 -6773
  4. package/WAProto/shizo.x +1 -0
  5. package/engine-requirements.js +1 -1
  6. package/lib/Defaults/baileys-version.json +1 -1
  7. package/lib/Defaults/index.d.ts +236 -3
  8. package/lib/Defaults/index.js +24 -8
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Signal/libsignal.js +9 -18
  11. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +2 -0
  12. package/lib/Socket/Client/index.d.ts +3 -2
  13. package/lib/Socket/Client/index.js +3 -2
  14. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  15. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  16. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  17. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +3 -3
  18. package/lib/Socket/business.d.ts +43 -43
  19. package/lib/Socket/chats.d.ts +17 -23
  20. package/lib/Socket/chats.js +9 -123
  21. package/lib/Socket/groups.d.ts +27 -32
  22. package/lib/Socket/groups.js +5 -18
  23. package/lib/Socket/index.d.ts +51 -49
  24. package/lib/Socket/index.js +2 -2
  25. package/lib/Socket/messages-recv.d.ts +41 -42
  26. package/lib/Socket/messages-recv.js +20 -39
  27. package/lib/Socket/messages-send.d.ts +33 -38
  28. package/lib/Socket/messages-send.js +16 -37
  29. package/lib/Socket/newsletter.d.ts +30 -35
  30. package/lib/Socket/newsletter.js +22 -26
  31. package/lib/Socket/registration.d.ts +271 -0
  32. package/lib/Socket/registration.js +166 -0
  33. package/lib/Socket/socket.d.ts +10 -9
  34. package/lib/Socket/socket.js +19 -16
  35. package/lib/Socket/usync.d.ts +12 -10
  36. package/lib/Socket/usync.js +15 -10
  37. package/lib/Store/index.d.ts +2 -1
  38. package/lib/Store/index.js +3 -1
  39. package/lib/Store/make-in-memory-store.d.ts +1 -1
  40. package/lib/Store/make-in-memory-store.js +10 -8
  41. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  42. package/lib/Store/make-ordered-dictionary.js +2 -2
  43. package/lib/Types/Auth.d.ts +8 -0
  44. package/lib/Types/Chat.d.ts +2 -12
  45. package/lib/Types/Contact.d.ts +1 -6
  46. package/lib/Types/GroupMetadata.d.ts +0 -7
  47. package/lib/Types/Label.d.ts +0 -11
  48. package/lib/Types/Label.js +1 -1
  49. package/lib/Types/LabelAssociation.js +1 -1
  50. package/lib/Types/Message.d.ts +8 -7
  51. package/lib/Types/Message.js +2 -0
  52. package/lib/Types/Newsletter.js +2 -2
  53. package/lib/Types/Socket.d.ts +6 -7
  54. package/lib/Types/index.js +1 -1
  55. package/lib/Utils/auth-utils.d.ts +1 -1
  56. package/lib/Utils/auth-utils.js +12 -5
  57. package/lib/Utils/business.js +2 -2
  58. package/lib/Utils/chat-utils.d.ts +13 -11
  59. package/lib/Utils/chat-utils.js +2 -28
  60. package/lib/Utils/crypto.d.ts +16 -14
  61. package/lib/Utils/crypto.js +22 -34
  62. package/lib/Utils/decode-wa-message.d.ts +2 -4
  63. package/lib/Utils/decode-wa-message.js +24 -160
  64. package/lib/Utils/event-buffer.js +6 -4
  65. package/lib/Utils/generics.d.ts +12 -40
  66. package/lib/Utils/generics.js +25 -103
  67. package/lib/Utils/link-preview.js +1 -34
  68. package/lib/Utils/lt-hash.d.ts +3 -3
  69. package/lib/Utils/lt-hash.js +45 -11
  70. package/lib/Utils/make-mutex.d.ts +2 -2
  71. package/lib/Utils/messages-media.d.ts +16 -26
  72. package/lib/Utils/messages-media.js +26 -102
  73. package/lib/Utils/messages.d.ts +8 -5
  74. package/lib/Utils/messages.js +15 -17
  75. package/lib/Utils/noise-handler.d.ts +8 -5
  76. package/lib/Utils/noise-handler.js +10 -5
  77. package/lib/Utils/process-message.js +2 -2
  78. package/lib/Utils/use-multi-file-auth-state.js +11 -48
  79. package/lib/Utils/validate-connection.d.ts +3 -2
  80. package/lib/Utils/validate-connection.js +44 -10
  81. package/lib/WABinary/constants.js +5 -5
  82. package/lib/WABinary/decode.d.ts +4 -2
  83. package/lib/WABinary/decode.js +7 -17
  84. package/lib/WABinary/encode.d.ts +3 -1
  85. package/lib/WABinary/encode.js +17 -40
  86. package/lib/WABinary/generic-utils.d.ts +3 -1
  87. package/lib/WABinary/generic-utils.js +2 -2
  88. package/lib/WABinary/jid-utils.d.ts +3 -8
  89. package/lib/WABinary/jid-utils.js +2 -23
  90. package/lib/WAM/BinaryInfo.d.ts +12 -2
  91. package/lib/WAM/constants.d.ts +2 -3
  92. package/lib/WAM/encode.d.ts +3 -1
  93. package/lib/WAM/encode.js +2 -2
  94. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  95. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
  96. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  97. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
  98. package/lib/WAUSync/USyncQuery.d.ts +0 -2
  99. package/lib/WAUSync/USyncQuery.js +13 -27
  100. package/lib/WAUSync/USyncUser.d.ts +0 -2
  101. package/lib/WAUSync/USyncUser.js +0 -4
  102. package/package.json +60 -55
  103. package/LICENSE +0 -21
  104. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  105. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
  106. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  107. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
  108. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -1,26 +1,16 @@
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
- const async_mutex_1 = require("async-mutex");
5
7
  const promises_1 = require("fs/promises");
6
8
  const path_1 = require("path");
7
9
  const WAProto_1 = require("../../WAProto");
8
10
  const auth_utils_1 = require("./auth-utils");
9
11
  const generics_1 = require("./generics");
10
- // We need to lock files due to the fact that we are using async functions to read and write files
11
- // https://github.com/WhiskeySockets/Baileys/issues/794
12
- // https://github.com/nodejs/node/issues/26338
13
- // Use a Map to store mutexes for each file path
14
- const fileLocks = new Map();
15
- // Get or create a mutex for a specific file path
16
- const getFileLock = (path) => {
17
- let mutex = fileLocks.get(path);
18
- if (!mutex) {
19
- mutex = new async_mutex_1.Mutex();
20
- fileLocks.set(path, mutex);
21
- }
22
- return mutex;
23
- };
12
+ const async_lock_1 = __importDefault(require("async-lock"));
13
+ const fileLock = new async_lock_1.default({ maxPending: Infinity });
24
14
  /**
25
15
  * stores the full authentication state in a single folder.
26
16
  * Far more efficient than singlefileauthstate
@@ -29,32 +19,15 @@ const getFileLock = (path) => {
29
19
  * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
30
20
  * */
31
21
  const useMultiFileAuthState = async (folder) => {
32
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
- const writeData = async (data, file) => {
22
+ const writeData = (data, file) => {
34
23
  const filePath = (0, path_1.join)(folder, fixFileName(file));
35
- const mutex = getFileLock(filePath);
36
- return mutex.acquire().then(async (release) => {
37
- try {
38
- await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
39
- }
40
- finally {
41
- release();
42
- }
43
- });
24
+ return fileLock.acquire(filePath, () => (0, promises_1.writeFile)((0, path_1.join)(filePath), JSON.stringify(data, generics_1.BufferJSON.replacer)));
44
25
  };
45
26
  const readData = async (file) => {
46
27
  try {
47
28
  const filePath = (0, path_1.join)(folder, fixFileName(file));
48
- const mutex = getFileLock(filePath);
49
- return await mutex.acquire().then(async (release) => {
50
- try {
51
- const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
52
- return JSON.parse(data, generics_1.BufferJSON.reviver);
53
- }
54
- finally {
55
- release();
56
- }
57
- });
29
+ const data = await fileLock.acquire(filePath, () => (0, promises_1.readFile)(filePath, { encoding: 'utf-8' }));
30
+ return JSON.parse(data, generics_1.BufferJSON.reviver);
58
31
  }
59
32
  catch (error) {
60
33
  return null;
@@ -63,17 +36,7 @@ const useMultiFileAuthState = async (folder) => {
63
36
  const removeData = async (file) => {
64
37
  try {
65
38
  const filePath = (0, path_1.join)(folder, fixFileName(file));
66
- const mutex = getFileLock(filePath);
67
- return mutex.acquire().then(async (release) => {
68
- try {
69
- await (0, promises_1.unlink)(filePath);
70
- }
71
- catch (_a) {
72
- }
73
- finally {
74
- release();
75
- }
76
- });
39
+ await fileLock.acquire(filePath, () => (0, promises_1.unlink)(filePath));
77
40
  }
78
41
  catch (_a) {
79
42
  }
@@ -117,7 +80,7 @@ const useMultiFileAuthState = async (folder) => {
117
80
  }
118
81
  }
119
82
  },
120
- saveCreds: async () => {
83
+ saveCreds: () => {
121
84
  return writeData(creds, 'creds.json');
122
85
  }
123
86
  };
@@ -1,10 +1,11 @@
1
1
  import { proto } from '../../WAProto';
2
2
  import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types';
3
3
  import { BinaryNode } from '../WABinary';
4
+ export declare const generateMobileNode: (config: SocketConfig) => proto.IClientPayload;
4
5
  export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
5
6
  export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
6
- export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, "advSecretKey" | "signedIdentityKey" | "signalIdentities">) => {
7
+ export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
7
8
  creds: Partial<AuthenticationCreds>;
8
9
  reply: BinaryNode;
9
10
  };
10
- export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array<ArrayBufferLike>;
11
+ export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
3
+ exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = exports.generateMobileNode = void 0;
4
4
  const boom_1 = require("@hapi/boom");
5
5
  const crypto_1 = require("crypto");
6
6
  const WAProto_1 = require("../../WAProto");
@@ -10,19 +10,30 @@ const crypto_2 = require("./crypto");
10
10
  const generics_1 = require("./generics");
11
11
  const signal_1 = require("./signal");
12
12
  const getUserAgent = (config) => {
13
+ var _a, _b;
14
+ const osVersion = config.mobile ? '15.3.1' : '0.1';
15
+ const version = config.mobile ? [2, 24, 6] : config.version;
16
+ const device = config.mobile ? 'iPhone_7' : 'Desktop';
17
+ const manufacturer = config.mobile ? 'Apple' : '';
18
+ const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB;
19
+ const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {};
13
20
  return {
14
21
  appVersion: {
15
- primary: config.version[0],
16
- secondary: config.version[1],
17
- tertiary: config.version[2],
22
+ primary: version[0],
23
+ secondary: version[1],
24
+ tertiary: version[2],
18
25
  },
19
- platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
26
+ platform,
20
27
  releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
21
- osVersion: '0.1',
22
- device: 'Desktop',
23
- osBuildNumber: '0.1',
28
+ mcc: ((_a = config.auth.creds.registration) === null || _a === void 0 ? void 0 : _a.phoneNumberMobileCountryCode) || '000',
29
+ mnc: ((_b = config.auth.creds.registration) === null || _b === void 0 ? void 0 : _b.phoneNumberMobileNetworkCode) || '000',
30
+ osVersion: osVersion,
31
+ manufacturer,
32
+ device,
33
+ osBuildNumber: osVersion,
24
34
  localeLanguageIso6391: 'en',
25
- localeCountryIso31661Alpha2: config.countryCode
35
+ localeCountryIso31661Alpha2: config.countryCode,
36
+ ...phoneId
26
37
  };
27
38
  };
28
39
  const PLATFORM_MAP = {
@@ -42,9 +53,32 @@ const getClientPayload = (config) => {
42
53
  connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
43
54
  userAgent: getUserAgent(config),
44
55
  };
45
- payload.webInfo = getWebInfo(config);
56
+ if (!config.mobile) {
57
+ payload.webInfo = getWebInfo(config);
58
+ }
46
59
  return payload;
47
60
  };
61
+ const generateMobileNode = (config) => {
62
+ if (!config.auth.creds) {
63
+ throw new boom_1.Boom('No registration data found', { data: config });
64
+ }
65
+ const payload = {
66
+ ...getClientPayload(config),
67
+ sessionId: Math.floor(Math.random() * 999999999 + 1),
68
+ shortConnect: true,
69
+ connectAttemptCount: 0,
70
+ device: 0,
71
+ dnsSource: {
72
+ appCached: false,
73
+ dnsMethod: WAProto_1.proto.ClientPayload.DNSSource.DNSResolutionMethod.SYSTEM,
74
+ },
75
+ passive: false,
76
+ pushName: 'test',
77
+ username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`),
78
+ };
79
+ return WAProto_1.proto.ClientPayload.fromObject(payload);
80
+ };
81
+ exports.generateMobileNode = generateMobileNode;
48
82
  const generateLoginNode = (userJid, config) => {
49
83
  const { user, device } = (0, WABinary_1.jidDecode)(userJid);
50
84
  const payload = {
@@ -30,11 +30,11 @@ exports.SINGLE_BYTE_TOKENS = [
30
30
  '', 'xmlstreamstart', 'xmlstreamend', 's.whatsapp.net', 'type', 'participant', 'from', 'receipt', 'id', 'broadcast', 'status', 'message', 'notification', 'notify', 'to', 'jid', 'user', 'class', 'offline', 'g.us', 'result', 'mediatype', 'enc', 'skmsg', 'off_cnt', 'xmlns', 'presence', 'participants', 'ack', 't', 'iq', 'device_hash', 'read', 'value', 'media', 'picture', 'chatstate', 'unavailable', 'text', 'urn:xmpp:whatsapp:push', 'devices', 'verified_name', 'contact', 'composing', 'edge_routing', 'routing_info', 'item', 'image', 'verified_level', 'get', 'fallback_hostname', '2', 'media_conn', '1', 'v', 'handshake', 'fallback_class', 'count', 'config', 'offline_preview', 'download_buckets', 'w:profile:picture', 'set', 'creation', 'location', 'fallback_ip4', 'msg', 'urn:xmpp:ping', 'fallback_ip6', 'call-creator', 'relaylatency', 'success', 'subscribe', 'video', 'business_hours_config', 'platform', 'hostname', 'version', 'unknown', '0', 'ping', 'hash', 'edit', 'subject', 'max_buckets', 'download', 'delivery', 'props', 'sticker', 'name', 'last', 'contacts', 'business', 'primary', 'preview', 'w:p', 'pkmsg', 'call-id', 'retry', 'prop', 'call', 'auth_ttl', 'available', 'relay_id', 'last_id', 'day_of_week', 'w', 'host', 'seen', 'bits', 'list', 'atn', 'upload', 'is_new', 'w:stats', 'key', 'paused', 'specific_hours', 'multicast', 'stream:error', 'mmg.whatsapp.net', 'code', 'deny', 'played', 'profile', 'fna', 'device-list', 'close_time', 'latency', 'gcm', 'pop', 'audio', '26', 'w:web', 'open_time', 'error', 'auth', 'ip4', 'update', 'profile_options', 'config_value', 'category', 'catalog_not_created', '00', 'config_code', 'mode', 'catalog_status', 'ip6', 'blocklist', 'registration', '7', 'web', 'fail', 'w:m', 'cart_enabled', 'ttl', 'gif', '300', 'device_orientation', 'identity', 'query', '401', 'media-gig2-1.cdn.whatsapp.net', 'in', '3', 'te2', 'add', 'fallback', 'categories', 'ptt', 'encrypt', 'notice', 'thumbnail-document', 'item-not-found', '12', 'thumbnail-image', 'stage', 'thumbnail-link', 'usync', 'out', 'thumbnail-video', '8', '01', 'context', 'sidelist', 'thumbnail-gif', 'terminate', 'not-authorized', 'orientation', 'dhash', 'capability', 'side_list', 'md-app-state', 'description', 'serial', 'readreceipts', 'te', 'business_hours', 'md-msg-hist', 'tag', 'attribute_padding', 'document', 'open_24h', 'delete', 'expiration', 'active', 'prev_v_id', 'true', 'passive', 'index', '4', 'conflict', 'remove', 'w:gp2', 'config_expo_key', 'screen_height', 'replaced', '02', 'screen_width', 'uploadfieldstat', '2:47DEQpj8', 'media-bog1-1.cdn.whatsapp.net', 'encopt', 'url', 'catalog_exists', 'keygen', 'rate', 'offer', 'opus', 'media-mia3-1.cdn.whatsapp.net', 'privacy', 'media-mia3-2.cdn.whatsapp.net', 'signature', 'preaccept', 'token_id', 'media-eze1-1.cdn.whatsapp.net'
31
31
  ];
32
32
  exports.TOKEN_MAP = {};
33
- for (const [i, SINGLE_BYTE_TOKEN] of exports.SINGLE_BYTE_TOKENS.entries()) {
34
- exports.TOKEN_MAP[SINGLE_BYTE_TOKEN] = { index: i };
33
+ for (let i = 0; i < exports.SINGLE_BYTE_TOKENS.length; i++) {
34
+ exports.TOKEN_MAP[exports.SINGLE_BYTE_TOKENS[i]] = { index: i };
35
35
  }
36
- for (const [i, DOUBLE_BYTE_TOKEN] of exports.DOUBLE_BYTE_TOKENS.entries()) {
37
- for (const [j, element] of DOUBLE_BYTE_TOKEN.entries()) {
38
- exports.TOKEN_MAP[element] = { dict: i, index: j };
36
+ for (let i = 0; i < exports.DOUBLE_BYTE_TOKENS.length; i++) {
37
+ for (let j = 0; j < exports.DOUBLE_BYTE_TOKENS[i].length; j++) {
38
+ exports.TOKEN_MAP[exports.DOUBLE_BYTE_TOKENS[i][j]] = { dict: i, index: j };
39
39
  }
40
40
  }
@@ -1,6 +1,8 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
2
- export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer<ArrayBufferLike>>;
3
- export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, "DOUBLE_BYTE_TOKENS" | "SINGLE_BYTE_TOKENS" | "TAGS">, indexRef?: {
4
+ export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer>;
5
+ export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, 'DOUBLE_BYTE_TOKENS' | 'SINGLE_BYTE_TOKENS' | 'TAGS'>, indexRef?: {
4
6
  index: number;
5
7
  }) => BinaryNode;
6
8
  export declare const decodeBinaryNode: (buff: Buffer) => Promise<BinaryNode>;
@@ -15,23 +15,13 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- 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
- })();
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
+ };
35
25
  Object.defineProperty(exports, "__esModule", { value: true });
36
26
  exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
37
27
  const util_1 = require("util");
@@ -1,2 +1,4 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
2
- export declare const encodeBinaryNode: (node: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, "TAGS" | "TOKEN_MAP">, buffer?: number[]) => Buffer;
4
+ export declare const encodeBinaryNode: (node: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) => Buffer;
@@ -15,23 +15,13 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- 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
- })();
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
+ };
35
25
  Object.defineProperty(exports, "__esModule", { value: true });
36
26
  exports.encodeBinaryNode = void 0;
37
27
  const constants = __importStar(require("./constants"));
@@ -50,11 +40,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
50
40
  buffer.push((value >> (curShift * 8)) & 0xff);
51
41
  }
52
42
  };
53
- const pushBytes = (bytes) => {
54
- for (const b of bytes) {
55
- buffer.push(b);
56
- }
57
- };
43
+ const pushBytes = (bytes) => (bytes.forEach(b => buffer.push(b)));
58
44
  const pushInt16 = (value) => {
59
45
  pushBytes([(value >> 8) & 0xff, value & 0xff]);
60
46
  };
@@ -153,10 +139,11 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
153
139
  }
154
140
  };
155
141
  const isNibble = (str) => {
156
- if (!str || str.length > TAGS.PACKED_MAX) {
142
+ if (str.length > TAGS.PACKED_MAX) {
157
143
  return false;
158
144
  }
159
- for (const char of str) {
145
+ for (let i = 0; i < str.length; i++) {
146
+ const char = str[i];
160
147
  const isInNibbleRange = char >= '0' && char <= '9';
161
148
  if (!isInNibbleRange && char !== '-' && char !== '.') {
162
149
  return false;
@@ -165,10 +152,11 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
165
152
  return true;
166
153
  };
167
154
  const isHex = (str) => {
168
- if (!str || str.length > TAGS.PACKED_MAX) {
155
+ if (str.length > TAGS.PACKED_MAX) {
169
156
  return false;
170
157
  }
171
- for (const char of str) {
158
+ for (let i = 0; i < str.length; i++) {
159
+ const char = str[i];
172
160
  const isInNibbleRange = char >= '0' && char <= '9';
173
161
  if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
174
162
  return false;
@@ -177,10 +165,6 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
177
165
  return true;
178
166
  };
179
167
  const writeString = (str) => {
180
- if (str === undefined || str === null) {
181
- pushByte(TAGS.LIST_EMPTY);
182
- return;
183
- }
184
168
  const tokenIndex = TOKEN_MAP[str];
185
169
  if (tokenIndex) {
186
170
  if (typeof tokenIndex.dict === 'number') {
@@ -191,9 +175,6 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
191
175
  else if (isNibble(str)) {
192
176
  writePackedBytes(str, 'nibble');
193
177
  }
194
- else if (isHex(str)) {
195
- writePackedBytes(str, 'hex');
196
- }
197
178
  else if (str) {
198
179
  const decodedJid = (0, jid_utils_1.jidDecode)(str);
199
180
  if (decodedJid) {
@@ -216,10 +197,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
216
197
  pushInt16(listSize);
217
198
  }
218
199
  };
219
- if (!tag) {
220
- throw new Error('Invalid node: tag cannot be undefined');
221
- }
222
- const validAttributes = Object.keys(attrs || {}).filter(k => (typeof attrs[k] !== 'undefined' && attrs[k] !== null));
200
+ const validAttributes = Object.keys(attrs).filter(k => (typeof attrs[k] !== 'undefined' && attrs[k] !== null));
223
201
  writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
224
202
  writeString(tag);
225
203
  for (const key of validAttributes) {
@@ -236,9 +214,8 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
236
214
  pushBytes(content);
237
215
  }
238
216
  else if (Array.isArray(content)) {
239
- const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
240
- writeListStart(validContent.length);
241
- for (const item of validContent) {
217
+ writeListStart(content.length);
218
+ for (const item of content) {
242
219
  encodeBinaryNodeInner(item, opts, buffer);
243
220
  }
244
221
  }
@@ -1,9 +1,11 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { proto } from '../../WAProto';
2
4
  import { BinaryNode } from './types';
3
5
  export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[];
4
6
  export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
5
7
  export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined;
6
- export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike> | undefined;
8
+ export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array | Buffer | undefined;
7
9
  export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined;
8
10
  export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
9
11
  export declare const assertNodeErrorFree: (node: BinaryNode) => void;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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;
3
+ exports.binaryNodeToString = exports.getBinaryNodeMessages = exports.reduceBinaryNodeToDictionary = exports.assertNodeErrorFree = exports.getBinaryNodeChildUInt = exports.getBinaryNodeChildString = exports.getBinaryNodeChildBuffer = exports.getBinaryNodeChild = exports.getAllBinaryNodeChildren = exports.getBinaryNodeChildren = void 0;
5
4
  const boom_1 = require("@hapi/boom");
6
5
  const WAProto_1 = require("../../WAProto");
7
6
  // some extra useful utilities
@@ -108,3 +107,4 @@ function binaryNodeToString(node, i = 0) {
108
107
  const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
109
108
  return tag + content;
110
109
  }
110
+ exports.binaryNodeToString = binaryNodeToString;
@@ -3,23 +3,19 @@ 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 declare const META_AI_JID = "13135550002@c.us";
7
- export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' | 'newsletter' | 'bot';
6
+ export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' | 'newsletter';
8
7
  export type JidWithDevice = {
9
8
  user: string;
10
9
  device?: number;
11
10
  };
12
11
  export type FullJid = JidWithDevice & {
13
- server: JidServer;
12
+ server: JidServer | string;
14
13
  domainType?: number;
15
14
  };
16
- export declare const getBotJid: (jid: string) => string;
17
15
  export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
18
16
  export declare const jidDecode: (jid: string | undefined) => FullJid | undefined;
19
17
  /** is the jid a user */
20
18
  export declare const areJidsSameUser: (jid1: string | undefined, jid2: string | undefined) => boolean;
21
- /** is the jid Meta AI */
22
- export declare const isJidMetaAI: (jid: string | undefined) => boolean | undefined;
23
19
  /** is the jid a user */
24
20
  export declare const isJidUser: (jid: string | undefined) => boolean | undefined;
25
21
  /** is the jid a group */
@@ -31,6 +27,5 @@ export declare const isJidNewsletter: (jid: string | undefined) => boolean | und
31
27
  /** is the jid a group */
32
28
  export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
33
29
  /** is the jid the status broadcast */
34
- export declare const isJidStatusBroadcast: (jid: string) => jid is "status@broadcast";
35
- export declare const isJidBot: (jid: string | undefined) => boolean | "" | undefined;
30
+ export declare const isJidStatusBroadcast: (jid: string) => boolean;
36
31
  export declare const jidNormalizedUser: (jid: string | undefined) => string;
@@ -1,26 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jidNormalizedUser = exports.isJidBot = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidNewsletter = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.isJidMetaAI = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.getBotJid = exports.META_AI_JID = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
3
+ exports.jidNormalizedUser = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidNewsletter = 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';
7
7
  exports.PSA_WID = '0@c.us';
8
8
  exports.STORIES_JID = 'status@broadcast';
9
- exports.META_AI_JID = '13135550002@c.us';
10
- const getBotJid = (jid) => {
11
- const BOT_MAP = new Map([["867051314767696", "13135550002"], ["1061492271844689", "13135550005"], ["245886058483988", "13135550009"], ["3509905702656130", "13135550012"], ["1059680132034576", "13135550013"], ["715681030623646", "13135550014"], ["1644971366323052", "13135550015"], ["582497970646566", "13135550019"], ["645459357769306", "13135550022"], ["294997126699143", "13135550023"], ["1522631578502677", "13135550027"], ["719421926276396", "13135550030"], ["1788488635002167", "13135550031"], ["24232338603080193", "13135550033"], ["689289903143209", "13135550035"], ["871626054177096", "13135550039"], ["362351902849370", "13135550042"], ["1744617646041527", "13135550043"], ["893887762270570", "13135550046"], ["1155032702135830", "13135550047"], ["333931965993883", "13135550048"], ["853748013058752", "13135550049"], ["1559068611564819", "13135550053"], ["890487432705716", "13135550054"], ["240254602395494", "13135550055"], ["1578420349663261", "13135550062"], ["322908887140421", "13135550065"], ["3713961535514771", "13135550067"], ["997884654811738", "13135550070"], ["403157239387035", "13135550081"], ["535242369074963", "13135550082"], ["946293427247659", "13135550083"], ["3664707673802291", "13135550084"], ["1821827464894892", "13135550085"], ["1760312477828757", "13135550086"], ["439480398712216", "13135550087"], ["1876735582800984", "13135550088"], ["984025089825661", "13135550089"], ["1001336351558186", "13135550090"], ["3739346336347061", "13135550091"], ["3632749426974980", "13135550092"], ["427864203481615", "13135550093"], ["1434734570493055", "13135550094"], ["992873449225921", "13135550095"], ["813087747426445", "13135550096"], ["806369104931434", "13135550098"], ["1220982902403148", "13135550099"], ["1365893374104393", "13135550100"], ["686482033622048", "13135550200"], ["1454999838411253", "13135550201"], ["718584497008509", "13135550202"], ["743520384213443", "13135550301"], ["1147715789823789", "13135550302"], ["1173034540372201", "13135550303"], ["974785541030953", "13135550304"], ["1122200255531507", "13135550305"], ["899669714813162", "13135550306"], ["631880108970650", "13135550307"], ["435816149330026", "13135550308"], ["1368717161184556", "13135550309"], ["7849963461784891", "13135550310"], ["3609617065968984", "13135550312"], ["356273980574602", "13135550313"], ["1043447920539760", "13135550314"], ["1052764336525346", "13135550315"], ["2631118843732685", "13135550316"], ["510505411332176", "13135550317"], ["1945664239227513", "13135550318"], ["1518594378764656", "13135550319"], ["1378821579456138", "13135550320"], ["490214716896013", "13135550321"], ["1028577858870699", "13135550322"], ["308915665545959", "13135550323"], ["845884253678900", "13135550324"], ["995031308616442", "13135550325"], ["2787365464763437", "13135550326"], ["1532790990671645", "13135550327"], ["302617036180485", "13135550328"], ["723376723197227", "13135550329"], ["8393570407377966", "13135550330"], ["1931159970680725", "13135550331"], ["401073885688605", "13135550332"], ["2234478453565422", "13135550334"], ["814748673882312", "13135550335"], ["26133635056281592", "13135550336"], ["1439804456676119", "13135550337"], ["889851503172161", "13135550338"], ["1018283232836879", "13135550339"], ["1012781386779537", "13135559000"], ["823280953239532", "13135559001"], ["1597090934573334", "13135559002"], ["485965054020343", "13135559003"], ["1033381648363446", "13135559004"], ["491802010206446", "13135559005"], ["1017139033184870", "13135559006"], ["499638325922174", "13135559008"], ["468946335863664", "13135559009"], ["1570389776875816", "13135559010"], ["1004342694328995", "13135559011"], ["1012240323971229", "13135559012"], ["392171787222419", "13135559013"], ["952081212945019", "13135559016"], ["444507875070178", "13135559017"], ["1274819440594668", "13135559018"], ["1397041101147050", "13135559019"], ["425657699872640", "13135559020"], ["532292852562549", "13135559021"], ["705863241720292", "13135559022"], ["476449815183959", "13135559023"], ["488071553854222", "13135559024"], ["468693832665397", "13135559025"], ["517422564037340", "13135559026"], ["819805466613825", "13135559027"], ["1847708235641382", "13135559028"], ["716282970644228", "13135559029"], ["521655380527741", "13135559030"], ["476193631941905", "13135559031"], ["485600497445562", "13135559032"], ["440217235683910", "13135559033"], ["523342446758478", "13135559034"], ["514784864360240", "13135559035"], ["505790121814530", "13135559036"], ["420008964419580", "13135559037"], ["492141680204555", "13135559038"], ["388462787271952", "13135559039"], ["423473920752072", "13135559040"], ["489574180468229", "13135559041"], ["432360635854105", "13135559042"], ["477878201669248", "13135559043"], ["351656951234045", "13135559044"], ["430178036732582", "13135559045"], ["434537312944552", "13135559046"], ["1240614300631808", "13135559047"], ["473135945605128", "13135559048"], ["423669800729310", "13135559049"], ["3685666705015792", "13135559050"], ["504196509016638", "13135559051"], ["346844785189449", "13135559052"], ["504823088911074", "13135559053"], ["402669415797083", "13135559054"], ["490939640234431", "13135559055"], ["875124128063715", "13135559056"], ["468788962654605", "13135559057"], ["562386196354570", "13135559058"], ["372159285928791", "13135559059"], ["531017479591050", "13135559060"], ["1328873881401826", "13135559061"], ["1608363646390484", "13135559062"], ["1229628561554232", "13135559063"], ["348802211530364", "13135559064"], ["3708535859420184", "13135559065"], ["415517767742187", "13135559066"], ["479330341612638", "13135559067"], ["480785414723083", "13135559068"], ["387299107507991", "13135559069"], ["333389813188944", "13135559070"], ["391794130316996", "13135559071"], ["457893470576314", "13135559072"], ["435550496166469", "13135559073"], ["1620162702100689", "13135559074"], ["867491058616043", "13135559075"], ["816224117357759", "13135559076"], ["334065176362830", "13135559077"], ["489973170554709", "13135559078"], ["473060669049665", "13135559079"], ["1221505815643060", "13135559080"], ["889000703096359", "13135559081"], ["475235961979883", "13135559082"], ["3434445653519934", "13135559084"], ["524503026827421", "13135559085"], ["1179639046403856", "13135559086"], ["471563305859144", "13135559087"], ["533896609192881", "13135559088"], ["365443583168041", "13135559089"], ["836082305329393", "13135559090"], ["1056787705969916", "13135559091"], ["503312598958357", "13135559092"], ["3718606738453460", "13135559093"], ["826066052850902", "13135559094"], ["1033611345091888", "13135559095"], ["3868390816783240", "13135559096"], ["7462677740498860", "13135559097"], ["436288576108573", "13135559098"], ["1047559746718900", "13135559099"], ["1099299455255491", "13135559100"], ["1202037301040633", "13135559101"], ["1720619402074074", "13135559102"], ["1030422235101467", "13135559103"], ["827238979523502", "13135559104"], ["1516443722284921", "13135559105"], ["1174442747196709", "13135559106"], ["1653165225503842", "13135559107"], ["1037648777635013", "13135559108"], ["551617757299900", "13135559109"], ["1158813558718726", "13135559110"], ["2463236450542262", "13135559111"], ["1550393252501466", "13135559112"], ["2057065188042796", "13135559113"], ["506163028760735", "13135559114"], ["2065249100538481", "13135559115"], ["1041382867195858", "13135559116"], ["886500209499603", "13135559117"], ["1491615624892655", "13135559118"], ["486563697299617", "13135559119"], ["1175736513679463", "13135559120"], ["491811473512352", "13165550064"]]);
12
- const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
13
- if (sepIdx < 0) {
14
- return jid;
15
- }
16
- const server = jid.slice(sepIdx + 1);
17
- if (server !== 'bot')
18
- return jid;
19
- const user = jid.slice(0, sepIdx);
20
- const mappedNumber = BOT_MAP.get(user);
21
- return mappedNumber ? `${mappedNumber}@s.whatsapp.net` : jid;
22
- };
23
- exports.getBotJid = getBotJid;
24
9
  const jidEncode = (user, server, device, agent) => {
25
10
  return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
26
11
  };
@@ -35,7 +20,7 @@ const jidDecode = (jid) => {
35
20
  const [userAgent, device] = userCombined.split(':');
36
21
  const user = userAgent.split('_')[0];
37
22
  return {
38
- server: server,
23
+ server,
39
24
  user,
40
25
  domainType: server === 'lid' ? 1 : 0,
41
26
  device: device ? +device : undefined
@@ -48,9 +33,6 @@ const areJidsSameUser = (jid1, jid2) => {
48
33
  return (((_a = (0, exports.jidDecode)(jid1)) === null || _a === void 0 ? void 0 : _a.user) === ((_b = (0, exports.jidDecode)(jid2)) === null || _b === void 0 ? void 0 : _b.user));
49
34
  };
50
35
  exports.areJidsSameUser = areJidsSameUser;
51
- /** is the jid Meta AI */
52
- const isJidMetaAI = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@bot'));
53
- exports.isJidMetaAI = isJidMetaAI;
54
36
  /** is the jid a user */
55
37
  const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
56
38
  exports.isJidUser = isJidUser;
@@ -69,9 +51,6 @@ exports.isJidGroup = isJidGroup;
69
51
  /** is the jid the status broadcast */
70
52
  const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
71
53
  exports.isJidStatusBroadcast = isJidStatusBroadcast;
72
- const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
73
- const isJidBot = (jid) => (jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us'));
74
- exports.isJidBot = isJidBot;
75
54
  const jidNormalizedUser = (jid) => {
76
55
  const result = (0, exports.jidDecode)(jid);
77
56
  if (!result) {
@@ -1,8 +1,18 @@
1
- import { EventInputType } from './constants';
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  export declare class BinaryInfo {
3
4
  protocolVersion: number;
4
5
  sequence: number;
5
- events: EventInputType[];
6
+ events: {
7
+ [x: string]: {
8
+ props: {
9
+ [x: string]: any;
10
+ };
11
+ globals: {
12
+ [x: string]: any;
13
+ };
14
+ };
15
+ }[];
6
16
  buffer: Buffer[];
7
17
  constructor(options?: Partial<BinaryInfo>);
8
18
  }
@@ -28,12 +28,11 @@ type EventByName<T extends Event['name']> = Extract<Event, {
28
28
  export type EventInputType = {
29
29
  [key in Event['name']]: {
30
30
  props: {
31
- [k in keyof EventByName<key>['props']]: Value;
31
+ [k in keyof EventByName<key>['props']]: any;
32
32
  };
33
33
  globals: {
34
- [x: string]: Value;
34
+ [x: string]: any;
35
35
  };
36
36
  };
37
37
  } & {};
38
- export type Value = number | null | string;
39
38
  export {};
@@ -1,2 +1,4 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { BinaryInfo } from './BinaryInfo';
2
- export declare const encodeWAM: (binaryInfo: BinaryInfo) => Buffer<ArrayBuffer>;
4
+ export declare const encodeWAM: (binaryInfo: BinaryInfo) => Buffer;
package/lib/WAM/encode.js CHANGED
@@ -13,10 +13,10 @@ const encodeWAM = (binaryInfo) => {
13
13
  .reduce((a, b) => a + b);
14
14
  const buffer = Buffer.alloc(totalSize);
15
15
  let offset = 0;
16
- for (const buffer_ of binaryInfo.buffer) {
16
+ binaryInfo.buffer.forEach((buffer_) => {
17
17
  buffer_.copy(buffer, offset);
18
18
  offset += buffer_.length;
19
- }
19
+ });
20
20
  return buffer;
21
21
  };
22
22
  exports.encodeWAM = encodeWAM;
@@ -9,7 +9,7 @@ class USyncContactProtocol {
9
9
  getQueryElement() {
10
10
  return {
11
11
  tag: 'contact',
12
- attrs: {}
12
+ attrs: {},
13
13
  };
14
14
  }
15
15
  getUserElement(user) {
@@ -17,7 +17,7 @@ class USyncContactProtocol {
17
17
  return {
18
18
  tag: 'contact',
19
19
  attrs: {},
20
- content: user.phone
20
+ content: user.phone,
21
21
  };
22
22
  }
23
23
  parser(node) {
@@ -10,8 +10,8 @@ class USyncDeviceProtocol {
10
10
  return {
11
11
  tag: 'devices',
12
12
  attrs: {
13
- version: '2'
14
- }
13
+ version: '2',
14
+ },
15
15
  };
16
16
  }
17
17
  getUserElement( /* user: USyncUser */) {
@@ -9,7 +9,7 @@ class USyncDisappearingModeProtocol {
9
9
  getQueryElement() {
10
10
  return {
11
11
  tag: 'disappearing_mode',
12
- attrs: {}
12
+ attrs: {},
13
13
  };
14
14
  }
15
15
  getUserElement() {
@@ -22,7 +22,7 @@ class USyncDisappearingModeProtocol {
22
22
  const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
23
23
  return {
24
24
  duration,
25
- setAt
25
+ setAt,
26
26
  };
27
27
  }
28
28
  }