mirror of https://github.com/vector-im/riot-web
Merge pull request #6613 from matrix-org/dbkr/crosssigningpanel_ts
Convert CrossSigningPanel to TSpull/21833/head
commit
1842cd1688
|
@ -24,36 +24,39 @@ import Spinner from '../elements/Spinner';
|
||||||
import InteractiveAuthDialog from '../dialogs/InteractiveAuthDialog';
|
import InteractiveAuthDialog from '../dialogs/InteractiveAuthDialog';
|
||||||
import ConfirmDestroyCrossSigningDialog from '../dialogs/security/ConfirmDestroyCrossSigningDialog';
|
import ConfirmDestroyCrossSigningDialog from '../dialogs/security/ConfirmDestroyCrossSigningDialog';
|
||||||
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||||
|
import { MatrixEvent } from 'matrix-js-sdk/src';
|
||||||
|
|
||||||
|
interface IState {
|
||||||
|
error?: Error;
|
||||||
|
crossSigningPublicKeysOnDevice?: boolean;
|
||||||
|
crossSigningPrivateKeysInStorage?: boolean;
|
||||||
|
masterPrivateKeyCached?: boolean;
|
||||||
|
selfSigningPrivateKeyCached?: boolean;
|
||||||
|
userSigningPrivateKeyCached?: boolean;
|
||||||
|
homeserverSupportsCrossSigning?: boolean;
|
||||||
|
crossSigningReady?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
@replaceableComponent("views.settings.CrossSigningPanel")
|
@replaceableComponent("views.settings.CrossSigningPanel")
|
||||||
export default class CrossSigningPanel extends React.PureComponent {
|
export default class CrossSigningPanel extends React.PureComponent<{}, IState> {
|
||||||
|
private unmounted = false;
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this._unmounted = false;
|
this.state = {};
|
||||||
|
|
||||||
this.state = {
|
|
||||||
error: null,
|
|
||||||
crossSigningPublicKeysOnDevice: null,
|
|
||||||
crossSigningPrivateKeysInStorage: null,
|
|
||||||
masterPrivateKeyCached: null,
|
|
||||||
selfSigningPrivateKeyCached: null,
|
|
||||||
userSigningPrivateKeyCached: null,
|
|
||||||
homeserverSupportsCrossSigning: null,
|
|
||||||
crossSigningReady: null,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
public componentDidMount() {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.get();
|
||||||
cli.on("accountData", this.onAccountData);
|
cli.on("accountData", this.onAccountData);
|
||||||
cli.on("userTrustStatusChanged", this.onStatusChanged);
|
cli.on("userTrustStatusChanged", this.onStatusChanged);
|
||||||
cli.on("crossSigning.keysChanged", this.onStatusChanged);
|
cli.on("crossSigning.keysChanged", this.onStatusChanged);
|
||||||
this._getUpdatedStatus();
|
this.getUpdatedStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
this._unmounted = true;
|
this.unmounted = true;
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.get();
|
||||||
if (!cli) return;
|
if (!cli) return;
|
||||||
cli.removeListener("accountData", this.onAccountData);
|
cli.removeListener("accountData", this.onAccountData);
|
||||||
|
@ -61,28 +64,28 @@ export default class CrossSigningPanel extends React.PureComponent {
|
||||||
cli.removeListener("crossSigning.keysChanged", this.onStatusChanged);
|
cli.removeListener("crossSigning.keysChanged", this.onStatusChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
onAccountData = (event) => {
|
private onAccountData = (event: MatrixEvent): void => {
|
||||||
const type = event.getType();
|
const type = event.getType();
|
||||||
if (type.startsWith("m.cross_signing") || type.startsWith("m.secret_storage")) {
|
if (type.startsWith("m.cross_signing") || type.startsWith("m.secret_storage")) {
|
||||||
this._getUpdatedStatus();
|
this.getUpdatedStatus();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_onBootstrapClick = () => {
|
private onBootstrapClick = () => {
|
||||||
this._bootstrapCrossSigning({ forceReset: false });
|
this.bootstrapCrossSigning({ forceReset: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
onStatusChanged = () => {
|
private onStatusChanged = () => {
|
||||||
this._getUpdatedStatus();
|
this.getUpdatedStatus();
|
||||||
};
|
};
|
||||||
|
|
||||||
async _getUpdatedStatus() {
|
private async getUpdatedStatus(): Promise<void> {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.get();
|
||||||
const pkCache = cli.getCrossSigningCacheCallbacks();
|
const pkCache = cli.getCrossSigningCacheCallbacks();
|
||||||
const crossSigning = cli.crypto.crossSigningInfo;
|
const crossSigning = cli.crypto.crossSigningInfo;
|
||||||
const secretStorage = cli.crypto.secretStorage;
|
const secretStorage = cli.crypto.secretStorage;
|
||||||
const crossSigningPublicKeysOnDevice = crossSigning.getId();
|
const crossSigningPublicKeysOnDevice = Boolean(crossSigning.getId());
|
||||||
const crossSigningPrivateKeysInStorage = await crossSigning.isStoredInSecretStorage(secretStorage);
|
const crossSigningPrivateKeysInStorage = Boolean(await crossSigning.isStoredInSecretStorage(secretStorage));
|
||||||
const masterPrivateKeyCached = !!(pkCache && await pkCache.getCrossSigningKeyCache("master"));
|
const masterPrivateKeyCached = !!(pkCache && await pkCache.getCrossSigningKeyCache("master"));
|
||||||
const selfSigningPrivateKeyCached = !!(pkCache && await pkCache.getCrossSigningKeyCache("self_signing"));
|
const selfSigningPrivateKeyCached = !!(pkCache && await pkCache.getCrossSigningKeyCache("self_signing"));
|
||||||
const userSigningPrivateKeyCached = !!(pkCache && await pkCache.getCrossSigningKeyCache("user_signing"));
|
const userSigningPrivateKeyCached = !!(pkCache && await pkCache.getCrossSigningKeyCache("user_signing"));
|
||||||
|
@ -110,8 +113,8 @@ export default class CrossSigningPanel extends React.PureComponent {
|
||||||
* 3. All keys are loaded and there's nothing to do.
|
* 3. All keys are loaded and there's nothing to do.
|
||||||
* @param {bool} [forceReset] Bootstrap again even if keys already present
|
* @param {bool} [forceReset] Bootstrap again even if keys already present
|
||||||
*/
|
*/
|
||||||
_bootstrapCrossSigning = async ({ forceReset = false }) => {
|
private bootstrapCrossSigning = async ({ forceReset = false }): Promise<void> => {
|
||||||
this.setState({ error: null });
|
this.setState({ error: undefined });
|
||||||
try {
|
try {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.get();
|
||||||
await cli.bootstrapCrossSigning({
|
await cli.bootstrapCrossSigning({
|
||||||
|
@ -135,20 +138,20 @@ export default class CrossSigningPanel extends React.PureComponent {
|
||||||
this.setState({ error: e });
|
this.setState({ error: e });
|
||||||
console.error("Error bootstrapping cross-signing", e);
|
console.error("Error bootstrapping cross-signing", e);
|
||||||
}
|
}
|
||||||
if (this._unmounted) return;
|
if (this.unmounted) return;
|
||||||
this._getUpdatedStatus();
|
this.getUpdatedStatus();
|
||||||
}
|
};
|
||||||
|
|
||||||
_resetCrossSigning = () => {
|
private resetCrossSigning = (): void => {
|
||||||
Modal.createDialog(ConfirmDestroyCrossSigningDialog, {
|
Modal.createDialog(ConfirmDestroyCrossSigningDialog, {
|
||||||
onFinished: (act) => {
|
onFinished: (act) => {
|
||||||
if (!act) return;
|
if (!act) return;
|
||||||
this._bootstrapCrossSigning({ forceReset: true });
|
this.bootstrapCrossSigning({ forceReset: true });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
render() {
|
public render() {
|
||||||
const AccessibleButton = sdk.getComponent("elements.AccessibleButton");
|
const AccessibleButton = sdk.getComponent("elements.AccessibleButton");
|
||||||
const {
|
const {
|
||||||
error,
|
error,
|
||||||
|
@ -208,7 +211,7 @@ export default class CrossSigningPanel extends React.PureComponent {
|
||||||
// TODO: determine how better to expose this to users in addition to prompts at login/toast
|
// TODO: determine how better to expose this to users in addition to prompts at login/toast
|
||||||
if (!keysExistEverywhere && homeserverSupportsCrossSigning) {
|
if (!keysExistEverywhere && homeserverSupportsCrossSigning) {
|
||||||
actions.push(
|
actions.push(
|
||||||
<AccessibleButton key="setup" kind="primary" onClick={this._onBootstrapClick}>
|
<AccessibleButton key="setup" kind="primary" onClick={this.onBootstrapClick}>
|
||||||
{ _t("Set up") }
|
{ _t("Set up") }
|
||||||
</AccessibleButton>,
|
</AccessibleButton>,
|
||||||
);
|
);
|
||||||
|
@ -216,7 +219,7 @@ export default class CrossSigningPanel extends React.PureComponent {
|
||||||
|
|
||||||
if (keysExistAnywhere) {
|
if (keysExistAnywhere) {
|
||||||
actions.push(
|
actions.push(
|
||||||
<AccessibleButton key="reset" kind="danger" onClick={this._resetCrossSigning}>
|
<AccessibleButton key="reset" kind="danger" onClick={this.resetCrossSigning}>
|
||||||
{ _t("Reset") }
|
{ _t("Reset") }
|
||||||
</AccessibleButton>,
|
</AccessibleButton>,
|
||||||
);
|
);
|
Loading…
Reference in New Issue