@badzz88/baileys 8.5.7 → 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 (142) hide show
  1. package/README.md +337 -1055
  2. package/WAProto/WAProto.proto +284 -264
  3. package/WAProto/index.js +5 -5
  4. package/engine-requirements.js +7 -15
  5. package/lib/Defaults/index.js +130 -187
  6. package/lib/Signal/Group/ciphertext-message.js +11 -14
  7. package/lib/Signal/Group/group-session-builder.js +29 -91
  8. package/lib/Signal/Group/group_cipher.js +81 -88
  9. package/lib/Signal/Group/index.js +12 -136
  10. package/lib/Signal/Group/keyhelper.js +15 -70
  11. package/lib/Signal/Group/sender-chain-key.js +25 -31
  12. package/lib/Signal/Group/sender-key-distribution-message.js +62 -65
  13. package/lib/Signal/Group/sender-key-message.js +65 -68
  14. package/lib/Signal/Group/sender-key-name.js +41 -43
  15. package/lib/Signal/Group/sender-key-record.js +40 -43
  16. package/lib/Signal/Group/sender-key-state.js +83 -96
  17. package/lib/Signal/Group/sender-message-key.js +25 -29
  18. package/lib/Signal/libsignal.js +425 -453
  19. package/lib/Signal/lid-mapping.js +276 -259
  20. package/lib/Socket/Client/index.js +3 -30
  21. package/lib/Socket/Client/types.js +10 -12
  22. package/lib/Socket/Client/websocket.js +53 -61
  23. package/lib/Socket/business.js +379 -422
  24. package/lib/Socket/chats.js +1193 -1816
  25. package/lib/Socket/communities.js +431 -549
  26. package/lib/Socket/graphql.js +672 -612
  27. package/lib/Socket/groups.js +374 -764
  28. package/lib/Socket/index.js +17 -38
  29. package/lib/Socket/interop.js +417 -503
  30. package/lib/Socket/messages-recv.js +1915 -2441
  31. package/lib/Socket/messages-send.js +1213 -1630
  32. package/lib/Socket/mex.js +9 -15
  33. package/lib/Socket/newsletter.js +747 -808
  34. package/lib/Socket/privacy.js +310 -441
  35. package/lib/Socket/socket.js +1025 -1022
  36. package/lib/Socket/username.js +8 -15
  37. package/lib/Store/index.js +10 -36
  38. package/lib/Store/make-cache-manager-store.js +80 -85
  39. package/lib/Store/make-in-memory-store.js +231 -591
  40. package/lib/Store/make-ordered-dictionary.js +72 -78
  41. package/lib/Store/object-repository.js +28 -25
  42. package/lib/Types/Auth.js +2 -38
  43. package/lib/Types/Bussines.js +2 -2
  44. package/lib/Types/Call.js +2 -2
  45. package/lib/Types/Chat.js +8 -4
  46. package/lib/Types/Contact.js +2 -2
  47. package/lib/Types/Events.js +2 -2
  48. package/lib/Types/GroupMetadata.js +2 -2
  49. package/lib/Types/Label.js +24 -26
  50. package/lib/Types/LabelAssociation.js +6 -8
  51. package/lib/Types/Message.js +11 -95
  52. package/lib/Types/Mex.js +111 -112
  53. package/lib/Types/Product.js +2 -2
  54. package/lib/Types/Signal.js +2 -2
  55. package/lib/Types/Socket.js +3 -2
  56. package/lib/Types/State.js +56 -70
  57. package/lib/Types/USync.js +2 -2
  58. package/lib/Types/index.js +26 -55
  59. package/lib/Utils/auth-utils.js +288 -292
  60. package/lib/Utils/browser-utils.js +47 -113
  61. package/lib/Utils/business.js +224 -240
  62. package/lib/Utils/chat-utils.js +869 -1205
  63. package/lib/Utils/companion-reg-client-utils.js +34 -41
  64. package/lib/Utils/crypto.js +107 -144
  65. package/lib/Utils/decode-wa-message.js +308 -518
  66. package/lib/Utils/event-buffer.js +611 -596
  67. package/lib/Utils/generics.js +355 -515
  68. package/lib/Utils/history.js +134 -244
  69. package/lib/Utils/identity-change-handler.js +49 -51
  70. package/lib/Utils/index.js +23 -57
  71. package/lib/Utils/link-preview.js +77 -135
  72. package/lib/Utils/logger.js +3 -9
  73. package/lib/Utils/lt-hash.js +6 -37
  74. package/lib/Utils/make-mutex.js +33 -36
  75. package/lib/Utils/message-composer.js +233 -439
  76. package/lib/Utils/message-retry-manager.js +260 -265
  77. package/lib/Utils/messages-media.js +829 -855
  78. package/lib/Utils/messages.js +961 -2528
  79. package/lib/Utils/noise-handler.js +200 -195
  80. package/lib/Utils/offline-node-processor.js +33 -35
  81. package/lib/Utils/pre-key-manager.js +102 -103
  82. package/lib/Utils/process-message.js +560 -978
  83. package/lib/Utils/reporting-utils.js +253 -257
  84. package/lib/Utils/signal.js +195 -218
  85. package/lib/Utils/stanza-ack.js +29 -31
  86. package/lib/Utils/sticker.js +109 -144
  87. package/lib/Utils/sync-action-utils.js +45 -50
  88. package/lib/Utils/tc-token-utils.js +139 -137
  89. package/lib/Utils/use-multi-file-auth-state.js +109 -109
  90. package/lib/Utils/validate-connection.js +202 -218
  91. package/lib/WABinary/constants.js +1299 -1302
  92. package/lib/WABinary/decode.js +262 -343
  93. package/lib/WABinary/encode.js +4 -12
  94. package/lib/WABinary/generic-utils.js +187 -223
  95. package/lib/WABinary/index.js +6 -33
  96. package/lib/WABinary/jid-utils.js +88 -351
  97. package/lib/WABinary/types.js +2 -2
  98. package/lib/WAM/BinaryInfo.js +9 -12
  99. package/lib/WAM/constants.js +22853 -39486
  100. package/lib/WAM/encode.js +140 -132
  101. package/lib/WAM/index.js +4 -31
  102. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +21 -23
  103. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +9 -9
  104. package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -7
  105. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -10
  106. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -7
  107. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +11 -12
  108. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +4 -5
  109. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +7 -7
  110. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +7 -8
  111. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -7
  112. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +8 -8
  113. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +7 -7
  114. package/lib/WAUSync/Protocols/index.js +12 -39
  115. package/lib/WAUSync/USyncQuery.js +67 -49
  116. package/lib/WAUSync/USyncUser.js +11 -5
  117. package/lib/WAUSync/index.js +3 -31
  118. package/lib/index.js +15 -48
  119. package/package.json +129 -99
  120. package/LICENSE +0 -21
  121. package/lib/Defaults/phonenumber-mcc.json +0 -223
  122. package/lib/Socket/aigroups.js +0 -240
  123. package/lib/Socket/interactive-handler.js +0 -522
  124. package/lib/Socket/managed-account.js +0 -183
  125. package/lib/Socket/registration.js +0 -427
  126. package/lib/Socket/text-router.js +0 -83
  127. package/lib/Types/Newsletter.js +0 -121
  128. package/lib/Utils/command-loader.d.ts +0 -31
  129. package/lib/Utils/command-loader.js +0 -100
  130. package/lib/Utils/consumer-application.js +0 -107
  131. package/lib/Utils/curve25519-js.js +0 -275
  132. package/lib/Utils/group-history.js +0 -60
  133. package/lib/Utils/jid-display-normalization.js +0 -218
  134. package/lib/Utils/meta-ai-msmsg.js +0 -262
  135. package/lib/Utils/native-bridge.js +0 -82
  136. package/lib/Utils/session-pool.d.ts +0 -16
  137. package/lib/Utils/session-pool.js +0 -94
  138. package/lib/Utils/sticker.d.ts +0 -17
  139. package/lib/Utils/view-once-cache.d.ts +0 -9
  140. package/lib/Utils/view-once-cache.js +0 -79
  141. package/lib/Utils/voip-rekey.js +0 -22
  142. package/lib/antiban.js +0 -4637
package/lib/WAM/encode.js CHANGED
@@ -1,142 +1,150 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.encodeWAM = void 0
4
- const constants_1 = require('./constants')
5
- const getHeaderBitLength = key => (key < 256 ? 2 : 3)
6
- const encodeWAM = binaryInfo => {
7
- binaryInfo.buffer = []
8
- encodeWAMHeader(binaryInfo)
9
- encodeEvents(binaryInfo)
10
- const totalSize = binaryInfo.buffer.map(a => a.length).reduce((a, b) => a + b)
11
- const buffer = Buffer.alloc(totalSize)
12
- let offset = 0
13
- for (const buffer_ of binaryInfo.buffer) {
14
- buffer_.copy(buffer, offset)
15
- offset += buffer_.length
16
- }
17
- return buffer
18
- }
19
- exports.encodeWAM = encodeWAM
1
+ import { BinaryInfo } from './BinaryInfo.js';
2
+ import { FLAG_BYTE, FLAG_EVENT, FLAG_EXTENDED, FLAG_FIELD, FLAG_GLOBAL, WEB_EVENTS, WEB_GLOBALS } from './constants.js';
3
+ const getHeaderBitLength = (key) => (key < 256 ? 2 : 3);
4
+ export const encodeWAM = (binaryInfo) => {
5
+ binaryInfo.buffer = [];
6
+ encodeWAMHeader(binaryInfo);
7
+ encodeEvents(binaryInfo);
8
+ const totalSize = binaryInfo.buffer.map(a => a.length).reduce((a, b) => a + b);
9
+ const buffer = Buffer.alloc(totalSize);
10
+ let offset = 0;
11
+ for (const buffer_ of binaryInfo.buffer) {
12
+ buffer_.copy(buffer, offset);
13
+ offset += buffer_.length;
14
+ }
15
+ return buffer;
16
+ };
20
17
  function encodeWAMHeader(binaryInfo) {
21
- const headerBuffer = Buffer.alloc(8) // starting buffer
22
- headerBuffer.write('WAM', 0, 'utf8')
23
- headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3)
24
- headerBuffer.writeUInt8(1, 4) //random flag
25
- headerBuffer.writeUInt16BE(binaryInfo.sequence, 5)
26
- headerBuffer.writeUInt8(0, 7) // regular channel
27
- binaryInfo.buffer.push(headerBuffer)
18
+ const headerBuffer = Buffer.alloc(8); // starting buffer
19
+ headerBuffer.write('WAM', 0, 'utf8');
20
+ headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3);
21
+ headerBuffer.writeUInt8(1, 4); //random flag
22
+ headerBuffer.writeUInt16BE(binaryInfo.sequence, 5);
23
+ headerBuffer.writeUInt8(0, 7); // regular channel
24
+ binaryInfo.buffer.push(headerBuffer);
28
25
  }
29
26
  function encodeGlobalAttributes(binaryInfo, globals) {
30
- for (const [key, _value] of Object.entries(globals)) {
31
- const id = constants_1.WEB_GLOBALS.find(a => a?.name === key).id
32
- let value = _value
33
- if (typeof value === 'boolean') {
34
- value = value ? 1 : 0
35
- }
36
- binaryInfo.buffer.push(serializeData(id, value, constants_1.FLAG_GLOBAL))
37
- }
27
+ for (const [key, _value] of Object.entries(globals)) {
28
+ const id = WEB_GLOBALS.find(a => a?.name === key).id;
29
+ let value = _value;
30
+ if (typeof value === 'boolean') {
31
+ value = value ? 1 : 0;
32
+ }
33
+ binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL));
34
+ }
38
35
  }
39
36
  function encodeEvents(binaryInfo) {
40
- for (const [name, { props, globals }] of binaryInfo.events.map(a => Object.entries(a)[0])) {
41
- encodeGlobalAttributes(binaryInfo, globals)
42
- const event = constants_1.WEB_EVENTS.find(a => a.name === name)
43
- const props_ = Object.entries(props)
44
- let extended = false
45
- for (const [, value] of props_) {
46
- extended || (extended = value !== null)
47
- }
48
- const eventFlag = extended ? constants_1.FLAG_EVENT : constants_1.FLAG_EVENT | constants_1.FLAG_EXTENDED
49
- binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag))
50
- for (let i = 0; i < props_.length; i++) {
51
- const [key, _value] = props_[i]
52
- const id = event.props[key]?.[0]
53
- extended = i < props_.length - 1
54
- let value = _value
55
- if (typeof value === 'boolean') {
56
- value = value ? 1 : 0
57
- }
58
- const fieldFlag = extended ? constants_1.FLAG_EVENT : constants_1.FLAG_FIELD | constants_1.FLAG_EXTENDED
59
- binaryInfo.buffer.push(serializeData(id, value, fieldFlag))
60
- }
61
- }
37
+ for (const [name, { props, globals }] of binaryInfo.events.map(a => Object.entries(a)[0])) {
38
+ encodeGlobalAttributes(binaryInfo, globals);
39
+ const event = WEB_EVENTS.find(a => a.name === name);
40
+ const props_ = Object.entries(props);
41
+ let extended = false;
42
+ for (const [, value] of props_) {
43
+ extended || (extended = value !== null);
44
+ }
45
+ const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED;
46
+ binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag));
47
+ for (let i = 0; i < props_.length; i++) {
48
+ const [key, _value] = props_[i];
49
+ const id = event.props[key]?.[0];
50
+ extended = i < props_.length - 1;
51
+ let value = _value;
52
+ if (typeof value === 'boolean') {
53
+ value = value ? 1 : 0;
54
+ }
55
+ const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED;
56
+ binaryInfo.buffer.push(serializeData(id, value, fieldFlag));
57
+ }
58
+ }
62
59
  }
63
60
  function serializeData(key, value, flag) {
64
- const bufferLength = getHeaderBitLength(key)
65
- let buffer
66
- let offset = 0
67
- if (value === null) {
68
- if (flag === constants_1.FLAG_GLOBAL) {
69
- buffer = Buffer.alloc(bufferLength)
70
- offset = serializeHeader(buffer, offset, key, flag)
71
- return buffer
72
- }
73
- } else if (typeof value === 'number' && Number.isInteger(value)) {
74
- // is number
75
- if (value === 0 || value === 1) {
76
- buffer = Buffer.alloc(bufferLength)
77
- offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4))
78
- return buffer
79
- } else if (-128 <= value && value < 128) {
80
- buffer = Buffer.alloc(bufferLength + 1)
81
- offset = serializeHeader(buffer, offset, key, flag | (3 << 4))
82
- buffer.writeInt8(value, offset)
83
- return buffer
84
- } else if (-32768 <= value && value < 32768) {
85
- buffer = Buffer.alloc(bufferLength + 2)
86
- offset = serializeHeader(buffer, offset, key, flag | (4 << 4))
87
- buffer.writeInt16LE(value, offset)
88
- return buffer
89
- } else if (-2147483648 <= value && value < 2147483648) {
90
- buffer = Buffer.alloc(bufferLength + 4)
91
- offset = serializeHeader(buffer, offset, key, flag | (5 << 4))
92
- buffer.writeInt32LE(value, offset)
93
- return buffer
94
- } else {
95
- buffer = Buffer.alloc(bufferLength + 8)
96
- offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
97
- buffer.writeDoubleLE(value, offset)
98
- return buffer
99
- }
100
- } else if (typeof value === 'number') {
101
- // is float
102
- buffer = Buffer.alloc(bufferLength + 8)
103
- offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
104
- buffer.writeDoubleLE(value, offset)
105
- return buffer
106
- } else if (typeof value === 'string') {
107
- // is string
108
- const utf8Bytes = Buffer.byteLength(value, 'utf8')
109
- if (utf8Bytes < 256) {
110
- buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes)
111
- offset = serializeHeader(buffer, offset, key, flag | (8 << 4))
112
- buffer.writeUint8(utf8Bytes, offset++)
113
- } else if (utf8Bytes < 65536) {
114
- buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes)
115
- offset = serializeHeader(buffer, offset, key, flag | (9 << 4))
116
- buffer.writeUInt16LE(utf8Bytes, offset)
117
- offset += 2
118
- } else {
119
- buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes)
120
- offset = serializeHeader(buffer, offset, key, flag | (10 << 4))
121
- buffer.writeUInt32LE(utf8Bytes, offset)
122
- offset += 4
123
- }
124
- buffer.write(value, offset, 'utf8')
125
- return buffer
126
- }
127
- throw 'missing'
61
+ const bufferLength = getHeaderBitLength(key);
62
+ let buffer;
63
+ let offset = 0;
64
+ if (value === null) {
65
+ if (flag === FLAG_GLOBAL) {
66
+ buffer = Buffer.alloc(bufferLength);
67
+ offset = serializeHeader(buffer, offset, key, flag);
68
+ return buffer;
69
+ }
70
+ }
71
+ else if (typeof value === 'number' && Number.isInteger(value)) {
72
+ // is number
73
+ if (value === 0 || value === 1) {
74
+ buffer = Buffer.alloc(bufferLength);
75
+ offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4));
76
+ return buffer;
77
+ }
78
+ else if (-128 <= value && value < 128) {
79
+ buffer = Buffer.alloc(bufferLength + 1);
80
+ offset = serializeHeader(buffer, offset, key, flag | (3 << 4));
81
+ buffer.writeInt8(value, offset);
82
+ return buffer;
83
+ }
84
+ else if (-32768 <= value && value < 32768) {
85
+ buffer = Buffer.alloc(bufferLength + 2);
86
+ offset = serializeHeader(buffer, offset, key, flag | (4 << 4));
87
+ buffer.writeInt16LE(value, offset);
88
+ return buffer;
89
+ }
90
+ else if (-2147483648 <= value && value < 2147483648) {
91
+ buffer = Buffer.alloc(bufferLength + 4);
92
+ offset = serializeHeader(buffer, offset, key, flag | (5 << 4));
93
+ buffer.writeInt32LE(value, offset);
94
+ return buffer;
95
+ }
96
+ else {
97
+ buffer = Buffer.alloc(bufferLength + 8);
98
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
99
+ buffer.writeDoubleLE(value, offset);
100
+ return buffer;
101
+ }
102
+ }
103
+ else if (typeof value === 'number') {
104
+ // is float
105
+ buffer = Buffer.alloc(bufferLength + 8);
106
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
107
+ buffer.writeDoubleLE(value, offset);
108
+ return buffer;
109
+ }
110
+ else if (typeof value === 'string') {
111
+ // is string
112
+ const utf8Bytes = Buffer.byteLength(value, 'utf8');
113
+ if (utf8Bytes < 256) {
114
+ buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes);
115
+ offset = serializeHeader(buffer, offset, key, flag | (8 << 4));
116
+ buffer.writeUint8(utf8Bytes, offset++);
117
+ }
118
+ else if (utf8Bytes < 65536) {
119
+ buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes);
120
+ offset = serializeHeader(buffer, offset, key, flag | (9 << 4));
121
+ buffer.writeUInt16LE(utf8Bytes, offset);
122
+ offset += 2;
123
+ }
124
+ else {
125
+ buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes);
126
+ offset = serializeHeader(buffer, offset, key, flag | (10 << 4));
127
+ buffer.writeUInt32LE(utf8Bytes, offset);
128
+ offset += 4;
129
+ }
130
+ buffer.write(value, offset, 'utf8');
131
+ return buffer;
132
+ }
133
+ throw 'missing';
128
134
  }
129
135
  function serializeHeader(buffer, offset, key, flag) {
130
- if (key < 256) {
131
- buffer.writeUInt8(flag, offset)
132
- offset += 1
133
- buffer.writeUInt8(key, offset)
134
- offset += 1
135
- } else {
136
- buffer.writeUInt8(flag | constants_1.FLAG_BYTE, offset)
137
- offset += 1
138
- buffer.writeUInt16LE(key, offset)
139
- offset += 2
140
- }
141
- return offset
136
+ if (key < 256) {
137
+ buffer.writeUInt8(flag, offset);
138
+ offset += 1;
139
+ buffer.writeUInt8(key, offset);
140
+ offset += 1;
141
+ }
142
+ else {
143
+ buffer.writeUInt8(flag | FLAG_BYTE, offset);
144
+ offset += 1;
145
+ buffer.writeUInt16LE(key, offset);
146
+ offset += 2;
147
+ }
148
+ return offset;
142
149
  }
150
+ //# sourceMappingURL=encode.js.map
package/lib/WAM/index.js CHANGED
@@ -1,31 +1,4 @@
1
- 'use strict'
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k
7
- var desc = Object.getOwnPropertyDescriptor(m, k)
8
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = {
10
- enumerable: true,
11
- get: function () {
12
- return m[k]
13
- }
14
- }
15
- }
16
- Object.defineProperty(o, k2, desc)
17
- }
18
- : function (o, m, k, k2) {
19
- if (k2 === undefined) k2 = k
20
- o[k2] = m[k]
21
- })
22
- var __exportStar =
23
- (this && this.__exportStar) ||
24
- function (m, exports) {
25
- for (var p in m)
26
- if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
27
- }
28
- Object.defineProperty(exports, '__esModule', { value: true })
29
- __exportStar(require('./constants'), exports)
30
- __exportStar(require('./encode'), exports)
31
- __exportStar(require('./BinaryInfo'), exports)
1
+ export * from './constants.js';
2
+ export * from './encode.js';
3
+ export * from './BinaryInfo.js';
4
+ //# sourceMappingURL=index.js.map
@@ -1,11 +1,10 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.USyncBotProfileProtocol = void 0
4
- const WABinary_1 = require('../../WABinary')
5
- class USyncBotProfileProtocol {
1
+ import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString } from '../../WABinary/index.js'
2
+
3
+ export class USyncBotProfileProtocol {
6
4
  constructor() {
7
5
  this.name = 'bot'
8
6
  }
7
+
9
8
  getQueryElement() {
10
9
  return {
11
10
  tag: 'bot',
@@ -13,6 +12,7 @@ class USyncBotProfileProtocol {
13
12
  content: [{ tag: 'profile', attrs: { v: '1' } }]
14
13
  }
15
14
  }
15
+
16
16
  getUserElement(user) {
17
17
  return {
18
18
  tag: 'bot',
@@ -20,36 +20,34 @@ class USyncBotProfileProtocol {
20
20
  content: [{ tag: 'profile', attrs: { persona_id: user.personaId } }]
21
21
  }
22
22
  }
23
+
23
24
  parser(node) {
24
- const botNode = (0, WABinary_1.getBinaryNodeChild)(node, 'bot')
25
- const profile = (0, WABinary_1.getBinaryNodeChild)(botNode, 'profile')
26
- const commandsNode = (0, WABinary_1.getBinaryNodeChild)(profile, 'commands')
27
- const promptsNode = (0, WABinary_1.getBinaryNodeChild)(profile, 'prompts')
25
+ const botNode = getBinaryNodeChild(node, 'bot')
26
+ const profile = getBinaryNodeChild(botNode, 'profile')
27
+ const commandsNode = getBinaryNodeChild(profile, 'commands')
28
+ const promptsNode = getBinaryNodeChild(profile, 'prompts')
28
29
  const commands = []
29
30
  const prompts = []
30
- for (const command of (0, WABinary_1.getBinaryNodeChildren)(commandsNode, 'command')) {
31
+ for (const command of getBinaryNodeChildren(commandsNode, 'command')) {
31
32
  commands.push({
32
- name: (0, WABinary_1.getBinaryNodeChildString)(command, 'name'),
33
- description: (0, WABinary_1.getBinaryNodeChildString)(command, 'description')
33
+ name: getBinaryNodeChildString(command, 'name'),
34
+ description: getBinaryNodeChildString(command, 'description')
34
35
  })
35
36
  }
36
- for (const prompt of (0, WABinary_1.getBinaryNodeChildren)(promptsNode, 'prompt')) {
37
- prompts.push(
38
- `${(0, WABinary_1.getBinaryNodeChildString)(prompt, 'emoji')} ${(0, WABinary_1.getBinaryNodeChildString)(prompt, 'text')}`
39
- )
37
+ for (const prompt of getBinaryNodeChildren(promptsNode, 'prompt')) {
38
+ prompts.push(`${getBinaryNodeChildString(prompt, 'emoji')} ${getBinaryNodeChildString(prompt, 'text')}`)
40
39
  }
41
40
  return {
42
- isDefault: !!(0, WABinary_1.getBinaryNodeChild)(profile, 'default'),
41
+ isDefault: !!getBinaryNodeChild(profile, 'default'),
43
42
  jid: node.attrs.jid,
44
- name: (0, WABinary_1.getBinaryNodeChildString)(profile, 'name'),
45
- attributes: (0, WABinary_1.getBinaryNodeChildString)(profile, 'attributes'),
46
- description: (0, WABinary_1.getBinaryNodeChildString)(profile, 'description'),
47
- category: (0, WABinary_1.getBinaryNodeChildString)(profile, 'category'),
43
+ name: getBinaryNodeChildString(profile, 'name'),
44
+ attributes: getBinaryNodeChildString(profile, 'attributes'),
45
+ description: getBinaryNodeChildString(profile, 'description'),
46
+ category: getBinaryNodeChildString(profile, 'category'),
48
47
  personaId: profile.attrs['persona_id'],
49
- commandsDescription: (0, WABinary_1.getBinaryNodeChildString)(commandsNode, 'description'),
48
+ commandsDescription: getBinaryNodeChildString(commandsNode, 'description'),
50
49
  commands,
51
50
  prompts
52
51
  }
53
52
  }
54
53
  }
55
- exports.USyncBotProfileProtocol = USyncBotProfileProtocol
@@ -1,12 +1,11 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.USyncBusinessProtocol = void 0
4
- const WABinary_1 = require('../../WABinary')
5
- class USyncBusinessProtocol {
1
+ import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js'
2
+
3
+ export class USyncBusinessProtocol {
6
4
  constructor(profileVersion = '2') {
7
5
  this.name = 'business'
8
6
  this.profileVersion = profileVersion
9
7
  }
8
+
10
9
  getQueryElement() {
11
10
  return {
12
11
  tag: 'business',
@@ -17,6 +16,7 @@ class USyncBusinessProtocol {
17
16
  ]
18
17
  }
19
18
  }
19
+
20
20
  getUserElement(user) {
21
21
  const children = []
22
22
  if (user.verifiedNameSerial) {
@@ -27,11 +27,12 @@ class USyncBusinessProtocol {
27
27
  }
28
28
  return children.length > 0 ? { tag: 'business', attrs: {}, content: children } : null
29
29
  }
30
+
30
31
  parser(node) {
31
32
  if (node.tag !== 'business') return null
32
- ;(0, WABinary_1.assertNodeErrorFree)(node)
33
- const verifiedNameNode = (0, WABinary_1.getBinaryNodeChild)(node, 'verified_name')
34
- const profileNode = (0, WABinary_1.getBinaryNodeChild)(node, 'profile')
33
+ assertNodeErrorFree(node)
34
+ const verifiedNameNode = getBinaryNodeChild(node, 'verified_name')
35
+ const profileNode = getBinaryNodeChild(node, 'profile')
35
36
  return {
36
37
  verifiedName: verifiedNameNode?.content ?? null,
37
38
  verifiedLevel: verifiedNameNode?.attrs?.verified_level ?? null,
@@ -40,4 +41,3 @@ class USyncBusinessProtocol {
40
41
  }
41
42
  }
42
43
  }
43
- exports.USyncBusinessProtocol = USyncBusinessProtocol
@@ -1,17 +1,17 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.USyncContactProtocol = void 0
4
- const WABinary_1 = require('../../WABinary')
5
- class USyncContactProtocol {
1
+ import { assertNodeErrorFree } from '../../WABinary/index.js'
2
+
3
+ export class USyncContactProtocol {
6
4
  constructor() {
7
5
  this.name = 'contact'
8
6
  }
7
+
9
8
  getQueryElement() {
10
9
  return {
11
10
  tag: 'contact',
12
11
  attrs: {}
13
12
  }
14
13
  }
14
+
15
15
  getUserElement(user) {
16
16
  if (user.phone) {
17
17
  return {
@@ -43,12 +43,12 @@ class USyncContactProtocol {
43
43
  attrs: {}
44
44
  }
45
45
  }
46
+
46
47
  parser(node) {
47
48
  if (node.tag === 'contact') {
48
- ;(0, WABinary_1.assertNodeErrorFree)(node)
49
+ assertNodeErrorFree(node)
49
50
  return node?.attrs?.type === 'in'
50
51
  }
51
52
  return false
52
53
  }
53
54
  }
54
- exports.USyncContactProtocol = USyncContactProtocol
@@ -1,11 +1,10 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.USyncDeviceProtocol = void 0
4
- const WABinary_1 = require('../../WABinary')
5
- class USyncDeviceProtocol {
1
+ import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js'
2
+
3
+ export class USyncDeviceProtocol {
6
4
  constructor() {
7
5
  this.name = 'devices'
8
6
  }
7
+
9
8
  getQueryElement() {
10
9
  return {
11
10
  tag: 'devices',
@@ -14,19 +13,21 @@ class USyncDeviceProtocol {
14
13
  }
15
14
  }
16
15
  }
17
- getUserElement(/* user: USyncUser */) {
16
+
17
+ getUserElement(/* user */) {
18
18
  //TODO: Implement device phashing, ts and expectedTs
19
19
  //TODO: if all are not present, return null <- current behavior
20
20
  //TODO: otherwise return a node w tag 'devices' w those as attrs
21
21
  return null
22
22
  }
23
+
23
24
  parser(node) {
24
25
  const deviceList = []
25
26
  let keyIndex = undefined
26
27
  if (node.tag === 'devices') {
27
- ;(0, WABinary_1.assertNodeErrorFree)(node)
28
- const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(node, 'device-list')
29
- const keyIndexNode = (0, WABinary_1.getBinaryNodeChild)(node, 'key-index-list')
28
+ assertNodeErrorFree(node)
29
+ const deviceListNode = getBinaryNodeChild(node, 'device-list')
30
+ const keyIndexNode = getBinaryNodeChild(node, 'key-index-list')
30
31
  if (Array.isArray(deviceListNode?.content)) {
31
32
  for (const { tag, attrs } of deviceListNode.content) {
32
33
  const id = +attrs.id
@@ -54,4 +55,3 @@ class USyncDeviceProtocol {
54
55
  }
55
56
  }
56
57
  }
57
- exports.USyncDeviceProtocol = USyncDeviceProtocol
@@ -1,23 +1,24 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.USyncDisappearingModeProtocol = void 0
4
- const WABinary_1 = require('../../WABinary')
5
- class USyncDisappearingModeProtocol {
1
+ import { assertNodeErrorFree } from '../../WABinary/index.js'
2
+
3
+ export class USyncDisappearingModeProtocol {
6
4
  constructor() {
7
5
  this.name = 'disappearing_mode'
8
6
  }
7
+
9
8
  getQueryElement() {
10
9
  return {
11
10
  tag: 'disappearing_mode',
12
11
  attrs: {}
13
12
  }
14
13
  }
14
+
15
15
  getUserElement() {
16
16
  return null
17
17
  }
18
+
18
19
  parser(node) {
19
20
  if (node.tag === 'disappearing_mode') {
20
- ;(0, WABinary_1.assertNodeErrorFree)(node)
21
+ assertNodeErrorFree(node)
21
22
  const duration = +node?.attrs.duration
22
23
  const setAt = new Date(+(node?.attrs.t || 0) * 1000)
23
24
  return {
@@ -27,4 +28,3 @@ class USyncDisappearingModeProtocol {
27
28
  }
28
29
  }
29
30
  }
30
- exports.USyncDisappearingModeProtocol = USyncDisappearingModeProtocol
@@ -1,10 +1,8 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.USyncFeatureProtocol = exports.USYNC_FEATURES = void 0
4
- const WABinary_1 = require('../../WABinary')
1
+ import { getBinaryNodeChild } from '../../WABinary/index.js'
2
+
5
3
  // Device feature flags that can be queried, ported from WhatsApp Web's
6
4
  // WAWebUsyncFeature module.
7
- exports.USYNC_FEATURES = [
5
+ export const USYNC_FEATURES = [
8
6
  'document',
9
7
  'encrypt',
10
8
  'encrypt_blist',
@@ -17,14 +15,16 @@ exports.USYNC_FEATURES = [
17
15
  'voip',
18
16
  'multi_agent'
19
17
  ]
20
- class USyncFeatureProtocol {
18
+
19
+ export class USyncFeatureProtocol {
21
20
  /**
22
21
  * @param {string[]} [features] feature names to query (defaults to all known)
23
22
  */
24
23
  constructor(features) {
25
24
  this.name = 'feature'
26
- this.features = features && features.length ? features : exports.USYNC_FEATURES
25
+ this.features = features && features.length ? features : USYNC_FEATURES
27
26
  }
27
+
28
28
  getQueryElement() {
29
29
  return {
30
30
  tag: 'feature',
@@ -32,14 +32,14 @@ class USyncFeatureProtocol {
32
32
  content: this.features.map(feature => ({ tag: feature, attrs: {} }))
33
33
  }
34
34
  }
35
+
35
36
  getUserElement() {
36
37
  return null
37
38
  }
39
+
38
40
  parser(node) {
39
- if (node.tag !== 'feature') {
40
- return null
41
- }
42
- const errorNode = (0, WABinary_1.getBinaryNodeChild)(node, 'error')
41
+ if (node.tag !== 'feature') return null
42
+ const errorNode = getBinaryNodeChild(node, 'error')
43
43
  if (errorNode) {
44
44
  return {
45
45
  errorCode: errorNode.attrs?.code ? +errorNode.attrs.code : undefined,
@@ -56,4 +56,3 @@ class USyncFeatureProtocol {
56
56
  return features
57
57
  }
58
58
  }
59
- exports.USyncFeatureProtocol = USyncFeatureProtocol
@@ -1,16 +1,15 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.USyncLIDProtocol = void 0
4
- class USyncLIDProtocol {
1
+ export class USyncLIDProtocol {
5
2
  constructor() {
6
3
  this.name = 'lid'
7
4
  }
5
+
8
6
  getQueryElement() {
9
7
  return {
10
8
  tag: 'lid',
11
9
  attrs: {}
12
10
  }
13
11
  }
12
+
14
13
  getUserElement(user) {
15
14
  if (user.lid) {
16
15
  return {
@@ -21,6 +20,7 @@ class USyncLIDProtocol {
21
20
  return null
22
21
  }
23
22
  }
23
+
24
24
  parser(node) {
25
25
  if (node.tag === 'lid') {
26
26
  return node.attrs.val
@@ -28,4 +28,3 @@ class USyncLIDProtocol {
28
28
  return null
29
29
  }
30
30
  }
31
- exports.USyncLIDProtocol = USyncLIDProtocol