2021-10-27 15:08:53 +02:00
|
|
|
/*
|
|
|
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {ViewModel} from "./ViewModel.js";
|
2021-10-29 15:48:28 +02:00
|
|
|
import {KeyType} from "../matrix/ssss/index.js";
|
2021-10-27 15:08:53 +02:00
|
|
|
|
|
|
|
export class AccountSetupViewModel extends ViewModel {
|
|
|
|
constructor(accountSetup) {
|
|
|
|
super();
|
|
|
|
this._accountSetup = accountSetup;
|
|
|
|
this._dehydratedDevice = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
get canDehydrateDevice() {
|
|
|
|
return !!this._accountSetup.encryptedDehydratedDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
get deviceDecrypted() {
|
|
|
|
return !!this._dehydratedDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
get dehydratedDeviceId() {
|
|
|
|
return this._accountSetup.encryptedDehydratedDevice.deviceId;
|
|
|
|
}
|
|
|
|
|
2021-10-29 15:48:28 +02:00
|
|
|
async tryDecryptDehydratedDevice(password) {
|
2021-10-27 15:08:53 +02:00
|
|
|
const {encryptedDehydratedDevice} = this._accountSetup;
|
|
|
|
if (encryptedDehydratedDevice) {
|
2021-10-29 15:48:28 +02:00
|
|
|
this._dehydratedDevice = await encryptedDehydratedDevice.decrypt(KeyType.RecoveryKey, password);
|
2021-10-27 15:08:53 +02:00
|
|
|
this.emitChange("deviceDecrypted");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finish() {
|
|
|
|
this._accountSetup.finish(this._dehydratedDevice);
|
|
|
|
}
|
|
|
|
}
|