@@ -290,6 +290,33 @@ export default class EventIndex extends EventEmitter {
290
290
return validEventType && validMsgType && hasContentValue ;
291
291
}
292
292
293
+ eventToJson ( ev ) {
294
+ const jsonEvent = ev . toJSON ( ) ;
295
+ const e = ev . isEncrypted ( ) ? jsonEvent . decrypted : jsonEvent ;
296
+
297
+ if ( ev . isEncrypted ( ) ) {
298
+ // Let us store some additional data so we can re-verify the event.
299
+ // The js-sdk checks if an event is encrypted using the algorithm,
300
+ // the sender key and ed25519 signing key are used to find the
301
+ // correct device that sent the event which allows us to check the
302
+ // verification state of the event, either directly or using cross
303
+ // signing.
304
+ e . curve25519Key = ev . getSenderKey ( ) ;
305
+ e . ed25519Key = ev . getClaimedEd25519Key ( ) ;
306
+ e . algorithm = ev . getWireContent ( ) . algorithm ;
307
+ e . forwardingCurve25519KeyChain = ev . getForwardingCurve25519KeyChain ( ) ;
308
+ } else {
309
+ // Make sure that unencrypted events don't contain any of that data,
310
+ // despite what the server might give to us.
311
+ delete e . curve25519Key ;
312
+ delete e . ed25519Key ;
313
+ delete e . algorithm ;
314
+ delete e . forwardingCurve25519KeyChain ;
315
+ }
316
+
317
+ return e ;
318
+ }
319
+
293
320
/**
294
321
* Queue up live events to be added to the event index.
295
322
*
@@ -300,8 +327,7 @@ export default class EventIndex extends EventEmitter {
300
327
301
328
if ( ! this . isValidEvent ( ev ) ) return ;
302
329
303
- const jsonEvent = ev . toJSON ( ) ;
304
- const e = ev . isEncrypted ( ) ? jsonEvent . decrypted : jsonEvent ;
330
+ const e = this . eventToJson ( ev ) ;
305
331
306
332
const profile = {
307
333
displayname : ev . sender . rawDisplayName ,
@@ -477,8 +503,7 @@ export default class EventIndex extends EventEmitter {
477
503
// Let us convert the events back into a format that EventIndex can
478
504
// consume.
479
505
const events = filteredEvents . map ( ( ev ) => {
480
- const jsonEvent = ev . toJSON ( ) ;
481
- const e = ev . isEncrypted ( ) ? jsonEvent . decrypted : jsonEvent ;
506
+ const e = this . eventToJson ( ev ) ;
482
507
483
508
let profile = { } ;
484
509
if ( e . sender in profiles ) profile = profiles [ e . sender ] ;
0 commit comments