diff --git a/docs/plans/2026-11-22-recipher-typescript-sdk.md b/docs/plans/2026-11-22-recipher-typescript-sdk.md index cc75541b0..3338d379a 100644 --- a/docs/plans/2026-11-22-recipher-typescript-sdk.md +++ b/docs/plans/2026-11-22-recipher-typescript-sdk.md @@ -1,10 +1,17 @@ # `@cipherstash/recipher`: the TypeScript SDK on Stack Encrypt 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. +with EQL as an extension, and the work is in three phases. Revised +2026-11-29: the value rules now match the code of #1775 and #1996. Revised +again that day: a record's declaration holds Stack Encrypt's plan, and the +language binding only reads it. -This plan says how to build the TypeScript SDK on the Stack Encrypt engine +Status: in progress. Steps 1 and 2 of the build order are built, in #1774 +and #1775. Step 3 and the UUID are in open pull requests: #1776 and #1996. +The record pull request is being reworked to follow +[A record](#a-record). + +This plan says how to build the TypeScript SDK on Stack Encrypt (`packages/stack-encrypt`). It is one new npm package and an addition to another: @@ -16,20 +23,20 @@ another: extension adds the EQL v4 types, so a record's fields can be stored in PostgreSQL columns and queried there. -The split is the one Rust has: `stack-encrypt` is the engine, and +The split is the one Rust has: `stack-encrypt` does the encryption, and `eql-bindings` adds the EQL types to it. The plan also says how the Drizzle, Supabase and Prisma Next adapters move onto the two packages. -It follows the [SDK design principles](../sdk-design-principles.md). The -engine's own documentation (`packages/stack-encrypt/src/lib.rs`) sets the +It follows the [SDK design principles](../sdk-design-principles.md). Stack +Encrypt's own documentation (`packages/stack-encrypt/src/lib.rs`) sets the order: a value first, then a whole object, then a record, then search terms. A database comes last, through EQL. The Go SDK (`languages/golang/encrypt`, with `encrypt/eql`) is the reference for what an SDK does. -The engine crate, `stack-encrypt`, is to be renamed `recipher`. This plan +The crate `stack-encrypt` is to be renamed `recipher`. This plan uses the current name. The Rust crates of the TypeScript SDK are named -`recipher-js`, so they never share the engine's name. +`recipher-js`, so they never share that name. ## Contents @@ -66,10 +73,27 @@ file, an object store, a key-value store, or a database column of bytes. A program that wants PostgreSQL to compare encrypted values adds the EQL extension. -The engine does all the work. The SDK sends a declaration and values across -a native binding, and the engine returns ciphertexts, terms and values. The -bytes are the same as Go's and Rust's for the same declaration, because they -run the same code. +Stack Encrypt does all the work, and that code exists once. The SDK sends +a plan and values across a language binding, and Stack Encrypt returns +ciphertexts, terms, and values. A plan is Stack Encrypt's description of how +to encrypt each field of a record: see [A record](#a-record). The bytes are +the same as Go's and Rust's for the same plan, because they run the same +code. + +The language binding is thin. A small team cannot maintain the same +behaviour written again in each language. Three rules keep the binding +thin: + +- **The binding does not repeat Stack Encrypt.** It does not read a plan, + check a row, convert a value to its field's kind, or build the encrypted + form itself. It calls `stack_encrypt::dynamic` for each of those. +- **A gap is fixed in Stack Encrypt.** When the SDK needs something that + `dynamic` cannot do, the change goes into Stack Encrypt, where every SDK + gets it. The binding does not work around the gap. +- **Stack Encrypt's names are not renamed.** A plan's outputs are named + `c`, `eq`, `match`, `ore`, `ope`, and `passthrough`. The SDK uses those + names. If a name is hard to read, an alias is added to Stack Encrypt's + plan, and every SDK gets it. It runs in two places: @@ -86,7 +110,7 @@ In scope, for the core: - A value, a file and a whole object, each as one ciphertext, with a context or with none. - A record: fields that are encrypted, indexed or passed through. -- The engine's indexes (`equality`, `match`, `ore`, `ope`) and the query +- Stack Encrypt's indexes (`eq`, `match`, `ore`, `ope`) and the query terms for them. - The parts of a context: policies, labels and partitions. - Nulls, credentials, keysets and audit metadata. @@ -96,7 +120,7 @@ In scope, for the EQL extension: - EQL v4 only. The extension writes and reads EQL v4 values. It does not read EQL v3 values or anything `cipherstash-client` wrote. -- Every EQL v4 type the engine produces, including `JsonSearch` documents. +- Every EQL v4 type Stack Encrypt produces, including `JsonSearch` documents. - The EQL/JSON profile, and the EQL rows of the exchange profile. In scope, after both, and after `recipher-compat`: @@ -115,16 +139,16 @@ Not in scope: ## Phases -The engine issues this plan first waited for are still open. The design of +Stack Encrypt issues this plan first waited for are still open. The design of a context is decided, in ADR-0016 (`packages/stack-encrypt/docs/adr/0016-a-context-is-a-field-path-and-named-parts.md`, -PR #1772), but the engine does not have it yet. So the work is in three +PR #1772), but Stack Encrypt does not have it yet. So the work is in three phases, and the first starts now. | Phase | Starts | What it builds | |---|---|---| | 1 | Now | Everything that needs no context from the caller. The core first: values, records, query terms, credentials and the wasm build. Then the EQL extension, and 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 has. | +| 2 | When Stack Encrypt has ADR-0016's named parts | Labels and partitions, a value with a context, and the policies Stack Encrypt has. | | 3 | When the issues that change stored bytes are closed | Refinements, the first stable release and, when `recipher-compat` exists, the adapters. | [Order of work](#order-of-work) lists the steps of each phase. @@ -141,8 +165,8 @@ value with no context, and a value whose whole context is a field path. Two rules keep phase 1 clear of the open design: -- **Only the Rust crate names an engine type.** The TypeScript code does - not. A rename in the engine changes one crate. +- **Only the Rust crate names a Stack Encrypt type.** The TypeScript code does + not. A rename in Stack Encrypt changes one crate. - **No phase 1 build promises that a later build opens its stored values.** The README says so. The promise starts with the first stable release. @@ -154,22 +178,34 @@ phase 1 when it lands. | Issue | State on 2026-11-23 | What it changes here | |---|---|---| | #1669 (`encrypt_with` and `decrypt_with` become `Planned`) | Closed | Nothing. The crate calls `Planned` from the first record step. | -| #1489 (the naming review) | Open | The engine names in the crate (`StackCipher` becomes `Cipher`, `stack-kms` becomes `stack-zerokms`, and the rest). The TypeScript names already follow the review: `Cipher` and `Keyset`. | +| #1489 (the naming review) | Open | Stack Encrypt names in the crate (`StackCipher` becomes `Cipher`, `stack-kms` becomes `stack-zerokms`, and the rest). The TypeScript names already follow the review: `Cipher` and `Keyset`. | | #1594 (a binding sends a serialised `Planned`) | Open | The conformance runners' reader of the corpus. The crate calls `Planned` directly. | -| #1672 (the closed `FieldIndexes` shape) | Open | The one function in the crate that writes a plan from a declaration. | +| #1672 (the closed `FieldIndexes` shape) | Open | `record()`, which writes the plan in TypeScript. | | #1673 (match options as one analyzer pipeline) | Open | The options of a `match` index. Phase 1 offers the default options only. | -| #1678 (JSON Schemas and a protocol version) | Open | Nothing in phase 1, because TypeScript writes no frame. Phase 3 checks the plan the crate writes against the schema. | +| #1678 (JSON Schemas and a protocol version) | Open | Nothing in phase 1. Phase 3 checks the plan that `record()` writes against the schema. | + +The record step found two gaps in Stack Encrypt. Each is fixed in Stack +Encrypt. The binding works around neither: -Phase 2 waits for the engine to have ADR-0016: +- **One field of a plan (#2028).** No call encrypts or decrypts one field of a + plan. A row that lacks a field is refused. `{ record, field }` needs + this call. +- **Serde for the encrypted tree (#2029).** The tree that a record encrypts to + (`StackCipherText`) cannot be serialised. Only its leaves can. So each + binding writes its own conversion: the Go guest has `encode_tree` and + `decode_tree`. With serde on the tree, the binding writes it to a frame, + and the value bridge builds the JavaScript value from the frame. + +Phase 2 waits for Stack Encrypt to have ADR-0016: - **#1663**: the `Label` struct becomes `FieldPath`, and `IntoLabel` goes. -- **Named parts in the engine.** The traits `Policy`, `Label` and +- **Named parts in Stack Encrypt.** The traits `Policy`, `Label` and `Partition`, the built-in parts, and `.partition(..)` on a query. The untyped `Scope` and `Bind` are removed. No issue tracks this yet. - **#1566**: a value's parts go to ZeroKMS as named key request items. A policy also needs ZeroKMS to check it. Phase 2 offers each policy when -the engine and ZeroKMS have it. #1683 is to be rewritten for that. +Stack Encrypt and ZeroKMS have it. #1683 is to be rewritten for that. Phase 3 waits for these, because they change stored bytes or the compatibility promise: @@ -191,19 +227,19 @@ do not change a binding. #1572 is to be rewritten or closed by ADR-0016. #1479 ( ## Packages and build targets -The SDK has two Rust crates: the Node addon, and the value bridge it +The SDK has two Rust crates: the language binding for Node, and the value bridge it converts values with. | Path | Name | What it is | |---|---|---| -| `languages/typescript/packages/recipher-js/crate` | crate `recipher-js` | Rust, napi-rs 3. The Node addon. It defines the classes TypeScript uses, runs every operation through the engine, and maps errors. It depends on `stack-encrypt` (`dynamic`) by path, and converts values with `recipher-value-napi`. | +| `languages/typescript/packages/recipher-js/crate` | crate `recipher-js` | Rust, napi-rs 3. The language binding for Node. It defines the classes TypeScript uses, runs every operation through Stack Encrypt, and maps errors. It depends on `stack-encrypt` (`dynamic`) by path, and converts values with `recipher-value-napi`. | | `languages/typescript/packages/recipher-js/value-napi` | crate `recipher-value-napi` | Rust, napi-rs 3. The value bridge: reads a JavaScript value into vitaminc's plaintext model, and builds one from it. Not published. | | `languages/typescript/packages/recipher-js` | npm `@cipherstash/recipher` | The core SDK, its types and the loaders. Its builds hold no EQL type (`NoTargets`). | | `languages/typescript/packages/recipher-js/platforms/*` | npm `@cipherstash/recipher-` | One package per Node platform, holding its `.node` file. | | `packages/eql/packages/eql` | npm `@cipherstash/eql`, entry `./recipher` | The EQL extension: the EQL v4 types in TypeScript, and the loaders of the builds that hold them. The package exists; the entry is new. | | `packages/eql/packages/eql-` | npm `@cipherstash/eql-` | One package per Node platform, holding the EQL build's `.node` file. | -**How the extension reaches the engine.** The engine runs a named type +**How the extension reaches Stack Encrypt.** Stack Encrypt runs a named type through a `TargetResolver` that the host links in. `NoTargets` is the build without one. So the crate has a cargo feature, `eql`, which links `eql-bindings` (`targets`) by path and uses its resolver. The core package @@ -218,7 +254,7 @@ the cipher, and the cipher loads the build that holds them: import { Cipher } from "@cipherstash/recipher"; import { eql } from "@cipherstash/eql/recipher"; -const cipher = (await Cipher.create({ extensions: [eql] })).unwrap(); +const cipher = await Cipher.create({ extensions: [eql] }).unwrap(); ``` The extension is passed as a value, not registered by an import, because a @@ -244,8 +280,8 @@ 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. Each native method returns the `Result` -itself: the package's TypeScript hands the addon its `Ok`, `Err` and -`RecipherError` classes once, when it loads the addon, and Rust builds +itself: the package's TypeScript hands the binding its `Ok`, `Err` and +`RecipherError` classes once, when it loads the binding, and Rust builds `new Ok(value)` or `new Err(error)`. Each method's public signature is written in Rust, in napi-rs's `ts_type` attribute, one overload per line, and the generated `native.d.ts` is the public type. A small header that @@ -256,9 +292,9 @@ parameter. TypeScript holds only what Rust cannot express: - the types of a declaration, such as `Plaintext<..>` and `Stored<..>`, and the compile-time checks of a query, which the signatures in Rust name; -- the loader, and stand-in classes for when the addon did not load. +- the loader, and stand-in classes for when the binding did not load. -**The crate uses the engine's and vitaminc's types.** It does not wrap +**The crate uses Stack Encrypt's and vitaminc's types.** It does not wrap `ValueFrame`, a ciphertext or an error in a type of its own. A type that holds a secret derives vitaminc's `OpaqueDebug`. The vitaminc skill (`.claude/skills/vitaminc/`, added by #1777) lists the type for each task. @@ -272,7 +308,7 @@ peer dependency, for that entry alone. The core package and the `./recipher` entry each pick their build by export condition, as `@cipherstash/auth` does: -- `node` loads the napi addon for the platform. +- `node` loads the napi binding for the platform. - `default` loads the wasm build, as a separate `.wasm` file. - `./wasm-inline` (`./recipher/wasm-inline` in `@cipherstash/eql`) loads the wasm build inlined into the JavaScript, for bundlers and edge @@ -289,7 +325,7 @@ Each package's `build` and `test` scripts never run cargo, so root ## The core -The core follows the engine's own order: a value, a whole object, a record, +The core follows Stack Encrypt's own order: a value, a whole object, a record, then search terms. Nothing in this section needs a database. ### A value @@ -297,7 +333,7 @@ then search terms. Nothing in this section needs a database. ```ts import { Cipher } from "@cipherstash/recipher"; -const cipher = (await Cipher.create()).unwrap(); +const cipher = await Cipher.create().unwrap(); const keyset = cipher.defaultKeyset(); const sealed = await keyset.encrypt("a secret message"); @@ -308,7 +344,7 @@ if (sealed.isErr()) { const opened = await cipher.decrypt(sealed.value); ``` -This is plain encryption, with no context. It is the engine's +This is plain encryption, with no context. It is Stack Encrypt's `keyset.encrypt(value)`. - **One value in, one ciphertext out.** The next section encrypts an @@ -322,13 +358,13 @@ This is plain encryption, with no context. It is the engine's the value bridge's mapping, and [Values](#values) has the table. No call names a kind. - **A plain object is refused.** It has no one encoding, so the caller - chooses `opaque(..)` or `json(..)`. The engine has the same rule: it has + chooses `opaque(..)` or `json(..)`. Stack Encrypt has the same rule: it has no fallback that picks the stored bytes of a struct. - **Encrypting needs a keyset; decrypting does not.** Every data key is made under one keyset, and a ciphertext names the keyset it was made under. `cipher.decrypt` opens a value from any of the cipher's keysets. - `keyset.decrypt` refuses a value from another keyset. This is the - engine's rule. + `keyset.decrypt` refuses a value from another keyset. This is Stack + Encrypt's rule. - **A `Ciphertext` is opaque bytes.** `ciphertext.toBytes()` gives a `Uint8Array` to store, and `Ciphertext.fromBytes(..)` reads one back. Each ciphertext has its own data key. @@ -342,14 +378,14 @@ This is plain encryption, with no context. It is the engine's ### An array of values ```ts -const sealed = await keyset.encrypt(["first secret", "second secret"]); -// sealed.value is an array of two ciphertexts, in the same order. +const sealed = await keyset.encrypt(["first secret", "second secret"]).unwrap(); +// sealed is an array of two ciphertexts, in the same order. -const opened = await cipher.decrypt(sealed.unwrap()); +const opened = await cipher.decrypt(sealed).unwrap(); ``` An array in is an array out, and it makes one ZeroKMS request however long -it is. This is the engine's rule for a collection. There is one `encrypt` +it is. This is Stack Encrypt's rule for a collection. There is one `encrypt` and one `decrypt`: no second function for a batch, and no loop over single calls. @@ -358,8 +394,8 @@ calls. A file or a stored object is a `Uint8Array`, so it needs no kind: ```ts -const sealed = await keyset.encrypt(await readFile("invoice.pdf")); -await writeFile("invoice.pdf.enc", sealed.unwrap().toBytes()); +const sealed = await keyset.encrypt(await readFile("invoice.pdf")).unwrap(); +await writeFile("invoice.pdf.enc", sealed.toBytes()); ``` A whole object is one ciphertext with `opaque`: @@ -368,75 +404,121 @@ A whole object is one ciphertext with `opaque`: import { opaque } from "@cipherstash/recipher"; const card = { number: "4111 1111 1111 1111", expiry: { month: 4, year: 2031 } }; -const sealed = await keyset.encrypt(opaque(card)); +const sealed = await keyset.encrypt(opaque(card)).unwrap(); ``` -`opaque` stores what the engine's `OpaqueBlob` stores, in the same format +`opaque` stores what Stack Encrypt's `OpaqueBlob` stores, in the same format as a Go opaque struct. Nothing inside it can be searched. An opaque value is a storage blob, vitaminc's storage profile, encrypted as bytes. Rust's `OpaqueBlob` writes the blob from a `Serialize`, and Go writes it with `vcffi.MarshalStorage`. The SDK needs the same from a JavaScript value, which reaches Rust as a frame, and nothing converts a -frame to a blob yet (#1822). The engine needs no change. Version 1 of the -profile holds plain scalars only, so a `Date` or a `VcDecimal` inside an +frame to a blob yet (#1822). Stack Encrypt needs no change. Version 1 of the +profile holds plain scalars only, so a `Date` or an `RcDecimal` inside an opaque object is refused. ### A record A record declares each field once. A field is encrypted, encrypted and -indexed, or passed through. The words are the engine's. +indexed, or passed through. The words are Stack Encrypt's. ```ts import { encrypt, kinds, passthrough, record } from "@cipherstash/recipher"; -export const user = record("users", { +export const UserRecord = record("users", { id: passthrough(), - email: encrypt(kinds.string, { index: ["equality"] }), + email: encrypt(kinds.string, { index: ["eq"] }), name: encrypt(kinds.string, { index: ["match"] }), - age: encrypt(kinds.int32, { index: ["equality", "ore"] }), + age: encrypt(kinds.int32, { index: ["eq", "ore"] }), notes: encrypt(kinds.string), }); +const user = { id: 1n, email: "ada@example.com", name: "Ada Lovelace", age: 36n, notes: "maths" }; + // One row. An array of rows returns an array, in one ZeroKMS request. -const stored = await keyset.encrypt(user, row); -const opened = await cipher.decrypt(user, stored.unwrap()); +const stored = await keyset.encrypt(user, { record: UserRecord }).unwrap(); +const opened = await cipher.decrypt(stored, { record: UserRecord }).unwrap(); ``` +- **The plaintext comes first.** Every `encrypt` takes the value first and + an options object second. The options are `{ kind }` for one value, + `{ record }` for a row, and `{ record, field }` for one field of a row. A declaration is + named for what it is (`UserRecord`), so a reader can tell it from the + row (`user`). A context will be another key of the same object, so no + call takes a third argument (#1776). - **A field names its kind.** A declaration has no value to read a type from, and the stored type is fixed before any row exists. So - `encrypt(kinds.string)` names it, in the engine's word for the kind. -- **The stored row has one object for each sealed field**, with one - property for each output: `ciphertext`, and `equality`, `match`, `ore` - or `ope` for each index the field declares. Each is opaque bytes. A - passthrough field keeps its value. This is the shape Go stores. -- **The compiler checks the row.** `Plaintext` is + `encrypt(kinds.string)` names it, in Stack Encrypt's word for the kind. +- **`record()` writes Stack Encrypt's plan.** The plan is the form that + `dynamic::record::plan` reads, and the form that Go sends. The + declaration above holds this plan: + + ```ts + { + id: { context: ["users", "id"], outputs: ["passthrough"] }, + email: { context: ["users", "email"], outputs: ["c", "eq"], type: "string" }, + name: { context: ["users", "name"], outputs: ["c", "match"], type: "string" }, + age: { context: ["users", "age"], outputs: ["c", "eq", "ore"], type: "int32" }, + notes: { context: ["users", "notes"], outputs: ["c"], type: "string" }, + } + ``` + + There is no second format. The binding has no declaration type of its + own, and builds no plan by hand. +- **The user never sees the plan.** A program calls `record`, `encrypt`, + and `passthrough`. The program passes the declaration to a call. The + declaration's public type shows the record's name and the types of its + fields. It does not show the plan. The plan still shapes the API: each + option of `encrypt(..)` is an option that a plan has, under the plan's + name for it. +- **The binding reads the plan and calls Stack Encrypt.** The value bridge + converts the plan object to a frame, as it converts any value, so + TypeScript writes no frame. `dynamic::record::plan` reads the frame. + `dynamic::Planned` encrypts and decrypts the rows. The binding keeps + each plan it has read, keyed by the plan's bytes, so each plan is read + once. +- **Stack Encrypt checks the plan and each row.** + `Cipher.create({ records: [UserRecord] })` reads each plan before it + looks for credentials. A refusal is an `Err` that names the field and + the reason. A `checkDeclarations()` function runs the same check with no + credentials, for a test or a CI step. For a row, Stack Encrypt refuses a + field that the plan does not name. It also refuses a missing field, + unless the field stores a null as SQL `NULL`. So a field that is not + encrypted must be declared as a passthrough. Stack Encrypt also converts + each value to its field's kind. The binding makes none of these checks + itself. +- **An encrypted row is Stack Encrypt's representation, unchanged.** Each + encrypted field is an object with one property for each output, under + the plan's names. `c` is the ciphertext. `eq`, `match`, `ore`, and `ope` + are the indexes that the field declares. Each is opaque bytes. A + passthrough field keeps its value. The binding renames nothing. +- **The compiler checks the row.** `Plaintext` is `{ id: bigint; email: string; name: string; age: bigint; notes: string }`. - A row of another shape does not compile. `Stored` is the - stored type, and `stored.notes.equality` does not compile. -- **The engine checks the declaration when the cipher is built.** - `Cipher.create({ records: [user] })` turns each record into a plan once, - in Rust. A refusal is an `Err` that names the record, the field and the - reason. A - `checkDeclarations()` function runs the same check with no credentials, - for a test or a CI step. -- **The user never sees the plan.** The plan's frame is written in Rust - from the declaration. TypeScript writes no frame. + A row of another shape does not compile. `Stored` is + the encrypted row's type. `stored.notes.eq` does not compile. +- **Index names are the plan's.** `index: ["eq"]` names the output `eq`. A + longer alias, such as `equality`, would be added to Stack Encrypt's + plan, so that every SDK reads it. This plan adds none. - **Context.** A field's context is its field path: the record's name and the field's name. Phase 2 adds parts; see [Context](#context-policies-labels-and-partitions). - **Nulls.** A field that can be `null` declares it, with the null modes - the engine's `NullMode` has. -- **A declaration is plain data.** A library reads a record's name, its - fields and each field's declaration from the object. + that a plan has: `sealed` and `sql`. +- **A declaration is plain data**: a frozen object with the record's name + and its plan. The package's own adapters read a field's kind and outputs + from the plan. An application does not. One field of a record, for an update of that field: ```ts -const email = await keyset.encryptField(user, "email", "ada@example.com"); -const opened = await cipher.decryptField(user, "email", email.unwrap()); +const email = await keyset.encrypt("ada@example.com", { record: UserRecord, field: "email" }).unwrap(); +const opened = await cipher.decrypt(email, { record: UserRecord, field: "email" }).unwrap(); ``` +Stack Encrypt has no call for one field of a plan yet (#2028). These two calls +wait for it. The binding does not build a second plan for each field. + ### Search terms A query names a field, an operator and a value. The result is the term to @@ -454,7 +536,7 @@ const terms = await keyset.query(user, [ - **The compiler checks queries.** A query on `name` with `eq` does not compile, because a `match` index answers no equality. The operators of - each index are generated from the engine. A test asks the engine + each index are generated from Stack Encrypt. A test asks Stack Encrypt (`dynamic::field_operators`) and compares the answer with the generated file. - **A term is opaque bytes**, byte-equal to the term Rust and Go derive. @@ -474,10 +556,11 @@ const terms = await keyset.query(user, [ way. - **All or nothing.** A batch that fails is one `Err`. It returns no partial array. -- **Each call returns a builder.** Awaiting it runs it and gives a - `Result`. `.audit`, `.withCredential` and `.signal` come before the - `await`. Phase 2 adds `.withContext` and `.partition` to the same - builder, so it changes no phase 1 call. +- **Each call returns a pending result.** Awaiting it runs the call and + gives a `Result`. `.audit`, `.withCredential`, and `.signal` set up + the call. They come before any `Result` method. Phase 2 adds `.withContext` + and `.partition` to the same object, so it changes no phase 1 call. See + [Results and errors](#results-and-errors). ## Context: policies, labels and partitions @@ -494,7 +577,7 @@ three kinds: group's values and search terms apart from another's. It restricts no reader. -The built-in parts have the engine's wire names: +The built-in parts have Stack Encrypt's wire names: | TypeScript | Wire name | Kinds | |---|---|---| @@ -509,12 +592,12 @@ The built-in parts have the engine's wire names: ### A value with a context ```ts -const sealed = await keyset.encrypt("a secret message").withContext("notes"); -const opened = await cipher.decrypt(sealed.unwrap()).withContext("notes"); +const sealed = await keyset.encrypt("a secret message").withContext("notes").unwrap(); +const opened = await cipher.decrypt(sealed).withContext("notes").unwrap(); ``` -A bare value in `.withContext` is a `note`, which is a label. This is the -engine's `encrypt_with_context`. It also takes named parts: +A bare value in `.withContext` is a `note`, which is a label. This is Stack +Encrypt's `encrypt_with_context`. It also takes named parts: `.withContext(tenantId(42n), recordId(id))`. ### A record with parts @@ -524,14 +607,14 @@ import { encrypt, forSub, kinds, passthrough, record, recordId, tenantId } from export const notes = record("notes", { id: passthrough().label(recordId), - title: encrypt(kinds.string, { index: ["equality"] }), + title: encrypt(kinds.string, { index: ["eq"] }), }, { context: [tenantId(), forSub] }); const tenant = keyset.with(tenantId(42n)); -const stored = await tenant.encrypt(notes, row); -const term = await tenant.query(notes, { field: "title", op: "eq", value: "Renewal" }); -const opened = await tenant.decrypt(notes, stored.unwrap()); +const stored = await tenant.encrypt(row, { record: notes }).unwrap(); +const term = await tenant.query(notes, { field: "title", op: "eq", value: "Renewal" }).unwrap(); +const opened = await tenant.decrypt(stored, { record: notes }).unwrap(); ``` - **A record lists its parts.** `context: [..]` names the parts a caller @@ -554,8 +637,8 @@ const opened = await tenant.decrypt(notes, stored.unwrap()); - **A custom part.** `label("region")` and `partition("region")` define a label or a partition of the application's own. A built-in wire name is refused. There is no function that defines a policy, because `Policy` - is sealed in the engine. -- **The order is the engine's.** Parts are sorted by wire name, not by + is sealed in Stack Encrypt. +- **The order is Stack Encrypt's.** Parts are sorted by wire name, not by the order they are written in. - **A label that does not match is refused before any key is requested**, as an `Err` with the code `stack_encrypt::context_mismatch`. @@ -564,9 +647,9 @@ const opened = await tenant.decrypt(notes, stored.unwrap()); ## Values -The conversion between JavaScript values and the engine is the value +The conversion between JavaScript values and Stack Encrypt is the value bridge, `recipher-value-napi`, in `recipher-js/value-napi`. It reads -JavaScript values into vitaminc's plaintext model, which the engine +JavaScript values into vitaminc's plaintext model, which Stack Encrypt encrypts, and builds them back. It is a copy of vitaminc's `vitaminc-aead-napi` 0.10.0, moved here because only this SDK uses it. It is not published. @@ -587,31 +670,59 @@ So no JSON text of a row crosses the boundary. | `bigint` | an integer, at the narrowest width that holds it | `bigint`, for every width | | `Uint8Array`, `Buffer` | bytes | `Uint8Array` | | `Date` | a timestamp, in milliseconds | `Date` | -| `VcTimestamp("2026-11-23T01:02:03.000000001Z")` | a timestamp, in nanoseconds | `Date` when it is whole milliseconds, else `VcTimestamp` | -| `VcDate("2026-11-23")` | a calendar date | `VcDate` | -| `VcDecimal("1.50")` | a decimal, with its scale | `VcDecimal` | -| `VcUuid("..")` | refused for now, with `recipher_js::uuid` | | -| `null` | null | `null`. In a record, only where the field declares `null` | +| `RcTimestamp.from("2026-11-23T01:02:03.000000001Z")` | a timestamp, in nanoseconds | `Date` when it is whole milliseconds, else `RcTimestamp` | +| `RcDate.from("2026-11-23")` | a calendar date | `RcDate` | +| `RcDecimal.from("1.50")` | a decimal, with its scale | `RcDecimal` | +| `RcUuid.from("..")` | a universally unique identifier (UUID), from #1996, as a value or a record field | `RcUuid` | +| `null` | a typed null, with `nullable(kind)` of a fixed-width kind | `null`, with `nullable(kind)`. In a record, only where the field declares `null` | - **Integers are a `bigint`.** A `number` is a float, and `5` does not match the integer `5n` in a query. Integer data uses `bigint`. - **An integer's width is not chosen.** The bridge stores a `bigint` at the narrowest width that holds it. Equality terms are the same across widths, so `5n` here matches an `int64` 5 from Go. -- **A UUID waits on the engine.** vitaminc's value model has a UUID - type, and the bridge reads a `VcUuid` into it. The engine's dynamic - value model, the types a frame may hold in `dynamic::ValueFrame`, has - no UUID, so the SDK refuses one until the engine adds it (#1821). +- **A UUID is an `RcUuid`.** Stack Encrypt's dynamic value model has a UUID + kind, `ValueKind::Uuid` (#1929). A UUID field takes an equality index + only. The SDK encrypts an `RcUuid` as that kind from #1996, as a value + on its own or in a record field declared `kinds.uuid`. A decrypted + `RcUuid` contains lowercase hyphenated hex. A string that contains a + UUID is encrypted as text. Until #1996 merges, the SDK refuses an + `RcUuid` with `recipher_js::uuid`. +- **A null is asked for, as with Rust's `Option`.** A plain kind, such as + `kinds.int64`, reads as `bigint`, and a stored null is an `Err` with + `recipher_js::opened_null`. `nullable(kinds.int64)` reads as + `bigint | null`. To encrypt a null, a caller gives `nullable(..)` of a + fixed-width kind: `keyset.encrypt(null, { kind: nullable(kinds.int64) })`. + Stack Encrypt refuses that until it seals typed nulls (#2023). A lone `null` + with no kind is refused with `recipher_js::null_value`. - **No precision is lost.** A timestamp finer than a millisecond opens as - a `VcTimestamp`, never as a rounded `Date`. -- **The wrapper classes are the bridge's.** Each holds its text, such as - `new VcDecimal("1.50")`, and is frozen. The core package re-exports the - four the addon defines. + an `RcTimestamp`, never as a rounded `Date`. +- **The wrapper classes are the bridge's.** Each is made with `from`, such + as `RcDecimal.from("1.50")`. `from` checks the text and returns a + `Result`. Each instance holds its text and is frozen. The classes have + no public constructor. The core package re-exports the + four the binding defines. The classes were renamed in #1775 to + `RcDate`, `RcTimestamp`, `RcDecimal`, and `RcUuid`. vitaminc's own + bridge names them `VcDate`, `VcTimestamp`, `VcDecimal`, and `VcUuid`. - **The bridge's safety rules apply.** Only a plain object is read, by its own enumerable string keys. A `Map`, a `Set`, a class instance, a sparse - array and a string with an unpaired surrogate are refused. Nesting is - limited to 128 levels. A polluted prototype cannot add a key or see a - decrypted value. + array and a string with an unpaired surrogate are refused. A polluted + prototype cannot add a key or see a decrypted value. +- **Nesting has two limits.** Both count levels the same way. The top + value is level 0, and each array or object puts its items one level + further down. So in `[[1]]`, the `1` is two levels down. + - The bridge reads no value more than 128 levels down. That is the + frame's limit. + - A JSON document has no array or object more than 126 levels down, + counted from the document's own top. So at most 127 arrays and + objects nest inside one another, and a scalar can be 127 levels + down. Stack Encrypt's JSON parser reads no deeper. #1775 checks this + limit when `json(..)` reads the document, and refuses a deeper one + with `recipher_js::too_deep`. + - A `Json` never sits inside a value tree. In #1775, `encrypt` takes a + `Json` as one value, or as one item of an array of values. Each item + is read from level 0. A `Json` anywhere deeper is refused. So only + the document's own limit applies to a document. - **A failed conversion is an `Err`.** The bridge reports which rule a value broke as a typed refusal, a diagnostic with a `recipher_js::` code, such as `recipher_js::not_plain` or `recipher_js::too_deep`. A scalar out of @@ -625,12 +736,19 @@ each kind is the one in the table, so an integer field is a `bigint`, at every width. A `number` in an integer field does not compile. **Integers in an adapter.** An ORM such as Drizzle gives an integer column -as a `number`. The adapter converts, because it knows the column's type: a -`number` that is a safe integer becomes a `bigint` on the way in, and a -`bigint` becomes a `number` on the way out. An unsafe integer is refused. +as a `number`. The adapter converts, because the adapter has the column's +type. The column's TypeScript type is `number | bigint`. + +- On the way in, a `number` that is a safe integer becomes a `bigint`. A + `bigint` is accepted as it is. A whole `number` outside the safe range + is refused, because it may have lost digits. +- On the way out, an integer within 2^53 - 1 of zero becomes a `number`. + A larger integer comes back as a `bigint`. So the adapter can read every + stored row, such as an `int64` above 2^53 that Go wrote. + The core has one mapping, and it is the bridge's. -**The wasm build.** The value bridge is for Node addons only. The wasm +**The wasm build.** The value bridge is for Node bindings only. The wasm build needs the same mapping over `wasm-bindgen`'s `JsValue`, with the same wrapper classes and the same refusals. It belongs beside the napi bridge, in `recipher-js`. cipherstash/vitaminc#632 asked for it in vitaminc, and @@ -641,11 +759,31 @@ value conformance cases (`value-napi/tests/value-conformance.cjs`). **JSON documents.** `json(value)` encrypts a JSON document, for a `json` field or an EQL `Json` type. A JavaScript `number` cannot hold every integer a JSON document can. So an integer outside the safe range is a -`bigint` in the tree. On encrypt, a `number` that is an unsafe integer is -refused, and a `bigint` is written as its digits. On decrypt, an integer -outside the safe range comes back as a `bigint`. The conversion is in Rust, -and the engine's one parser reads the result. The `eql-json-v1` case that -holds `18446744073709551615` round-trips on both builds. +`bigint` in the tree. + +On encrypt, #1775 stores a whole number in a document by these rules. +Each range includes both ends. + +| The whole number | As a `number` | As a `bigint` | +|---|---|---| +| -(2^53 - 1) to 2^53 - 1 | an integer | an integer | +| 2^53 to 2^64 - 1 | refused, and the refusal asks for a `bigint` | an integer | +| -2^63 to -2^53 | refused, and the refusal asks for a `bigint` | an integer | +| -(2^64 - 1) to -(2^63 + 1) | refused: no exact form in a document | refused | +| 2^64 or more, or -2^64 or less | a float, such as `1e20` or `-1e20` | refused | + +A whole `number` outside the safe range may have lost digits, so the +refusal asks for a `bigint` where one fits. Below -2^63 no `bigint` +fits, so the refusal says the integer has no exact form. A `number` with +a fraction is a float. `NaN` and the infinities are refused. + +On decrypt, an integer outside the safe range comes back as a `bigint`. +The conversion is in Rust, and Stack Encrypt's one parser reads the result. +On the native build, a test in #1775 (`__tests__/addon/values.test.ts`, +"keeps an integer outside the safe range as a bigint") round-trips +2^64 - 1. The wasm build is not built yet. The plan is for the wasm build +to pass the same test, and the `eql-json-v1` case that contains +`18446744073709551615`. The value profile of the conformance suite (`record-values-v1`) is the contract for the record kinds. Its cases include every kind at its edges @@ -654,7 +792,7 @@ and the conversions the host refuses. ## The EQL extension `@cipherstash/eql/recipher` adds one thing to the core: a field that is -stored as an EQL v4 type. In the engine's words, the field names a target. +stored as an EQL v4 type. In Stack Encrypt's words, the field names a target. In Go it is the `encrypt_into=` tag. ```ts @@ -669,24 +807,24 @@ export const users = record("users", { profile: types.JsonSearch({ ordered: ["$.score"] }), }); -const cipher = (await Cipher.create({ extensions: [eql], records: [users] })).unwrap(); +const cipher = await Cipher.create({ extensions: [eql], records: [users] }).unwrap(); const keyset = cipher.defaultKeyset(); -const stored = await keyset.encrypt(users, rows); +const stored = await keyset.encrypt(rows, { record: users }).unwrap(); const byEmail = await keyset.query(users, { field: "email", op: "eq", value: "ada@example.com" }); ``` - **The same declaration and the same calls.** An EQL type goes where - `encrypt(..)` goes in a record. `encrypt`, `query`, `decrypt`, - `encryptField` and `decryptField` are the core's. The extension adds no + `encrypt(..)` goes in a record. `encrypt`, `query`, and `decrypt` + are the core's. The extension adds no call of its own for a scalar type. - **A record is a table, and a field is a column.** The record's name is the table's name and the field's name is the column's name. EQL stores both in the value. - **A field is plain verbs or one EQL type, never both.** A record can mix - the two kinds of field, as an engine plan can. + the two kinds of field, as a Stack Encrypt plan can. - **The stored field is EQL v4 JSON**, ready for a SQL parameter. A query - term carries the SQL domain it binds as (`term.domain`), as the engine's + term carries the SQL domain it binds as (`term.domain`), as Stack Encrypt's `QueryTerm` does, so an adapter writes the cast without a table of its own. - **The types come from the EQL catalog.** `eql-codegen` writes the Go @@ -723,12 +861,12 @@ const byEmail = await keyset.query(users, { field: "email", op: "eq", value: "ad - **Keysets.** `cipher.defaultKeyset()` is the keyset a ZeroKMS administrator set for the client. `cipher.keyset(name)` is any other, loaded on first use. -- **Audit metadata.** `.audit({ ... })` on `encrypt`, `encryptField`, - `decrypt`, `decryptField` and `openJson`. A date and time in it is sent +- **Audit metadata.** `.audit({ ... })` on `encrypt`, `decrypt`, + and `openJson`. A date and time in it is sent as RFC 3339 text in UTC, the form every SDK sends. A query has no data-key request, so it has no `.audit`. - **Testing without ZeroKMS.** `@cipherstash/recipher/testing` builds a - cipher over the engine's deterministic test keys, with no credentials and + cipher over Stack Encrypt's deterministic test keys, with no credentials and no network, as Go's `encrypttest.NewClient` does. ## Results and errors @@ -751,6 +889,12 @@ if (sealed.isOk()) { // Or combine it. const bytes = sealed.map((ciphertext) => ciphertext.toBytes()).unwrapOr(null); + +// Or combine it before the await, on the pending result. +const stored = await keyset + .encrypt("a secret message") + .map((ciphertext) => ciphertext.toBytes()) + .unwrapOr(null); ``` - **The methods are Rust's `Result` methods,** in camelCase: `isOk`, @@ -759,27 +903,45 @@ const bytes = sealed.map((ciphertext) => ciphertext.toBytes()).unwrapOr(null); what Rust's does. `unwrap()` and `expect(..)` are the only functions that throw, as they are the only ones that panic in Rust. They are for a script, a test or a startup path. +- **An async call returns a pending result (#2026).** It is a thenable, + not a `Promise`. It has the methods that set up the call (`.audit`, + `.withCredential`, `.signal`, and in phase 2 `.withContext` and + `.partition`). It also has the `Result` methods that need no value + before it arrives: `map`, `mapErr`, `andThen`, `orElse`, `unwrap`, + `unwrapOr`, `expect`, and `match`. So `await x.unwrap()` needs no + parentheses. The setup methods come first, because a `Result` method + starts the call. `isOk` and `isErr` are left out, because the value + has not arrived. +- **Awaiting a pending result never rejects.** `await x` gives a `Result`. + Only `unwrap` and `expect` reject, on an `Err`, as they throw on a + `Result`. +- **The binding returns the pending result itself.** No TypeScript code + wraps a native method. The package's TypeScript hands the binding the + pending-result class when it loads the binding, as it hands over `Ok` + and `Err`. +- **A call that does not wait returns a plain `Result`:** + `Ciphertext.fromBytes`, `RcDate.from`, and the other factories. - **`Result` is the core's own type**, with no dependency, so it can stay as close to Rust's as TypeScript allows. `Ok` and `Err` are its two cases, and `isOk()` narrows the type as a Rust `match` does. -- **An error is the engine's diagnostic, as a value.** The engine's errors +- **An error is Stack Encrypt's diagnostic, as a value.** Stack Encrypt's errors are miette diagnostics, and a `RecipherError` carries all of one, as the Go SDK's `Diagnostic` does: the stable `code` (`stack_encrypt::aead`), the one-line `message`, the `help`, the `url` of its documentation page, the `severity`, the structured `fields` (a refusal's `reason` among them), and the `causes` behind it. `field` and `record` name the field and the record - at fault, which the SDK knows where the engine does not. A cause from another library is - named as one and its message is never copied. The engine sets no `url` + at fault, which the SDK knows where Stack Encrypt does not. A cause from another library is + named as one and its message is never copied. Stack Encrypt sets no `url` yet (#1790); the property shows the link when it does. - **The SDK adds nothing of its own to an error's description.** A caller switches on `code`. There is no coarser grouping that the SDK invents: a grouping the SDK made up would have to be kept in step with every - engine error, in every language. The SDK's own errors (a value that is + Stack Encrypt error, in every language. The SDK's own errors (a value that is not a record, a build that did not load) are diagnostics too, declared - the way the engine declares its own, with codes under `recipher_js::`, - named after the crate as the engine's are, so that no SDK code can clash - with an engine code when the engine takes the name `recipher`. The + the way Stack Encrypt declares its own, with codes under `recipher_js::`, + named after the crate as Stack Encrypt's are, so that no SDK code can clash + with a Stack Encrypt code when Stack Encrypt takes the name `recipher`. The value bridge says which rule a refused value broke as a typed value, so nothing reads the wording of a message. - **Nothing else escapes as an exception.** A failure in the binding, @@ -813,7 +975,7 @@ can check, and the README says so. ## Promises and cancellation - Every operation returns a `Promise` of a `Result`, which never rejects. - napi-rs runs the engine's future on its tokio runtime. The wasm build + napi-rs runs Stack Encrypt's future on its tokio runtime. The wasm build runs it through `wasm-bindgen-futures`, and ZeroKMS requests go out through the runtime's `fetch`. - A call takes an `AbortSignal`. Aborting drops the future, which wipes what @@ -839,7 +1001,8 @@ they cannot read. - **Batches.** Drizzle's batched query terms map to `keyset.query`. Supabase's model encryption maps to `keyset.encrypt` and `cipher.decrypt`. Prisma Next's middleware encrypts and decrypts column - by column, which maps to `encryptField` and `decryptField`. + by column, which maps to `keyset.encrypt` and `cipher.decrypt` with + `{ record, field }`. - **SQL.** Each adapter writes EQL v3 SQL today: `eql_v3` operators and casts, and Prisma Next's baseline migration installs the v3 bundle. Each moves to the EQL v4 functions and query domains, taking the cast from the @@ -863,8 +1026,8 @@ they cannot read. ## Room for EQL v3 and v2 -`recipher-compat` is planned to read and write EQL v3 and v2 on the same -engine. In TypeScript it arrives as another extension, beside +`recipher-compat` is planned to read and write EQL v3 and v2 on Stack +Encrypt too. In TypeScript it arrives as another extension, beside `@cipherstash/eql/recipher`, with no new call shape. So this plan holds to three rules: @@ -890,8 +1053,8 @@ these rules are checked then. `conformance/stack-encrypt/v1`, against both the napi build and the wasm build (#1479). The core package runs the profiles that name no EQL type. `@cipherstash/eql` runs `eql-json-v1`. Phase 1 runs the cases that take no - context from the caller. Phase 2 adds the context profiles, as the - engine rewrites them for named parts. Today they are + context from the caller. Phase 2 adds the context profiles, as Stack + Encrypt rewrites them for named parts. Today they are `record-contexts-v1`, `record-context-boundaries-v1` and `record-bindings-v1`. A case a phase skips is listed as not run, never as passed. The exchange profile enrols TypeScript in @@ -931,22 +1094,22 @@ these rules are checked then. The packages follow `@cipherstash/auth`: -- `release.yml` builds the six platform addons and the wasm build of each +- `release.yml` builds the six platform bindings and the wasm build of each package, and publishes the platform packages before the wrapper, as `publish-auth` does. npm trusted publishing is set up for each package, bound to `release.yml`. - `@cipherstash/eql` keeps EQL's version, which its SQL bundle, its docs, its image and the `eql-bindings` crate share. Its release gains the six - platform addons and the wasm build of the extension. A change to EQL's + platform bindings and the wasm build of the extension. A change to EQL's SQL and the bindings for it ship together, in one EQL release. - `@cipherstash/recipher` has its own version. An EQL release is built - against one engine, and works with every core version that has the same + against one version of Stack Encrypt, and works with every core version that has the same binding interface number. The peer dependency of `@cipherstash/eql` names that range. A new EQL release is needed for the core only when the interface number changes. - Each package gets a changeset like any other workspace package. - The crates depend on `stack-encrypt` and `eql-bindings` by path, so one - release carries the engine of its own commit. Each package names that + release carries Stack Encrypt of its own commit. Each package names that commit in an `engineCommit` export, for a bug report. ## Documentation and skills @@ -972,18 +1135,23 @@ The core, with no EQL: 1. **Walking skeleton.** The crate, its generated types and the core npm package. `Cipher.create`, `Result`, and plain `encrypt` and `decrypt` of one - `string` value on Node, with no context. CI builds it on Linux. Proves that the engine's futures run on + `string` value on Node, with no context. CI builds it on Linux. Proves that Stack Encrypt's futures run on napi-rs's runtime. Adds the test that the crate links no `eql-bindings`. -2. **Values.** The value bridge for every type in the table above, - the wrapper classes, an array of values, - `bytes` for a file, the value profile and the fuzz target. `opaque` - for a whole object follows the storage-blob converter (#1822), and - the UUID type the engine's (#1821). -3. **Records.** `record`, `encrypt`, `passthrough`, nulls, the stored row - type, `encryptField` and `decryptField`, the type tests, and the - declaration, runtime and read profiles. This step is the first to call - `Planned`. +2. **Values.** The value bridge for every type in the table above + except `RcUuid`. The wrapper classes, an array of values, `bytes` for + a file, the value profile, and the fuzz target. `opaque` for a whole + object follows the storage-blob converter (#1822). #1996 adds + `RcUuid` after step 3, over Stack Encrypt's UUID kind (#1929). A + `RcUuid` then encrypts as a value on its own, with no record. The + pull request comes after step 3 so that its tests can also store a + UUID record field. +3. **Records.** `record`, `encrypt`, `passthrough`, nulls, the encrypted + row's type, the type tests, and the declaration, runtime, and read + profiles. This step is the first to call `dynamic::record::plan` and + `Planned`. One field with `{ record, field }` comes later, when Stack + Encrypt has a call for it (#2028). The pending result (#2026) follows + the records, and changes every async call before search terms add more. 4. **Search terms.** The indexes, `query`, every operator, match `verify` and `targetLimit` with the default match options, and the scalar and query-refusal profiles. @@ -1012,21 +1180,21 @@ with no caller context, on Node and on wasm, and that anyone can install as a pre-release. Each README says that a pre-release makes no promise that a later version opens its stored values. -### Phase 2: when the engine has named parts +### Phase 2: when Stack Encrypt has named parts 11. **Labels and partitions.** The built-in parts, `keyset.with(..)`, a part declared on a record and on a field, `.partition(..)`, custom labels and partitions, `.withContext` on a value, and the context profiles. 12. **Policies.** `forSub`, `forTenant`, `notBefore` and `notAfter`, each - when the engine and ZeroKMS have it, with a live test of a refused + when Stack Encrypt and ZeroKMS have it, with a live test of a refused reader. Each phase 2 step is published as a pre-release too. ### Phase 3: after the issues that change stored bytes -13. **Catch up with the engine.** Match options (#1673), refinements +13. **Catch up with Stack Encrypt.** Match options (#1673), refinements (#1567), the plan checked against the JSON Schemas (#1678), and any rename from #1489 not yet taken. 14. **Stored rows.** The frozen stored-rows file. @@ -1061,20 +1229,20 @@ Decided on 2026-11-23: - Calls return a `Result` and never throw. `Result` is the core's own type, with Rust's methods. - Phase 1 ends with a pre-release on npm. -- Two Rust crates, the addon and the value bridge, until the wasm build - needs more. +- The SDK has two Rust crates until the wasm build needs more. The two + are the language binding and the value bridge. - Rust defines the classes and napi-rs generates their types. TypeScript keeps `Result` and the declaration types. (The typed signatures moved into Rust's `ts_type` attributes on 2026-11-25.) -- A context follows ADR-0016: policies, labels and partitions, with the - engine's wire names. Parts attach to the keyset with `with(..)`. +- A context follows ADR-0016: policies, labels and partitions, with Stack + Encrypt's wire names. Parts attach to the keyset with `with(..)`. Decided on 2026-11-25: - The value bridge is `recipher-value-napi`, an unpublished crate in this repository, copied from vitaminc's `vitaminc-aead-napi`. Its refusals are typed diagnostics. -- An error is the engine's whole diagnostic: `code`, `message`, `help`, +- An error is Stack Encrypt's whole diagnostic: `code`, `message`, `help`, `url`, `severity`, `fields` and `causes`, with `field` and `record` added by the SDK. A refusal's reason is in `fields`. - An error has no `kind`. A caller switches on `code`, as in every @@ -1087,6 +1255,18 @@ Decided on 2026-11-25: each native method, and the hand-written interfaces that typed it, are gone. +Decided on 2026-11-29: + +- The language binding is thin. `record()` writes Stack Encrypt's plan, + and the binding reads it and calls `dynamic`. A gap is fixed in Stack + Encrypt. The rules are in [What it is](#what-it-is). +- Stack Encrypt's names for a plan's outputs are used as they are. An + alias is a change to Stack Encrypt's plan. +- A record's field can name an EQL type, through the plan's `target`. The + EQL types are optional, and `@cipherstash/eql` defines them. The design + is in [The EQL extension](#the-eql-extension). The record pull request + does not include them. + ## What was checked Run on 2026-11-22, on `next` at `38db57856`: @@ -1127,14 +1307,14 @@ Read on 2026-11-23, on `next` at `e62420d8e`: - Of the conformance case files, only `record-bindings-v1` names a scope or a binding; `record-declarations-v1` and `record-reads-v1` have cases that name a context field. -- The engine separates the EQL types from itself. A plan field is plain +- Stack Encrypt separates the EQL types from itself. A plan field is plain outputs (`"outputs": ["c", "eq"]`) or one named target. A `TargetResolver` that the host links in runs a named target, and `NoTargets` is the build without one (`packages/stack-encrypt/src/dynamic/mod.rs`). `eql-bindings`' `targets` feature is the resolver for the EQL types. Go's `encrypt/eql` embeds a second guest build with them. -- The engine's documentation order: a scalar, a context, credentials, a +- Stack Encrypt's documentation order: a scalar, a context, credentials, a whole value as one ciphertext (`OpaqueBlob`, `src/blob.rs`), then records (`packages/stack-encrypt/src/lib.rs` and `examples/`). - A whole value is sealed outside `dynamic`: a `ValueFrame` implements @@ -1159,10 +1339,10 @@ Read on 2026-11-23, in PR #1772 at `docs/adr-context-parts`: Read on 2026-11-23, in `cipherstash/vitaminc` at `222f1ad39`: - `packages/aead-napi` (`vitaminc-aead-napi`) is a Rust library for a Node - addon, on napi-rs 3. It is not an npm package and not a wasm binding. It + binding, on napi-rs 3. It is not an npm package and not a wasm binding. It supplies `JsRef`, `JsBuilder`, `JsCipherText` and `Wrappers`, and its README holds the mapping and the safety rules this plan repeats. -- Its test addon (`tests/addon/src/lib.rs`) exports the wrapper classes +- Its test binding (`tests/addon/src/lib.rs`) exports the wrapper classes and seals a frame from `JsRef::to_frame` in an `AsyncTask`. - vitaminc has no `wasm-bindgen` counterpart to it. Its other bindings are for Go: `bindings/go/vcffi` (the transport codec into a wasm guest), @@ -1171,19 +1351,28 @@ Read on 2026-11-23, in `cipherstash/vitaminc` at `222f1ad39`: Found by steps 1 to 3, in #1774 at `872ff2ea2`, #1775 at `30f1d26fd` and #1776 at `17a20ffa8`: -- The engine's pending calls are `Send`. The addon runs them with napi's +- Stack Encrypt's pending calls are `Send`. The binding runs them with napi's `spawn_future_with_callback`, which requires it, for a value and for a `Planned` call (`crate/src/cipher.rs`). -- The value bridge builds against the vitaminc 0.10.0 crates the engine +- The value bridge builds against the vitaminc 0.10.0 crates Stack Encrypt resolves. - An `OpaqueBlob` is its storage blob sealed as a bytes value: it decrypts as a `Vec` holding the blob, and the blob encrypted as bytes decrypts as the `OpaqueBlob`. So a binding reaches the format by writing the blob itself. See [A file, and a whole object](#a-file-and-a-whole-object). -- The engine's dynamic value model has no UUID. See [Values](#values). -- The engine opens one field of a stored row without the row's other - fields: `decryptField` runs the plan of that field alone, and a field - encrypted alone has the same bytes as in a whole row. +- Stack Encrypt's dynamic value model had no UUID at those commits. The + model has one now (#1929). #1996 makes the binding use it. See + [Values](#values). +- Stack Encrypt reads a plan from a frame (`dynamic::record::plan`), and + the Go guest calls it (`languages/golang/encrypt/guest/src/ops.rs`). +- Stack Encrypt refuses a row with a field that the plan does not name. + It also refuses a row that lacks a field, unless the field stores a + null as SQL `NULL` (`source_row` in `dynamic/record.rs`). So no call + encrypts one field of a plan. Stack Encrypt converts each value to its field's kind + (`check_field`, in the same file). +- The encrypted tree has no serde. `CipherText` in + `packages/vitaminc-aead/src/container.rs` derives none, and + `SealedValue`, the leaf, does. - A sealed scalar's bytes name its type, so it decrypts as what it was encrypted as with no type named. A JSON document's bytes do not say it is JSON: with no kind it decrypts as its JSON text, and @@ -1199,5 +1388,5 @@ Not checked: install for the SQL entries alone downloads no native build. - How a prerelease of `@cipherstash/eql` carries the extension while the package is at an EQL v3 version. -- napi-rs addons under Bun and Deno. +- napi-rs bindings under Bun and Deno. - Whether PostgREST can write the EQL v4 query domains.