matrix-js-sdk 42.1.0 → 42.2.0

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.
Files changed (154) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lib/@types/beacon.d.ts +1 -1
  3. package/lib/@types/beacon.js +1 -1
  4. package/lib/@types/beacon.js.map +1 -1
  5. package/lib/@types/extensible_events.d.ts.map +1 -1
  6. package/lib/@types/extensible_events.js.map +1 -1
  7. package/lib/autodiscovery.js.map +1 -1
  8. package/lib/browser-index.js.map +1 -1
  9. package/lib/client.d.ts +12 -5
  10. package/lib/client.d.ts.map +1 -1
  11. package/lib/client.js +23 -26
  12. package/lib/client.js.map +1 -1
  13. package/lib/common-crypto/key-passphrase.js +1 -1
  14. package/lib/common-crypto/key-passphrase.js.map +1 -1
  15. package/lib/crypto/store/indexeddb-crypto-store-backend.js +2 -1
  16. package/lib/crypto/store/indexeddb-crypto-store-backend.js.map +1 -1
  17. package/lib/crypto/store/indexeddb-crypto-store.d.ts.map +1 -1
  18. package/lib/crypto/store/indexeddb-crypto-store.js +1 -1
  19. package/lib/crypto/store/indexeddb-crypto-store.js.map +1 -1
  20. package/lib/crypto/store/memory-crypto-store.js.map +1 -1
  21. package/lib/embedded.d.ts +16 -0
  22. package/lib/embedded.d.ts.map +1 -1
  23. package/lib/embedded.js +19 -6
  24. package/lib/embedded.js.map +1 -1
  25. package/lib/matrixrtc/MatrixRTCSession.js.map +1 -1
  26. package/lib/matrixrtc/MembershipManager.js.map +1 -1
  27. package/lib/matrixrtc/MembershipManagerActionScheduler.js.map +1 -1
  28. package/lib/matrixrtc/RTCEncryptionManager.js.map +1 -1
  29. package/lib/matrixrtc/ToDeviceKeyTransport.js.map +1 -1
  30. package/lib/matrixrtc/membershipData/rtc.js.map +1 -1
  31. package/lib/matrixrtc/utils.d.ts +0 -1
  32. package/lib/matrixrtc/utils.d.ts.map +1 -1
  33. package/lib/matrixrtc/utils.js +0 -1
  34. package/lib/matrixrtc/utils.js.map +1 -1
  35. package/lib/models/event-timeline-set.js +3 -3
  36. package/lib/models/event-timeline-set.js.map +1 -1
  37. package/lib/models/event.d.ts.map +1 -1
  38. package/lib/models/event.js.map +1 -1
  39. package/lib/models/invites-ignorer.js.map +1 -1
  40. package/lib/models/poll.js.map +1 -1
  41. package/lib/models/read-receipt.js.map +1 -1
  42. package/lib/models/relations-container.d.ts +10 -0
  43. package/lib/models/relations-container.d.ts.map +1 -1
  44. package/lib/models/relations-container.js +39 -17
  45. package/lib/models/relations-container.js.map +1 -1
  46. package/lib/models/relations.js +1 -1
  47. package/lib/models/relations.js.map +1 -1
  48. package/lib/models/room.js +3 -3
  49. package/lib/models/room.js.map +1 -1
  50. package/lib/models/thread.d.ts +3 -0
  51. package/lib/models/thread.d.ts.map +1 -1
  52. package/lib/models/thread.js +36 -3
  53. package/lib/models/thread.js.map +1 -1
  54. package/lib/oauth/authorize.js +1 -1
  55. package/lib/oauth/authorize.js.map +1 -1
  56. package/lib/oauth/index.js +4 -2
  57. package/lib/oauth/index.js.map +1 -1
  58. package/lib/pollingCachedValue.d.ts +77 -0
  59. package/lib/pollingCachedValue.d.ts.map +1 -0
  60. package/lib/pollingCachedValue.js +160 -0
  61. package/lib/pollingCachedValue.js.map +1 -0
  62. package/lib/pushprocessor.js.map +1 -1
  63. package/lib/receipt-accumulator.d.ts.map +1 -1
  64. package/lib/receipt-accumulator.js.map +1 -1
  65. package/lib/rendezvous/MSC4108SignInWithQR.d.ts.map +1 -1
  66. package/lib/rendezvous/MSC4108SignInWithQR.js +2 -3
  67. package/lib/rendezvous/MSC4108SignInWithQR.js.map +1 -1
  68. package/lib/rtcTransportsCachedValue.d.ts +9 -0
  69. package/lib/rtcTransportsCachedValue.d.ts.map +1 -0
  70. package/lib/rtcTransportsCachedValue.js +38 -0
  71. package/lib/rtcTransportsCachedValue.js.map +1 -0
  72. package/lib/rust-crypto/PerSessionKeyBackupDownloader.js.map +1 -1
  73. package/lib/rust-crypto/backup.d.ts +2 -3
  74. package/lib/rust-crypto/backup.d.ts.map +1 -1
  75. package/lib/rust-crypto/backup.js.map +1 -1
  76. package/lib/rust-crypto/index.d.ts +10 -4
  77. package/lib/rust-crypto/index.d.ts.map +1 -1
  78. package/lib/rust-crypto/index.js +20 -3
  79. package/lib/rust-crypto/index.js.map +1 -1
  80. package/lib/rust-crypto/libolm_migration.js.map +1 -1
  81. package/lib/rust-crypto/rust-crypto.js.map +1 -1
  82. package/lib/sliding-sync-sdk.js.map +1 -1
  83. package/lib/sliding-sync.js.map +1 -1
  84. package/lib/store/indexeddb-local-backend.js +1 -1
  85. package/lib/store/indexeddb-local-backend.js.map +1 -1
  86. package/lib/store/indexeddb-store-worker.d.ts.map +1 -1
  87. package/lib/store/indexeddb-store-worker.js +1 -0
  88. package/lib/store/indexeddb-store-worker.js.map +1 -1
  89. package/lib/sync.d.ts.map +1 -1
  90. package/lib/sync.js.map +1 -1
  91. package/lib/utils.d.ts +1 -1
  92. package/lib/utils.d.ts.map +1 -1
  93. package/lib/utils.js +1 -0
  94. package/lib/utils.js.map +1 -1
  95. package/lib/webrtc/call.js.map +1 -1
  96. package/lib/webrtc/groupCall.js.map +1 -1
  97. package/lib/webrtc/mediaHandler.js.map +1 -1
  98. package/lib/webrtc/stats/callStatsReportGatherer.js.map +1 -1
  99. package/lib/webrtc/stats/transportStatsBuilder.js.map +1 -1
  100. package/lib/wellKnownCachedValue.d.ts +8 -0
  101. package/lib/wellKnownCachedValue.d.ts.map +1 -0
  102. package/lib/wellKnownCachedValue.js +34 -0
  103. package/lib/wellKnownCachedValue.js.map +1 -0
  104. package/package.json +4 -4
  105. package/src/@types/beacon.ts +1 -1
  106. package/src/@types/extensible_events.ts +3 -4
  107. package/src/autodiscovery.ts +2 -2
  108. package/src/browser-index.ts +1 -1
  109. package/src/client.ts +48 -40
  110. package/src/common-crypto/key-passphrase.ts +1 -1
  111. package/src/crypto/store/indexeddb-crypto-store-backend.ts +2 -1
  112. package/src/crypto/store/indexeddb-crypto-store.ts +1 -3
  113. package/src/crypto/store/memory-crypto-store.ts +1 -1
  114. package/src/embedded.ts +34 -11
  115. package/src/matrixrtc/MatrixRTCSession.ts +3 -3
  116. package/src/matrixrtc/MembershipManager.ts +1 -1
  117. package/src/matrixrtc/MembershipManagerActionScheduler.ts +1 -1
  118. package/src/matrixrtc/RTCEncryptionManager.ts +2 -2
  119. package/src/matrixrtc/ToDeviceKeyTransport.ts +3 -3
  120. package/src/matrixrtc/membershipData/rtc.ts +1 -1
  121. package/src/matrixrtc/utils.ts +0 -2
  122. package/src/models/event-timeline-set.ts +3 -3
  123. package/src/models/event.ts +7 -10
  124. package/src/models/invites-ignorer.ts +1 -1
  125. package/src/models/poll.ts +1 -1
  126. package/src/models/read-receipt.ts +1 -1
  127. package/src/models/relations-container.ts +55 -19
  128. package/src/models/relations.ts +1 -1
  129. package/src/models/room.ts +9 -9
  130. package/src/models/thread.ts +49 -4
  131. package/src/oauth/authorize.ts +1 -1
  132. package/src/oauth/index.ts +2 -2
  133. package/src/pollingCachedValue.ts +184 -0
  134. package/src/pushprocessor.ts +3 -3
  135. package/src/receipt-accumulator.ts +1 -2
  136. package/src/rendezvous/MSC4108SignInWithQR.ts +3 -4
  137. package/src/rtcTransportsCachedValue.ts +40 -0
  138. package/src/rust-crypto/PerSessionKeyBackupDownloader.ts +1 -1
  139. package/src/rust-crypto/backup.ts +1 -5
  140. package/src/rust-crypto/index.ts +23 -25
  141. package/src/rust-crypto/libolm_migration.ts +1 -1
  142. package/src/rust-crypto/rust-crypto.ts +3 -3
  143. package/src/sliding-sync-sdk.ts +1 -1
  144. package/src/sliding-sync.ts +1 -1
  145. package/src/store/indexeddb-local-backend.ts +1 -1
  146. package/src/store/indexeddb-store-worker.ts +1 -0
  147. package/src/sync.ts +4 -3
  148. package/src/utils.ts +3 -2
  149. package/src/webrtc/call.ts +6 -6
  150. package/src/webrtc/groupCall.ts +7 -7
  151. package/src/webrtc/mediaHandler.ts +1 -1
  152. package/src/webrtc/stats/callStatsReportGatherer.ts +2 -2
  153. package/src/webrtc/stats/transportStatsBuilder.ts +1 -1
  154. package/src/wellKnownCachedValue.ts +34 -0
@@ -23,7 +23,7 @@ import { deriveRecoveryKeyFromPassphrase } from "../crypto-api/index.js";
23
23
  */
24
24
  export function keyFromAuthData(authData, passphrase) {
25
25
  if (!authData.private_key_salt || !authData.private_key_iterations) {
26
- throw new Error("Salt and/or iterations not found: " + "this backup cannot be restored with a passphrase");
26
+ throw new Error("Salt and/or iterations not found: this backup cannot be restored with a passphrase");
27
27
  }
28
28
  return deriveRecoveryKeyFromPassphrase(passphrase, authData.private_key_salt, authData.private_key_iterations, authData.private_key_bits);
29
29
  }
