@badzz88/baileys 8.4.7 → 8.5.0

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 (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1055 -337
  3. package/WAProto/index.js +5 -5
  4. package/lib/Defaults/index.js +187 -127
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/ciphertext-message.js +14 -11
  7. package/lib/Signal/Group/group-session-builder.js +91 -29
  8. package/lib/Signal/Group/group_cipher.js +88 -81
  9. package/lib/Signal/Group/index.js +136 -12
  10. package/lib/Signal/Group/keyhelper.js +70 -15
  11. package/lib/Signal/Group/sender-chain-key.js +31 -25
  12. package/lib/Signal/Group/sender-key-distribution-message.js +65 -62
  13. package/lib/Signal/Group/sender-key-message.js +68 -65
  14. package/lib/Signal/Group/sender-key-name.js +43 -41
  15. package/lib/Signal/Group/sender-key-record.js +43 -40
  16. package/lib/Signal/Group/sender-key-state.js +96 -83
  17. package/lib/Signal/Group/sender-message-key.js +29 -25
  18. package/lib/Signal/libsignal.js +483 -424
  19. package/lib/Signal/lid-mapping.js +261 -276
  20. package/lib/Socket/Client/index.js +30 -3
  21. package/lib/Socket/Client/types.js +12 -10
  22. package/lib/Socket/Client/websocket.js +61 -53
  23. package/lib/Socket/aigroups.js +240 -0
  24. package/lib/Socket/business.js +422 -379
  25. package/lib/Socket/chats.js +1816 -1193
  26. package/lib/Socket/communities.js +549 -431
  27. package/lib/Socket/graphql.js +656 -0
  28. package/lib/Socket/groups.js +764 -374
  29. package/lib/Socket/index.js +38 -11
  30. package/lib/Socket/interactive-handler.js +522 -0
  31. package/lib/Socket/interop.js +549 -0
  32. package/lib/Socket/luxu.js +6 -5
  33. package/lib/Socket/managed-account.js +183 -0
  34. package/lib/Socket/messages-recv.js +2439 -1915
  35. package/lib/Socket/messages-send.js +1642 -1242
  36. package/lib/Socket/mex.js +59 -40
  37. package/lib/Socket/newsletter.js +812 -249
  38. package/lib/Socket/privacy.js +449 -0
  39. package/lib/Socket/registration.js +427 -0
  40. package/lib/Socket/socket.js +1077 -965
  41. package/lib/Socket/text-router.js +83 -0
  42. package/lib/Socket/username.js +237 -140
  43. package/lib/Store/index.js +36 -10
  44. package/lib/Store/make-cache-manager-store.js +85 -80
  45. package/lib/Store/make-in-memory-store.js +591 -185
  46. package/lib/Store/make-ordered-dictionary.js +78 -72
  47. package/lib/Store/object-repository.js +25 -28
  48. package/lib/Types/Auth.js +38 -2
  49. package/lib/Types/Bussines.js +2 -2
  50. package/lib/Types/Call.js +2 -2
  51. package/lib/Types/Chat.js +4 -8
  52. package/lib/Types/Contact.js +2 -2
  53. package/lib/Types/Events.js +2 -2
  54. package/lib/Types/GroupMetadata.js +2 -2
  55. package/lib/Types/Label.js +26 -24
  56. package/lib/Types/LabelAssociation.js +8 -6
  57. package/lib/Types/Message.js +95 -11
  58. package/lib/Types/Mex.js +112 -37
  59. package/lib/Types/Newsletter.js +121 -0
  60. package/lib/Types/Product.js +2 -2
  61. package/lib/Types/Signal.js +2 -2
  62. package/lib/Types/Socket.js +2 -3
  63. package/lib/Types/State.js +70 -56
  64. package/lib/Types/USync.js +2 -2
  65. package/lib/Types/index.js +55 -26
  66. package/lib/Utils/auth-utils.js +292 -288
  67. package/lib/Utils/browser-utils.js +113 -48
  68. package/lib/Utils/business.js +240 -224
  69. package/lib/Utils/chat-utils.js +1205 -869
  70. package/lib/Utils/command-loader.d.ts +31 -0
  71. package/lib/Utils/command-loader.js +100 -0
  72. package/lib/Utils/companion-reg-client-utils.js +41 -34
  73. package/lib/Utils/consumer-application.js +107 -0
  74. package/lib/Utils/crypto.js +144 -107
  75. package/lib/Utils/curve25519-js.js +275 -0
  76. package/lib/Utils/decode-wa-message.js +518 -308
  77. package/lib/Utils/event-buffer.js +596 -611
  78. package/lib/Utils/generics.js +514 -354
  79. package/lib/Utils/group-history.js +60 -0
  80. package/lib/Utils/history.js +244 -134
  81. package/lib/Utils/identity-change-handler.js +51 -49
  82. package/lib/Utils/index.js +57 -23
  83. package/lib/Utils/jid-display-normalization.js +218 -0
  84. package/lib/Utils/link-preview.js +135 -77
  85. package/lib/Utils/logger.js +9 -3
  86. package/lib/Utils/lt-hash.js +37 -6
  87. package/lib/Utils/make-mutex.js +36 -33
  88. package/lib/Utils/message-composer.js +439 -233
  89. package/lib/Utils/message-retry-manager.js +265 -260
  90. package/lib/Utils/messages-media.js +855 -747
  91. package/lib/Utils/messages.js +2528 -884
  92. package/lib/Utils/meta-ai-msmsg.js +262 -0
  93. package/lib/Utils/native-bridge.js +82 -0
  94. package/lib/Utils/noise-handler.js +195 -200
  95. package/lib/Utils/offline-node-processor.js +35 -33
  96. package/lib/Utils/pre-key-manager.js +103 -102
  97. package/lib/Utils/process-message.js +978 -560
  98. package/lib/Utils/reporting-utils.js +257 -253
  99. package/lib/Utils/session-pool.d.ts +16 -0
  100. package/lib/Utils/session-pool.js +94 -0
  101. package/lib/Utils/signal.js +218 -195
  102. package/lib/Utils/stanza-ack.js +31 -29
  103. package/lib/Utils/sticker.d.ts +17 -0
  104. package/lib/Utils/sticker.js +145 -0
  105. package/lib/Utils/sync-action-utils.js +50 -45
  106. package/lib/Utils/tc-token-utils.js +137 -139
  107. package/lib/Utils/use-multi-file-auth-state.js +109 -109
  108. package/lib/Utils/validate-connection.js +218 -202
  109. package/lib/Utils/view-once-cache.d.ts +9 -0
  110. package/lib/Utils/view-once-cache.js +79 -0
  111. package/lib/Utils/voip-rekey.js +22 -0
  112. package/lib/WABinary/constants.js +1302 -1299
  113. package/lib/WABinary/decode.js +343 -262
  114. package/lib/WABinary/encode.js +12 -4
  115. package/lib/WABinary/generic-utils.js +223 -187
  116. package/lib/WABinary/index.js +33 -6
  117. package/lib/WABinary/jid-utils.js +351 -88
  118. package/lib/WABinary/types.js +2 -2
  119. package/lib/WAM/BinaryInfo.js +12 -9
  120. package/lib/WAM/constants.js +39486 -22853
  121. package/lib/WAM/encode.js +132 -140
  122. package/lib/WAM/index.js +31 -4
  123. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
  124. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  125. package/lib/WAUSync/Protocols/USyncContactProtocol.js +53 -51
  126. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +56 -53
  127. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +29 -26
  128. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +59 -0
  129. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
  130. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  131. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
  132. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -37
  133. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  134. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +26 -24
  135. package/lib/WAUSync/Protocols/index.js +39 -6
  136. package/lib/WAUSync/USyncQuery.js +132 -97
  137. package/lib/WAUSync/USyncUser.js +49 -30
  138. package/lib/WAUSync/index.js +31 -4
  139. package/lib/antiban.js +4637 -0
  140. package/lib/index.js +48 -15
  141. package/package.json +55 -92
  142. package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -263
  143. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
  144. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
package/lib/WAM/encode.js CHANGED
@@ -1,150 +1,142 @@
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
- };
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
17
20
  function encodeWAMHeader(binaryInfo) {
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);
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)
25
28
  }
26
29
  function encodeGlobalAttributes(binaryInfo, globals) {
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
- }
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
+ }
35
38
  }
36
39
  function encodeEvents(binaryInfo) {
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
- }
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
+ }
59
62
  }
60
63
  function serializeData(key, value, flag) {
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';
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'
134
128
  }
135
129
  function serializeHeader(buffer, offset, key, flag) {
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;
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
149
142
  }
150
- //# sourceMappingURL=encode.js.map
package/lib/WAM/index.js CHANGED
@@ -1,4 +1,31 @@
1
- export * from './constants.js';
2
- export * from './encode.js';
3
- export * from './BinaryInfo.js';
4
- //# sourceMappingURL=index.js.map
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)
@@ -0,0 +1,55 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.USyncBotProfileProtocol = void 0
4
+ const WABinary_1 = require('../../WABinary')
5
+ class USyncBotProfileProtocol {
6
+ constructor() {
7
+ this.name = 'bot'
8
+ }
9
+ getQueryElement() {
10
+ return {
11
+ tag: 'bot',
12
+ attrs: {},
13
+ content: [{ tag: 'profile', attrs: { v: '1' } }]
14
+ }
15
+ }
16
+ getUserElement(user) {
17
+ return {
18
+ tag: 'bot',
19
+ attrs: {},
20
+ content: [{ tag: 'profile', attrs: { persona_id: user.personaId } }]
21
+ }
22
+ }
23
+ 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')
28
+ const commands = []
29
+ const prompts = []
30
+ for (const command of (0, WABinary_1.getBinaryNodeChildren)(commandsNode, 'command')) {
31
+ commands.push({
32
+ name: (0, WABinary_1.getBinaryNodeChildString)(command, 'name'),
33
+ description: (0, WABinary_1.getBinaryNodeChildString)(command, 'description')
34
+ })
35
+ }
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
+ )
40
+ }
41
+ return {
42
+ isDefault: !!(0, WABinary_1.getBinaryNodeChild)(profile, 'default'),
43
+ 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'),
48
+ personaId: profile.attrs['persona_id'],
49
+ commandsDescription: (0, WABinary_1.getBinaryNodeChildString)(commandsNode, 'description'),
50
+ commands,
51
+ prompts
52
+ }
53
+ }
54
+ }
55
+ exports.USyncBotProfileProtocol = USyncBotProfileProtocol
@@ -0,0 +1,43 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.USyncBusinessProtocol = void 0
4
+ const WABinary_1 = require('../../WABinary')
5
+ class USyncBusinessProtocol {
6
+ constructor(profileVersion = '2') {
7
+ this.name = 'business'
8
+ this.profileVersion = profileVersion
9
+ }
10
+ getQueryElement() {
11
+ return {
12
+ tag: 'business',
13
+ attrs: {},
14
+ content: [
15
+ { tag: 'verified_name', attrs: {} },
16
+ { tag: 'profile', attrs: { v: this.profileVersion } }
17
+ ]
18
+ }
19
+ }
20
+ getUserElement(user) {
21
+ const children = []
22
+ if (user.verifiedNameSerial) {
23
+ children.push({ tag: 'verified_name', attrs: { serial: user.verifiedNameSerial } })
24
+ }
25
+ if (user.businessProfileTag) {
26
+ children.push({ tag: 'profile', attrs: { tag: user.businessProfileTag } })
27
+ }
28
+ return children.length > 0 ? { tag: 'business', attrs: {}, content: children } : null
29
+ }
30
+ parser(node) {
31
+ 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')
35
+ return {
36
+ verifiedName: verifiedNameNode?.content ?? null,
37
+ verifiedLevel: verifiedNameNode?.attrs?.verified_level ?? null,
38
+ profileTag: profileNode?.attrs?.tag ?? null,
39
+ pnJid: node.attrs?.pn_jid ?? null
40
+ }
41
+ }
42
+ }
43
+ exports.USyncBusinessProtocol = USyncBusinessProtocol
@@ -1,52 +1,54 @@
1
- import { assertNodeErrorFree } from '../../WABinary/index.js';
2
- import { USyncUser } from '../USyncUser.js';
3
- export class USyncContactProtocol {
4
- constructor() {
5
- this.name = 'contact';
6
- }
7
- getQueryElement() {
8
- return {
9
- tag: 'contact',
10
- attrs: {}
11
- };
12
- }
13
- getUserElement(user) {
14
- if (user.phone) {
15
- return {
16
- tag: 'contact',
17
- attrs: {},
18
- content: user.phone
19
- };
20
- }
21
- if (user.username) {
22
- return {
23
- tag: 'contact',
24
- attrs: {
25
- username: user.username,
26
- ...(user.usernameKey ? { pin: user.usernameKey } : {}),
27
- ...(user.lid ? { lid: user.lid } : {})
28
- }
29
- };
30
- }
31
- if (user.type) {
32
- return {
33
- tag: 'contact',
34
- attrs: {
35
- type: user.type
36
- }
37
- };
38
- }
39
- return {
40
- tag: 'contact',
41
- attrs: {}
42
- };
43
- }
44
- parser(node) {
45
- if (node.tag === 'contact') {
46
- assertNodeErrorFree(node);
47
- return node?.attrs?.type === 'in';
48
- }
49
- return false;
50
- }
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.USyncContactProtocol = void 0
4
+ const WABinary_1 = require('../../WABinary')
5
+ class USyncContactProtocol {
6
+ constructor() {
7
+ this.name = 'contact'
8
+ }
9
+ getQueryElement() {
10
+ return {
11
+ tag: 'contact',
12
+ attrs: {}
13
+ }
14
+ }
15
+ getUserElement(user) {
16
+ if (user.phone) {
17
+ return {
18
+ tag: 'contact',
19
+ attrs: {},
20
+ content: user.phone
21
+ }
22
+ }
23
+ if (user.username) {
24
+ return {
25
+ tag: 'contact',
26
+ attrs: {
27
+ username: user.username,
28
+ ...(user.usernameKey ? { pin: user.usernameKey } : {}),
29
+ ...(user.lid ? { lid: user.lid } : {})
30
+ }
31
+ }
32
+ }
33
+ if (user.type) {
34
+ return {
35
+ tag: 'contact',
36
+ attrs: {
37
+ type: user.type
38
+ }
39
+ }
40
+ }
41
+ return {
42
+ tag: 'contact',
43
+ attrs: {}
44
+ }
45
+ }
46
+ parser(node) {
47
+ if (node.tag === 'contact') {
48
+ ;(0, WABinary_1.assertNodeErrorFree)(node)
49
+ return node?.attrs?.type === 'in'
50
+ }
51
+ return false
52
+ }
51
53
  }
52
- //# sourceMappingURL=USyncContactProtocol.js.map
54
+ exports.USyncContactProtocol = USyncContactProtocol
@@ -1,54 +1,57 @@
1
- import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js';
2
- export class USyncDeviceProtocol {
3
- constructor() {
4
- this.name = 'devices';
5
- }
6
- getQueryElement() {
7
- return {
8
- tag: 'devices',
9
- attrs: {
10
- version: '2'
11
- }
12
- };
13
- }
14
- getUserElement( /* user: USyncUser */) {
15
- //TODO: Implement device phashing, ts and expectedTs
16
- //TODO: if all are not present, return null <- current behavior
17
- //TODO: otherwise return a node w tag 'devices' w those as attrs
18
- return null;
19
- }
20
- parser(node) {
21
- const deviceList = [];
22
- let keyIndex = undefined;
23
- if (node.tag === 'devices') {
24
- assertNodeErrorFree(node);
25
- const deviceListNode = getBinaryNodeChild(node, 'device-list');
26
- const keyIndexNode = getBinaryNodeChild(node, 'key-index-list');
27
- if (Array.isArray(deviceListNode?.content)) {
28
- for (const { tag, attrs } of deviceListNode.content) {
29
- const id = +attrs.id;
30
- const keyIndex = +attrs['key-index'];
31
- if (tag === 'device') {
32
- deviceList.push({
33
- id,
34
- keyIndex,
35
- isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
36
- });
37
- }
38
- }
39
- }
40
- if (keyIndexNode?.tag === 'key-index-list') {
41
- keyIndex = {
42
- timestamp: +keyIndexNode.attrs['ts'],
43
- signedKeyIndex: keyIndexNode?.content,
44
- expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
45
- };
46
- }
47
- }
48
- return {
49
- deviceList,
50
- keyIndex
51
- };
52
- }
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.USyncDeviceProtocol = void 0
4
+ const WABinary_1 = require('../../WABinary')
5
+ class USyncDeviceProtocol {
6
+ constructor() {
7
+ this.name = 'devices'
8
+ }
9
+ getQueryElement() {
10
+ return {
11
+ tag: 'devices',
12
+ attrs: {
13
+ version: '2'
14
+ }
15
+ }
16
+ }
17
+ getUserElement(/* user: USyncUser */) {
18
+ //TODO: Implement device phashing, ts and expectedTs
19
+ //TODO: if all are not present, return null <- current behavior
20
+ //TODO: otherwise return a node w tag 'devices' w those as attrs
21
+ return null
22
+ }
23
+ parser(node) {
24
+ const deviceList = []
25
+ let keyIndex = undefined
26
+ 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')
30
+ if (Array.isArray(deviceListNode?.content)) {
31
+ for (const { tag, attrs } of deviceListNode.content) {
32
+ const id = +attrs.id
33
+ const keyIndex = +attrs['key-index']
34
+ if (tag === 'device') {
35
+ deviceList.push({
36
+ id,
37
+ keyIndex,
38
+ isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
39
+ })
40
+ }
41
+ }
42
+ }
43
+ if (keyIndexNode?.tag === 'key-index-list') {
44
+ keyIndex = {
45
+ timestamp: +keyIndexNode.attrs['ts'],
46
+ signedKeyIndex: keyIndexNode?.content,
47
+ expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
48
+ }
49
+ }
50
+ }
51
+ return {
52
+ deviceList,
53
+ keyIndex
54
+ }
55
+ }
53
56
  }
54
- //# sourceMappingURL=USyncDeviceProtocol.js.map
57
+ exports.USyncDeviceProtocol = USyncDeviceProtocol