@textrp/briij-js-sdk 41.0.1 → 43.0.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 (380) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/LICENSE +177 -177
  3. package/README.md +85 -3
  4. package/lib/@types/AESEncryptedSecretStoragePayload.js.map +1 -1
  5. package/lib/@types/IIdentityServerProvider.js.map +1 -1
  6. package/lib/@types/PushRules.js +14 -14
  7. package/lib/@types/PushRules.js.map +1 -1
  8. package/lib/@types/another-json.d.js.map +1 -1
  9. package/lib/@types/auth.d.ts +72 -1
  10. package/lib/@types/auth.d.ts.map +1 -1
  11. package/lib/@types/auth.js +57 -54
  12. package/lib/@types/auth.js.map +1 -1
  13. package/lib/@types/beacon.js +100 -100
  14. package/lib/@types/beacon.js.map +1 -1
  15. package/lib/@types/common.js.map +1 -1
  16. package/lib/@types/crypto.js.map +1 -1
  17. package/lib/@types/event.d.ts +59 -0
  18. package/lib/@types/event.d.ts.map +1 -1
  19. package/lib/@types/event.js +105 -102
  20. package/lib/@types/event.js.map +1 -1
  21. package/lib/@types/events.js.map +1 -1
  22. package/lib/@types/extensible_events.js +53 -53
  23. package/lib/@types/extensible_events.js.map +1 -1
  24. package/lib/@types/local_notifications.js.map +1 -1
  25. package/lib/@types/location.js +41 -41
  26. package/lib/@types/location.js.map +1 -1
  27. package/lib/@types/matrix-sdk-crypto-wasm.d.js.map +1 -1
  28. package/lib/@types/media.js.map +1 -1
  29. package/lib/@types/membership.js +39 -39
  30. package/lib/@types/membership.js.map +1 -1
  31. package/lib/@types/partials.js +25 -25
  32. package/lib/@types/partials.js.map +1 -1
  33. package/lib/@types/polls.js +46 -46
  34. package/lib/@types/polls.js.map +1 -1
  35. package/lib/@types/read_receipts.js +14 -14
  36. package/lib/@types/read_receipts.js.map +1 -1
  37. package/lib/@types/registration.js.map +1 -1
  38. package/lib/@types/search.js +14 -14
  39. package/lib/@types/search.js.map +1 -1
  40. package/lib/@types/signed.js.map +1 -1
  41. package/lib/@types/spaces.js.map +1 -1
  42. package/lib/@types/state_events.js.map +1 -1
  43. package/lib/@types/synapse.js.map +1 -1
  44. package/lib/@types/sync.js +18 -18
  45. package/lib/@types/sync.js.map +1 -1
  46. package/lib/@types/threepids.js +14 -14
  47. package/lib/@types/threepids.js.map +1 -1
  48. package/lib/@types/topic.js +47 -47
  49. package/lib/@types/topic.js.map +1 -1
  50. package/lib/@types/uia.js.map +1 -1
  51. package/lib/NamespacedValue.js +20 -20
  52. package/lib/NamespacedValue.js.map +1 -1
  53. package/lib/ReEmitter.js +16 -16
  54. package/lib/ReEmitter.js.map +1 -1
  55. package/lib/base64.js +32 -32
  56. package/lib/base64.js.map +1 -1
  57. package/lib/briij.d.ts +4 -0
  58. package/lib/briij.d.ts.map +1 -1
  59. package/lib/briij.js +4 -0
  60. package/lib/briij.js.map +1 -1
  61. package/lib/client.d.ts +48 -1
  62. package/lib/client.d.ts.map +1 -1
  63. package/lib/client.js +262 -108
  64. package/lib/client.js.map +1 -1
  65. package/lib/common-crypto/key-passphrase.js +19 -19
  66. package/lib/common-crypto/key-passphrase.js.map +1 -1
  67. package/lib/content-helpers.js +57 -57
  68. package/lib/content-helpers.js.map +1 -1
  69. package/lib/content-repo.js +36 -36
  70. package/lib/content-repo.js.map +1 -1
  71. package/lib/crypto/store/base.js +69 -69
  72. package/lib/crypto/store/base.js.map +1 -1
  73. package/lib/crypto/store/indexeddb-crypto-store-backend.js +58 -58
  74. package/lib/crypto/store/indexeddb-crypto-store-backend.js.map +1 -1
  75. package/lib/crypto/store/indexeddb-crypto-store.js +193 -193
  76. package/lib/crypto/store/indexeddb-crypto-store.js.map +1 -1
  77. package/lib/crypto/store/localStorage-crypto-store.js +72 -72
  78. package/lib/crypto/store/localStorage-crypto-store.js.map +1 -1
  79. package/lib/crypto/store/memory-crypto-store.js +74 -74
  80. package/lib/crypto/store/memory-crypto-store.js.map +1 -1
  81. package/lib/crypto-api/CryptoEventHandlerMap.js.map +1 -1
  82. package/lib/crypto-api/key-passphrase.js +22 -22
  83. package/lib/crypto-api/key-passphrase.js.map +1 -1
  84. package/lib/crypto-api/keybackup.js.map +1 -1
  85. package/lib/crypto-api/recovery-key.js +20 -20
  86. package/lib/crypto-api/recovery-key.js.map +1 -1
  87. package/lib/digest.js +21 -21
  88. package/lib/digest.js.map +1 -1
  89. package/lib/extensible_events_v1/ExtensibleEvent.js +39 -39
  90. package/lib/extensible_events_v1/ExtensibleEvent.js.map +1 -1
  91. package/lib/extensible_events_v1/InvalidEventError.js +16 -16
  92. package/lib/extensible_events_v1/InvalidEventError.js.map +1 -1
  93. package/lib/extensible_events_v1/MessageEvent.js +39 -39
  94. package/lib/extensible_events_v1/MessageEvent.js.map +1 -1
  95. package/lib/extensible_events_v1/PollEndEvent.js +29 -29
  96. package/lib/extensible_events_v1/PollEndEvent.js.map +1 -1
  97. package/lib/extensible_events_v1/PollResponseEvent.js +39 -39
  98. package/lib/extensible_events_v1/PollResponseEvent.js.map +1 -1
  99. package/lib/extensible_events_v1/PollStartEvent.js +52 -52
  100. package/lib/extensible_events_v1/PollStartEvent.js.map +1 -1
  101. package/lib/extensible_events_v1/utilities.js +22 -22
  102. package/lib/extensible_events_v1/utilities.js.map +1 -1
  103. package/lib/feature.js +16 -16
  104. package/lib/feature.js.map +1 -1
  105. package/lib/http-api/method.js +14 -14
  106. package/lib/http-api/method.js.map +1 -1
  107. package/lib/http-api/prefix.js +26 -26
  108. package/lib/http-api/prefix.js.map +1 -1
  109. package/lib/indexeddb-helpers.js +21 -21
  110. package/lib/indexeddb-helpers.js.map +1 -1
  111. package/lib/indexeddb-worker.js +18 -18
  112. package/lib/indexeddb-worker.js.map +1 -1
  113. package/lib/matrixrtc/IKeyTransport.js +17 -17
  114. package/lib/matrixrtc/IKeyTransport.js.map +1 -1
  115. package/lib/matrixrtc/IMembershipManager.js +27 -27
  116. package/lib/matrixrtc/IMembershipManager.js.map +1 -1
  117. package/lib/matrixrtc/LivekitTransport.js +19 -19
  118. package/lib/matrixrtc/LivekitTransport.js.map +1 -1
  119. package/lib/matrixrtc/index.js +14 -14
  120. package/lib/matrixrtc/index.js.map +1 -1
  121. package/lib/matrixrtc/utils.js +27 -27
  122. package/lib/matrixrtc/utils.js.map +1 -1
  123. package/lib/models/ToDeviceMessage.js.map +1 -1
  124. package/lib/models/device.js +24 -24
  125. package/lib/models/device.js.map +1 -1
  126. package/lib/models/event-status.js +17 -17
  127. package/lib/models/event-status.js.map +1 -1
  128. package/lib/models/invites-ignorer-types.js +25 -25
  129. package/lib/models/invites-ignorer-types.js.map +1 -1
  130. package/lib/models/profile-keys.js +26 -26
  131. package/lib/models/profile-keys.js.map +1 -1
  132. package/lib/models/room-summary.js +26 -26
  133. package/lib/models/room-summary.js.map +1 -1
  134. package/lib/models/search-result.js +22 -22
  135. package/lib/models/search-result.js.map +1 -1
  136. package/lib/models/typed-event-emitter.js +122 -122
  137. package/lib/models/typed-event-emitter.js.map +1 -1
  138. package/lib/oidc/authorize.js +76 -76
  139. package/lib/oidc/authorize.js.map +1 -1
  140. package/lib/oidc/error.js +17 -17
  141. package/lib/oidc/error.js.map +1 -1
  142. package/lib/oidc/index.js +17 -17
  143. package/lib/oidc/index.js.map +1 -1
  144. package/lib/oidc/register.js +41 -41
  145. package/lib/oidc/register.js.map +1 -1
  146. package/lib/oidc/tokenRefresher.js +51 -51
  147. package/lib/oidc/tokenRefresher.js.map +1 -1
  148. package/lib/oidc/validate.js +59 -59
  149. package/lib/oidc/validate.js.map +1 -1
  150. package/lib/randomstring.js +35 -35
  151. package/lib/randomstring.js.map +1 -1
  152. package/lib/realtime-callbacks.js +39 -39
  153. package/lib/realtime-callbacks.js.map +1 -1
  154. package/lib/receipt-accumulator.js +44 -44
  155. package/lib/receipt-accumulator.js.map +1 -1
  156. package/lib/rendezvous/RendezvousChannel.js.map +1 -1
  157. package/lib/rendezvous/RendezvousCode.js.map +1 -1
  158. package/lib/rendezvous/RendezvousError.js +14 -14
  159. package/lib/rendezvous/RendezvousError.js.map +1 -1
  160. package/lib/rendezvous/RendezvousFailureReason.js +14 -14
  161. package/lib/rendezvous/RendezvousFailureReason.js.map +1 -1
  162. package/lib/rendezvous/RendezvousIntent.js +14 -14
  163. package/lib/rendezvous/RendezvousIntent.js.map +1 -1
  164. package/lib/rendezvous/RendezvousTransport.js.map +1 -1
  165. package/lib/rendezvous/channels/MSC4108SecureChannel.js +63 -63
  166. package/lib/rendezvous/channels/MSC4108SecureChannel.js.map +1 -1
  167. package/lib/rendezvous/channels/index.js +14 -14
  168. package/lib/rendezvous/channels/index.js.map +1 -1
  169. package/lib/rendezvous/index.js +14 -14
  170. package/lib/rendezvous/index.js.map +1 -1
  171. package/lib/rendezvous/transports/index.js +14 -14
  172. package/lib/rendezvous/transports/index.js.map +1 -1
  173. package/lib/rust-crypto/CrossSigningIdentity.js +29 -29
  174. package/lib/rust-crypto/CrossSigningIdentity.js.map +1 -1
  175. package/lib/rust-crypto/OutgoingRequestsManager.js +37 -37
  176. package/lib/rust-crypto/OutgoingRequestsManager.js.map +1 -1
  177. package/lib/rust-crypto/device-converter.js +30 -30
  178. package/lib/rust-crypto/device-converter.js.map +1 -1
  179. package/lib/rust-crypto/secret-storage.js +30 -30
  180. package/lib/rust-crypto/secret-storage.js.map +1 -1
  181. package/lib/service-types.js +14 -14
  182. package/lib/service-types.js.map +1 -1
  183. package/lib/store/local-storage-events-emitter.js +21 -21
  184. package/lib/store/local-storage-events-emitter.js.map +1 -1
  185. package/lib/sync-accumulator.js +50 -50
  186. package/lib/sync-accumulator.js.map +1 -1
  187. package/lib/thread-utils.js +20 -20
  188. package/lib/thread-utils.js.map +1 -1
  189. package/lib/types.js +34 -34
  190. package/lib/types.js.map +1 -1
  191. package/lib/utils/decryptAESSecretStorageItem.js +22 -22
  192. package/lib/utils/decryptAESSecretStorageItem.js.map +1 -1
  193. package/lib/utils/encryptAESSecretStorageItem.js +26 -26
  194. package/lib/utils/encryptAESSecretStorageItem.js.map +1 -1
  195. package/lib/utils/internal/deriveKeys.js +21 -21
  196. package/lib/utils/internal/deriveKeys.js.map +1 -1
  197. package/lib/utils/roomVersion.js +26 -26
  198. package/lib/utils/roomVersion.js.map +1 -1
  199. package/lib/version-support.js +26 -26
  200. package/lib/version-support.js.map +1 -1
  201. package/lib/wallet-recovery.d.ts +24 -0
  202. package/lib/wallet-recovery.d.ts.map +1 -0
  203. package/lib/wallet-recovery.js +232 -0
  204. package/lib/wallet-recovery.js.map +1 -0
  205. package/lib/webrtc/audioContext.js +24 -24
  206. package/lib/webrtc/audioContext.js.map +1 -1
  207. package/lib/webrtc/callEventTypes.js.map +1 -1
  208. package/lib/webrtc/stats/callFeedStatsReporter.js +14 -14
  209. package/lib/webrtc/stats/callFeedStatsReporter.js.map +1 -1
  210. package/lib/webrtc/stats/callStatsReportGatherer.js +14 -14
  211. package/lib/webrtc/stats/callStatsReportGatherer.js.map +1 -1
  212. package/lib/webrtc/stats/callStatsReportSummary.js.map +1 -1
  213. package/lib/webrtc/stats/connectionStats.js +14 -14
  214. package/lib/webrtc/stats/connectionStats.js.map +1 -1
  215. package/lib/webrtc/stats/connectionStatsBuilder.js +14 -14
  216. package/lib/webrtc/stats/connectionStatsBuilder.js.map +1 -1
  217. package/lib/webrtc/stats/connectionStatsReportBuilder.js +14 -14
  218. package/lib/webrtc/stats/connectionStatsReportBuilder.js.map +1 -1
  219. package/lib/webrtc/stats/groupCallStats.js +14 -14
  220. package/lib/webrtc/stats/groupCallStats.js.map +1 -1
  221. package/lib/webrtc/stats/media/mediaSsrcHandler.js +14 -14
  222. package/lib/webrtc/stats/media/mediaSsrcHandler.js.map +1 -1
  223. package/lib/webrtc/stats/media/mediaTrackHandler.js +14 -14
  224. package/lib/webrtc/stats/media/mediaTrackHandler.js.map +1 -1
  225. package/lib/webrtc/stats/media/mediaTrackStats.js +27 -27
  226. package/lib/webrtc/stats/media/mediaTrackStats.js.map +1 -1
  227. package/lib/webrtc/stats/media/mediaTrackStatsHandler.js +20 -20
  228. package/lib/webrtc/stats/media/mediaTrackStatsHandler.js.map +1 -1
  229. package/lib/webrtc/stats/statsReport.js +14 -14
  230. package/lib/webrtc/stats/statsReport.js.map +1 -1
  231. package/lib/webrtc/stats/statsReportEmitter.js +14 -14
  232. package/lib/webrtc/stats/statsReportEmitter.js.map +1 -1
  233. package/lib/webrtc/stats/trackStatsBuilder.js +4 -4
  234. package/lib/webrtc/stats/trackStatsBuilder.js.map +1 -1
  235. package/lib/webrtc/stats/transportStats.js.map +1 -1
  236. package/lib/webrtc/stats/transportStatsBuilder.js.map +1 -1
  237. package/lib/webrtc/stats/valueFormatter.js +11 -11
  238. package/lib/webrtc/stats/valueFormatter.js.map +1 -1
  239. package/lib/xrpl/identity.d.ts +28 -0
  240. package/lib/xrpl/identity.d.ts.map +1 -0
  241. package/lib/xrpl/identity.js +213 -0
  242. package/lib/xrpl/identity.js.map +1 -0
  243. package/lib/xrpl/trust.d.ts +8 -0
  244. package/lib/xrpl/trust.d.ts.map +1 -0
  245. package/lib/xrpl/trust.js +61 -0
  246. package/lib/xrpl/trust.js.map +1 -0
  247. package/lib/xrpl/verification.d.ts +26 -0
  248. package/lib/xrpl/verification.d.ts.map +1 -0
  249. package/lib/xrpl/verification.js +295 -0
  250. package/lib/xrpl/verification.js.map +1 -0
  251. package/package.json +130 -129
  252. package/src/@types/AESEncryptedSecretStoragePayload.ts +29 -29
  253. package/src/@types/IIdentityServerProvider.ts +24 -24
  254. package/src/@types/PushRules.ts +208 -208
  255. package/src/@types/another-json.d.ts +19 -19
  256. package/src/@types/auth.ts +340 -258
  257. package/src/@types/beacon.ts +140 -140
  258. package/src/@types/common.ts +24 -24
  259. package/src/@types/crypto.ts +71 -71
  260. package/src/@types/event.ts +508 -449
  261. package/src/@types/events.ts +119 -119
  262. package/src/@types/extensible_events.ts +147 -147
  263. package/src/@types/local_notifications.ts +19 -19
  264. package/src/@types/location.ts +92 -92
  265. package/src/@types/matrix-sdk-crypto-wasm.d.ts +39 -39
  266. package/src/@types/media.ts +245 -245
  267. package/src/@types/membership.ts +57 -57
  268. package/src/@types/partials.ts +103 -103
  269. package/src/@types/polls.ts +120 -120
  270. package/src/@types/read_receipts.ts +61 -61
  271. package/src/@types/registration.ts +102 -102
  272. package/src/@types/search.ts +119 -119
  273. package/src/@types/signed.ts +25 -25
  274. package/src/@types/spaces.ts +37 -37
  275. package/src/@types/state_events.ts +153 -153
  276. package/src/@types/synapse.ts +40 -40
  277. package/src/@types/sync.ts +27 -27
  278. package/src/@types/threepids.ts +29 -29
  279. package/src/@types/topic.ts +69 -69
  280. package/src/@types/uia.ts +24 -24
  281. package/src/NamespacedValue.ts +121 -121
  282. package/src/ReEmitter.ts +93 -93
  283. package/src/base64.ts +86 -86
  284. package/src/briij.ts +4 -0
  285. package/src/client.ts +183 -10
  286. package/src/common-crypto/README.md +4 -4
  287. package/src/common-crypto/key-passphrase.ts +43 -43
  288. package/src/content-helpers.ts +298 -298
  289. package/src/content-repo.ts +122 -122
  290. package/src/crypto/store/base.ts +388 -388
  291. package/src/crypto/store/indexeddb-crypto-store-backend.ts +655 -655
  292. package/src/crypto/store/indexeddb-crypto-store.ts +555 -555
  293. package/src/crypto/store/localStorage-crypto-store.ts +409 -409
  294. package/src/crypto/store/memory-crypto-store.ts +326 -326
  295. package/src/crypto-api/CryptoEventHandlerMap.ts +42 -42
  296. package/src/crypto-api/key-passphrase.ts +58 -58
  297. package/src/crypto-api/keybackup.ts +114 -114
  298. package/src/crypto-api/recovery-key.ts +69 -69
  299. package/src/digest.ts +34 -34
  300. package/src/extensible_events_v1/ExtensibleEvent.ts +58 -58
  301. package/src/extensible_events_v1/InvalidEventError.ts +24 -24
  302. package/src/extensible_events_v1/MessageEvent.ts +143 -143
  303. package/src/extensible_events_v1/PollEndEvent.ts +97 -97
  304. package/src/extensible_events_v1/PollResponseEvent.ts +148 -148
  305. package/src/extensible_events_v1/PollStartEvent.ts +207 -207
  306. package/src/extensible_events_v1/utilities.ts +35 -35
  307. package/src/feature.ts +88 -88
  308. package/src/http-api/method.ts +25 -25
  309. package/src/http-api/prefix.ts +48 -48
  310. package/src/indexeddb-helpers.ts +50 -50
  311. package/src/indexeddb-worker.ts +24 -24
  312. package/src/matrixrtc/IKeyTransport.ts +63 -63
  313. package/src/matrixrtc/IMembershipManager.ts +120 -120
  314. package/src/matrixrtc/LivekitTransport.ts +46 -46
  315. package/src/matrixrtc/index.ts +24 -24
  316. package/src/matrixrtc/utils.ts +71 -71
  317. package/src/models/ToDeviceMessage.ts +38 -38
  318. package/src/models/device.ts +85 -85
  319. package/src/models/event-status.ts +39 -39
  320. package/src/models/invites-ignorer-types.ts +58 -58
  321. package/src/models/profile-keys.ts +33 -33
  322. package/src/models/room-summary.ts +78 -78
  323. package/src/models/search-result.ts +57 -57
  324. package/src/models/typed-event-emitter.ts +246 -246
  325. package/src/oidc/authorize.ts +279 -279
  326. package/src/oidc/error.ts +33 -33
  327. package/src/oidc/index.ts +33 -33
  328. package/src/oidc/register.ts +163 -163
  329. package/src/oidc/tokenRefresher.ts +184 -184
  330. package/src/oidc/validate.ts +265 -265
  331. package/src/randomstring.ts +103 -103
  332. package/src/realtime-callbacks.ts +191 -191
  333. package/src/receipt-accumulator.ts +189 -189
  334. package/src/rendezvous/RendezvousChannel.ts +48 -48
  335. package/src/rendezvous/RendezvousCode.ts +25 -25
  336. package/src/rendezvous/RendezvousError.ts +26 -26
  337. package/src/rendezvous/RendezvousFailureReason.ts +49 -49
  338. package/src/rendezvous/RendezvousIntent.ts +20 -20
  339. package/src/rendezvous/RendezvousTransport.ts +58 -58
  340. package/src/rendezvous/channels/MSC4108SecureChannel.ts +270 -270
  341. package/src/rendezvous/channels/index.ts +17 -17
  342. package/src/rendezvous/index.ts +25 -25
  343. package/src/rendezvous/transports/index.ts +17 -17
  344. package/src/rust-crypto/CrossSigningIdentity.ts +195 -195
  345. package/src/rust-crypto/OutgoingRequestsManager.ts +170 -170
  346. package/src/rust-crypto/device-converter.ts +128 -128
  347. package/src/rust-crypto/secret-storage.ts +60 -60
  348. package/src/service-types.ts +20 -20
  349. package/src/store/local-storage-events-emitter.ts +46 -46
  350. package/src/sync-accumulator.ts +779 -779
  351. package/src/thread-utils.ts +31 -31
  352. package/src/types.ts +59 -59
  353. package/src/utils/decryptAESSecretStorageItem.ts +54 -54
  354. package/src/utils/encryptAESSecretStorageItem.ts +73 -73
  355. package/src/utils/internal/deriveKeys.ts +63 -63
  356. package/src/utils/roomVersion.ts +35 -35
  357. package/src/version-support.ts +50 -50
  358. package/src/wallet-recovery.ts +252 -0
  359. package/src/webrtc/audioContext.ts +44 -44
  360. package/src/webrtc/callEventTypes.ts +101 -101
  361. package/src/webrtc/stats/callFeedStatsReporter.ts +91 -91
  362. package/src/webrtc/stats/callStatsReportGatherer.ts +219 -219
  363. package/src/webrtc/stats/callStatsReportSummary.ts +30 -30
  364. package/src/webrtc/stats/connectionStats.ts +47 -47
  365. package/src/webrtc/stats/connectionStatsBuilder.ts +28 -28
  366. package/src/webrtc/stats/connectionStatsReportBuilder.ts +140 -140
  367. package/src/webrtc/stats/groupCallStats.ts +93 -93
  368. package/src/webrtc/stats/media/mediaSsrcHandler.ts +57 -57
  369. package/src/webrtc/stats/media/mediaTrackHandler.ts +70 -70
  370. package/src/webrtc/stats/media/mediaTrackStats.ts +176 -176
  371. package/src/webrtc/stats/media/mediaTrackStatsHandler.ts +90 -90
  372. package/src/webrtc/stats/statsReport.ts +133 -133
  373. package/src/webrtc/stats/statsReportEmitter.ts +49 -49
  374. package/src/webrtc/stats/trackStatsBuilder.ts +207 -207
  375. package/src/webrtc/stats/transportStats.ts +26 -26
  376. package/src/webrtc/stats/transportStatsBuilder.ts +48 -48
  377. package/src/webrtc/stats/valueFormatter.ts +27 -27
  378. package/src/xrpl/identity.ts +245 -0
  379. package/src/xrpl/trust.ts +64 -0
  380. package/src/xrpl/verification.ts +284 -0
@@ -1,28 +1,28 @@
1
- /*
2
- * Copyright 2024 The Matrix.org Foundation C.I.C.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
1
+ /*
2
+ * Copyright 2024 The Matrix.org Foundation C.I.C.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
15
  */
16
16
 
17
17
  import { deriveRecoveryKeyFromPassphrase } from "../crypto-api/index.js";
18
18
 
19
19
  /* eslint-disable camelcase */
20
20
 
21
- /**
22
- * Derive a backup key from a passphrase using the salt and iterations from the auth data.
23
- * @param authData - The auth data containing the salt and iterations
24
- * @param passphrase - The passphrase to derive the key from
25
- * @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.
21
+ /**
22
+ * Derive a backup key from a passphrase using the salt and iterations from the auth data.
23
+ * @param authData - The auth data containing the salt and iterations
24
+ * @param passphrase - The passphrase to derive the key from
25
+ * @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.
26
26
  */
27
27
  export function keyFromAuthData(authData, passphrase) {
28
28
  if (!authData.private_key_salt || !authData.private_key_iterations) {
@@ -1 +1 @@
1
- {"version":3,"file":"key-passphrase.js","names":["deriveRecoveryKeyFromPassphrase","keyFromAuthData","authData","passphrase","private_key_salt","private_key_iterations","Error","private_key_bits"],"sources":["../../src/common-crypto/key-passphrase.ts"],"sourcesContent":["/*\r\n * Copyright 2024 The Matrix.org Foundation C.I.C.\r\n *\r\n * Licensed under the Apache License, Version 2.0 (the \"License\");\r\n * you may not use this file except in compliance with the License.\r\n * You may obtain a copy of the License at\r\n *\r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n *\r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n * See the License for the specific language governing permissions and\r\n * limitations under the License.\r\n */\r\n\r\nimport { deriveRecoveryKeyFromPassphrase } from \"../crypto-api/index.ts\";\r\n\r\n/* eslint-disable camelcase */\r\ninterface IAuthData {\r\n private_key_salt?: string;\r\n private_key_iterations?: number;\r\n private_key_bits?: number;\r\n}\r\n\r\n/**\r\n * Derive a backup key from a passphrase using the salt and iterations from the auth data.\r\n * @param authData - The auth data containing the salt and iterations\r\n * @param passphrase - The passphrase to derive the key from\r\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.\r\n */\r\nexport function keyFromAuthData(authData: IAuthData, passphrase: string): Promise<Uint8Array> {\r\n if (!authData.private_key_salt || !authData.private_key_iterations) {\r\n throw new Error(\"Salt and/or iterations not found: \" + \"this backup cannot be restored with a passphrase\");\r\n }\r\n\r\n return deriveRecoveryKeyFromPassphrase(\r\n passphrase,\r\n authData.private_key_salt,\r\n authData.private_key_iterations,\r\n authData.private_key_bits,\r\n );\r\n}\r\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,+BAA+B,QAAQ,wBAAwB;;AAExE;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAACC,QAAmB,EAAEC,UAAkB,EAAuB;EAC1F,IAAI,CAACD,QAAQ,CAACE,gBAAgB,IAAI,CAACF,QAAQ,CAACG,sBAAsB,EAAE;IAChE,MAAM,IAAIC,KAAK,CAAC,oCAAoC,GAAG,kDAAkD,CAAC;EAC9G;EAEA,OAAON,+BAA+B,CAClCG,UAAU,EACVD,QAAQ,CAACE,gBAAgB,EACzBF,QAAQ,CAACG,sBAAsB,EAC/BH,QAAQ,CAACK,gBACb,CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"file":"key-passphrase.js","names":["deriveRecoveryKeyFromPassphrase","keyFromAuthData","authData","passphrase","private_key_salt","private_key_iterations","Error","private_key_bits"],"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\n/* eslint-disable camelcase */\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,SAASA,+BAA+B,QAAQ,wBAAwB;;AAExE;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAACC,QAAmB,EAAEC,UAAkB,EAAuB;EAC1F,IAAI,CAACD,QAAQ,CAACE,gBAAgB,IAAI,CAACF,QAAQ,CAACG,sBAAsB,EAAE;IAChE,MAAM,IAAIC,KAAK,CAAC,oCAAoC,GAAG,kDAAkD,CAAC;EAC9G;EAEA,OAAON,+BAA+B,CAClCG,UAAU,EACVD,QAAQ,CAACE,gBAAgB,EACzBF,QAAQ,CAACG,sBAAsB,EAC/BH,QAAQ,CAACK,gBACb,CAAC;AACL","ignoreList":[]}
@@ -1,20 +1,20 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- /*
5
- Copyright 2018 - 2022 The Matrix.org Foundation C.I.C.
6
-
7
- Licensed under the Apache License, Version 2.0 (the "License");
8
- you may not use this file except in compliance with the License.
9
- You may obtain a copy of the License at
10
-
11
- http://www.apache.org/licenses/LICENSE-2.0
12
-
13
- Unless required by applicable law or agreed to in writing, software
14
- distributed under the License is distributed on an "AS IS" BASIS,
15
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- See the License for the specific language governing permissions and
17
- limitations under the License.
4
+ /*
5
+ Copyright 2018 - 2022 The Matrix.org Foundation C.I.C.
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
18
  */
19
19
 
20
20
  import { MsgType } from "./@types/event.js";
@@ -22,11 +22,11 @@ import { M_TEXT, REFERENCE_RELATION } from "./@types/extensible_events.js";
22
22
  import { isProvided } from "./extensible_events_v1/utilities.js";
23
23
  import { M_ASSET, LocationAssetType, M_LOCATION, M_TIMESTAMP } from "./@types/location.js";
24
24
  import { M_TOPIC } from "./@types/topic.js";
25
- /**
26
- * Generates the content for a HTML Message event
27
- * @param body - the plaintext body of the message
28
- * @param htmlBody - the HTML representation of the message
29
- * @returns
25
+ /**
26
+ * Generates the content for a HTML Message event
27
+ * @param body - the plaintext body of the message
28
+ * @param htmlBody - the HTML representation of the message
29
+ * @returns
30
30
  */
31
31
  export function makeHtmlMessage(body, htmlBody) {
32
32
  return {
@@ -37,11 +37,11 @@ export function makeHtmlMessage(body, htmlBody) {
37
37
  };
38
38
  }
39
39
 
40
- /**
41
- * Generates the content for a HTML Notice event
42
- * @param body - the plaintext body of the notice
43
- * @param htmlBody - the HTML representation of the notice
44
- * @returns
40
+ /**
41
+ * Generates the content for a HTML Notice event
42
+ * @param body - the plaintext body of the notice
43
+ * @param htmlBody - the HTML representation of the notice
44
+ * @returns
45
45
  */
46
46
  export function makeHtmlNotice(body, htmlBody) {
47
47
  return {
@@ -52,11 +52,11 @@ export function makeHtmlNotice(body, htmlBody) {
52
52
  };
53
53
  }
54
54
 
55
- /**
56
- * Generates the content for a HTML Emote event
57
- * @param body - the plaintext body of the emote
58
- * @param htmlBody - the HTML representation of the emote
59
- * @returns
55
+ /**
56
+ * Generates the content for a HTML Emote event
57
+ * @param body - the plaintext body of the emote
58
+ * @param htmlBody - the HTML representation of the emote
59
+ * @returns
60
60
  */
61
61
  export function makeHtmlEmote(body, htmlBody) {
62
62
  return {
@@ -67,10 +67,10 @@ export function makeHtmlEmote(body, htmlBody) {
67
67
  };
68
68
  }
69
69
 
70
- /**
71
- * Generates the content for a Plaintext Message event
72
- * @param body - the plaintext body of the emote
73
- * @returns
70
+ /**
71
+ * Generates the content for a Plaintext Message event
72
+ * @param body - the plaintext body of the emote
73
+ * @returns
74
74
  */
75
75
  export function makeTextMessage(body) {
76
76
  return {
@@ -79,10 +79,10 @@ export function makeTextMessage(body) {
79
79
  };
80
80
  }
81
81
 
82
- /**
83
- * Generates the content for a Plaintext Notice event
84
- * @param body - the plaintext body of the notice
85
- * @returns
82
+ /**
83
+ * Generates the content for a Plaintext Notice event
84
+ * @param body - the plaintext body of the notice
85
+ * @returns
86
86
  */
87
87
  export function makeNotice(body) {
88
88
  return {
@@ -91,10 +91,10 @@ export function makeNotice(body) {
91
91
  };
92
92
  }
93
93
 
94
- /**
95
- * Generates the content for a Plaintext Emote event
96
- * @param body - the plaintext body of the emote
97
- * @returns
94
+ /**
95
+ * Generates the content for a Plaintext Emote event
96
+ * @param body - the plaintext body of the emote
97
+ * @returns
98
98
  */
99
99
  export function makeEmoteMessage(body) {
100
100
  return {
@@ -112,13 +112,13 @@ export var getTextForLocationEvent = (uri, assetType, timestamp, description) =>
112
112
  return [assetName, "Location", quotedDescription, uri, date].filter(Boolean).join(" ");
113
113
  };
114
114
 
115
- /**
116
- * Generates the content for a Location event
117
- * @param uri - a geo:// uri for the location
118
- * @param timestamp - the timestamp when the location was correct (milliseconds since the UNIX epoch)
119
- * @param description - the (optional) label for this location on the map
120
- * @param assetType - the (optional) asset type of this location e.g. "m.self"
121
- * @param text - optional. A text for the location
115
+ /**
116
+ * Generates the content for a Location event
117
+ * @param uri - a geo:// uri for the location
118
+ * @param timestamp - the timestamp when the location was correct (milliseconds since the UNIX epoch)
119
+ * @param description - the (optional) label for this location on the map
120
+ * @param assetType - the (optional) asset type of this location e.g. "m.self"
121
+ * @param text - optional. A text for the location
122
122
  */
123
123
  export var makeLocationContent = (text, uri, timestamp, description, assetType) => {
124
124
  var defaultedText = text !== null && text !== void 0 ? text : getTextForLocationEvent(uri, assetType || LocationAssetType.Self, timestamp, description);
@@ -140,9 +140,9 @@ export var makeLocationContent = (text, uri, timestamp, description, assetType)
140
140
  }, timestampEvent);
141
141
  };
142
142
 
143
- /**
144
- * Parse location event content and transform to
145
- * a backwards compatible modern m.location event format
143
+ /**
144
+ * Parse location event content and transform to
145
+ * a backwards compatible modern m.location event format
146
146
  */
147
147
  export var parseLocationEvent = wireEventContent => {
148
148
  var _location$uri, _asset$type;
@@ -157,8 +157,8 @@ export var parseLocationEvent = wireEventContent => {
157
157
  return makeLocationContent(fallbackText, geoUri, timestamp !== null && timestamp !== void 0 ? timestamp : undefined, description, assetType);
158
158
  };
159
159
 
160
- /**
161
- * Topic event helpers
160
+ /**
161
+ * Topic event helpers
162
162
  */
163
163
 
164
164
  export var makeTopicContent = (topic, htmlTopic) => {
@@ -205,8 +205,8 @@ export var parseTopicContent = content => {
205
205
  };
206
206
  };
207
207
 
208
- /**
209
- * Beacon event helpers
208
+ /**
209
+ * Beacon event helpers
210
210
  */
211
211
 
212
212
  export var makeBeaconInfoContent = (timeout, isLive, description, assetType, timestamp) => ({
@@ -218,8 +218,8 @@ export var makeBeaconInfoContent = (timeout, isLive, description, assetType, tim
218
218
  type: assetType !== null && assetType !== void 0 ? assetType : LocationAssetType.Self
219
219
  }
220
220
  });
221
- /**
222
- * Flatten beacon info event content
221
+ /**
222
+ * Flatten beacon info event content
223
223
  */
224
224
  export var parseBeaconInfoContent = content => {
225
225
  var _M_TIMESTAMP$findIn;
@@ -1 +1 @@
1
- {"version":3,"file":"content-helpers.js","names":["MsgType","M_TEXT","REFERENCE_RELATION","isProvided","M_ASSET","LocationAssetType","M_LOCATION","M_TIMESTAMP","M_TOPIC","makeHtmlMessage","body","htmlBody","msgtype","Text","format","formatted_body","makeHtmlNotice","Notice","makeHtmlEmote","Emote","makeTextMessage","makeNotice","makeEmoteMessage","getTextForLocationEvent","uri","assetType","timestamp","description","date","concat","Date","toISOString","assetName","Self","undefined","quotedDescription","filter","Boolean","join","makeLocationContent","text","defaultedText","timestampEvent","name","_objectSpread","Location","geo_uri","type","parseLocationEvent","wireEventContent","_location$uri","_asset$type","location","findIn","asset","geoUri","fallbackText","makeTopicContent","topic","htmlTopic","renderings","push","mimetype","parseTopicContent","content","_ref","_mtopic$find$body","_mtopic$find","_mtopic$find2","mtopicParent","mtopic","Array","isArray","_content$topic","find","r","html","makeBeaconInfoContent","timeout","isLive","live","now","parseBeaconInfoContent","_M_TIMESTAMP$findIn","makeBeaconContent","beaconInfoEventId","rel_type","event_id","parseBeaconContent","_M_TIMESTAMP$findIn2"],"sources":["../src/content-helpers.ts"],"sourcesContent":["/*\r\nCopyright 2018 - 2022 The Matrix.org Foundation C.I.C.\r\n\r\nLicensed under the Apache License, Version 2.0 (the \"License\");\r\nyou may not use this file except in compliance with the License.\r\nYou may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nUnless required by applicable law or agreed to in writing, software\r\ndistributed under the License is distributed on an \"AS IS\" BASIS,\r\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\nSee the License for the specific language governing permissions and\r\nlimitations under the License.\r\n*/\r\n\r\nimport { type MBeaconEventContent, type MBeaconInfoContent, type MBeaconInfoEventContent } from \"./@types/beacon.ts\";\r\nimport { MsgType } from \"./@types/event.ts\";\r\nimport { type IMessageRendering, M_TEXT, REFERENCE_RELATION } from \"./@types/extensible_events.ts\";\r\nimport { isProvided } from \"./extensible_events_v1/utilities.ts\";\r\nimport {\r\n M_ASSET,\r\n LocationAssetType,\r\n M_LOCATION,\r\n M_TIMESTAMP,\r\n type LocationEventWireContent,\r\n type MLocationEventContent,\r\n type MLocationContent,\r\n type MAssetContent,\r\n type LegacyLocationEventContent,\r\n} from \"./@types/location.ts\";\r\nimport { type MRoomTopicEventContent, type MTopicContent, M_TOPIC, type MTopicEvent } from \"./@types/topic.ts\";\r\nimport { type RoomMessageEventContent } from \"./@types/events.ts\";\r\n\r\n/**\r\n * Generates the content for a HTML Message event\r\n * @param body - the plaintext body of the message\r\n * @param htmlBody - the HTML representation of the message\r\n * @returns\r\n */\r\nexport function makeHtmlMessage(body: string, htmlBody: string): RoomMessageEventContent {\r\n return {\r\n msgtype: MsgType.Text,\r\n format: \"org.matrix.custom.html\",\r\n body: body,\r\n formatted_body: htmlBody,\r\n };\r\n}\r\n\r\n/**\r\n * Generates the content for a HTML Notice event\r\n * @param body - the plaintext body of the notice\r\n * @param htmlBody - the HTML representation of the notice\r\n * @returns\r\n */\r\nexport function makeHtmlNotice(body: string, htmlBody: string): RoomMessageEventContent {\r\n return {\r\n msgtype: MsgType.Notice,\r\n format: \"org.matrix.custom.html\",\r\n body: body,\r\n formatted_body: htmlBody,\r\n };\r\n}\r\n\r\n/**\r\n * Generates the content for a HTML Emote event\r\n * @param body - the plaintext body of the emote\r\n * @param htmlBody - the HTML representation of the emote\r\n * @returns\r\n */\r\nexport function makeHtmlEmote(body: string, htmlBody: string): RoomMessageEventContent {\r\n return {\r\n msgtype: MsgType.Emote,\r\n format: \"org.matrix.custom.html\",\r\n body: body,\r\n formatted_body: htmlBody,\r\n };\r\n}\r\n\r\n/**\r\n * Generates the content for a Plaintext Message event\r\n * @param body - the plaintext body of the emote\r\n * @returns\r\n */\r\nexport function makeTextMessage(body: string): RoomMessageEventContent {\r\n return {\r\n msgtype: MsgType.Text,\r\n body: body,\r\n };\r\n}\r\n\r\n/**\r\n * Generates the content for a Plaintext Notice event\r\n * @param body - the plaintext body of the notice\r\n * @returns\r\n */\r\nexport function makeNotice(body: string): RoomMessageEventContent {\r\n return {\r\n msgtype: MsgType.Notice,\r\n body: body,\r\n };\r\n}\r\n\r\n/**\r\n * Generates the content for a Plaintext Emote event\r\n * @param body - the plaintext body of the emote\r\n * @returns\r\n */\r\nexport function makeEmoteMessage(body: string): RoomMessageEventContent {\r\n return {\r\n msgtype: MsgType.Emote,\r\n body: body,\r\n };\r\n}\r\n\r\n/** Location content helpers */\r\n\r\nexport const getTextForLocationEvent = (\r\n uri: string | undefined,\r\n assetType: LocationAssetType,\r\n timestamp?: number,\r\n description?: string | null,\r\n): string => {\r\n const date = `at ${new Date(timestamp!).toISOString()}`;\r\n const assetName = assetType === LocationAssetType.Self ? \"User\" : undefined;\r\n const quotedDescription = description ? `\"${description}\"` : undefined;\r\n\r\n return [assetName, \"Location\", quotedDescription, uri, date].filter(Boolean).join(\" \");\r\n};\r\n\r\n/**\r\n * Generates the content for a Location event\r\n * @param uri - a geo:// uri for the location\r\n * @param timestamp - the timestamp when the location was correct (milliseconds since the UNIX epoch)\r\n * @param description - the (optional) label for this location on the map\r\n * @param assetType - the (optional) asset type of this location e.g. \"m.self\"\r\n * @param text - optional. A text for the location\r\n */\r\nexport const makeLocationContent = (\r\n // this is first but optional\r\n // to avoid a breaking change\r\n text?: string,\r\n uri?: string,\r\n timestamp?: number,\r\n description?: string | null,\r\n assetType?: LocationAssetType,\r\n): LegacyLocationEventContent & MLocationEventContent => {\r\n const defaultedText =\r\n text ?? getTextForLocationEvent(uri, assetType || LocationAssetType.Self, timestamp, description);\r\n const timestampEvent = timestamp ? { [M_TIMESTAMP.name]: timestamp } : {};\r\n return {\r\n msgtype: MsgType.Location,\r\n body: defaultedText,\r\n geo_uri: uri,\r\n [M_LOCATION.name]: {\r\n description,\r\n uri,\r\n },\r\n [M_ASSET.name]: {\r\n type: assetType || LocationAssetType.Self,\r\n },\r\n [M_TEXT.name]: defaultedText,\r\n ...timestampEvent,\r\n } as LegacyLocationEventContent & MLocationEventContent;\r\n};\r\n\r\n/**\r\n * Parse location event content and transform to\r\n * a backwards compatible modern m.location event format\r\n */\r\nexport const parseLocationEvent = (wireEventContent: LocationEventWireContent): MLocationEventContent => {\r\n const location = M_LOCATION.findIn<MLocationContent>(wireEventContent);\r\n const asset = M_ASSET.findIn<MAssetContent>(wireEventContent);\r\n const timestamp = M_TIMESTAMP.findIn<number>(wireEventContent);\r\n const text = M_TEXT.findIn<string>(wireEventContent);\r\n\r\n const geoUri = location?.uri ?? wireEventContent?.geo_uri;\r\n const description = location?.description;\r\n const assetType = asset?.type ?? LocationAssetType.Self;\r\n const fallbackText = text ?? wireEventContent.body;\r\n\r\n return makeLocationContent(fallbackText, geoUri, timestamp ?? undefined, description, assetType);\r\n};\r\n\r\n/**\r\n * Topic event helpers\r\n */\r\nexport type MakeTopicContent = (topic: string | null | undefined, htmlTopic?: string) => MRoomTopicEventContent;\r\n\r\nexport const makeTopicContent: MakeTopicContent = (topic, htmlTopic) => {\r\n const renderings = [];\r\n // Put HTML first because clients will render the first type in\r\n // the array that they understand\r\n if (isProvided(htmlTopic)) {\r\n renderings.push({ body: htmlTopic, mimetype: \"text/html\" });\r\n }\r\n if (isProvided(topic)) {\r\n renderings.push({ body: topic, mimetype: \"text/plain\" });\r\n }\r\n return { topic, [M_TOPIC.name]: { \"m.text\": renderings } };\r\n};\r\n\r\nexport type TopicState = {\r\n text?: string;\r\n html?: string;\r\n};\r\n\r\nexport const parseTopicContent = (content: MRoomTopicEventContent): TopicState => {\r\n const mtopicParent = M_TOPIC.findIn<MTopicContent | IMessageRendering[]>(content as MTopicEvent);\r\n const mtopic = Array.isArray(mtopicParent) ? mtopicParent : mtopicParent?.[\"m.text\"];\r\n // TODO remove support for the old malformed m.topic arrays after a few releases (only allow array in m.text)\r\n // https://github.com/matrix-org/matrix-js-sdk/pull/4984#pullrequestreview-3174251065\r\n //const mtopic = M_TOPIC.findIn<MTopicContent>(content)?.[\"m.text\"];\r\n if (!Array.isArray(mtopic)) {\r\n return { text: content.topic ?? undefined };\r\n }\r\n const text =\r\n mtopic?.find((r) => !isProvided(r.mimetype) || r.mimetype === \"text/plain\")?.body ?? content.topic ?? undefined;\r\n const html = mtopic?.find((r) => r.mimetype === \"text/html\")?.body;\r\n return { text, html };\r\n};\r\n\r\n/**\r\n * Beacon event helpers\r\n */\r\nexport type MakeBeaconInfoContent = (\r\n timeout: number,\r\n isLive?: boolean,\r\n description?: string,\r\n assetType?: LocationAssetType,\r\n timestamp?: number,\r\n) => MBeaconInfoEventContent;\r\n\r\nexport const makeBeaconInfoContent: MakeBeaconInfoContent = (timeout, isLive, description, assetType, timestamp) => ({\r\n description,\r\n timeout,\r\n live: isLive,\r\n [M_TIMESTAMP.name]: timestamp || Date.now(),\r\n [M_ASSET.name]: {\r\n type: assetType ?? LocationAssetType.Self,\r\n },\r\n});\r\n\r\nexport type BeaconInfoState = MBeaconInfoContent & {\r\n assetType?: LocationAssetType;\r\n timestamp?: number;\r\n};\r\n/**\r\n * Flatten beacon info event content\r\n */\r\nexport const parseBeaconInfoContent = (content: MBeaconInfoEventContent): BeaconInfoState => {\r\n const { description, timeout, live } = content;\r\n const timestamp = M_TIMESTAMP.findIn<number>(content) ?? undefined;\r\n const asset = M_ASSET.findIn<MAssetContent>(content);\r\n\r\n return {\r\n description,\r\n timeout,\r\n live,\r\n assetType: asset?.type,\r\n timestamp,\r\n };\r\n};\r\n\r\nexport type MakeBeaconContent = (\r\n uri: string,\r\n timestamp: number,\r\n beaconInfoEventId: string,\r\n description?: string,\r\n) => MBeaconEventContent;\r\n\r\nexport const makeBeaconContent: MakeBeaconContent = (uri, timestamp, beaconInfoEventId, description) => ({\r\n [M_LOCATION.name]: {\r\n description,\r\n uri,\r\n },\r\n [M_TIMESTAMP.name]: timestamp,\r\n \"m.relates_to\": {\r\n rel_type: REFERENCE_RELATION.name,\r\n event_id: beaconInfoEventId,\r\n },\r\n});\r\n\r\nexport type BeaconLocationState = Omit<MLocationContent, \"uri\"> & {\r\n uri?: string; // override from MLocationContent to allow optionals\r\n timestamp?: number;\r\n};\r\n\r\nexport const parseBeaconContent = (content: MBeaconEventContent): BeaconLocationState => {\r\n const location = M_LOCATION.findIn<MLocationContent>(content);\r\n const timestamp = M_TIMESTAMP.findIn<number>(content) ?? undefined;\r\n\r\n return {\r\n description: location?.description,\r\n uri: location?.uri,\r\n timestamp,\r\n };\r\n};\r\n"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,OAAO,QAAQ,mBAAmB;AAC3C,SAAiCC,MAAM,EAAEC,kBAAkB,QAAQ,+BAA+B;AAClG,SAASC,UAAU,QAAQ,qCAAqC;AAChE,SACIC,OAAO,EACPC,iBAAiB,EACjBC,UAAU,EACVC,WAAW,QAMR,sBAAsB;AAC7B,SAA0DC,OAAO,QAA0B,mBAAmB;AAG9G;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAACC,IAAY,EAAEC,QAAgB,EAA2B;EACrF,OAAO;IACHC,OAAO,EAAEZ,OAAO,CAACa,IAAI;IACrBC,MAAM,EAAE,wBAAwB;IAChCJ,IAAI,EAAEA,IAAI;IACVK,cAAc,EAAEJ;EACpB,CAAC;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,cAAcA,CAACN,IAAY,EAAEC,QAAgB,EAA2B;EACpF,OAAO;IACHC,OAAO,EAAEZ,OAAO,CAACiB,MAAM;IACvBH,MAAM,EAAE,wBAAwB;IAChCJ,IAAI,EAAEA,IAAI;IACVK,cAAc,EAAEJ;EACpB,CAAC;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASO,aAAaA,CAACR,IAAY,EAAEC,QAAgB,EAA2B;EACnF,OAAO;IACHC,OAAO,EAAEZ,OAAO,CAACmB,KAAK;IACtBL,MAAM,EAAE,wBAAwB;IAChCJ,IAAI,EAAEA,IA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,aAARA,QAAQ,uBAARA,QAAQ,CAAE5B,GAAG;IAClBE;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"content-helpers.js","names":["MsgType","M_TEXT","REFERENCE_RELATION","isProvided","M_ASSET","LocationAssetType","M_LOCATION","M_TIMESTAMP","M_TOPIC","makeHtmlMessage","body","htmlBody","msgtype","Text","format","formatted_body","makeHtmlNotice","Notice","makeHtmlEmote","Emote","makeTextMessage","makeNotice","makeEmoteMessage","getTextForLocationEvent","uri","assetType","timestamp","description","date","concat","Date","toISOString","assetName","Self","undefined","quotedDescription","filter","Boolean","join","makeLocationContent","text","defaultedText","timestampEvent","name","_objectSpread","Location","geo_uri","type","parseLocationEvent","wireEventContent","_location$uri","_asset$type","location","findIn","asset","geoUri","fallbackText","makeTopicContent","topic","htmlTopic","renderings","push","mimetype","parseTopicContent","content","_ref","_mtopic$find$body","_mtopic$find","_mtopic$find2","mtopicParent","mtopic","Array","isArray","_content$topic","find","r","html","makeBeaconInfoContent","timeout","isLive","live","now","parseBeaconInfoContent","_M_TIMESTAMP$findIn","makeBeaconContent","beaconInfoEventId","rel_type","event_id","parseBeaconContent","_M_TIMESTAMP$findIn2"],"sources":["../src/content-helpers.ts"],"sourcesContent":["/*\nCopyright 2018 - 2022 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 MBeaconEventContent, type MBeaconInfoContent, type MBeaconInfoEventContent } from \"./@types/beacon.ts\";\nimport { MsgType } from \"./@types/event.ts\";\nimport { type IMessageRendering, M_TEXT, REFERENCE_RELATION } from \"./@types/extensible_events.ts\";\nimport { isProvided } from \"./extensible_events_v1/utilities.ts\";\nimport {\n M_ASSET,\n LocationAssetType,\n M_LOCATION,\n M_TIMESTAMP,\n type LocationEventWireContent,\n type MLocationEventContent,\n type MLocationContent,\n type MAssetContent,\n type LegacyLocationEventContent,\n} from \"./@types/location.ts\";\nimport { type MRoomTopicEventContent, type MTopicContent, M_TOPIC, type MTopicEvent } from \"./@types/topic.ts\";\nimport { type RoomMessageEventContent } from \"./@types/events.ts\";\n\n/**\n * Generates the content for a HTML Message event\n * @param body - the plaintext body of the message\n * @param htmlBody - the HTML representation of the message\n * @returns\n */\nexport function makeHtmlMessage(body: string, htmlBody: string): RoomMessageEventContent {\n return {\n msgtype: MsgType.Text,\n format: \"org.matrix.custom.html\",\n body: body,\n formatted_body: htmlBody,\n };\n}\n\n/**\n * Generates the content for a HTML Notice event\n * @param body - the plaintext body of the notice\n * @param htmlBody - the HTML representation of the notice\n * @returns\n */\nexport function makeHtmlNotice(body: string, htmlBody: string): RoomMessageEventContent {\n return {\n msgtype: MsgType.Notice,\n format: \"org.matrix.custom.html\",\n body: body,\n formatted_body: htmlBody,\n };\n}\n\n/**\n * Generates the content for a HTML Emote event\n * @param body - the plaintext body of the emote\n * @param htmlBody - the HTML representation of the emote\n * @returns\n */\nexport function makeHtmlEmote(body: string, htmlBody: string): RoomMessageEventContent {\n return {\n msgtype: MsgType.Emote,\n format: \"org.matrix.custom.html\",\n body: body,\n formatted_body: htmlBody,\n };\n}\n\n/**\n * Generates the content for a Plaintext Message event\n * @param body - the plaintext body of the emote\n * @returns\n */\nexport function makeTextMessage(body: string): RoomMessageEventContent {\n return {\n msgtype: MsgType.Text,\n body: body,\n };\n}\n\n/**\n * Generates the content for a Plaintext Notice event\n * @param body - the plaintext body of the notice\n * @returns\n */\nexport function makeNotice(body: string): RoomMessageEventContent {\n return {\n msgtype: MsgType.Notice,\n body: body,\n };\n}\n\n/**\n * Generates the content for a Plaintext Emote event\n * @param body - the plaintext body of the emote\n * @returns\n */\nexport function makeEmoteMessage(body: string): RoomMessageEventContent {\n return {\n msgtype: MsgType.Emote,\n body: body,\n };\n}\n\n/** Location content helpers */\n\nexport const getTextForLocationEvent = (\n uri: string | undefined,\n assetType: LocationAssetType,\n timestamp?: number,\n description?: string | null,\n): string => {\n const date = `at ${new Date(timestamp!).toISOString()}`;\n const assetName = assetType === LocationAssetType.Self ? \"User\" : undefined;\n const quotedDescription = description ? `\"${description}\"` : undefined;\n\n return [assetName, \"Location\", quotedDescription, uri, date].filter(Boolean).join(\" \");\n};\n\n/**\n * Generates the content for a Location event\n * @param uri - a geo:// uri for the location\n * @param timestamp - the timestamp when the location was correct (milliseconds since the UNIX epoch)\n * @param description - the (optional) label for this location on the map\n * @param assetType - the (optional) asset type of this location e.g. \"m.self\"\n * @param text - optional. A text for the location\n */\nexport const makeLocationContent = (\n // this is first but optional\n // to avoid a breaking change\n text?: string,\n uri?: string,\n timestamp?: number,\n description?: string | null,\n assetType?: LocationAssetType,\n): LegacyLocationEventContent & MLocationEventContent => {\n const defaultedText =\n text ?? getTextForLocationEvent(uri, assetType || LocationAssetType.Self, timestamp, description);\n const timestampEvent = timestamp ? { [M_TIMESTAMP.name]: timestamp } : {};\n return {\n msgtype: MsgType.Location,\n body: defaultedText,\n geo_uri: uri,\n [M_LOCATION.name]: {\n description,\n uri,\n },\n [M_ASSET.name]: {\n type: assetType || LocationAssetType.Self,\n },\n [M_TEXT.name]: defaultedText,\n ...timestampEvent,\n } as LegacyLocationEventContent & MLocationEventContent;\n};\n\n/**\n * Parse location event content and transform to\n * a backwards compatible modern m.location event format\n */\nexport const parseLocationEvent = (wireEventContent: LocationEventWireContent): MLocationEventContent => {\n const location = M_LOCATION.findIn<MLocationContent>(wireEventContent);\n const asset = M_ASSET.findIn<MAssetContent>(wireEventContent);\n const timestamp = M_TIMESTAMP.findIn<number>(wireEventContent);\n const text = M_TEXT.findIn<string>(wireEventContent);\n\n const geoUri = location?.uri ?? wireEventContent?.geo_uri;\n const description = location?.description;\n const assetType = asset?.type ?? LocationAssetType.Self;\n const fallbackText = text ?? wireEventContent.body;\n\n return makeLocationContent(fallbackText, geoUri, timestamp ?? undefined, description, assetType);\n};\n\n/**\n * Topic event helpers\n */\nexport type MakeTopicContent = (topic: string | null | undefined, htmlTopic?: string) => MRoomTopicEventContent;\n\nexport const makeTopicContent: MakeTopicContent = (topic, htmlTopic) => {\n const renderings = [];\n // Put HTML first because clients will render the first type in\n // the array that they understand\n if (isProvided(htmlTopic)) {\n renderings.push({ body: htmlTopic, mimetype: \"text/html\" });\n }\n if (isProvided(topic)) {\n renderings.push({ body: topic, mimetype: \"text/plain\" });\n }\n return { topic, [M_TOPIC.name]: { \"m.text\": renderings } };\n};\n\nexport type TopicState = {\n text?: string;\n html?: string;\n};\n\nexport const parseTopicContent = (content: MRoomTopicEventContent): TopicState => {\n const mtopicParent = M_TOPIC.findIn<MTopicContent | IMessageRendering[]>(content as MTopicEvent);\n const mtopic = Array.isArray(mtopicParent) ? mtopicParent : mtopicParent?.[\"m.text\"];\n // TODO remove support for the old malformed m.topic arrays after a few releases (only allow array in m.text)\n // https://github.com/matrix-org/matrix-js-sdk/pull/4984#pullrequestreview-3174251065\n //const mtopic = M_TOPIC.findIn<MTopicContent>(content)?.[\"m.text\"];\n if (!Array.isArray(mtopic)) {\n return { text: content.topic ?? undefined };\n }\n const text =\n mtopic?.find((r) => !isProvided(r.mimetype) || r.mimetype === \"text/plain\")?.body ?? content.topic ?? undefined;\n const html = mtopic?.find((r) => r.mimetype === \"text/html\")?.body;\n return { text, html };\n};\n\n/**\n * Beacon event helpers\n */\nexport type MakeBeaconInfoContent = (\n timeout: number,\n isLive?: boolean,\n description?: string,\n assetType?: LocationAssetType,\n timestamp?: number,\n) => MBeaconInfoEventContent;\n\nexport const makeBeaconInfoContent: MakeBeaconInfoContent = (timeout, isLive, description, assetType, timestamp) => ({\n description,\n timeout,\n live: isLive,\n [M_TIMESTAMP.name]: timestamp || Date.now(),\n [M_ASSET.name]: {\n type: assetType ?? LocationAssetType.Self,\n },\n});\n\nexport type BeaconInfoState = MBeaconInfoContent & {\n assetType?: LocationAssetType;\n timestamp?: number;\n};\n/**\n * Flatten beacon info event content\n */\nexport const parseBeaconInfoContent = (content: MBeaconInfoEventContent): BeaconInfoState => {\n const { description, timeout, live } = content;\n const timestamp = M_TIMESTAMP.findIn<number>(content) ?? undefined;\n const asset = M_ASSET.findIn<MAssetContent>(content);\n\n return {\n description,\n timeout,\n live,\n assetType: asset?.type,\n timestamp,\n };\n};\n\nexport type MakeBeaconContent = (\n uri: string,\n timestamp: number,\n beaconInfoEventId: string,\n description?: string,\n) => MBeaconEventContent;\n\nexport const makeBeaconContent: MakeBeaconContent = (uri, timestamp, beaconInfoEventId, description) => ({\n [M_LOCATION.name]: {\n description,\n uri,\n },\n [M_TIMESTAMP.name]: timestamp,\n \"m.relates_to\": {\n rel_type: REFERENCE_RELATION.name,\n event_id: beaconInfoEventId,\n },\n});\n\nexport type BeaconLocationState = Omit<MLocationContent, \"uri\"> & {\n uri?: string; // override from MLocationContent to allow optionals\n timestamp?: number;\n};\n\nexport const parseBeaconContent = (content: MBeaconEventContent): BeaconLocationState => {\n const location = M_LOCATION.findIn<MLocationContent>(content);\n const timestamp = M_TIMESTAMP.findIn<number>(content) ?? undefined;\n\n return {\n description: location?.description,\n uri: location?.uri,\n timestamp,\n };\n};\n"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,OAAO,QAAQ,mBAAmB;AAC3C,SAAiCC,MAAM,EAAEC,kBAAkB,QAAQ,+BAA+B;AAClG,SAASC,UAAU,QAAQ,qCAAqC;AAChE,SACIC,OAAO,EACPC,iBAAiB,EACjBC,UAAU,EACVC,WAAW,QAMR,sBAAsB;AAC7B,SAA0DC,OAAO,QAA0B,mBAAmB;AAG9G;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAACC,IAAY,EAAEC,Q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,IAAI,GAAG;IACfhB,WAAW;IACXH;EACJ,CAAC;EACD,CAACjB,WAAW,CAACoC,IAAI,GAAGjB,SAAS;EAC7B,cAAc,EAAE;IACZ4D,QAAQ,EAAEpF,kBAAkB,CAACyC,IAAI;IACjC4C,QAAQ,EAAEF;EACd;AACJ,CAAC,CAAC;AAOF,OAAO,IAAMG,kBAAkB,GAAIxB,OAA4B,IAA0B;EAAA,IAAAyB,oBAAA;EACrF,IAAMrC,QAAQ,GAAG9C,UAAU,CAAC+C,MAAM,CAAmBW,OAAO,CAAC;EAC7D,IAAMtC,SAAS,IAAA+D,oBAAA,GAAGlF,WAAW,CAAC8C,MAAM,CAASW,OAAO,CAAC,cAAAyB,oBAAA,cAAAA,oBAAA,GAAIvD,SAAS;EAElE,OAAO;IACHP,WAAW,EAAEyB,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEzB,WAAW;IAClCH,GAAG,EAAE4B,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAE5B,GAAG;IAClBE;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
@@ -1,17 +1,17 @@
1
- /*
2
- Copyright 2015 - 2024 The Matrix.org Foundation C.I.C.
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
1
+ /*
2
+ Copyright 2015 - 2024 The Matrix.org Foundation C.I.C.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
15
  */
16
16
 
17
17
  // Validation based on https://spec.matrix.org/v1.12/appendices/#server-name
@@ -30,28 +30,28 @@ function validateMediaId(mediaId) {
30
30
  return (matches === null || matches === void 0 ? void 0 : matches[0]) === mediaId;
31
31
  }
32
32
 
33
- /**
34
- * Get the HTTP URL for an MXC URI.
35
- * @param baseUrl - The base homeserver url which has a content repo.
36
- * @param mxc - The mxc:// URI.
37
- * @param width - The desired width of the thumbnail.
38
- * @param height - The desired height of the thumbnail.
39
- * @param resizeMethod - The thumbnail resize method to use, either
40
- * "crop" or "scale".
41
- * @param allowDirectLinks - If true, return any non-mxc URLs
42
- * directly. Fetching such URLs will leak information about the user to
43
- * anyone they share a room with. If false, will return the emptry string
44
- * for such URLs.
45
- * @param allowRedirects - If true, the caller supports the URL being 307 or
46
- * 308 redirected to another resource upon request. If false, redirects
47
- * are not expected. Implied `true` when `useAuthentication` is `true`.
48
- * @param useAuthentication - If true, the caller supports authenticated
49
- * media and wants an authentication-required URL. Note that server support
50
- * for authenticated media will *not* be checked - it is the caller's responsibility
51
- * to do so before calling this function. Note also that `useAuthentication`
52
- * implies `allowRedirects`. Defaults to false (unauthenticated endpoints).
53
- * @param animated - Whether the desired thumbnail should be animated.
54
- * @returns The complete URL to the content, may be an empty string if the provided mxc is not valid.
33
+ /**
34
+ * Get the HTTP URL for an MXC URI.
35
+ * @param baseUrl - The base homeserver url which has a content repo.
36
+ * @param mxc - The mxc:// URI.
37
+ * @param width - The desired width of the thumbnail.
38
+ * @param height - The desired height of the thumbnail.
39
+ * @param resizeMethod - The thumbnail resize method to use, either
40
+ * "crop" or "scale".
41
+ * @param allowDirectLinks - If true, return any non-mxc URLs
42
+ * directly. Fetching such URLs will leak information about the user to
43
+ * anyone they share a room with. If false, will return the emptry string
44
+ * for such URLs.
45
+ * @param allowRedirects - If true, the caller supports the URL being 307 or
46
+ * 308 redirected to another resource upon request. If false, redirects
47
+ * are not expected. Implied `true` when `useAuthentication` is `true`.
48
+ * @param useAuthentication - If true, the caller supports authenticated
49
+ * media and wants an authentication-required URL. Note that server support
50
+ * for authenticated media will *not* be checked - it is the caller's responsibility
51
+ * to do so before calling this function. Note also that `useAuthentication`
52
+ * implies `allowRedirects`. Defaults to false (unauthenticated endpoints).
53
+ * @param animated - Whether the desired thumbnail should be animated.
54
+ * @returns The complete URL to the content, may be an empty string if the provided mxc is not valid.
55
55
  */
56
56
  export function getHttpUriForMxc(baseUrl, mxc, width, height, resizeMethod) {
57
57
  var allowDirectLinks = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
@@ -1 +1 @@
1
- {"version":3,"file":"content-repo.js","names":["serverNameRegex","validateServerName","serverName","matches","exec","mediaIdRegex","validateMediaId","mediaId","getHttpUriForMxc","baseUrl","mxc","width","height","resizeMethod","allowDirectLinks","arguments","length","undefined","allowRedirects","useAuthentication","animated","startsWith","rest","slice","split","prefix","isThumbnailRequest","verb","concat","url","URL","searchParams","set","Math","round","toString","String","JSON","stringify","href"],"sources":["../src/content-repo.ts"],"sourcesContent":["/*\r\nCopyright 2015 - 2024 The Matrix.org Foundation C.I.C.\r\n\r\nLicensed under the Apache License, Version 2.0 (the \"License\");\r\nyou may not use this file except in compliance with the License.\r\nYou may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nUnless required by applicable law or agreed to in writing, software\r\ndistributed under the License is distributed on an \"AS IS\" BASIS,\r\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\nSee the License for the specific language governing permissions and\r\nlimitations under the License.\r\n*/\r\n\r\n// Validation based on https://spec.matrix.org/v1.12/appendices/#server-name\r\n// We do not use the validation described in https://spec.matrix.org/v1.12/client-server-api/#security-considerations-5\r\n// as it'd wrongly make all MXCs invalid due to not allowing `[].:` in server names.\r\nconst serverNameRegex =\r\n /^(?:(?:\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})|(?:\\[[\\dA-Fa-f:.]{2,45}])|(?:[A-Za-z\\d\\-.]{1,255}))(?::\\d{1,5})?$/;\r\nfunction validateServerName(serverName: string): boolean {\r\n const matches = serverNameRegex.exec(serverName);\r\n return matches?.[0] === serverName;\r\n}\r\n\r\n// Validation based on https://spec.matrix.org/v1.12/client-server-api/#security-considerations-5\r\nconst mediaIdRegex = /^[\\w-]+$/;\r\nfunction validateMediaId(mediaId: string): boolean {\r\n const matches = mediaIdRegex.exec(mediaId);\r\n return matches?.[0] === mediaId;\r\n}\r\n\r\n/**\r\n * Get the HTTP URL for an MXC URI.\r\n * @param baseUrl - The base homeserver url which has a content repo.\r\n * @param mxc - The mxc:// URI.\r\n * @param width - The desired width of the thumbnail.\r\n * @param height - The desired height of the thumbnail.\r\n * @param resizeMethod - The thumbnail resize method to use, either\r\n * \"crop\" or \"scale\".\r\n * @param allowDirectLinks - If true, return any non-mxc URLs\r\n * directly. Fetching such URLs will leak information about the user to\r\n * anyone they share a room with. If false, will return the emptry string\r\n * for such URLs.\r\n * @param allowRedirects - If true, the caller supports the URL being 307 or\r\n * 308 redirected to another resource upon request. If false, redirects\r\n * are not expected. Implied `true` when `useAuthentication` is `true`.\r\n * @param useAuthentication - If true, the caller supports authenticated\r\n * media and wants an authentication-required URL. Note that server support\r\n * for authenticated media will *not* be checked - it is the caller's responsibility\r\n * to do so before calling this function. Note also that `useAuthentication`\r\n * implies `allowRedirects`. Defaults to false (unauthenticated endpoints).\r\n * @param animated - Whether the desired thumbnail should be animated.\r\n * @returns The complete URL to the content, may be an empty string if the provided mxc is not valid.\r\n */\r\nexport function getHttpUriForMxc(\r\n baseUrl: string,\r\n mxc?: string,\r\n width?: number,\r\n height?: number,\r\n resizeMethod?: string,\r\n allowDirectLinks = false,\r\n allowRedirects?: boolean,\r\n useAuthentication?: boolean,\r\n animated?: boolean,\r\n): string {\r\n if (typeof mxc !== \"string\" || !mxc) {\r\n return \"\";\r\n }\r\n if (!mxc.startsWith(\"mxc://\")) {\r\n if (allowDirectLinks) {\r\n return mxc;\r\n } else {\r\n return \"\";\r\n }\r\n }\r\n\r\n const [serverName, mediaId, ...rest] = mxc.slice(6).split(\"/\");\r\n if (rest.length > 0 || !validateServerName(serverName) || !validateMediaId(mediaId)) {\r\n return \"\";\r\n }\r\n\r\n if (useAuthentication) {\r\n allowRedirects = true; // per docs (MSC3916 always expects redirects)\r\n\r\n // Dev note: MSC3916 removes `allow_redirect` entirely, but\r\n // for explicitness we set it here. This makes it slightly more obvious to\r\n // callers, hopefully.\r\n }\r\n\r\n let prefix: string;\r\n const isThumbnailRequest = !!width || !!height || !!resizeMethod;\r\n const verb = isThumbnailRequest ? \"thumbnail\" : \"download\";\r\n if (useAuthentication) {\r\n prefix = `/_matrix/client/v1/media/${verb}`;\r\n } else {\r\n prefix = `/_matrix/media/v3/${verb}`;\r\n }\r\n\r\n const url = new URL(`${prefix}/${serverName}/${mediaId}`, baseUrl);\r\n\r\n if (width) {\r\n url.searchParams.set(\"width\", Math.round(width).toString());\r\n }\r\n if (height) {\r\n url.searchParams.set(\"height\", Math.round(height).toString());\r\n }\r\n if (resizeMethod) {\r\n url.searchParams.set(\"method\", resizeMethod);\r\n }\r\n if (animated !== undefined) {\r\n url.searchParams.set(\"animated\", String(animated));\r\n }\r\n\r\n if (typeof allowRedirects === \"boolean\") {\r\n // We add this after, so we don't convert everything to a thumbnail request.\r\n url.searchParams.set(\"allow_redirect\", JSON.stringify(allowRedirects));\r\n }\r\n\r\n return url.href;\r\n}\r\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,IAAMA,eAAe,GACjB,8GAA8G;AAClH,SAASC,kBAAkBA,CAACC,UAAkB,EAAW;EACrD,IAAMC,OAAO,GAAGH,eAAe,CAACI,IAAI,CAACF,UAAU,CAAC;EAChD,OAAO,CA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ACtD;EAEA,IAAI,OAAOF,cAAc,KAAK,SAAS,EAAE;IACrC;IACAW,GAAG,CAACE,YAAY,CAACC,GAAG,CAAC,gBAAgB,EAAEK,IAAI,CAACC,SAAS,CAACpB,cAAc,CAAC,CAAC;EAC1E;EAEA,OAAOW,GAAG,CAACU,IAAI;AACnB","ignoreList":[]}
1
+ {"version":3,"file":"content-repo.js","names":["serverNameRegex","validateServerName","serverName","matches","exec","mediaIdRegex","validateMediaId","mediaId","getHttpUriForMxc","baseUrl","mxc","width","height","resizeMethod","allowDirectLinks","arguments","length","undefined","allowRedirects","useAuthentication","animated","startsWith","rest","slice","split","prefix","isThumbnailRequest","verb","concat","url","URL","searchParams","set","Math","round","toString","String","JSON","stringify","href"],"sources":["../src/content-repo.ts"],"sourcesContent":["/*\nCopyright 2015 - 2024 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// Validation based on https://spec.matrix.org/v1.12/appendices/#server-name\n// We do not use the validation described in https://spec.matrix.org/v1.12/client-server-api/#security-considerations-5\n// as it'd wrongly make all MXCs invalid due to not allowing `[].:` in server names.\nconst serverNameRegex =\n /^(?:(?:\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})|(?:\\[[\\dA-Fa-f:.]{2,45}])|(?:[A-Za-z\\d\\-.]{1,255}))(?::\\d{1,5})?$/;\nfunction validateServerName(serverName: string): boolean {\n const matches = serverNameRegex.exec(serverName);\n return matches?.[0] === serverName;\n}\n\n// Validation based on https://spec.matrix.org/v1.12/client-server-api/#security-considerations-5\nconst mediaIdRegex = /^[\\w-]+$/;\nfunction validateMediaId(mediaId: string): boolean {\n const matches = mediaIdRegex.exec(mediaId);\n return matches?.[0] === mediaId;\n}\n\n/**\n * Get the HTTP URL for an MXC URI.\n * @param baseUrl - The base homeserver url which has a content repo.\n * @param mxc - The mxc:// URI.\n * @param width - The desired width of the thumbnail.\n * @param height - The desired height of the thumbnail.\n * @param resizeMethod - The thumbnail resize method to use, either\n * \"crop\" or \"scale\".\n * @param allowDirectLinks - If true, return any non-mxc URLs\n * directly. Fetching such URLs will leak information about the user to\n * anyone they share a room with. If false, will return the emptry string\n * for such URLs.\n * @param allowRedirects - If true, the caller supports the URL being 307 or\n * 308 redirected to another resource upon request. If false, redirects\n * are not expected. Implied `true` when `useAuthentication` is `true`.\n * @param useAuthentication - If true, the caller supports authenticated\n * media and wants an authentication-required URL. Note that server support\n * for authenticated media will *not* be checked - it is the caller's responsibility\n * to do so before calling this function. Note also that `useAuthentication`\n * implies `allowRedirects`. Defaults to false (unauthenticated endpoints).\n * @param animated - Whether the desired thumbnail should be animated.\n * @returns The complete URL to the content, may be an empty string if the provided mxc is not valid.\n */\nexport function getHttpUriForMxc(\n baseUrl: string,\n mxc?: string,\n width?: number,\n height?: number,\n resizeMethod?: string,\n allowDirectLinks = false,\n allowRedirects?: boolean,\n useAuthentication?: boolean,\n animated?: boolean,\n): string {\n if (typeof mxc !== \"string\" || !mxc) {\n return \"\";\n }\n if (!mxc.startsWith(\"mxc://\")) {\n if (allowDirectLinks) {\n return mxc;\n } else {\n return \"\";\n }\n }\n\n const [serverName, mediaId, ...rest] = mxc.slice(6).split(\"/\");\n if (rest.length > 0 || !validateServerName(serverName) || !validateMediaId(mediaId)) {\n return \"\";\n }\n\n if (useAuthentication) {\n allowRedirects = true; // per docs (MSC3916 always expects redirects)\n\n // Dev note: MSC3916 removes `allow_redirect` entirely, but\n // for explicitness we set it here. This makes it slightly more obvious to\n // callers, hopefully.\n }\n\n let prefix: string;\n const isThumbnailRequest = !!width || !!height || !!resizeMethod;\n const verb = isThumbnailRequest ? \"thumbnail\" : \"download\";\n if (useAuthentication) {\n prefix = `/_matrix/client/v1/media/${verb}`;\n } else {\n prefix = `/_matrix/media/v3/${verb}`;\n }\n\n const url = new URL(`${prefix}/${serverName}/${mediaId}`, baseUrl);\n\n if (width) {\n url.searchParams.set(\"width\", Math.round(width).toString());\n }\n if (height) {\n url.searchParams.set(\"height\", Math.round(height).toString());\n }\n if (resizeMethod) {\n url.searchParams.set(\"method\", resizeMethod);\n }\n if (animated !== undefined) {\n url.searchParams.set(\"animated\", String(animated));\n }\n\n if (typeof allowRedirects === \"boolean\") {\n // We add this after, so we don't convert everything to a thumbnail request.\n url.searchParams.set(\"allow_redirect\", JSON.stringify(allowRedirects));\n }\n\n return url.href;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,IAAMA,eAAe,GACjB,8GAA8G;AAClH,SAASC,kBAAkBA,CAACC,UAAkB,EAAW;EACrD,IAAMC,OAAO,GAAGH,eAAe,CAACI,IAAI,CAACF,UAAU,CAAC;EAChD,OAAO,CAAAC,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAG,CAAC,CAAC,MAAKD,UAAU;AACtC;;AAEA;AACA,IAAMG,YAAY,GAAG,UAAU;AAC/B,SAASC,eAAeA,CAACC,OAAe,EAAW;EAC/C,IAAMJ,OAAO,GAAGE,YAAY,CAACD,IAAI,CAACG,OAAO,CAAC;EAC1C,OAAO,CAAAJ,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAG,CAAC,CAAC,MAAKI,OAAO;AACnC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC5BC,OAAe,EACfC,GAAY,EACZC,KAAc,EACdC,MAAe,EACfC,YAAqB,EAKf;EAAA,IAJNC,g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