@skycodee/baileys 8.0.4 → 8.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 (224) hide show
  1. package/LICENSE +1 -1
  2. package/WAProto/WAProto.proto +352 -520
  3. package/WAProto/index.js +558 -4154
  4. package/lib/Defaults/index.js +123 -0
  5. package/lib/Defaults/index.js.bak +123 -0
  6. package/lib/KeyDB/BinarySearch.js +20 -0
  7. package/lib/KeyDB/KeyedDB.js +167 -0
  8. package/lib/KeyDB/index.js +4 -0
  9. package/lib/Signal/Group/ciphertext-message.js +13 -0
  10. package/lib/Signal/Group/group-session-builder.js +32 -0
  11. package/lib/Signal/Group/group_cipher.js +84 -0
  12. package/lib/Signal/Group/index.js +13 -0
  13. package/lib/Signal/Group/keyhelper.js +20 -0
  14. package/lib/Signal/Group/sender-chain-key.js +28 -0
  15. package/lib/Signal/Group/sender-key-distribution-message.js +65 -0
  16. package/lib/Signal/Group/sender-key-message.js +68 -0
  17. package/lib/Signal/Group/sender-key-name.js +52 -0
  18. package/lib/Signal/Group/sender-key-record.js +43 -0
  19. package/lib/Signal/Group/sender-key-state.js +86 -0
  20. package/lib/Signal/Group/sender-message-key.js +28 -0
  21. package/lib/Signal/libsignal.js +324 -0
  22. package/lib/Signal/lid-mapping.js +155 -0
  23. package/lib/Socket/Client/index.js +4 -0
  24. package/lib/Socket/Client/types.js +13 -0
  25. package/lib/Socket/Client/websocket.js +52 -0
  26. package/lib/Socket/Client/websocket.js.bak +53 -0
  27. package/lib/Socket/business.js +377 -0
  28. package/lib/Socket/chats.js +885 -0
  29. package/lib/Socket/communities.js +413 -0
  30. package/lib/Socket/groups.js +312 -0
  31. package/lib/Socket/index.js +16 -0
  32. package/lib/Socket/messages-recv.js +1163 -0
  33. package/lib/Socket/messages-send.js +1100 -0
  34. package/lib/Socket/mex.js +45 -0
  35. package/lib/Socket/newsletter.js +247 -0
  36. package/lib/Socket/socket.js +820 -0
  37. package/lib/Store/index.js +6 -0
  38. package/lib/Store/make-cache-manager-store.js +75 -0
  39. package/lib/Store/make-in-memory-store.js +290 -0
  40. package/lib/Store/make-ordered-dictionary.js +79 -0
  41. package/lib/Store/object-repository.js +25 -0
  42. package/lib/Types/Auth.js +3 -0
  43. package/lib/Types/Bussines.js +3 -0
  44. package/lib/Types/Call.js +3 -0
  45. package/lib/Types/Chat.js +9 -0
  46. package/lib/Types/Contact.js +3 -0
  47. package/lib/Types/Events.js +3 -0
  48. package/lib/Types/GroupMetadata.js +3 -0
  49. package/lib/Types/Label.js +25 -0
  50. package/lib/Types/LabelAssociation.js +7 -0
  51. package/lib/Types/Message.js +12 -0
  52. package/lib/Types/Newsletter.js +33 -0
  53. package/lib/Types/Newsletter.js.bak +33 -0
  54. package/lib/Types/Product.js +3 -0
  55. package/lib/Types/Signal.js +3 -0
  56. package/lib/Types/Socket.js +4 -0
  57. package/lib/Types/State.js +11 -0
  58. package/lib/Types/USync.js +3 -0
  59. package/lib/Types/index.js +28 -0
  60. package/lib/Utils/auth-utils.js +219 -0
  61. package/lib/Utils/baileys-event-stream.js +44 -0
  62. package/lib/Utils/browser-utils.js +25 -0
  63. package/lib/Utils/business.js +233 -0
  64. package/lib/Utils/chat-utils.js +752 -0
  65. package/lib/Utils/crypto.js +130 -0
  66. package/lib/Utils/decode-wa-message.js +267 -0
  67. package/lib/Utils/event-buffer.js +528 -0
  68. package/lib/Utils/generics.js +355 -0
  69. package/lib/Utils/history.js +87 -0
  70. package/lib/Utils/index.js +21 -0
  71. package/lib/Utils/link-preview.js +81 -0
  72. package/lib/Utils/logger.js +5 -0
  73. package/lib/Utils/lt-hash.js +45 -0
  74. package/lib/Utils/make-mutex.js +36 -0
  75. package/lib/Utils/message-retry-manager.js +113 -0
  76. package/lib/Utils/messages-media.js +627 -0
  77. package/lib/Utils/messages.js +909 -0
  78. package/lib/Utils/noise-handler.js +144 -0
  79. package/lib/Utils/pre-key-manager.js +85 -0
  80. package/lib/Utils/process-message.js +341 -0
  81. package/lib/Utils/signal.js +161 -0
  82. package/lib/Utils/use-multi-file-auth-state.js +111 -0
  83. package/lib/Utils/validate-connection.js +200 -0
  84. package/lib/WABinary/constants.js +1303 -0
  85. package/lib/WABinary/decode.js +240 -0
  86. package/lib/WABinary/encode.js +218 -0
  87. package/lib/WABinary/generic-utils.js +189 -0
  88. package/lib/WABinary/index.js +7 -0
  89. package/lib/WABinary/jid-utils.js +93 -0
  90. package/lib/WABinary/types.js +3 -0
  91. package/lib/WAM/BinaryInfo.js +11 -0
  92. package/lib/WAM/constants.js +22853 -0
  93. package/lib/WAM/encode.js +154 -0
  94. package/lib/WAM/index.js +5 -0
  95. package/lib/WAUSync/Protocols/USyncContactProtocol.js +30 -0
  96. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  97. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +29 -0
  98. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
  99. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  100. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +30 -0
  101. package/lib/WAUSync/Protocols/index.js +6 -0
  102. package/lib/WAUSync/USyncQuery.js +90 -0
  103. package/lib/WAUSync/USyncUser.js +24 -0
  104. package/lib/WAUSync/index.js +5 -0
  105. package/lib/index.js +21 -0
  106. package/package.json +84 -57
  107. package/README.md +0 -1312
  108. package/WAProto/GenerateStatics.sh +0 -3
  109. package/WAProto/fix-imports.js +0 -81
  110. package/WAProto/index.d.ts +0 -14017
  111. package/engine-requirements.js +0 -10
  112. package/src/Defaults/baileys-version.json +0 -1
  113. package/src/Defaults/index.ts +0 -149
  114. package/src/Signal/Group/ciphertext-message.ts +0 -9
  115. package/src/Signal/Group/group-session-builder.ts +0 -56
  116. package/src/Signal/Group/group_cipher.ts +0 -117
  117. package/src/Signal/Group/index.ts +0 -11
  118. package/src/Signal/Group/keyhelper.ts +0 -28
  119. package/src/Signal/Group/sender-chain-key.ts +0 -34
  120. package/src/Signal/Group/sender-key-distribution-message.ts +0 -95
  121. package/src/Signal/Group/sender-key-message.ts +0 -96
  122. package/src/Signal/Group/sender-key-name.ts +0 -66
  123. package/src/Signal/Group/sender-key-record.ts +0 -69
  124. package/src/Signal/Group/sender-key-state.ts +0 -134
  125. package/src/Signal/Group/sender-message-key.ts +0 -36
  126. package/src/Signal/libsignal.ts +0 -521
  127. package/src/Signal/lid-mapping.ts +0 -328
  128. package/src/Socket/Client/index.ts +0 -2
  129. package/src/Socket/Client/types.ts +0 -22
  130. package/src/Socket/Client/websocket.ts +0 -63
  131. package/src/Socket/business.ts +0 -424
  132. package/src/Socket/chats.ts +0 -1272
  133. package/src/Socket/communities.ts +0 -477
  134. package/src/Socket/groups.ts +0 -361
  135. package/src/Socket/index.ts +0 -15
  136. package/src/Socket/messages-recv.ts +0 -1668
  137. package/src/Socket/messages-send.ts +0 -1296
  138. package/src/Socket/mex.ts +0 -58
  139. package/src/Socket/newsletter.ts +0 -229
  140. package/src/Socket/socket.ts +0 -1184
  141. package/src/Types/Auth.ts +0 -116
  142. package/src/Types/Bussines.ts +0 -20
  143. package/src/Types/Call.ts +0 -15
  144. package/src/Types/Chat.ts +0 -138
  145. package/src/Types/Contact.ts +0 -24
  146. package/src/Types/Events.ts +0 -159
  147. package/src/Types/GroupMetadata.ts +0 -70
  148. package/src/Types/Label.ts +0 -48
  149. package/src/Types/LabelAssociation.ts +0 -35
  150. package/src/Types/Message.ts +0 -380
  151. package/src/Types/Newsletter.ts +0 -98
  152. package/src/Types/Product.ts +0 -85
  153. package/src/Types/Signal.ts +0 -76
  154. package/src/Types/Socket.ts +0 -150
  155. package/src/Types/State.ts +0 -43
  156. package/src/Types/USync.ts +0 -27
  157. package/src/Types/globals.d.ts +0 -8
  158. package/src/Types/index.ts +0 -67
  159. package/src/Utils/auth-utils.ts +0 -368
  160. package/src/Utils/browser-utils.ts +0 -31
  161. package/src/Utils/business.ts +0 -286
  162. package/src/Utils/chat-utils.ts +0 -974
  163. package/src/Utils/crypto.ts +0 -147
  164. package/src/Utils/decode-wa-message.ts +0 -355
  165. package/src/Utils/event-buffer.ts +0 -692
  166. package/src/Utils/generics.ts +0 -474
  167. package/src/Utils/history.ts +0 -161
  168. package/src/Utils/identity-change-handler.ts +0 -83
  169. package/src/Utils/index.ts +0 -19
  170. package/src/Utils/link-preview.ts +0 -111
  171. package/src/Utils/logger.ts +0 -13
  172. package/src/Utils/lt-hash.ts +0 -8
  173. package/src/Utils/make-mutex.ts +0 -42
  174. package/src/Utils/message-retry-manager.ts +0 -295
  175. package/src/Utils/messages-media.ts +0 -984
  176. package/src/Utils/messages.ts +0 -1097
  177. package/src/Utils/noise-handler.ts +0 -268
  178. package/src/Utils/pre-key-manager.ts +0 -126
  179. package/src/Utils/process-message.ts +0 -670
  180. package/src/Utils/reporting-utils.ts +0 -344
  181. package/src/Utils/signal.ts +0 -214
  182. package/src/Utils/sync-action-utils.ts +0 -74
  183. package/src/Utils/tc-token-utils.ts +0 -34
  184. package/src/Utils/use-multi-file-auth-state.ts +0 -136
  185. package/src/Utils/validate-connection.ts +0 -253
  186. package/src/WABinary/constants.ts +0 -1305
  187. package/src/WABinary/decode.ts +0 -308
  188. package/src/WABinary/encode.ts +0 -258
  189. package/src/WABinary/generic-utils.ts +0 -141
  190. package/src/WABinary/index.ts +0 -5
  191. package/src/WABinary/jid-utils.ts +0 -128
  192. package/src/WABinary/types.ts +0 -17
  193. package/src/WAM/BinaryInfo.ts +0 -12
  194. package/src/WAM/constants.ts +0 -22889
  195. package/src/WAM/encode.ts +0 -169
  196. package/src/WAM/index.ts +0 -3
  197. package/src/WAUSync/Protocols/USyncContactProtocol.ts +0 -32
  198. package/src/WAUSync/Protocols/USyncDeviceProtocol.ts +0 -78
  199. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.ts +0 -35
  200. package/src/WAUSync/Protocols/USyncStatusProtocol.ts +0 -44
  201. package/src/WAUSync/Protocols/UsyncBotProfileProtocol.ts +0 -76
  202. package/src/WAUSync/Protocols/UsyncLIDProtocol.ts +0 -33
  203. package/src/WAUSync/Protocols/index.ts +0 -4
  204. package/src/WAUSync/USyncQuery.ts +0 -133
  205. package/src/WAUSync/USyncUser.ts +0 -32
  206. package/src/WAUSync/index.ts +0 -3
  207. package/src/__tests__/Signal/Group/sender-key-state-regression.test.ts +0 -22
  208. package/src/__tests__/Signal/lid-mapping.test.ts +0 -47
  209. package/src/__tests__/Socket/identity-change-handling.test.ts +0 -207
  210. package/src/__tests__/TestUtils/session.ts +0 -47
  211. package/src/__tests__/Utils/generics.test.ts +0 -70
  212. package/src/__tests__/Utils/history.test.ts +0 -362
  213. package/src/__tests__/Utils/messages-media.test.ts +0 -405
  214. package/src/__tests__/Utils/noise-handler.test.ts +0 -339
  215. package/src/__tests__/Utils/process-message.test.ts +0 -138
  216. package/src/__tests__/Utils/process-sync-action.test.ts +0 -359
  217. package/src/__tests__/Utils/reporting-utils.test.ts +0 -160
  218. package/src/__tests__/Utils/signal.test.ts +0 -69
  219. package/src/__tests__/Utils/sync-action-utils.test.ts +0 -183
  220. package/src/__tests__/binary/connection-deadlock.test.ts +0 -54
  221. package/src/__tests__/e2e/fetch-wa-web-version.test-e2e.ts +0 -60
  222. package/src/__tests__/e2e/send-receive-message.test-e2e.ts +0 -644
  223. package/src/__tests__/proto-tojson-long.test.ts +0 -31
  224. package/src/index.ts +0 -13
package/src/WAM/encode.ts DELETED
@@ -1,169 +0,0 @@
1
- import { BinaryInfo } from './BinaryInfo'
2
- import {
3
- FLAG_BYTE,
4
- FLAG_EVENT,
5
- FLAG_EXTENDED,
6
- FLAG_FIELD,
7
- FLAG_GLOBAL,
8
- type Value,
9
- WEB_EVENTS,
10
- WEB_GLOBALS
11
- } from './constants'
12
-
13
- const getHeaderBitLength = (key: number) => (key < 256 ? 2 : 3)
14
-
15
- export const encodeWAM = (binaryInfo: BinaryInfo) => {
16
- binaryInfo.buffer = []
17
-
18
- encodeWAMHeader(binaryInfo)
19
- encodeEvents(binaryInfo)
20
-
21
- const totalSize = binaryInfo.buffer.map(a => a.length).reduce((a, b) => a + b)
22
- const buffer = Buffer.alloc(totalSize)
23
- let offset = 0
24
- for (const buffer_ of binaryInfo.buffer) {
25
- buffer_.copy(buffer, offset)
26
- offset += buffer_.length
27
- }
28
-
29
- return buffer
30
- }
31
-
32
- function encodeWAMHeader(binaryInfo: BinaryInfo) {
33
- const headerBuffer = Buffer.alloc(8) // starting buffer
34
- headerBuffer.write('WAM', 0, 'utf8')
35
- headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3)
36
- headerBuffer.writeUInt8(1, 4) //random flag
37
- headerBuffer.writeUInt16BE(binaryInfo.sequence, 5)
38
- headerBuffer.writeUInt8(0, 7) // regular channel
39
-
40
- binaryInfo.buffer.push(headerBuffer)
41
- }
42
-
43
- function encodeGlobalAttributes(binaryInfo: BinaryInfo, globals: { [key: string]: Value }) {
44
- for (const [key, _value] of Object.entries(globals)) {
45
- const id = WEB_GLOBALS.find(a => a?.name === key)!.id
46
- let value = _value
47
- if (typeof value === 'boolean') {
48
- value = value ? 1 : 0
49
- }
50
-
51
- binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL))
52
- }
53
- }
54
-
55
- function encodeEvents(binaryInfo: BinaryInfo) {
56
- for (const [name, { props, globals }] of binaryInfo.events.map(a => Object.entries(a)[0]!)) {
57
- encodeGlobalAttributes(binaryInfo, globals)
58
- const event = WEB_EVENTS.find(a => a.name === name)!
59
-
60
- const props_ = Object.entries(props)
61
-
62
- let extended = false
63
-
64
- for (const [, value] of props_) {
65
- extended ||= value !== null
66
- }
67
-
68
- const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED
69
- binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag))
70
-
71
- for (let i = 0; i < props_.length; i++) {
72
- const [key, _value] = props_[i]!
73
- const id = event.props[key]?.[0]
74
- extended = i < props_.length - 1
75
- let value = _value
76
- if (typeof value === 'boolean') {
77
- value = value ? 1 : 0
78
- }
79
-
80
- const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED
81
- binaryInfo.buffer.push(serializeData(id!, value, fieldFlag))
82
- }
83
- }
84
- }
85
-
86
- function serializeData(key: number, value: Value, flag: number): Buffer {
87
- const bufferLength = getHeaderBitLength(key)
88
- let buffer: Buffer
89
- let offset = 0
90
- if (value === null) {
91
- if (flag === FLAG_GLOBAL) {
92
- buffer = Buffer.alloc(bufferLength)
93
- offset = serializeHeader(buffer, offset, key, flag)
94
- return buffer
95
- }
96
- } else if (typeof value === 'number' && Number.isInteger(value)) {
97
- // is number
98
- if (value === 0 || value === 1) {
99
- buffer = Buffer.alloc(bufferLength)
100
- offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4))
101
- return buffer
102
- } else if (-128 <= value && value < 128) {
103
- buffer = Buffer.alloc(bufferLength + 1)
104
- offset = serializeHeader(buffer, offset, key, flag | (3 << 4))
105
- buffer.writeInt8(value, offset)
106
- return buffer
107
- } else if (-32768 <= value && value < 32768) {
108
- buffer = Buffer.alloc(bufferLength + 2)
109
- offset = serializeHeader(buffer, offset, key, flag | (4 << 4))
110
- buffer.writeInt16LE(value, offset)
111
- return buffer
112
- } else if (-2147483648 <= value && value < 2147483648) {
113
- buffer = Buffer.alloc(bufferLength + 4)
114
- offset = serializeHeader(buffer, offset, key, flag | (5 << 4))
115
- buffer.writeInt32LE(value, offset)
116
- return buffer
117
- } else {
118
- buffer = Buffer.alloc(bufferLength + 8)
119
- offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
120
- buffer.writeDoubleLE(value, offset)
121
- return buffer
122
- }
123
- } else if (typeof value === 'number') {
124
- // is float
125
- buffer = Buffer.alloc(bufferLength + 8)
126
- offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
127
- buffer.writeDoubleLE(value, offset)
128
- return buffer
129
- } else if (typeof value === 'string') {
130
- // is string
131
- const utf8Bytes = Buffer.byteLength(value, 'utf8')
132
- if (utf8Bytes < 256) {
133
- buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes)
134
- offset = serializeHeader(buffer, offset, key, flag | (8 << 4))
135
- buffer.writeUint8(utf8Bytes, offset++)
136
- } else if (utf8Bytes < 65536) {
137
- buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes)
138
- offset = serializeHeader(buffer, offset, key, flag | (9 << 4))
139
- buffer.writeUInt16LE(utf8Bytes, offset)
140
- offset += 2
141
- } else {
142
- buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes)
143
- offset = serializeHeader(buffer, offset, key, flag | (10 << 4))
144
- buffer.writeUInt32LE(utf8Bytes, offset)
145
- offset += 4
146
- }
147
-
148
- buffer.write(value, offset, 'utf8')
149
- return buffer
150
- }
151
-
152
- throw 'missing'
153
- }
154
-
155
- function serializeHeader(buffer: Buffer, offset: number, key: number, flag: number) {
156
- if (key < 256) {
157
- buffer.writeUInt8(flag, offset)
158
- offset += 1
159
- buffer.writeUInt8(key, offset)
160
- offset += 1
161
- } else {
162
- buffer.writeUInt8(flag | FLAG_BYTE, offset)
163
- offset += 1
164
- buffer.writeUInt16LE(key, offset)
165
- offset += 2
166
- }
167
-
168
- return offset
169
- }
package/src/WAM/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './constants'
2
- export * from './encode'
3
- export * from './BinaryInfo'
@@ -1,32 +0,0 @@
1
- import type { USyncQueryProtocol } from '../../Types/USync'
2
- import { assertNodeErrorFree, type BinaryNode } from '../../WABinary'
3
- import { USyncUser } from '../USyncUser'
4
-
5
- export class USyncContactProtocol implements USyncQueryProtocol {
6
- name = 'contact'
7
-
8
- getQueryElement(): BinaryNode {
9
- return {
10
- tag: 'contact',
11
- attrs: {}
12
- }
13
- }
14
-
15
- getUserElement(user: USyncUser): BinaryNode {
16
- //TODO: Implement type / username fields (not yet supported)
17
- return {
18
- tag: 'contact',
19
- attrs: {},
20
- content: user.phone
21
- }
22
- }
23
-
24
- parser(node: BinaryNode): boolean {
25
- if (node.tag === 'contact') {
26
- assertNodeErrorFree(node)
27
- return node?.attrs?.type === 'in'
28
- }
29
-
30
- return false
31
- }
32
- }
@@ -1,78 +0,0 @@
1
- import type { USyncQueryProtocol } from '../../Types/USync'
2
- import { assertNodeErrorFree, type BinaryNode, getBinaryNodeChild } from '../../WABinary'
3
- //import { USyncUser } from '../USyncUser'
4
-
5
- export type KeyIndexData = {
6
- timestamp: number
7
- signedKeyIndex?: Uint8Array
8
- expectedTimestamp?: number
9
- }
10
-
11
- export type DeviceListData = {
12
- id: number
13
- keyIndex?: number
14
- isHosted?: boolean
15
- }
16
-
17
- export type ParsedDeviceInfo = {
18
- deviceList?: DeviceListData[]
19
- keyIndex?: KeyIndexData
20
- }
21
-
22
- export class USyncDeviceProtocol implements USyncQueryProtocol {
23
- name = 'devices'
24
-
25
- getQueryElement(): BinaryNode {
26
- return {
27
- tag: 'devices',
28
- attrs: {
29
- version: '2'
30
- }
31
- }
32
- }
33
-
34
- getUserElement(/* user: USyncUser */): BinaryNode | null {
35
- //TODO: Implement device phashing, ts and expectedTs
36
- //TODO: if all are not present, return null <- current behavior
37
- //TODO: otherwise return a node w tag 'devices' w those as attrs
38
- return null
39
- }
40
-
41
- parser(node: BinaryNode): ParsedDeviceInfo {
42
- const deviceList: DeviceListData[] = []
43
- let keyIndex: KeyIndexData | undefined = undefined
44
-
45
- if (node.tag === 'devices') {
46
- assertNodeErrorFree(node)
47
- const deviceListNode = getBinaryNodeChild(node, 'device-list')
48
- const keyIndexNode = getBinaryNodeChild(node, 'key-index-list')
49
-
50
- if (Array.isArray(deviceListNode?.content)) {
51
- for (const { tag, attrs } of deviceListNode.content) {
52
- const id = +attrs.id!
53
- const keyIndex = +attrs['key-index']!
54
- if (tag === 'device') {
55
- deviceList.push({
56
- id,
57
- keyIndex,
58
- isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
59
- })
60
- }
61
- }
62
- }
63
-
64
- if (keyIndexNode?.tag === 'key-index-list') {
65
- keyIndex = {
66
- timestamp: +keyIndexNode.attrs['ts']!,
67
- signedKeyIndex: keyIndexNode?.content as Uint8Array,
68
- expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
69
- }
70
- }
71
- }
72
-
73
- return {
74
- deviceList,
75
- keyIndex
76
- }
77
- }
78
- }
@@ -1,35 +0,0 @@
1
- import type { USyncQueryProtocol } from '../../Types/USync'
2
- import { assertNodeErrorFree, type BinaryNode } from '../../WABinary'
3
-
4
- export type DisappearingModeData = {
5
- duration: number
6
- setAt?: Date
7
- }
8
-
9
- export class USyncDisappearingModeProtocol implements USyncQueryProtocol {
10
- name = 'disappearing_mode'
11
-
12
- getQueryElement(): BinaryNode {
13
- return {
14
- tag: 'disappearing_mode',
15
- attrs: {}
16
- }
17
- }
18
-
19
- getUserElement(): null {
20
- return null
21
- }
22
-
23
- parser(node: BinaryNode): DisappearingModeData | undefined {
24
- if (node.tag === 'disappearing_mode') {
25
- assertNodeErrorFree(node)
26
- const duration: number = +node?.attrs.duration!
27
- const setAt = new Date(+(node?.attrs.t || 0) * 1000)
28
-
29
- return {
30
- duration,
31
- setAt
32
- }
33
- }
34
- }
35
- }
@@ -1,44 +0,0 @@
1
- import type { USyncQueryProtocol } from '../../Types/USync'
2
- import { assertNodeErrorFree, type BinaryNode } from '../../WABinary'
3
-
4
- export type StatusData = {
5
- status?: string | null
6
- setAt?: Date
7
- }
8
-
9
- export class USyncStatusProtocol implements USyncQueryProtocol {
10
- name = 'status'
11
-
12
- getQueryElement(): BinaryNode {
13
- return {
14
- tag: 'status',
15
- attrs: {}
16
- }
17
- }
18
-
19
- getUserElement(): null {
20
- return null
21
- }
22
-
23
- parser(node: BinaryNode): StatusData | undefined {
24
- if (node.tag === 'status') {
25
- assertNodeErrorFree(node)
26
- let status: string | null = node?.content?.toString() ?? null
27
- const setAt = new Date(+(node?.attrs.t || 0) * 1000)
28
- if (!status) {
29
- if (node.attrs?.code && +node.attrs.code === 401) {
30
- status = ''
31
- } else {
32
- status = null
33
- }
34
- } else if (typeof status === 'string' && status.length === 0) {
35
- status = null
36
- }
37
-
38
- return {
39
- status,
40
- setAt
41
- }
42
- }
43
- }
44
- }
@@ -1,76 +0,0 @@
1
- import type { USyncQueryProtocol } from '../../Types/USync'
2
- import { type BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString } from '../../WABinary'
3
- import { USyncUser } from '../USyncUser'
4
-
5
- export type BotProfileCommand = {
6
- name: string
7
- description: string
8
- }
9
-
10
- export type BotProfileInfo = {
11
- jid: string
12
- name: string
13
- attributes: string
14
- description: string
15
- category: string
16
- isDefault: boolean
17
- prompts: string[]
18
- personaId: string
19
- commands: BotProfileCommand[]
20
- commandsDescription: string
21
- }
22
-
23
- export class USyncBotProfileProtocol implements USyncQueryProtocol {
24
- name = 'bot'
25
-
26
- getQueryElement(): BinaryNode {
27
- return {
28
- tag: 'bot',
29
- attrs: {},
30
- content: [{ tag: 'profile', attrs: { v: '1' } }]
31
- }
32
- }
33
-
34
- getUserElement(user: USyncUser): BinaryNode {
35
- return {
36
- tag: 'bot',
37
- attrs: {},
38
- content: [{ tag: 'profile', attrs: { persona_id: user.personaId! } }]
39
- }
40
- }
41
-
42
- parser(node: BinaryNode): BotProfileInfo {
43
- const botNode = getBinaryNodeChild(node, 'bot')
44
- const profile = getBinaryNodeChild(botNode, 'profile')
45
-
46
- const commandsNode = getBinaryNodeChild(profile, 'commands')
47
- const promptsNode = getBinaryNodeChild(profile, 'prompts')
48
-
49
- const commands: BotProfileCommand[] = []
50
- const prompts: string[] = []
51
-
52
- for (const command of getBinaryNodeChildren(commandsNode, 'command')) {
53
- commands.push({
54
- name: getBinaryNodeChildString(command, 'name')!,
55
- description: getBinaryNodeChildString(command, 'description')!
56
- })
57
- }
58
-
59
- for (const prompt of getBinaryNodeChildren(promptsNode, 'prompt')) {
60
- prompts.push(`${getBinaryNodeChildString(prompt, 'emoji')!} ${getBinaryNodeChildString(prompt, 'text')!}`)
61
- }
62
-
63
- return {
64
- isDefault: !!getBinaryNodeChild(profile, 'default'),
65
- jid: node.attrs.jid!,
66
- name: getBinaryNodeChildString(profile, 'name')!,
67
- attributes: getBinaryNodeChildString(profile, 'attributes')!,
68
- description: getBinaryNodeChildString(profile, 'description')!,
69
- category: getBinaryNodeChildString(profile, 'category')!,
70
- personaId: profile!.attrs['persona_id']!,
71
- commandsDescription: getBinaryNodeChildString(commandsNode, 'description')!,
72
- commands,
73
- prompts
74
- }
75
- }
76
- }
@@ -1,33 +0,0 @@
1
- import type { USyncQueryProtocol } from '../../Types/USync'
2
- import type { BinaryNode } from '../../WABinary'
3
- import type { USyncUser } from '../USyncUser'
4
-
5
- export class USyncLIDProtocol implements USyncQueryProtocol {
6
- name = 'lid'
7
-
8
- getQueryElement(): BinaryNode {
9
- return {
10
- tag: 'lid',
11
- attrs: {}
12
- }
13
- }
14
-
15
- getUserElement(user: USyncUser): BinaryNode | null {
16
- if (user.lid) {
17
- return {
18
- tag: 'lid',
19
- attrs: { jid: user.lid }
20
- }
21
- } else {
22
- return null
23
- }
24
- }
25
-
26
- parser(node: BinaryNode): string | null {
27
- if (node.tag === 'lid') {
28
- return node.attrs.val!
29
- }
30
-
31
- return null
32
- }
33
- }
@@ -1,4 +0,0 @@
1
- export * from './USyncDeviceProtocol'
2
- export * from './USyncContactProtocol'
3
- export * from './USyncStatusProtocol'
4
- export * from './USyncDisappearingModeProtocol'
@@ -1,133 +0,0 @@
1
- import type { USyncQueryProtocol } from '../Types/USync'
2
- import { type BinaryNode, getBinaryNodeChild } from '../WABinary'
3
- import { USyncBotProfileProtocol } from './Protocols/UsyncBotProfileProtocol'
4
- import { USyncLIDProtocol } from './Protocols/UsyncLIDProtocol'
5
- import {
6
- USyncContactProtocol,
7
- USyncDeviceProtocol,
8
- USyncDisappearingModeProtocol,
9
- USyncStatusProtocol
10
- } from './Protocols'
11
- import { USyncUser } from './USyncUser'
12
-
13
- export type USyncQueryResultList = { [protocol: string]: unknown; id: string }
14
-
15
- export type USyncQueryResult = {
16
- list: USyncQueryResultList[]
17
- sideList: USyncQueryResultList[]
18
- }
19
-
20
- export class USyncQuery {
21
- protocols: USyncQueryProtocol[]
22
- users: USyncUser[]
23
- context: string
24
- mode: string
25
-
26
- constructor() {
27
- this.protocols = []
28
- this.users = []
29
- this.context = 'interactive'
30
- this.mode = 'query'
31
- }
32
-
33
- withMode(mode: string) {
34
- this.mode = mode
35
- return this
36
- }
37
-
38
- withContext(context: string) {
39
- this.context = context
40
- return this
41
- }
42
-
43
- withUser(user: USyncUser) {
44
- this.users.push(user)
45
- return this
46
- }
47
-
48
- parseUSyncQueryResult(result: BinaryNode | undefined): USyncQueryResult | undefined {
49
- if (!result || result.attrs.type !== 'result') {
50
- return
51
- }
52
-
53
- const protocolMap = Object.fromEntries(
54
- this.protocols.map(protocol => {
55
- return [protocol.name, protocol.parser]
56
- })
57
- )
58
-
59
- const queryResult: USyncQueryResult = {
60
- // TODO: implement errors etc.
61
- list: [],
62
- sideList: []
63
- }
64
-
65
- const usyncNode = getBinaryNodeChild(result, 'usync')
66
-
67
- //TODO: implement error backoff, refresh etc.
68
- //TODO: see if there are any errors in the result node
69
- //const resultNode = getBinaryNodeChild(usyncNode, 'result')
70
-
71
- const listNode = usyncNode ? getBinaryNodeChild(usyncNode, 'list') : undefined
72
-
73
- if (listNode?.content && Array.isArray(listNode.content)) {
74
- queryResult.list = listNode.content.reduce((acc: USyncQueryResultList[], node) => {
75
- const id = node?.attrs.jid
76
- if (id) {
77
- const data = Array.isArray(node?.content)
78
- ? Object.fromEntries(
79
- node.content
80
- .map(content => {
81
- const protocol = content.tag
82
- const parser = protocolMap[protocol]
83
- if (parser) {
84
- return [protocol, parser(content)]
85
- } else {
86
- return [protocol, null]
87
- }
88
- })
89
- .filter(([, b]) => b !== null) as [string, unknown][]
90
- )
91
- : {}
92
- acc.push({ ...data, id })
93
- }
94
-
95
- return acc
96
- }, [])
97
- }
98
-
99
- //TODO: implement side list
100
- //const sideListNode = getBinaryNodeChild(usyncNode, 'side_list')
101
- return queryResult
102
- }
103
-
104
- withDeviceProtocol() {
105
- this.protocols.push(new USyncDeviceProtocol())
106
- return this
107
- }
108
-
109
- withContactProtocol() {
110
- this.protocols.push(new USyncContactProtocol())
111
- return this
112
- }
113
-
114
- withStatusProtocol() {
115
- this.protocols.push(new USyncStatusProtocol())
116
- return this
117
- }
118
-
119
- withDisappearingModeProtocol() {
120
- this.protocols.push(new USyncDisappearingModeProtocol())
121
- return this
122
- }
123
-
124
- withBotProfileProtocol() {
125
- this.protocols.push(new USyncBotProfileProtocol())
126
- return this
127
- }
128
-
129
- withLIDProtocol() {
130
- this.protocols.push(new USyncLIDProtocol())
131
- return this
132
- }
133
- }
@@ -1,32 +0,0 @@
1
- export class USyncUser {
2
- id?: string
3
- lid?: string
4
- phone?: string
5
- type?: string
6
- personaId?: string
7
-
8
- withId(id: string) {
9
- this.id = id
10
- return this
11
- }
12
-
13
- withLid(lid: string) {
14
- this.lid = lid
15
- return this
16
- }
17
-
18
- withPhone(phone: string) {
19
- this.phone = phone
20
- return this
21
- }
22
-
23
- withType(type: string) {
24
- this.type = type
25
- return this
26
- }
27
-
28
- withPersonaId(personaId: string) {
29
- this.personaId = personaId
30
- return this
31
- }
32
- }
@@ -1,3 +0,0 @@
1
- export * from './Protocols/index'
2
- export * from './USyncQuery'
3
- export * from './USyncUser'
@@ -1,22 +0,0 @@
1
- import { SenderKeyState } from '../../../Signal/Group/sender-key-state'
2
- import { SenderMessageKey } from '../../../Signal/Group/sender-message-key'
3
-
4
- describe('SenderKeyState regression: missing senderMessageKeys array', () => {
5
- it('should initialize senderMessageKeys when absent in provided structure', () => {
6
- const legacyStructure = {
7
- senderKeyId: 42,
8
- senderChainKey: { iteration: 0, seed: Buffer.from([1, 2, 3]) },
9
- senderSigningKey: { public: Buffer.from([4, 5, 6]) }
10
- }
11
-
12
- const state = new SenderKeyState(null, null, null, null, null, null, legacyStructure as any)
13
- const msgKey = new SenderMessageKey(0, Buffer.from([7, 8, 9]))
14
- state.addSenderMessageKey(msgKey)
15
-
16
- const structure = state.getStructure()
17
- expect(structure.senderMessageKeys).toBeDefined()
18
- expect(Array.isArray(structure.senderMessageKeys)).toBe(true)
19
- expect(structure.senderMessageKeys.length).toBe(1)
20
- expect(structure.senderMessageKeys[0]?.iteration).toBe(0)
21
- })
22
- })