Repository navigation
Conversation
Encrypt every value in vitaminc's JavaScript mapping: text, booleans, numbers, bigints at every width, bytes, a Date, and vitaminc's VcDate, VcTimestamp and VcDecimal, which the package re-exports. Values are read and built only through vitaminc-aead-napi. Each value goes through the engine's own opaque scalar path (keyset.encrypt), so its ciphertext is the one Rust and Go write for it. An array in is an array out: the engine's collection path makes one key request each way, which a Rust test counts. json(value) seals a document as the engine's JsonPlaintext. The conversion from a frame to the document is in the core crate: an integer outside a number's safe range is a bigint, an unsafe integer held as a number is refused, and the engine's parser reads the result. A plain object is refused, as is a UUID, which the engine's value model does not hold.
|
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Step 2 of phase 1 of the TypeScript SDK plan (#1747), on top of #1774.
@cipherstash/reciphernow encrypts every value in vitaminc's JavaScript mapping, an array of values in one key request, and a JSON document withjson(..). A value's type picks how it is encrypted; no call names a kind.The package is still private and takes no changeset.
Changes
Values.
keyset.encrypt(value)takes astring,boolean,number(a float),bigint(an integer at the narrowest width that holds it),Uint8ArrayorBuffer(bytes),Date,VcTimestamp,VcDate,VcDecimalornull, and returns aCiphertext<T>typed by what it decrypts as (Opened<V>). vitaminc's four wrapper classes are re-exported. The addon reads and builds every value withvitaminc-aead-napi(JsRef::to_frame,JsBuilder::build); it has no conversion of its own.The engine's own path. The core crate now seals each value through the engine's opaque scalar path,
keyset.encrypt(value), by way of a smallSealabletype that is one vitamincScalar. So each ciphertext is exactly what Rust'skeyset.encryptand Go write for that value. (Step 1 usedencrypt_treewith an empty context; a test showed the bytes open either way, and this removes the question.)Arrays.
keyset.encrypt([a, b, c])returns an array of ciphertexts, anddecryptof an array returns an array, in order. Both go through the engine's collection path (Vec<_>::encrypt_into,Vec<ValueFrame>::decrypt_from), which merges the elements' key requests into one. All or nothing: one refused element is anErrfor the array, before any request.JSON documents.
json(value)seals a document as the engine'sJsonPlaintext: one ciphertext holding its JSON text. The core crate converts the frame to a document (crates/core/src/json.rs): an integer outside anumber's safe range is abigint; anumberthat is an integer outside that range is refused, because its digits are not the number the caller meant; abigintis written as its digits; bytes, dates andundefinedare refused. On decrypt, the engine's parser reads the text, and an integer outside the safe range comes back as abigint.Refusals, as
Errvalues. A plain object,Map,Setor class instance (recipher::plain_object),undefined, an array inside an array, abigintof more than 128 bits and a string with an unpaired surrogate (vitaminc's refusals), and aVcUuid(the engine's).What the tests prove
Rust (
crates/core/tests/values.rs):i8,u64::MAX,i128::MIN, bytes, null, a date, a nanosecond timestamp, a decimal) round-trips as itself, byte for byte.generate_keysand oneretrieve_keys. An empty array makes none. A refused element makes none.keyset.decrypt::<String>and::<i64>open them.json(..)ciphertext opens with the engine's typedkeyset.decrypt::<JsonPlaintext>, as the same document,u64::MAXincluded.TypeScript (
__tests__/addon/values.test.ts, 22 tests): each row of the mapping round-trips through stored bytes; a timestamp of whole milliseconds opens as aDateand a finer one as aVcTimestamp; arrays (in order, one element alone, mixed types, empty, refused whole); JSON documents (nested,bigintoutside the safe range, refusals); and each refusal resolves to anErr, with no plaintext in its message.type-tests/values.tschecks the types: each value'sCiphertext<T>, a literal widening to its type, arrays, decrypt's result, and that a plain object, aVcUuid,undefined, aMap, and bytes or aDateinsidejson(..)do not compile.Verification
Run locally on macOS (arm64), Rust 1.94.1, Node 24, pnpm 10.33.2:
cargo fmt --all --check: passed.cargo clippy --locked --all-targets --all-features -- -D warnings: passed.cargo test --locked --all-features: 30 passed (13 unit, 3 boundary, 7 round-trip, 7 value).pnpm --filter @cipherstash/recipher build: passed.pnpm --filter @cipherstash/recipher build:debugthentest:addon: 35 passed.pnpm --filter @cipherstash/recipher test(unit suites andtscwith the type tests): 16 passed, typecheck clean.pnpm run code:check: no errors.pnpm run test:scripts: 96 files passed.Not run: anything against a live ZeroKMS. CI runs on this PR's push; see the checks.
Deviations from the plan
opaque(..)is not here. See "Needs from the engine".VcUuidis refused. The plan's table lists it. The engine's value model (ValueFrame) refuses a UUID, and the plan says to follow the engine. The class is still re-exported, and its type is left out ofScalar, sokeyset.encrypt(uuid)does not compile.Ciphertextfromencrypt(json(..))remembers it; one fromCiphertext.fromBytes(bytes)does not, and opens as the JSON text. TypedfromBytes(the plan'sCiphertext.fromBytes(bytes, kinds.json)) needskinds, which arrive with records in step 3.Dateis stored as nanoseconds, not milliseconds. vitaminc reads aDateas milliseconds, and the engine's value model stores every timestamp in nanoseconds. It still opens as the sameDate.record-values-v1), which is a record profile and needs step 3; running vitaminc's ownvalue-conformance.cjsagainst this addon, which is written against vitaminc's test addon's exports; and the fuzz target. Each is listed under "Issues to open" in the stack's report.TypeErrorthat says why. Every other call still returns anErr.Needs from the engine
opaque(..)(the engine'sOpaqueBlobformat) for a value whose type is known only at run time.OpaqueBlob<T>writes vitaminc's storage profile throughserde::Serialize, so it needs a Rust type. A binding holds a frame, and the engine has no function that writes the storage profile from a frame or reads one back into a frame. Writing that mapping in the SDK would make choices that decide whether Rust and Go can read the bytes (a JavaScriptnullasNoneor as unit, a map key's kind, how a date or a decimal is written). So this step does not invent it. What is missing: an engine (or vitaminc) entry point, frame to storage-profile bytes and back, with the mapping written down once for every binding.ValueFramerefuses a scalar with vitaminc'sUuidlogical type, so no binding can encrypt one throughdynamic, while Rust can encrypt auuid::Uuid.Related
Refs #1747 (the plan). Based on #1774.