@pontalabs/baileys 1.0.6 → 1.0.7

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 (185) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +839 -267
  3. package/WAProto/GenerateStatics.sh +4 -3
  4. package/WAProto/WAProto.proto +511 -1215
  5. package/WAProto/index.d.ts +55 -14017
  6. package/WAProto/index.js +29 -97689
  7. package/lib/Defaults/index.d.ts +74 -72
  8. package/lib/Defaults/index.js +108 -94
  9. package/lib/Signal/Group/ciphertext-message.d.ts +7 -8
  10. package/lib/Signal/Group/ciphertext-message.js +16 -9
  11. package/lib/Signal/Group/group-session-builder.d.ts +13 -11
  12. package/lib/Signal/Group/group-session-builder.js +61 -19
  13. package/lib/Signal/Group/group_cipher.d.ts +16 -14
  14. package/lib/Signal/Group/group_cipher.js +70 -41
  15. package/lib/Signal/Group/index.d.ts +11 -12
  16. package/lib/Signal/Group/index.js +61 -12
  17. package/lib/Signal/Group/keyhelper.d.ts +14 -9
  18. package/lib/Signal/Group/keyhelper.js +58 -10
  19. package/lib/Signal/Group/sender-chain-key.d.ts +13 -13
  20. package/lib/Signal/Group/sender-chain-key.js +34 -13
  21. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -16
  22. package/lib/Signal/Group/sender-key-distribution-message.js +36 -28
  23. package/lib/Signal/Group/sender-key-message.d.ts +18 -18
  24. package/lib/Signal/Group/sender-key-message.js +45 -38
  25. package/lib/Signal/Group/sender-key-name.d.ts +15 -14
  26. package/lib/Signal/Group/sender-key-name.js +31 -20
  27. package/lib/Signal/Group/sender-key-record.d.ts +25 -24
  28. package/lib/Signal/Group/sender-key-record.js +35 -18
  29. package/lib/Signal/Group/sender-key-state.d.ts +34 -29
  30. package/lib/Signal/Group/sender-key-state.js +100 -37
  31. package/lib/Signal/Group/sender-message-key.d.ts +10 -11
  32. package/lib/Signal/Group/sender-message-key.js +22 -15
  33. package/lib/Signal/libsignal.d.ts +8 -5
  34. package/lib/Signal/libsignal.js +142 -288
  35. package/lib/Signal/lid-mapping.d.ts +28 -23
  36. package/lib/Signal/lid-mapping.js +184 -277
  37. package/lib/Socket/Client/index.d.ts +2 -3
  38. package/lib/Socket/Client/index.js +22 -3
  39. package/lib/Socket/Client/types.d.ts +15 -15
  40. package/lib/Socket/Client/types.js +15 -8
  41. package/lib/Socket/Client/websocket.d.ts +12 -12
  42. package/lib/Socket/Client/websocket.js +37 -29
  43. package/lib/Socket/business.d.ts +178 -208
  44. package/lib/Socket/business.js +127 -91
  45. package/lib/Socket/chats.d.ts +93 -120
  46. package/lib/Socket/chats.js +652 -727
  47. package/lib/Socket/community.js +10 -2
  48. package/lib/Socket/groups.d.ts +111 -143
  49. package/lib/Socket/groups.js +186 -165
  50. package/lib/Socket/index.d.ts +183 -252
  51. package/lib/Socket/index.js +18 -38
  52. package/lib/Socket/messages-recv.d.ts +167 -196
  53. package/lib/Socket/messages-recv.js +1567 -1443
  54. package/lib/Socket/messages-send.d.ts +158 -192
  55. package/lib/Socket/messages-send.js +1208 -1102
  56. package/lib/Socket/newsletter.d.ts +138 -163
  57. package/lib/Socket/newsletter.js +249 -153
  58. package/lib/Socket/socket.d.ts +36 -50
  59. package/lib/Socket/socket.js +820 -749
  60. package/lib/Store/index.d.ts +4 -4
  61. package/lib/Store/index.js +24 -4
  62. package/lib/Store/make-in-memory-store.d.ts +104 -44
  63. package/lib/Store/make-in-memory-store.js +213 -199
  64. package/lib/Store/make-ordered-dictionary.d.ts +12 -13
  65. package/lib/Store/make-ordered-dictionary.js +45 -38
  66. package/lib/Store/object-repository.d.ts +10 -11
  67. package/lib/Store/object-repository.js +16 -9
  68. package/lib/Types/Auth.d.ts +97 -93
  69. package/lib/Types/Auth.js +3 -2
  70. package/lib/Types/Bussines.js +3 -2
  71. package/lib/Types/Call.d.ts +13 -14
  72. package/lib/Types/Call.js +3 -2
  73. package/lib/Types/Chat.d.ts +97 -78
  74. package/lib/Types/Chat.js +9 -8
  75. package/lib/Types/Contact.d.ts +9 -12
  76. package/lib/Types/Contact.js +3 -2
  77. package/lib/Types/Events.d.ts +176 -206
  78. package/lib/Types/Events.js +3 -2
  79. package/lib/Types/GroupMetadata.d.ts +48 -53
  80. package/lib/Types/GroupMetadata.js +3 -2
  81. package/lib/Types/Label.d.ts +14 -13
  82. package/lib/Types/Label.js +30 -24
  83. package/lib/Types/LabelAssociation.d.ts +20 -15
  84. package/lib/Types/LabelAssociation.js +12 -6
  85. package/lib/Types/Message.d.ts +412 -248
  86. package/lib/Types/Message.js +19 -17
  87. package/lib/Types/Product.d.ts +71 -58
  88. package/lib/Types/Product.js +3 -2
  89. package/lib/Types/Signal.d.ts +82 -71
  90. package/lib/Types/Signal.js +3 -2
  91. package/lib/Types/Socket.d.ts +81 -76
  92. package/lib/Types/Socket.js +3 -3
  93. package/lib/Types/State.d.ts +19 -75
  94. package/lib/Types/State.js +14 -56
  95. package/lib/Types/USync.d.ts +8 -8
  96. package/lib/Types/USync.js +3 -2
  97. package/lib/Types/index.d.ts +62 -47
  98. package/lib/Types/index.js +50 -26
  99. package/lib/Utils/auth-utils.d.ts +10 -13
  100. package/lib/Utils/auth-utils.js +472 -213
  101. package/lib/Utils/business.d.ts +20 -14
  102. package/lib/Utils/business.js +134 -110
  103. package/lib/Utils/chat-utils.d.ts +70 -88
  104. package/lib/Utils/chat-utils.js +403 -466
  105. package/lib/Utils/crypto.d.ts +46 -27
  106. package/lib/Utils/crypto.js +188 -117
  107. package/lib/Utils/decode-wa-message.d.ts +45 -58
  108. package/lib/Utils/decode-wa-message.js +311 -212
  109. package/lib/Utils/event-buffer.d.ts +17 -14
  110. package/lib/Utils/event-buffer.js +296 -321
  111. package/lib/Utils/generics.d.ts +92 -66
  112. package/lib/Utils/generics.js +436 -270
  113. package/lib/Utils/history.d.ts +23 -24
  114. package/lib/Utils/history.js +76 -106
  115. package/lib/Utils/index.d.ts +21 -24
  116. package/lib/Utils/index.js +41 -24
  117. package/lib/Utils/link-preview.d.ts +14 -12
  118. package/lib/Utils/link-preview.js +75 -40
  119. package/lib/Utils/logger.d.ts +11 -10
  120. package/lib/Utils/logger.js +7 -3
  121. package/lib/Utils/lt-hash.d.ts +14 -8
  122. package/lib/Utils/lt-hash.js +53 -3
  123. package/lib/Utils/make-mutex.d.ts +7 -7
  124. package/lib/Utils/make-mutex.js +44 -28
  125. package/lib/Utils/message-retry-manager.d.ts +88 -115
  126. package/lib/Utils/message-retry-manager.js +160 -265
  127. package/lib/Utils/messages-media.d.ts +107 -105
  128. package/lib/Utils/messages-media.js +619 -548
  129. package/lib/Utils/messages.d.ts +66 -52
  130. package/lib/Utils/messages.js +1558 -1730
  131. package/lib/Utils/noise-handler.d.ts +18 -18
  132. package/lib/Utils/noise-handler.js +130 -176
  133. package/lib/Utils/process-message.d.ts +32 -43
  134. package/lib/Utils/process-message.js +282 -484
  135. package/lib/Utils/rich-message-utils.js +724 -1220
  136. package/lib/Utils/signal.d.ts +32 -37
  137. package/lib/Utils/signal.js +105 -140
  138. package/lib/Utils/use-multi-file-auth-state.d.ts +5 -5
  139. package/lib/Utils/use-multi-file-auth-state.js +120 -70
  140. package/lib/Utils/use-single-file-auth-state.d.ts +13 -11
  141. package/lib/Utils/use-single-file-auth-state.js +66 -92
  142. package/lib/Utils/validate-connection.d.ts +13 -11
  143. package/lib/Utils/validate-connection.js +113 -128
  144. package/lib/WABinary/constants.d.ts +27 -25
  145. package/lib/WABinary/constants.js +1292 -1451
  146. package/lib/WABinary/decode.d.ts +9 -7
  147. package/lib/WABinary/decode.js +189 -163
  148. package/lib/WABinary/encode.d.ts +3 -3
  149. package/lib/WABinary/encode.js +155 -110
  150. package/lib/WABinary/generic-utils.d.ts +27 -14
  151. package/lib/WABinary/generic-utils.js +105 -177
  152. package/lib/WABinary/index.d.ts +5 -6
  153. package/lib/WABinary/index.js +25 -6
  154. package/lib/WABinary/jid-utils.d.ts +54 -41
  155. package/lib/WABinary/jid-utils.js +152 -83
  156. package/lib/WABinary/types.d.ts +13 -10
  157. package/lib/WABinary/types.js +3 -2
  158. package/lib/WAM/BinaryInfo.d.ts +15 -8
  159. package/lib/WAM/BinaryInfo.js +14 -7
  160. package/lib/WAM/constants.d.ts +37 -30
  161. package/lib/WAM/constants.js +11983 -19465
  162. package/lib/WAM/encode.d.ts +3 -3
  163. package/lib/WAM/encode.js +109 -95
  164. package/lib/WAM/index.d.ts +3 -4
  165. package/lib/WAM/index.js +23 -4
  166. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
  167. package/lib/WAUSync/Protocols/USyncContactProtocol.js +21 -37
  168. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -19
  169. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +26 -18
  170. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -11
  171. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -12
  172. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -11
  173. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +24 -16
  174. package/lib/WAUSync/Protocols/index.d.ts +6 -6
  175. package/lib/WAUSync/Protocols/index.js +26 -6
  176. package/lib/WAUSync/USyncQuery.d.ts +28 -27
  177. package/lib/WAUSync/USyncQuery.js +62 -68
  178. package/lib/WAUSync/USyncUser.d.ts +10 -15
  179. package/lib/WAUSync/USyncUser.js +19 -20
  180. package/lib/WAUSync/index.d.ts +3 -4
  181. package/lib/WAUSync/index.js +23 -4
  182. package/lib/index.d.ts +12 -11
  183. package/lib/index.js +39 -12
  184. package/package.json +42 -86
  185. package/engine-requirements.js +0 -10
@@ -1,3 +1,3 @@
1
- import { BinaryInfo } from './BinaryInfo.js';
2
- export declare const encodeWAM: (binaryInfo: BinaryInfo) => Buffer<ArrayBuffer>;
3
- //# sourceMappingURL=encode.d.ts.map
1
+ import { BinaryInfo } from './BinaryInfo'
2
+
3
+ export declare const encodeWAM: (binaryInfo: BinaryInfo) => Buffer
package/lib/WAM/encode.js CHANGED
@@ -1,150 +1,164 @@
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;
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const constants_1 = require("./constants")
6
+ const getHeaderBitLength = (key) => (key < 256 ? 2 : 3)
7
+
8
+ const encodeWAM = (binaryInfo) => {
9
+ binaryInfo.buffer = []
10
+ encodeWAMHeader(binaryInfo)
11
+ encodeEvents(binaryInfo)
12
+ const totalSize = binaryInfo.buffer
13
+ .map((a) => a.length)
14
+ .reduce((a, b) => a + b)
15
+ const buffer = Buffer.alloc(totalSize)
16
+ let offset = 0
11
17
  for (const buffer_ of binaryInfo.buffer) {
12
- buffer_.copy(buffer, offset);
13
- offset += buffer_.length;
18
+ buffer_.copy(buffer, offset)
19
+ offset += buffer_.length
14
20
  }
15
- return buffer;
16
- };
21
+ return buffer
22
+ }
23
+
17
24
  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);
25
+ const headerBuffer = Buffer.alloc(8) // starting buffer
26
+ headerBuffer.write('WAM', 0, 'utf8')
27
+ headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3)
28
+ headerBuffer.writeUInt8(1, 4) //random flag
29
+ headerBuffer.writeUInt16BE(binaryInfo.sequence, 5)
30
+ headerBuffer.writeUInt8(0, 7) // regular channel
31
+ binaryInfo.buffer.push(headerBuffer)
25
32
  }
33
+
26
34
  function encodeGlobalAttributes(binaryInfo, globals) {
27
35
  for (const [key, _value] of Object.entries(globals)) {
28
- const id = WEB_GLOBALS.find(a => a?.name === key).id;
29
- let value = _value;
36
+ const id = constants_1.WEB_GLOBALS.find(a => a?.name === key)?.id
37
+ let value = _value
30
38
  if (typeof value === 'boolean') {
31
- value = value ? 1 : 0;
39
+ value = value ? 1 : 0
32
40
  }
33
- binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL));
41
+ binaryInfo.buffer.push(serializeData(id, value, constants_1.FLAG_GLOBAL))
34
42
  }
35
43
  }
44
+
36
45
  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;
46
+ for (const [name, { props, globals },] of binaryInfo.events.map((a) => Object.entries(a)[0])) {
47
+ encodeGlobalAttributes(binaryInfo, globals)
48
+ const event = constants_1.WEB_EVENTS.find((a) => a.name === name)
49
+ const props_ = Object.entries(props)
50
+ let extended = false
42
51
  for (const [, value] of props_) {
43
- extended || (extended = value !== null);
52
+ extended || (extended = value !== null)
44
53
  }
45
- const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED;
46
- binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag));
54
+ const eventFlag = extended ? constants_1.FLAG_EVENT : constants_1.FLAG_EVENT | constants_1.FLAG_EXTENDED
55
+ binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag))
47
56
  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;
57
+ const [key, _value] = props_[i]
58
+ const id = (event.props)[key][0]
59
+ extended = i < (props_.length - 1)
60
+ let value = _value
52
61
  if (typeof value === 'boolean') {
53
- value = value ? 1 : 0;
62
+ value = value ? 1 : 0
54
63
  }
55
- const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED;
56
- binaryInfo.buffer.push(serializeData(id, value, fieldFlag));
64
+ const fieldFlag = extended ? constants_1.FLAG_EVENT : constants_1.FLAG_FIELD | constants_1.FLAG_EXTENDED
65
+ binaryInfo.buffer.push(serializeData(id, value, fieldFlag))
57
66
  }
58
67
  }
59
68
  }
69
+
60
70
  function serializeData(key, value, flag) {
61
- const bufferLength = getHeaderBitLength(key);
62
- let buffer;
63
- let offset = 0;
71
+ const bufferLength = getHeaderBitLength(key)
72
+ let buffer
73
+ let offset = 0
64
74
  if (value === null) {
65
- if (flag === FLAG_GLOBAL) {
66
- buffer = Buffer.alloc(bufferLength);
67
- offset = serializeHeader(buffer, offset, key, flag);
68
- return buffer;
75
+ if (flag === constants_1.FLAG_GLOBAL) {
76
+ buffer = Buffer.alloc(bufferLength)
77
+ offset = serializeHeader(buffer, offset, key, flag)
78
+ return buffer
69
79
  }
70
80
  }
71
81
  else if (typeof value === 'number' && Number.isInteger(value)) {
72
82
  // is number
73
83
  if (value === 0 || value === 1) {
74
- buffer = Buffer.alloc(bufferLength);
75
- offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4));
76
- return buffer;
84
+ buffer = Buffer.alloc(bufferLength)
85
+ offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4))
86
+ return buffer
77
87
  }
78
88
  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;
89
+ buffer = Buffer.alloc(bufferLength + 1)
90
+ offset = serializeHeader(buffer, offset, key, flag | (3 << 4))
91
+ buffer.writeInt8(value, offset)
92
+ return buffer
83
93
  }
84
94
  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;
95
+ buffer = Buffer.alloc(bufferLength + 2)
96
+ offset = serializeHeader(buffer, offset, key, flag | (4 << 4))
97
+ buffer.writeInt16LE(value, offset)
98
+ return buffer
89
99
  }
90
100
  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;
101
+ buffer = Buffer.alloc(bufferLength + 4)
102
+ offset = serializeHeader(buffer, offset, key, flag | (5 << 4))
103
+ buffer.writeInt32LE(value, offset)
104
+ return buffer
95
105
  }
96
106
  else {
97
- buffer = Buffer.alloc(bufferLength + 8);
98
- offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
99
- buffer.writeDoubleLE(value, offset);
100
- return buffer;
107
+ buffer = Buffer.alloc(bufferLength + 8)
108
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
109
+ buffer.writeDoubleLE(value, offset)
110
+ return buffer
101
111
  }
102
112
  }
103
113
  else if (typeof value === 'number') {
104
114
  // 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;
115
+ buffer = Buffer.alloc(bufferLength + 8)
116
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
117
+ buffer.writeDoubleLE(value, offset)
118
+ return buffer
109
119
  }
110
120
  else if (typeof value === 'string') {
111
121
  // is string
112
- const utf8Bytes = Buffer.byteLength(value, 'utf8');
122
+ const utf8Bytes = Buffer.byteLength(value, 'utf8')
113
123
  if (utf8Bytes < 256) {
114
- buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes);
115
- offset = serializeHeader(buffer, offset, key, flag | (8 << 4));
116
- buffer.writeUint8(utf8Bytes, offset++);
124
+ buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes)
125
+ offset = serializeHeader(buffer, offset, key, flag | (8 << 4))
126
+ buffer.writeUint8(utf8Bytes, offset++)
117
127
  }
118
128
  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;
129
+ buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes)
130
+ offset = serializeHeader(buffer, offset, key, flag | (9 << 4))
131
+ buffer.writeUInt16LE(utf8Bytes, offset)
132
+ offset += 2
123
133
  }
124
134
  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;
135
+ buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes)
136
+ offset = serializeHeader(buffer, offset, key, flag | (10 << 4))
137
+ buffer.writeUInt32LE(utf8Bytes, offset)
138
+ offset += 4
129
139
  }
130
- buffer.write(value, offset, 'utf8');
131
- return buffer;
140
+ buffer.write(value, offset, 'utf8')
141
+ return buffer
132
142
  }
133
- throw 'missing';
143
+ throw 'missing'
134
144
  }
145
+
135
146
  function serializeHeader(buffer, offset, key, flag) {
136
147
  if (key < 256) {
137
- buffer.writeUInt8(flag, offset);
138
- offset += 1;
139
- buffer.writeUInt8(key, offset);
140
- offset += 1;
148
+ buffer.writeUInt8(flag, offset)
149
+ offset += 1
150
+ buffer.writeUInt8(key, offset)
151
+ offset += 1
141
152
  }
142
153
  else {
143
- buffer.writeUInt8(flag | FLAG_BYTE, offset);
144
- offset += 1;
145
- buffer.writeUInt16LE(key, offset);
146
- offset += 2;
154
+ buffer.writeUInt8(flag | constants_1.FLAG_BYTE, offset)
155
+ offset += 1
156
+ buffer.writeUInt16LE(key, offset)
157
+ offset += 2
147
158
  }
148
- return offset;
159
+ return offset
149
160
  }
150
- //# sourceMappingURL=encode.js.map
161
+
162
+ module.exports = {
163
+ encodeWAM
164
+ }
@@ -1,4 +1,3 @@
1
- export * from './constants.js';
2
- export * from './encode.js';
3
- export * from './BinaryInfo.js';
4
- //# sourceMappingURL=index.d.ts.map
1
+ export * from './constants'
2
+ export * from './encode'
3
+ export * from './BinaryInfo'
package/lib/WAM/index.js CHANGED
@@ -1,4 +1,23 @@
1
- export * from './constants.js';
2
- export * from './encode.js';
3
- export * from './BinaryInfo.js';
4
- //# sourceMappingURL=index.js.map
1
+ "use strict"
2
+
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
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)
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k
12
+ o[k2] = m[k]
13
+ }))
14
+
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
17
+ }
18
+
19
+ Object.defineProperty(exports, "__esModule", { value: true })
20
+
21
+ __exportStar(require("./constants"), exports)
22
+ __exportStar(require("./encode"), exports)
23
+ __exportStar(require("./BinaryInfo"), exports)
@@ -1,10 +1,10 @@
1
- import type { USyncQueryProtocol } from '../../Types/USync.js';
2
- import { type BinaryNode } from '../../WABinary/index.js';
3
- import { USyncUser } from '../USyncUser.js';
1
+ import { USyncQueryProtocol } from '../../Types/USync'
2
+ import { BinaryNode } from '../../WABinary'
3
+ import { USyncUser } from '../USyncUser'
4
+
4
5
  export declare class USyncContactProtocol implements USyncQueryProtocol {
5
- name: string;
6
- getQueryElement(): BinaryNode;
7
- getUserElement(user: USyncUser): BinaryNode;
8
- parser(node: BinaryNode): boolean;
9
- }
10
- //# sourceMappingURL=USyncContactProtocol.d.ts.map
6
+ name: string
7
+ getQueryElement(): BinaryNode
8
+ getUserElement(user: USyncUser): BinaryNode
9
+ parser(node: BinaryNode): boolean
10
+ }
@@ -1,52 +1,36 @@
1
- import { assertNodeErrorFree } from '../../WABinary/index.js';
2
- import { USyncUser } from '../USyncUser.js';
3
- export class USyncContactProtocol {
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const WABinary_1 = require("../../WABinary")
6
+
7
+ class USyncContactProtocol {
4
8
  constructor() {
5
- this.name = 'contact';
9
+ this.name = 'contact'
6
10
  }
7
11
  getQueryElement() {
8
12
  return {
9
13
  tag: 'contact',
10
- attrs: {}
11
- };
14
+ attrs: {},
15
+ }
12
16
  }
13
17
  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
- }
18
+ //TODO: Implement type / username fields (not yet supported)
39
19
  return {
40
20
  tag: 'contact',
41
- attrs: {}
42
- };
21
+ attrs: {},
22
+ content: user.phone,
23
+ }
43
24
  }
44
25
  parser(node) {
45
26
  if (node.tag === 'contact') {
46
- assertNodeErrorFree(node);
47
- return node?.attrs?.type === 'in';
27
+ WABinary_1.assertNodeErrorFree(node)
28
+ return node?.attrs?.type === 'in'
48
29
  }
49
- return false;
30
+ return false
50
31
  }
51
32
  }
52
- //# sourceMappingURL=USyncContactProtocol.js.map
33
+
34
+ module.exports = {
35
+ USyncContactProtocol
36
+ }
@@ -1,23 +1,26 @@
1
- import type { USyncQueryProtocol } from '../../Types/USync.js';
2
- import { type BinaryNode } from '../../WABinary/index.js';
1
+ import { USyncQueryProtocol } from '../../Types/USync'
2
+ import { BinaryNode } from '../../WABinary'
3
+
3
4
  export type KeyIndexData = {
4
- timestamp: number;
5
- signedKeyIndex?: Uint8Array;
6
- expectedTimestamp?: number;
7
- };
5
+ timestamp: number
6
+ signedKeyIndex?: Uint8Array
7
+ expectedTimestamp?: number
8
+ }
9
+
8
10
  export type DeviceListData = {
9
- id: number;
10
- keyIndex?: number;
11
- isHosted?: boolean;
12
- };
11
+ id: number
12
+ keyIndex?: number
13
+ isHosted?: boolean
14
+ }
15
+
13
16
  export type ParsedDeviceInfo = {
14
- deviceList?: DeviceListData[];
15
- keyIndex?: KeyIndexData;
16
- };
17
- export declare class USyncDeviceProtocol implements USyncQueryProtocol {
18
- name: string;
19
- getQueryElement(): BinaryNode;
20
- getUserElement(): BinaryNode | null;
21
- parser(node: BinaryNode): ParsedDeviceInfo;
17
+ deviceList?: DeviceListData[]
18
+ keyIndex?: KeyIndexData
22
19
  }
23
- //# sourceMappingURL=USyncDeviceProtocol.d.ts.map
20
+
21
+ export declare class USyncDeviceProtocol implements USyncQueryProtocol {
22
+ name: string
23
+ getQueryElement(): BinaryNode
24
+ getUserElement(): BinaryNode | null
25
+ parser(node: BinaryNode): ParsedDeviceInfo
26
+ }
@@ -1,39 +1,44 @@
1
- import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js';
2
- export class USyncDeviceProtocol {
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const WABinary_1 = require("../../WABinary")
6
+
7
+ class USyncDeviceProtocol {
3
8
  constructor() {
4
- this.name = 'devices';
9
+ this.name = 'devices'
5
10
  }
6
11
  getQueryElement() {
7
12
  return {
8
13
  tag: 'devices',
9
14
  attrs: {
10
- version: '2'
11
- }
12
- };
15
+ version: '2',
16
+ },
17
+ }
13
18
  }
14
19
  getUserElement( /* user: USyncUser */) {
15
20
  //TODO: Implement device phashing, ts and expectedTs
16
21
  //TODO: if all are not present, return null <- current behavior
17
22
  //TODO: otherwise return a node w tag 'devices' w those as attrs
18
- return null;
23
+ return null
19
24
  }
20
25
  parser(node) {
21
- const deviceList = [];
22
- let keyIndex = undefined;
26
+ const deviceList = []
27
+ let keyIndex = undefined
23
28
  if (node.tag === 'devices') {
24
- assertNodeErrorFree(node);
25
- const deviceListNode = getBinaryNodeChild(node, 'device-list');
26
- const keyIndexNode = getBinaryNodeChild(node, 'key-index-list');
29
+ WABinary_1.assertNodeErrorFree(node)
30
+ const deviceListNode = WABinary_1.getBinaryNodeChild(node, 'device-list')
31
+ const keyIndexNode = WABinary_1.getBinaryNodeChild(node, 'key-index-list')
27
32
  if (Array.isArray(deviceListNode?.content)) {
28
33
  for (const { tag, attrs } of deviceListNode.content) {
29
- const id = +attrs.id;
30
- const keyIndex = +attrs['key-index'];
34
+ const id = +attrs.id
35
+ const keyIndex = +attrs['key-index']
31
36
  if (tag === 'device') {
32
37
  deviceList.push({
33
38
  id,
34
39
  keyIndex,
35
40
  isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
36
- });
41
+ })
37
42
  }
38
43
  }
39
44
  }
@@ -42,13 +47,16 @@ export class USyncDeviceProtocol {
42
47
  timestamp: +keyIndexNode.attrs['ts'],
43
48
  signedKeyIndex: keyIndexNode?.content,
44
49
  expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
45
- };
50
+ }
46
51
  }
47
52
  }
48
53
  return {
49
54
  deviceList,
50
55
  keyIndex
51
- };
56
+ }
52
57
  }
53
58
  }
54
- //# sourceMappingURL=USyncDeviceProtocol.js.map
59
+
60
+ module.exports = {
61
+ USyncDeviceProtocol
62
+ }
@@ -1,13 +1,14 @@
1
- import type { USyncQueryProtocol } from '../../Types/USync.js';
2
- import { type BinaryNode } from '../../WABinary/index.js';
1
+ import { USyncQueryProtocol } from '../../Types/USync'
2
+ import { BinaryNode } from '../../WABinary'
3
+
3
4
  export type DisappearingModeData = {
4
- duration: number;
5
- setAt?: Date;
6
- };
7
- export declare class USyncDisappearingModeProtocol implements USyncQueryProtocol {
8
- name: string;
9
- getQueryElement(): BinaryNode;
10
- getUserElement(): null;
11
- parser(node: BinaryNode): DisappearingModeData | undefined;
5
+ duration: number
6
+ setAt?: Date
12
7
  }
13
- //# sourceMappingURL=USyncDisappearingModeProtocol.d.ts.map
8
+
9
+ export declare class USyncDisappearingModeProtocol implements USyncQueryProtocol {
10
+ name: string
11
+ getQueryElement(): BinaryNode
12
+ getUserElement(): null
13
+ parser(node: BinaryNode): DisappearingModeData | undefined
14
+ }
@@ -1,27 +1,35 @@
1
- import { assertNodeErrorFree } from '../../WABinary/index.js';
2
- export class USyncDisappearingModeProtocol {
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const WABinary_1 = require("../../WABinary")
6
+
7
+ class USyncDisappearingModeProtocol {
3
8
  constructor() {
4
- this.name = 'disappearing_mode';
9
+ this.name = 'disappearing_mode'
5
10
  }
6
11
  getQueryElement() {
7
12
  return {
8
13
  tag: 'disappearing_mode',
9
- attrs: {}
10
- };
14
+ attrs: {},
15
+ }
11
16
  }
12
17
  getUserElement() {
13
- return null;
18
+ return null
14
19
  }
15
20
  parser(node) {
16
21
  if (node.tag === 'disappearing_mode') {
17
- assertNodeErrorFree(node);
18
- const duration = +node?.attrs.duration;
19
- const setAt = new Date(+(node?.attrs.t || 0) * 1000);
22
+ WABinary_1.assertNodeErrorFree(node)
23
+ const duration = +node?.attrs?.duration
24
+ const setAt = new Date(+(node?.attrs?.t || 0) * 1000)
20
25
  return {
21
26
  duration,
22
- setAt
23
- };
27
+ setAt,
28
+ }
24
29
  }
25
30
  }
26
31
  }
27
- //# sourceMappingURL=USyncDisappearingModeProtocol.js.map
32
+
33
+ module.exports = {
34
+ USyncDisappearingModeProtocol
35
+ }
@@ -1,13 +1,14 @@
1
- import type { USyncQueryProtocol } from '../../Types/USync.js';
2
- import { type BinaryNode } from '../../WABinary/index.js';
1
+ import { USyncQueryProtocol } from '../../Types/USync'
2
+ import { BinaryNode } from '../../WABinary'
3
+
3
4
  export type StatusData = {
4
- status?: string | null;
5
- setAt?: Date;
6
- };
7
- export declare class USyncStatusProtocol implements USyncQueryProtocol {
8
- name: string;
9
- getQueryElement(): BinaryNode;
10
- getUserElement(): null;
11
- parser(node: BinaryNode): StatusData | undefined;
5
+ status?: string | null
6
+ setAt?: Date
12
7
  }
13
- //# sourceMappingURL=USyncStatusProtocol.d.ts.map
8
+
9
+ export declare class USyncStatusProtocol implements USyncQueryProtocol {
10
+ name: string
11
+ getQueryElement(): BinaryNode
12
+ getUserElement(): null
13
+ parser(node: BinaryNode): StatusData | undefined
14
+ }