@badzz88/baileys 8.5.6 → 8.5.8

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 (225) hide show
  1. package/README.md +337 -1055
  2. package/WAProto/WAProto.proto +28 -1189
  3. package/WAProto/fix-imports.js +79 -69
  4. package/WAProto/index.d.ts +71491 -15254
  5. package/WAProto/index.js +126436 -19814
  6. package/engine-requirements.js +8 -15
  7. package/lib/Defaults/index.js +130 -0
  8. package/{src → lib}/Signal/Group/ciphertext-message.js +2 -5
  9. package/lib/Signal/Group/group-session-builder.js +30 -0
  10. package/{src → lib}/Signal/Group/group_cipher.js +11 -11
  11. package/lib/Signal/Group/index.js +12 -0
  12. package/lib/Signal/Group/keyhelper.js +18 -0
  13. package/{src → lib}/Signal/Group/sender-chain-key.js +6 -9
  14. package/{src → lib}/Signal/Group/sender-key-distribution-message.js +6 -9
  15. package/{src → lib}/Signal/Group/sender-key-message.js +9 -12
  16. package/{src → lib}/Signal/Group/sender-key-name.js +2 -5
  17. package/{src → lib}/Signal/Group/sender-key-record.js +8 -11
  18. package/{src → lib}/Signal/Group/sender-key-state.js +6 -9
  19. package/lib/Signal/Group/sender-message-key.js +26 -0
  20. package/{src → lib}/Signal/libsignal.js +131 -155
  21. package/{src → lib}/Signal/lid-mapping.js +27 -23
  22. package/lib/Socket/Client/index.js +3 -0
  23. package/lib/Socket/Client/types.js +11 -0
  24. package/{src → lib}/Socket/Client/websocket.js +11 -18
  25. package/{src → lib}/Socket/business.js +35 -67
  26. package/{src → lib}/Socket/chats.js +294 -550
  27. package/{src → lib}/Socket/communities.js +82 -114
  28. package/lib/Socket/graphql.js +716 -0
  29. package/lib/Socket/groups.js +374 -0
  30. package/lib/Socket/index.js +18 -0
  31. package/lib/Socket/interop.js +463 -0
  32. package/{src → lib}/Socket/luxu.js +120 -82
  33. package/lib/Socket/messages-recv.js +1916 -0
  34. package/lib/Socket/messages-send.js +1436 -0
  35. package/lib/Socket/mex.js +54 -0
  36. package/lib/Socket/newsletter.js +757 -0
  37. package/lib/Socket/privacy.js +318 -0
  38. package/{src → lib}/Socket/socket.js +356 -244
  39. package/lib/Socket/username.js +236 -0
  40. package/lib/Store/index.js +10 -0
  41. package/{src → lib}/Store/keyed-db.js +11 -21
  42. package/lib/Store/make-cache-manager-store.js +85 -0
  43. package/lib/Store/make-in-memory-store.js +244 -0
  44. package/{src → lib}/Store/make-ordered-dictionary.js +19 -25
  45. package/{src → lib}/Store/object-repository.js +11 -5
  46. package/lib/Types/Auth.js +2 -0
  47. package/lib/Types/Bussines.js +2 -0
  48. package/lib/Types/Call.js +2 -0
  49. package/lib/Types/Chat.js +8 -0
  50. package/lib/Types/Contact.js +2 -0
  51. package/lib/Types/Events.js +2 -0
  52. package/lib/Types/GroupMetadata.js +2 -0
  53. package/lib/Types/Label.js +25 -0
  54. package/lib/Types/LabelAssociation.js +7 -0
  55. package/lib/Types/Message.js +11 -0
  56. package/lib/Types/Mex.js +111 -0
  57. package/lib/Types/Product.js +2 -0
  58. package/lib/Types/Signal.js +2 -0
  59. package/lib/Types/Socket.js +3 -0
  60. package/lib/Types/State.js +56 -0
  61. package/lib/Types/USync.js +2 -0
  62. package/lib/Types/index.js +26 -0
  63. package/{src → lib}/Utils/auth-utils.js +91 -43
  64. package/lib/Utils/browser-utils.js +48 -0
  65. package/lib/Utils/business.js +231 -0
  66. package/lib/Utils/chat-utils.js +872 -0
  67. package/lib/Utils/companion-reg-client-utils.js +35 -0
  68. package/lib/Utils/crypto.js +118 -0
  69. package/lib/Utils/decode-wa-message.js +350 -0
  70. package/{src → lib}/Utils/event-buffer.js +81 -39
  71. package/lib/Utils/generics.js +403 -0
  72. package/lib/Utils/history.js +134 -0
  73. package/{src → lib}/Utils/identity-change-handler.js +9 -11
  74. package/lib/Utils/index.js +23 -0
  75. package/lib/Utils/link-preview.js +85 -0
  76. package/lib/Utils/logger.js +3 -0
  77. package/lib/Utils/lt-hash.js +8 -0
  78. package/{src → lib}/Utils/make-mutex.js +7 -10
  79. package/lib/Utils/message-composer.js +273 -0
  80. package/{src → lib}/Utils/message-retry-manager.js +76 -28
  81. package/lib/Utils/messages-media.js +870 -0
  82. package/lib/Utils/messages.js +1337 -0
  83. package/lib/Utils/noise-handler.js +201 -0
  84. package/{src → lib}/Utils/offline-node-processor.js +10 -4
  85. package/{src → lib}/Utils/pre-key-manager.js +27 -11
  86. package/lib/Utils/process-message.js +630 -0
  87. package/{src → lib}/Utils/reporting-utils.js +12 -15
  88. package/lib/Utils/signal.js +201 -0
  89. package/{src → lib}/Utils/stanza-ack.js +12 -4
  90. package/lib/Utils/sticker.js +110 -0
  91. package/{src → lib}/Utils/sync-action-utils.js +14 -10
  92. package/{src → lib}/Utils/tc-token-utils.js +48 -43
  93. package/{src → lib}/Utils/use-multi-file-auth-state.js +35 -25
  94. package/lib/Utils/validate-connection.js +203 -0
  95. package/{src → lib}/WABinary/constants.js +9 -12
  96. package/{src → lib}/WABinary/decode.js +38 -118
  97. package/{src → lib}/WABinary/encode.js +6 -11
  98. package/lib/WABinary/generic-utils.js +204 -0
  99. package/lib/WABinary/index.js +6 -0
  100. package/lib/WABinary/jid-utils.js +98 -0
  101. package/lib/WABinary/types.js +2 -0
  102. package/{src → lib}/WAM/BinaryInfo.js +2 -5
  103. package/{src → lib}/WAM/constants.js +4 -16635
  104. package/{src → lib}/WAM/encode.js +18 -17
  105. package/lib/WAM/index.js +4 -0
  106. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
  107. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  108. package/lib/WAUSync/Protocols/USyncContactProtocol.js +54 -0
  109. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  110. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  111. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +58 -0
  112. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
  113. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  114. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +28 -0
  115. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
  116. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  117. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
  118. package/lib/WAUSync/Protocols/index.js +12 -0
  119. package/lib/WAUSync/USyncQuery.js +151 -0
  120. package/lib/WAUSync/USyncUser.js +56 -0
  121. package/lib/WAUSync/index.js +3 -0
  122. package/{src → lib}/index.js +16 -51
  123. package/package.json +129 -99
  124. package/LICENSE +0 -21
  125. package/src/Defaults/index.js +0 -186
  126. package/src/Defaults/phonenumber-mcc.json +0 -223
  127. package/src/Signal/Group/group-session-builder.js +0 -86
  128. package/src/Signal/Group/index.js +0 -140
  129. package/src/Signal/Group/keyhelper.js +0 -77
  130. package/src/Signal/Group/sender-message-key.js +0 -29
  131. package/src/Socket/Client/index.js +0 -31
  132. package/src/Socket/Client/types.js +0 -13
  133. package/src/Socket/aigroups.js +0 -221
  134. package/src/Socket/graphql.js +0 -523
  135. package/src/Socket/groups.js +0 -516
  136. package/src/Socket/index.js +0 -31
  137. package/src/Socket/interactive-handler.js +0 -527
  138. package/src/Socket/interop.js +0 -339
  139. package/src/Socket/managed-account.js +0 -98
  140. package/src/Socket/messages-recv.js +0 -2685
  141. package/src/Socket/messages-send.js +0 -2047
  142. package/src/Socket/mex.js +0 -57
  143. package/src/Socket/newsletter.js +0 -455
  144. package/src/Socket/privacy.js +0 -125
  145. package/src/Socket/registration.js +0 -236
  146. package/src/Socket/text-router.js +0 -65
  147. package/src/Socket/username.js +0 -130
  148. package/src/Store/index.js +0 -33
  149. package/src/Store/make-cache-manager-store.js +0 -84
  150. package/src/Store/make-in-memory-store.js +0 -551
  151. package/src/Types/Auth.js +0 -31
  152. package/src/Types/Bussines.js +0 -2
  153. package/src/Types/Call.js +0 -2
  154. package/src/Types/Chat.js +0 -4
  155. package/src/Types/Contact.js +0 -2
  156. package/src/Types/Events.js +0 -2
  157. package/src/Types/GroupMetadata.js +0 -2
  158. package/src/Types/Label.js +0 -26
  159. package/src/Types/LabelAssociation.js +0 -8
  160. package/src/Types/Message.js +0 -93
  161. package/src/Types/Mex.js +0 -112
  162. package/src/Types/Newsletter.js +0 -109
  163. package/src/Types/Product.js +0 -2
  164. package/src/Types/Signal.js +0 -2
  165. package/src/Types/Socket.js +0 -2
  166. package/src/Types/State.js +0 -62
  167. package/src/Types/USync.js +0 -2
  168. package/src/Types/index.js +0 -56
  169. package/src/Utils/browser-utils.js +0 -112
  170. package/src/Utils/business.js +0 -240
  171. package/src/Utils/chat-utils.js +0 -1230
  172. package/src/Utils/command-loader.d.ts +0 -27
  173. package/src/Utils/command-loader.js +0 -89
  174. package/src/Utils/companion-reg-client-utils.js +0 -40
  175. package/src/Utils/consumer-application.js +0 -105
  176. package/src/Utils/crypto.js +0 -118
  177. package/src/Utils/curve25519-js.js +0 -242
  178. package/src/Utils/decode-wa-message.js +0 -529
  179. package/src/Utils/generics.js +0 -483
  180. package/src/Utils/group-history.js +0 -44
  181. package/src/Utils/history.js +0 -232
  182. package/src/Utils/index.js +0 -58
  183. package/src/Utils/jid-display-normalization.js +0 -195
  184. package/src/Utils/link-preview.js +0 -135
  185. package/src/Utils/logger.js +0 -8
  186. package/src/Utils/lt-hash.js +0 -25
  187. package/src/Utils/message-composer.js +0 -471
  188. package/src/Utils/messages-media.js +0 -843
  189. package/src/Utils/messages.js +0 -2817
  190. package/src/Utils/meta-ai-msmsg.js +0 -222
  191. package/src/Utils/native-bridge.js +0 -68
  192. package/src/Utils/noise-handler.js +0 -169
  193. package/src/Utils/process-message.js +0 -950
  194. package/src/Utils/session-pool.d.ts +0 -14
  195. package/src/Utils/session-pool.js +0 -70
  196. package/src/Utils/signal.js +0 -217
  197. package/src/Utils/sticker.d.ts +0 -13
  198. package/src/Utils/sticker.js +0 -123
  199. package/src/Utils/validate-connection.js +0 -209
  200. package/src/Utils/view-once-cache.d.ts +0 -12
  201. package/src/Utils/view-once-cache.js +0 -63
  202. package/src/Utils/voip-rekey.js +0 -22
  203. package/src/WABinary/generic-utils.js +0 -238
  204. package/src/WABinary/index.js +0 -34
  205. package/src/WABinary/jid-utils.js +0 -351
  206. package/src/WABinary/types.js +0 -2
  207. package/src/WAM/index.js +0 -32
  208. package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -53
  209. package/src/WAUSync/Protocols/USyncBusinessProtocol.js +0 -44
  210. package/src/WAUSync/Protocols/USyncContactProtocol.js +0 -55
  211. package/src/WAUSync/Protocols/USyncDeviceProtocol.js +0 -55
  212. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -31
  213. package/src/WAUSync/Protocols/USyncFeatureProtocol.js +0 -54
  214. package/src/WAUSync/Protocols/USyncLIDProtocol.js +0 -32
  215. package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -473
  216. package/src/WAUSync/Protocols/USyncPictureProtocol.js +0 -34
  217. package/src/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
  218. package/src/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
  219. package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
  220. package/src/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
  221. package/src/WAUSync/Protocols/index.js +0 -40
  222. package/src/WAUSync/USyncQuery.js +0 -126
  223. package/src/WAUSync/USyncUser.js +0 -50
  224. package/src/WAUSync/index.js +0 -32
  225. package/src/antiban.js +0 -4152
@@ -1,27 +0,0 @@
1
- export interface CommandContext {
2
- sock: any;
3
- msg: any;
4
- args: string[];
5
- text: string;
6
- jid: string;
7
- sender: string;
8
- isGroup: boolean;
9
- }
10
- export interface Command {
11
- name: string;
12
- aliases?: string[];
13
- description?: string;
14
- execute(ctx: CommandContext): Promise<void> | void;
15
- }
16
- export interface CommandHandlerOptions {
17
- commandsDir: string;
18
- prefix?: string;
19
- logger?: any;
20
- onError?: (error: any, msg: any) => void;
21
- }
22
- export interface CommandHandler {
23
- commands: Map<string, Command>;
24
- reload: () => void;
25
- stop: () => void;
26
- }
27
- export function createCommandHandler(sock: any, options: CommandHandlerOptions): CommandHandler;
@@ -1,89 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.createCommandHandler = void 0;
4
- const fs = require('fs');
5
- const path = require('path');
6
- const createCommandHandler = (sock, options) => {
7
- const prefix = options.prefix ?? '!';
8
- const logger = options.logger || sock.logger;
9
- const commands = new Map();
10
- const load = () => {
11
- commands.clear();
12
- const dir = options.commandsDir;
13
- if (!fs.existsSync(dir)) {
14
- logger?.warn?.({ dir }, 'commands directory does not exist');
15
- return;
16
- }
17
- const files = fs.readdirSync(dir).filter(f => f.endsWith('.js'));
18
- for (const file of files) {
19
- const fullPath = path.join(dir, file);
20
- try {
21
- delete require.cache[require.resolve(fullPath)];
22
- const mod = require(fullPath);
23
- const cmd = mod?.default || mod;
24
- if (!cmd?.name || typeof cmd.execute !== 'function') {
25
- logger?.warn?.({ file }, 'skipping invalid command module (missing name/execute)');
26
- continue;
27
- }
28
- commands.set(cmd.name.toLowerCase(), cmd);
29
- for (const alias of cmd.aliases || []) {
30
- commands.set(alias.toLowerCase(), cmd);
31
- }
32
- }
33
- catch (error) {
34
- logger?.error?.({ error, file }, 'failed to load command');
35
- }
36
- }
37
- logger?.debug?.({ count: commands.size }, 'commands loaded');
38
- };
39
- load();
40
- const handler = async ({ messages, type }) => {
41
- if (type !== 'notify')
42
- return;
43
- for (const msg of messages) {
44
- try {
45
- if (!msg.message || msg.key.fromMe)
46
- continue;
47
- const body = msg.message.conversation ||
48
- msg.message.extendedTextMessage?.text ||
49
- msg.message.imageMessage?.caption ||
50
- msg.message.videoMessage?.caption ||
51
- '';
52
- if (!body.startsWith(prefix))
53
- continue;
54
- const [cmdName, ...args] = body.slice(prefix.length).trim().split(/\s+/);
55
- if (!cmdName)
56
- continue;
57
- const cmd = commands.get(cmdName.toLowerCase());
58
- if (!cmd)
59
- continue;
60
- const jid = msg.key.remoteJid;
61
- const ctx = {
62
- sock,
63
- msg,
64
- args,
65
- text: args.join(' '),
66
- jid,
67
- sender: msg.key.participant || msg.key.remoteJid,
68
- isGroup: !!jid && jid.endsWith('@g.us')
69
- };
70
- await cmd.execute(ctx);
71
- }
72
- catch (error) {
73
- if (options.onError) {
74
- options.onError(error, msg);
75
- }
76
- else {
77
- logger?.error?.({ error }, 'command execution failed');
78
- }
79
- }
80
- }
81
- };
82
- sock.ev.on('messages.upsert', handler);
83
- return {
84
- commands,
85
- reload: load,
86
- stop: () => sock.ev.off('messages.upsert', handler)
87
- };
88
- };
89
- exports.createCommandHandler = createCommandHandler;
@@ -1,40 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.buildPairingQRData = exports.getCompanionPlatformId = exports.getCompanionWebClientType = exports.CompanionWebClientType = void 0;
4
- var CompanionWebClientType;
5
- (function (CompanionWebClientType) {
6
- CompanionWebClientType[(CompanionWebClientType['UNKNOWN'] = 0)] = 'UNKNOWN';
7
- CompanionWebClientType[(CompanionWebClientType['CHROME'] = 1)] = 'CHROME';
8
- CompanionWebClientType[(CompanionWebClientType['EDGE'] = 2)] = 'EDGE';
9
- CompanionWebClientType[(CompanionWebClientType['FIREFOX'] = 3)] = 'FIREFOX';
10
- CompanionWebClientType[(CompanionWebClientType['IE'] = 4)] = 'IE';
11
- CompanionWebClientType[(CompanionWebClientType['OPERA'] = 5)] = 'OPERA';
12
- CompanionWebClientType[(CompanionWebClientType['SAFARI'] = 6)] = 'SAFARI';
13
- CompanionWebClientType[(CompanionWebClientType['ELECTRON'] = 7)] = 'ELECTRON';
14
- CompanionWebClientType[(CompanionWebClientType['UWP'] = 8)] = 'UWP';
15
- CompanionWebClientType[(CompanionWebClientType['OTHER_WEB_CLIENT'] = 9)] = 'OTHER_WEB_CLIENT';
16
- })((CompanionWebClientType = exports.CompanionWebClientType || (exports.CompanionWebClientType = {})));
17
- const BROWSER_TO_COMPANION_WEB_CLIENT = {
18
- Chrome: CompanionWebClientType.CHROME,
19
- Edge: CompanionWebClientType.EDGE,
20
- Firefox: CompanionWebClientType.FIREFOX,
21
- IE: CompanionWebClientType.IE,
22
- Opera: CompanionWebClientType.OPERA,
23
- Safari: CompanionWebClientType.SAFARI
24
- };
25
- const getCompanionWebClientType = ([os, browserName]) => {
26
- if (browserName === 'Desktop') {
27
- return os === 'Windows' ? CompanionWebClientType.UWP : CompanionWebClientType.ELECTRON;
28
- }
29
- return BROWSER_TO_COMPANION_WEB_CLIENT[browserName] || CompanionWebClientType.OTHER_WEB_CLIENT;
30
- };
31
- exports.getCompanionWebClientType = getCompanionWebClientType;
32
- const getCompanionPlatformId = (browser) => {
33
- return getCompanionWebClientType(browser).toString();
34
- };
35
- exports.getCompanionPlatformId = getCompanionPlatformId;
36
- const buildPairingQRData = (ref, noiseKeyB64, identityKeyB64, advB64, browser) => {
37
- return ('https://wa.me/settings/linked_devices#' +
38
- [ref, noiseKeyB64, identityKeyB64, advB64, getCompanionPlatformId(browser)].join(','));
39
- };
40
- exports.buildPairingQRData = buildPairingQRData;
@@ -1,105 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.consumerApplicationToMessage = exports.decodeConsumerApplication = void 0;
4
- const index_js_1 = require('../../WAProto/index.js');
5
- const decodeConsumerApplication = buffer => {
6
- if (!Buffer.isBuffer(buffer) && !(buffer instanceof Uint8Array)) {
7
- throw new TypeError('decodeConsumerApplication: buffer must be Buffer or Uint8Array');
8
- }
9
- return index_js_1.proto.ConsumerApplication.decode(buffer);
10
- };
11
- exports.decodeConsumerApplication = decodeConsumerApplication;
12
- const textOf = mt => (mt && typeof mt.text === 'string' ? mt.text : undefined);
13
- const mapContent = content => {
14
- if (!content)
15
- return null;
16
- switch (content.content) {
17
- case 'messageText':
18
- return { conversation: textOf(content.messageText) ?? '' };
19
- case 'extendedTextMessage': {
20
- const e = content.extendedTextMessage;
21
- return {
22
- extendedTextMessage: {
23
- text: textOf(e.text),
24
- matchedText: e.matchedText,
25
- canonicalUrl: e.canonicalUrl,
26
- description: e.description,
27
- title: e.title
28
- }
29
- };
30
- }
31
- case 'imageMessage':
32
- return {
33
- imageMessage: { mediaPayload: content.imageMessage.image, caption: textOf(content.imageMessage.caption) }
34
- };
35
- case 'videoMessage':
36
- return {
37
- videoMessage: { mediaPayload: content.videoMessage.video, caption: textOf(content.videoMessage.caption) }
38
- };
39
- case 'audioMessage':
40
- return { audioMessage: { mediaPayload: content.audioMessage.audio, ptt: content.audioMessage.ptt } };
41
- case 'documentMessage':
42
- return {
43
- documentMessage: { mediaPayload: content.documentMessage.document, fileName: content.documentMessage.fileName }
44
- };
45
- case 'stickerMessage':
46
- return { stickerMessage: { mediaPayload: content.stickerMessage.sticker } };
47
- case 'contactMessage':
48
- return { contactMessage: { mediaPayload: content.contactMessage.contact } };
49
- case 'contactsArrayMessage':
50
- return {
51
- contactsArrayMessage: {
52
- displayName: content.contactsArrayMessage.displayName,
53
- contacts: content.contactsArrayMessage.contacts || []
54
- }
55
- };
56
- case 'locationMessage': {
57
- const loc = content.locationMessage.location || {};
58
- return {
59
- locationMessage: {
60
- degreesLatitude: loc.degreesLatitude,
61
- degreesLongitude: loc.degreesLongitude,
62
- name: loc.name
63
- }
64
- };
65
- }
66
- case 'liveLocationMessage': {
67
- const loc = content.liveLocationMessage.location || {};
68
- return {
69
- liveLocationMessage: {
70
- degreesLatitude: loc.degreesLatitude,
71
- degreesLongitude: loc.degreesLongitude,
72
- caption: textOf(content.liveLocationMessage.caption)
73
- }
74
- };
75
- }
76
- case 'reactionMessage':
77
- return { reactionMessage: content.reactionMessage };
78
- default:
79
- return null;
80
- }
81
- };
82
- const consumerApplicationToMessage = app => {
83
- const payload = app?.payload;
84
- if (!payload)
85
- return null;
86
- switch (payload.payload) {
87
- case 'content':
88
- return mapContent(payload.content);
89
- case 'applicationData': {
90
- const ad = payload.applicationData;
91
- if (ad?.applicationContent === 'revoke' && ad.revoke?.key) {
92
- return {
93
- protocolMessage: {
94
- key: ad.revoke.key,
95
- type: index_js_1.proto.Message.ProtocolMessage.Type.REVOKE
96
- }
97
- };
98
- }
99
- return null;
100
- }
101
- default:
102
- return null;
103
- }
104
- };
105
- exports.consumerApplicationToMessage = consumerApplicationToMessage;
@@ -1,118 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = exports.hkdf = exports.md5 = void 0;
4
- exports.aesEncryptGCM = aesEncryptGCM;
5
- exports.aesDecryptGCM = aesDecryptGCM;
6
- exports.aesEncryptCTR = aesEncryptCTR;
7
- exports.aesDecryptCTR = aesDecryptCTR;
8
- exports.aesDecrypt = aesDecrypt;
9
- exports.aesDecryptWithIV = aesDecryptWithIV;
10
- exports.aesEncrypt = aesEncrypt;
11
- exports.aesEncrypWithIV = aesEncrypWithIV;
12
- exports.hmacSign = hmacSign;
13
- exports.sha256 = sha256;
14
- exports.derivePairingCodeKey = derivePairingCodeKey;
15
- const { subtle } = globalThis.crypto;
16
- const Defaults_1 = require('../Defaults');
17
- const nodeCrypto = require('crypto');
18
- const md5 = buffer => nodeCrypto.createHash('md5').update(buffer).digest();
19
- Object.defineProperty(exports, 'md5', { enumerable: true, get: () => md5 });
20
- const hkdfExtractJS = (salt, ikm) => nodeCrypto.createHmac('sha256', salt).update(ikm).digest();
21
- const hkdfExpandJS = (prk, length, info) => {
22
- const hashLen = 32;
23
- const n = Math.ceil(length / hashLen);
24
- let t = Buffer.alloc(0);
25
- let okm = Buffer.alloc(0);
26
- for (let i = 1; i <= n; i++) {
27
- t = nodeCrypto
28
- .createHmac('sha256', prk)
29
- .update(Buffer.concat([t, info, Buffer.from([i])]))
30
- .digest();
31
- okm = Buffer.concat([okm, t]);
32
- }
33
- return okm.subarray(0, length);
34
- };
35
- const hkdf = (ikm, length, options = {}) => {
36
- const ikmBuf = Buffer.isBuffer(ikm) ? ikm : Buffer.from(ikm);
37
- const saltBuf = options.salt
38
- ? Buffer.isBuffer(options.salt)
39
- ? options.salt
40
- : Buffer.from(options.salt)
41
- : Buffer.alloc(32);
42
- const infoBuf = options.info
43
- ? Buffer.isBuffer(options.info)
44
- ? options.info
45
- : Buffer.from(options.info)
46
- : Buffer.alloc(0);
47
- const prk = hkdfExtractJS(saltBuf, ikmBuf);
48
- return hkdfExpandJS(prk, length, infoBuf);
49
- };
50
- Object.defineProperty(exports, 'hkdf', { enumerable: true, get: () => hkdf });
51
- const generateSignalPubKey = pubKey => pubKey.length === 33 ? pubKey : Buffer.concat([Defaults_1.KEY_BUNDLE_TYPE, pubKey]);
52
- exports.generateSignalPubKey = generateSignalPubKey;
53
- const curve25519JS = require('./curve25519-js');
54
- exports.Curve = {
55
- generateKeyPair: () => curve25519JS.generateKeyPairJS(),
56
- sharedKey: (privateKey, publicKey) => curve25519JS.sharedKeyJS(privateKey, publicKey),
57
- sign: (privateKey, buf) => curve25519JS.signJS(privateKey, buf),
58
- verify: (pubKey, message, signature) => curve25519JS.verifyJS(pubKey, message, signature)
59
- };
60
- const signedKeyPair = (identityKeyPair, keyId) => {
61
- const preKey = exports.Curve.generateKeyPair();
62
- const pubKey = generateSignalPubKey(preKey.public);
63
- const signature = exports.Curve.sign(identityKeyPair.private, pubKey);
64
- return { keyPair: preKey, signature, keyId };
65
- };
66
- exports.signedKeyPair = signedKeyPair;
67
- function aesEncryptGCM(plaintext, key, iv, additionalData) {
68
- const cipher = nodeCrypto.createCipheriv('aes-256-gcm', key, iv);
69
- if (additionalData)
70
- cipher.setAAD(additionalData);
71
- const encrypted = Buffer.concat([cipher.update(plaintext), cipher.final()]);
72
- return Buffer.concat([encrypted, cipher.getAuthTag()]);
73
- }
74
- function aesDecryptGCM(ciphertext, key, iv, additionalData) {
75
- const authTag = ciphertext.subarray(ciphertext.length - 16);
76
- const encrypted = ciphertext.subarray(0, ciphertext.length - 16);
77
- const decipher = nodeCrypto.createDecipheriv('aes-256-gcm', key, iv);
78
- if (additionalData)
79
- decipher.setAAD(additionalData);
80
- decipher.setAuthTag(authTag);
81
- return Buffer.concat([decipher.update(encrypted), decipher.final()]);
82
- }
83
- function aesEncryptCTR(plaintext, key, iv) {
84
- const cipher = nodeCrypto.createCipheriv('aes-256-ctr', key, iv);
85
- return Buffer.concat([cipher.update(plaintext), cipher.final()]);
86
- }
87
- function aesDecryptCTR(ciphertext, key, iv) {
88
- const decipher = nodeCrypto.createDecipheriv('aes-256-ctr', key, iv);
89
- return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
90
- }
91
- function aesDecrypt(buffer, key) {
92
- return aesDecryptWithIV(buffer, key, Buffer.alloc(16));
93
- }
94
- function aesEncrypt(buffer, key) {
95
- return aesEncrypWithIV(buffer, key, Buffer.alloc(16));
96
- }
97
- function aesDecryptWithIV(buffer, key, IV) {
98
- const decipher = nodeCrypto.createDecipheriv('aes-256-cbc', key, IV);
99
- return Buffer.concat([decipher.update(buffer), decipher.final()]);
100
- }
101
- function aesEncrypWithIV(buffer, key, IV) {
102
- const cipher = nodeCrypto.createCipheriv('aes-256-cbc', key, IV);
103
- return Buffer.concat([cipher.update(buffer), cipher.final()]);
104
- }
105
- function hmacSign(buffer, key, variant = 'sha256') {
106
- return nodeCrypto.createHmac(variant, key).update(buffer).digest();
107
- }
108
- function sha256(buffer) {
109
- return nodeCrypto.createHash('sha256').update(buffer).digest();
110
- }
111
- async function derivePairingCodeKey(pairingCode, salt) {
112
- const encoder = new TextEncoder();
113
- const pairingCodeBuffer = encoder.encode(pairingCode);
114
- const saltBuffer = new Uint8Array(salt instanceof Uint8Array ? salt : new Uint8Array(salt));
115
- const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, ['deriveBits']);
116
- const derivedBits = await subtle.deriveBits({ name: 'PBKDF2', salt: saltBuffer, iterations: 2 << 16, hash: 'SHA-256' }, keyMaterial, 256);
117
- return Buffer.from(derivedBits);
118
- }
@@ -1,242 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.generateKeyPairJS = exports.sharedKeyJS = exports.signJS = exports.verifyJS = void 0;
4
- const crypto = require('crypto');
5
- const P = 2n ** 255n - 19n;
6
- const L = 2n ** 252n + 27742317777372353535851937790883648493n;
7
- function mod(a, m = P) {
8
- const r = a % m;
9
- return r >= 0n ? r : r + m;
10
- }
11
- function powmod(b, e, m) {
12
- b = mod(b, m);
13
- let r = 1n;
14
- while (e > 0n) {
15
- if (e & 1n)
16
- r = mod(r * b, m);
17
- b = mod(b * b, m);
18
- e >>= 1n;
19
- }
20
- return r;
21
- }
22
- function invert(a, m = P) {
23
- return powmod(a, m - 2n, m);
24
- }
25
- const D = mod(-121665n * invert(121666n));
26
- const I = powmod(2n, (P - 1n) / 4n, P);
27
- function pointAdd(p1, p2) {
28
- const [X1, Y1, Z1, T1] = p1;
29
- const [X2, Y2, Z2, T2] = p2;
30
- const A = mod((Y1 - X1) * (Y2 - X2));
31
- const Bb = mod((Y1 + X1) * (Y2 + X2));
32
- const C = mod(T1 * 2n * D * T2);
33
- const Dd = mod(Z1 * 2n * Z2);
34
- const E = Bb - A;
35
- const F = Dd - C;
36
- const G = Dd + C;
37
- const H = Bb + A;
38
- return [mod(E * F), mod(G * H), mod(F * G), mod(E * H)];
39
- }
40
- function pointDouble(p) {
41
- const [X1, Y1, Z1] = p;
42
- const A = mod(X1 * X1);
43
- const Bb = mod(Y1 * Y1);
44
- const C = mod(2n * Z1 * Z1);
45
- const H = A + Bb;
46
- const E = H - mod((X1 + Y1) * (X1 + Y1));
47
- const G = A - Bb;
48
- const F = C + G;
49
- return [mod(E * F), mod(G * H), mod(F * G), mod(E * H)];
50
- }
51
- function scalarMul(s, p) {
52
- let result = [0n, 1n, 1n, 0n];
53
- let addend = p;
54
- s = mod(s, L * 8n);
55
- if (s < 0n)
56
- s += L * 8n;
57
- while (s > 0n) {
58
- if (s & 1n)
59
- result = pointAdd(result, addend);
60
- addend = pointDouble(addend);
61
- s >>= 1n;
62
- }
63
- return result;
64
- }
65
- function negatePoint(p) {
66
- const [X, Y, Z, T] = p;
67
- return [mod(-X), Y, Z, mod(-T)];
68
- }
69
- function pointEqual(p1, p2) {
70
- const [X1, Y1, Z1] = p1;
71
- const [X2, Y2, Z2] = p2;
72
- return mod(X1 * Z2 - X2 * Z1) === 0n && mod(Y1 * Z2 - Y2 * Z1) === 0n;
73
- }
74
- function recoverX(y, sign) {
75
- const y2 = y * y;
76
- const u = mod(y2 - 1n);
77
- const v = mod(D * y2 + 1n);
78
- let x = mod(u * invert(v));
79
- x = powmod(x, (P + 3n) / 8n, P);
80
- if (mod(x * x - u * invert(v)) !== 0n) {
81
- x = mod(x * I);
82
- }
83
- if (mod(x * x - u * invert(v)) !== 0n) {
84
- throw new Error('invalid Edwards point (not on curve)');
85
- }
86
- if ((x & 1n) !== BigInt(sign)) {
87
- x = P - x;
88
- }
89
- return x;
90
- }
91
- const By = mod(4n * invert(5n));
92
- const Bx = recoverX(By, 0n);
93
- const BASE = [mod(Bx), mod(By), 1n, mod(mod(Bx) * mod(By))];
94
- function bigIntToBytesLE(n, len) {
95
- const out = Buffer.alloc(len);
96
- for (let i = 0; i < len; i++) {
97
- out[i] = Number(n & 0xffn);
98
- n >>= 8n;
99
- }
100
- return out;
101
- }
102
- function bytesToBigIntLE(buf) {
103
- let n = 0n;
104
- for (let i = buf.length - 1; i >= 0; i--) {
105
- n = (n << 8n) | BigInt(buf[i]);
106
- }
107
- return n;
108
- }
109
- function encodePoint(p) {
110
- const [X, Y, Z] = p;
111
- const zinv = invert(Z);
112
- const x = mod(X * zinv);
113
- const y = mod(Y * zinv);
114
- const bytes = bigIntToBytesLE(y, 32);
115
- if (x & 1n)
116
- bytes[31] |= 0x80;
117
- return bytes;
118
- }
119
- function decodePoint(buf) {
120
- const sign = buf[31] & 0x80 ? 1 : 0;
121
- const y = bytesToBigIntLE(buf) & ((1n << 255n) - 1n);
122
- const x = recoverX(y, BigInt(sign));
123
- return [x, y, 1n, mod(x * y)];
124
- }
125
- function sha512(...bufs) {
126
- const h = crypto.createHash('sha512');
127
- for (const b of bufs)
128
- h.update(b);
129
- return h.digest();
130
- }
131
- function hashI(i, ...bufs) {
132
- const padding = Buffer.alloc(32, 0xff);
133
- padding[0] = 0xff - i;
134
- const h = crypto.createHash('sha512');
135
- h.update(padding);
136
- for (const b of bufs)
137
- h.update(b);
138
- return h.digest();
139
- }
140
- function signBit(pointBytes) {
141
- return pointBytes[31] & 0x80 ? 1 : 0;
142
- }
143
- function montgomeryUToEdwardsY(uBuf) {
144
- const u = mod(bytesToBigIntLE(uBuf), P);
145
- return mod((u - 1n) * invert(mod(u + 1n, P)), P);
146
- }
147
- function encodeYWithSign(y, sign) {
148
- const yBytes = bigIntToBytesLE(y, 32);
149
- if (sign)
150
- yBytes[31] |= 0x80;
151
- return encodePoint(decodePoint(yBytes));
152
- }
153
- function stripKeyTypePrefix(buf) {
154
- return buf.length === 33 ? buf.subarray(1) : buf;
155
- }
156
- function calculateKeyPair(kBuf) {
157
- const k = bytesToBigIntLE(kBuf);
158
- const rawPoint = scalarMul(k, BASE);
159
- const rawEnc = encodePoint(rawPoint);
160
- let a;
161
- let A;
162
- if (signBit(rawEnc) === 1) {
163
- a = mod(-k, L);
164
- A = encodePoint(negatePoint(rawPoint));
165
- }
166
- else {
167
- a = mod(k, L);
168
- A = rawEnc;
169
- }
170
- return { a, A };
171
- }
172
- function signJS(privateKey, message) {
173
- const Z = crypto.randomBytes(64);
174
- const { a, A } = calculateKeyPair(privateKey);
175
- const aBytes = bigIntToBytesLE(a, 32);
176
- const r = mod(bytesToBigIntLE(hashI(1, aBytes, message, Z)), L);
177
- const R = scalarMul(r, BASE);
178
- const REnc = encodePoint(R);
179
- const h = mod(bytesToBigIntLE(sha512(REnc, A, message)), L);
180
- const s = mod(r + h * a, L);
181
- return Buffer.concat([REnc, bigIntToBytesLE(s, 32)]);
182
- }
183
- exports.signJS = signJS;
184
- function verifyJS(pubKey, message, signature) {
185
- try {
186
- const u = stripKeyTypePrefix(pubKey);
187
- if (u.length !== 32 || signature.length !== 64)
188
- return false;
189
- const REnc = signature.subarray(0, 32);
190
- const s = bytesToBigIntLE(signature.subarray(32, 64));
191
- if (s >= L)
192
- return false;
193
- const A = encodeYWithSign(montgomeryUToEdwardsY(u), 0);
194
- const APoint = decodePoint(A);
195
- const h = mod(bytesToBigIntLE(sha512(REnc, A, message)), L);
196
- const sB = scalarMul(s, BASE);
197
- const hA = scalarMul(h, APoint);
198
- const RCheck = pointAdd(sB, negatePoint(hA));
199
- return encodePoint(RCheck).equals(REnc);
200
- }
201
- catch {
202
- return false;
203
- }
204
- }
205
- exports.verifyJS = verifyJS;
206
- function b64url(buf) {
207
- return buf.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
208
- }
209
- function fromB64url(str) {
210
- str = str.replace(/-/g, '+').replace(/_/g, '/');
211
- while (str.length % 4)
212
- str += '=';
213
- return Buffer.from(str, 'base64');
214
- }
215
- function generateKeyPairJS() {
216
- const { publicKey, privateKey } = crypto.generateKeyPairSync('x25519');
217
- const priv = fromB64url(privateKey.export({ format: 'jwk' }).d);
218
- const pub = fromB64url(publicKey.export({ format: 'jwk' }).x);
219
- return { private: priv, public: pub };
220
- }
221
- exports.generateKeyPairJS = generateKeyPairJS;
222
- function sharedKeyJS(privateKey, publicKey) {
223
- const pub = stripKeyTypePrefix(publicKey);
224
- const privKey = crypto.createPrivateKey({
225
- key: { kty: 'OKP', crv: 'X25519', d: b64url(privateKey), x: b64url(generateKeyPairJS_publicFrom(privateKey)) },
226
- format: 'jwk'
227
- });
228
- const pubKey = crypto.createPublicKey({
229
- key: { kty: 'OKP', crv: 'X25519', x: b64url(pub) },
230
- format: 'jwk'
231
- });
232
- return crypto.diffieHellman({ privateKey: privKey, publicKey: pubKey });
233
- }
234
- exports.sharedKeyJS = sharedKeyJS;
235
- function generateKeyPairJS_publicFrom(privateKeyRaw) {
236
- const k = bytesToBigIntLE(privateKeyRaw);
237
- const point = scalarMul(k, BASE);
238
- const [, Y, Z] = point;
239
- const y = mod(Y * invert(Z));
240
- const u = mod((1n + y) * invert(mod(1n - y)));
241
- return bigIntToBytesLE(u, 32);
242
- }