@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.
- package/README.md +96 -8
- package/dist/api/AppStateSyncManager.d.ts +0 -1
- package/dist/api/AppStateSyncManager.js +0 -1
- package/dist/api/FakePairingDriver.d.ts +0 -1
- package/dist/api/FakePairingDriver.js +0 -1
- package/dist/api/FakePeer.d.ts +77 -4
- package/dist/api/FakePeer.js +208 -2
- package/dist/api/FakeServerSession.d.ts +67 -0
- package/dist/api/FakeServerSession.js +293 -0
- package/dist/api/FakeWaServer.d.ts +77 -31
- package/dist/api/FakeWaServer.js +140 -259
- package/dist/api/PreKeyDispenser.d.ts +0 -1
- package/dist/api/PreKeyDispenser.js +0 -1
- package/dist/api/Scenario.d.ts +0 -1
- package/dist/api/Scenario.js +0 -1
- package/dist/api/ServerRegistries.d.ts +0 -1
- package/dist/api/ServerRegistries.js +0 -1
- package/dist/api/iq-handlers.d.ts +1 -1
- package/dist/api/iq-handlers.js +23 -1
- package/dist/{cli.d.ts → bin.d.ts} +0 -1
- package/dist/bin.js +296 -0
- package/dist/esm/api/AppStateSyncManager.js +146 -0
- package/dist/esm/api/FakePairingDriver.js +31 -0
- package/dist/esm/api/FakePeer.js +610 -0
- package/dist/esm/api/FakeServerSession.js +287 -0
- package/dist/esm/api/FakeWaServer.js +528 -0
- package/dist/esm/api/PreKeyDispenser.js +93 -0
- package/dist/esm/api/Scenario.js +32 -0
- package/dist/esm/api/ServerRegistries.js +261 -0
- package/dist/esm/api/iq-handlers.js +515 -0
- package/dist/{cli.js → esm/bin.js} +70 -25
- package/dist/esm/index.js +26 -0
- package/dist/esm/infra/WaFakeConnection.js +49 -0
- package/dist/esm/infra/WaFakeConnectionPipeline.js +235 -0
- package/dist/esm/infra/WaFakeFrameSocket.js +117 -0
- package/dist/esm/infra/WaFakeMediaHttpsServer.js +126 -0
- package/dist/esm/infra/WaFakeNoiseHandshake.js +67 -0
- package/dist/esm/infra/WaFakeTransport.js +31 -0
- package/dist/esm/infra/WaFakeWsServer.js +96 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/protocol/auth/cert-chain.js +50 -0
- package/dist/esm/protocol/auth/client-payload-validate.js +55 -0
- package/dist/esm/protocol/auth/fake-primary-device.js +47 -0
- package/dist/esm/protocol/auth/pair-device.js +87 -0
- package/dist/esm/protocol/auth/success-node.js +26 -0
- package/dist/esm/protocol/iq/abprops.js +30 -0
- package/dist/esm/protocol/iq/appstate-sync.js +146 -0
- package/dist/esm/protocol/iq/business.js +59 -0
- package/dist/esm/protocol/iq/dirty-bits.js +19 -0
- package/dist/esm/protocol/iq/group-ops.js +154 -0
- package/dist/esm/protocol/iq/newsletter.js +14 -0
- package/dist/esm/protocol/iq/prekey-fetch.js +88 -0
- package/dist/esm/protocol/iq/privacy-token.js +26 -0
- package/dist/esm/protocol/iq/privacy.js +123 -0
- package/dist/esm/protocol/iq/profile.js +72 -0
- package/dist/esm/protocol/iq/router.js +117 -0
- package/dist/esm/protocol/iq/usync.js +64 -0
- package/dist/esm/protocol/push/app-state-key-share.js +26 -0
- package/dist/esm/protocol/push/call-failure.js +27 -0
- package/dist/esm/protocol/push/chatstate.js +23 -0
- package/dist/esm/protocol/push/error-stanza.js +13 -0
- package/dist/esm/protocol/push/history-sync.js +111 -0
- package/dist/esm/protocol/push/message.js +38 -0
- package/dist/esm/protocol/push/notification.js +29 -0
- package/dist/esm/protocol/push/presence.js +14 -0
- package/dist/esm/protocol/push/receipt.js +21 -0
- package/dist/esm/protocol/signal/fake-app-state-crypto.js +196 -0
- package/dist/esm/protocol/signal/fake-peer-double-ratchet.js +398 -0
- package/dist/esm/protocol/signal/fake-peer-group-recv-session.js +120 -0
- package/dist/esm/protocol/signal/fake-peer-identity.js +8 -0
- package/dist/esm/protocol/signal/fake-peer-key-bundle.js +25 -0
- package/dist/esm/protocol/signal/fake-sender-key.js +83 -0
- package/dist/esm/protocol/signal/prekey-upload.js +107 -0
- package/dist/esm/protocol/stream/stream-error.js +56 -0
- package/dist/esm/state/fake-app-state-collection.js +134 -0
- package/dist/esm/state/fake-media-store.js +53 -0
- package/dist/esm/transport/codec.js +8 -0
- package/dist/esm/transport/crypto.js +8 -0
- package/dist/esm/transport/protos.js +7 -0
- package/dist/esm/transport/util.js +8 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -2
- package/dist/infra/WaFakeConnection.d.ts +0 -1
- package/dist/infra/WaFakeConnection.js +0 -1
- package/dist/infra/WaFakeConnectionPipeline.d.ts +10 -3
- package/dist/infra/WaFakeConnectionPipeline.js +47 -32
- package/dist/infra/WaFakeFrameSocket.d.ts +0 -1
- package/dist/infra/WaFakeFrameSocket.js +0 -1
- package/dist/infra/WaFakeMediaHttpsServer.d.ts +0 -1
- package/dist/infra/WaFakeMediaHttpsServer.js +0 -1
- package/dist/infra/WaFakeNoiseHandshake.d.ts +8 -10
- package/dist/infra/WaFakeNoiseHandshake.js +19 -24
- package/dist/infra/WaFakeTransport.d.ts +2 -4
- package/dist/infra/WaFakeTransport.js +2 -1
- package/dist/infra/WaFakeWsServer.d.ts +0 -1
- package/dist/infra/WaFakeWsServer.js +0 -1
- package/dist/protocol/auth/cert-chain.d.ts +4 -1
- package/dist/protocol/auth/cert-chain.js +13 -3
- package/dist/protocol/auth/client-payload-validate.d.ts +0 -1
- package/dist/protocol/auth/client-payload-validate.js +0 -1
- package/dist/protocol/auth/fake-primary-device.d.ts +0 -1
- package/dist/protocol/auth/fake-primary-device.js +1 -3
- package/dist/protocol/auth/pair-device.d.ts +0 -1
- package/dist/protocol/auth/pair-device.js +4 -16
- package/dist/protocol/auth/success-node.d.ts +0 -1
- package/dist/protocol/auth/success-node.js +0 -1
- package/dist/protocol/iq/abprops.d.ts +0 -1
- package/dist/protocol/iq/abprops.js +0 -1
- package/dist/protocol/iq/appstate-sync.d.ts +0 -1
- package/dist/protocol/iq/appstate-sync.js +0 -1
- package/dist/protocol/iq/business.d.ts +0 -1
- package/dist/protocol/iq/business.js +0 -1
- package/dist/protocol/iq/dirty-bits.d.ts +0 -1
- package/dist/protocol/iq/dirty-bits.js +0 -1
- package/dist/protocol/iq/group-ops.d.ts +0 -1
- package/dist/protocol/iq/group-ops.js +0 -1
- package/dist/protocol/iq/newsletter.d.ts +0 -1
- package/dist/protocol/iq/newsletter.js +0 -1
- package/dist/protocol/iq/prekey-fetch.d.ts +0 -1
- package/dist/protocol/iq/prekey-fetch.js +0 -1
- package/dist/protocol/iq/privacy-token.d.ts +0 -1
- package/dist/protocol/iq/privacy-token.js +0 -1
- package/dist/protocol/iq/privacy.d.ts +0 -1
- package/dist/protocol/iq/privacy.js +15 -16
- package/dist/protocol/iq/profile.d.ts +0 -1
- package/dist/protocol/iq/profile.js +0 -1
- package/dist/protocol/iq/router.d.ts +7 -2
- package/dist/protocol/iq/router.js +8 -3
- package/dist/protocol/iq/usync.d.ts +0 -1
- package/dist/protocol/iq/usync.js +0 -1
- package/dist/protocol/push/app-state-key-share.d.ts +0 -1
- package/dist/protocol/push/app-state-key-share.js +0 -1
- package/dist/protocol/push/call-failure.d.ts +0 -1
- package/dist/protocol/push/call-failure.js +0 -1
- package/dist/protocol/push/chatstate.d.ts +0 -1
- package/dist/protocol/push/chatstate.js +0 -1
- package/dist/protocol/push/error-stanza.d.ts +0 -1
- package/dist/protocol/push/error-stanza.js +0 -1
- package/dist/protocol/push/history-sync.d.ts +0 -1
- package/dist/protocol/push/history-sync.js +0 -1
- package/dist/protocol/push/message.d.ts +0 -1
- package/dist/protocol/push/message.js +0 -1
- package/dist/protocol/push/notification.d.ts +0 -1
- package/dist/protocol/push/notification.js +0 -1
- package/dist/protocol/push/presence.d.ts +0 -1
- package/dist/protocol/push/presence.js +0 -1
- package/dist/protocol/push/receipt.d.ts +0 -1
- package/dist/protocol/push/receipt.js +0 -1
- package/dist/protocol/signal/fake-app-state-crypto.d.ts +7 -9
- package/dist/protocol/signal/fake-app-state-crypto.js +31 -33
- package/dist/protocol/signal/fake-peer-double-ratchet.d.ts +0 -1
- package/dist/protocol/signal/fake-peer-double-ratchet.js +23 -28
- package/dist/protocol/signal/fake-peer-group-recv-session.d.ts +0 -1
- package/dist/protocol/signal/fake-peer-group-recv-session.js +6 -10
- package/dist/protocol/signal/fake-peer-identity.d.ts +0 -1
- package/dist/protocol/signal/fake-peer-identity.js +0 -1
- package/dist/protocol/signal/fake-peer-key-bundle.d.ts +0 -1
- package/dist/protocol/signal/fake-peer-key-bundle.js +0 -1
- package/dist/protocol/signal/fake-sender-key.d.ts +0 -1
- package/dist/protocol/signal/fake-sender-key.js +5 -9
- package/dist/protocol/signal/prekey-upload.d.ts +0 -1
- package/dist/protocol/signal/prekey-upload.js +0 -1
- package/dist/protocol/stream/stream-error.d.ts +0 -1
- package/dist/protocol/stream/stream-error.js +0 -1
- package/dist/state/fake-app-state-collection.d.ts +0 -1
- package/dist/state/fake-app-state-collection.js +0 -1
- package/dist/state/fake-media-store.d.ts +0 -1
- package/dist/state/fake-media-store.js +2 -2
- package/dist/transport/codec.d.ts +2 -3
- package/dist/transport/codec.js +2 -3
- package/dist/transport/crypto.d.ts +5 -7
- package/dist/transport/crypto.js +6 -11
- package/dist/transport/protos.d.ts +2 -4
- package/dist/transport/protos.js +2 -4
- package/dist/transport/util.d.ts +8 -0
- package/dist/transport/util.js +16 -0
- package/package.json +26 -6
- package/dist/api/AppStateSyncManager.d.ts.map +0 -1
- package/dist/api/AppStateSyncManager.js.map +0 -1
- package/dist/api/FakePairingDriver.d.ts.map +0 -1
- package/dist/api/FakePairingDriver.js.map +0 -1
- package/dist/api/FakePeer.d.ts.map +0 -1
- package/dist/api/FakePeer.js.map +0 -1
- package/dist/api/FakeWaServer.d.ts.map +0 -1
- package/dist/api/FakeWaServer.js.map +0 -1
- package/dist/api/PreKeyDispenser.d.ts.map +0 -1
- package/dist/api/PreKeyDispenser.js.map +0 -1
- package/dist/api/Scenario.d.ts.map +0 -1
- package/dist/api/Scenario.js.map +0 -1
- package/dist/api/ServerRegistries.d.ts.map +0 -1
- package/dist/api/ServerRegistries.js.map +0 -1
- package/dist/api/iq-handlers.d.ts.map +0 -1
- package/dist/api/iq-handlers.js.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/infra/WaFakeConnection.d.ts.map +0 -1
- package/dist/infra/WaFakeConnection.js.map +0 -1
- package/dist/infra/WaFakeConnectionPipeline.d.ts.map +0 -1
- package/dist/infra/WaFakeConnectionPipeline.js.map +0 -1
- package/dist/infra/WaFakeFrameSocket.d.ts.map +0 -1
- package/dist/infra/WaFakeFrameSocket.js.map +0 -1
- package/dist/infra/WaFakeMediaHttpsServer.d.ts.map +0 -1
- package/dist/infra/WaFakeMediaHttpsServer.js.map +0 -1
- package/dist/infra/WaFakeNoiseHandshake.d.ts.map +0 -1
- package/dist/infra/WaFakeNoiseHandshake.js.map +0 -1
- package/dist/infra/WaFakeTransport.d.ts.map +0 -1
- package/dist/infra/WaFakeTransport.js.map +0 -1
- package/dist/infra/WaFakeWsServer.d.ts.map +0 -1
- package/dist/infra/WaFakeWsServer.js.map +0 -1
- package/dist/protocol/auth/cert-chain.d.ts.map +0 -1
- package/dist/protocol/auth/cert-chain.js.map +0 -1
- package/dist/protocol/auth/client-payload-validate.d.ts.map +0 -1
- package/dist/protocol/auth/client-payload-validate.js.map +0 -1
- package/dist/protocol/auth/fake-primary-device.d.ts.map +0 -1
- package/dist/protocol/auth/fake-primary-device.js.map +0 -1
- package/dist/protocol/auth/pair-device.d.ts.map +0 -1
- package/dist/protocol/auth/pair-device.js.map +0 -1
- package/dist/protocol/auth/success-node.d.ts.map +0 -1
- package/dist/protocol/auth/success-node.js.map +0 -1
- package/dist/protocol/iq/abprops.d.ts.map +0 -1
- package/dist/protocol/iq/abprops.js.map +0 -1
- package/dist/protocol/iq/appstate-sync.d.ts.map +0 -1
- package/dist/protocol/iq/appstate-sync.js.map +0 -1
- package/dist/protocol/iq/business.d.ts.map +0 -1
- package/dist/protocol/iq/business.js.map +0 -1
- package/dist/protocol/iq/dirty-bits.d.ts.map +0 -1
- package/dist/protocol/iq/dirty-bits.js.map +0 -1
- package/dist/protocol/iq/group-ops.d.ts.map +0 -1
- package/dist/protocol/iq/group-ops.js.map +0 -1
- package/dist/protocol/iq/newsletter.d.ts.map +0 -1
- package/dist/protocol/iq/newsletter.js.map +0 -1
- package/dist/protocol/iq/prekey-fetch.d.ts.map +0 -1
- package/dist/protocol/iq/prekey-fetch.js.map +0 -1
- package/dist/protocol/iq/privacy-token.d.ts.map +0 -1
- package/dist/protocol/iq/privacy-token.js.map +0 -1
- package/dist/protocol/iq/privacy.d.ts.map +0 -1
- package/dist/protocol/iq/privacy.js.map +0 -1
- package/dist/protocol/iq/profile.d.ts.map +0 -1
- package/dist/protocol/iq/profile.js.map +0 -1
- package/dist/protocol/iq/router.d.ts.map +0 -1
- package/dist/protocol/iq/router.js.map +0 -1
- package/dist/protocol/iq/usync.d.ts.map +0 -1
- package/dist/protocol/iq/usync.js.map +0 -1
- package/dist/protocol/push/app-state-key-share.d.ts.map +0 -1
- package/dist/protocol/push/app-state-key-share.js.map +0 -1
- package/dist/protocol/push/call-failure.d.ts.map +0 -1
- package/dist/protocol/push/call-failure.js.map +0 -1
- package/dist/protocol/push/chatstate.d.ts.map +0 -1
- package/dist/protocol/push/chatstate.js.map +0 -1
- package/dist/protocol/push/error-stanza.d.ts.map +0 -1
- package/dist/protocol/push/error-stanza.js.map +0 -1
- package/dist/protocol/push/history-sync.d.ts.map +0 -1
- package/dist/protocol/push/history-sync.js.map +0 -1
- package/dist/protocol/push/message.d.ts.map +0 -1
- package/dist/protocol/push/message.js.map +0 -1
- package/dist/protocol/push/notification.d.ts.map +0 -1
- package/dist/protocol/push/notification.js.map +0 -1
- package/dist/protocol/push/presence.d.ts.map +0 -1
- package/dist/protocol/push/presence.js.map +0 -1
- package/dist/protocol/push/receipt.d.ts.map +0 -1
- package/dist/protocol/push/receipt.js.map +0 -1
- package/dist/protocol/signal/fake-app-state-crypto.d.ts.map +0 -1
- package/dist/protocol/signal/fake-app-state-crypto.js.map +0 -1
- package/dist/protocol/signal/fake-peer-double-ratchet.d.ts.map +0 -1
- package/dist/protocol/signal/fake-peer-double-ratchet.js.map +0 -1
- package/dist/protocol/signal/fake-peer-group-recv-session.d.ts.map +0 -1
- package/dist/protocol/signal/fake-peer-group-recv-session.js.map +0 -1
- package/dist/protocol/signal/fake-peer-identity.d.ts.map +0 -1
- package/dist/protocol/signal/fake-peer-identity.js.map +0 -1
- package/dist/protocol/signal/fake-peer-key-bundle.d.ts.map +0 -1
- package/dist/protocol/signal/fake-peer-key-bundle.js.map +0 -1
- package/dist/protocol/signal/fake-peer-recv-session.d.ts +0 -60
- package/dist/protocol/signal/fake-peer-recv-session.d.ts.map +0 -1
- package/dist/protocol/signal/fake-peer-recv-session.js +0 -284
- package/dist/protocol/signal/fake-peer-recv-session.js.map +0 -1
- package/dist/protocol/signal/fake-peer-session.d.ts +0 -87
- package/dist/protocol/signal/fake-peer-session.d.ts.map +0 -1
- package/dist/protocol/signal/fake-peer-session.js +0 -207
- package/dist/protocol/signal/fake-peer-session.js.map +0 -1
- package/dist/protocol/signal/fake-sender-key.d.ts.map +0 -1
- package/dist/protocol/signal/fake-sender-key.js.map +0 -1
- package/dist/protocol/signal/prekey-upload.d.ts.map +0 -1
- package/dist/protocol/signal/prekey-upload.js.map +0 -1
- package/dist/protocol/stream/stream-error.d.ts.map +0 -1
- package/dist/protocol/stream/stream-error.js.map +0 -1
- package/dist/state/fake-app-state-collection.d.ts.map +0 -1
- package/dist/state/fake-app-state-collection.js.map +0 -1
- package/dist/state/fake-media-store.d.ts.map +0 -1
- package/dist/state/fake-media-store.js.map +0 -1
- package/dist/transport/codec.d.ts.map +0 -1
- package/dist/transport/codec.js.map +0 -1
- package/dist/transport/crypto.d.ts.map +0 -1
- package/dist/transport/crypto.js.map +0 -1
- package/dist/transport/index.d.ts +0 -4
- package/dist/transport/index.d.ts.map +0 -1
- package/dist/transport/index.js +0 -20
- package/dist/transport/index.js.map +0 -1
- package/dist/transport/protos.d.ts.map +0 -1
- package/dist/transport/protos.js.map +0 -1
|
@@ -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
|
|
@@ -7,7 +7,13 @@ export interface WaFakeIqMatcher {
|
|
|
7
7
|
readonly xmlns?: string;
|
|
8
8
|
readonly childTag?: string;
|
|
9
9
|
}
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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
|
|
3
|
+
export declare const APP_STATE_EMPTY_LT_HASH: Readonly<Uint8Array>;
|
|
5
4
|
export interface FakeAppStateDerivedKeys {
|
|
6
|
-
readonly indexHmacKey:
|
|
7
|
-
readonly valueEncryptionAesKey:
|
|
8
|
-
readonly valueMacHmacKey:
|
|
9
|
-
readonly snapshotMacHmacKey:
|
|
10
|
-
readonly patchMacHmacKey:
|
|
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):
|
|
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
|
-
|
|
23
|
-
const derived =
|
|
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 =
|
|
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 =
|
|
53
|
-
const cipherText =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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.
|
|
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 =
|
|
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.
|
|
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
|
-
|
|
122
|
+
ltHashApply(base, values, combine) {
|
|
124
123
|
if (values.length === 0) {
|
|
125
124
|
return base.slice();
|
|
126
125
|
}
|
|
127
|
-
const expandedValues =
|
|
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
|
-
|
|
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 =
|
|
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
|
|
@@ -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] =
|
|
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] =
|
|
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 } =
|
|
89
|
-
const
|
|
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 =
|
|
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] =
|
|
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] =
|
|
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 =
|
|
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
|
|
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
|
|
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] =
|
|
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] =
|
|
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
|
-
|
|
335
|
-
const
|
|
336
|
-
const
|
|
337
|
-
|
|
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
|
-
|
|
352
|
-
const result =
|
|
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
|