Skip to content

@cipherstash/recipher cannot encrypt a whole object with opaque(..) — write and read the storage blob from a JavaScript value #1822

Todo

Description

@coderdan

Background

@cipherstash/recipher is the TypeScript SDK on Stack Encrypt (the Rust crate stack-encrypt). Its plan has opaque(value): encrypt a whole JavaScript object as one ciphertext, under one data key, with nothing inside it searchable. Rust has the same thing as OpaqueBlob<T>, and Go has it as an opaque struct.

All three store an opaque value the same way. The value is written as a storage blob: vitaminc's storage profile, a frozen, versioned binary encoding that starts with "VCS" and a version byte (vitaminc_aead_frame::storage, specified in vitaminc's STORAGE.md). The blob is then encrypted as an ordinary bytes value.

Problem

The TypeScript SDK has no way to write or read a storage blob from a JavaScript value, so opaque(..) is not built (#1775 left it out).

A JavaScript value reaches Rust as a frame: vitaminc's transport encoding, which the value bridge (recipher-value-napi) writes from a live JavaScript value. The frame and the storage profile share their scalar encodings and their array and object layout, but nothing converts one into the other. storage::to_vec only takes a Rust Serialize, and storage::from_slice only gives one back.

Verified on next with a small program against the engine:

  • The ciphertext of an OpaqueBlob decrypts as a Vec<u8>, and the bytes are exactly the blob OpaqueBlob::encode writes.
  • A blob encrypted as a plain Vec<u8> decrypts as the OpaqueBlob it encodes.

So the engine needs no new entry point. What is missing is the conversion between a JavaScript value and a storage blob.

One rule carries over from the format: version 1 of the storage profile holds plain scalars only, with no logical types. A Date, a VcDate, a VcDecimal or a VcTimestamp inside an opaque object has no storage form. In Go, vcffi.MarshalStorage refuses a value with no storage form, and opaqueBytes reports it as an encoding error. Whether a Go time.Time field hits that refusal has not been checked.

Proposal

  1. Write a blob from a JavaScript value. Walk the value the bridge reads (a JsRef, or the frame it snapshots) into a storage blob. The two formats differ in four ways: the blob's header, a marker for a present optional value, a map node whose keys keep their type, and no logical types. Refuse a logical type with a typed refusal that names the property, such as recipher::no_storage_form.
  2. Read a blob into a JavaScript value. Decrypt as bytes, check the "VCS" header, and build the value with the bridge's JsBuilder. Refuse a blob with a later version, or one that is malformed, with the storage profile's own error kinds.
  3. Add opaque(value) to the core, returning a Ciphertext that decrypts to the object. Add exchange tests in which a blob written by Rust's OpaqueBlob and by a Go opaque struct opens in TypeScript, and one written by TypeScript opens in both.
  4. Decide where the converter lives. It can sit in the value bridge, or in vitaminc-aead-frame beside the storage profile, where it could be shared with a future wasm build. This depends on which vitaminc code moves into this repository.

Relationship to other work

Activity

  1. added
    enhancement
    JavaScript
    on Nov 25, 2026
  2. self-assigned this
    on Nov 25, 2026
  3. coderdan commented on Nov 25, 2026

    @coderdan
    ContributorAuthor

    The converter itself is now tracked upstream: cipherstash/vitaminc#643 (frame to storage blob and back, and whether storage version 2 adds dates and UUIDs).

  4. coderdan commented on Nov 25, 2026

    @coderdan
    ContributorAuthor

    Checked: Go does not refuse time.Time in an opaque struct. vcffi.MarshalStorage writes a type that formats itself as text as text, so a time.Time is stored as RFC 3339 text and opens as text, not a timestamp. What Go refuses is its logical-type values (encrypt.Date, encrypt.Decimal) and a passthrough, with vcffi.ErrUnwritable (vcffi/storage.go at the version languages/golang/go.mod pins). So the TypeScript converter has a choice to make for a Date: refuse it, or write it as text as Go does. #1828 documents both rules in the integration guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

JavaScriptSDKenhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions