From 3aa1c30f5cd541eaeb7e40670ceeb50c050ba63d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 15 Mar 2023 14:47:40 +0100 Subject: [PATCH] Re-expose the vodozemac and matrix-sdk-crypto versions in the bindings --- bindings/matrix-sdk-crypto-ffi/src/lib.rs | 3 +++ bindings/matrix-sdk-crypto-js/src/lib.rs | 21 +++++++++++++++++ .../tests/machine.test.js | 17 ++++++++++++-- bindings/matrix-sdk-crypto-nodejs/src/lib.rs | 23 +++++++++++++++++++ .../tests/machine.test.js | 15 +++++++++++- 5 files changed, 76 insertions(+), 3 deletions(-) diff --git a/bindings/matrix-sdk-crypto-ffi/src/lib.rs b/bindings/matrix-sdk-crypto-ffi/src/lib.rs index aad28d805..4b1c0d55c 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/lib.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/lib.rs @@ -840,6 +840,9 @@ fn parse_user_id(user_id: &str) -> Result { } mod uniffi_types { + pub use matrix_sdk_crypto::VERSION; + pub use vodozemac::VERSION as VODOZEMAC_VERSION; + pub use crate::{ backup_recovery_key::{ BackupRecoveryKey, DecodeError, MegolmV1BackupKey, PassphraseInfo, PkDecryptionError, diff --git a/bindings/matrix-sdk-crypto-js/src/lib.rs b/bindings/matrix-sdk-crypto-js/src/lib.rs index afbacff00..4c2067a2b 100644 --- a/bindings/matrix-sdk-crypto-js/src/lib.rs +++ b/bindings/matrix-sdk-crypto-js/src/lib.rs @@ -40,6 +40,27 @@ pub mod vodozemac; use wasm_bindgen::prelude::*; +/// Object containing the versions of the Rust libraries we are using. +#[wasm_bindgen(getter_with_clone)] +#[derive(Debug)] +pub struct Versions { + /// The version of the vodozemac crate. + #[wasm_bindgen(readonly)] + pub vodozemac: &'static str, + /// The version of the matrix-sdk-crypto crate. + #[wasm_bindgen(readonly)] + pub matrix_sdk_crypto: &'static str, +} + +/// Get the versions of the Rust libraries we are using. +#[wasm_bindgen(js_name = "getVersions")] +pub fn get_versions() -> Versions { + Versions { + vodozemac: matrix_sdk_crypto::vodozemac::VERSION, + matrix_sdk_crypto: matrix_sdk_crypto::VERSION, + } +} + /// Run some stuff when the Wasm module is instantiated. /// /// Right now, it does the following: diff --git a/bindings/matrix-sdk-crypto-js/tests/machine.test.js b/bindings/matrix-sdk-crypto-js/tests/machine.test.js index 32a0ffa0d..871758e2a 100644 --- a/bindings/matrix-sdk-crypto-js/tests/machine.test.js +++ b/bindings/matrix-sdk-crypto-js/tests/machine.test.js @@ -7,7 +7,6 @@ const { EncryptionSettings, EventId, InboundGroupSession, - KeysClaimRequest, KeysQueryRequest, KeysUploadRequest, MaybeSignature, @@ -16,16 +15,30 @@ const { RequestType, RoomId, RoomMessageRequest, + ShieldColor, SignatureUploadRequest, ToDeviceRequest, UserId, UserIdentity, VerificationRequest, - ShieldColor, + VerificationState, + Versions, + getVersions, } = require("../pkg/matrix_sdk_crypto_js"); const { addMachineToMachine } = require("./helper"); require("fake-indexeddb/auto"); +describe("Versions", () => { + test("can find out the crate versions", async () => { + const versions = getVersions(); + + expect(versions).toBeInstanceOf(Versions) + expect(versions.vodozemac).toBeDefined() + expect(versions.matrix_sdk_crypto).toBeDefined() + }); + +}); + describe(OlmMachine.name, () => { test("can be instantiated with the async initializer", async () => { expect(await OlmMachine.initialize(new UserId("@foo:bar.org"), new DeviceId("baz"))).toBeInstanceOf(OlmMachine); diff --git a/bindings/matrix-sdk-crypto-nodejs/src/lib.rs b/bindings/matrix-sdk-crypto-nodejs/src/lib.rs index 26e165fd4..98a90bcea 100644 --- a/bindings/matrix-sdk-crypto-nodejs/src/lib.rs +++ b/bindings/matrix-sdk-crypto-nodejs/src/lib.rs @@ -16,6 +16,8 @@ #![cfg_attr(docsrs, feature(doc_auto_cfg))] //#![warn(missing_docs, missing_debug_implementations)] +use napi_derive::napi; + pub mod attachment; pub mod encryption; mod errors; @@ -31,4 +33,25 @@ pub mod tracing; pub mod types; pub mod vodozemac; +/// Object containing the versions of the Rust libraries we are using. +#[napi(object)] +pub struct Versions { + /// The version of the vodozemac crate. + #[napi(getter)] + pub vodozemac: &'static str, + + /// The version of the matrix-sdk-crypto crate. + #[napi(getter)] + pub matrix_sdk_crypto: &'static str, +} + +/// Get the versions of the Rust libraries we are using. +#[napi(js_name = "getVersions")] +pub fn get_versions() -> Versions { + Versions { + vodozemac: matrix_sdk_crypto::vodozemac::VERSION, + matrix_sdk_crypto: matrix_sdk_crypto::VERSION, + } +} + use crate::errors::into_err; diff --git a/bindings/matrix-sdk-crypto-nodejs/tests/machine.test.js b/bindings/matrix-sdk-crypto-nodejs/tests/machine.test.js index 90ed77f19..e1223f4aa 100644 --- a/bindings/matrix-sdk-crypto-nodejs/tests/machine.test.js +++ b/bindings/matrix-sdk-crypto-nodejs/tests/machine.test.js @@ -14,8 +14,10 @@ const { VerificationState, CrossSigningStatus, MaybeSignature, - StoreType, ShieldColor, + StoreType, + Versions, + getVersions, } = require("../"); const path = require("path"); const os = require("os"); @@ -28,6 +30,17 @@ describe("StoreType", () => { }); }); +describe("Versions", () => { + test("can find out the crate versions", async () => { + const versions = getVersions(); + + expect(versions).toBeInstanceOf(Versions) + expect(versions.vodozemac).toBeDefined() + expect(versions.matrix_sdk_crypto).toBeDefined() + }); + +}); + describe(OlmMachine.name, () => { test("cannot be instantiated with the constructor", () => { expect(() => {