Skip to content

Expose credential exchange in wasm #222

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

Merged
merged 5 commits into from
Apr 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/bitwarden-exporters/Cargo.toml
Original file line number Diff line number Diff line change
@@ -17,11 +17,13 @@ keywords.workspace = true

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

[dependencies]
base64 = ">=0.22.1, <0.23"
bitwarden-core = { workspace = true }
bitwarden-crypto = { workspace = true }
bitwarden-error = { workspace = true }
bitwarden-fido = { workspace = true }
bitwarden-vault = { workspace = true }
chrono = { workspace = true, features = ["std"] }
@@ -32,8 +34,10 @@ schemars = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
tsify-next = { workspace = true, optional = true }
uniffi = { workspace = true, optional = true }
uuid = { workspace = true }
wasm-bindgen = { workspace = true, optional = true }

[dev-dependencies]
rand = ">=0.8.5, <0.9"
7 changes: 7 additions & 0 deletions crates/bitwarden-exporters/src/cxf/export.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ use credential_exchange_format::{
Account as CxfAccount, Credential, Item, NoteCredential, OTPHashAlgorithm, TotpCredential,
};
use uuid::Uuid;
#[cfg(feature = "wasm")]
use {tsify_next::Tsify, wasm_bindgen::prelude::*};

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

@@ -11,6 +13,11 @@ use crate::{cxf::CxfError, Cipher, CipherType, Login};
/// Eventually the SDK itself should have this state and we get rid of this struct.
#[derive(Debug)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
#[cfg_attr(
feature = "wasm",
derive(serde::Serialize, serde::Deserialize, Tsify),
tsify(into_wasm_abi, from_wasm_abi)
)]
pub struct Account {
id: Uuid,
email: String,
2 changes: 2 additions & 0 deletions crates/bitwarden-exporters/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use bitwarden_error::bitwarden_error;
use thiserror::Error;

#[bitwarden_error(flat)]

Check warning on line 4 in crates/bitwarden-exporters/src/error.rs

Codecov / codecov/patch

crates/bitwarden-exporters/src/error.rs#L4

Added line #L4 was not covered by tests
#[derive(Error, Debug)]
pub enum ExportError {
#[error(transparent)]
4 changes: 4 additions & 0 deletions crates/bitwarden-exporters/src/exporter_client.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
use bitwarden_core::Client;
use bitwarden_vault::{Cipher, Collection, Folder};
#[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*;

use crate::{
export::{export_cxf, export_organization_vault, export_vault, import_cxf},
Account, ExportError, ExportFormat,
};

#[cfg_attr(feature = "wasm", wasm_bindgen)]
pub struct ExporterClient {
client: Client,
}

#[cfg_attr(feature = "wasm", wasm_bindgen)]
impl ExporterClient {
fn new(client: Client) -> Self {
Self { client }
5 changes: 5 additions & 0 deletions crates/bitwarden-exporters/src/lib.rs
Original file line number Diff line number Diff line change
@@ -26,6 +26,11 @@ pub use error::ExportError;

#[derive(JsonSchema)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
#[cfg_attr(
feature = "wasm",
derive(serde::Serialize, serde::Deserialize, tsify_next::Tsify),
tsify(into_wasm_abi, from_wasm_abi)
)]
pub enum ExportFormat {
Csv,
Json,
5 changes: 5 additions & 0 deletions crates/bitwarden-vault/src/collection.rs
Original file line number Diff line number Diff line change
@@ -13,6 +13,11 @@ use crate::VaultParseError;
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
#[cfg_attr(
feature = "wasm",
derive(tsify_next::Tsify),
tsify(into_wasm_abi, from_wasm_abi)
)]
pub struct Collection {
pub id: Option<Uuid>,
pub organization_id: Uuid,
1 change: 1 addition & 0 deletions crates/bitwarden-wasm-internal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ crate-type = ["cdylib"]
bitwarden-core = { workspace = true, features = ["wasm", "internal"] }
bitwarden-crypto = { workspace = true, features = ["wasm"] }
bitwarden-error = { workspace = true }
bitwarden-exporters = { workspace = true, features = ["wasm"] }
bitwarden-generators = { workspace = true, features = ["wasm"] }
bitwarden-ipc = { workspace = true, features = ["wasm"] }
bitwarden-ssh = { workspace = true, features = ["wasm"] }
5 changes: 5 additions & 0 deletions crates/bitwarden-wasm-internal/src/client.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

use bitwarden_core::{Client, ClientSettings};
use bitwarden_error::bitwarden_error;
use bitwarden_exporters::ExporterClientExt;
use bitwarden_vault::VaultClientExt;
use wasm_bindgen::prelude::*;

@@ -51,6 +52,10 @@
pub fn generator(&self) -> GeneratorClient {
GeneratorClient::new(self.0.clone())
}

pub fn exporters(&self) -> bitwarden_exporters::ExporterClient {
self.0.exporters()
}

Check warning on line 58 in crates/bitwarden-wasm-internal/src/client.rs

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/client.rs#L56-L58

Added lines #L56 - L58 were not covered by tests
}

#[bitwarden_error(basic)]