diff --git a/CHANGELOG.md b/CHANGELOG.md index e56b28348..aab9d31e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # UNRELEASED +**BREAKING CHANGES** + +- Update matrix-rusk-sdk to `0.9.0`. +- Expose new API `DehydratedDevices.getDehydratedDeviceKey`, `DehydratedDevices.saveDehydratedDeviceKey` + and `DehydratedDevices.deleteDehydratedDeviceKey` to store/load the dehydrated device pickle key. + `DehydratedDevices.keysForUpload` and `DehydratedDevices.rehydrate` now use the `DehydratedDeviceKey` as parameter + instead of a raw UInt8Array.Use `DehydratedDeviceKey::createKeyFromArray` to migrate. + # matrix-sdk-crypto-wasm v12.1.0 - Update matrix-rusk-sdk to `37c17cf854a70f` for the fix for diff --git a/Cargo.lock b/Cargo.lock index 4cf93d1bf..5d0034928 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,9 +61,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" +checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7" [[package]] name = "aquamarine" @@ -210,9 +210,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" +checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] name = "cbc" @@ -225,9 +225,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.1" +version = "1.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" +checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e" dependencies = [ "shlex", ] @@ -291,9 +291,9 @@ checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "const_panic" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "013b6c2c3a14d678f38cd23994b02da3a1a1b6a5d1eedddfe63a5a5f11b13a81" +checksum = "53857514f72ee4a2b583de67401e3ff63a5472ca4acf289d09a9ea7636dfec17" [[package]] name = "constant_time_eq" @@ -644,9 +644,9 @@ dependencies = [ [[package]] name = "http" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea" dependencies = [ "bytes", "fnv", @@ -852,9 +852,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" dependencies = [ "equivalent", "hashbrown", @@ -897,10 +897,11 @@ checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "js-sys" -version = "0.3.70" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" dependencies = [ + "once_cell", "wasm-bindgen", ] @@ -924,9 +925,9 @@ dependencies = [ [[package]] name = "konst" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b65f00fb3910881e52bf0850ae2a82aea411488a557e1c02820ceaa60963dce3" +checksum = "298ddf99f06a97c1ecd0e910932662b7842855046234b0d0376d35d93add087f" dependencies = [ "const_panic", "konst_kernel", @@ -935,9 +936,9 @@ dependencies = [ [[package]] name = "konst_kernel" -version = "0.3.12" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "599c1232f55c72c7fc378335a3efe1c878c92720838c8e6a4fd87784ef7764de" +checksum = "e4b1eb7788f3824c629b1116a7a9060d6e898c358ebff59070093d51103dcc3c" dependencies = [ "typewit", ] @@ -950,9 +951,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.166" +version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2ccc108bbc0b1331bd061864e7cd823c0cab660bbe6970e66e2c0614decde36" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "litemap" @@ -1044,8 +1045,8 @@ dependencies = [ [[package]] name = "matrix-sdk-common" -version = "0.8.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#37c17cf854a70fe6f719c7fde49a6b0e4402988f" +version = "0.9.0" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#b18100228e0456973d56d4ac6a58caf30b17bd8d" dependencies = [ "async-trait", "eyeball-im", @@ -1056,7 +1057,7 @@ dependencies = [ "ruma", "serde", "serde_json", - "thiserror 2.0.3", + "thiserror 2.0.8", "tokio", "tracing", "tracing-subscriber", @@ -1067,8 +1068,8 @@ dependencies = [ [[package]] name = "matrix-sdk-crypto" -version = "0.8.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#37c17cf854a70fe6f719c7fde49a6b0e4402988f" +version = "0.9.0" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#b18100228e0456973d56d4ac6a58caf30b17bd8d" dependencies = [ "aes", "aquamarine", @@ -1095,7 +1096,7 @@ dependencies = [ "serde_json", "sha2", "subtle", - "thiserror 2.0.3", + "thiserror 2.0.8", "time", "tokio", "tokio-stream", @@ -1134,8 +1135,8 @@ dependencies = [ [[package]] name = "matrix-sdk-indexeddb" -version = "0.8.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#37c17cf854a70fe6f719c7fde49a6b0e4402988f" +version = "0.9.0" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#b18100228e0456973d56d4ac6a58caf30b17bd8d" dependencies = [ "anyhow", "async-trait", @@ -1152,7 +1153,7 @@ dependencies = [ "serde-wasm-bindgen 0.6.5", "serde_json", "sha2", - "thiserror 2.0.3", + "thiserror 2.0.8", "tokio", "tracing", "wasm-bindgen", @@ -1162,20 +1163,20 @@ dependencies = [ [[package]] name = "matrix-sdk-qrcode" -version = "0.8.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#37c17cf854a70fe6f719c7fde49a6b0e4402988f" +version = "0.9.0" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#b18100228e0456973d56d4ac6a58caf30b17bd8d" dependencies = [ "byteorder", "qrcode", "ruma-common", - "thiserror 2.0.3", + "thiserror 2.0.8", "vodozemac", ] [[package]] name = "matrix-sdk-store-encryption" -version = "0.8.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#37c17cf854a70fe6f719c7fde49a6b0e4402988f" +version = "0.9.0" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#b18100228e0456973d56d4ac6a58caf30b17bd8d" dependencies = [ "base64", "blake3", @@ -1187,7 +1188,7 @@ dependencies = [ "serde", "serde_json", "sha2", - "thiserror 2.0.3", + "thiserror 2.0.8", "zeroize", ] @@ -1209,9 +1210,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.8.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" dependencies = [ "adler2", ] @@ -1388,9 +1389,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f" +checksum = "2c0fef6c4230e4ccf618a35c59d7ede15dea37de8427500f50aff708806e42ec" dependencies = [ "bytes", "prost-derive", @@ -1398,9 +1399,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" +checksum = "157c5a9d7ea5c2ed2d9fb8f495b64759f7816c7eaea54ba3978f0d63000162e3" dependencies = [ "anyhow", "itertools 0.13.0", @@ -1522,9 +1523,9 @@ dependencies = [ [[package]] name = "ruma" -version = "0.11.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94984418ae8a5e1160e6c87608141330e9ae26330abf22e3d15416efa96d48a" +checksum = "f5100fcaf13d18b9c5c2dfdee5632c428e3201b04ddefd82c930953b461d000a" dependencies = [ "assign", "js_int", @@ -1537,9 +1538,9 @@ dependencies = [ [[package]] name = "ruma-client-api" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "325e054db8d5545c00767d9868356d61e63f2c6cb8b54768346d66696ea4ad48" +checksum = "25f5929f675a96adb22dcfbab1c527862d7f92a6346a280f2ddcfc6380b19391" dependencies = [ "as_variant", "assign", @@ -1554,16 +1555,16 @@ dependencies = [ "serde", "serde_html_form", "serde_json", - "thiserror 1.0.69", + "thiserror 2.0.8", "url", "web-time", ] [[package]] name = "ruma-common" -version = "0.14.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad71c7f49abaa047ba228339d34f9aaefa4d8b50ebeb8e859d0340cc2138bda8" +checksum = "6c537899b20312655aa9bf4cd825aaf00dd13203f215df2007bc4fbbeac8d8ba" dependencies = [ "as_variant", "base64", @@ -1583,7 +1584,7 @@ dependencies = [ "serde", "serde_html_form", "serde_json", - "thiserror 1.0.69", + "thiserror 2.0.8", "time", "tracing", "url", @@ -1594,9 +1595,9 @@ dependencies = [ [[package]] name = "ruma-events" -version = "0.29.1" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be86dccf3504588c1f4dc1bda4ce1f8bbd646fc6dda40c77cc7de6e203e62dad" +checksum = "34e4f72eb598c62f51a199bd9218f3fc36a5d50361ecc7a30d864df7bfcef220" dependencies = [ "as_variant", "indexmap", @@ -1609,7 +1610,7 @@ dependencies = [ "ruma-macros", "serde", "serde_json", - "thiserror 1.0.69", + "thiserror 2.0.8", "tracing", "url", "web-time", @@ -1618,22 +1619,21 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e7f9b534a65698d7db3c08d94bf91de0046fe6c7893a7b360502f65e7011ac4" +checksum = "6ad674b5e5368c53a2c90fde7dac7e30747004aaf7b1827b72874a25fc06d4d8" dependencies = [ "js_int", - "thiserror 1.0.69", + "thiserror 2.0.8", ] [[package]] name = "ruma-macros" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d57d3cb20e8e758e8f7c5e408ce831d46758003b615100099852e468631934" +checksum = "ff7bc55ea278668253c9898dd905325bf1f72df4bf2abddd04ff1c99b7b3c4fb" dependencies = [ "cfg-if", - "once_cell", "proc-macro-crate", "proc-macro2", "quote", @@ -1687,15 +1687,15 @@ checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" [[package]] name = "semver" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" [[package]] name = "serde" -version = "1.0.215" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" dependencies = [ "serde_derive", ] @@ -1733,9 +1733,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" dependencies = [ "proc-macro2", "quote", @@ -1850,9 +1850,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.89" +version = "2.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" dependencies = [ "proc-macro2", "quote", @@ -1881,11 +1881,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.3" +version = "2.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +checksum = "08f5383f3e0071702bf93ab5ee99b52d26936be9dedd9413067cbdcddcb6141a" dependencies = [ - "thiserror-impl 2.0.3", + "thiserror-impl 2.0.8", ] [[package]] @@ -1901,9 +1901,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.3" +version = "2.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +checksum = "f2f357fcec90b3caef6623a099691be676d033b40a058ac95d2a6ade6fa0c943" dependencies = [ "proc-macro2", "quote", @@ -1922,9 +1922,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.36" +version = "0.3.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" dependencies = [ "deranged", "itoa", @@ -1945,9 +1945,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" dependencies = [ "num-conv", "time-core", @@ -1980,9 +1980,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.41.1" +version = "1.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" +checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" dependencies = [ "backtrace", "pin-project-lite", @@ -2002,9 +2002,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" dependencies = [ "futures-core", "pin-project-lite", @@ -2014,9 +2014,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.12" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078" dependencies = [ "bytes", "futures-core", @@ -2104,9 +2104,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" dependencies = [ "nu-ansi-term", "sharded-slab", @@ -2124,9 +2124,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "typewit" -version = "1.10.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d51dbd25812f740f45e2a9769f84711982e000483b13b73a8a1852e092abac8c" +checksum = "cb77c29baba9e4d3a6182d51fa75e3215c7fd1dab8f4ea9d107c716878e55fc0" dependencies = [ "typewit_proc_macros", ] @@ -2270,9 +2270,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.93" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" dependencies = [ "cfg-if", "once_cell", @@ -2281,13 +2281,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.93" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", "syn", @@ -2296,21 +2295,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.43" +version = "0.4.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" dependencies = [ "cfg-if", "js-sys", + "once_cell", "wasm-bindgen", "web-sys", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.93" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2318,9 +2318,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.93" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", @@ -2331,17 +2331,16 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.93" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" [[package]] name = "wasm-bindgen-test" -version = "0.3.43" +version = "0.3.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68497a05fb21143a08a7d24fc81763384a3072ee43c44e86aad1744d6adef9d9" +checksum = "c61d44563646eb934577f2772656c7ad5e9c90fac78aa8013d776fcdaf24625d" dependencies = [ - "console_error_panic_hook", "js-sys", "minicov", "scoped-tls", @@ -2352,9 +2351,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.43" +version = "0.3.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8220be1fa9e4c889b30fd207d4906657e7e90b12e0e6b0c8b8d8709f5de021" +checksum = "54171416ce73aa0b9c377b51cc3cb542becee1cd678204812e8392e5b0e4a031" dependencies = [ "proc-macro2", "quote", @@ -2363,9 +2362,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.70" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/src/dehydrated_devices.rs b/src/dehydrated_devices.rs index f3deb9718..529d20e5d 100644 --- a/src/dehydrated_devices.rs +++ b/src/dehydrated_devices.rs @@ -3,7 +3,9 @@ //! WASM wrapper for `matrix_sdk_crypto::dehydrated_devices`. use js_sys::{Array, JsString, Uint8Array}; -use matrix_sdk_crypto::dehydrated_devices; +use matrix_sdk_crypto::{ + dehydrated_devices, store::DehydratedDeviceKey as InnerDehydratedDeviceKey, +}; use wasm_bindgen::prelude::*; use crate::{identifiers::DeviceId, requests::PutDehydratedDeviceRequest, store::RoomKeyInfo}; @@ -21,9 +23,46 @@ impl From for DehydratedDevices { } } +/// Dehydrated device key +#[wasm_bindgen] +#[derive(Debug)] +pub struct DehydratedDeviceKey { + inner: InnerDehydratedDeviceKey, +} + +#[wasm_bindgen] +impl DehydratedDeviceKey { + /// Generates a new random dehydrated device key. + #[wasm_bindgen(js_name = "createRandomKey")] + pub fn create_random_key() -> Result { + Ok(DehydratedDeviceKey { inner: InnerDehydratedDeviceKey::new()? }) + } + + /// Generates a dehydrated device key from a given array. + #[wasm_bindgen(js_name = "createKeyFromArray")] + pub fn create_key_from_array(array: Uint8Array) -> Result { + Ok(DehydratedDeviceKey { + inner: InnerDehydratedDeviceKey::from_slice(array.to_vec().as_slice())?, + }) + } + + /// Convert the dehydrated device key to a base64-encoded string. + #[wasm_bindgen(js_name = "toBase64")] + pub fn to_base64(&self) -> JsString { + self.inner.to_base64().into() + } +} + +impl From for DehydratedDeviceKey { + fn from(inner: InnerDehydratedDeviceKey) -> Self { + DehydratedDeviceKey { inner } + } +} + #[wasm_bindgen] impl DehydratedDevices { - /// Create a new [`DehydratedDevice`] which can be uploaded to the server. + /// Create a new {@link DehydratedDevice} which can be uploaded to the + /// server. #[wasm_bindgen] pub async fn create(&self) -> Result { Ok(self.inner.create().await?.into()) @@ -33,18 +72,47 @@ impl DehydratedDevices { #[wasm_bindgen] pub async fn rehydrate( &self, - pickle_key: &Uint8Array, + dehydrated_device_key: &DehydratedDeviceKey, device_id: &DeviceId, device_data: &str, ) -> Result { - let pickle_key: [u8; 32] = - pickle_key.to_vec().try_into().map_err(|_| JsError::new("Wrong key length"))?; Ok(self .inner - .rehydrate(&pickle_key, &device_id.inner, serde_json::from_str(device_data)?) + .rehydrate( + &dehydrated_device_key.inner, + &device_id.inner, + serde_json::from_str(device_data)?, + ) .await? .into()) } + + /// Get the cached dehydrated device key if any. + /// + /// `None` if the key was not previously cached (via + /// {@link DehydratedDevices.saveDehydratedDeviceKey}). + #[wasm_bindgen(js_name = "getDehydratedDeviceKey")] + pub async fn get_dehydrated_device_key(&self) -> Result, JsError> { + let key = self.inner.get_dehydrated_device_pickle_key().await?; + Ok(key.map(DehydratedDeviceKey::from)) + } + + /// Store the dehydrated device key in the crypto store. + #[wasm_bindgen(js_name = "saveDehydratedDeviceKey")] + pub async fn save_dehydrated_device_key( + &self, + dehydrated_device_key: &DehydratedDeviceKey, + ) -> Result<(), JsError> { + self.inner.save_dehydrated_device_pickle_key(&dehydrated_device_key.inner).await?; + Ok(()) + } + + /// Clear the dehydrated device key saved in the crypto store. + #[wasm_bindgen(js_name = "deleteDehydratedDeviceKey")] + pub async fn delete_dehydrated_device_key(&self) -> Result<(), JsError> { + self.inner.delete_dehydrated_device_pickle_key().await?; + Ok(()) + } } #[wasm_bindgen] @@ -104,13 +172,11 @@ impl DehydratedDevice { pub async fn keys_for_upload( &self, initial_device_display_name: JsString, - pickle_key: Uint8Array, + dehydrated_device_key: &DehydratedDeviceKey, ) -> Result { - let pickle_key: [u8; 32] = - pickle_key.to_vec().try_into().map_err(|_| JsError::new("Wrong key length"))?; Ok(self .inner - .keys_for_upload(initial_device_display_name.into(), &pickle_key) + .keys_for_upload(initial_device_display_name.into(), &dehydrated_device_key.inner) .await? .try_into()?) } diff --git a/src/machine.rs b/src/machine.rs index c0c5ba5f9..ba2efc45c 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -1324,10 +1324,14 @@ impl OlmMachine { copy_stream_to_callback( stream, - |input| { - iter::once( - input.into_iter().map(RoomKeyInfo::from).map(JsValue::from).collect::(), - ) + |input| match input { + Ok(keys) => iter::once( + keys.into_iter().map(RoomKeyInfo::from).map(JsValue::from).collect::(), + ), + Err(e) => { + warn!("Error reading room_keys_received_stream {:?}", e); + iter::once(Array::new()) + } }, callback, "room-key-received", diff --git a/tests/dehydrated_devices.test.ts b/tests/dehydrated_devices.test.ts index 56fda71ef..fa2bc7bdc 100644 --- a/tests/dehydrated_devices.test.ts +++ b/tests/dehydrated_devices.test.ts @@ -1,4 +1,5 @@ import { + DehydratedDeviceKey, DecryptionSettings, DeviceId, DeviceLists, @@ -21,6 +22,41 @@ afterEach(() => { }); describe("dehydrated devices", () => { + test("can save and restore dehydrated device pickle key", async () => { + const user = new UserId("@alice:example.org"); + // set up OlmMachine to dehydrated device + const machine = await OlmMachine.initialize(user, new DeviceId("ABCDEFG")); + + const dehydratedDevices = machine.dehydratedDevices(); + const key = DehydratedDeviceKey.createRandomKey(); + + await dehydratedDevices.saveDehydratedDeviceKey(key); + + const loaded_key: DehydratedDeviceKey = await dehydratedDevices.getDehydratedDeviceKey(); + + expect(key.toBase64()).toEqual(loaded_key.toBase64()); + }); + + test("can delete a previously saved dehydrated device key", async () => { + const user = new UserId("@alice:example.org"); + // set up OlmMachine to dehydrated device + const machine = await OlmMachine.initialize(user, new DeviceId("ABCDEFG")); + const dehydratedDevices = machine.dehydratedDevices(); + + const key = DehydratedDeviceKey.createRandomKey(); + + await dehydratedDevices.saveDehydratedDeviceKey(key); + + const loaded_key = await dehydratedDevices.getDehydratedDeviceKey(); + + expect(loaded_key).toBeDefined(); + + await dehydratedDevices.deleteDehydratedDeviceKey(); + + const loaded_key_after = await dehydratedDevices.getDehydratedDeviceKey(); + expect(loaded_key_after).toBeUndefined(); + }); + test("can dehydrate and rehydrate a device", async () => { const room = new RoomId("!test:localhost"); const user = new UserId("@alice:example.org"); @@ -52,7 +88,8 @@ describe("dehydrated devices", () => { // create dehydrated device const dehydratedDevices = machine.dehydratedDevices(); const device = await dehydratedDevices.create(); - const key = new Uint8Array(32); + + const key = DehydratedDeviceKey.createKeyFromArray(new Uint8Array(32)); const dehydrationRequest = await device.keysForUpload("Dehydrated device", key); const dehydrationBody = JSON.parse(dehydrationRequest.body);