@openclaw/matrix 2026.5.14-beta.1 → 2026.5.16-beta.1
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/api.js +4 -4
- package/dist/{approval-handler.runtime-DcgDdi8L.js → approval-handler.runtime--UYE3D2j.js} +5 -6
- package/dist/{approval-ids-DoC2z7tR.js → approval-ids-D6IQvvRE.js} +1 -1
- package/dist/{approval-reaction-auth-BY5VFY-q.js → approval-reaction-auth-99PRu7rF.js} +2 -2
- package/dist/{channel-eRrwLDE9.js → channel-CwN56Pko.js} +285 -26
- package/dist/channel-plugin-api.js +1 -1
- package/dist/{channel.runtime-CsQesLGI.js → channel.runtime-9qwvlUwp.js} +8 -8
- package/dist/{cli-DAMPUa3J.js → cli-BeWdjXLV.js} +15 -17
- package/dist/{cli-metadata-Bt5SrlLo.js → cli-metadata-B2_76YSe.js} +1 -1
- package/dist/cli-metadata.js +1 -1
- package/dist/{client-DrmLRQnw.js → client-D6fFVbNM.js} +2 -2
- package/dist/{client-bootstrap-Ba68NvZB.js → client-bootstrap-DBwUKgC3.js} +3 -3
- package/dist/{client-DBDvsx0D.js → client-oci1tD6-.js} +4 -5
- package/dist/{account-config-LVxGiX7e.js → config-paths-msaDGRh6.js} +18 -1
- package/dist/{config-schema-DOKrNEs_.js → config-schema-BPCzSyjT.js} +70 -4
- package/dist/contract-api.js +5 -6
- package/dist/{create-client-ChlpNpAA.js → create-client-BahCtURn.js} +4 -4
- package/dist/{credentials-DV6fWXhC.js → credentials-DK0lK9cZ.js} +1 -1
- package/dist/{credentials-write.runtime-zniTq-Gr.js → credentials-write.runtime-DhPvBU-C.js} +1 -1
- package/dist/{crypto-runtime-BevaUxax.js → crypto-runtime-B-SPS5mv.js} +5 -5
- package/dist/{directory-live-Btsr0yok.js → directory-live-BCfx1C0G.js} +3 -3
- package/dist/{doctor-qL-bgDwE.js → doctor-KuNYX5N3.js} +3 -3
- package/dist/doctor-contract-api.js +1 -1
- package/dist/{draft-stream-B-hyLmMw.js → draft-stream-BayHVmtO.js} +1 -2
- package/dist/{encryption-guidance-BPi3A_m3.js → encryption-guidance-1QoIvd-g.js} +1 -1
- package/dist/{http-client-C7AeVJay.js → http-client-DS3UoC_p.js} +1 -1
- package/dist/index.js +2 -2
- package/dist/{legacy-crypto-inspector-C4VpBdDV.js → legacy-crypto-inspector-_gWJGVQ_.js} +1 -1
- package/dist/{legacy-crypto-restore-Biw-w2ng.js → legacy-crypto-restore-B9eF1gob.js} +1 -1
- package/dist/{logging-DZHSPP5N.js → logging-bJ8EEe1G.js} +1 -1
- package/dist/{matrix-migration.runtime-CDasos7a.js → matrix-migration.runtime-Cf_wX9mk.js} +3 -3
- package/dist/{media-text-BLL8-Dr3.js → media-text-4h4YwCGC.js} +1 -1
- package/dist/{messages-BJi_jdEA.js → messages-BKTEUSwJ.js} +5 -5
- package/dist/{migration-snapshot.runtime-CKHE3xF9.js → migration-snapshot.runtime-C7yiKWS7.js} +1 -1
- package/dist/{monitor-COvHRaUQ.js → monitor-DPJO3wS1.js} +35 -35
- package/dist/plugin-entry.handlers.runtime.js +2 -2
- package/dist/probe.runtime-zExLz3Ek.js +3 -0
- package/dist/{profile-update-DK5rfmA-.js → profile-update-BAAflurI.js} +2 -3
- package/dist/{reaction-events-Cfvkp-A-.js → reaction-events-Dimh8FUE.js} +6 -6
- package/dist/{resolve-targets-ZSM4KKln.js → resolve-targets-DPqngj4V.js} +1 -1
- package/dist/{resolver.runtime-m_D8JSm3.js → resolver.runtime-C0RDK0VW.js} +1 -1
- package/dist/{route-D6rg-iXN.js → route-R-ajT21_.js} +1 -1
- package/dist/{runtime-api-DTKcXOhp.js → runtime-api-C-QeChQj.js} +1 -1
- package/dist/runtime-api.js +1 -1
- package/dist/runtime-heavy-api.js +2 -2
- package/dist/{sdk-BLBGvKEe.js → sdk-BwfNtBhM.js} +301 -13
- package/dist/secret-contract-api.js +1 -1
- package/dist/{send-D651usmb.js → send-CdoJ1pZY.js} +323 -6
- package/dist/{setup-bootstrap-DT2Gj9hX.js → setup-bootstrap-krQU60Az.js} +4 -4
- package/dist/setup-core-CgOV8zmh.js +675 -0
- package/dist/setup-plugin-api.js +3 -4
- package/dist/{setup-surface-KzA9__US.js → setup-surface-BgUaEySF.js} +7 -10
- package/dist/{config-xD5Y8nFT.js → shared-BlXw87Kp.js} +199 -9
- package/dist/{logger-CnZRVrux.js → startup-abort-br7BZHJQ.js} +32 -1
- package/dist/{startup-verification-Demyp0bP.js → startup-verification-CTfhD7V_.js} +2 -2
- package/dist/{storage-tC3ujLiW.js → storage-HI1nL3im.js} +1 -1
- package/dist/{subagent-hooks-DQbyqq9V.js → subagent-hooks-api-BgQgDwAS.js} +22 -1
- package/dist/subagent-hooks-api.js +1 -22
- package/dist/test-api.js +2 -2
- package/dist/thread-binding-api.js +1 -1
- package/dist/{thread-bindings-DHUszTA0.js → thread-bindings-8AyQOYDT.js} +2 -2
- package/dist/{tool-actions.runtime-Bn8bvkQN.js → tool-actions.runtime-BuCnleVD.js} +9 -9
- package/dist/{verification-BJT2k9TI.js → verification-DvC37Z_y.js} +2 -2
- package/package.json +6 -6
- package/dist/accounts--0L_EuMK.js +0 -130
- package/dist/allowlist-sTzpCn5d.js +0 -68
- package/dist/config-paths-nsVaysCu.js +0 -19
- package/dist/config-update-BBkpLB9o.js +0 -143
- package/dist/direct-management--Y8ypgLv.js +0 -251
- package/dist/direct-room-XkutHjES.js +0 -76
- package/dist/exec-approvals-to3d_jMv.js +0 -196
- package/dist/probe.runtime-sh9piX22.js +0 -3
- package/dist/profile-BlHu0wDX.js +0 -111
- package/dist/recovery-key-store-BTJ6jz5v.js +0 -294
- package/dist/session-store-metadata-DQXjgNLt.js +0 -77
- package/dist/setup-core-C-uKN68n.js +0 -116
- package/dist/setup-dm-policy-0_kFUfW4.js +0 -195
- package/dist/shared-DarXfhzC.js +0 -195
- package/dist/startup-abort-56edvmbM.js +0 -32
- /package/dist/{active-client-uhlxdhEy.js → active-client-DUi-lumi.js} +0 -0
- /package/dist/{approval-reactions-o2_tuH8D.js → approval-reactions-Cwd1PMCC.js} +0 -0
- /package/dist/{async-lock-uQfhfQIY.js → async-lock-SsmtFXtt.js} +0 -0
- /package/dist/{backup-health-Cabu_WQC.js → backup-health-3BHbHxyd.js} +0 -0
- /package/dist/{config-secret-input.runtime-DiKFehsE.js → config-secret-input.runtime-nbLCnJq7.js} +0 -0
- /package/dist/{crypto-node.runtime-pihzdpY7.js → crypto-node.runtime-D9qxgRPa.js} +0 -0
- /package/dist/{deps-DR0MIYrW.js → deps-LqqGWPWt.js} +0 -0
- /package/dist/{device-health-UVYpbA_W.js → device-health-Di9MUzFj.js} +0 -0
- /package/dist/{doctor-contract-D4-64QuJ.js → doctor-contract-s4gUPmRN.js} +0 -0
- /package/dist/{errors-CTcpEDq-.js → errors-BpHgvm2o.js} +0 -0
- /package/dist/{exec-approval-resolver-Bza9Dhlm.js → exec-approval-resolver-C8faS0XB.js} +0 -0
- /package/dist/{migration-snapshot-backup-DaCHTp8C.js → migration-snapshot-backup-BWTIFXgQ.js} +0 -0
- /package/dist/{reaction-common-ejrL19w-.js → reaction-common-B-QgNfEs.js} +0 -0
- /package/dist/{runtime-C6X4h_SJ.js → runtime-lwTSy9Yt.js} +0 -0
- /package/dist/{secret-contract-DcrJWCQI.js → secret-contract-e4SdhUtT.js} +0 -0
- /package/dist/{sync-state-C_beeevA.js → sync-state-Bx0gPaGA.js} +0 -0
- /package/dist/{thread-binding-api-Cq_E-E1K.js → thread-binding-api-Bx55B6hm.js} +0 -0
- /package/dist/{timeout-abort-signal-CtaIaP1v.js → timeout-abort-signal-sT0wAxVn.js} +0 -0
- /package/dist/{url-validation-DiK9j7jz.js → url-validation-CBZBxN3F.js} +0 -0
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
|
|
2
2
|
import { t as isRecord } from "./record-shared-CHWJCTWf.js";
|
|
3
|
-
import { n as formatMatrixErrorReason, r as isMatrixNotFoundError, t as formatMatrixErrorMessage } from "./errors-
|
|
4
|
-
import { t as claimCurrentTokenStorageState } from "./storage-
|
|
5
|
-
import { n as resolveMatrixRoomKeyBackupReadinessError } from "./backup-health-
|
|
6
|
-
import { t as createAsyncLock } from "./async-lock-
|
|
7
|
-
import { n as
|
|
8
|
-
import { t as createMatrixJsSdkClientLogger } from "./logging-
|
|
9
|
-
import { a as matrixEventToRaw, n as createMatrixGuardedFetch, o as parseMxc, t as MatrixAuthedHttpClient } from "./http-client-
|
|
10
|
-
import { n as
|
|
11
|
-
import { i as throwIfMatrixStartupAborted, n as createMatrixStartupAbortError } from "./startup-abort-56edvmbM.js";
|
|
12
|
-
import { n as isMatrixReadySyncState, r as isMatrixTerminalSyncState } from "./sync-state-C_beeevA.js";
|
|
3
|
+
import { n as formatMatrixErrorReason, r as isMatrixNotFoundError, t as formatMatrixErrorMessage } from "./errors-BpHgvm2o.js";
|
|
4
|
+
import { t as claimCurrentTokenStorageState } from "./storage-HI1nL3im.js";
|
|
5
|
+
import { n as resolveMatrixRoomKeyBackupReadinessError } from "./backup-health-3BHbHxyd.js";
|
|
6
|
+
import { t as createAsyncLock } from "./async-lock-SsmtFXtt.js";
|
|
7
|
+
import { a as ConsoleLogger, i as throwIfMatrixStartupAborted, n as createMatrixStartupAbortError, o as LogService, s as noop } from "./startup-abort-br7BZHJQ.js";
|
|
8
|
+
import { t as createMatrixJsSdkClientLogger } from "./logging-bJ8EEe1G.js";
|
|
9
|
+
import { a as matrixEventToRaw, n as createMatrixGuardedFetch, o as parseMxc, t as MatrixAuthedHttpClient } from "./http-client-DS3UoC_p.js";
|
|
10
|
+
import { n as isMatrixReadySyncState, r as isMatrixTerminalSyncState } from "./sync-state-Bx0gPaGA.js";
|
|
13
11
|
import { normalizeNullableString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
14
12
|
import { readFileSync } from "node:fs";
|
|
15
13
|
import path from "node:path";
|
|
16
|
-
import { writeJsonFileAtomically } from "openclaw/plugin-sdk/json-store";
|
|
14
|
+
import { loadJsonFile, saveJsonFile, writeJsonFileAtomically } from "openclaw/plugin-sdk/json-store";
|
|
17
15
|
import { KeyedAsyncQueue } from "openclaw/plugin-sdk/keyed-async-queue";
|
|
18
16
|
import { EventEmitter } from "node:events";
|
|
19
17
|
import { Category, ClientEvent, Filter, MatrixEventEvent, MemoryStore, Preset, SyncAccumulator, createClient } from "matrix-js-sdk/lib/matrix.js";
|
|
20
18
|
import { VerificationMethod } from "matrix-js-sdk/lib/types.js";
|
|
21
19
|
import fs$1 from "node:fs/promises";
|
|
20
|
+
import { decodeRecoveryKey } from "matrix-js-sdk/lib/crypto-api/recovery-key.js";
|
|
22
21
|
//#region extensions/matrix/src/matrix/client/file-sync-store.ts
|
|
23
22
|
const STORE_VERSION = 1;
|
|
24
23
|
const PERSIST_DEBOUNCE_MS = 250;
|
|
@@ -208,6 +207,295 @@ var FileBackedMatrixSyncStore = class extends MemoryStore {
|
|
|
208
207
|
}
|
|
209
208
|
};
|
|
210
209
|
//#endregion
|
|
210
|
+
//#region extensions/matrix/src/matrix/sdk/idb-persistence-lock.ts
|
|
211
|
+
const MATRIX_IDB_PERSIST_INTERVAL_MS = 6e4;
|
|
212
|
+
const IDB_SNAPSHOT_LOCK_STALE_MS = 5 * 6e4;
|
|
213
|
+
const IDB_SNAPSHOT_LOCK_RETRY_BASE = {
|
|
214
|
+
factor: 2,
|
|
215
|
+
minTimeout: 50,
|
|
216
|
+
maxTimeout: 5e3,
|
|
217
|
+
randomize: true
|
|
218
|
+
};
|
|
219
|
+
function computeRetryDelayMs(retries, attempt) {
|
|
220
|
+
return Math.min(retries.maxTimeout, Math.max(retries.minTimeout, retries.minTimeout * retries.factor ** attempt));
|
|
221
|
+
}
|
|
222
|
+
function computeMinimumRetryWindowMs(retries) {
|
|
223
|
+
let total = 0;
|
|
224
|
+
const attempts = Math.max(1, retries.retries + 1);
|
|
225
|
+
for (let attempt = 0; attempt < attempts - 1; attempt += 1) total += computeRetryDelayMs(retries, attempt);
|
|
226
|
+
return total;
|
|
227
|
+
}
|
|
228
|
+
function resolveRetriesForMinimumWindowMs(retries, minimumWindowMs) {
|
|
229
|
+
const resolved = {
|
|
230
|
+
...retries,
|
|
231
|
+
retries: 0
|
|
232
|
+
};
|
|
233
|
+
while (computeMinimumRetryWindowMs(resolved) < minimumWindowMs) resolved.retries += 1;
|
|
234
|
+
return resolved;
|
|
235
|
+
}
|
|
236
|
+
const MATRIX_IDB_SNAPSHOT_LOCK_OPTIONS = {
|
|
237
|
+
retries: resolveRetriesForMinimumWindowMs(IDB_SNAPSHOT_LOCK_RETRY_BASE, MATRIX_IDB_PERSIST_INTERVAL_MS),
|
|
238
|
+
stale: IDB_SNAPSHOT_LOCK_STALE_MS
|
|
239
|
+
};
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region extensions/matrix/src/matrix/sdk/recovery-key-store.ts
|
|
242
|
+
function isRepairableSecretStorageAccessError(err) {
|
|
243
|
+
const message = formatMatrixErrorReason(err);
|
|
244
|
+
if (!message) return false;
|
|
245
|
+
if (message.includes("getsecretstoragekey callback returned falsey")) return true;
|
|
246
|
+
if (message.includes("decrypting secret") && message.includes("bad mac")) return true;
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
var MatrixRecoveryKeyStore = class {
|
|
250
|
+
constructor(recoveryKeyPath) {
|
|
251
|
+
this.recoveryKeyPath = recoveryKeyPath;
|
|
252
|
+
this.secretStorageKeyCache = /* @__PURE__ */ new Map();
|
|
253
|
+
this.stagedRecoveryKey = null;
|
|
254
|
+
this.stagedRecoveryKeyUsed = false;
|
|
255
|
+
this.stagedCacheKeyIds = /* @__PURE__ */ new Set();
|
|
256
|
+
}
|
|
257
|
+
buildCryptoCallbacks() {
|
|
258
|
+
return {
|
|
259
|
+
getSecretStorageKey: async ({ keys }) => {
|
|
260
|
+
const requestedKeyIds = Object.keys(keys ?? {});
|
|
261
|
+
if (requestedKeyIds.length === 0) return null;
|
|
262
|
+
const staged = this.resolveStagedSecretStorageKey(requestedKeyIds);
|
|
263
|
+
if (staged) return staged;
|
|
264
|
+
for (const keyId of requestedKeyIds) {
|
|
265
|
+
const cached = this.secretStorageKeyCache.get(keyId);
|
|
266
|
+
if (cached) return [keyId, new Uint8Array(cached.key)];
|
|
267
|
+
}
|
|
268
|
+
const stored = this.loadStoredRecoveryKey();
|
|
269
|
+
if (!stored?.privateKeyBase64) return null;
|
|
270
|
+
const privateKey = new Uint8Array(Buffer.from(stored.privateKeyBase64, "base64"));
|
|
271
|
+
if (privateKey.length === 0) return null;
|
|
272
|
+
if (stored.keyId && requestedKeyIds.includes(stored.keyId)) {
|
|
273
|
+
this.rememberSecretStorageKey(stored.keyId, privateKey, stored.keyInfo);
|
|
274
|
+
return [stored.keyId, privateKey];
|
|
275
|
+
}
|
|
276
|
+
const firstRequestedKeyId = requestedKeyIds[0];
|
|
277
|
+
if (!firstRequestedKeyId) return null;
|
|
278
|
+
this.rememberSecretStorageKey(firstRequestedKeyId, privateKey, stored.keyInfo);
|
|
279
|
+
return [firstRequestedKeyId, privateKey];
|
|
280
|
+
},
|
|
281
|
+
cacheSecretStorageKey: (keyId, keyInfo, key) => {
|
|
282
|
+
const privateKey = new Uint8Array(key);
|
|
283
|
+
const normalizedKeyInfo = {
|
|
284
|
+
passphrase: keyInfo?.passphrase,
|
|
285
|
+
name: typeof keyInfo?.name === "string" ? keyInfo.name : void 0
|
|
286
|
+
};
|
|
287
|
+
this.rememberSecretStorageKey(keyId, privateKey, normalizedKeyInfo);
|
|
288
|
+
const stored = this.loadStoredRecoveryKey();
|
|
289
|
+
this.saveRecoveryKeyToDisk({
|
|
290
|
+
keyId,
|
|
291
|
+
keyInfo: normalizedKeyInfo,
|
|
292
|
+
privateKey,
|
|
293
|
+
encodedPrivateKey: stored?.encodedPrivateKey
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
getRecoveryKeySummary() {
|
|
299
|
+
const stored = this.loadStoredRecoveryKey();
|
|
300
|
+
if (!stored) return null;
|
|
301
|
+
return {
|
|
302
|
+
encodedPrivateKey: stored.encodedPrivateKey,
|
|
303
|
+
keyId: stored.keyId,
|
|
304
|
+
createdAt: stored.createdAt
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
resolveEncodedRecoveryKeyInput(params) {
|
|
308
|
+
const encodedPrivateKey = params.encodedPrivateKey.trim();
|
|
309
|
+
if (!encodedPrivateKey) throw new Error("Matrix recovery key is required");
|
|
310
|
+
let privateKey;
|
|
311
|
+
try {
|
|
312
|
+
privateKey = decodeRecoveryKey(encodedPrivateKey);
|
|
313
|
+
} catch (err) {
|
|
314
|
+
throw new Error(`Invalid Matrix recovery key: ${formatMatrixErrorMessage(err)}`, { cause: err });
|
|
315
|
+
}
|
|
316
|
+
const keyId = typeof params.keyId === "string" && params.keyId.trim() ? params.keyId.trim() : null;
|
|
317
|
+
return {
|
|
318
|
+
encodedPrivateKey,
|
|
319
|
+
privateKey,
|
|
320
|
+
keyId,
|
|
321
|
+
keyInfo: params.keyInfo ?? this.loadStoredRecoveryKey()?.keyInfo
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
storeEncodedRecoveryKey(params) {
|
|
325
|
+
const prepared = this.resolveEncodedRecoveryKeyInput(params);
|
|
326
|
+
this.saveRecoveryKeyToDisk({
|
|
327
|
+
keyId: prepared.keyId,
|
|
328
|
+
keyInfo: prepared.keyInfo,
|
|
329
|
+
privateKey: prepared.privateKey,
|
|
330
|
+
encodedPrivateKey: prepared.encodedPrivateKey
|
|
331
|
+
});
|
|
332
|
+
if (prepared.keyId) this.rememberSecretStorageKey(prepared.keyId, prepared.privateKey, prepared.keyInfo);
|
|
333
|
+
return this.getRecoveryKeySummary() ?? {};
|
|
334
|
+
}
|
|
335
|
+
stageEncodedRecoveryKey(params) {
|
|
336
|
+
const prepared = this.resolveEncodedRecoveryKeyInput(params);
|
|
337
|
+
this.discardStagedRecoveryKey();
|
|
338
|
+
this.stagedRecoveryKey = {
|
|
339
|
+
version: 1,
|
|
340
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
341
|
+
keyId: prepared.keyId,
|
|
342
|
+
encodedPrivateKey: prepared.encodedPrivateKey,
|
|
343
|
+
privateKeyBase64: Buffer.from(prepared.privateKey).toString("base64"),
|
|
344
|
+
keyInfo: prepared.keyInfo
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
hasStagedRecoveryKeyBeenUsed() {
|
|
348
|
+
return this.stagedRecoveryKeyUsed;
|
|
349
|
+
}
|
|
350
|
+
commitStagedRecoveryKey(params) {
|
|
351
|
+
if (!this.stagedRecoveryKey) return this.getRecoveryKeySummary();
|
|
352
|
+
const staged = this.stagedRecoveryKey;
|
|
353
|
+
const privateKey = new Uint8Array(Buffer.from(staged.privateKeyBase64, "base64"));
|
|
354
|
+
const keyId = typeof params?.keyId === "string" && params.keyId.trim() ? params.keyId.trim() : staged.keyId;
|
|
355
|
+
this.saveRecoveryKeyToDisk({
|
|
356
|
+
keyId,
|
|
357
|
+
keyInfo: params?.keyInfo ?? staged.keyInfo,
|
|
358
|
+
privateKey,
|
|
359
|
+
encodedPrivateKey: staged.encodedPrivateKey
|
|
360
|
+
});
|
|
361
|
+
this.clearStagedRecoveryKeyTracking();
|
|
362
|
+
return this.getRecoveryKeySummary();
|
|
363
|
+
}
|
|
364
|
+
discardStagedRecoveryKey() {
|
|
365
|
+
for (const keyId of this.stagedCacheKeyIds) this.secretStorageKeyCache.delete(keyId);
|
|
366
|
+
this.clearStagedRecoveryKeyTracking();
|
|
367
|
+
}
|
|
368
|
+
async bootstrapSecretStorageWithRecoveryKey(crypto, options = {}) {
|
|
369
|
+
let status = null;
|
|
370
|
+
const getSecretStorageStatus = crypto.getSecretStorageStatus;
|
|
371
|
+
if (typeof getSecretStorageStatus === "function") try {
|
|
372
|
+
status = await getSecretStorageStatus.call(crypto);
|
|
373
|
+
} catch (err) {
|
|
374
|
+
LogService.warn("MatrixClientLite", "Failed to read secret storage status:", err);
|
|
375
|
+
}
|
|
376
|
+
const hasDefaultSecretStorageKey = Boolean(status?.defaultKeyId);
|
|
377
|
+
const hasKnownInvalidSecrets = Object.values(status?.secretStorageKeyValidityMap ?? {}).some((valid) => !valid);
|
|
378
|
+
let generatedRecoveryKey = false;
|
|
379
|
+
const storedRecovery = this.loadStoredRecoveryKey();
|
|
380
|
+
const stagedRecovery = this.stagedRecoveryKey;
|
|
381
|
+
const sourceRecovery = options.forceNewRecoveryKey === true ? null : stagedRecovery ?? storedRecovery;
|
|
382
|
+
let recoveryKey = sourceRecovery ? {
|
|
383
|
+
keyInfo: sourceRecovery.keyInfo,
|
|
384
|
+
privateKey: new Uint8Array(Buffer.from(sourceRecovery.privateKeyBase64, "base64")),
|
|
385
|
+
encodedPrivateKey: sourceRecovery.encodedPrivateKey
|
|
386
|
+
} : null;
|
|
387
|
+
if (recoveryKey && status?.defaultKeyId) {
|
|
388
|
+
const defaultKeyId = status.defaultKeyId;
|
|
389
|
+
if (!stagedRecovery) {
|
|
390
|
+
this.rememberSecretStorageKey(defaultKeyId, recoveryKey.privateKey, recoveryKey.keyInfo);
|
|
391
|
+
if (storedRecovery && storedRecovery.keyId !== defaultKeyId) this.saveRecoveryKeyToDisk({
|
|
392
|
+
keyId: defaultKeyId,
|
|
393
|
+
keyInfo: recoveryKey.keyInfo,
|
|
394
|
+
privateKey: recoveryKey.privateKey,
|
|
395
|
+
encodedPrivateKey: recoveryKey.encodedPrivateKey
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const ensureRecoveryKey = async () => {
|
|
400
|
+
if (recoveryKey) {
|
|
401
|
+
if (stagedRecovery) this.stagedRecoveryKeyUsed = true;
|
|
402
|
+
return recoveryKey;
|
|
403
|
+
}
|
|
404
|
+
if (typeof crypto.createRecoveryKeyFromPassphrase !== "function") throw new Error("Matrix crypto backend does not support recovery key generation (createRecoveryKeyFromPassphrase missing)");
|
|
405
|
+
recoveryKey = await crypto.createRecoveryKeyFromPassphrase();
|
|
406
|
+
this.saveRecoveryKeyToDisk(recoveryKey);
|
|
407
|
+
generatedRecoveryKey = true;
|
|
408
|
+
return recoveryKey;
|
|
409
|
+
};
|
|
410
|
+
const shouldRecreateSecretStorage = options.forceNewSecretStorage === true || !hasDefaultSecretStorageKey || !recoveryKey && status?.ready === false || hasKnownInvalidSecrets;
|
|
411
|
+
if (hasKnownInvalidSecrets) recoveryKey = null;
|
|
412
|
+
const secretStorageOptions = { setupNewKeyBackup: options.setupNewKeyBackup === true };
|
|
413
|
+
if (shouldRecreateSecretStorage) {
|
|
414
|
+
secretStorageOptions.setupNewSecretStorage = true;
|
|
415
|
+
secretStorageOptions.createSecretStorageKey = ensureRecoveryKey;
|
|
416
|
+
}
|
|
417
|
+
try {
|
|
418
|
+
await crypto.bootstrapSecretStorage(secretStorageOptions);
|
|
419
|
+
} catch (err) {
|
|
420
|
+
if (!(options.allowSecretStorageRecreateWithoutRecoveryKey === true && hasDefaultSecretStorageKey && isRepairableSecretStorageAccessError(err))) throw err;
|
|
421
|
+
recoveryKey = null;
|
|
422
|
+
LogService.warn("MatrixClientLite", "Secret storage exists on the server but local recovery material cannot unlock it; recreating secret storage during explicit bootstrap.");
|
|
423
|
+
await crypto.bootstrapSecretStorage({
|
|
424
|
+
setupNewSecretStorage: true,
|
|
425
|
+
setupNewKeyBackup: options.setupNewKeyBackup === true,
|
|
426
|
+
createSecretStorageKey: ensureRecoveryKey
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
if (generatedRecoveryKey && this.recoveryKeyPath) LogService.warn("MatrixClientLite", `Generated Matrix recovery key and saved it to ${this.recoveryKeyPath}. Keep this file secure.`);
|
|
430
|
+
}
|
|
431
|
+
clearStagedRecoveryKeyTracking() {
|
|
432
|
+
this.stagedRecoveryKey = null;
|
|
433
|
+
this.stagedRecoveryKeyUsed = false;
|
|
434
|
+
this.stagedCacheKeyIds.clear();
|
|
435
|
+
}
|
|
436
|
+
resolveStagedSecretStorageKey(requestedKeyIds) {
|
|
437
|
+
const staged = this.stagedRecoveryKey;
|
|
438
|
+
if (!staged?.privateKeyBase64) return null;
|
|
439
|
+
const privateKey = new Uint8Array(Buffer.from(staged.privateKeyBase64, "base64"));
|
|
440
|
+
if (privateKey.length === 0) return null;
|
|
441
|
+
const keyId = staged.keyId && requestedKeyIds.includes(staged.keyId) ? staged.keyId : requestedKeyIds[0];
|
|
442
|
+
if (!keyId) return null;
|
|
443
|
+
this.rememberStagedSecretStorageKey(keyId, privateKey, staged.keyInfo);
|
|
444
|
+
this.stagedCacheKeyIds.add(keyId);
|
|
445
|
+
return [keyId, privateKey];
|
|
446
|
+
}
|
|
447
|
+
rememberStagedSecretStorageKey(keyId, key, keyInfo) {
|
|
448
|
+
this.stagedRecoveryKeyUsed = true;
|
|
449
|
+
this.rememberSecretStorageKey(keyId, key, keyInfo);
|
|
450
|
+
}
|
|
451
|
+
rememberSecretStorageKey(keyId, key, keyInfo) {
|
|
452
|
+
if (!keyId.trim()) return;
|
|
453
|
+
this.secretStorageKeyCache.set(keyId, {
|
|
454
|
+
key: new Uint8Array(key),
|
|
455
|
+
keyInfo
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
loadStoredRecoveryKey() {
|
|
459
|
+
if (!this.recoveryKeyPath) return null;
|
|
460
|
+
try {
|
|
461
|
+
const parsed = loadJsonFile(this.recoveryKeyPath);
|
|
462
|
+
if (parsed?.version !== 1 || typeof parsed.createdAt !== "string" || typeof parsed.privateKeyBase64 !== "string" || !parsed.privateKeyBase64.trim()) return null;
|
|
463
|
+
return {
|
|
464
|
+
version: 1,
|
|
465
|
+
createdAt: parsed.createdAt,
|
|
466
|
+
keyId: typeof parsed.keyId === "string" ? parsed.keyId : null,
|
|
467
|
+
encodedPrivateKey: typeof parsed.encodedPrivateKey === "string" ? parsed.encodedPrivateKey : void 0,
|
|
468
|
+
privateKeyBase64: parsed.privateKeyBase64,
|
|
469
|
+
keyInfo: parsed.keyInfo && typeof parsed.keyInfo === "object" ? {
|
|
470
|
+
passphrase: parsed.keyInfo.passphrase,
|
|
471
|
+
name: typeof parsed.keyInfo.name === "string" ? parsed.keyInfo.name : void 0
|
|
472
|
+
} : void 0
|
|
473
|
+
};
|
|
474
|
+
} catch {
|
|
475
|
+
return null;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
saveRecoveryKeyToDisk(params) {
|
|
479
|
+
if (!this.recoveryKeyPath) return;
|
|
480
|
+
try {
|
|
481
|
+
const payload = {
|
|
482
|
+
version: 1,
|
|
483
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
484
|
+
keyId: typeof params.keyId === "string" ? params.keyId : null,
|
|
485
|
+
encodedPrivateKey: params.encodedPrivateKey,
|
|
486
|
+
privateKeyBase64: Buffer.from(params.privateKey).toString("base64"),
|
|
487
|
+
keyInfo: params.keyInfo ? {
|
|
488
|
+
passphrase: params.keyInfo.passphrase,
|
|
489
|
+
name: params.keyInfo.name
|
|
490
|
+
} : void 0
|
|
491
|
+
};
|
|
492
|
+
saveJsonFile(this.recoveryKeyPath, payload);
|
|
493
|
+
} catch (err) {
|
|
494
|
+
LogService.warn("MatrixClientLite", "Failed to persist recovery key:", err);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
//#endregion
|
|
211
499
|
//#region extensions/matrix/src/matrix/sdk.ts
|
|
212
500
|
var sdk_exports = /* @__PURE__ */ __exportAll({
|
|
213
501
|
ConsoleLogger: () => ConsoleLogger,
|
|
@@ -290,7 +578,7 @@ function createMatrixExplicitBootstrapOptions(params) {
|
|
|
290
578
|
let loadedMatrixCryptoRuntime = null;
|
|
291
579
|
let matrixCryptoRuntimePromise = null;
|
|
292
580
|
async function loadMatrixCryptoRuntime() {
|
|
293
|
-
matrixCryptoRuntimePromise ??= import("./crypto-runtime-
|
|
581
|
+
matrixCryptoRuntimePromise ??= import("./crypto-runtime-B-SPS5mv.js").then((runtime) => {
|
|
294
582
|
loadedMatrixCryptoRuntime = runtime;
|
|
295
583
|
return runtime;
|
|
296
584
|
});
|
|
@@ -1413,4 +1701,4 @@ var MatrixClient = class {
|
|
|
1413
1701
|
}
|
|
1414
1702
|
};
|
|
1415
1703
|
//#endregion
|
|
1416
|
-
export { sdk_exports as n, MatrixClient as t };
|
|
1704
|
+
export { MATRIX_IDB_SNAPSHOT_LOCK_OPTIONS as i, sdk_exports as n, isRepairableSecretStorageAccessError as r, MatrixClient as t };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries, t as channelSecrets } from "./secret-contract-
|
|
1
|
+
import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries, t as channelSecrets } from "./secret-contract-e4SdhUtT.js";
|
|
2
2
|
export { channelSecrets, collectRuntimeConfigAssignments, secretTargetRegistryEntries };
|