@nexustechpro/baileys 2.0.2 → 2.0.5

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 (102) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +924 -1299
  3. package/lib/Defaults/baileys-version.json +6 -2
  4. package/lib/Defaults/index.js +172 -172
  5. package/lib/Signal/libsignal.js +380 -292
  6. package/lib/Signal/lid-mapping.js +264 -171
  7. package/lib/Socket/Client/index.js +2 -2
  8. package/lib/Socket/Client/types.js +10 -10
  9. package/lib/Socket/Client/websocket.js +45 -310
  10. package/lib/Socket/business.js +375 -375
  11. package/lib/Socket/chats.js +909 -963
  12. package/lib/Socket/communities.js +430 -430
  13. package/lib/Socket/groups.js +342 -342
  14. package/lib/Socket/index.js +22 -22
  15. package/lib/Socket/messages-recv.js +777 -743
  16. package/lib/Socket/messages-send.js +295 -305
  17. package/lib/Socket/mex.js +50 -50
  18. package/lib/Socket/newsletter.js +148 -148
  19. package/lib/Socket/nexus-handler.js +75 -261
  20. package/lib/Socket/socket.js +709 -1201
  21. package/lib/Store/index.js +5 -5
  22. package/lib/Store/make-cache-manager-store.js +81 -81
  23. package/lib/Store/make-in-memory-store.js +416 -416
  24. package/lib/Store/make-ordered-dictionary.js +81 -81
  25. package/lib/Store/object-repository.js +30 -30
  26. package/lib/Types/Auth.js +1 -1
  27. package/lib/Types/Bussines.js +1 -1
  28. package/lib/Types/Call.js +1 -1
  29. package/lib/Types/Chat.js +7 -7
  30. package/lib/Types/Contact.js +1 -1
  31. package/lib/Types/Events.js +1 -1
  32. package/lib/Types/GroupMetadata.js +1 -1
  33. package/lib/Types/Label.js +24 -24
  34. package/lib/Types/LabelAssociation.js +6 -6
  35. package/lib/Types/Message.js +10 -10
  36. package/lib/Types/Newsletter.js +28 -28
  37. package/lib/Types/Product.js +1 -1
  38. package/lib/Types/Signal.js +1 -1
  39. package/lib/Types/Socket.js +2 -2
  40. package/lib/Types/State.js +12 -12
  41. package/lib/Types/USync.js +1 -1
  42. package/lib/Types/index.js +25 -25
  43. package/lib/Utils/auth-utils.js +264 -256
  44. package/lib/Utils/baileys-event-stream.js +55 -55
  45. package/lib/Utils/browser-utils.js +27 -27
  46. package/lib/Utils/business.js +228 -230
  47. package/lib/Utils/chat-utils.js +694 -764
  48. package/lib/Utils/crypto.js +109 -135
  49. package/lib/Utils/decode-wa-message.js +310 -314
  50. package/lib/Utils/event-buffer.js +547 -547
  51. package/lib/Utils/generics.js +297 -297
  52. package/lib/Utils/history.js +91 -83
  53. package/lib/Utils/index.js +21 -20
  54. package/lib/Utils/key-store.js +17 -0
  55. package/lib/Utils/link-preview.js +97 -98
  56. package/lib/Utils/logger.js +2 -2
  57. package/lib/Utils/lt-hash.js +47 -47
  58. package/lib/Utils/make-mutex.js +39 -39
  59. package/lib/Utils/message-retry-manager.js +148 -148
  60. package/lib/Utils/messages-media.js +534 -534
  61. package/lib/Utils/messages.js +705 -705
  62. package/lib/Utils/noise-handler.js +255 -255
  63. package/lib/Utils/pre-key-manager.js +105 -105
  64. package/lib/Utils/process-message.js +412 -412
  65. package/lib/Utils/signal.js +160 -158
  66. package/lib/Utils/use-multi-file-auth-state.js +120 -120
  67. package/lib/Utils/validate-connection.js +194 -194
  68. package/lib/WABinary/constants.js +1300 -1300
  69. package/lib/WABinary/decode.js +237 -237
  70. package/lib/WABinary/encode.js +232 -232
  71. package/lib/WABinary/generic-utils.js +252 -211
  72. package/lib/WABinary/index.js +5 -5
  73. package/lib/WABinary/jid-utils.js +279 -95
  74. package/lib/WABinary/types.js +1 -1
  75. package/lib/WAM/BinaryInfo.js +9 -9
  76. package/lib/WAM/constants.js +22852 -22852
  77. package/lib/WAM/encode.js +149 -149
  78. package/lib/WAM/index.js +3 -3
  79. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -28
  80. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -53
  81. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -26
  82. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -37
  83. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
  84. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -28
  85. package/lib/WAUSync/Protocols/index.js +4 -4
  86. package/lib/WAUSync/USyncQuery.js +93 -93
  87. package/lib/WAUSync/USyncUser.js +22 -22
  88. package/lib/WAUSync/index.js +3 -3
  89. package/lib/index.js +66 -66
  90. package/package.json +171 -144
  91. package/lib/Signal/Group/ciphertext-message.js +0 -12
  92. package/lib/Signal/Group/group-session-builder.js +0 -30
  93. package/lib/Signal/Group/group_cipher.js +0 -100
  94. package/lib/Signal/Group/index.js +0 -12
  95. package/lib/Signal/Group/keyhelper.js +0 -18
  96. package/lib/Signal/Group/sender-chain-key.js +0 -26
  97. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  98. package/lib/Signal/Group/sender-key-message.js +0 -66
  99. package/lib/Signal/Group/sender-key-name.js +0 -48
  100. package/lib/Signal/Group/sender-key-record.js +0 -41
  101. package/lib/Signal/Group/sender-key-state.js +0 -84
  102. package/lib/Signal/Group/sender-message-key.js +0 -26
@@ -1,48 +0,0 @@
1
- function isNull(str) {
2
- return str === null || str === '';
3
- }
4
- function intValue(num) {
5
- const MAX_VALUE = 0x7fffffff;
6
- const MIN_VALUE = -0x80000000;
7
- if (num > MAX_VALUE || num < MIN_VALUE) {
8
- return num & 0xffffffff;
9
- }
10
- return num;
11
- }
12
- function hashCode(strKey) {
13
- let hash = 0;
14
- if (!isNull(strKey)) {
15
- for (let i = 0; i < strKey.length; i++) {
16
- hash = hash * 31 + strKey.charCodeAt(i);
17
- hash = intValue(hash);
18
- }
19
- }
20
- return hash;
21
- }
22
- export class SenderKeyName {
23
- constructor(groupId, sender) {
24
- this.groupId = groupId;
25
- this.sender = sender;
26
- }
27
- getGroupId() {
28
- return this.groupId;
29
- }
30
- getSender() {
31
- return this.sender;
32
- }
33
- serialize() {
34
- return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}`;
35
- }
36
- toString() {
37
- return this.serialize();
38
- }
39
- equals(other) {
40
- if (other === null)
41
- return false;
42
- return this.groupId === other.groupId && this.sender.toString() === other.sender.toString();
43
- }
44
- hashCode() {
45
- return hashCode(this.groupId) ^ hashCode(this.sender.toString());
46
- }
47
- }
48
- //# sourceMappingURL=sender-key-name.js.map
@@ -1,41 +0,0 @@
1
- import { BufferJSON } from '../../Utils/generics.js';
2
- import { SenderKeyState } from './sender-key-state.js';
3
- export class SenderKeyRecord {
4
- constructor(serialized) {
5
- this.MAX_STATES = 5;
6
- this.senderKeyStates = [];
7
- if (serialized) {
8
- for (const structure of serialized) {
9
- this.senderKeyStates.push(new SenderKeyState(null, null, null, null, null, null, structure));
10
- }
11
- }
12
- }
13
- isEmpty() {
14
- return this.senderKeyStates.length === 0;
15
- }
16
- getSenderKeyState(keyId) {
17
- if (keyId === undefined && this.senderKeyStates.length) {
18
- return this.senderKeyStates[this.senderKeyStates.length - 1];
19
- }
20
- return this.senderKeyStates.find(state => state.getKeyId() === keyId);
21
- }
22
- addSenderKeyState(id, iteration, chainKey, signatureKey) {
23
- this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, null, signatureKey));
24
- if (this.senderKeyStates.length > this.MAX_STATES) {
25
- this.senderKeyStates.shift();
26
- }
27
- }
28
- setSenderKeyState(id, iteration, chainKey, keyPair) {
29
- this.senderKeyStates.length = 0;
30
- this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, keyPair));
31
- }
32
- serialize() {
33
- return this.senderKeyStates.map(state => state.getStructure());
34
- }
35
- static deserialize(data) {
36
- const str = Buffer.from(data).toString('utf-8');
37
- const parsed = JSON.parse(str, BufferJSON.reviver);
38
- return new SenderKeyRecord(parsed);
39
- }
40
- }
41
- //# sourceMappingURL=sender-key-record.js.map
@@ -1,84 +0,0 @@
1
- import { SenderChainKey } from './sender-chain-key.js';
2
- import { SenderMessageKey } from './sender-message-key.js';
3
- export class SenderKeyState {
4
- constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
5
- this.MAX_MESSAGE_KEYS = 2000;
6
- if (senderKeyStateStructure) {
7
- this.senderKeyStateStructure = {
8
- ...senderKeyStateStructure,
9
- senderMessageKeys: Array.isArray(senderKeyStateStructure.senderMessageKeys)
10
- ? senderKeyStateStructure.senderMessageKeys
11
- : []
12
- };
13
- }
14
- else {
15
- if (signatureKeyPair) {
16
- signatureKeyPublic = signatureKeyPair.public;
17
- signatureKeyPrivate = signatureKeyPair.private;
18
- }
19
- this.senderKeyStateStructure = {
20
- senderKeyId: id || 0,
21
- senderChainKey: {
22
- iteration: iteration || 0,
23
- seed: Buffer.from(chainKey || [])
24
- },
25
- senderSigningKey: {
26
- public: Buffer.from(signatureKeyPublic || []),
27
- private: Buffer.from(signatureKeyPrivate || [])
28
- },
29
- senderMessageKeys: []
30
- };
31
- }
32
- }
33
- getKeyId() {
34
- return this.senderKeyStateStructure.senderKeyId;
35
- }
36
- getSenderChainKey() {
37
- return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
38
- }
39
- setSenderChainKey(chainKey) {
40
- this.senderKeyStateStructure.senderChainKey = {
41
- iteration: chainKey.getIteration(),
42
- seed: chainKey.getSeed()
43
- };
44
- }
45
- getSigningKeyPublic() {
46
- const publicKey = Buffer.from(this.senderKeyStateStructure.senderSigningKey.public);
47
- if (publicKey.length === 32) {
48
- const fixed = Buffer.alloc(33);
49
- fixed[0] = 0x05;
50
- publicKey.copy(fixed, 1);
51
- return fixed;
52
- }
53
- return publicKey;
54
- }
55
- getSigningKeyPrivate() {
56
- const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
57
- return Buffer.from(privateKey || []);
58
- }
59
- hasSenderMessageKey(iteration) {
60
- return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration);
61
- }
62
- addSenderMessageKey(senderMessageKey) {
63
- this.senderKeyStateStructure.senderMessageKeys.push({
64
- iteration: senderMessageKey.getIteration(),
65
- seed: senderMessageKey.getSeed()
66
- });
67
- if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
68
- this.senderKeyStateStructure.senderMessageKeys.shift();
69
- }
70
- }
71
- removeSenderMessageKey(iteration) {
72
- const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration);
73
- if (index !== -1) {
74
- const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
75
- this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
76
- return new SenderMessageKey(messageKey.iteration, messageKey.seed);
77
- }
78
- return null;
79
- }
80
- getStructure() {
81
- return this.senderKeyStateStructure;
82
- }
83
- }
84
- //# sourceMappingURL=sender-key-state.js.map
@@ -1,26 +0,0 @@
1
- import { deriveSecrets } from 'libsignal/src/crypto.js';
2
- export class SenderMessageKey {
3
- constructor(iteration, seed) {
4
- const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
5
- const keys = new Uint8Array(32);
6
- keys.set(new Uint8Array(derivative[0].slice(16)));
7
- keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
8
- this.iv = Buffer.from(derivative[0].slice(0, 16));
9
- this.cipherKey = Buffer.from(keys.buffer);
10
- this.iteration = iteration;
11
- this.seed = seed;
12
- }
13
- getIteration() {
14
- return this.iteration;
15
- }
16
- getIv() {
17
- return this.iv;
18
- }
19
- getCipherKey() {
20
- return this.cipherKey;
21
- }
22
- getSeed() {
23
- return this.seed;
24
- }
25
- }
26
- //# sourceMappingURL=sender-message-key.js.map