Repository navigation
Conversation
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.
|
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
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.
There was a problem hiding this comment.
🟡 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 | |
| - **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"`. |
| `client.decrypt`. Prisma Next's middleware encrypts column by column, | ||
| which maps to `client.encryptColumn`. |
| - The wasm build follows the same rules, and its linear memory holds no | ||
| plaintext after a call returns. |
| ## 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"] }), | ||
| }); | ||
| ``` |
There was a problem hiding this comment.
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.
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.
| 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. |
There was a problem hiding this comment.
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.



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-encryptfromeql-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/eqlexists 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):
recipher-compatexists, the adapters.Nothing is built. This pull request adds one document.
Changes
docs/plans/2026-11-22-recipher-typescript-sdk.md, which covers:encrypt,index,passthrough,opaque,Cipher,Keyset.wasm32-unknown-unknownwithwasm-bindgenfor edge runtimes. The core's builds hold no EQL code.@cipherstash/eqlships builds that linkeql-bindings' resolver, as Go'sencrypt/eqlguest does. Its root,./schemaand./sqlentries load no native build.recipher-js,recipher-js-nodeandrecipher-js-wasm. The engine crate itself is to be renamedrecipher.Planned, and the conformance corpus is written as one #1594, stack-encrypt: a dynamic plan holds its indexes as a free list — add the closedFieldIndexesshape #1672, stack-encrypt: match options are a fixed struct — add one analyzer pipeline for Rust, Go and EQL #1673, stack-encrypt conformance: declarations, requests and responses have no JSON Schema and no protocol version #1678), the plan says which part of phase 1 changes when it lands. The core crate names noLabel, so stack-encrypt: the context path typeLabelis still public, and the Go guest takes a context as path text — removeLabelandIntoLabel#1663 removes it without a change to the SDK.vitaminc-aead-napi, with vitaminc's mapping: anumberis a float, abigintan integer, aDatea timestamp, andVcDate,VcTimestamp,VcDecimalandVcUuidare the types JavaScript lacks. The wasm build needs the same mapping, which vitaminc does not have yet.@cipherstash/auth.recipher-compat, and EQL v4 installable throughstash eql install, which it is not yet.recipher-compat, the planned crate for them, would arrive as another extension.tenantId,recordId,forSub,notAfterand the rest) with the engine's wire names. A record lists its parts or reads one from a field,keyset.with(..)carries them, and a query takes partitions only.Result<T, RecipherError>with Rust's combinators.Review feedback taken
eql-bindings. The extension lives in@cipherstash/eql.keyset.encrypt(value)has. Go SDK: a value cannot be encrypted without a context, or without a struct — add plainEncryptandDecryptonCipher#1771 asks the same of the Go SDK.keyset.encrypt("a secret message"). No call names a kind; only a record field does.Resultand never throw.Resultis the core's own type with Rust'sResultmethods.unwrap()andexpect()are the only way to get an exception.vitaminc-aead-napi's, not the SDK's own.bigint, so theeql-json-v1case with18446744073709551615round-trips.decryptFieldcovers Prisma Next's reads of one column.Verification
Claims the plan depends on were run or read on
next:cargo check --target wasm32-unknown-unknown -p stack-encrypt --features dynamic: passes (at38db57856).cargo check --manifest-path packages/eql/Cargo.toml -p eql-bindings --features targets --target wasm32-unknown-unknown: passes (at38db57856).e62420d8e: a plan field is plain outputs or one named target, and aTargetResolverthe host links in runs a named target.NoTargetsis the build without one.eql-bindings'targetsfeature is the EQL resolver.Plannedencrypts and decrypts with no context from the caller.Plan::with_context_fieldrefuses an EQL type.dynamic::record::encrypt_withanddecrypt_withrun the lowering themselves — build aPlannedinstead #1669 and match index: "Mike Ng" no longer finds "Mike Nguyen" with short words; cut query word tokens only when the query has no n-gram #1398 are closed. The other issues the plan names are open.Read in
cipherstash/vitamincat222f1ad39:vitaminc-aead-napiis 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
Sendfor napi-rs, that a binding can reachOpaqueBlob'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/eqldeclares 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
bigintin the core at every width, as in vitaminc. An adapter converts for an ORM whose integer columns are anumber.wasm-bindgen.vitaminc-aead-napihas no WebAssembly counterpart, so awasm-bindgenbuild must copy the JavaScript value mapping — addvitaminc-aead-wasmvitaminc#632 asks for it; the wasm crate holds it until then.keyset.with(..), as Go'sCipher.Withdoes, not to each call. Rust passes them to each call. Check that this is the form you want..withContext. It writes only the two forms ADR-0016 says keep their stored bytes.