mod-baileys 1.0.2 → 2.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 (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -61
  3. package/lib/Defaults/constants.js +74 -0
  4. package/lib/Defaults/index.d.ts +53 -0
  5. package/lib/Defaults/index.js +6 -6
  6. package/lib/Defaults/media.js +48 -0
  7. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  8. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  9. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  10. package/lib/Signal/Group/index.d.ts +11 -0
  11. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  12. package/lib/Signal/Group/queue-job.d.ts +1 -0
  13. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  14. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  15. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  16. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  17. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  18. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  19. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  20. package/lib/Signal/libsignal.d.ts +3 -0
  21. package/lib/Signal/libsignal.js +5 -5
  22. package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
  23. package/lib/Socket/Client/index.d.ts +3 -0
  24. package/lib/Socket/Client/index.js +3 -3
  25. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  26. package/lib/Socket/Client/mobile-socket-client.js +1 -1
  27. package/lib/Socket/Client/web-socket-client.d.ts +12 -0
  28. package/lib/Socket/Client/web-socket-client.js +2 -2
  29. package/lib/Socket/business.d.ts +171 -0
  30. package/lib/Socket/chats.d.ts +267 -0
  31. package/lib/Socket/groups.d.ts +115 -0
  32. package/lib/Socket/groups.js +6 -6
  33. package/lib/Socket/index.d.ts +173 -0
  34. package/lib/Socket/index.js +2 -2
  35. package/lib/Socket/luxu.d.ts +268 -0
  36. package/lib/Socket/{dew.js → luxu.js} +11 -11
  37. package/lib/Socket/messages-recv.d.ts +161 -0
  38. package/lib/Socket/messages-send.d.ts +149 -0
  39. package/lib/Socket/messages-send.js +10 -10
  40. package/lib/Socket/newsletter.d.ts +134 -0
  41. package/lib/Socket/newsletter.js +5 -8
  42. package/lib/Socket/registration.d.ts +267 -0
  43. package/lib/Socket/registration.js +4 -4
  44. package/lib/Socket/socket.d.ts +43 -0
  45. package/lib/Socket/socket.js +10 -9
  46. package/lib/Socket/usync.d.ts +36 -0
  47. package/lib/Store/index.d.ts +3 -0
  48. package/lib/Store/index.js +2 -2
  49. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  50. package/lib/Store/make-cache-manager-store.js +3 -3
  51. package/lib/Store/make-in-memory-store.d.ts +118 -0
  52. package/lib/Store/make-in-memory-store.js +7 -7
  53. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  54. package/lib/Store/object-repository.d.ts +10 -0
  55. package/lib/Types/Auth.d.ts +110 -0
  56. package/lib/Types/Call.d.ts +13 -0
  57. package/lib/Types/Chat.d.ts +102 -0
  58. package/lib/Types/Contact.d.ts +19 -0
  59. package/lib/Types/Events.d.ts +157 -0
  60. package/lib/Types/GroupMetadata.d.ts +55 -0
  61. package/lib/Types/Label.d.ts +35 -0
  62. package/lib/Types/LabelAssociation.d.ts +29 -0
  63. package/lib/Types/Message.d.ts +273 -0
  64. package/lib/Types/Message.js +1 -1
  65. package/lib/Types/Newsletter.d.ts +103 -0
  66. package/lib/Types/Product.d.ts +78 -0
  67. package/lib/Types/Signal.d.ts +57 -0
  68. package/lib/Types/Socket.d.ts +111 -0
  69. package/lib/Types/State.d.ts +27 -0
  70. package/lib/Types/USync.d.ts +25 -0
  71. package/lib/Types/index.d.ts +57 -0
  72. package/lib/Types/index.js +12 -12
  73. package/lib/Utils/auth-utils.d.ts +18 -0
  74. package/lib/Utils/auth-utils.js +3 -3
  75. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  76. package/lib/Utils/baileys-event-stream.js +2 -2
  77. package/lib/Utils/business.d.ts +22 -0
  78. package/lib/Utils/chat-utils.d.ts +71 -0
  79. package/lib/Utils/chat-utils.js +7 -7
  80. package/lib/Utils/crypto.d.ts +41 -0
  81. package/lib/Utils/crypto.js +1 -1
  82. package/lib/Utils/decode-wa-message.d.ts +19 -0
  83. package/lib/Utils/decode-wa-message.js +3 -3
  84. package/lib/Utils/event-buffer.d.ts +35 -0
  85. package/lib/Utils/event-buffer.js +4 -4
  86. package/lib/Utils/generics.d.ts +92 -0
  87. package/lib/Utils/generics.js +5 -5
  88. package/lib/Utils/history.d.ts +15 -0
  89. package/lib/Utils/history.js +6 -6
  90. package/lib/Utils/index.d.ts +17 -0
  91. package/lib/Utils/index.js +17 -17
  92. package/lib/Utils/link-preview.d.ts +21 -0
  93. package/lib/Utils/link-preview.js +2 -2
  94. package/lib/Utils/logger.d.ts +4 -0
  95. package/lib/Utils/lt-hash.d.ts +12 -0
  96. package/lib/Utils/lt-hash.js +1 -1
  97. package/lib/Utils/make-mutex.d.ts +7 -0
  98. package/lib/Utils/messages-media.d.ts +116 -0
  99. package/lib/Utils/messages-media.js +837 -548
  100. package/lib/Utils/messages.d.ts +77 -0
  101. package/lib/Utils/messages.js +1539 -497
  102. package/lib/Utils/noise-handler.d.ts +21 -0
  103. package/lib/Utils/noise-handler.js +4 -4
  104. package/lib/Utils/process-message.d.ts +41 -0
  105. package/lib/Utils/process-message.js +7 -7
  106. package/lib/Utils/signal.d.ts +32 -0
  107. package/lib/Utils/signal.js +4 -4
  108. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  109. package/lib/Utils/use-multi-file-auth-state.js +3 -3
  110. package/lib/Utils/validate-connection.d.ts +11 -0
  111. package/lib/Utils/validate-connection.js +6 -6
  112. package/lib/WABinary/constants.d.ts +30 -0
  113. package/lib/WABinary/decode.d.ts +7 -0
  114. package/lib/WABinary/decode.js +2 -2
  115. package/lib/WABinary/encode.d.ts +3 -0
  116. package/lib/WABinary/encode.js +2 -2
  117. package/lib/WABinary/generic-utils.d.ts +17 -0
  118. package/lib/WABinary/generic-utils.js +2 -2
  119. package/lib/WABinary/index.d.ts +5 -0
  120. package/lib/WABinary/index.js +5 -5
  121. package/lib/WABinary/jid-utils.d.ts +31 -0
  122. package/lib/WABinary/jid-utils.js +3 -0
  123. package/lib/WABinary/types.d.ts +18 -0
  124. package/lib/WAM/BinaryInfo.d.ts +17 -0
  125. package/lib/WAM/constants.d.ts +38 -0
  126. package/lib/WAM/encode.d.ts +3 -0
  127. package/lib/WAM/encode.js +1 -1
  128. package/lib/WAM/index.d.ts +3 -0
  129. package/lib/WAM/index.js +3 -3
  130. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -3
  131. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
  132. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
  133. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
  134. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -3
  135. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +2 -2
  136. package/lib/WAUSync/Protocols/index.d.ts +4 -4
  137. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  138. package/lib/WAUSync/USyncQuery.js +4 -4
  139. package/lib/WAUSync/USyncUser.d.ts +12 -0
  140. package/lib/WAUSync/index.js +3 -3
  141. package/lib/index.d.ts +12 -0
  142. package/lib/index.js +10 -18
  143. package/lib/temp +1 -0
  144. package/package.json +5 -5
@@ -0,0 +1,21 @@
1
+ /// <reference types="node" />
2
+ import { Logger } from 'pino';
3
+ import { proto } from '../../WAProto';
4
+ import { KeyPair } from '../Types';
5
+ import { BinaryNode } from '../WABinary';
6
+ export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }: {
7
+ keyPair: KeyPair;
8
+ NOISE_HEADER: Uint8Array;
9
+ mobile: boolean;
10
+ logger: Logger;
11
+ routingInfo?: Buffer | undefined;
12
+ }) => {
13
+ encrypt: (plaintext: Uint8Array) => Buffer;
14
+ decrypt: (ciphertext: Uint8Array) => Buffer;
15
+ authenticate: (data: Uint8Array) => void;
16
+ mixIntoKey: (data: Uint8Array) => void;
17
+ finishInit: () => void;
18
+ processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Buffer;
19
+ encodeFrame: (data: Buffer | Uint8Array) => Buffer;
20
+ decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => void;
21
+ };
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeNoiseHandler = void 0;
4
4
  const boom_1 = require("@hapi/boom");
5
- const WAProto_1 = require("mod-baileys/WAProto");
6
- const Defaults_1 = require("mod-baileys/lib/Defaults");
7
- const WABinary_1 = require("mod-baileys/lib/WABinary");
8
- const crypto_1 = require("mod-baileys/lib/Utils/crypto");
5
+ const WAProto_1 = require("../../WAProto");
6
+ const Defaults_1 = require("../Defaults");
7
+ const WABinary_1 = require("../WABinary");
8
+ const crypto_1 = require("./crypto");
9
9
  const generateIV = (counter) => {
10
10
  const iv = new ArrayBuffer(12);
11
11
  new DataView(iv).setUint32(8, counter);
@@ -0,0 +1,41 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import type { Logger } from 'pino';
3
+ import { proto } from '../../WAProto';
4
+ import { AuthenticationCreds, BaileysEventEmitter, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
5
+ type ProcessMessageContext = {
6
+ shouldProcessHistoryMsg: boolean;
7
+ creds: AuthenticationCreds;
8
+ keyStore: SignalKeyStoreWithTransaction;
9
+ ev: BaileysEventEmitter;
10
+ getMessage: SocketConfig['getMessage'];
11
+ logger?: Logger;
12
+ options: AxiosRequestConfig<{}>;
13
+ };
14
+ /** Cleans a received message to further processing */
15
+ export declare const cleanMessage: (message: proto.IWebMessageInfo, meId: string) => void;
16
+ export declare const isRealMessage: (message: proto.IWebMessageInfo, meId: string) => boolean | undefined;
17
+ export declare const shouldIncrementChatUnread: (message: proto.IWebMessageInfo) => boolean;
18
+ /**
19
+ * Get the ID of the chat from the given key.
20
+ * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
21
+ */
22
+ export declare const getChatId: ({ remoteJid, participant, fromMe }: proto.IMessageKey) => string;
23
+ type PollContext = {
24
+ /** normalised jid of the person that created the poll */
25
+ pollCreatorJid: string;
26
+ /** ID of the poll creation message */
27
+ pollMsgId: string;
28
+ /** poll creation message enc key */
29
+ pollEncKey: Uint8Array;
30
+ /** jid of the person that voted */
31
+ voterJid: string;
32
+ };
33
+ /**
34
+ * Decrypt a poll vote
35
+ * @param vote encrypted vote
36
+ * @param ctx additional info about the poll required for decryption
37
+ * @returns list of SHA256 options
38
+ */
39
+ export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: PollContext): proto.Message.PollVoteMessage;
40
+ declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
41
+ export default processMessage;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decryptPollVote = exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
4
- const WAProto_1 = require("mod-baileys/WAProto");
5
- const Types_1 = require("mod-baileys/lib/Types");
6
- const messages_1 = require("mod-baileys/lib/Utils/messages");
7
- const WABinary_1 = require("mod-baileys/lib/WABinary");
8
- const crypto_1 = require("mod-baileys/lib/Utils/crypto");
9
- const generics_1 = require("mod-baileys/lib/Utils/generics");
10
- const history_1 = require("mod-baileys/lib/Utils/history");
4
+ const WAProto_1 = require("../../WAProto");
5
+ const Types_1 = require("../Types");
6
+ const messages_1 = require("../Utils/messages");
7
+ const WABinary_1 = require("../WABinary");
8
+ const crypto_1 = require("./crypto");
9
+ const generics_1 = require("./generics");
10
+ const history_1 = require("./history");
11
11
  const REAL_MSG_STUB_TYPES = new Set([
12
12
  Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
13
13
  Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE,
@@ -0,0 +1,32 @@
1
+ import { SignalRepository } from '../Types';
2
+ import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth';
3
+ import { BinaryNode, JidWithDevice } from '../WABinary';
4
+ export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
5
+ export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
6
+ [id: string]: KeyPair;
7
+ }>;
8
+ export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: number) => {
9
+ newPreKeys: {
10
+ [id: number]: KeyPair;
11
+ };
12
+ lastPreKeyId: number;
13
+ preKeysRange: readonly [number, number];
14
+ };
15
+ export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
16
+ export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
17
+ export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>;
18
+ export declare const extractDeviceJids: (result: BinaryNode, myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
19
+ /**
20
+ * get the next N keys for upload or processing
21
+ * @param count number of pre-keys to get or generate
22
+ */
23
+ export declare const getNextPreKeys: ({ creds, keys }: AuthenticationState, count: number) => Promise<{
24
+ update: Partial<AuthenticationCreds>;
25
+ preKeys: {
26
+ [id: string]: KeyPair;
27
+ };
28
+ }>;
29
+ export declare const getNextPreKeysNode: (state: AuthenticationState, count: number) => Promise<{
30
+ update: Partial<AuthenticationCreds>;
31
+ node: BinaryNode;
32
+ }>;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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("mod-baileys/lib/Defaults");
5
- const WABinary_1 = require("mod-baileys/lib/WABinary");
6
- const crypto_1 = require("mod-baileys/lib/Utils/crypto");
4
+ const Defaults_1 = require("../Defaults");
5
+ const WABinary_1 = require("../WABinary");
6
+ const crypto_1 = require("./crypto");
7
7
  const lodash_1 = require("lodash")
8
- const generics_1 = require("mod-baileys/lib/Utils/generics");
8
+ const generics_1 = require("./generics");
9
9
  const createSignalIdentity = (wid, accountSignatureKey) => {
10
10
  return {
11
11
  identifier: { name: wid, deviceId: 0 },
@@ -0,0 +1,13 @@
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
+
@@ -4,9 +4,9 @@ exports.useMultiFileAuthState = void 0;
4
4
  const async_mutex_1 = require("async-mutex");
5
5
  const promises_1 = require("fs/promises");
6
6
  const path_1 = require("path");
7
- const WAProto_1 = require("mod-baileys/WAProto");
8
- const auth_utils_1 = require("mod-baileys/lib/Utils/auth-utils");
9
- const generics_1 = require("mod-baileys/lib/Utils/generics");
7
+ const WAProto_1 = require("../../WAProto");
8
+ const auth_utils_1 = require("./auth-utils");
9
+ const generics_1 = require("./generics");
10
10
  const fileLocks = new Map();
11
11
  const getFileLock = (path) => {
12
12
  let mutex = fileLocks.get(path);
@@ -0,0 +1,11 @@
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;
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
4
4
  const boom_1 = require("@hapi/boom");
5
5
  const crypto_1 = require("crypto");
6
- const WAProto_1 = require("mod-baileys/WAProto");
7
- const Defaults_1 = require("mod-baileys/lib/Defaults");
8
- const WABinary_1 = require("mod-baileys/lib/WABinary");
9
- const crypto_2 = require("mod-baileys/lib/Utils/crypto");
10
- const generics_1 = require("mod-baileys/lib/Utils/generics");
11
- const signal_1 = require("mod-baileys/lib/Utils/signal");
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
12
 
13
13
  const getUserAgent = (config) => {
14
14
  return {
@@ -0,0 +1,30 @@
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
+ }
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ import type { BinaryNode, BinaryNodeCodingOptions } from './types';
3
+ 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?: {
5
+ index: number;
6
+ }) => BinaryNode;
7
+ export declare const decodeBinaryNode: (buff: Buffer) => BinaryNode;
@@ -25,8 +25,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
27
27
  const zlib_1 = require("zlib");
28
- const constants = __importStar(require("mod-baileys/lib/WABinary/constants"));
29
- const jid_utils_1 = require("mod-baileys/lib/WABinary/jid-utils");
28
+ const constants = __importStar(require("./constants"));
29
+ const jid_utils_1 = require("./jid-utils");
30
30
  const decompressingIfRequired = (buffer) => {
31
31
  if (2 & buffer.readUInt8()) {
32
32
  buffer = (0, zlib_1.inflateSync)(buffer.slice(1));
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ import type { BinaryNode, BinaryNodeCodingOptions } from './types';
3
+ export declare const encodeBinaryNode: ({ tag, attrs, content }: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) => Buffer;
@@ -28,8 +28,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
28
28
 
29
29
  Object.defineProperty(exports, "__esModule", { value: true })
30
30
 
31
- const constants = __importStar(require("mod-baileys/lib/WABinary/constants"))
32
- const jid_utils_1 = require("mod-baileys/lib/WABinary/jid-utils")
31
+ const constants = __importStar(require("./constants"))
32
+ const jid_utils_1 = require("./jid-utils")
33
33
 
34
34
  const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
35
35
  const encoded = encodeBinaryNodeInner(node, opts, buffer)
@@ -0,0 +1,17 @@
1
+ /// <reference types="node" />
2
+ import { proto } from '../../WAProto';
3
+ import { BinaryNode } from './types';
4
+ export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[];
5
+ export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
6
+ 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;
9
+ export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
10
+ export declare const assertNodeErrorFree: (node: BinaryNode) => void;
11
+ export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: string) => {
12
+ [_: string]: string;
13
+ };
14
+ export declare const getBinaryNodeMessages: ({ content }: BinaryNode) => proto.WebMessageInfo[];
15
+ export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'], i?: number): any;
16
+ export declare const getBinaryNodeFilter: (node: BinaryNode[]) => boolean;
17
+ export declare const getAdditionalNode: (name: string) => BinaryNode[];
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAdditionalNode = exports.getBinaryNodeFilter = exports.binaryNodeToString = exports.getBinaryNodeMessages = exports.reduceBinaryNodeToDictionary = exports.assertNodeErrorFree = exports.getBinaryNodeChildUInt = exports.getBinaryNodeChildString = exports.getBinaryNodeChildBuffer = exports.getBinaryNodeChild = exports.getAllBinaryNodeChildren = exports.getBinaryNodeChildren = void 0;
4
4
  const boom_1 = require("@hapi/boom");
5
- const WAProto_1 = require("mod-baileys/WAProto");
6
- const Utils_1 = require("mod-baileys/lib/Utils")
5
+ const WAProto_1 = require("../../WAProto");
6
+ const Utils_1 = require("../Utils")
7
7
  // some extra useful utilities
8
8
  const getBinaryNodeChildren = (node, childTag) => {
9
9
  if (Array.isArray(node?.content)) {
@@ -0,0 +1,5 @@
1
+ export * from './encode';
2
+ export * from './decode';
3
+ export * from './generic-utils';
4
+ export * from './jid-utils';
5
+ export * from './types';
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("mod-baileys/lib/WABinary/encode"), exports);
18
- __exportStar(require("mod-baileys/lib/WABinary/decode"), exports);
19
- __exportStar(require("mod-baileys/lib/WABinary/generic-utils"), exports);
20
- __exportStar(require("mod-baileys/lib/WABinary/jid-utils"), exports);
21
- __exportStar(require("mod-baileys/lib/WABinary/types"), exports);
17
+ __exportStar(require("./encode"), exports);
18
+ __exportStar(require("./decode"), exports);
19
+ __exportStar(require("./generic-utils"), exports);
20
+ __exportStar(require("./jid-utils"), exports);
21
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,31 @@
1
+ export declare const S_WHATSAPP_NET = "@s.whatsapp.net";
2
+ export declare const OFFICIAL_BIZ_JID = "16505361212@c.us";
3
+ export declare const SERVER_JID = "server@c.us";
4
+ export declare const PSA_WID = "0@c.us";
5
+ export declare const STORIES_JID = "status@broadcast";
6
+ export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' | 'newsletter';
7
+ export type JidWithDevice = {
8
+ user: string;
9
+ device?: number;
10
+ };
11
+ export type FullJid = JidWithDevice & {
12
+ server: JidServer | string;
13
+ domainType?: number;
14
+ };
15
+ export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
16
+ export declare const jidDecode: (jid: string | undefined) => FullJid | undefined;
17
+ /** is the jid a user */
18
+ export declare const areJidsSameUser: (jid1: string | undefined, jid2: string | undefined) => boolean;
19
+ /** is the jid a user */
20
+ export declare const isJidUser: (jid: string | undefined) => boolean | undefined;
21
+ /** is the jid a group */
22
+ export declare const isLidUser: (jid: string | undefined) => boolean | undefined;
23
+ /** is the jid a broadcast */
24
+ export declare const isJidBroadcast: (jid: string | undefined) => boolean | undefined;
25
+ /** is the jid a group */
26
+ export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
27
+ /** is the jid the status broadcast */
28
+ export declare const isJidStatusBroadcast: (jid: string) => boolean;
29
+ /** is the jid the newsletter */
30
+ export declare const isJidNewsLetter: (jid: string | undefined) => boolean | undefined;
31
+ export declare const jidNormalizedUser: (jid: string | undefined) => string;
@@ -49,6 +49,9 @@ exports.isJidGroup = isJidGroup;
49
49
  const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
50
50
  exports.isJidStatusBroadcast = isJidStatusBroadcast;
51
51
  /** is the jid the newsletter */
52
+ const isJidNewsletter = (jid) => jid?.endsWith('@newsletter')
53
+ exports.isJidNewsletter = isJidNewsletter;
54
+
52
55
  const isJidNewsLetter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('newsletter'));
53
56
  exports.isJidNewsLetter = isJidNewsLetter;
54
57
  const jidNormalizedUser = (jid) => {
@@ -0,0 +1,18 @@
1
+ import * as constants from './constants';
2
+ /**
3
+ * the binary node WA uses internally for communication
4
+ *
5
+ * this is manipulated soley as an object and it does not have any functions.
6
+ * This is done for easy serialization, to prevent running into issues with prototypes &
7
+ * to maintain functional code structure
8
+ * */
9
+ export type BinaryNode = {
10
+ tag: string;
11
+ attrs: {
12
+ [key: string]: string;
13
+ };
14
+ content?: BinaryNode[] | string | Uint8Array;
15
+ };
16
+ export type BinaryNodeAttributes = BinaryNode['attrs'];
17
+ export type BinaryNodeData = BinaryNode['content'];
18
+ export type BinaryNodeCodingOptions = typeof constants;
@@ -0,0 +1,17 @@
1
+ /// <reference types="node" />
2
+ export declare class BinaryInfo {
3
+ protocolVersion: number;
4
+ sequence: number;
5
+ events: {
6
+ [x: string]: {
7
+ props: {
8
+ [x: string]: any;
9
+ };
10
+ globals: {
11
+ [x: string]: any;
12
+ };
13
+ };
14
+ }[];
15
+ buffer: Buffer[];
16
+ constructor(options?: Partial<BinaryInfo>);
17
+ }
@@ -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 {};
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ import { BinaryInfo } from './BinaryInfo';
3
+ export declare const encodeWAM: (binaryInfo: BinaryInfo) => Buffer;
package/lib/WAM/encode.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.encodeWAM = void 0;
4
- const constants_1 = require("mod-baileys/lib/WAM/constants");
4
+ const constants_1 = require("./constants");
5
5
  const getHeaderBitLength = (key) => (key < 256 ? 2 : 3);
6
6
  const encodeWAM = (binaryInfo) => {
7
7
  binaryInfo.buffer = [];
@@ -0,0 +1,3 @@
1
+ export * from './constants';
2
+ export * from './encode';
3
+ export * from './BinaryInfo';
package/lib/WAM/index.js CHANGED
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("mod-baileys/lib/WAM/constants"), exports);
18
- __exportStar(require("mod-baileys/lib/WAM/encode"), exports);
19
- __exportStar(require("mod-baileys/lib/WAM/BinaryInfo"), exports);
17
+ __exportStar(require("./constants"), exports);
18
+ __exportStar(require("./encode"), exports);
19
+ __exportStar(require("./BinaryInfo"), exports);
@@ -1,6 +1,6 @@
1
- import { USyncQueryProtocol } from 'mod-baileys/lib/Types/USync';
2
- import { BinaryNode } from 'mod-baileys/lib/WABinary';
3
- import { USyncUser } from 'mod-baileys/lib/WAUSync/USyncUser';
1
+ import { USyncQueryProtocol } from '../../Types/USync';
2
+ import { BinaryNode } from '../../WABinary';
3
+ import { USyncUser } from '../USyncUser';
4
4
  export declare class USyncContactProtocol implements USyncQueryProtocol {
5
5
  name: string;
6
6
  getQueryElement(): BinaryNode;
@@ -1,5 +1,5 @@
1
- import { USyncQueryProtocol } from 'mod-baileys/lib/Types/USync';
2
- import { BinaryNode } from 'mod-baileys/lib/WABinary';
1
+ import { USyncQueryProtocol } from '../../Types/USync';
2
+ import { BinaryNode } from '../../WABinary';
3
3
  export type KeyIndexData = {
4
4
  timestamp: number;
5
5
  signedKeyIndex?: Uint8Array;
@@ -1,5 +1,5 @@
1
- import { USyncQueryProtocol } from 'mod-baileys/lib/Types/USync';
2
- import { BinaryNode } from 'mod-baileys/lib/WABinary';
1
+ import { USyncQueryProtocol } from '../../Types/USync';
2
+ import { BinaryNode } from '../../WABinary';
3
3
  export type DisappearingModeData = {
4
4
  duration: number;
5
5
  setAt?: Date;
@@ -1,5 +1,5 @@
1
- import { USyncQueryProtocol } from 'mod-baileys/lib/Types/USync';
2
- import { BinaryNode } from 'mod-baileys/lib/WABinary';
1
+ import { USyncQueryProtocol } from '../../Types/USync';
2
+ import { BinaryNode } from '../../WABinary';
3
3
  export type StatusData = {
4
4
  status?: string | null;
5
5
  setAt?: Date;
@@ -1,6 +1,6 @@
1
- import { USyncQueryProtocol } from 'mod-baileys/lib/Types/USync';
2
- import { BinaryNode } from 'mod-baileys/lib/WABinary';
3
- import { USyncUser } from 'mod-baileys/lib/WAUSync/USyncUser';
1
+ import { USyncQueryProtocol } from '../../Types/USync';
2
+ import { BinaryNode } from '../../WABinary';
3
+ import { USyncUser } from '../USyncUser';
4
4
  export type BotProfileCommand = {
5
5
  name: string;
6
6
  description: string;
@@ -1,5 +1,5 @@
1
- import { USyncQueryProtocol } from 'mod-baileys/lib/Types/USync';
2
- import { BinaryNode } from 'mod-baileys/lib/WABinary';
1
+ import { USyncQueryProtocol } from '../../Types/USync';
2
+ import { BinaryNode } from '../../WABinary';
3
3
  export declare class USyncLIDProtocol implements USyncQueryProtocol {
4
4
  name: string;
5
5
  getQueryElement(): BinaryNode;
@@ -1,4 +1,4 @@
1
- export * from 'mod-baileys/lib/WAUSync/Protocols/USyncDeviceProtocol';
2
- export * from 'mod-baileys/lib/WAUSync/Protocols/USyncContactProtocol';
3
- export * from 'mod-baileys/lib/WAUSync/Protocols/USyncStatusProtocol';
4
- export * from 'mod-baileys/lib/WAUSync/Protocols/USyncDisappearingModeProtocol';
1
+ export * from './USyncDeviceProtocol';
2
+ export * from './USyncContactProtocol';
3
+ export * from './USyncStatusProtocol';
4
+ export * from './USyncDisappearingModeProtocol';
@@ -0,0 +1,28 @@
1
+ import { USyncQueryProtocol } from '../Types/USync';
2
+ import { BinaryNode } from '../WABinary';
3
+ import { USyncUser } from './USyncUser';
4
+ export type USyncQueryResultList = {
5
+ [protocol: string]: unknown;
6
+ id: string;
7
+ };
8
+ export type USyncQueryResult = {
9
+ list: USyncQueryResultList[];
10
+ sideList: USyncQueryResultList[];
11
+ };
12
+ export declare class USyncQuery {
13
+ protocols: USyncQueryProtocol[];
14
+ users: USyncUser[];
15
+ context: string;
16
+ mode: string;
17
+ constructor();
18
+ withMode(mode: string): this;
19
+ withContext(context: string): this;
20
+ withUser(user: USyncUser): this;
21
+ parseUSyncQueryResult(result: BinaryNode): USyncQueryResult | undefined;
22
+ withDeviceProtocol(): this;
23
+ withContactProtocol(): this;
24
+ withStatusProtocol(): this;
25
+ withDisappearingModeProtocol(): this;
26
+ withBotProfileProtocol(): this;
27
+ withLIDProtocol(): this;
28
+ }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.USyncQuery = void 0;
4
- const WABinary_1 = require("mod-baileys/lib/WABinary");
5
- const UsyncBotProfileProtocol_1 = require("mod-baileys/lib/WAUSync/Protocols/UsyncBotProfileProtocol");
6
- const UsyncLIDProtocol_1 = require("mod-baileys/lib/WAUSync/Protocols/UsyncLIDProtocol");
7
- const Protocols_1 = require("mod-baileys/lib/WAUSync/Protocols");
4
+ const WABinary_1 = require("../WABinary");
5
+ const UsyncBotProfileProtocol_1 = require("./Protocols/UsyncBotProfileProtocol");
6
+ const UsyncLIDProtocol_1 = require("./Protocols/UsyncLIDProtocol");
7
+ const Protocols_1 = require("./Protocols");
8
8
  class USyncQuery {
9
9
  constructor() {
10
10
  this.protocols = [];
@@ -0,0 +1,12 @@
1
+ export declare class USyncUser {
2
+ id: string;
3
+ lid: string;
4
+ phone: string;
5
+ type: string;
6
+ personaId: string;
7
+ withId(id: string): this;
8
+ withLid(lid: string): this;
9
+ withPhone(phone: string): this;
10
+ withType(type: string): this;
11
+ withPersonaId(personaId: string): this;
12
+ }
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("mod-baileys/lib/WAUSync/Protocols"), exports);
18
- __exportStar(require("mod-baileys/lib/WAUSync/USyncQuery"), exports);
19
- __exportStar(require("mod-baileys/lib/WAUSync/USyncUser"), exports);
17
+ __exportStar(require("./Protocols"), exports);
18
+ __exportStar(require("./USyncQuery"), exports);
19
+ __exportStar(require("./USyncUser"), exports);