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

Create jazz-crypto-rs package #1

Merged
merged 15 commits into from
Feb 12, 2025
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
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/four-hornets-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"jazz-crypto-rs": patch
---

Initial release
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
30 changes: 30 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build Package

on:
push:
branches: [main]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
with:
version: 8

- uses: actions/setup-node@v3
with:
node-version: 20
cache: 'pnpm'

- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy

- run: pnpm install
- run: pnpm build
- run: pnpm test
70 changes: 70 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Release

on:
push:
branches:
- main
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: "Run tmate session for debugging"
required: false
default: false

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Enable latestcorepack
run: |
echo "Before: corepack version => $(corepack --version || echo 'not installed')"
npm install -g corepack@latest
echo "After : corepack version => $(corepack --version)"
corepack enable
pnpm --version

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
cache: 'pnpm'

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
version: pnpm changeset-version
publish: pnpm release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

# Enable tmate debugging only if the workflow is manually triggered, debug_enabled is true, and the workflow failed
- name: Setup tmate session for debugging
if: ${{ failure() && github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
uses: mxschmitt/action-tmate@v3
with:
timeout-minutes: 15
23 changes: 17 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,20 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# RustRover
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# Node.js
node_modules/
dist/
.env

# WebAssembly
pkg/
wasm-pack.log

# IDE
.idea/
.vscode/

# Nix
.direnv/
result
result-*
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.changeset
!dist
target/
28 changes: 28 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "jazz-crypto-rs"
version = "0.1.0"
edition = "2021"
description = "WASM crypto library for Jazz"
license = "MIT"
repository = "https://github.com/garden-co/jazz"

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

[dependencies]
wasm-bindgen = "0.2"
js-sys = "0.3"
getrandom = { version = "0.2", features = ["js"] }
blake3 = "1.5"
x25519-dalek = { version = "2.0", features = ["getrandom", "static_secrets"] }
crypto_secretbox = { version = "0.1.1", features = ["getrandom"] }
salsa20 = "0.10.2"
ed25519-dalek = { version = "2.1", features = ["rand_core"] }
rand = "0.8"
bs58 = "0.5"

[dev-dependencies]
wasm-bindgen-test = "0.3"

[profile.release]
lto = true
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Jazz Crypto RS

A Rust implementation of cryptographic primitives for the Jazz project, compiled to WebAssembly.

## Module Structure

The codebase is organized into the following modules:

```
src
├── crypto
│ ├── ed25519.rs // Ed25519 functions for signing and verification
│ ├── encrypt.rs // High-level encryption functions
│ ├── seal.rs // High-level sealing and unsealing functions
│ ├── sign.rs // High-level signing and verification functions
│ ├── x25519.rs // X25519 key exchange
│ └── xsalsa20.rs // XSalsa20 and XSalsa20-Poly1305 encryption
├── error.rs // Error types for cryptographic operations
├── hash
│ └── blake3.rs // BLAKE3 hashing functionality
└── lib.rs // Main entry point for the library
```

## Features

- Ed25519 signing and verification
- X25519 key exchange
- XSalsa20 and XSalsa20-Poly1305 encryption
- BLAKE3 hashing with incremental state updates
- Secure nonce generation
- WebAssembly bindings for all operations

## Usage

The library exposes WebAssembly-compatible functions for all cryptographic operations. See the individual module files for detailed documentation of available functions.

## Installation

Get a working Rust environment (rustup).

```bash
rustup install stable
rustup default stable
```

[Install `wasm-pack`](https://rustwasm.github.io/wasm-pack/installer/).

Then add wasm target to your toolchain:

```bash
rustup target add wasm32-unknown-unknown
```

## Build

```bash
wasm-pack build --target web
```

## Development

Install the [`rust-analyzer` extension](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) to get Rust support in VSCode. `rust-analyzer` expects a `Cargo.toml` file in the root of the project, so configure the workspace setting with the root directory of the project:

```json
// .vscode/settings.json
{
"rust-analyzer.linkedProjects": [
"packages/jazz-crypto-rs/Cargo.toml"
]
}
```


## Test

```bash
cargo test
```
82 changes: 82 additions & 0 deletions flake.lock

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

Loading