@zapo-js/fake-server 0.3.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 (238) hide show
  1. package/README.md +176 -0
  2. package/dist/api/AppStateSyncManager.d.ts +27 -0
  3. package/dist/api/AppStateSyncManager.d.ts.map +1 -0
  4. package/dist/api/AppStateSyncManager.js +151 -0
  5. package/dist/api/AppStateSyncManager.js.map +1 -0
  6. package/dist/api/FakePairingDriver.d.ts +27 -0
  7. package/dist/api/FakePairingDriver.d.ts.map +1 -0
  8. package/dist/api/FakePairingDriver.js +36 -0
  9. package/dist/api/FakePairingDriver.js.map +1 -0
  10. package/dist/api/FakePeer.d.ts +143 -0
  11. package/dist/api/FakePeer.d.ts.map +1 -0
  12. package/dist/api/FakePeer.js +408 -0
  13. package/dist/api/FakePeer.js.map +1 -0
  14. package/dist/api/FakeWaServer.d.ts +167 -0
  15. package/dist/api/FakeWaServer.d.ts.map +1 -0
  16. package/dist/api/FakeWaServer.js +652 -0
  17. package/dist/api/FakeWaServer.js.map +1 -0
  18. package/dist/api/PreKeyDispenser.d.ts +23 -0
  19. package/dist/api/PreKeyDispenser.d.ts.map +1 -0
  20. package/dist/api/PreKeyDispenser.js +98 -0
  21. package/dist/api/PreKeyDispenser.js.map +1 -0
  22. package/dist/api/Scenario.d.ts +24 -0
  23. package/dist/api/Scenario.d.ts.map +1 -0
  24. package/dist/api/Scenario.js +38 -0
  25. package/dist/api/Scenario.js.map +1 -0
  26. package/dist/api/ServerRegistries.d.ts +110 -0
  27. package/dist/api/ServerRegistries.d.ts.map +1 -0
  28. package/dist/api/ServerRegistries.js +268 -0
  29. package/dist/api/ServerRegistries.js.map +1 -0
  30. package/dist/api/iq-handlers.d.ts +47 -0
  31. package/dist/api/iq-handlers.d.ts.map +1 -0
  32. package/dist/api/iq-handlers.js +498 -0
  33. package/dist/api/iq-handlers.js.map +1 -0
  34. package/dist/cli.d.ts +4 -0
  35. package/dist/cli.d.ts.map +1 -0
  36. package/dist/cli.js +249 -0
  37. package/dist/cli.js.map +1 -0
  38. package/dist/index.d.ts +51 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +74 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/infra/WaFakeConnection.d.ts +23 -0
  43. package/dist/infra/WaFakeConnection.d.ts.map +1 -0
  44. package/dist/infra/WaFakeConnection.js +54 -0
  45. package/dist/infra/WaFakeConnection.js.map +1 -0
  46. package/dist/infra/WaFakeConnectionPipeline.d.ts +51 -0
  47. package/dist/infra/WaFakeConnectionPipeline.d.ts.map +1 -0
  48. package/dist/infra/WaFakeConnectionPipeline.js +224 -0
  49. package/dist/infra/WaFakeConnectionPipeline.js.map +1 -0
  50. package/dist/infra/WaFakeFrameSocket.d.ts +29 -0
  51. package/dist/infra/WaFakeFrameSocket.d.ts.map +1 -0
  52. package/dist/infra/WaFakeFrameSocket.js +122 -0
  53. package/dist/infra/WaFakeFrameSocket.js.map +1 -0
  54. package/dist/infra/WaFakeMediaHttpsServer.d.ts +16 -0
  55. package/dist/infra/WaFakeMediaHttpsServer.d.ts.map +1 -0
  56. package/dist/infra/WaFakeMediaHttpsServer.js +131 -0
  57. package/dist/infra/WaFakeMediaHttpsServer.js.map +1 -0
  58. package/dist/infra/WaFakeNoiseHandshake.d.ts +23 -0
  59. package/dist/infra/WaFakeNoiseHandshake.d.ts.map +1 -0
  60. package/dist/infra/WaFakeNoiseHandshake.js +76 -0
  61. package/dist/infra/WaFakeNoiseHandshake.js.map +1 -0
  62. package/dist/infra/WaFakeTransport.d.ts +15 -0
  63. package/dist/infra/WaFakeTransport.d.ts.map +1 -0
  64. package/dist/infra/WaFakeTransport.js +34 -0
  65. package/dist/infra/WaFakeTransport.js.map +1 -0
  66. package/dist/infra/WaFakeWsServer.d.ts +29 -0
  67. package/dist/infra/WaFakeWsServer.d.ts.map +1 -0
  68. package/dist/infra/WaFakeWsServer.js +101 -0
  69. package/dist/infra/WaFakeWsServer.js.map +1 -0
  70. package/dist/protocol/auth/cert-chain.d.ts +18 -0
  71. package/dist/protocol/auth/cert-chain.d.ts.map +1 -0
  72. package/dist/protocol/auth/cert-chain.js +44 -0
  73. package/dist/protocol/auth/cert-chain.js.map +1 -0
  74. package/dist/protocol/auth/client-payload-validate.d.ts +21 -0
  75. package/dist/protocol/auth/client-payload-validate.d.ts.map +1 -0
  76. package/dist/protocol/auth/client-payload-validate.js +61 -0
  77. package/dist/protocol/auth/client-payload-validate.js.map +1 -0
  78. package/dist/protocol/auth/fake-primary-device.d.ts +19 -0
  79. package/dist/protocol/auth/fake-primary-device.d.ts.map +1 -0
  80. package/dist/protocol/auth/fake-primary-device.js +53 -0
  81. package/dist/protocol/auth/fake-primary-device.js.map +1 -0
  82. package/dist/protocol/auth/pair-device.d.ts +26 -0
  83. package/dist/protocol/auth/pair-device.d.ts.map +1 -0
  84. package/dist/protocol/auth/pair-device.js +104 -0
  85. package/dist/protocol/auth/pair-device.js.map +1 -0
  86. package/dist/protocol/auth/success-node.d.ts +15 -0
  87. package/dist/protocol/auth/success-node.d.ts.map +1 -0
  88. package/dist/protocol/auth/success-node.js +30 -0
  89. package/dist/protocol/auth/success-node.js.map +1 -0
  90. package/dist/protocol/iq/abprops.d.ts +14 -0
  91. package/dist/protocol/iq/abprops.d.ts.map +1 -0
  92. package/dist/protocol/iq/abprops.js +34 -0
  93. package/dist/protocol/iq/abprops.js.map +1 -0
  94. package/dist/protocol/iq/appstate-sync.d.ts +38 -0
  95. package/dist/protocol/iq/appstate-sync.d.ts.map +1 -0
  96. package/dist/protocol/iq/appstate-sync.js +154 -0
  97. package/dist/protocol/iq/appstate-sync.js.map +1 -0
  98. package/dist/protocol/iq/business.d.ts +13 -0
  99. package/dist/protocol/iq/business.d.ts.map +1 -0
  100. package/dist/protocol/iq/business.js +64 -0
  101. package/dist/protocol/iq/business.js.map +1 -0
  102. package/dist/protocol/iq/dirty-bits.d.ts +8 -0
  103. package/dist/protocol/iq/dirty-bits.d.ts.map +1 -0
  104. package/dist/protocol/iq/dirty-bits.js +23 -0
  105. package/dist/protocol/iq/dirty-bits.js.map +1 -0
  106. package/dist/protocol/iq/group-ops.d.ts +34 -0
  107. package/dist/protocol/iq/group-ops.d.ts.map +1 -0
  108. package/dist/protocol/iq/group-ops.js +164 -0
  109. package/dist/protocol/iq/group-ops.js.map +1 -0
  110. package/dist/protocol/iq/newsletter.d.ts +4 -0
  111. package/dist/protocol/iq/newsletter.d.ts.map +1 -0
  112. package/dist/protocol/iq/newsletter.js +18 -0
  113. package/dist/protocol/iq/newsletter.js.map +1 -0
  114. package/dist/protocol/iq/prekey-fetch.d.ts +18 -0
  115. package/dist/protocol/iq/prekey-fetch.d.ts.map +1 -0
  116. package/dist/protocol/iq/prekey-fetch.js +92 -0
  117. package/dist/protocol/iq/prekey-fetch.js.map +1 -0
  118. package/dist/protocol/iq/privacy-token.d.ts +9 -0
  119. package/dist/protocol/iq/privacy-token.d.ts.map +1 -0
  120. package/dist/protocol/iq/privacy-token.js +30 -0
  121. package/dist/protocol/iq/privacy-token.js.map +1 -0
  122. package/dist/protocol/iq/privacy.d.ts +22 -0
  123. package/dist/protocol/iq/privacy.d.ts.map +1 -0
  124. package/dist/protocol/iq/privacy.js +133 -0
  125. package/dist/protocol/iq/privacy.js.map +1 -0
  126. package/dist/protocol/iq/profile.d.ts +22 -0
  127. package/dist/protocol/iq/profile.d.ts.map +1 -0
  128. package/dist/protocol/iq/profile.js +80 -0
  129. package/dist/protocol/iq/profile.js.map +1 -0
  130. package/dist/protocol/iq/router.d.ts +39 -0
  131. package/dist/protocol/iq/router.d.ts.map +1 -0
  132. package/dist/protocol/iq/router.js +118 -0
  133. package/dist/protocol/iq/router.js.map +1 -0
  134. package/dist/protocol/iq/usync.d.ts +8 -0
  135. package/dist/protocol/iq/usync.d.ts.map +1 -0
  136. package/dist/protocol/iq/usync.js +68 -0
  137. package/dist/protocol/iq/usync.js.map +1 -0
  138. package/dist/protocol/push/app-state-key-share.d.ts +17 -0
  139. package/dist/protocol/push/app-state-key-share.d.ts.map +1 -0
  140. package/dist/protocol/push/app-state-key-share.js +30 -0
  141. package/dist/protocol/push/app-state-key-share.js.map +1 -0
  142. package/dist/protocol/push/call-failure.d.ts +16 -0
  143. package/dist/protocol/push/call-failure.d.ts.map +1 -0
  144. package/dist/protocol/push/call-failure.js +32 -0
  145. package/dist/protocol/push/call-failure.js.map +1 -0
  146. package/dist/protocol/push/chatstate.d.ts +15 -0
  147. package/dist/protocol/push/chatstate.d.ts.map +1 -0
  148. package/dist/protocol/push/chatstate.js +27 -0
  149. package/dist/protocol/push/chatstate.js.map +1 -0
  150. package/dist/protocol/push/error-stanza.d.ts +8 -0
  151. package/dist/protocol/push/error-stanza.d.ts.map +1 -0
  152. package/dist/protocol/push/error-stanza.js +17 -0
  153. package/dist/protocol/push/error-stanza.js.map +1 -0
  154. package/dist/protocol/push/history-sync.d.ts +46 -0
  155. package/dist/protocol/push/history-sync.d.ts.map +1 -0
  156. package/dist/protocol/push/history-sync.js +117 -0
  157. package/dist/protocol/push/history-sync.js.map +1 -0
  158. package/dist/protocol/push/message.d.ts +21 -0
  159. package/dist/protocol/push/message.d.ts.map +1 -0
  160. package/dist/protocol/push/message.js +42 -0
  161. package/dist/protocol/push/message.js.map +1 -0
  162. package/dist/protocol/push/notification.d.ts +21 -0
  163. package/dist/protocol/push/notification.d.ts.map +1 -0
  164. package/dist/protocol/push/notification.js +34 -0
  165. package/dist/protocol/push/notification.js.map +1 -0
  166. package/dist/protocol/push/presence.d.ts +11 -0
  167. package/dist/protocol/push/presence.d.ts.map +1 -0
  168. package/dist/protocol/push/presence.js +18 -0
  169. package/dist/protocol/push/presence.js.map +1 -0
  170. package/dist/protocol/push/receipt.d.ts +14 -0
  171. package/dist/protocol/push/receipt.d.ts.map +1 -0
  172. package/dist/protocol/push/receipt.js +25 -0
  173. package/dist/protocol/push/receipt.js.map +1 -0
  174. package/dist/protocol/signal/fake-app-state-crypto.d.ts +49 -0
  175. package/dist/protocol/signal/fake-app-state-crypto.d.ts.map +1 -0
  176. package/dist/protocol/signal/fake-app-state-crypto.js +202 -0
  177. package/dist/protocol/signal/fake-app-state-crypto.js.map +1 -0
  178. package/dist/protocol/signal/fake-peer-double-ratchet.d.ts +38 -0
  179. package/dist/protocol/signal/fake-peer-double-ratchet.d.ts.map +1 -0
  180. package/dist/protocol/signal/fake-peer-double-ratchet.js +408 -0
  181. package/dist/protocol/signal/fake-peer-double-ratchet.js.map +1 -0
  182. package/dist/protocol/signal/fake-peer-group-recv-session.d.ts +10 -0
  183. package/dist/protocol/signal/fake-peer-group-recv-session.d.ts.map +1 -0
  184. package/dist/protocol/signal/fake-peer-group-recv-session.js +129 -0
  185. package/dist/protocol/signal/fake-peer-group-recv-session.js.map +1 -0
  186. package/dist/protocol/signal/fake-peer-identity.d.ts +7 -0
  187. package/dist/protocol/signal/fake-peer-identity.d.ts.map +1 -0
  188. package/dist/protocol/signal/fake-peer-identity.js +12 -0
  189. package/dist/protocol/signal/fake-peer-identity.js.map +1 -0
  190. package/dist/protocol/signal/fake-peer-key-bundle.d.ts +24 -0
  191. package/dist/protocol/signal/fake-peer-key-bundle.d.ts.map +1 -0
  192. package/dist/protocol/signal/fake-peer-key-bundle.js +29 -0
  193. package/dist/protocol/signal/fake-peer-key-bundle.js.map +1 -0
  194. package/dist/protocol/signal/fake-peer-recv-session.d.ts +60 -0
  195. package/dist/protocol/signal/fake-peer-recv-session.d.ts.map +1 -0
  196. package/dist/protocol/signal/fake-peer-recv-session.js +284 -0
  197. package/dist/protocol/signal/fake-peer-recv-session.js.map +1 -0
  198. package/dist/protocol/signal/fake-peer-session.d.ts +87 -0
  199. package/dist/protocol/signal/fake-peer-session.d.ts.map +1 -0
  200. package/dist/protocol/signal/fake-peer-session.js +207 -0
  201. package/dist/protocol/signal/fake-peer-session.js.map +1 -0
  202. package/dist/protocol/signal/fake-sender-key.d.ts +15 -0
  203. package/dist/protocol/signal/fake-sender-key.d.ts.map +1 -0
  204. package/dist/protocol/signal/fake-sender-key.js +91 -0
  205. package/dist/protocol/signal/fake-sender-key.js.map +1 -0
  206. package/dist/protocol/signal/prekey-upload.d.ts +22 -0
  207. package/dist/protocol/signal/prekey-upload.d.ts.map +1 -0
  208. package/dist/protocol/signal/prekey-upload.js +113 -0
  209. package/dist/protocol/signal/prekey-upload.js.map +1 -0
  210. package/dist/protocol/stream/stream-error.d.ts +8 -0
  211. package/dist/protocol/stream/stream-error.d.ts.map +1 -0
  212. package/dist/protocol/stream/stream-error.js +64 -0
  213. package/dist/protocol/stream/stream-error.js.map +1 -0
  214. package/dist/state/fake-app-state-collection.d.ts +35 -0
  215. package/dist/state/fake-app-state-collection.d.ts.map +1 -0
  216. package/dist/state/fake-app-state-collection.js +139 -0
  217. package/dist/state/fake-app-state-collection.js.map +1 -0
  218. package/dist/state/fake-media-store.d.ts +35 -0
  219. package/dist/state/fake-media-store.d.ts.map +1 -0
  220. package/dist/state/fake-media-store.js +57 -0
  221. package/dist/state/fake-media-store.js.map +1 -0
  222. package/dist/transport/codec.d.ts +10 -0
  223. package/dist/transport/codec.d.ts.map +1 -0
  224. package/dist/transport/codec.js +17 -0
  225. package/dist/transport/codec.js.map +1 -0
  226. package/dist/transport/crypto.d.ts +11 -0
  227. package/dist/transport/crypto.d.ts.map +1 -0
  228. package/dist/transport/crypto.js +36 -0
  229. package/dist/transport/crypto.js.map +1 -0
  230. package/dist/transport/index.d.ts +4 -0
  231. package/dist/transport/index.d.ts.map +1 -0
  232. package/dist/transport/index.js +20 -0
  233. package/dist/transport/index.js.map +1 -0
  234. package/dist/transport/protos.d.ts +10 -0
  235. package/dist/transport/protos.d.ts.map +1 -0
  236. package/dist/transport/protos.js +13 -0
  237. package/dist/transport/protos.js.map +1 -0
  238. package/package.json +43 -0
@@ -0,0 +1,408 @@
1
+ "use strict";
2
+ /** Fake peer used by tests to encrypt and push Signal messages to the lib. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.FakePeer = void 0;
5
+ const app_state_key_share_1 = require("../protocol/push/app-state-key-share");
6
+ const history_sync_1 = require("../protocol/push/history-sync");
7
+ const message_1 = require("../protocol/push/message");
8
+ const fake_peer_double_ratchet_1 = require("../protocol/signal/fake-peer-double-ratchet");
9
+ const fake_peer_group_recv_session_1 = require("../protocol/signal/fake-peer-group-recv-session");
10
+ const fake_peer_key_bundle_1 = require("../protocol/signal/fake-peer-key-bundle");
11
+ const fake_sender_key_1 = require("../protocol/signal/fake-sender-key");
12
+ const protos_1 = require("../transport/protos");
13
+ class FakePeer {
14
+ constructor(keyBundle, options, deps) {
15
+ this.ratchetInitiated = false;
16
+ this.nextMessageCounter = 0;
17
+ this.senderKeysByGroup = new Map();
18
+ this.groupsBootstrapped = new Set();
19
+ this.groupRecvSession = new fake_peer_group_recv_session_1.FakePeerGroupRecvSession();
20
+ this.keyBundle = keyBundle;
21
+ this.identity = {
22
+ identityKeyPair: keyBundle.identityKeyPair,
23
+ registrationId: keyBundle.registrationId
24
+ };
25
+ this.jid = options.jid;
26
+ this.displayName = options.displayName;
27
+ this.deps = deps;
28
+ this.skipOneTimePreKey = options.skipOneTimePreKey === true;
29
+ this.reservedOneTimePreKey =
30
+ !this.skipOneTimePreKey && deps.reserveOneTimePreKey
31
+ ? deps.reserveOneTimePreKey()
32
+ : null;
33
+ this.ratchet = new fake_peer_double_ratchet_1.FakePeerDoubleRatchet(keyBundle);
34
+ }
35
+ static async create(options, deps) {
36
+ const keyBundle = options.keyBundle ?? (await (0, fake_peer_key_bundle_1.generateFakePeerKeyBundle)());
37
+ return new FakePeer(keyBundle, options, deps);
38
+ }
39
+ async sendMessage(message, options = {}) {
40
+ await this.ensureRatchetInitiated();
41
+ const plaintext = encodePlaintextWithPadding(message);
42
+ const { type, ciphertext } = await this.ratchet.encrypt(plaintext);
43
+ const finalCiphertext = options.tamperCiphertext
44
+ ? options.tamperCiphertext(ciphertext)
45
+ : ciphertext;
46
+ const enc = { type, ciphertext: finalCiphertext };
47
+ const id = options.id ?? this.nextId();
48
+ const stanza = (0, message_1.buildMessage)({
49
+ id,
50
+ from: options.from ?? this.jid,
51
+ t: options.t,
52
+ type: options.type ?? 'text',
53
+ notify: this.displayName,
54
+ participant: options.participant,
55
+ enc: [enc]
56
+ });
57
+ await this.deps.pushStanza(stanza);
58
+ }
59
+ sendConversation(text, options = {}) {
60
+ return this.sendMessage({ conversation: text }, options);
61
+ }
62
+ async sendMessageEdit(input, options = {}) {
63
+ await this.sendMessage({
64
+ protocolMessage: {
65
+ type: protos_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT,
66
+ key: {
67
+ remoteJid: this.jid,
68
+ fromMe: false,
69
+ id: input.targetMessageId
70
+ },
71
+ timestampMs: Date.now(),
72
+ editedMessage: {
73
+ conversation: input.newText
74
+ }
75
+ }
76
+ }, options);
77
+ }
78
+ async sendMessageRevoke(input, options = {}) {
79
+ await this.sendMessage({
80
+ protocolMessage: {
81
+ type: protos_1.proto.Message.ProtocolMessage.Type.REVOKE,
82
+ key: {
83
+ remoteJid: this.jid,
84
+ fromMe: false,
85
+ id: input.targetMessageId
86
+ }
87
+ }
88
+ }, options);
89
+ }
90
+ async sendReaction(input, options = {}) {
91
+ await this.sendMessage({
92
+ reactionMessage: {
93
+ key: {
94
+ remoteJid: this.jid,
95
+ fromMe: false,
96
+ id: input.targetMessageId
97
+ },
98
+ text: input.emoji,
99
+ senderTimestampMs: Date.now()
100
+ }
101
+ }, options);
102
+ }
103
+ async sendHistorySync(input = {}, options = {}) {
104
+ const message = await (0, history_sync_1.buildHistorySyncMessage)(input);
105
+ await this.sendMessage(message, options);
106
+ }
107
+ async sendHistorySyncExternal(input, options = {}) {
108
+ const message = (0, history_sync_1.buildHistorySyncExternalMessage)(input);
109
+ await this.sendMessage(message, options);
110
+ }
111
+ async sendImageMessage(input, options = {}) {
112
+ await this.sendMessage({
113
+ imageMessage: {
114
+ url: input.directPath,
115
+ directPath: input.directPath,
116
+ mediaKey: input.mediaKey,
117
+ fileSha256: input.fileSha256,
118
+ fileEncSha256: input.fileEncSha256,
119
+ fileLength: input.fileLength,
120
+ mimetype: input.mimetype ?? 'image/jpeg',
121
+ caption: input.caption,
122
+ width: input.width,
123
+ height: input.height,
124
+ mediaKeyTimestamp: Math.floor(Date.now() / 1000)
125
+ }
126
+ }, options);
127
+ }
128
+ async sendVideoMessage(input, options = {}) {
129
+ await this.sendMessage({
130
+ videoMessage: {
131
+ url: input.directPath,
132
+ directPath: input.directPath,
133
+ mediaKey: input.mediaKey,
134
+ fileSha256: input.fileSha256,
135
+ fileEncSha256: input.fileEncSha256,
136
+ fileLength: input.fileLength,
137
+ mimetype: input.mimetype ?? 'video/mp4',
138
+ caption: input.caption,
139
+ seconds: input.seconds,
140
+ width: input.width,
141
+ height: input.height,
142
+ mediaKeyTimestamp: Math.floor(Date.now() / 1000)
143
+ }
144
+ }, options);
145
+ }
146
+ async sendAudioMessage(input, options = {}) {
147
+ await this.sendMessage({
148
+ audioMessage: {
149
+ url: input.directPath,
150
+ directPath: input.directPath,
151
+ mediaKey: input.mediaKey,
152
+ fileSha256: input.fileSha256,
153
+ fileEncSha256: input.fileEncSha256,
154
+ fileLength: input.fileLength,
155
+ mimetype: input.mimetype ?? (input.ptt ? 'audio/ogg' : 'audio/mp4'),
156
+ seconds: input.seconds,
157
+ ptt: input.ptt,
158
+ mediaKeyTimestamp: Math.floor(Date.now() / 1000)
159
+ }
160
+ }, options);
161
+ }
162
+ async sendDocumentMessage(input, options = {}) {
163
+ await this.sendMessage({
164
+ documentMessage: {
165
+ url: input.directPath,
166
+ directPath: input.directPath,
167
+ mediaKey: input.mediaKey,
168
+ fileSha256: input.fileSha256,
169
+ fileEncSha256: input.fileEncSha256,
170
+ fileLength: input.fileLength,
171
+ mimetype: input.mimetype ?? 'application/pdf',
172
+ title: input.title,
173
+ fileName: input.fileName,
174
+ pageCount: input.pageCount,
175
+ mediaKeyTimestamp: Math.floor(Date.now() / 1000)
176
+ }
177
+ }, options);
178
+ }
179
+ async sendStickerMessage(input, options = {}) {
180
+ await this.sendMessage({
181
+ stickerMessage: {
182
+ url: input.directPath,
183
+ directPath: input.directPath,
184
+ mediaKey: input.mediaKey,
185
+ fileSha256: input.fileSha256,
186
+ fileEncSha256: input.fileEncSha256,
187
+ fileLength: input.fileLength,
188
+ mimetype: input.mimetype ?? 'image/webp',
189
+ width: input.width,
190
+ height: input.height,
191
+ isAnimated: input.isAnimated,
192
+ mediaKeyTimestamp: Math.floor(Date.now() / 1000)
193
+ }
194
+ }, options);
195
+ }
196
+ async sendAppStateSyncKeyShare(input, options = {}) {
197
+ const message = (0, app_state_key_share_1.buildAppStateSyncKeyShareMessage)(input);
198
+ await this.sendMessage(message, options);
199
+ }
200
+ async sendGroupConversation(groupJid, text, options = {}) {
201
+ return this.sendGroupMessage(groupJid, { conversation: text }, options);
202
+ }
203
+ async sendGroupMessage(groupJid, message, options = {}) {
204
+ let senderKey = this.senderKeysByGroup.get(groupJid);
205
+ if (!senderKey) {
206
+ senderKey = await fake_sender_key_1.FakeSenderKey.generate();
207
+ this.senderKeysByGroup.set(groupJid, senderKey);
208
+ }
209
+ const plaintext = encodePlaintextWithPadding(message);
210
+ const { ciphertext, distributionMessage } = await senderKey.encrypt(plaintext);
211
+ // Seed the sender key before the first skmsg for this group.
212
+ const encChildren = [];
213
+ if (!this.groupsBootstrapped.has(groupJid)) {
214
+ await this.ensureRatchetInitiated();
215
+ const bootstrapPlaintext = encodePlaintextWithPadding({
216
+ senderKeyDistributionMessage: {
217
+ groupId: groupJid,
218
+ axolotlSenderKeyDistributionMessage: distributionMessage
219
+ }
220
+ });
221
+ const { type: pkType, ciphertext: pkCt } = await this.ratchet.encrypt(bootstrapPlaintext);
222
+ encChildren.push({ type: pkType, ciphertext: pkCt });
223
+ this.groupsBootstrapped.add(groupJid);
224
+ }
225
+ encChildren.push({ type: 'skmsg', ciphertext });
226
+ const groupStanza = (0, message_1.buildMessage)({
227
+ id: options.id ?? this.nextId(),
228
+ from: groupJid,
229
+ participant: this.jid,
230
+ t: options.t,
231
+ type: options.type ?? 'text',
232
+ notify: this.displayName,
233
+ enc: encChildren
234
+ });
235
+ await this.deps.pushStanza(groupStanza);
236
+ }
237
+ expectMessage(options = {}) {
238
+ const timeoutMs = options.timeoutMs ?? 5000;
239
+ return new Promise((resolve, reject) => {
240
+ let unsubscribe = null;
241
+ const timer = setTimeout(() => {
242
+ if (unsubscribe)
243
+ unsubscribe();
244
+ reject(new Error(`FakePeer.expectMessage timed out after ${timeoutMs}ms`));
245
+ }, timeoutMs);
246
+ unsubscribe = this.deps.subscribeInboundMessages((stanza) => {
247
+ const to = stanza.attrs.to ?? '';
248
+ if (to.endsWith('@g.us'))
249
+ return;
250
+ const enc = findEncForPeer(stanza, this.jid);
251
+ if (!enc)
252
+ return;
253
+ const encType = enc.attrs.type;
254
+ if (encType !== 'pkmsg' && encType !== 'msg')
255
+ return;
256
+ const ciphertext = enc.content;
257
+ if (!(ciphertext instanceof Uint8Array))
258
+ return;
259
+ this.decryptPairwise(encType, ciphertext)
260
+ .then((message) => {
261
+ clearTimeout(timer);
262
+ if (unsubscribe)
263
+ unsubscribe();
264
+ resolve({ message, stanza, encType });
265
+ })
266
+ .catch((error) => {
267
+ clearTimeout(timer);
268
+ if (unsubscribe)
269
+ unsubscribe();
270
+ reject(error instanceof Error ? error : new Error(String(error)));
271
+ });
272
+ });
273
+ });
274
+ }
275
+ expectGroupMessage(groupJid, options = {}) {
276
+ const timeoutMs = options.timeoutMs ?? 5000;
277
+ return new Promise((resolve, reject) => {
278
+ let unsubscribe = null;
279
+ const timer = setTimeout(() => {
280
+ if (unsubscribe)
281
+ unsubscribe();
282
+ reject(new Error(`FakePeer.expectGroupMessage timed out after ${timeoutMs}ms`));
283
+ }, timeoutMs);
284
+ unsubscribe = this.deps.subscribeInboundMessages((stanza) => {
285
+ if (stanza.attrs.to !== groupJid)
286
+ return;
287
+ const skmsg = findTopLevelEnc(stanza, 'skmsg');
288
+ if (!skmsg || !(skmsg.content instanceof Uint8Array))
289
+ return;
290
+ const senderJid = options.senderJid ?? stanza.attrs.participant;
291
+ if (!senderJid) {
292
+ return;
293
+ }
294
+ this.bootstrapAndDecryptGroup(senderJid, groupJid, stanza, skmsg.content)
295
+ .then((message) => {
296
+ clearTimeout(timer);
297
+ if (unsubscribe)
298
+ unsubscribe();
299
+ resolve({ message, stanza, encType: 'skmsg' });
300
+ })
301
+ .catch((error) => {
302
+ clearTimeout(timer);
303
+ if (unsubscribe)
304
+ unsubscribe();
305
+ reject(error instanceof Error ? error : new Error(String(error)));
306
+ });
307
+ });
308
+ });
309
+ }
310
+ async decryptPairwise(encType, ciphertext) {
311
+ const padded = encType === 'pkmsg'
312
+ ? await this.ratchet.decryptPreKeyMessage(ciphertext)
313
+ : await this.ratchet.decryptMessage(ciphertext);
314
+ return protos_1.proto.Message.decode(padded);
315
+ }
316
+ async decryptStanza(stanza) {
317
+ const enc = findEncForPeer(stanza, this.jid);
318
+ if (!enc || !(enc.content instanceof Uint8Array))
319
+ return null;
320
+ const encType = enc.attrs.type;
321
+ if (encType !== 'pkmsg' && encType !== 'msg')
322
+ return null;
323
+ const message = await this.decryptPairwise(encType, enc.content);
324
+ return { message, stanza, encType };
325
+ }
326
+ async bootstrapAndDecryptGroup(senderJid, groupJid, stanza, skmsgCiphertext) {
327
+ const bootstrap = findEncForPeer(stanza, this.jid);
328
+ if (bootstrap && bootstrap.content instanceof Uint8Array) {
329
+ const bootstrapType = bootstrap.attrs.type;
330
+ if (bootstrapType === 'pkmsg' || bootstrapType === 'msg') {
331
+ const padded = bootstrapType === 'pkmsg'
332
+ ? await this.ratchet.decryptPreKeyMessage(bootstrap.content)
333
+ : await this.ratchet.decryptMessage(bootstrap.content);
334
+ const innerMessage = protos_1.proto.Message.decode(padded);
335
+ const skdm = innerMessage.senderKeyDistributionMessage;
336
+ const axolotl = skdm?.axolotlSenderKeyDistributionMessage;
337
+ if (axolotl) {
338
+ this.groupRecvSession.addDistribution(groupJid, senderJid, axolotl);
339
+ }
340
+ }
341
+ }
342
+ const padded = await this.groupRecvSession.decryptGroupMessage(groupJid, senderJid, skmsgCiphertext);
343
+ return protos_1.proto.Message.decode(padded);
344
+ }
345
+ async ensureRatchetInitiated() {
346
+ if (this.ratchetInitiated)
347
+ return;
348
+ if (this.ratchet.hasSendChain()) {
349
+ this.ratchetInitiated = true;
350
+ return;
351
+ }
352
+ const bundle = await this.deps.bundleResolver();
353
+ const oneTimePreKey = this.reservedOneTimePreKey ?? undefined;
354
+ await this.ratchet.initiateOutbound(bundle, {
355
+ oneTimePreKey,
356
+ skipOneTimePreKey: this.skipOneTimePreKey || !oneTimePreKey
357
+ });
358
+ this.ratchetInitiated = true;
359
+ }
360
+ nextId() {
361
+ this.nextMessageCounter += 1;
362
+ return `${this.jid}-${Date.now()}-${this.nextMessageCounter}`;
363
+ }
364
+ }
365
+ exports.FakePeer = FakePeer;
366
+ function findEncForPeer(stanza, peerJid) {
367
+ if (!Array.isArray(stanza.content))
368
+ return null;
369
+ for (const child of stanza.content) {
370
+ if (child.tag === 'enc' && stanza.attrs.to === peerJid) {
371
+ return child;
372
+ }
373
+ if (child.tag === 'participants' && Array.isArray(child.content)) {
374
+ for (const toNode of child.content) {
375
+ if (toNode.tag !== 'to' || toNode.attrs.jid !== peerJid)
376
+ continue;
377
+ if (!Array.isArray(toNode.content))
378
+ continue;
379
+ for (const inner of toNode.content) {
380
+ if (inner.tag === 'enc')
381
+ return inner;
382
+ }
383
+ }
384
+ }
385
+ }
386
+ return null;
387
+ }
388
+ function findTopLevelEnc(stanza, type) {
389
+ if (!Array.isArray(stanza.content))
390
+ return null;
391
+ for (const child of stanza.content) {
392
+ if (child.tag === 'enc' && child.attrs.type === type) {
393
+ return child;
394
+ }
395
+ }
396
+ return null;
397
+ }
398
+ function encodePlaintextWithPadding(message) {
399
+ const encoded = protos_1.proto.Message.encode(message).finish();
400
+ const padLen = 16 - (encoded.byteLength % 16);
401
+ const out = new Uint8Array(encoded.byteLength + padLen);
402
+ out.set(encoded, 0);
403
+ for (let i = encoded.byteLength; i < out.byteLength; i += 1) {
404
+ out[i] = padLen;
405
+ }
406
+ return out;
407
+ }
408
+ //# sourceMappingURL=FakePeer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FakePeer.js","sourceRoot":"","sources":["../../src/api/FakePeer.ts"],"names":[],"mappings":";AAAA,8EAA8E;;;AAE9E,8EAG6C;AAC7C,gEAKsC;AACtC,sDAA0E;AAC1E,0FAAmF;AACnF,kGAA0F;AAE1F,kFAGgD;AAChD,wEAAkE;AAGlE,gDAA2C;AA2C3C,MAAa,QAAQ;IAmBjB,YACI,SAA4B,EAC5B,OAA8B,EAC9B,IAAkB;QATd,qBAAgB,GAAG,KAAK,CAAA;QACxB,uBAAkB,GAAG,CAAC,CAAA;QACb,sBAAiB,GAAG,IAAI,GAAG,EAAyB,CAAA;QACpD,uBAAkB,GAAG,IAAI,GAAG,EAAU,CAAA;QACtC,qBAAgB,GAAG,IAAI,uDAAwB,EAAE,CAAA;QAO9D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,QAAQ,GAAG;YACZ,eAAe,EAAE,SAAS,CAAC,eAAe;YAC1C,cAAc,EAAE,SAAS,CAAC,cAAc;SAC3C,CAAA;QACD,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;QACtB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAA;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,KAAK,IAAI,CAAA;QAC3D,IAAI,CAAC,qBAAqB;YACtB,CAAC,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,oBAAoB;gBAChD,CAAC,CAAC,IAAI,CAAC,oBAAoB,EAAE;gBAC7B,CAAC,CAAC,IAAI,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,IAAI,gDAAqB,CAAC,SAAS,CAAC,CA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ionPipeline } from '../infra/WaFakeConnectionPipeline';
3
+ import type { BuildAbPropsResultInput } from '../protocol/iq/abprops';
4
+ import { type BuildServerSyncNotificationInput, type FakeAppStateCollectionPayload } from '../protocol/iq/appstate-sync';
5
+ import type { FakeBusinessProfile } from '../protocol/iq/business';
6
+ import type { FakePrivacyCategoryName, FakePrivacySettingsState } from '../protocol/iq/privacy';
7
+ import type { FakePrivacyTokenIssue } from '../protocol/iq/privacy-token';
8
+ import type { FakeProfilePictureResult } from '../protocol/iq/profile';
9
+ import { type WaFakeIqMatcher, type WaFakeIqResponder } from '../protocol/iq/router';
10
+ import type { ClientPreKeyBundle } from '../protocol/signal/prekey-upload';
11
+ import { type PublishedMediaBlob, type PublishMediaInput } from '../state/fake-media-store';
12
+ import { type BinaryNode } from '../transport/codec';
13
+ import { AppStateSyncManager, type CapturedAppStateMutation } from './AppStateSyncManager';
14
+ import { type FakePairingDriverOptions } from './FakePairingDriver';
15
+ import { type CreateFakePeerOptions, FakePeer } from './FakePeer';
16
+ import { PreKeyDispenser } from './PreKeyDispenser';
17
+ import { type AuthenticatedPipelineListener, Scenario } from './Scenario';
18
+ import { type CapturedBlocklistChange, type CapturedDirtyBitsClear, type CapturedGroupOp, type CapturedPrivacySet, type CapturedProfilePictureSet, type CapturedStatusSet, type FakeGroupMetadata, ServerRegistries } from './ServerRegistries';
19
+ export type { FakeGroupMetadata, CapturedGroupOp, CapturedPrivacySet, CapturedBlocklistChange, CapturedProfilePictureSet, CapturedStatusSet, CapturedDirtyBitsClear } from './ServerRegistries';
20
+ export type { CapturedAppStateMutation } from './AppStateSyncManager';
21
+ export interface FakeWaServerOptions {
22
+ readonly host?: string;
23
+ readonly port?: number;
24
+ readonly path?: string;
25
+ }
26
+ export interface FakeWaServerNoiseRootCa {
27
+ readonly publicKey: Uint8Array;
28
+ readonly serial: number;
29
+ }
30
+ export type FakeWaServerPipelineListener = (pipeline: WaFakeConnectionPipeline) => void;
31
+ export interface ExpectIqOptions {
32
+ readonly timeoutMs?: number;
33
+ }
34
+ export interface ExpectStanzaOptions {
35
+ readonly timeoutMs?: number;
36
+ }
37
+ export interface StanzaMatcher {
38
+ readonly tag?: string;
39
+ readonly type?: string;
40
+ readonly xmlns?: string;
41
+ readonly from?: string;
42
+ readonly to?: string;
43
+ readonly childTag?: string;
44
+ }
45
+ export interface CapturedMediaUpload {
46
+ readonly path: string;
47
+ readonly mediaType: string;
48
+ readonly encryptedBytes: Uint8Array;
49
+ readonly contentType: string | undefined;
50
+ readonly auth: string | undefined;
51
+ readonly receivedAtMs: number;
52
+ }
53
+ export declare class FakeWaServer {
54
+ readonly registries: ServerRegistries;
55
+ readonly preKeyDispenser: PreKeyDispenser;
56
+ readonly appStateSync: AppStateSyncManager;
57
+ private readonly wsServer;
58
+ private readonly pipelines;
59
+ private readonly iqRouter;
60
+ private readonly capturedStanzas;
61
+ private readonly pendingIqExpectations;
62
+ private readonly pendingStanzaExpectations;
63
+ private readonly authenticatedListeners;
64
+ private readonly inboundStanzaListeners;
65
+ private rootCa;
66
+ private serverStaticKeyPair;
67
+ private listenInfo;
68
+ private pipelineListener;
69
+ private rejectMode;
70
+ private readonly mediaStore;
71
+ private readonly mediaHttpsServer;
72
+ private readonly capturedMediaUploads;
73
+ private nextUploadCounter;
74
+ private cachedMediaProxyAgent;
75
+ constructor(options?: FakeWaServerOptions);
76
+ private buildIqHandlerDeps;
77
+ registerIqHandler(matcher: WaFakeIqMatcher, respond: WaFakeIqResponder, label?: string): () => void;
78
+ routeIqForTest(iq: BinaryNode): Promise<BinaryNode | null>;
79
+ onOutboundGroupOp(listener: (op: CapturedGroupOp) => void): () => void;
80
+ onOutboundPrivacySet(listener: (op: CapturedPrivacySet) => void): () => void;
81
+ onOutboundBlocklistChange(listener: (op: CapturedBlocklistChange) => void): () => void;
82
+ onOutboundProfilePictureSet(listener: (op: CapturedProfilePictureSet) => void): () => void;
83
+ onOutboundStatusSet(listener: (op: CapturedStatusSet) => void): () => void;
84
+ onLogout(listener: () => void): () => void;
85
+ onOutboundPrivacyTokenIssue(listener: (op: FakePrivacyTokenIssue) => void): () => void;
86
+ onOutboundDirtyBitsClear(listener: (op: CapturedDirtyBitsClear) => void): () => void;
87
+ privacyTokensIssuedSnapshot(): ReadonlyMap<string, FakePrivacyTokenIssue>;
88
+ privacySettingsSnapshot(): FakePrivacySettingsState;
89
+ blocklistSnapshot(): readonly string[];
90
+ latestStatusSnapshot(): string | null;
91
+ groupRegistrySnapshot(): ReadonlyMap<string, FakeGroupMetadata>;
92
+ setAbProps(input: BuildAbPropsResultInput): void;
93
+ setPrivacyDisallowedList(category: FakePrivacyCategoryName, jids: readonly string[]): void;
94
+ setProfilePictureRecord(jid: string, picture: FakeProfilePictureResult): void;
95
+ setBusinessProfileRecord(jid: string, profile: FakeBusinessProfile): void;
96
+ createFakeGroup(input: {
97
+ readonly groupJid: string;
98
+ readonly subject?: string;
99
+ readonly description?: string;
100
+ readonly participants: readonly FakePeer[];
101
+ readonly creator?: string;
102
+ readonly creationSeconds?: number;
103
+ }): FakeGroupMetadata;
104
+ triggerPreKeyUpload(pipeline: WaFakeConnectionPipeline, options?: {
105
+ readonly timeoutMs?: number;
106
+ readonly force?: boolean;
107
+ } | number): Promise<ClientPreKeyBundle>;
108
+ awaitPreKeyBundle(timeoutMs?: number): Promise<ClientPreKeyBundle>;
109
+ capturedPreKeyBundleSnapshot(): ClientPreKeyBundle | null;
110
+ dispenseOneTimePreKey(): {
111
+ readonly keyId: number;
112
+ readonly publicKey: Uint8Array;
113
+ } | null;
114
+ preKeyDispenserMissesSnapshot(): number;
115
+ preKeysAvailable(): number;
116
+ registerAppStateSyncKey(keyId: Uint8Array, keyData: Uint8Array): void;
117
+ onOutboundAppStateMutation(listener: (mutation: CapturedAppStateMutation) => void): () => void;
118
+ expectAppStateMutation(predicate: (mutation: CapturedAppStateMutation) => boolean, timeoutMs?: number): Promise<CapturedAppStateMutation>;
119
+ provideAppStateCollection(name: string, provider: () => Promise<FakeAppStateCollectionPayload | null> | FakeAppStateCollectionPayload | null): () => void;
120
+ pushServerSyncNotification(pipeline: WaFakeConnectionPipeline, input: BuildServerSyncNotificationInput): Promise<void>;
121
+ onAuthenticatedPipeline(listener: AuthenticatedPipelineListener): () => void;
122
+ scenario(configure: (s: Scenario) => void): void;
123
+ expectIq(matcher: WaFakeIqMatcher, options?: ExpectIqOptions): Promise<BinaryNode>;
124
+ capturedStanzaSnapshot(): readonly BinaryNode[];
125
+ expectStanza(matcher: StanzaMatcher, options?: ExpectStanzaOptions): Promise<BinaryNode>;
126
+ broadcastStanza(node: BinaryNode): Promise<number>;
127
+ waitForAuthenticatedPipeline(timeoutMs?: number): Promise<WaFakeConnectionPipeline>;
128
+ waitForNextAuthenticatedPipeline(timeoutMs?: number): Promise<WaFakeConnectionPipeline>;
129
+ publishMediaBlob(input: PublishMediaInput): Promise<PublishedMediaBlob>;
130
+ mediaUrl(path: string): string;
131
+ private requireMediaHttpsInfo;
132
+ get mediaProxyAgent(): HttpsAgent;
133
+ capturedMediaUploadSnapshot(): readonly CapturedMediaUpload[];
134
+ createFakePeer(options: CreateFakePeerOptions, pipeline: WaFakeConnectionPipeline): Promise<FakePeer>;
135
+ createFakePeerWithDevices(input: {
136
+ readonly userJid: string;
137
+ readonly deviceIds: readonly number[];
138
+ readonly displayName?: string;
139
+ readonly skipOneTimePreKey?: boolean;
140
+ }, pipeline: WaFakeConnectionPipeline): Promise<readonly FakePeer[]>;
141
+ private buildFakePeerDeps;
142
+ runPairing(pipeline: WaFakeConnectionPipeline, options: FakePairingDriverOptions, companionMaterialResolver: () => Promise<{
143
+ readonly advSecretKey: Uint8Array;
144
+ readonly identityPublicKey: Uint8Array;
145
+ }>): Promise<void>;
146
+ setRejectMode(info: {
147
+ readonly code?: number;
148
+ readonly reason?: string;
149
+ } | null): void;
150
+ static start(options?: FakeWaServerOptions): Promise<FakeWaServer>;
151
+ get url(): string;
152
+ get host(): string;
153
+ get port(): number;
154
+ get noiseRootCa(): FakeWaServerNoiseRootCa;
155
+ onPipeline(listener: FakeWaServerPipelineListener): void;
156
+ listen(): Promise<void>;
157
+ stop(): Promise<void>;
158
+ private handleConnection;
159
+ private handleCapturedStanza;
160
+ private buildMediaRequestHandler;
161
+ private handleMediaUpload;
162
+ private requireListening;
163
+ private requireRootCa;
164
+ }
165
+ export type { WaFakeAuthenticatedInfo, WaFakeConnectionPipeline };
166
+ export type { BinaryNode };
167
+ //# sourceMappingURL=FakeWaServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FakeWaServer.d.ts","sourceRoot":"","sources":["../../src/api/FakeWaServer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAGhD,OAAO,EACH,KAAK,uBAAuB,EAC5B,wBAAwB,EAC3B,MAAM,mCAAmC,CAAA;AAI1C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AACrE,OAAO,EACH,KAAK,gCAAgC,EACrC,KAAK,6BAA6B,EACrC,MAAM,8BAA8B,CAAA;AACrC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAClE,OAAO,KAAK,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAA;AAC/F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACzE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAA;AACtE,OAAO,EAEH,KAAK,eAAe,EACpB,KAAK,iBAAiB,EAEzB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,EAGH,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACzB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAGpD,OAAO,EAAE,mBAAmB,EAAE,KAAK,wBAA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