Skip to content

Seal every timestamp in nanoseconds in vitaminc-aead, not by the engine's rewrite #1846

Done

Description

@coderdan

Background

vitaminc-aead (now in this repository at packages/vitaminc-aead) seals each value as a leaf. A timestamp has a short leaf form for nanoseconds (tag 0x13). A timestamp in any other unit (seconds, milliseconds, microseconds) is sealed in a longer, generic envelope (0xF3 …) of a different length.

Every timestamp stored through the Stack Encrypt engine today is in nanoseconds, because the engine rewrites the unit before sealing (model in packages/stack-encrypt/src/dynamic/value_frame.rs). That rule lives in the engine, not in the crate that owns the encoding.

The TypeScript SDK's value bridge (recipher-value-napi) writes a JavaScript Date as a timestamp in milliseconds, and relies on the engine to rewrite it.

Problem

  • The rule that a timestamp is sealed in nanoseconds is enforced by one caller, the engine. Any other path into vitaminc-aead can seal a timestamp in another unit, which gives the same instant a different stored length and bytes, and a sealed null of a different length from its values.
  • The bridge's README says a Date is stored as its millisecond count, which is false once the value passes through the engine.
  • Plan step 2.3 deletes the engine's allow-list. If the rewrite went with it, a JavaScript Date would seal as a 12-byte envelope where Go and Rust write the 13-byte nanosecond leaf.

Proposal

  1. In vitaminc-aead, seal every timestamp in nanoseconds, whatever unit it arrives in, and give a timestamp's typed null the nanosecond width. Keep reading every unit, so anything already sealed in another unit still opens.
  2. In recipher-value-napi, write a JavaScript Date as a timestamp in nanoseconds, so its frame matches the conformance corpus.
  3. Delete the engine's timestamp rewrite (in model and model_null). The rest of the allow-list stays until step 2.3.
  4. No stored byte changes. The stage 0 pins (packages/stack-encrypt/tests/value_bytes.rs, the conformance suites, EQL's encryption tests) pass unchanged. The bridge's pinned Date frames change on purpose, and now match the corpus.

Step 2.1 of docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md. Part of #1831.

Metadata

Metadata

Assignees

Labels

RustSDKenhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions