@mrlegendbot/baileys 1.2.1 → 1.2.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 (212) hide show
  1. package/README.upstream.md +1312 -0
  2. package/WAProto/WAProto.json +1 -0
  3. package/WAProto/WAProto.proto +6275 -0
  4. package/WAProto/compiler.js +550 -0
  5. package/WAProto/index.js +2 -97691
  6. package/lib/Defaults/index.js +89 -92
  7. package/lib/Signal/Group/ciphertext-message.js +9 -10
  8. package/lib/Signal/Group/group-session-builder.js +21 -22
  9. package/lib/Signal/Group/group_cipher.js +75 -69
  10. package/lib/Signal/Group/index.js +0 -1
  11. package/lib/Signal/Group/keyhelper.js +9 -10
  12. package/lib/Signal/Group/sender-chain-key.js +21 -22
  13. package/lib/Signal/Group/sender-key-distribution-message.js +51 -60
  14. package/lib/Signal/Group/sender-key-message.js +56 -62
  15. package/lib/Signal/Group/sender-key-name.js +38 -40
  16. package/lib/Signal/Group/sender-key-record.js +33 -34
  17. package/lib/Signal/Group/sender-key-state.js +72 -76
  18. package/lib/Signal/Group/sender-message-key.js +22 -23
  19. package/lib/Signal/libsignal.js +506 -405
  20. package/lib/Signal/lid-mapping.js +276 -258
  21. package/lib/Socket/Client/index.js +0 -1
  22. package/lib/Socket/Client/types.js +6 -7
  23. package/lib/Socket/Client/websocket.js +48 -49
  24. package/lib/Socket/business.js +349 -369
  25. package/lib/Socket/chats.js +1172 -1148
  26. package/lib/Socket/communities.js +473 -413
  27. package/lib/Socket/groups.js +387 -331
  28. package/lib/Socket/index.js +6 -8
  29. package/lib/Socket/messages-recv.js +1782 -1719
  30. package/lib/Socket/messages-send.js +1503 -2450
  31. package/lib/Socket/mex.js +40 -35
  32. package/lib/Socket/newsletter.js +239 -191
  33. package/lib/Socket/socket.js +992 -923
  34. package/lib/Store/index.js +8 -0
  35. package/lib/Store/keyed-db.js +108 -0
  36. package/lib/Store/make-cache-manager-store.js +70 -0
  37. package/lib/Store/make-in-memory-store.js +417 -0
  38. package/lib/Store/make-ordered-dictionary.js +69 -0
  39. package/lib/Store/object-repository.js +27 -0
  40. package/lib/Types/Auth.js +0 -1
  41. package/lib/Types/Bussines.js +0 -1
  42. package/lib/Types/Call.js +0 -1
  43. package/lib/Types/Chat.js +1 -8
  44. package/lib/Types/Contact.js +0 -1
  45. package/lib/Types/Events.js +1 -2
  46. package/lib/Types/GroupMetadata.js +0 -1
  47. package/lib/Types/Label.js +20 -22
  48. package/lib/Types/LabelAssociation.js +2 -4
  49. package/lib/Types/Message.js +3 -5
  50. package/lib/Types/Mex.js +26 -31
  51. package/lib/Types/Product.js +0 -1
  52. package/lib/Types/Signal.js +1 -2
  53. package/lib/Types/Socket.js +2 -3
  54. package/lib/Types/State.js +4 -52
  55. package/lib/Types/USync.js +0 -1
  56. package/lib/Types/index.js +10 -11
  57. package/lib/Utils/auth-utils.js +240 -277
  58. package/lib/Utils/browser-utils.js +20 -23
  59. package/lib/Utils/business.js +200 -204
  60. package/lib/Utils/chat-utils.js +836 -810
  61. package/lib/Utils/companion-reg-client-utils.js +23 -25
  62. package/lib/Utils/crypto.js +70 -86
  63. package/lib/Utils/decode-wa-message.js +277 -284
  64. package/lib/Utils/event-buffer.js +592 -595
  65. package/lib/Utils/generics.js +312 -335
  66. package/lib/Utils/history.js +123 -115
  67. package/lib/Utils/index.js +1 -2
  68. package/lib/Utils/link-preview.js +74 -73
  69. package/lib/Utils/logger.js +3 -2
  70. package/lib/Utils/lt-hash.js +0 -6
  71. package/lib/Utils/make-mutex.js +27 -27
  72. package/lib/Utils/message-retry-manager.js +213 -254
  73. package/lib/Utils/messages-media.js +741 -715
  74. package/lib/Utils/messages.js +791 -827
  75. package/lib/Utils/noise-handler.js +215 -187
  76. package/lib/Utils/pre-key-manager.js +69 -98
  77. package/lib/Utils/process-message.js +617 -586
  78. package/lib/Utils/reporting-utils.js +553 -234
  79. package/lib/Utils/signal.js +217 -170
  80. package/lib/Utils/stanza-ack.js +27 -35
  81. package/lib/Utils/sync-action-utils.js +37 -41
  82. package/lib/Utils/tc-token-utils.js +120 -141
  83. package/lib/Utils/use-multi-file-auth-state.js +87 -105
  84. package/lib/Utils/use-sqlite-auth-state.js +162 -0
  85. package/lib/Utils/validate-connection.js +190 -188
  86. package/lib/WABinary/constants.js +28 -1294
  87. package/lib/WABinary/decode.js +245 -249
  88. package/lib/WABinary/encode.js +201 -206
  89. package/lib/WABinary/generic-utils.js +86 -89
  90. package/lib/WABinary/index.js +0 -1
  91. package/lib/WABinary/jid-utils.js +68 -77
  92. package/lib/WABinary/types.js +0 -1
  93. package/lib/WAM/BinaryInfo.js +7 -8
  94. package/lib/WAM/constants.js +19892 -22853
  95. package/lib/WAM/encode.js +121 -132
  96. package/lib/WAM/index.js +0 -1
  97. package/lib/WAUSync/Protocols/USyncContactProtocol.js +46 -43
  98. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +47 -48
  99. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -23
  100. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -33
  101. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -20
  102. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -44
  103. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
  104. package/lib/WAUSync/Protocols/index.js +0 -1
  105. package/lib/WAUSync/USyncQuery.js +79 -88
  106. package/lib/WAUSync/USyncUser.js +28 -29
  107. package/lib/WAUSync/index.js +0 -1
  108. package/lib/index.js +2 -2
  109. package/package.json +22 -86
  110. package/WAProto/GenerateStatics.sh +0 -3
  111. package/WAProto/fix-imports.js +0 -85
  112. package/WAProto/index.d.ts +0 -14017
  113. package/lib/Defaults/index.d.ts +0 -75
  114. package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
  115. package/lib/Signal/Group/group-session-builder.d.ts +0 -15
  116. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  117. package/lib/Signal/Group/index.d.ts +0 -12
  118. package/lib/Signal/Group/keyhelper.d.ts +0 -11
  119. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  120. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  121. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  122. package/lib/Signal/Group/sender-key-name.d.ts +0 -18
  123. package/lib/Signal/Group/sender-key-record.d.ts +0 -31
  124. package/lib/Signal/Group/sender-key-state.d.ts +0 -39
  125. package/lib/Signal/Group/sender-message-key.d.ts +0 -12
  126. package/lib/Signal/libsignal.d.ts +0 -5
  127. package/lib/Signal/lid-mapping.d.ts +0 -23
  128. package/lib/Socket/Client/index.d.ts +0 -3
  129. package/lib/Socket/Client/types.d.ts +0 -16
  130. package/lib/Socket/Client/websocket.d.ts +0 -13
  131. package/lib/Socket/business.d.ts +0 -217
  132. package/lib/Socket/chats.d.ts +0 -125
  133. package/lib/Socket/communities.d.ts +0 -273
  134. package/lib/Socket/groups.d.ts +0 -161
  135. package/lib/Socket/index.d.ts +0 -260
  136. package/lib/Socket/messages-recv.d.ts +0 -203
  137. package/lib/Socket/messages-send.d.ts +0 -199
  138. package/lib/Socket/mex.d.ts +0 -3
  139. package/lib/Socket/newsletter.d.ts +0 -170
  140. package/lib/Socket/socket.d.ts +0 -59
  141. package/lib/Types/Auth.d.ts +0 -117
  142. package/lib/Types/Bussines.d.ts +0 -25
  143. package/lib/Types/Call.d.ts +0 -15
  144. package/lib/Types/Chat.d.ts +0 -124
  145. package/lib/Types/Contact.d.ts +0 -26
  146. package/lib/Types/Events.d.ts +0 -256
  147. package/lib/Types/GroupMetadata.d.ts +0 -71
  148. package/lib/Types/Label.d.ts +0 -47
  149. package/lib/Types/LabelAssociation.d.ts +0 -30
  150. package/lib/Types/Message.d.ts +0 -320
  151. package/lib/Types/Mex.d.ts +0 -141
  152. package/lib/Types/Product.d.ts +0 -79
  153. package/lib/Types/Signal.d.ts +0 -87
  154. package/lib/Types/Socket.d.ts +0 -136
  155. package/lib/Types/State.d.ts +0 -97
  156. package/lib/Types/USync.d.ts +0 -26
  157. package/lib/Types/index.d.ts +0 -66
  158. package/lib/Utils/auth-utils.d.ts +0 -24
  159. package/lib/Utils/browser-utils.d.ts +0 -4
  160. package/lib/Utils/business.d.ts +0 -23
  161. package/lib/Utils/chat-utils.d.ts +0 -100
  162. package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
  163. package/lib/Utils/crypto.d.ts +0 -37
  164. package/lib/Utils/decode-wa-message.d.ts +0 -66
  165. package/lib/Utils/event-buffer.d.ts +0 -36
  166. package/lib/Utils/generics.d.ts +0 -92
  167. package/lib/Utils/history.d.ts +0 -24
  168. package/lib/Utils/identity-change-handler.d.ts +0 -44
  169. package/lib/Utils/identity-change-handler.js +0 -50
  170. package/lib/Utils/index.d.ts +0 -22
  171. package/lib/Utils/link-preview.d.ts +0 -21
  172. package/lib/Utils/logger.d.ts +0 -12
  173. package/lib/Utils/lt-hash.d.ts +0 -8
  174. package/lib/Utils/make-mutex.d.ts +0 -9
  175. package/lib/Utils/message-retry-manager.d.ts +0 -115
  176. package/lib/Utils/messages-media.d.ts +0 -133
  177. package/lib/Utils/messages.d.ts +0 -91
  178. package/lib/Utils/noise-handler.d.ts +0 -20
  179. package/lib/Utils/offline-node-processor.d.ts +0 -17
  180. package/lib/Utils/offline-node-processor.js +0 -40
  181. package/lib/Utils/pre-key-manager.d.ts +0 -28
  182. package/lib/Utils/process-message.d.ts +0 -60
  183. package/lib/Utils/reporting-utils.d.ts +0 -11
  184. package/lib/Utils/signal.d.ts +0 -47
  185. package/lib/Utils/stanza-ack.d.ts +0 -11
  186. package/lib/Utils/sync-action-utils.d.ts +0 -19
  187. package/lib/Utils/tc-token-utils.d.ts +0 -37
  188. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  189. package/lib/Utils/validate-connection.d.ts +0 -11
  190. package/lib/WABinary/constants.d.ts +0 -28
  191. package/lib/WABinary/decode.d.ts +0 -7
  192. package/lib/WABinary/encode.d.ts +0 -3
  193. package/lib/WABinary/generic-utils.d.ts +0 -15
  194. package/lib/WABinary/index.d.ts +0 -6
  195. package/lib/WABinary/jid-utils.d.ts +0 -48
  196. package/lib/WABinary/types.d.ts +0 -19
  197. package/lib/WAM/BinaryInfo.d.ts +0 -9
  198. package/lib/WAM/constants.d.ts +0 -40
  199. package/lib/WAM/encode.d.ts +0 -3
  200. package/lib/WAM/index.d.ts +0 -4
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  202. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
  203. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
  204. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
  205. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
  206. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
  207. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
  208. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  209. package/lib/WAUSync/USyncQuery.d.ts +0 -30
  210. package/lib/WAUSync/USyncUser.d.ts +0 -17
  211. package/lib/WAUSync/index.d.ts +0 -4
  212. package/lib/index.d.ts +0 -12
@@ -1,92 +0,0 @@
1
- import type Long from 'long';
2
- import { proto } from '../../WAProto/index.js';
3
- import type { BaileysEventEmitter, BaileysEventMap, ConnectionState, WACallUpdateType, WAMessageKey, WAVersion } from '../Types/index.js';
4
- import { type BinaryNode } from '../WABinary/index.js';
5
- export declare const BufferJSON: {
6
- replacer: (k: any, value: any) => any;
7
- reviver: (_: any, value: any) => any;
8
- };
9
- export declare const getKeyAuthor: (key: WAMessageKey | undefined | null, meId?: string) => string;
10
- export declare const isStringNullOrEmpty: (value: string | null | undefined) => value is null | undefined | "";
11
- export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer<ArrayBuffer>;
12
- export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array<ArrayBuffer>;
13
- export declare const generateParticipantHashV2: (participants: string[]) => string;
14
- export declare const encodeWAMessage: (message: proto.IMessage) => Buffer<ArrayBuffer>;
15
- export declare const generateRegistrationId: () => number;
16
- export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array<ArrayBuffer>;
17
- export declare const toNumber: (t: Long | number | null | undefined) => number;
18
- /** unix timestamp of a date in seconds */
19
- export declare const unixTimestampSeconds: (date?: Date) => number;
20
- export type DebouncedTimeout = ReturnType<typeof debouncedTimeout>;
21
- export declare const debouncedTimeout: (intervalMs?: number, task?: () => void) => {
22
- start: (newIntervalMs?: number, newTask?: () => void) => void;
23
- cancel: () => void;
24
- setTask: (newTask: () => void) => () => void;
25
- setInterval: (newInterval: number) => number;
26
- };
27
- export declare const delay: (ms: number) => Promise<void>;
28
- export declare const delayCancellable: (ms: number) => {
29
- delay: Promise<void>;
30
- cancel: () => void;
31
- };
32
- export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
33
- export declare const generateMessageIDV2: (userId?: string) => string;
34
- export declare const generateMessageID: () => string;
35
- export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
36
- export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
37
- /**
38
- * utility that fetches latest baileys version from the master branch.
39
- * Use to ensure your WA connection is always on the latest version
40
- */
41
- export declare const fetchLatestBaileysVersion: (options?: RequestInit) => Promise<{
42
- version: WAVersion;
43
- isLatest: boolean;
44
- error?: undefined;
45
- } | {
46
- version: WAVersion;
47
- isLatest: boolean;
48
- error: unknown;
49
- }>;
50
- /**
51
- * A utility that fetches the latest web version of whatsapp.
52
- * Use to ensure your WA connection is always on the latest version
53
- */
54
- export declare const fetchLatestWaWebVersion: (options?: RequestInit) => Promise<{
55
- version: WAVersion;
56
- isLatest: boolean;
57
- error?: undefined;
58
- } | {
59
- version: WAVersion;
60
- isLatest: boolean;
61
- error: unknown;
62
- }>;
63
- /** unique message tag prefix for MD clients */
64
- export declare const generateMdTagPrefix: () => string;
65
- /**
66
- * Given a type of receipt, returns what the new status of the message should be
67
- * @param type type from receipt
68
- */
69
- export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status | undefined;
70
- /**
71
- * Stream errors generally provide a reason, map that to a baileys DisconnectReason
72
- * @param reason the string reason given, eg. "conflict"
73
- */
74
- export declare const getErrorCodeFromStreamError: (node: BinaryNode) => {
75
- reason: string;
76
- statusCode: number;
77
- };
78
- export declare const getCallStatusFromNode: ({ tag, attrs }: BinaryNode) => WACallUpdateType;
79
- export declare const getCodeFromWSError: (error: Error) => number;
80
- /**
81
- * Is the given platform WA business
82
- * @param platform AuthenticationCreds.platform
83
- */
84
- export declare const isWABusinessPlatform: (platform: string) => platform is "smba" | "smbi";
85
- export declare function trimUndefined(obj: {
86
- [_: string]: any;
87
- }): {
88
- [_: string]: any;
89
- };
90
- export declare function bytesToCrockford(buffer: Buffer): string;
91
- export declare function encodeNewsletterMessage(message: proto.IMessage): Uint8Array;
92
- //# sourceMappingURL=generics.d.ts.map
@@ -1,24 +0,0 @@
1
- import { proto } from '../../WAProto/index.js';
2
- import type { Chat, Contact, LIDMapping, WAMessage } from '../Types/index.js';
3
- import type { ILogger } from './logger.js';
4
- export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: RequestInit) => Promise<proto.HistorySync>;
5
- export declare const processHistoryMessage: (item: proto.IHistorySync, logger?: ILogger) => {
6
- chats: Chat[];
7
- contacts: Contact[];
8
- messages: WAMessage[];
9
- lidPnMappings: LIDMapping[];
10
- pastParticipants: proto.IPastParticipants[] | null | undefined;
11
- syncType: proto.HistorySync.HistorySyncType | null | undefined;
12
- progress: number | null | undefined;
13
- };
14
- export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: RequestInit, logger?: ILogger) => Promise<{
15
- chats: Chat[];
16
- contacts: Contact[];
17
- messages: WAMessage[];
18
- lidPnMappings: LIDMapping[];
19
- pastParticipants: proto.IPastParticipants[] | null | undefined;
20
- syncType: proto.HistorySync.HistorySyncType | null | undefined;
21
- progress: number | null | undefined;
22
- }>;
23
- export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification;
24
- //# sourceMappingURL=history.d.ts.map
@@ -1,44 +0,0 @@
1
- import NodeCache from '@cacheable/node-cache';
2
- import { type BinaryNode } from '../WABinary/index.js';
3
- import type { ILogger } from './logger.js';
4
- export type IdentityChangeResult = {
5
- action: 'no_identity_node';
6
- } | {
7
- action: 'invalid_notification';
8
- } | {
9
- action: 'skipped_companion_device';
10
- device: number;
11
- } | {
12
- action: 'skipped_self_primary';
13
- } | {
14
- action: 'debounced';
15
- } | {
16
- action: 'skipped_offline';
17
- } | {
18
- action: 'skipped_no_session';
19
- } | {
20
- action: 'session_refreshed';
21
- } | {
22
- action: 'session_refresh_failed';
23
- error: unknown;
24
- };
25
- export type IdentityChangeContext = {
26
- meId: string | undefined;
27
- meLid: string | undefined;
28
- validateSession: (jid: string) => Promise<{
29
- exists: boolean;
30
- reason?: string;
31
- }>;
32
- assertSessions: (jids: string[], force?: boolean) => Promise<boolean>;
33
- debounceCache: NodeCache<boolean>;
34
- logger: ILogger;
35
- /**
36
- * Invoked right before `assertSessions` is called for an existing-session identity change.
37
- * Used to kick off fire-and-forget side effects (e.g. tctoken re-issuance) in the same
38
- * order WA Web does — i.e. before the E2E session is re-established.
39
- * Must not throw; implementations are responsible for their own error handling.
40
- */
41
- onBeforeSessionRefresh?: (jid: string) => void;
42
- };
43
- export declare function handleIdentityChange(node: BinaryNode, ctx: IdentityChangeContext): Promise<IdentityChangeResult>;
44
- //# sourceMappingURL=identity-change-handler.d.ts.map
@@ -1,50 +0,0 @@
1
- import NodeCache from '@cacheable/node-cache';
2
- import { areJidsSameUser, getBinaryNodeChild, jidDecode } from '../WABinary/index.js';
3
- import { isStringNullOrEmpty } from './generics.js';
4
- export async function handleIdentityChange(node, ctx) {
5
- const from = node.attrs.from;
6
- if (!from) {
7
- return { action: 'invalid_notification' };
8
- }
9
- const identityNode = getBinaryNodeChild(node, 'identity');
10
- if (!identityNode) {
11
- return { action: 'no_identity_node' };
12
- }
13
- ctx.logger.info({ jid: from }, 'identity changed');
14
- const decoded = jidDecode(from);
15
- if (decoded?.device && decoded.device !== 0) {
16
- ctx.logger.debug({ jid: from, device: decoded.device }, 'ignoring identity change from companion device');
17
- return { action: 'skipped_companion_device', device: decoded.device };
18
- }
19
- const isSelfPrimary = ctx.meId && (areJidsSameUser(from, ctx.meId) || (ctx.meLid && areJidsSameUser(from, ctx.meLid)));
20
- if (isSelfPrimary) {
21
- ctx.logger.info({ jid: from }, 'self primary identity changed');
22
- return { action: 'skipped_self_primary' };
23
- }
24
- if (ctx.debounceCache.get(from)) {
25
- ctx.logger.debug({ jid: from }, 'skipping identity assert (debounced)');
26
- return { action: 'debounced' };
27
- }
28
- ctx.debounceCache.set(from, true);
29
- const isOfflineNotification = !isStringNullOrEmpty(node.attrs.offline);
30
- const hasExistingSession = await ctx.validateSession(from);
31
- if (!hasExistingSession.exists) {
32
- ctx.logger.debug({ jid: from }, 'no old session, skipping session refresh');
33
- return { action: 'skipped_no_session' };
34
- }
35
- ctx.logger.debug({ jid: from }, 'old session exists, will refresh session');
36
- if (isOfflineNotification) {
37
- ctx.logger.debug({ jid: from }, 'skipping session refresh during offline processing');
38
- return { action: 'skipped_offline' };
39
- }
40
- ctx.onBeforeSessionRefresh?.(from);
41
- try {
42
- await ctx.assertSessions([from], true);
43
- return { action: 'session_refreshed' };
44
- }
45
- catch (error) {
46
- ctx.logger.warn({ error, jid: from }, 'failed to assert sessions after identity change');
47
- return { action: 'session_refresh_failed', error };
48
- }
49
- }
50
- //# sourceMappingURL=identity-change-handler.js.map
@@ -1,22 +0,0 @@
1
- export * from './generics.js';
2
- export * from './decode-wa-message.js';
3
- export * from './messages.js';
4
- export * from './messages-media.js';
5
- export * from './validate-connection.js';
6
- export * from './crypto.js';
7
- export * from './signal.js';
8
- export * from './noise-handler.js';
9
- export * from './history.js';
10
- export * from './chat-utils.js';
11
- export * from './lt-hash.js';
12
- export * from './auth-utils.js';
13
- export * from './use-multi-file-auth-state.js';
14
- export * from './link-preview.js';
15
- export * from './event-buffer.js';
16
- export * from './process-message.js';
17
- export * from './message-retry-manager.js';
18
- export * from './browser-utils.js';
19
- export * from './companion-reg-client-utils.js';
20
- export * from './identity-change-handler.js';
21
- export * from './stanza-ack.js';
22
- //# sourceMappingURL=index.d.ts.map
@@ -1,21 +0,0 @@
1
- import type { WAMediaUploadFunction, WAUrlInfo } from '../Types/index.js';
2
- import type { ILogger } from './logger.js';
3
- export type URLGenerationOptions = {
4
- thumbnailWidth: number;
5
- fetchOpts: {
6
- /** Timeout in ms */
7
- timeout: number;
8
- proxyUrl?: string;
9
- headers?: HeadersInit;
10
- };
11
- uploadImage?: WAMediaUploadFunction;
12
- logger?: ILogger;
13
- };
14
- /**
15
- * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
16
- * Return undefined if the fetch failed or no URL was found
17
- * @param text first matched URL in text
18
- * @returns the URL info required to generate link preview
19
- */
20
- export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>;
21
- //# sourceMappingURL=link-preview.d.ts.map
@@ -1,12 +0,0 @@
1
- export interface ILogger {
2
- level: string;
3
- child(obj: Record<string, unknown>): ILogger;
4
- trace(obj: unknown, msg?: string): void;
5
- debug(obj: unknown, msg?: string): void;
6
- info(obj: unknown, msg?: string): void;
7
- warn(obj: unknown, msg?: string): void;
8
- error(obj: unknown, msg?: string): void;
9
- }
10
- declare const _default: import("pino").Logger<never, boolean>;
11
- export default _default;
12
- //# sourceMappingURL=logger.d.ts.map
@@ -1,8 +0,0 @@
1
- import { LTHashAntiTampering } from 'whatsapp-rust-bridge';
2
- /**
3
- * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
4
- * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
5
- * if the same series of mutations was made sequentially.
6
- */
7
- export declare const LT_HASH_ANTI_TAMPERING: LTHashAntiTampering;
8
- //# sourceMappingURL=lt-hash.d.ts.map
@@ -1,9 +0,0 @@
1
- export declare const makeMutex: () => {
2
- mutex<T>(code: () => Promise<T> | T): Promise<T>;
3
- };
4
- export type Mutex = ReturnType<typeof makeMutex>;
5
- export declare const makeKeyedMutex: () => {
6
- mutex<T>(key: string, task: () => Promise<T> | T): Promise<T>;
7
- };
8
- export type KeyedMutex = ReturnType<typeof makeKeyedMutex>;
9
- //# sourceMappingURL=make-mutex.d.ts.map
@@ -1,115 +0,0 @@
1
- import type { proto } from '../../WAProto/index.js';
2
- import type { ILogger } from './logger.js';
3
- export interface RecentMessageKey {
4
- to: string;
5
- id: string;
6
- }
7
- export interface RecentMessage {
8
- message: proto.IMessage;
9
- timestamp: number;
10
- }
11
- export interface SessionRecreateHistory {
12
- [jid: string]: number;
13
- }
14
- export interface RetryCounter {
15
- [messageId: string]: number;
16
- }
17
- export type PendingPhoneRequest = Record<string, ReturnType<typeof setTimeout>>;
18
- export interface RetryStatistics {
19
- totalRetries: number;
20
- successfulRetries: number;
21
- failedRetries: number;
22
- mediaRetries: number;
23
- sessionRecreations: number;
24
- phoneRequests: number;
25
- }
26
- export declare enum RetryReason {
27
- UnknownError = 0,
28
- SignalErrorNoSession = 1,
29
- SignalErrorInvalidKey = 2,
30
- SignalErrorInvalidKeyId = 3,
31
- /** MAC verification failed - most common cause of decryption failures */
32
- SignalErrorInvalidMessage = 4,
33
- SignalErrorInvalidSignature = 5,
34
- SignalErrorFutureMessage = 6,
35
- /** Explicit MAC failure - session is definitely out of sync */
36
- SignalErrorBadMac = 7,
37
- SignalErrorInvalidSession = 8,
38
- SignalErrorInvalidMsgKey = 9,
39
- BadBroadcastEphemeralSetting = 10,
40
- UnknownCompanionNoPrekey = 11,
41
- AdvFailure = 12,
42
- StatusRevokeDelay = 13
43
- }
44
- export declare class MessageRetryManager {
45
- private logger;
46
- private recentMessagesMap;
47
- private messageKeyIndex;
48
- private sessionRecreateHistory;
49
- private retryCounters;
50
- private baseKeys;
51
- private pendingPhoneRequests;
52
- private readonly maxMsgRetryCount;
53
- private statistics;
54
- constructor(logger: ILogger, maxMsgRetryCount: number);
55
- /**
56
- * Add a recent message to the cache for retry handling
57
- */
58
- addRecentMessage(to: string, id: string, message: proto.IMessage): void;
59
- /**
60
- * Get a recent message from the cache
61
- */
62
- getRecentMessage(to: string, id: string): RecentMessage | undefined;
63
- /**
64
- * Check if a session should be recreated based on retry count, history, and error code.
65
- * MAC errors (codes 4 and 7) trigger immediate session recreation regardless of timeout.
66
- */
67
- shouldRecreateSession(jid: string, hasSession: boolean, errorCode?: RetryReason): {
68
- reason: string;
69
- recreate: boolean;
70
- };
71
- /**
72
- * Parse error code from retry receipt's retry node.
73
- * Returns undefined if no error code is present.
74
- */
75
- parseRetryErrorCode(errorAttr: string | undefined): RetryReason | undefined;
76
- /**
77
- * Check if an error code indicates a MAC failure
78
- */
79
- isMacError(errorCode: RetryReason | undefined): boolean;
80
- /**
81
- * Increment retry counter for a message
82
- */
83
- incrementRetryCount(messageId: string): number;
84
- /**
85
- * Get retry count for a message
86
- */
87
- getRetryCount(messageId: string): number;
88
- /**
89
- * Check if message has exceeded maximum retry attempts
90
- */
91
- hasExceededMaxRetries(messageId: string): boolean;
92
- /**
93
- * Mark retry as successful
94
- */
95
- markRetrySuccess(messageId: string): void;
96
- /**
97
- * Mark retry as failed
98
- */
99
- markRetryFailed(messageId: string): void;
100
- /**
101
- * Schedule a phone request with delay
102
- */
103
- schedulePhoneRequest(messageId: string, callback: () => void, delay?: number): void;
104
- /**
105
- * Cancel pending phone request
106
- */
107
- cancelPendingPhoneRequest(messageId: string): void;
108
- clear(): void;
109
- saveBaseKey(addr: string, msgId: string, baseKey: Uint8Array): void;
110
- hasSameBaseKey(addr: string, msgId: string, baseKey: Uint8Array): boolean;
111
- deleteBaseKey(addr: string, msgId: string): void;
112
- private keyToString;
113
- private removeRecentMessage;
114
- }
115
- //# sourceMappingURL=message-retry-manager.d.ts.map
@@ -1,133 +0,0 @@
1
- import { Boom } from '@hapi/boom';
2
- import type { Agent } from 'https';
3
- import { Readable, Transform } from 'stream';
4
- import { URL } from 'url';
5
- import { proto } from '../../WAProto/index.js';
6
- import { type MediaType } from '../Defaults/index.js';
7
- import type { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent, WAMessageKey } from '../Types/index.js';
8
- import { type BinaryNode } from '../WABinary/index.js';
9
- import type { ILogger } from './logger.js';
10
- export declare const hkdfInfoKey: (type: MediaType) => string;
11
- export declare const getRawMediaUploadData: (media: WAMediaUpload, mediaType: MediaType, logger?: ILogger) => Promise<{
12
- filePath: string;
13
- fileSha256: Buffer<ArrayBufferLike>;
14
- fileLength: number;
15
- }>;
16
- /** generates all the keys required to encrypt/decrypt & sign a media message */
17
- export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): Promise<MediaDecryptionKeyInfo>;
18
- export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
19
- buffer: any;
20
- original: {
21
- width: any;
22
- height: any;
23
- };
24
- }>;
25
- export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
26
- export declare const generateProfilePicture: (mediaUpload: WAMediaUpload, dimensions?: {
27
- width: number;
28
- height: number;
29
- }) => Promise<{
30
- img: Buffer<ArrayBufferLike>;
31
- }>;
32
- /** gets the SHA256 of the given media message */
33
- export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
34
- export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;
35
- /**
36
- referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
37
- */
38
- export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: ILogger): Promise<Uint8Array<ArrayBuffer> | undefined>;
39
- export declare const toReadable: (buffer: Buffer) => Readable;
40
- export declare const toBuffer: (stream: Readable) => Promise<Buffer<ArrayBuffer>>;
41
- export declare const getStream: (item: WAMediaUpload, opts?: RequestInit & {
42
- maxContentLength?: number;
43
- }) => Promise<{
44
- readonly stream: Readable;
45
- readonly type: "buffer";
46
- } | {
47
- readonly stream: Readable;
48
- readonly type: "readable";
49
- } | {
50
- readonly stream: Readable;
51
- readonly type: "remote";
52
- } | {
53
- readonly stream: import("fs").ReadStream;
54
- readonly type: "file";
55
- }>;
56
- /** generates a thumbnail for a given media, if required */
57
- export declare function generateThumbnail(file: string, mediaType: 'video' | 'image', options: {
58
- logger?: ILogger;
59
- }): Promise<{
60
- thumbnail: string | undefined;
61
- originalImageDimensions: {
62
- width: number;
63
- height: number;
64
- } | undefined;
65
- }>;
66
- export declare const getHttpStream: (url: string | URL, options?: RequestInit & {
67
- isStream?: true;
68
- }) => Promise<Readable>;
69
- type EncryptedStreamOptions = {
70
- saveOriginalFileIfRequired?: boolean;
71
- logger?: ILogger;
72
- opts?: RequestInit;
73
- };
74
- export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
75
- mediaKey: Buffer<ArrayBufferLike>;
76
- originalFilePath: string | undefined;
77
- encFilePath: string;
78
- mac: Buffer<ArrayBuffer>;
79
- fileEncSha256: Buffer<ArrayBufferLike>;
80
- fileSha256: Buffer<ArrayBufferLike>;
81
- fileLength: number;
82
- }>;
83
- export declare const DEF_MEDIA_HOST = "mmg.whatsapp.net";
84
- export type MediaDownloadOptions = {
85
- startByte?: number;
86
- endByte?: number;
87
- options?: RequestInit;
88
- /** Optional media host override; falls back to DEF_MEDIA_HOST when not provided. */
89
- host?: string;
90
- };
91
- export declare const getUrlFromDirectPath: (directPath: string, host?: string) => string;
92
- export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
93
- /**
94
- * Decrypts and downloads an AES256-CBC encrypted file given the keys.
95
- * Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
96
- * */
97
- export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<Transform>;
98
- export declare function extensionForMediaMessage(message: WAMessageContent): string;
99
- type MediaUploadResult = {
100
- url?: string;
101
- direct_path?: string;
102
- meta_hmac?: string;
103
- ts?: number;
104
- fbid?: number;
105
- };
106
- export type UploadParams = {
107
- url: string;
108
- filePath: string;
109
- headers: Record<string, string>;
110
- timeoutMs?: number;
111
- agent?: Agent;
112
- };
113
- export declare const uploadWithNodeHttp: ({ url, filePath, headers, timeoutMs, agent }: UploadParams, redirectCount?: number) => Promise<MediaUploadResult | undefined>;
114
- export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logger, options }: SocketConfig, refreshMediaConn: (force: boolean) => Promise<MediaConnInfo>) => WAMediaUploadFunction;
115
- /**
116
- * Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
117
- */
118
- export declare const encryptMediaRetryRequest: (key: WAMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
119
- export declare const decodeMediaRetryNode: (node: BinaryNode) => {
120
- key: WAMessageKey;
121
- media?: {
122
- ciphertext: Uint8Array;
123
- iv: Uint8Array;
124
- };
125
- error?: Boom;
126
- };
127
- export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
128
- ciphertext: Uint8Array;
129
- iv: Uint8Array;
130
- }, mediaKey: Uint8Array, msgId: string) => proto.MediaRetryNotification;
131
- export declare const getStatusCodeForMediaRetry: (code: number) => 200 | 412 | 404 | 418;
132
- export {};
133
- //# sourceMappingURL=messages-media.d.ts.map
@@ -1,91 +0,0 @@
1
- import { type Transform } from 'stream';
2
- import { proto } from '../../WAProto/index.js';
3
- import type { AnyMediaMessageContent, AnyMessageContent, MessageContentGenerationOptions, MessageGenerationOptions, MessageGenerationOptionsFromContent, MessageUserReceipt, WAMessage, WAMessageContent, WAMessageKey } from '../Types/index.js';
4
- import type { ILogger } from './logger.js';
5
- import { type MediaDownloadOptions } from './messages-media.js';
6
- type ExtractByKey<T, K extends PropertyKey> = T extends Record<K, any> ? T : never;
7
- /**
8
- * Uses a regex to test whether the string contains a URL, and returns the URL if it does.
9
- * @param text eg. hello https://google.com
10
- * @returns the URL, eg. https://google.com
11
- */
12
- export declare const extractUrlFromText: (text: string) => string | undefined;
13
- export declare const generateLinkPreviewIfRequired: (text: string, getUrlInfo: MessageGenerationOptions["getUrlInfo"], logger: MessageGenerationOptions["logger"]) => Promise<import("../Types/index.js").WAUrlInfo | undefined>;
14
- export declare const prepareWAMessageMedia: (message: AnyMediaMessageContent, options: MessageContentGenerationOptions) => Promise<proto.Message>;
15
- export declare const prepareDisappearingMessageSettingContent: (ephemeralExpiration?: number) => proto.Message;
16
- /**
17
- * Generate forwarded message content like WA does
18
- * @param message the message to forward
19
- * @param options.forceForward will show the message as forwarded even if it is from you
20
- */
21
- export declare const generateForwardMessageContent: (message: WAMessage, forceForward?: boolean) => proto.IMessage;
22
- export declare const hasNonNullishProperty: <K extends PropertyKey>(message: AnyMessageContent, key: K) => message is ExtractByKey<AnyMessageContent, K>;
23
- export declare const generateWAMessageContent: (message: AnyMessageContent, options: MessageContentGenerationOptions) => Promise<proto.Message>;
24
- export declare const generateWAMessageFromContent: (jid: string, message: WAMessageContent, options: MessageGenerationOptionsFromContent) => WAMessage;
25
- export declare const generateWAMessage: (jid: string, content: AnyMessageContent, options: MessageGenerationOptions) => Promise<WAMessage>;
26
- /** Get the key to access the true type of content */
27
- export declare const getContentType: (content: proto.IMessage | undefined) => keyof proto.IMessage | undefined;
28
- /**
29
- * Normalizes ephemeral, view once messages to regular message content
30
- * Eg. image messages in ephemeral messages, in view once messages etc.
31
- * @param content
32
- * @returns
33
- */
34
- export declare const normalizeMessageContent: (content: WAMessageContent | null | undefined) => WAMessageContent | undefined;
35
- /**
36
- * Extract the true message content from a message
37
- * Eg. extracts the inner message from a disappearing message/view once message
38
- */
39
- export declare const extractMessageContent: (content: WAMessageContent | undefined | null) => WAMessageContent | undefined;
40
- /**
41
- * Returns the device predicted by message ID
42
- */
43
- export declare const getDevice: (id: string) => "web" | "unknown" | "android" | "ios" | "desktop";
44
- /** Upserts a receipt in the message */
45
- export declare const updateMessageWithReceipt: (msg: Pick<WAMessage, "userReceipt">, receipt: MessageUserReceipt) => void;
46
- /** Update the message with a new reaction */
47
- export declare const updateMessageWithReaction: (msg: Pick<WAMessage, "reactions">, reaction: proto.IReaction) => void;
48
- /** Update the message with a new poll update */
49
- export declare const updateMessageWithPollUpdate: (msg: Pick<WAMessage, "pollUpdates">, update: proto.IPollUpdate) => void;
50
- /** Update the message with a new event response */
51
- export declare const updateMessageWithEventResponse: (msg: Pick<WAMessage, "eventResponses">, update: proto.IEventResponse) => void;
52
- type VoteAggregation = {
53
- name: string;
54
- voters: string[];
55
- };
56
- /**
57
- * Aggregates all poll updates in a poll.
58
- * @param msg the poll creation message
59
- * @param meId your jid
60
- * @returns A list of options & their voters
61
- */
62
- export declare function getAggregateVotesInPollMessage({ message, pollUpdates }: Pick<WAMessage, 'pollUpdates' | 'message'>, meId?: string): VoteAggregation[];
63
- type ResponseAggregation = {
64
- response: string;
65
- responders: string[];
66
- };
67
- /**
68
- * Aggregates all event responses in an event message.
69
- * @param msg the event creation message
70
- * @param meId your jid
71
- * @returns A list of response types & their responders
72
- */
73
- export declare function getAggregateResponsesInEventMessage({ eventResponses }: Pick<WAMessage, 'eventResponses'>, meId?: string): ResponseAggregation[];
74
- /** Given a list of message keys, aggregates them by chat & sender. Useful for sending read receipts in bulk */
75
- export declare const aggregateMessageKeysNotFromMe: (keys: WAMessageKey[]) => {
76
- jid: string;
77
- participant: string | undefined;
78
- messageIds: string[];
79
- }[];
80
- type DownloadMediaMessageContext = {
81
- reuploadRequest: (msg: WAMessage) => Promise<WAMessage>;
82
- logger: ILogger;
83
- };
84
- /**
85
- * Downloads the given message. Throws an error if it's not a media message
86
- */
87
- export declare const downloadMediaMessage: <Type extends "buffer" | "stream">(message: WAMessage, type: Type, options: MediaDownloadOptions, ctx?: DownloadMediaMessageContext) => Promise<Type extends "buffer" ? Buffer<ArrayBufferLike> : Transform>;
88
- /** Checks whether the given message is a media message; if it is returns the inner content */
89
- export declare const assertMediaContent: (content: proto.IMessage | null | undefined) => proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
90
- export {};
91
- //# sourceMappingURL=messages.d.ts.map
@@ -1,20 +0,0 @@
1
- import { proto } from '../../WAProto/index.js';
2
- import type { KeyPair } from '../Types/index.js';
3
- import type { BinaryNode } from '../WABinary/index.js';
4
- import type { ILogger } from './logger.js';
5
- export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }: {
6
- keyPair: KeyPair;
7
- NOISE_HEADER: Uint8Array;
8
- logger: ILogger;
9
- routingInfo?: Buffer | undefined;
10
- }) => {
11
- encrypt: (plaintext: Uint8Array) => Uint8Array;
12
- decrypt: (ciphertext: Uint8Array) => Uint8Array;
13
- authenticate: (data: Uint8Array) => void;
14
- mixIntoKey: (data: Uint8Array) => void;
15
- finishInit: () => Promise<void>;
16
- processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Uint8Array<ArrayBufferLike>;
17
- encodeFrame: (data: Buffer | Uint8Array) => Buffer<ArrayBuffer>;
18
- decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => Promise<void>;
19
- };
20
- //# sourceMappingURL=noise-handler.d.ts.map