You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
4.0 MiB
2 lines
4.0 MiB
2 years ago
|
(window.webpackJsonp=window.webpackJsonp||[]).push([[32],{1550:function(A,g,I){"use strict";I.r(g),I.d(g,"initRustCrypto",(function(){return M}));var Q=I(482),C=I(13),B=I.n(C),E=I(1),D=I(360),o=I(129);class i{constructor(A,g,I,Q){this.olmMachine=A,this.keyClaimManager=g,this.room=I,this.encryptionSettings=Q,B()(this,"prefixedLogger",void 0),this.prefixedLogger=E.a.withPrefix(`[${I.roomId} encryption]`)}onCryptoEvent(A){JSON.stringify(this.encryptionSettings)!=JSON.stringify(A)&&this.prefixedLogger.error("Ignoring m.room.encryption event which requests a change of config")}onRoomMembership(A){this.prefixedLogger.debug(`${A.membership} event for ${A.userId}`),("join"==A.membership||"invite"==A.membership&&this.room.shouldEncryptForInvitedMembers())&&(this.prefixedLogger.debug(`starting to track devices for: ${A.userId}`),this.olmMachine.updateTrackedUsers([new Q.UserId(A.userId)]))}async ensureEncryptionSession(){if("m.megolm.v1.aes-sha2"!==this.encryptionSettings.algorithm)throw new Error(`Cannot encrypt in ${this.room.roomId} for unsupported algorithm '${this.encryptionSettings.algorithm}'`);const A=await this.room.getEncryptionTargetMembers();this.prefixedLogger.debug(`Encrypting for users (shouldEncryptForInvitedMembers: ${this.room.shouldEncryptForInvitedMembers()}):`,A.map((A=>`${A.userId} (${A.membership})`)));const g=A.map((A=>new Q.UserId(A.userId)));await this.keyClaimManager.ensureSessionsForUsers(g);const I=new Q.EncryptionSettings;await this.olmMachine.shareRoomKey(new Q.RoomId(this.room.roomId),g,I)}async encryptEvent(A){await this.ensureEncryptionSession();const g=await this.olmMachine.encryptRoomEvent(new Q.RoomId(this.room.roomId),A.getType(),JSON.stringify(A.getContent()));A.makeEncrypted(o.b.RoomMessageEncrypted,JSON.parse(g),this.olmMachine.identityKeys.curve25519.toBase64(),this.olmMachine.identityKeys.ed25519.toBase64())}}var w=I(193);class G{constructor(A,g){this.olmMachine=A,this.http=g}async makeOutgoingRequest(A){let g;if(A instanceof Q.KeysUploadRequest)g=await this.rawJsonRequest(w.i.Post,"/_matrix/client/v3/keys/upload",{},A.body);else if(A instanceof Q.KeysQueryRequest)g=await this.rawJsonRequest(w.i.Post,"/_matrix/client/v3/keys/query",{},A.body);else if(A instanceof Q.KeysClaimRequest)g=await this.rawJsonRequest(w.i.Post,"/_matrix/client/v3/keys/claim",{},A.body);else if(A instanceof Q.SignatureUploadRequest)g=await this.rawJsonRequest(w.i.Post,"/_matrix/client/v3/keys/signatures/upload",{},A.body);else if(A instanceof Q.KeysBackupRequest)g=await this.rawJsonRequest(w.i.Put,"/_matrix/client/v3/room_keys/keys",{},A.body);else if(A instanceof Q.ToDeviceRequest){const I=`/_matrix/client/v3/sendToDevice/${encodeURIComponent(A.event_type)}/`+encodeURIComponent(A.txn_id);g=await this.rawJsonRequest(w.i.Put,I,{},A.body)}else if(A instanceof Q.RoomMessageRequest){const I=`/_matrix/client/v3/room/${encodeURIComponent(A.room_id)}/send/${encodeURIComponent(A.event_type)}/${encodeURIComponent(A.txn_id)}`;g=await this.rawJsonRequest(w.i.Put,I,{},A.body)}else E.a.warn("Unsupported outgoing message",Object.getPrototypeOf(A)),g="";A.id&&await this.olmMachine.markRequestAsSent(A.id,A.type,g)}async rawJsonRequest(A,g,I,Q){const C={json:!1,headers:{"Content-Type":"application/json",Accept:"application/json"},prefix:""};try{const B=await this.http.authedRequest(A,g,I,Q,C);return E.a.info(`rust-crypto: successfully made HTTP request: ${A} ${g}`),B}catch(I){throw E.a.warn(`rust-crypto: error making HTTP request: ${A} ${g}: ${I}`),I}}}class n{constructor(A,g){this.olmMachine=A,this.outgoingRequestProcessor=g,B()(this,"currentClaimPromise",void 0),B()(this,"stopped",!1),this.currentClaimPromise=Promise.resolve()}stop(){this.stopped=!0}ensureSessionsForUsers(A){const g=this.currentClaimPromise.finally((()=>this.ensureSessionsForUsersInner(A)));return this.currentClaimPromise=g,g}async ensureSessionsForUsersInner(A){if(this.stopped)throw new Error("Cannot ensure Olm sessions: shutting down");const g=await this.olmMachine.getMissingSessions(A);g&&await this.outgoingRequestProcessor.makeOutgoingRequest(g)}}class N{con
|
||
|
//# sourceMappingURL=32.js.map
|