Skip to content

Rust crypto: only one account in the store #3974

@moufmouf

Description

@moufmouf

Hey!

I'm currently trying to create a Matrix client inside WorkAventure.

So far, I managed to set up Rust crypto and everything seems to run fine. I can log into my application using my "john.doe" user and the connection to Synapse is successful.

However, if I log out, and log in with another used ("jane.doe"), I'm getting the following error during the call to await client.initRustCrypto();:

the account in the store doesn't match the account in the constructor: expected @john.doe:matrix.workadventure.localhost:ULlGg2Bzxv, got @jane.doe:matrix.workadventure.localhost:aUM4pNrpuo

I'm quite new to Matrix so I don't know if I stumbled on a bug or if there is something I don't understand.

My expectation was that a store could contain several accounts.

Am I supposed to purge the store when someone logs out?

When I look at the code, I see that the name of the indexedDb we use to store the crypto keys is always the same (it is RUST_SDK_STORE_PREFIX):

matrix-js-sdk/src/client.ts

Lines 2320 to 2329 in 48d4f1b

const rustCrypto = await RustCrypto.initRustCrypto(
this.logger,
this.http,
userId,
deviceId,
this.secretStorage,
this.cryptoCallbacks,
useIndexedDB ? RUST_SDK_STORE_PREFIX : null,
this.pickleKey,
);

If the store can only contain one user, wouldn't it make sense to create one store per user?

Something like:

        const rustCrypto = await RustCrypto.initRustCrypto(
            this.logger,
            this.http,
            userId,
            deviceId,
            this.secretStorage,
            this.cryptoCallbacks,
-           useIndexedDB ? RUST_SDK_STORE_PREFIX : null,
+           useIndexedDB ? RUST_SDK_STORE_PREFIX + userId : null,
            this.pickleKey,
        );

Or is there something I don't understand?

Note: I will happily contribute a PR if this is something that needs fixing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions