Skip to content
Closed
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
141 changes: 141 additions & 0 deletions .github/workflows/tests-recipher-js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: Tests (recipher-js)

# `@cipherstash/recipher`, the TypeScript SDK on the Stack Encrypt engine:
# its detached Cargo workspace (one crate, `recipher-js`, the napi-rs 3
# addon) and the suites that load the addon.
#
# Root `pnpm test` runs the package's `test` (the suites that need no
# addon, and the typecheck with the type tests) in tests.yml. This workflow
# runs what needs Rust: `test:cargo`, `build:debug` (napi-rs's CLI, which
# also writes the committed `native.d.ts`) and `test:addon`. Every test here
# is offline, over the engine's deterministic test keys, so the job takes no
# credentials.
#
# The engine crates and the root Cargo.toml are in the filter: the crate
# depends on stack-encrypt by path, and stack-encrypt's `workspace = true`
# dependencies resolve against the root manifest.

on:
pull_request:
paths:
- languages/typescript/packages/recipher-js/**
- packages/stack-auth/**
- packages/stack-profile/**
- packages/stack-kms/**
- packages/stack-encrypt/**
- packages/stack-encrypt-derive/**
- packages/stack-encrypt-jsonpath/**
- Cargo.toml
- mise.toml
- pnpm-lock.yaml
- .github/workflows/tests-recipher-js.yml
push:
branches: [main]
paths:
- languages/typescript/packages/recipher-js/**
- packages/stack-auth/**
- packages/stack-profile/**
- packages/stack-kms/**
- packages/stack-encrypt/**
- packages/stack-encrypt-derive/**
- packages/stack-encrypt-jsonpath/**
- Cargo.toml
- mise.toml
- pnpm-lock.yaml
- .github/workflows/tests-recipher-js.yml
workflow_dispatch: {}

permissions:
contents: read

defaults:
run:
shell: bash

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
RUST_BACKTRACE: full
CARGO_TERM_COLOR: always
CARGO_NET_GIT_FETCH_WITH_CLI: true

jobs:
recipher-js:
name: cargo checks, the addon, and its suites (Linux)
runs-on: blacksmith-16vcpu-ubuntu-2204
timeout-minutes: 45
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false

# At the repository root: the root mise.toml pins rust 1.94.1.
- uses: jdx/mise-action@1648a7812b9aeae629881980618f079932869151 # v4
with:
version: 2026.4.0
install: true
working_directory: .
install_args: rust
cache: true
# Must name runs-on's image; see scripts/__tests__/workflow-mise-cache-image.test.mjs
cache_key_prefix: mise-v1-ubuntu-2204

# As in tests-crates.yml: a cached toolchain can lack the components
# mise.toml declares. A no-op when they are there.
- name: Add rustfmt and clippy to the pinned toolchain
run: rustup component add rustfmt clippy

- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
with:
workspaces: languages/typescript/packages/recipher-js -> target

- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
with:
run_install: false

- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
with:
node-version: 22
cache: 'pnpm'

# node-pty falls back to `node-gyp rebuild` on Linux during any
# workspace install. See scripts/__tests__/workflow-node-gyp.test.mjs.
- name: Install node-gyp
run: npm install -g node-gyp

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

# `cargo test --locked`, `cargo fmt --check` and clippy, with every
# feature. The tests include the checks that the crate names no
# `Label`, links no eql-bindings, and that a build with its default
# features (the release build) has no test cipher.
- name: cargo checks
run: pnpm --filter @cipherstash/recipher run test:cargo

# The debug addon, with the test cipher, as `recipher.node`. napi-rs
# writes the addon's TypeScript declarations to `native.d.ts`, which is
# committed: the package's TypeScript imports its types from it.
- name: Build the addon
run: pnpm --filter @cipherstash/recipher run build:debug

# The build must leave the tracked tree as it found it. Nothing else
# regenerates `native.d.ts`, so a change to a `#[napi]` item that is not
# rebuilt and committed would leave declarations that disagree with the
# addon; `git status` also catches an untracked file the build leaves.
- name: Guard the committed declarations and Cargo.lock against drift
run: |
dirty=$(git status --porcelain -- languages/typescript/packages/recipher-js)
if [ -n "$dirty" ]; then
echo "$dirty"
git diff -- languages/typescript/packages/recipher-js
echo "::error::the recipher-js build changed tracked files or left untracked ones. Run 'pnpm --filter @cipherstash/recipher run build:debug' and commit native.d.ts and Cargo.lock; ignore other build outputs in the package's .gitignore."
exit 1
fi

# Builds the TypeScript (tsup) first: one suite runs the ESM and the
# CommonJS build in one process.
- name: Suites that load the addon
run: pnpm --filter @cipherstash/recipher run test:addon
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Every npm package except EQL lives under `languages/typescript/`: packages in `l
links are provenance only.
- `packages/stack-auth`, `packages/stack-profile`, `packages/stack-kms`, `packages/stack-encrypt`, `packages/stack-encrypt-derive`, `packages/stack-encrypt-jsonpath`, `packages/stack-guest-abi`: The Rust crates imported from `cipherstash/cipherstash-suite` with their history, and one added here — `stack-auth` and `stack-profile` (published to crates.io, one version group), `stack-kms` (published to crates.io from 0.1.0, its own version group, re-exported by `stack-encrypt` as `stack_encrypt::kms`), `stack-encrypt` and `stack-encrypt-derive` (published to crates.io from 0.1.0, one version group; `eql-bindings`' `stack-encrypt` feature depends on them from the registry), `stack-encrypt-jsonpath` (the JSONPath grammar of the JSON index and the SQL/JSON path predicate grammar its `match` operator reads, moved out of `stack-encrypt` so the derive can check a field's declared paths, and `predicate!` a predicate's text, at compile time; in the `stack-encrypt` version group, re-exported at `stack_encrypt::json`; its first version is published by hand, as the others' were, before Trusted Publishing can take it), and `stack-guest-abi` (`publish = false`). They are the members of the **root Cargo workspace**, with the three node binding crates below. See "Working on the Rust crates".
- `languages/typescript/packages/auth`, `languages/typescript/packages/profile`, `languages/typescript/packages/stack-auth-wasm`: The node bindings of those crates. `@cipherstash/auth` (napi-rs v2) and its six `platforms/*` packages are published to npm from this repository by `release.yml` (`auth-artifacts`, `publish-auth`); a change to what it ships, the `stack-auth` crate included, needs an `@cipherstash/auth` changeset (`require-auth-npm-changeset.yml`). `@cipherstash/profile` and its platforms are private and never published; `@cipherstash/stack-auth-wasm` is private and builds the wasm that `@cipherstash/auth` ships. Their `build` and `test` scripts never invoke cargo; `build:native`, `build:debug` and `test:cargo` do. `@cipherstash/auth` also ships two pure-JS framework adapters over the wasm `OidcFederationStrategy`: `./next` (Next.js App Router, hands the token to the render on a request header) and `./start` (TanStack Start: `csFederateCurrent` is called inside a function middleware the app declares itself, which hands the token to the server function through `next({ context })`; `@tanstack/react-start` is an optional peer loaded only by that entry).
- `languages/typescript/packages/recipher-js`: `@cipherstash/recipher`, the TypeScript SDK on the Stack Encrypt engine (design: `docs/plans/2026-11-22-recipher-typescript-sdk.md`). **Private and unpublished**: it has no platform packages and no release job yet, so it must stay `"private": true` (a public manifest would be published by `changeset publish` on merge) and takes no changeset. Its Rust is **one crate** in a **detached Cargo workspace** with its own `Cargo.lock`, excluded from the root: `crate/` (crate `recipher-js`, napi-rs 3), which defines the `Cipher`, `Keyset` and `Ciphertext` classes the package exports, runs every operation through the engine, and reads and builds JavaScript values only through vitaminc's `vitaminc-aead-napi`. A test fails if it names `Label`/`IntoLabel`, links `eql-bindings`, or reaches the engine's `test-support` with its default features. `@napi-rs/cli` v3 builds it (`build:debug`, `build:native`) and writes its generated TypeScript declarations to the committed `native.d.ts`; CI fails when the build changes that file. The TypeScript (`src/`) holds only `Result`, `RecipherError`, the typed signatures over the native methods and the adapter that turns each native outcome into a `Result`. Its `build` (tsup) and `test` (the suites in `__tests__/unit` and `tsc` over `src`, the tests and `type-tests`) never run cargo; `build:debug` (the addon with the deterministic test cipher behind `@cipherstash/recipher/testing`), `build:native`, `test:addon` (the suites that load `recipher.node`) and `test:cargo` do, and run in `.github/workflows/tests-recipher-js.yml`.
- `languages/golang`: The Go module — the SDK `encrypt` with its generated-code support `encrypt/gensupport`, its test package `encrypt/encrypttest` (context assertions, and `NewClient`: an offline client over the deterministic test builds, for an application's tests; a **nested Go module** of its own, so only a program that imports it downloads those builds, requiring the SDK at the zero pseudo-version with `replace ../..` in the tree, and `NewClient` fails when the two are at different versions) and the policy packages `encrypt/policy` and `encrypt/policy/protosource`; the credential package `auth`; the generator `stashgen` and its command `cmd/stashgen`; and `internal` (the shared guest plumbing and the `record` wire model). A wazero host with no cgo. Its two WASI guests (`encrypt/guest`, `auth/guest`) are detached Cargo workspaces built by `mise run wasm:guest:build` and `mise run wasm:auth-guest:build`; `mise run wasm:guest:build:deterministic` and `wasm:guest:build:eql:deterministic` build the seeded TEST builds into `encrypt/encrypttest/wasm`, which `encrypttest` embeds and the hermetic Go tests read; the `.wasm` files are gitignored. The stack-encrypt guest has a second build with the EQL types (`mise run wasm:guest:build:eql`, cargo feature `eql`, linking `eql-bindings` by path; `wasm:guest:build:eql:deterministic` is its test build), embedded by `encrypt/eql` and registered on import, so a program whose generated code names an EQL type runs it (ADR-0007, amended). `encrypt/eql`'s types and `Types` table are generated from the EQL catalog by `eql-codegen` (`eql_gen.go`, written by `mise run types:generate` in `packages/eql` and drift-gated by `types:check` and `cargo test -p eql-codegen`). Generated `*_stash.go` files are committed and CI fails when `go generate ./...` changes one. Releases are cut by hand with `.github/workflows/release-golang.yml` (`gh workflow run release-golang.yml -f version=X.Y.Z[-pre] --ref <branch>`): because the guests are gitignored on main and Go fetches a version as the files committed at its tag, the workflow builds them, commits them on a release-only commit no branch points at, with `encrypt/encrypttest/go.mod` pinned to the SDK version by `scripts/go-release-pin-encrypttest.sh` (run in `build` and in `publish`), tags it `languages/golang/vX.Y.Z` and `languages/golang/encrypt/encrypttest/vX.Y.Z` (the workflow's `MODULES`) and pushes the tags alone, then attaches the EQL v4 SQL bundle to the GitHub release. The ref must carry the EQL v4 bundle, or the build stops at "Build the EQL SQL bundles". `scripts/go-release-version.mjs` refuses, before anything is built, every version Go would refuse (non-canonical semver, `+build` metadata, a v2+ major on a module path with no `/vN` suffix, a version shaped like a pseudo-version), a final version dispatched from anywhere but `main`, and a final version while `languages/golang/go.mod` pins a `github.com/cipherstash/vitaminc/…` module at a pseudo-version (vitaminc's Go bindings have no tags, and a TEMPORARY pin on an unreleased commit must be gone before the module is tagged); a pre-release may come from a branch and may carry such a pin. The build job also refuses a version the Go proxy already lists in `@v/list`, which catches a tag deleted after the proxy fetched it; it never asks the proxy for the version itself before the tag exists, because the proxy would cache "not found" for up to 30 minutes and `verify` would fail after the push. The build checks the `Cargo.lock` of the EQL workspace and both guest workspaces with `--locked` first, since none of those builds passes it. It runs in a job with no write token and hands the guests to a `publish` job that holds `contents: write` and runs only git and gh. `publish` fetches the commit with plain unauthenticated git rather than `actions/checkout`, whose `token` input defaults to the job's writable token, and refuses a release commit whose tree is not the one the build tested. `publish` takes the paths it commits from the workflow's fixed `GUESTS` list, never from the artifact, and refuses a `guests.sha256` that is not exactly one SHA-256 line for each of those five guests (the three production guests and the two test builds `encrypttest` embeds): the build job runs third-party code after writing that manifest, so a path read from it could put any file on the tag (`scripts/__tests__/go-release-artifact.test.mjs`). The release page's notes are the version's `## [X.Y.Z]` section of `languages/golang/CHANGELOG.md`, taken by `scripts/go-release-notes.mjs` in a `notes` job that runs no third-party code and that `build` waits for: a version with no section, or an empty one, is refused before anything is built, so write the section before dispatching. A version is immutable once the Go proxy has fetched it, so a tag is never moved or deleted: if `publish` or `verify` fails after the tag is pushed, use "Re-run failed jobs" on the same run, which keeps a tag that run pushed and creates or completes the release; a new dispatch of the same version is refused. Never tag a main commit by hand: `go get` would fetch a module with no guests. `encrypt/example` is a third nested module, never tagged: it requires both modules as an application does. `./...` stops at a nested module, so `scripts/go-binding-test.sh`, `go:lint` and the generated-code check find each `go.mod` and run in its directory.
- `e2e/*`: Cross-package end-to-end tests (package managers, supply chain, Prisma example README)
- `e2e/migration-guide`: Unpublished, separately installed npm examples for the Protect/EQL v2 to Stack/EQL v3 guide. See its README before running; Postgres requires a disposable database and DynamoDB persistence is in memory.
Expand Down Expand Up @@ -739,6 +740,9 @@ exact pin would stop the suite sharing one `cts-common` with it.
- **Three Cargo workspaces, not one.** The root workspace (the seven stack-*
crates and the three node binding crates), protect-ffi's and EQL's. The root
`Cargo.toml` excludes the other two, and they pin their own vitaminc. The
TypeScript SDK's crate (`languages/typescript/packages/recipher-js`, napi-rs 3)
is a detached workspace too, with its own `Cargo.lock`, depending on
stack-encrypt by path. The
three fuzz crates, the two Go guests and the EQL v4 block ORE timing
harness's ciphertext generator
(`packages/eql/tests/timing/ore_block_v2/ctgen`) are detached workspaces
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ members = [
exclude = [
"packages/eql",
"languages/typescript/packages/protect-ffi",
# The TypeScript SDK's crate (`@cipherstash/recipher`): napi-rs 3, which
# the root's napi-rs 2 bindings must not unify with.
"languages/typescript/packages/recipher-js",
# cargo-fuzz crates: nightly-only, run through the `fuzz:*` mise tasks.
"packages/stack-auth/fuzz",
"packages/stack-kms/fuzz",
Expand Down
1 change: 1 addition & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This repository is the CipherStash Stack monorepo for JavaScript/TypeScript. It
| `@cipherstash/protect-ffi-darwin-arm64`<br>`@cipherstash/protect-ffi-darwin-x64`<br>`@cipherstash/protect-ffi-linux-arm64-gnu`<br>`@cipherstash/protect-ffi-linux-x64-gnu`<br>`@cipherstash/protect-ffi-linux-x64-musl`<br>`@cipherstash/protect-ffi-win32-x64-msvc` | Prebuilt per-platform binaries for `@cipherstash/protect-ffi`. Installed as optional dependencies; one is selected at load time for the host platform |
| `@cipherstash/auth` | Authentication strategies for CipherStash (napi-rs native binding, with a WASM build for edge runtimes, plus the `./next` and `./start` framework adapters) — imported from `cipherstash/cipherstash-suite` with the `stack-auth` crate it wraps |
| `@cipherstash/auth-darwin-arm64`<br>`@cipherstash/auth-darwin-x64`<br>`@cipherstash/auth-linux-arm64-gnu`<br>`@cipherstash/auth-linux-x64-gnu`<br>`@cipherstash/auth-linux-x64-musl`<br>`@cipherstash/auth-win32-x64-msvc` | Prebuilt per-platform binaries for `@cipherstash/auth`. Installed as optional peer dependencies; one is selected at load time for the host platform |
| `@cipherstash/recipher` | The TypeScript SDK on the Stack Encrypt engine (`languages/typescript/packages/recipher-js`): a napi-rs native addon over the `stack-encrypt` crate. Private and not published to npm yet; in scope for reports against the source |
| `@cipherstash/eql` | Encrypt Query Language — the PostgreSQL SQL bundle (`eql_v3` schema: domains, operators, index-term extractors) that stores and queries encrypted payloads, plus its generated TypeScript types. Applied by `stash eql install` and by the Prisma Next adapter's migrations. Released in lockstep with the `eql-bindings` Rust crate, which emits the payloads this SQL reads |

This repository also carries the source of the **`eql-bindings`** Rust crate
Expand Down
1 change: 1 addition & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"!languages/typescript/packages/auth/LICENSE",
"!languages/typescript/packages/profile/index.d.ts",
"!languages/typescript/packages/profile/native.d.ts",
"!languages/typescript/packages/recipher-js/native.d.ts",
"!languages/golang",
"!**/*.grit",
"!**/*.yml",
Expand Down
4 changes: 4 additions & 0 deletions languages/typescript/packages/recipher-js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target/
node_modules/
dist/
*.node
Loading
Loading