@lennyyaawa/lannysecx 9.9.18

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 (201) hide show
  1. package/README.md +61 -0
  2. package/WAProto/GenerateStatics.sh +4 -0
  3. package/WAProto/WAProto.proto +3344 -0
  4. package/WAProto/index.d.ts +37016 -0
  5. package/WAProto/index.js +130281 -0
  6. package/lib/Database/mongoAdapter.js +77 -0
  7. package/lib/Defaults/baileys-version.json +3 -0
  8. package/lib/Defaults/index.d.ts +53 -0
  9. package/lib/Defaults/index.js +130 -0
  10. package/lib/Defaults/phonenumber-mcc.json +223 -0
  11. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  12. package/lib/Signal/Group/ciphertext-message.js +15 -0
  13. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  14. package/lib/Signal/Group/group-session-builder.js +64 -0
  15. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  16. package/lib/Signal/Group/group_cipher.js +96 -0
  17. package/lib/Signal/Group/index.d.ts +11 -0
  18. package/lib/Signal/Group/index.js +57 -0
  19. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  20. package/lib/Signal/Group/keyhelper.js +55 -0
  21. package/lib/Signal/Group/queue-job.d.ts +1 -0
  22. package/lib/Signal/Group/queue-job.js +57 -0
  23. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  24. package/lib/Signal/Group/sender-chain-key.js +34 -0
  25. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  26. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  27. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  28. package/lib/Signal/Group/sender-key-message.js +69 -0
  29. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  30. package/lib/Signal/Group/sender-key-name.js +51 -0
  31. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  32. package/lib/Signal/Group/sender-key-record.js +53 -0
  33. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  34. package/lib/Signal/Group/sender-key-state.js +99 -0
  35. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  36. package/lib/Signal/Group/sender-message-key.js +29 -0
  37. package/lib/Signal/libsignal.d.ts +3 -0
  38. package/lib/Signal/libsignal.js +174 -0
  39. package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
  40. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  41. package/lib/Socket/Client/index.d.ts +3 -0
  42. package/lib/Socket/Client/index.js +19 -0
  43. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  44. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  45. package/lib/Socket/Client/web-socket-client.d.ts +12 -0
  46. package/lib/Socket/Client/web-socket-client.js +62 -0
  47. package/lib/Socket/PaxHeaders.0/swzesty st 1963.d.ts +1 -0
  48. package/lib/Socket/PaxHeaders.0/swzesty st 1963.js +1 -0
  49. package/lib/Socket/business.d.ts +171 -0
  50. package/lib/Socket/business.js +260 -0
  51. package/lib/Socket/chats.d.ts +84 -0
  52. package/lib/Socket/chats.js +890 -0
  53. package/lib/Socket/groups.d.ts +115 -0
  54. package/lib/Socket/groups.js +317 -0
  55. package/lib/Socket/index.d.ts +173 -0
  56. package/lib/Socket/index.js +10 -0
  57. package/lib/Socket/messages-recv.d.ts +161 -0
  58. package/lib/Socket/messages-recv.js +1110 -0
  59. package/lib/Socket/messages-send.d.ts +149 -0
  60. package/lib/Socket/messages-send.js +805 -0
  61. package/lib/Socket/newsletter.d.ts +134 -0
  62. package/lib/Socket/newsletter.js +236 -0
  63. package/lib/Socket/registration.d.ts +267 -0
  64. package/lib/Socket/registration.js +166 -0
  65. package/lib/Socket/socket.d.ts +43 -0
  66. package/lib/Socket/socket.js +630 -0
  67. package/lib/Socket/sw/303/250zesty /303/250st 1963.d.ts" +220 -0
  68. package/lib/Socket/sw/303/250zesty /303/250st 1963.js" +437 -0
  69. package/lib/Socket/usync.d.ts +36 -0
  70. package/lib/Socket/usync.js +70 -0
  71. package/lib/Store/index.d.ts +3 -0
  72. package/lib/Store/index.js +10 -0
  73. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  74. package/lib/Store/make-cache-manager-store.js +83 -0
  75. package/lib/Store/make-in-memory-store.d.ts +118 -0
  76. package/lib/Store/make-in-memory-store.js +427 -0
  77. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  78. package/lib/Store/make-ordered-dictionary.js +81 -0
  79. package/lib/Store/object-repository.d.ts +10 -0
  80. package/lib/Store/object-repository.js +27 -0
  81. package/lib/Types/Auth.d.ts +110 -0
  82. package/lib/Types/Auth.js +2 -0
  83. package/lib/Types/Call.d.ts +13 -0
  84. package/lib/Types/Call.js +2 -0
  85. package/lib/Types/Chat.d.ts +102 -0
  86. package/lib/Types/Chat.js +4 -0
  87. package/lib/Types/Contact.d.ts +19 -0
  88. package/lib/Types/Contact.js +2 -0
  89. package/lib/Types/Events.d.ts +157 -0
  90. package/lib/Types/Events.js +2 -0
  91. package/lib/Types/GroupMetadata.d.ts +55 -0
  92. package/lib/Types/GroupMetadata.js +2 -0
  93. package/lib/Types/Label.d.ts +35 -0
  94. package/lib/Types/Label.js +27 -0
  95. package/lib/Types/LabelAssociation.d.ts +29 -0
  96. package/lib/Types/LabelAssociation.js +9 -0
  97. package/lib/Types/Message.d.ts +273 -0
  98. package/lib/Types/Message.js +9 -0
  99. package/lib/Types/Newsletter.d.ts +92 -0
  100. package/lib/Types/Newsletter.js +32 -0
  101. package/lib/Types/Product.d.ts +78 -0
  102. package/lib/Types/Product.js +2 -0
  103. package/lib/Types/Signal.d.ts +57 -0
  104. package/lib/Types/Signal.js +2 -0
  105. package/lib/Types/Socket.d.ts +111 -0
  106. package/lib/Types/Socket.js +2 -0
  107. package/lib/Types/State.d.ts +27 -0
  108. package/lib/Types/State.js +2 -0
  109. package/lib/Types/USync.d.ts +25 -0
  110. package/lib/Types/USync.js +2 -0
  111. package/lib/Types/index.d.ts +57 -0
  112. package/lib/Types/index.js +42 -0
  113. package/lib/Utils/auth-utils.d.ts +18 -0
  114. package/lib/Utils/auth-utils.js +206 -0
  115. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  116. package/lib/Utils/baileys-event-stream.js +63 -0
  117. package/lib/Utils/business.d.ts +22 -0
  118. package/lib/Utils/business.js +234 -0
  119. package/lib/Utils/chat-utils.d.ts +71 -0
  120. package/lib/Utils/chat-utils.js +729 -0
  121. package/lib/Utils/crypto.d.ts +41 -0
  122. package/lib/Utils/crypto.js +151 -0
  123. package/lib/Utils/decode-wa-message.d.ts +19 -0
  124. package/lib/Utils/decode-wa-message.js +198 -0
  125. package/lib/Utils/event-buffer.d.ts +35 -0
  126. package/lib/Utils/event-buffer.js +514 -0
  127. package/lib/Utils/generics.d.ts +92 -0
  128. package/lib/Utils/generics.js +391 -0
  129. package/lib/Utils/history.d.ts +15 -0
  130. package/lib/Utils/history.js +96 -0
  131. package/lib/Utils/index.d.ts +17 -0
  132. package/lib/Utils/index.js +33 -0
  133. package/lib/Utils/link-preview.d.ts +21 -0
  134. package/lib/Utils/link-preview.js +93 -0
  135. package/lib/Utils/logger.d.ts +4 -0
  136. package/lib/Utils/logger.js +7 -0
  137. package/lib/Utils/lt-hash.d.ts +12 -0
  138. package/lib/Utils/lt-hash.js +51 -0
  139. package/lib/Utils/make-mutex.d.ts +7 -0
  140. package/lib/Utils/make-mutex.js +43 -0
  141. package/lib/Utils/messages-media.d.ts +116 -0
  142. package/lib/Utils/messages-media.js +731 -0
  143. package/lib/Utils/messages.d.ts +77 -0
  144. package/lib/Utils/messages.js +825 -0
  145. package/lib/Utils/noise-handler.d.ts +21 -0
  146. package/lib/Utils/noise-handler.js +155 -0
  147. package/lib/Utils/process-message.d.ts +41 -0
  148. package/lib/Utils/process-message.js +321 -0
  149. package/lib/Utils/signal.d.ts +32 -0
  150. package/lib/Utils/signal.js +151 -0
  151. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  152. package/lib/Utils/use-multi-file-auth-state.js +81 -0
  153. package/lib/Utils/validate-connection.d.ts +11 -0
  154. package/lib/Utils/validate-connection.js +205 -0
  155. package/lib/WABinary/constants.d.ts +27 -0
  156. package/lib/WABinary/constants.js +40 -0
  157. package/lib/WABinary/decode.d.ts +7 -0
  158. package/lib/WABinary/decode.js +252 -0
  159. package/lib/WABinary/encode.d.ts +3 -0
  160. package/lib/WABinary/encode.js +228 -0
  161. package/lib/WABinary/generic-utils.d.ts +16 -0
  162. package/lib/WABinary/generic-utils.js +199 -0
  163. package/lib/WABinary/index.d.ts +5 -0
  164. package/lib/WABinary/index.js +21 -0
  165. package/lib/WABinary/jid-utils.d.ts +31 -0
  166. package/lib/WABinary/jid-utils.js +62 -0
  167. package/lib/WABinary/types.d.ts +18 -0
  168. package/lib/WABinary/types.js +2 -0
  169. package/lib/WAM/BinaryInfo.d.ts +17 -0
  170. package/lib/WAM/BinaryInfo.js +13 -0
  171. package/lib/WAM/constants.d.ts +38 -0
  172. package/lib/WAM/constants.js +15350 -0
  173. package/lib/WAM/encode.d.ts +3 -0
  174. package/lib/WAM/encode.js +155 -0
  175. package/lib/WAM/index.d.ts +3 -0
  176. package/lib/WAM/index.js +19 -0
  177. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  178. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  179. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  180. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  181. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  182. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  183. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  184. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  185. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  186. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  187. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  188. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  189. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  190. package/lib/WAUSync/Protocols/index.js +20 -0
  191. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  192. package/lib/WAUSync/USyncQuery.js +89 -0
  193. package/lib/WAUSync/USyncUser.d.ts +12 -0
  194. package/lib/WAUSync/USyncUser.js +26 -0
  195. package/lib/WAUSync/index.d.ts +3 -0
  196. package/lib/WAUSync/index.js +19 -0
  197. package/lib/index.d.ts +11 -0
  198. package/lib/index.js +85 -0
  199. package/lib/index.js.bak +44 -0
  200. package/lib/index.js.bak2 +133 -0
  201. package/package.json +108 -0
@@ -0,0 +1,41 @@
1
+ /// <reference types="node" />
2
+ import { KeyPair } from '../Types';
3
+ /** prefix version byte to the pub keys, required for some curve crypto functions */
4
+ export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array | Buffer;
5
+ export declare const Curve: {
6
+ generateKeyPair: () => KeyPair;
7
+ sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer;
8
+ sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
9
+ verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
10
+ };
11
+ export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) => {
12
+ keyPair: KeyPair;
13
+ signature: any;
14
+ keyId: number;
15
+ };
16
+ /**
17
+ * encrypt AES 256 GCM;
18
+ * where the tag tag is suffixed to the ciphertext
19
+ * */
20
+ export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
21
+ /**
22
+ * decrypt AES 256 GCM;
23
+ * where the auth tag is suffixed to the ciphertext
24
+ * */
25
+ export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
26
+ export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
27
+ export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
28
+ /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
29
+ export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer;
30
+ /** decrypt AES 256 CBC */
31
+ export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
32
+ export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer;
33
+ export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
34
+ export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer;
35
+ export declare function sha256(buffer: Buffer): Buffer;
36
+ export declare function md5(buffer: Buffer): Buffer;
37
+ export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
38
+ salt?: Buffer;
39
+ info?: string;
40
+ }): Buffer;
41
+ export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Buffer;
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.derivePairingCodeKey = exports.hkdf = exports.md5 = exports.sha256 = exports.hmacSign = exports.aesEncrypWithIV = exports.aesEncrypt = exports.aesDecryptWithIV = exports.aesDecrypt = exports.aesDecryptCTR = exports.aesEncryptCTR = exports.aesDecryptGCM = exports.aesEncryptGCM = exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
30
+ const crypto_1 = require("crypto");
31
+ const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
32
+ const libsignal = __importStar(require("libsignal"));
33
+ const Defaults_1 = require("../Defaults");
34
+ /** prefix version byte to the pub keys, required for some curve crypto functions */
35
+ const generateSignalPubKey = (pubKey) => (pubKey.length === 33
36
+ ? pubKey
37
+ : Buffer.concat([Defaults_1.KEY_BUNDLE_TYPE, pubKey]));
38
+ exports.generateSignalPubKey = generateSignalPubKey;
39
+ exports.Curve = {
40
+ generateKeyPair: () => {
41
+ const { pubKey, privKey } = libsignal.curve.generateKeyPair();
42
+ return {
43
+ private: Buffer.from(privKey),
44
+ // remove version byte
45
+ public: Buffer.from(pubKey.slice(1))
46
+ };
47
+ },
48
+ sharedKey: (privateKey, publicKey) => {
49
+ const shared = libsignal.curve.calculateAgreement((0, exports.generateSignalPubKey)(publicKey), privateKey);
50
+ return Buffer.from(shared);
51
+ },
52
+ sign: (privateKey, buf) => (libsignal.curve.calculateSignature(privateKey, buf)),
53
+ verify: (pubKey, message, signature) => {
54
+ try {
55
+ libsignal.curve.verifySignature((0, exports.generateSignalPubKey)(pubKey), message, signature);
56
+ return true;
57
+ }
58
+ catch (error) {
59
+ return false;
60
+ }
61
+ }
62
+ };
63
+ const signedKeyPair = (identityKeyPair, keyId) => {
64
+ const preKey = exports.Curve.generateKeyPair();
65
+ const pubKey = (0, exports.generateSignalPubKey)(preKey.public);
66
+ const signature = exports.Curve.sign(identityKeyPair.private, pubKey);
67
+ return { keyPair: preKey, signature, keyId };
68
+ };
69
+ exports.signedKeyPair = signedKeyPair;
70
+ const GCM_TAG_LENGTH = 128 >> 3;
71
+ /**
72
+ * encrypt AES 256 GCM;
73
+ * where the tag tag is suffixed to the ciphertext
74
+ * */
75
+ function aesEncryptGCM(plaintext, key, iv, additionalData) {
76
+ const cipher = (0, crypto_1.createCipheriv)('aes-256-gcm', key, iv);
77
+ cipher.setAAD(additionalData);
78
+ return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
79
+ }
80
+ exports.aesEncryptGCM = aesEncryptGCM;
81
+ /**
82
+ * decrypt AES 256 GCM;
83
+ * where the auth tag is suffixed to the ciphertext
84
+ * */
85
+ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
86
+ const decipher = (0, crypto_1.createDecipheriv)('aes-256-gcm', key, iv);
87
+ // decrypt additional adata
88
+ const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH);
89
+ const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
90
+ // set additional data
91
+ decipher.setAAD(additionalData);
92
+ decipher.setAuthTag(tag);
93
+ return Buffer.concat([decipher.update(enc), decipher.final()]);
94
+ }
95
+ exports.aesDecryptGCM = aesDecryptGCM;
96
+ function aesEncryptCTR(plaintext, key, iv) {
97
+ const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
98
+ return Buffer.concat([cipher.update(plaintext), cipher.final()]);
99
+ }
100
+ exports.aesEncryptCTR = aesEncryptCTR;
101
+ function aesDecryptCTR(ciphertext, key, iv) {
102
+ const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
103
+ return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
104
+ }
105
+ exports.aesDecryptCTR = aesDecryptCTR;
106
+ /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
107
+ function aesDecrypt(buffer, key) {
108
+ return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
109
+ }
110
+ exports.aesDecrypt = aesDecrypt;
111
+ /** decrypt AES 256 CBC */
112
+ function aesDecryptWithIV(buffer, key, IV) {
113
+ const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
114
+ return Buffer.concat([aes.update(buffer), aes.final()]);
115
+ }
116
+ exports.aesDecryptWithIV = aesDecryptWithIV;
117
+ // encrypt AES 256 CBC; where a random IV is prefixed to the buffer
118
+ function aesEncrypt(buffer, key) {
119
+ const IV = (0, crypto_1.randomBytes)(16);
120
+ const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
121
+ return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
122
+ }
123
+ exports.aesEncrypt = aesEncrypt;
124
+ // encrypt AES 256 CBC with a given IV
125
+ function aesEncrypWithIV(buffer, key, IV) {
126
+ const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
127
+ return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
128
+ }
129
+ exports.aesEncrypWithIV = aesEncrypWithIV;
130
+ // sign HMAC using SHA 256
131
+ function hmacSign(buffer, key, variant = 'sha256') {
132
+ return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
133
+ }
134
+ exports.hmacSign = hmacSign;
135
+ function sha256(buffer) {
136
+ return (0, crypto_1.createHash)('sha256').update(buffer).digest();
137
+ }
138
+ exports.sha256 = sha256;
139
+ function md5(buffer) {
140
+ return (0, crypto_1.createHash)('md5').update(buffer).digest();
141
+ }
142
+ exports.md5 = md5;
143
+ // HKDF key expansion
144
+ function hkdf(buffer, expandedLength, info) {
145
+ return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
146
+ }
147
+ exports.hkdf = hkdf;
148
+ function derivePairingCodeKey(pairingCode, salt) {
149
+ return (0, crypto_1.pbkdf2Sync)(pairingCode, salt, 2 << 16, 32, 'sha256');
150
+ }
151
+ exports.derivePairingCodeKey = derivePairingCodeKey;
@@ -0,0 +1,19 @@
1
+ import { Logger } from 'pino';
2
+ import { proto } from '../../WAProto';
3
+ import { SignalRepository } from '../Types';
4
+ import { BinaryNode } from '../WABinary';
5
+ /**
6
+ * Decode the received node as a message.
7
+ * @note this will only parse the message, not decrypt it
8
+ */
9
+ export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
10
+ fullMessage: proto.IWebMessageInfo;
11
+ author: string;
12
+ sender: string;
13
+ };
14
+ export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: Logger) => {
15
+ fullMessage: proto.IWebMessageInfo;
16
+ category: string;
17
+ author: string;
18
+ decrypt(): Promise<void>;
19
+ };
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decryptMessageNode = exports.decodeMessageNode = void 0;
4
+ const boom_1 = require("@hapi/boom");
5
+ const WAProto_1 = require("../../WAProto");
6
+ const WABinary_1 = require("../WABinary");
7
+ const generics_1 = require("./generics");
8
+ const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
9
+ /**
10
+ * Decode the received node as a message.
11
+ * @note this will only parse the message, not decrypt it
12
+ */
13
+ function decodeMessageNode(stanza, meId, meLid) {
14
+ var _a, _b;
15
+ let msgType;
16
+ let chatId;
17
+ let author;
18
+ const msgId = stanza.attrs.id;
19
+ const from = stanza.attrs.from;
20
+ const participant = stanza.attrs.participant;
21
+ const recipient = stanza.attrs.recipient;
22
+ const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
23
+ const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
24
+ if ((0, WABinary_1.isJidUser)(from)) {
25
+ if (recipient) {
26
+ if (!isMe(from)) {
27
+ throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
28
+ }
29
+ chatId = recipient;
30
+ }
31
+ else {
32
+ chatId = from;
33
+ }
34
+ msgType = 'chat';
35
+ author = from;
36
+ }
37
+ else if ((0, WABinary_1.isLidUser)(from)) {
38
+ if (recipient) {
39
+ if (!isMeLid(from)) {
40
+ throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
41
+ }
42
+ chatId = recipient;
43
+ }
44
+ else {
45
+ chatId = from;
46
+ }
47
+ msgType = 'chat';
48
+ author = from;
49
+ }
50
+ else if ((0, WABinary_1.isJidGroup)(from)) {
51
+ if (!participant) {
52
+ throw new boom_1.Boom('No participant in group message');
53
+ }
54
+ msgType = 'group';
55
+ author = participant;
56
+ chatId = from;
57
+ }
58
+ else if ((0, WABinary_1.isJidBroadcast)(from)) {
59
+ if (!participant) {
60
+ throw new boom_1.Boom('No participant in group message');
61
+ }
62
+ const isParticipantMe = isMe(participant);
63
+ if ((0, WABinary_1.isJidStatusBroadcast)(from)) {
64
+ msgType = isParticipantMe ? 'direct_peer_status' : 'other_status';
65
+ }
66
+ else {
67
+ msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast';
68
+ }
69
+ chatId = from;
70
+ author = participant;
71
+ }
72
+ else if ((0, WABinary_1.isJidNewsLetter)(from)) {
73
+ msgType = 'newsletter';
74
+ author = from;
75
+ chatId = from;
76
+ }
77
+ else {
78
+ throw new boom_1.Boom('Unknown message type', { data: stanza });
79
+ }
80
+ const fromMe = (0, WABinary_1.isJidNewsLetter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
81
+ const pushname = stanza.attrs.notify;
82
+ const key = {
83
+ remoteJid: chatId,
84
+ fromMe,
85
+ id: msgId,
86
+ participant
87
+ };
88
+ const fullMessage = {
89
+ key,
90
+ messageTimestamp: +stanza.attrs.t,
91
+ pushName: pushname,
92
+ broadcast: (0, WABinary_1.isJidBroadcast)(from)
93
+ };
94
+ if (msgType === 'newsletter') {
95
+ fullMessage.newsletterServerId = +((_b = stanza.attrs) === null || _b === void 0 ? void 0 : _b.server_id);
96
+ }
97
+ if (key.fromMe) {
98
+ fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
99
+ }
100
+ return {
101
+ fullMessage,
102
+ author,
103
+ sender: msgType === 'chat' ? author : chatId
104
+ };
105
+ }
106
+ exports.decodeMessageNode = decodeMessageNode;
107
+ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
108
+ const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
109
+ return {
110
+ fullMessage,
111
+ category: stanza.attrs.category,
112
+ author,
113
+ async decrypt() {
114
+ var _a;
115
+ let decryptables = 0;
116
+ async function processSenderKeyDistribution(msg) {
117
+ if (msg.senderKeyDistributionMessage) {
118
+ try {
119
+ await repository.processSenderKeyDistributionMessage({
120
+ authorJid: author,
121
+ item: msg.senderKeyDistributionMessage
122
+ });
123
+ }
124
+ catch (err) {
125
+ logger.error({ key: fullMessage.key, err }, 'failed to process senderKeyDistribution');
126
+ }
127
+ }
128
+ }
129
+ if ((0, WABinary_1.isJidNewsLetter)(fullMessage.key.remoteJid)) {
130
+ const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
131
+ const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
132
+ await processSenderKeyDistribution(msg);
133
+ fullMessage.message = msg;
134
+ decryptables += 1;
135
+ }
136
+ else if (Array.isArray(stanza.content)) {
137
+ for (const { tag, attrs, content } of stanza.content) {
138
+ if (tag === 'verified_name' && content instanceof Uint8Array) {
139
+ const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
140
+ const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
141
+ fullMessage.verifiedBizName = details.verifiedName;
142
+ }
143
+ if (tag !== 'enc') {
144
+ continue;
145
+ }
146
+ if (!(content instanceof Uint8Array)) {
147
+ continue;
148
+ }
149
+ decryptables += 1;
150
+ let msgBuffer;
151
+ try {
152
+ const e2eType = attrs.type;
153
+ switch (e2eType) {
154
+ case 'skmsg':
155
+ msgBuffer = await repository.decryptGroupMessage({
156
+ group: sender,
157
+ authorJid: author,
158
+ msg: content
159
+ });
160
+ break;
161
+ case 'pkmsg':
162
+ case 'msg':
163
+ const user = (0, WABinary_1.isJidUser)(sender) ? sender : author;
164
+ msgBuffer = await repository.decryptMessage({
165
+ jid: user,
166
+ type: e2eType,
167
+ ciphertext: content
168
+ });
169
+ break;
170
+ default:
171
+ throw new Error(`Unknown e2e type: ${e2eType}`);
172
+ }
173
+ let msg = WAProto_1.proto.Message.decode((0, generics_1.unpadRandomMax16)(msgBuffer));
174
+ msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
175
+ await processSenderKeyDistribution(msg);
176
+ if (fullMessage.message) {
177
+ Object.assign(fullMessage.message, msg);
178
+ }
179
+ else {
180
+ fullMessage.message = msg;
181
+ }
182
+ }
183
+ catch (err) {
184
+ logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
185
+ fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
186
+ fullMessage.messageStubParameters = [err.message];
187
+ }
188
+ }
189
+ }
190
+ // if nothing was found to decrypt
191
+ if (!decryptables) {
192
+ fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
193
+ fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, JSON.stringify(stanza, generics_1.BufferJSON.replacer)];
194
+ }
195
+ }
196
+ };
197
+ };
198
+ exports.decryptMessageNode = decryptMessageNode;
@@ -0,0 +1,35 @@
1
+ import { Logger } from 'pino';
2
+ import { BaileysEventEmitter, BaileysEventMap } from '../Types';
3
+ /**
4
+ * A map that contains a list of all events that have been triggered
5
+ *
6
+ * Note, this can contain different type of events
7
+ * this can make processing events extremely efficient -- since everything
8
+ * can be done in a single transaction
9
+ */
10
+ type BaileysEventData = Partial<BaileysEventMap>;
11
+ type BaileysBufferableEventEmitter = BaileysEventEmitter & {
12
+ /** Use to process events in a batch */
13
+ process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void);
14
+ /**
15
+ * starts buffering events, call flush() to release them
16
+ * */
17
+ buffer(): void;
18
+ /** buffers all events till the promise completes */
19
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
20
+ /**
21
+ * flushes all buffered events
22
+ * @param force if true, will flush all data regardless of any pending buffers
23
+ * @returns returns true if the flush actually happened, otherwise false
24
+ */
25
+ flush(force?: boolean): boolean;
26
+ /** is there an ongoing buffer */
27
+ isBuffering(): boolean;
28
+ };
29
+ /**
30
+ * The event buffer logically consolidates different events into a single event
31
+ * making the data processing more efficient.
32
+ * @param ev the baileys event emitter
33
+ */
34
+ export declare const makeEventBuffer: (logger: Logger) => BaileysBufferableEventEmitter;
35
+ export {};