summaryrefslogtreecommitdiff
path: root/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-04-24 14:03:36 +0200
committerRaindropsSys <contact@minteck.org>2023-04-24 14:03:36 +0200
commit633c92eae865e957121e08de634aeee11a8b3992 (patch)
tree09d881bee1dae0b6eee49db1dfaf0f500240606c /includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto
parentc4657e4509733699c0f26a3c900bab47e915d5a0 (diff)
downloadpluralconnect-633c92eae865e957121e08de634aeee11a8b3992.tar.gz
pluralconnect-633c92eae865e957121e08de634aeee11a8b3992.tar.bz2
pluralconnect-633c92eae865e957121e08de634aeee11a8b3992.zip
Updated 18 files, added 1692 files and deleted includes/system/compare.inc (automated)
Diffstat (limited to 'includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto')
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.d.ts30
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.d.ts.map1
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.js78
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.js.map1
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.d.ts29
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.d.ts.map1
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.js94
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.js.map1
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.d.ts57
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.d.ts.map1
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.js126
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.js.map1
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.d.ts5
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.d.ts.map1
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.js32
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.js.map1
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.d.ts3
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.d.ts.map1
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.js26
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.js.map1
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.d.ts6
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.d.ts.map1
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.js45
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.js.map1
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.d.ts87
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.d.ts.map1
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.js301
-rw-r--r--includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.js.map1
28 files changed, 933 insertions, 0 deletions
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.d.ts b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.d.ts
new file mode 100644
index 0000000..023b36b
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.d.ts
@@ -0,0 +1,30 @@
+import { OlmMachine, UserId } from "@matrix-org/matrix-sdk-crypto-js";
+import { OutgoingRequestProcessor } from "./OutgoingRequestProcessor";
+/**
+ * KeyClaimManager: linearises calls to OlmMachine.getMissingSessions to avoid races
+ *
+ * We have one of these per `RustCrypto` (and hence per `MatrixClient`).
+ */
+export declare class KeyClaimManager {
+ private readonly olmMachine;
+ private readonly outgoingRequestProcessor;
+ private currentClaimPromise;
+ private stopped;
+ constructor(olmMachine: OlmMachine, outgoingRequestProcessor: OutgoingRequestProcessor);
+ /**
+ * Tell the KeyClaimManager to immediately stop processing requests.
+ *
+ * Any further calls, and any still in the queue, will fail with an error.
+ */
+ stop(): void;
+ /**
+ * Given a list of users, attempt to ensure that we have Olm Sessions active with each of their devices
+ *
+ * If we don't have an active olm session, we will claim a one-time key and start one.
+ *
+ * @param userList - list of userIDs to claim
+ */
+ ensureSessionsForUsers(userList: Array<UserId>): Promise<void>;
+ private ensureSessionsForUsersInner;
+}
+//# sourceMappingURL=KeyClaimManager.d.ts.map \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.d.ts.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.d.ts.map
new file mode 100644
index 0000000..6bca2ce
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"KeyClaimManager.d.ts","sourceRoot":"","sources":["../../src/rust-crypto/KeyClaimManager.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAEtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE;;;;GAIG;AACH,qBAAa,eAAe;IAKpB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,wBAAwB;IAL7C,OAAO,CAAC,mBAAmB,CAAgB;IAC3C,OAAO,CAAC,OAAO,CAAS;gBAGH,UAAU,EAAE,UAAU,EACtB,wBAAwB,EAAE,wBAAwB;IAKvE;;;;OAIG;IACI,IAAI,IAAI,IAAI;IAInB;;;;;;OAMG;IACI,sBAAsB,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YAcvD,2BAA2B;CAU5C"} \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.js b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.js
new file mode 100644
index 0000000..6565745
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.js
@@ -0,0 +1,78 @@
+"use strict";
+
+var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.KeyClaimManager = void 0;
+var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
+/*
+Copyright 2023 The Matrix.org Foundation C.I.C.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/**
+ * KeyClaimManager: linearises calls to OlmMachine.getMissingSessions to avoid races
+ *
+ * We have one of these per `RustCrypto` (and hence per `MatrixClient`).
+ */
+class KeyClaimManager {
+ constructor(olmMachine, outgoingRequestProcessor) {
+ this.olmMachine = olmMachine;
+ this.outgoingRequestProcessor = outgoingRequestProcessor;
+ (0, _defineProperty2.default)(this, "currentClaimPromise", void 0);
+ (0, _defineProperty2.default)(this, "stopped", false);
+ this.currentClaimPromise = Promise.resolve();
+ }
+
+ /**
+ * Tell the KeyClaimManager to immediately stop processing requests.
+ *
+ * Any further calls, and any still in the queue, will fail with an error.
+ */
+ stop() {
+ this.stopped = true;
+ }
+
+ /**
+ * Given a list of users, attempt to ensure that we have Olm Sessions active with each of their devices
+ *
+ * If we don't have an active olm session, we will claim a one-time key and start one.
+ *
+ * @param userList - list of userIDs to claim
+ */
+ ensureSessionsForUsers(userList) {
+ // The Rust-SDK requires that we only have one getMissingSessions process in flight at once. This little dance
+ // ensures that, by only having one call to ensureSessionsForUsersInner active at once (and making them
+ // queue up in order).
+ const prom = this.currentClaimPromise.catch(() => {
+ // any errors in the previous claim will have been reported already, so there is nothing to do here.
+ // we just throw away the error and start anew.
+ }).then(() => this.ensureSessionsForUsersInner(userList));
+ this.currentClaimPromise = prom;
+ return prom;
+ }
+ async ensureSessionsForUsersInner(userList) {
+ // bail out quickly if we've been stopped.
+ if (this.stopped) {
+ throw new Error(`Cannot ensure Olm sessions: shutting down`);
+ }
+ const claimRequest = await this.olmMachine.getMissingSessions(userList);
+ if (claimRequest) {
+ await this.outgoingRequestProcessor.makeOutgoingRequest(claimRequest);
+ }
+ }
+}
+exports.KeyClaimManager = KeyClaimManager;
+//# sourceMappingURL=KeyClaimManager.js.map \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.js.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.js.map
new file mode 100644
index 0000000..d3d4786
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/KeyClaimManager.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"KeyClaimManager.js","names":["KeyClaimManager","constructor","olmMachine","outgoingRequestProcessor","_defineProperty2","default","currentClaimPromise","Promise","resolve","stop","stopped","ensureSessionsForUsers","userList","prom","catch","then","ensureSessionsForUsersInner","Error","claimRequest","getMissingSessions","makeOutgoingRequest","exports"],"sources":["../../src/rust-crypto/KeyClaimManager.ts"],"sourcesContent":["/*\nCopyright 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { OlmMachine, UserId } from \"@matrix-org/matrix-sdk-crypto-js\";\n\nimport { OutgoingRequestProcessor } from \"./OutgoingRequestProcessor\";\n\n/**\n * KeyClaimManager: linearises calls to OlmMachine.getMissingSessions to avoid races\n *\n * We have one of these per `RustCrypto` (and hence per `MatrixClient`).\n */\nexport class KeyClaimManager {\n private currentClaimPromise: Promise<void>;\n private stopped = false;\n\n public constructor(\n private readonly olmMachine: OlmMachine,\n private readonly outgoingRequestProcessor: OutgoingRequestProcessor,\n ) {\n this.currentClaimPromise = Promise.resolve();\n }\n\n /**\n * Tell the KeyClaimManager to immediately stop processing requests.\n *\n * Any further calls, and any still in the queue, will fail with an error.\n */\n public stop(): void {\n this.stopped = true;\n }\n\n /**\n * Given a list of users, attempt to ensure that we have Olm Sessions active with each of their devices\n *\n * If we don't have an active olm session, we will claim a one-time key and start one.\n *\n * @param userList - list of userIDs to claim\n */\n public ensureSessionsForUsers(userList: Array<UserId>): Promise<void> {\n // The Rust-SDK requires that we only have one getMissingSessions process in flight at once. This little dance\n // ensures that, by only having one call to ensureSessionsForUsersInner active at once (and making them\n // queue up in order).\n const prom = this.currentClaimPromise\n .catch(() => {\n // any errors in the previous claim will have been reported already, so there is nothing to do here.\n // we just throw away the error and start anew.\n })\n .then(() => this.ensureSessionsForUsersInner(userList));\n this.currentClaimPromise = prom;\n return prom;\n }\n\n private async ensureSessionsForUsersInner(userList: Array<UserId>): Promise<void> {\n // bail out quickly if we've been stopped.\n if (this.stopped) {\n throw new Error(`Cannot ensure Olm sessions: shutting down`);\n }\n const claimRequest = await this.olmMachine.getMissingSessions(userList);\n if (claimRequest) {\n await this.outgoingRequestProcessor.makeOutgoingRequest(claimRequest);\n }\n }\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACO,MAAMA,eAAe,CAAC;EAIlBC,WAAWA,CACGC,UAAsB,EACtBC,wBAAkD,EACrE;IAAA,KAFmBD,UAAsB,GAAtBA,UAAsB;IAAA,KACtBC,wBAAkD,GAAlDA,wBAAkD;IAAA,IAAAC,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA,mBAJrD,KAAK;IAMnB,IAAI,CAACC,mBAAmB,GAAGC,OAAO,CAACC,OAAO,EAAE;EAChD;;EAEA;AACJ;AACA;AACA;AACA;EACWC,IAAIA,CAAA,EAAS;IAChB,IAAI,CAACC,OAAO,GAAG,IAAI;EACvB;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;EACWC,sBAAsBA,CAACC,QAAuB,EAAiB;IAClE;IACA;IACA;IACA,MAAMC,IAAI,GAAG,IAAI,CAACP,mBAAmB,CAChCQ,KAAK,CAAC,MAAM;MACT;MACA;IAAA,CACH,CAAC,CACDC,IAAI,CAAC,MAAM,IAAI,CAACC,2BAA2B,CAACJ,QAAQ,CAAC,CAAC;IAC3D,IAAI,CAACN,mBAAmB,GAAGO,IAAI;IAC/B,OAAOA,IAAI;EACf;EAEA,MAAcG,2BAA2BA,CAACJ,QAAuB,EAAiB;IAC9E;IACA,IAAI,IAAI,CAACF,OAAO,EAAE;MACd,MAAM,IAAIO,KAAK,CAAE,2CAA0C,CAAC;IAChE;IACA,MAAMC,YAAY,GAAG,MAAM,IAAI,CAAChB,UAAU,CAACiB,kBAAkB,CAACP,QAAQ,CAAC;IACvE,IAAIM,YAAY,EAAE;MACd,MAAM,IAAI,CAACf,wBAAwB,CAACiB,mBAAmB,CAACF,YAAY,CAAC;IACzE;EACJ;AACJ;AAACG,OAAA,CAAArB,eAAA,GAAAA,eAAA"} \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.d.ts b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.d.ts
new file mode 100644
index 0000000..d588f1b
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.d.ts
@@ -0,0 +1,29 @@
+import { OlmMachine } from "@matrix-org/matrix-sdk-crypto-js";
+import { IHttpOpts, MatrixHttpApi } from "../http-api";
+/**
+ * Common interface for all the request types returned by `OlmMachine.outgoingRequests`.
+ */
+export interface OutgoingRequest {
+ readonly id: string | undefined;
+ readonly type: number;
+}
+/**
+ * OutgoingRequestManager: turns `OutgoingRequest`s from the rust sdk into HTTP requests
+ *
+ * We have one of these per `RustCrypto` (and hence per `MatrixClient`), not that it does anything terribly complicated.
+ * It's responsible for:
+ *
+ * * holding the reference to the `MatrixHttpApi`
+ * * turning `OutgoingRequest`s from the rust backend into HTTP requests, and sending them
+ * * sending the results of such requests back to the rust backend.
+ */
+export declare class OutgoingRequestProcessor {
+ private readonly olmMachine;
+ private readonly http;
+ constructor(olmMachine: OlmMachine, http: MatrixHttpApi<IHttpOpts & {
+ onlyData: true;
+ }>);
+ makeOutgoingRequest(msg: OutgoingRequest): Promise<void>;
+ private rawJsonRequest;
+}
+//# sourceMappingURL=OutgoingRequestProcessor.d.ts.map \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.d.ts.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.d.ts.map
new file mode 100644
index 0000000..cdbc218
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"OutgoingRequestProcessor.d.ts","sourceRoot":"","sources":["../../src/rust-crypto/OutgoingRequestProcessor.ts"],"names":[],"mappings":"AAgBA,OAAO,EACH,UAAU,EAQb,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAU,MAAM,aAAa,CAAC;AAG/D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;GASG;AACH,qBAAa,wBAAwB;IAE7B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI;gBADJ,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,aAAa,CAAC,SAAS,GAAG;QAAE,QAAQ,EAAE,IAAI,CAAA;KAAE,CAAC;IAG3D,mBAAmB,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;YAoCvD,cAAc;CAwB/B"} \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.js b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.js
new file mode 100644
index 0000000..b8d1387
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.js
@@ -0,0 +1,94 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.OutgoingRequestProcessor = void 0;
+var _matrixSdkCryptoJs = require("@matrix-org/matrix-sdk-crypto-js");
+var _logger = require("../logger");
+var _httpApi = require("../http-api");
+/*
+Copyright 2023 The Matrix.org Foundation C.I.C.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/**
+ * OutgoingRequestManager: turns `OutgoingRequest`s from the rust sdk into HTTP requests
+ *
+ * We have one of these per `RustCrypto` (and hence per `MatrixClient`), not that it does anything terribly complicated.
+ * It's responsible for:
+ *
+ * * holding the reference to the `MatrixHttpApi`
+ * * turning `OutgoingRequest`s from the rust backend into HTTP requests, and sending them
+ * * sending the results of such requests back to the rust backend.
+ */
+class OutgoingRequestProcessor {
+ constructor(olmMachine, http) {
+ this.olmMachine = olmMachine;
+ this.http = http;
+ }
+ async makeOutgoingRequest(msg) {
+ let resp;
+
+ /* refer https://docs.rs/matrix-sdk-crypto/0.6.0/matrix_sdk_crypto/requests/enum.OutgoingRequests.html
+ * for the complete list of request types
+ */
+ if (msg instanceof _matrixSdkCryptoJs.KeysUploadRequest) {
+ resp = await this.rawJsonRequest(_httpApi.Method.Post, "/_matrix/client/v3/keys/upload", {}, msg.body);
+ } else if (msg instanceof _matrixSdkCryptoJs.KeysQueryRequest) {
+ resp = await this.rawJsonRequest(_httpApi.Method.Post, "/_matrix/client/v3/keys/query", {}, msg.body);
+ } else if (msg instanceof _matrixSdkCryptoJs.KeysClaimRequest) {
+ resp = await this.rawJsonRequest(_httpApi.Method.Post, "/_matrix/client/v3/keys/claim", {}, msg.body);
+ } else if (msg instanceof _matrixSdkCryptoJs.SignatureUploadRequest) {
+ resp = await this.rawJsonRequest(_httpApi.Method.Post, "/_matrix/client/v3/keys/signatures/upload", {}, msg.body);
+ } else if (msg instanceof _matrixSdkCryptoJs.KeysBackupRequest) {
+ resp = await this.rawJsonRequest(_httpApi.Method.Put, "/_matrix/client/v3/room_keys/keys", {}, msg.body);
+ } else if (msg instanceof _matrixSdkCryptoJs.ToDeviceRequest) {
+ const path = `/_matrix/client/v3/sendToDevice/${encodeURIComponent(msg.event_type)}/` + encodeURIComponent(msg.txn_id);
+ resp = await this.rawJsonRequest(_httpApi.Method.Put, path, {}, msg.body);
+ } else if (msg instanceof _matrixSdkCryptoJs.RoomMessageRequest) {
+ const path = `/_matrix/client/v3/room/${encodeURIComponent(msg.room_id)}/send/` + `${encodeURIComponent(msg.event_type)}/${encodeURIComponent(msg.txn_id)}`;
+ resp = await this.rawJsonRequest(_httpApi.Method.Put, path, {}, msg.body);
+ } else {
+ _logger.logger.warn("Unsupported outgoing message", Object.getPrototypeOf(msg));
+ resp = "";
+ }
+ if (msg.id) {
+ await this.olmMachine.markRequestAsSent(msg.id, msg.type, resp);
+ }
+ }
+ async rawJsonRequest(method, path, queryParams, body) {
+ const opts = {
+ // inhibit the JSON stringification and parsing within HttpApi.
+ json: false,
+ // nevertheless, we are sending, and accept, JSON.
+ headers: {
+ "Content-Type": "application/json",
+ "Accept": "application/json"
+ },
+ // we use the full prefix
+ prefix: ""
+ };
+ try {
+ const response = await this.http.authedRequest(method, path, queryParams, body, opts);
+ _logger.logger.info(`rust-crypto: successfully made HTTP request: ${method} ${path}`);
+ return response;
+ } catch (e) {
+ _logger.logger.warn(`rust-crypto: error making HTTP request: ${method} ${path}: ${e}`);
+ throw e;
+ }
+ }
+}
+exports.OutgoingRequestProcessor = OutgoingRequestProcessor;
+//# sourceMappingURL=OutgoingRequestProcessor.js.map \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.js.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.js.map
new file mode 100644
index 0000000..16beb60
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/OutgoingRequestProcessor.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"OutgoingRequestProcessor.js","names":["_matrixSdkCryptoJs","require","_logger","_httpApi","OutgoingRequestProcessor","constructor","olmMachine","http","makeOutgoingRequest","msg","resp","KeysUploadRequest","rawJsonRequest","Method","Post","body","KeysQueryRequest","KeysClaimRequest","SignatureUploadRequest","KeysBackupRequest","Put","ToDeviceRequest","path","encodeURIComponent","event_type","txn_id","RoomMessageRequest","room_id","logger","warn","Object","getPrototypeOf","id","markRequestAsSent","type","method","queryParams","opts","json","headers","prefix","response","authedRequest","info","e","exports"],"sources":["../../src/rust-crypto/OutgoingRequestProcessor.ts"],"sourcesContent":["/*\nCopyright 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport {\n OlmMachine,\n KeysBackupRequest,\n KeysClaimRequest,\n KeysQueryRequest,\n KeysUploadRequest,\n RoomMessageRequest,\n SignatureUploadRequest,\n ToDeviceRequest,\n} from \"@matrix-org/matrix-sdk-crypto-js\";\n\nimport { logger } from \"../logger\";\nimport { IHttpOpts, MatrixHttpApi, Method } from \"../http-api\";\nimport { QueryDict } from \"../utils\";\n\n/**\n * Common interface for all the request types returned by `OlmMachine.outgoingRequests`.\n */\nexport interface OutgoingRequest {\n readonly id: string | undefined;\n readonly type: number;\n}\n\n/**\n * OutgoingRequestManager: turns `OutgoingRequest`s from the rust sdk into HTTP requests\n *\n * We have one of these per `RustCrypto` (and hence per `MatrixClient`), not that it does anything terribly complicated.\n * It's responsible for:\n *\n * * holding the reference to the `MatrixHttpApi`\n * * turning `OutgoingRequest`s from the rust backend into HTTP requests, and sending them\n * * sending the results of such requests back to the rust backend.\n */\nexport class OutgoingRequestProcessor {\n public constructor(\n private readonly olmMachine: OlmMachine,\n private readonly http: MatrixHttpApi<IHttpOpts & { onlyData: true }>,\n ) {}\n\n public async makeOutgoingRequest(msg: OutgoingRequest): Promise<void> {\n let resp: string;\n\n /* refer https://docs.rs/matrix-sdk-crypto/0.6.0/matrix_sdk_crypto/requests/enum.OutgoingRequests.html\n * for the complete list of request types\n */\n if (msg instanceof KeysUploadRequest) {\n resp = await this.rawJsonRequest(Method.Post, \"/_matrix/client/v3/keys/upload\", {}, msg.body);\n } else if (msg instanceof KeysQueryRequest) {\n resp = await this.rawJsonRequest(Method.Post, \"/_matrix/client/v3/keys/query\", {}, msg.body);\n } else if (msg instanceof KeysClaimRequest) {\n resp = await this.rawJsonRequest(Method.Post, \"/_matrix/client/v3/keys/claim\", {}, msg.body);\n } else if (msg instanceof SignatureUploadRequest) {\n resp = await this.rawJsonRequest(Method.Post, \"/_matrix/client/v3/keys/signatures/upload\", {}, msg.body);\n } else if (msg instanceof KeysBackupRequest) {\n resp = await this.rawJsonRequest(Method.Put, \"/_matrix/client/v3/room_keys/keys\", {}, msg.body);\n } else if (msg instanceof ToDeviceRequest) {\n const path =\n `/_matrix/client/v3/sendToDevice/${encodeURIComponent(msg.event_type)}/` +\n encodeURIComponent(msg.txn_id);\n resp = await this.rawJsonRequest(Method.Put, path, {}, msg.body);\n } else if (msg instanceof RoomMessageRequest) {\n const path =\n `/_matrix/client/v3/room/${encodeURIComponent(msg.room_id)}/send/` +\n `${encodeURIComponent(msg.event_type)}/${encodeURIComponent(msg.txn_id)}`;\n resp = await this.rawJsonRequest(Method.Put, path, {}, msg.body);\n } else {\n logger.warn(\"Unsupported outgoing message\", Object.getPrototypeOf(msg));\n resp = \"\";\n }\n\n if (msg.id) {\n await this.olmMachine.markRequestAsSent(msg.id, msg.type, resp);\n }\n }\n\n private async rawJsonRequest(method: Method, path: string, queryParams: QueryDict, body: string): Promise<string> {\n const opts = {\n // inhibit the JSON stringification and parsing within HttpApi.\n json: false,\n\n // nevertheless, we are sending, and accept, JSON.\n headers: {\n \"Content-Type\": \"application/json\",\n \"Accept\": \"application/json\",\n },\n\n // we use the full prefix\n prefix: \"\",\n };\n\n try {\n const response = await this.http.authedRequest<string>(method, path, queryParams, body, opts);\n logger.info(`rust-crypto: successfully made HTTP request: ${method} ${path}`);\n return response;\n } catch (e) {\n logger.warn(`rust-crypto: error making HTTP request: ${method} ${path}: ${e}`);\n throw e;\n }\n }\n}\n"],"mappings":";;;;;;AAgBA,IAAAA,kBAAA,GAAAC,OAAA;AAWA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAyBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,wBAAwB,CAAC;EAC3BC,WAAWA,CACGC,UAAsB,EACtBC,IAAmD,EACtE;IAAA,KAFmBD,UAAsB,GAAtBA,UAAsB;IAAA,KACtBC,IAAmD,GAAnDA,IAAmD;EACrE;EAEH,MAAaC,mBAAmBA,CAACC,GAAoB,EAAiB;IAClE,IAAIC,IAAY;;IAEhB;AACR;AACA;IACQ,IAAID,GAAG,YAAYE,oCAAiB,EAAE;MAClCD,IAAI,GAAG,MAAM,IAAI,CAACE,cAAc,CAACC,eAAM,CAACC,IAAI,EAAE,gCAAgC,EAAE,CAAC,CAAC,EAAEL,GAAG,CAACM,IAAI,CAAC;IACjG,CAAC,MAAM,IAAIN,GAAG,YAAYO,mCAAgB,EAAE;MACxCN,IAAI,GAAG,MAAM,IAAI,CAACE,cAAc,CAACC,eAAM,CAACC,IAAI,EAAE,+BAA+B,EAAE,CAAC,CAAC,EAAEL,GAAG,CAACM,IAAI,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AI,CAAC;IACpE,CAAC,MAAM;MACHa,cAAM,CAACC,IAAI,CAAC,8BAA8B,EAAEC,MAAM,CAACC,cAAc,CAACtB,GAAG,CAAC,CAAC;MACvEC,IAAI,GAAG,EAAE;IACb;IAEA,IAAID,GAAG,CAACuB,EAAE,EAAE;MACR,MAAM,IAAI,CAAC1B,UAAU,CAAC2B,iBAAiB,CAACxB,GAAG,CAACuB,EAAE,EAAEvB,GAAG,CAACyB,IAAI,EAAExB,IAAI,CAAC;IACnE;EACJ;EAEA,MAAcE,cAAcA,CAACuB,MAAc,EAAEb,IAAY,EAAEc,WAAsB,EAAErB,IAAY,EAAmB;IAC9G,MAAMsB,IAAI,GAAG;MACT;MACAC,IAAI,EAAE,KAAK;MAEX;MACAC,OAAO,EAAE;QACL,cAAc,EAAE,kBAAkB;QAClC,QAAQ,EAAE;MACd,CAAC;MAED;MACAC,MAAM,EAAE;IACZ,CAAC;IAED,IAAI;MACA,MAAMC,QAAQ,GAAG,MAAM,IAAI,CAAClC,IAAI,CAACmC,aAAa,CAASP,MAAM,EAAEb,IAAI,EAAEc,WAAW,EAAErB,IAAI,EAAEsB,IAAI,CAAC;MAC7FT,cAAM,CAACe,IAAI,CAAE,gDAA+CR,MAAO,IAAGb,IAAK,EAAC,CAAC;MAC7E,OAAOmB,QAAQ;IACnB,CAAC,CAAC,OAAOG,CAAC,EAAE;MACRhB,cAAM,CAACC,IAAI,CAAE,2CAA0CM,MAAO,IAAGb,IAAK,KAAIsB,CAAE,EAAC,CAAC;MAC9E,MAAMA,CAAC;IACX;EACJ;AACJ;AAACC,OAAA,CAAAzC,wBAAA,GAAAA,wBAAA"} \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.d.ts b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.d.ts
new file mode 100644
index 0000000..f9f68dc
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.d.ts
@@ -0,0 +1,57 @@
+import { OlmMachine } from "@matrix-org/matrix-sdk-crypto-js";
+import { IContent, MatrixEvent } from "../models/event";
+import { Room } from "../models/room";
+import { KeyClaimManager } from "./KeyClaimManager";
+import { RoomMember } from "../models/room-member";
+import { OutgoingRequestProcessor } from "./OutgoingRequestProcessor";
+/**
+ * RoomEncryptor: responsible for encrypting messages to a given room
+ */
+export declare class RoomEncryptor {
+ private readonly olmMachine;
+ private readonly keyClaimManager;
+ private readonly outgoingRequestProcessor;
+ private readonly room;
+ private encryptionSettings;
+ private readonly prefixedLogger;
+ /**
+ * @param olmMachine - The rust-sdk's OlmMachine
+ * @param keyClaimManager - Our KeyClaimManager, which manages the queue of one-time-key claim requests
+ * @param room - The room we want to encrypt for
+ * @param encryptionSettings - body of the m.room.encryption event currently in force in this room
+ */
+ constructor(olmMachine: OlmMachine, keyClaimManager: KeyClaimManager, outgoingRequestProcessor: OutgoingRequestProcessor, room: Room, encryptionSettings: IContent);
+ /**
+ * Handle a new `m.room.encryption` event in this room
+ *
+ * @param config - The content of the encryption event
+ */
+ onCryptoEvent(config: IContent): void;
+ /**
+ * Handle a new `m.room.member` event in this room
+ *
+ * @param member - new membership state
+ */
+ onRoomMembership(member: RoomMember): void;
+ /**
+ * Prepare to encrypt events in this room.
+ *
+ * This ensures that we have a megolm session ready to use and that we have shared its key with all the devices
+ * in the room.
+ */
+ ensureEncryptionSession(): Promise<void>;
+ /**
+ * Discard any existing group session for this room
+ */
+ forceDiscardSession(): Promise<void>;
+ /**
+ * Encrypt an event for this room
+ *
+ * This will ensure that we have a megolm session for this room, share it with the devices in the room, and
+ * then encrypt the event using the session.
+ *
+ * @param event - Event to be encrypted.
+ */
+ encryptEvent(event: MatrixEvent): Promise<void>;
+}
+//# sourceMappingURL=RoomEncryptor.d.ts.map \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.d.ts.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.d.ts.map
new file mode 100644
index 0000000..52b231e
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"RoomEncryptor.d.ts","sourceRoot":"","sources":["../../src/rust-crypto/RoomEncryptor.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAsB,UAAU,EAAkB,MAAM,kCAAkC,CAAC;AAGlG,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE;;GAEG;AACH,qBAAa,aAAa;IAUlB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,wBAAwB;IACzC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,kBAAkB;IAb9B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAEhD;;;;;OAKG;gBAEkB,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,eAAe,EAChC,wBAAwB,EAAE,wBAAwB,EAClD,IAAI,EAAE,IAAI,EACnB,kBAAkB,EAAE,QAAQ;IAKxC;;;;OAIG;IACI,aAAa,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI;IAM5C;;;;OAIG;IACI,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAejD;;;;;OAKG;IACU,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC;IAiCrD;;OAEG;IACU,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjD;;;;;;;OAOG;IACU,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAgB/D"} \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.js b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.js
new file mode 100644
index 0000000..c805fe7
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.js
@@ -0,0 +1,126 @@
+"use strict";
+
+var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.RoomEncryptor = void 0;
+var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
+var _matrixSdkCryptoJs = require("@matrix-org/matrix-sdk-crypto-js");
+var _event = require("../@types/event");
+var _logger = require("../logger");
+/*
+Copyright 2023 The Matrix.org Foundation C.I.C.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/**
+ * RoomEncryptor: responsible for encrypting messages to a given room
+ */
+class RoomEncryptor {
+ /**
+ * @param olmMachine - The rust-sdk's OlmMachine
+ * @param keyClaimManager - Our KeyClaimManager, which manages the queue of one-time-key claim requests
+ * @param room - The room we want to encrypt for
+ * @param encryptionSettings - body of the m.room.encryption event currently in force in this room
+ */
+ constructor(olmMachine, keyClaimManager, outgoingRequestProcessor, room, encryptionSettings) {
+ this.olmMachine = olmMachine;
+ this.keyClaimManager = keyClaimManager;
+ this.outgoingRequestProcessor = outgoingRequestProcessor;
+ this.room = room;
+ this.encryptionSettings = encryptionSettings;
+ (0, _defineProperty2.default)(this, "prefixedLogger", void 0);
+ this.prefixedLogger = _logger.logger.withPrefix(`[${room.roomId} encryption]`);
+ }
+
+ /**
+ * Handle a new `m.room.encryption` event in this room
+ *
+ * @param config - The content of the encryption event
+ */
+ onCryptoEvent(config) {
+ if (JSON.stringify(this.encryptionSettings) != JSON.stringify(config)) {
+ this.prefixedLogger.error(`Ignoring m.room.encryption event which requests a change of config`);
+ }
+ }
+
+ /**
+ * Handle a new `m.room.member` event in this room
+ *
+ * @param member - new membership state
+ */
+ onRoomMembership(member) {
+ this.prefixedLogger.debug(`${member.membership} event for ${member.userId}`);
+ if (member.membership == "join" || member.membership == "invite" && this.room.shouldEncryptForInvitedMembers()) {
+ // make sure we are tracking the deviceList for this user
+ this.prefixedLogger.debug(`starting to track devices for: ${member.userId}`);
+ this.olmMachine.updateTrackedUsers([new _matrixSdkCryptoJs.UserId(member.userId)]);
+ }
+
+ // TODO: handle leaves (including our own)
+ }
+
+ /**
+ * Prepare to encrypt events in this room.
+ *
+ * This ensures that we have a megolm session ready to use and that we have shared its key with all the devices
+ * in the room.
+ */
+ async ensureEncryptionSession() {
+ if (this.encryptionSettings.algorithm !== "m.megolm.v1.aes-sha2") {
+ throw new Error(`Cannot encrypt in ${this.room.roomId} for unsupported algorithm '${this.encryptionSettings.algorithm}'`);
+ }
+ const members = await this.room.getEncryptionTargetMembers();
+ this.prefixedLogger.debug(`Encrypting for users (shouldEncryptForInvitedMembers: ${this.room.shouldEncryptForInvitedMembers()}):`, members.map(u => `${u.userId} (${u.membership})`));
+ const userList = members.map(u => new _matrixSdkCryptoJs.UserId(u.userId));
+ await this.keyClaimManager.ensureSessionsForUsers(userList);
+ this.prefixedLogger.debug("Sessions for users are ready; now sharing room key");
+ const rustEncryptionSettings = new _matrixSdkCryptoJs.EncryptionSettings();
+ /* FIXME historyVisibility, rotation, etc */
+
+ const shareMessages = await this.olmMachine.shareRoomKey(new _matrixSdkCryptoJs.RoomId(this.room.roomId), userList, rustEncryptionSettings);
+ if (shareMessages) {
+ for (const m of shareMessages) {
+ await this.outgoingRequestProcessor.makeOutgoingRequest(m);
+ }
+ }
+ }
+
+ /**
+ * Discard any existing group session for this room
+ */
+ async forceDiscardSession() {
+ const r = await this.olmMachine.invalidateGroupSession(new _matrixSdkCryptoJs.RoomId(this.room.roomId));
+ if (r) {
+ this.prefixedLogger.info("Discarded existing group session");
+ }
+ }
+
+ /**
+ * Encrypt an event for this room
+ *
+ * This will ensure that we have a megolm session for this room, share it with the devices in the room, and
+ * then encrypt the event using the session.
+ *
+ * @param event - Event to be encrypted.
+ */
+ async encryptEvent(event) {
+ await this.ensureEncryptionSession();
+ const encryptedContent = await this.olmMachine.encryptRoomEvent(new _matrixSdkCryptoJs.RoomId(this.room.roomId), event.getType(), JSON.stringify(event.getContent()));
+ event.makeEncrypted(_event.EventType.RoomMessageEncrypted, JSON.parse(encryptedContent), this.olmMachine.identityKeys.curve25519.toBase64(), this.olmMachine.identityKeys.ed25519.toBase64());
+ }
+}
+exports.RoomEncryptor = RoomEncryptor;
+//# sourceMappingURL=RoomEncryptor.js.map \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.js.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.js.map
new file mode 100644
index 0000000..aaa2afc
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/RoomEncryptor.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"RoomEncryptor.js","names":["_matrixSdkCryptoJs","require","_event","_logger","RoomEncryptor","constructor","olmMachine","keyClaimManager","outgoingRequestProcessor","room","encryptionSettings","_defineProperty2","default","prefixedLogger","logger","withPrefix","roomId","onCryptoEvent","config","JSON","stringify","error","onRoomMembership","member","debug","membership","userId","shouldEncryptForInvitedMembers","updateTrackedUsers","UserId","ensureEncryptionSession","algorithm","Error","members","getEncryptionTargetMembers","map","u","userList","ensureSessionsForUsers","rustEncryptionSettings","EncryptionSettings","shareMessages","shareRoomKey","RoomId","m","makeOutgoingRequest","forceDiscardSession","r","invalidateGroupSession","info","encryptEvent","event","encryptedContent","encryptRoomEvent","getType","getContent","makeEncrypted","EventType","RoomMessageEncrypted","parse","identityKeys","curve25519","toBase64","ed25519","exports"],"sources":["../../src/rust-crypto/RoomEncryptor.ts"],"sourcesContent":["/*\nCopyright 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { EncryptionSettings, OlmMachine, RoomId, UserId } from \"@matrix-org/matrix-sdk-crypto-js\";\n\nimport { EventType } from \"../@types/event\";\nimport { IContent, MatrixEvent } from \"../models/event\";\nimport { Room } from \"../models/room\";\nimport { logger, PrefixedLogger } from \"../logger\";\nimport { KeyClaimManager } from \"./KeyClaimManager\";\nimport { RoomMember } from \"../models/room-member\";\nimport { OutgoingRequestProcessor } from \"./OutgoingRequestProcessor\";\n\n/**\n * RoomEncryptor: responsible for encrypting messages to a given room\n */\nexport class RoomEncryptor {\n private readonly prefixedLogger: PrefixedLogger;\n\n /**\n * @param olmMachine - The rust-sdk's OlmMachine\n * @param keyClaimManager - Our KeyClaimManager, which manages the queue of one-time-key claim requests\n * @param room - The room we want to encrypt for\n * @param encryptionSettings - body of the m.room.encryption event currently in force in this room\n */\n public constructor(\n private readonly olmMachine: OlmMachine,\n private readonly keyClaimManager: KeyClaimManager,\n private readonly outgoingRequestProcessor: OutgoingRequestProcessor,\n private readonly room: Room,\n private encryptionSettings: IContent,\n ) {\n this.prefixedLogger = logger.withPrefix(`[${room.roomId} encryption]`);\n }\n\n /**\n * Handle a new `m.room.encryption` event in this room\n *\n * @param config - The content of the encryption event\n */\n public onCryptoEvent(config: IContent): void {\n if (JSON.stringify(this.encryptionSettings) != JSON.stringify(config)) {\n this.prefixedLogger.error(`Ignoring m.room.encryption event which requests a change of config`);\n }\n }\n\n /**\n * Handle a new `m.room.member` event in this room\n *\n * @param member - new membership state\n */\n public onRoomMembership(member: RoomMember): void {\n this.prefixedLogger.debug(`${member.membership} event for ${member.userId}`);\n\n if (\n member.membership == \"join\" ||\n (member.membership == \"invite\" && this.room.shouldEncryptForInvitedMembers())\n ) {\n // make sure we are tracking the deviceList for this user\n this.prefixedLogger.debug(`starting to track devices for: ${member.userId}`);\n this.olmMachine.updateTrackedUsers([new UserId(member.userId)]);\n }\n\n // TODO: handle leaves (including our own)\n }\n\n /**\n * Prepare to encrypt events in this room.\n *\n * This ensures that we have a megolm session ready to use and that we have shared its key with all the devices\n * in the room.\n */\n public async ensureEncryptionSession(): Promise<void> {\n if (this.encryptionSettings.algorithm !== \"m.megolm.v1.aes-sha2\") {\n throw new Error(\n `Cannot encrypt in ${this.room.roomId} for unsupported algorithm '${this.encryptionSettings.algorithm}'`,\n );\n }\n\n const members = await this.room.getEncryptionTargetMembers();\n this.prefixedLogger.debug(\n `Encrypting for users (shouldEncryptForInvitedMembers: ${this.room.shouldEncryptForInvitedMembers()}):`,\n members.map((u) => `${u.userId} (${u.membership})`),\n );\n\n const userList = members.map((u) => new UserId(u.userId));\n await this.keyClaimManager.ensureSessionsForUsers(userList);\n\n this.prefixedLogger.debug(\"Sessions for users are ready; now sharing room key\");\n\n const rustEncryptionSettings = new EncryptionSettings();\n /* FIXME historyVisibility, rotation, etc */\n\n const shareMessages = await this.olmMachine.shareRoomKey(\n new RoomId(this.room.roomId),\n userList,\n rustEncryptionSettings,\n );\n if (shareMessages) {\n for (const m of shareMessages) {\n await this.outgoingRequestProcessor.makeOutgoingRequest(m);\n }\n }\n }\n\n /**\n * Discard any existing group session for this room\n */\n public async forceDiscardSession(): Promise<void> {\n const r = await this.olmMachine.invalidateGroupSession(new RoomId(this.room.roomId));\n if (r) {\n this.prefixedLogger.info(\"Discarded existing group session\");\n }\n }\n\n /**\n * Encrypt an event for this room\n *\n * This will ensure that we have a megolm session for this room, share it with the devices in the room, and\n * then encrypt the event using the session.\n *\n * @param event - Event to be encrypted.\n */\n public async encryptEvent(event: MatrixEvent): Promise<void> {\n await this.ensureEncryptionSession();\n\n const encryptedContent = await this.olmMachine.encryptRoomEvent(\n new RoomId(this.room.roomId),\n event.getType(),\n JSON.stringify(event.getContent()),\n );\n\n event.makeEncrypted(\n EventType.RoomMessageEncrypted,\n JSON.parse(encryptedContent),\n this.olmMachine.identityKeys.curve25519.toBase64(),\n this.olmMachine.identityKeys.ed25519.toBase64(),\n );\n }\n}\n"],"mappings":";;;;;;;;AAgBA,IAAAA,kBAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAGA,IAAAE,OAAA,GAAAF,OAAA;AArBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA;AACA;AACA;AACO,MAAMG,aAAa,CAAC;EAGvB;AACJ;AACA;AACA;AACA;AACA;EACWC,WAAWA,CACGC,UAAsB,EACtBC,eAAgC,EAChCC,wBAAkD,EAClDC,IAAU,EACnBC,kBAA4B,EACtC;IAAA,KALmBJ,UAAsB,GAAtBA,UAAsB;IAAA,KACtBC,eAAgC,GAAhCA,eAAgC;IAAA,KAChCC,wBAAkD,GAAlDA,wBAAkD;IAAA,KAClDC,IAAU,GAAVA,IAAU;IAAA,KACnBC,kBAA4B,GAA5BA,kBAA4B;IAAA,IAAAC,gBAAA,CAAAC,OAAA;IAEpC,IAAI,CAACC,cAAc,GAAGC,cAAM,CAACC,UAAU,CAAE,IAAGN,IAAI,CAACO,MAAO,cAAa,CAAC;EAC1E;;EAEA;AACJ;AACA;AACA;AACA;EACWC,aAAaA,CAACC,MAAgB,EAAQ;IACz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AACC,SAAS,CAAC+B,KAAK,CAACI,UAAU,EAAE,CAAC,CACrC;IAEDJ,KAAK,CAACK,aAAa,CACfC,gBAAS,CAACC,oBAAoB,EAC9BvC,IAAI,CAACwC,KAAK,CAACP,gBAAgB,CAAC,EAC5B,IAAI,CAAC9C,UAAU,CAACsD,YAAY,CAACC,UAAU,CAACC,QAAQ,EAAE,EAClD,IAAI,CAACxD,UAAU,CAACsD,YAAY,CAACG,OAAO,CAACD,QAAQ,EAAE,CAClD;EACL;AACJ;AAACE,OAAA,CAAA5D,aAAA,GAAAA,aAAA"} \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.d.ts b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.d.ts
new file mode 100644
index 0000000..43de354
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.d.ts
@@ -0,0 +1,5 @@
+import { IHttpOpts, MatrixHttpApi } from "../http-api";
+export declare function initRustCrypto(_http: MatrixHttpApi<IHttpOpts & {
+ onlyData: true;
+}>, _userId: string, _deviceId: string): Promise<Crypto>;
+//# sourceMappingURL=browserify-index.d.ts.map \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.d.ts.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.d.ts.map
new file mode 100644
index 0000000..ac98bf2
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"browserify-index.d.ts","sourceRoot":"","sources":["../../src/rust-crypto/browserify-index.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEvD,wBAAsB,cAAc,CAChC,KAAK,EAAE,aAAa,CAAC,SAAS,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,CAAC,EACpD,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CAEjB"} \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.js b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.js
new file mode 100644
index 0000000..4608108
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.js
@@ -0,0 +1,32 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.initRustCrypto = initRustCrypto;
+/*
+Copyright 2023 The Matrix.org Foundation C.I.C.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/* This file replaces rust-crypto/index.ts when the js-sdk is being built for browserify.
+ *
+ * It is a stub, so that we do not import the whole of the base64'ed wasm artifact into the browserify bundle.
+ * It deliberately does nothing except raise an exception.
+ */
+
+async function initRustCrypto(_http, _userId, _deviceId) {
+ throw new Error("Rust crypto is not supported under browserify.");
+}
+//# sourceMappingURL=browserify-index.js.map \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.js.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.js.map
new file mode 100644
index 0000000..0f2c31c
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/browserify-index.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"browserify-index.js","names":["initRustCrypto","_http","_userId","_deviceId","Error"],"sources":["../../src/rust-crypto/browserify-index.ts"],"sourcesContent":["/*\nCopyright 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n/* This file replaces rust-crypto/index.ts when the js-sdk is being built for browserify.\n *\n * It is a stub, so that we do not import the whole of the base64'ed wasm artifact into the browserify bundle.\n * It deliberately does nothing except raise an exception.\n */\n\nimport { IHttpOpts, MatrixHttpApi } from \"../http-api\";\n\nexport async function initRustCrypto(\n _http: MatrixHttpApi<IHttpOpts & { onlyData: true }>,\n _userId: string,\n _deviceId: string,\n): Promise<Crypto> {\n throw new Error(\"Rust crypto is not supported under browserify.\");\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAIO,eAAeA,cAAcA,CAChCC,KAAoD,EACpDC,OAAe,EACfC,SAAiB,EACF;EACf,MAAM,IAAIC,KAAK,CAAC,gDAAgD,CAAC;AACrE"} \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.d.ts b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.d.ts
new file mode 100644
index 0000000..7f68385
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.d.ts
@@ -0,0 +1,3 @@
+/** The prefix used on indexeddbs created by rust-crypto */
+export declare const RUST_SDK_STORE_PREFIX = "matrix-js-sdk";
+//# sourceMappingURL=constants.d.ts.map \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.d.ts.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.d.ts.map
new file mode 100644
index 0000000..91c78cc
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/rust-crypto/constants.ts"],"names":[],"mappings":"AAgBA,2DAA2D;AAC3D,eAAO,MAAM,qBAAqB,kBAAkB,CAAC"} \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.js b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.js
new file mode 100644
index 0000000..75bd09e
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.js
@@ -0,0 +1,26 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.RUST_SDK_STORE_PREFIX = void 0;
+/*
+Copyright 2022 The Matrix.org Foundation C.I.C.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/** The prefix used on indexeddbs created by rust-crypto */
+const RUST_SDK_STORE_PREFIX = "matrix-js-sdk";
+exports.RUST_SDK_STORE_PREFIX = RUST_SDK_STORE_PREFIX;
+//# sourceMappingURL=constants.js.map \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.js.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.js.map
new file mode 100644
index 0000000..0533885
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/constants.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"constants.js","names":["RUST_SDK_STORE_PREFIX","exports"],"sources":["../../src/rust-crypto/constants.ts"],"sourcesContent":["/*\nCopyright 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\n/** The prefix used on indexeddbs created by rust-crypto */\nexport const RUST_SDK_STORE_PREFIX = \"matrix-js-sdk\";\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACO,MAAMA,qBAAqB,GAAG,eAAe;AAACC,OAAA,CAAAD,qBAAA,GAAAA,qBAAA"} \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.d.ts b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.d.ts
new file mode 100644
index 0000000..64fe34f
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.d.ts
@@ -0,0 +1,6 @@
+import { RustCrypto } from "./rust-crypto";
+import { IHttpOpts, MatrixHttpApi } from "../http-api";
+export declare function initRustCrypto(http: MatrixHttpApi<IHttpOpts & {
+ onlyData: true;
+}>, userId: string, deviceId: string): Promise<RustCrypto>;
+//# sourceMappingURL=index.d.ts.map \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.d.ts.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.d.ts.map
new file mode 100644
index 0000000..c1ff61e
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rust-crypto/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEvD,wBAAsB,cAAc,CAChC,IAAI,EAAE,aAAa,CAAC,SAAS,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,CAAC,EACnD,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,CAAC,CAiBrB"} \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.js b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.js
new file mode 100644
index 0000000..b5618fd
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.js
@@ -0,0 +1,45 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.initRustCrypto = initRustCrypto;
+var RustSdkCryptoJs = _interopRequireWildcard(require("@matrix-org/matrix-sdk-crypto-js"));
+var _rustCrypto = require("./rust-crypto");
+var _logger = require("../logger");
+var _constants = require("./constants");
+function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
+function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+/*
+Copyright 2022 The Matrix.org Foundation C.I.C.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+async function initRustCrypto(http, userId, deviceId) {
+ // initialise the rust matrix-sdk-crypto-js, if it hasn't already been done
+ await RustSdkCryptoJs.initAsync();
+
+ // enable tracing in the rust-sdk
+ new RustSdkCryptoJs.Tracing(RustSdkCryptoJs.LoggerLevel.Trace).turnOn();
+ const u = new RustSdkCryptoJs.UserId(userId);
+ const d = new RustSdkCryptoJs.DeviceId(deviceId);
+ _logger.logger.info("Init OlmMachine");
+
+ // TODO: use the pickle key for the passphrase
+ const olmMachine = await RustSdkCryptoJs.OlmMachine.initialize(u, d, _constants.RUST_SDK_STORE_PREFIX, "test pass");
+ const rustCrypto = new _rustCrypto.RustCrypto(olmMachine, http, userId, deviceId);
+ _logger.logger.info("Completed rust crypto-sdk setup");
+ return rustCrypto;
+}
+//# sourceMappingURL=index.js.map \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.js.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.js.map
new file mode 100644
index 0000000..22ee888
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/index.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"index.js","names":["RustSdkCryptoJs","_interopRequireWildcard","require","_rustCrypto","_logger","_constants","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","initRustCrypto","http","userId","deviceId","initAsync","Tracing","LoggerLevel","Trace","turnOn","u","UserId","d","DeviceId","logger","info","olmMachine","OlmMachine","initialize","RUST_SDK_STORE_PREFIX","rustCrypto","RustCrypto"],"sources":["../../src/rust-crypto/index.ts"],"sourcesContent":["/*\nCopyright 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 * as RustSdkCryptoJs from \"@matrix-org/matrix-sdk-crypto-js\";\n\nimport { RustCrypto } from \"./rust-crypto\";\nimport { logger } from \"../logger\";\nimport { RUST_SDK_STORE_PREFIX } from \"./constants\";\nimport { IHttpOpts, MatrixHttpApi } from \"../http-api\";\n\nexport async function initRustCrypto(\n http: MatrixHttpApi<IHttpOpts & { onlyData: true }>,\n userId: string,\n deviceId: string,\n): Promise<RustCrypto> {\n // initialise the rust matrix-sdk-crypto-js, if it hasn't already been done\n await RustSdkCryptoJs.initAsync();\n\n // enable tracing in the rust-sdk\n new RustSdkCryptoJs.Tracing(RustSdkCryptoJs.LoggerLevel.Trace).turnOn();\n\n const u = new RustSdkCryptoJs.UserId(userId);\n const d = new RustSdkCryptoJs.DeviceId(deviceId);\n logger.info(\"Init OlmMachine\");\n\n // TODO: use the pickle key for the passphrase\n const olmMachine = await RustSdkCryptoJs.OlmMachine.initialize(u, d, RUST_SDK_STORE_PREFIX, \"test pass\");\n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CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA;AApBpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASO,eAAeW,cAAcA,CAChCC,IAAmD,EACnDC,MAAc,EACdC,QAAgB,EACG;EACnB;EACA,MAAM/B,eAAe,CAACgC,SAAS,EAAE;;EAEjC;EACA,IAAIhC,eAAe,CAACiC,OAAO,CAACjC,eAAe,CAACkC,WAAW,CAACC,KAAK,CAAC,CAACC,MAAM,EAAE;EAEvE,MAAMC,CAAC,GAAG,IAAIrC,eAAe,CAACsC,MAAM,CAACR,MAAM,CAAC;EAC5C,MAAMS,CAAC,GAAG,IAAIvC,eAAe,CAACwC,QAAQ,CAACT,QAAQ,CAAC;EAChDU,cAAM,CAACC,IAAI,CAAC,iBAAiB,CAAC;;EAE9B;EACA,MAAMC,UAAU,GAAG,MAAM3C,eAAe,CAAC4C,UAAU,CAACC,UAAU,CAACR,CAAC,EAAEE,CAAC,EAAEO,gCAAqB,EAAE,WAAW,CAAC;EACxG,MAAMC,UAAU,GAAG,IAAIC,sBAAU,CAACL,UAAU,EAAEd,IAAI,EAAEC,MAAM,EAAEC,QAAQ,CAAC;EAErEU,cAAM,CAACC,IAAI,CAAC,iCAAiC,CAAC;EAC9C,OAAOK,UAAU;AACrB"} \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.d.ts b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.d.ts
new file mode 100644
index 0000000..fe94fdc
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.d.ts
@@ -0,0 +1,87 @@
+import * as RustSdkCryptoJs from "@matrix-org/matrix-sdk-crypto-js";
+import type { IEventDecryptionResult, IMegolmSessionData } from "../@types/crypto";
+import type { IToDeviceEvent } from "../sync-accumulator";
+import type { IEncryptedEventInfo } from "../crypto/api";
+import { MatrixEvent } from "../models/event";
+import { Room } from "../models/room";
+import { RoomMember } from "../models/room-member";
+import { CryptoBackend, OnSyncCompletedData } from "../common-crypto/CryptoBackend";
+import { IHttpOpts, MatrixHttpApi } from "../http-api";
+import { DeviceTrustLevel, UserTrustLevel } from "../crypto/CrossSigning";
+/**
+ * An implementation of {@link CryptoBackend} using the Rust matrix-sdk-crypto.
+ */
+export declare class RustCrypto implements CryptoBackend {
+ private readonly olmMachine;
+ globalErrorOnUnknownDevices: boolean;
+ /** whether {@link stop} has been called */
+ private stopped;
+ /** whether {@link outgoingRequestLoop} is currently running */
+ private outgoingRequestLoopRunning;
+ /** mapping of roomId → encryptor class */
+ private roomEncryptors;
+ private keyClaimManager;
+ private outgoingRequestProcessor;
+ constructor(olmMachine: RustSdkCryptoJs.OlmMachine, http: MatrixHttpApi<IHttpOpts & {
+ onlyData: true;
+ }>, _userId: string, _deviceId: string);
+ stop(): void;
+ encryptEvent(event: MatrixEvent, _room: Room): Promise<void>;
+ decryptEvent(event: MatrixEvent): Promise<IEventDecryptionResult>;
+ getEventEncryptionInfo(event: MatrixEvent): IEncryptedEventInfo;
+ checkUserTrust(userId: string): UserTrustLevel;
+ checkDeviceTrust(userId: string, deviceId: string): DeviceTrustLevel;
+ globalBlacklistUnverifiedDevices: boolean;
+ userHasCrossSigningKeys(): Promise<boolean>;
+ prepareToEncrypt(room: Room): void;
+ forceDiscardSession(roomId: string): Promise<void>;
+ exportRoomKeys(): Promise<IMegolmSessionData[]>;
+ /**
+ * Apply sync changes to the olm machine
+ * @param events - the received to-device messages
+ * @param oneTimeKeysCounts - the received one time key counts
+ * @param unusedFallbackKeys - the received unused fallback keys
+ * @returns A list of preprocessed to-device messages.
+ */
+ private receiveSyncChanges;
+ /** called by the sync loop to preprocess incoming to-device messages
+ *
+ * @param events - the received to-device messages
+ * @returns A list of preprocessed to-device messages.
+ */
+ preprocessToDeviceMessages(events: IToDeviceEvent[]): Promise<IToDeviceEvent[]>;
+ /** called by the sync loop to preprocess one time key counts
+ *
+ * @param oneTimeKeysCounts - the received one time key counts
+ * @returns A list of preprocessed to-device messages.
+ */
+ preprocessOneTimeKeyCounts(oneTimeKeysCounts: Map<string, number>): Promise<void>;
+ /** called by the sync loop to preprocess unused fallback keys
+ *
+ * @param unusedFallbackKeys - the received unused fallback keys
+ * @returns A list of preprocessed to-device messages.
+ */
+ preprocessUnusedFallbackKeys(unusedFallbackKeys: Set<string>): Promise<void>;
+ /** called by the sync loop on m.room.encrypted events
+ *
+ * @param room - in which the event was received
+ * @param event - encryption event to be processed
+ */
+ onCryptoEvent(room: Room, event: MatrixEvent): Promise<void>;
+ /** called by the sync loop after processing each sync.
+ *
+ * TODO: figure out something equivalent for sliding sync.
+ *
+ * @param syncState - information on the completed sync.
+ */
+ onSyncCompleted(syncState: OnSyncCompletedData): void;
+ /** called by the MatrixClient on a room membership event
+ *
+ * @param event - The matrix event which caused this event to fire.
+ * @param member - The member whose RoomMember.membership changed.
+ * @param oldMembership - The previous membership state. Null if it's a new member.
+ */
+ onRoomMembership(event: MatrixEvent, member: RoomMember, oldMembership?: string): void;
+ private outgoingRequestLoop;
+}
+//# sourceMappingURL=rust-crypto.d.ts.map \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.d.ts.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.d.ts.map
new file mode 100644
index 0000000..b550e06
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"rust-crypto.d.ts","sourceRoot":"","sources":["../../src/rust-crypto/rust-crypto.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,eAAe,MAAM,kCAAkC,CAAC;AAEpE,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE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,EAAE,MAAM,GAAG,cAAc;IAK9C,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,gBAAgB;IAWpE,gCAAgC,UAAS;IAEnC,uBAAuB,IAAI,OAAO,CAAC,OAAO,CAAC;IAKjD,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAQlC,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C,cAAc,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAW5D;;;;;;OAMG;YACW,kBAAkB;IAoBhC;;;;OAIG;IACI,0BAA0B,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAMtF;;;;OAIG;IACU,0BAA0B,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9F;;;;OAIG;IACU,4BAA4B,CAAC,kBAAkB,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzF;;;;OAIG;IACU,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBzE;;;;;OAKG;IACI,eAAe,CAAC,SAAS,EAAE,mBAAmB,GAAG,IAAI;IAY5D;;;;;OAKG;IACI,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;YAe/E,mBAAmB;CAsBpC"} \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.js b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.js
new file mode 100644
index 0000000..4faf66b
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.js
@@ -0,0 +1,301 @@
+"use strict";
+
+var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.RustCrypto = void 0;
+var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
+var RustSdkCryptoJs = _interopRequireWildcard(require("@matrix-org/matrix-sdk-crypto-js"));
+var _logger = require("../logger");
+var _CrossSigning = require("../crypto/CrossSigning");
+var _RoomEncryptor = require("./RoomEncryptor");
+var _OutgoingRequestProcessor = require("./OutgoingRequestProcessor");
+var _KeyClaimManager = require("./KeyClaimManager");
+function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
+function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
+/*
+Copyright 2022 The Matrix.org Foundation C.I.C.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/**
+ * An implementation of {@link CryptoBackend} using the Rust matrix-sdk-crypto.
+ */
+class RustCrypto {
+ /** whether {@link stop} has been called */
+
+ /** whether {@link outgoingRequestLoop} is currently running */
+
+ /** mapping of roomId → encryptor class */
+
+ constructor(olmMachine, http, _userId, _deviceId) {
+ this.olmMachine = olmMachine;
+ (0, _defineProperty2.default)(this, "globalErrorOnUnknownDevices", false);
+ (0, _defineProperty2.default)(this, "stopped", false);
+ (0, _defineProperty2.default)(this, "outgoingRequestLoopRunning", false);
+ (0, _defineProperty2.default)(this, "roomEncryptors", {});
+ (0, _defineProperty2.default)(this, "keyClaimManager", void 0);
+ (0, _defineProperty2.default)(this, "outgoingRequestProcessor", void 0);
+ (0, _defineProperty2.default)(this, "globalBlacklistUnverifiedDevices", false);
+ this.outgoingRequestProcessor = new _OutgoingRequestProcessor.OutgoingRequestProcessor(olmMachine, http);
+ this.keyClaimManager = new _KeyClaimManager.KeyClaimManager(olmMachine, this.outgoingRequestProcessor);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ //
+ // CryptoBackend implementation
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ stop() {
+ // stop() may be called multiple times, but attempting to close() the OlmMachine twice
+ // will cause an error.
+ if (this.stopped) {
+ return;
+ }
+ this.stopped = true;
+ this.keyClaimManager.stop();
+
+ // make sure we close() the OlmMachine; doing so means that all the Rust objects will be
+ // cleaned up; in particular, the indexeddb connections will be closed, which means they
+ // can then be deleted.
+ this.olmMachine.close();
+ }
+ async encryptEvent(event, _room) {
+ const roomId = event.getRoomId();
+ const encryptor = this.roomEncryptors[roomId];
+ if (!encryptor) {
+ throw new Error(`Cannot encrypt event in unconfigured room ${roomId}`);
+ }
+ await encryptor.encryptEvent(event);
+ }
+ async decryptEvent(event) {
+ const roomId = event.getRoomId();
+ if (!roomId) {
+ // presumably, a to-device message. These are normally decrypted in preprocessToDeviceMessages
+ // so the fact it has come back here suggests that decryption failed.
+ //
+ // once we drop support for the libolm crypto implementation, we can stop passing to-device messages
+ // through decryptEvent and hence get rid of this case.
+ throw new Error("to-device event was not decrypted in preprocessToDeviceMessages");
+ }
+ const res = await this.olmMachine.decryptRoomEvent(JSON.stringify({
+ event_id: event.getId(),
+ type: event.getWireType(),
+ sender: event.getSender(),
+ state_key: event.getStateKey(),
+ content: event.getWireContent(),
+ origin_server_ts: event.getTs()
+ }), new RustSdkCryptoJs.RoomId(event.getRoomId()));
+ return {
+ clearEvent: JSON.parse(res.event),
+ claimedEd25519Key: res.senderClaimedEd25519Key,
+ senderCurve25519Key: res.senderCurve25519Key,
+ forwardingCurve25519KeyChain: res.forwardingCurve25519KeyChain
+ };
+ }
+ getEventEncryptionInfo(event) {
+ var _event$getSenderKey;
+ // TODO: make this work properly. Or better, replace it.
+
+ const ret = {};
+ ret.senderKey = (_event$getSenderKey = event.getSenderKey()) !== null && _event$getSenderKey !== void 0 ? _event$getSenderKey : undefined;
+ ret.algorithm = event.getWireContent().algorithm;
+ if (!ret.senderKey || !ret.algorithm) {
+ ret.encrypted = false;
+ return ret;
+ }
+ ret.encrypted = true;
+ ret.authenticated = true;
+ ret.mismatchedSender = true;
+ return ret;
+ }
+ checkUserTrust(userId) {
+ // TODO
+ return new _CrossSigning.UserTrustLevel(false, false, false);
+ }
+ checkDeviceTrust(userId, deviceId) {
+ // TODO
+ return new _CrossSigning.DeviceTrustLevel(false, false, false, false);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ //
+ // CryptoApi implementation
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ async userHasCrossSigningKeys() {
+ // TODO
+ return false;
+ }
+ prepareToEncrypt(room) {
+ const encryptor = this.roomEncryptors[room.roomId];
+ if (encryptor) {
+ encryptor.ensureEncryptionSession();
+ }
+ }
+ forceDiscardSession(roomId) {
+ var _this$roomEncryptors$;
+ return (_this$roomEncryptors$ = this.roomEncryptors[roomId]) === null || _this$roomEncryptors$ === void 0 ? void 0 : _this$roomEncryptors$.forceDiscardSession();
+ }
+ async exportRoomKeys() {
+ // TODO
+ return [];
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ //
+ // SyncCryptoCallbacks implementation
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Apply sync changes to the olm machine
+ * @param events - the received to-device messages
+ * @param oneTimeKeysCounts - the received one time key counts
+ * @param unusedFallbackKeys - the received unused fallback keys
+ * @returns A list of preprocessed to-device messages.
+ */
+ async receiveSyncChanges({
+ events,
+ oneTimeKeysCounts = new Map(),
+ unusedFallbackKeys = new Set()
+ }) {
+ const result = await this.olmMachine.receiveSyncChanges(events ? JSON.stringify(events) : "[]", new RustSdkCryptoJs.DeviceLists(), oneTimeKeysCounts, unusedFallbackKeys);
+
+ // receiveSyncChanges returns a JSON-encoded list of decrypted to-device messages.
+ return JSON.parse(result);
+ }
+
+ /** called by the sync loop to preprocess incoming to-device messages
+ *
+ * @param events - the received to-device messages
+ * @returns A list of preprocessed to-device messages.
+ */
+ preprocessToDeviceMessages(events) {
+ // send the received to-device messages into receiveSyncChanges. We have no info on device-list changes,
+ // one-time-keys, or fallback keys, so just pass empty data.
+ return this.receiveSyncChanges({
+ events
+ });
+ }
+
+ /** called by the sync loop to preprocess one time key counts
+ *
+ * @param oneTimeKeysCounts - the received one time key counts
+ * @returns A list of preprocessed to-device messages.
+ */
+ async preprocessOneTimeKeyCounts(oneTimeKeysCounts) {
+ await this.receiveSyncChanges({
+ oneTimeKeysCounts
+ });
+ }
+
+ /** called by the sync loop to preprocess unused fallback keys
+ *
+ * @param unusedFallbackKeys - the received unused fallback keys
+ * @returns A list of preprocessed to-device messages.
+ */
+ async preprocessUnusedFallbackKeys(unusedFallbackKeys) {
+ await this.receiveSyncChanges({
+ unusedFallbackKeys
+ });
+ }
+
+ /** called by the sync loop on m.room.encrypted events
+ *
+ * @param room - in which the event was received
+ * @param event - encryption event to be processed
+ */
+ async onCryptoEvent(room, event) {
+ const config = event.getContent();
+ const existingEncryptor = this.roomEncryptors[room.roomId];
+ if (existingEncryptor) {
+ existingEncryptor.onCryptoEvent(config);
+ } else {
+ this.roomEncryptors[room.roomId] = new _RoomEncryptor.RoomEncryptor(this.olmMachine, this.keyClaimManager, this.outgoingRequestProcessor, room, config);
+ }
+
+ // start tracking devices for any users already known to be in this room.
+ const members = await room.getEncryptionTargetMembers();
+ _logger.logger.debug(`[${room.roomId} encryption] starting to track devices for: `, members.map(u => `${u.userId} (${u.membership})`));
+ await this.olmMachine.updateTrackedUsers(members.map(u => new RustSdkCryptoJs.UserId(u.userId)));
+ }
+
+ /** called by the sync loop after processing each sync.
+ *
+ * TODO: figure out something equivalent for sliding sync.
+ *
+ * @param syncState - information on the completed sync.
+ */
+ onSyncCompleted(syncState) {
+ // Processing the /sync may have produced new outgoing requests which need sending, so kick off the outgoing
+ // request loop, if it's not already running.
+ this.outgoingRequestLoop();
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ //
+ // Other public functions
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ /** called by the MatrixClient on a room membership event
+ *
+ * @param event - The matrix event which caused this event to fire.
+ * @param member - The member whose RoomMember.membership changed.
+ * @param oldMembership - The previous membership state. Null if it's a new member.
+ */
+ onRoomMembership(event, member, oldMembership) {
+ const enc = this.roomEncryptors[event.getRoomId()];
+ if (!enc) {
+ // not encrypting in this room
+ return;
+ }
+ enc.onRoomMembership(member);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ //
+ // Outgoing requests
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ async outgoingRequestLoop() {
+ if (this.outgoingRequestLoopRunning) {
+ return;
+ }
+ this.outgoingRequestLoopRunning = true;
+ try {
+ while (!this.stopped) {
+ const outgoingRequests = await this.olmMachine.outgoingRequests();
+ if (outgoingRequests.length == 0 || this.stopped) {
+ // no more messages to send (or we have been told to stop): exit the loop
+ return;
+ }
+ for (const msg of outgoingRequests) {
+ await this.outgoingRequestProcessor.makeOutgoingRequest(msg);
+ }
+ }
+ } catch (e) {
+ _logger.logger.error("Error processing outgoing-message requests from rust crypto-sdk", e);
+ } finally {
+ this.outgoingRequestLoopRunning = false;
+ }
+ }
+}
+exports.RustCrypto = RustCrypto;
+//# sourceMappingURL=rust-crypto.js.map \ No newline at end of file
diff --git a/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.js.map b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.js.map
new file mode 100644
index 0000000..18bf6af
--- /dev/null
+++ b/includes/external/matrix/node_modules/matrix-js-sdk/lib/rust-crypto/rust-crypto.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"rust-crypto.js","names":["RustSdkCryptoJs","_interopRequireWildcard","require","_logger","_CrossSigning","_RoomEncryptor","_OutgoingRequestProcessor","_KeyClaimManager","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","RustCrypto","constructor","olmMachine","http","_userId","_deviceId","_defineProperty2","outgoingRequestProcessor","OutgoingRequestProcessor","keyClaimManager","KeyClaimManager","stop","stopped","close","encryptEvent","event","_room","roomId","getRoomId","encryptor","roomEncryptors","Error","decryptEvent","res","decryptRoomEvent","JSON","stringify","event_id","getId","type","getWireType","sender","getSender","state_key","getStateKey","content","getWireContent","origin_server_ts","getTs","RoomId","clearEvent","parse","claimedEd25519Key","senderClaimedEd25519Key","senderCurve25519Key","forwardingCurve25519KeyChain","getEventEncryptionInfo","_event$getSenderKey","ret","senderKey","getSenderKey","undefined","algorithm","encrypted","authenticated","mismatchedSender","checkUserTrust","userId","UserTrustLevel","checkDeviceTrust","deviceId","DeviceTrustLevel","userHasCrossSigningKeys","prepareToEncrypt","room","ensureEncryptionSession","forceDiscardSession","_this$roomEncryptors$","exportRoomKeys","receiveSyncChanges","events","oneTimeKeysCounts","Map","unusedFallbackKeys","Set","result","DeviceLists","preprocessToDeviceMessages","preprocessOneTimeKeyCounts","preprocessUnusedFallbackKeys","onCryptoEvent","config","getContent","existingEncryptor","RoomEncryptor","members","getEncryptionTargetMembers","logger","debug","map","u","membership","updateTrackedUsers","UserId","onSyncCompleted","syncState","outgoingRequestLoop","onRoomMembership","member","oldMembership","enc","outgoingRequestLoopRunning","outgoingRequests","length","msg","makeOutgoingRequest","e","error","exports"],"sources":["../../src/rust-crypto/rust-crypto.ts"],"sourcesContent":["/*\nCopyright 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 * as RustSdkCryptoJs from \"@matrix-org/matrix-sdk-crypto-js\";\n\nimport type { IEventDecryptionResult, IMegolmSessionData } from \"../@types/crypto\";\nimport type { IToDeviceEvent } from \"../sync-accumulator\";\nimport type { IEncryptedEventInfo } from \"../crypto/api\";\nimport { MatrixEvent } from \"../models/event\";\nimport { Room } from \"../models/room\";\nimport { RoomMember } from \"../models/room-member\";\nimport { CryptoBackend, OnSyncCompletedData } from \"../common-crypto/CryptoBackend\";\nimport { logger } from \"../logger\";\nimport { IHttpOpts, MatrixHttpApi } from \"../http-api\";\nimport { DeviceTrustLevel, UserTrustLevel } from \"../crypto/CrossSigning\";\nimport { RoomEncryptor } from \"./RoomEncryptor\";\nimport { OutgoingRequest, OutgoingRequestProcessor } from \"./OutgoingRequestProcessor\";\nimport { KeyClaimManager } from \"./KeyClaimManager\";\n\n/**\n * An implementation of {@link CryptoBackend} using the Rust matrix-sdk-crypto.\n */\nexport class RustCrypto implements CryptoBackend {\n public globalErrorOnUnknownDevices = false;\n\n /** whether {@link stop} has been called */\n private stopped = false;\n\n /** whether {@link outgoingRequestLoop} is currently running */\n private outgoingRequestLoopRunning = false;\n\n /** mapping of roomId → encryptor class */\n private roomEncryptors: Record<string, RoomEncryptor> = {};\n\n private keyClaimManager: KeyClaimManager;\n private outgoingRequestProcessor: OutgoingRequestProcessor;\n\n public constructor(\n private readonly olmMachine: RustSdkCryptoJs.OlmMachine,\n http: MatrixHttpApi<IHttpOpts & { onlyData: true }>,\n _userId: string,\n _deviceId: string,\n ) {\n this.outgoingRequestProcessor = new OutgoingRequestProcessor(olmMachine, http);\n this.keyClaimManager = new KeyClaimManager(olmMachine, this.outgoingRequestProcessor);\n }\n\n ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n //\n // CryptoBackend implementation\n //\n ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n public stop(): void {\n // stop() may be called multiple times, but attempting to close() the OlmMachine twice\n // will cause an error.\n if (this.stopped) {\n return;\n }\n this.stopped = true;\n\n this.keyClaimManager.stop();\n\n // make sure we close() the OlmMachine; doing so means that all the Rust objects will be\n // cleaned up; in particular, the indexeddb connections will be closed, which means they\n // can then be deleted.\n this.olmMachine.close();\n }\n\n public async encryptEvent(event: MatrixEvent, _room: Room): Promise<void> {\n const roomId = event.getRoomId()!;\n const encryptor = this.roomEncryptors[roomId];\n\n if (!encryptor) {\n throw new Error(`Cannot encrypt event in unconfigured room ${roomId}`);\n }\n\n await encryptor.encryptEvent(event);\n }\n\n public async decryptEvent(event: MatrixEvent): Promise<IEventDecryptionResult> {\n const roomId = event.getRoomId();\n if (!roomId) {\n // presumably, a to-device message. These are normally decrypted in preprocessToDeviceMessages\n // so the fact it has come back here suggests that decryption failed.\n //\n // once we drop support for the libolm crypto implementation, we can stop passing to-device messages\n // through decryptEvent and hence get rid of this case.\n throw new Error(\"to-device event was not decrypted in preprocessToDeviceMessages\");\n }\n const res = (await this.olmMachine.decryptRoomEvent(\n JSON.stringify({\n event_id: event.getId(),\n type: event.getWireType(),\n sender: event.getSender(),\n state_key: event.getStateKey(),\n content: event.getWireContent(),\n origin_server_ts: event.getTs(),\n }),\n new RustSdkCryptoJs.RoomId(event.getRoomId()!),\n )) as RustSdkCryptoJs.DecryptedRoomEvent;\n return {\n clearEvent: JSON.parse(res.event),\n claimedEd25519Key: res.senderClaimedEd25519Key,\n senderCurve25519Key: res.senderCurve25519Key,\n forwardingCurve25519KeyChain: res.forwardingCurve25519KeyChain,\n };\n }\n\n public getEventEncryptionInfo(event: MatrixEvent): IEncryptedEventInfo {\n // TODO: make this work properly. Or better, replace it.\n\n const ret: Partial<IEncryptedEventInfo> = {};\n\n ret.senderKey = event.getSenderKey() ?? undefined;\n ret.algorithm = event.getWireContent().algorithm;\n\n if (!ret.senderKey || !ret.algorithm) {\n ret.encrypted = false;\n return ret as IEncryptedEventInfo;\n }\n ret.encrypted = true;\n ret.authenticated = true;\n ret.mismatchedSender = true;\n return ret as IEncryptedEventInfo;\n }\n\n public checkUserTrust(userId: string): UserTrustLevel {\n // TODO\n return new UserTrustLevel(false, false, false);\n }\n\n public checkDeviceTrust(userId: string, deviceId: string): DeviceTrustLevel {\n // TODO\n return new DeviceTrustLevel(false, false, false, false);\n }\n\n ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n //\n // CryptoApi implementation\n //\n ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n public globalBlacklistUnverifiedDevices = false;\n\n public async userHasCrossSigningKeys(): Promise<boolean> {\n // TODO\n return false;\n }\n\n public prepareToEncrypt(room: Room): void {\n const encryptor = this.roomEncryptors[room.roomId];\n\n if (encryptor) {\n encryptor.ensureEncryptionSession();\n }\n }\n\n public forceDiscardSession(roomId: string): Promise<void> {\n return this.roomEncryptors[roomId]?.forceDiscardSession();\n }\n\n public async exportRoomKeys(): Promise<IMegolmSessionData[]> {\n // TODO\n return [];\n }\n\n ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n //\n // SyncCryptoCallbacks implementation\n //\n ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n /**\n * Apply sync changes to the olm machine\n * @param events - the received to-device messages\n * @param oneTimeKeysCounts - the received one time key counts\n * @param unusedFallbackKeys - the received unused fallback keys\n * @returns A list of preprocessed to-device messages.\n */\n private async receiveSyncChanges({\n events,\n oneTimeKeysCounts = new Map<string, number>(),\n unusedFallbackKeys = new Set<string>(),\n }: {\n events?: IToDeviceEvent[];\n oneTimeKeysCounts?: Map<string, number>;\n unusedFallbackKeys?: Set<string>;\n }): Promise<IToDeviceEvent[]> {\n const result = await this.olmMachine.receiveSyncChanges(\n events ? JSON.stringify(events) : \"[]\",\n new RustSdkCryptoJs.DeviceLists(),\n oneTimeKeysCounts,\n unusedFallbackKeys,\n );\n\n // receiveSyncChanges returns a JSON-encoded list of decrypted to-device messages.\n return JSON.parse(result);\n }\n\n /** called by the sync loop to preprocess incoming to-device messages\n *\n * @param events - the received to-device messages\n * @returns A list of preprocessed to-device messages.\n */\n public preprocessToDeviceMessages(events: IToDeviceEvent[]): Promise<IToDeviceEvent[]> {\n // send the received to-device messages into receiveSyncChanges. We have no info on device-list changes,\n // one-time-keys, or fallback keys, so just pass empty data.\n return this.receiveSyncChanges({ events });\n }\n\n /** called by the sync loop to preprocess one time key counts\n *\n * @param oneTimeKeysCounts - the received one time key counts\n * @returns A list of preprocessed to-device messages.\n */\n public async preprocessOneTimeKeyCounts(oneTimeKeysCounts: Map<string, number>): Promise<void> {\n await this.receiveSyncChanges({ oneTimeKeysCounts });\n }\n\n /** called by the sync loop to preprocess unused fallback keys\n *\n * @param unusedFallbackKeys - the received unused fallback keys\n * @returns A list of preprocessed to-device messages.\n */\n public async preprocessUnusedFallbackKeys(unusedFallbackKeys: Set<string>): Promise<void> {\n await this.receiveSyncChanges({ unusedFallbackKeys });\n }\n\n /** called by the sync loop on m.room.encrypted events\n *\n * @param room - in which the event was received\n * @param event - encryption event to be processed\n */\n public async onCryptoEvent(room: Room, event: MatrixEvent): Promise<void> {\n const config = event.getContent();\n\n const existingEncryptor = this.roomEncryptors[room.roomId];\n if (existingEncryptor) {\n existingEncryptor.onCryptoEvent(config);\n } else {\n this.roomEncryptors[room.roomId] = new RoomEncryptor(\n this.olmMachine,\n this.keyClaimManager,\n this.outgoingRequestProcessor,\n room,\n config,\n );\n }\n\n // start tracking devices for any users already known to be in this room.\n const members = await room.getEncryptionTargetMembers();\n logger.debug(\n `[${room.roomId} encryption] starting to track devices for: `,\n members.map((u) => `${u.userId} (${u.membership})`),\n );\n await this.olmMachine.updateTrackedUsers(members.map((u) => new RustSdkCryptoJs.UserId(u.userId)));\n }\n\n /** called by the sync loop after processing each sync.\n *\n * TODO: figure out something equivalent for sliding sync.\n *\n * @param syncState - information on the completed sync.\n */\n public onSyncCompleted(syncState: OnSyncCompletedData): void {\n // Processing the /sync may have produced new outgoing requests which need sending, so kick off the outgoing\n // request loop, if it's not already running.\n this.outgoingRequestLoop();\n }\n\n ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n //\n // Other public functions\n //\n ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n /** called by the MatrixClient on a room membership event\n *\n * @param event - The matrix event which caused this event to fire.\n * @param member - The member whose RoomMember.membership changed.\n * @param oldMembership - The previous membership state. Null if it's a new member.\n */\n public onRoomMembership(event: MatrixEvent, member: RoomMember, oldMembership?: string): void {\n const enc = this.roomEncryptors[event.getRoomId()!];\n if (!enc) {\n // not encrypting in this room\n return;\n }\n enc.onRoomMembership(member);\n }\n\n ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n //\n // Outgoing requests\n //\n ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n private async outgoingRequestLoop(): Promise<void> {\n if (this.outgoingRequestLoopRunning) {\n return;\n }\n this.outgoingRequestLoopRunning = true;\n try {\n while (!this.stopped) {\n const outgoingRequests: Object[] = await this.olmMachine.outgoingRequests();\n if (outgoingRequests.length == 0 || this.stopped) {\n // no more messages to send (or we have been told to stop): exit the loop\n return;\n }\n for (const msg of outgoingRequests) {\n await this.outgoingRequestProcessor.makeOutgoingRequest(msg as OutgoingRequest);\n }\n }\n } catch (e) {\n logger.error(\"Error processing outgoing-message requests from rust crypto-sdk\", e);\n } finally {\n this.outgoingRequestLoopRunning = false;\n }\n }\n}\n"],"mappings":";;;;;;;;AAgBA,IAAAA,eAAA,GAAAC,uBAAA,CAAAC,OAAA;AASA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,yBAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AAAoD,SAAAM,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAR,wBAAAY,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,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