Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Add Rust/JS + CI (#1)
Browse files Browse the repository at this point in the history
* add tests and CI

Signed-off-by: John Sahhar <[email protected]>
  • Loading branch information
ok-john authored Nov 5, 2022
1 parent ae21c74 commit fe36d1f
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 337 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/jstest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Javascript Tests

on:
- pull_request

jobs:
format:
strategy:
matrix:
os:
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Run js tests
run: ./example/ci-test.sh

29 changes: 29 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Formatting

on:
- pull_request

jobs:
format:
strategy:
matrix:
os:
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Testing

on:
- pull_request

jobs:
test:
strategy:
matrix:
os:
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Run cargo test
run: cargo test --release
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/Cargo.lock
node_modules
/Cargo.lock
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ description = "x25519 & chacha20poly1305"
repository = "https://github.com/entropyxyz/x25519-chacha20poly1305"

[dependencies]
bytes = "1.2.1"
hex = "*"
# bip39 ={ git="https://github.com/infincia/bip39-rs.git", tag="v0.6.0-beta.1" }
bip39 ={ git="https://github.com/infincia/bip39-rs.git", tag="v0.6.0-beta.1" }
wasm-bindgen = "0.2.83"
x25519-dalek = "2.0.0-pre.1"
serde ={ version="1.0", features=["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ link-local :: build-nodejs
cd pkg && npm link

# Links the example frontend project with the locally built wasm/js package.
link-project :: link-local
link :: link-local
cd example && npm link $(CRATE_NAME)

# Another build option for compiling to webpack, builds a typescript library around the WASM for use
Expand Down
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,33 @@

Nodejs package for x25519 key exchange and chacha20poly1305 encryption, written in Rust compiled to WASM.

## Development process

### Install dependencies

Requires `wasm-pack` which can be installed with `cargo install wasm-pack`.
See `example/ci-test.sh` for example of how to install both rust and javascript dependencies.

### Compile

Compile a nodejs/wasm library from the Rust source.

```sh
make
```

### Link

Link the nodejs/wasm library locally.

```sh
make link
```

### Test

After compiling and linking, run:

```sh
ts-node example/test.ts
```

29 changes: 29 additions & 0 deletions example/ci-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
readonly EXEC_DIR=$(dirname "$(realpath $0)")
readonly NODE_VERSION="v18.12.1"
readonly NODE_OS="linux"
readonly NODE_ARCH="x64"
readonly FN="node-$NODE_VERSION-$NODE_OS-$NODE_ARCH"

# Install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
rustup update nightly
rustup update stable
rustup default stable
rustup target add wasm32-unknown-unknown --toolchain nightly
cargo install wasm-pack

# Compile/link typescript library
make
make link

# Install JS dependencies
cd $EXEC_DIR
wget https://nodejs.org/dist/$NODE_VERSION/$FN.tar.xz
tar xf $FN.tar.xz
export PATH=$PATH:$EXEC_DIR/$FN/bin
npm install -g ts-node

# Run tests
ts-node test.ts

Loading

0 comments on commit fe36d1f

Please sign in to comment.