@unwanted/matrix-sdk-mini 34.12.0-2 → 34.12.0-4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (492) hide show
  1. package/git-revision.txt +1 -1
  2. package/lib/@types/global.d.js +0 -2
  3. package/lib/@types/global.d.js.map +1 -1
  4. package/lib/browser-index.d.ts.map +1 -1
  5. package/lib/browser-index.js +0 -11
  6. package/lib/browser-index.js.map +1 -1
  7. package/lib/client.d.ts +2 -1221
  8. package/lib/client.d.ts.map +1 -1
  9. package/lib/client.js +331 -2821
  10. package/lib/client.js.map +1 -1
  11. package/lib/embedded.d.ts +0 -22
  12. package/lib/embedded.d.ts.map +1 -1
  13. package/lib/embedded.js +24 -166
  14. package/lib/embedded.js.map +1 -1
  15. package/lib/event-mapper.d.ts.map +1 -1
  16. package/lib/event-mapper.js +0 -4
  17. package/lib/event-mapper.js.map +1 -1
  18. package/lib/matrix.d.ts +0 -19
  19. package/lib/matrix.d.ts.map +1 -1
  20. package/lib/matrix.js +1 -26
  21. package/lib/matrix.js.map +1 -1
  22. package/lib/models/MSC3089Branch.d.ts.map +1 -1
  23. package/lib/models/MSC3089Branch.js +0 -3
  24. package/lib/models/MSC3089Branch.js.map +1 -1
  25. package/lib/models/event.d.ts +0 -94
  26. package/lib/models/event.d.ts.map +1 -1
  27. package/lib/models/event.js +0 -274
  28. package/lib/models/event.js.map +1 -1
  29. package/lib/models/poll.d.ts.map +1 -1
  30. package/lib/models/poll.js +1 -5
  31. package/lib/models/poll.js.map +1 -1
  32. package/lib/models/relations-container.d.ts.map +1 -1
  33. package/lib/models/relations-container.js +1 -7
  34. package/lib/models/relations-container.js.map +1 -1
  35. package/lib/models/relations.d.ts +0 -1
  36. package/lib/models/relations.d.ts.map +1 -1
  37. package/lib/models/relations.js +0 -8
  38. package/lib/models/relations.js.map +1 -1
  39. package/lib/models/room-state.d.ts.map +1 -1
  40. package/lib/models/room-state.js +10 -26
  41. package/lib/models/room-state.js.map +1 -1
  42. package/lib/models/room.d.ts +0 -18
  43. package/lib/models/room.d.ts.map +1 -1
  44. package/lib/models/room.js +94 -148
  45. package/lib/models/room.js.map +1 -1
  46. package/lib/models/thread.d.ts.map +1 -1
  47. package/lib/models/thread.js +0 -1
  48. package/lib/models/thread.js.map +1 -1
  49. package/lib/sliding-sync-sdk.d.ts +2 -3
  50. package/lib/sliding-sync-sdk.d.ts.map +1 -1
  51. package/lib/sliding-sync-sdk.js +41 -90
  52. package/lib/sliding-sync-sdk.js.map +1 -1
  53. package/lib/sync.d.ts +0 -12
  54. package/lib/sync.d.ts.map +1 -1
  55. package/lib/sync.js +1 -73
  56. package/lib/sync.js.map +1 -1
  57. package/lib/testing.d.ts +0 -48
  58. package/lib/testing.d.ts.map +1 -1
  59. package/lib/testing.js +0 -105
  60. package/lib/testing.js.map +1 -1
  61. package/lib/types.d.ts +0 -1
  62. package/lib/types.d.ts.map +1 -1
  63. package/lib/types.js.map +1 -1
  64. package/package.json +1 -3
  65. package/src/@types/global.d.ts +0 -3
  66. package/src/browser-index.ts +0 -11
  67. package/src/client.ts +60 -2882
  68. package/src/embedded.ts +3 -130
  69. package/src/event-mapper.ts +0 -4
  70. package/src/matrix.ts +0 -28
  71. package/src/models/MSC3089Branch.ts +0 -3
  72. package/src/models/event.ts +0 -289
  73. package/src/models/poll.ts +0 -6
  74. package/src/models/relations-container.ts +1 -8
  75. package/src/models/relations.ts +0 -8
  76. package/src/models/room-state.ts +2 -8
  77. package/src/models/room.ts +0 -62
  78. package/src/models/thread.ts +0 -1
  79. package/src/sliding-sync-sdk.ts +2 -72
  80. package/src/sync.ts +1 -98
  81. package/src/testing.ts +0 -108
  82. package/src/types.ts +0 -1
  83. package/CHANGELOG.md +0 -5910
  84. package/lib/@types/AESEncryptedSecretStoragePayload.d.ts +0 -14
  85. package/lib/@types/AESEncryptedSecretStoragePayload.d.ts.map +0 -1
  86. package/lib/@types/AESEncryptedSecretStoragePayload.js +0 -1
  87. package/lib/@types/AESEncryptedSecretStoragePayload.js.map +0 -1
  88. package/lib/@types/crypto.d.ts +0 -47
  89. package/lib/@types/crypto.d.ts.map +0 -1
  90. package/lib/@types/crypto.js +0 -1
  91. package/lib/@types/crypto.js.map +0 -1
  92. package/lib/@types/matrix-sdk-crypto-wasm.d.js +0 -1
  93. package/lib/@types/matrix-sdk-crypto-wasm.d.js.map +0 -1
  94. package/lib/common-crypto/CryptoBackend.d.ts +0 -240
  95. package/lib/common-crypto/CryptoBackend.d.ts.map +0 -1
  96. package/lib/common-crypto/CryptoBackend.js +0 -73
  97. package/lib/common-crypto/CryptoBackend.js.map +0 -1
  98. package/lib/common-crypto/key-passphrase.d.ts +0 -14
  99. package/lib/common-crypto/key-passphrase.d.ts.map +0 -1
  100. package/lib/common-crypto/key-passphrase.js +0 -33
  101. package/lib/common-crypto/key-passphrase.js.map +0 -1
  102. package/lib/crypto/CrossSigning.d.ts +0 -184
  103. package/lib/crypto/CrossSigning.d.ts.map +0 -1
  104. package/lib/crypto/CrossSigning.js +0 -718
  105. package/lib/crypto/CrossSigning.js.map +0 -1
  106. package/lib/crypto/DeviceList.d.ts +0 -216
  107. package/lib/crypto/DeviceList.d.ts.map +0 -1
  108. package/lib/crypto/DeviceList.js +0 -892
  109. package/lib/crypto/DeviceList.js.map +0 -1
  110. package/lib/crypto/EncryptionSetup.d.ts +0 -152
  111. package/lib/crypto/EncryptionSetup.d.ts.map +0 -1
  112. package/lib/crypto/EncryptionSetup.js +0 -356
  113. package/lib/crypto/EncryptionSetup.js.map +0 -1
  114. package/lib/crypto/OlmDevice.d.ts +0 -457
  115. package/lib/crypto/OlmDevice.d.ts.map +0 -1
  116. package/lib/crypto/OlmDevice.js +0 -1241
  117. package/lib/crypto/OlmDevice.js.map +0 -1
  118. package/lib/crypto/OutgoingRoomKeyRequestManager.d.ts +0 -109
  119. package/lib/crypto/OutgoingRoomKeyRequestManager.d.ts.map +0 -1
  120. package/lib/crypto/OutgoingRoomKeyRequestManager.js +0 -415
  121. package/lib/crypto/OutgoingRoomKeyRequestManager.js.map +0 -1
  122. package/lib/crypto/RoomList.d.ts +0 -26
  123. package/lib/crypto/RoomList.d.ts.map +0 -1
  124. package/lib/crypto/RoomList.js +0 -71
  125. package/lib/crypto/RoomList.js.map +0 -1
  126. package/lib/crypto/SecretSharing.d.ts +0 -24
  127. package/lib/crypto/SecretSharing.d.ts.map +0 -1
  128. package/lib/crypto/SecretSharing.js +0 -194
  129. package/lib/crypto/SecretSharing.js.map +0 -1
  130. package/lib/crypto/SecretStorage.d.ts +0 -55
  131. package/lib/crypto/SecretStorage.d.ts.map +0 -1
  132. package/lib/crypto/SecretStorage.js +0 -118
  133. package/lib/crypto/SecretStorage.js.map +0 -1
  134. package/lib/crypto/aes.d.ts +0 -6
  135. package/lib/crypto/aes.d.ts.map +0 -1
  136. package/lib/crypto/aes.js +0 -24
  137. package/lib/crypto/aes.js.map +0 -1
  138. package/lib/crypto/algorithms/base.d.ts +0 -156
  139. package/lib/crypto/algorithms/base.d.ts.map +0 -1
  140. package/lib/crypto/algorithms/base.js +0 -187
  141. package/lib/crypto/algorithms/base.js.map +0 -1
  142. package/lib/crypto/algorithms/index.d.ts +0 -4
  143. package/lib/crypto/algorithms/index.d.ts.map +0 -1
  144. package/lib/crypto/algorithms/index.js +0 -20
  145. package/lib/crypto/algorithms/index.js.map +0 -1
  146. package/lib/crypto/algorithms/megolm.d.ts +0 -385
  147. package/lib/crypto/algorithms/megolm.d.ts.map +0 -1
  148. package/lib/crypto/algorithms/megolm.js +0 -1822
  149. package/lib/crypto/algorithms/megolm.js.map +0 -1
  150. package/lib/crypto/algorithms/olm.d.ts +0 -5
  151. package/lib/crypto/algorithms/olm.d.ts.map +0 -1
  152. package/lib/crypto/algorithms/olm.js +0 -299
  153. package/lib/crypto/algorithms/olm.js.map +0 -1
  154. package/lib/crypto/api.d.ts +0 -32
  155. package/lib/crypto/api.d.ts.map +0 -1
  156. package/lib/crypto/api.js +0 -22
  157. package/lib/crypto/api.js.map +0 -1
  158. package/lib/crypto/backup.d.ts +0 -227
  159. package/lib/crypto/backup.d.ts.map +0 -1
  160. package/lib/crypto/backup.js +0 -824
  161. package/lib/crypto/backup.js.map +0 -1
  162. package/lib/crypto/crypto.d.ts +0 -3
  163. package/lib/crypto/crypto.d.ts.map +0 -1
  164. package/lib/crypto/crypto.js +0 -19
  165. package/lib/crypto/crypto.js.map +0 -1
  166. package/lib/crypto/dehydration.d.ts +0 -34
  167. package/lib/crypto/dehydration.d.ts.map +0 -1
  168. package/lib/crypto/dehydration.js +0 -252
  169. package/lib/crypto/dehydration.js.map +0 -1
  170. package/lib/crypto/device-converter.d.ts +0 -9
  171. package/lib/crypto/device-converter.d.ts.map +0 -1
  172. package/lib/crypto/device-converter.js +0 -42
  173. package/lib/crypto/device-converter.js.map +0 -1
  174. package/lib/crypto/deviceinfo.d.ts +0 -99
  175. package/lib/crypto/deviceinfo.d.ts.map +0 -1
  176. package/lib/crypto/deviceinfo.js +0 -148
  177. package/lib/crypto/deviceinfo.js.map +0 -1
  178. package/lib/crypto/index.d.ts +0 -1209
  179. package/lib/crypto/index.d.ts.map +0 -1
  180. package/lib/crypto/index.js +0 -4097
  181. package/lib/crypto/index.js.map +0 -1
  182. package/lib/crypto/key_passphrase.d.ts +0 -14
  183. package/lib/crypto/key_passphrase.d.ts.map +0 -1
  184. package/lib/crypto/key_passphrase.js +0 -44
  185. package/lib/crypto/key_passphrase.js.map +0 -1
  186. package/lib/crypto/keybackup.d.ts +0 -18
  187. package/lib/crypto/keybackup.d.ts.map +0 -1
  188. package/lib/crypto/keybackup.js +0 -1
  189. package/lib/crypto/keybackup.js.map +0 -1
  190. package/lib/crypto/olmlib.d.ts +0 -129
  191. package/lib/crypto/olmlib.d.ts.map +0 -1
  192. package/lib/crypto/olmlib.js +0 -492
  193. package/lib/crypto/olmlib.js.map +0 -1
  194. package/lib/crypto/recoverykey.d.ts +0 -2
  195. package/lib/crypto/recoverykey.d.ts.map +0 -1
  196. package/lib/crypto/recoverykey.js +0 -19
  197. package/lib/crypto/recoverykey.js.map +0 -1
  198. package/lib/crypto/store/base.d.ts +0 -252
  199. package/lib/crypto/store/base.d.ts.map +0 -1
  200. package/lib/crypto/store/base.js +0 -64
  201. package/lib/crypto/store/base.js.map +0 -1
  202. package/lib/crypto/store/indexeddb-crypto-store-backend.d.ts +0 -187
  203. package/lib/crypto/store/indexeddb-crypto-store-backend.d.ts.map +0 -1
  204. package/lib/crypto/store/indexeddb-crypto-store-backend.js +0 -1145
  205. package/lib/crypto/store/indexeddb-crypto-store-backend.js.map +0 -1
  206. package/lib/crypto/store/indexeddb-crypto-store.d.ts +0 -432
  207. package/lib/crypto/store/indexeddb-crypto-store.d.ts.map +0 -1
  208. package/lib/crypto/store/indexeddb-crypto-store.js +0 -728
  209. package/lib/crypto/store/indexeddb-crypto-store.js.map +0 -1
  210. package/lib/crypto/store/localStorage-crypto-store.d.ts +0 -119
  211. package/lib/crypto/store/localStorage-crypto-store.d.ts.map +0 -1
  212. package/lib/crypto/store/localStorage-crypto-store.js +0 -531
  213. package/lib/crypto/store/localStorage-crypto-store.js.map +0 -1
  214. package/lib/crypto/store/memory-crypto-store.d.ts +0 -215
  215. package/lib/crypto/store/memory-crypto-store.d.ts.map +0 -1
  216. package/lib/crypto/store/memory-crypto-store.js +0 -622
  217. package/lib/crypto/store/memory-crypto-store.js.map +0 -1
  218. package/lib/crypto/verification/Base.d.ts +0 -105
  219. package/lib/crypto/verification/Base.d.ts.map +0 -1
  220. package/lib/crypto/verification/Base.js +0 -372
  221. package/lib/crypto/verification/Base.js.map +0 -1
  222. package/lib/crypto/verification/Error.d.ts +0 -35
  223. package/lib/crypto/verification/Error.d.ts.map +0 -1
  224. package/lib/crypto/verification/Error.js +0 -86
  225. package/lib/crypto/verification/Error.js.map +0 -1
  226. package/lib/crypto/verification/IllegalMethod.d.ts +0 -15
  227. package/lib/crypto/verification/IllegalMethod.d.ts.map +0 -1
  228. package/lib/crypto/verification/IllegalMethod.js +0 -43
  229. package/lib/crypto/verification/IllegalMethod.js.map +0 -1
  230. package/lib/crypto/verification/QRCode.d.ts +0 -51
  231. package/lib/crypto/verification/QRCode.d.ts.map +0 -1
  232. package/lib/crypto/verification/QRCode.js +0 -277
  233. package/lib/crypto/verification/QRCode.js.map +0 -1
  234. package/lib/crypto/verification/SAS.d.ts +0 -27
  235. package/lib/crypto/verification/SAS.d.ts.map +0 -1
  236. package/lib/crypto/verification/SAS.js +0 -485
  237. package/lib/crypto/verification/SAS.js.map +0 -1
  238. package/lib/crypto/verification/SASDecimal.d.ts +0 -8
  239. package/lib/crypto/verification/SASDecimal.d.ts.map +0 -1
  240. package/lib/crypto/verification/SASDecimal.js +0 -34
  241. package/lib/crypto/verification/SASDecimal.js.map +0 -1
  242. package/lib/crypto/verification/request/Channel.d.ts +0 -18
  243. package/lib/crypto/verification/request/Channel.d.ts.map +0 -1
  244. package/lib/crypto/verification/request/Channel.js +0 -1
  245. package/lib/crypto/verification/request/Channel.js.map +0 -1
  246. package/lib/crypto/verification/request/InRoomChannel.d.ts +0 -113
  247. package/lib/crypto/verification/request/InRoomChannel.d.ts.map +0 -1
  248. package/lib/crypto/verification/request/InRoomChannel.js +0 -351
  249. package/lib/crypto/verification/request/InRoomChannel.js.map +0 -1
  250. package/lib/crypto/verification/request/ToDeviceChannel.d.ts +0 -105
  251. package/lib/crypto/verification/request/ToDeviceChannel.d.ts.map +0 -1
  252. package/lib/crypto/verification/request/ToDeviceChannel.js +0 -328
  253. package/lib/crypto/verification/request/ToDeviceChannel.js.map +0 -1
  254. package/lib/crypto/verification/request/VerificationRequest.d.ts +0 -227
  255. package/lib/crypto/verification/request/VerificationRequest.d.ts.map +0 -1
  256. package/lib/crypto/verification/request/VerificationRequest.js +0 -937
  257. package/lib/crypto/verification/request/VerificationRequest.js.map +0 -1
  258. package/lib/crypto-api/CryptoEvent.d.ts +0 -69
  259. package/lib/crypto-api/CryptoEvent.d.ts.map +0 -1
  260. package/lib/crypto-api/CryptoEvent.js +0 -33
  261. package/lib/crypto-api/CryptoEvent.js.map +0 -1
  262. package/lib/crypto-api/CryptoEventHandlerMap.d.ts +0 -16
  263. package/lib/crypto-api/CryptoEventHandlerMap.d.ts.map +0 -1
  264. package/lib/crypto-api/CryptoEventHandlerMap.js +0 -22
  265. package/lib/crypto-api/CryptoEventHandlerMap.js.map +0 -1
  266. package/lib/crypto-api/index.d.ts +0 -978
  267. package/lib/crypto-api/index.d.ts.map +0 -1
  268. package/lib/crypto-api/index.js +0 -304
  269. package/lib/crypto-api/index.js.map +0 -1
  270. package/lib/crypto-api/key-passphrase.d.ts +0 -11
  271. package/lib/crypto-api/key-passphrase.d.ts.map +0 -1
  272. package/lib/crypto-api/key-passphrase.js +0 -51
  273. package/lib/crypto-api/key-passphrase.js.map +0 -1
  274. package/lib/crypto-api/keybackup.d.ts +0 -88
  275. package/lib/crypto-api/keybackup.d.ts.map +0 -1
  276. package/lib/crypto-api/keybackup.js +0 -1
  277. package/lib/crypto-api/keybackup.js.map +0 -1
  278. package/lib/crypto-api/recovery-key.d.ts +0 -11
  279. package/lib/crypto-api/recovery-key.d.ts.map +0 -1
  280. package/lib/crypto-api/recovery-key.js +0 -65
  281. package/lib/crypto-api/recovery-key.js.map +0 -1
  282. package/lib/crypto-api/verification.d.ts +0 -344
  283. package/lib/crypto-api/verification.d.ts.map +0 -1
  284. package/lib/crypto-api/verification.js +0 -91
  285. package/lib/crypto-api/verification.js.map +0 -1
  286. package/lib/rendezvous/MSC4108SignInWithQR.d.ts +0 -112
  287. package/lib/rendezvous/MSC4108SignInWithQR.d.ts.map +0 -1
  288. package/lib/rendezvous/MSC4108SignInWithQR.js +0 -392
  289. package/lib/rendezvous/MSC4108SignInWithQR.js.map +0 -1
  290. package/lib/rendezvous/RendezvousChannel.d.ts +0 -27
  291. package/lib/rendezvous/RendezvousChannel.d.ts.map +0 -1
  292. package/lib/rendezvous/RendezvousChannel.js +0 -1
  293. package/lib/rendezvous/RendezvousChannel.js.map +0 -1
  294. package/lib/rendezvous/RendezvousCode.d.ts +0 -9
  295. package/lib/rendezvous/RendezvousCode.d.ts.map +0 -1
  296. package/lib/rendezvous/RendezvousCode.js +0 -1
  297. package/lib/rendezvous/RendezvousCode.js.map +0 -1
  298. package/lib/rendezvous/RendezvousError.d.ts +0 -6
  299. package/lib/rendezvous/RendezvousError.d.ts.map +0 -1
  300. package/lib/rendezvous/RendezvousError.js +0 -23
  301. package/lib/rendezvous/RendezvousError.js.map +0 -1
  302. package/lib/rendezvous/RendezvousFailureReason.d.ts +0 -31
  303. package/lib/rendezvous/RendezvousFailureReason.d.ts.map +0 -1
  304. package/lib/rendezvous/RendezvousFailureReason.js +0 -38
  305. package/lib/rendezvous/RendezvousFailureReason.js.map +0 -1
  306. package/lib/rendezvous/RendezvousIntent.d.ts +0 -5
  307. package/lib/rendezvous/RendezvousIntent.d.ts.map +0 -1
  308. package/lib/rendezvous/RendezvousIntent.js +0 -22
  309. package/lib/rendezvous/RendezvousIntent.js.map +0 -1
  310. package/lib/rendezvous/RendezvousTransport.d.ts +0 -36
  311. package/lib/rendezvous/RendezvousTransport.d.ts.map +0 -1
  312. package/lib/rendezvous/RendezvousTransport.js +0 -1
  313. package/lib/rendezvous/RendezvousTransport.js.map +0 -1
  314. package/lib/rendezvous/channels/MSC4108SecureChannel.d.ts +0 -58
  315. package/lib/rendezvous/channels/MSC4108SecureChannel.d.ts.map +0 -1
  316. package/lib/rendezvous/channels/MSC4108SecureChannel.js +0 -246
  317. package/lib/rendezvous/channels/MSC4108SecureChannel.js.map +0 -1
  318. package/lib/rendezvous/channels/index.d.ts +0 -2
  319. package/lib/rendezvous/channels/index.d.ts.map +0 -1
  320. package/lib/rendezvous/channels/index.js +0 -18
  321. package/lib/rendezvous/channels/index.js.map +0 -1
  322. package/lib/rendezvous/index.d.ts +0 -10
  323. package/lib/rendezvous/index.d.ts.map +0 -1
  324. package/lib/rendezvous/index.js +0 -23
  325. package/lib/rendezvous/index.js.map +0 -1
  326. package/lib/rendezvous/transports/MSC4108RendezvousSession.d.ts +0 -61
  327. package/lib/rendezvous/transports/MSC4108RendezvousSession.d.ts.map +0 -1
  328. package/lib/rendezvous/transports/MSC4108RendezvousSession.js +0 -253
  329. package/lib/rendezvous/transports/MSC4108RendezvousSession.js.map +0 -1
  330. package/lib/rendezvous/transports/index.d.ts +0 -2
  331. package/lib/rendezvous/transports/index.d.ts.map +0 -1
  332. package/lib/rendezvous/transports/index.js +0 -18
  333. package/lib/rendezvous/transports/index.js.map +0 -1
  334. package/lib/rust-crypto/CrossSigningIdentity.d.ts +0 -33
  335. package/lib/rust-crypto/CrossSigningIdentity.d.ts.map +0 -1
  336. package/lib/rust-crypto/CrossSigningIdentity.js +0 -157
  337. package/lib/rust-crypto/CrossSigningIdentity.js.map +0 -1
  338. package/lib/rust-crypto/DehydratedDeviceManager.d.ts +0 -98
  339. package/lib/rust-crypto/DehydratedDeviceManager.d.ts.map +0 -1
  340. package/lib/rust-crypto/DehydratedDeviceManager.js +0 -285
  341. package/lib/rust-crypto/DehydratedDeviceManager.js.map +0 -1
  342. package/lib/rust-crypto/KeyClaimManager.d.ts +0 -33
  343. package/lib/rust-crypto/KeyClaimManager.d.ts.map +0 -1
  344. package/lib/rust-crypto/KeyClaimManager.js +0 -82
  345. package/lib/rust-crypto/KeyClaimManager.js.map +0 -1
  346. package/lib/rust-crypto/OutgoingRequestProcessor.d.ts +0 -43
  347. package/lib/rust-crypto/OutgoingRequestProcessor.d.ts.map +0 -1
  348. package/lib/rust-crypto/OutgoingRequestProcessor.js +0 -195
  349. package/lib/rust-crypto/OutgoingRequestProcessor.js.map +0 -1
  350. package/lib/rust-crypto/OutgoingRequestsManager.d.ts +0 -47
  351. package/lib/rust-crypto/OutgoingRequestsManager.d.ts.map +0 -1
  352. package/lib/rust-crypto/OutgoingRequestsManager.js +0 -148
  353. package/lib/rust-crypto/OutgoingRequestsManager.js.map +0 -1
  354. package/lib/rust-crypto/PerSessionKeyBackupDownloader.d.ts +0 -120
  355. package/lib/rust-crypto/PerSessionKeyBackupDownloader.d.ts.map +0 -1
  356. package/lib/rust-crypto/PerSessionKeyBackupDownloader.js +0 -467
  357. package/lib/rust-crypto/PerSessionKeyBackupDownloader.js.map +0 -1
  358. package/lib/rust-crypto/RoomEncryptor.d.ts +0 -98
  359. package/lib/rust-crypto/RoomEncryptor.d.ts.map +0 -1
  360. package/lib/rust-crypto/RoomEncryptor.js +0 -299
  361. package/lib/rust-crypto/RoomEncryptor.js.map +0 -1
  362. package/lib/rust-crypto/backup.d.ts +0 -254
  363. package/lib/rust-crypto/backup.d.ts.map +0 -1
  364. package/lib/rust-crypto/backup.js +0 -837
  365. package/lib/rust-crypto/backup.js.map +0 -1
  366. package/lib/rust-crypto/constants.d.ts +0 -3
  367. package/lib/rust-crypto/constants.d.ts.map +0 -1
  368. package/lib/rust-crypto/constants.js +0 -19
  369. package/lib/rust-crypto/constants.js.map +0 -1
  370. package/lib/rust-crypto/device-converter.d.ts +0 -28
  371. package/lib/rust-crypto/device-converter.d.ts.map +0 -1
  372. package/lib/rust-crypto/device-converter.js +0 -123
  373. package/lib/rust-crypto/device-converter.js.map +0 -1
  374. package/lib/rust-crypto/index.d.ts +0 -61
  375. package/lib/rust-crypto/index.d.ts.map +0 -1
  376. package/lib/rust-crypto/index.js +0 -152
  377. package/lib/rust-crypto/index.js.map +0 -1
  378. package/lib/rust-crypto/libolm_migration.d.ts +0 -81
  379. package/lib/rust-crypto/libolm_migration.d.ts.map +0 -1
  380. package/lib/rust-crypto/libolm_migration.js +0 -459
  381. package/lib/rust-crypto/libolm_migration.js.map +0 -1
  382. package/lib/rust-crypto/rust-crypto.d.ts +0 -556
  383. package/lib/rust-crypto/rust-crypto.d.ts.map +0 -1
  384. package/lib/rust-crypto/rust-crypto.js +0 -2016
  385. package/lib/rust-crypto/rust-crypto.js.map +0 -1
  386. package/lib/rust-crypto/secret-storage.d.ts +0 -22
  387. package/lib/rust-crypto/secret-storage.d.ts.map +0 -1
  388. package/lib/rust-crypto/secret-storage.js +0 -63
  389. package/lib/rust-crypto/secret-storage.js.map +0 -1
  390. package/lib/rust-crypto/verification.d.ts +0 -319
  391. package/lib/rust-crypto/verification.d.ts.map +0 -1
  392. package/lib/rust-crypto/verification.js +0 -816
  393. package/lib/rust-crypto/verification.js.map +0 -1
  394. package/lib/secret-storage.d.ts +0 -370
  395. package/lib/secret-storage.d.ts.map +0 -1
  396. package/lib/secret-storage.js +0 -466
  397. package/lib/secret-storage.js.map +0 -1
  398. package/lib/utils/decryptAESSecretStorageItem.d.ts +0 -12
  399. package/lib/utils/decryptAESSecretStorageItem.d.ts.map +0 -1
  400. package/lib/utils/decryptAESSecretStorageItem.js +0 -50
  401. package/lib/utils/decryptAESSecretStorageItem.js.map +0 -1
  402. package/lib/utils/encryptAESSecretStorageItem.d.ts +0 -16
  403. package/lib/utils/encryptAESSecretStorageItem.d.ts.map +0 -1
  404. package/lib/utils/encryptAESSecretStorageItem.js +0 -68
  405. package/lib/utils/encryptAESSecretStorageItem.js.map +0 -1
  406. package/lib/utils/internal/deriveKeys.d.ts +0 -10
  407. package/lib/utils/internal/deriveKeys.d.ts.map +0 -1
  408. package/lib/utils/internal/deriveKeys.js +0 -60
  409. package/lib/utils/internal/deriveKeys.js.map +0 -1
  410. package/src/@types/AESEncryptedSecretStoragePayload.ts +0 -29
  411. package/src/@types/crypto.ts +0 -73
  412. package/src/@types/matrix-sdk-crypto-wasm.d.ts +0 -44
  413. package/src/common-crypto/CryptoBackend.ts +0 -302
  414. package/src/common-crypto/README.md +0 -4
  415. package/src/common-crypto/key-passphrase.ts +0 -43
  416. package/src/crypto/CrossSigning.ts +0 -773
  417. package/src/crypto/DeviceList.ts +0 -989
  418. package/src/crypto/EncryptionSetup.ts +0 -351
  419. package/src/crypto/OlmDevice.ts +0 -1500
  420. package/src/crypto/OutgoingRoomKeyRequestManager.ts +0 -485
  421. package/src/crypto/RoomList.ts +0 -70
  422. package/src/crypto/SecretSharing.ts +0 -240
  423. package/src/crypto/SecretStorage.ts +0 -136
  424. package/src/crypto/aes.ts +0 -23
  425. package/src/crypto/algorithms/base.ts +0 -236
  426. package/src/crypto/algorithms/index.ts +0 -20
  427. package/src/crypto/algorithms/megolm.ts +0 -2216
  428. package/src/crypto/algorithms/olm.ts +0 -381
  429. package/src/crypto/api.ts +0 -70
  430. package/src/crypto/backup.ts +0 -922
  431. package/src/crypto/crypto.ts +0 -18
  432. package/src/crypto/dehydration.ts +0 -272
  433. package/src/crypto/device-converter.ts +0 -45
  434. package/src/crypto/deviceinfo.ts +0 -158
  435. package/src/crypto/index.ts +0 -4414
  436. package/src/crypto/key_passphrase.ts +0 -42
  437. package/src/crypto/keybackup.ts +0 -47
  438. package/src/crypto/olmlib.ts +0 -539
  439. package/src/crypto/recoverykey.ts +0 -18
  440. package/src/crypto/store/base.ts +0 -348
  441. package/src/crypto/store/indexeddb-crypto-store-backend.ts +0 -1250
  442. package/src/crypto/store/indexeddb-crypto-store.ts +0 -845
  443. package/src/crypto/store/localStorage-crypto-store.ts +0 -579
  444. package/src/crypto/store/memory-crypto-store.ts +0 -680
  445. package/src/crypto/verification/Base.ts +0 -409
  446. package/src/crypto/verification/Error.ts +0 -76
  447. package/src/crypto/verification/IllegalMethod.ts +0 -50
  448. package/src/crypto/verification/QRCode.ts +0 -310
  449. package/src/crypto/verification/SAS.ts +0 -494
  450. package/src/crypto/verification/SASDecimal.ts +0 -37
  451. package/src/crypto/verification/request/Channel.ts +0 -34
  452. package/src/crypto/verification/request/InRoomChannel.ts +0 -371
  453. package/src/crypto/verification/request/ToDeviceChannel.ts +0 -354
  454. package/src/crypto/verification/request/VerificationRequest.ts +0 -976
  455. package/src/crypto-api/CryptoEvent.ts +0 -93
  456. package/src/crypto-api/CryptoEventHandlerMap.ts +0 -32
  457. package/src/crypto-api/index.ts +0 -1175
  458. package/src/crypto-api/key-passphrase.ts +0 -58
  459. package/src/crypto-api/keybackup.ts +0 -115
  460. package/src/crypto-api/recovery-key.ts +0 -69
  461. package/src/crypto-api/verification.ts +0 -408
  462. package/src/rendezvous/MSC4108SignInWithQR.ts +0 -444
  463. package/src/rendezvous/RendezvousChannel.ts +0 -48
  464. package/src/rendezvous/RendezvousCode.ts +0 -25
  465. package/src/rendezvous/RendezvousError.ts +0 -26
  466. package/src/rendezvous/RendezvousFailureReason.ts +0 -49
  467. package/src/rendezvous/RendezvousIntent.ts +0 -20
  468. package/src/rendezvous/RendezvousTransport.ts +0 -58
  469. package/src/rendezvous/channels/MSC4108SecureChannel.ts +0 -270
  470. package/src/rendezvous/channels/index.ts +0 -17
  471. package/src/rendezvous/index.ts +0 -25
  472. package/src/rendezvous/transports/MSC4108RendezvousSession.ts +0 -270
  473. package/src/rendezvous/transports/index.ts +0 -17
  474. package/src/rust-crypto/CrossSigningIdentity.ts +0 -183
  475. package/src/rust-crypto/DehydratedDeviceManager.ts +0 -306
  476. package/src/rust-crypto/KeyClaimManager.ts +0 -86
  477. package/src/rust-crypto/OutgoingRequestProcessor.ts +0 -236
  478. package/src/rust-crypto/OutgoingRequestsManager.ts +0 -143
  479. package/src/rust-crypto/PerSessionKeyBackupDownloader.ts +0 -501
  480. package/src/rust-crypto/RoomEncryptor.ts +0 -352
  481. package/src/rust-crypto/backup.ts +0 -881
  482. package/src/rust-crypto/constants.ts +0 -18
  483. package/src/rust-crypto/device-converter.ts +0 -128
  484. package/src/rust-crypto/index.ts +0 -237
  485. package/src/rust-crypto/libolm_migration.ts +0 -530
  486. package/src/rust-crypto/rust-crypto.ts +0 -2205
  487. package/src/rust-crypto/secret-storage.ts +0 -60
  488. package/src/rust-crypto/verification.ts +0 -830
  489. package/src/secret-storage.ts +0 -693
  490. package/src/utils/decryptAESSecretStorageItem.ts +0 -54
  491. package/src/utils/encryptAESSecretStorageItem.ts +0 -73
  492. package/src/utils/internal/deriveKeys.ts +0 -63
@@ -1,466 +0,0 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- /*
3
- Copyright 2021-2023 The Matrix.org Foundation C.I.C.
4
-
5
- Licensed under the Apache License, Version 2.0 (the "License");
6
- you may not use this file except in compliance with the License.
7
- You may obtain a copy of the License at
8
-
9
- http://www.apache.org/licenses/LICENSE-2.0
10
-
11
- Unless required by applicable law or agreed to in writing, software
12
- distributed under the License is distributed on an "AS IS" BASIS,
13
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- See the License for the specific language governing permissions and
15
- limitations under the License.
16
- */
17
-
18
- /**
19
- * Implementation of server-side secret storage
20
- *
21
- * @see https://spec.matrix.org/v1.6/client-server-api/#storage
22
- */
23
-
24
- import { ClientEvent } from "./client.js";
25
- import { randomString } from "./randomstring.js";
26
- import { logger } from "./logger.js";
27
- import encryptAESSecretStorageItem from "./utils/encryptAESSecretStorageItem.js";
28
- import decryptAESSecretStorageItem from "./utils/decryptAESSecretStorageItem.js";
29
- export var SECRET_STORAGE_ALGORITHM_V1_AES = "m.secret_storage.v1.aes-hmac-sha2";
30
-
31
- /**
32
- * Common base interface for Secret Storage Keys.
33
- *
34
- * The common properties for all encryption keys used in server-side secret storage.
35
- *
36
- * @see https://spec.matrix.org/v1.6/client-server-api/#key-storage
37
- */
38
-
39
- /**
40
- * Properties for a SSSS key using the `m.secret_storage.v1.aes-hmac-sha2` algorithm.
41
- *
42
- * Corresponds to `AesHmacSha2KeyDescription` in the specification.
43
- *
44
- * @see https://spec.matrix.org/v1.6/client-server-api/#msecret_storagev1aes-hmac-sha2
45
- */
46
-
47
- /**
48
- * Union type for secret storage keys.
49
- *
50
- * For now, this is only {@link SecretStorageKeyDescriptionAesV1}, but other interfaces may be added in future.
51
- */
52
-
53
- /**
54
- * Information on how to generate the key from a passphrase.
55
- *
56
- * @see https://spec.matrix.org/v1.6/client-server-api/#deriving-keys-from-passphrases
57
- */
58
-
59
- /**
60
- * Options for {@link ServerSideSecretStorageImpl#addKey}.
61
- */
62
-
63
- /**
64
- * Return type for {@link ServerSideSecretStorageImpl#getKey}.
65
- */
66
-
67
- /**
68
- * Return type for {@link ServerSideSecretStorageImpl#addKey}.
69
- */
70
-
71
- /** Interface for managing account data on the server.
72
- *
73
- * A subset of {@link MatrixClient}.
74
- */
75
-
76
- /**
77
- * Application callbacks for use with {@link SecretStorage.ServerSideSecretStorageImpl}
78
- */
79
-
80
- /**
81
- * Interface provided by SecretStorage implementations
82
- *
83
- * Normally this will just be an {@link ServerSideSecretStorageImpl}, but for backwards
84
- * compatibility some methods allow other implementations.
85
- */
86
-
87
- /**
88
- * Implementation of Server-side secret storage.
89
- *
90
- * Secret *sharing* is *not* implemented here: this class is strictly about the storage component of
91
- * SSSS.
92
- *
93
- * @see https://spec.matrix.org/v1.6/client-server-api/#storage
94
- */
95
- export class ServerSideSecretStorageImpl {
96
- /**
97
- * Construct a new `SecretStorage`.
98
- *
99
- * Normally, it is unnecessary to call this directly, since MatrixClient automatically constructs one.
100
- * However, it may be useful to construct a new `SecretStorage`, if custom `callbacks` are required, for example.
101
- *
102
- * @param accountDataAdapter - interface for fetching and setting account data on the server. Normally an instance
103
- * of {@link MatrixClient}.
104
- * @param callbacks - application level callbacks for retrieving secret keys
105
- */
106
- constructor(accountDataAdapter, callbacks) {
107
- this.accountDataAdapter = accountDataAdapter;
108
- this.callbacks = callbacks;
109
- }
110
-
111
- /**
112
- * Get the current default key ID for encrypting secrets.
113
- *
114
- * @returns The default key ID or null if no default key ID is set
115
- */
116
- getDefaultKeyId() {
117
- var _this = this;
118
- return _asyncToGenerator(function* () {
119
- var defaultKey = yield _this.accountDataAdapter.getAccountDataFromServer("m.secret_storage.default_key");
120
- if (!defaultKey) return null;
121
- return defaultKey.key;
122
- })();
123
- }
124
-
125
- /**
126
- * Set the default key ID for encrypting secrets.
127
- *
128
- * @param keyId - The new default key ID
129
- */
130
- setDefaultKeyId(keyId) {
131
- return new Promise((resolve, reject) => {
132
- var listener = ev => {
133
- if (ev.getType() === "m.secret_storage.default_key" && ev.getContent().key === keyId) {
134
- this.accountDataAdapter.removeListener(ClientEvent.AccountData, listener);
135
- resolve();
136
- }
137
- };
138
- this.accountDataAdapter.on(ClientEvent.AccountData, listener);
139
- this.accountDataAdapter.setAccountData("m.secret_storage.default_key", {
140
- key: keyId
141
- }).catch(e => {
142
- this.accountDataAdapter.removeListener(ClientEvent.AccountData, listener);
143
- reject(e);
144
- });
145
- });
146
- }
147
-
148
- /**
149
- * Add a key for encrypting secrets.
150
- *
151
- * @param algorithm - the algorithm used by the key.
152
- * @param opts - the options for the algorithm. The properties used
153
- * depend on the algorithm given.
154
- * @param keyId - the ID of the key. If not given, a random
155
- * ID will be generated.
156
- *
157
- * @returns An object with:
158
- * keyId: the ID of the key
159
- * keyInfo: details about the key (iv, mac, passphrase)
160
- */
161
- addKey(algorithm, opts, keyId) {
162
- var _this2 = this;
163
- return _asyncToGenerator(function* () {
164
- if (algorithm !== SECRET_STORAGE_ALGORITHM_V1_AES) {
165
- throw new Error("Unknown key algorithm ".concat(algorithm));
166
- }
167
- var keyInfo = {
168
- algorithm
169
- };
170
- if (opts.name) {
171
- keyInfo.name = opts.name;
172
- }
173
- if (opts.passphrase) {
174
- keyInfo.passphrase = opts.passphrase;
175
- }
176
- var {
177
- iv,
178
- mac
179
- } = yield calculateKeyCheck(opts.key);
180
- keyInfo.iv = iv;
181
- keyInfo.mac = mac;
182
-
183
- // Create a unique key id. XXX: this is racey.
184
- if (!keyId) {
185
- do {
186
- keyId = randomString(32);
187
- } while (yield _this2.accountDataAdapter.getAccountDataFromServer("m.secret_storage.key.".concat(keyId)));
188
- }
189
- yield _this2.accountDataAdapter.setAccountData("m.secret_storage.key.".concat(keyId), keyInfo);
190
- return {
191
- keyId,
192
- keyInfo
193
- };
194
- })();
195
- }
196
-
197
- /**
198
- * Get the key information for a given ID.
199
- *
200
- * @param keyId - The ID of the key to check
201
- * for. Defaults to the default key ID if not provided.
202
- * @returns If the key was found, the return value is an array of
203
- * the form [keyId, keyInfo]. Otherwise, null is returned.
204
- * XXX: why is this an array when addKey returns an object?
205
- */
206
- getKey(keyId) {
207
- var _this3 = this;
208
- return _asyncToGenerator(function* () {
209
- if (!keyId) {
210
- keyId = yield _this3.getDefaultKeyId();
211
- }
212
- if (!keyId) {
213
- return null;
214
- }
215
- var keyInfo = yield _this3.accountDataAdapter.getAccountDataFromServer("m.secret_storage.key." + keyId);
216
- return keyInfo ? [keyId, keyInfo] : null;
217
- })();
218
- }
219
-
220
- /**
221
- * Check whether we have a key with a given ID.
222
- *
223
- * @param keyId - The ID of the key to check
224
- * for. Defaults to the default key ID if not provided.
225
- * @returns Whether we have the key.
226
- */
227
- hasKey(keyId) {
228
- var _this4 = this;
229
- return _asyncToGenerator(function* () {
230
- var key = yield _this4.getKey(keyId);
231
- return Boolean(key);
232
- })();
233
- }
234
-
235
- /**
236
- * Check whether a key matches what we expect based on the key info
237
- *
238
- * @param key - the key to check
239
- * @param info - the key info
240
- *
241
- * @returns whether or not the key matches
242
- */
243
- checkKey(key, info) {
244
- return _asyncToGenerator(function* () {
245
- if (info.algorithm === SECRET_STORAGE_ALGORITHM_V1_AES) {
246
- if (info.mac) {
247
- var {
248
- mac
249
- } = yield calculateKeyCheck(key, info.iv);
250
- return trimTrailingEquals(info.mac) === trimTrailingEquals(mac);
251
- } else {
252
- // if we have no information, we have to assume the key is right
253
- return true;
254
- }
255
- } else {
256
- throw new Error("Unknown algorithm");
257
- }
258
- })();
259
- }
260
-
261
- /**
262
- * Store an encrypted secret on the server.
263
- *
264
- * Details of the encryption keys to be used must previously have been stored in account data
265
- * (for example, via {@link ServerSideSecretStorageImpl#addKey}. {@link SecretStorageCallbacks#getSecretStorageKey} will be called to obtain a secret storage
266
- * key to decrypt the secret.
267
- *
268
- * @param name - The name of the secret - i.e., the "event type" to be stored in the account data
269
- * @param secret - The secret contents.
270
- * @param keys - The IDs of the keys to use to encrypt the secret, or null/undefined to use the default key.
271
- */
272
- store(name, secret, keys) {
273
- var _this5 = this;
274
- return _asyncToGenerator(function* () {
275
- var encrypted = {};
276
- if (!keys) {
277
- var defaultKeyId = yield _this5.getDefaultKeyId();
278
- if (!defaultKeyId) {
279
- throw new Error("No keys specified and no default key present");
280
- }
281
- keys = [defaultKeyId];
282
- }
283
- if (keys.length === 0) {
284
- throw new Error("Zero keys given to encrypt with!");
285
- }
286
- for (var _keyId of keys) {
287
- // get key information from key storage
288
- var _keyInfo = yield _this5.accountDataAdapter.getAccountDataFromServer("m.secret_storage.key." + _keyId);
289
- if (!_keyInfo) {
290
- throw new Error("Unknown key: " + _keyId);
291
- }
292
-
293
- // encrypt secret, based on the algorithm
294
- if (_keyInfo.algorithm === SECRET_STORAGE_ALGORITHM_V1_AES) {
295
- var _keys = {
296
- [_keyId]: _keyInfo
297
- };
298
- var [, encryption] = yield _this5.getSecretStorageKey(_keys, name);
299
- encrypted[_keyId] = yield encryption.encrypt(secret);
300
- } else {
301
- logger.warn("unknown algorithm for secret storage key " + _keyId + ": " + _keyInfo.algorithm);
302
- // do nothing if we don't understand the encryption algorithm
303
- }
304
- }
305
-
306
- // save encrypted secret
307
- yield _this5.accountDataAdapter.setAccountData(name, {
308
- encrypted
309
- });
310
- })();
311
- }
312
-
313
- /**
314
- * Get a secret from storage, and decrypt it.
315
- *
316
- * {@link SecretStorageCallbacks#getSecretStorageKey} will be called to obtain a secret storage
317
- * key to decrypt the secret.
318
- *
319
- * @param name - the name of the secret - i.e., the "event type" stored in the account data
320
- *
321
- * @returns the decrypted contents of the secret, or "undefined" if `name` is not found in
322
- * the user's account data.
323
- */
324
- get(name) {
325
- var _this6 = this;
326
- return _asyncToGenerator(function* () {
327
- var secretInfo = yield _this6.accountDataAdapter.getAccountDataFromServer(name);
328
- if (!secretInfo) {
329
- return;
330
- }
331
- if (!secretInfo.encrypted) {
332
- throw new Error("Content is not encrypted!");
333
- }
334
-
335
- // get possible keys to decrypt
336
- var keys = {};
337
- for (var _keyId2 of Object.keys(secretInfo.encrypted)) {
338
- // get key information from key storage
339
- var _keyInfo2 = yield _this6.accountDataAdapter.getAccountDataFromServer("m.secret_storage.key." + _keyId2);
340
- var _encInfo = secretInfo.encrypted[_keyId2];
341
- // only use keys we understand the encryption algorithm of
342
- if ((_keyInfo2 === null || _keyInfo2 === void 0 ? void 0 : _keyInfo2.algorithm) === SECRET_STORAGE_ALGORITHM_V1_AES) {
343
- if (_encInfo.iv && _encInfo.ciphertext && _encInfo.mac) {
344
- keys[_keyId2] = _keyInfo2;
345
- }
346
- }
347
- }
348
- if (Object.keys(keys).length === 0) {
349
- throw new Error("Could not decrypt ".concat(name, " because none of ") + "the keys it is encrypted with are for a supported algorithm");
350
- }
351
-
352
- // fetch private key from app
353
- var [keyId, decryption] = yield _this6.getSecretStorageKey(keys, name);
354
- var encInfo = secretInfo.encrypted[keyId];
355
- return decryption.decrypt(encInfo);
356
- })();
357
- }
358
-
359
- /**
360
- * Check if a secret is stored on the server.
361
- *
362
- * @param name - the name of the secret
363
- *
364
- * @returns map of key name to key info the secret is encrypted
365
- * with, or null if it is not present or not encrypted with a trusted
366
- * key
367
- */
368
- isStored(name) {
369
- var _this7 = this;
370
- return _asyncToGenerator(function* () {
371
- // check if secret exists
372
- var secretInfo = yield _this7.accountDataAdapter.getAccountDataFromServer(name);
373
- if (!(secretInfo !== null && secretInfo !== void 0 && secretInfo.encrypted)) return null;
374
- var ret = {};
375
-
376
- // filter secret encryption keys with supported algorithm
377
- for (var _keyId3 of Object.keys(secretInfo.encrypted)) {
378
- // get key information from key storage
379
- var _keyInfo3 = yield _this7.accountDataAdapter.getAccountDataFromServer("m.secret_storage.key." + _keyId3);
380
- if (!_keyInfo3) continue;
381
- var encInfo = secretInfo.encrypted[_keyId3];
382
-
383
- // only use keys we understand the encryption algorithm of
384
- if (_keyInfo3.algorithm === SECRET_STORAGE_ALGORITHM_V1_AES) {
385
- if (encInfo.iv && encInfo.ciphertext && encInfo.mac) {
386
- ret[_keyId3] = _keyInfo3;
387
- }
388
- }
389
- }
390
- return Object.keys(ret).length ? ret : null;
391
- })();
392
- }
393
- getSecretStorageKey(keys, name) {
394
- var _this8 = this;
395
- return _asyncToGenerator(function* () {
396
- if (!_this8.callbacks.getSecretStorageKey) {
397
- throw new Error("No getSecretStorageKey callback supplied");
398
- }
399
- var returned = yield _this8.callbacks.getSecretStorageKey({
400
- keys
401
- }, name);
402
- if (!returned) {
403
- throw new Error("getSecretStorageKey callback returned falsey");
404
- }
405
- if (returned.length < 2) {
406
- throw new Error("getSecretStorageKey callback returned invalid data");
407
- }
408
- var [keyId, privateKey] = returned;
409
- if (!keys[keyId]) {
410
- throw new Error("App returned unknown key from getSecretStorageKey!");
411
- }
412
- if (keys[keyId].algorithm === SECRET_STORAGE_ALGORITHM_V1_AES) {
413
- var decryption = {
414
- encrypt: function encrypt(secret) {
415
- return encryptAESSecretStorageItem(secret, privateKey, name);
416
- },
417
- decrypt: function decrypt(encInfo) {
418
- return decryptAESSecretStorageItem(encInfo, privateKey, name);
419
- }
420
- };
421
- return [keyId, decryption];
422
- } else {
423
- throw new Error("Unknown key type: " + keys[keyId].algorithm);
424
- }
425
- })();
426
- }
427
- }
428
-
429
- /** trim trailing instances of '=' from a string
430
- *
431
- * @internal
432
- *
433
- * @param input - input string
434
- */
435
- export function trimTrailingEquals(input) {
436
- // according to Sonar and CodeQL, a regex such as /=+$/ is superlinear.
437
- // Not sure I believe it, but it's easy enough to work around.
438
-
439
- // find the number of characters before the trailing =
440
- var i = input.length;
441
- while (i >= 1 && input.charCodeAt(i - 1) == 0x3d) i--;
442
-
443
- // trim to the calculated length
444
- if (i < input.length) {
445
- return input.substring(0, i);
446
- } else {
447
- return input;
448
- }
449
- }
450
-
451
- // string of zeroes, for calculating the key check
452
- var ZERO_STR = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
453
-
454
- /**
455
- * Calculate the MAC for checking the key.
456
- * See https://spec.matrix.org/v1.11/client-server-api/#msecret_storagev1aes-hmac-sha2, steps 3 and 4.
457
- *
458
- * @param key - the key to use
459
- * @param iv - The initialization vector as a base64-encoded string.
460
- * If omitted, a random initialization vector will be created.
461
- * @returns An object that contains, `mac` and `iv` properties.
462
- */
463
- export function calculateKeyCheck(key, iv) {
464
- return encryptAESSecretStorageItem(ZERO_STR, key, "", iv);
465
- }
466
- //# sourceMappingURL=secret-storage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"secret-storage.js","names":["ClientEvent","randomString","logger","encryptAESSecretStorageItem","decryptAESSecretStorageItem","SECRET_STORAGE_ALGORITHM_V1_AES","ServerSideSecretStorageImpl","constructor","accountDataAdapter","callbacks","getDefaultKeyId","_this","_asyncToGenerator","defaultKey","getAccountDataFromServer","key","setDefaultKeyId","keyId","Promise","resolve","reject","listener","ev","getType","getContent","removeListener","AccountData","on","setAccountData","catch","e","addKey","algorithm","opts","_this2","Error","concat","keyInfo","name","passphrase","iv","mac","calculateKeyCheck","getKey","_this3","hasKey","_this4","Boolean","checkKey","info","trimTrailingEquals","store","secret","keys","_this5","encrypted","defaultKeyId","length","encryption","getSecretStorageKey","encrypt","warn","get","_this6","secretInfo","Object","encInfo","ciphertext","decryption","decrypt","isStored","_this7","ret","_this8","returned","privateKey","input","i","charCodeAt","substring","ZERO_STR"],"sources":["../src/secret-storage.ts"],"sourcesContent":["/*\nCopyright 2021-2023 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\n/**\n * Implementation of server-side secret storage\n *\n * @see https://spec.matrix.org/v1.6/client-server-api/#storage\n */\n\nimport { TypedEventEmitter } from \"./models/typed-event-emitter.ts\";\nimport { ClientEvent, ClientEventHandlerMap } from \"./client.ts\";\nimport { MatrixEvent } from \"./models/event.ts\";\nimport { randomString } from \"./randomstring.ts\";\nimport { logger } from \"./logger.ts\";\nimport encryptAESSecretStorageItem from \"./utils/encryptAESSecretStorageItem.ts\";\nimport decryptAESSecretStorageItem from \"./utils/decryptAESSecretStorageItem.ts\";\nimport { AESEncryptedSecretStoragePayload } from \"./@types/AESEncryptedSecretStoragePayload.ts\";\n\nexport const SECRET_STORAGE_ALGORITHM_V1_AES = \"m.secret_storage.v1.aes-hmac-sha2\";\n\n/**\n * Common base interface for Secret Storage Keys.\n *\n * The common properties for all encryption keys used in server-side secret storage.\n *\n * @see https://spec.matrix.org/v1.6/client-server-api/#key-storage\n */\nexport interface SecretStorageKeyDescriptionCommon {\n /** A human-readable name for this key. */\n // XXX: according to the spec, this is optional\n name: string;\n\n /** The encryption algorithm used with this key. */\n algorithm: string;\n\n /** Information for deriving this key from a passphrase. */\n // XXX: according to the spec, this is optional\n passphrase: PassphraseInfo;\n}\n\n/**\n * Properties for a SSSS key using the `m.secret_storage.v1.aes-hmac-sha2` algorithm.\n *\n * Corresponds to `AesHmacSha2KeyDescription` in the specification.\n *\n * @see https://spec.matrix.org/v1.6/client-server-api/#msecret_storagev1aes-hmac-sha2\n */\nexport interface SecretStorageKeyDescriptionAesV1 extends SecretStorageKeyDescriptionCommon {\n // XXX: strictly speaking, we should be able to enforce the algorithm here. But\n // this interface ends up being incorrectly used where other algorithms are in use (notably\n // in device-dehydration support), and unpicking that is too much like hard work\n // at the moment.\n // algorithm: \"m.secret_storage.v1.aes-hmac-sha2\";\n\n /** The 16-byte AES initialization vector, encoded as base64. */\n iv: string;\n\n /** The MAC of the result of encrypting 32 bytes of 0, encoded as base64. */\n mac: string;\n}\n\n/**\n * Union type for secret storage keys.\n *\n * For now, this is only {@link SecretStorageKeyDescriptionAesV1}, but other interfaces may be added in future.\n */\nexport type SecretStorageKeyDescription = SecretStorageKeyDescriptionAesV1;\n\n/**\n * Information on how to generate the key from a passphrase.\n *\n * @see https://spec.matrix.org/v1.6/client-server-api/#deriving-keys-from-passphrases\n */\nexport interface PassphraseInfo {\n /** The algorithm to be used to derive the key. */\n algorithm: \"m.pbkdf2\";\n\n /** The number of PBKDF2 iterations to use. */\n iterations: number;\n\n /** The salt to be used for PBKDF2. */\n salt: string;\n\n /** The number of bits to generate. Defaults to 256. */\n bits?: number;\n}\n\n/**\n * Options for {@link ServerSideSecretStorageImpl#addKey}.\n */\nexport interface AddSecretStorageKeyOpts {\n /** Information for deriving the key from a passphrase if any. */\n passphrase?: PassphraseInfo;\n /** Optional name of the key. */\n name?: string;\n /** The private key. Will be used to generate the key check values in the key info; it will not be stored on the server */\n key: Uint8Array;\n}\n\n/**\n * Return type for {@link ServerSideSecretStorageImpl#getKey}.\n */\nexport type SecretStorageKeyTuple = [keyId: string, keyInfo: SecretStorageKeyDescription];\n\n/**\n * Return type for {@link ServerSideSecretStorageImpl#addKey}.\n */\nexport type SecretStorageKeyObject = {\n /** The ID of the key */\n keyId: string;\n /** details about the key */\n keyInfo: SecretStorageKeyDescription;\n};\n\n/** Interface for managing account data on the server.\n *\n * A subset of {@link MatrixClient}.\n */\nexport interface AccountDataClient extends TypedEventEmitter<ClientEvent.AccountData, ClientEventHandlerMap> {\n /**\n * Get account data event of given type for the current user. This variant\n * gets account data directly from the homeserver if the local store is not\n * ready, which can be useful very early in startup before the initial sync.\n *\n * @param eventType - The type of account data\n * @returns The contents of the given account data event, or `null` if the event is not found\n */\n getAccountDataFromServer: <T extends Record<string, any>>(eventType: string) => Promise<T | null>;\n\n /**\n * Set account data event for the current user, with retries\n *\n * @param eventType - The type of account data\n * @param content - the content object to be set\n * @returns an empty object\n */\n setAccountData: (eventType: string, content: any) => Promise<{}>;\n}\n\n/**\n * Application callbacks for use with {@link SecretStorage.ServerSideSecretStorageImpl}\n */\nexport interface SecretStorageCallbacks {\n /**\n * Called to retrieve a secret storage encryption key\n *\n * Before a secret can be stored in server-side storage, it must be encrypted with one or more\n * keys. Similarly, after it has been retrieved from storage, it must be decrypted with one of\n * the keys it was encrypted with. These encryption keys are known as \"secret storage keys\".\n *\n * Descriptions of the secret storage keys are also stored in server-side storage, per the\n * [matrix specification](https://spec.matrix.org/v1.6/client-server-api/#key-storage), so\n * before a key can be used in this way, it must have been stored on the server. This is\n * done via {@link ServerSideSecretStorage#addKey}.\n *\n * Obviously the keys themselves are not stored server-side, so the js-sdk calls this callback\n * in order to retrieve a secret storage key from the application.\n *\n * @param keys - An options object, containing only the property `keys`.\n *\n * @param name - the name of the *secret* (NB: not the encryption key) being stored or retrieved.\n * This is the \"event type\" stored in account data.\n *\n * @returns a pair [`keyId`, `privateKey`], where `keyId` is one of the keys from the `keys` parameter,\n * and `privateKey` is the raw private encryption key, as appropriate for the encryption algorithm.\n * (For `m.secret_storage.v1.aes-hmac-sha2`, it is the input to an HKDF as defined in the\n * [specification](https://spec.matrix.org/v1.6/client-server-api/#msecret_storagev1aes-hmac-sha2).)\n *\n * Alternatively, if none of the keys are known, may return `null` — in which case the original\n * storage/retrieval operation will fail with an exception.\n */\n getSecretStorageKey?: (\n keys: {\n /**\n * details of the secret storage keys required: a map from the key ID\n * (excluding the `m.secret_storage.key.` prefix) to details of the key.\n *\n * When storing a secret, `keys` will contain exactly one entry; this method will be called\n * once for each secret storage key to be used for encryption.\n *\n * For secret retrieval, `keys` may contain several entries, and the application can return\n * any one of the requested keys.\n */\n keys: Record<string, SecretStorageKeyDescription>;\n },\n name: string,\n ) => Promise<[string, Uint8Array] | null>;\n}\n\ninterface SecretInfo {\n encrypted: {\n [keyId: string]: AESEncryptedSecretStoragePayload;\n };\n}\n\ninterface Decryptors {\n encrypt: (plaintext: string) => Promise<AESEncryptedSecretStoragePayload>;\n decrypt: (ciphertext: AESEncryptedSecretStoragePayload) => Promise<string>;\n}\n\n/**\n * Interface provided by SecretStorage implementations\n *\n * Normally this will just be an {@link ServerSideSecretStorageImpl}, but for backwards\n * compatibility some methods allow other implementations.\n */\nexport interface ServerSideSecretStorage {\n /**\n * Add a key for encrypting secrets.\n *\n * @param algorithm - the algorithm used by the key.\n * @param opts - the options for the algorithm. The properties used\n * depend on the algorithm given.\n * @param keyId - the ID of the key. If not given, a random\n * ID will be generated.\n *\n * @returns details about the key.\n */\n addKey(algorithm: string, opts: AddSecretStorageKeyOpts, keyId?: string): Promise<SecretStorageKeyObject>;\n\n /**\n * Get the key information for a given ID.\n *\n * @param keyId - The ID of the key to check\n * for. Defaults to the default key ID if not provided.\n * @returns If the key was found, the return value is an array of\n * the form [keyId, keyInfo]. Otherwise, null is returned.\n * XXX: why is this an array when addKey returns an object?\n */\n getKey(keyId?: string | null): Promise<SecretStorageKeyTuple | null>;\n\n /**\n * Check whether we have a key with a given ID.\n *\n * @param keyId - The ID of the key to check\n * for. Defaults to the default key ID if not provided.\n * @returns Whether we have the key.\n */\n hasKey(keyId?: string): Promise<boolean>;\n\n /**\n * Check whether a key matches what we expect based on the key info\n *\n * @param key - the key to check\n * @param info - the key info\n *\n * @returns whether or not the key matches\n */\n checkKey(key: Uint8Array, info: SecretStorageKeyDescriptionAesV1): Promise<boolean>;\n\n /**\n * Store an encrypted secret on the server.\n *\n * Details of the encryption keys to be used must previously have been stored in account data\n * (for example, via {@link ServerSideSecretStorage#addKey}.\n *\n * @param name - The name of the secret - i.e., the \"event type\" to be stored in the account data\n * @param secret - The secret contents.\n * @param keys - The IDs of the keys to use to encrypt the secret, or null/undefined to use the default key\n * (will throw if no default key is set).\n */\n store(name: string, secret: string, keys?: string[] | null): Promise<void>;\n\n /**\n * Get a secret from storage, and decrypt it.\n *\n * @param name - the name of the secret - i.e., the \"event type\" stored in the account data\n *\n * @returns the decrypted contents of the secret, or \"undefined\" if `name` is not found in\n * the user's account data.\n */\n get(name: string): Promise<string | undefined>;\n\n /**\n * Check if a secret is stored on the server.\n *\n * @param name - the name of the secret\n *\n * @returns map of key name to key info the secret is encrypted\n * with, or null if it is not present or not encrypted with a trusted\n * key\n */\n isStored(name: string): Promise<Record<string, SecretStorageKeyDescriptionAesV1> | null>;\n\n /**\n * Get the current default key ID for encrypting secrets.\n *\n * @returns The default key ID or null if no default key ID is set\n */\n getDefaultKeyId(): Promise<string | null>;\n\n /**\n * Set the default key ID for encrypting secrets.\n *\n * @param keyId - The new default key ID\n */\n setDefaultKeyId(keyId: string): Promise<void>;\n}\n\n/**\n * Implementation of Server-side secret storage.\n *\n * Secret *sharing* is *not* implemented here: this class is strictly about the storage component of\n * SSSS.\n *\n * @see https://spec.matrix.org/v1.6/client-server-api/#storage\n */\nexport class ServerSideSecretStorageImpl implements ServerSideSecretStorage {\n /**\n * Construct a new `SecretStorage`.\n *\n * Normally, it is unnecessary to call this directly, since MatrixClient automatically constructs one.\n * However, it may be useful to construct a new `SecretStorage`, if custom `callbacks` are required, for example.\n *\n * @param accountDataAdapter - interface for fetching and setting account data on the server. Normally an instance\n * of {@link MatrixClient}.\n * @param callbacks - application level callbacks for retrieving secret keys\n */\n public constructor(\n private readonly accountDataAdapter: AccountDataClient,\n private readonly callbacks: SecretStorageCallbacks,\n ) {}\n\n /**\n * Get the current default key ID for encrypting secrets.\n *\n * @returns The default key ID or null if no default key ID is set\n */\n public async getDefaultKeyId(): Promise<string | null> {\n const defaultKey = await this.accountDataAdapter.getAccountDataFromServer<{ key: string }>(\n \"m.secret_storage.default_key\",\n );\n if (!defaultKey) return null;\n return defaultKey.key;\n }\n\n /**\n * Set the default key ID for encrypting secrets.\n *\n * @param keyId - The new default key ID\n */\n public setDefaultKeyId(keyId: string): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n const listener = (ev: MatrixEvent): void => {\n if (ev.getType() === \"m.secret_storage.default_key\" && ev.getContent().key === keyId) {\n this.accountDataAdapter.removeListener(ClientEvent.AccountData, listener);\n resolve();\n }\n };\n this.accountDataAdapter.on(ClientEvent.AccountData, listener);\n\n this.accountDataAdapter.setAccountData(\"m.secret_storage.default_key\", { key: keyId }).catch((e) => {\n this.accountDataAdapter.removeListener(ClientEvent.AccountData, listener);\n reject(e);\n });\n });\n }\n\n /**\n * Add a key for encrypting secrets.\n *\n * @param algorithm - the algorithm used by the key.\n * @param opts - the options for the algorithm. The properties used\n * depend on the algorithm given.\n * @param keyId - the ID of the key. If not given, a random\n * ID will be generated.\n *\n * @returns An object with:\n * keyId: the ID of the key\n * keyInfo: details about the key (iv, mac, passphrase)\n */\n public async addKey(\n algorithm: string,\n opts: AddSecretStorageKeyOpts,\n keyId?: string,\n ): Promise<SecretStorageKeyObject> {\n if (algorithm !== SECRET_STORAGE_ALGORITHM_V1_AES) {\n throw new Error(`Unknown key algorithm ${algorithm}`);\n }\n\n const keyInfo = { algorithm } as SecretStorageKeyDescriptionAesV1;\n\n if (opts.name) {\n keyInfo.name = opts.name;\n }\n\n if (opts.passphrase) {\n keyInfo.passphrase = opts.passphrase;\n }\n\n const { iv, mac } = await calculateKeyCheck(opts.key);\n keyInfo.iv = iv;\n keyInfo.mac = mac;\n\n // Create a unique key id. XXX: this is racey.\n if (!keyId) {\n do {\n keyId = randomString(32);\n } while (\n await this.accountDataAdapter.getAccountDataFromServer<SecretStorageKeyDescription>(\n `m.secret_storage.key.${keyId}`,\n )\n );\n }\n\n await this.accountDataAdapter.setAccountData(`m.secret_storage.key.${keyId}`, keyInfo);\n\n return {\n keyId,\n keyInfo,\n };\n }\n\n /**\n * Get the key information for a given ID.\n *\n * @param keyId - The ID of the key to check\n * for. Defaults to the default key ID if not provided.\n * @returns If the key was found, the return value is an array of\n * the form [keyId, keyInfo]. Otherwise, null is returned.\n * XXX: why is this an array when addKey returns an object?\n */\n public async getKey(keyId?: string | null): Promise<SecretStorageKeyTuple | null> {\n if (!keyId) {\n keyId = await this.getDefaultKeyId();\n }\n if (!keyId) {\n return null;\n }\n\n const keyInfo = await this.accountDataAdapter.getAccountDataFromServer<SecretStorageKeyDescriptionAesV1>(\n \"m.secret_storage.key.\" + keyId,\n );\n return keyInfo ? [keyId, keyInfo] : null;\n }\n\n /**\n * Check whether we have a key with a given ID.\n *\n * @param keyId - The ID of the key to check\n * for. Defaults to the default key ID if not provided.\n * @returns Whether we have the key.\n */\n public async hasKey(keyId?: string): Promise<boolean> {\n const key = await this.getKey(keyId);\n return Boolean(key);\n }\n\n /**\n * Check whether a key matches what we expect based on the key info\n *\n * @param key - the key to check\n * @param info - the key info\n *\n * @returns whether or not the key matches\n */\n public async checkKey(key: Uint8Array, info: SecretStorageKeyDescriptionAesV1): Promise<boolean> {\n if (info.algorithm === SECRET_STORAGE_ALGORITHM_V1_AES) {\n if (info.mac) {\n const { mac } = await calculateKeyCheck(key, info.iv);\n return trimTrailingEquals(info.mac) === trimTrailingEquals(mac);\n } else {\n // if we have no information, we have to assume the key is right\n return true;\n }\n } else {\n throw new Error(\"Unknown algorithm\");\n }\n }\n\n /**\n * Store an encrypted secret on the server.\n *\n * Details of the encryption keys to be used must previously have been stored in account data\n * (for example, via {@link ServerSideSecretStorageImpl#addKey}. {@link SecretStorageCallbacks#getSecretStorageKey} will be called to obtain a secret storage\n * key to decrypt the secret.\n *\n * @param name - The name of the secret - i.e., the \"event type\" to be stored in the account data\n * @param secret - The secret contents.\n * @param keys - The IDs of the keys to use to encrypt the secret, or null/undefined to use the default key.\n */\n public async store(name: string, secret: string, keys?: string[] | null): Promise<void> {\n const encrypted: Record<string, AESEncryptedSecretStoragePayload> = {};\n\n if (!keys) {\n const defaultKeyId = await this.getDefaultKeyId();\n if (!defaultKeyId) {\n throw new Error(\"No keys specified and no default key present\");\n }\n keys = [defaultKeyId];\n }\n\n if (keys.length === 0) {\n throw new Error(\"Zero keys given to encrypt with!\");\n }\n\n for (const keyId of keys) {\n // get key information from key storage\n const keyInfo = await this.accountDataAdapter.getAccountDataFromServer<SecretStorageKeyDescriptionAesV1>(\n \"m.secret_storage.key.\" + keyId,\n );\n if (!keyInfo) {\n throw new Error(\"Unknown key: \" + keyId);\n }\n\n // encrypt secret, based on the algorithm\n if (keyInfo.algorithm === SECRET_STORAGE_ALGORITHM_V1_AES) {\n const keys = { [keyId]: keyInfo };\n const [, encryption] = await this.getSecretStorageKey(keys, name);\n encrypted[keyId] = await encryption.encrypt(secret);\n } else {\n logger.warn(\"unknown algorithm for secret storage key \" + keyId + \": \" + keyInfo.algorithm);\n // do nothing if we don't understand the encryption algorithm\n }\n }\n\n // save encrypted secret\n await this.accountDataAdapter.setAccountData(name, { encrypted });\n }\n\n /**\n * Get a secret from storage, and decrypt it.\n *\n * {@link SecretStorageCallbacks#getSecretStorageKey} will be called to obtain a secret storage\n * key to decrypt the secret.\n *\n * @param name - the name of the secret - i.e., the \"event type\" stored in the account data\n *\n * @returns the decrypted contents of the secret, or \"undefined\" if `name` is not found in\n * the user's account data.\n */\n public async get(name: string): Promise<string | undefined> {\n const secretInfo = await this.accountDataAdapter.getAccountDataFromServer<SecretInfo>(name);\n if (!secretInfo) {\n return;\n }\n if (!secretInfo.encrypted) {\n throw new Error(\"Content is not encrypted!\");\n }\n\n // get possible keys to decrypt\n const keys: Record<string, SecretStorageKeyDescriptionAesV1> = {};\n for (const keyId of Object.keys(secretInfo.encrypted)) {\n // get key information from key storage\n const keyInfo = await this.accountDataAdapter.getAccountDataFromServer<SecretStorageKeyDescriptionAesV1>(\n \"m.secret_storage.key.\" + keyId,\n );\n const encInfo = secretInfo.encrypted[keyId];\n // only use keys we understand the encryption algorithm of\n if (keyInfo?.algorithm === SECRET_STORAGE_ALGORITHM_V1_AES) {\n if (encInfo.iv && encInfo.ciphertext && encInfo.mac) {\n keys[keyId] = keyInfo;\n }\n }\n }\n\n if (Object.keys(keys).length === 0) {\n throw new Error(\n `Could not decrypt ${name} because none of ` +\n `the keys it is encrypted with are for a supported algorithm`,\n );\n }\n\n // fetch private key from app\n const [keyId, decryption] = await this.getSecretStorageKey(keys, name);\n const encInfo = secretInfo.encrypted[keyId];\n\n return decryption.decrypt(encInfo);\n }\n\n /**\n * Check if a secret is stored on the server.\n *\n * @param name - the name of the secret\n *\n * @returns map of key name to key info the secret is encrypted\n * with, or null if it is not present or not encrypted with a trusted\n * key\n */\n public async isStored(name: string): Promise<Record<string, SecretStorageKeyDescriptionAesV1> | null> {\n // check if secret exists\n const secretInfo = await this.accountDataAdapter.getAccountDataFromServer<SecretInfo>(name);\n if (!secretInfo?.encrypted) return null;\n\n const ret: Record<string, SecretStorageKeyDescriptionAesV1> = {};\n\n // filter secret encryption keys with supported algorithm\n for (const keyId of Object.keys(secretInfo.encrypted)) {\n // get key information from key storage\n const keyInfo = await this.accountDataAdapter.getAccountDataFromServer<SecretStorageKeyDescriptionAesV1>(\n \"m.secret_storage.key.\" + keyId,\n );\n if (!keyInfo) continue;\n const encInfo = secretInfo.encrypted[keyId];\n\n // only use keys we understand the encryption algorithm of\n if (keyInfo.algorithm === SECRET_STORAGE_ALGORITHM_V1_AES) {\n if (encInfo.iv && encInfo.ciphertext && encInfo.mac) {\n ret[keyId] = keyInfo;\n }\n }\n }\n return Object.keys(ret).length ? ret : null;\n }\n\n private async getSecretStorageKey(\n keys: Record<string, SecretStorageKeyDescriptionAesV1>,\n name: string,\n ): Promise<[string, Decryptors]> {\n if (!this.callbacks.getSecretStorageKey) {\n throw new Error(\"No getSecretStorageKey callback supplied\");\n }\n\n const returned = await this.callbacks.getSecretStorageKey({ keys }, name);\n\n if (!returned) {\n throw new Error(\"getSecretStorageKey callback returned falsey\");\n }\n if (returned.length < 2) {\n throw new Error(\"getSecretStorageKey callback returned invalid data\");\n }\n\n const [keyId, privateKey] = returned;\n if (!keys[keyId]) {\n throw new Error(\"App returned unknown key from getSecretStorageKey!\");\n }\n\n if (keys[keyId].algorithm === SECRET_STORAGE_ALGORITHM_V1_AES) {\n const decryption = {\n encrypt: function (secret: string): Promise<AESEncryptedSecretStoragePayload> {\n return encryptAESSecretStorageItem(secret, privateKey, name);\n },\n decrypt: function (encInfo: AESEncryptedSecretStoragePayload): Promise<string> {\n return decryptAESSecretStorageItem(encInfo, privateKey, name);\n },\n };\n return [keyId, decryption];\n } else {\n throw new Error(\"Unknown key type: \" + keys[keyId].algorithm);\n }\n }\n}\n\n/** trim trailing instances of '=' from a string\n *\n * @internal\n *\n * @param input - input string\n */\nexport function trimTrailingEquals(input: string): string {\n // according to Sonar and CodeQL, a regex such as /=+$/ is superlinear.\n // Not sure I believe it, but it's easy enough to work around.\n\n // find the number of characters before the trailing =\n let i = input.length;\n while (i >= 1 && input.charCodeAt(i - 1) == 0x3d) i--;\n\n // trim to the calculated length\n if (i < input.length) {\n return input.substring(0, i);\n } else {\n return input;\n }\n}\n\n// string of zeroes, for calculating the key check\nconst ZERO_STR = \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\";\n\n/**\n * Calculate the MAC for checking the key.\n * See https://spec.matrix.org/v1.11/client-server-api/#msecret_storagev1aes-hmac-sha2, steps 3 and 4.\n *\n * @param key - the key to use\n * @param iv - The initialization vector as a base64-encoded string.\n * If omitted, a random initialization vector will be created.\n * @returns An object that contains, `mac` and `iv` properties.\n */\nexport function calculateKeyCheck(key: Uint8Array, iv?: string): Promise<AESEncryptedSecretStoragePayload> {\n return encryptAESSecretStorageItem(ZERO_STR, key, \"\", iv);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAGA,SAASA,WAAW,QAA+B,aAAa;AAEhE,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SAASC,MAAM,QAAQ,aAAa;AACpC,OAAOC,2BAA2B,MAAM,wCAAwC;AAChF,OAAOC,2BAA2B,MAAM,wCAAwC;AAGhF,OAAO,IAAMC,+BAA+B,GAAG,mCAAmC;;AAElF;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;;AAUA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;AACA;;AAsBA;AACA;AACA;;AA2DA;AACA;AACA;AACA;AACA;AACA;;AA8FA;AACA;AACA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AAC,GAAGD,KAAK,CAACnB,MAAM,EAAE;IAClB,OAAOmB,KAAK,CAACG,SAAS,CAAC,CAAC,EAAEF,CAAC,CAAC;EAChC,CAAC,MAAM;IACH,OAAOD,KAAK;EAChB;AACJ;;AAEA;AACA,IAAMI,QAAQ,GAAG,kEAAkE;;AAEnF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAStC,iBAAiBA,CAAC3B,GAAe,EAAEyB,EAAW,EAA6C;EACvG,OAAOrC,2BAA2B,CAAC6E,QAAQ,EAAEjE,GAAG,EAAE,EAAE,EAAEyB,EAAE,CAAC;AAC7D","ignoreList":[]}
@@ -1,12 +0,0 @@
1
- import { AESEncryptedSecretStoragePayload } from "../@types/AESEncryptedSecretStoragePayload.ts";
2
- /**
3
- * Decrypt an AES-encrypted Secret Storage item.
4
- *
5
- * @param data - the encrypted data, returned by {@link utils/encryptAESSecretStorageItem.default | encryptAESSecretStorageItem}.
6
- * @param key - the encryption key to use as an input to the HKDF function which is used to derive the AES key. Must
7
- * be the same as provided to {@link utils/encryptAESSecretStorageItem.default | encryptAESSecretStorageItem}.
8
- * @param name - the name of the secret. Also used as an input to the HKDF operation which is used to derive the AES
9
- * key, so again must be the same as provided to {@link utils/encryptAESSecretStorageItem.default | encryptAESSecretStorageItem}.
10
- */
11
- export default function decryptAESSecretStorageItem(data: AESEncryptedSecretStoragePayload, key: Uint8Array, name: string): Promise<string>;
12
- //# sourceMappingURL=decryptAESSecretStorageItem.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decryptAESSecretStorageItem.d.ts","sourceRoot":"","sources":["../../src/utils/decryptAESSecretStorageItem.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AAEjG;;;;;;;;GAQG;AACH,wBAA8B,2BAA2B,CACrD,IAAI,EAAE,gCAAgC,EACtC,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAoBjB"}
@@ -1,50 +0,0 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- /*
3
- * Copyright 2024 The Matrix.org Foundation C.I.C.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- import { decodeBase64 } from "../base64.js";
19
- import { deriveKeys } from "./internal/deriveKeys.js";
20
- /**
21
- * Decrypt an AES-encrypted Secret Storage item.
22
- *
23
- * @param data - the encrypted data, returned by {@link utils/encryptAESSecretStorageItem.default | encryptAESSecretStorageItem}.
24
- * @param key - the encryption key to use as an input to the HKDF function which is used to derive the AES key. Must
25
- * be the same as provided to {@link utils/encryptAESSecretStorageItem.default | encryptAESSecretStorageItem}.
26
- * @param name - the name of the secret. Also used as an input to the HKDF operation which is used to derive the AES
27
- * key, so again must be the same as provided to {@link utils/encryptAESSecretStorageItem.default | encryptAESSecretStorageItem}.
28
- */
29
- export default function decryptAESSecretStorageItem(_x, _x2, _x3) {
30
- return _decryptAESSecretStorageItem.apply(this, arguments);
31
- }
32
- function _decryptAESSecretStorageItem() {
33
- _decryptAESSecretStorageItem = _asyncToGenerator(function* (data, key, name) {
34
- var [aesKey, hmacKey] = yield deriveKeys(key, name);
35
- var ciphertext = decodeBase64(data.ciphertext);
36
- if (!(yield globalThis.crypto.subtle.verify({
37
- name: "HMAC"
38
- }, hmacKey, decodeBase64(data.mac), ciphertext))) {
39
- throw new Error("Error decrypting secret ".concat(name, ": bad MAC"));
40
- }
41
- var plaintext = yield globalThis.crypto.subtle.decrypt({
42
- name: "AES-CTR",
43
- counter: decodeBase64(data.iv),
44
- length: 64
45
- }, aesKey, ciphertext);
46
- return new TextDecoder().decode(new Uint8Array(plaintext));
47
- });
48
- return _decryptAESSecretStorageItem.apply(this, arguments);
49
- }
50
- //# sourceMappingURL=decryptAESSecretStorageItem.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decryptAESSecretStorageItem.js","names":["decodeBase64","deriveKeys","decryptAESSecretStorageItem","_x","_x2","_x3","_decryptAESSecretStorageItem","apply","arguments","_asyncToGenerator","data","key","name","aesKey","hmacKey","ciphertext","globalThis","crypto","subtle","verify","mac","Error","concat","plaintext","decrypt","counter","iv","length","TextDecoder","decode","Uint8Array"],"sources":["../../src/utils/decryptAESSecretStorageItem.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 { decodeBase64 } from \"../base64.ts\";\nimport { deriveKeys } from \"./internal/deriveKeys.ts\";\nimport { AESEncryptedSecretStoragePayload } from \"../@types/AESEncryptedSecretStoragePayload.ts\";\n\n/**\n * Decrypt an AES-encrypted Secret Storage item.\n *\n * @param data - the encrypted data, returned by {@link utils/encryptAESSecretStorageItem.default | encryptAESSecretStorageItem}.\n * @param key - the encryption key to use as an input to the HKDF function which is used to derive the AES key. Must\n * be the same as provided to {@link utils/encryptAESSecretStorageItem.default | encryptAESSecretStorageItem}.\n * @param name - the name of the secret. Also used as an input to the HKDF operation which is used to derive the AES\n * key, so again must be the same as provided to {@link utils/encryptAESSecretStorageItem.default | encryptAESSecretStorageItem}.\n */\nexport default async function decryptAESSecretStorageItem(\n data: AESEncryptedSecretStoragePayload,\n key: Uint8Array,\n name: string,\n): Promise<string> {\n const [aesKey, hmacKey] = await deriveKeys(key, name);\n\n const ciphertext = decodeBase64(data.ciphertext);\n\n if (!(await globalThis.crypto.subtle.verify({ name: \"HMAC\" }, hmacKey, decodeBase64(data.mac), ciphertext))) {\n throw new Error(`Error decrypting secret ${name}: bad MAC`);\n }\n\n const plaintext = await globalThis.crypto.subtle.decrypt(\n {\n name: \"AES-CTR\",\n counter: decodeBase64(data.iv),\n length: 64,\n },\n aesKey,\n ciphertext,\n );\n\n return new TextDecoder().decode(new Uint8Array(plaintext));\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,YAAY,QAAQ,cAAc;AAC3C,SAASC,UAAU,QAAQ,0BAA0B;AAGrD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,wBAA8BC,2BAA2BA,CAAAC,EAAA,EAAAC,GAAA,EAAAC,GAAA;EAAA,OAAAC,4BAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAwBxD,SAAAF,6BAAA;EAAAA,4BAAA,GAAAG,iBAAA,CAxBc,WACXC,IAAsC,EACtCC,GAAe,EACfC,IAAY,EACG;IACf,IAAM,CAACC,MAAM,EAAEC,OAAO,CAAC,SAASb,UAAU,CAACU,GAAG,EAAEC,IAAI,CAAC;IAErD,IAAMG,UAAU,GAAGf,YAAY,CAACU,IAAI,CAACK,UAAU,CAAC;IAEhD,IAAI,QAAQC,UAAU,CAACC,MAAM,CAACC,MAAM,CAACC,MAAM,CAAC;MAAEP,IAAI,EAAE;IAAO,CAAC,EAAEE,OAAO,EAAEd,YAAY,CAACU,IAAI,CAACU,GAAG,CAAC,EAAEL,UAAU,CAAC,CAAC,EAAE;MACzG,MAAM,IAAIM,KAAK,4BAAAC,MAAA,CAA4BV,IAAI,cAAW,CAAC;IAC/D;IAEA,IAAMW,SAAS,SAASP,UAAU,CAACC,MAAM,CAACC,MAAM,CAACM,OAAO,CACpD;MACIZ,IAAI,EAAE,SAAS;MACfa,OAAO,EAAEzB,YAAY,CAACU,IAAI,CAACgB,EAAE,CAAC;MAC9BC,MAAM,EAAE;IACZ,CAAC,EACDd,MAAM,EACNE,UACJ,CAAC;IAED,OAAO,IAAIa,WAAW,CAAC,CAAC,CAACC,MAAM,CAAC,IAAIC,UAAU,CAACP,SAAS,CAAC,CAAC;EAC9D,CAAC;EAAA,OAAAjB,4BAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA","ignoreList":[]}
@@ -1,16 +0,0 @@
1
- import { AESEncryptedSecretStoragePayload } from "../@types/AESEncryptedSecretStoragePayload.ts";
2
- /**
3
- * Encrypt a string as a secret storage item, using AES-CTR.
4
- *
5
- * @param data - the plaintext to encrypt
6
- * @param key - the encryption key to use as an input to the HKDF function which is used to derive the AES key for
7
- * encryption. Obviously, the same key must be provided when decrypting.
8
- * @param name - the name of the secret. Used as an input to the HKDF operation which is used to derive the AES key,
9
- * so again the same value must be provided when decrypting.
10
- * @param ivStr - the base64-encoded initialization vector to use. If not supplied, a random one will be generated.
11
- *
12
- * @returns The encrypted result, including the ciphertext itself, the initialization vector (as supplied in `ivStr`,
13
- * or generated), and an HMAC on the ciphertext — all base64-encoded.
14
- */
15
- export default function encryptAESSecretStorageItem(data: string, key: Uint8Array, name: string, ivStr?: string): Promise<AESEncryptedSecretStoragePayload>;
16
- //# sourceMappingURL=encryptAESSecretStorageItem.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryptAESSecretStorageItem.d.ts","sourceRoot":"","sources":["../../src/utils/encryptAESSecretStorageItem.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AAEjG;;;;;;;;;;;;GAYG;AACH,wBAA8B,2BAA2B,CACrD,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,gCAAgC,CAAC,CAkC3C"}