Repository navigation
Description
Background
Stack Encrypt (packages/stack-encrypt) is the Rust library that does the encryption for every CipherStash language SDK. A language SDK reaches it through a language binding: a thin layer of Rust between the language and Stack Encrypt.
When Stack Encrypt encrypts a record, the result is a tree, StackCipherText. The tree has one entry for each field. A field's entry has one node for each output. c is the ciphertext. eq, match, ore, and ope are the index terms.
A decrypt call takes the same tree back.
The rule for bindings is that the code exists once, in Stack Encrypt. A binding does not repeat that code. A binding does not work around something that Stack Encrypt lacks.
Problem
A binding has to move that tree to its language and back. Stack Encrypt gives it no way to do that.
- The tree's type is
CipherText<Leaf, P>(packages/vitaminc-aead/src/container.rs). It has noSerializeorDeserialize. Its doc says that each host converts it to its own structures. - The leaf,
SealedValue, does have serde and a byte form (packages/stack-encrypt/src/cipher.rs).
So each binding writes the conversion itself:
- Go. The guest has
encode_tree,decode_tree,map_leaves, andtree_encoded_len(languages/golang/encrypt/guest/src/ops.rs). They walk the tree, convert each leaf to bytes, and write the transport encoding. The Go module then decodes that encoding in Go. - TypeScript. The binding in feat(recipher-js): records through the engine's Planned #1776 has
stored_rowandstored_tree, about 170 lines. They walk the tree in both directions. They also rename Stack Encrypt's output names, and check the tree's shape a second time.
Each copy is code that can go wrong at a security boundary. A tree that a binding reads comes from storage, so an attacker can write it. Stack Encrypt already checks a tree's shape when it decrypts. A second check in each binding can disagree with it.
Proposal
- Give the encrypted tree one conversion that every binding uses. The simplest form is serde on the tree, with each leaf written as its bytes (
SealedValue::to_bytes). A binding then writes the tree to a frame with the frame's serde (recipher-frame), and reads it back the same way. - Decide where that lives: on
CipherTextinvitaminc-aead, or as a function instack_encrypt::dynamicoverStackCipherText. - Keep Stack Encrypt's output names as they are:
c,eq,match,ore,ope, andpassthrough. No binding renames them. - State that this is a transport form and not a storage format, as the leaf's serde already says.
Relationship to other work
-
Follow-ups, outside this issue: the rework of feat(recipher-js): records through the engine's Planned #1776 replaces the TypeScript binding's
stored_rowandstored_treewith this conversion. A later change replaces the Go guest'sencode_tree,decode_tree, andmap_leaves. -
stack-encrypt: bindings send a serialised
Planned, and the conformance corpus is written as one #1594 asks for one entry point that reads a serialisedPlanned. It covers what a binding sends. This issue covers what a binding gets back, and what it sends to decrypt. -
feat(recipher-js): records through the engine's Planned #1776 is the TypeScript record pull request with its own conversion.
-
The TypeScript SDK plan (
docs/plans/2026-11-22-recipher-typescript-sdk.md, updated in docs(plans): correct the TypeScript SDK plan on numbers, nesting and UUIDs #2019) lists this gap.
Activity
docs(plans): the TypeScript records step waits for #2029 and #2028
coderdan commentedon Nov 30, 2026
The typed record that this issue asks for is being built in #2031. Its target output is named
target, noteql. #2033 covers the same rename for the tree form and the rest of Stack Encrypt.