Skip to content

Commit 27a8a7f

Browse files
authored
fix: detect identity reset by listening to cross-signing key changes (#1258)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description <!-- Please include a summary of the change. Please also include relevant motivation and context. List any dependencies that are required for this change. --> When the server/IdP resets identity, the Matrix SDK fires CryptoEvent.KeysChanged, but the client only re-evaluated verification status on CryptoEvent.DevicesUpdated. So after a reset the client kept showing "Verified" and never surfaced the unverified state. Adds useCrossSigningKeysChange (mirroring useDeviceListChange) and wires it into both verification hooks so status and unverified-device count re-evaluate on key changes. The existing unverified banner and Devices page then reflect the reset. Fixes #1255 #### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings ### AI disclosure: - [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). <!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. -->
2 parents 1d256b9 + 509a1ff commit 27a8a7f

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/app/hooks/useDeviceVerificationStatus.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import { useCallback, useEffect, useState } from 'react';
2-
import type { CryptoApi } from '$types/matrix-sdk';
2+
import { type CryptoApi, type CryptoEventHandlerMap, CryptoEvent } from '$types/matrix-sdk';
33
import { verifiedDevice } from '$utils/matrix-crypto';
44
import { fulfilledPromiseSettledResult } from '$utils/common';
55
import { useAlive } from './useAlive';
66
import { useMatrixClient } from './useMatrixClient';
77
import { useDeviceListChange } from './useDeviceList';
88

9+
export const useCrossSigningKeysChange = (
10+
onChange: CryptoEventHandlerMap[CryptoEvent.KeysChanged]
11+
) => {
12+
const mx = useMatrixClient();
13+
useEffect(() => {
14+
mx.on(CryptoEvent.KeysChanged, onChange);
15+
return () => {
16+
mx.removeListener(CryptoEvent.KeysChanged, onChange);
17+
};
18+
}, [mx, onChange]);
19+
};
20+
921
export enum VerificationStatus {
1022
Unknown,
1123
Unverified,
@@ -48,6 +60,8 @@ export const useDeviceVerificationDetect = (
4860
[userId, updateStatus]
4961
)
5062
);
63+
64+
useCrossSigningKeysChange(useCallback(() => updateStatus(), [updateStatus]));
5165
};
5266

5367
export const useDeviceVerificationStatus = (
@@ -98,6 +112,8 @@ export const useUnverifiedDeviceCount = (
98112
)
99113
);
100114

115+
useCrossSigningKeysChange(useCallback(() => updateCount(), [updateCount]));
116+
101117
useEffect(() => {
102118
updateCount();
103119
}, [updateCount]);

0 commit comments

Comments
 (0)