diff --git a/chat/protocols/matrix/lib/@matrix-org/olm/LICENSE b/chat/protocols/matrix/lib/@matrix-org/olm/LICENSE new file mode 100644 index 0000000000..f433b1a53f --- /dev/null +++ b/chat/protocols/matrix/lib/@matrix-org/olm/LICENSE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/chat/protocols/matrix/lib/@matrix-org/olm/olm.js b/chat/protocols/matrix/lib/@matrix-org/olm/olm.js new file mode 100644 index 0000000000..e466ee6ce0 --- /dev/null +++ b/chat/protocols/matrix/lib/@matrix-org/olm/olm.js @@ -0,0 +1,158 @@ +// @license magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt Apache-2.0 +// @source: https://gitlab.matrix.org/matrix-org/olm/-/tree/3.2.3 + +var Olm = (function() { +var olm_exports = {}; +var onInitSuccess; +var onInitFail; + + +var Module = (function() { + var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; + if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename; + return ( +function(Module) { + Module = Module || {}; + + +var a;a||(a=typeof Module !== 'undefined' ? Module : {});var aa;a.ready=new Promise(function(b){aa=b});var g;if("undefined"!==typeof window)g=function(b){window.crypto.getRandomValues(b)};else if(module.exports){var ba=require("crypto");g=function(b){var c=ba.randomBytes(b.length);b.set(c)};process=global.process}else throw Error("Cannot find global to attach library to");if("undefined"!==typeof OLM_OPTIONS)for(var ca in OLM_OPTIONS)OLM_OPTIONS.hasOwnProperty(ca)&&(a[ca]=OLM_OPTIONS[ca]); +a.onRuntimeInitialized=function(){h=a._olm_error();olm_exports.PRIVATE_KEY_LENGTH=a._olm_pk_private_key_length();onInitSuccess&&onInitSuccess()};a.onAbort=function(b){onInitFail&&onInitFail(b)};var da={},l;for(l in a)a.hasOwnProperty(l)&&(da[l]=a[l]);var ea=!1,m=!1,fa=!1,ia=!1;ea="object"===typeof window;m="function"===typeof importScripts;fa="object"===typeof process&&"object"===typeof process.versions&&"string"===typeof process.versions.node;ia=!ea&&!fa&&!m;var n="",ja,ka,la,ma; +if(fa)n=m?require("path").dirname(n)+"/":__dirname+"/",ja=function(b,c){la||(la=require("fs"));ma||(ma=require("path"));b=ma.normalize(b);return la.readFileSync(b,c?null:"utf8")},ka=function(b){b=ja(b,!0);b.buffer||(b=new Uint8Array(b));b.buffer||q("Assertion failed: undefined");return b},1>0]=0;break;case "i8":t[b>>0]=0;break;case "i16":qa[b>>1]=0;break;case "i32":u[b>>2]=0;break;case "i64":ra=[0,(w=0,1<=+sa(w)?0>>0:~~+va((w-+(~~w>>>0))/4294967296)>>>0:0)];u[b>>2]=ra[0];u[b+4>>2]=ra[1];break;case "float":wa[b>>2]=0;break;case "double":xa[b>>3]=0;break;default:q("invalid type for setValue: "+c)}} +function ya(b,c){c=c||"i8";"*"===c.charAt(c.length-1)&&(c="i32");switch(c){case "i1":return t[b>>0];case "i8":return t[b>>0];case "i16":return qa[b>>1];case "i32":return u[b>>2];case "i64":return u[b>>2];case "float":return wa[b>>2];case "double":return xa[b>>3];default:q("invalid type for getValue: "+c)}return null}var za,Aa=new WebAssembly.Table({initial:9,maximum:9,element:"anyfunc"}),Ba=!1,Ca="undefined"!==typeof TextDecoder?new TextDecoder("utf8"):void 0; +function x(b,c){if(b){var d=y,e=b+c;for(c=b;d[c]&&!(c>=e);)++c;if(16f?e+=String.fromCharCode(f):(f-=65536,e+=String.fromCharCode(55296|f>>10,56320|f&1023))}}else e+=String.fromCharCode(f)}b=e}}else b="";return b} +function z(b,c,d,e){if(!(0=p){var v=b.charCodeAt(++k);p=65536+((p&1023)<<10)|v&1023}if(127>=p){if(d>=e)break;c[d++]=p}else{if(2047>=p){if(d+1>=e)break;c[d++]=192|p>>6}else{if(65535>=p){if(d+2>=e)break;c[d++]=224|p>>12}else{if(d+3>=e)break;c[d++]=240|p>>18;c[d++]=128|p>>12&63}c[d++]=128|p>>6&63}c[d++]=128|p&63}}c[d]=0;return d-f} +function A(b){for(var c=0,d=0;d=e&&(e=65536+((e&1023)<<10)|b.charCodeAt(++d)&1023);127>=e?++c:c=2047>=e?c+2:65535>=e?c+3:c+4}return c}function Da(b,c){for(var d=0;d>0]=b.charCodeAt(d)}var Ea,t,y,qa,u,wa,xa,Ga=a.INITIAL_MEMORY||262144;a.wasmMemory?za=a.wasmMemory:za=new WebAssembly.Memory({initial:Ga/65536,maximum:Ga/65536});za&&(Ea=za.buffer);Ga=Ea.byteLength;var B=Ea;Ea=B;a.HEAP8=t=new Int8Array(B);a.HEAP16=qa=new Int16Array(B); +a.HEAP32=u=new Int32Array(B);a.HEAPU8=y=new Uint8Array(B);a.HEAPU16=new Uint16Array(B);a.HEAPU32=new Uint32Array(B);a.HEAPF32=wa=new Float32Array(B);a.HEAPF64=xa=new Float64Array(B);u[9592]=104064;function Ha(b){for(;0 { this._client = MatrixSDK.createClient(opts); if (this._client.isLoggedIn()) { @@ -1042,6 +1029,45 @@ MatrixAccount.prototype = { }); }, + /** + * Builds the options for the |createClient| call to the SDK including all + * stores. + * @returns {Object} + */ + getClientOptions() { + let dbName = "chat:matrix:" + this.imAccount.id; + + // Create a storage principal unique to this account. + const accountPrincipal = Services.scriptSecurityManager.createContentPrincipal( + Services.io.newURI("https://" + this.imAccount.id + ".matrix.localhost"), + {} + ); + const localStorage = Services.domStorageManager.createStorage( + Services.appShell.hiddenDOMWindow, + accountPrincipal, + accountPrincipal, + "" + ); + + return { + useAuthorizationHeader: true, + baseUrl: this._baseURL, + store: new MatrixSDK.IndexedDBStore({ + indexedDB, + dbName, + }), + sessionStore: new MatrixSDK.WebStorageSessionStore(localStorage), + cryptoStore: new MatrixSDK.IndexedDBCryptoStore( + indexedDB, + dbName + ":crypto" + ), + deviceId: this.prefs.getStringPref("deviceId", "") || undefined, + accessToken: this.prefs.getStringPref("accessToken", "") || undefined, + userId: this.prefs.getStringPref("userId", "") || undefined, + timelineSupport: true, + }; + }, + /** * Log the client in. Sets the session device display name if configured and * stores the session information on successful login. @@ -1062,6 +1088,11 @@ MatrixAccount.prototype = { throw new Error(data.error); } this.storeSessionInformation(data); + // Need to create a new client with the device ID set. + this._client = MatrixSDK.createClient(this.getClientOptions()); + if (!this._client.isLoggedIn()) { + throw new Error("Client has no access token after login"); + } this.startClient(); } catch (error) { let errorType = Ci.prplIAccount.ERROR_OTHER_ERROR; @@ -1343,7 +1374,10 @@ MatrixAccount.prototype = { // Room.localEchoUpdated // Room.tags - this._client.startClient(); + this._client + .initCrypto() + .then(() => this._client.startClient()) + .catch(error => this.ERROR(error)); }, /**