@unwanted/matrix-sdk-mini 34.13.0 → 36.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/git-revision.txt +1 -1
  2. package/lib/@types/event.d.ts +25 -0
  3. package/lib/@types/event.d.ts.map +1 -1
  4. package/lib/@types/event.js +5 -0
  5. package/lib/@types/event.js.map +1 -1
  6. package/lib/client.d.ts +44 -19
  7. package/lib/client.d.ts.map +1 -1
  8. package/lib/client.js +148 -90
  9. package/lib/client.js.map +1 -1
  10. package/lib/embedded.d.ts +4 -3
  11. package/lib/embedded.d.ts.map +1 -1
  12. package/lib/embedded.js +57 -74
  13. package/lib/embedded.js.map +1 -1
  14. package/lib/feature.d.ts.map +1 -1
  15. package/lib/feature.js +2 -1
  16. package/lib/feature.js.map +1 -1
  17. package/lib/http-api/errors.d.ts +3 -3
  18. package/lib/http-api/errors.js +3 -3
  19. package/lib/http-api/errors.js.map +1 -1
  20. package/lib/http-api/utils.js +2 -2
  21. package/lib/http-api/utils.js.map +1 -1
  22. package/lib/models/event-timeline.d.ts.map +1 -1
  23. package/lib/models/event-timeline.js +1 -21
  24. package/lib/models/event-timeline.js.map +1 -1
  25. package/lib/models/event.d.ts +11 -1
  26. package/lib/models/event.d.ts.map +1 -1
  27. package/lib/models/event.js +48 -5
  28. package/lib/models/event.js.map +1 -1
  29. package/lib/models/invites-ignorer-types.d.ts +27 -0
  30. package/lib/models/invites-ignorer-types.d.ts.map +1 -0
  31. package/lib/models/invites-ignorer-types.js +36 -0
  32. package/lib/models/invites-ignorer-types.js.map +1 -0
  33. package/lib/models/invites-ignorer.d.ts +2 -26
  34. package/lib/models/invites-ignorer.d.ts.map +1 -1
  35. package/lib/models/invites-ignorer.js +2 -27
  36. package/lib/models/invites-ignorer.js.map +1 -1
  37. package/lib/models/room-member.d.ts +6 -1
  38. package/lib/models/room-member.d.ts.map +1 -1
  39. package/lib/models/room-member.js +7 -1
  40. package/lib/models/room-member.js.map +1 -1
  41. package/lib/models/room.d.ts +6 -1
  42. package/lib/models/room.d.ts.map +1 -1
  43. package/lib/models/room.js +7 -1
  44. package/lib/models/room.js.map +1 -1
  45. package/lib/oidc/authorize.d.ts +2 -2
  46. package/lib/oidc/authorize.d.ts.map +1 -1
  47. package/lib/oidc/authorize.js +5 -5
  48. package/lib/oidc/authorize.js.map +1 -1
  49. package/lib/oidc/discovery.d.ts +8 -0
  50. package/lib/oidc/discovery.d.ts.map +1 -1
  51. package/lib/oidc/discovery.js +22 -11
  52. package/lib/oidc/discovery.js.map +1 -1
  53. package/lib/oidc/index.d.ts +3 -4
  54. package/lib/oidc/index.d.ts.map +1 -1
  55. package/lib/oidc/index.js.map +1 -1
  56. package/lib/oidc/register.js +3 -3
  57. package/lib/oidc/register.js.map +1 -1
  58. package/lib/oidc/tokenRefresher.d.ts.map +1 -1
  59. package/lib/oidc/tokenRefresher.js +6 -5
  60. package/lib/oidc/tokenRefresher.js.map +1 -1
  61. package/lib/oidc/validate.d.ts +9 -23
  62. package/lib/oidc/validate.d.ts.map +1 -1
  63. package/lib/oidc/validate.js +13 -28
  64. package/lib/oidc/validate.js.map +1 -1
  65. package/lib/randomstring.d.ts +30 -3
  66. package/lib/randomstring.d.ts.map +1 -1
  67. package/lib/randomstring.js +68 -16
  68. package/lib/randomstring.js.map +1 -1
  69. package/lib/store/indexeddb-local-backend.js +4 -2
  70. package/lib/store/indexeddb-local-backend.js.map +1 -1
  71. package/lib/testing.d.ts +17 -0
  72. package/lib/testing.d.ts.map +1 -1
  73. package/lib/testing.js +42 -0
  74. package/lib/testing.js.map +1 -1
  75. package/package.json +5 -5
  76. package/src/@types/event.ts +17 -0
  77. package/src/client.ts +87 -41
  78. package/src/embedded.ts +41 -51
  79. package/src/feature.ts +1 -0
  80. package/src/http-api/errors.ts +3 -3
  81. package/src/http-api/utils.ts +2 -2
  82. package/src/models/event-timeline.ts +1 -21
  83. package/src/models/event.ts +46 -0
  84. package/src/models/invites-ignorer-types.ts +48 -0
  85. package/src/models/invites-ignorer.ts +7 -42
  86. package/src/models/room-member.ts +16 -1
  87. package/src/models/room.ts +16 -1
  88. package/src/oidc/authorize.ts +7 -7
  89. package/src/oidc/discovery.ts +16 -10
  90. package/src/oidc/index.ts +3 -4
  91. package/src/oidc/register.ts +3 -3
  92. package/src/oidc/tokenRefresher.ts +3 -2
  93. package/src/oidc/validate.ts +40 -63
  94. package/src/randomstring.ts +65 -19
  95. package/src/store/indexeddb-local-backend.ts +2 -2
  96. package/src/testing.ts +41 -0
package/lib/client.js CHANGED
@@ -46,7 +46,7 @@ import { NotificationCountType } from "./models/room.js";
46
46
  import { EventType, LOCAL_NOTIFICATION_SETTINGS_PREFIX, MSC3912_RELATION_BASED_REDACTIONS_PROP, MsgType, PUSHER_ENABLED, RelationType, RoomCreateTypeField, RoomType, UNSTABLE_MSC3088_ENABLED, UNSTABLE_MSC3088_PURPOSE, UNSTABLE_MSC3089_TREE_SUBTYPE } from "./@types/event.js";
47
47
  import { GuestAccess, HistoryVisibility, Preset } from "./@types/partials.js";
48
48
  import { eventMapperFor } from "./event-mapper.js";
49
- import { randomString } from "./randomstring.js";
49
+ import { secureRandomString } from "./randomstring.js";
50
50
  import { DEFAULT_TREE_POWER_LEVELS_TEMPLATE, MSC3089TreeSpace } from "./models/MSC3089TreeSpace.js";
51
51
  import { SearchOrderBy } from "./@types/search.js";
52
52
  import { PushRuleActionName, PushRuleKind } from "./@types/PushRules.js";
@@ -63,6 +63,7 @@ import { getRelationsThreadFilter } from "./thread-utils.js";
63
63
  import { KnownMembership } from "./@types/membership.js";
64
64
  import { ServerCapabilities } from "./serverCapabilities.js";
65
65
  import { sha256 } from "./digest.js";
66
+ import { discoverAndValidateOIDCIssuerWellKnown, validateAuthMetadataAndKeys } from "./oidc/index.js";
66
67
  var SCROLLBACK_DELAY_MS = 3000;
67
68
  export var UNSTABLE_MSC3852_LAST_SEEN_UA = new UnstableValue("last_seen_user_agent", "org.matrix.msc3852.last_seen_user_agent");
68
69
  export var PendingEventOrdering = /*#__PURE__*/function (PendingEventOrdering) {
@@ -115,16 +116,13 @@ var SSO_ACTION_PARAM = new UnstableValue("action", "org.matrix.msc3824.action");
115
116
  */
116
117
  export class MatrixClient extends TypedEventEmitter {
117
118
  constructor(opts) {
118
- var _opts$logger, _opts$usingExternalCr, _this;
119
+ var _opts$logger, _this;
119
120
  // If a custom logger is provided, use it. Otherwise, default to the global
120
121
  // one in logger.ts.
121
122
  super();
122
123
  _this = this;
123
124
  _defineProperty(this, "logger", void 0);
124
125
  _defineProperty(this, "reEmitter", new TypedReEmitter(this));
125
- _defineProperty(this, "olmVersion", null);
126
- // populated after initCrypto
127
- _defineProperty(this, "usingExternalCrypto", false);
128
126
  _defineProperty(this, "_store", void 0);
129
127
  _defineProperty(this, "deviceId", void 0);
130
128
  _defineProperty(this, "credentials", void 0);
@@ -208,10 +206,9 @@ export class MatrixClient extends TypedEventEmitter {
208
206
  this.baseUrl = opts.baseUrl;
209
207
  this.idBaseUrl = opts.idBaseUrl;
210
208
  this.identityServer = opts.identityServer;
211
- this.usingExternalCrypto = (_opts$usingExternalCr = opts.usingExternalCrypto) !== null && _opts$usingExternalCr !== void 0 ? _opts$usingExternalCr : false;
212
209
  this.store = opts.store || new StubStore();
213
210
  this.deviceId = opts.deviceId || null;
214
- this.sessionId = randomString(10);
211
+ this.sessionId = secureRandomString(10);
215
212
  var userId = opts.userId || null;
216
213
  this.credentials = {
217
214
  userId
@@ -775,7 +772,7 @@ export class MatrixClient extends TypedEventEmitter {
775
772
  * @returns The array of users that are ignored (empty if none)
776
773
  */
777
774
  getIgnoredUsers() {
778
- var event = this.getAccountData("m.ignored_user_list");
775
+ var event = this.getAccountData(EventType.IgnoredUserList);
779
776
  if (!(event !== null && event !== void 0 && event.getContent()["ignored_users"])) return [];
780
777
  return Object.keys(event.getContent()["ignored_users"]);
781
778
  }
@@ -793,7 +790,7 @@ export class MatrixClient extends TypedEventEmitter {
793
790
  userIds.forEach(u => {
794
791
  content.ignored_users[u] = {};
795
792
  });
796
- return this.setAccountData("m.ignored_user_list", content);
793
+ return this.setAccountData(EventType.IgnoredUserList, content);
797
794
  }
798
795
 
799
796
  /**
@@ -3338,8 +3335,7 @@ export class MatrixClient extends TypedEventEmitter {
3338
3335
  if (_room5) {
3339
3336
  // Copy over a known event sender if we can
3340
3337
  for (var ev of sr.context.getTimeline()) {
3341
- var sender = _room5.getMember(ev.getSender());
3342
- if (!ev.sender && sender) ev.sender = sender;
3338
+ ev.setMetadata(_room5.currentState, false);
3343
3339
  }
3344
3340
  }
3345
3341
  searchResults.results.push(sr);
@@ -3835,7 +3831,7 @@ export class MatrixClient extends TypedEventEmitter {
3835
3831
  * @returns A new client secret
3836
3832
  */
3837
3833
  generateClientSecret() {
3838
- return randomString(32);
3834
+ return secureRandomString(32);
3839
3835
  }
3840
3836
 
3841
3837
  /**
@@ -4063,9 +4059,13 @@ export class MatrixClient extends TypedEventEmitter {
4063
4059
  /**
4064
4060
  * @returns Promise which resolves to a LoginResponse object
4065
4061
  * @returns Rejects: with an error response.
4062
+ *
4063
+ * @deprecated This method has unintuitive behaviour: it updates the `MatrixClient` instance with *some* of the
4064
+ * returned credentials. Instead, call {@link loginRequest} and create a new `MatrixClient` instance using the
4065
+ * results. See https://github.com/matrix-org/matrix-js-sdk/issues/4502.
4066
4066
  */
4067
4067
  login(loginType, data) {
4068
- return this.http.authedRequest(Method.Post, "/login", undefined, _objectSpread(_objectSpread({}, data), {}, {
4068
+ return this.loginRequest(_objectSpread(_objectSpread({}, data), {}, {
4069
4069
  type: loginType
4070
4070
  })).then(response => {
4071
4071
  if (response.access_token && response.user_id) {
@@ -4081,6 +4081,10 @@ export class MatrixClient extends TypedEventEmitter {
4081
4081
  /**
4082
4082
  * @returns Promise which resolves to a LoginResponse object
4083
4083
  * @returns Rejects: with an error response.
4084
+ *
4085
+ * @deprecated This method has unintuitive behaviour: it updates the `MatrixClient` instance with *some* of the
4086
+ * returned credentials. Instead, call {@link loginRequest} with `data.type: "m.login.password"`, and create a new
4087
+ * `MatrixClient` instance using the results. See https://github.com/matrix-org/matrix-js-sdk/issues/4502.
4084
4088
  */
4085
4089
  loginWithPassword(user, password) {
4086
4090
  return this.login("m.login.password", {
@@ -4126,6 +4130,10 @@ export class MatrixClient extends TypedEventEmitter {
4126
4130
  * @param token - Login token previously received from homeserver
4127
4131
  * @returns Promise which resolves to a LoginResponse object
4128
4132
  * @returns Rejects: with an error response.
4133
+ *
4134
+ * @deprecated This method has unintuitive behaviour: it updates the `MatrixClient` instance with *some* of the
4135
+ * returned credentials. Instead, call {@link loginRequest} with `data.type: "m.login.token"`, and create a new
4136
+ * `MatrixClient` instance using the results. See https://github.com/matrix-org/matrix-js-sdk/issues/4502.
4129
4137
  */
4130
4138
  loginWithToken(token) {
4131
4139
  return this.login("m.login.token", {
@@ -4133,6 +4141,23 @@ export class MatrixClient extends TypedEventEmitter {
4133
4141
  });
4134
4142
  }
4135
4143
 
4144
+ /**
4145
+ * Sends a `POST /login` request to the server.
4146
+ *
4147
+ * If successful, this will create a new device and access token for the user.
4148
+ *
4149
+ * @see {@link MatrixClient.loginFlows} which makes a `GET /login` request.
4150
+ * @see https://spec.matrix.org/v1.13/client-server-api/#post_matrixclientv3login
4151
+ *
4152
+ * @param data - Credentials and other details for the login request.
4153
+ */
4154
+ loginRequest(data) {
4155
+ var _this39 = this;
4156
+ return _asyncToGenerator(function* () {
4157
+ return yield _this39.http.authedRequest(Method.Post, "/login", undefined, data);
4158
+ })();
4159
+ }
4160
+
4136
4161
  /**
4137
4162
  * Logs out the current session.
4138
4163
  * Obviously, further calls that require authorisation should fail after this
@@ -4144,14 +4169,14 @@ export class MatrixClient extends TypedEventEmitter {
4144
4169
  */
4145
4170
  logout() {
4146
4171
  var _arguments7 = arguments,
4147
- _this39 = this;
4172
+ _this40 = this;
4148
4173
  return _asyncToGenerator(function* () {
4149
4174
  var stopClient = _arguments7.length > 0 && _arguments7[0] !== undefined ? _arguments7[0] : false;
4150
4175
  if (stopClient) {
4151
- _this39.stopClient();
4152
- _this39.http.abort();
4176
+ _this40.stopClient();
4177
+ _this40.http.abort();
4153
4178
  }
4154
- return _this39.http.authedRequest(Method.Post, "/logout");
4179
+ return _this40.http.authedRequest(Method.Post, "/logout");
4155
4180
  })();
4156
4181
  }
4157
4182
 
@@ -4189,12 +4214,12 @@ export class MatrixClient extends TypedEventEmitter {
4189
4214
  * or UIA auth data.
4190
4215
  */
4191
4216
  requestLoginToken(auth) {
4192
- var _this40 = this;
4217
+ var _this41 = this;
4193
4218
  return _asyncToGenerator(function* () {
4194
4219
  var body = {
4195
4220
  auth
4196
4221
  };
4197
- return _this40.http.authedRequest(Method.Post, "/login/get_token", undefined,
4222
+ return _this41.http.authedRequest(Method.Post, "/login/get_token", undefined,
4198
4223
  // no query params
4199
4224
  body, {
4200
4225
  prefix: ClientPrefix.V1
@@ -4226,23 +4251,23 @@ export class MatrixClient extends TypedEventEmitter {
4226
4251
  * @returns Rejects: with an error response.
4227
4252
  */
4228
4253
  createRoom(options) {
4229
- var _this41 = this;
4254
+ var _this42 = this;
4230
4255
  return _asyncToGenerator(function* () {
4231
- var _this41$identityServe;
4256
+ var _this42$identityServe;
4232
4257
  // eslint-disable-line camelcase
4233
4258
  // some valid options include: room_alias_name, visibility, invite
4234
4259
 
4235
4260
  // inject the id_access_token if inviting 3rd party addresses
4236
4261
  var invitesNeedingToken = (options.invite_3pid || []).filter(i => !i.id_access_token);
4237
- if (invitesNeedingToken.length > 0 && (_this41$identityServe = _this41.identityServer) !== null && _this41$identityServe !== void 0 && _this41$identityServe.getAccessToken) {
4238
- var identityAccessToken = yield _this41.identityServer.getAccessToken();
4262
+ if (invitesNeedingToken.length > 0 && (_this42$identityServe = _this42.identityServer) !== null && _this42$identityServe !== void 0 && _this42$identityServe.getAccessToken) {
4263
+ var identityAccessToken = yield _this42.identityServer.getAccessToken();
4239
4264
  if (identityAccessToken) {
4240
4265
  for (var invite of invitesNeedingToken) {
4241
4266
  invite.id_access_token = identityAccessToken;
4242
4267
  }
4243
4268
  }
4244
4269
  }
4245
- return _this41.http.authedRequest(Method.Post, "/createRoom", undefined, options);
4270
+ return _this42.http.authedRequest(Method.Post, "/createRoom", undefined, options);
4246
4271
  })();
4247
4272
  }
4248
4273
 
@@ -4426,7 +4451,7 @@ export class MatrixClient extends TypedEventEmitter {
4426
4451
  * @returns Promise which resolves: the empty object, `{}`.
4427
4452
  */
4428
4453
  setRoomReadMarkersHttpRequest(roomId, rmEventId, rrEventId, rpEventId) {
4429
- var _this42 = this;
4454
+ var _this43 = this;
4430
4455
  return _asyncToGenerator(function* () {
4431
4456
  var path = utils.encodeUri("/rooms/$roomId/read_markers", {
4432
4457
  $roomId: roomId
@@ -4435,10 +4460,10 @@ export class MatrixClient extends TypedEventEmitter {
4435
4460
  [ReceiptType.FullyRead]: rmEventId,
4436
4461
  [ReceiptType.Read]: rrEventId
4437
4462
  };
4438
- if ((yield _this42.doesServerSupportUnstableFeature("org.matrix.msc2285.stable")) || (yield _this42.isVersionSupported("v1.4"))) {
4463
+ if ((yield _this43.doesServerSupportUnstableFeature("org.matrix.msc2285.stable")) || (yield _this43.isVersionSupported("v1.4"))) {
4439
4464
  content[ReceiptType.ReadPrivate] = rpEventId;
4440
4465
  }
4441
- return _this42.http.authedRequest(Method.Post, path, undefined, content);
4466
+ return _this43.http.authedRequest(Method.Post, path, undefined, content);
4442
4467
  })();
4443
4468
  }
4444
4469
 
@@ -4671,9 +4696,9 @@ export class MatrixClient extends TypedEventEmitter {
4671
4696
  * @returns `true` if supported, otherwise `false`
4672
4697
  */
4673
4698
  doesServerSupportExtendedProfiles() {
4674
- var _this43 = this;
4699
+ var _this44 = this;
4675
4700
  return _asyncToGenerator(function* () {
4676
- return _this43.doesServerSupportUnstableFeature(UNSTABLE_MSC4133_EXTENDED_PROFILES);
4701
+ return _this44.doesServerSupportUnstableFeature(UNSTABLE_MSC4133_EXTENDED_PROFILES);
4677
4702
  })();
4678
4703
  }
4679
4704
 
@@ -4683,9 +4708,9 @@ export class MatrixClient extends TypedEventEmitter {
4683
4708
  * @returns The prefix for use with `authedRequest`
4684
4709
  */
4685
4710
  getExtendedProfileRequestPrefix() {
4686
- var _this44 = this;
4711
+ var _this45 = this;
4687
4712
  return _asyncToGenerator(function* () {
4688
- if (yield _this44.doesServerSupportUnstableFeature("uk.tcpip.msc4133.stable")) {
4713
+ if (yield _this45.doesServerSupportUnstableFeature("uk.tcpip.msc4133.stable")) {
4689
4714
  return ClientPrefix.V3;
4690
4715
  }
4691
4716
  return "/_matrix/client/unstable/uk.tcpip.msc4133";
@@ -4703,15 +4728,15 @@ export class MatrixClient extends TypedEventEmitter {
4703
4728
  * @throws A M_NOT_FOUND error if the profile could not be found.
4704
4729
  */
4705
4730
  getExtendedProfile(userId) {
4706
- var _this45 = this;
4731
+ var _this46 = this;
4707
4732
  return _asyncToGenerator(function* () {
4708
- if (!(yield _this45.doesServerSupportExtendedProfiles())) {
4733
+ if (!(yield _this46.doesServerSupportExtendedProfiles())) {
4709
4734
  throw new Error("Server does not support extended profiles");
4710
4735
  }
4711
- return _this45.http.authedRequest(Method.Get, utils.encodeUri("/profile/$userId", {
4736
+ return _this46.http.authedRequest(Method.Get, utils.encodeUri("/profile/$userId", {
4712
4737
  $userId: userId
4713
4738
  }), undefined, undefined, {
4714
- prefix: yield _this45.getExtendedProfileRequestPrefix()
4739
+ prefix: yield _this46.getExtendedProfileRequestPrefix()
4715
4740
  });
4716
4741
  })();
4717
4742
  }
@@ -4728,16 +4753,16 @@ export class MatrixClient extends TypedEventEmitter {
4728
4753
  * @throws A M_NOT_FOUND error if the key was not set OR the profile could not be found.
4729
4754
  */
4730
4755
  getExtendedProfileProperty(userId, key) {
4731
- var _this46 = this;
4756
+ var _this47 = this;
4732
4757
  return _asyncToGenerator(function* () {
4733
- if (!(yield _this46.doesServerSupportExtendedProfiles())) {
4758
+ if (!(yield _this47.doesServerSupportExtendedProfiles())) {
4734
4759
  throw new Error("Server does not support extended profiles");
4735
4760
  }
4736
- var profile = yield _this46.http.authedRequest(Method.Get, utils.encodeUri("/profile/$userId/$key", {
4761
+ var profile = yield _this47.http.authedRequest(Method.Get, utils.encodeUri("/profile/$userId/$key", {
4737
4762
  $userId: userId,
4738
4763
  $key: key
4739
4764
  }), undefined, undefined, {
4740
- prefix: yield _this46.getExtendedProfileRequestPrefix()
4765
+ prefix: yield _this47.getExtendedProfileRequestPrefix()
4741
4766
  });
4742
4767
  return profile[key];
4743
4768
  })();
@@ -4753,19 +4778,19 @@ export class MatrixClient extends TypedEventEmitter {
4753
4778
  * @throws An error if the server does not support MSC4133 OR the server disallows editing the user profile.
4754
4779
  */
4755
4780
  setExtendedProfileProperty(key, value) {
4756
- var _this47 = this;
4781
+ var _this48 = this;
4757
4782
  return _asyncToGenerator(function* () {
4758
- if (!(yield _this47.doesServerSupportExtendedProfiles())) {
4783
+ if (!(yield _this48.doesServerSupportExtendedProfiles())) {
4759
4784
  throw new Error("Server does not support extended profiles");
4760
4785
  }
4761
- var userId = _this47.getUserId();
4762
- yield _this47.http.authedRequest(Method.Put, utils.encodeUri("/profile/$userId/$key", {
4786
+ var userId = _this48.getUserId();
4787
+ yield _this48.http.authedRequest(Method.Put, utils.encodeUri("/profile/$userId/$key", {
4763
4788
  $userId: userId,
4764
4789
  $key: key
4765
4790
  }), undefined, {
4766
4791
  [key]: value
4767
4792
  }, {
4768
- prefix: yield _this47.getExtendedProfileRequestPrefix()
4793
+ prefix: yield _this48.getExtendedProfileRequestPrefix()
4769
4794
  });
4770
4795
  })();
4771
4796
  }
@@ -4779,17 +4804,17 @@ export class MatrixClient extends TypedEventEmitter {
4779
4804
  * @throws An error if the server does not support MSC4133 OR the server disallows editing the user profile.
4780
4805
  */
4781
4806
  deleteExtendedProfileProperty(key) {
4782
- var _this48 = this;
4807
+ var _this49 = this;
4783
4808
  return _asyncToGenerator(function* () {
4784
- if (!(yield _this48.doesServerSupportExtendedProfiles())) {
4809
+ if (!(yield _this49.doesServerSupportExtendedProfiles())) {
4785
4810
  throw new Error("Server does not support extended profiles");
4786
4811
  }
4787
- var userId = _this48.getUserId();
4788
- yield _this48.http.authedRequest(Method.Delete, utils.encodeUri("/profile/$userId/$key", {
4812
+ var userId = _this49.getUserId();
4813
+ yield _this49.http.authedRequest(Method.Delete, utils.encodeUri("/profile/$userId/$key", {
4789
4814
  $userId: userId,
4790
4815
  $key: key
4791
4816
  }), undefined, undefined, {
4792
- prefix: yield _this48.getExtendedProfileRequestPrefix()
4817
+ prefix: yield _this49.getExtendedProfileRequestPrefix()
4793
4818
  });
4794
4819
  })();
4795
4820
  }
@@ -4805,16 +4830,16 @@ export class MatrixClient extends TypedEventEmitter {
4805
4830
  * @throws An error if the server does not support MSC4133 OR the server disallows editing the user profile.
4806
4831
  */
4807
4832
  patchExtendedProfile(profile) {
4808
- var _this49 = this;
4833
+ var _this50 = this;
4809
4834
  return _asyncToGenerator(function* () {
4810
- if (!(yield _this49.doesServerSupportExtendedProfiles())) {
4835
+ if (!(yield _this50.doesServerSupportExtendedProfiles())) {
4811
4836
  throw new Error("Server does not support extended profiles");
4812
4837
  }
4813
- var userId = _this49.getUserId();
4814
- return _this49.http.authedRequest(Method.Patch, utils.encodeUri("/profile/$userId", {
4838
+ var userId = _this50.getUserId();
4839
+ return _this50.http.authedRequest(Method.Patch, utils.encodeUri("/profile/$userId", {
4815
4840
  $userId: userId
4816
4841
  }), {}, profile, {
4817
- prefix: yield _this49.getExtendedProfileRequestPrefix()
4842
+ prefix: yield _this50.getExtendedProfileRequestPrefix()
4818
4843
  });
4819
4844
  })();
4820
4845
  }
@@ -4829,16 +4854,16 @@ export class MatrixClient extends TypedEventEmitter {
4829
4854
  * @throws An error if the server does not support MSC4133 OR the server disallows editing the user profile.
4830
4855
  */
4831
4856
  setExtendedProfile(profile) {
4832
- var _this50 = this;
4857
+ var _this51 = this;
4833
4858
  return _asyncToGenerator(function* () {
4834
- if (!(yield _this50.doesServerSupportExtendedProfiles())) {
4859
+ if (!(yield _this51.doesServerSupportExtendedProfiles())) {
4835
4860
  throw new Error("Server does not support extended profiles");
4836
4861
  }
4837
- var userId = _this50.getUserId();
4838
- yield _this50.http.authedRequest(Method.Put, utils.encodeUri("/profile/$userId", {
4862
+ var userId = _this51.getUserId();
4863
+ yield _this51.http.authedRequest(Method.Put, utils.encodeUri("/profile/$userId", {
4839
4864
  $userId: userId
4840
4865
  }), {}, profile, {
4841
- prefix: yield _this50.getExtendedProfileRequestPrefix()
4866
+ prefix: yield _this51.getExtendedProfileRequestPrefix()
4842
4867
  });
4843
4868
  })();
4844
4869
  }
@@ -4861,10 +4886,10 @@ export class MatrixClient extends TypedEventEmitter {
4861
4886
  * @returns Rejects: with an error response.
4862
4887
  */
4863
4888
  addThreePidOnly(data) {
4864
- var _this51 = this;
4889
+ var _this52 = this;
4865
4890
  return _asyncToGenerator(function* () {
4866
4891
  var path = "/account/3pid/add";
4867
- return _this51.http.authedRequest(Method.Post, path, undefined, data);
4892
+ return _this52.http.authedRequest(Method.Post, path, undefined, data);
4868
4893
  })();
4869
4894
  }
4870
4895
 
@@ -4880,10 +4905,10 @@ export class MatrixClient extends TypedEventEmitter {
4880
4905
  * @returns Rejects: with an error response.
4881
4906
  */
4882
4907
  bindThreePid(data) {
4883
- var _this52 = this;
4908
+ var _this53 = this;
4884
4909
  return _asyncToGenerator(function* () {
4885
4910
  var path = "/account/3pid/bind";
4886
- return _this52.http.authedRequest(Method.Post, path, undefined, data);
4911
+ return _this53.http.authedRequest(Method.Post, path, undefined, data);
4887
4912
  })();
4888
4913
  }
4889
4914
 
@@ -4901,15 +4926,15 @@ export class MatrixClient extends TypedEventEmitter {
4901
4926
  unbindThreePid(medium, address
4902
4927
  // eslint-disable-next-line camelcase
4903
4928
  ) {
4904
- var _this53 = this;
4929
+ var _this54 = this;
4905
4930
  return _asyncToGenerator(function* () {
4906
4931
  var path = "/account/3pid/unbind";
4907
4932
  var data = {
4908
4933
  medium,
4909
4934
  address,
4910
- id_server: _this53.getIdentityServerUrl(true)
4935
+ id_server: _this54.getIdentityServerUrl(true)
4911
4936
  };
4912
- return _this53.http.authedRequest(Method.Post, path, undefined, data);
4937
+ return _this54.http.authedRequest(Method.Post, path, undefined, data);
4913
4938
  })();
4914
4939
  }
4915
4940
 
@@ -5031,13 +5056,13 @@ export class MatrixClient extends TypedEventEmitter {
5031
5056
  * @returns Rejects: with an error response.
5032
5057
  */
5033
5058
  getPushers() {
5034
- var _this54 = this;
5059
+ var _this55 = this;
5035
5060
  return _asyncToGenerator(function* () {
5036
- var response = yield _this54.http.authedRequest(Method.Get, "/pushers");
5061
+ var response = yield _this55.http.authedRequest(Method.Get, "/pushers");
5037
5062
 
5038
5063
  // Migration path for clients that connect to a homeserver that does not support
5039
5064
  // MSC3881 yet, see https://github.com/matrix-org/matrix-spec-proposals/blob/kerry/remote-push-toggle/proposals/3881-remote-push-notification-toggling.md#migration
5040
- if (!(yield _this54.doesServerSupportUnstableFeature("org.matrix.msc3881"))) {
5065
+ if (!(yield _this55.doesServerSupportUnstableFeature("org.matrix.msc3881"))) {
5041
5066
  response.pushers = response.pushers.map(pusher => {
5042
5067
  if (!pusher.hasOwnProperty(PUSHER_ENABLED.name)) {
5043
5068
  pusher[PUSHER_ENABLED.name] = true;
@@ -5377,7 +5402,7 @@ export class MatrixClient extends TypedEventEmitter {
5377
5402
  * found MXIDs. Results where no user could be found will not be listed.
5378
5403
  */
5379
5404
  identityHashedLookup(addressPairs, identityAccessToken) {
5380
- var _this55 = this;
5405
+ var _this56 = this;
5381
5406
  return _asyncToGenerator(function* () {
5382
5407
  var params = {
5383
5408
  // addresses: ["email@example.org", "10005550000"],
@@ -5386,7 +5411,7 @@ export class MatrixClient extends TypedEventEmitter {
5386
5411
  };
5387
5412
 
5388
5413
  // Get hash information first before trying to do a lookup
5389
- var hashes = yield _this55.getIdentityHashDetails(identityAccessToken);
5414
+ var hashes = yield _this56.getIdentityHashDetails(identityAccessToken);
5390
5415
  if (!hashes || !hashes["lookup_pepper"] || !hashes["algorithms"]) {
5391
5416
  throw new Error("Unsupported identity server: bad response");
5392
5417
  }
@@ -5429,7 +5454,7 @@ export class MatrixClient extends TypedEventEmitter {
5429
5454
  } else {
5430
5455
  throw new Error("Unsupported identity server: unknown hash algorithm");
5431
5456
  }
5432
- var response = yield _this55.http.idServerRequest(Method.Post, "/lookup", params, IdentityPrefix.V2, identityAccessToken);
5457
+ var response = yield _this56.http.idServerRequest(Method.Post, "/lookup", params, IdentityPrefix.V2, identityAccessToken);
5433
5458
  if (!(response !== null && response !== void 0 && response["mappings"])) return []; // no results
5434
5459
 
5435
5460
  var foundAddresses = [];
@@ -5463,12 +5488,12 @@ export class MatrixClient extends TypedEventEmitter {
5463
5488
  * @returns Rejects: with an error response.
5464
5489
  */
5465
5490
  lookupThreePid(medium, address, identityAccessToken) {
5466
- var _this56 = this;
5491
+ var _this57 = this;
5467
5492
  return _asyncToGenerator(function* () {
5468
5493
  // Note: we're using the V2 API by calling this function, but our
5469
5494
  // function contract requires a V1 response. We therefore have to
5470
5495
  // convert it manually.
5471
- var response = yield _this56.identityHashedLookup([[address, medium]], identityAccessToken);
5496
+ var response = yield _this57.identityHashedLookup([[address, medium]], identityAccessToken);
5472
5497
  var result = response.find(p => p.address === address);
5473
5498
  if (!result) {
5474
5499
  return {};
@@ -5500,12 +5525,12 @@ export class MatrixClient extends TypedEventEmitter {
5500
5525
  * @returns Rejects: with an error response.
5501
5526
  */
5502
5527
  bulkLookupThreePids(query, identityAccessToken) {
5503
- var _this57 = this;
5528
+ var _this58 = this;
5504
5529
  return _asyncToGenerator(function* () {
5505
5530
  // Note: we're using the V2 API by calling this function, but our
5506
5531
  // function contract requires a V1 response. We therefore have to
5507
5532
  // convert it manually.
5508
- var response = yield _this57.identityHashedLookup(
5533
+ var response = yield _this58.identityHashedLookup(
5509
5534
  // We have to reverse the query order to get [address, medium] pairs
5510
5535
  query.map(p => [p[1], p[0]]), identityAccessToken);
5511
5536
  var v1results = [];
@@ -5706,16 +5731,16 @@ export class MatrixClient extends TypedEventEmitter {
5706
5731
  * @returns Promise which resolves to the created space.
5707
5732
  */
5708
5733
  unstableCreateFileTree(name) {
5709
- var _this58 = this;
5734
+ var _this59 = this;
5710
5735
  return _asyncToGenerator(function* () {
5711
5736
  var {
5712
5737
  room_id: roomId
5713
- } = yield _this58.createRoom({
5738
+ } = yield _this59.createRoom({
5714
5739
  name: name,
5715
5740
  preset: Preset.PrivateChat,
5716
5741
  power_level_content_override: _objectSpread(_objectSpread({}, DEFAULT_TREE_POWER_LEVELS_TEMPLATE), {}, {
5717
5742
  users: {
5718
- [_this58.getUserId()]: 100
5743
+ [_this59.getUserId()]: 100
5719
5744
  }
5720
5745
  }),
5721
5746
  creation_content: {
@@ -5729,7 +5754,7 @@ export class MatrixClient extends TypedEventEmitter {
5729
5754
  }
5730
5755
  }]
5731
5756
  });
5732
- return new MSC3089TreeSpace(_this58, roomId);
5757
+ return new MSC3089TreeSpace(_this59, roomId);
5733
5758
  })();
5734
5759
  }
5735
5760
 
@@ -5806,7 +5831,7 @@ export class MatrixClient extends TypedEventEmitter {
5806
5831
  * @param via - The list of servers which know about the room if only an ID was provided.
5807
5832
  */
5808
5833
  getRoomSummary(roomIdOrAlias, via) {
5809
- var _this59 = this;
5834
+ var _this60 = this;
5810
5835
  return _asyncToGenerator(function* () {
5811
5836
  var paramOpts = {
5812
5837
  prefix: "/_matrix/client/unstable/im.nheko.summary"
@@ -5815,7 +5840,7 @@ export class MatrixClient extends TypedEventEmitter {
5815
5840
  var path = utils.encodeUri("/summary/$roomid", {
5816
5841
  $roomid: roomIdOrAlias
5817
5842
  });
5818
- return yield _this59.http.authedRequest(Method.Get, path, {
5843
+ return yield _this60.http.authedRequest(Method.Get, path, {
5819
5844
  via
5820
5845
  }, undefined, paramOpts);
5821
5846
  } catch (e) {
@@ -5823,7 +5848,7 @@ export class MatrixClient extends TypedEventEmitter {
5823
5848
  var _path = utils.encodeUri("/rooms/$roomid/summary", {
5824
5849
  $roomid: roomIdOrAlias
5825
5850
  });
5826
- return yield _this59.http.authedRequest(Method.Get, _path, {
5851
+ return yield _this60.http.authedRequest(Method.Get, _path, {
5827
5852
  via
5828
5853
  }, undefined, paramOpts);
5829
5854
  } else {
@@ -5875,9 +5900,9 @@ export class MatrixClient extends TypedEventEmitter {
5875
5900
  * Fetches information about the user for the configured access token.
5876
5901
  */
5877
5902
  whoami() {
5878
- var _this60 = this;
5903
+ var _this61 = this;
5879
5904
  return _asyncToGenerator(function* () {
5880
- return _this60.http.authedRequest(Method.Get, "/account/whoami");
5905
+ return _this61.http.authedRequest(Method.Get, "/account/whoami");
5881
5906
  })();
5882
5907
  }
5883
5908
 
@@ -5888,7 +5913,7 @@ export class MatrixClient extends TypedEventEmitter {
5888
5913
  * @returns Rejects: when the request fails (module:http-api.MatrixError)
5889
5914
  */
5890
5915
  timestampToEvent(roomId, timestamp, dir) {
5891
- var _this61 = this;
5916
+ var _this62 = this;
5892
5917
  return _asyncToGenerator(function* () {
5893
5918
  var path = utils.encodeUri("/rooms/$roomId/timestamp_to_event", {
5894
5919
  $roomId: roomId
@@ -5898,7 +5923,7 @@ export class MatrixClient extends TypedEventEmitter {
5898
5923
  dir: dir
5899
5924
  };
5900
5925
  try {
5901
- return yield _this61.http.authedRequest(Method.Get, path, queryParams, undefined, {
5926
+ return yield _this62.http.authedRequest(Method.Get, path, queryParams, undefined, {
5902
5927
  prefix: ClientPrefix.V1
5903
5928
  });
5904
5929
  } catch (err) {
@@ -5914,7 +5939,7 @@ export class MatrixClient extends TypedEventEmitter {
5914
5939
  // both indicate that this endpoint+verb combination is
5915
5940
  // not supported.
5916
5941
  err.httpStatus === 404 || err.httpStatus === 405)) {
5917
- return yield _this61.http.authedRequest(Method.Get, path, queryParams, undefined, {
5942
+ return yield _this62.http.authedRequest(Method.Get, path, queryParams, undefined, {
5918
5943
  prefix: "/_matrix/client/unstable/org.matrix.msc3030"
5919
5944
  });
5920
5945
  }
@@ -5928,15 +5953,48 @@ export class MatrixClient extends TypedEventEmitter {
5928
5953
  * @returns Resolves: A promise of an object containing the OIDC issuer if configured
5929
5954
  * @returns Rejects: when the request fails (module:http-api.MatrixError)
5930
5955
  * @experimental - part of MSC2965
5956
+ * @deprecated in favour of getAuthMetadata
5931
5957
  */
5932
5958
  getAuthIssuer() {
5933
- var _this62 = this;
5959
+ var _this63 = this;
5934
5960
  return _asyncToGenerator(function* () {
5935
- return _this62.http.request(Method.Get, "/auth_issuer", undefined, undefined, {
5961
+ return _this63.http.request(Method.Get, "/auth_issuer", undefined, undefined, {
5936
5962
  prefix: ClientPrefix.Unstable + "/org.matrix.msc2965"
5937
5963
  });
5938
5964
  })();
5939
5965
  }
5966
+
5967
+ /**
5968
+ * Discover and validate delegated auth configuration
5969
+ * - delegated auth issuer openid-configuration is reachable
5970
+ * - delegated auth issuer openid-configuration is configured correctly for us
5971
+ * Fetches /auth_metadata falling back to legacy implementation using /auth_issuer followed by
5972
+ * https://oidc-issuer.example.com/.well-known/openid-configuration and other files linked therein.
5973
+ * When successful, validated metadata is returned
5974
+ * @returns validated authentication metadata and optionally signing keys
5975
+ * @throws when delegated auth config is invalid or unreachable
5976
+ * @experimental - part of MSC2965
5977
+ */
5978
+ getAuthMetadata() {
5979
+ var _this64 = this;
5980
+ return _asyncToGenerator(function* () {
5981
+ var authMetadata;
5982
+ try {
5983
+ authMetadata = yield _this64.http.request(Method.Get, "/auth_metadata", undefined, undefined, {
5984
+ prefix: ClientPrefix.Unstable + "/org.matrix.msc2965"
5985
+ });
5986
+ } catch (e) {
5987
+ if (e instanceof MatrixError && e.errcode === "M_UNRECOGNIZED") {
5988
+ var {
5989
+ issuer
5990
+ } = yield _this64.getAuthIssuer();
5991
+ return discoverAndValidateOIDCIssuerWellKnown(issuer);
5992
+ }
5993
+ throw e;
5994
+ }
5995
+ return validateAuthMetadataAndKeys(authMetadata);
5996
+ })();
5997
+ }
5940
5998
  }
5941
5999
  _defineProperty(MatrixClient, "RESTORE_BACKUP_ERROR_BAD_KEY", "RESTORE_BACKUP_ERROR_BAD_KEY");
5942
6000
  function getUnstableDelayQueryOpts(delayOpts) {