@@ -1 +1 @@
1
- {"version":3,"file":"key-passphrase.js","names":[],"sources":["../../src/common-crypto/key-passphrase.ts"],"sourcesContent":["/*\n * Copyright 2024 The Matrix.org Foundation C.I.C.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { deriveRecoveryKeyFromPassphrase } from \"../crypto-api/index.ts\";\n\ninterface IAuthData {\n private_key_salt?: string;\n private_key_iterations?: number;\n private_key_bits?: number;\n}\n\n/**\n * Derive a backup key from a passphrase using the salt and iterations from the auth data.\n * @param authData - The auth data containing the salt and iterations\n * @param passphrase - The passphrase to derive the key from\n * @deprecated Deriving a backup key from a passphrase is not part of the matrix spec. Instead, a random key is generated and stored/shared via 4S.\n */\nexport function keyFromAuthData(authData: IAuthData, passphrase: string): Promise<Uint8Array> {\n if (!authData.private_key_salt || !authData.private_key_iterations) {\n throw new Error(\"Salt and/or iterations not found: \" + \"this backup cannot be restored with a passphrase\");\n }\n\n return deriveRecoveryKeyFromPassphrase(\n passphrase,\n authData.private_key_salt,\n authData.private_key_iterations,\n authData.private_key_bits,\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAS,+BAA+B,QAAQ,wBAAwB;AAQxE;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,eAAe,CAAC,QAAmB,EAAE,UAAkB,EAAuB;EAC1F,IAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,QAAQ,CAAC,sBAAsB,EAAE;IAChE,MAAM,IAAI,KAAK,CAAC,oCAAoC,GAAG,kDAAkD,CAAC;EAC9G;EAEA,OAAO,+BAA+B,CAClC,UAAU,EACV,QAAQ,CAAC,gBAAgB,EACzB,QAAQ,CAAC,sBAAsB,EAC/B,QAAQ,CAAC,gBACb,CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"file":"key-passphrase.js","names":[],"sources":["../../src/common-crypto/key-passphrase.ts"],"sourcesContent":["/*\n * Copyright 2024 The Matrix.org Foundation C.I.C.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { deriveRecoveryKeyFromPassphrase } from \"../crypto-api/index.ts\";\n\ninterface IAuthData {\n private_key_salt?: string;\n private_key_iterations?: number;\n private_key_bits?: number;\n}\n\n/**\n * Derive a backup key from a passphrase using the salt and iterations from the auth data.\n * @param authData - The auth data containing the salt and iterations\n * @param passphrase - The passphrase to derive the key from\n * @deprecated Deriving a backup key from a passphrase is not part of the matrix spec. Instead, a random key is generated and stored/shared via 4S.\n */\nexport function keyFromAuthData(authData: IAuthData, passphrase: string): Promise<Uint8Array> {\n if (!authData.private_key_salt || !authData.private_key_iterations) {\n throw new Error(\"Salt and/or iterations not found: this backup cannot be restored with a passphrase\");\n }\n\n return deriveRecoveryKeyFromPassphrase(\n passphrase,\n authData.private_key_salt,\n authData.private_key_iterations,\n authData.private_key_bits,\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAS,+BAA+B,QAAQ,wBAAwB;AAQxE;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,eAAe,CAAC,QAAmB,EAAE,UAAkB,EAAuB;EAC1F,IAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,QAAQ,CAAC,sBAAsB,EAAE;IAChE,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC;EACzG;EAEA,OAAO,+BAA+B,CAClC,UAAU,EACV,QAAQ,CAAC,gBAAgB,EACzB,QAAQ,CAAC,sBAAsB,EAC/B,QAAQ,CAAC,gBACb,CAAC;AACL","ignoreList":[]}
@@ -494,7 +494,7 @@ const DB_MIGRATIONS = [db => {
494
494
  ];
495
495
  export const VERSION = DB_MIGRATIONS.length;
496
496
  export function upgradeDatabase(db, oldVersion) {
497
- logger.log(`Upgrading IndexedDBCryptoStore from version ${oldVersion}` + ` to ${VERSION}`);
497
+ logger.log(`Upgrading IndexedDBCryptoStore from version ${oldVersion} to ${VERSION}`);
498
498
  DB_MIGRATIONS.forEach((migration, index) => {
499
499
  if (oldVersion <= index) migration(db);
500
500
  });
@@ -530,6 +530,7 @@ function promiseifyTxn(txn) {
530
530
  txn.oncomplete = () => {
531
531
  if (txn._mx_abortexception !== undefined) {
532
532
  reject(txn._mx_abortexception);
533
+ return;
533
534
  }
534
535
  resolve(null);
535
536
  };
@@ -1 +1 @@
1
- {"version":3,"file":"indexeddb-crypto-store-backend.js","names":[],"sources":["../../../src/crypto/store/indexeddb-crypto-store-backend.ts"],"sourcesContent":["/*\nCopyright 2017 - 2021 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type Logger, logger } from \"../../logger.ts\";\nimport {\n type CryptoStore,\n type IDeviceData,\n type ISession,\n type SessionExtended,\n type ISessionInfo,\n type IWithheld,\n MigrationState,\n type Mode,\n type SecretStorePrivateKeys,\n SESSION_BATCH_SIZE,\n ACCOUNT_OBJECT_KEY_MIGRATION_STATE,\n type InboundGroupSessionData,\n type IRoomEncryption,\n} from \"./base.ts\";\nimport { IndexedDBCryptoStore } from \"./indexeddb-crypto-store.ts\";\nimport { type CrossSigningKeyInfo } from \"../../crypto-api/index.ts\";\n\nconst PROFILE_TRANSACTIONS = false;\n\n/**\n * Implementation of a CryptoStore which is backed by an existing\n * IndexedDB connection. Generally you want IndexedDBCryptoStore\n * which connects to the database and defers to one of these.\n *\n * @internal\n */\nexport class Backend implements CryptoStore {\n private nextTxnId = 0;\n\n /**\n */\n public constructor(private db: IDBDatabase) {\n // make sure we close the db on `onversionchange` - otherwise\n // attempts to delete the database will block (and subsequent\n // attempts to re-create it will also block).\n db.onversionchange = (): void => {\n logger.log(`versionchange for indexeddb ${this.db.name}: closing`);\n db.close();\n };\n }\n\n public async containsData(): Promise<boolean> {\n throw Error(\"Not implemented for Backend\");\n }\n\n public async startup(): Promise<CryptoStore> {\n // No work to do, as the startup is done by the caller (e.g IndexedDBCryptoStore)\n // by passing us a ready IDBDatabase instance\n return this;\n }\n\n public async deleteAllData(): Promise<void> {\n throw Error(\"This is not implemented, call IDBFactory::deleteDatabase(dbName) instead.\");\n }\n\n /**\n * Get data on how much of the libolm to Rust Crypto migration has been done.\n *\n * Implementation of {@link CryptoStore.getMigrationState}.\n */\n public async getMigrationState(): Promise<MigrationState> {\n let migrationState = MigrationState.NOT_STARTED;\n await this.doTxn(\"readonly\", [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => {\n const objectStore = txn.objectStore(IndexedDBCryptoStore.STORE_ACCOUNT);\n const getReq = objectStore.get(ACCOUNT_OBJECT_KEY_MIGRATION_STATE);\n getReq.onsuccess = (): void => {\n migrationState = getReq.result ?? MigrationState.NOT_STARTED;\n };\n });\n return migrationState;\n }\n\n /**\n * Set data on how much of the libolm to Rust Crypto migration has been done.\n *\n * Implementation of {@link CryptoStore.setMigrationState}.\n */\n public async setMigrationState(migrationState: MigrationState): Promise<void> {\n await this.doTxn(\"readwrite\", [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => {\n const objectStore = txn.objectStore(IndexedDBCryptoStore.STORE_ACCOUNT);\n objectStore.put(migrationState, ACCOUNT_OBJECT_KEY_MIGRATION_STATE);\n });\n }\n\n // Olm Account\n\n public getAccount(txn: IDBTransaction, func: (accountPickle: string | null) => void): void {\n const objectStore = txn.objectStore(\"account\");\n const getReq = objectStore.get(\"-\");\n getReq.onsuccess = function (): void {\n try {\n func(getReq.result || null);\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n }\n\n public storeAccount(txn: IDBTransaction, accountPickle: string): void {\n const objectStore = txn.objectStore(\"account\");\n objectStore.put(accountPickle, \"-\");\n }\n\n public getCrossSigningKeys(\n txn: IDBTransaction,\n func: (keys: Record<string, CrossSigningKeyInfo> | null) => void,\n ): void {\n const objectStore = txn.objectStore(\"account\");\n const getReq = objectStore.get(\"crossSigningKeys\");\n getReq.onsuccess = function (): void {\n try {\n func(getReq.result || null);\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n }\n\n public getSecretStorePrivateKey<K extends keyof SecretStorePrivateKeys>(\n txn: IDBTransaction,\n func: (key: SecretStorePrivateKeys[K] | null) => void,\n type: K,\n ): void {\n const objectStore = txn.objectStore(\"account\");\n const getReq = objectStore.get(`ssss_cache:${type}`);\n getReq.onsuccess = function (): void {\n try {\n func(getReq.result || null);\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n }\n\n public storeSecretStorePrivateKey<K extends keyof SecretStorePrivateKeys>(\n txn: IDBTransaction,\n type: K,\n key: SecretStorePrivateKeys[K],\n ): void {\n const objectStore = txn.objectStore(\"account\");\n objectStore.put(key, `ssss_cache:${type}`);\n }\n\n // Olm Sessions\n\n public countEndToEndSessions(txn: IDBTransaction, func: (count: number) => void): void {\n const objectStore = txn.objectStore(\"sessions\");\n const countReq = objectStore.count();\n countReq.onsuccess = function (): void {\n try {\n func(countReq.result);\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n }\n\n public getEndToEndSessions(\n deviceKey: string,\n txn: IDBTransaction,\n func: (sessions: { [sessionId: string]: ISessionInfo }) => void,\n ): void {\n const objectStore = txn.objectStore(\"sessions\");\n const idx = objectStore.index(\"deviceKey\");\n const getReq = idx.openCursor(deviceKey);\n const results: Parameters<Parameters<Backend[\"getEndToEndSessions\"]>[2]>[0] = {};\n getReq.onsuccess = function (): void {\n const cursor = getReq.result;\n if (cursor) {\n results[cursor.value.sessionId] = {\n session: cursor.value.session,\n lastReceivedMessageTs: cursor.value.lastReceivedMessageTs,\n };\n cursor.continue();\n } else {\n try {\n func(results);\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n }\n };\n }\n\n public getEndToEndSession(\n deviceKey: string,\n sessionId: string,\n txn: IDBTransaction,\n func: (session: ISessionInfo | null) => void,\n ): void {\n const objectStore = txn.objectStore(\"sessions\");\n const getReq = objectStore.get([deviceKey, sessionId]);\n getReq.onsuccess = function (): void {\n try {\n if (getReq.result) {\n func({\n session: getReq.result.session,\n lastReceivedMessageTs: getReq.result.lastReceivedMessageTs,\n });\n } else {\n func(null);\n }\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n }\n\n public storeEndToEndSession(\n deviceKey: string,\n sessionId: string,\n sessionInfo: ISessionInfo,\n txn: IDBTransaction,\n ): void {\n const objectStore = txn.objectStore(\"sessions\");\n objectStore.put({\n deviceKey,\n sessionId,\n session: sessionInfo.session,\n lastReceivedMessageTs: sessionInfo.lastReceivedMessageTs,\n });\n }\n\n /**\n * Fetch a batch of Olm sessions from the database.\n *\n * Implementation of {@link CryptoStore.getEndToEndSessionsBatch}.\n */\n public async getEndToEndSessionsBatch(): Promise<null | ISessionInfo[]> {\n const result: ISessionInfo[] = [];\n await this.doTxn(\"readonly\", [IndexedDBCryptoStore.STORE_SESSIONS], (txn) => {\n const objectStore = txn.objectStore(IndexedDBCryptoStore.STORE_SESSIONS);\n const getReq = objectStore.openCursor();\n getReq.onsuccess = function (): void {\n try {\n const cursor = getReq.result;\n if (cursor) {\n result.push(cursor.value);\n if (result.length < SESSION_BATCH_SIZE) {\n cursor.continue();\n }\n }\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n });\n\n if (result.length === 0) {\n // No sessions left.\n return null;\n }\n\n return result;\n }\n\n /**\n * Delete a batch of Olm sessions from the database.\n *\n * Implementation of {@link CryptoStore.deleteEndToEndSessionsBatch}.\n *\n * @internal\n */\n public async deleteEndToEndSessionsBatch(sessions: { deviceKey: string; sessionId: string }[]): Promise<void> {\n await this.doTxn(\"readwrite\", [IndexedDBCryptoStore.STORE_SESSIONS], async (txn) => {\n try {\n const objectStore = txn.objectStore(IndexedDBCryptoStore.STORE_SESSIONS);\n for (const { deviceKey, sessionId } of sessions) {\n const req = objectStore.delete([deviceKey, sessionId]);\n await new Promise((resolve) => {\n req.onsuccess = resolve;\n });\n }\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n });\n }\n\n // Inbound group sessions\n\n public getEndToEndInboundGroupSession(\n senderCurve25519Key: string,\n sessionId: string,\n txn: IDBTransaction,\n func: (groupSession: InboundGroupSessionData | null, groupSessionWithheld: IWithheld | null) => void,\n ): void {\n let session: InboundGroupSessionData | null | boolean = false;\n let withheld: IWithheld | null | boolean = false;\n const objectStore = txn.objectStore(\"inbound_group_sessions\");\n const getReq = objectStore.get([senderCurve25519Key, sessionId]);\n getReq.onsuccess = function (): void {\n try {\n if (getReq.result) {\n session = getReq.result.session;\n } else {\n session = null;\n }\n if (withheld !== false) {\n func(session as InboundGroupSessionData, withheld as IWithheld);\n }\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n\n const withheldObjectStore = txn.objectStore(\"inbound_group_sessions_withheld\");\n const withheldGetReq = withheldObjectStore.get([senderCurve25519Key, sessionId]);\n withheldGetReq.onsuccess = function (): void {\n try {\n if (withheldGetReq.result) {\n withheld = withheldGetReq.result.session;\n } else {\n withheld = null;\n }\n if (session !== false) {\n func(session as InboundGroupSessionData, withheld as IWithheld);\n }\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n }\n\n public storeEndToEndInboundGroupSession(\n senderCurve25519Key: string,\n sessionId: string,\n sessionData: InboundGroupSessionData,\n txn: IDBTransaction,\n ): void {\n const objectStore = txn.objectStore(\"inbound_group_sessions\");\n objectStore.put({\n senderCurve25519Key,\n sessionId,\n session: sessionData,\n });\n }\n\n /**\n * Count the number of Megolm sessions in the database.\n *\n * Implementation of {@link CryptoStore.countEndToEndInboundGroupSessions}.\n *\n * @internal\n */\n public async countEndToEndInboundGroupSessions(): Promise<number> {\n let result = 0;\n await this.doTxn(\"readonly\", [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], (txn) => {\n const sessionStore = txn.objectStore(IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS);\n const countReq = sessionStore.count();\n countReq.onsuccess = (): void => {\n result = countReq.result;\n };\n });\n return result;\n }\n\n /**\n * Fetch a batch of Megolm sessions from the database.\n *\n * Implementation of {@link CryptoStore.getEndToEndInboundGroupSessionsBatch}.\n */\n public async getEndToEndInboundGroupSessionsBatch(): Promise<null | SessionExtended[]> {\n const result: SessionExtended[] = [];\n await this.doTxn(\n \"readonly\",\n [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS, IndexedDBCryptoStore.STORE_BACKUP],\n (txn) => {\n const sessionStore = txn.objectStore(IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS);\n const backupStore = txn.objectStore(IndexedDBCryptoStore.STORE_BACKUP);\n\n const getReq = sessionStore.openCursor();\n getReq.onsuccess = function (): void {\n try {\n const cursor = getReq.result;\n if (cursor) {\n const backupGetReq = backupStore.get(cursor.key);\n backupGetReq.onsuccess = (): void => {\n result.push({\n senderKey: cursor.value.senderCurve25519Key,\n sessionId: cursor.value.sessionId,\n sessionData: cursor.value.session,\n needsBackup: backupGetReq.result !== undefined,\n });\n if (result.length < SESSION_BATCH_SIZE) {\n cursor.continue();\n }\n };\n }\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n },\n );\n\n if (result.length === 0) {\n // No sessions left.\n return null;\n }\n\n return result;\n }\n\n /**\n * Delete a batch of Megolm sessions from the database.\n *\n * Implementation of {@link CryptoStore.deleteEndToEndInboundGroupSessionsBatch}.\n *\n * @internal\n */\n public async deleteEndToEndInboundGroupSessionsBatch(\n sessions: { senderKey: string; sessionId: string }[],\n ): Promise<void> {\n await this.doTxn(\"readwrite\", [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], async (txn) => {\n try {\n const objectStore = txn.objectStore(IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS);\n for (const { senderKey, sessionId } of sessions) {\n const req = objectStore.delete([senderKey, sessionId]);\n await new Promise((resolve) => {\n req.onsuccess = resolve;\n });\n }\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n });\n }\n\n public getEndToEndDeviceData(txn: IDBTransaction, func: (deviceData: IDeviceData | null) => void): void {\n const objectStore = txn.objectStore(\"device_data\");\n const getReq = objectStore.get(\"-\");\n getReq.onsuccess = function (): void {\n try {\n func(getReq.result || null);\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n }\n\n public getEndToEndRooms(txn: IDBTransaction, func: (rooms: Record<string, IRoomEncryption>) => void): void {\n const rooms: Parameters<Parameters<Backend[\"getEndToEndRooms\"]>[1]>[0] = {};\n const objectStore = txn.objectStore(\"rooms\");\n const getReq = objectStore.openCursor();\n getReq.onsuccess = function (): void {\n const cursor = getReq.result;\n if (cursor) {\n rooms[cursor.key as string] = cursor.value;\n cursor.continue();\n } else {\n try {\n func(rooms);\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n }\n };\n }\n\n public async markSessionsNeedingBackup(sessions: ISession[], txn?: IDBTransaction): Promise<void> {\n if (!txn) {\n txn = this.db.transaction(\"sessions_needing_backup\", \"readwrite\");\n }\n const objectStore = txn.objectStore(\"sessions_needing_backup\");\n await Promise.all(\n sessions.map((session) => {\n return new Promise((resolve, reject) => {\n const req = objectStore.put({\n senderCurve25519Key: session.senderKey,\n sessionId: session.sessionId,\n });\n req.onsuccess = resolve;\n req.onerror = reject;\n });\n }),\n );\n }\n\n public doTxn<T>(\n mode: Mode,\n stores: string | string[],\n func: (txn: IDBTransaction) => T,\n log: Logger = logger,\n ): Promise<T> {\n let startTime: number;\n let description: string;\n if (PROFILE_TRANSACTIONS) {\n const txnId = this.nextTxnId++;\n startTime = Date.now();\n description = `${mode} crypto store transaction ${txnId} in ${stores}`;\n log.debug(`Starting ${description}`);\n }\n const txn = this.db.transaction(stores, mode);\n const promise = promiseifyTxn(txn);\n const result = func(txn);\n if (PROFILE_TRANSACTIONS) {\n promise.then(\n () => {\n const elapsedTime = Date.now() - startTime;\n log.debug(`Finished ${description}, took ${elapsedTime} ms`);\n },\n () => {\n const elapsedTime = Date.now() - startTime;\n log.error(`Failed ${description}, took ${elapsedTime} ms`);\n },\n );\n }\n return promise.then(() => {\n return result;\n });\n }\n}\n\ntype DbMigration = (db: IDBDatabase) => void;\nconst DB_MIGRATIONS: DbMigration[] = [\n (db): void => {\n createDatabase(db);\n },\n (db): void => {\n db.createObjectStore(\"account\");\n },\n (db): void => {\n const sessionsStore = db.createObjectStore(\"sessions\", {\n keyPath: [\"deviceKey\", \"sessionId\"],\n });\n sessionsStore.createIndex(\"deviceKey\", \"deviceKey\");\n },\n (db): void => {\n db.createObjectStore(\"inbound_group_sessions\", {\n keyPath: [\"senderCurve25519Key\", \"sessionId\"],\n });\n },\n (db): void => {\n db.createObjectStore(\"device_data\");\n },\n (db): void => {\n db.createObjectStore(\"rooms\");\n },\n (db): void => {\n db.createObjectStore(\"sessions_needing_backup\", {\n keyPath: [\"senderCurve25519Key\", \"sessionId\"],\n });\n },\n (db): void => {\n db.createObjectStore(\"inbound_group_sessions_withheld\", {\n keyPath: [\"senderCurve25519Key\", \"sessionId\"],\n });\n },\n (db): void => {\n const problemsStore = db.createObjectStore(\"session_problems\", {\n keyPath: [\"deviceKey\", \"time\"],\n });\n problemsStore.createIndex(\"deviceKey\", \"deviceKey\");\n\n db.createObjectStore(\"notified_error_devices\", {\n keyPath: [\"userId\", \"deviceId\"],\n });\n },\n (db): void => {\n db.createObjectStore(\"shared_history_inbound_group_sessions\", {\n keyPath: [\"roomId\"],\n });\n },\n (db): void => {\n db.createObjectStore(\"parked_shared_history\", {\n keyPath: [\"roomId\"],\n });\n },\n // Expand as needed.\n];\nexport const VERSION = DB_MIGRATIONS.length;\n\nexport function upgradeDatabase(db: IDBDatabase, oldVersion: number): void {\n logger.log(`Upgrading IndexedDBCryptoStore from version ${oldVersion}` + ` to ${VERSION}`);\n DB_MIGRATIONS.forEach((migration, index) => {\n if (oldVersion <= index) migration(db);\n });\n}\n\nfunction createDatabase(db: IDBDatabase): void {\n const outgoingRoomKeyRequestsStore = db.createObjectStore(\"outgoingRoomKeyRequests\", { keyPath: \"requestId\" });\n\n // we assume that the RoomKeyRequestBody will have room_id and session_id\n // properties, to make the index efficient.\n outgoingRoomKeyRequestsStore.createIndex(\"session\", [\"requestBody.room_id\", \"requestBody.session_id\"]);\n\n outgoingRoomKeyRequestsStore.createIndex(\"state\", \"state\");\n}\n\ninterface IWrappedIDBTransaction extends IDBTransaction {\n _mx_abortexception: Error;\n}\n\n/*\n * Aborts a transaction with a given exception\n * The transaction promise will be rejected with this exception.\n */\nfunction abortWithException(txn: IDBTransaction, e: Error): void {\n // We cheekily stick our exception onto the transaction object here\n // We could alternatively make the thing we pass back to the app\n // an object containing the transaction and exception.\n (txn as IWrappedIDBTransaction)._mx_abortexception = e;\n try {\n txn.abort();\n } catch {\n // sometimes we won't be able to abort the transaction\n // (ie. if it's aborted or completed)\n }\n}\n\nfunction promiseifyTxn<T>(txn: IDBTransaction): Promise<T | null> {\n return new Promise((resolve, reject) => {\n txn.oncomplete = (): void => {\n if ((txn as IWrappedIDBTransaction)._mx_abortexception !== undefined) {\n reject((txn as IWrappedIDBTransaction)._mx_abortexception);\n }\n resolve(null);\n };\n txn.onerror = (event): void => {\n if ((txn as IWrappedIDBTransaction)._mx_abortexception !== undefined) {\n reject((txn as IWrappedIDBTransaction)._mx_abortexception);\n } else {\n logger.log(\"Error performing indexeddb txn\", event);\n reject(txn.error);\n }\n };\n txn.onabort = (event): void => {\n if ((txn as IWrappedIDBTransaction)._mx_abortexception !== undefined) {\n reject((txn as IWrappedIDBTransaction)._mx_abortexception);\n } else {\n logger.log(\"Error performing indexeddb txn\", event);\n reject(txn.error);\n }\n };\n });\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAsB,MAAM,QAAQ,iBAAiB;AACrD,SAOI,cAAc,EAGd,kBAAkB,EAClB,kCAAkC,QAG/B,WAAW;AAClB,SAAS,oBAAoB,QAAQ,6BAA6B;AAGlE,MAAM,oBAAoB,GAAG,KAAK;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAM,OAAO,CAAwB;EAGxC;AACJ;EACW,WAAW,CAAS,EAAe,EAAE;IAAA,mCAJxB,CAAC;IAAA,KAIM,EAAe,GAAf,EAAe;IACtC;IACA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AAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;IACpC,GAAG,CAAC,UAAU,GAAG,MAAY;MACzB,IAAK,GAAG,CAA4B,kBAAkB,KAAK,SAAS,EAAE;QAClE,MAAM,CAAE,GAAG,CAA4B,kBAAkB,CAAC;MAC9D;MACA,OAAO,CAAC,IAAI,CAAC;IACjB,CAAC;IACD,GAAG,CAAC,OAAO,GAAI,KAAK,IAAW;MAC3B,IAAK,GAAG,CAA4B,kBAAkB,KAAK,SAAS,EAAE;QAClE,MAAM,CAAE,GAAG,CAA4B,kBAAkB,CAAC;MAC9D,CAAC,MAAM;QACH,MAAM,CAAC,GAAG,CAAC,gCAAgC,EAAE,KAAK,CAAC;QACnD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;MACrB;IACJ,CAAC;IACD,GAAG,CAAC,OAAO,GAAI,KAAK,IAAW;MAC3B,IAAK,GAAG,CAA4B,kBAAkB,KAAK,SAAS,EAAE;QAClE,MAAM,CAAE,GAAG,CAA4B,kBAAkB,CAAC;MAC9D,CAAC,MAAM;QACH,MAAM,CAAC,GAAG,CAAC,gCAAgC,EAAE,KAAK,CAAC;QACnD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;MACrB;IACJ,CAAC;EACL,CAAC,CAAC;AACN","ignoreList":[]}
1
+ {"version":3,"file":"indexeddb-crypto-store-backend.js","names":[],"sources":["../../../src/crypto/store/indexeddb-crypto-store-backend.ts"],"sourcesContent":["/*\nCopyright 2017 - 2021 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type Logger, logger } from \"../../logger.ts\";\nimport {\n type CryptoStore,\n type IDeviceData,\n type ISession,\n type SessionExtended,\n type ISessionInfo,\n type IWithheld,\n MigrationState,\n type Mode,\n type SecretStorePrivateKeys,\n SESSION_BATCH_SIZE,\n ACCOUNT_OBJECT_KEY_MIGRATION_STATE,\n type InboundGroupSessionData,\n type IRoomEncryption,\n} from \"./base.ts\";\nimport { IndexedDBCryptoStore } from \"./indexeddb-crypto-store.ts\";\nimport { type CrossSigningKeyInfo } from \"../../crypto-api/index.ts\";\n\nconst PROFILE_TRANSACTIONS = false;\n\n/**\n * Implementation of a CryptoStore which is backed by an existing\n * IndexedDB connection. Generally you want IndexedDBCryptoStore\n * which connects to the database and defers to one of these.\n *\n * @internal\n */\nexport class Backend implements CryptoStore {\n private nextTxnId = 0;\n\n /**\n */\n public constructor(private db: IDBDatabase) {\n // make sure we close the db on `onversionchange` - otherwise\n // attempts to delete the database will block (and subsequent\n // attempts to re-create it will also block).\n db.onversionchange = (): void => {\n logger.log(`versionchange for indexeddb ${this.db.name}: closing`);\n db.close();\n };\n }\n\n public async containsData(): Promise<boolean> {\n throw Error(\"Not implemented for Backend\");\n }\n\n public async startup(): Promise<CryptoStore> {\n // No work to do, as the startup is done by the caller (e.g IndexedDBCryptoStore)\n // by passing us a ready IDBDatabase instance\n return this;\n }\n\n public async deleteAllData(): Promise<void> {\n throw Error(\"This is not implemented, call IDBFactory::deleteDatabase(dbName) instead.\");\n }\n\n /**\n * Get data on how much of the libolm to Rust Crypto migration has been done.\n *\n * Implementation of {@link CryptoStore.getMigrationState}.\n */\n public async getMigrationState(): Promise<MigrationState> {\n let migrationState = MigrationState.NOT_STARTED;\n await this.doTxn(\"readonly\", [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => {\n const objectStore = txn.objectStore(IndexedDBCryptoStore.STORE_ACCOUNT);\n const getReq = objectStore.get(ACCOUNT_OBJECT_KEY_MIGRATION_STATE);\n getReq.onsuccess = (): void => {\n migrationState = getReq.result ?? MigrationState.NOT_STARTED;\n };\n });\n return migrationState;\n }\n\n /**\n * Set data on how much of the libolm to Rust Crypto migration has been done.\n *\n * Implementation of {@link CryptoStore.setMigrationState}.\n */\n public async setMigrationState(migrationState: MigrationState): Promise<void> {\n await this.doTxn(\"readwrite\", [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => {\n const objectStore = txn.objectStore(IndexedDBCryptoStore.STORE_ACCOUNT);\n objectStore.put(migrationState, ACCOUNT_OBJECT_KEY_MIGRATION_STATE);\n });\n }\n\n // Olm Account\n\n public getAccount(txn: IDBTransaction, func: (accountPickle: string | null) => void): void {\n const objectStore = txn.objectStore(\"account\");\n const getReq = objectStore.get(\"-\");\n getReq.onsuccess = function (): void {\n try {\n func(getReq.result || null);\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n }\n\n public storeAccount(txn: IDBTransaction, accountPickle: string): void {\n const objectStore = txn.objectStore(\"account\");\n objectStore.put(accountPickle, \"-\");\n }\n\n public getCrossSigningKeys(\n txn: IDBTransaction,\n func: (keys: Record<string, CrossSigningKeyInfo> | null) => void,\n ): void {\n const objectStore = txn.objectStore(\"account\");\n const getReq = objectStore.get(\"crossSigningKeys\");\n getReq.onsuccess = function (): void {\n try {\n func(getReq.result || null);\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n }\n\n public getSecretStorePrivateKey<K extends keyof SecretStorePrivateKeys>(\n txn: IDBTransaction,\n func: (key: SecretStorePrivateKeys[K] | null) => void,\n type: K,\n ): void {\n const objectStore = txn.objectStore(\"account\");\n const getReq = objectStore.get(`ssss_cache:${type}`);\n getReq.onsuccess = function (): void {\n try {\n func(getReq.result || null);\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n }\n\n public storeSecretStorePrivateKey<K extends keyof SecretStorePrivateKeys>(\n txn: IDBTransaction,\n type: K,\n key: SecretStorePrivateKeys[K],\n ): void {\n const objectStore = txn.objectStore(\"account\");\n objectStore.put(key, `ssss_cache:${type}`);\n }\n\n // Olm Sessions\n\n public countEndToEndSessions(txn: IDBTransaction, func: (count: number) => void): void {\n const objectStore = txn.objectStore(\"sessions\");\n const countReq = objectStore.count();\n countReq.onsuccess = function (): void {\n try {\n func(countReq.result);\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n }\n\n public getEndToEndSessions(\n deviceKey: string,\n txn: IDBTransaction,\n func: (sessions: { [sessionId: string]: ISessionInfo }) => void,\n ): void {\n const objectStore = txn.objectStore(\"sessions\");\n const idx = objectStore.index(\"deviceKey\");\n const getReq = idx.openCursor(deviceKey);\n const results: Parameters<Parameters<Backend[\"getEndToEndSessions\"]>[2]>[0] = {};\n getReq.onsuccess = function (): void {\n const cursor = getReq.result;\n if (cursor) {\n results[cursor.value.sessionId] = {\n session: cursor.value.session,\n lastReceivedMessageTs: cursor.value.lastReceivedMessageTs,\n };\n cursor.continue();\n } else {\n try {\n func(results);\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n }\n };\n }\n\n public getEndToEndSession(\n deviceKey: string,\n sessionId: string,\n txn: IDBTransaction,\n func: (session: ISessionInfo | null) => void,\n ): void {\n const objectStore = txn.objectStore(\"sessions\");\n const getReq = objectStore.get([deviceKey, sessionId]);\n getReq.onsuccess = function (): void {\n try {\n if (getReq.result) {\n func({\n session: getReq.result.session,\n lastReceivedMessageTs: getReq.result.lastReceivedMessageTs,\n });\n } else {\n func(null);\n }\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n }\n\n public storeEndToEndSession(\n deviceKey: string,\n sessionId: string,\n sessionInfo: ISessionInfo,\n txn: IDBTransaction,\n ): void {\n const objectStore = txn.objectStore(\"sessions\");\n objectStore.put({\n deviceKey,\n sessionId,\n session: sessionInfo.session,\n lastReceivedMessageTs: sessionInfo.lastReceivedMessageTs,\n });\n }\n\n /**\n * Fetch a batch of Olm sessions from the database.\n *\n * Implementation of {@link CryptoStore.getEndToEndSessionsBatch}.\n */\n public async getEndToEndSessionsBatch(): Promise<null | ISessionInfo[]> {\n const result: ISessionInfo[] = [];\n await this.doTxn(\"readonly\", [IndexedDBCryptoStore.STORE_SESSIONS], (txn) => {\n const objectStore = txn.objectStore(IndexedDBCryptoStore.STORE_SESSIONS);\n const getReq = objectStore.openCursor();\n getReq.onsuccess = function (): void {\n try {\n const cursor = getReq.result;\n if (cursor) {\n result.push(cursor.value);\n if (result.length < SESSION_BATCH_SIZE) {\n cursor.continue();\n }\n }\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n });\n\n if (result.length === 0) {\n // No sessions left.\n return null;\n }\n\n return result;\n }\n\n /**\n * Delete a batch of Olm sessions from the database.\n *\n * Implementation of {@link CryptoStore.deleteEndToEndSessionsBatch}.\n *\n * @internal\n */\n public async deleteEndToEndSessionsBatch(sessions: { deviceKey: string; sessionId: string }[]): Promise<void> {\n await this.doTxn(\"readwrite\", [IndexedDBCryptoStore.STORE_SESSIONS], async (txn) => {\n try {\n const objectStore = txn.objectStore(IndexedDBCryptoStore.STORE_SESSIONS);\n for (const { deviceKey, sessionId } of sessions) {\n const req = objectStore.delete([deviceKey, sessionId]);\n await new Promise((resolve) => {\n req.onsuccess = resolve;\n });\n }\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n });\n }\n\n // Inbound group sessions\n\n public getEndToEndInboundGroupSession(\n senderCurve25519Key: string,\n sessionId: string,\n txn: IDBTransaction,\n func: (groupSession: InboundGroupSessionData | null, groupSessionWithheld: IWithheld | null) => void,\n ): void {\n let session: InboundGroupSessionData | null | boolean = false;\n let withheld: IWithheld | null | boolean = false;\n const objectStore = txn.objectStore(\"inbound_group_sessions\");\n const getReq = objectStore.get([senderCurve25519Key, sessionId]);\n getReq.onsuccess = function (): void {\n try {\n if (getReq.result) {\n session = getReq.result.session;\n } else {\n session = null;\n }\n if (withheld !== false) {\n func(session as InboundGroupSessionData, withheld as IWithheld);\n }\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n\n const withheldObjectStore = txn.objectStore(\"inbound_group_sessions_withheld\");\n const withheldGetReq = withheldObjectStore.get([senderCurve25519Key, sessionId]);\n withheldGetReq.onsuccess = function (): void {\n try {\n if (withheldGetReq.result) {\n withheld = withheldGetReq.result.session;\n } else {\n withheld = null;\n }\n if (session !== false) {\n func(session as InboundGroupSessionData, withheld as IWithheld);\n }\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n }\n\n public storeEndToEndInboundGroupSession(\n senderCurve25519Key: string,\n sessionId: string,\n sessionData: InboundGroupSessionData,\n txn: IDBTransaction,\n ): void {\n const objectStore = txn.objectStore(\"inbound_group_sessions\");\n objectStore.put({\n senderCurve25519Key,\n sessionId,\n session: sessionData,\n });\n }\n\n /**\n * Count the number of Megolm sessions in the database.\n *\n * Implementation of {@link CryptoStore.countEndToEndInboundGroupSessions}.\n *\n * @internal\n */\n public async countEndToEndInboundGroupSessions(): Promise<number> {\n let result = 0;\n await this.doTxn(\"readonly\", [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], (txn) => {\n const sessionStore = txn.objectStore(IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS);\n const countReq = sessionStore.count();\n countReq.onsuccess = (): void => {\n result = countReq.result;\n };\n });\n return result;\n }\n\n /**\n * Fetch a batch of Megolm sessions from the database.\n *\n * Implementation of {@link CryptoStore.getEndToEndInboundGroupSessionsBatch}.\n */\n public async getEndToEndInboundGroupSessionsBatch(): Promise<null | SessionExtended[]> {\n const result: SessionExtended[] = [];\n await this.doTxn(\n \"readonly\",\n [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS, IndexedDBCryptoStore.STORE_BACKUP],\n (txn) => {\n const sessionStore = txn.objectStore(IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS);\n const backupStore = txn.objectStore(IndexedDBCryptoStore.STORE_BACKUP);\n\n const getReq = sessionStore.openCursor();\n getReq.onsuccess = function (): void {\n try {\n const cursor = getReq.result;\n if (cursor) {\n const backupGetReq = backupStore.get(cursor.key);\n backupGetReq.onsuccess = (): void => {\n result.push({\n senderKey: cursor.value.senderCurve25519Key,\n sessionId: cursor.value.sessionId,\n sessionData: cursor.value.session,\n needsBackup: backupGetReq.result !== undefined,\n });\n if (result.length < SESSION_BATCH_SIZE) {\n cursor.continue();\n }\n };\n }\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n },\n );\n\n if (result.length === 0) {\n // No sessions left.\n return null;\n }\n\n return result;\n }\n\n /**\n * Delete a batch of Megolm sessions from the database.\n *\n * Implementation of {@link CryptoStore.deleteEndToEndInboundGroupSessionsBatch}.\n *\n * @internal\n */\n public async deleteEndToEndInboundGroupSessionsBatch(\n sessions: { senderKey: string; sessionId: string }[],\n ): Promise<void> {\n await this.doTxn(\"readwrite\", [IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS], async (txn) => {\n try {\n const objectStore = txn.objectStore(IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS);\n for (const { senderKey, sessionId } of sessions) {\n const req = objectStore.delete([senderKey, sessionId]);\n await new Promise((resolve) => {\n req.onsuccess = resolve;\n });\n }\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n });\n }\n\n public getEndToEndDeviceData(txn: IDBTransaction, func: (deviceData: IDeviceData | null) => void): void {\n const objectStore = txn.objectStore(\"device_data\");\n const getReq = objectStore.get(\"-\");\n getReq.onsuccess = function (): void {\n try {\n func(getReq.result || null);\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n };\n }\n\n public getEndToEndRooms(txn: IDBTransaction, func: (rooms: Record<string, IRoomEncryption>) => void): void {\n const rooms: Parameters<Parameters<Backend[\"getEndToEndRooms\"]>[1]>[0] = {};\n const objectStore = txn.objectStore(\"rooms\");\n const getReq = objectStore.openCursor();\n getReq.onsuccess = function (): void {\n const cursor = getReq.result;\n if (cursor) {\n rooms[cursor.key as string] = cursor.value;\n cursor.continue();\n } else {\n try {\n func(rooms);\n } catch (e) {\n abortWithException(txn, <Error>e);\n }\n }\n };\n }\n\n public async markSessionsNeedingBackup(sessions: ISession[], txn?: IDBTransaction): Promise<void> {\n if (!txn) {\n txn = this.db.transaction(\"sessions_needing_backup\", \"readwrite\");\n }\n const objectStore = txn.objectStore(\"sessions_needing_backup\");\n await Promise.all(\n sessions.map((session) => {\n return new Promise((resolve, reject) => {\n const req = objectStore.put({\n senderCurve25519Key: session.senderKey,\n sessionId: session.sessionId,\n });\n req.onsuccess = resolve;\n req.onerror = reject;\n });\n }),\n );\n }\n\n public doTxn<T>(\n mode: Mode,\n stores: string | string[],\n func: (txn: IDBTransaction) => T,\n log: Logger = logger,\n ): Promise<T> {\n let startTime: number;\n let description: string;\n if (PROFILE_TRANSACTIONS) {\n const txnId = this.nextTxnId++;\n startTime = Date.now();\n description = `${mode} crypto store transaction ${txnId} in ${stores}`;\n log.debug(`Starting ${description}`);\n }\n const txn = this.db.transaction(stores, mode);\n const promise = promiseifyTxn(txn);\n const result = func(txn);\n if (PROFILE_TRANSACTIONS) {\n promise.then(\n () => {\n const elapsedTime = Date.now() - startTime;\n log.debug(`Finished ${description}, took ${elapsedTime} ms`);\n },\n () => {\n const elapsedTime = Date.now() - startTime;\n log.error(`Failed ${description}, took ${elapsedTime} ms`);\n },\n );\n }\n return promise.then(() => {\n return result;\n });\n }\n}\n\ntype DbMigration = (db: IDBDatabase) => void;\nconst DB_MIGRATIONS: DbMigration[] = [\n (db): void => {\n createDatabase(db);\n },\n (db): void => {\n db.createObjectStore(\"account\");\n },\n (db): void => {\n const sessionsStore = db.createObjectStore(\"sessions\", {\n keyPath: [\"deviceKey\", \"sessionId\"],\n });\n sessionsStore.createIndex(\"deviceKey\", \"deviceKey\");\n },\n (db): void => {\n db.createObjectStore(\"inbound_group_sessions\", {\n keyPath: [\"senderCurve25519Key\", \"sessionId\"],\n });\n },\n (db): void => {\n db.createObjectStore(\"device_data\");\n },\n (db): void => {\n db.createObjectStore(\"rooms\");\n },\n (db): void => {\n db.createObjectStore(\"sessions_needing_backup\", {\n keyPath: [\"senderCurve25519Key\", \"sessionId\"],\n });\n },\n (db): void => {\n db.createObjectStore(\"inbound_group_sessions_withheld\", {\n keyPath: [\"senderCurve25519Key\", \"sessionId\"],\n });\n },\n (db): void => {\n const problemsStore = db.createObjectStore(\"session_problems\", {\n keyPath: [\"deviceKey\", \"time\"],\n });\n problemsStore.createIndex(\"deviceKey\", \"deviceKey\");\n\n db.createObjectStore(\"notified_error_devices\", {\n keyPath: [\"userId\", \"deviceId\"],\n });\n },\n (db): void => {\n db.createObjectStore(\"shared_history_inbound_group_sessions\", {\n keyPath: [\"roomId\"],\n });\n },\n (db): void => {\n db.createObjectStore(\"parked_shared_history\", {\n keyPath: [\"roomId\"],\n });\n },\n // Expand as needed.\n];\nexport const VERSION = DB_MIGRATIONS.length;\n\nexport function upgradeDatabase(db: IDBDatabase, oldVersion: number): void {\n logger.log(`Upgrading IndexedDBCryptoStore from version ${oldVersion} to ${VERSION}`);\n DB_MIGRATIONS.forEach((migration, index) => {\n if (oldVersion <= index) migration(db);\n });\n}\n\nfunction createDatabase(db: IDBDatabase): void {\n const outgoingRoomKeyRequestsStore = db.createObjectStore(\"outgoingRoomKeyRequests\", { keyPath: \"requestId\" });\n\n // we assume that the RoomKeyRequestBody will have room_id and session_id\n // properties, to make the index efficient.\n outgoingRoomKeyRequestsStore.createIndex(\"session\", [\"requestBody.room_id\", \"requestBody.session_id\"]);\n\n outgoingRoomKeyRequestsStore.createIndex(\"state\", \"state\");\n}\n\ninterface IWrappedIDBTransaction extends IDBTransaction {\n _mx_abortexception: Error;\n}\n\n/*\n * Aborts a transaction with a given exception\n * The transaction promise will be rejected with this exception.\n */\nfunction abortWithException(txn: IDBTransaction, e: Error): void {\n // We cheekily stick our exception onto the transaction object here\n // We could alternatively make the thing we pass back to the app\n // an object containing the transaction and exception.\n (txn as IWrappedIDBTransaction)._mx_abortexception = e;\n try {\n txn.abort();\n } catch {\n // sometimes we won't be able to abort the transaction\n // (ie. if it's aborted or completed)\n }\n}\n\nfunction promiseifyTxn<T>(txn: IDBTransaction): Promise<T | null> {\n return new Promise((resolve, reject) => {\n txn.oncomplete = (): void => {\n if ((txn as IWrappedIDBTransaction)._mx_abortexception !== undefined) {\n reject((txn as IWrappedIDBTransaction)._mx_abortexception);\n return;\n }\n resolve(null);\n };\n txn.onerror = (event): void => {\n if ((txn as IWrappedIDBTransaction)._mx_abortexception !== undefined) {\n reject((txn as IWrappedIDBTransaction)._mx_abortexception);\n } else {\n logger.log(\"Error performing indexeddb txn\", event);\n reject(txn.error);\n }\n };\n txn.onabort = (event): void => {\n if ((txn as IWrappedIDBTransaction)._mx_abortexception !== undefined) {\n reject((txn as IWrappedIDBTransaction)._mx_abortexception);\n } else {\n logger.log(\"Error performing indexeddb txn\", event);\n reject(txn.error);\n }\n };\n });\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAsB,MAAM,QAAQ,iBAAiB;AACrD,SAOI,cAAc,EAGd,kBAAkB,EAClB,kCAAkC,QAG/B,WAAW;AAClB,SAAS,oBAAoB,QAAQ,6BAA6B;AAGlE,MAAM,oBAAoB,GAAG,KAAK;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAM,OAAO,CAAwB;EAGxC;AACJ;EACW,WAAW,CAAS,EAAe,EAAE;IAAA,mCAJxB,CAAC;IAAA,KAIM,EAAe,GAAf,EAAe;IACtC;IACA;IACA;IACA,EAAE,CAAC,eAAe,GAAG,MAAY;MAC7B,MAAM,CAAC,GAAG,CAAC,+BAA+B,IAAI,CAAC,EAAE,CAAC,IAAI,WAAW,CAAC;MAClE,EAAE,CAAC,KAAK,CAAC,CAAC;IACd,CAAC;EACL;EAEA,MAAa,YAAY,GAAqB;IAC1C,MAAM,KAAK,CAAC,6BAA6B,CAAC;EAC9C;EAEA,MAAa,OAAO,GAAyB;IACzC;IACA;IACA,OAAO,IAAI;EACf;EAEA,MAAa,aAAa,GAAkB;IACxC,MAAM,KAAK,CAAC,2E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AkB,CAAC;MAC9D,CAAC,MAAM;QACH,MAAM,CAAC,GAAG,CAAC,gCAAgC,EAAE,KAAK,CAAC;QACnD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;MACrB;IACJ,CAAC;IACD,GAAG,CAAC,OAAO,GAAI,KAAK,IAAW;MAC3B,IAAK,GAAG,CAA4B,kBAAkB,KAAK,SAAS,EAAE;QAClE,MAAM,CAAE,GAAG,CAA4B,kBAAkB,CAAC;MAC9D,CAAC,MAAM;QACH,MAAM,CAAC,GAAG,CAAC,gCAAgC,EAAE,KAAK,CAAC;QACnD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;MACrB;IACJ,CAAC;EACL,CAAC,CAAC;AACN","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"indexeddb-crypto-store.d.ts","sourceRoot":"","sources":["../../../src/crypto/store/indexeddb-crypto-store.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAMtD,OAAO,EACH,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,cAAc,EACd,KAAK,IAAI,EACT,KAAK,sBAAsB,EAE3B,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAMrE;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,WAAW;IAuEhD,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAvE3B,OAAc,aAAa,SAAa;IACxC,OAAc,cAAc,SAAc;IAC1C,OAAc,4BAA4B,SAA4B;IACtE,OAAc,qCAAqC,SAAqC;IACxF,OAAc,2CAA2C,SAA2C;IACpG,OAAc,2BAA2B,SAA2B;IACpE,OAAc,iBAAiB,SAAiB;IAChD,OAAc,WAAW,S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,CAAC,eAAe,EAAE,GAAG,IAAI,CAAC,CAE/E;IAED;;;;;;OAMG;IACI,uCAAuC,CAC1C,QAAQ,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,GACrD,OAAO,CAAC,IAAI,CAAC,CAEf;IAED;;;;OAIG;IACI,gBAAgB,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,KAAK,IAAI,GAAG,IAAI,CAEzG;IAED;;;;;OAKG;IACI,yBAAyB,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,GAAG,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1F;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACI,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAEhH;CACJ"}
@@ -152,7 +152,7 @@ export class IndexedDBCryptoStore {
152
152
  // in this db so we should use it or nothing at all.
153
153
  throw new InvalidCryptoStoreError(InvalidCryptoStoreState.TooNew);
154
154
  }
155
- logger.warn(`unable to connect to indexeddb ${this.dbName}` + `: falling back to localStorage store: ${e}`);
155
+ logger.warn(`unable to connect to indexeddb ${this.dbName}: falling back to localStorage store: ${e}`);
156
156
  try {
157
157
  if (!(globalThis.localStorage instanceof Storage)) {
158
158
  throw new Error("localStorage is not available");
@@ -1 +1 @@
1
- {"version":3,"file":"indexeddb-crypto-store.js","names":[],"sources":["../../../src/crypto/store/indexeddb-crypto-store.ts"],"sourcesContent":["/*\nCopyright 2017 - 2021 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { logger, type Logger } from \"../../logger.ts\";\nimport { LocalStorageCryptoStore } from \"./localStorage-crypto-store.ts\";\nimport { MemoryCryptoStore } from \"./memory-crypto-store.ts\";\nimport * as IndexedDBCryptoStoreBackend from \"./indexeddb-crypto-store-backend.ts\";\nimport { InvalidCryptoStoreError, InvalidCryptoStoreState } from \"../../errors.ts\";\nimport * as IndexedDBHelpers from \"../../indexeddb-helpers.ts\";\nimport {\n type CryptoStore,\n type ISession,\n type SessionExtended,\n type ISessionInfo,\n type IWithheld,\n MigrationState,\n type Mode,\n type SecretStorePrivateKeys,\n ACCOUNT_OBJECT_KEY_MIGRATION_STATE,\n type InboundGroupSessionData,\n type IRoomEncryption,\n} from \"./base.ts\";\nimport { type CrossSigningKeyInfo } from \"../../crypto-api/index.ts\";\n\n/*\n * Internal module. indexeddb storage for e2e.\n */\n\n/**\n * An implementation of CryptoStore, which is normally backed by an indexeddb,\n * but with fallback to MemoryCryptoStore.\n */\nexport class IndexedDBCryptoStore implements CryptoStore {\n public static STORE_ACCOUNT = \"account\";\n public static STORE_SESSIONS = \"sessions\";\n public static STORE_INBOUND_GROUP_SESSIONS = \"inbound_group_sessions\";\n public static STORE_INBOUND_GROUP_SESSIONS_WITHHELD = \"inbound_group_sessions_withheld\";\n public static STORE_SHARED_HISTORY_INBOUND_GROUP_SESSIONS = \"shared_history_inbound_group_sessions\";\n public static STORE_PARKED_SHARED_HISTORY = \"parked_shared_history\";\n public static STORE_DEVICE_DATA = \"device_data\";\n public static STORE_ROOMS = \"rooms\";\n public static STORE_BACKUP = \"sessions_needing_backup\";\n\n public static exists(indexedDB: IDBFactory, dbName: string): Promise<boolean> {\n return IndexedDBHelpers.exists(indexedDB, dbName);\n }\n\n /**\n * Utility to check if a legacy crypto store exists and has not been migrated.\n * Returns true if the store exists and has not been migrated, false otherwise.\n */\n public static existsAndIsNotMigrated(indexedDb: IDBFactory, dbName: string): Promise<boolean> {\n return new Promise<boolean>((resolve, reject) => {\n let exists = true;\n const openDBRequest = indexedDb.open(dbName);\n openDBRequest.onupgradeneeded = (): void => {\n // Since we did not provide an explicit version when opening, this event\n // should only fire if the DB did not exist before at any version.\n exists = false;\n };\n openDBRequest.onblocked = (): void => reject(openDBRequest.error);\n openDBRequest.onsuccess = (): void => {\n const db = openDBRequest.result;\n if (!exists) {\n db.close();\n // The DB did not exist before, but has been created as part of this\n // existence check. Delete it now to restore previous state. Delete can\n // actually take a while to complete in some browsers, so don't wait for\n // it. This won't block future open calls that a store might issue next to\n // properly set up the DB.\n indexedDb.deleteDatabase(dbName);\n resolve(false);\n } else {\n const tx = db.transaction([IndexedDBCryptoStore.STORE_ACCOUNT], \"readonly\");\n const objectStore = tx.objectStore(IndexedDBCryptoStore.STORE_ACCOUNT);\n const getReq = objectStore.get(ACCOUNT_OBJECT_KEY_MIGRATION_STATE);\n\n getReq.onsuccess = (): void => {\n const migrationState = getReq.result ?? MigrationState.NOT_STARTED;\n resolve(migrationState === MigrationState.NOT_STARTED);\n };\n\n getReq.onerror = (): void => {\n reject(getReq.error);\n };\n\n db.close();\n }\n };\n openDBRequest.onerror = (): void => reject(openDBRequest.error);\n });\n }\n\n private backendPromise?: Promise<CryptoStore>;\n private backend?: CryptoStore;\n\n /**\n * Create a new IndexedDBCryptoStore\n *\n * @param indexedDB - global indexedDB instance\n * @param dbName - name of db to connect to\n */\n public constructor(\n private readonly indexedDB: IDBFactory,\n private readonly dbName: string,\n ) {}\n\n /**\n * Returns true if this CryptoStore has ever been initialised (ie, it might contain data).\n *\n * Implementation of {@link CryptoStore.containsData}.\n *\n * @internal\n */\n public async containsData(): Promise<boolean> {\n return IndexedDBCryptoStore.exists(this.indexedDB, this.dbName);\n }\n\n /**\n * Ensure the database exists and is up-to-date, or fall back to\n * a local storage or in-memory store.\n *\n * This must be called before the store can be used.\n *\n * @returns resolves to either an IndexedDBCryptoStoreBackend.Backend,\n * or a MemoryCryptoStore\n */\n public startup(): Promise<CryptoStore> {\n if (this.backendPromise) {\n return this.backendPromise;\n }\n\n this.backendPromise = new Promise<CryptoStore>((resolve, reject) => {\n if (!this.indexedDB) {\n reject(new Error(\"no indexeddb support available\"));\n return;\n }\n\n logger.log(`connecting to indexeddb ${this.dbName}`);\n\n const req = this.indexedDB.open(this.dbName, IndexedDBCryptoStoreBackend.VERSION);\n\n req.onupgradeneeded = (ev): void => {\n const db = req.result;\n const oldVersion = ev.oldVersion;\n IndexedDBCryptoStoreBackend.upgradeDatabase(db, oldVersion);\n };\n\n req.onblocked = (): void => {\n logger.log(`can't yet open IndexedDBCryptoStore because it is open elsewhere`);\n };\n\n req.onerror = (ev): void => {\n logger.log(\"Error connecting to indexeddb\", ev);\n reject(req.error);\n };\n\n req.onsuccess = (): void => {\n const db = req.result;\n\n logger.log(`connected to indexeddb ${this.dbName}`);\n resolve(new IndexedDBCryptoStoreBackend.Backend(db));\n };\n })\n .then((backend) => {\n // Edge has IndexedDB but doesn't support compund keys which we use fairly extensively.\n // Try a dummy query which will fail if the browser doesn't support compund keys, so\n // we can fall back to a different backend.\n return backend\n .doTxn(\n \"readonly\",\n [\n IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS,\n IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS_WITHHELD,\n ],\n (txn) => {\n backend.getEndToEndInboundGroupSession(\"\", \"\", txn, () => {});\n },\n )\n .then(() => backend);\n })\n .catch((e) => {\n if (e.name === \"VersionError\") {\n logger.warn(\"Crypto DB is too new for us to use!\", e);\n // don't fall back to a different store: the user has crypto data\n // in this db so we should use it or nothing at all.\n throw new InvalidCryptoStoreError(InvalidCryptoStoreState.TooNew);\n }\n logger.warn(\n `unable to connect to indexeddb ${this.dbName}` + `: falling back to localStorage store: ${e}`,\n );\n\n try {\n if (!(globalThis.localStorage instanceof Storage)) {\n throw new Error(\"localStorage is not available\");\n }\n return new LocalStorageCryptoStore(globalThis.localStorage);\n } catch (e) {\n logger.warn(`Unable to open localStorage: falling back to in-memory store: ${e}`);\n return new MemoryCryptoStore();\n }\n })\n .then((backend) => {\n this.backend = backend;\n return backend;\n });\n\n return this.backendPromise;\n }\n\n /**\n * Delete all data from this store.\n *\n * @returns resolves when the store has been cleared.\n */\n public deleteAllData(): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (!this.indexedDB) {\n reject(new Error(\"no indexeddb support available\"));\n return;\n }\n\n logger.log(`Removing indexeddb instance: ${this.dbName}`);\n const req = this.indexedDB.deleteDatabase(this.dbName);\n\n req.onblocked = (): void => {\n logger.log(`can't yet delete IndexedDBCryptoStore because it is open elsewhere`);\n };\n\n req.onerror = (ev): void => {\n logger.log(\"Error deleting data from indexeddb\", ev);\n reject(req.error);\n };\n\n req.onsuccess = (): void => {\n logger.log(`Removed indexeddb instance: ${this.dbName}`);\n resolve();\n };\n }).catch((e) => {\n // in firefox, with indexedDB disabled, this fails with a\n // DOMError. We treat this as non-fatal, so that people can\n // still use the app.\n logger.warn(`unable to delete IndexedDBCryptoStore: ${e}`);\n });\n }\n\n /**\n * Get data on how much of the libolm to Rust Crypto migration has been done.\n *\n * Implementation of {@link CryptoStore.getMigrationState}.\n *\n * @internal\n */\n public getMigrationState(): Promise<MigrationState> {\n return this.backend!.getMigrationState();\n }\n\n /**\n * Set data on how much of the libolm to Rust Crypto migration has been done.\n *\n * Implementation of {@link CryptoStore.setMigrationState}.\n *\n * @internal\n */\n public setMigrationState(migrationState: MigrationState): Promise<void> {\n return this.backend!.setMigrationState(migrationState);\n }\n\n // Olm Account\n\n /*\n * Get the account pickle from the store.\n * This requires an active transaction. See doTxn().\n *\n * @param txn - An active transaction. See doTxn().\n * @param func - Called with the account pickle\n */\n public getAccount(txn: IDBTransaction, func: (accountPickle: string | null) => void): void {\n this.backend!.getAccount(txn, func);\n }\n\n /**\n * Write the account pickle to the store.\n * This requires an active transaction. See doTxn().\n *\n * @param txn - An active transaction. See doTxn().\n * @param accountPickle - The new account pickle to store.\n */\n public storeAccount(txn: IDBTransaction, accountPickle: string): void {\n this.backend!.storeAccount(txn, accountPickle);\n }\n\n /**\n * Get the public part of the cross-signing keys (eg. self-signing key,\n * user signing key).\n *\n * @param txn - An active transaction. See doTxn().\n * @param func - Called with the account keys object:\n * `{ key_type: base64 encoded seed }` where key type = user_signing_key_seed or self_signing_key_seed\n */\n public getCrossSigningKeys(\n txn: IDBTransaction,\n func: (keys: Record<string, CrossSigningKeyInfo> | null) => void,\n ): void {\n this.backend!.getCrossSigningKeys(txn, func);\n }\n\n /**\n * @param txn - An active transaction. See doTxn().\n * @param func - Called with the private key\n * @param type - A key type\n */\n public getSecretStorePrivateKey<K extends keyof SecretStorePrivateKeys>(\n txn: IDBTransaction,\n func: (key: SecretStorePrivateKeys[K] | null) => void,\n type: K,\n ): void {\n this.backend!.getSecretStorePrivateKey(txn, func, type);\n }\n\n /**\n * Write the cross-signing private keys back to the store\n *\n * @param txn - An active transaction. See doTxn().\n * @param type - The type of cross-signing private key to store\n * @param key - keys object as getCrossSigningKeys()\n */\n public storeSecretStorePrivateKey<K extends keyof SecretStorePrivateKeys>(\n txn: IDBTransaction,\n type: K,\n key: SecretStorePrivateKeys[K],\n ): void {\n this.backend!.storeSecretStorePrivateKey(txn, type, key);\n }\n\n // Olm sessions\n\n /**\n * Returns the number of end-to-end sessions in the store\n * @param txn - An active transaction. See doTxn().\n * @param func - Called with the count of sessions\n */\n public countEndToEndSessions(txn: IDBTransaction, func: (count: number) => void): void {\n this.backend!.countEndToEndSessions(txn, func);\n }\n\n /**\n * Retrieve a specific end-to-end session between the logged-in user\n * and another device.\n * @param deviceKey - The public key of the other device.\n * @param sessionId - The ID of the session to retrieve\n * @param txn - An active transaction. See doTxn().\n * @param func - Called with A map from sessionId\n * to session information object with 'session' key being the\n * Base64 end-to-end session and lastReceivedMessageTs being the\n * timestamp in milliseconds at which the session last received\n * a message.\n */\n public getEndToEndSession(\n deviceKey: string,\n sessionId: string,\n txn: IDBTransaction,\n func: (session: ISessionInfo | null) => void,\n ): void {\n this.backend!.getEndToEndSession(deviceKey, sessionId, txn, func);\n }\n\n /**\n * Retrieve the end-to-end sessions between the logged-in user and another\n * device.\n * @param deviceKey - The public key of the other device.\n * @param txn - An active transaction. See doTxn().\n * @param func - Called with A map from sessionId\n * to session information object with 'session' key being the\n * Base64 end-to-end session and lastReceivedMessageTs being the\n * timestamp in milliseconds at which the session last received\n * a message.\n */\n public getEndToEndSessions(\n deviceKey: string,\n txn: IDBTransaction,\n func: (sessions: { [sessionId: string]: ISessionInfo }) => void,\n ): void {\n this.backend!.getEndToEndSessions(deviceKey, txn, func);\n }\n\n /**\n * Store a session between the logged-in user and another device\n * @param deviceKey - The public key of the other device.\n * @param sessionId - The ID for this end-to-end session.\n * @param sessionInfo - Session information object\n * @param txn - An active transaction. See doTxn().\n */\n public storeEndToEndSession(\n deviceKey: string,\n sessionId: string,\n sessionInfo: ISessionInfo,\n txn: IDBTransaction,\n ): void {\n this.backend!.storeEndToEndSession(deviceKey, sessionId, sessionInfo, txn);\n }\n\n /**\n * Count the number of Megolm sessions in the database.\n *\n * Implementation of {@link CryptoStore.countEndToEndInboundGroupSessions}.\n *\n * @internal\n */\n public countEndToEndInboundGroupSessions(): Promise<number> {\n return this.backend!.countEndToEndInboundGroupSessions();\n }\n\n /**\n * Fetch a batch of Olm sessions from the database.\n *\n * Implementation of {@link CryptoStore.getEndToEndSessionsBatch}.\n *\n * @internal\n */\n public getEndToEndSessionsBatch(): Promise<null | ISessionInfo[]> {\n return this.backend!.getEndToEndSessionsBatch();\n }\n\n /**\n * Delete a batch of Olm sessions from the database.\n *\n * Implementation of {@link CryptoStore.deleteEndToEndSessionsBatch}.\n *\n * @internal\n */\n public deleteEndToEndSessionsBatch(sessions: { deviceKey: string; sessionId: string }[]): Promise<void> {\n return this.backend!.deleteEndToEndSessionsBatch(sessions);\n }\n\n // Inbound group sessions\n\n /**\n * Retrieve the end-to-end inbound group session for a given\n * server key and session ID\n * @param senderCurve25519Key - The sender's curve 25519 key\n * @param sessionId - The ID of the session\n * @param txn - An active transaction. See doTxn().\n * @param func - Called with A map from sessionId\n * to Base64 end-to-end session.\n */\n public getEndToEndInboundGroupSession(\n senderCurve25519Key: string,\n sessionId: string,\n txn: IDBTransaction,\n func: (groupSession: InboundGroupSessionData | null, groupSessionWithheld: IWithheld | null) => void,\n ): void {\n this.backend!.getEndToEndInboundGroupSession(senderCurve25519Key, sessionId, txn, func);\n }\n\n /**\n * Writes an end-to-end inbound group session to the store.\n * If there already exists an inbound group session with the same\n * senderCurve25519Key and sessionID, it will be overwritten.\n * @param senderCurve25519Key - The sender's curve 25519 key\n * @param sessionId - The ID of the session\n * @param sessionData - The session data structure\n * @param txn - An active transaction. See doTxn().\n */\n public storeEndToEndInboundGroupSession(\n senderCurve25519Key: string,\n sessionId: string,\n sessionData: InboundGroupSessionData,\n txn: IDBTransaction,\n ): void {\n this.backend!.storeEndToEndInboundGroupSession(senderCurve25519Key, sessionId, sessionData, txn);\n }\n\n /**\n * Fetch a batch of Megolm sessions from the database.\n *\n * Implementation of {@link CryptoStore.getEndToEndInboundGroupSessionsBatch}.\n *\n * @internal\n */\n public getEndToEndInboundGroupSessionsBatch(): Promise<SessionExtended[] | null> {\n return this.backend!.getEndToEndInboundGroupSessionsBatch();\n }\n\n /**\n * Delete a batch of Megolm sessions from the database.\n *\n * Implementation of {@link CryptoStore.deleteEndToEndInboundGroupSessionsBatch}.\n *\n * @internal\n */\n public deleteEndToEndInboundGroupSessionsBatch(\n sessions: { senderKey: string; sessionId: string }[],\n ): Promise<void> {\n return this.backend!.deleteEndToEndInboundGroupSessionsBatch(sessions);\n }\n\n /**\n * Get an object of `roomId->roomInfo` for all e2e rooms in the store\n * @param txn - An active transaction. See doTxn().\n * @param func - Function called with the end-to-end encrypted rooms\n */\n public getEndToEndRooms(txn: IDBTransaction, func: (rooms: Record<string, IRoomEncryption>) => void): void {\n this.backend!.getEndToEndRooms(txn, func);\n }\n\n /**\n * Mark sessions as needing to be backed up.\n * @param sessions - The sessions that need to be backed up.\n * @param txn - An active transaction. See doTxn(). (optional)\n * @returns resolves when the sessions are marked\n */\n public markSessionsNeedingBackup(sessions: ISession[], txn?: IDBTransaction): Promise<void> {\n return this.backend!.markSessionsNeedingBackup(sessions, txn);\n }\n\n /**\n * Perform a transaction on the crypto store. Any store methods\n * that require a transaction (txn) object to be passed in may\n * only be called within a callback of either this function or\n * one of the store functions operating on the same transaction.\n *\n * @param mode - 'readwrite' if you need to call setter\n * functions with this transaction. Otherwise, 'readonly'.\n * @param stores - List IndexedDBCryptoStore.STORE_*\n * options representing all types of object that will be\n * accessed or written to with this transaction.\n * @param func - Function called with the\n * transaction object: an opaque object that should be passed\n * to store functions.\n * @param log - A possibly customised log\n * @returns Promise that resolves with the result of the `func`\n * when the transaction is complete. If the backend is\n * async (ie. the indexeddb backend) any of the callback\n * functions throwing an exception will cause this promise to\n * reject with that exception. On synchronous backends, the\n * exception will propagate to the caller of the getFoo method.\n */\n public doTxn<T>(mode: Mode, stores: Iterable<string>, func: (txn: IDBTransaction) => T, log?: Logger): Promise<T> {\n return this.backend!.doTxn<T>(mode, stores, func as (txn: unknown) => T, log);\n }\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAS,MAAM,QAAqB,iBAAiB;AACrD,SAAS,uBAAuB,QAAQ,gCAAgC;AACxE,SAAS,iBAAiB,QAAQ,0BAA0B;AAC5D,OAAO,KAAK,2BAA2B,MAAM,qCAAqC;AAClF,SAAS,uBAAuB,EAAE,uBAAuB,QAAQ,iBAAiB;AAClF,OAAO,KAAK,gBAAgB,MAAM,4BAA4B;AAC9D,SAMI,cAAc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BACC,SAAS;AAAA,gBAD9B,oBAAoB,oBAEE,UAAU;AAAA,gBAFhC,oBAAoB,kCAGgB,wBAAwB;AAAA,gBAH5D,oBAAoB,2CAIyB,iCAAiC;AAAA,gBAJ9E,oBAAoB,iDAK+B,uCAAuC;AAAA,gBAL1F,oBAAoB,iCAMe,uBAAuB;AAAA,gBAN1D,oBAAoB,uBAOK,aAAa;AAAA,gBAPtC,oBAAoB,iBAQD,OAAO;AAAA,gBAR1B,oBAAoB,kBASA,yBAAyB","ignoreList":[]}
1
+ {"version":3,"file":"indexeddb-crypto-store.js","names":[],"sources":["../../../src/crypto/store/indexeddb-crypto-store.ts"],"sourcesContent":["/*\nCopyright 2017 - 2021 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { logger, type Logger } from \"../../logger.ts\";\nimport { LocalStorageCryptoStore } from \"./localStorage-crypto-store.ts\";\nimport { MemoryCryptoStore } from \"./memory-crypto-store.ts\";\nimport * as IndexedDBCryptoStoreBackend from \"./indexeddb-crypto-store-backend.ts\";\nimport { InvalidCryptoStoreError, InvalidCryptoStoreState } from \"../../errors.ts\";\nimport * as IndexedDBHelpers from \"../../indexeddb-helpers.ts\";\nimport {\n type CryptoStore,\n type ISession,\n type SessionExtended,\n type ISessionInfo,\n type IWithheld,\n MigrationState,\n type Mode,\n type SecretStorePrivateKeys,\n ACCOUNT_OBJECT_KEY_MIGRATION_STATE,\n type InboundGroupSessionData,\n type IRoomEncryption,\n} from \"./base.ts\";\nimport { type CrossSigningKeyInfo } from \"../../crypto-api/index.ts\";\n\n/*\n * Internal module. indexeddb storage for e2e.\n */\n\n/**\n * An implementation of CryptoStore, which is normally backed by an indexeddb,\n * but with fallback to MemoryCryptoStore.\n */\nexport class IndexedDBCryptoStore implements CryptoStore {\n public static STORE_ACCOUNT = \"account\";\n public static STORE_SESSIONS = \"sessions\";\n public static STORE_INBOUND_GROUP_SESSIONS = \"inbound_group_sessions\";\n public static STORE_INBOUND_GROUP_SESSIONS_WITHHELD = \"inbound_group_sessions_withheld\";\n public static STORE_SHARED_HISTORY_INBOUND_GROUP_SESSIONS = \"shared_history_inbound_group_sessions\";\n public static STORE_PARKED_SHARED_HISTORY = \"parked_shared_history\";\n public static STORE_DEVICE_DATA = \"device_data\";\n public static STORE_ROOMS = \"rooms\";\n public static STORE_BACKUP = \"sessions_needing_backup\";\n\n public static exists(indexedDB: IDBFactory, dbName: string): Promise<boolean> {\n return IndexedDBHelpers.exists(indexedDB, dbName);\n }\n\n /**\n * Utility to check if a legacy crypto store exists and has not been migrated.\n * Returns true if the store exists and has not been migrated, false otherwise.\n */\n public static existsAndIsNotMigrated(indexedDb: IDBFactory, dbName: string): Promise<boolean> {\n return new Promise<boolean>((resolve, reject) => {\n let exists = true;\n const openDBRequest = indexedDb.open(dbName);\n openDBRequest.onupgradeneeded = (): void => {\n // Since we did not provide an explicit version when opening, this event\n // should only fire if the DB did not exist before at any version.\n exists = false;\n };\n openDBRequest.onblocked = (): void => reject(openDBRequest.error);\n openDBRequest.onsuccess = (): void => {\n const db = openDBRequest.result;\n if (!exists) {\n db.close();\n // The DB did not exist before, but has been created as part of this\n // existence check. Delete it now to restore previous state. Delete can\n // actually take a while to complete in some browsers, so don't wait for\n // it. This won't block future open calls that a store might issue next to\n // properly set up the DB.\n indexedDb.deleteDatabase(dbName);\n resolve(false);\n } else {\n const tx = db.transaction([IndexedDBCryptoStore.STORE_ACCOUNT], \"readonly\");\n const objectStore = tx.objectStore(IndexedDBCryptoStore.STORE_ACCOUNT);\n const getReq = objectStore.get(ACCOUNT_OBJECT_KEY_MIGRATION_STATE);\n\n getReq.onsuccess = (): void => {\n const migrationState = getReq.result ?? MigrationState.NOT_STARTED;\n resolve(migrationState === MigrationState.NOT_STARTED);\n };\n\n getReq.onerror = (): void => {\n reject(getReq.error);\n };\n\n db.close();\n }\n };\n openDBRequest.onerror = (): void => reject(openDBRequest.error);\n });\n }\n\n private backendPromise?: Promise<CryptoStore>;\n private backend?: CryptoStore;\n\n /**\n * Create a new IndexedDBCryptoStore\n *\n * @param indexedDB - global indexedDB instance\n * @param dbName - name of db to connect to\n */\n public constructor(\n private readonly indexedDB: IDBFactory,\n private readonly dbName: string,\n ) {}\n\n /**\n * Returns true if this CryptoStore has ever been initialised (ie, it might contain data).\n *\n * Implementation of {@link CryptoStore.containsData}.\n *\n * @internal\n */\n public async containsData(): Promise<boolean> {\n return IndexedDBCryptoStore.exists(this.indexedDB, this.dbName);\n }\n\n /**\n * Ensure the database exists and is up-to-date, or fall back to\n * a local storage or in-memory store.\n *\n * This must be called before the store can be used.\n *\n * @returns resolves to either an IndexedDBCryptoStoreBackend.Backend,\n * or a MemoryCryptoStore\n */\n public startup(): Promise<CryptoStore> {\n if (this.backendPromise) {\n return this.backendPromise;\n }\n\n this.backendPromise = new Promise<CryptoStore>((resolve, reject) => {\n if (!this.indexedDB) {\n reject(new Error(\"no indexeddb support available\"));\n return;\n }\n\n logger.log(`connecting to indexeddb ${this.dbName}`);\n\n const req = this.indexedDB.open(this.dbName, IndexedDBCryptoStoreBackend.VERSION);\n\n req.onupgradeneeded = (ev): void => {\n const db = req.result;\n const oldVersion = ev.oldVersion;\n IndexedDBCryptoStoreBackend.upgradeDatabase(db, oldVersion);\n };\n\n req.onblocked = (): void => {\n logger.log(`can't yet open IndexedDBCryptoStore because it is open elsewhere`);\n };\n\n req.onerror = (ev): void => {\n logger.log(\"Error connecting to indexeddb\", ev);\n reject(req.error);\n };\n\n req.onsuccess = (): void => {\n const db = req.result;\n\n logger.log(`connected to indexeddb ${this.dbName}`);\n resolve(new IndexedDBCryptoStoreBackend.Backend(db));\n };\n })\n .then((backend) => {\n // Edge has IndexedDB but doesn't support compund keys which we use fairly extensively.\n // Try a dummy query which will fail if the browser doesn't support compund keys, so\n // we can fall back to a different backend.\n return backend\n .doTxn(\n \"readonly\",\n [\n IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS,\n IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS_WITHHELD,\n ],\n (txn) => {\n backend.getEndToEndInboundGroupSession(\"\", \"\", txn, () => {});\n },\n )\n .then(() => backend);\n })\n .catch((e) => {\n if (e.name === \"VersionError\") {\n logger.warn(\"Crypto DB is too new for us to use!\", e);\n // don't fall back to a different store: the user has crypto data\n // in this db so we should use it or nothing at all.\n throw new InvalidCryptoStoreError(InvalidCryptoStoreState.TooNew);\n }\n logger.warn(`unable to connect to indexeddb ${this.dbName}: falling back to localStorage store: ${e}`);\n\n try {\n if (!(globalThis.localStorage instanceof Storage)) {\n throw new Error(\"localStorage is not available\");\n }\n return new LocalStorageCryptoStore(globalThis.localStorage);\n } catch (e) {\n logger.warn(`Unable to open localStorage: falling back to in-memory store: ${e}`);\n return new MemoryCryptoStore();\n }\n })\n .then((backend) => {\n this.backend = backend;\n return backend;\n });\n\n return this.backendPromise;\n }\n\n /**\n * Delete all data from this store.\n *\n * @returns resolves when the store has been cleared.\n */\n public deleteAllData(): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (!this.indexedDB) {\n reject(new Error(\"no indexeddb support available\"));\n return;\n }\n\n logger.log(`Removing indexeddb instance: ${this.dbName}`);\n const req = this.indexedDB.deleteDatabase(this.dbName);\n\n req.onblocked = (): void => {\n logger.log(`can't yet delete IndexedDBCryptoStore because it is open elsewhere`);\n };\n\n req.onerror = (ev): void => {\n logger.log(\"Error deleting data from indexeddb\", ev);\n reject(req.error);\n };\n\n req.onsuccess = (): void => {\n logger.log(`Removed indexeddb instance: ${this.dbName}`);\n resolve();\n };\n }).catch((e) => {\n // in firefox, with indexedDB disabled, this fails with a\n // DOMError. We treat this as non-fatal, so that people can\n // still use the app.\n logger.warn(`unable to delete IndexedDBCryptoStore: ${e}`);\n });\n }\n\n /**\n * Get data on how much of the libolm to Rust Crypto migration has been done.\n *\n * Implementation of {@link CryptoStore.getMigrationState}.\n *\n * @internal\n */\n public getMigrationState(): Promise<MigrationState> {\n return this.backend!.getMigrationState();\n }\n\n /**\n * Set data on how much of the libolm to Rust Crypto migration has been done.\n *\n * Implementation of {@link CryptoStore.setMigrationState}.\n *\n * @internal\n */\n public setMigrationState(migrationState: MigrationState): Promise<void> {\n return this.backend!.setMigrationState(migrationState);\n }\n\n // Olm Account\n\n /*\n * Get the account pickle from the store.\n * This requires an active transaction. See doTxn().\n *\n * @param txn - An active transaction. See doTxn().\n * @param func - Called with the account pickle\n */\n public getAccount(txn: IDBTransaction, func: (accountPickle: string | null) => void): void {\n this.backend!.getAccount(txn, func);\n }\n\n /**\n * Write the account pickle to the store.\n * This requires an active transaction. See doTxn().\n *\n * @param txn - An active transaction. See doTxn().\n * @param accountPickle - The new account pickle to store.\n */\n public storeAccount(txn: IDBTransaction, accountPickle: string): void {\n this.backend!.storeAccount(txn, accountPickle);\n }\n\n /**\n * Get the public part of the cross-signing keys (eg. self-signing key,\n * user signing key).\n *\n * @param txn - An active transaction. See doTxn().\n * @param func - Called with the account keys object:\n * `{ key_type: base64 encoded seed }` where key type = user_signing_key_seed or self_signing_key_seed\n */\n public getCrossSigningKeys(\n txn: IDBTransaction,\n func: (keys: Record<string, CrossSigningKeyInfo> | null) => void,\n ): void {\n this.backend!.getCrossSigningKeys(txn, func);\n }\n\n /**\n * @param txn - An active transaction. See doTxn().\n * @param func - Called with the private key\n * @param type - A key type\n */\n public getSecretStorePrivateKey<K extends keyof SecretStorePrivateKeys>(\n txn: IDBTransaction,\n func: (key: SecretStorePrivateKeys[K] | null) => void,\n type: K,\n ): void {\n this.backend!.getSecretStorePrivateKey(txn, func, type);\n }\n\n /**\n * Write the cross-signing private keys back to the store\n *\n * @param txn - An active transaction. See doTxn().\n * @param type - The type of cross-signing private key to store\n * @param key - keys object as getCrossSigningKeys()\n */\n public storeSecretStorePrivateKey<K extends keyof SecretStorePrivateKeys>(\n txn: IDBTransaction,\n type: K,\n key: SecretStorePrivateKeys[K],\n ): void {\n this.backend!.storeSecretStorePrivateKey(txn, type, key);\n }\n\n // Olm sessions\n\n /**\n * Returns the number of end-to-end sessions in the store\n * @param txn - An active transaction. See doTxn().\n * @param func - Called with the count of sessions\n */\n public countEndToEndSessions(txn: IDBTransaction, func: (count: number) => void): void {\n this.backend!.countEndToEndSessions(txn, func);\n }\n\n /**\n * Retrieve a specific end-to-end session between the logged-in user\n * and another device.\n * @param deviceKey - The public key of the other device.\n * @param sessionId - The ID of the session to retrieve\n * @param txn - An active transaction. See doTxn().\n * @param func - Called with A map from sessionId\n * to session information object with 'session' key being the\n * Base64 end-to-end session and lastReceivedMessageTs being the\n * timestamp in milliseconds at which the session last received\n * a message.\n */\n public getEndToEndSession(\n deviceKey: string,\n sessionId: string,\n txn: IDBTransaction,\n func: (session: ISessionInfo | null) => void,\n ): void {\n this.backend!.getEndToEndSession(deviceKey, sessionId, txn, func);\n }\n\n /**\n * Retrieve the end-to-end sessions between the logged-in user and another\n * device.\n * @param deviceKey - The public key of the other device.\n * @param txn - An active transaction. See doTxn().\n * @param func - Called with A map from sessionId\n * to session information object with 'session' key being the\n * Base64 end-to-end session and lastReceivedMessageTs being the\n * timestamp in milliseconds at which the session last received\n * a message.\n */\n public getEndToEndSessions(\n deviceKey: string,\n txn: IDBTransaction,\n func: (sessions: { [sessionId: string]: ISessionInfo }) => void,\n ): void {\n this.backend!.getEndToEndSessions(deviceKey, txn, func);\n }\n\n /**\n * Store a session between the logged-in user and another device\n * @param deviceKey - The public key of the other device.\n * @param sessionId - The ID for this end-to-end session.\n * @param sessionInfo - Session information object\n * @param txn - An active transaction. See doTxn().\n */\n public storeEndToEndSession(\n deviceKey: string,\n sessionId: string,\n sessionInfo: ISessionInfo,\n txn: IDBTransaction,\n ): void {\n this.backend!.storeEndToEndSession(deviceKey, sessionId, sessionInfo, txn);\n }\n\n /**\n * Count the number of Megolm sessions in the database.\n *\n * Implementation of {@link CryptoStore.countEndToEndInboundGroupSessions}.\n *\n * @internal\n */\n public countEndToEndInboundGroupSessions(): Promise<number> {\n return this.backend!.countEndToEndInboundGroupSessions();\n }\n\n /**\n * Fetch a batch of Olm sessions from the database.\n *\n * Implementation of {@link CryptoStore.getEndToEndSessionsBatch}.\n *\n * @internal\n */\n public getEndToEndSessionsBatch(): Promise<null | ISessionInfo[]> {\n return this.backend!.getEndToEndSessionsBatch();\n }\n\n /**\n * Delete a batch of Olm sessions from the database.\n *\n * Implementation of {@link CryptoStore.deleteEndToEndSessionsBatch}.\n *\n * @internal\n */\n public deleteEndToEndSessionsBatch(sessions: { deviceKey: string; sessionId: string }[]): Promise<void> {\n return this.backend!.deleteEndToEndSessionsBatch(sessions);\n }\n\n // Inbound group sessions\n\n /**\n * Retrieve the end-to-end inbound group session for a given\n * server key and session ID\n * @param senderCurve25519Key - The sender's curve 25519 key\n * @param sessionId - The ID of the session\n * @param txn - An active transaction. See doTxn().\n * @param func - Called with A map from sessionId\n * to Base64 end-to-end session.\n */\n public getEndToEndInboundGroupSession(\n senderCurve25519Key: string,\n sessionId: string,\n txn: IDBTransaction,\n func: (groupSession: InboundGroupSessionData | null, groupSessionWithheld: IWithheld | null) => void,\n ): void {\n this.backend!.getEndToEndInboundGroupSession(senderCurve25519Key, sessionId, txn, func);\n }\n\n /**\n * Writes an end-to-end inbound group session to the store.\n * If there already exists an inbound group session with the same\n * senderCurve25519Key and sessionID, it will be overwritten.\n * @param senderCurve25519Key - The sender's curve 25519 key\n * @param sessionId - The ID of the session\n * @param sessionData - The session data structure\n * @param txn - An active transaction. See doTxn().\n */\n public storeEndToEndInboundGroupSession(\n senderCurve25519Key: string,\n sessionId: string,\n sessionData: InboundGroupSessionData,\n txn: IDBTransaction,\n ): void {\n this.backend!.storeEndToEndInboundGroupSession(senderCurve25519Key, sessionId, sessionData, txn);\n }\n\n /**\n * Fetch a batch of Megolm sessions from the database.\n *\n * Implementation of {@link CryptoStore.getEndToEndInboundGroupSessionsBatch}.\n *\n * @internal\n */\n public getEndToEndInboundGroupSessionsBatch(): Promise<SessionExtended[] | null> {\n return this.backend!.getEndToEndInboundGroupSessionsBatch();\n }\n\n /**\n * Delete a batch of Megolm sessions from the database.\n *\n * Implementation of {@link CryptoStore.deleteEndToEndInboundGroupSessionsBatch}.\n *\n * @internal\n */\n public deleteEndToEndInboundGroupSessionsBatch(\n sessions: { senderKey: string; sessionId: string }[],\n ): Promise<void> {\n return this.backend!.deleteEndToEndInboundGroupSessionsBatch(sessions);\n }\n\n /**\n * Get an object of `roomId->roomInfo` for all e2e rooms in the store\n * @param txn - An active transaction. See doTxn().\n * @param func - Function called with the end-to-end encrypted rooms\n */\n public getEndToEndRooms(txn: IDBTransaction, func: (rooms: Record<string, IRoomEncryption>) => void): void {\n this.backend!.getEndToEndRooms(txn, func);\n }\n\n /**\n * Mark sessions as needing to be backed up.\n * @param sessions - The sessions that need to be backed up.\n * @param txn - An active transaction. See doTxn(). (optional)\n * @returns resolves when the sessions are marked\n */\n public markSessionsNeedingBackup(sessions: ISession[], txn?: IDBTransaction): Promise<void> {\n return this.backend!.markSessionsNeedingBackup(sessions, txn);\n }\n\n /**\n * Perform a transaction on the crypto store. Any store methods\n * that require a transaction (txn) object to be passed in may\n * only be called within a callback of either this function or\n * one of the store functions operating on the same transaction.\n *\n * @param mode - 'readwrite' if you need to call setter\n * functions with this transaction. Otherwise, 'readonly'.\n * @param stores - List IndexedDBCryptoStore.STORE_*\n * options representing all types of object that will be\n * accessed or written to with this transaction.\n * @param func - Function called with the\n * transaction object: an opaque object that should be passed\n * to store functions.\n * @param log - A possibly customised log\n * @returns Promise that resolves with the result of the `func`\n * when the transaction is complete. If the backend is\n * async (ie. the indexeddb backend) any of the callback\n * functions throwing an exception will cause this promise to\n * reject with that exception. On synchronous backends, the\n * exception will propagate to the caller of the getFoo method.\n */\n public doTxn<T>(mode: Mode, stores: Iterable<string>, func: (txn: IDBTransaction) => T, log?: Logger): Promise<T> {\n return this.backend!.doTxn<T>(mode, stores, func as (txn: unknown) => T, log);\n }\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAS,MAAM,QAAqB,iBAAiB;AACrD,SAAS,uBAAuB,QAAQ,gCAAgC;AACxE,SAAS,iBAAiB,QAAQ,0BAA0B;AAC5D,OAAO,KAAK,2BAA2B,MAAM,qCAAqC;AAClF,SAAS,uBAAuB,EAAE,uBAAuB,QAAQ,iBAAiB;AAClF,OAAO,KAAK,gBAAgB,MAAM,4BAA4B;AAC9D,SAMI,cAAc,EAGd,kCAAkC,QAG/B,WAAW;AAGlB;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,OAAO,MAAM,oBAAoB,CAAwB;EAWrD,OAAc,MAAM,CAAC,SAAqB,EAAE,MAAc,EAAoB;IAC1E,OAAO,gBAAgB,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC;EACrD;;EAEA;AACJ;AACA;AACA;EACI,OAAc,sBAAsB,CAAC,SAAqB,EAAE,MAAc,EAAoB;IAC1F,OAAO,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,MAAM,KAAK;MAC7C,IAAI,MAAM,GAAG,IAAI;MACjB,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;MAC5C,aAAa,CAAC,eAAe,GAAG,MAAY;QACxC;QACA;QACA,MAAM,GAAG,KAAK;MAClB,CAAC;MACD,aAAa,CAAC,SAAS,GAAG,MAAY,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC;MACjE,aAAa,CAAC,SAAS,GAAG,MAAY;QAClC,MAAM,EAAE,GAAG,aAAa,CAAC,MAAM;QAC/B,IAAI,CAAC,MAAM,EAAE;UACT,EAAE,CAAC,KAAK,CAAC,CAAC;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7C;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACW,yBAAyB,CAAC,QAAoB,EAAE,GAAoB,EAAiB;IACxF,OAAO,IAAI,CAAC,OAAO,CAAE,yBAAyB,CAAC,QAAQ,EAAE,GAAG,CAAC;EACjE;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACW,KAAK,CAAI,IAAU,EAAE,MAAwB,EAAE,IAAgC,EAAE,GAAY,EAAc;IAC9G,OAAO,IAAI,CAAC,OAAO,CAAE,KAAK,CAAI,IAAI,EAAE,MAAM,EAAE,IAAI,EAAyB,GAAG,CAAC;EACjF;AACJ;AAAC,gBA3fY,oBAAoB,mBACC,SAAS;AAAA,gBAD9B,oBAAoB,oBAEE,UAAU;AAAA,gBAFhC,oBAAoB,kCAGgB,wBAAwB;AAAA,gBAH5D,oBAAoB,2CAIyB,iCAAiC;AAAA,gBAJ9E,oBAAoB,iDAK+B,uCAAuC;AAAA,gBAL1F,oBAAoB,iCAMe,uBAAuB;AAAA,gBAN1D,oBAAoB,uBAOK,aAAa;AAAA,gBAPtC,oBAAoB,iBAQD,OAAO;AAAA,gBAR1B,oBAAoB,kBASA,yBAAyB","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"memory-crypto-store.js","names":[],"sources":["../../../src/crypto/store/memory-crypto-store.ts"],"sourcesContent":["/*\nCopyright 2017 - 2021 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { safeSet } from \"../../utils.ts\";\nimport {\n type CryptoStore,\n type ISession,\n type SessionExtended,\n type ISessionInfo,\n type IWithheld,\n MigrationState,\n type Mode,\n type SecretStorePrivateKeys,\n SESSION_BATCH_SIZE,\n type InboundGroupSessionData,\n type IRoomEncryption,\n} from \"./base.ts\";\nimport { type CrossSigningKeyInfo } from \"../../crypto-api/index.ts\";\n\nfunction encodeSessionKey(senderCurve25519Key: string, sessionId: string): string {\n return encodeURIComponent(senderCurve25519Key) + \"/\" + encodeURIComponent(sessionId);\n}\n\nfunction decodeSessionKey(key: string): { senderKey: string; sessionId: string } {\n const keyParts = key.split(\"/\");\n const senderKey = decodeURIComponent(keyParts[0]);\n const sessionId = decodeURIComponent(keyParts[1]);\n return { senderKey, sessionId };\n}\n\n/**\n * Internal module. in-memory storage for e2e.\n */\n\nexport class MemoryCryptoStore implements CryptoStore {\n private migrationState: MigrationState = MigrationState.NOT_STARTED;\n private account: string | null = null;\n private crossSigningKeys: Record<string, CrossSigningKeyInfo> | null = null;\n private privateKeys: Partial<SecretStorePrivateKeys> = {};\n\n private sessions: { [deviceKey: string]: { [sessionId: string]: ISessionInfo } } = {};\n private inboundGroupSessions: { [sessionKey: string]: InboundGroupSessionData } = {};\n private inboundGroupSessionsWithheld: Record<string, IWithheld> = {};\n // Opaque device data object\n private rooms: { [roomId: string]: IRoomEncryption } = {};\n private sessionsNeedingBackup: { [sessionKey: string]: boolean } = {};\n\n /**\n * Returns true if this CryptoStore has ever been initialised (ie, it might contain data).\n *\n * Implementation of {@link CryptoStore.containsData}.\n *\n * @internal\n */\n public async containsData(): Promise<boolean> {\n // If it contains anything, it should contain an account.\n return this.account !== null;\n }\n\n /**\n * Ensure the database exists and is up-to-date.\n *\n * This must be called before the store can be used.\n *\n * @returns resolves to the store.\n */\n public async startup(): Promise<CryptoStore> {\n // No startup work to do for the memory store.\n return this;\n }\n\n /**\n * Delete all data from this store.\n *\n * @returns Promise which resolves when the store has been cleared.\n */\n public deleteAllData(): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Get data on how much of the libolm to Rust Crypto migration has been done.\n *\n * Implementation of {@link CryptoStore.getMigrationState}.\n *\n * @internal\n */\n public async getMigrationState(): Promise<MigrationState> {\n return this.migrationState;\n }\n\n /**\n * Set data on how much of the libolm to Rust Crypto migration has been done.\n *\n * Implementation of {@link CryptoStore.setMigrationState}.\n *\n * @internal\n */\n public async setMigrationState(migrationState: MigrationState): Promise<void> {\n this.migrationState = migrationState;\n }\n\n // Olm Account\n\n public getAccount(txn: unknown, func: (accountPickle: string | null) => void): void {\n func(this.account);\n }\n\n public storeAccount(txn: unknown, accountPickle: string): void {\n this.account = accountPickle;\n }\n\n public getCrossSigningKeys(txn: unknown, func: (keys: Record<string, CrossSigningKeyInfo> | null) => void): void {\n func(this.crossSigningKeys);\n }\n\n public getSecretStorePrivateKey<K extends keyof SecretStorePrivateKeys>(\n txn: unknown,\n func: (key: SecretStorePrivateKeys[K] | null) => void,\n type: K,\n ): void {\n const result = this.privateKeys[type] as SecretStorePrivateKeys[K] | undefined;\n func(result || null);\n }\n\n public storeSecretStorePrivateKey<K extends keyof SecretStorePrivateKeys>(\n txn: unknown,\n type: K,\n key: SecretStorePrivateKeys[K],\n ): void {\n this.privateKeys[type] = key;\n }\n\n // Olm Sessions\n\n public countEndToEndSessions(txn: unknown, func: (count: number) => void): void {\n let count = 0;\n for (const deviceSessions of Object.values(this.sessions)) {\n count += Object.keys(deviceSessions).length;\n }\n func(count);\n }\n\n public getEndToEndSession(\n deviceKey: string,\n sessionId: string,\n txn: unknown,\n func: (session: ISessionInfo) => void,\n ): void {\n const deviceSessions = this.sessions[deviceKey] || {};\n func(deviceSessions[sessionId] || null);\n }\n\n public getEndToEndSessions(\n deviceKey: string,\n txn: unknown,\n func: (sessions: { [sessionId: string]: ISessionInfo }) => void,\n ): void {\n func(this.sessions[deviceKey] || {});\n }\n\n public storeEndToEndSession(deviceKey: string, sessionId: string, sessionInfo: ISessionInfo, txn: unknown): void {\n let deviceSessions = this.sessions[deviceKey];\n if (deviceSessions === undefined) {\n deviceSessions = {};\n this.sessions[deviceKey] = deviceSessions;\n }\n safeSet(deviceSessions, sessionId, sessionInfo);\n }\n\n /**\n * Fetch a batch of Olm sessions from the database.\n *\n * Implementation of {@link CryptoStore.getEndToEndSessionsBatch}.\n *\n * @internal\n */\n public async getEndToEndSessionsBatch(): Promise<null | ISessionInfo[]> {\n const result: ISessionInfo[] = [];\n for (const deviceSessions of Object.values(this.sessions)) {\n for (const session of Object.values(deviceSessions)) {\n result.push(session);\n if (result.length >= SESSION_BATCH_SIZE) {\n return result;\n }\n }\n }\n\n if (result.length === 0) {\n // No sessions left.\n return null;\n }\n\n // There are fewer sessions than the batch size; return the final batch of sessions.\n return result;\n }\n\n /**\n * Delete a batch of Olm sessions from the database.\n *\n * Implementation of {@link CryptoStore.deleteEndToEndSessionsBatch}.\n *\n * @internal\n */\n public async deleteEndToEndSessionsBatch(sessions: { deviceKey: string; sessionId: string }[]): Promise<void> {\n for (const { deviceKey, sessionId } of sessions) {\n const deviceSessions = this.sessions[deviceKey] || {};\n delete deviceSessions[sessionId];\n if (Object.keys(deviceSessions).length === 0) {\n // No more sessions for this device.\n delete this.sessions[deviceKey];\n }\n }\n }\n\n // Inbound Group Sessions\n\n public getEndToEndInboundGroupSession(\n senderCurve25519Key: string,\n sessionId: string,\n txn: unknown,\n func: (groupSession: InboundGroupSessionData | null, groupSessionWithheld: IWithheld | null) => void,\n ): void {\n const k = encodeSessionKey(senderCurve25519Key, sessionId);\n func(this.inboundGroupSessions[k] || null, this.inboundGroupSessionsWithheld[k] || null);\n }\n\n public storeEndToEndInboundGroupSession(\n senderCurve25519Key: string,\n sessionId: string,\n sessionData: InboundGroupSessionData,\n txn: unknown,\n ): void {\n const k = encodeSessionKey(senderCurve25519Key, sessionId);\n this.inboundGroupSessions[k] = sessionData;\n }\n\n /**\n * Count the number of Megolm sessions in the database.\n *\n * Implementation of {@link CryptoStore.countEndToEndInboundGroupSessions}.\n *\n * @internal\n */\n public async countEndToEndInboundGroupSessions(): Promise<number> {\n return Object.keys(this.inboundGroupSessions).length;\n }\n\n /**\n * Fetch a batch of Megolm sessions from the database.\n *\n * Implementation of {@link CryptoStore.getEndToEndInboundGroupSessionsBatch}.\n *\n * @internal\n */\n public async getEndToEndInboundGroupSessionsBatch(): Promise<null | SessionExtended[]> {\n const result: SessionExtended[] = [];\n for (const [key, session] of Object.entries(this.inboundGroupSessions)) {\n result.push({\n ...decodeSessionKey(key),\n sessionData: session,\n needsBackup: key in this.sessionsNeedingBackup,\n });\n if (result.length >= SESSION_BATCH_SIZE) {\n return result;\n }\n }\n\n if (result.length === 0) {\n // No sessions left.\n return null;\n }\n\n // There are fewer sessions than the batch size; return the final batch of sessions.\n return result;\n }\n\n /**\n * Delete a batch of Megolm sessions from the database.\n *\n * Implementation of {@link CryptoStore.deleteEndToEndInboundGroupSessionsBatch}.\n *\n * @internal\n */\n public async deleteEndToEndInboundGroupSessionsBatch(\n sessions: { senderKey: string; sessionId: string }[],\n ): Promise<void> {\n for (const { senderKey, sessionId } of sessions) {\n const k = encodeSessionKey(senderKey, sessionId);\n delete this.inboundGroupSessions[k];\n }\n }\n\n // E2E rooms\n\n public getEndToEndRooms(txn: unknown, func: (rooms: Record<string, IRoomEncryption>) => void): void {\n func(this.rooms);\n }\n\n public markSessionsNeedingBackup(sessions: ISession[]): Promise<void> {\n for (const session of sessions) {\n const sessionKey = encodeSessionKey(session.senderKey, session.sessionId);\n this.sessionsNeedingBackup[sessionKey] = true;\n }\n return Promise.resolve();\n }\n\n // Session key backups\n\n public doTxn<T>(mode: Mode, stores: Iterable<string>, func: (txn?: unknown) => T): Promise<T> {\n return Promise.resolve(func(null));\n }\n}\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAS,OAAO,QAAQ,gBAAgB;AACxC,SAMI,cAAc,EAGd,kBAAkB,QAGf,WAAW;AAGlB,SAAS,gBAAgB,CAAC,m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MAAE,SAAS;MAAE;IAAU,CAAC,IAAI,QAAQ,EAAE;MAC7C,MAAM,CAAC,GAAG,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC;MAChD,OAAO,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;IACvC;EACJ;;EAEA;;EAEO,gBAAgB,CAAC,GAAY,EAAE,IAAsD,EAAQ;IAChG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;EACpB;EAEO,yBAAyB,CAAC,QAAoB,EAAiB;IAClE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;MAC5B,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC;MACzE,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,GAAG,IAAI;IACjD;IACA,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;EAC5B;;EAEA;;EAEO,KAAK,CAAI,IAAU,EAAE,MAAwB,EAAE,IAA0B,EAAc;IAC1F,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;EACtC;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"memory-crypto-store.js","names":[],"sources":["../../../src/crypto/store/memory-crypto-store.ts"],"sourcesContent":["/*\nCopyright 2017 - 2021 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { safeSet } from \"../../utils.ts\";\nimport {\n type CryptoStore,\n type ISession,\n type SessionExtended,\n type ISessionInfo,\n type IWithheld,\n MigrationState,\n type Mode,\n type SecretStorePrivateKeys,\n SESSION_BATCH_SIZE,\n type InboundGroupSessionData,\n type IRoomEncryption,\n} from \"./base.ts\";\nimport { type CrossSigningKeyInfo } from \"../../crypto-api/index.ts\";\n\nfunction encodeSessionKey(senderCurve25519Key: string, sessionId: string): string {\n return encodeURIComponent(senderCurve25519Key) + \"/\" + encodeURIComponent(sessionId);\n}\n\nfunction decodeSessionKey(key: string): { senderKey: string; sessionId: string } {\n const keyParts = key.split(\"/\");\n const senderKey = decodeURIComponent(keyParts[0]);\n const sessionId = decodeURIComponent(keyParts[1]);\n return { senderKey, sessionId };\n}\n\n/**\n * Internal module. in-memory storage for e2e.\n */\n\nexport class MemoryCryptoStore implements CryptoStore {\n private migrationState: MigrationState = MigrationState.NOT_STARTED;\n private account: string | null = null;\n private crossSigningKeys: Record<string, CrossSigningKeyInfo> | null = null;\n private privateKeys: Partial<SecretStorePrivateKeys> = {};\n\n private sessions: { [deviceKey: string]: { [sessionId: string]: ISessionInfo } } = {};\n private inboundGroupSessions: { [sessionKey: string]: InboundGroupSessionData } = {};\n private inboundGroupSessionsWithheld: Record<string, IWithheld> = {};\n // Opaque device data object\n private rooms: { [roomId: string]: IRoomEncryption } = {};\n private sessionsNeedingBackup: { [sessionKey: string]: boolean } = {};\n\n /**\n * Returns true if this CryptoStore has ever been initialised (ie, it might contain data).\n *\n * Implementation of {@link CryptoStore.containsData}.\n *\n * @internal\n */\n public async containsData(): Promise<boolean> {\n // If it contains anything, it should contain an account.\n return this.account !== null;\n }\n\n /**\n * Ensure the database exists and is up-to-date.\n *\n * This must be called before the store can be used.\n *\n * @returns resolves to the store.\n */\n public async startup(): Promise<CryptoStore> {\n // No startup work to do for the memory store.\n return this;\n }\n\n /**\n * Delete all data from this store.\n *\n * @returns Promise which resolves when the store has been cleared.\n */\n public deleteAllData(): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Get data on how much of the libolm to Rust Crypto migration has been done.\n *\n * Implementation of {@link CryptoStore.getMigrationState}.\n *\n * @internal\n */\n public async getMigrationState(): Promise<MigrationState> {\n return this.migrationState;\n }\n\n /**\n * Set data on how much of the libolm to Rust Crypto migration has been done.\n *\n * Implementation of {@link CryptoStore.setMigrationState}.\n *\n * @internal\n */\n public async setMigrationState(migrationState: MigrationState): Promise<void> {\n this.migrationState = migrationState;\n }\n\n // Olm Account\n\n public getAccount(txn: unknown, func: (accountPickle: string | null) => void): void {\n func(this.account);\n }\n\n public storeAccount(txn: unknown, accountPickle: string): void {\n this.account = accountPickle;\n }\n\n public getCrossSigningKeys(txn: unknown, func: (keys: Record<string, CrossSigningKeyInfo> | null) => void): void {\n func(this.crossSigningKeys);\n }\n\n public getSecretStorePrivateKey<K extends keyof SecretStorePrivateKeys>(\n txn: unknown,\n func: (key: SecretStorePrivateKeys[K] | null) => void,\n type: K,\n ): void {\n const result = this.privateKeys[type];\n func(result || null);\n }\n\n public storeSecretStorePrivateKey<K extends keyof SecretStorePrivateKeys>(\n txn: unknown,\n type: K,\n key: SecretStorePrivateKeys[K],\n ): void {\n this.privateKeys[type] = key;\n }\n\n // Olm Sessions\n\n public countEndToEndSessions(txn: unknown, func: (count: number) => void): void {\n let count = 0;\n for (const deviceSessions of Object.values(this.sessions)) {\n count += Object.keys(deviceSessions).length;\n }\n func(count);\n }\n\n public getEndToEndSession(\n deviceKey: string,\n sessionId: string,\n txn: unknown,\n func: (session: ISessionInfo) => void,\n ): void {\n const deviceSessions = this.sessions[deviceKey] || {};\n func(deviceSessions[sessionId] || null);\n }\n\n public getEndToEndSessions(\n deviceKey: string,\n txn: unknown,\n func: (sessions: { [sessionId: string]: ISessionInfo }) => void,\n ): void {\n func(this.sessions[deviceKey] || {});\n }\n\n public storeEndToEndSession(deviceKey: string, sessionId: string, sessionInfo: ISessionInfo, txn: unknown): void {\n let deviceSessions = this.sessions[deviceKey];\n if (deviceSessions === undefined) {\n deviceSessions = {};\n this.sessions[deviceKey] = deviceSessions;\n }\n safeSet(deviceSessions, sessionId, sessionInfo);\n }\n\n /**\n * Fetch a batch of Olm sessions from the database.\n *\n * Implementation of {@link CryptoStore.getEndToEndSessionsBatch}.\n *\n * @internal\n */\n public async getEndToEndSessionsBatch(): Promise<null | ISessionInfo[]> {\n const result: ISessionInfo[] = [];\n for (const deviceSessions of Object.values(this.sessions)) {\n for (const session of Object.values(deviceSessions)) {\n result.push(session);\n if (result.length >= SESSION_BATCH_SIZE) {\n return result;\n }\n }\n }\n\n if (result.length === 0) {\n // No sessions left.\n return null;\n }\n\n // There are fewer sessions than the batch size; return the final batch of sessions.\n return result;\n }\n\n /**\n * Delete a batch of Olm sessions from the database.\n *\n * Implementation of {@link CryptoStore.deleteEndToEndSessionsBatch}.\n *\n * @internal\n */\n public async deleteEndToEndSessionsBatch(sessions: { deviceKey: string; sessionId: string }[]): Promise<void> {\n for (const { deviceKey, sessionId } of sessions) {\n const deviceSessions = this.sessions[deviceKey] || {};\n delete deviceSessions[sessionId];\n if (Object.keys(deviceSessions).length === 0) {\n // No more sessions for this device.\n delete this.sessions[deviceKey];\n }\n }\n }\n\n // Inbound Group Sessions\n\n public getEndToEndInboundGroupSession(\n senderCurve25519Key: string,\n sessionId: string,\n txn: unknown,\n func: (groupSession: InboundGroupSessionData | null, groupSessionWithheld: IWithheld | null) => void,\n ): void {\n const k = encodeSessionKey(senderCurve25519Key, sessionId);\n func(this.inboundGroupSessions[k] || null, this.inboundGroupSessionsWithheld[k] || null);\n }\n\n public storeEndToEndInboundGroupSession(\n senderCurve25519Key: string,\n sessionId: string,\n sessionData: InboundGroupSessionData,\n txn: unknown,\n ): void {\n const k = encodeSessionKey(senderCurve25519Key, sessionId);\n this.inboundGroupSessions[k] = sessionData;\n }\n\n /**\n * Count the number of Megolm sessions in the database.\n *\n * Implementation of {@link CryptoStore.countEndToEndInboundGroupSessions}.\n *\n * @internal\n */\n public async countEndToEndInboundGroupSessions(): Promise<number> {\n return Object.keys(this.inboundGroupSessions).length;\n }\n\n /**\n * Fetch a batch of Megolm sessions from the database.\n *\n * Implementation of {@link CryptoStore.getEndToEndInboundGroupSessionsBatch}.\n *\n * @internal\n */\n public async getEndToEndInboundGroupSessionsBatch(): Promise<null | SessionExtended[]> {\n const result: SessionExtended[] = [];\n for (const [key, session] of Object.entries(this.inboundGroupSessions)) {\n result.push({\n ...decodeSessionKey(key),\n sessionData: session,\n needsBackup: key in this.sessionsNeedingBackup,\n });\n if (result.length >= SESSION_BATCH_SIZE) {\n return result;\n }\n }\n\n if (result.length === 0) {\n // No sessions left.\n return null;\n }\n\n // There are fewer sessions than the batch size; return the final batch of sessions.\n return result;\n }\n\n /**\n * Delete a batch of Megolm sessions from the database.\n *\n * Implementation of {@link CryptoStore.deleteEndToEndInboundGroupSessionsBatch}.\n *\n * @internal\n */\n public async deleteEndToEndInboundGroupSessionsBatch(\n sessions: { senderKey: string; sessionId: string }[],\n ): Promise<void> {\n for (const { senderKey, sessionId } of sessions) {\n const k = encodeSessionKey(senderKey, sessionId);\n delete this.inboundGroupSessions[k];\n }\n }\n\n // E2E rooms\n\n public getEndToEndRooms(txn: unknown, func: (rooms: Record<string, IRoomEncryption>) => void): void {\n func(this.rooms);\n }\n\n public markSessionsNeedingBackup(sessions: ISession[]): Promise<void> {\n for (const session of sessions) {\n const sessionKey = encodeSessionKey(session.senderKey, session.sessionId);\n this.sessionsNeedingBackup[sessionKey] = true;\n }\n return Promise.resolve();\n }\n\n // Session key backups\n\n public doTxn<T>(mode: Mode, stores: Iterable<string>, func: (txn?: unknown) => T): Promise<T> {\n return Promise.resolve(func(null));\n }\n}\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAS,OAAO,QAAQ,gBAAgB;AACxC,SAMI,cAAc,EAGd,kBAAkB,QAGf,WAAW;AAGlB,SAAS,gBAAgB,CAAC,mBAA2B,EAAE,SAAiB,EAAU;EAC9E,OAAO,kBAAkB,CAAC,mBAAmB,CAAC,GAAG,GAAG,GAAG,kBAAkB,CAAC,SAAS,CAAC;AACxF;AAEA,SAAS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AAC,oBAAoB,CAAC,CAAC,CAAC;IACvC;EACJ;;EAEA;;EAEO,gBAAgB,CAAC,GAAY,EAAE,IAAsD,EAAQ;IAChG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;EACpB;EAEO,yBAAyB,CAAC,QAAoB,EAAiB;IAClE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;MAC5B,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC;MACzE,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,GAAG,IAAI;IACjD;IACA,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;EAC5B;;EAEA;;EAEO,KAAK,CAAI,IAAU,EAAE,MAAwB,EAAE,IAA0B,EAAc;IAC1F,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;EACtC;AACJ","ignoreList":[]}
package/lib/embedded.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type WidgetApi } from "matrix-widget-api";
2
+ import { type Transport } from "./matrixrtc/index.ts";
2
3
  import { MatrixEvent } from "./models/event.ts";
3
4
  import { type ISendEventResponse, type SendDelayedEventRequestOpts, type SendDelayedEventResponse, UpdateDelayedEventAction } from "./@types/requests.ts";
4
5
  import { type StateEvents } from "./@types/event.ts";
@@ -76,6 +77,12 @@ export interface ICapabilities {
76
77
  * @defaultValue false
77
78
  */
78
79
  receiveSticky?: boolean;
80
+ /**
81
+ * Whether this client needs to be able to discover the RTC transports the host can reach.
82
+ * @experimental Part of MSC4515
83
+ * @defaultValue false
84
+ */
85
+ rtcTransports?: boolean;
79
86
  }
80
87
  export declare enum RoomWidgetClientEvent {
81
88
  PendingEventsChanged = "PendingEvent.pendingEventsChanged"
@@ -153,6 +160,15 @@ export declare class RoomWidgetClient extends MatrixClient {
153
160
  }[], payload: ToDevicePayload): Promise<void>;
154
161
  sendToDevice(eventType: string, contentMap: SendToDeviceContentMap): Promise<EmptyObject>;
155
162
  getOpenIdToken(): Promise<IOpenIDToken>;
163
+ /**
164
+ * Returns a set of configured RTC transports supported by the homeserver.
165
+ *
166
+ * Overrides the homeserver-side {@link MatrixClient._unstable_getRTCTransports} (MSC4143):
167
+ * a widget cannot make authenticated homeserver calls itself, so we ask the host over the
168
+ * widget API instead (MSC4515). Requires the `rtcTransports` capability and a host that
169
+ * advertises the `org.matrix.msc4515` API version (otherwise the request throws).
170
+ */
171
+ _unstable_getRTCTransports(): Promise<Transport[]>;
156
172
  queueToDevice({ eventType, batch }: ToDeviceBatch): Promise<void>;
157
173
  /**
158
174
  * Send an event to a specific list of devices via the widget API. Optionally encrypts the event.
@@ -1 +1 @@
1
- {"version":3,"file":"embedded.d.ts","sourceRoot":"","sources":["../src/embedded.ts"],"names":[],"mappings":"AAgBA,OAAO,EACH,KAAK,SAAS,EAejB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,WAAW,EAA2C,MAAM,mBAAmB,CAAC;AACzF,OAAO,EACH,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,EAC7B,wBAAwB,EAE3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EACH,YAAY,EAEZ,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EAEpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAW,SAAS,EAAE,MAAM,WAAW,CAAC;AAI/C,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACvF,OAAO,EAAkB,KAAK,SAAS,EAAwB,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,KAAK,WAAW,EAA4D,MAAM,aAAa,CAAC;AAEzG,UAAU,kBAAkB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U,CAchB;IAEF,OAAO,CAAC,aAAa,CA6BnB;YAEY,gBAAgB;CAyBjC"}
package/lib/embedded.js CHANGED
@@ -257,6 +257,9 @@ export class RoomWidgetClient extends MatrixClient {
257
257
  if (capabilities.turnServers) {
258
258
  this.widgetApi.requestCapability(MatrixCapabilities.MSC3846TurnServers);
259
259
  }
260
+ if (capabilities.rtcTransports) {
261
+ this.widgetApi.requestCapability(MatrixCapabilities.MSC4515RtcTransports);
262
+ }
260
263
  }
261
264
  async supportUpdateState() {
262
265
  return (await this.widgetApi.getClientVersions()).includes(UnstableApiVersion.MSC2762_UPDATE_STATE);
@@ -310,12 +313,7 @@ export class RoomWidgetClient extends MatrixClient {
310
313
  });
311
314
  }) ?? []);
312
315
  }
313
- if (opts.clientWellKnownPollPeriod !== undefined) {
314
- this.clientWellKnownIntervalID = setInterval(() => {
315
- this.fetchClientWellKnown();
316
- }, 1000 * opts.clientWellKnownPollPeriod);
317
- this.fetchClientWellKnown();
318
- }
316
+ this.cachedWellKnown.start(opts.clientWellKnownPollPeriod !== undefined ? 1000 * opts.clientWellKnownPollPeriod : undefined);
319
317
  this.setSyncState(SyncState.Syncing);
320
318
  logger.info("Finished initial sync");
321
319
  this.matrixRTC.start();
@@ -507,6 +505,21 @@ export class RoomWidgetClient extends MatrixClient {
507
505
  token_type: token.token_type
508
506
  };
509
507
  }
508
+
509
+ /**
510
+ * Returns a set of configured RTC transports supported by the homeserver.
511
+ *
512
+ * Overrides the homeserver-side {@link MatrixClient._unstable_getRTCTransports} (MSC4143):
513
+ * a widget cannot make authenticated homeserver calls itself, so we ask the host over the
514
+ * widget API instead (MSC4515). Requires the `rtcTransports` capability and a host that
515
+ * advertises the `org.matrix.msc4515` API version (otherwise the request throws).
516
+ */
517
+ async _unstable_getRTCTransports() {
518
+ const {
519
+ rtc_transports: rtcTransports
520
+ } = await this.widgetApi.getRtcTransports().catch(timeoutToConnectionError);
521
+ return rtcTransports;
522
+ }
510
523
  async queueToDevice({
511
524
  eventType,
512
525
  batch