Skip to content

Commit 0b97bdd

Browse files
authored
Expose credential exchange in wasm (#222)
We would like to do a PoC where we implement credential exchange in our browser extension. Which requires us to expose the CXF flow in wasm.
1 parent d27f58b commit 0b97bdd

File tree

9 files changed

+37
-0
lines changed

9 files changed

+37
-0
lines changed

Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bitwarden-exporters/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ keywords.workspace = true
1717

1818
[features]
1919
uniffi = ["dep:uniffi", "bitwarden-core/uniffi"] # Uniffi bindings
20+
wasm = ["dep:tsify-next", "dep:wasm-bindgen"] # WebAssembly bindings
2021

2122
[dependencies]
2223
base64 = ">=0.22.1, <0.23"
2324
bitwarden-core = { workspace = true }
2425
bitwarden-crypto = { workspace = true }
26+
bitwarden-error = { workspace = true }
2527
bitwarden-fido = { workspace = true }
2628
bitwarden-vault = { workspace = true }
2729
chrono = { workspace = true, features = ["std"] }
@@ -32,8 +34,10 @@ schemars = { workspace = true }
3234
serde = { workspace = true }
3335
serde_json = { workspace = true }
3436
thiserror = { workspace = true }
37+
tsify-next = { workspace = true, optional = true }
3538
uniffi = { workspace = true, optional = true }
3639
uuid = { workspace = true }
40+
wasm-bindgen = { workspace = true, optional = true }
3741

3842
[dev-dependencies]
3943
rand = ">=0.8.5, <0.9"

crates/bitwarden-exporters/src/cxf/export.rs

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use credential_exchange_format::{
33
Account as CxfAccount, Credential, Item, NoteCredential, OTPHashAlgorithm, TotpCredential,
44
};
55
use uuid::Uuid;
6+
#[cfg(feature = "wasm")]
7+
use {tsify_next::Tsify, wasm_bindgen::prelude::*};
68

79
use crate::{cxf::CxfError, Cipher, CipherType, Login};
810

@@ -11,6 +13,11 @@ use crate::{cxf::CxfError, Cipher, CipherType, Login};
1113
/// Eventually the SDK itself should have this state and we get rid of this struct.
1214
#[derive(Debug)]
1315
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
16+
#[cfg_attr(
17+
feature = "wasm",
18+
derive(serde::Serialize, serde::Deserialize, Tsify),
19+
tsify(into_wasm_abi, from_wasm_abi)
20+
)]
1421
pub struct Account {
1522
id: Uuid,
1623
email: String,

crates/bitwarden-exporters/src/error.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use bitwarden_error::bitwarden_error;
12
use thiserror::Error;
23

4+
#[bitwarden_error(flat)]
35
#[derive(Error, Debug)]
46
pub enum ExportError {
57
#[error(transparent)]

crates/bitwarden-exporters/src/exporter_client.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
use bitwarden_core::Client;
22
use bitwarden_vault::{Cipher, Collection, Folder};
3+
#[cfg(feature = "wasm")]
4+
use wasm_bindgen::prelude::*;
35

46
use crate::{
57
export::{export_cxf, export_organization_vault, export_vault, import_cxf},
68
Account, ExportError, ExportFormat,
79
};
810

11+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
912
pub struct ExporterClient {
1013
client: Client,
1114
}
1215

16+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
1317
impl ExporterClient {
1418
fn new(client: Client) -> Self {
1519
Self { client }

crates/bitwarden-exporters/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ pub use error::ExportError;
2626

2727
#[derive(JsonSchema)]
2828
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
29+
#[cfg_attr(
30+
feature = "wasm",
31+
derive(serde::Serialize, serde::Deserialize, tsify_next::Tsify),
32+
tsify(into_wasm_abi, from_wasm_abi)
33+
)]
2934
pub enum ExportFormat {
3035
Csv,
3136
Json,

crates/bitwarden-vault/src/collection.rs

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ use crate::VaultParseError;
1313
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
1414
#[serde(rename_all = "camelCase", deny_unknown_fields)]
1515
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
16+
#[cfg_attr(
17+
feature = "wasm",
18+
derive(tsify_next::Tsify),
19+
tsify(into_wasm_abi, from_wasm_abi)
20+
)]
1621
pub struct Collection {
1722
pub id: Option<Uuid>,
1823
pub organization_id: Uuid,

crates/bitwarden-wasm-internal/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ crate-type = ["cdylib"]
1919
bitwarden-core = { workspace = true, features = ["wasm", "internal"] }
2020
bitwarden-crypto = { workspace = true, features = ["wasm"] }
2121
bitwarden-error = { workspace = true }
22+
bitwarden-exporters = { workspace = true, features = ["wasm"] }
2223
bitwarden-generators = { workspace = true, features = ["wasm"] }
2324
bitwarden-ipc = { workspace = true, features = ["wasm"] }
2425
bitwarden-ssh = { workspace = true, features = ["wasm"] }

crates/bitwarden-wasm-internal/src/client.rs

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fmt::Display;
33

44
use bitwarden_core::{Client, ClientSettings};
55
use bitwarden_error::bitwarden_error;
6+
use bitwarden_exporters::ExporterClientExt;
67
use bitwarden_vault::VaultClientExt;
78
use wasm_bindgen::prelude::*;
89

@@ -51,6 +52,10 @@ impl BitwardenClient {
5152
pub fn generator(&self) -> GeneratorClient {
5253
GeneratorClient::new(self.0.clone())
5354
}
55+
56+
pub fn exporters(&self) -> bitwarden_exporters::ExporterClient {
57+
self.0.exporters()
58+
}
5459
}
5560

5661
#[bitwarden_error(basic)]

0 commit comments

Comments
 (0)