@zapo-js/fake-server 0.3.0 → 1.1.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 (301) hide show
  1. package/README.md +96 -8
  2. package/dist/api/AppStateSyncManager.d.ts +0 -1
  3. package/dist/api/AppStateSyncManager.js +0 -1
  4. package/dist/api/FakePairingDriver.d.ts +0 -1
  5. package/dist/api/FakePairingDriver.js +0 -1
  6. package/dist/api/FakePeer.d.ts +77 -4
  7. package/dist/api/FakePeer.js +208 -2
  8. package/dist/api/FakeServerSession.d.ts +67 -0
  9. package/dist/api/FakeServerSession.js +293 -0
  10. package/dist/api/FakeWaServer.d.ts +77 -31
  11. package/dist/api/FakeWaServer.js +140 -259
  12. package/dist/api/PreKeyDispenser.d.ts +0 -1
  13. package/dist/api/PreKeyDispenser.js +0 -1
  14. package/dist/api/Scenario.d.ts +0 -1
  15. package/dist/api/Scenario.js +0 -1
  16. package/dist/api/ServerRegistries.d.ts +0 -1
  17. package/dist/api/ServerRegistries.js +0 -1
  18. package/dist/api/iq-handlers.d.ts +1 -1
  19. package/dist/api/iq-handlers.js +23 -1
  20. package/dist/{cli.d.ts → bin.d.ts} +0 -1
  21. package/dist/bin.js +296 -0
  22. package/dist/esm/api/AppStateSyncManager.js +146 -0
  23. package/dist/esm/api/FakePairingDriver.js +31 -0
  24. package/dist/esm/api/FakePeer.js +610 -0
  25. package/dist/esm/api/FakeServerSession.js +287 -0
  26. package/dist/esm/api/FakeWaServer.js +528 -0
  27. package/dist/esm/api/PreKeyDispenser.js +93 -0
  28. package/dist/esm/api/Scenario.js +32 -0
  29. package/dist/esm/api/ServerRegistries.js +261 -0
  30. package/dist/esm/api/iq-handlers.js +515 -0
  31. package/dist/{cli.js → esm/bin.js} +70 -25
  32. package/dist/esm/index.js +26 -0
  33. package/dist/esm/infra/WaFakeConnection.js +49 -0
  34. package/dist/esm/infra/WaFakeConnectionPipeline.js +235 -0
  35. package/dist/esm/infra/WaFakeFrameSocket.js +117 -0
  36. package/dist/esm/infra/WaFakeMediaHttpsServer.js +126 -0
  37. package/dist/esm/infra/WaFakeNoiseHandshake.js +67 -0
  38. package/dist/esm/infra/WaFakeTransport.js +31 -0
  39. package/dist/esm/infra/WaFakeWsServer.js +96 -0
  40. package/dist/esm/package.json +3 -0
  41. package/dist/esm/protocol/auth/cert-chain.js +50 -0
  42. package/dist/esm/protocol/auth/client-payload-validate.js +55 -0
  43. package/dist/esm/protocol/auth/fake-primary-device.js +47 -0
  44. package/dist/esm/protocol/auth/pair-device.js +87 -0
  45. package/dist/esm/protocol/auth/success-node.js +26 -0
  46. package/dist/esm/protocol/iq/abprops.js +30 -0
  47. package/dist/esm/protocol/iq/appstate-sync.js +146 -0
  48. package/dist/esm/protocol/iq/business.js +59 -0
  49. package/dist/esm/protocol/iq/dirty-bits.js +19 -0
  50. package/dist/esm/protocol/iq/group-ops.js +154 -0
  51. package/dist/esm/protocol/iq/newsletter.js +14 -0
  52. package/dist/esm/protocol/iq/prekey-fetch.js +88 -0
  53. package/dist/esm/protocol/iq/privacy-token.js +26 -0
  54. package/dist/esm/protocol/iq/privacy.js +123 -0
  55. package/dist/esm/protocol/iq/profile.js +72 -0
  56. package/dist/esm/protocol/iq/router.js +117 -0
  57. package/dist/esm/protocol/iq/usync.js +64 -0
  58. package/dist/esm/protocol/push/app-state-key-share.js +26 -0
  59. package/dist/esm/protocol/push/call-failure.js +27 -0
  60. package/dist/esm/protocol/push/chatstate.js +23 -0
  61. package/dist/esm/protocol/push/error-stanza.js +13 -0
  62. package/dist/esm/protocol/push/history-sync.js +111 -0
  63. package/dist/esm/protocol/push/message.js +38 -0
  64. package/dist/esm/protocol/push/notification.js +29 -0
  65. package/dist/esm/protocol/push/presence.js +14 -0
  66. package/dist/esm/protocol/push/receipt.js +21 -0
  67. package/dist/esm/protocol/signal/fake-app-state-crypto.js +196 -0
  68. package/dist/esm/protocol/signal/fake-peer-double-ratchet.js +398 -0
  69. package/dist/esm/protocol/signal/fake-peer-group-recv-session.js +120 -0
  70. package/dist/esm/protocol/signal/fake-peer-identity.js +8 -0
  71. package/dist/esm/protocol/signal/fake-peer-key-bundle.js +25 -0
  72. package/dist/esm/protocol/signal/fake-sender-key.js +83 -0
  73. package/dist/esm/protocol/signal/prekey-upload.js +107 -0
  74. package/dist/esm/protocol/stream/stream-error.js +56 -0
  75. package/dist/esm/state/fake-app-state-collection.js +134 -0
  76. package/dist/esm/state/fake-media-store.js +53 -0
  77. package/dist/esm/transport/codec.js +8 -0
  78. package/dist/esm/transport/crypto.js +8 -0
  79. package/dist/esm/transport/protos.js +7 -0
  80. package/dist/esm/transport/util.js +8 -0
  81. package/dist/index.d.ts +2 -3
  82. package/dist/index.js +2 -2
  83. package/dist/infra/WaFakeConnection.d.ts +0 -1
  84. package/dist/infra/WaFakeConnection.js +0 -1
  85. package/dist/infra/WaFakeConnectionPipeline.d.ts +10 -3
  86. package/dist/infra/WaFakeConnectionPipeline.js +47 -32
  87. package/dist/infra/WaFakeFrameSocket.d.ts +0 -1
  88. package/dist/infra/WaFakeFrameSocket.js +0 -1
  89. package/dist/infra/WaFakeMediaHttpsServer.d.ts +0 -1
  90. package/dist/infra/WaFakeMediaHttpsServer.js +0 -1
  91. package/dist/infra/WaFakeNoiseHandshake.d.ts +8 -10
  92. package/dist/infra/WaFakeNoiseHandshake.js +19 -24
  93. package/dist/infra/WaFakeTransport.d.ts +2 -4
  94. package/dist/infra/WaFakeTransport.js +2 -1
  95. package/dist/infra/WaFakeWsServer.d.ts +0 -1
  96. package/dist/infra/WaFakeWsServer.js +0 -1
  97. package/dist/protocol/auth/cert-chain.d.ts +4 -1
  98. package/dist/protocol/auth/cert-chain.js +13 -3
  99. package/dist/protocol/auth/client-payload-validate.d.ts +0 -1
  100. package/dist/protocol/auth/client-payload-validate.js +0 -1
  101. package/dist/protocol/auth/fake-primary-device.d.ts +0 -1
  102. package/dist/protocol/auth/fake-primary-device.js +1 -3
  103. package/dist/protocol/auth/pair-device.d.ts +0 -1
  104. package/dist/protocol/auth/pair-device.js +4 -16
  105. package/dist/protocol/auth/success-node.d.ts +0 -1
  106. package/dist/protocol/auth/success-node.js +0 -1
  107. package/dist/protocol/iq/abprops.d.ts +0 -1
  108. package/dist/protocol/iq/abprops.js +0 -1
  109. package/dist/protocol/iq/appstate-sync.d.ts +0 -1
  110. package/dist/protocol/iq/appstate-sync.js +0 -1
  111. package/dist/protocol/iq/business.d.ts +0 -1
  112. package/dist/protocol/iq/business.js +0 -1
  113. package/dist/protocol/iq/dirty-bits.d.ts +0 -1
  114. package/dist/protocol/iq/dirty-bits.js +0 -1
  115. package/dist/protocol/iq/group-ops.d.ts +0 -1
  116. package/dist/protocol/iq/group-ops.js +0 -1
  117. package/dist/protocol/iq/newsletter.d.ts +0 -1
  118. package/dist/protocol/iq/newsletter.js +0 -1
  119. package/dist/protocol/iq/prekey-fetch.d.ts +0 -1
  120. package/dist/protocol/iq/prekey-fetch.js +0 -1
  121. package/dist/protocol/iq/privacy-token.d.ts +0 -1
  122. package/dist/protocol/iq/privacy-token.js +0 -1
  123. package/dist/protocol/iq/privacy.d.ts +0 -1
  124. package/dist/protocol/iq/privacy.js +15 -16
  125. package/dist/protocol/iq/profile.d.ts +0 -1
  126. package/dist/protocol/iq/profile.js +0 -1
  127. package/dist/protocol/iq/router.d.ts +7 -2
  128. package/dist/protocol/iq/router.js +8 -3
  129. package/dist/protocol/iq/usync.d.ts +0 -1
  130. package/dist/protocol/iq/usync.js +0 -1
  131. package/dist/protocol/push/app-state-key-share.d.ts +0 -1
  132. package/dist/protocol/push/app-state-key-share.js +0 -1
  133. package/dist/protocol/push/call-failure.d.ts +0 -1
  134. package/dist/protocol/push/call-failure.js +0 -1
  135. package/dist/protocol/push/chatstate.d.ts +0 -1
  136. package/dist/protocol/push/chatstate.js +0 -1
  137. package/dist/protocol/push/error-stanza.d.ts +0 -1
  138. package/dist/protocol/push/error-stanza.js +0 -1
  139. package/dist/protocol/push/history-sync.d.ts +0 -1
  140. package/dist/protocol/push/history-sync.js +0 -1
  141. package/dist/protocol/push/message.d.ts +0 -1
  142. package/dist/protocol/push/message.js +0 -1
  143. package/dist/protocol/push/notification.d.ts +0 -1
  144. package/dist/protocol/push/notification.js +0 -1
  145. package/dist/protocol/push/presence.d.ts +0 -1
  146. package/dist/protocol/push/presence.js +0 -1
  147. package/dist/protocol/push/receipt.d.ts +0 -1
  148. package/dist/protocol/push/receipt.js +0 -1
  149. package/dist/protocol/signal/fake-app-state-crypto.d.ts +7 -9
  150. package/dist/protocol/signal/fake-app-state-crypto.js +31 -33
  151. package/dist/protocol/signal/fake-peer-double-ratchet.d.ts +0 -1
  152. package/dist/protocol/signal/fake-peer-double-ratchet.js +23 -28
  153. package/dist/protocol/signal/fake-peer-group-recv-session.d.ts +0 -1
  154. package/dist/protocol/signal/fake-peer-group-recv-session.js +6 -10
  155. package/dist/protocol/signal/fake-peer-identity.d.ts +0 -1
  156. package/dist/protocol/signal/fake-peer-identity.js +0 -1
  157. package/dist/protocol/signal/fake-peer-key-bundle.d.ts +0 -1
  158. package/dist/protocol/signal/fake-peer-key-bundle.js +0 -1
  159. package/dist/protocol/signal/fake-sender-key.d.ts +0 -1
  160. package/dist/protocol/signal/fake-sender-key.js +5 -9
  161. package/dist/protocol/signal/prekey-upload.d.ts +0 -1
  162. package/dist/protocol/signal/prekey-upload.js +0 -1
  163. package/dist/protocol/stream/stream-error.d.ts +0 -1
  164. package/dist/protocol/stream/stream-error.js +0 -1
  165. package/dist/state/fake-app-state-collection.d.ts +0 -1
  166. package/dist/state/fake-app-state-collection.js +0 -1
  167. package/dist/state/fake-media-store.d.ts +0 -1
  168. package/dist/state/fake-media-store.js +2 -2
  169. package/dist/transport/codec.d.ts +2 -3
  170. package/dist/transport/codec.js +2 -3
  171. package/dist/transport/crypto.d.ts +5 -7
  172. package/dist/transport/crypto.js +6 -11
  173. package/dist/transport/protos.d.ts +2 -4
  174. package/dist/transport/protos.js +2 -4
  175. package/dist/transport/util.d.ts +8 -0
  176. package/dist/transport/util.js +16 -0
  177. package/package.json +26 -6
  178. package/dist/api/AppStateSyncManager.d.ts.map +0 -1
  179. package/dist/api/AppStateSyncManager.js.map +0 -1
  180. package/dist/api/FakePairingDriver.d.ts.map +0 -1
  181. package/dist/api/FakePairingDriver.js.map +0 -1
  182. package/dist/api/FakePeer.d.ts.map +0 -1
  183. package/dist/api/FakePeer.js.map +0 -1
  184. package/dist/api/FakeWaServer.d.ts.map +0 -1
  185. package/dist/api/FakeWaServer.js.map +0 -1
  186. package/dist/api/PreKeyDispenser.d.ts.map +0 -1
  187. package/dist/api/PreKeyDispenser.js.map +0 -1
  188. package/dist/api/Scenario.d.ts.map +0 -1
  189. package/dist/api/Scenario.js.map +0 -1
  190. package/dist/api/ServerRegistries.d.ts.map +0 -1
  191. package/dist/api/ServerRegistries.js.map +0 -1
  192. package/dist/api/iq-handlers.d.ts.map +0 -1
  193. package/dist/api/iq-handlers.js.map +0 -1
  194. package/dist/cli.d.ts.map +0 -1
  195. package/dist/cli.js.map +0 -1
  196. package/dist/index.d.ts.map +0 -1
  197. package/dist/index.js.map +0 -1
  198. package/dist/infra/WaFakeConnection.d.ts.map +0 -1
  199. package/dist/infra/WaFakeConnection.js.map +0 -1
  200. package/dist/infra/WaFakeConnectionPipeline.d.ts.map +0 -1
  201. package/dist/infra/WaFakeConnectionPipeline.js.map +0 -1
  202. package/dist/infra/WaFakeFrameSocket.d.ts.map +0 -1
  203. package/dist/infra/WaFakeFrameSocket.js.map +0 -1
  204. package/dist/infra/WaFakeMediaHttpsServer.d.ts.map +0 -1
  205. package/dist/infra/WaFakeMediaHttpsServer.js.map +0 -1
  206. package/dist/infra/WaFakeNoiseHandshake.d.ts.map +0 -1
  207. package/dist/infra/WaFakeNoiseHandshake.js.map +0 -1
  208. package/dist/infra/WaFakeTransport.d.ts.map +0 -1
  209. package/dist/infra/WaFakeTransport.js.map +0 -1
  210. package/dist/infra/WaFakeWsServer.d.ts.map +0 -1
  211. package/dist/infra/WaFakeWsServer.js.map +0 -1
  212. package/dist/protocol/auth/cert-chain.d.ts.map +0 -1
  213. package/dist/protocol/auth/cert-chain.js.map +0 -1
  214. package/dist/protocol/auth/client-payload-validate.d.ts.map +0 -1
  215. package/dist/protocol/auth/client-payload-validate.js.map +0 -1
  216. package/dist/protocol/auth/fake-primary-device.d.ts.map +0 -1
  217. package/dist/protocol/auth/fake-primary-device.js.map +0 -1
  218. package/dist/protocol/auth/pair-device.d.ts.map +0 -1
  219. package/dist/protocol/auth/pair-device.js.map +0 -1
  220. package/dist/protocol/auth/success-node.d.ts.map +0 -1
  221. package/dist/protocol/auth/success-node.js.map +0 -1
  222. package/dist/protocol/iq/abprops.d.ts.map +0 -1
  223. package/dist/protocol/iq/abprops.js.map +0 -1
  224. package/dist/protocol/iq/appstate-sync.d.ts.map +0 -1
  225. package/dist/protocol/iq/appstate-sync.js.map +0 -1
  226. package/dist/protocol/iq/business.d.ts.map +0 -1
  227. package/dist/protocol/iq/business.js.map +0 -1
  228. package/dist/protocol/iq/dirty-bits.d.ts.map +0 -1
  229. package/dist/protocol/iq/dirty-bits.js.map +0 -1
  230. package/dist/protocol/iq/group-ops.d.ts.map +0 -1
  231. package/dist/protocol/iq/group-ops.js.map +0 -1
  232. package/dist/protocol/iq/newsletter.d.ts.map +0 -1
  233. package/dist/protocol/iq/newsletter.js.map +0 -1
  234. package/dist/protocol/iq/prekey-fetch.d.ts.map +0 -1
  235. package/dist/protocol/iq/prekey-fetch.js.map +0 -1
  236. package/dist/protocol/iq/privacy-token.d.ts.map +0 -1
  237. package/dist/protocol/iq/privacy-token.js.map +0 -1
  238. package/dist/protocol/iq/privacy.d.ts.map +0 -1
  239. package/dist/protocol/iq/privacy.js.map +0 -1
  240. package/dist/protocol/iq/profile.d.ts.map +0 -1
  241. package/dist/protocol/iq/profile.js.map +0 -1
  242. package/dist/protocol/iq/router.d.ts.map +0 -1
  243. package/dist/protocol/iq/router.js.map +0 -1
  244. package/dist/protocol/iq/usync.d.ts.map +0 -1
  245. package/dist/protocol/iq/usync.js.map +0 -1
  246. package/dist/protocol/push/app-state-key-share.d.ts.map +0 -1
  247. package/dist/protocol/push/app-state-key-share.js.map +0 -1
  248. package/dist/protocol/push/call-failure.d.ts.map +0 -1
  249. package/dist/protocol/push/call-failure.js.map +0 -1
  250. package/dist/protocol/push/chatstate.d.ts.map +0 -1
  251. package/dist/protocol/push/chatstate.js.map +0 -1
  252. package/dist/protocol/push/error-stanza.d.ts.map +0 -1
  253. package/dist/protocol/push/error-stanza.js.map +0 -1
  254. package/dist/protocol/push/history-sync.d.ts.map +0 -1
  255. package/dist/protocol/push/history-sync.js.map +0 -1
  256. package/dist/protocol/push/message.d.ts.map +0 -1
  257. package/dist/protocol/push/message.js.map +0 -1
  258. package/dist/protocol/push/notification.d.ts.map +0 -1
  259. package/dist/protocol/push/notification.js.map +0 -1
  260. package/dist/protocol/push/presence.d.ts.map +0 -1
  261. package/dist/protocol/push/presence.js.map +0 -1
  262. package/dist/protocol/push/receipt.d.ts.map +0 -1
  263. package/dist/protocol/push/receipt.js.map +0 -1
  264. package/dist/protocol/signal/fake-app-state-crypto.d.ts.map +0 -1
  265. package/dist/protocol/signal/fake-app-state-crypto.js.map +0 -1
  266. package/dist/protocol/signal/fake-peer-double-ratchet.d.ts.map +0 -1
  267. package/dist/protocol/signal/fake-peer-double-ratchet.js.map +0 -1
  268. package/dist/protocol/signal/fake-peer-group-recv-session.d.ts.map +0 -1
  269. package/dist/protocol/signal/fake-peer-group-recv-session.js.map +0 -1
  270. package/dist/protocol/signal/fake-peer-identity.d.ts.map +0 -1
  271. package/dist/protocol/signal/fake-peer-identity.js.map +0 -1
  272. package/dist/protocol/signal/fake-peer-key-bundle.d.ts.map +0 -1
  273. package/dist/protocol/signal/fake-peer-key-bundle.js.map +0 -1
  274. package/dist/protocol/signal/fake-peer-recv-session.d.ts +0 -60
  275. package/dist/protocol/signal/fake-peer-recv-session.d.ts.map +0 -1
  276. package/dist/protocol/signal/fake-peer-recv-session.js +0 -284
  277. package/dist/protocol/signal/fake-peer-recv-session.js.map +0 -1
  278. package/dist/protocol/signal/fake-peer-session.d.ts +0 -87
  279. package/dist/protocol/signal/fake-peer-session.d.ts.map +0 -1
  280. package/dist/protocol/signal/fake-peer-session.js +0 -207
  281. package/dist/protocol/signal/fake-peer-session.js.map +0 -1
  282. package/dist/protocol/signal/fake-sender-key.d.ts.map +0 -1
  283. package/dist/protocol/signal/fake-sender-key.js.map +0 -1
  284. package/dist/protocol/signal/prekey-upload.d.ts.map +0 -1
  285. package/dist/protocol/signal/prekey-upload.js.map +0 -1
  286. package/dist/protocol/stream/stream-error.d.ts.map +0 -1
  287. package/dist/protocol/stream/stream-error.js.map +0 -1
  288. package/dist/state/fake-app-state-collection.d.ts.map +0 -1
  289. package/dist/state/fake-app-state-collection.js.map +0 -1
  290. package/dist/state/fake-media-store.d.ts.map +0 -1
  291. package/dist/state/fake-media-store.js.map +0 -1
  292. package/dist/transport/codec.d.ts.map +0 -1
  293. package/dist/transport/codec.js.map +0 -1
  294. package/dist/transport/crypto.d.ts.map +0 -1
  295. package/dist/transport/crypto.js.map +0 -1
  296. package/dist/transport/index.d.ts +0 -4
  297. package/dist/transport/index.d.ts.map +0 -1
  298. package/dist/transport/index.js +0 -20
  299. package/dist/transport/index.js.map +0 -1
  300. package/dist/transport/protos.d.ts.map +0 -1
  301. package/dist/transport/protos.js.map +0 -1
@@ -19,4 +19,3 @@ export declare function parseBlocklistChangeIq(iq: BinaryNode): {
19
19
  readonly action: 'block' | 'unblock';
20
20
  } | null;
21
21
  export declare function parsePrivacyDisallowedListGetIq(iq: BinaryNode): FakePrivacyCategoryName | null;
22
- //# sourceMappingURL=privacy.d.ts.map
@@ -9,8 +9,8 @@ exports.parsePrivacySetCategoryIq = parsePrivacySetCategoryIq;
9
9
  exports.parseBlocklistChangeIq = parseBlocklistChangeIq;
10
10
  exports.parsePrivacyDisallowedListGetIq = parsePrivacyDisallowedListGetIq;
11
11
  const router_1 = require("./router");
12
- exports.FAKE_DEFAULT_PRIVACY_SETTINGS = {
13
- settings: {
12
+ exports.FAKE_DEFAULT_PRIVACY_SETTINGS = Object.freeze({
13
+ settings: Object.freeze({
14
14
  readreceipts: 'all',
15
15
  last: 'all',
16
16
  online: 'all',
@@ -20,19 +20,19 @@ exports.FAKE_DEFAULT_PRIVACY_SETTINGS = {
20
20
  calladd: 'all',
21
21
  messages: 'all',
22
22
  defense: 'off'
23
- },
24
- disallowed: {
25
- readreceipts: [],
26
- last: [],
27
- online: [],
28
- profile: [],
29
- status: [],
30
- groupadd: [],
31
- calladd: [],
32
- messages: [],
33
- defense: []
34
- }
35
- };
23
+ }),
24
+ disallowed: Object.freeze({
25
+ readreceipts: Object.freeze([]),
26
+ last: Object.freeze([]),
27
+ online: Object.freeze([]),
28
+ profile: Object.freeze([]),
29
+ status: Object.freeze([]),
30
+ groupadd: Object.freeze([]),
31
+ calladd: Object.freeze([]),
32
+ messages: Object.freeze([]),
33
+ defense: Object.freeze([])
34
+ })
35
+ });
36
36
  function buildPrivacySettingsResult(iq, state) {
37
37
  const result = (0, router_1.buildIqResult)(iq);
38
38
  return {
@@ -130,4 +130,3 @@ function parsePrivacyDisallowedListGetIq(iq) {
130
130
  const name = list.attrs.name;
131
131
  return name ?? null;
132
132
  }
133
- //# sourceMappingURL=privacy.js.map
@@ -19,4 +19,3 @@ export declare function parseSetProfilePictureIq(iq: BinaryNode): {
19
19
  export declare function parseSetStatusIq(iq: BinaryNode): {
20
20
  readonly text: string;
21
21
  } | null;
22
- //# sourceMappingURL=profile.d.ts.map
@@ -77,4 +77,3 @@ function parseSetStatusIq(iq) {
77
77
  }
78
78
  return { text: '' };
79
79
  }
80
- //# sourceMappingURL=profile.js.map
@@ -7,7 +7,13 @@ export interface WaFakeIqMatcher {
7
7
  readonly xmlns?: string;
8
8
  readonly childTag?: string;
9
9
  }
10
- export type WaFakeIqResponder = (iq: BinaryNode) => BinaryNode | Promise<BinaryNode>;
10
+ /**
11
+ * Returns the response stanza, or `null` to fall through: the router keeps
12
+ * scanning lower-priority handlers as if this one had not matched. Lets a
13
+ * high-priority handler observe an IQ (capture, log, assert) while the
14
+ * default handler still answers it.
15
+ */
16
+ export type WaFakeIqResponder = (iq: BinaryNode) => BinaryNode | null | Promise<BinaryNode | null>;
11
17
  export interface WaFakeIqHandler {
12
18
  readonly matcher: WaFakeIqMatcher;
13
19
  readonly respond: WaFakeIqResponder;
@@ -36,4 +42,3 @@ export declare function buildIqError(inbound: BinaryNode, options: {
36
42
  readonly text?: string;
37
43
  readonly from?: string;
38
44
  }): BinaryNode;
39
- //# sourceMappingURL=router.d.ts.map
@@ -30,12 +30,18 @@ class WaFakeIqRouter {
30
30
  }
31
31
  for (const handler of this.highPriorityHandlers) {
32
32
  if (matches(iq, handler.matcher)) {
33
- return handler.respond(iq);
33
+ const response = await handler.respond(iq);
34
+ if (response !== null) {
35
+ return response;
36
+ }
34
37
  }
35
38
  }
36
39
  for (const handler of this.handlers) {
37
40
  if (matches(iq, handler.matcher)) {
38
- return handler.respond(iq);
41
+ const response = await handler.respond(iq);
42
+ if (response !== null) {
43
+ return response;
44
+ }
39
45
  }
40
46
  }
41
47
  this.events.onUnhandled?.(iq);
@@ -115,4 +121,3 @@ function buildIqError(inbound, options) {
115
121
  ]
116
122
  };
117
123
  }
118
- //# sourceMappingURL=router.js.map
@@ -5,4 +5,3 @@ export interface UsyncUserDevicesResult {
5
5
  readonly deviceIds?: readonly number[];
6
6
  }
7
7
  export declare function buildUsyncDevicesResult(inboundIq: BinaryNode, users: readonly UsyncUserDevicesResult[]): BinaryNode;
8
- //# sourceMappingURL=usync.d.ts.map
@@ -65,4 +65,3 @@ function extractUsyncSid(iq) {
65
65
  }
66
66
  return undefined;
67
67
  }
68
- //# sourceMappingURL=usync.js.map
@@ -14,4 +14,3 @@ export interface BuildAppStateSyncKeyShareInput {
14
14
  readonly keys: readonly FakeAppStateSyncKey[];
15
15
  }
16
16
  export declare function buildAppStateSyncKeyShareMessage(input: BuildAppStateSyncKeyShareInput): proto.IMessage;
17
- //# sourceMappingURL=app-state-key-share.d.ts.map
@@ -27,4 +27,3 @@ function buildAppStateSyncKeyShareMessage(input) {
27
27
  }
28
28
  };
29
29
  }
30
- //# sourceMappingURL=app-state-key-share.js.map
@@ -13,4 +13,3 @@ export interface BuildFailureInput {
13
13
  readonly extraAttrs?: Readonly<Record<string, string>>;
14
14
  }
15
15
  export declare function buildFailure(input: BuildFailureInput): BinaryNode;
16
- //# sourceMappingURL=call-failure.d.ts.map
@@ -29,4 +29,3 @@ function buildFailure(input) {
29
29
  attrs
30
30
  };
31
31
  }
32
- //# sourceMappingURL=call-failure.js.map
@@ -12,4 +12,3 @@ export interface BuildChatstateInput {
12
12
  readonly state: FakeChatstateState;
13
13
  }
14
14
  export declare function buildChatstate(input: BuildChatstateInput): BinaryNode;
15
- //# sourceMappingURL=chatstate.d.ts.map
@@ -24,4 +24,3 @@ function buildChatstate(input) {
24
24
  content: [stateChild]
25
25
  };
26
26
  }
27
- //# sourceMappingURL=chatstate.js.map
@@ -5,4 +5,3 @@ export interface BuildIncomingErrorStanzaInput {
5
5
  readonly from?: string;
6
6
  }
7
7
  export declare function buildIncomingErrorStanza(input: BuildIncomingErrorStanzaInput): BinaryNode;
