Repository navigation
docs(plans): the TypeScript SDK on Stack Encrypt, a core with EQL as an extension - #1747
Conversation
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
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
dfdc959 to
ceb6cb6
Compare
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.
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.
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.
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.
From review of #1774. The SDK has one Rust crate, the Node addon. The split into a core crate and a thin node crate had one consumer, and the core mostly re-wrapped engine types. A common crate is split off when the wasm build exists and what the two builds share can be seen. Cipher, Keyset and Ciphertext are napi classes written in Rust, and napi-rs generates their types. TypeScript keeps only what Rust cannot express: Result, the declaration types and the typed signatures. There is no hand-written description of the native interface. The crate uses the engine's and vitaminc's types directly, and derives OpaqueDebug for a type that holds a secret. The plan no longer takes the Python SDK as an example.
The bridge between JavaScript values and the engine was copied in from vitaminc as an unpublished crate. Its refusals are typed diagnostics with recipher:: codes, and the wasm mapping belongs beside it here.
The context design is settled, so the test that held the crate clear of Label and IntoLabel was removed in review, and the rule goes with it.
opaque and UUID wait on the engine: nothing writes a frame in the storage profile, and the dynamic value model has no UUID. The engine's futures are Send, one field opens alone, and a scalar's bytes name its type. The two crates get the checks #1797 lists.
ceb6cb6 to
9cfbfdc
Compare
cipherstash-agent
left a comment
There was a problem hiding this comment.
Review attestation
Reviewed 9cfbfdc · posted from Claude Code · claude-opus-5-5 · effort medium
Sources: rust-security · claude-opus-5-5; code-review (manual) · claude-opus-5-5; mattpocock code-review · claude-opus-5-5
Skills: code-review (loaded, but it reviewed the wrong target; the delegate reviewed by hand), company-skills:rust-security, mattpocock-skills:code-review, company-skills:review-cross-check
Every finding was checked against 9cfbfdc and cross-checked against the existing threads, and none repeats one. This PR merged while the review ran.
Findings (23): 10 major, 13 minor. 22 inline, 1 below.
generalminor The PR description listsVcUuidamong the bridge's types, but the plan refuses it withrecipher::uuiduntil #1821 (586, 594-597). Its "Not checked" list also still names three items the plan records as found (1160-1175).
Source: mattpocock code-review · claude-opus-5-5
Generated by Claude Code
| - **Testing without ZeroKMS.** `@cipherstash/recipher/testing` builds a | ||
| cipher over the engine's deterministic test keys, with no credentials and | ||
| no network, as Go's `encrypttest.NewClient` does. |
There was a problem hiding this comment.
major @cipherstash/recipher/testing puts the engine's deterministic keys in the production package, so every shipped .node and wasm build must carry stack-kms/test-support (DeterministicSource: "A test double, not a cipher"), and an app that imports /testing by mistake seals real data under keys anyone can derive. Go's encrypttest is a separate module with its own deterministic guest, "Import it only from _test.go files". Publish it as a separate package with its own test build, and check in CI that no release artefact links the deterministic source.
Source: rust-security · claude-opus-5-5
Generated by Claude Code
| - **Node.js**, through a native extension built with napi-rs. | ||
| - **Edge runtimes and browsers**, through the same Rust code built for | ||
| `wasm32-unknown-unknown` with `wasm-bindgen`. |
There was a problem hiding this comment.
major "Edge runtimes and browsers", with default loading the wasm build (line 270) and credentials from "the variables or the cipher's options" (704-708), ships the workspace clientKey in a browser bundle: the engine needs CS_CLIENT_KEY on every auth path (packages/stack-encrypt/src/lib.rs:130). skills/stash-edge says server-side only with no browser condition (#804), and @cipherstash/auth sets "browser": false. Drop browsers, say the wasm build is server-side only, and add "browser": false.
Source: rust-security · claude-opus-5-5
Generated by Claude Code
| - **No error holds a secret.** 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.
major A decrypted row is a plain object of own data properties (Plaintext<..> at 406-407, built by the value bridge's JsBuilder), so console.log(row), util.inspect and JSON.stringify print the plaintext: nothing in the plan gives the promised redacted inspect. Either drop the claim and say a decrypted row must not be logged, or make rows a redacted wrapper type and change Plaintext<..> to match.
Source: rust-security · claude-opus-5-5
Generated by Claude Code
| A cipher runs in one build. A program names its extensions when it builds | ||
| the cipher, and the cipher loads the build that holds them: | ||
|
|
||
| ```ts | ||
| import { Cipher } from "@cipherstash/recipher"; | ||
| import { eql } from "@cipherstash/eql/recipher"; | ||
|
|
||
| const cipher = (await Cipher.create({ extensions: [eql] })).unwrap(); | ||
| ``` |
There was a problem hiding this comment.
major The core addon and the EQL build each define their own napi Cipher/Ciphertext classes, and with no TypeScript wrapper (245-246) an object made by one cannot be used by the other: napi 3 tags classes by crate@version::path, so a core Ciphertext.fromBytes(..) passed to an EQL-build cipher is refused once the two are released at different versions (928-932), and instanceof Cipher is false. Either keep every class in one addon or put a TypeScript layer in front of each build, and record the choice; it is missing from "Not checked".
Source: code-review (manual) · claude-opus-5-5
Generated by Claude Code
| - **Nothing escapes as an exception.** A failure in the binding, such as a | ||
| build that does not load, is an `Err` too. A test passes each call a | ||
| wrong argument and a failing key service, and asserts that none throws | ||
| or rejects. |
There was a problem hiding this comment.
major napi-rs converts arguments in the generated callback and throws InvalidArg synchronously before any promise exists, so cipher.decrypt(123) throws, which this test would fail on and which contradicts "No call throws" (310, 729). Take arguments as Unknown and validate in Rust, or add a guard layer; widen #1801 to cover it.
Source: code-review (manual) · claude-opus-5-5
Generated by Claude Code
| - **Installing EQL v4.** `@cipherstash/eql` ships the v3 bundle, and | ||
| `stash eql install` installs it. Both need the v4 bundle before an | ||
| adapter can move. That is its own piece of work, in the CLI and in | ||
| `packages/eql`, and step 17 depends on it. |
There was a problem hiding this comment.
minor Step 17 is DynamoDB, which needs no EQL; the step that waits for the EQL v4 install is step 16 (1021-1023).
| `packages/eql`, and step 17 depends on it. | |
| `packages/eql`, and step 16 depends on it. |
Source: mattpocock code-review · claude-opus-5-5; code-review (manual) · claude-opus-5-5
Generated by Claude Code
| - **A method called without its object (#1801).** When Rust returns each | ||
| `Result`, the hand-written TypeScript layer over the native classes can |
There was a problem hiding this comment.
minor "the hand-written TypeScript layer over the native classes can go" contradicts "no TypeScript class that wraps a native one" (245-246), and Result is a TypeScript type (249, 753) that Rust would then have to build. Say which side defines Result and whether a layer exists.
Source: mattpocock code-review · claude-opus-5-5
Generated by Claude Code
| Date: 2026-11-22. Revised 2026-11-23: the SDK is a general-purpose core | ||
| with EQL as an extension, and the work is in three phases. Status: | ||
| proposed. Nothing in this plan is built. |
There was a problem hiding this comment.
minor The header says "Revised 2026-11-23" while the decisions are dated 2026-11-25 (1068), and "Nothing in this plan is built" sits beside findings from #1774-#1776 (1160-1165). Refresh the date and status.
Source: mattpocock code-review · claude-opus-5-5
Generated by Claude Code
| **Rust defines the API, and TypeScript does not copy it.** `Cipher`, | ||
| `Keyset` and `Ciphertext` are napi classes written in Rust. napi-rs | ||
| generates their TypeScript types, and the generated file is committed and | ||
| checked for drift in CI, as `@cipherstash/auth`'s `native.d.ts` is. There | ||
| is no hand-written description of the native interface, and no TypeScript | ||
| class that wraps a native one. TypeScript holds only what Rust cannot | ||
| express: | ||
|
|
||
| - `Result` and its methods, because `isOk()` narrows a type; | ||
| - the types of a declaration, such as `Plaintext<..>` and `Stored<..>`, | ||
| and the compile-time checks of a query; | ||
| - the typed signatures over the Rust methods, such as one value in and | ||
| one out, an array in and an array out. |
There was a problem hiding this comment.
minor napi-rs cannot generate a generic class or per-record overloads, so Ciphertext<string> (329) and the typed signatures need a hand-written .d.ts that re-declares the native classes, which "no hand-written description of the native interface" rules out. Say a hand-written declaration re-types the generated classes, and how CI checks the two for drift.
Source: code-review (manual) · claude-opus-5-5
Generated by Claude Code
| - **Each call returns a builder.** Awaiting it runs it and gives a | ||
| `Result`. `.audit`, `.withCredential` and `.signal` come before the |
There was a problem hiding this comment.
minor "Each call returns a builder … .audit, .withCredential and .signal" reads as every call, but a query has no .audit (721-722) and .withCredential exists only on the per-call-credential cipher (709-713). Qualify the sentence.
Source: code-review (manual) · claude-opus-5-5
Generated by Claude Code



Closes #1809.
Summary
A plan for the TypeScript SDK on Stack Encrypt, CipherStash's Rust encryption engine. Today only Go uses the engine.
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, the Node addon.Cipher,KeysetandCiphertextare napi classes written in Rust, and napi-rs generates their TypeScript types. TypeScript keeps onlyResult, the declaration types and the typed signatures. A common crate is split off when the wasm build needs one. 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.