From 36bb7df90aec361a943c4f216d939e471ddab98e Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Wed, 25 Nov 2026 23:17:07 +1100 Subject: [PATCH 1/3] docs(stack-encrypt): the value model, nulls, opaque values and error codes in the integration guide A binding author could not learn four things from the guide that every binding meets: which types the engine accepts, that vitaminc decides whether a null is padded and the type for it comes from the plan, that an opaque value is a storage blob in a format separate from the frame, and how a binding names its own error codes beside the engine's. Each was worked out once for Go and again for TypeScript. --- .../docs/language-integration.md | 125 +++++++++++++++++- 1 file changed, 124 insertions(+), 1 deletion(-) diff --git a/packages/stack-encrypt/docs/language-integration.md b/packages/stack-encrypt/docs/language-integration.md index cecf965c5..075bc0e01 100644 --- a/packages/stack-encrypt/docs/language-integration.md +++ b/packages/stack-encrypt/docs/language-integration.md @@ -373,6 +373,103 @@ engine does. Rust. The Go SDK's is in `languages/golang/internal/guest`. It targets one version of the frame format and says which. +### The value model + +A frame can carry more types than the engine accepts. The engine accepts +the *value model*: + +- null and `undefined`, booleans, and integers of every width from `i8` + to `u128`, each kept at its own width; +- both floats, text and bytes; +- three of vitaminc's logical types: a date, a decimal (its scale kept) + and a timestamp, read in nanoseconds whatever unit it arrives in; +- arrays, maps and passthroughs of these. + +A UUID is refused, although vitaminc has a UUID type. So is a logical type +the engine does not know, and a date, decimal or timestamp outside +vitaminc's range. [`crate::dynamic::ValueFrame#the-value-model`] holds the +rule, and [`crate::dynamic::ValueFrame::from_bytes`] refuses a frame that +breaks it. + +Map your language's types onto this list, and refuse anything else before +it reaches the engine, with an error that names the field and the type. A +plan's field types ([`crate::dynamic::ValueKind`], section 4) are the same +list. + +### Nulls + +Whether a null is padded is vitaminc's rule, and the engine follows it: + +- **A null of a fixed-width type** (a boolean, a number, a date, a + timestamp or a decimal) is a *typed null*. It is padded to the length of + a value of that type, so once sealed it cannot be told from a value by + its length. +- **A null of a variable-width type** (text, bytes) is a plain null. There + is no length to pad it to. + +The padding needs the type, and a frame does not carry it: a typed null in +a frame handed over by a host reads as a plain null +([`crate::dynamic::ValueFrame::from_bytes`]). So the type comes from the +plan. A field declared with a fixed-width type and `"null": "sealed"` +seals its nulls padded. A field with `"null": "sql"` stores nothing, and +the host's column holds SQL `NULL`, which shows that the value is absent. +[`crate::dynamic::NullMode`] has the rules. + +Do not decide padding in your SDK. Pass the field's null mode in the plan, +and let the engine apply vitaminc's rule. + +### A whole object as one value + +An *opaque* value is a whole object sealed as one ciphertext, with nothing +inside it searchable. In Rust it is [`crate::OpaqueBlob`]. In the Go SDK it +is an opaque struct. + +An opaque value is not a frame. It is a *storage blob*: vitaminc's storage +profile, a separate format specified in +[`vitaminc_aead_frame::storage`](https://docs.rs/vitaminc-aead-frame/0.10.0/vitaminc_aead_frame/storage/index.html) +and the crate's `STORAGE.md`. The blob is sealed as an ordinary bytes +value. A ciphertext of an `OpaqueBlob` decrypts as the bytes of its blob, +and those bytes encrypted as bytes decrypt as the `OpaqueBlob`. So every +language that writes the same blob writes the same ciphertext. + +Three formats are involved, and they are easy to confuse: + +| Format | What it holds | Stored? | +|---|---|---| +| Sealed leaf | One scalar or record field, inside the encryption | Yes, and frozen | +| Frame | One value crossing between a host and the engine | No: it can change in any release | +| Storage blob | One whole object, written before it is sealed as bytes | Yes, and frozen at version 1 | + +The storage profile shares the frame's scalar encodings and its array and +object layout, and differs in four ways: + +- it starts with a header, `"VCS"` and a version byte; +- it marks a present optional value, so `None` and `Some(None)` differ; +- its map keys keep their type, where a frame's object keys are text; +- version 1 holds plain scalars only. A date, a timestamp, a decimal, a + UUID, `undefined` and a passthrough have no storage form and are + refused. + +So a blob is written from your language's value, not converted from the +frame the engine sees. Rust writes it with `storage::to_vec` from a type's +serde `Serialize`. The Go SDK writes it with `vcffi.MarshalStorage` and +seals it as the one field of a record +(`languages/golang/encrypt/gensupport/codec.go`). + +A value with no storage form is either refused or written as a plain +type, and each language must say which: + +- Go refuses its logical-type values, such as `encrypt.Date` and + `encrypt.Decimal`, and a passthrough, with `vcffi.ErrUnwritable`. +- Go writes a type that formats itself as text, such as `time.Time`, as + text: RFC 3339. A timestamp in an opaque struct therefore opens as text, + not as a timestamp. +- Rust writes whatever a type's `Serialize` writes in a compact format: a + `uuid::Uuid` is its 16 bytes. + +Whichever rule you choose, write it down, and make a refusal name the +field. + ## 6. Plaintext hygiene The engine's rule is that plaintext lives in one place, for as long as the @@ -590,6 +687,26 @@ for a native extension's exceptions: a refused credential, a wrong keyset and a tampered value are different failures, and a caller acts on each differently. +**Codes.** A caller branches on an error's code, so codes are kept stable +and apart: + +- **Pass the engine's codes on unchanged.** An engine error keeps its own + code (`stack_encrypt::aead`), help, fields and causes. Do not map engine + errors onto codes of your own, or group them into coarser kinds: a + grouping would have to be kept in step with every engine error. +- **Name your own codes after your binding's crate.** An error that only + your SDK raises, such as a value your language cannot convert, gets a + code under its crate's name, never under the engine's: a crate + `example_binding` raises `example_binding::not_a_string`. Then no code + of yours can clash with one the engine adds later. +- **Report a refused value as a typed error.** When your conversion + refuses a value, say which rule it broke as a value with a code. Never + make a caller, or your own SDK, read the wording of a message. + +How an error reaches a caller is your language's choice: an exception, a +`Result`, or an `error` value as in Go. The codes are the same in every +shape. + **Never a value.** No error, warning or log line holds a plaintext value, a key, a token, a ciphertext or a context value. The guest's configuration parser names the key at fault and never its value, because the value may be @@ -843,7 +960,13 @@ done: 5. **A stored-rows fixture exists and is frozen** (section 9): rows your binding wrote with its first release, opened on every build and never regenerated. -6. **The versions are tied.** The engine version, the frame-format version +6. **Your type mapping is written down and tested.** Each of your + language's types maps onto the value model (section 5) or is refused + with a typed error. A null of a fixed-width field is sealed through the + plan's null mode, not padded by your SDK. An opaque value is written in + the storage profile, and a blob your SDK writes opens in Rust and Go, and + theirs in yours. +7. **The versions are tied.** The engine version, the frame-format version and your binding's version move together, and a reader of your release notes can tell which engine a release carries. From 800c9eb630c4914272d3a081ed0dbb51a4640250 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Mon, 30 Nov 2026 00:09:18 +1100 Subject: [PATCH 2/3] docs(stack-encrypt): a language binding is thin, and the guide says Stack Encrypt The guide and AGENTS.md now name the crate Stack Encrypt, not "the engine", and the Rust layer of an SDK a language binding. Section 1 of the guide gains the rules for a thin binding: send Stack Encrypt's plan as it is, let Stack Encrypt check each row, keep its names, and fix a gap in Stack Encrypt. The checklist gains the same item, and AGENTS.md points to the section. Merging next showed that the value model and null sections were stale: ValueFrame is gone, a UUID is in the value model, an unknown logical type is stored as it arrived in an untyped field, and a host's frame can carry a typed null. Those passages now say so. --- AGENTS.md | 24 +- .../docs/language-integration.md | 240 ++++++++++-------- 2 files changed, 158 insertions(+), 106 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 116fd54ef..97b86f899 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -93,7 +93,7 @@ Every npm package except EQL lives under `languages/typescript/`: packages in `l - `packages/stack-auth`, `packages/stack-profile`, `packages/stack-kms`, `packages/stack-encrypt`, `packages/stack-encrypt-derive`, `packages/stack-encrypt-jsonpath`, `packages/stack-guest-abi`: The Rust crates imported from `cipherstash/cipherstash-suite` with their history, and one added here — `stack-auth` and `stack-profile` (published to crates.io, one version group), `stack-kms` (published to crates.io from 0.1.0, its own version group, re-exported by `stack-encrypt` as `stack_encrypt::kms`), `stack-encrypt` and `stack-encrypt-derive` (published to crates.io from 0.1.0, one version group; `eql-bindings`' `stack-encrypt` feature depends on them from the registry), `stack-encrypt-jsonpath` (the JSONPath grammar of the JSON index and the SQL/JSON path predicate grammar its `match` operator reads, moved out of `stack-encrypt` so the derive can check a field's declared paths, and `predicate!` a predicate's text, at compile time; in the `stack-encrypt` version group, re-exported at `stack_encrypt::json`; its first version is published by hand, as the others' were, before Trusted Publishing can take it), and `stack-guest-abi` (`publish = false`). They are the members of the **root Cargo workspace**, with the three AEAD crates and the three node binding crates below. See "Working on the Rust crates". - `packages/vitaminc-aead`, `packages/recipher-frame`, `packages/vitaminc-aead-derive`: vitaminc's AEAD crates, imported from `cipherstash/vitaminc` with their history at the code of their crates.io 0.10.0 release (`docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md`). They define the value types Stack Encrypt seals, the transport frame and storage profile (`recipher-frame`, whose storage corpus is `testdata/storage-v1.json`), and the derive macros. `vitaminc-aead` and `vitaminc-aead-derive` keep their crates.io names, because vitaminc crates that stay on crates.io depend on `vitaminc-aead`; the frame crate was `vitaminc-aead-frame` and is now `recipher-frame`, since only crates here depend on it. All three keep the MIT licence, are members of the root workspace, and are `publish = false` with `release = false` in `release-plz.toml`: crates.io's 0.10.0 was published from vitaminc, and they publish from here only before the next `stack-encrypt` release. Every Cargo workspace that resolves `vitaminc-aead` carries a `[patch.crates-io]` table pointing at these copies (see "Working on the Rust crates"). The cross-language value conformance corpus their tests read is `conformance/vitaminc-aead/value-conformance.json`. vitaminc's checks on them run here: the storage corpus append-only check (`storage-corpus.yml`), the Kani proofs of the storage reader (`kani.yml`), `cargo deny` and `cargo vet` over their dependency graph only (`supply-chain-vitaminc-aead.yml`, config in `supply-chain/vitaminc-aead/`; the rest of the workspace is #1842), and mutation testing (`mutants.yml`). See "Working on the Rust crates". - `languages/typescript/packages/auth`, `languages/typescript/packages/profile`, `languages/typescript/packages/stack-auth-wasm`: The node bindings of those crates. `@cipherstash/auth` (napi-rs v2) and its six `platforms/*` packages are published to npm from this repository by `release.yml` (`auth-artifacts`, `publish-auth`); a change to what it ships, the `stack-auth` crate included, needs an `@cipherstash/auth` changeset (`require-auth-npm-changeset.yml`). `@cipherstash/profile` and its platforms are private and never published; `@cipherstash/stack-auth-wasm` is private and builds the wasm that `@cipherstash/auth` ships. Their `build` and `test` scripts never invoke cargo; `build:native`, `build:debug` and `test:cargo` do. `@cipherstash/auth` also ships two pure-JS framework adapters over the wasm `OidcFederationStrategy`: `./next` (Next.js App Router, hands the token to the render on a request header) and `./start` (TanStack Start: `csFederateCurrent` is called inside a function middleware the app declares itself, which hands the token to the server function through `next({ context })`; `@tanstack/react-start` is an optional peer loaded only by that entry). -- `languages/typescript/packages/recipher-js`: `@cipherstash/recipher`, the TypeScript SDK on the Stack Encrypt engine (design: `docs/plans/2026-11-22-recipher-typescript-sdk.md`). **Private and unpublished**: it has no platform packages and no release job yet, so it must stay `"private": true` (a public manifest would be published by `changeset publish` on merge) and takes no changeset. Its Rust is **two crates** in a **detached Cargo workspace** with its own `Cargo.lock`. The root workspace names its members, so it needs no `exclude` entry there; leave the root `Cargo.toml` alone, because a change to it starts every stack-* crate workflow. The two crates: `crate/` (crate `recipher-js`, napi-rs 3), which defines the `Cipher`, `Keyset`, `Ciphertext`, and `Json` classes the package exports, runs every operation through the engine, and reads and builds JavaScript values only through the value bridge beside it, `value-napi/` (crate `recipher-value-napi`, a copy of vitaminc's `vitaminc-aead-napi` 0.10.0, unpublished, with a detached test addon workspace of its own at `value-napi/tests/addon` and vitaminc's value conformance corpus at `value-napi/tests/testdata`; Biome does not check that directory). The bridge converts JSON documents too. `JsRef::to_json` writes a JavaScript value as a document's JSON text, with the JavaScript number rules. `JsBuilder::build_json` builds a decrypted document. The addon's `json.rs` contains only the `Json` class, and passes the text to the engine's `JsonPlaintext`. A test fails if it links `eql-bindings` or reaches the engine's `test-support` with its default features. `@napi-rs/cli` v3 builds it (`build:debug`, `build:native`) and writes its generated TypeScript declarations to the committed `native.d.ts`; CI fails when the build changes that file. Each native method returns the package's `Result` itself, and its public signature is written in Rust (napi-rs's `ts_type`, `ts_args_type` and `ts_return_type` attributes, with `native-header.d.ts` as the generated file's header), so `native.d.ts` is the public type: never add a TypeScript wrapper or hand-written interface over a native class. The TypeScript (`src/`) contains only `Result`, `RecipherError`, the loader, stand-ins for a build that did not load, and the types that the generated signatures name. The loader is `src/binding.ts`. The loader gives the addon the `Ok`, `Err`, and `RecipherError` classes. The types are in `src/kinds.ts` and `src/value-types.ts`. `native.d.ts` imports those types, so a module that `native.d.ts` imports from must never load the addon. If one did, the declarations would import themselves. The declaration build of tsup would then fail. Two kinds of call throw: a method called without its object (#1801), and `new` on a class whose type has no constructor (`Cipher`, `Keyset`, `Ciphertext`, and the wrapper classes, which an application makes with `RcDate.from(text)` and the like, each returning a `Result`). Every other call returns or resolves to a `Result`. Its `build` (tsup) and `test` (the suites in `__tests__/unit` and `tsc` over `src`, the tests and `type-tests`) never run cargo; `build:debug` (the addon with the deterministic test cipher behind `@cipherstash/recipher/testing`), `build:native`, `test:addon` (the suites that load `recipher.node`) and `test:cargo` do. `.github/workflows/tests-recipher-js.yml` runs all four, and fmt and clippy over the value bridge's test addon by its manifest: `tests.yml`'s live jobs skip a change that touches only this package, so apart from that file's ungated lint and repo checks it is the only workflow such a change runs. One Dependabot cargo entry covers both lockfiles, and `scripts/__tests__/recipher-js-lock-parity.test.mjs` fails when they resolve different napi or vitaminc crates. +- `languages/typescript/packages/recipher-js`: `@cipherstash/recipher`, the TypeScript SDK on Stack Encrypt (design: `docs/plans/2026-11-22-recipher-typescript-sdk.md`). **Private and unpublished**: it has no platform packages and no release job yet, so it must stay `"private": true` (a public manifest would be published by `changeset publish` on merge) and takes no changeset. Its Rust is **two crates** in a **detached Cargo workspace** with its own `Cargo.lock`. The root workspace names its members, so it needs no `exclude` entry there; leave the root `Cargo.toml` alone, because a change to it starts every stack-* crate workflow. The two crates: `crate/` (crate `recipher-js`, napi-rs 3), which defines the `Cipher`, `Keyset`, `Ciphertext`, and `Json` classes the package exports, runs every operation through Stack Encrypt, and reads and builds JavaScript values only through the value bridge beside it, `value-napi/` (crate `recipher-value-napi`, a copy of vitaminc's `vitaminc-aead-napi` 0.10.0, unpublished, with a detached test addon workspace of its own at `value-napi/tests/addon` and vitaminc's value conformance corpus at `value-napi/tests/testdata`; Biome does not check that directory). The bridge converts JSON documents too. `JsRef::to_json` writes a JavaScript value as a document's JSON text, with the JavaScript number rules. `JsBuilder::build_json` builds a decrypted document. The binding's `json.rs` contains only the `Json` class, and passes the text to Stack Encrypt's `JsonPlaintext`. A test fails if it links `eql-bindings` or reaches Stack Encrypt's `test-support` with its default features. `@napi-rs/cli` v3 builds it (`build:debug`, `build:native`) and writes its generated TypeScript declarations to the committed `native.d.ts`; CI fails when the build changes that file. Each native method returns the package's `Result` itself, and its public signature is written in Rust (napi-rs's `ts_type`, `ts_args_type` and `ts_return_type` attributes, with `native-header.d.ts` as the generated file's header), so `native.d.ts` is the public type: never add a TypeScript wrapper or hand-written interface over a native class. The TypeScript (`src/`) contains only `Result`, `RecipherError`, the loader, stand-ins for a build that did not load, and the types that the generated signatures name. The loader is `src/binding.ts`. The loader gives the binding the `Ok`, `Err`, and `RecipherError` classes. The types are in `src/kinds.ts` and `src/value-types.ts`. `native.d.ts` imports those types, so a module that `native.d.ts` imports from must never load the binding. If one did, the declarations would import themselves. The declaration build of tsup would then fail. Two kinds of call throw: a method called without its object (#1801), and `new` on a class whose type has no constructor (`Cipher`, `Keyset`, `Ciphertext`, and the wrapper classes, which an application makes with `RcDate.from(text)` and the like, each returning a `Result`). Every other call returns or resolves to a `Result`. Its `build` (tsup) and `test` (the suites in `__tests__/unit` and `tsc` over `src`, the tests and `type-tests`) never run cargo; `build:debug` (the binding with the deterministic test cipher behind `@cipherstash/recipher/testing`), `build:native`, `test:addon` (the suites that load `recipher.node`) and `test:cargo` do. `.github/workflows/tests-recipher-js.yml` runs all four, and fmt and clippy over the value bridge's test addon by its manifest: `tests.yml`'s live jobs skip a change that touches only this package, so apart from that file's ungated lint and repo checks it is the only workflow such a change runs. One Dependabot cargo entry covers both lockfiles, and `scripts/__tests__/recipher-js-lock-parity.test.mjs` fails when they resolve different napi or vitaminc crates. - `languages/golang`: The Go module — the SDK `encrypt` with its generated-code support `encrypt/gensupport`, its test package `encrypt/encrypttest` (context assertions, and `NewClient`: an offline client over the deterministic test builds, for an application's tests; a **nested Go module** of its own, so only a program that imports it downloads those builds, requiring the SDK at the zero pseudo-version with `replace ../..` in the tree, and `NewClient` fails when the two are at different versions) and the policy packages `encrypt/policy` and `encrypt/policy/protosource`; the credential package `auth`; the generator `stashgen` and its command `cmd/stashgen`; and `internal` (the shared guest plumbing, the `record` wire model, and `wasmtestrun`, the wazero runner that `wasm:auth-guest:test` runs the auth guest's wasm32 tests under). A wazero host with no cgo. Its two WASI guests (`encrypt/guest`, `auth/guest`) are detached Cargo workspaces built by `mise run wasm:guest:build` and `mise run wasm:auth-guest:build`; `mise run wasm:guest:build:deterministic` and `wasm:guest:build:eql:deterministic` build the seeded TEST builds into `encrypt/encrypttest/wasm`, which `encrypttest` embeds and the hermetic Go tests read; the `.wasm` files are gitignored. The stack-encrypt guest has a second build with the EQL types (`mise run wasm:guest:build:eql`, cargo feature `eql`, linking `eql-bindings` by path; `wasm:guest:build:eql:deterministic` is its test build), embedded by `encrypt/eql` and registered on import, so a program whose generated code names an EQL type runs it (ADR-0007, amended). `encrypt/eql`'s types and `Types` table are generated from the EQL catalog by `eql-codegen` (`eql_gen.go`, written by `mise run types:generate` in `packages/eql` and drift-gated by `types:check` and `cargo test -p eql-codegen`). Generated `*_stash.go` files are committed and CI fails when `go generate ./...` changes one. Releases are cut by hand with `.github/workflows/release-golang.yml` (`gh workflow run release-golang.yml -f version=X.Y.Z[-pre] --ref `): because the guests are gitignored on main and Go fetches a version as the files committed at its tag, the workflow builds them, commits them on a release-only commit no branch points at, with `encrypt/encrypttest/go.mod` pinned to the SDK version by `scripts/go-release-pin-encrypttest.sh` (run in `build` and in `publish`), tags it `languages/golang/vX.Y.Z` and `languages/golang/encrypt/encrypttest/vX.Y.Z` (the workflow's `MODULES`) and pushes the tags alone, then attaches the EQL v4 SQL bundle to the GitHub release. The ref must carry the EQL v4 bundle, or the build stops at "Build the EQL SQL bundles". `scripts/go-release-version.mjs` refuses, before anything is built, every version Go would refuse (non-canonical semver, `+build` metadata, a v2+ major on a module path with no `/vN` suffix, a version shaped like a pseudo-version), a final version dispatched from anywhere but `main`, and a final version while `languages/golang/go.mod` pins a `github.com/cipherstash/vitaminc/…` module at a pseudo-version (vitaminc's Go bindings have no tags, and a TEMPORARY pin on an unreleased commit must be gone before the module is tagged); a pre-release may come from a branch and may carry such a pin. The build job also refuses a version the Go proxy already lists in `@v/list`, which catches a tag deleted after the proxy fetched it; it never asks the proxy for the version itself before the tag exists, because the proxy would cache "not found" for up to 30 minutes and `verify` would fail after the push. The build checks the `Cargo.lock` of the EQL workspace and both guest workspaces with `--locked` first, since none of those builds passes it. It runs in a job with no write token and hands the guests to a `publish` job that holds `contents: write` and runs only git and gh. `publish` fetches the commit with plain unauthenticated git rather than `actions/checkout`, whose `token` input defaults to the job's writable token, and refuses a release commit whose tree is not the one the build tested. `publish` takes the paths it commits from the workflow's fixed `GUESTS` list, never from the artifact, and refuses a `guests.sha256` that is not exactly one SHA-256 line for each of those five guests (the three production guests and the two test builds `encrypttest` embeds): the build job runs third-party code after writing that manifest, so a path read from it could put any file on the tag (`scripts/__tests__/go-release-artifact.test.mjs`). The release page's notes are the version's `## [X.Y.Z]` section of `languages/golang/CHANGELOG.md`, taken by `scripts/go-release-notes.mjs` in a `notes` job that runs no third-party code and that `build` waits for: a version with no section, or an empty one, is refused before anything is built, so write the section before dispatching. A version is immutable once the Go proxy has fetched it, so a tag is never moved or deleted: if `publish` or `verify` fails after the tag is pushed, use "Re-run failed jobs" on the same run, which keeps a tag that run pushed and creates or completes the release; a new dispatch of the same version is refused. Never tag a main commit by hand: `go get` would fetch a module with no guests. `encrypt/example` is a third nested module, never tagged: it requires both modules as an application does. `./...` stops at a nested module, so `scripts/go-binding-test.sh`, `go:lint` and the generated-code check find each `go.mod` and run in its directory. - `e2e/*`: Cross-package end-to-end tests (package managers, supply chain, Prisma example README) - `e2e/migration-guide`: Unpublished, separately installed npm examples for the Protect/EQL v2 to Stack/EQL v3 guide. See its README before running; Postgres requires a disposable database and DynamoDB persistence is in memory. @@ -705,8 +705,8 @@ monorepo, which is where the silent failures are. - **Changesets for `@cipherstash/eql` go in the repo-root `.changeset/`.** The subtree's own `.changeset/` was deleted with the import; there is no second one to put them in by mistake. -- **The JSON tree family is EQL v4 only and spans two crates.** The engine - half is `packages/stack-encrypt/src/json/` (the `Json` index, `JsonDocument`, +- **The JSON tree family is EQL v4 only and spans two crates.** The Stack + Encrypt half is `packages/stack-encrypt/src/json/` (the `Json` index, `JsonDocument`, the query terms); the SQL is `packages/eql/src/v3/json_tree/` under `-- ONLY EQL VERSION: 4`; the EQL types are hand-written in `packages/eql/crates/eql-bindings/src/v4/json_tree.rs`; and the live @@ -774,7 +774,7 @@ which the plan schedules before the next `stack-encrypt` release. patches `vitaminc-aead` to the copies here, as the root does; protect-ffi's resolves no `vitaminc-aead` 0.10. The TypeScript SDK's crates (`languages/typescript/packages/recipher-js`, napi-rs 3: - the addon `crate` and the value bridge `value-napi`) are a detached workspace + the language binding `crate` and the value bridge `value-napi`) are a detached workspace too, with its own `Cargo.lock`, depending on stack-encrypt by path. The value bridge's test addon (`value-napi/tests/addon`) is one more, built by that crate's own `tests/node.rs`. The @@ -980,7 +980,7 @@ Two rules the skill does not state yet: `#[non_sensitive]`, shows it as it is. Write `Debug` by hand only to show something the derive cannot, such as a count or a length. That text must still show no secret. -- Use a type the engine or vitaminc already has before you wrap it in a new +- Use a type Stack Encrypt or vitaminc already has before you wrap it in a new one. ## Designing a language SDK @@ -993,12 +993,22 @@ Go SDK, and the order to apply them in when two disagree. Two terms from it are used across this repository: -- A **binding** is the FFI or WASI interface between the Rust engine and a - target language. +- A **language binding**, or binding, is the FFI or WASI interface between + Stack Encrypt and a target language. - A **language SDK** is what users of the target language work with day to day. Do not call the user-facing library a binding. +A language binding is thin. The code exists once, in Stack Encrypt. A +binding sends Stack Encrypt's plan as it is, and calls +`stack_encrypt::dynamic`. It has no declaration format, row check, or value +conversion of its own. It renames none of Stack Encrypt's names. + +When +`dynamic` cannot do something that a language SDK needs, the fix goes into +Stack Encrypt, not into a workaround in the binding. Section 1 of +`packages/stack-encrypt/docs/language-integration.md` has the rules. + ## Agent Skills — these ship to customers `skills/*/SKILL.md` are **published artifacts, not internal notes.** Treat a wrong diff --git a/packages/stack-encrypt/docs/language-integration.md b/packages/stack-encrypt/docs/language-integration.md index b1c08730f..1d4941656 100644 --- a/packages/stack-encrypt/docs/language-integration.md +++ b/packages/stack-encrypt/docs/language-integration.md @@ -1,10 +1,10 @@ # Building a language integration -How to reach Stack Encrypt from a language other than Rust: what crosses -between your code and the engine, what the engine expects of you, and how -to prove you got it right. +How to reach Stack Encrypt from a language other than Rust. The guide says +what crosses between your code and Stack Encrypt, what Stack Encrypt +expects of you, and how to prove you got it right. -Stack Encrypt is CipherStash's encryption engine. It encrypts each value of a +Stack Encrypt is CipherStash's encryption library. It encrypts each value of a record under its own data key from ZeroKMS, the key service, and derives the *search terms* a database can compare without decrypting: an equality term (a keyed hash), order terms (for `<`, `>` and `BETWEEN`), match terms (for @@ -17,36 +17,65 @@ does, and every rule below names where in it the rule is kept. Its binding is a WebAssembly guest, which is right for Go and wrong for a language that can link Rust natively. Section 2 says which kind of binding to build. -## 1. A binding and a language SDK are two things +## 1. Stack Encrypt, a language binding and a language SDK -- The **engine** is this crate: the Rust code that encrypts, decrypts and +- **Stack Encrypt** is this crate: the Rust code that encrypts, decrypts and derives terms. -- A **binding** is the interface between the engine and a language: a native - extension that links this crate, or a WebAssembly module. What crosses it - is data: a declaration, a value, a result. +- A **language binding** is the interface between Stack Encrypt and a + language: a native extension that links this crate, or a WebAssembly + module. What crosses it is data: a plan, a value, a result. This guide + calls it a binding for short. - A **language SDK** is what users of the language work with: the types, decorators, struct tags or generators they write against. It sits on the binding. -Keep the two apart in code and in words. The user-facing library is never +Keep the binding and the SDK apart in code and in words. The user-facing library is never "the binding". The Go SDK is `languages/golang/encrypt`; its binding is the WebAssembly guest in `languages/golang/encrypt/guest` and the Go code in `languages/golang/internal/guest` that runs it. `docs/sdk-design-principles.md` fixes what a language SDK may and may not -do, and this guide does not repeat it. Two of the engine's rules matter +do, and this guide does not repeat it. Two of Stack Encrypt's rules matter most here: -- A binding enters the engine through a plan, never through an executor of +- A binding enters Stack Encrypt through a plan, never through an executor of its own. It has no loop over fields, no batching and no sealing. - An operator selects the index that answers it, and a query term is derived for that operator. It is not the stored term. -The one sentence to carry: the engine does all the work, an SDK declares -what to do and sends it across as data, and the bytes are the same in -every language because every language runs the same code. - -## 2. Link the engine natively +The main rule: Stack Encrypt does all the work. An SDK declares +what to do, and sends it across as data. The bytes are the same in every +language, because every language runs the same code. + +### A binding is thin + +The code exists once, in Stack Encrypt. A binding is a thin layer over +`dynamic`. So a fix or a new feature in Stack Encrypt reaches every +language at once. No language keeps a copy of a rule that can drift. + +- **Send Stack Encrypt's plan as it is.** The language SDK writes the plan + in the grammar of section 4. The binding reads it with + [`crate::dynamic::record::plan`] or + [`crate::dynamic::record::plan_with`]. A binding has no declaration + format of its own, and builds no [`crate::dynamic::FieldPlan`] by hand. +- **Let Stack Encrypt check each row.** Stack Encrypt refuses a field that + the plan does not name, and a field that the row lacks. It converts each + value to its field's declared kind. Its error names the field. A binding + makes none of these checks itself. +- **Keep Stack Encrypt's names.** The outputs, the operators, the kinds, + and the error codes reach the language unchanged. The outputs are `c`, + `eq`, `match`, `ore`, `ope`, and `passthrough`. A binding that renames one leaks the rename into + every other binding that has to read the same data. If a name is hard to + read, add an alias to Stack Encrypt's plan, where every SDK gets it. +- **Fix a gap in Stack Encrypt.** When `dynamic` cannot do something that a + language SDK needs, change Stack Encrypt. Do not work around the gap in + the binding. + +The plan is never shown to the user of a language SDK, but it shapes the +SDK's API. So a change to the plan grammar keeps it easy for a language SDK +to write. + +## 2. Link Stack Encrypt natively Build a native extension that links this crate with the `dynamic` feature, through the language's own Rust binding tool: @@ -55,7 +84,7 @@ through the language's own Rust binding tool: - Elixir and Erlang: Rustler. - Node.js: napi-rs. -The engine then runs in the host's process, on the host's threads. It makes +Stack Encrypt then runs in the host's process, on the host's threads. It makes its own requests to ZeroKMS, its errors are Rust values the extension turns into the language's own, and the extension calls the Rust API in section 3 directly. There is no buffer registry to manage, no step loop and no status @@ -66,7 +95,7 @@ cannot load a native library, so build the same extension crate for the `wasm32-unknown-unknown` target with `wasm-bindgen`, as the `@cipherstash/stack/wasm-inline` entry is built (the `build:wasm` script of `languages/typescript/packages/protect-ffi`). The extension then exports a -JavaScript API, and the engine's requests to ZeroKMS go out through the +JavaScript API, and Stack Encrypt's requests to ZeroKMS go out through the runtime's `fetch` (stack-kms's HTTP connection on that target). It is the native extension's code and the native extension's API, compiled to another target; nothing in the guest sections of this guide applies to it. @@ -77,7 +106,7 @@ its binding is a guest that the wazero runtime runs. C and C++ may be another case. A language with a good native binding story never uses the guest. -The engine is the same either way. A guest wraps the same `dynamic` API in +Stack Encrypt is the same either way. A guest wraps the same `dynamic` API in exports, as `languages/golang/encrypt/guest/src/abi.rs` does, over the conventions in the `stack-guest-abi` crate (`packages/stack-guest-abi`). Where this guide describes the guest, it says so; skip those parts for a @@ -102,8 +131,8 @@ context argument. [`vitaminc_protected::ProtectedRef`]; call [`crate::AsProtectedRef::as_protected_ref`] on the bytes. - A **value**: the record, as one frame. A binding never builds a tree of - values; it writes the host value straight into a frame, in a buffer wiped - when it drops, and the engine walks the bytes in place. A call that reads + values. It writes the host value straight into a frame, in a buffer wiped + when it drops. Stack Encrypt walks the bytes in place. A call that reads the value only while it runs borrows it as a [`crate::dynamic::frame::Frame`]; a value kept past the call, such as one an async call holds, is a [`crate::dynamic::frame::OwnedFrame`], which owns @@ -151,10 +180,10 @@ an SDK that builds queries one at a time: An operator ([`crate::dynamic::Op`]) is named by its wire name: `eq`, `lt`, `lte`, `gt`, `gte`, `between` and `matches` for a single value, and the JSON -operators below for a document. The engine reads the value as the field's -declared type, finds the index that answers the operator -([`crate::dynamic::Op::answered_by`]), and derives the term the same way -the stored term was derived. +operators below for a document. Stack Encrypt reads the value as the field's +declared type, and finds the index that answers the operator +([`crate::dynamic::Op::answered_by`]). It derives the term the same way +as the stored term. ### Decrypt a record @@ -195,8 +224,8 @@ makes one call for each value, and merges the calls with [`crate::Pending::all`]. Awaiting the merged call makes one key request. Each value keeps its own declared kind. -A ciphertext contains one scalar. The engine refuses an array, an object, a -passthrough, and a null before it requests any key. The engine also refuses +A ciphertext contains one scalar. Stack Encrypt refuses an array, an object, a +passthrough, and a null before it requests any key. Stack Encrypt also refuses JavaScript's `undefined`, with any declared kind. The refusal is [`crate::dynamic::Error::Value`], with the code `stack_encrypt::dynamic_value` and the reason `not_a_scalar`. An SDK stores @@ -208,7 +237,7 @@ the payload field `found`. Examples are `array`, `null`, `undefined`, and `not_an_object` error. The kind is the kind of the input. A refused decrypt never names the kind of the decrypted value. -`json` is a declared kind, and the engine stores a document as text. So a +`json` is a declared kind, and Stack Encrypt stores a document as text. So a `string` and a document have one stored form. A check of the stored kind cannot distinguish them. A stored document decrypts as `string`. A stored string whose text is a JSON document decrypts as `json`. @@ -240,7 +269,7 @@ Some questions take a plan and no record, so they are functions of the plan rather than `Planned` calls: - [`crate::dynamic::field_operators`] lists the operators a plan field - answers, so a generator can ask the engine instead of keeping a copy of + answers, so a generator can ask Stack Encrypt instead of keeping a copy of the table. - [`crate::dynamic::verify`] answers, for a page of decrypted values, which ones a probabilistic query matches (a match index gives a @@ -261,7 +290,7 @@ the `expected` argument of [`crate::dynamic::record::decrypt`]. A field of type `"json"` stores a JSON document, which the language SDK hands over as UTF-8 JSON text. It names a target that stores a document -(`JsonSearch`), and its options say which paths are ordered. The engine +(`JsonSearch`), and its options say which paths are ordered. Stack Encrypt parses the text by one set of rules ([`crate::dynamic::read_json`]) and gives it back as text ([`crate::dynamic::json_frame`]). The whole document is sealed as one leaf, its JSON text. @@ -278,11 +307,11 @@ query plan derives the operand for every one of them, and A plan field may name an EQL type as its **target** instead of listing outputs: `{"context": ["profiles", "age"], "target": "IntegerEq"}`. EQL is the SQL library installed into a customer's PostgreSQL, and an EQL type is -the JSON value one of its column types stores. The engine does not know the +the JSON value one of its column types stores. Stack Encrypt does not know the EQL types; the crate that does, `eql-bindings`, depends on this one. So the binding that links the EQL types passes a -[`crate::dynamic::TargetResolver`], which the engine calls once per target -field to run the named type's own plan: to +[`crate::dynamic::TargetResolver`]. Stack Encrypt calls it once for each +target field, to run the named type's own plan. The binding passes it to [`crate::dynamic::record::plan_with`], to `Planned::with_resolver`, and to [`crate::dynamic::record::Plan::query_with`] and [`crate::dynamic::record::Plan::field_with`]. @@ -347,9 +376,9 @@ with the cases every binding runs. The shape: Every field of one plan shares the same prefix (the table) and its last part is the field's identity (the column). A scope nests to the left: `[["profiles", "age"], 7]`, and every field carries the same scopes. -- **`outputs`** are what the engine produces for the field: `c` is the - ciphertext; `eq`, `ore`, `ope` and `match` are index terms; `passthrough` - carries the value as it is, unsealed and unauthenticated. These keys are +- **`outputs`** are what Stack Encrypt produces for the field. `c` is the + ciphertext. `eq`, `ore`, `ope`, and `match` are index terms. + `passthrough` is the value as it is, unsealed and unauthenticated. These keys are wire format: they are the map keys of the stored record, fixed in [`crate::dynamic::Output`] and [`crate::target::IndexSpec`], so a binding never spells its own. A match index with options other than the defaults @@ -391,11 +420,11 @@ declaration. A refusal names the field and a reason (section 8). ## 5. Control messages and plaintext -Two kinds of data cross a binding, and the engine treats them differently. +Two kinds of data cross a binding, and Stack Encrypt treats them differently. **Plaintext** is a value or a record. It crosses as a *frame*: vitaminc's self-describing transport encoding, the same bytes a native Rust value -describes itself as. The engine never decodes a frame into a tree. It reads +describes itself as. Stack Encrypt never decodes a frame into a tree. It reads it in place, walks it into the encrypting sink and the term derivers, and drops it. [`crate::dynamic::frame::Frame::parse`] accepts bytes that hold exactly one frame and lends them in place, and @@ -408,8 +437,8 @@ too, in a buffer wiped on drop. **Control messages** are everything else: the plan, a context, query statistics, an error, and for a guest the options object, a configuration -and a step's requests and responses. They cross as frames as well, and the -engine reads each straight into a typed message with serde +and a step's requests and responses. They cross as frames as well, and Stack +Encrypt reads each straight into a typed message with serde (`recipher_frame::serde`), with no intermediate tree. There is no type a binding can use to hold plaintext as a tree, by design. If you find yourself building one, you are building a second value model. @@ -417,8 +446,8 @@ yourself building one, you are building a second value model. The frame format itself is documented in the crate that owns it, `recipher-frame`: the byte layout, the tag table, and the depth and length limits. This guide does not restate it. This crate re-exports it as -[`crate::dynamic::frame`], so a binding builds against the same version the -engine does. +[`crate::dynamic::frame`], so a binding builds against the same version Stack +Encrypt does. - **A native extension links the crate** and has no codec of its own: the crate writes and reads every frame, on both sides. The version it pins in @@ -432,30 +461,36 @@ engine does. ### The value model -A frame can carry more types than the engine accepts. The engine accepts -the *value model*: +A frame can contain a value that Stack Encrypt refuses. Stack Encrypt +accepts the *value model*: - null and `undefined`, booleans, and integers of every width from `i8` to `u128`, each kept at its own width; - both floats, text and bytes; -- three of vitaminc's logical types: a date, a decimal (its scale kept) - and a timestamp, read in nanoseconds whatever unit it arrives in; +- four of vitaminc's logical types: + - a date; + - a decimal, with its scale kept; + - a timestamp, read in nanoseconds whatever unit it arrives in; + - a UUID, as 16 bytes; - arrays, maps and passthroughs of these. -A UUID is refused, although vitaminc has a UUID type. So is a logical type -the engine does not know, and a date, decimal or timestamp outside -vitaminc's range. [`crate::dynamic::ValueFrame#the-value-model`] holds the -rule, and [`crate::dynamic::ValueFrame::from_bytes`] refuses a frame that -breaks it. +A date, decimal, timestamp, or UUID outside vitaminc's range is refused +when it is sealed. [`crate::dynamic::plaintext::Logical::admits`] holds the +rule. + +A frame can also carry a logical type that this build does not know. A +field with no declared kind seals it as it arrived, and opens it the same +way. A declared kind refuses it, and no index takes it. So an older build +can store a value of a type that a newer build added. Map your language's types onto this list, and refuse anything else before -it reaches the engine, with an error that names the field and the type. A +it reaches Stack Encrypt, with an error that names the field and the type. A plan's field types ([`crate::dynamic::ValueKind`], section 4) are the same list. ### Nulls -Whether a null is padded is vitaminc's rule, and the engine follows it: +Whether a null is padded is vitaminc's rule, and Stack Encrypt follows it: - **A null of a fixed-width type** (a boolean, a number, a date, a timestamp or a decimal) is a *typed null*. It is padded to the length of @@ -464,16 +499,19 @@ Whether a null is padded is vitaminc's rule, and the engine follows it: - **A null of a variable-width type** (text, bytes) is a plain null. There is no length to pad it to. -The padding needs the type, and a frame does not carry it: a typed null in -a frame handed over by a host reads as a plain null -([`crate::dynamic::ValueFrame::from_bytes`]). So the type comes from the -plan. A field declared with a fixed-width type and `"null": "sealed"` -seals its nulls padded. A field with `"null": "sql"` stores nothing, and +The padding needs the type. A frame that a host sends can carry a typed +null, and Stack Encrypt pads it when it seals it. But a frame that a frame +writer writes holds a plain null in its place +([`crate::dynamic::frame::OwnedFrame::of`]). So for a record, the type +comes from the plan. + +A field declared with a fixed-width type and +`"null": "sealed"` seals its nulls padded. A field with `"null": "sql"` stores nothing, and the host's column holds SQL `NULL`, which shows that the value is absent. [`crate::dynamic::NullMode`] has the rules. Do not decide padding in your SDK. Pass the field's null mode in the plan, -and let the engine apply vitaminc's rule. +and let Stack Encrypt apply vitaminc's rule. ### A whole object as one value @@ -494,7 +532,7 @@ Three formats are involved, and they are easy to confuse: | Format | What it holds | Stored? | |---|---|---| | Sealed leaf | One scalar or record field, inside the encryption | Yes, and frozen | -| Frame | One value crossing between a host and the engine | No: it can change in any release | +| Frame | One value crossing between a host and Stack Encrypt | No: it can change in any release | | Storage blob | One whole object, written before it is sealed as bytes | Yes, and frozen at version 1 | The storage profile shares the frame's scalar encodings and its array and @@ -508,7 +546,7 @@ object layout, and differs in four ways: refused. So a blob is written from your language's value, not converted from the -frame the engine sees. Rust writes it with `storage::to_vec` from a type's +frame Stack Encrypt sees. Rust writes it with `storage::to_vec` from a type's serde `Serialize`. The Go SDK writes it with `vcffi.MarshalStorage` and seals it as the one field of a record (`languages/golang/encrypt/gensupport/codec.go`). @@ -529,19 +567,19 @@ field. ## 6. Plaintext hygiene -The engine's rule is that plaintext lives in one place, for as long as the +Stack Encrypt's rule is that plaintext lives in one place, for as long as the operation needs it, and is wiped on every path out, including failure. A binding inherits the rule for every copy it makes. -What the engine does for every binding: +What Stack Encrypt does for every binding: -- The engine reads a value in place, from the buffer the binding wrote it - into, and holds what it must keep, an opened value or a field split out of - a record, as a [`crate::dynamic::frame::OwnedFrame`], whose buffer wipes - itself. So each copy is wiped by its type, not by a line someone has to +- Stack Encrypt reads a value in place, from the buffer the binding wrote + it into. Stack Encrypt keeps an opened value, + or a field split out of a record, in a + [`crate::dynamic::frame::OwnedFrame`], whose buffer wipes itself. So each copy is wiped by its type, not by a line someone has to remember. A `Planned` value is moved in and wiped when the call is done with it. -- **Keys never leave the engine.** Key material derived from a ZeroKMS +- **Keys never leave Stack Encrypt.** Key material derived from a ZeroKMS response stays in it. - **Errors carry no values** (section 8). @@ -592,13 +630,13 @@ your binding's own copies: it is item 4 of the checklist. ## 7. Keys and authentication -The engine fetches data keys from ZeroKMS with a bearer token, from an +Stack Encrypt fetches data keys from ZeroKMS with a bearer token, from an auth strategy in `stack-auth`. ### A native extension The extension builds a [`crate::StackCipher`] over a ZeroKMS client and an -auth strategy, as a Rust program would, and the engine makes its own +auth strategy, as a Rust program would, and Stack Encrypt makes its own requests. Choose the strategy by who the calls are for: - A strategy that holds its own credential, such as an access key, serves @@ -705,10 +743,10 @@ impatient caller. ## 8. Errors -**A native extension** gets the engine's error as a Rust value: +**A native extension** gets Stack Encrypt's error as a Rust value: [`crate::Error`], or the [`crate::dynamic::Error`] that a plan or a value was refused with. Turn it into the language's own exception, keeping what -the error carries. Every engine error implements [`crate::ErrorPayload`]: +the error carries. Every Stack Encrypt error implements [`crate::ErrorPayload`]: a code, a message, help, structured fields and causes. Every input error from the `dynamic` module names the field it is about and a [`crate::dynamic::Reason`] (`no_such_field`, `operator_not_answered`, @@ -739,7 +777,7 @@ and a code keeps its value for good. The ones a host meets first: | 29 | `NEEDS_IO` | not a failure: the step loop of section 7 | Codes 13 to 27 belong to the credential guest (profile files and sign-in). -How the Go guest maps the engine's errors onto those numbers, and what +How the Go guest maps Stack Encrypt's errors onto those numbers, and what `FOREIGN_KEYSET` and `CONTEXT_MISMATCH` do not prove, is `languages/golang/encrypt/guest/src/status.rs`. The same distinctions hold for a native extension's exceptions: a refused credential, a wrong keyset @@ -749,15 +787,15 @@ differently. **Codes.** A caller branches on an error's code, so codes are kept stable and apart: -- **Pass the engine's codes on unchanged.** An engine error keeps its own - code (`stack_encrypt::aead`), help, fields and causes. Do not map engine - errors onto codes of your own, or group them into coarser kinds: a - grouping would have to be kept in step with every engine error. +- **Pass Stack Encrypt's codes on unchanged.** A Stack Encrypt error keeps its own + code (`stack_encrypt::aead`), help, fields, and causes. Do not map its + errors onto codes of your own, or group them into coarser kinds. A + grouping would have to be kept in step with every Stack Encrypt error. - **Name your own codes after your binding's crate.** An error that only - your SDK raises, such as a value your language cannot convert, gets a - code under its crate's name, never under the engine's: a crate - `example_binding` raises `example_binding::not_a_string`. Then no code - of yours can clash with one the engine adds later. + your SDK raises gets a code under its crate's name, never under Stack + Encrypt's. For example, a crate `example_binding` refuses a value that + your language cannot convert with `example_binding::not_a_string`. Then no code + of yours can clash with one Stack Encrypt adds later. - **Report a refused value as a typed error.** When your conversion refuses a value, say which rule it broke as a value with a code. Never make a caller, or your own SDK, read the wording of a message. @@ -776,11 +814,11 @@ prints when a user prints a struct. Three things have versions, and a binding ties them together. -- **The engine.** This crate is on crates.io. A native extension pins its +- **Stack Encrypt.** This crate is on crates.io. A native extension pins its version in its `Cargo.toml`. The Go guest depends on `stack-encrypt` by - path (`languages/golang/encrypt/guest/Cargo.toml`), and the Go package - embeds the guest built from the same commit, so host and engine cannot - drift: a tagged Go release carries the guest built at that tag + path (`languages/golang/encrypt/guest/Cargo.toml`). The Go package embeds + the guest built from the same commit. So the host and Stack Encrypt + cannot drift: a tagged Go release carries the guest built at that tag (`languages/golang/encrypt/README.md`, "Building"). - **The wire.** The frame format is `recipher-frame`'s. A native extension gets the version this crate depends on; a guest's host codec @@ -821,8 +859,8 @@ type Profile struct { `stashgen` turns it into the declaration in `profile_stash.go`, `EncryptInto("age", gensupport.Int32, "IntegerEq")`, and the declaration -becomes a plan. The one-field plan, as JSON for reading and as the frame the -engine actually receives: +becomes a plan. The one-field plan, as JSON for reading and as the frame Stack +Encrypt actually receives: ```text { "age": { "context": ["profiles", "age"], "target": "IntegerEq" } } @@ -977,15 +1015,15 @@ assert_eq!(opened.frame(), row()?.frame()); Decrypting the stored `IntegerEq` value runs the type's own `DecryptInto` through the resolver, which reads the ciphertext inside the JSON, authenticates it under `profiles/age`, and refuses a different stored `i`. -What comes back to the binding is the frame `04 2a000000`, in a buffer the -engine wipes when it drops. In the Go SDK it lands in `Age int32` and +What comes back to the binding is the frame `04 2a000000`, in a buffer Stack +Encrypt wipes when it drops. In the Go SDK it lands in `Age int32` and nowhere else. ## 11. Checklist for a new binding -`conformance/stack-encrypt` holds the shared test contract for bindings: -language-neutral cases, the outputs the native engine froze for them, and -the requirement IDs each profile maps onto existing tests. Its `README.md` +`conformance/stack-encrypt` contains the shared test contract for +bindings. It has language-neutral cases, the outputs that Rust froze for +them, and the requirement IDs that map each profile onto existing tests. Its `README.md` lists every profile and its Rust and Go runners. Before a binding is called done: @@ -1025,12 +1063,12 @@ done: against [`crate::dynamic::frame::OwnedFrame::of`] for the same value. For a guest, the host's codec writes and reads every frame of the raw-frame profile and refuses every frame it says to refuse; add a fuzz target - that feeds the codec's output to the engine's reader and the engine's - output to the codec's reader. The engine's own fuzz targets are in + that feeds the codec's output to Stack Encrypt's reader and Stack Encrypt's + output to the codec's reader. Stack Encrypt's own fuzz targets are in `packages/stack-encrypt/fuzz/fuzz_targets` (`check_record`, `json_text`, `json_wire_decode`, `label_parse`, `sealed_value_decode`, `term_decode`), run as `docs/fuzzing.md` describes. -4. **The plaintext hygiene tests pass**, for the engine's copies and for +4. **The plaintext hygiene tests pass**, for Stack Encrypt's copies and for yours (section 6), and the lifecycle profile's cases hold for your language: cancellation, cleanup of a partial output, validation before any key is requested. @@ -1043,9 +1081,13 @@ done: plan's null mode, not padded by your SDK. An opaque value is written in the storage profile, and a blob your SDK writes opens in Rust and Go, and theirs in yours. -7. **The versions are tied.** The engine version, the frame-format version - and your binding's version move together, and a reader of your release - notes can tell which engine a release carries. +7. **The versions are tied.** The Stack Encrypt version, the frame-format + version, and your binding's version move together. A reader of your + release notes can tell which Stack Encrypt version a release carries. +8. **Your binding is thin** (section 1). It has no plan reader, row check, + or value conversion of its own. It renames none of Stack Encrypt's + names. Anything it would have to write itself is a change to Stack + Encrypt first. ## 12. Where the rest is From 4315942dbf2e484e5b9c47314df3974431e4babd Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Mon, 30 Nov 2026 00:09:18 +1100 Subject: [PATCH 3/3] docs(plans): the TypeScript records step waits for #2029 and #2028 The records pull request includes one field with { record, field }, and starts after Stack Encrypt has a conversion of the encrypted tree and a call for one field of a plan. --- docs/plans/2026-11-22-recipher-typescript-sdk.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/plans/2026-11-22-recipher-typescript-sdk.md b/docs/plans/2026-11-22-recipher-typescript-sdk.md index 3338d379a..8c3f97d4b 100644 --- a/docs/plans/2026-11-22-recipher-typescript-sdk.md +++ b/docs/plans/2026-11-22-recipher-typescript-sdk.md @@ -8,8 +8,8 @@ language binding only reads it. 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). +The record pull request is reworked to follow [A record](#a-record), after +#2029 and #2028 change Stack Encrypt. 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 @@ -1147,11 +1147,13 @@ The core, with no EQL: 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. + row's type, the type tests, the declaration, runtime, and read + profiles, and one field with `{ record, field }`. This step is the + first to call `dynamic::record::plan` and `Planned`. It waits for two + changes to Stack Encrypt: a conversion of the encrypted tree (#2029), + and a call for one field of a plan (#2028). The pending result (#2026) + follows the records. It 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.