Skip to content
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

Rework the WASM code #44

Merged
merged 50 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b95d125
Rework the WASM code
Hinton Apr 10, 2023
3ab7955
Merge branch 'master' of github.com:bitwarden/sdk into feature/wasm
Hinton Apr 27, 2023
4b2468e
Fix documentation, remove any
Hinton Apr 27, 2023
cfd00a4
Merge branch 'master' of github.com:bitwarden/sdk into feature/wasm
Hinton Apr 27, 2023
b0eb600
Bump rimraf to 5
Hinton Apr 27, 2023
ed74aec
Refresh lock file
Hinton Apr 27, 2023
ff8b0b9
B64 encode fingerprint
Hinton Apr 27, 2023
df7970c
Add fingerprint response model (should we have this, or a generic jso…
Hinton Apr 27, 2023
eb45b2c
Merge branch 'master' of github.com:bitwarden/sdk into feature/wasm
Hinton May 2, 2023
9f8dc27
fmt
Hinton May 2, 2023
bc069fc
Add support for node.js wasm
Hinton May 4, 2023
0ec12ed
Change debug to release
Hinton May 4, 2023
5b2bea8
Add optimize command
Hinton May 4, 2023
2427e62
Merge branch 'master' of github.com:bitwarden/sdk into feature/wasm
Hinton Jun 5, 2023
68d32ac
Undo uneccesary change
Hinton Jun 5, 2023
ea553f9
Fix tests
Hinton Jun 5, 2023
fa66677
Change back default kdf iterations
Hinton Jun 6, 2023
6ad22c1
Remove package-lock
Hinton Jun 6, 2023
4faa056
Refresh the schemas
Hinton Jun 6, 2023
4277ae6
update readme
Hinton Jun 6, 2023
93bd786
Merge branch 'master' of github.com:bitwarden/sdk into feature/wasm
Hinton Jun 17, 2023
3068216
Update schemas
Hinton Jun 17, 2023
696000c
Merge branch 'master' of github.com:bitwarden/sdk into feature/wasm
Hinton Jul 21, 2023
0bc62b5
Refresh lockfile
Hinton Jul 21, 2023
1bdeab8
Revert accidental default feature
Hinton Jul 21, 2023
ed3093f
Merge branch 'master' of github.com:bitwarden/sdk into feature/wasm
Hinton Jul 31, 2023
f0476a6
Switch to unimplemented
Hinton Jul 31, 2023
30d79cd
Push forgotten lockfile
Hinton Jul 31, 2023
a2323de
Remove unused internal
Hinton Jul 31, 2023
d18be58
Remove last internal
Hinton Jul 31, 2023
2791410
Remove unused struct
Hinton Jul 31, 2023
e7fd7f1
Remove another unused struct
Hinton Jul 31, 2023
3cea843
Remove unused lockfile
Hinton Jul 31, 2023
5e4ea6b
Rollback fingerprint stuff
Hinton Jul 31, 2023
0d86f16
Fix workflow path
Hinton Jul 31, 2023
aa3fb80
Merge branch 'master' of github.com:bitwarden/sdk into feature/wasm
Hinton Nov 23, 2023
95a546d
Remove stdweb
Hinton Nov 23, 2023
7326b41
Cleanup gitignore
Hinton Nov 23, 2023
ee4b5bc
Merge branch 'master' of github.com:bitwarden/sdk into feature/wasm
Hinton Nov 23, 2023
5efa69e
Re-add missing std
Hinton Nov 23, 2023
ba02aa4
Remove `release-wasm`
Hinton Nov 24, 2023
dc715fb
Handle conditional loading of js wasm
Hinton Nov 24, 2023
06c646a
Cleanup
Hinton Nov 24, 2023
8d716b9
Update readme
Hinton Nov 24, 2023
2ef38f9
Merge branch 'master' of github.com:bitwarden/sdk into feature/wasm
Hinton Nov 27, 2023
4e85734
Merge branch 'master' of github.com:bitwarden/sdk into feature/wasm
Hinton Dec 7, 2023
3bb32ce
Remove instant
Hinton Dec 7, 2023
98acbb0
Move readme to bitwarden-wasm crate
Hinton Dec 8, 2023
7b3596c
Move readme and extract code to script
Hinton Dec 8, 2023
fe60a48
Add index.js to package.json
Hinton Dec 8, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/generate_schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: schemas.ts
path: ${{ github.workspace }}/languages/js_webassembly/bitwarden_client/schemas.ts
path: ${{ github.workspace }}/languages/js/sdk-client/src/schemas.ts
if-no-files-found: error

- name: Upload c# schemas artifact
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ build/
bld/
[Bb]in/
[Oo]bj/
*.wasm

# Editor directories and files
.idea
Expand All @@ -34,6 +35,7 @@ crates/bitwarden-napi/sdk-napi.*.node

# Complied TypeScript client
crates/bitwarden-napi/dist
languages/js/sdk-client/dist/

# Uniffi
languages/swift/BitwardenFFI.xcframework
Expand All @@ -48,4 +50,5 @@ support/schemas
crates/bitwarden-napi/src-ts/bitwarden_client/schemas.ts
languages/csharp/Bitwarden.Sdk/schemas.cs
languages/js_webassembly/bitwarden_client/schemas.ts
languages/js/sdk-client/src/schemas.ts
languages/python/BitwardenClient/schemas.py
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.

36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,39 @@ generation. In that case we excluded the file from being generated and manually

The hope going forward is that we can continue to use the generator with minimal manual
intervention.

Hinton marked this conversation as resolved.
Show resolved Hide resolved
### WASM - WebAssembly

Requirements:

- `wasm32-unknown-unknown` rust target.
- `wasm-bindgen-cli` installed.
- `binaryen` installed for `wasm-opt` and `wasm2js`.

```bash
rustup target add wasm32-unknown-unknown
cargo install -f wasm-bindgen-cli
Hinton marked this conversation as resolved.
Show resolved Hide resolved
brew install binaryen
```

#### Build

```bash
# dev
cargo build -p bitwarden-wasm -p bitwarden --target wasm32-unknown-unknown --features wasm-bindgen
wasm-bindgen --target bundler --out-dir languages/js/wasm ./target/wasm32-unknown-unknown/debug/bitwarden_wasm.wasm
wasm-bindgen --target nodejs --out-dir languages/js/wasm/node ./target/wasm32-unknown-unknown/debug/bitwarden_wasm.wasm

# release
cargo build -p bitwarden -p bitwarden-wasm --target wasm32-unknown-unknown --features wasm-bindgen --release
wasm-bindgen --target bundler --out-dir languages/js/wasm ./target/wasm32-unknown-unknown/release/bitwarden_wasm.wasm
wasm-bindgen --target nodejs --out-dir languages/js/wasm/node ./target/wasm32-unknown-unknown/release/bitwarden_wasm.wasm
dani-garcia marked this conversation as resolved.
Show resolved Hide resolved

# Optimize size
wasm-opt -Os ./languages/js/wasm/bitwarden_wasm_bg.wasm -o ./languages/js/wasm/bitwarden_wasm_bg.wasm
wasm-opt -Os ./languages/js/wasm/node/bitwarden_wasm_bg.wasm -o ./languages/js/wasm/node/bitwarden_wasm_bg.wasm

# Transpile to JS
wasm2js ./languages/js/wasm/bitwarden_wasm_bg.wasm -o ./languages/js/wasm/bitwarden_wasm_bg.wasm.js
npx terser ./languages/js/wasm/bitwarden_wasm_bg.wasm.js -o ./languages/js/wasm/bitwarden_wasm_bg.wasm.js
```
7 changes: 5 additions & 2 deletions crates/bitwarden-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
rust-version = "1.57"

[lib]
crate-type = ["cdylib", "rlib"]
crate-type = ["cdylib"]

[dependencies]
console_error_panic_hook = "0.1.7"
Expand All @@ -16,7 +16,10 @@ serde = { version = "1.0.163", features = ["derive"] }
wasm-bindgen = { version = "=0.2.87", features = ["serde-serialize"] }
wasm-bindgen-futures = "0.4.36"

bitwarden-json = { path = "../bitwarden-json", features = ["secrets"] }
bitwarden-json = { path = "../bitwarden-json", features = [
"secrets",
"internal",
] }

[dev-dependencies]
wasm-bindgen-test = "0.3.36"
5 changes: 4 additions & 1 deletion crates/bitwarden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ secrets = [] # Secrets manager API
internal = [] # Internal testing methods
mobile = ["uniffi", "internal"] # Mobile-specific features

wasm-bindgen = ["instant/wasm-bindgen"]

[dependencies]
aes = ">=0.8.2, <0.9"
argon2 = { version = ">=0.5.0, <0.6", features = [
Expand All @@ -37,6 +39,7 @@ chrono = { version = ">=0.4.26, <0.5", features = [
getrandom = { version = ">=0.2.9", features = ["js"] }
hkdf = ">=0.12.3, <0.13"
hmac = ">=0.12.1, <0.13"
instant = ">=0.1.12, <0.2"
Hinton marked this conversation as resolved.
Show resolved Hide resolved
lazy_static = ">=1.4.0, <2.0"
log = ">=0.4.18, <0.5"
num-bigint = ">=0.4, <0.5"
Expand All @@ -45,7 +48,7 @@ pbkdf2 = { version = ">=0.12.1, <0.13", default-features = false }
rand = ">=0.8.5, <0.9"
reqwest = { version = ">=0.11, <0.12", features = ["json"] }
rsa = ">=0.9.2, <0.10"
schemars = { version = ">=0.8, <0.9", features = ["uuid1", "chrono"] }
schemars = { version = ">=0.8.9, <0.9", features = ["uuid1", "chrono"] }
serde = { version = ">=1.0, <2.0", features = ["derive"] }
serde_json = ">=1.0.96, <2.0"
serde_qs = ">=0.12.0, <0.13"
Expand Down
4 changes: 3 additions & 1 deletion crates/bitwarden/src/auth/renew.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::time::{Duration, Instant};
use std::time::Duration;

use instant::Instant;

#[cfg(feature = "internal")]
use crate::{auth::api::request::ApiTokenRequest, client::UserLoginMethod};
Expand Down
3 changes: 2 additions & 1 deletion crates/bitwarden/src/client/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::time::{Duration, Instant};
use std::time::Duration;

use instant::Instant;
use reqwest::header::{self};
use uuid::Uuid;

Expand Down
File renamed without changes.
Loading