sanka-baileyss 2.3.2 → 2.3.3

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 (158) hide show
  1. package/WAProto/BotMetadata/BotMetadata.d.ts +594 -1
  2. package/WAProto/BotMetadata/BotMetadata.js +1910 -148
  3. package/WAProto/BotMetadata/BotMetadata.proto +36 -0
  4. package/WAProto/E2E/E2E.d.ts +570 -6
  5. package/WAProto/E2E/E2E.js +1591 -26
  6. package/WAProto/E2E/E2E.proto +10 -1
  7. package/WAProto/HistorySync/HistorySync.d.ts +806 -6
  8. package/WAProto/HistorySync/HistorySync.js +2193 -29
  9. package/WAProto/HistorySync/HistorySync.proto +2 -1
  10. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +570 -6
  11. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +1591 -26
  12. package/WAProto/StatusAttributions/StatusAttributions.d.ts +2 -1
  13. package/WAProto/StatusAttributions/StatusAttributions.js +7 -0
  14. package/WAProto/StatusAttributions/StatusAttributions.proto +1 -0
  15. package/WAProto/SyncAction/SyncAction.d.ts +230 -0
  16. package/WAProto/SyncAction/SyncAction.js +578 -2
  17. package/WAProto/SyncAction/SyncAction.proto +13 -1
  18. package/WAProto/Web/Web.d.ts +570 -6
  19. package/WAProto/Web/Web.js +1591 -26
  20. package/lib/Defaults/baileys-version.json +2 -2
  21. package/lib/Defaults/index.d.ts +42 -25
  22. package/lib/Defaults/index.js +6 -2
  23. package/lib/Signal/libsignal.d.ts +1 -0
  24. package/lib/Socket/Client/index.js +13 -9
  25. package/lib/Socket/Client/types.d.ts +11 -10
  26. package/lib/Socket/Client/types.js +11 -7
  27. package/lib/Socket/Client/websocket.d.ts +9 -8
  28. package/lib/Socket/Client/websocket.js +52 -47
  29. package/lib/Socket/business.d.ts +185 -182
  30. package/lib/Socket/business.js +258 -249
  31. package/lib/Socket/chats.d.ts +90 -87
  32. package/lib/Socket/chats.js +1095 -888
  33. package/lib/Socket/community.d.ts +131 -0
  34. package/lib/Socket/community.js +369 -0
  35. package/lib/Socket/groups.d.ts +50 -41
  36. package/lib/Socket/groups.js +10 -3
  37. package/lib/Socket/index.d.ts +5 -1
  38. package/lib/Socket/index.js +19 -5
  39. package/lib/Socket/messages-recv.d.ts +6 -2
  40. package/lib/Socket/messages-recv.js +31 -8
  41. package/lib/Socket/messages-send.d.ts +5 -1
  42. package/lib/Socket/messages-send.js +1293 -1351
  43. package/lib/Socket/newsletter.d.ts +142 -135
  44. package/lib/Socket/newsletter.js +274 -230
  45. package/lib/Socket/socket.d.ts +37 -35
  46. package/lib/Socket/usync.d.ts +31 -30
  47. package/lib/Socket/usync.js +74 -62
  48. package/lib/Types/Auth.d.ts +89 -72
  49. package/lib/Types/Auth.js +1 -0
  50. package/lib/Types/Call.d.ts +11 -10
  51. package/lib/Types/Call.js +1 -0
  52. package/lib/Types/Chat.d.ts +85 -62
  53. package/lib/Types/Chat.js +4 -1
  54. package/lib/Types/Contact.js +1 -0
  55. package/lib/Types/Events.d.ts +209 -191
  56. package/lib/Types/Events.js +1 -0
  57. package/lib/Types/GroupMetadata.d.ts +12 -27
  58. package/lib/Types/GroupMetadata.js +1 -0
  59. package/lib/Types/Label.d.ts +41 -39
  60. package/lib/Types/Label.js +24 -21
  61. package/lib/Types/LabelAssociation.d.ts +18 -12
  62. package/lib/Types/LabelAssociation.js +6 -3
  63. package/lib/Types/Message.d.ts +3 -2
  64. package/lib/Types/Message.js +7 -3
  65. package/lib/Types/MexUpdates.d.ts +9 -0
  66. package/lib/Types/MexUpdates.js +18 -0
  67. package/lib/Types/Newsletter.d.ts +84 -67
  68. package/lib/Types/Newsletter.js +30 -23
  69. package/lib/Types/Product.d.ts +70 -56
  70. package/lib/Types/Product.js +1 -0
  71. package/lib/Types/Signal.d.ts +46 -35
  72. package/lib/Types/Signal.js +1 -0
  73. package/lib/Types/Socket.d.ts +105 -101
  74. package/lib/Types/Socket.js +1 -0
  75. package/lib/Types/State.d.ts +37 -23
  76. package/lib/Types/State.js +13 -1
  77. package/lib/Types/USync.d.ts +21 -20
  78. package/lib/Types/USync.js +1 -0
  79. package/lib/Types/index.d.ts +51 -42
  80. package/lib/Types/index.js +25 -19
  81. package/lib/Utils/auth-utils.d.ts +14 -11
  82. package/lib/Utils/auth-utils.js +189 -182
  83. package/lib/Utils/baileys-event-stream.d.ts +12 -10
  84. package/lib/Utils/baileys-event-stream.js +52 -46
  85. package/lib/Utils/business.d.ts +15 -8
  86. package/lib/Utils/business.js +229 -217
  87. package/lib/Utils/chat-utils.d.ts +22 -12
  88. package/lib/Utils/chat-utils.js +57 -27
  89. package/lib/Utils/crypto.d.ts +31 -15
  90. package/lib/Utils/crypto.js +136 -107
  91. package/lib/Utils/decode-wa-message.d.ts +34 -245
  92. package/lib/Utils/decode-wa-message.js +205 -217
  93. package/lib/Utils/event-buffer.d.ts +30 -26
  94. package/lib/Utils/event-buffer.js +519 -515
  95. package/lib/Utils/history.d.ts +2 -8
  96. package/lib/Utils/index.js +13 -9
  97. package/lib/Utils/link-preview.d.ts +16 -14
  98. package/lib/Utils/link-preview.js +100 -92
  99. package/lib/Utils/logger.d.ts +9 -7
  100. package/lib/Utils/logger.js +1 -1
  101. package/lib/Utils/lt-hash.d.ts +10 -8
  102. package/lib/Utils/lt-hash.js +49 -44
  103. package/lib/Utils/make-mutex.d.ts +4 -2
  104. package/lib/Utils/make-mutex.js +43 -39
  105. package/lib/Utils/messages-media.d.ts +75 -50
  106. package/lib/Utils/messages.d.ts +60 -35
  107. package/lib/Utils/messages.js +87 -8
  108. package/lib/Utils/noise-handler.d.ts +13 -12
  109. package/lib/Utils/noise-handler.js +143 -138
  110. package/lib/Utils/process-message.d.ts +32 -24
  111. package/lib/Utils/process-message.js +387 -367
  112. package/lib/Utils/signal.d.ts +24 -15
  113. package/lib/Utils/signal.js +143 -131
  114. package/lib/Utils/use-mongo-file-auth-state.d.ts +3 -2
  115. package/lib/Utils/use-mongo-file-auth-state.js +72 -63
  116. package/lib/Utils/use-multi-file-auth-state.d.ts +9 -8
  117. package/lib/Utils/use-multi-file-auth-state.js +110 -102
  118. package/lib/Utils/use-single-file-auth-state.d.ts +8 -7
  119. package/lib/Utils/use-single-file-auth-state.js +66 -61
  120. package/lib/Utils/validate-connection.d.ts +5 -2
  121. package/lib/Utils/validate-connection.js +7 -6
  122. package/lib/WABinary/constants.d.ts +24 -21
  123. package/lib/WABinary/constants.js +1302 -31
  124. package/lib/WABinary/decode.d.ts +4 -1
  125. package/lib/WABinary/decode.js +267 -234
  126. package/lib/WABinary/encode.d.ts +1 -0
  127. package/lib/WABinary/encode.js +248 -226
  128. package/lib/WABinary/generic-utils.d.ts +13 -1
  129. package/lib/WABinary/generic-utils.js +113 -96
  130. package/lib/WABinary/index.js +13 -9
  131. package/lib/WABinary/jid-utils.d.ts +23 -4
  132. package/lib/WABinary/jid-utils.js +58 -39
  133. package/lib/WABinary/types.d.ts +15 -11
  134. package/lib/WABinary/types.js +1 -0
  135. package/lib/WAM/BinaryInfo.d.ts +14 -14
  136. package/lib/WAM/BinaryInfo.js +11 -8
  137. package/lib/WAM/constants.d.ts +34 -26
  138. package/lib/WAM/constants.js +15358 -15349
  139. package/lib/WAM/encode.d.ts +1 -0
  140. package/lib/WAM/encode.js +153 -144
  141. package/lib/WAM/index.js +13 -9
  142. package/lib/index.js +11 -11
  143. package/package.json +1 -2
  144. package/WASignalGroup/GroupProtocol.js +0 -1771
  145. package/WASignalGroup/ciphertext_message.js +0 -10
  146. package/WASignalGroup/group_cipher.js +0 -103
  147. package/WASignalGroup/group_session_builder.js +0 -39
  148. package/WASignalGroup/index.js +0 -5
  149. package/WASignalGroup/keyhelper.js +0 -17
  150. package/WASignalGroup/protobufs.js +0 -2
  151. package/WASignalGroup/queue_job.js +0 -64
  152. package/WASignalGroup/sender_chain_key.js +0 -38
  153. package/WASignalGroup/sender_key_distribution_message.js +0 -68
  154. package/WASignalGroup/sender_key_message.js +0 -79
  155. package/WASignalGroup/sender_key_name.js +0 -59
  156. package/WASignalGroup/sender_key_record.js +0 -47
  157. package/WASignalGroup/sender_key_state.js +0 -110
  158. package/WASignalGroup/sender_message_key.js +0 -30
@@ -1,243 +1,265 @@
1
1
  "use strict"
2
+
2
3
  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)
4
+ if (k2 === undefined) k2 = k
5
+ var desc = Object.getOwnPropertyDescriptor(m, k)
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k] } }
8
+ }
9
+ Object.defineProperty(o, k2, desc)
9
10
  }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k
11
- o[k2] = m[k]
11
+ if (k2 === undefined) k2 = k
12
+ o[k2] = m[k]
12
13
  }))
14
+
13
15
  var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v })
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v })
15
17
  }) : function(o, v) {
16
- o["default"] = v
18
+ o["default"] = v
17
19
  })
20
+
18
21
  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
22
+ if (mod && mod.__esModule) return mod
23
+ var result = {}
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
25
+ __setModuleDefault(result, mod)
26
+ return result
24
27
  }
28
+
25
29
  Object.defineProperty(exports, "__esModule", { value: true })
30
+
26
31
  const constants = __importStar(require("./constants"))
27
32
  const jid_utils_1 = require("./jid-utils")
33
+
28
34
  const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
29
- const encoded = encodeBinaryNodeInner(node, opts, buffer)
30
- return Buffer.from(encoded)
35
+ const encoded = encodeBinaryNodeInner(node, opts, buffer)
36
+ return Buffer.from(encoded)
31
37
  }
38
+
32
39
  const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
33
- const { TAGS, TOKEN_MAP } = opts
34
- const pushByte = (value) => buffer.push(value & 0xff)
35
- const pushInt = (value, n, littleEndian = false) => {
36
- for (let i = 0; i < n; i++) {
37
- const curShift = littleEndian ? i : n - 1 - i
38
- buffer.push((value >> (curShift * 8)) & 0xff)
39
- }
40
- }
41
- const pushBytes = (bytes) => {
42
- for (const b of bytes) {
43
- buffer.push(b)
44
- }
45
- }
46
- const pushInt16 = (value) => {
47
- pushBytes([(value >> 8) & 0xff, value & 0xff])
48
- }
49
- const pushInt20 = (value) => (pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]))
50
- const writeByteLength = (length) => {
51
- if (length >= 4294967296) {
52
- throw new Error('string too large to encode: ' + length)
53
- }
54
- if (length >= 1 << 20) {
55
- pushByte(TAGS.BINARY_32)
56
- pushInt(length, 4) // 32 bit integer
57
- }
58
- else if (length >= 256) {
59
- pushByte(TAGS.BINARY_20)
60
- pushInt20(length)
61
- }
62
- else {
63
- pushByte(TAGS.BINARY_8)
64
- pushByte(length)
65
- }
66
- }
67
- const writeStringRaw = (str) => {
68
- const bytes = Buffer.from(str, 'utf-8')
69
- writeByteLength(bytes.length)
70
- pushBytes(bytes)
71
- }
72
- const writeJid = ({ domainType, device, user, server }) => {
73
- if (typeof device !== 'undefined') {
74
- pushByte(TAGS.AD_JID)
75
- pushByte(domainType || 0)
76
- pushByte(device || 0)
77
- writeString(user)
78
- }
79
- else {
80
- pushByte(TAGS.JID_PAIR)
81
- if (user.length) {
82
- writeString(user)
83
- }
84
- else {
85
- pushByte(TAGS.LIST_EMPTY)
86
- }
87
- writeString(server)
88
- }
89
- }
90
- const packNibble = (char) => {
91
- switch (char) {
92
- case '-':
93
- return 10
94
- case '.':
95
- return 11
96
- case '\0':
97
- return 15
98
- default:
99
- if (char >= '0' && char <= '9') {
100
- return char.charCodeAt(0) - '0'.charCodeAt(0)
101
- }
102
- throw new Error(`invalid byte for nibble "${char}"`)
103
- }
104
- }
105
- const packHex = (char) => {
106
- if (char >= '0' && char <= '9') {
107
- return char.charCodeAt(0) - '0'.charCodeAt(0)
108
- }
109
- if (char >= 'A' && char <= 'F') {
110
- return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0)
111
- }
112
- if (char >= 'a' && char <= 'f') {
113
- return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0)
114
- }
115
- if (char === '\0') {
116
- return 15
117
- }
118
- throw new Error(`Invalid hex char "${char}"`)
119
- }
120
- const writePackedBytes = (str, type) => {
121
- if (str.length > TAGS.PACKED_MAX) {
122
- throw new Error('Too many bytes to pack')
123
- }
124
- pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8)
125
- let roundedLength = Math.ceil(str.length / 2.0)
126
- if (str.length % 2 !== 0) {
127
- roundedLength |= 128
128
- }
129
- pushByte(roundedLength)
130
- const packFunction = type === 'nibble' ? packNibble : packHex
131
- const packBytePair = (v1, v2) => {
132
- const result = (packFunction(v1) << 4) | packFunction(v2)
133
- return result
134
- }
135
- const strLengthHalf = Math.floor(str.length / 2)
136
- for (let i = 0; i < strLengthHalf; i++) {
137
- pushByte(packBytePair(str[2 * i], str[2 * i + 1]))
138
- }
139
- if (str.length % 2 !== 0) {
140
- pushByte(packBytePair(str[str.length - 1], '\x00'))
141
- }
142
- }
143
- const isNibble = (str) => {
144
- if (!str || str.length > TAGS.PACKED_MAX) {
145
- return false
146
- }
147
- for (const char of str) {
148
- const isInNibbleRange = char >= '0' && char <= '9'
149
- if (!isInNibbleRange && char !== '-' && char !== '.') {
150
- return false
151
- }
152
- }
153
- return true
154
- }
155
- const isHex = (str) => {
156
- if (!str || str.length > TAGS.PACKED_MAX) {
157
- return false
158
- }
159
- for (const char of str) {
160
- const isInNibbleRange = char >= '0' && char <= '9'
161
- if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
162
- return false
163
- }
164
- }
165
- return true
166
- }
167
- const writeString = (str) => {
168
- if (str === undefined || str === null) {
169
- pushByte(TAGS.LIST_EMPTY)
170
- return
171
- }
172
- const tokenIndex = TOKEN_MAP[str]
173
- if (tokenIndex) {
174
- if (typeof tokenIndex.dict === 'number') {
175
- pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict)
176
- }
177
- pushByte(tokenIndex.index)
178
- }
179
- else if (isNibble(str)) {
180
- writePackedBytes(str, 'nibble')
181
- }
182
- else if (isHex(str)) {
183
- writePackedBytes(str, 'hex')
184
- }
185
- else if (str) {
186
- const decodedJid = (0, jid_utils_1.jidDecode)(str)
187
- if (decodedJid) {
188
- writeJid(decodedJid)
189
- }
190
- else {
191
- writeStringRaw(str)
192
- }
193
- }
194
- }
195
- const writeListStart = (listSize) => {
196
- if (listSize === 0) {
197
- pushByte(TAGS.LIST_EMPTY)
198
- }
199
- else if (listSize < 256) {
200
- pushBytes([TAGS.LIST_8, listSize])
201
- }
202
- else {
203
- pushByte(TAGS.LIST_16)
204
- pushInt16(listSize)
205
- }
206
- }
207
- if (!tag) {
208
- throw new Error('Invalid node: tag cannot be undefined')
209
- }
210
- const validAttributes = Object.keys(attrs).filter(k => (typeof attrs[k] !== 'undefined' && attrs[k] !== null))
211
- writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0))
212
- writeString(tag)
213
- for (const key of validAttributes) {
214
- if (typeof attrs[key] === 'string') {
215
- writeString(key)
216
- writeString(attrs[key])
217
- }
218
- }
219
- if (typeof content === 'string') {
220
- writeString(content)
221
- }
222
- else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
223
- writeByteLength(content.length)
224
- pushBytes(content)
225
- }
226
- else if (Array.isArray(content)) {
227
- const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'))
228
- writeListStart(validContent.length)
229
- for (const item of validContent) {
230
- encodeBinaryNodeInner(item, opts, buffer)
231
- }
232
- }
233
- else if (typeof content === 'undefined') {
234
- // do nothing
235
- }
236
- else {
237
- throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`)
238
- }
239
- return buffer
240
- }
40
+ const { TAGS, TOKEN_MAP } = opts
41
+ const pushByte = (value) => buffer.push(value & 0xff)
42
+ const pushInt = (value, n, littleEndian = false) => {
43
+ for (let i = 0; i < n; i++) {
44
+ const curShift = littleEndian ? i : n - 1 - i
45
+ buffer.push((value >> (curShift * 8)) & 0xff)
46
+ }
47
+ }
48
+
49
+ const pushBytes = (bytes) => {
50
+ for (const b of bytes) {
51
+ buffer.push(b)
52
+ }
53
+ }
54
+
55
+ const pushInt16 = (value) => {
56
+ pushBytes([(value >> 8) & 0xff, value & 0xff])
57
+ }
58
+
59
+ const pushInt20 = (value) => (pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]))
60
+ const writeByteLength = (length) => {
61
+ if (length >= 4294967296) {
62
+ throw new Error('string too large to encode: ' + length)
63
+ }
64
+ if (length >= 1 << 20) {
65
+ pushByte(TAGS.BINARY_32)
66
+ pushInt(length, 4) // 32 bit integer
67
+ }
68
+ else if (length >= 256) {
69
+ pushByte(TAGS.BINARY_20)
70
+ pushInt20(length)
71
+ }
72
+ else {
73
+ pushByte(TAGS.BINARY_8)
74
+ pushByte(length)
75
+ }
76
+ }
77
+
78
+ const writeStringRaw = (str) => {
79
+ const bytes = Buffer.from(str, 'utf-8')
80
+ writeByteLength(bytes.length)
81
+ pushBytes(bytes)
82
+ }
83
+
84
+ const writeJid = ({ domainType, device, user, server }) => {
85
+ if (typeof device !== 'undefined') {
86
+ pushByte(TAGS.AD_JID)
87
+ pushByte(domainType || 0)
88
+ pushByte(device || 0)
89
+ writeString(user)
90
+ }
91
+ else {
92
+ pushByte(TAGS.JID_PAIR)
93
+ if (user.length) {
94
+ writeString(user)
95
+ }
96
+ else {
97
+ pushByte(TAGS.LIST_EMPTY)
98
+ }
99
+ writeString(server)
100
+ }
101
+ }
102
+
103
+ const packNibble = (char) => {
104
+ switch (char) {
105
+ case '-':
106
+ return 10
107
+ case '.':
108
+ return 11
109
+ case '\0':
110
+ return 15
111
+ default:
112
+ if (char >= '0' && char <= '9') {
113
+ return char.charCodeAt(0) - '0'.charCodeAt(0)
114
+ }
115
+ throw new Error(`invalid byte for nibble "${char}"`)
116
+ }
117
+ }
118
+
119
+ const packHex = (char) => {
120
+ if (char >= '0' && char <= '9') {
121
+ return char.charCodeAt(0) - '0'.charCodeAt(0)
122
+ }
123
+ if (char >= 'A' && char <= 'F') {
124
+ return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0)
125
+ }
126
+ if (char >= 'a' && char <= 'f') {
127
+ return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0)
128
+ }
129
+ if (char === '\0') {
130
+ return 15
131
+ }
132
+ throw new Error(`Invalid hex char "${char}"`)
133
+ }
134
+
135
+ const writePackedBytes = (str, type) => {
136
+ if (str.length > TAGS.PACKED_MAX) {
137
+ throw new Error('Too many bytes to pack')
138
+ }
139
+ pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8)
140
+ let roundedLength = Math.ceil(str.length / 2.0)
141
+ if (str.length % 2 !== 0) {
142
+ roundedLength |= 128
143
+ }
144
+ pushByte(roundedLength)
145
+ const packFunction = type === 'nibble' ? packNibble : packHex
146
+ const packBytePair = (v1, v2) => {
147
+ const result = (packFunction(v1) << 4) | packFunction(v2)
148
+ return result
149
+ }
150
+ const strLengthHalf = Math.floor(str.length / 2)
151
+ for (let i = 0; i < strLengthHalf; i++) {
152
+ pushByte(packBytePair(str[2 * i], str[2 * i + 1]))
153
+ }
154
+ if (str.length % 2 !== 0) {
155
+ pushByte(packBytePair(str[str.length - 1], '\x00'))
156
+ }
157
+ }
158
+
159
+ const isNibble = (str) => {
160
+ if (!str || str.length > TAGS.PACKED_MAX) {
161
+ return false
162
+ }
163
+ for (const char of str) {
164
+ const isInNibbleRange = char >= '0' && char <= '9'
165
+ if (!isInNibbleRange && char !== '-' && char !== '.') {
166
+ return false
167
+ }
168
+ }
169
+ return true
170
+ }
171
+
172
+ const isHex = (str) => {
173
+ if (!str || str.length > TAGS.PACKED_MAX) {
174
+ return false
175
+ }
176
+ for (const char of str) {
177
+ const isInNibbleRange = char >= '0' && char <= '9'
178
+ if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
179
+ return false
180
+ }
181
+ }
182
+ return true
183
+ }
184
+
185
+ const writeString = (str) => {
186
+ if (str === undefined || str === null) {
187
+ pushByte(TAGS.LIST_EMPTY)
188
+ return
189
+ }
190
+ const tokenIndex = TOKEN_MAP[str]
191
+ if (tokenIndex) {
192
+ if (typeof tokenIndex.dict === 'number') {
193
+ pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict)
194
+ }
195
+ pushByte(tokenIndex.index)
196
+ }
197
+ else if (isNibble(str)) {
198
+ writePackedBytes(str, 'nibble')
199
+ }
200
+ else if (isHex(str)) {
201
+ writePackedBytes(str, 'hex')
202
+ }
203
+ else if (str) {
204
+ const decodedJid = (0, jid_utils_1.jidDecode)(str)
205
+ if (decodedJid) {
206
+ writeJid(decodedJid)
207
+ }
208
+ else {
209
+ writeStringRaw(str)
210
+ }
211
+ }
212
+ }
213
+
214
+ const writeListStart = (listSize) => {
215
+ if (listSize === 0) {
216
+ pushByte(TAGS.LIST_EMPTY)
217
+ }
218
+ else if (listSize < 256) {
219
+ pushBytes([TAGS.LIST_8, listSize])
220
+ }
221
+ else {
222
+ pushByte(TAGS.LIST_16)
223
+ pushInt16(listSize)
224
+ }
225
+ }
226
+
227
+ if (!tag) {
228
+ throw new Error('Invalid node: tag cannot be undefined')
229
+ }
230
+
231
+ const validAttributes = Object.keys(attrs).filter(k => (typeof attrs[k] !== 'undefined' && attrs[k] !== null))
232
+ writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0))
233
+ writeString(tag)
234
+ for (const key of validAttributes) {
235
+ if (typeof attrs[key] === 'string') {
236
+ writeString(key)
237
+ writeString(attrs[key])
238
+ }
239
+ }
240
+ if (typeof content === 'string') {
241
+ writeString(content)
242
+ }
243
+ else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
244
+ writeByteLength(content.length)
245
+ pushBytes(content)
246
+ }
247
+ else if (Array.isArray(content)) {
248
+ const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'))
249
+ writeListStart(validContent.length)
250
+ for (const item of validContent) {
251
+ encodeBinaryNodeInner(item, opts, buffer)
252
+ }
253
+ }
254
+ else if (typeof content === 'undefined') {
255
+ // do nothing
256
+ }
257
+ else {
258
+ throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`)
259
+ }
260
+ return buffer
261
+ }
262
+
241
263
  module.exports = {
242
- encodeBinaryNode
264
+ encodeBinaryNode
243
265
  }
@@ -1,16 +1,28 @@
1
1
  import { proto } from '../../WAProto'
2
2
  import { BinaryNode } from './types'
3
+
3
4
  export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[]
5
+
4
6
  export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[]
7
+
5
8
  export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined
9
+
6
10
  export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array | Buffer | undefined
11
+
7
12
  export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined
13
+
8
14
  export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined
15
+
9
16
  export declare const assertNodeErrorFree: (node: BinaryNode) => void
17
+
10
18
  export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: string) => {
11
- [_: string]: string
19
+ [_: string]: string
12
20
  }
21
+
13
22
  export declare const getBinaryNodeMessages: ({ content }: BinaryNode) => proto.WebMessageInfo[]
23
+
14
24
  export declare const getBinaryFilteredButtons: (nodeContent: BinaryNode | BinaryNode['content']) => BinaryNode['content']
25
+
15
26
  export declare const getBinaryFilteredBizBot: (nodeContent: BinaryNode | BinaryNode['content']) => BinaryNode['content']
27
+
16
28
  export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'], i?: number): any