Skip to content

docs(plans): the TypeScript SDK on Stack Encrypt, a core with EQL as an extension - #1747

Draft
coderdan wants to merge 11 commits into
nextfrom
docs/typescript-sdk-plan
Draft

coderdan wants to merge 11 commits into
nextfrom
docs/typescript-sdk-plan

Conversation

@coderdan

@coderdan coderdan commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A plan for the TypeScript SDK on Stack Encrypt, CipherStash's Rust encryption engine. Today only Go uses the engine, and Python is in review.

The SDK is one new npm package and an addition to an existing one, split the way Rust splits stack-encrypt from eql-bindings:

  • @cipherstash/recipher, the core. It encrypts a value, a file, a whole object and a record, and derives search terms. It names no EQL type and needs no database.
  • @cipherstash/eql/recipher, an extension. @cipherstash/eql exists and holds EQL's wire types, schemas and SQL. Its new entry adds the EQL v4 types (the JSON a CipherStash-enabled PostgreSQL column stores) to the core, so a record's fields can be stored in PostgreSQL and queried there.

The plan also moves the Drizzle, Supabase and Prisma Next adapters, and the DynamoDB integration, onto them. They wait for recipher-compat, the planned crate that reads EQL v3 and v2, so no customer upgrades into rows they cannot read.

