Skip to content

Conversation

@xsanm
Copy link
Collaborator

@xsanm xsanm commented Dec 2, 2025

Summary:
ENG-11531.

There is one thing with naming which is not obvious, this is using Olm name - Olm is still part of Vodozemac crate, so I think this is still correct, but I am okay with updating this too.

I tried to make the API as similar as it is possible, so there are files where changing the import is everything we have to do.

I redefined EncryptResult in lib/. Importing it from Olm was a bad idea because it was used on native too, which causes Olm/Vodozemac wasm to be bundled into native, which worked with Olm but not with Vodozemac.

Depends on D15547

Test Plan: Test encrypt/decrypt and create a session with Olm and Vodozemac.

Reviewers: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D15548

@xsanm xsanm requested a review from Ashoat December 2, 2025 16:00
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

},
"transformIgnorePatterns": [
"/node_modules/(?!@babel/runtime)"
"/node_modules/(?!(@babel/runtime|@commapp/vodozemac))"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only for tests. @commapp/vodozemac was configured with "type": "module" (using ES6), while Jest runs in Node's CommonJS environment by default, so without transformation, it can't understand these ES6 export statements


const prekey = account.prekey();
const prekeySignature = account.prekey_signature();
if (!prekey) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we adding this check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Olm, prekey was typed as defined because it was always returned. Olm just read bytes of memory allocated for the prekey struct, even though it wasn't generated, so there was a chance to get some trash bytes as prekey. We even had an issue with it (link).

In Rust, it is not easy to just read a chunk of memory where the prekey should be, so to make it work, I've made it optional, and we need to check if this exists here.

Prekey is set during account creation, so this couldn't have happened. Taking a step back, probably throwing an error was a better fit than making it optional, but fixing this now is probably too much work

Comment on lines +21 to +24
const identityKeys = JSON.stringify({
ed25519: account.ed25519_key,
curve25519: account.curve25519_key,
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we need these conversions on the other platforms? Should we have functions to implent this conversion, as wella s the prekey and one-time key conversions below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prekey and one-time key conversions are deprecated, the only exception is this particular endpoint.

For identity keys, this is something that can be improved even further, created ENG-11553 because here it gets too messy.

): Promise<{ +result: T, +pickledOlmAccount: PickledOlmAccount }> {
const { picklingKey, pickledAccount } = pickledOlmAccount;

await olm.init();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need an equivalent init call for Vodozemac?

Copy link
Collaborator Author

@xsanm xsanm Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really sure why this call was added here. Both Olm before, and Vodozemac now are initialized at keyserver start here, I think this is unnecessary no-op, but I can add it if you think it is better to keep it as it is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's bring these back so that standalone scripts can still work

} {
const prekey = getPrekeyValueFromBlob(account.prekey());
const prekey = account.prekey();
if (!prekey) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we adding this check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new Error(`error decrypt => ${OLM_ERROR_FLAG} ` + e.message);
}

olmMessage.free();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do this in a finally block

// into_session() is consuming object.
// There is no need to call free() on inboundCreationResult
session = inboundCreationResult.into_session();
olmMessage.free();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this not be freed if an exception is thrown above?


const olmMessage = new OlmMessage(type, encryptedPayload);
const decryptedString = session.decrypt(olmMessage);
olmMessage.free();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this not be freed if an exception is thrown above?

throw new Error(`error decrypt => ${OLM_ERROR_FLAG} ` + e.message);
}

olmMessage.free();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finally?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to have been addressed

// There is no need to call free() on inboundCreationResult
const initialEncryptedMessage = inboundCreationResult.plaintext;
const session = inboundCreationResult.into_session();
olmMessage.free();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finally?

@xsanm xsanm force-pushed the vodozemac-work-part-2 branch from f3e1025 to 080ab37 Compare December 3, 2025 12:09
@xsanm xsanm force-pushed the vodozemac-work-part-3 branch 2 times, most recently from 17ec456 to 2c625b5 Compare December 3, 2025 15:47
);
result = olmSession.session.decrypt(olmMessage);
} catch (e) {
olmMessage.free();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this one

throw new Error(`error decrypt => ${OLM_ERROR_FLAG} ` + e.message);
}

olmMessage.free();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to have been addressed

);
} catch (e) {
session.free();
olmMessage.free();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this one

): Promise<{ +result: T, +pickledOlmAccount: PickledOlmAccount }> {
const { picklingKey, pickledAccount } = pickledOlmAccount;

await olm.init();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's bring these back so that standalone scripts can still work

Summary:
[ENG-11531](https://linear.app/comm/issue/ENG-11531/migrate-the-full-crypto-api-to-vodozemac).

There is one thing with naming which is not obvious, this is using Olm name - Olm is still part of Vodozemac crate, so I think this is still correct, but I am okay with updating this too.

I tried to make API as similar as it is possible, so there are files when changing import is everything we have to do.

I redefined `EncryptResult` in `lib/`. Importing it from Olm was bad idea because it was used on native too, which causes Olm/Vodozemac wasm to be bundled into native, which worked with Olm but not with Vodozemac.

Depends on D15547

Test Plan: Test encrypt/decrypt and creating session with Olm and Vodozemac.

Reviewers: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D15548
@xsanm xsanm force-pushed the vodozemac-work-part-3 branch from 2c625b5 to d87e0e8 Compare December 3, 2025 16:11
Summary:
[ENG-11531](https://linear.app/comm/issue/ENG-11531/migrate-the-full-crypto-api-to-vodozemac).

Making vodozemac available on native.

Branch needs to be updated after PRs are merged

Test Plan: Tested in next diff

Reviewers: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D15549
@Ashoat Ashoat merged commit df4e62a into vodozemac-work-part-2 Dec 3, 2025
@Ashoat Ashoat deleted the vodozemac-work-part-3 branch December 3, 2025 17:09
Ashoat pushed a commit that referenced this pull request Dec 3, 2025
…#324)

* [lib][web][keyserver] add Vodozemac library and `.wasm` file handling

Summary:
[ENG-11531](https://linear.app/comm/issue/ENG-11531/migrate-the-full-crypto-api-to-vodozemac).

Using the same pattern as have for existing `.wasm` files (Olm, SQLite and Backup Client).

Currently linking my local library, so CI will fail. This should be updated to NPM package after CommE2E/vodozemac#3 is merged and published.

This diff shouldn't be landed without following one with API migration, because it replaces initializing Olm with Vodozemac, so Olm is not working anymore.

Depends on D15546

Test Plan: Run web and keyserver, vodozemac should be available, usage tested in next diff

Reviewers: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D15547

* [lib][web][keyserver] replace Olm with Vodozemac's Olm (#325)

* [lib][web][keyserver] replace Olm with Vodozemac's Olm

Summary:
[ENG-11531](https://linear.app/comm/issue/ENG-11531/migrate-the-full-crypto-api-to-vodozemac).

There is one thing with naming which is not obvious, this is using Olm name - Olm is still part of Vodozemac crate, so I think this is still correct, but I am okay with updating this too.

I tried to make API as similar as it is possible, so there are files when changing import is everything we have to do.

I redefined `EncryptResult` in `lib/`. Importing it from Olm was bad idea because it was used on native too, which causes Olm/Vodozemac wasm to be bundled into native, which worked with Olm but not with Vodozemac.

Depends on D15547

Test Plan: Test encrypt/decrypt and creating session with Olm and Vodozemac.

Reviewers: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D15548

* [native] implement CXX bindings to Vodozemac (#326)

Summary:
[ENG-11531](https://linear.app/comm/issue/ENG-11531/migrate-the-full-crypto-api-to-vodozemac).

Making vodozemac available on native.

Branch needs to be updated after PRs are merged

Test Plan: Tested in next diff

Reviewers: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D15549
xsanm added a commit that referenced this pull request Dec 4, 2025
…#324)

* [lib][web][keyserver] add Vodozemac library and `.wasm` file handling

Summary:
[ENG-11531](https://linear.app/comm/issue/ENG-11531/migrate-the-full-crypto-api-to-vodozemac).

Using the same pattern as have for existing `.wasm` files (Olm, SQLite and Backup Client).

Currently linking my local library, so CI will fail. This should be updated to NPM package after CommE2E/vodozemac#3 is merged and published.

This diff shouldn't be landed without following one with API migration, because it replaces initializing Olm with Vodozemac, so Olm is not working anymore.

Depends on D15546

Test Plan: Run web and keyserver, vodozemac should be available, usage tested in next diff

Reviewers: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D15547

* [lib][web][keyserver] replace Olm with Vodozemac's Olm (#325)

* [lib][web][keyserver] replace Olm with Vodozemac's Olm

Summary:
[ENG-11531](https://linear.app/comm/issue/ENG-11531/migrate-the-full-crypto-api-to-vodozemac).

There is one thing with naming which is not obvious, this is using Olm name - Olm is still part of Vodozemac crate, so I think this is still correct, but I am okay with updating this too.

I tried to make API as similar as it is possible, so there are files when changing import is everything we have to do.

I redefined `EncryptResult` in `lib/`. Importing it from Olm was bad idea because it was used on native too, which causes Olm/Vodozemac wasm to be bundled into native, which worked with Olm but not with Vodozemac.

Depends on D15547

Test Plan: Test encrypt/decrypt and creating session with Olm and Vodozemac.

Reviewers: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D15548

* [native] implement CXX bindings to Vodozemac (#326)

Summary:
[ENG-11531](https://linear.app/comm/issue/ENG-11531/migrate-the-full-crypto-api-to-vodozemac).

Making vodozemac available on native.

Branch needs to be updated after PRs are merged

Test Plan: Tested in next diff

Reviewers: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D15549
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants