UNPKG

matrix-js-sdk

Version:
71 lines (63 loc) 4.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.initRustCrypto = initRustCrypto; var RustSdkCryptoJs = _interopRequireWildcard(require("@matrix-org/matrix-sdk-crypto-wasm")); var _rustCrypto = require("./rust-crypto"); var _logger = require("../logger"); 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. */ /** * Create a new `RustCrypto` implementation * * @param http - Low-level HTTP interface: used to make outgoing requests required by the rust SDK. * We expect it to set the access token, etc. * @param userId - The local user's User ID. * @param deviceId - The local user's Device ID. * @param secretStorage - Interface to server-side secret storage. * @param cryptoCallbacks - Crypto callbacks provided by the application * @param storePrefix - the prefix to use on the indexeddbs created by rust-crypto. * If unset, a memory store will be used. * * @internal */ async function initRustCrypto(http, userId, deviceId, secretStorage, cryptoCallbacks, storePrefix) { var _ref; // initialise the rust matrix-sdk-crypto-wasm, 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, storePrefix !== null && storePrefix !== void 0 ? storePrefix : undefined, (_ref = storePrefix && "test pass") !== null && _ref !== void 0 ? _ref : undefined); const rustCrypto = new _rustCrypto.RustCrypto(olmMachine, http, userId, deviceId, secretStorage, cryptoCallbacks); await olmMachine.registerRoomKeyUpdatedCallback(sessions => rustCrypto.onRoomKeysUpdated(sessions)); // Tell the OlmMachine to think about its outgoing requests before we hand control back to the application. // // This is primarily a fudge to get it to correctly populate the `users_for_key_query` list, so that future // calls to getIdentity (etc) block until the key queries are performed. // // Note that we don't actually need to *make* any requests here; it is sufficient to tell the Rust side to think // about them. // // XXX: find a less hacky way to do this. await olmMachine.outgoingRequests(); _logger.logger.info("Completed rust crypto-sdk setup"); return rustCrypto; } //# sourceMappingURL=index.js.map