-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## 🎟️ Tracking <!-- Paste the link to the Jira or GitHub issue or otherwise describe / point to where this change is coming from. --> ## 📔 Objective - Expose crypto client - Add error handling ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## 🦮 Reviewer guidelines <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or⚠️ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes
- Loading branch information
Showing
18 changed files
with
202 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::rc::Rc; | ||
|
||
use bitwarden_core::{ | ||
mobile::crypto::{InitOrgCryptoRequest, InitUserCryptoRequest}, | ||
Client, | ||
}; | ||
use wasm_bindgen::prelude::*; | ||
|
||
use crate::error::Result; | ||
|
||
#[wasm_bindgen] | ||
pub struct ClientCrypto(Rc<Client>); | ||
|
||
impl ClientCrypto { | ||
pub fn new(client: Rc<Client>) -> Self { | ||
Self(client) | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl ClientCrypto { | ||
/// Initialization method for the user crypto. Needs to be called before any other crypto | ||
/// operations. | ||
pub async fn initialize_user_crypto(&self, req: InitUserCryptoRequest) -> Result<()> { | ||
Ok(self.0.crypto().initialize_user_crypto(req).await?) | ||
} | ||
|
||
/// Initialization method for the organization crypto. Needs to be called after | ||
/// `initialize_user_crypto` but before any other crypto operations. | ||
pub async fn initialize_org_crypto(&self, req: InitOrgCryptoRequest) -> Result<()> { | ||
Ok(self.0.crypto().initialize_org_crypto(req).await?) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/// This file contains custom TypeScript for types defined by external crates. | ||
/// Everything in the string below is appended to the generated TypeScript definition file. | ||
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)] | ||
const TS_CUSTOM_TYPES: &'static str = r#" | ||
export type Uuid = string; | ||
/** | ||
* RFC3339 compliant date-time string. | ||
* @typeParam T - Not used in JavaScript. | ||
*/ | ||
export type DateTime<T = unknown> = string; | ||
/** | ||
* UTC date-time string. Not used in JavaScript. | ||
*/ | ||
export type Utc = unknown; | ||
/** | ||
* An integer that is known not to equal zero. | ||
*/ | ||
export type NonZeroU32 = number; | ||
"#; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Error thrown by the WASM module. | ||
* @param {string} message - Error message. | ||
* @extends Error | ||
*/ | ||
class WasmError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = "WasmError"; | ||
} | ||
} | ||
|
||
exports.WasmError = WasmError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
// Importing an error class defined in JavaScript instead of defining it in Rust | ||
// allows us to extend the `Error` class. It also provides much better console output. | ||
#[wasm_bindgen(module = "/src/error.js")] | ||
extern "C" { | ||
type WasmError; | ||
|
||
#[wasm_bindgen(constructor)] | ||
fn new(message: String) -> WasmError; | ||
} | ||
|
||
pub type Result<T, E = GenericError> = std::result::Result<T, E>; | ||
|
||
pub struct GenericError(pub String); | ||
|
||
impl<T: ToString> From<T> for GenericError { | ||
fn from(error: T) -> Self { | ||
GenericError(error.to_string()) | ||
} | ||
} | ||
|
||
impl From<GenericError> for JsValue { | ||
fn from(error: GenericError) -> Self { | ||
WasmError::new(error.0).into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
mod client; | ||
mod crypto; | ||
mod custom_types; | ||
mod error; | ||
mod vault; | ||
|
||
pub use client::BitwardenClient; | ||
pub use crypto::ClientCrypto; | ||
pub use vault::{folders::ClientFolders, ClientVault}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use std::rc::Rc; | ||
|
||
use bitwarden_core::Client; | ||
use bitwarden_vault::{ClientVaultExt, Folder, FolderView}; | ||
use wasm_bindgen::prelude::*; | ||
|
||
use crate::error::Result; | ||
|
||
#[wasm_bindgen] | ||
pub struct ClientFolders(Rc<Client>); | ||
|
||
impl ClientFolders { | ||
pub fn new(client: Rc<Client>) -> Self { | ||
Self(client) | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl ClientFolders { | ||
/// Decrypt folder | ||
pub fn decrypt(&self, folder: Folder) -> Result<FolderView> { | ||
Ok(self.0.vault().folders().decrypt(folder)?) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
pub mod folders; | ||
|
||
use std::rc::Rc; | ||
|
||
use bitwarden_core::Client; | ||
use wasm_bindgen::prelude::*; | ||
|
||
use crate::ClientFolders; | ||
|
||
#[wasm_bindgen] | ||
pub struct ClientVault(Rc<Client>); | ||
|
||
impl ClientVault { | ||
pub fn new(client: Rc<Client>) -> Self { | ||
Self(client) | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl ClientVault { | ||
pub fn folders(&self) -> ClientFolders { | ||
ClientFolders::new(self.0.clone()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters