Skip to content
Merged
Show file tree
Hide file tree
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
54 changes: 54 additions & 0 deletions .github/workflows/argon2-wasm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: argon2-wasm CI

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

on:
pull_request:
paths:
- "src/components/passwordProvider/argon2-wasm/**"

permissions: {}

jobs:
build-and-test:
runs-on: ubuntu-latest
timeout-minutes: 20
defaults:
run:
working-directory: src/components/passwordProvider/argon2-wasm

steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false

- uses: extractions/setup-just@dd310ad5a97d8e7b41793f8ef055398d51ad4de6 # v2

# Reads rust-toolchain.toml and installs the pinned toolchain + targets.
- name: Install pinned Rust toolchain
run: rustup toolchain install

- name: Cache cargo registry and build artifacts
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
with:
path: |
~/.cargo/registry
~/.cargo/git
src/components/passwordProvider/argon2-wasm/target
key: ${{ runner.os }}-cargo-argon2-wasm-${{ hashFiles('src/components/passwordProvider/argon2-wasm/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-argon2-wasm-

- name: cargo fmt
run: just fmt

- name: cargo clippy
run: just lint

- name: cargo test
run: just test

- name: Compile for wasm32 target
run: just check
2 changes: 2 additions & 0 deletions src/components/passwordProvider/argon2-wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/pkg
251 changes: 251 additions & 0 deletions src/components/passwordProvider/argon2-wasm/Cargo.lock

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

11 changes: 11 additions & 0 deletions src/components/passwordProvider/argon2-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "argon2-wasm"
version = "0.1.0"
edition = "2021"

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

[dependencies]
wasm-bindgen = "0.2.100"
argon2 = { version = "0.5", features = ["password-hash"] }
27 changes: 27 additions & 0 deletions src/components/passwordProvider/argon2-wasm/Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
set shell := ["bash", "-uc"]

wasm-pack-version := "0.15.0"

_default:
@just --list

# Install the pinned wasm-pack version.
install-wasm-pack:
cargo install wasm-pack --version {{ wasm-pack-version }} --locked --force

# Regenerate the wasm-bindgen bindings in pkg/.
build: install-wasm-pack
wasm-pack build --release --target web --out-dir pkg --out-name argon2_wasm

test:
cargo test --locked

# Compile for the wasm32 target without regenerating bindings (fast syntax/type check).
check:
cargo build --locked --release --target wasm32-unknown-unknown

fmt:
cargo fmt --check

lint:
cargo clippy --locked --all-targets -- -D warnings
21 changes: 21 additions & 0 deletions src/components/passwordProvider/argon2-wasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# argon2-wasm

A tiny Rust crate that wraps [`argon2`](https://docs.rs/argon2) and compiles to WebAssembly
via `wasm-bindgen`, used by the password provider component to hash and verify passwords.

## Building

Requires [`just`](https://github.com/casey/just) and the toolchain pinned in
`rust-toolchain.toml` (installed automatically by `rustup` on first use).

```sh
just test # cargo test
just check # compile for wasm32 (fast syntax/type check, no bindings)
just build # regenerate pkg/ via wasm-pack (pinned version)
```

`pkg/` is gitignored and regenerated by `just build`. After changing `src/lib.rs`, run
`just build` before using the password provider component.

TODO: once this crate lives in a monorepo, `just build` should be invoked from a `prepare`
script instead of run manually.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "1.96.1"
targets = ["wasm32-unknown-unknown"]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using wasm32-unknown-unknown because:

  • we don't need 64 bit memory
  • wasm32-unknown-unknown is a Tier 2 without Host Tools platform (wasm64-unknown-unknown is tier 3)
  • this crate doesn’t need any assumptions about the host environment, so it’s fine to use unknown-unknown

components = ["rustfmt", "clippy"]
Loading
Loading