@telecrypt-io/storage 0.2.5 → 0.2.8
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/dist/TeleCryptIOStorage.js +26 -7
- package/package.json +1 -1
|
@@ -158,6 +158,18 @@ export class TeleCryptIOStorage {
|
|
|
158
158
|
*/
|
|
159
159
|
async keysSetupRecovery() {
|
|
160
160
|
const crypto = this.requireCrypto();
|
|
161
|
+
// If this account already has secret storage configured (e.g. from a
|
|
162
|
+
// previous setup on another device), we cannot unlock it here: the SDK
|
|
163
|
+
// has no `getSecretStorageKey` callback wired yet and the old recovery
|
|
164
|
+
// key is not available, so `bootstrapCrossSigning` would try to read the
|
|
165
|
+
// existing 4S and fail with "No getSecretStorageKey callback supplied".
|
|
166
|
+
// Reset the account's 4S + key backup so we can bootstrap a fresh,
|
|
167
|
+
// self-consistent recovery state (new cross-signing keys, new 4S key,
|
|
168
|
+
// new backup) and hand the user a working recovery key.
|
|
169
|
+
const status = await crypto.getSecretStorageStatus();
|
|
170
|
+
if (status.defaultKeyId) {
|
|
171
|
+
await crypto.disableKeyStorage();
|
|
172
|
+
}
|
|
161
173
|
await crypto.bootstrapCrossSigning({
|
|
162
174
|
// No existing verified device to interactively re-authenticate against
|
|
163
175
|
// for this account, so there is nothing to feed into `makeRequest`;
|
|
@@ -351,13 +363,20 @@ export class TeleCryptIOStorage {
|
|
|
351
363
|
return event_id;
|
|
352
364
|
}
|
|
353
365
|
async downloadFile(branch) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
366
|
+
let info;
|
|
367
|
+
try {
|
|
368
|
+
({ info } = await branch.getFileInfo());
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
// matrix-js-sdk's MSC3089Branch.getFileInfo() reads `file["url"]` off
|
|
372
|
+
// the raw event content; when the event is undecryptable on this
|
|
373
|
+
// device it hands back a placeholder with no `file` block, so that
|
|
374
|
+
// read throws an opaque "Cannot read properties of undefined" instead
|
|
375
|
+
// of a useful error. Surface the real cause.
|
|
376
|
+
throw new Error(`downloadFile: could not read file info from the event — it is likely undecryptable on this device (missing megolm session; try restoring from a Recovery Key)`);
|
|
377
|
+
}
|
|
378
|
+
// Belt-and-braces: if a future matrix-js-sdk version returns a
|
|
379
|
+
// placeholder without throwing, still fail with the clear message.
|
|
361
380
|
if (!info || typeof info.url !== "string") {
|
|
362
381
|
throw new Error("downloadFile: could not read file info from the event — it is likely undecryptable on this device (missing megolm session; try restoring from a Recovery Key)");
|
|
363
382
|
}
|