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