Repository navigation
Conversation
One napi-rs 3 crate, recipher-js, defines the Cipher, Keyset and Ciphertext classes and runs encrypt and decrypt of one string through the engine. @napi-rs/cli v3 builds it and writes its TypeScript declarations to the committed native.d.ts. The TypeScript holds Result, RecipherError, the typed signatures over the native methods, and the adapter that turns each native outcome into a Result, so no call throws.
keyset.encrypt takes every value in vitaminc's JavaScript mapping, an array of them in one key request, and a JSON document made with json(..), a native class that reads the document when it is made. Ciphertext carries the kind it opens as, and Ciphertext.fromBytes(bytes, kind) reads stored bytes as a kind, kinds.json among them. vitaminc's refusals each get a code of their own. The binding interface is 2.
record(..), encrypt(..) and passthrough() declare a record as plain data. The crate builds the engine's plan from it with the engine's own types, once for each declaration, and encrypts and decrypts rows, and one field or an array of one field, through dynamic::Planned. A refusal names the record and the field. A decrypted row's inspect hides its values. The binding interface is 3.
…causes A RecipherError held the engine's code and a message with the help appended to it, and two of the structured fields. It now holds the whole diagnostic, as the Go SDK's does: help and url as properties of their own, every structured field, and the cause chain. A cause from another library is named as one and its message is never copied. A test lists every code the SDK gives an error of its own and checks each one's form.
miette's Diagnostic has a severity, and the Go SDK's Diagnostic carries it. A RecipherError now does too: error unless the engine's diagnostic states warning or advice.
fields holds every structured field of the engine's error, the reason token among them, so the typed reason property was the same string a second way. It is removed. field and record stay: the SDK names them where the engine does not.
recipher-value-napi is vitaminc-aead-napi 0.10.0, copied from cipherstash/vitaminc at b3f69b12 and renamed, as an unpublished member of the recipher-js workspace at value-napi/. The addon depends on it by path in place of the crates.io crate, so the value mapping can change in the pull request that needs the change. The source files are unchanged. The manifest, the README, the docs.rs links, the test addon's dependencies and two test paths are edited for the new home. vitaminc's value conformance corpus comes with it, at the same commit.
…ue broke The bridge reported a refusal as a Node-API status and a sentence, and the addon found out which refusal it was by matching the start of the sentence against a table, with a second table repeating the six scalar codes. A reworded message would have turned a specific code into the generic one with no test failing. The bridge now has a Refusal enum, a miette diagnostic with a code and a message for each rule, and JsFault carries it. JsRef::to_frame and JsBuilder::build return the JsFault. The addon reads the variant; both tables and the code that read `code` off a thrown error are gone. The codes a caller sees are unchanged. Closes #1799
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 |
coderdan
force-pushed
the
chore/recipher-value-napi
branch
from
November 24, 2026 12:18
ec655d7 to
4881e04
Compare
This was referenced Nov 24, 2026
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
Closes #1799. On top of #1794.
When the value bridge (
recipher-value-napi) refuses a JavaScript value, it now says which rule the value broke as a typed value, so the addon no longer works it out from the wording of a message.Before, a refusal was a Node-API status and a sentence. The addon compared the start of the sentence against a table to pick a code, and a second table repeated the bridge's six scalar codes. A reworded message in the bridge would have silently turned a specific code into the generic
recipher::value.The codes a caller sees are unchanged. The package is private, so there is no changeset.
Changes
In the bridge (
value-napi/):Refusalenum, one variant for each rule: not a plain object, a reserved property name, nested too deeply, a sparse array, bytes of the wrong kind, a type with no value, an object that changed while it was read, an unpaired surrogate, and a refused scalar. It derivesmiette::Diagnostic, so each variant has a code and a message, and two have help.ConversionError(the six scalar refusals) derivesDiagnostictoo, with theERR_…codes it already had.JsFaultcarries an optionalRefusal.JsFault::refusal()returns it. It isNonefor a failure of Node-API itself and for an exception the application threw.JsRef::to_frameandJsBuilder::buildreturnResult<_, JsFault>instead ofnapi::Result, so the variant reaches the caller. AJsFaultstill converts to a napi error with?, and the text JavaScript sees when the bridge is used directly is unchanged, so the bridge's four Node suites pass untouched.JsFaultinstead of a napi error.In the addon (
crate/src/js.rs):refusedreadsfault.refusal()and converts the diagnostic.WALK_REFUSALS,VITAMINC_CODESandvitaminc_code(which readcodeoff a thrown error) are deleted: about 110 lines.not_builtmatchesRefusal::ReservedKeyinstead of the start of a message.What changes for a caller
invalid UUID) where they were the addon's own (a VcUuid's text is not a UUID). The other messages are the addon's old ones, moved into the enum.recipher::not_plainandrecipher::sparse_arraynow havehelp.Verification
Run locally:
cargo test --locked --all-features:recipher-js39 and 4;recipher-value-napi33 (two new: every refusal has a code of its own, and a fault says which refusal it is); its Node suite against the test addon passed.cargo fmt --all --checkand clippy with-D warnings: clean.tsc --noEmit: clean.native.d.tsunchanged.Review notes
ERR_…codes keep their names. They are also the codes of theTypeErrorthe bridge throws when used directly, and the bridge's Node suites assert on them. Engine errors have codes but no documentation links — decide the URL format and give every code a page #1790 asks what they should be called in the SDK.TypeErrorfor a refused scalar, and the addon clears it. The addon is the only caller now, so the bridge could stop throwing. That would change the bridge's own Node suites, so I left it.mietteand its two dependencies. Nothing else in it moved.ErrorKindand string codes.RecipherErrorre-describes the engine's errors with akindand string-literal codes — make it the diagnostic and nothing else #1800 removes those.Related
RecipherErrorre-describes the engine's errors with akindand string-literal codes — make it the diagnostic and nothing else #1800 (next: the error is the diagnostic and nothing else).