Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(crypto-nodejs) Implement missing APIs #721

Merged
merged 43 commits into from
Jun 9, 2022

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented May 31, 2022

Implementation of #699.

The work has started in #675. This PR is the sequel of it.

Progress

The methods that are needed for basic encryption/decryption are:

  • OlmMachine::new() -> OlmMachine::initialize() (since JavaScript cannot have async constructor, we use the factory pattern)
  • OlmMachine::receive_sync_changes()
  • OlmMachine::outgoing_requests()
  • OlmMachine::mark_request_as_sent()
  • OlmMachine::decrypt_room_event()
  • OlmMachine::update_tracked_users()
  • OlmMachine::get_missing_sessions()
  • OlmMachine::share_room_key()
  • OlmMachine::encrypt_raw()

Bonus:

  • OlmMachine::user_id()
  • OlmMachine::device_id()
  • OlmMachine::identity_keys()

Note: This PR includes #723 temporarily.

Other tasks than the binding itself:

  • Test suites are written to cover the entire API
  • CI has been updated to run the test
  • Documentation can be generated
  • Documentation is online (will be addressed in another PR to keep the scope of this one small)
  • README.md is written (and helpful)

@codecov
Copy link

codecov bot commented May 31, 2022

Codecov Report

Merging #721 (fe4ddfd) into main (7f49618) will decrease coverage by 0.06%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #721      +/-   ##
==========================================
- Coverage   71.61%   71.54%   -0.07%     
==========================================
  Files         117      118       +1     
  Lines       16432    16487      +55     
==========================================
+ Hits        11767    11796      +29     
- Misses       4665     4691      +26     
Impacted Files Coverage Δ
crates/matrix-sdk-crypto-nodejs/src/errors.rs 0.00% <0.00%> (ø)
crates/matrix-sdk-crypto-nodejs/src/responses.rs 0.00% <0.00%> (ø)
.../matrix-sdk-crypto/src/session_manager/sessions.rs 86.63% <0.00%> (-1.20%) ⬇️
crates/matrix-sdk/src/http_client.rs 87.65% <0.00%> (-0.45%) ⬇️
crates/matrix-sdk-crypto/src/identities/manager.rs 68.23% <0.00%> (-0.28%) ⬇️
crates/matrix-sdk-crypto/src/machine.rs 77.36% <0.00%> (-0.27%) ⬇️
crates/matrix-sdk-crypto-ffi/src/machine.rs 5.16% <0.00%> (-0.08%) ⬇️
crates/matrix-sdk-base/src/client.rs 78.77% <0.00%> (ø)
crates/matrix-sdk/src/room/joined.rs 52.50% <0.00%> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7f49618...fe4ddfd. Read the comment docs.

@Hywan Hywan added enhancement New feature or request bindings labels May 31, 2022
@Hywan Hywan marked this pull request as ready for review June 7, 2022 13:27
Copy link
Collaborator

@jplatte jplatte left a comment

Choose a reason for hiding this comment

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

Incomplete review, will continue later.

crates/matrix-sdk-crypto-nodejs/Cargo.toml Outdated Show resolved Hide resolved
crates/matrix-sdk-crypto-nodejs/README.md Outdated Show resolved Hide resolved
crates/matrix-sdk-crypto-nodejs/src/identifiers.rs Outdated Show resolved Hide resolved
Comment on lines 52 to 57
let user_id = user_id.inner.clone();
let device_id = device_id.inner.clone();

OlmMachine {
inner: matrix_sdk_crypto::OlmMachine::new(user_id.as_ref(), device_id.as_ref()).await,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should implement Deref<Target = ruma::UserId> for the nodejs UserId type, then this can be simplified to

Suggested change
let user_id = user_id.inner.clone();
let device_id = device_id.inner.clone();
OlmMachine {
inner: matrix_sdk_crypto::OlmMachine::new(user_id.as_ref(), device_id.as_ref()).await,
}
OlmMachine {
inner: matrix_sdk_crypto::OlmMachine::new(user_id, device_id).await,
}

crates/matrix-sdk-crypto-nodejs/src/identifiers.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-crypto-nodejs/src/machine.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-crypto-nodejs/src/errors.rs Show resolved Hide resolved
crates/matrix-sdk-crypto-nodejs/src/machine.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-crypto-nodejs/src/machine.rs Outdated Show resolved Hide resolved
crates/matrix-sdk-crypto-nodejs/src/machine.rs Outdated Show resolved Hide resolved
@Hywan Hywan merged commit 253affe into matrix-org:main Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bindings enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants