From fc8c6de53a29042cba5a2dc64b7c1f094c7c8f45 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Sat, 14 Nov 2026 21:17:22 +1100 Subject: [PATCH 1/9] docs(plans): move vitaminc's encryption crates and ore.rs into stack-encrypt A plan in five stages: pin every stored and wire format, copy the crates in unchanged, fold them into stack-encrypt, move the Go packages, then retire the code in vitaminc and ore.rs. --- ...-vitaminc-encryption-into-stack-encrypt.md | 246 ++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 docs/plans/2026-11-14-move-vitaminc-encryption-into-stack-encrypt.md diff --git a/docs/plans/2026-11-14-move-vitaminc-encryption-into-stack-encrypt.md b/docs/plans/2026-11-14-move-vitaminc-encryption-into-stack-encrypt.md new file mode 100644 index 000000000..c0f95836e --- /dev/null +++ b/docs/plans/2026-11-14-move-vitaminc-encryption-into-stack-encrypt.md @@ -0,0 +1,246 @@ +# Move vitaminc's encryption crates and ore.rs into stack-encrypt + +Status: draft, 14 November 2026. Decision by Dan Draper: move the code, and +bring `ore.rs` too (option 1 below). + +## Summary + +`vitaminc-aead`, `vitaminc-ore`, `vitaminc-prf`, and the crates that depend on +them, move out of `cipherstash/vitaminc` and into `stack-encrypt`. The order +scheme crates `clww-ore` and `ore-rs` move with them, from `cipherstash/ore.rs`. +vitaminc keeps its base crates: `protected`, `random`, `context`, and the key +traits. + +The move happens in five stages. The first stage pins every stored and wire +format with known-answer tests, so each later stage can prove it changed +nothing that is stored. Code is moved first as it is, then merged with +stack-encrypt's own record layer, and only then deleted from vitaminc. + +This plan does not cover any change to the stored formats. A format change +during the move is a defect. + +## Why + +stack-encrypt is the only consumer that vitaminc's encryption crates exist +for. Splitting the work across two repositories has caused three problems: + +- **Two record designs.** vitaminc's `#[derive(Encrypt)]` turns a struct into + one type-erased tree. The derive copies each passthrough field into bytes. + stack-encrypt's `EncryptTarget` turns a struct into the user's own record + type. `EncryptTarget` moves each passthrough field. stack-encrypt uses its own design + for every record. Only one example uses the vitaminc derive: + `packages/stack-encrypt/examples/mixed_user.rs`. +- **A release before every change.** stack-encrypt is published, so it builds + against vitaminc from crates.io. Each fix needs a vitaminc release before + stack-encrypt can use it. The Go module pins vitaminc's `vcffi` and + `vcvalue` at an unreleased commit. While that pin is there, the Go release + script refuses a final version. +- **Unclear ownership.** Work on vitaminc has included features that nothing + in stack-encrypt uses, such as the derive's by-reference walk. + +## What moves, what stays, and what is deleted + +### Crates that move into stack-encrypt + +I checked this list against vitaminc `main` and `ore.rs` `main`. + +| Crate | Repository | Why it moves | +|---|---|---| +| `vitaminc-aead` | vitaminc | The plaintext model, the ciphertext tree, batching, frames | +| `vitaminc-aead-frame` | vitaminc | The transport frame for the bindings | +| `vitaminc-encrypt` | vitaminc | The AES (Advanced Encryption Standard) cipher; it depends on `vitaminc-aead` | +| `vitaminc-normalize` | vitaminc | Text normalization for terms; it depends on `vitaminc-aead` | +| `vitaminc-prf` | vitaminc | The pseudorandom function (PRF) behind equality and match terms | +| `vitaminc-hmac` | vitaminc | It depends on `vitaminc-prf` | +| `vitaminc-ore` | vitaminc | The order scheme traits and order spaces | +| `clww-ore` | ore.rs | The CLLW (Chenette, Lewi, Weis and Wu) order-revealing (ORE) and order-preserving (OPE) schemes; they implement `vitaminc-ore`'s traits | +| `ore-rs` | ore.rs | The block ORE scheme; it implements `vitaminc-ore`'s and `vitaminc-prf`'s traits | + +`ore.rs` has to move too. The `ore.rs` schemes implement `vitaminc-ore`'s traits, and +stack-encrypt depends on the schemes. If `vitaminc-ore` moved into +stack-encrypt and the schemes stayed in `ore.rs`, Cargo would refuse the +dependency cycle. + +### Go packages that move into `languages/golang` + +The stack Go module imports `github.com/cipherstash/vitaminc/bindings/go/vcffi` +and `vcvalue`, in `languages/golang/encrypt` and `languages/golang/auth`. Both +packages move into the Go module. That removes the +temporary pseudo-version pin from `languages/golang/go.mod`. + +### Crates that stay in vitaminc + +- `vitaminc-protected`, with its derive +- `vitaminc-random`, with its derive +- `vitaminc-context` +- `vitaminc-traits` and `vitaminc-async-traits` +- `vitaminc-kms` +- `vitaminc-password` +- `vitaminc-permutation` +- the `vitaminc` umbrella crate + +The umbrella loses its features for the crates that +move. + +`stack-auth`, `stack-kms`, and `cts-common` use only these crates. + +### Code that is deleted, not moved + +| Code | Why | +|---|---| +| `vitaminc-aead-derive` and `#[aead(passthrough)]` | No library code uses it. `EncryptTarget` replaces it. | +| `vitaminc_aead::hlist` | No code in the stack repository uses it. | +| `vitaminc_aead::plaintext::Tee` | No code in the stack repository uses it. Check again before deleting. | +| `vitaminc-aead-napi` | No lockfile in the stack repository includes it. | +| vitaminc's `bindings/go/vcencrypt` and its guest | The stack Go module has its own guest. Check that nothing imports `vcencrypt` before deleting. | + +The `mixed_user.rs` example is rewritten with `EncryptTarget`, or deleted. + +## Where the code goes + +All of it goes into `stack-encrypt` as modules, not as separate crates. + +stack-encrypt is published to crates.io. A published crate cannot depend on a +crate that is only a path in this repository. Each separate crate would +have to be published under a new name, and its version kept in step. Modules +avoid that. + +Two other crates in this repository use parts of `vitaminc-aead` today, and +they depend on stack-encrypt instead: + +- `stack-guest-abi` uses the plaintext model and the transport frame for + `HostValue`. +- The EQL encryption tests (`packages/eql/tests/encryption`). + +`eql-bindings` already reaches these through stack-encrypt. + +## The order of work + +Each stage is one or more pull requests. Each must pass the known-answer +tests from stage 1 with no change to the pinned bytes. + +### Stage 1: pin every stored and wire format + +Before any code moves, add known-answer tests for everything that is stored +or that crosses to a host: + +- the leaf ciphertext, its additional authenticated data (AAD), and + `WIRE_VERSION`; +- the AAD of a map entry, a sequence element, and a typed null; +- transport frames and passthrough frames; +- PRF key blocks, and the equality and match terms made from them; +- CLLW ORE, OPE, and block ORE terms, for every order target. + +Some of these exist already: + +- vitaminc: the storage corpus in `packages/aead-frame/testdata`, with an + append-only check, and the normalization known answers in + `packages/normalize/tests/known_answers.rs`; +- ore.rs: `clww-ore/src/known_answers.rs` and + `ore-rs/src/scheme/chained/compat_vectors_data.rs`. + +The work is to find the gaps, fill them, and run the whole set from +stack-encrypt against the crates.io versions it uses today. + +### Stage 2: copy the code in, unchanged + +Copy the crates into this repository at the versions that stack-encrypt's +`Cargo.lock` resolves today, keeping their names, as members of the root +workspace with `publish = false`. Point stack-encrypt and the other crates at +them by path. Port their tests, fuzz targets, and benchmarks with them. + +This stage changes no behaviour, so it is easy to review: the copied source +can be compared with the published crates file by file. + +Bring the history with the code if possible, as was done for the EQL subtree +and the stack-* crates. + +At the end of this stage stack-encrypt cannot be published, because it +depends on unpublished path crates. Stage 3 must land before the next +stack-encrypt release. + +### Stage 3: fold the crates into stack-encrypt + +Turn each copied crate into a module of stack-encrypt, then merge it with what +stack-encrypt already has: + +- **One record model.** `EncryptTarget` is the only way to encrypt a record. + `EncryptTarget` moves a passthrough field when the record is owned. +- **The planning sink and the type-erased tree stay** for the dynamic engine. + The dynamic engine encrypts values from Go and JavaScript. +- **Frames stay** as the format for values that cross to a host. +- Delete the code listed in "Code that is deleted, not moved". + +This stage can be several pull requests, one per area. The stage 1 tests pin +the bytes throughout. + +### Stage 4: move the Go packages + +Move `vcffi` and `vcvalue` into the Go module, update the imports, and delete +the pseudo-version pin from `go.mod`. Remove the matching refusal from +`scripts/go-release-version.mjs`. + +### Stage 5: retire the code in vitaminc and ore.rs + +- Delete the moved crates from vitaminc, and remove their features from the + `vitaminc` umbrella crate. Release vitaminc. +- Publish a final release of each moved crate whose README says where the code + now lives. Do not yank any version: old versions must keep building. +- Archive `ore.rs`, after the question below about `cipherstash-client` is + settled. + +## Checks that must move with the code + +vitaminc and ore.rs run checks that the stack repository does not. Each needs +a home in this repository's CI before its code moves: + +- Kani proofs, including `kani-storage`; +- sanitizers; +- the storage corpus append-only check; +- `cargo vet` and `cargo deny`; +- the fuzz targets of the moved crates; +- Miri for the moved crates; +- mutation testing. stack-encrypt already has it, with `--in-diff`. + +The stack repository already runs Miri, fuzzing, mutation testing, and +`cargo udeps` for its own crates. The work is to add the moved crates to +them, and to add the checks it lacks. + +## Open questions + +1. **Should the three open vitaminc pull requests be merged in vitaminc first?** + The three pull requests are reviewed and green: + - #616 encrypts by reference. + - #617 keys order schemes from the PRF. + - #618 adds `Date`, `Decimal`, and `Uuid`. + + Merging them first means stage 2 copies a version that + stack-encrypt does not use yet, so stage 2 is no longer a pure copy. + **Recommendation:** copy the released version, then reapply the three + pull requests in this repository. Drop the derive commit in #616 + (`ee9db984`). +2. **Should ore.rs stay open for `cipherstash-client`?** The legacy client, + used by protect-ffi and the EQL tests, depends on an older `ore-rs` from + crates.io. Moving the code does not break the client, because published + versions stay. But a fix to that line of `ore-rs` would have no + repository once ore.rs is archived. +3. **Which licence applies to the moved code?** vitaminc uses the MIT + licence. ore.rs has its own licence file. stack-encrypt has its own + licence file too. Ask the person responsible for licensing whether the + moved code keeps its MIT notice, and what licence the moved ore.rs code + has. +4. **Does anyone outside CipherStash use the vitaminc crates?** The crates + are on crates.io. Nobody has checked who else depends on them. + +## Rules this changes + +Two working rules agreed earlier no longer apply once this lands: + +- "A fix always belongs in vitaminc." The code that rule was about moves to + stack-encrypt. +- "The interop types, such as `FfiValue` and frames, live in vitaminc." The + interop types move with the record layer. + +`AGENTS.md` describes vitaminc as a dependency from crates.io, and lists +`clww-ore` and `ore-rs` among the exact pins in the root `Cargo.toml`. Update +both in the stage that changes them. From 2e9d93652b82df4cd0abb299d2408e2541a56f45 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Thu, 19 Nov 2026 21:44:55 +1100 Subject: [PATCH 2/9] docs(plans): vitaminc 0.10 settles the first open question --- ...-vitaminc-encryption-into-stack-encrypt.md | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/docs/plans/2026-11-14-move-vitaminc-encryption-into-stack-encrypt.md b/docs/plans/2026-11-14-move-vitaminc-encryption-into-stack-encrypt.md index c0f95836e..67df1d3ba 100644 --- a/docs/plans/2026-11-14-move-vitaminc-encryption-into-stack-encrypt.md +++ b/docs/plans/2026-11-14-move-vitaminc-encryption-into-stack-encrypt.md @@ -144,8 +144,8 @@ stack-encrypt against the crates.io versions it uses today. ### Stage 2: copy the code in, unchanged -Copy the crates into this repository at the versions that stack-encrypt's -`Cargo.lock` resolves today, keeping their names, as members of the root +Copy the crates in at the versions stack-encrypt's `Cargo.lock` resolves +when the stage starts. Keep their names, and make them members of the root workspace with `publish = false`. Point stack-encrypt and the other crates at them by path. Port their tests, fuzz targets, and benchmarks with them. @@ -206,30 +206,26 @@ The stack repository already runs Miri, fuzzing, mutation testing, and `cargo udeps` for its own crates. The work is to add the moved crates to them, and to add the checks it lacks. +## Settled since the first draft + +vitaminc 0.10.0 was released on 19 November 2026, with vitaminc #616, #617 +and #618 merged. Stage 2 copies 0.10.0 once stack-encrypt depends on it. +Moving stack-encrypt to 0.10 needs `clww-ore` and `ore-rs` releases on +vitaminc 0.10 first (ore.rs #144). + ## Open questions -1. **Should the three open vitaminc pull requests be merged in vitaminc first?** - The three pull requests are reviewed and green: - - #616 encrypts by reference. - - #617 keys order schemes from the PRF. - - #618 adds `Date`, `Decimal`, and `Uuid`. - - Merging them first means stage 2 copies a version that - stack-encrypt does not use yet, so stage 2 is no longer a pure copy. - **Recommendation:** copy the released version, then reapply the three - pull requests in this repository. Drop the derive commit in #616 - (`ee9db984`). -2. **Should ore.rs stay open for `cipherstash-client`?** The legacy client, +1. **Should ore.rs stay open for `cipherstash-client`?** The legacy client, used by protect-ffi and the EQL tests, depends on an older `ore-rs` from crates.io. Moving the code does not break the client, because published versions stay. But a fix to that line of `ore-rs` would have no repository once ore.rs is archived. -3. **Which licence applies to the moved code?** vitaminc uses the MIT +2. **Which licence applies to the moved code?** vitaminc uses the MIT licence. ore.rs has its own licence file. stack-encrypt has its own licence file too. Ask the person responsible for licensing whether the moved code keeps its MIT notice, and what licence the moved ore.rs code has. -4. **Does anyone outside CipherStash use the vitaminc crates?** The crates +3. **Does anyone outside CipherStash use the vitaminc crates?** The crates are on crates.io. Nobody has checked who else depends on them. ## Rules this changes From ebec81efa429041920fc65e7d0fa312a9de2a0fd Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Thu, 26 Nov 2026 11:24:00 +1100 Subject: [PATCH 3/9] docs(plans): move the AEAD crates as crates, in two stages, and define the value types once The first draft moved nine crates and ore.rs into stack-encrypt as modules. This draft moves three (vitaminc-aead, -aead-frame, -aead-derive) under their own names with no change in behaviour, then removes the engine's second copy of the value types: ValueKind, the allow-list and the ValueFrame wrapper. The TypeScript SDK showed the cost of the copies. A UUID is read by the bridge and refused by the engine, a Date is written in one unit and rewritten to another, and each SDK reconciles the two. --- ...11-14-move-vitaminc-aead-into-the-stack.md | 320 ++++++++++++++++++ ...-vitaminc-encryption-into-stack-encrypt.md | 242 ------------- 2 files changed, 320 insertions(+), 242 deletions(-) create mode 100644 docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md delete mode 100644 docs/plans/2026-11-14-move-vitaminc-encryption-into-stack-encrypt.md diff --git a/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md b/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md new file mode 100644 index 000000000..dce22b2e1 --- /dev/null +++ b/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md @@ -0,0 +1,320 @@ +# Move vitaminc's AEAD crates into the stack, and define the value types once + +Status: draft, rewritten 26 November 2026. Decisions by Dan Draper: + +- Move the AEAD crates into this repository as crates. Do not fold them into + modules of `stack-encrypt`. +- Work in two stages: move first with no change in behaviour, then + consolidate. +- Keep the move as small as possible. `vitaminc-protected` and + `vitaminc-random` never move. +- No more work on the TypeScript SDK until this is done. + +The first draft of this plan (14 November) moved nine crates, with `ore.rs`, +into `stack-encrypt` as modules. This draft replaces it. + +AEAD means authenticated encryption with associated data. The AEAD crates +define the value types, how each is encoded, and how a value is sealed. + +## Summary + +Three crates move from `cipherstash/vitaminc` into this repository: +`vitaminc-aead`, `vitaminc-aead-frame` and `vitaminc-aead-derive`. They keep +their names and are published from here. + +Then the value handling is consolidated. Today the list of value types is +written down in vitaminc, written again in the engine (`stack-encrypt`), and +reconciled a third time in each language SDK. After this plan: + +- The AEAD crates define the types, the encodings, the null rule, the + canonical form of each type, and the name of each type. Nothing else does. +- The engine depends on the AEAD crates. It does not wrap their types, hold + its own list of them, or rewrite a value. +- A language bridge converts a host language's values to and from the AEAD + types, and does nothing else. + +No stored format changes. A change to stored bytes during this work is a +defect. + +## Why + +### The same list is written at least five times + +vitaminc defines the types as `Logical` and `Physical`. The engine's +`dynamic` module then restates them: + +| Where | What it restates | +|---|---| +| `ValueKind` (`dynamic/kind.rs`) | A second enum of 21 types, with the text names a plan uses | +| `model`, `model_null` (`dynamic/value_frame.rs`) | An allow-list of the types the engine accepts | +| `scalar_kind` (`dynamic/value_frame.rs`) | A value's type as a `ValueKind` | +| `scalar_of` (`dynamic/kind.rs`) | A sample value for each `ValueKind` | +| `ValueKind::sealed_null` (`dynamic/kind.rs`) | The fixed-width type of each kind's null | +| `ordered`, `order_of` (`dynamic/term.rs`) | Which types an order index takes, twice | + +Outside the engine, the Go module (`record.Kind`), EQL (`plaintext_of` and +the `Plaintext` trait) and the TypeScript SDK each hold a copy as well. Go and +EQL call these "vitaminc's ValueKind names". vitaminc has no `ValueKind`. + +### The copies disagree + +- **A UUID.** vitaminc has the type, a sealed form, a null, an equality term + and an order term for it. The JavaScript bridge reads and builds one. The + engine's allow-list leaves it out, and no reason is recorded (#1821). The + engine is not consistent with itself either: `dynamic::term()` gives a UUID + an equality term, and the record path cannot store one. +- **A timestamp.** The JavaScript bridge writes a `Date` in milliseconds. The + engine rewrites every timestamp to nanoseconds. The bridge's README says a + `Date` is stored as its millisecond count, which is false once the value + passes through the engine. +- **An integer.** Go converts an integer to the declared type before it + encodes it. The engine refuses a value of another width on write, and + converts one on a query. The JavaScript bridge sends a `bigint` at the + narrowest width that fits, whatever the field declares. + +### An SDK pays for each disagreement + +The TypeScript SDK's addon classifies a value to explain the engine's refusal +(`is_uuid`), wraps the engine's wrapper to satisfy a trait (`OneValue`), and +copies every value twice: the bridge writes a frame, then the engine parses +it and copies it into a second buffer. + +### `ValueFrame` is not needed for what it is assumed to do + +`ValueFrame` is the engine's wrapper around frame bytes. It is not what wipes +a plaintext. `to_frame` and `decrypt_to_frame` already return +`vitaminc_protected::Buffer`, which wipes its bytes when it grows and when it +drops, and whose `Debug` shows nothing. + +What `ValueFrame` does add: + +- the allow-list; +- an owned value that can be encrypted, and a target a ciphertext opens into; +- comparison in constant time; +- reading a text value as a context label. + +The engine has to write these on a wrapper because it cannot implement the +AEAD crates' traits for a type from another crate. Once the AEAD crates are in +this repository, they can provide them. + +## What moves, and what stays + +### Stage 1 moves three crates + +| Crate | Why | +|---|---| +| `vitaminc-aead` | The types, the sealed leaf, the ciphertext tree, the sinks | +| `vitaminc-aead-frame` | The frame encoding a binding sends | +| `vitaminc-aead-derive` | `vitaminc-aead` depends on it | + +The JavaScript bridge, `recipher-value-napi`, is already here. It is a renamed +copy of `vitaminc-aead-napi` 0.10.0, and depends only on `vitaminc-aead` and +`vitaminc-protected`. + +### What stays in vitaminc + +- **Never moves:** `vitaminc-protected`, `vitaminc-random`. +- **Stays, and does not depend on the AEAD crates:** `vitaminc-context` + (`vitaminc-aead` depends on it), `vitaminc-hmac` (it depends on + `vitaminc-prf`), `vitaminc-traits`, and the rest. +- **Stays for now, and depends on `vitaminc-aead`:** `vitaminc-normalize`, + `vitaminc-prf`, `vitaminc-ore`, `vitaminc-encrypt`. See the next section. + +`clww-ore` and `ore-rs` stay in `cipherstash/ore.rs`. + +### The four crates that depend on `vitaminc-aead` + +| Crate | What it uses from `vitaminc-aead` | +|---|---| +| `vitaminc-normalize` | The canonical-form helpers (`timestamp_nanos`, `strip_trailing_zeros`, the date and timestamp limits). It implements the `Sink` traits, and uses the encrypting sink's internals (`shape`, `seal_all`, `Tee`). | +| `vitaminc-ore` | `Logical`, `Physical`, the value types. It implements the `Sink` traits. | +| `vitaminc-prf` | `Logical`, `Physical`, behind an optional feature. | +| `vitaminc-encrypt` | `seal::Cipher`, which it implements for the AES cipher, and the ciphertext builder. | + +The engine passes AEAD types into all four. So the engine and these four must +build against the same `vitaminc-aead`. Two consequences: + +- **The moved crates keep their names.** Under a new name, Cargo would build + two crates with two sets of types, and the engine's calls into the four + would not compile. +- **A breaking change to `vitaminc-aead` needs new releases of all four**, + and then of `clww-ore` and `ore-rs`, which the root `Cargo.toml` pins with + `=`. A change that only adds a type, a method or a `Logical` variant does + not break them. A change to the `Sink` traits or to `Physical` does. + +Stage 2 decides, step by step, whether a change can be made without breaking +them. If one cannot, the four move too. `vitaminc-normalize` is the most +likely: it holds rules about canonical forms, which this plan gives to the +AEAD crates. + +## Stage 0: pin the bytes + +Before any code moves, every stored and wire format has a test that fails +when its bytes change. Most exist: the conformance corpus +(`conformance/stack-encrypt/v1`), the engine's stored-row fixtures, and +vitaminc's own storage corpus. The known gaps: + +- **What the JavaScript bridge writes.** No TypeScript runner exists for the + corpus, so nothing compares a `Date`'s frame with the engine's. +- **A host's typed null.** One engine unit test covers it. No conformance + case does. +- **A JSON document's leaf.** The dynamic path writes a bytes leaf and the + typed path seals a text leaf. Which one each path stores has not been + traced. +- **The contents of `stored_rows_v1.json` and + `record-scalars-v1.expected.rust-native.json`** have not been listed by + type. + +The work is to list what each fixture freezes, fill the gaps, and run the +whole set against the crates.io versions in use today. + +## Stage 1: move the three crates, unchanged + +1. Copy the three crates in at the version the root `Cargo.lock` resolves. + Keep their names. Bring their history if possible, as was done for the + stack-* crates. +2. Bring their tests, fuzz targets and benchmarks, and the checks under + "Checks that must move with the code". +3. Point every workspace at them: the root workspace, the TypeScript SDK's + workspace, the two Go guests, and EQL's workspace. Each resolves vitaminc + on its own today. +4. Publish them from this repository under the same names and version line, + so that the four crates on crates.io and a published `stack-encrypt` all + resolve the same crate. +5. Move the open vitaminc issues about this code with it: vitaminc #643, + #473 and #632. + +This stage changes no behaviour. The copied source can be compared with the +published crates file by file. + +To settle before the stage starts: how a workspace build makes the four +registry crates resolve the in-repository `vitaminc-aead` (a `[patch]` table +is the candidate), and who owns the crates on crates.io. + +## Stage 2: consolidate + +Each step is its own pull request or small set of them. Each passes the +stage 0 tests with no change to pinned bytes. The steps are in dependency +order. + +### 2.1 One canonical form for a timestamp + +The sealed leaf has a short form for a timestamp in nanoseconds. Any other +unit is sealed in a longer envelope of a different length. Every value stored +through the engine is in nanoseconds, because the engine rewrites it. + +Move the rule into the AEAD crates, so that no caller can seal another unit +by accident, and change the JavaScript bridge to write a `Date` in +nanoseconds. Then delete the engine's rewrite. + +If this were skipped, a JavaScript `Date` would seal to a different length +from the same instant written by Go or Rust, and from its own sealed null. + +### 2.2 One description of a type, with its name + +Add one type to the AEAD crates that describes a value's type without a +value, and that has a text name. It replaces `ValueKind`. The names are a +wire format: plans, error payloads, the Go module, EQL's generated code and +the conformance corpus all use them, so they do not change. + +`scalar_kind`, `scalar_of` and `sealed_null` become methods of that type, or +are deleted. + +vitaminc has no such type today. `Kind`, `Width`, `KnownLogical` and +`FixedType` each cover part of it, and its only text names include a +parameter (`timestamp(ms)`, `decimal(2)`). + +### 2.3 Each index says which types it takes + +Delete the allow-list. An index refuses a type it cannot handle: + +- **Equality:** already asks `vitaminc-normalize`. +- **Order:** `vitaminc-ore` already refuses a boolean and an 8-bit integer. + The engine also refuses bytes and a UUID, which `vitaminc-ore` allows. + Decide whether that stays, and put it in one place. +- **Match:** text only. + +A plan is refused when it is built, before a value arrives. The index answers +that for a type from 2.2, with no sample value. + +### 2.4 The AEAD crates provide the owned value + +Add to the AEAD crates an owned, wiped frame that can be encrypted, that a +ciphertext opens into, and that compares in constant time. Delete +`ValueFrame`, `Modeled`, `Opening`, `Children` and `FromFrameError`. + +This is the widest step. `ValueFrame` is named in about 50 files of +`stack-encrypt`, 23 of EQL, and both SDK guests. It is in the public API of +`eql-bindings`, which is published, so this is a breaking release of that +crate. + +### 2.5 The bridges and the SDKs + +- **TypeScript:** the addon hands the bridge's frame to the engine with no + second copy. `OneValue`, `is_uuid`, and the `recipher_js::uuid` code are + deleted. +- **Go:** the guest stops calling `ValueFrame::from_bytes` and + `ValueFrame::check`. +- **EQL:** the `Plaintext` trait and the generated code use the type from + 2.2. + +A UUID then works in every SDK, which closes #1821. + +## What waits on this plan + +- The TypeScript SDK: #1775, #1776 and the prototype #1829. +- `ScalarFrame` (#1825, draft #1827). It wraps `ValueFrame`, so step 2.4 + replaces it. +- The language integration guide's new sections on the value model (#1828). + They describe the model this plan removes. +- The UUID fix (#1821). + +## Checks that must move with the code + +vitaminc runs checks that this repository does not. Each needs a home in this +repository's CI before its code moves: + +- Kani proofs, including `kani-storage`; +- sanitizers; +- the storage corpus append-only check; +- `cargo vet` and `cargo deny`; +- the fuzz targets of the moved crates; +- Miri for the moved crates; +- mutation testing. `stack-encrypt` already has it, with `--in-diff`. + +## Open questions + +1. **Who converts a value to its declared type on a write?** Today Go + converts on the host, the engine refuses a mismatch, and the JavaScript + bridge cannot know the width of a `bigint`. Either the AEAD crates convert + a value to a declared type when the conversion is exact, as the engine + already does for a query, or every bridge is told the declared type. The + first keeps a bridge free of types. It also changes a rule the conformance + corpus pins: a value of another width is refused on a write. +2. **Is a host's typed null kept?** The frame writer drops the type, and a + plan's `"null": "sealed"` adds the padding back from the declared type. + Once the declared type is an AEAD type, the two overlap. +3. **Where do `json`, `array` and `object` live?** They are `ValueKind` + variants and not scalar types. No index takes an array or an object, and + Go has no constant for either. +4. **Is `undefined` a null to a typed field?** The engine accepts it, gives + it no type, and does not treat it as a null. No test covers it against a + nullable field. +5. **Does the order index take bytes and a UUID?** See 2.3. +6. **Do Go's `vcffi` and `vcvalue` move?** They are vitaminc's Go packages, + with their own encoder, pinned at an unreleased commit. The Go release + script refuses a final version while that pin is there. They are a bridge, + so the consolidation applies to them, but they are not Rust crates. +7. **Which licence applies to the moved code?** vitaminc uses the MIT + licence. Ask the person responsible for licensing. +8. **Does anyone outside CipherStash use the moved crates?** They are on + crates.io. Nobody has checked. +9. **What is a frame called?** "Frame" does not say whether it is a transport + or a storage format. Rename it during stage 2, where the type is already + being replaced. + +## Rules this changes + +- "A fix always belongs in vitaminc." A fix to the AEAD crates belongs here. +- `AGENTS.md` describes vitaminc as a dependency from crates.io. Update it in + the stage that changes that. diff --git a/docs/plans/2026-11-14-move-vitaminc-encryption-into-stack-encrypt.md b/docs/plans/2026-11-14-move-vitaminc-encryption-into-stack-encrypt.md deleted file mode 100644 index 67df1d3ba..000000000 --- a/docs/plans/2026-11-14-move-vitaminc-encryption-into-stack-encrypt.md +++ /dev/null @@ -1,242 +0,0 @@ -# Move vitaminc's encryption crates and ore.rs into stack-encrypt - -Status: draft, 14 November 2026. Decision by Dan Draper: move the code, and -bring `ore.rs` too (option 1 below). - -## Summary - -`vitaminc-aead`, `vitaminc-ore`, `vitaminc-prf`, and the crates that depend on -them, move out of `cipherstash/vitaminc` and into `stack-encrypt`. The order -scheme crates `clww-ore` and `ore-rs` move with them, from `cipherstash/ore.rs`. -vitaminc keeps its base crates: `protected`, `random`, `context`, and the key -traits. - -The move happens in five stages. The first stage pins every stored and wire -format with known-answer tests, so each later stage can prove it changed -nothing that is stored. Code is moved first as it is, then merged with -stack-encrypt's own record layer, and only then deleted from vitaminc. - -This plan does not cover any change to the stored formats. A format change -during the move is a defect. - -## Why - -stack-encrypt is the only consumer that vitaminc's encryption crates exist -for. Splitting the work across two repositories has caused three problems: - -- **Two record designs.** vitaminc's `#[derive(Encrypt)]` turns a struct into - one type-erased tree. The derive copies each passthrough field into bytes. - stack-encrypt's `EncryptTarget` turns a struct into the user's own record - type. `EncryptTarget` moves each passthrough field. stack-encrypt uses its own design - for every record. Only one example uses the vitaminc derive: - `packages/stack-encrypt/examples/mixed_user.rs`. -- **A release before every change.** stack-encrypt is published, so it builds - against vitaminc from crates.io. Each fix needs a vitaminc release before - stack-encrypt can use it. The Go module pins vitaminc's `vcffi` and - `vcvalue` at an unreleased commit. While that pin is there, the Go release - script refuses a final version. -- **Unclear ownership.** Work on vitaminc has included features that nothing - in stack-encrypt uses, such as the derive's by-reference walk. - -## What moves, what stays, and what is deleted - -### Crates that move into stack-encrypt - -I checked this list against vitaminc `main` and `ore.rs` `main`. - -| Crate | Repository | Why it moves | -|---|---|---| -| `vitaminc-aead` | vitaminc | The plaintext model, the ciphertext tree, batching, frames | -| `vitaminc-aead-frame` | vitaminc | The transport frame for the bindings | -| `vitaminc-encrypt` | vitaminc | The AES (Advanced Encryption Standard) cipher; it depends on `vitaminc-aead` | -| `vitaminc-normalize` | vitaminc | Text normalization for terms; it depends on `vitaminc-aead` | -| `vitaminc-prf` | vitaminc | The pseudorandom function (PRF) behind equality and match terms | -| `vitaminc-hmac` | vitaminc | It depends on `vitaminc-prf` | -| `vitaminc-ore` | vitaminc | The order scheme traits and order spaces | -| `clww-ore` | ore.rs | The CLLW (Chenette, Lewi, Weis and Wu) order-revealing (ORE) and order-preserving (OPE) schemes; they implement `vitaminc-ore`'s traits | -| `ore-rs` | ore.rs | The block ORE scheme; it implements `vitaminc-ore`'s and `vitaminc-prf`'s traits | - -`ore.rs` has to move too. The `ore.rs` schemes implement `vitaminc-ore`'s traits, and -stack-encrypt depends on the schemes. If `vitaminc-ore` moved into -stack-encrypt and the schemes stayed in `ore.rs`, Cargo would refuse the -dependency cycle. - -### Go packages that move into `languages/golang` - -The stack Go module imports `github.com/cipherstash/vitaminc/bindings/go/vcffi` -and `vcvalue`, in `languages/golang/encrypt` and `languages/golang/auth`. Both -packages move into the Go module. That removes the -temporary pseudo-version pin from `languages/golang/go.mod`. - -### Crates that stay in vitaminc - -- `vitaminc-protected`, with its derive -- `vitaminc-random`, with its derive -- `vitaminc-context` -- `vitaminc-traits` and `vitaminc-async-traits` -- `vitaminc-kms` -- `vitaminc-password` -- `vitaminc-permutation` -- the `vitaminc` umbrella crate - -The umbrella loses its features for the crates that -move. - -`stack-auth`, `stack-kms`, and `cts-common` use only these crates. - -### Code that is deleted, not moved - -| Code | Why | -|---|---| -| `vitaminc-aead-derive` and `#[aead(passthrough)]` | No library code uses it. `EncryptTarget` replaces it. | -| `vitaminc_aead::hlist` | No code in the stack repository uses it. | -| `vitaminc_aead::plaintext::Tee` | No code in the stack repository uses it. Check again before deleting. | -| `vitaminc-aead-napi` | No lockfile in the stack repository includes it. | -| vitaminc's `bindings/go/vcencrypt` and its guest | The stack Go module has its own guest. Check that nothing imports `vcencrypt` before deleting. | - -The `mixed_user.rs` example is rewritten with `EncryptTarget`, or deleted. - -## Where the code goes - -All of it goes into `stack-encrypt` as modules, not as separate crates. - -stack-encrypt is published to crates.io. A published crate cannot depend on a -crate that is only a path in this repository. Each separate crate would -have to be published under a new name, and its version kept in step. Modules -avoid that. - -Two other crates in this repository use parts of `vitaminc-aead` today, and -they depend on stack-encrypt instead: - -- `stack-guest-abi` uses the plaintext model and the transport frame for - `HostValue`. -- The EQL encryption tests (`packages/eql/tests/encryption`). - -`eql-bindings` already reaches these through stack-encrypt. - -## The order of work - -Each stage is one or more pull requests. Each must pass the known-answer -tests from stage 1 with no change to the pinned bytes. - -### Stage 1: pin every stored and wire format - -Before any code moves, add known-answer tests for everything that is stored -or that crosses to a host: - -- the leaf ciphertext, its additional authenticated data (AAD), and - `WIRE_VERSION`; -- the AAD of a map entry, a sequence element, and a typed null; -- transport frames and passthrough frames; -- PRF key blocks, and the equality and match terms made from them; -- CLLW ORE, OPE, and block ORE terms, for every order target. - -Some of these exist already: - -- vitaminc: the storage corpus in `packages/aead-frame/testdata`, with an - append-only check, and the normalization known answers in - `packages/normalize/tests/known_answers.rs`; -- ore.rs: `clww-ore/src/known_answers.rs` and - `ore-rs/src/scheme/chained/compat_vectors_data.rs`. - -The work is to find the gaps, fill them, and run the whole set from -stack-encrypt against the crates.io versions it uses today. - -### Stage 2: copy the code in, unchanged - -Copy the crates in at the versions stack-encrypt's `Cargo.lock` resolves -when the stage starts. Keep their names, and make them members of the root -workspace with `publish = false`. Point stack-encrypt and the other crates at -them by path. Port their tests, fuzz targets, and benchmarks with them. - -This stage changes no behaviour, so it is easy to review: the copied source -can be compared with the published crates file by file. - -Bring the history with the code if possible, as was done for the EQL subtree -and the stack-* crates. - -At the end of this stage stack-encrypt cannot be published, because it -depends on unpublished path crates. Stage 3 must land before the next -stack-encrypt release. - -### Stage 3: fold the crates into stack-encrypt - -Turn each copied crate into a module of stack-encrypt, then merge it with what -stack-encrypt already has: - -- **One record model.** `EncryptTarget` is the only way to encrypt a record. - `EncryptTarget` moves a passthrough field when the record is owned. -- **The planning sink and the type-erased tree stay** for the dynamic engine. - The dynamic engine encrypts values from Go and JavaScript. -- **Frames stay** as the format for values that cross to a host. -- Delete the code listed in "Code that is deleted, not moved". - -This stage can be several pull requests, one per area. The stage 1 tests pin -the bytes throughout. - -### Stage 4: move the Go packages - -Move `vcffi` and `vcvalue` into the Go module, update the imports, and delete -the pseudo-version pin from `go.mod`. Remove the matching refusal from -`scripts/go-release-version.mjs`. - -### Stage 5: retire the code in vitaminc and ore.rs - -- Delete the moved crates from vitaminc, and remove their features from the - `vitaminc` umbrella crate. Release vitaminc. -- Publish a final release of each moved crate whose README says where the code - now lives. Do not yank any version: old versions must keep building. -- Archive `ore.rs`, after the question below about `cipherstash-client` is - settled. - -## Checks that must move with the code - -vitaminc and ore.rs run checks that the stack repository does not. Each needs -a home in this repository's CI before its code moves: - -- Kani proofs, including `kani-storage`; -- sanitizers; -- the storage corpus append-only check; -- `cargo vet` and `cargo deny`; -- the fuzz targets of the moved crates; -- Miri for the moved crates; -- mutation testing. stack-encrypt already has it, with `--in-diff`. - -The stack repository already runs Miri, fuzzing, mutation testing, and -`cargo udeps` for its own crates. The work is to add the moved crates to -them, and to add the checks it lacks. - -## Settled since the first draft - -vitaminc 0.10.0 was released on 19 November 2026, with vitaminc #616, #617 -and #618 merged. Stage 2 copies 0.10.0 once stack-encrypt depends on it. -Moving stack-encrypt to 0.10 needs `clww-ore` and `ore-rs` releases on -vitaminc 0.10 first (ore.rs #144). - -## Open questions - -1. **Should ore.rs stay open for `cipherstash-client`?** The legacy client, - used by protect-ffi and the EQL tests, depends on an older `ore-rs` from - crates.io. Moving the code does not break the client, because published - versions stay. But a fix to that line of `ore-rs` would have no - repository once ore.rs is archived. -2. **Which licence applies to the moved code?** vitaminc uses the MIT - licence. ore.rs has its own licence file. stack-encrypt has its own - licence file too. Ask the person responsible for licensing whether the - moved code keeps its MIT notice, and what licence the moved ore.rs code - has. -3. **Does anyone outside CipherStash use the vitaminc crates?** The crates - are on crates.io. Nobody has checked who else depends on them. - -## Rules this changes - -Two working rules agreed earlier no longer apply once this lands: - -- "A fix always belongs in vitaminc." The code that rule was about moves to - stack-encrypt. -- "The interop types, such as `FfiValue` and frames, live in vitaminc." The - interop types move with the record layer. - -`AGENTS.md` describes vitaminc as a dependency from crates.io, and lists -`clww-ore` and `ore-rs` among the exact pins in the root `Cargo.toml`. Update -both in the stage that changes them. From 52bddc161b9c77123052dcb800970304f9d7cce1 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Thu, 26 Nov 2026 11:37:57 +1100 Subject: [PATCH 4/9] docs(plans): do not publish the moved crates until stack-encrypt is next released --- ...11-14-move-vitaminc-aead-into-the-stack.md | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md b/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md index dce22b2e1..94f689c9c 100644 --- a/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md +++ b/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md @@ -178,18 +178,35 @@ whole set against the crates.io versions in use today. 3. Point every workspace at them: the root workspace, the TypeScript SDK's workspace, the two Go guests, and EQL's workspace. Each resolves vitaminc on its own today. -4. Publish them from this repository under the same names and version line, - so that the four crates on crates.io and a published `stack-encrypt` all - resolve the same crate. +4. Do not publish them yet. In each workspace, a `[patch.crates-io]` table + makes the four crates from crates.io resolve the in-repository + `vitaminc-aead`. That works while its version stays on the 0.10 line. 5. Move the open vitaminc issues about this code with it: vitaminc #643, #473 and #632. This stage changes no behaviour. The copied source can be compared with the published crates file by file. -To settle before the stage starts: how a workspace build makes the four -registry crates resolve the in-repository `vitaminc-aead` (a `[patch]` table -is the candidate), and who owns the crates on crates.io. +While the crates are unpublished: + +- **`stack-encrypt` cannot be published.** A published crate cannot depend + on a path, and a consumer has no `[patch]` table. +- **The Go and TypeScript SDKs are not affected.** Both build the engine by + path from the tree. +- **`eql-bindings` can be published until step 2.4.** Its `stack-encrypt` + feature is compiled against the `stack-encrypt` on crates.io when it is + published. Stage 1 changes no API, so that still compiles. Step 2.4 changes + the API that `eql-bindings` uses, and from then an EQL release waits for a + `stack-encrypt` release. +- **vitaminc must stop changing these three crates**, or the two copies + diverge. + +### Before the next `stack-encrypt` release + +Publish the three crates from this repository, under the same names. That +needs the crates.io owners and trusted publishing moved here. If stage 2 has +made a breaking change by then, the four crates that depend on +`vitaminc-aead` need a release against it first, or must have moved. ## Stage 2: consolidate From 9fc87528a27992c0e6245cd2bd776d670c5b9f22 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Thu, 26 Nov 2026 11:43:03 +1100 Subject: [PATCH 5/9] docs(plans): move vcffi and vcvalue in a third stage, and delete vcencrypt --- ...11-14-move-vitaminc-aead-into-the-stack.md | 57 ++++++++++++++++--- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md b/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md index 94f689c9c..75174c759 100644 --- a/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md +++ b/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md @@ -9,6 +9,8 @@ Status: draft, rewritten 26 November 2026. Decisions by Dan Draper: - Keep the move as small as possible. `vitaminc-protected` and `vitaminc-random` never move. - No more work on the TypeScript SDK until this is done. +- vitaminc's Go packages `vcffi` and `vcvalue` move too, as a third stage, + before the Go SDK's final release. vitaminc's `vcencrypt` is deleted. The first draft of this plan (14 November) moved nine crates, with `ore.rs`, into `stack-encrypt` as modules. This draft replaces it. @@ -22,7 +24,10 @@ Three crates move from `cipherstash/vitaminc` into this repository: `vitaminc-aead`, `vitaminc-aead-frame` and `vitaminc-aead-derive`. They keep their names and are published from here. -Then the value handling is consolidated. Today the list of value types is +vitaminc's two Go packages, `vcffi` and `vcvalue`, move into the Go module in +a third stage. + +The value handling is consolidated in stage 2. Today the list of value types is written down in vitaminc, written again in the engine (`stack-encrypt`), and reconciled a third time in each language SDK. After this plan: @@ -277,6 +282,45 @@ crate. A UUID then works in every SDK, which closes #1821. +## Stage 3: move the Go packages + +vitaminc has two Go packages that the Go module imports in about 60 places: + +| Package | What it is | +|---|---| +| `vcvalue` | The Go value types: `Date`, `Decimal`, `Int128`, `Uint128`, `Timestamp`, `UUID`, `TypedNull`, `Plain`, `Object`. No dependencies. | +| `vcffi` | The frame codec in Go: frames, ciphertext trees and the storage profile (`MarshalStorage`). | + +They do not link the Rust crates. The Go host encodes a frame and the guest +decodes it, so the two share a byte format and no code. That is why this +stage does not have to run with stage 1. It starts after stage 1 and can run +beside stage 2. + +It must finish before the Go SDK's final release: + +- **The types are in the SDK's public API.** `encrypt.Date`, + `encrypt.Decimal`, `encrypt.Int128` and `encrypt.Uint128` are aliases of + `vcvalue` types. Moving a type changes its package path, which breaks a + user's code after a release. +- **The release is blocked on them.** The packages have no tags, so `go.mod` + pins an unreleased commit, and `scripts/go-release-version.mjs` refuses a + final version while that pin is there. +- **The codec's test data moves in stage 1.** `vcffi`'s tests read the + storage corpus that sits beside `vitaminc-aead-frame`. + +The work: + +1. Move both packages into `languages/golang`, with their tests and fuzz + targets. Decide where each type is declared: the value types are public, + and the codec need not be. +2. Update the imports. Remove the pin from `languages/golang/go.mod` and + from the two nested modules that carry it. +3. Remove the matching refusal from `scripts/go-release-version.mjs`. +4. Apply stage 2 to them. `vcvalue.FixedType` is one more copy of the type + list. +5. Delete `vcencrypt` and its guest from vitaminc. It was a demonstration of + the approach, and the Go module replaces it. + ## What waits on this plan - The TypeScript SDK: #1775, #1776 and the prototype #1829. @@ -285,6 +329,7 @@ A UUID then works in every SDK, which closes #1821. - The language integration guide's new sections on the value model (#1828). They describe the model this plan removes. - The UUID fix (#1821). +- The Go SDK's final release, on stage 3. ## Checks that must move with the code @@ -318,15 +363,11 @@ repository's CI before its code moves: it no type, and does not treat it as a null. No test covers it against a nullable field. 5. **Does the order index take bytes and a UUID?** See 2.3. -6. **Do Go's `vcffi` and `vcvalue` move?** They are vitaminc's Go packages, - with their own encoder, pinned at an unreleased commit. The Go release - script refuses a final version while that pin is there. They are a bridge, - so the consolidation applies to them, but they are not Rust crates. -7. **Which licence applies to the moved code?** vitaminc uses the MIT +6. **Which licence applies to the moved code?** vitaminc uses the MIT licence. Ask the person responsible for licensing. -8. **Does anyone outside CipherStash use the moved crates?** They are on +7. **Does anyone outside CipherStash use the moved crates?** They are on crates.io. Nobody has checked. -9. **What is a frame called?** "Frame" does not say whether it is a transport +8. **What is a frame called?** "Frame" does not say whether it is a transport or a storage format. Rename it during stage 2, where the type is already being replaced. From 121f10e0a3f7d4d28929200110b52b5a0c0c0de3 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Thu, 26 Nov 2026 11:46:48 +1100 Subject: [PATCH 6/9] docs(plans): record the order index, licence and outside-use decisions --- ...26-11-14-move-vitaminc-aead-into-the-stack.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md b/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md index 75174c759..c8fe18300 100644 --- a/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md +++ b/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md @@ -11,6 +11,9 @@ Status: draft, rewritten 26 November 2026. Decisions by Dan Draper: - No more work on the TypeScript SDK until this is done. - vitaminc's Go packages `vcffi` and `vcvalue` move too, as a third stage, before the Go SDK's final release. vitaminc's `vcencrypt` is deleted. +- An order index takes no bytes and no UUID. +- The moved code keeps the MIT licence, which is this repository's licence. +- Nobody outside CipherStash uses the moved crates. The first draft of this plan (14 November) moved nine crates, with `ore.rs`, into `stack-encrypt` as modules. This draft replaces it. @@ -251,9 +254,9 @@ parameter (`timestamp(ms)`, `decimal(2)`). Delete the allow-list. An index refuses a type it cannot handle: - **Equality:** already asks `vitaminc-normalize`. -- **Order:** `vitaminc-ore` already refuses a boolean and an 8-bit integer. - The engine also refuses bytes and a UUID, which `vitaminc-ore` allows. - Decide whether that stays, and put it in one place. +- **Order:** no boolean, no 8-bit integer, no bytes and no UUID. + `vitaminc-ore` already refuses the first two. It allows bytes and a UUID, + so the engine's order index refuses those, in one place. - **Match:** text only. A plan is refused when it is built, before a value arrives. The index answers @@ -362,12 +365,7 @@ repository's CI before its code moves: 4. **Is `undefined` a null to a typed field?** The engine accepts it, gives it no type, and does not treat it as a null. No test covers it against a nullable field. -5. **Does the order index take bytes and a UUID?** See 2.3. -6. **Which licence applies to the moved code?** vitaminc uses the MIT - licence. Ask the person responsible for licensing. -7. **Does anyone outside CipherStash use the moved crates?** They are on - crates.io. Nobody has checked. -8. **What is a frame called?** "Frame" does not say whether it is a transport +5. **What is a frame called?** "Frame" does not say whether it is a transport or a storage format. Rename it during stage 2, where the type is already being replaced. From 657f474a50f9a8c77ca42eeed4a27510e06842de Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Thu, 26 Nov 2026 11:52:18 +1100 Subject: [PATCH 7/9] docs(plans): record the conversion, null, json and undefined decisions --- ...11-14-move-vitaminc-aead-into-the-stack.md | 61 +++++++++++++------ 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md b/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md index c8fe18300..35721166d 100644 --- a/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md +++ b/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md @@ -245,6 +245,18 @@ the conformance corpus all use them, so they do not change. `scalar_kind`, `scalar_of` and `sealed_null` become methods of that type, or are deleted. +The type covers every scalar, and an array and an object, which are shapes of +the AEAD encoding. It does not cover `json`. A JSON field's value is text or +bytes, and `json` only tells the engine to parse it for the JSON index. So a +plan field's type is an AEAD type or `json`, and `json` belongs to the JSON +index. + +The type also gives the width a sealed null is padded to. A field's declared +type is the only thing that decides that width. A host can send a null with +a type of its own, and the frame writer drops that type, as it does today. +If the host's type counted, it could disagree with the declaration, and a +null padded to the wrong length would show that it is a null. + vitaminc has no such type today. `Kind`, `Width`, `KnownLogical` and `FixedType` each cover part of it, and its only text names include a parameter (`timestamp(ms)`, `decimal(2)`). @@ -273,7 +285,29 @@ This is the widest step. `ValueFrame` is named in about 50 files of `eql-bindings`, which is published, so this is a breaking release of that crate. -### 2.5 The bridges and the SDKs +### 2.5 One place converts a value to its declared type + +Today Go converts a value to the field's type on the host, the engine +refuses a write whose width differs from the declared type, and the engine +converts a query's value when the conversion is exact. A JavaScript `bigint` +has no width, so the bridge writes the narrowest one that fits, and a +JavaScript user cannot write `34n` to an `int64` field. + +The exact conversion the engine uses for a query also runs on a write, in +one place. A bridge is never told the declared type. The conversion is never +lossy, never between a number and a value that is not a number, and never +from a float to a decimal. The value is sealed at the declared width, so no +stored bytes change. The conformance cases that pin today's refusal change +from refused to accepted. + +A typed field takes a value of its type or a null, and nothing else. +JavaScript's `undefined` is refused with an error of its own, and a +conformance case pins that. Today it is refused only because it has no type, +with a general error, and no test covers it. Storing it as a null would hide +a misspelt property name. Inside an untyped value, `undefined` is kept as it +is today. + +### 2.6 The bridges and the SDKs - **TypeScript:** the addon hands the bridge's frame to the engine with no second copy. `OneValue`, `is_uuid`, and the `recipher_js::uuid` code are @@ -349,25 +383,12 @@ repository's CI before its code moves: ## Open questions -1. **Who converts a value to its declared type on a write?** Today Go - converts on the host, the engine refuses a mismatch, and the JavaScript - bridge cannot know the width of a `bigint`. Either the AEAD crates convert - a value to a declared type when the conversion is exact, as the engine - already does for a query, or every bridge is told the declared type. The - first keeps a bridge free of types. It also changes a rule the conformance - corpus pins: a value of another width is refused on a write. -2. **Is a host's typed null kept?** The frame writer drops the type, and a - plan's `"null": "sealed"` adds the padding back from the declared type. - Once the declared type is an AEAD type, the two overlap. -3. **Where do `json`, `array` and `object` live?** They are `ValueKind` - variants and not scalar types. No index takes an array or an object, and - Go has no constant for either. -4. **Is `undefined` a null to a typed field?** The engine accepts it, gives - it no type, and does not treat it as a null. No test covers it against a - nullable field. -5. **What is a frame called?** "Frame" does not say whether it is a transport - or a storage format. Rename it during stage 2, where the type is already - being replaced. +1. **What is a frame called?** "Frame" does not say whether it is a transport + or a storage format. Rename it in step 2.4, where the type is already + being replaced. Stages 0 and 1 do not need the answer. "Transport" is the + candidate: the Go codec's documentation and the language integration + guide already use it. "Wire" is taken: the sealed leaf's version constant + is `WIRE_VERSION`. ## Rules this changes From 1d17ab0ae03dbda372a4c03354a64b9d445e036e Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Thu, 26 Nov 2026 11:54:48 +1100 Subject: [PATCH 8/9] docs(plans): bring the history, and freeze the vitaminc copies but keep them --- .../2026-11-14-move-vitaminc-aead-into-the-stack.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md b/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md index 35721166d..7c633df6d 100644 --- a/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md +++ b/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md @@ -179,8 +179,8 @@ whole set against the crates.io versions in use today. ## Stage 1: move the three crates, unchanged 1. Copy the three crates in at the version the root `Cargo.lock` resolves. - Keep their names. Bring their history if possible, as was done for the - stack-* crates. + Keep their names. Bring their git history, as was done for the stack-* + crates. 2. Bring their tests, fuzz targets and benchmarks, and the checks under "Checks that must move with the code". 3. Point every workspace at them: the root workspace, the TypeScript SDK's @@ -206,8 +206,10 @@ While the crates are unpublished: published. Stage 1 changes no API, so that still compiles. Step 2.4 changes the API that `eql-bindings` uses, and from then an EQL release waits for a `stack-encrypt` release. -- **vitaminc must stop changing these three crates**, or the two copies - diverge. +- **vitaminc stops changing these three crates as soon as the copy is + taken**, or the two copies diverge. The crates stay in vitaminc, unchanged, + until everything in this plan is settled, so that the move can be backed + out. They are deleted from vitaminc only then. ### Before the next `stack-encrypt` release From 2f5ae372397166c65917cb53c8ab331e0fef6596 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Thu, 26 Nov 2026 11:55:15 +1100 Subject: [PATCH 9/9] docs(plans): name every workspace that resolves the AEAD crates --- .../2026-11-14-move-vitaminc-aead-into-the-stack.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md b/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md index 7c633df6d..b675457e0 100644 --- a/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md +++ b/docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md @@ -183,9 +183,15 @@ whole set against the crates.io versions in use today. crates. 2. Bring their tests, fuzz targets and benchmarks, and the checks under "Checks that must move with the code". -3. Point every workspace at them: the root workspace, the TypeScript SDK's - workspace, the two Go guests, and EQL's workspace. Each resolves vitaminc - on its own today. +3. Point every workspace at them. Each resolves vitaminc on its own today: + - the root workspace, where `stack-encrypt` and `stack-guest-abi` name + the crates, and where the `vitaminc` umbrella crate depends on + `vitaminc-aead`; + - the TypeScript SDK's workspace, and the bridge's test addon, which is a + workspace of its own; + - the two Go guests; + - EQL's workspace, for its encryption test crate; + - the detached fuzz crate `packages/stack-encrypt/fuzz`. 4. Do not publish them yet. In each workspace, a `[patch.crates-io]` table makes the four crates from crates.io resolve the in-repository `vitaminc-aead`. That works while its version stays on the 0.10 line.