The work is in three phases, so it can start before the engine has the context design of ADR-0016 (#1772):

  1. Now: everything that needs no context from the caller. The core first, then the EQL extension, then a pre-release of both on npm.
  2. When the engine has ADR-0016's named parts: labels and partitions, a value with a context, and the policies the engine and ZeroKMS have.
  3. After the issues that change stored bytes: refinements and the first stable release. Then, when recipher-compat exists, the adapters.

Nothing is built. This pull request adds one document.

Changes

Review feedback taken

  • The examples no longer start with a database table. The core has its own sections, and EQL has one section after them.
  • The core is decoupled from EQL: separate builds, and a test that the core links no eql-bindings. The extension lives in @cipherstash/eql.
  • The core has plain encryption with no context, as the engine's keyset.encrypt(value) has. Go SDK: a value cannot be encrypted without a context, or without a struct — add plain Encrypt and Decrypt on Cipher #1771 asks the same of the Go SDK.
  • A value's TypeScript type picks how it is encrypted: keyset.encrypt("a secret message"). No call names a kind; only a record field does.
  • The first example encrypts one string. An array in is an array out, through the same call, in one request.
  • Calls return a Result and never throw. Result is the core's own type with Rust's Result methods. unwrap() and expect() are the only way to get an exception.
  • Value conversion is vitaminc-aead-napi's, not the SDK's own.
  • The core and EQL are released apart. A build reports a binding interface number, so several EQL versions work with one core.
  • A JSON integer outside JavaScript's safe range is a bigint, so the eql-json-v1 case with 18446744073709551615 round-trips.
  • An EQL record has no context field, because the engine refuses one. It takes a tenant as a scope from the caller.
  • decryptField covers Prisma Next's reads of one column.
  • The wasm build promises to wipe the buffers a finished call owned, not all of linear memory.

Verification

Claims the plan depends on were run or read on next:

Read in cipherstash/vitaminc at 222f1ad39: vitaminc-aead-napi is a Rust library for a Node addon on napi-rs 3, with no wasm counterpart.

Not checked, and listed in the plan: that the engine's pending calls are Send for napi-rs, that a binding can reach OpaqueBlob's format, that the engine opens one field of a stored row alone, the largest value one call can seal, the size of each wasm build, how @cipherstash/eql declares its platform packages so the SQL entries install no native build, napi addons under Bun and Deno, and whether PostgREST can write the EQL v4 query casts.

No package changes, so no changeset.

Related

Refs #1479 (the TypeScript conformance runner, which the plan includes).

Review notes

  • Read "The core" and "The EQL extension" first. They hold the API shape.
  • Integers are a bigint in the core at every width, as in vitaminc. An adapter converts for an ORM whose integer columns are a number.
  • The wasm build needs vitaminc's mapping over wasm-bindgen. vitaminc-aead-napi has no WebAssembly counterpart, so a wasm-bindgen build must copy the JavaScript value mapping — add vitaminc-aead-wasm vitaminc#632 asks for it; the wasm crate holds it until then.
  • "Phases" is the section to check against milestone priorities.
  • "Context" gives parts to the keyset with keyset.with(..), as Go's Cipher.With does, not to each call. Rust passes them to each call. Check that this is the form you want.
  • Phase 1 has no .withContext. It writes only the two forms ADR-0016 says keep their stored bytes.

A plan for @cipherstash/recipher: a napi-rs extension for Node.js and
the same Rust built for wasm32-unknown-unknown with wasm-bindgen for
edge runtimes, both running every operation through dynamic::Planned.
EQL v4 only.

It covers the milestone issues that must land first, the declaration
and its compile-time checks from the EQL catalog, columns named by
table and column name (as the Drizzle, Supabase and Prisma Next
adapters already name them), values, credentials, errors, plaintext
hygiene, cancellation, the conformance runners, packaging after
@cipherstash/auth, moving the three adapters onto it in a new major
each, and the order of work. Three decisions are open: data the
current adapters wrote, the date and time types, and DynamoDB.
The engine crate is to be renamed recipher, so the TypeScript SDK's
Rust crates are recipher-js, recipher-js-node and recipher-js-wasm, in
languages/typescript/packages/recipher-js. The npm package stays
@cipherstash/recipher.
recipher-compat is planned to read and write EQL v3 and v2. The plan
does not design it, but keeps the EQL version in a column's type, builds
the EQL resolver in one place, and has adapters take casts from a query
term's domain, so recipher-compat needs no new call shape. Decision 1
now asks whether the adapters' new majors wait for it.
@changeset-bot

changeset-bot Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: bfb2e30

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

The engine issues the plan waited for are mostly still open, and the
design of contexts and labels is taking time. Phase 1 starts now and
builds everything that needs no context from the caller. Phase 2 adds
scopes, bindings, context fields and the expected context once #1663 is
closed and the context design is settled. Phase 3 is the stable release
and the adapters, after the issues that change stored bytes.

Phase 1 values are encrypted under the table and column name only, and
the core crate names no Label, so #1663 removes it without a change
here. The plan now lists what each open issue changes when it lands,
and asks whether phase 1 publishes a pre-release.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The plan’s JSON representation risks corrupting large integers, and its EQL scoping and Prisma projected-read contracts remain incompatible with existing engine behavior.

4 open issues
What changed in this PR

Proposes @cipherstash/recipher, a TypeScript SDK on the Stack Encrypt engine, and a path for moving the existing database adapters to EQL v4. This PR adds a design document only; no implementation or package changes are included.

Changes:

  • Defines native Node.js and WebAssembly backends, typed declarations, operations and value handling.
  • Plans conformance coverage, packaging, release steps and engine prerequisites.
  • Outlines adapter migrations and open decisions about legacy data, timestamps and DynamoDB.
File Description
docs/​plans/​2026-11-22-recipher-typescript-sdk.md Adds the SDK architecture, API proposal, verification notes and staged delivery plan.

Review effort: Balanced

| date | see [Decisions needed](#decisions-needed) | |
| timestamp | see [Decisions needed](#decisions-needed) | |
| bytes | `Uint8Array` | |
| json | any JSON value | Written to JSON text in Rust, then parsed by the engine's one parser |
Comment on lines +192 to +194
- **Context.** The table name and the column name are the column's label, as
in Go. A table whose tenant is in each row declares its context field with
`contextField: "tenant"`.
Comment on lines +344 to +345
`client.decrypt`. Prisma Next's middleware encrypts column by column,
which maps to `client.encryptColumn`.
Comment on lines +314 to +315
- The wasm build follows the same rules, and its linear memory holds no
plaintext after a call returns.
Comment on lines +186 to +201
## The declaration

A table is declared with a builder and the EQL v4 type of each column. The
type names are the EQL catalog's.

```ts
import { encryptedTable, types } from "@cipherstash/recipher";

export const users = encryptedTable("users", {
id: types.passthrough<bigint>(),
email: types.TextEq(),
name: types.TextMatch(),
age: types.IntegerEq({ null: "sealed" }),
profile: types.JsonSearch({ ordered: ["$.score"] }),
});
```

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is an EQL/database example, but unlike the old stack, Recipher is a more general-purpose library. It is intended to be able to support encryption of straight values, files, object stores, and of course databases via EQL. EQL is an extension to the core, not the core itself.

In Rust, we separate what is currently called stack-encrypt from the EQL bindings crate. We should have a similar separation in TypeScript.

The plan followed the old stack library: one package, declared as
database tables of EQL types. Stack Encrypt is a general-purpose engine,
and eql-bindings adds the EQL types to it. The TypeScript SDK now has
the same split.

@cipherstash/recipher is the core. It encrypts a value, a file, a whole
object and a record, and derives search terms, in the order the engine's
own documentation teaches them. It names no EQL type and needs no
database. @cipherstash/recipher-eql is an extension: an EQL v4 type is a
field's target in a core record, through the core's calls. Its builds
link eql-bindings' resolver, as Go's encrypt/eql guest does.

Also from review: a JSON integer outside the safe range is a bigint, an
EQL record takes no context field, decryptField covers a projected
column, and the wasm wipe promise covers one call's own buffers.
@coderdan coderdan changed the title docs(plans): @cipherstash/recipher, the TypeScript SDK on Stack Encrypt docs(plans): the TypeScript SDK on Stack Encrypt, a core with EQL as an extension Nov 23, 2026
The EQL extension is an entry of @cipherstash/eql,
@cipherstash/eql/recipher, not a new package. The package's root,
schema and SQL entries load no native build.

The core has plain encryption with no context, as the engine's
keyset.encrypt(value) has: a kind used alone is the declaration. A value
with a context is value(kind, { context }).

The adapters' new majors, and DynamoDB after them, wait for
recipher-compat, so no customer upgrades into rows they cannot read.
Dates and timestamps are a Date for now, and a finer timestamp opens
truncated to the millisecond.

Two decisions stay open: a pre-release after phase 1, and where the EQL
builds are published.
Comment on lines +544 to +551
Every failure is a `RecipherError` with `code`, `reason` and `field` from
the engine's error. Subclasses name the failures a caller acts on
differently: a refused declaration, a value of the wrong type, a refused
credential, a ZeroKMS refusal, a foreign keyset, a context mismatch and a
value that did not open. No message, property or `toString()` holds a
plaintext, a key, a token, a ciphertext or a context value. A decrypted
row's `inspect` output names its fields and hides their values, as Go's
`Redacted` does.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As mentioned above, these should be result types rather than exceptions per se.

From review of the TypeScript SDK plan.

A value's TypeScript type picks how it is encrypted, so the plain call
is keyset.encrypt("a secret message"). A kind is named only to choose
another encoding, as kinds.int32(36), and in a record field.

One value returns one result. An array is a batch in one request.

No call throws and no promise rejects. Every call resolves to a
Result<T, RecipherError> with Rust's combinators; unwrap() is the only
way to get an exception.

The core and EQL are released apart. A build reports a binding interface
number, and Cipher.create refuses another, so several EQL versions work
with one core. That closes the decision on where the EQL builds are
published.
From review of the TypeScript SDK plan.

The node crate converts JavaScript values with vitaminc's napi bridge
(JsRef, JsBuilder, Wrappers) and holds no conversion of its own. The
mapping is vitaminc's: a number is a float, a bigint an integer at the
narrowest width, a Date a millisecond timestamp, and VcDate, VcTimestamp,
VcDecimal and VcUuid are the types JavaScript lacks. A timestamp finer
than a millisecond opens as a VcTimestamp, so nothing is truncated. The
wasm crate needs the same mapping, which vitaminc does not have yet.

The first example encrypts one string. An array is its own section: an
array in is an array out, through the same call, so principle 5 holds
and is not amended.

Result is the core's own type with Rust's Result methods.
The core keeps vitaminc's one mapping, so an integer field is a bigint
at every width. An adapter converts for an ORM whose integer columns are
a number, because it knows the column's type.

The wasm build's mapping belongs in vitaminc, which has no wasm-bindgen
bridge: cipherstash/vitaminc#632 asks for one. vcffi is the Go transport
into a WASI guest and does not apply.
The release jobs, the platform packages and trusted publishing move into
phase 1, as step 10. Both packages are published under a pre-release
version and tag, with no promise that a later version opens their stored
values. The stable release stays in phase 3. No decision is open.
ADR-0016 (PR #1772) decides that a context is a field path and named
parts: policies, labels and partitions, with one wire name each. The
plan takes its words, its wire names and its rules, and gives the
TypeScript form: the built-in parts as functions, parts listed on a
record or read from a field, keyset.with(..) to carry them, and
.partition(..) on a query. A bare value in .withContext is a note.

Phase 2 now waits for the engine to have named parts, not for a design.
Phase 1 writes only values with no parts, which are the two forms the
ADR says keep their stored bytes, so .withContext moves to phase 2.
Refinements are in phase 3, with #1567.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants