Skip to content

Error: Can't find the room key to decrypt the event #378

@Ser5

Description

@Ser5

Describe the bug
https://turt2live.github.io/matrix-bot-sdk/tutorial-encryption-bots.html
can't get this example to work - getting error "Error: Can't find the room key to decrypt the event" for every new message in the room.

To Reproduce
Steps to reproduce the behavior:

  1. npm install @matrix-org/olm matrix-js-sdk matrix-bot-sdk
  2. Have an encrypted private room
  3. Write down its ID
  4. Create a bot account
  5. Make sure that it hasn't any superfluous devices and E2E keys
  6. Log bot in to get an access token:
    import * as sdk from "matrix-js-sdk";
    
    const client = sdk.createClient({
        baseUrl: "https://matrix.example.com",
        deviceId: 'YOURDEVICE',
    });
    
    const loginResponse = await client.loginRequest({
        type:     "m.login.password",
        user:     "@bot:example.com",
        password: "botSecurePassword",
        device_id: 'YOURDEVICE',
    });
    console.log("Access Token:", loginResponse.access_token);
  7. Invite the bot to the room via Element /invite @bot:example.com
  8. Accept invitation for bot (use any script applicable)
  9. Run a script from the example via node
    import * as sdk from "matrix-bot-sdk";
    
    const homeserverUrl  = "https://matrix.example.com";
    const botAccessToken = "syt_...";
    
    const storageProvider = new sdk.SimpleFsStorageProvider("./bot-storage/bot.json");
    const cryptoProvider  = new sdk.RustSdkCryptoStorageProvider("./bot-storage/crypto");
    
    const client = new sdk.MatrixClient(homeserverUrl, botAccessToken, storageProvider, cryptoProvider);
    
    client.on("room.message", (roomId, event) => {
        if (!event['content']?.['msgtype']) return;
        console.log(event);
    });
    
    client.start().then(() => console.log("Bot started!"));
  10. Send some messages from Element to the room
  11. See console

Expected behavior
console.log(event) producing something meaningful.

Log snippet

(node:261538) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
MatrixHttpClient (REQ-2) { errcode: 'M_NOT_FOUND', error: 'Account data not found' }
MatrixClientLite End-to-end encryption enabled
Bot started!
MatrixClientLite Decryption error on !OktwJGBgCDQnsIALCM:example.com $LTGPVbZDtDvILZOGj4shj3Wu7RD63Vp2Cpz4HutAEt4 [Error: Can't find the room key to decrypt the event] {
  code: 'GenericFailure'
}
MatrixClientLite Decryption error on !OktwJGBgCDQnsIALCM:example.com $9TZZVw_pLPGgZ2PaVCMxJhFiV2ot9srYJhuRk5-RYug [Error: Can't find the room key to decrypt the event] {
  code: 'GenericFailure'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions