@neelegirl/baileys 1.5.5 → 1.5.7

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 (203) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +183 -10
  3. package/WAProto/WAProto.proto +5007 -0
  4. package/WAProto/index.d.ts +57712 -0
  5. package/WAProto/index.js +178969 -0
  6. package/lib/Defaults/baileys-version.json +3 -0
  7. package/lib/Defaults/index.d.ts +68 -0
  8. package/lib/Defaults/index.js +137 -0
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Signal/WASignalGroup/GroupProtocol.js +1909 -0
  11. package/lib/Signal/WASignalGroup/ciphertext_message.js +16 -0
  12. package/lib/Signal/WASignalGroup/generate-proto.sh +1 -0
  13. package/lib/Signal/WASignalGroup/group.proto +42 -0
  14. package/lib/Signal/WASignalGroup/group_cipher.js +120 -0
  15. package/lib/Signal/WASignalGroup/group_session_builder.js +46 -0
  16. package/lib/Signal/WASignalGroup/index.js +6 -0
  17. package/lib/Signal/WASignalGroup/keyhelper.js +21 -0
  18. package/lib/Signal/WASignalGroup/protobufs.js +3 -0
  19. package/lib/Signal/WASignalGroup/queue_job.js +69 -0
  20. package/lib/Signal/WASignalGroup/readme.md +6 -0
  21. package/lib/Signal/WASignalGroup/sender_chain_key.js +50 -0
  22. package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +78 -0
  23. package/lib/Signal/WASignalGroup/sender_key_message.js +92 -0
  24. package/lib/Signal/WASignalGroup/sender_key_name.js +70 -0
  25. package/lib/Signal/WASignalGroup/sender_key_record.js +56 -0
  26. package/lib/Signal/WASignalGroup/sender_key_state.js +129 -0
  27. package/lib/Signal/WASignalGroup/sender_message_key.js +39 -0
  28. package/lib/Signal/libsignal.d.ts +4 -0
  29. package/lib/Signal/libsignal.js +162 -0
  30. package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
  31. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  32. package/lib/Socket/Client/index.d.ts +2 -0
  33. package/lib/Socket/Client/index.js +22 -0
  34. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
  35. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  36. package/lib/Socket/Client/types.d.ts +16 -0
  37. package/lib/Socket/Client/types.js +18 -0
  38. package/lib/Socket/Client/websocket.d.ts +13 -0
  39. package/lib/Socket/Client/websocket.js +62 -0
  40. package/lib/Socket/business.d.ts +187 -0
  41. package/lib/Socket/business.js +268 -0
  42. package/lib/Socket/chats.d.ts +98 -0
  43. package/lib/Socket/chats.js +1113 -0
  44. package/lib/Socket/communities.d.ts +223 -0
  45. package/lib/Socket/communities.js +433 -0
  46. package/lib/Socket/groups.d.ts +131 -0
  47. package/lib/Socket/groups.js +352 -0
  48. package/lib/Socket/index.d.ts +191 -0
  49. package/lib/Socket/index.js +23 -0
  50. package/lib/Socket/messages-recv.d.ts +177 -0
  51. package/lib/Socket/messages-recv.js +1764 -0
  52. package/lib/Socket/messages-send.d.ts +168 -0
  53. package/lib/Socket/messages-send.js +1303 -0
  54. package/lib/Socket/mex.d.ts +2 -0
  55. package/lib/Socket/mex.js +47 -0
  56. package/lib/Socket/newsletter.d.ts +147 -0
  57. package/lib/Socket/newsletter.js +286 -0
  58. package/lib/Socket/registration.d.ts +266 -0
  59. package/lib/Socket/registration.js +166 -0
  60. package/lib/Socket/socket.d.ts +45 -0
  61. package/lib/Socket/socket.js +766 -0
  62. package/lib/Socket/usync.d.ts +37 -0
  63. package/lib/Socket/usync.js +83 -0
  64. package/lib/Store/index.d.ts +4 -0
  65. package/lib/Store/index.js +24 -0
  66. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  67. package/lib/Store/make-cache-manager-store.js +90 -0
  68. package/lib/Store/make-in-memory-store.d.ts +123 -0
  69. package/lib/Store/make-in-memory-store.js +429 -0
  70. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  71. package/lib/Store/make-ordered-dictionary.js +86 -0
  72. package/lib/Store/object-repository.d.ts +10 -0
  73. package/lib/Store/object-repository.js +31 -0
  74. package/lib/Types/Auth.d.ts +120 -0
  75. package/lib/Types/Auth.js +3 -0
  76. package/lib/Types/Call.d.ts +14 -0
  77. package/lib/Types/Call.js +3 -0
  78. package/lib/Types/Chat.d.ts +138 -0
  79. package/lib/Types/Chat.js +9 -0
  80. package/lib/Types/Contact.d.ts +20 -0
  81. package/lib/Types/Contact.js +3 -0
  82. package/lib/Types/Events.d.ts +229 -0
  83. package/lib/Types/Events.js +3 -0
  84. package/lib/Types/GroupMetadata.d.ts +66 -0
  85. package/lib/Types/GroupMetadata.js +3 -0
  86. package/lib/Types/Label.d.ts +48 -0
  87. package/lib/Types/Label.js +31 -0
  88. package/lib/Types/LabelAssociation.d.ts +35 -0
  89. package/lib/Types/LabelAssociation.js +13 -0
  90. package/lib/Types/Message.d.ts +473 -0
  91. package/lib/Types/Message.js +13 -0
  92. package/lib/Types/MexUpdates.d.ts +9 -0
  93. package/lib/Types/MexUpdates.js +18 -0
  94. package/lib/Types/Newsletter.d.ts +109 -0
  95. package/lib/Types/Newsletter.js +40 -0
  96. package/lib/Types/Product.d.ts +92 -0
  97. package/lib/Types/Product.js +3 -0
  98. package/lib/Types/Signal.d.ts +68 -0
  99. package/lib/Types/Signal.js +3 -0
  100. package/lib/Types/Socket.d.ts +122 -0
  101. package/lib/Types/Socket.js +3 -0
  102. package/lib/Types/State.d.ts +41 -0
  103. package/lib/Types/State.js +14 -0
  104. package/lib/Types/USync.d.ts +26 -0
  105. package/lib/Types/USync.js +3 -0
  106. package/lib/Types/index.d.ts +79 -0
  107. package/lib/Types/index.js +48 -0
  108. package/lib/Utils/auth-utils.d.ts +21 -0
  109. package/lib/Utils/auth-utils.js +205 -0
  110. package/lib/Utils/baileys-event-stream.d.ts +18 -0
  111. package/lib/Utils/baileys-event-stream.js +70 -0
  112. package/lib/Utils/business.d.ts +29 -0
  113. package/lib/Utils/business.js +255 -0
  114. package/lib/Utils/chat-utils.d.ts +82 -0
  115. package/lib/Utils/chat-utils.js +781 -0
  116. package/lib/Utils/check-npm-version.d.ts +15 -0
  117. package/lib/Utils/check-npm-version.js +52 -0
  118. package/lib/Utils/crypto.d.ts +56 -0
  119. package/lib/Utils/crypto.js +179 -0
  120. package/lib/Utils/decode-wa-message.d.ts +41 -0
  121. package/lib/Utils/decode-wa-message.js +253 -0
  122. package/lib/Utils/event-buffer.d.ts +39 -0
  123. package/lib/Utils/event-buffer.js +565 -0
  124. package/lib/Utils/generics.d.ts +129 -0
  125. package/lib/Utils/generics.js +618 -0
  126. package/lib/Utils/history.d.ts +23 -0
  127. package/lib/Utils/history.js +110 -0
  128. package/lib/Utils/index.d.ts +19 -0
  129. package/lib/Utils/index.js +41 -0
  130. package/lib/Utils/link-preview.d.ts +23 -0
  131. package/lib/Utils/link-preview.js +120 -0
  132. package/lib/Utils/logger.d.ts +13 -0
  133. package/lib/Utils/logger.js +7 -0
  134. package/lib/Utils/lt-hash.d.ts +14 -0
  135. package/lib/Utils/lt-hash.js +58 -0
  136. package/lib/Utils/make-mutex.d.ts +9 -0
  137. package/lib/Utils/make-mutex.js +49 -0
  138. package/lib/Utils/message-retry-manager.d.ts +82 -0
  139. package/lib/Utils/message-retry-manager.js +177 -0
  140. package/lib/Utils/messages-media.d.ts +129 -0
  141. package/lib/Utils/messages-media.js +806 -0
  142. package/lib/Utils/messages.d.ts +103 -0
  143. package/lib/Utils/messages.js +1579 -0
  144. package/lib/Utils/noise-handler.d.ts +20 -0
  145. package/lib/Utils/noise-handler.js +155 -0
  146. package/lib/Utils/process-message.d.ts +49 -0
  147. package/lib/Utils/process-message.js +428 -0
  148. package/lib/Utils/signal.d.ts +42 -0
  149. package/lib/Utils/signal.js +166 -0
  150. package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
  151. package/lib/Utils/use-mongo-file-auth-state.js +84 -0
  152. package/lib/Utils/use-multi-file-auth-state.d.ts +18 -0
  153. package/lib/Utils/use-multi-file-auth-state.js +238 -0
  154. package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
  155. package/lib/Utils/use-single-file-auth-state.js +80 -0
  156. package/lib/Utils/validate-connection.d.ts +13 -0
  157. package/lib/Utils/validate-connection.js +187 -0
  158. package/lib/WABinary/constants.d.ts +30 -0
  159. package/lib/WABinary/constants.js +1316 -0
  160. package/lib/WABinary/decode.d.ts +9 -0
  161. package/lib/WABinary/decode.js +288 -0
  162. package/lib/WABinary/encode.d.ts +3 -0
  163. package/lib/WABinary/encode.js +265 -0
  164. package/lib/WABinary/generic-utils.d.ts +28 -0
  165. package/lib/WABinary/generic-utils.js +142 -0
  166. package/lib/WABinary/index.d.ts +5 -0
  167. package/lib/WABinary/index.js +25 -0
  168. package/lib/WABinary/jid-utils.d.ts +53 -0
  169. package/lib/WABinary/jid-utils.js +92 -0
  170. package/lib/WABinary/types.d.ts +22 -0
  171. package/lib/WABinary/types.js +3 -0
  172. package/lib/WAM/BinaryInfo.d.ts +16 -0
  173. package/lib/WAM/BinaryInfo.js +17 -0
  174. package/lib/WAM/constants.d.ts +47 -0
  175. package/lib/WAM/constants.js +15371 -0
  176. package/lib/WAM/encode.d.ts +3 -0
  177. package/lib/WAM/encode.js +165 -0
  178. package/lib/WAM/index.d.ts +3 -0
  179. package/lib/WAM/index.js +23 -0
  180. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +28 -0
  181. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +69 -0
  182. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  183. package/lib/WAUSync/Protocols/USyncContactProtocol.js +36 -0
  184. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +26 -0
  185. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +62 -0
  186. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +14 -0
  187. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +35 -0
  188. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +9 -0
  189. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
  190. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +14 -0
  191. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +46 -0
  192. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  193. package/lib/WAUSync/Protocols/index.js +26 -0
  194. package/lib/WAUSync/USyncQuery.d.ts +31 -0
  195. package/lib/WAUSync/USyncQuery.js +92 -0
  196. package/lib/WAUSync/USyncUser.d.ts +12 -0
  197. package/lib/WAUSync/USyncUser.js +30 -0
  198. package/lib/WAUSync/index.d.ts +3 -0
  199. package/lib/WAUSync/index.js +23 -0
  200. package/lib/index.d.ts +13 -0
  201. package/lib/index.js +33 -0
  202. package/package.json +88 -10
  203. package/index.js +0 -38
@@ -0,0 +1,266 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { KeyPair, SignedKeyPair, SocketConfig } from '../Types';
3
+ export declare const makeRegistrationSocket: (config: SocketConfig) => {
4
+ register: (code: string) => Promise<ExistsResponse>;
5
+ requestRegistrationCode: (registrationOptions?: RegistrationOptions) => Promise<ExistsResponse>;
6
+ logger: import("../Utils/logger").ILogger;
7
+ getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
8
+ getCatalog: ({ jid, limit, cursor }: import("../Types").GetCatalogOptions) => Promise<{
9
+ products: import("../Types").Product[];
10
+ nextPageCursor: string | undefined;
11
+ }>;
12
+ getCollections: (jid?: string, limit?: number) => Promise<{
13
+ collections: import("../Types").CatalogCollection[];
14
+ }>;
15
+ productCreate: (create: import("../Types").ProductCreate) => Promise<import("../Types").Product>;
16
+ productDelete: (productIds: string[]) => Promise<{
17
+ deleted: number;
18
+ }>;
19
+ productUpdate: (productId: string, update: import("../Types").ProductUpdate) => Promise<import("../Types").Product>;
20
+ sendMessageAck: ({ tag, attrs, content }: import("../WABinary").BinaryNode, errorCode?: number) => Promise<void>;
21
+ sendRetryRequest: (node: import("../WABinary").BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
22
+ rejectCall: (callId: string, callFrom: string) => Promise<void>;
23
+ offerCall: (toJid: string, isVideo?: boolean) => Promise<{
24
+ callId: string;
25
+ toJid: string;
26
+ isVideo: boolean;
27
+ }>;
28
+ fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
29
+ requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<"RESOLVED" | string | undefined>;
30
+ getPrivacyTokens: (jids: string[]) => Promise<any>;
31
+ assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
32
+ relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
33
+ sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
34
+ sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
35
+ readMessages: (keys: import("../Types").WAMessageKey[]) => Promise<void>;
36
+ refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
37
+ waUploadToServer: import("../Types").WAMediaUploadFunction;
38
+ fetchPrivacySettings: (force?: boolean) => Promise<{
39
+ [_: string]: string;
40
+ }>;
41
+ getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
42
+ createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: import("../WABinary").BinaryNode["attrs"]) => Promise<{
43
+ nodes: import("../WABinary").BinaryNode[];
44
+ shouldIncludeDeviceIdentity: boolean;
45
+ }>;
46
+ sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
47
+ updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
48
+ sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
49
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
50
+ duration: string;
51
+ }>;
52
+ newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
53
+ newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
54
+ newsletterUpdateName: (jid: string, name: string) => Promise<void>;
55
+ newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
56
+ newsletterRemovePicture: (jid: string) => Promise<void>;
57
+ newsletterUnfollow: (jid: string) => Promise<void>;
58
+ newsletterFollow: (jid: string) => Promise<void>;
59
+ newsletterUnmute: (jid: string) => Promise<void>;
60
+ newsletterMute: (jid: string) => Promise<void>;
61
+ newsletterCreate: (name: string, description?: string, picture?: import("../Types").WAMediaUpload) => Promise<import("../Types").NewsletterMetadata>;
62
+ newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole) => Promise<import("../Types").NewsletterMetadata>;
63
+ newsletterAdminCount: (jid: string) => Promise<number>;
64
+ newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
65
+ newsletterDemote: (jid: string, user: string) => Promise<void>;
66
+ newsletterDelete: (jid: string) => Promise<void>;
67
+ newsletterReactMessage: (jid: string, server_id: string, code?: string) => Promise<void>;
68
+ newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
69
+ newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
70
+ groupQuery: (jid: string, type: "get" | "set", content: import("../WABinary").BinaryNode[]) => Promise<any>;
71
+ groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
72
+ groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
73
+ groupLeave: (id: string) => Promise<void>;
74
+ groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
75
+ groupRequestParticipantsList: (jid: string) => Promise<{
76
+ [key: string]: string;
77
+ }[]>;
78
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
79
+ status: string;
80
+ jid: string;
81
+ }[]>;
82
+ groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
83
+ status: string;
84
+ jid: string;
85
+ content: import("../WABinary").BinaryNode;
86
+ }[]>;
87
+ groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
88
+ groupInviteCode: (jid: string) => Promise<string | undefined>;
89
+ groupRevokeInvite: (jid: string) => Promise<string | undefined>;
90
+ groupAcceptInvite: (code: string) => Promise<string | undefined>;
91
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
92
+ groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
93
+ groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
94
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
95
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
96
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
97
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
98
+ groupFetchAllParticipating: () => Promise<{
99
+ [_: string]: import("../Types").GroupMetadata;
100
+ }>;
101
+ getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
102
+ processingMutex: {
103
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
104
+ };
105
+ upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
106
+ appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
107
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
108
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
109
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
110
+ onWhatsApp: (...jids: string[]) => Promise<{
111
+ jid: string;
112
+ exists: unknown;
113
+ lid: unknown;
114
+ }[] | undefined>;
115
+ fetchBlocklist: () => Promise<string[]>;
116
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
117
+ fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
118
+ updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
119
+ removeProfilePicture: (jid: string) => Promise<void>;
120
+ updateProfileStatus: (status: string) => Promise<void>;
121
+ updateProfileName: (name: string) => Promise<void>;
122
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
123
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
124
+ updateMessagesPrivacy: (value: import("../Types").WAPrivacyMessagesValue) => Promise<void>;
125
+ updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
126
+ updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
127
+ updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
128
+ updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
129
+ updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
130
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
131
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>;
132
+ getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
133
+ resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
134
+ chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
135
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
136
+ addChatLabel: (jid: string, labelId: string) => Promise<void>;
137
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>;
138
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
139
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
140
+ star: (jid: string, messages: {
141
+ id: string;
142
+ fromMe?: boolean;
143
+ }[], star: boolean) => Promise<void>;
144
+ executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
145
+ type: "md";
146
+ ws: any;
147
+ ev: import("../Types").BaileysEventEmitter & {
148
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
149
+ buffer(): void;
150
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
151
+ flush(force?: boolean): boolean;
152
+ isBuffering(): boolean;
153
+ };
154
+ authState: {
155
+ creds: import("../Types").AuthenticationCreds;
156
+ keys: import("../Types").SignalKeyStoreWithTransaction;
157
+ };
158
+ signalRepository: import("../Types").SignalRepository;
159
+ user: import("../Types").Contact | undefined;
160
+ generateMessageTag: () => string;
161
+ query: (node: import("../WABinary").BinaryNode, timeoutMs?: number) => Promise<any>;
162
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
163
+ waitForSocketOpen: () => Promise<void>;
164
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
165
+ sendNode: (frame: import("../WABinary").BinaryNode) => Promise<void>;
166
+ logout: (msg?: string) => Promise<void>;
167
+ end: (error: Error | undefined) => void;
168
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
169
+ uploadPreKeys: (count?: number) => Promise<void>;
170
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
171
+ requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
172
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
173
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
174
+ };
175
+ export interface RegistrationData {
176
+ registrationId: number;
177
+ signedPreKey: SignedKeyPair;
178
+ noiseKey: KeyPair;
179
+ signedIdentityKey: KeyPair;
180
+ identityId: Buffer;
181
+ phoneId: string;
182
+ deviceId: string;
183
+ backupToken: Buffer;
184
+ }
185
+ export interface RegistrationOptions {
186
+ /** your phone number */
187
+ phoneNumber?: string;
188
+ /** the country code of your phone number */
189
+ phoneNumberCountryCode: string;
190
+ /** your phone number without country code */
191
+ phoneNumberNationalNumber: string;
192
+ /** the country code of your mobile network
193
+ * @see {@link https://de.wikipedia.org/wiki/Mobile_Country_Code}
194
+ */
195
+ phoneNumberMobileCountryCode: string;
196
+ /** the network code of your mobile network
197
+ * @see {@link https://de.wikipedia.org/wiki/Mobile_Network_Code}
198
+ */
199
+ phoneNumberMobileNetworkCode: string;
200
+ /**
201
+ * How to send the one time code
202
+ */
203
+ method?: 'sms' | 'voice' | 'captcha';
204
+ /**
205
+ * The captcha code if it was requested
206
+ */
207
+ captcha?: string;
208
+ }
209
+ export type RegistrationParams = RegistrationData & RegistrationOptions;
210
+ export declare function registrationParams(params: RegistrationParams): {
211
+ cc: string;
212
+ in: string;
213
+ Rc: string;
214
+ lg: string;
215
+ lc: string;
216
+ mistyped: string;
217
+ authkey: string;
218
+ e_regid: string;
219
+ e_keytype: string;
220
+ e_ident: string;
221
+ e_skey_id: string;
222
+ e_skey_val: string;
223
+ e_skey_sig: string;
224
+ fdid: string;
225
+ network_ratio_type: string;
226
+ expid: string;
227
+ simnum: string;
228
+ hasinrc: string;
229
+ pid: string;
230
+ id: string;
231
+ backup_token: string;
232
+ token: string;
233
+ fraud_checkpoint_code: string | undefined;
234
+ };
235
+ /**
236
+ * Requests a registration code for the given phone number.
237
+ */
238
+ export declare function mobileRegisterCode(params: RegistrationParams, fetchOptions?: AxiosRequestConfig): Promise<ExistsResponse>;
239
+ export declare function mobileRegisterExists(params: RegistrationParams, fetchOptions?: AxiosRequestConfig): Promise<ExistsResponse>;
240
+ /**
241
+ * Registers the phone number on whatsapp with the received OTP code.
242
+ */
243
+ export declare function mobileRegister(params: RegistrationParams & {
244
+ code: string;
245
+ }, fetchOptions?: AxiosRequestConfig): Promise<ExistsResponse>;
246
+ /**
247
+ * Encrypts the given string as AEAD aes-256-gcm with the public whatsapp key and a random keypair.
248
+ */
249
+ export declare function mobileRegisterEncrypt(data: string): string;
250
+ export declare function mobileRegisterFetch(path: string, opts?: AxiosRequestConfig): Promise<ExistsResponse>;
251
+ export interface ExistsResponse {
252
+ status: 'fail' | 'sent';
253
+ voice_length?: number;
254
+ voice_wait?: number;
255
+ sms_length?: number;
256
+ sms_wait?: number;
257
+ reason?: 'incorrect' | 'missing_param' | 'code_checkpoint';
258
+ login?: string;
259
+ flash_type?: number;
260
+ ab_hash?: string;
261
+ ab_key?: string;
262
+ exp_cfg?: string;
263
+ lid?: string;
264
+ image_blob?: string;
265
+ audio_blob?: string;
266
+ }
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.makeRegistrationSocket = void 0;
7
+ exports.registrationParams = registrationParams;
8
+ exports.mobileRegisterCode = mobileRegisterCode;
9
+ exports.mobileRegisterExists = mobileRegisterExists;
10
+ exports.mobileRegister = mobileRegister;
11
+ exports.mobileRegisterEncrypt = mobileRegisterEncrypt;
12
+ exports.mobileRegisterFetch = mobileRegisterFetch;
13
+ /* eslint-disable camelcase */
14
+ const axios_1 = __importDefault(require("axios"));
15
+ const Defaults_1 = require("../Defaults");
16
+ const crypto_1 = require("../Utils/crypto");
17
+ const WABinary_1 = require("../WABinary");
18
+ const business_1 = require("./business");
19
+ function urlencode(str) {
20
+ return str.replace(/-/g, '%2d').replace(/_/g, '%5f').replace(/~/g, '%7e');
21
+ }
22
+ const validRegistrationOptions = (config) => (config === null || config === void 0 ? void 0 : config.phoneNumberCountryCode) &&
23
+ config.phoneNumberNationalNumber &&
24
+ config.phoneNumberMobileCountryCode;
25
+ const makeRegistrationSocket = (config) => {
26
+ const sock = (0, business_1.makeBusinessSocket)(config);
27
+ const register = async (code) => {
28
+ if (!validRegistrationOptions(config.auth.creds.registration)) {
29
+ throw new Error('please specify the registration options');
30
+ }
31
+ const result = await mobileRegister({ ...sock.authState.creds, ...sock.authState.creds.registration, code }, config.options);
32
+ sock.authState.creds.me = {
33
+ id: (0, WABinary_1.jidEncode)(result.login, 's.whatsapp.net'),
34
+ name: '~'
35
+ };
36
+ sock.authState.creds.registered = true;
37
+ sock.ev.emit('creds.update', sock.authState.creds);
38
+ return result;
39
+ };
40
+ const requestRegistrationCode = async (registrationOptions) => {
41
+ registrationOptions = registrationOptions || config.auth.creds.registration;
42
+ if (!validRegistrationOptions(registrationOptions)) {
43
+ throw new Error('Invalid registration options');
44
+ }
45
+ sock.authState.creds.registration = registrationOptions;
46
+ sock.ev.emit('creds.update', sock.authState.creds);
47
+ return mobileRegisterCode({ ...config.auth.creds, ...registrationOptions }, config.options);
48
+ };
49
+ return {
50
+ ...sock,
51
+ register,
52
+ requestRegistrationCode,
53
+ };
54
+ };
55
+ exports.makeRegistrationSocket = makeRegistrationSocket;
56
+ function convertBufferToUrlHex(buffer) {
57
+ var id = '';
58
+ buffer.forEach((x) => {
59
+ // encode random identity_id buffer as percentage url encoding
60
+ id += `%${x.toString(16).padStart(2, '0').toLowerCase()}`;
61
+ });
62
+ return id;
63
+ }
64
+ function registrationParams(params) {
65
+ const e_regid = Buffer.alloc(4);
66
+ e_regid.writeInt32BE(params.registrationId);
67
+ const e_skey_id = Buffer.alloc(3);
68
+ e_skey_id.writeInt16BE(params.signedPreKey.keyId);
69
+ params.phoneNumberCountryCode = params.phoneNumberCountryCode.replace('+', '').trim();
70
+ params.phoneNumberNationalNumber = params.phoneNumberNationalNumber.replace(/[/-\s)(]/g, '').trim();
71
+ return {
72
+ cc: params.phoneNumberCountryCode,
73
+ in: params.phoneNumberNationalNumber,
74
+ Rc: '0',
75
+ lg: 'en',
76
+ lc: 'GB',
77
+ mistyped: '6',
78
+ authkey: Buffer.from(params.noiseKey.public).toString('base64url'),
79
+ e_regid: e_regid.toString('base64url'),
80
+ e_keytype: 'BQ',
81
+ e_ident: Buffer.from(params.signedIdentityKey.public).toString('base64url'),
82
+ // e_skey_id: e_skey_id.toString('base64url'),
83
+ e_skey_id: 'AAAA',
84
+ e_skey_val: Buffer.from(params.signedPreKey.keyPair.public).toString('base64url'),
85
+ e_skey_sig: Buffer.from(params.signedPreKey.signature).toString('base64url'),
86
+ fdid: params.phoneId,
87
+ network_ratio_type: '1',
88
+ expid: params.deviceId,
89
+ simnum: '1',
90
+ hasinrc: '1',
91
+ pid: Math.floor(Math.random() * 1000).toString(),
92
+ id: convertBufferToUrlHex(params.identityId),
93
+ backup_token: convertBufferToUrlHex(params.backupToken),
94
+ token: (0, crypto_1.md5)(Buffer.concat([Defaults_1.MOBILE_TOKEN, Buffer.from(params.phoneNumberNationalNumber)])).toString('hex'),
95
+ fraud_checkpoint_code: params.captcha,
96
+ };
97
+ }
98
+ /**
99
+ * Requests a registration code for the given phone number.
100
+ */
101
+ function mobileRegisterCode(params, fetchOptions) {
102
+ return mobileRegisterFetch('/code', {
103
+ params: {
104
+ ...registrationParams(params),
105
+ mcc: `${params.phoneNumberMobileCountryCode}`.padStart(3, '0'),
106
+ mnc: `${params.phoneNumberMobileNetworkCode || '001'}`.padStart(3, '0'),
107
+ sim_mcc: '000',
108
+ sim_mnc: '000',
109
+ method: (params === null || params === void 0 ? void 0 : params.method) || 'sms',
110
+ reason: '',
111
+ hasav: '1'
112
+ },
113
+ ...fetchOptions,
114
+ });
115
+ }
116
+ function mobileRegisterExists(params, fetchOptions) {
117
+ return mobileRegisterFetch('/exist', {
118
+ params: registrationParams(params),
119
+ ...fetchOptions
120
+ });
121
+ }
122
+ /**
123
+ * Registers the phone number on whatsapp with the received OTP code.
124
+ */
125
+ async function mobileRegister(params, fetchOptions) {
126
+ //const result = await mobileRegisterFetch(`/reg_onboard_abprop?cc=${params.phoneNumberCountryCode}&in=${params.phoneNumberNationalNumber}&rc=0`)
127
+ return mobileRegisterFetch('/register', {
128
+ params: { ...registrationParams(params), code: params.code.replace('-', '') },
129
+ ...fetchOptions,
130
+ });
131
+ }
132
+ /**
133
+ * Encrypts the given string as AEAD aes-256-gcm with the public whatsapp key and a random keypair.
134
+ */
135
+ function mobileRegisterEncrypt(data) {
136
+ const keypair = crypto_1.Curve.generateKeyPair();
137
+ const key = crypto_1.Curve.sharedKey(keypair.private, Defaults_1.REGISTRATION_PUBLIC_KEY);
138
+ const buffer = (0, crypto_1.aesEncryptGCM)(Buffer.from(data), new Uint8Array(key), Buffer.alloc(12), Buffer.alloc(0));
139
+ return Buffer.concat([Buffer.from(keypair.public), buffer]).toString('base64url');
140
+ }
141
+ async function mobileRegisterFetch(path, opts = {}) {
142
+ let url = `${Defaults_1.MOBILE_REGISTRATION_ENDPOINT}${path}`;
143
+ if (opts.params) {
144
+ const parameter = [];
145
+ for (const param in opts.params) {
146
+ if (opts.params[param] !== null && opts.params[param] !== undefined) {
147
+ parameter.push(param + '=' + urlencode(opts.params[param]));
148
+ }
149
+ }
150
+ url += `?${parameter.join('&')}`;
151
+ delete opts.params;
152
+ }
153
+ if (!opts.headers) {
154
+ opts.headers = {};
155
+ }
156
+ opts.headers['User-Agent'] = Defaults_1.MOBILE_USERAGENT;
157
+ const response = await (0, axios_1.default)(url, opts);
158
+ var json = response.data;
159
+ if (response.status > 300 || json.reason) {
160
+ throw json;
161
+ }
162
+ if (json.status && !['ok', 'sent'].includes(json.status)) {
163
+ throw json;
164
+ }
165
+ return json;
166
+ }
@@ -0,0 +1,45 @@
1
+ import { Boom } from '@hapi/boom'
2
+ import { SocketConfig } from '../Types'
3
+ import { BinaryNode } from '../WABinary'
4
+ import { WebSocketClient } from './Client'
5
+
6
+ /**
7
+ * Connects to WA servers and performs:
8
+ * - simple queries (no retry mechanism, wait for connection establishment)
9
+ * - listen to messages and emit events
10
+ * - query phone connection
11
+ */
12
+ export declare const makeSocket: (config: SocketConfig) => {
13
+ type: "md"
14
+ ws: WebSocketClient
15
+ ev: import("../Types").BaileysEventEmitter & {
16
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void
17
+ buffer(): void
18
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>
19
+ flush(force?: boolean | undefined): boolean
20
+ isBuffering(): boolean
21
+ }
22
+ authState: {
23
+ creds: import("../Types").AuthenticationCreds
24
+ keys: import("../Types").SignalKeyStoreWithTransaction
25
+ }
26
+ signalRepository: import("../Types").SignalRepository
27
+ readonly user: import("../Types").Contact | undefined
28
+ generateMessageTag: () => string
29
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>
30
+ waitForMessage: <T_1>(msgId: string, timeoutMs?: number | undefined) => Promise<T_1>
31
+ waitForSocketOpen: () => Promise<void>
32
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>
33
+ sendNode: (frame: BinaryNode) => Promise<void>
34
+ logout: (msg?: string) => Promise<void>
35
+ end: (error: Error | undefined) => void
36
+ onUnexpectedError: (err: Error | Boom, msg: string) => void
37
+ uploadPreKeys: (count?: number) => Promise<void>
38
+ uploadPreKeysToServerIfRequired: () => Promise<void>
39
+ requestPairingCode: (phoneNumber: string, code?: string) => Promise<string>
40
+ /** Waits for the connection to WA to reach a state */
41
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>
42
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>
43
+ }
44
+
45
+ export type Socket = ReturnType<typeof makeSocket>