@zapo-js/fake-server 0.3.0 → 1.0.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 (298) hide show
  1. package/README.md +3 -3
  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 +201 -1
  8. package/dist/api/FakeWaServer.d.ts +11 -1
  9. package/dist/api/FakeWaServer.js +34 -2
  10. package/dist/api/PreKeyDispenser.d.ts +0 -1
  11. package/dist/api/PreKeyDispenser.js +0 -1
  12. package/dist/api/Scenario.d.ts +0 -1
  13. package/dist/api/Scenario.js +0 -1
  14. package/dist/api/ServerRegistries.d.ts +0 -1
  15. package/dist/api/ServerRegistries.js +0 -1
  16. package/dist/api/iq-handlers.d.ts +0 -1
  17. package/dist/api/iq-handlers.js +0 -1
  18. package/dist/{cli.d.ts → bin.d.ts} +0 -1
  19. package/dist/{cli.js → bin.js} +1 -2
  20. package/dist/esm/api/AppStateSyncManager.js +146 -0
  21. package/dist/esm/api/FakePairingDriver.js +31 -0
  22. package/dist/esm/api/FakePeer.js +604 -0
  23. package/dist/esm/api/FakeWaServer.js +680 -0
  24. package/dist/esm/api/PreKeyDispenser.js +93 -0
  25. package/dist/esm/api/Scenario.js +32 -0
  26. package/dist/esm/api/ServerRegistries.js +261 -0
  27. package/dist/esm/api/iq-handlers.js +492 -0
  28. package/dist/esm/bin.js +246 -0
  29. package/dist/esm/index.js +26 -0
  30. package/dist/esm/infra/WaFakeConnection.js +49 -0
  31. package/dist/esm/infra/WaFakeConnectionPipeline.js +223 -0
  32. package/dist/esm/infra/WaFakeFrameSocket.js +117 -0
  33. package/dist/esm/infra/WaFakeMediaHttpsServer.js +126 -0
  34. package/dist/esm/infra/WaFakeNoiseHandshake.js +67 -0
  35. package/dist/esm/infra/WaFakeTransport.js +31 -0
  36. package/dist/esm/infra/WaFakeWsServer.js +96 -0
  37. package/dist/esm/package.json +3 -0
  38. package/dist/esm/protocol/auth/cert-chain.js +39 -0
  39. package/dist/esm/protocol/auth/client-payload-validate.js +55 -0
  40. package/dist/esm/protocol/auth/fake-primary-device.js +47 -0
  41. package/dist/esm/protocol/auth/pair-device.js +87 -0
  42. package/dist/esm/protocol/auth/success-node.js +26 -0
  43. package/dist/esm/protocol/iq/abprops.js +30 -0
  44. package/dist/esm/protocol/iq/appstate-sync.js +146 -0
  45. package/dist/esm/protocol/iq/business.js +59 -0
  46. package/dist/esm/protocol/iq/dirty-bits.js +19 -0
  47. package/dist/esm/protocol/iq/group-ops.js +154 -0
  48. package/dist/esm/protocol/iq/newsletter.js +14 -0
  49. package/dist/esm/protocol/iq/prekey-fetch.js +88 -0
  50. package/dist/esm/protocol/iq/privacy-token.js +26 -0
  51. package/dist/esm/protocol/iq/privacy.js +123 -0
  52. package/dist/esm/protocol/iq/profile.js +72 -0
  53. package/dist/esm/protocol/iq/router.js +111 -0
  54. package/dist/esm/protocol/iq/usync.js +64 -0
  55. package/dist/esm/protocol/push/app-state-key-share.js +26 -0
  56. package/dist/esm/protocol/push/call-failure.js +27 -0
  57. package/dist/esm/protocol/push/chatstate.js +23 -0
  58. package/dist/esm/protocol/push/error-stanza.js +13 -0
  59. package/dist/esm/protocol/push/history-sync.js +111 -0
  60. package/dist/esm/protocol/push/message.js +38 -0
  61. package/dist/esm/protocol/push/notification.js +29 -0
  62. package/dist/esm/protocol/push/presence.js +14 -0
  63. package/dist/esm/protocol/push/receipt.js +21 -0
  64. package/dist/esm/protocol/signal/fake-app-state-crypto.js +196 -0
  65. package/dist/esm/protocol/signal/fake-peer-double-ratchet.js +398 -0
  66. package/dist/esm/protocol/signal/fake-peer-group-recv-session.js +120 -0
  67. package/dist/esm/protocol/signal/fake-peer-identity.js +8 -0
  68. package/dist/esm/protocol/signal/fake-peer-key-bundle.js +25 -0
  69. package/dist/esm/protocol/signal/fake-sender-key.js +83 -0
  70. package/dist/esm/protocol/signal/prekey-upload.js +107 -0
  71. package/dist/esm/protocol/stream/stream-error.js +56 -0
  72. package/dist/esm/state/fake-app-state-collection.js +134 -0
  73. package/dist/esm/state/fake-media-store.js +53 -0
  74. package/dist/esm/transport/codec.js +8 -0
  75. package/dist/esm/transport/crypto.js +8 -0
  76. package/dist/esm/transport/protos.js +7 -0
  77. package/dist/esm/transport/util.js +8 -0
  78. package/dist/index.d.ts +0 -1
  79. package/dist/index.js +0 -1
  80. package/dist/infra/WaFakeConnection.d.ts +0 -1
  81. package/dist/infra/WaFakeConnection.js +0 -1
  82. package/dist/infra/WaFakeConnectionPipeline.d.ts +0 -1
  83. package/dist/infra/WaFakeConnectionPipeline.js +27 -24
  84. package/dist/infra/WaFakeFrameSocket.d.ts +0 -1
  85. package/dist/infra/WaFakeFrameSocket.js +0 -1
  86. package/dist/infra/WaFakeMediaHttpsServer.d.ts +0 -1
  87. package/dist/infra/WaFakeMediaHttpsServer.js +0 -1
  88. package/dist/infra/WaFakeNoiseHandshake.d.ts +8 -10
  89. package/dist/infra/WaFakeNoiseHandshake.js +19 -24
  90. package/dist/infra/WaFakeTransport.d.ts +2 -4
  91. package/dist/infra/WaFakeTransport.js +2 -1
  92. package/dist/infra/WaFakeWsServer.d.ts +0 -1
  93. package/dist/infra/WaFakeWsServer.js +0 -1
  94. package/dist/protocol/auth/cert-chain.d.ts +0 -1
  95. package/dist/protocol/auth/cert-chain.js +0 -1
  96. package/dist/protocol/auth/client-payload-validate.d.ts +0 -1
  97. package/dist/protocol/auth/client-payload-validate.js +0 -1
  98. package/dist/protocol/auth/fake-primary-device.d.ts +0 -1
  99. package/dist/protocol/auth/fake-primary-device.js +1 -3
  100. package/dist/protocol/auth/pair-device.d.ts +0 -1
  101. package/dist/protocol/auth/pair-device.js +4 -16
  102. package/dist/protocol/auth/success-node.d.ts +0 -1
  103. package/dist/protocol/auth/success-node.js +0 -1
  104. package/dist/protocol/iq/abprops.d.ts +0 -1
  105. package/dist/protocol/iq/abprops.js +0 -1
  106. package/dist/protocol/iq/appstate-sync.d.ts +0 -1
  107. package/dist/protocol/iq/appstate-sync.js +0 -1
  108. package/dist/protocol/iq/business.d.ts +0 -1
  109. package/dist/protocol/iq/business.js +0 -1
  110. package/dist/protocol/iq/dirty-bits.d.ts +0 -1
  111. package/dist/protocol/iq/dirty-bits.js +0 -1
  112. package/dist/protocol/iq/group-ops.d.ts +0 -1
  113. package/dist/protocol/iq/group-ops.js +0 -1
  114. package/dist/protocol/iq/newsletter.d.ts +0 -1
  115. package/dist/protocol/iq/newsletter.js +0 -1
  116. package/dist/protocol/iq/prekey-fetch.d.ts +0 -1
  117. package/dist/protocol/iq/prekey-fetch.js +0 -1
  118. package/dist/protocol/iq/privacy-token.d.ts +0 -1
  119. package/dist/protocol/iq/privacy-token.js +0 -1
  120. package/dist/protocol/iq/privacy.d.ts +0 -1
  121. package/dist/protocol/iq/privacy.js +15 -16
  122. package/dist/protocol/iq/profile.d.ts +0 -1
  123. package/dist/protocol/iq/profile.js +0 -1
  124. package/dist/protocol/iq/router.d.ts +0 -1
  125. package/dist/protocol/iq/router.js +0 -1
  126. package/dist/protocol/iq/usync.d.ts +0 -1
  127. package/dist/protocol/iq/usync.js +0 -1
  128. package/dist/protocol/push/app-state-key-share.d.ts +0 -1
  129. package/dist/protocol/push/app-state-key-share.js +0 -1
  130. package/dist/protocol/push/call-failure.d.ts +0 -1
  131. package/dist/protocol/push/call-failure.js +0 -1
  132. package/dist/protocol/push/chatstate.d.ts +0 -1
  133. package/dist/protocol/push/chatstate.js +0 -1
  134. package/dist/protocol/push/error-stanza.d.ts +0 -1
  135. package/dist/protocol/push/error-stanza.js +0 -1
  136. package/dist/protocol/push/history-sync.d.ts +0 -1
  137. package/dist/protocol/push/history-sync.js +0 -1
  138. package/dist/protocol/push/message.d.ts +0 -1
  139. package/dist/protocol/push/message.js +0 -1
  140. package/dist/protocol/push/notification.d.ts +0 -1
  141. package/dist/protocol/push/notification.js +0 -1
  142. package/dist/protocol/push/presence.d.ts +0 -1
  143. package/dist/protocol/push/presence.js +0 -1
  144. package/dist/protocol/push/receipt.d.ts +0 -1
  145. package/dist/protocol/push/receipt.js +0 -1
  146. package/dist/protocol/signal/fake-app-state-crypto.d.ts +7 -9
  147. package/dist/protocol/signal/fake-app-state-crypto.js +31 -33
  148. package/dist/protocol/signal/fake-peer-double-ratchet.d.ts +0 -1
  149. package/dist/protocol/signal/fake-peer-double-ratchet.js +23 -28
  150. package/dist/protocol/signal/fake-peer-group-recv-session.d.ts +0 -1
  151. package/dist/protocol/signal/fake-peer-group-recv-session.js +6 -10
  152. package/dist/protocol/signal/fake-peer-identity.d.ts +0 -1
  153. package/dist/protocol/signal/fake-peer-identity.js +0 -1
  154. package/dist/protocol/signal/fake-peer-key-bundle.d.ts +0 -1
  155. package/dist/protocol/signal/fake-peer-key-bundle.js +0 -1
  156. package/dist/protocol/signal/fake-sender-key.d.ts +0 -1
  157. package/dist/protocol/signal/fake-sender-key.js +5 -9
  158. package/dist/protocol/signal/prekey-upload.d.ts +0 -1
  159. package/dist/protocol/signal/prekey-upload.js +0 -1
  160. package/dist/protocol/stream/stream-error.d.ts +0 -1
  161. package/dist/protocol/stream/stream-error.js +0 -1
  162. package/dist/state/fake-app-state-collection.d.ts +0 -1
  163. package/dist/state/fake-app-state-collection.js +0 -1
  164. package/dist/state/fake-media-store.d.ts +0 -1
  165. package/dist/state/fake-media-store.js +2 -2
  166. package/dist/transport/codec.d.ts +2 -3
  167. package/dist/transport/codec.js +2 -3
  168. package/dist/transport/crypto.d.ts +5 -7
  169. package/dist/transport/crypto.js +6 -11
  170. package/dist/transport/protos.d.ts +2 -4
  171. package/dist/transport/protos.js +2 -4
  172. package/dist/transport/util.d.ts +8 -0
  173. package/dist/transport/util.js +15 -0
  174. package/package.json +21 -6
  175. package/dist/api/AppStateSyncManager.d.ts.map +0 -1
  176. package/dist/api/AppStateSyncManager.js.map +0 -1
  177. package/dist/api/FakePairingDriver.d.ts.map +0 -1
  178. package/dist/api/FakePairingDriver.js.map +0 -1
  179. package/dist/api/FakePeer.d.ts.map +0 -1
  180. package/dist/api/FakePeer.js.map +0 -1
  181. package/dist/api/FakeWaServer.d.ts.map +0 -1
  182. package/dist/api/FakeWaServer.js.map +0 -1
  183. package/dist/api/PreKeyDispenser.d.ts.map +0 -1
  184. package/dist/api/PreKeyDispenser.js.map +0 -1
  185. package/dist/api/Scenario.d.ts.map +0 -1
  186. package/dist/api/Scenario.js.map +0 -1
  187. package/dist/api/ServerRegistries.d.ts.map +0 -1
  188. package/dist/api/ServerRegistries.js.map +0 -1
  189. package/dist/api/iq-handlers.d.ts.map +0 -1
  190. package/dist/api/iq-handlers.js.map +0 -1
  191. package/dist/cli.d.ts.map +0 -1
  192. package/dist/cli.js.map +0 -1
  193. package/dist/index.d.ts.map +0 -1
  194. package/dist/index.js.map +0 -1
  195. package/dist/infra/WaFakeConnection.d.ts.map +0 -1
  196. package/dist/infra/WaFakeConnection.js.map +0 -1
  197. package/dist/infra/WaFakeConnectionPipeline.d.ts.map +0 -1
  198. package/dist/infra/WaFakeConnectionPipeline.js.map +0 -1
  199. package/dist/infra/WaFakeFrameSocket.d.ts.map +0 -1
  200. package/dist/infra/WaFakeFrameSocket.js.map +0 -1
  201. package/dist/infra/WaFakeMediaHttpsServer.d.ts.map +0 -1
  202. package/dist/infra/WaFakeMediaHttpsServer.js.map +0 -1
  203. package/dist/infra/WaFakeNoiseHandshake.d.ts.map +0 -1
  204. package/dist/infra/WaFakeNoiseHandshake.js.map +0 -1
  205. package/dist/infra/WaFakeTransport.d.ts.map +0 -1
  206. package/dist/infra/WaFakeTransport.js.map +0 -1
  207. package/dist/infra/WaFakeWsServer.d.ts.map +0 -1
  208. package/dist/infra/WaFakeWsServer.js.map +0 -1
  209. package/dist/protocol/auth/cert-chain.d.ts.map +0 -1
  210. package/dist/protocol/auth/cert-chain.js.map +0 -1
  211. package/dist/protocol/auth/client-payload-validate.d.ts.map +0 -1
  212. package/dist/protocol/auth/client-payload-validate.js.map +0 -1
  213. package/dist/protocol/auth/fake-primary-device.d.ts.map +0 -1
  214. package/dist/protocol/auth/fake-primary-device.js.map +0 -1
  215. package/dist/protocol/auth/pair-device.d.ts.map +0 -1
  216. package/dist/protocol/auth/pair-device.js.map +0 -1
  217. package/dist/protocol/auth/success-node.d.ts.map +0 -1
  218. package/dist/protocol/auth/success-node.js.map +0 -1
  219. package/dist/protocol/iq/abprops.d.ts.map +0 -1
  220. package/dist/protocol/iq/abprops.js.map +0 -1
  221. package/dist/protocol/iq/appstate-sync.d.ts.map +0 -1
  222. package/dist/protocol/iq/appstate-sync.js.map +0 -1
  223. package/dist/protocol/iq/business.d.ts.map +0 -1
  224. package/dist/protocol/iq/business.js.map +0 -1
  225. package/dist/protocol/iq/dirty-bits.d.ts.map +0 -1
  226. package/dist/protocol/iq/dirty-bits.js.map +0 -1
  227. package/dist/protocol/iq/group-ops.d.ts.map +0 -1
  228. package/dist/protocol/iq/group-ops.js.map +0 -1
  229. package/dist/protocol/iq/newsletter.d.ts.map +0 -1
  230. package/dist/protocol/iq/newsletter.js.map +0 -1
  231. package/dist/protocol/iq/prekey-fetch.d.ts.map +0 -1
  232. package/dist/protocol/iq/prekey-fetch.js.map +0 -1
  233. package/dist/protocol/iq/privacy-token.d.ts.map +0 -1
  234. package/dist/protocol/iq/privacy-token.js.map +0 -1
  235. package/dist/protocol/iq/privacy.d.ts.map +0 -1
  236. package/dist/protocol/iq/privacy.js.map +0 -1
  237. package/dist/protocol/iq/profile.d.ts.map +0 -1
  238. package/dist/protocol/iq/profile.js.map +0 -1
  239. package/dist/protocol/iq/router.d.ts.map +0 -1
  240. package/dist/protocol/iq/router.js.map +0 -1
  241. package/dist/protocol/iq/usync.d.ts.map +0 -1
  242. package/dist/protocol/iq/usync.js.map +0 -1
  243. package/dist/protocol/push/app-state-key-share.d.ts.map +0 -1
  244. package/dist/protocol/push/app-state-key-share.js.map +0 -1
  245. package/dist/protocol/push/call-failure.d.ts.map +0 -1
  246. package/dist/protocol/push/call-failure.js.map +0 -1
  247. package/dist/protocol/push/chatstate.d.ts.map +0 -1
  248. package/dist/protocol/push/chatstate.js.map +0 -1
  249. package/dist/protocol/push/error-stanza.d.ts.map +0 -1
  250. package/dist/protocol/push/error-stanza.js.map +0 -1
  251. package/dist/protocol/push/history-sync.d.ts.map +0 -1
  252. package/dist/protocol/push/history-sync.js.map +0 -1
  253. package/dist/protocol/push/message.d.ts.map +0 -1
  254. package/dist/protocol/push/message.js.map +0 -1
  255. package/dist/protocol/push/notification.d.ts.map +0 -1
  256. package/dist/protocol/push/notification.js.map +0 -1
  257. package/dist/protocol/push/presence.d.ts.map +0 -1
  258. package/dist/protocol/push/presence.js.map +0 -1
  259. package/dist/protocol/push/receipt.d.ts.map +0 -1
  260. package/dist/protocol/push/receipt.js.map +0 -1
  261. package/dist/protocol/signal/fake-app-state-crypto.d.ts.map +0 -1
  262. package/dist/protocol/signal/fake-app-state-crypto.js.map +0 -1
  263. package/dist/protocol/signal/fake-peer-double-ratchet.d.ts.map +0 -1
  264. package/dist/protocol/signal/fake-peer-double-ratchet.js.map +0 -1
  265. package/dist/protocol/signal/fake-peer-group-recv-session.d.ts.map +0 -1
  266. package/dist/protocol/signal/fake-peer-group-recv-session.js.map +0 -1
  267. package/dist/protocol/signal/fake-peer-identity.d.ts.map +0 -1
  268. package/dist/protocol/signal/fake-peer-identity.js.map +0 -1
  269. package/dist/protocol/signal/fake-peer-key-bundle.d.ts.map +0 -1
  270. package/dist/protocol/signal/fake-peer-key-bundle.js.map +0 -1
  271. package/dist/protocol/signal/fake-peer-recv-session.d.ts +0 -60
  272. package/dist/protocol/signal/fake-peer-recv-session.d.ts.map +0 -1
  273. package/dist/protocol/signal/fake-peer-recv-session.js +0 -284
  274. package/dist/protocol/signal/fake-peer-recv-session.js.map +0 -1
  275. package/dist/protocol/signal/fake-peer-session.d.ts +0 -87
  276. package/dist/protocol/signal/fake-peer-session.d.ts.map +0 -1
  277. package/dist/protocol/signal/fake-peer-session.js +0 -207
  278. package/dist/protocol/signal/fake-peer-session.js.map +0 -1
  279. package/dist/protocol/signal/fake-sender-key.d.ts.map +0 -1
  280. package/dist/protocol/signal/fake-sender-key.js.map +0 -1
  281. package/dist/protocol/signal/prekey-upload.d.ts.map +0 -1
  282. package/dist/protocol/signal/prekey-upload.js.map +0 -1
  283. package/dist/protocol/stream/stream-error.d.ts.map +0 -1
  284. package/dist/protocol/stream/stream-error.js.map +0 -1
  285. package/dist/state/fake-app-state-collection.d.ts.map +0 -1
  286. package/dist/state/fake-app-state-collection.js.map +0 -1
  287. package/dist/state/fake-media-store.d.ts.map +0 -1
  288. package/dist/state/fake-media-store.js.map +0 -1
  289. package/dist/transport/codec.d.ts.map +0 -1
  290. package/dist/transport/codec.js.map +0 -1
  291. package/dist/transport/crypto.d.ts.map +0 -1
  292. package/dist/transport/crypto.js.map +0 -1
  293. package/dist/transport/index.d.ts +0 -4
  294. package/dist/transport/index.d.ts.map +0 -1
  295. package/dist/transport/index.js +0 -20
  296. package/dist/transport/index.js.map +0 -1
  297. package/dist/transport/protos.d.ts.map +0 -1
  298. package/dist/transport/protos.js.map +0 -1
@@ -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
@@ -4,11 +4,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.FakePeerGroupRecvSession = exports.FakePeerGroupRecvSessionError = 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_GROUP_VERSION = 3;
8
9
  const SIGNAL_SIGNATURE_LENGTH = 64;
9
10
  const MESSAGE_KEY_LABEL = new Uint8Array([1]);
10
11
  const CHAIN_KEY_LABEL = new Uint8Array([2]);
11
- const WHISPER_GROUP_INFO = 'WhisperGroup';
12
+ const WHISPER_GROUP_INFO = util_1.TEXT_ENCODER.encode('WhisperGroup');
12
13
  class FakePeerGroupRecvSessionError extends Error {
13
14
  constructor(message) {
14
15
  super(message);
@@ -88,12 +89,9 @@ class FakePeerGroupRecvSession {
88
89
  let seed = null;
89
90
  let iteration = record.nextIteration;
90
91
  while (iteration <= targetIteration) {
91
- const hmacKeyHandle = await (0, crypto_1.importHmacKey)(chainKey);
92
- const [nextChainRaw, messageInputKey] = await Promise.all([
93
- (0, crypto_1.hmacSign)(hmacKeyHandle, CHAIN_KEY_LABEL),
94
- (0, crypto_1.hmacSign)(hmacKeyHandle, MESSAGE_KEY_LABEL)
95
- ]);
96
- const messageSeed = await (0, crypto_1.hkdf)(messageInputKey, null, WHISPER_GROUP_INFO, 50);
92
+ const nextChainRaw = (0, crypto_1.hmacSha256Sign)(chainKey, CHAIN_KEY_LABEL);
93
+ const messageInputKey = (0, crypto_1.hmacSha256Sign)(chainKey, MESSAGE_KEY_LABEL);
94
+ const messageSeed = (0, crypto_1.hkdf)(messageInputKey, null, WHISPER_GROUP_INFO, 50);
97
95
  if (iteration === targetIteration) {
98
96
  seed = messageSeed;
99
97
  }
@@ -107,8 +105,7 @@ class FakePeerGroupRecvSession {
107
105
  record.nextIteration = iteration;
108
106
  const iv = seed.subarray(0, 16);
109
107
  const keyBytes = seed.subarray(16, 48);
110
- const cipherKey = await (0, crypto_1.importAesCbcKey)(keyBytes);
111
- const padded = await (0, crypto_1.aesCbcDecrypt)(cipherKey, iv, decoded.ciphertext);
108
+ const padded = (0, crypto_1.aesCbcDecrypt)(keyBytes, iv, decoded.ciphertext);
112
109
  return unpadPkcs7(padded);
113
110
  }
114
111
  }
@@ -126,4 +123,3 @@ function unpadPkcs7(padded) {
126
123
  return padded;
127
124
  return padded.subarray(0, padded.byteLength - padLen);
128
125
  }
129
- //# sourceMappingURL=fake-peer-group-recv-session.js.map
@@ -4,4 +4,3 @@ export interface FakePeerIdentity {
4
4
  readonly registrationId: number;
5
5
  }
6
6
  export declare function generateFakePeerIdentity(): Promise<FakePeerIdentity>;
7
- //# sourceMappingURL=fake-peer-identity.d.ts.map
@@ -9,4 +9,3 @@ async function generateFakePeerIdentity() {
9
9
  registrationId: Math.floor(Math.random() * 0x3fff) + 1
10
10
  };
11
11
  }
12
- //# sourceMappingURL=fake-peer-identity.js.map
@@ -21,4 +21,3 @@ export interface GenerateFakePeerKeyBundleOptions {
21
21
  readonly firstOneTimePreKeyId?: number;
22
22
  }
23
23
  export declare function generateFakePeerKeyBundle(options?: GenerateFakePeerKeyBundleOptions): Promise<FakePeerKeyBundle>;
24
- //# sourceMappingURL=fake-peer-key-bundle.d.ts.map
@@ -26,4 +26,3 @@ async function generateFakePeerKeyBundle(options = {}) {
26
26
  oneTimePreKeys
27
27
  };
28
28
  }
29
- //# sourceMappingURL=fake-peer-key-bundle.js.map
@@ -12,4 +12,3 @@ export declare class FakeSenderKey {
12
12
  encrypt(plaintext: Uint8Array): Promise<FakeSenderKeyEncryptionResult>;
13
13
  private buildDistributionMessage;
14
14
  }
15
- //# sourceMappingURL=fake-sender-key.d.ts.map
@@ -33,8 +33,7 @@ class FakeSenderKey {
33
33
  const distributionMessage = this.buildDistributionMessage();
34
34
  const { messageKey, nextChainKey } = await deriveSenderKeyMessageKey(this.state.iteration, this.state.chainKey);
35
35
  const { iv, cipherKey } = splitSenderKeyMessageSeed(messageKey.seed);
36
- const cipherKeyHandle = await (0, crypto_1.importAesCbcKey)(cipherKey);
37
- const ciphertext = await (0, crypto_1.aesCbcEncrypt)(cipherKeyHandle, iv, plaintext);
36
+ const ciphertext = (0, crypto_1.aesCbcEncrypt)(cipherKey, iv, plaintext);
38
37
  const senderKeyMessage = protos_1.proto.SenderKeyMessage.encode({
39
38
  id: this.state.id,
40
39
  iteration: messageKey.iteration,
@@ -67,13 +66,11 @@ class FakeSenderKey {
67
66
  }
68
67
  }
69
68
  exports.FakeSenderKey = FakeSenderKey;
69
+ // eslint-disable-next-line @typescript-eslint/require-await
70
70
  async function deriveSenderKeyMessageKey(iteration, chainKey) {
71
- const hmacKey = await (0, crypto_1.importHmacKey)(chainKey);
72
- const [messageInputKey, nextChainRaw] = await Promise.all([
73
- (0, crypto_1.hmacSign)(hmacKey, MESSAGE_KEY_LABEL),
74
- (0, crypto_1.hmacSign)(hmacKey, CHAIN_KEY_LABEL)
75
- ]);
76
- const seed = await (0, crypto_1.hkdf)(messageInputKey, null, WHISPER_GROUP_INFO, 50);
71
+ const messageInputKey = (0, crypto_1.hmacSha256Sign)(chainKey, MESSAGE_KEY_LABEL);
72
+ const nextChainRaw = (0, crypto_1.hmacSha256Sign)(chainKey, CHAIN_KEY_LABEL);
73
+ const seed = (0, crypto_1.hkdf)(messageInputKey, null, WHISPER_GROUP_INFO, 50);
77
74
  return {
78
75
  messageKey: { iteration, seed },
79
76
  nextChainKey: nextChainRaw.subarray(0, 32)
@@ -88,4 +85,3 @@ function splitSenderKeyMessageSeed(seed) {
88
85
  cipherKey: seed.subarray(16, 48)
89
86
  };
90
87
  }
91
- //# sourceMappingURL=fake-sender-key.js.map
@@ -19,4 +19,3 @@ export declare class PreKeyUploadParseError extends Error {
19
19
  constructor(message: string);
20
20
  }
21
21
  export declare function parsePreKeyUploadIq(iq: BinaryNode): ClientPreKeyBundle;
22
- //# sourceMappingURL=prekey-upload.d.ts.map
@@ -110,4 +110,3 @@ function readBigEndianInt(bytes) {
110
110
  }
111
111
  return value;
112
112
  }
113
- //# sourceMappingURL=prekey-upload.js.map
@@ -5,4 +5,3 @@ export declare function buildStreamErrorReplaced(): BinaryNode;
5
5
  export declare function buildStreamErrorDeviceRemoved(): BinaryNode;
6
6
  export declare function buildStreamErrorAck(id: string): BinaryNode;
7
7
  export declare function buildStreamErrorXmlNotWellFormed(): BinaryNode;
8
- //# sourceMappingURL=stream-error.d.ts.map
@@ -61,4 +61,3 @@ function buildStreamErrorXmlNotWellFormed() {
61
61
  ]
62
62
  };
63
63
  }
64
- //# sourceMappingURL=stream-error.js.map
@@ -32,4 +32,3 @@ export declare class FakeAppStateCollection {
32
32
  hasPending(): boolean;
33
33
  private applyLtHash;
34
34
  }
35
- //# sourceMappingURL=fake-app-state-collection.d.ts.map
@@ -136,4 +136,3 @@ function bytesToHex(bytes) {
136
136
  }
137
137
  return out;
138
138
  }
139
- //# sourceMappingURL=fake-app-state-collection.js.map
@@ -32,4 +32,3 @@ export declare class FakeMediaStore {
32
32
  private randomPath;
33
33
  }
34
34
  export {};
35
- //# sourceMappingURL=fake-media-store.d.ts.map
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.FakeMediaStore = void 0;
5
5
  const node_crypto_1 = require("node:crypto");
6
6
  const crypto_1 = require("../transport/crypto");
7
+ const util_1 = require("../transport/util");
7
8
  class FakeMediaStore {
8
9
  constructor() {
9
10
  this.blobs = new Map();
@@ -49,9 +50,8 @@ class FakeMediaStore {
49
50
  this.blobs.clear();
50
51
  }
51
52
  randomPath(mediaType) {
52
- const slug = (0, node_crypto_1.randomBytes)(16).toString('hex');
53
+ const slug = (0, util_1.bytesToHex)((0, node_crypto_1.randomBytes)(16));
53
54
  return `/fake-media/${mediaType}/${slug}`;
54
55
  }
55
56
  }
56
57
  exports.FakeMediaStore = FakeMediaStore;
57
- //# sourceMappingURL=fake-media-store.js.map
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Layer 1 — binary stanza codec wrapper.
2
+ * Layer 1 – binary stanza codec wrapper.
3
3
  *
4
4
  * Re-exports the bit-exact WhatsApp WAP token encoder/decoder from zapo-js.
5
5
  * This file is the only sanctioned import path for binary node serialization
6
- * inside the fake server. See AGENTS.md §3 for the layering rule.
6
+ * inside the fake server.
7
7
  */
8
8
  export { decodeBinaryNode, decodeBinaryNodeStanza, encodeBinaryNode, encodeBinaryNodeStanza, verifyNoiseCertificateChain } from 'zapo-js/transport';
9
9
  export type { BinaryNode, WaNoiseRootCa } from 'zapo-js/transport';
10
- //# sourceMappingURL=codec.d.ts.map
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  /**
3
- * Layer 1 — binary stanza codec wrapper.
3
+ * Layer 1 – binary stanza codec wrapper.
4
4
  *
5
5
  * Re-exports the bit-exact WhatsApp WAP token encoder/decoder from zapo-js.
6
6
  * This file is the only sanctioned import path for binary node serialization
7
- * inside the fake server. See AGENTS.md §3 for the layering rule.
7
+ * inside the fake server.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.verifyNoiseCertificateChain = exports.encodeBinaryNodeStanza = exports.encodeBinaryNode = exports.decodeBinaryNodeStanza = exports.decodeBinaryNode = void 0;
@@ -14,4 +14,3 @@ Object.defineProperty(exports, "decodeBinaryNodeStanza", { enumerable: true, get
14
14
  Object.defineProperty(exports, "encodeBinaryNode", { enumerable: true, get: function () { return transport_1.encodeBinaryNode; } });
15
15
  Object.defineProperty(exports, "encodeBinaryNodeStanza", { enumerable: true, get: function () { return transport_1.encodeBinaryNodeStanza; } });
16
16
  Object.defineProperty(exports, "verifyNoiseCertificateChain", { enumerable: true, get: function () { return transport_1.verifyNoiseCertificateChain; } });
17
- //# sourceMappingURL=codec.js.map