8
- //# sourceMappingURL=error-stanza.d.ts.map
@@ -14,4 +14,3 @@ function buildIncomingErrorStanza(input) {
14
14
  attrs
15
15
  };
16
16
  }
17
- //# sourceMappingURL=error-stanza.js.map
@@ -43,4 +43,3 @@ export interface BuildHistorySyncExternalInput {
43
43
  export declare function buildHistorySyncMessage(input?: BuildHistorySyncInput): Promise<proto.IMessage>;
44
44
  export declare function encodeHistorySyncPlaintext(input?: BuildHistorySyncInput): Promise<Uint8Array>;
45
45
  export declare function buildHistorySyncExternalMessage(input: BuildHistorySyncExternalInput): proto.IMessage;
46
- //# sourceMappingURL=history-sync.d.ts.map
@@ -114,4 +114,3 @@ function buildHistorySyncExternalMessage(input) {
114
114
  }
115
115
  };
116
116
  }
117
- //# sourceMappingURL=history-sync.js.map
@@ -18,4 +18,3 @@ export interface BuildMessageInput {
18
18
  readonly extraChildren?: readonly BinaryNode[];
19
19
  }
20
20
  export declare function buildMessage(input: BuildMessageInput): BinaryNode;
21
- //# sourceMappingURL=message.d.ts.map
@@ -39,4 +39,3 @@ function buildMessage(input) {
39
39
  content: children
40
40
  };
41
41
  }
42
- //# sourceMappingURL=message.js.map
@@ -18,4 +18,3 @@ export interface BuildGroupNotificationInput {
18
18
  readonly children: readonly BinaryNode[];
19
19
  }
20
20
  export declare function buildGroupNotification(input: BuildGroupNotificationInput): BinaryNode;
21
- //# sourceMappingURL=notification.d.ts.map
@@ -31,4 +31,3 @@ function buildGroupNotification(input) {
31
31
  content: input.children
32
32
  });
33
33
  }
34
- //# sourceMappingURL=notification.js.map
@@ -8,4 +8,3 @@ export interface BuildIncomingPresenceInput {
8
8
  readonly last?: number | FakePresenceLastSentinel;
9
9
  }
10
10
  export declare function buildIncomingPresence(input: BuildIncomingPresenceInput): BinaryNode;
11
- //# sourceMappingURL=presence.d.ts.map
@@ -15,4 +15,3 @@ function buildIncomingPresence(input) {
15
15
  attrs
16
16
  };
17
17
  }
18
- //# sourceMappingURL=presence.js.map
@@ -11,4 +11,3 @@ export interface BuildReceiptInput {
11
11
  readonly content?: readonly BinaryNode[];
12
12
  }
13
13
  export declare function buildReceipt(input: BuildReceiptInput): BinaryNode;
14
- //# sourceMappingURL=receipt.d.ts.map
@@ -22,4 +22,3 @@ function buildReceipt(input) {
22
22
  ...(input.content ? { content: input.content } : {})
23
23
  };
24
24
  }
25
- //# sourceMappingURL=receipt.js.map
@@ -1,13 +1,12 @@
1
1
  /** App-state crypto helpers mirrored from WhatsApp Web behavior. */
2
- import { type CryptoKey } from '../../transport/crypto';
3
2
  import { type Proto } from '../../transport/protos';
4
- export declare const APP_STATE_EMPTY_LT_HASH: Uint8Array<ArrayBuffer>;
3
+ export declare const APP_STATE_EMPTY_LT_HASH: Readonly<Uint8Array>;
5
4
  export interface FakeAppStateDerivedKeys {
6
- readonly indexHmacKey: CryptoKey;
7
- readonly valueEncryptionAesKey: CryptoKey;
8
- readonly valueMacHmacKey: CryptoKey;
9
- readonly snapshotMacHmacKey: CryptoKey;
10
- readonly patchMacHmacKey: CryptoKey;
5
+ readonly indexHmacKey: Uint8Array;
6
+ readonly valueEncryptionAesKey: Uint8Array;
7
+ readonly valueMacHmacKey: Uint8Array;
8
+ readonly snapshotMacHmacKey: Uint8Array;
9
+ readonly patchMacHmacKey: Uint8Array;
11
10
  }
12
11
  export interface FakeAppStateEncryptedMutation {
13
12
  readonly indexMac: Uint8Array;
@@ -24,7 +23,7 @@ export interface FakeAppStateMutationInput {
24
23
  readonly iv?: Uint8Array;
25
24
  }
26
25
  export declare class FakeAppStateCrypto {
27
- deriveKeys(keyData: Uint8Array): Promise<FakeAppStateDerivedKeys>;
26
+ deriveKeys(keyData: Uint8Array): FakeAppStateDerivedKeys;
28
27
  encryptMutation(input: FakeAppStateMutationInput): Promise<FakeAppStateEncryptedMutation>;
29
28
  decryptMutation(input: {
30
29
  readonly operation: 'set' | 'remove';
@@ -46,4 +45,3 @@ export declare class FakeAppStateCrypto {
46
45
  private ltHashApply;
47
46
  private generateValueMac;
48
47
  }
49
- //# sourceMappingURL=fake-app-state-crypto.d.ts.map
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.FakeAppStateCrypto = exports.APP_STATE_EMPTY_LT_HASH = void 0;
5
5
  const crypto_1 = require("../../transport/crypto");
6
6
  const protos_1 = require("../../transport/protos");
7
+ const util_1 = require("../../transport/util");
7
8
  const APP_STATE_DERIVED_KEY_LENGTH = 160;
8
9
  const APP_STATE_DERIVED_INDEX_KEY_END = 32;
9
10
  const APP_STATE_DERIVED_VALUE_ENCRYPTION_KEY_END = 64;
@@ -15,29 +16,22 @@ const APP_STATE_MAC_OCTET_LENGTH = 8;
15
16
  const APP_STATE_IV_LENGTH = 16;
16
17
  const APP_STATE_LT_HASH_SIZE = 128;
17
18
  const APP_STATE_POINT_SIZE = 2;
18
- const KDF_INFO_MUTATION_KEYS = 'WhatsApp Mutation Keys';
19
- const KDF_INFO_PATCH_INTEGRITY = 'WhatsApp Patch Integrity';
19
+ const KDF_INFO_MUTATION_KEYS = util_1.TEXT_ENCODER.encode('WhatsApp Mutation Keys');
20
+ const KDF_INFO_PATCH_INTEGRITY = util_1.TEXT_ENCODER.encode('WhatsApp Patch Integrity');
20
21
  exports.APP_STATE_EMPTY_LT_HASH = new Uint8Array(APP_STATE_LT_HASH_SIZE);
21
22
  class FakeAppStateCrypto {
22
- async deriveKeys(keyData) {
23
- const derived = await (0, crypto_1.hkdf)(keyData, null, KDF_INFO_MUTATION_KEYS, APP_STATE_DERIVED_KEY_LENGTH);
24
- const [indexHmacKey, valueEncryptionAesKey, valueMacHmacKey, snapshotMacHmacKey, patchMacHmacKey] = await Promise.all([
25
- (0, crypto_1.importHmacKey)(derived.subarray(0, APP_STATE_DERIVED_INDEX_KEY_END)),
26
- (0, crypto_1.importAesCbcKey)(derived.subarray(APP_STATE_DERIVED_INDEX_KEY_END, APP_STATE_DERIVED_VALUE_ENCRYPTION_KEY_END)),
27
- (0, crypto_1.importHmacSha512Key)(derived.subarray(APP_STATE_DERIVED_VALUE_ENCRYPTION_KEY_END, APP_STATE_DERIVED_VALUE_MAC_KEY_END)),
28
- (0, crypto_1.importHmacKey)(derived.subarray(APP_STATE_DERIVED_VALUE_MAC_KEY_END, APP_STATE_DERIVED_SNAPSHOT_MAC_KEY_END)),
29
- (0, crypto_1.importHmacKey)(derived.subarray(APP_STATE_DERIVED_SNAPSHOT_MAC_KEY_END, APP_STATE_DERIVED_PATCH_MAC_KEY_END))
30
- ]);
23
+ deriveKeys(keyData) {
24
+ const derived = (0, crypto_1.hkdf)(keyData, null, KDF_INFO_MUTATION_KEYS, APP_STATE_DERIVED_KEY_LENGTH);
31
25
  return {
32
- indexHmacKey,
33
- valueEncryptionAesKey,
34
- valueMacHmacKey,
35
- snapshotMacHmacKey,
36
- patchMacHmacKey
26
+ indexHmacKey: derived.subarray(0, APP_STATE_DERIVED_INDEX_KEY_END),
27
+ valueEncryptionAesKey: derived.subarray(APP_STATE_DERIVED_INDEX_KEY_END, APP_STATE_DERIVED_VALUE_ENCRYPTION_KEY_END),
28
+ valueMacHmacKey: derived.subarray(APP_STATE_DERIVED_VALUE_ENCRYPTION_KEY_END, APP_STATE_DERIVED_VALUE_MAC_KEY_END),
29
+ snapshotMacHmacKey: derived.subarray(APP_STATE_DERIVED_VALUE_MAC_KEY_END, APP_STATE_DERIVED_SNAPSHOT_MAC_KEY_END),
30
+ patchMacHmacKey: derived.subarray(APP_STATE_DERIVED_SNAPSHOT_MAC_KEY_END, APP_STATE_DERIVED_PATCH_MAC_KEY_END)
37
31
  };
38
32
  }
39
33
  async encryptMutation(input) {
40
- const derivedKeys = await this.deriveKeys(input.keyData);
34
+ const derivedKeys = this.deriveKeys(input.keyData);
41
35
  const indexBytes = new TextEncoder().encode(input.index);
42
36
  const encoded = protos_1.proto.SyncActionData.encode({
43
37
  index: indexBytes,
@@ -49,33 +43,34 @@ class FakeAppStateCrypto {
49
43
  if (iv.byteLength !== APP_STATE_IV_LENGTH) {
50
44
  throw new Error(`invalid IV length ${iv.byteLength}`);
51
45
  }
52
- const indexMac = await (0, crypto_1.hmacSign)(derivedKeys.indexHmacKey, indexBytes);
53
- const cipherText = await (0, crypto_1.aesCbcEncrypt)(derivedKeys.valueEncryptionAesKey, iv, encoded);
46
+ const indexMac = (0, crypto_1.hmacSha256Sign)(derivedKeys.indexHmacKey, indexBytes);
47
+ const cipherText = (0, crypto_1.aesCbcEncrypt)(derivedKeys.valueEncryptionAesKey, iv, encoded);
54
48
  const cipherWithIv = concatBytes([iv, cipherText]);
55
49
  const associatedData = generateAssociatedData(input.operation, input.keyId);
56
- const valueMac = await this.generateValueMac(derivedKeys.valueMacHmacKey, associatedData, cipherWithIv);
50
+ const valueMac = this.generateValueMac(derivedKeys.valueMacHmacKey, associatedData, cipherWithIv);
57
51
  return {
58
52
  indexMac,
59
53
  valueBlob: concatBytes([cipherWithIv, valueMac]),
60
54
  valueMac
61
55
  };
62
56
  }
57
+ // eslint-disable-next-line @typescript-eslint/require-await
63
58
  async decryptMutation(input) {
64
59
  if (input.valueBlob.byteLength < APP_STATE_IV_LENGTH + APP_STATE_VALUE_MAC_LENGTH) {
65
60
  throw new Error('invalid mutation value blob');
66
61
  }
67
- const derivedKeys = await this.deriveKeys(input.keyData);
62
+ const derivedKeys = this.deriveKeys(input.keyData);
68
63
  const iv = input.valueBlob.subarray(0, APP_STATE_IV_LENGTH);
69
64
  const macStart = input.valueBlob.byteLength - APP_STATE_VALUE_MAC_LENGTH;
70
65
  const valueMac = input.valueBlob.subarray(macStart);
71
66
  const cipherText = input.valueBlob.subarray(APP_STATE_IV_LENGTH, macStart);
72
67
  const cipherWithIv = input.valueBlob.subarray(0, macStart);
73
68
  const associatedData = generateAssociatedData(input.operation, input.keyId);
74
- const expectedMac = await this.generateValueMac(derivedKeys.valueMacHmacKey, associatedData, cipherWithIv);
69
+ const expectedMac = this.generateValueMac(derivedKeys.valueMacHmacKey, associatedData, cipherWithIv);
75
70
  if (!uint8Equal(expectedMac, valueMac)) {
76
71
  throw new Error('mutation value MAC mismatch');
77
72
  }
78
- const plaintext = await (0, crypto_1.aesCbcDecrypt)(derivedKeys.valueEncryptionAesKey, iv, cipherText);
73
+ const plaintext = (0, crypto_1.aesCbcDecrypt)(derivedKeys.valueEncryptionAesKey, iv, cipherText);
79
74
  const syncActionData = protos_1.proto.SyncActionData.decode(plaintext);
80
75
  if (!syncActionData.index) {
81
76
  throw new Error('missing sync action index');
@@ -83,7 +78,7 @@ class FakeAppStateCrypto {
83
78
  if (syncActionData.version === null || syncActionData.version === undefined) {
84
79
  throw new Error('missing sync action version');
85
80
  }
86
- const generatedIndexMac = await (0, crypto_1.hmacSign)(derivedKeys.indexHmacKey, syncActionData.index);
81
+ const generatedIndexMac = (0, crypto_1.hmacSha256Sign)(derivedKeys.indexHmacKey, syncActionData.index);
87
82
  if (!uint8Equal(generatedIndexMac, input.indexMac)) {
88
83
  throw new Error('mutation index MAC mismatch');
89
84
  }
@@ -95,36 +90,40 @@ class FakeAppStateCrypto {
95
90
  valueMac
96
91
  };
97
92
  }
93
+ // eslint-disable-next-line @typescript-eslint/require-await
98
94
  async generateSnapshotMac(keyData, ltHash, version, collectionName) {
99
- const derivedKeys = await this.deriveKeys(keyData);
95
+ const derivedKeys = this.deriveKeys(keyData);
100
96
  const payload = concatBytes([
101
97
  ltHash,
102
98
  intToBytesBe(8, version),
103
99
  new TextEncoder().encode(collectionName)
104
100
  ]);
105
- return (0, crypto_1.hmacSign)(derivedKeys.snapshotMacHmacKey, payload);
101
+ return (0, crypto_1.hmacSha256Sign)(derivedKeys.snapshotMacHmacKey, payload);
106
102
  }
103
+ // eslint-disable-next-line @typescript-eslint/require-await
107
104
  async generatePatchMac(keyData, snapshotMac, valueMacs, version, collectionName) {
108
- const derivedKeys = await this.deriveKeys(keyData);
105
+ const derivedKeys = this.deriveKeys(keyData);
109
106
  const payload = concatBytes([
110
107
  snapshotMac,
111
108
  ...valueMacs,
112
109
  intToBytesBe(8, version),
113
110
  new TextEncoder().encode(collectionName)
114
111
  ]);
115
- return (0, crypto_1.hmacSign)(derivedKeys.patchMacHmacKey, payload);
112
+ return (0, crypto_1.hmacSha256Sign)(derivedKeys.patchMacHmacKey, payload);
116
113
  }
114
+ // eslint-disable-next-line @typescript-eslint/require-await
117
115
  async ltHashAdd(base, addValues) {
118
116
  return this.ltHashApply(base, addValues, (left, right) => left + right);
119
117
  }
118
+ // eslint-disable-next-line @typescript-eslint/require-await
120
119
  async ltHashSubtract(base, removeValues) {
121
120
  return this.ltHashApply(base, removeValues, (left, right) => left - right);
122
121
  }
123
- async ltHashApply(base, values, combine) {
122
+ ltHashApply(base, values, combine) {
124
123
  if (values.length === 0) {
125
124
  return base.slice();
126
125
  }
127
- const expandedValues = await Promise.all(values.map((value) => (0, crypto_1.hkdf)(value, null, KDF_INFO_PATCH_INTEGRITY, APP_STATE_LT_HASH_SIZE)));
126
+ const expandedValues = values.map((value) => (0, crypto_1.hkdf)(value, null, KDF_INFO_PATCH_INTEGRITY, APP_STATE_LT_HASH_SIZE));
128
127
  const out = new Uint8Array(base.byteLength);
129
128
  pointwise(base, expandedValues[0], combine, out);
130
129
  for (let index = 1; index < expandedValues.length; index += 1) {
@@ -132,10 +131,10 @@ class FakeAppStateCrypto {
132
131
  }
133
132
  return out;
134
133
  }
135
- async generateValueMac(valueMacHmacKey, associatedData, cipherWithIv) {
134
+ generateValueMac(valueMacHmacKey, associatedData, cipherWithIv) {
136
135
  const octetLength = new Uint8Array(APP_STATE_MAC_OCTET_LENGTH);
137
136
  octetLength[octetLength.length - 1] = associatedData.byteLength & 0xff;
138
- const full = await (0, crypto_1.hmacSign)(valueMacHmacKey, concatBytes([associatedData, cipherWithIv, octetLength]));
137
+ const full = (0, crypto_1.hmacSha512Sign)(valueMacHmacKey, concatBytes([associatedData, cipherWithIv, octetLength]));
139
138
  return full.subarray(0, APP_STATE_VALUE_MAC_LENGTH);
140
139
  }
141
140
  }
@@ -199,4 +198,3 @@ function concatBytes(parts) {
199
198
  }
200
199
  return out;
201
200
  }
202
- //# sourceMappingURL=fake-app-state-crypto.js.map
@@ -35,4 +35,3 @@ export declare class FakePeerDoubleRatchet {
35
35
  private runRecvRatchetStep;
36
36
  private rotateSendRatchet;
37
37
  }
38
- //# sourceMappingURL=fake-peer-double-ratchet.d.ts.map
@@ -4,11 +4,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.FakePeerDoubleRatchet = exports.FakePeerDoubleRatchetError = void 0;
5
5
  const crypto_1 = require("../../transport/crypto");
6
6
  const protos_1 = require("../../transport/protos");
7
+ const util_1 = require("../../transport/util");
7
8
  const SIGNAL_VERSION = 3;
8
9
  const SIGNAL_MAC_SIZE = 8;
9
10
  const SIGNAL_PREFIX_FF = new Uint8Array(32).fill(0xff);
10
11
  const MESSAGE_KEY_LABEL = new Uint8Array([1]);
11
12
  const CHAIN_KEY_LABEL = new Uint8Array([2]);
13
+ const WHISPER_TEXT_INFO = util_1.TEXT_ENCODER.encode('WhisperText');
14
+ const WHISPER_RATCHET_INFO = util_1.TEXT_ENCODER.encode('WhisperRatchet');
15
+ const WHISPER_MESSAGE_KEYS_INFO = util_1.TEXT_ENCODER.encode('WhisperMessageKeys');
12
16
  class FakePeerDoubleRatchetError extends Error {
13
17
  constructor(message) {
14
18
  super(message);
@@ -58,11 +62,11 @@ class FakePeerDoubleRatchet {
58
62
  if (dh4)
59
63
  sharedParts.push(dh4);
60
64
  const shared = concatBytes(sharedParts);
61
- const [rootKey, _chainKey] = await (0, crypto_1.hkdfSplit)(shared, null, 'WhisperText');
65
+ const [rootKey, _chainKey] = (0, crypto_1.hkdfSplit)(shared, null, WHISPER_TEXT_INFO);
62
66
  void _chainKey;
63
67
  const sendRatchet = await crypto_1.X25519.generateKeyPair();
64
68
  const ratchetSecret = await crypto_1.X25519.scalarMult(sendRatchet.privKey, (0, crypto_1.toRawPubKey)(remoteSigned));
65
- const [nextRootKey, sendChainKey] = await (0, crypto_1.hkdfSplit)(ratchetSecret, rootKey, 'WhisperRatchet');
69
+ const [nextRootKey, sendChainKey] = (0, crypto_1.hkdfSplit)(ratchetSecret, rootKey, WHISPER_RATCHET_INFO);
66
70
  this.rootKey = nextRootKey;
67
71
  this.remoteIdentityPubSerialized = remoteIdentity;
68
72
  this.sendChain = {
@@ -78,6 +82,7 @@ class FakePeerDoubleRatchet {
78
82
  baseKey: localBaseSerialized
79
83
  };
80
84
  }
85
+ // eslint-disable-next-line @typescript-eslint/require-await
81
86
  async encrypt(plaintext) {
82
87
  if (!this.sendChain) {
83
88
  throw new FakePeerDoubleRatchetError('cannot encrypt: session has no send chain (call initiateOutbound first)');
@@ -85,12 +90,8 @@ class FakePeerDoubleRatchet {
85
90
  if (!this.remoteIdentityPubSerialized) {
86
91
  throw new FakePeerDoubleRatchetError('remote identity not set');
87
92
  }
88
- const { nextChainKey, messageKey } = await deriveMessageKey(this.sendChain.nextIndex, this.sendChain.chainKey);
89
- const [cipherKey, macKey] = await Promise.all([
90
- (0, crypto_1.importAesCbcKey)(messageKey.cipherKey),
91
- (0, crypto_1.importHmacKey)(messageKey.macKey)
92
- ]);
93
- const ciphertext = await (0, crypto_1.aesCbcEncrypt)(cipherKey, messageKey.iv, plaintext);
93
+ const { nextChainKey, messageKey } = deriveMessageKey(this.sendChain.nextIndex, this.sendChain.chainKey);
94
+ const ciphertext = (0, crypto_1.aesCbcEncrypt)(messageKey.cipherKey, messageKey.iv, plaintext);
94
95
  const signalPayload = protos_1.proto.SignalMessage.encode({
95
96
  ratchetKey: this.sendChain.ratchetPubSerialized,
96
97
  counter: messageKey.index,
@@ -103,7 +104,7 @@ class FakePeerDoubleRatchet {
103
104
  this.remoteIdentityPubSerialized,
104
105
  versioned
105
106
  ]);
106
- const fullMac = await (0, crypto_1.hmacSign)(macKey, macInput);
107
+ const fullMac = (0, crypto_1.hmacSha256Sign)(messageKey.macKey, macInput);
107
108
  const mac = fullMac.subarray(0, SIGNAL_MAC_SIZE);
108
109
  const inner = concatBytes([versioned, mac]);
109
110
  this.sendChain = {
@@ -167,7 +168,7 @@ class FakePeerDoubleRatchet {
167
168
  if (dh4)
168
169
  sharedParts.push(dh4);
169
170
  const shared = concatBytes(sharedParts);
170
- const [rootKey, chainKey] = await (0, crypto_1.hkdfSplit)(shared, null, 'WhisperText');
171
+ const [rootKey, chainKey] = (0, crypto_1.hkdfSplit)(shared, null, WHISPER_TEXT_INFO);
171
172
  this.remoteIdentityPubSerialized = (0, crypto_1.toSerializedPubKey)(remoteIdentity);
172
173
  this.rootKey = rootKey;
173
174
  this.bootstrapChainKey = chainKey;
@@ -201,7 +202,7 @@ class FakePeerDoubleRatchet {
201
202
  throw new FakePeerDoubleRatchetError('bootstrap state missing');
202
203
  }
203
204
  const ratchetShared = await crypto_1.X25519.scalarMult(this.keyBundle.signedPreKey.keyPair.privKey, (0, crypto_1.toRawPubKey)(ratchetKey));
204
- const [nextRootKey, recvChainKey] = await (0, crypto_1.hkdfSplit)(ratchetShared, this.rootKey, 'WhisperRatchet');
205
+ const [nextRootKey, recvChainKey] = (0, crypto_1.hkdfSplit)(ratchetShared, this.rootKey, WHISPER_RATCHET_INFO);
205
206
  this.rootKey = nextRootKey;
206
207
  this.bootstrapChainKey = null;
207
208
  this.recvChain = {
@@ -247,7 +248,7 @@ class FakePeerDoubleRatchet {
247
248
  const newlyStashed = [];
248
249
  let walkIndex = this.recvChain.nextIndex;
249
250
  while (walkIndex <= counter) {
250
- const derived = await deriveMessageKeyFromChain(chainKey);
251
+ const derived = deriveMessageKeyFromChain(chainKey);
251
252
  chainKey = derived.nextChainKey;
252
253
  if (walkIndex === counter) {
253
254
  messageKey = derived.messageKey;
@@ -284,14 +285,12 @@ class FakePeerDoubleRatchet {
284
285
  this.localIdentityPubSerialized,
285
286
  versionedBody
286
287
  ]);
287
- const macKeyHandle = await (0, crypto_1.importHmacKey)(messageKey.macKey);
288
- const expectedFullMac = await (0, crypto_1.hmacSign)(macKeyHandle, macInput);
288
+ const expectedFullMac = (0, crypto_1.hmacSha256Sign)(messageKey.macKey, macInput);
289
289
  const expectedMac = expectedFullMac.subarray(0, SIGNAL_MAC_SIZE);
290
290
  if (!uint8Equal(expectedMac, macBytes)) {
291
291
  throw new FakePeerDoubleRatchetError('signal message MAC mismatch');
292
292
  }
293
- const cipherKeyHandle = await (0, crypto_1.importAesCbcKey)(messageKey.cipherKey);
294
- const padded = await (0, crypto_1.aesCbcDecrypt)(cipherKeyHandle, messageKey.iv, ciphertext);
293
+ const padded = (0, crypto_1.aesCbcDecrypt)(messageKey.cipherKey, messageKey.iv, ciphertext);
295
294
  return unpadPkcs7(padded);
296
295
  }
297
296
  async runRecvRatchetStep(remoteRatchetPub) {
@@ -303,7 +302,7 @@ class FakePeerDoubleRatchet {
303
302
  }
304
303
  const remoteRatchetRaw = (0, crypto_1.toRawPubKey)(remoteRatchetPub);
305
304
  const ratchetShared = await crypto_1.X25519.scalarMult(this.sendChain.ratchetKeyPair.privKey, remoteRatchetRaw);
306
- const [nextRootKey, recvChainKey] = await (0, crypto_1.hkdfSplit)(ratchetShared, this.rootKey, 'WhisperRatchet');
305
+ const [nextRootKey, recvChainKey] = (0, crypto_1.hkdfSplit)(ratchetShared, this.rootKey, WHISPER_RATCHET_INFO);
307
306
  this.rootKey = nextRootKey;
308
307
  this.recvChain = {
309
308
  ratchetPubKey: (0, crypto_1.toSerializedPubKey)(remoteRatchetPub),
@@ -319,7 +318,7 @@ class FakePeerDoubleRatchet {
319
318
  }
320
319
  const newRatchet = await crypto_1.X25519.generateKeyPair();
321
320
  const ratchetShared = await crypto_1.X25519.scalarMult(newRatchet.privKey, (0, crypto_1.toRawPubKey)(remoteRatchetPub));
322
- const [nextRootKey, sendChainKey] = await (0, crypto_1.hkdfSplit)(ratchetShared, this.rootKey, 'WhisperRatchet');
321
+ const [nextRootKey, sendChainKey] = (0, crypto_1.hkdfSplit)(ratchetShared, this.rootKey, WHISPER_RATCHET_INFO);
323
322
  this.rootKey = nextRootKey;
324
323
  this.sendChain = {
325
324
  ratchetKeyPair: newRatchet,
@@ -331,13 +330,10 @@ class FakePeerDoubleRatchet {
331
330
  }
332
331
  }
333
332
  exports.FakePeerDoubleRatchet = FakePeerDoubleRatchet;
334
- async function deriveMessageKey(index, chainKey) {
335
- const hmacKey = await (0, crypto_1.importHmacKey)(chainKey);
336
- const [messageInputKey, nextChainRaw] = await Promise.all([
337
- (0, crypto_1.hmacSign)(hmacKey, MESSAGE_KEY_LABEL),
338
- (0, crypto_1.hmacSign)(hmacKey, CHAIN_KEY_LABEL)
339
- ]);
340
- const expanded = await (0, crypto_1.hkdf)(messageInputKey, null, 'WhisperMessageKeys', 80);
333
+ function deriveMessageKey(index, chainKey) {
334
+ const messageInputKey = (0, crypto_1.hmacSha256Sign)(chainKey, MESSAGE_KEY_LABEL);
335
+ const nextChainRaw = (0, crypto_1.hmacSha256Sign)(chainKey, CHAIN_KEY_LABEL);
336
+ const expanded = (0, crypto_1.hkdf)(messageInputKey, null, WHISPER_MESSAGE_KEYS_INFO, 80);
341
337
  return {
342
338
  nextChainKey: nextChainRaw.subarray(0, 32),
343
339
  messageKey: {
@@ -348,8 +344,8 @@ async function deriveMessageKey(index, chainKey) {
348
344
  }
349
345
  };
350
346
  }
351
- async function deriveMessageKeyFromChain(chainKey) {
352
- const result = await deriveMessageKey(0, chainKey);
347
+ function deriveMessageKeyFromChain(chainKey) {
348
+ const result = deriveMessageKey(0, chainKey);
353
349
  return {
354
350
  nextChainKey: result.nextChainKey,
355
351
  messageKey: {
@@ -405,4 +401,3 @@ function requireBytes(value, label) {
405
401
  throw new FakePeerDoubleRatchetError(`${label} missing`);
406
402
  return value;
407
403
  }
408
- //# sourceMappingURL=fake-peer-double-ratchet.js.map
@@ -7,4 +7,3 @@ export declare class FakePeerGroupRecvSession {
7
7
  addDistribution(groupId: string, senderJid: string, axolotlBytes: Uint8Array): void;
8
8
  decryptGroupMessage(groupId: string, senderJid: string, skmsgBytes: Uint8Array): Promise<Uint8Array>;
9
9
  }
10
- //# sourceMappingURL=fake-peer-group-recv-session.d.ts.map