Skip to content

feat(recipher-js): every value type, arrays and JSON documents - #1775

Draft
coderdan wants to merge 1 commit into
nextfrom
feat/recipher-js-values
Draft

coderdan wants to merge 1 commit into
nextfrom
feat/recipher-js-values

Conversation

@coderdan

@coderdan coderdan commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #1812

This PR lets @cipherstash/recipher encrypt every value type in the value bridge's mapping, arrays of values, and JSON documents. A value's type decides how it is encrypted; no call names a type. A ciphertext read back from stored bytes can be given a kind (a value type, such as kinds.string), so a stored JSON document decrypts as the document and not as its text.

It follows #1774's design: every native method builds its Result in Rust, and the signatures are written on the Rust methods, so the generated native.d.ts is the public type. There is no TypeScript layer that wraps the native methods.

The package is private and not published, so there is no changeset.

Changes

Values. keyset.encrypt(value) takes a string, boolean, number (a float), bigint (an integer at the narrowest width that holds it), Uint8Array or Buffer, Date, VcTimestamp, VcDate, VcDecimal, null, or a Json. It resolves to a Result of a Ciphertext<T>, where T is the type it decrypts to. The addon exports the bridge's wrapper classes, and the package re-exports them.

Arrays. An array in gives an array out, in the same order, through the engine's collection path: one key request each way. If one element is refused, the whole array is an Err, before any request.

JSON documents. json(document) is a native function that returns a native Json. It reads the document when it is called, and never throws. The conversion is in crate/src/json.rs:

  • an integer outside a number's safe range is a bigint, within the 64-bit range the engine's parser reads;
  • a whole number between 2^53 and 2^64 is refused, because an integer was likely meant; any other finite number, such as 1e20, is a float;
  • a document nested deeper than 127 levels is refused as recipher_js::too_deep;
  • a map key is kept in Zeroizing until it is in the object, so a refused member leaves no unwiped copy.

Reading stored bytes as a kind. Ciphertext.fromBytes(bytes, kinds.string) is typed Ciphertext<string>. Decrypting it refuses a value encrypted as another type (recipher_js::opened_type). An integer kind takes an integer of any width that fits. kinds.json decrypts the text as a document. Ciphertext.fromBytes(bytes) with no kind is a Ciphertext<OpenedScalar>: it can decrypt to any scalar.

Signatures. The new overloads are ts_type strings on the Rust methods, one per line: encrypt and decrypt on an array (crate/src/cipher.rs), and fromBytes<K extends Kind>(bytes, kind) (crate/src/ciphertext.rs). json takes a JsonValue. native-header.d.ts imports the types they name, makes Ciphertext's default OpenedScalar, and marks Json so no other object type-checks as one.

Where the value types live. The types the signatures name (Value, Opened, OpenedScalar, JsonValue, the wrapper interfaces) are in src/value-types.ts, which imports nothing. native.d.ts imports them, and a module that loaded the addon would make the declarations import themselves, which the declaration bundler cannot build. src/values.ts keeps the runtime part: the wrapper classes and json, with stand-ins.

Errors. Each new refusal is a variant of the SDK's error enum, with its own code: recipher_js::undefined, uuid, not_a_scalar, plain_object, not_json, too_deep, not_sealed, not_a_kind, opened_type and not_a_document. The skeleton's recipher_js::not_a_string is gone. The bridge's refusals keep the bridge's codes. recipher_js::reserved_key reaches the caller on decrypt too, through the bridge's Refusal.

Decrypting through open_in. The array and kind decrypt path runs through #1774's open_in, so keyset confinement stays in one place.

AGENTS.md. The recipher-js entry now names the Json class, and says that src/kinds.ts and src/value-types.ts hold the types the generated signatures name and must never load the addon.

Missing build. Without the addon, the wrapper classes and json are stand-ins that construct normally, and every call resolves to the load error.

The binding interface number stays 1: nothing is released.

Verification

Run locally on macOS (arm64), Rust 1.94.1, Node 24, pnpm 10.33.2, at this PR's head:

  • cargo fmt --all --check: clean.
  • cargo test --locked --all-features: recipher-js 31 unit tests and 2 boundary tests passed; recipher-value-napi 33 unit tests and tests/node.rs passed.
  • cargo clippy --locked --all-targets --all-features -- -D warnings: clean.
  • The value bridge's test addon: cargo fmt --check and cargo clippy --locked --target-dir target/napi-test-addon -- -D warnings by its manifest: clean.
  • build:debug: native.d.ts regenerated and committed; the build leaves no other change.
  • test:addon: 57 passed. test (vitest, then tsc with the type tests): 26 passed, typecheck clean.
  • Biome on the changed files: clean.
  • The repository's script tests: the same failures as the base, plus check-auth-npm-changeset, which cannot load @changesets/parse in the local sandbox. tests-workflow-gate, recipher-js-lock-parity and workflow-turbo-build-deps pass.

The Rust tests check that the engine and the SDK each decrypt what the other encrypted, for every type, and that an array is one key request each way. Not run: anything against a live ZeroKMS. CI results are in the checks.

Review notes

  • One type test changed: type-tests/native.ts checked that Ciphertext with no type named is Ciphertext<string>. It is now Ciphertext<OpenedScalar>, because a ciphertext read from stored bytes with no kind can decrypt to any scalar. The test also checks that Json and json are the generated ones.
  • opaque(..) is not here. The engine has no entry point from a frame to its storage-profile bytes.
  • A VcUuid is refused with recipher_js::uuid. The engine's value model has no UUID type.
  • A JSON document read back with no kind decrypts as its JSON text. The bytes do not say a value is JSON. kinds.json reads it as a document.
  • The JSON number rule is narrower than the plan's. Only whole numbers between 2^53 and 2^64 are refused, so a document another SDK wrote with 1e20 encrypts again.
  • recipher_js::reserved_key has the same code on encrypt and decrypt. Only the call that failed says which.
  • OneValue in crate/src/value.rs is widened here to a scalar or a JSON document. The engine's own single-value frame will replace it later.

Related

@changeset-bot

changeset-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fc5c851

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

@coderdan coderdan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an automated code review, run at the PR author's request.

Summary. The scalar mapping is vitaminc's from end to end. The addon reads each value with JsRef::to_frame and builds each result with JsBuilder. Every value is sealed by the engine through one Vec<_>::encrypt_into, and the counting key source really checks one generate and one retrieve for three values. I found no lossy scalar conversion. -0, NaN, Infinity, the i128 bounds, year 0001, and a JS 42n (sealed as i8) all round-trip, and Rust's decrypt::<i64> and decrypt::<Timestamp> open what the SDK seals. The problems are in the JSON path, in some error kinds, and in one interface check. Nothing is blocking.

Blocking

None.

Should fix

  1. A JSON document nested 128 levels deep fails on encrypt with kind open, code stack_encrypt::aead, and a message saying the ciphertext is damaged or was altered (crates/core/src/json.rs:70).
  2. A stored JSON document read back with fromBytes opens as its JSON text. The obvious next step, JSON.parse, silently loses the digits the bigint rule protects (src/cipher.ts:48, README.md:52).
  3. Every float of 2^53 or more is refused in a JSON document, because such a float has no fraction. A document Rust wrote with 1e20 opens in JS, and encrypting it again is refused (crates/core/src/json.rs:146).
  4. A JSON document with a constructor, prototype or __proto__ key cannot be encrypted, and one written by another SDK opens as an internal error (crates/core/src/json.rs:79).
  5. The native encrypt and decrypt changed shape, but BINDING_INTERFACE is still 1, so a stale step-1 recipher.node is accepted (src/native.ts:25).
  6. A VcUuid is refused with a message that does not mention a UUID (src/cipher.ts:291).
  7. Tests. The engine-seals, SDK-opens direction is tested only for a string (crates/core/tests/round_trip.rs). Add cases where the engine seals an i64, u64::MAX, a Timestamp, a Decimal, bytes and a JsonPlaintext holding u64::MAX, and the SDK opens each one. Without them, the claim that both sides read each other holds for text only. Separately, the "with vitaminc's code" test does not check the code (__tests__/addon/values.test.ts:217).

Question / design

  1. When the addon is missing, constructing a wrapper class throws. The classes are also built at import time, so the addon now loads when the package is imported (src/values.ts:85).

Nit

  1. A JSON map key copied in Rust is not wiped when its value is refused (crates/core/src/json.rs:285).
  2. The docs say a bigint in a document "is written as its digits". They do not say that one outside the 64-bit range is refused (src/values.ts:119).
  3. A top-level typed array other than Uint8Array, such as a Uint16Array, is refused as recipher::plain_object with "wrap it in json(..)". json(..) refuses it too. Only the message is wrong (src/cipher.ts, refuse).

What I ran. I built the debug addon (build:debug) and ran test:addon: 35 passed. I also ran throwaway probes, deleted afterwards. In Rust (cargo test --all-features), the SDK sealed an i8 and a millisecond timestamp, and the engine opened them as i64 and Timestamp. I checked JSON depths 126 to 129, re-encrypted an engine-sealed {"x": 1e20}, and round-tripped NaN, Infinity and -0. In vitest I checked each refusal's kind and code, json(..) with large floats, sparse arrays, lone surrogates and the prototype keys, Dates at the range ends, and fromBytes of a JSON ciphertext. CI is green.

}

/// The document a frame holds, as the engine's [`JsonPlaintext`].
pub(crate) fn document(frame: &ValueFrame) -> Result<JsonPlaintext, Refusal> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix: a document that is too deep fails on encrypt as open / stack_encrypt::aead.

vitaminc lets a frame nest 128 levels. The engine's JSON parser reads 127. So keyset.encrypt(json(deep)) with 128 nested arrays passes document(). Then JsonPlaintext's visit refuses it as Error::Aead, and Refusal::engine maps that to kind open. What comes back is:

{ kind: 'open', code: 'stack_encrypt::aead',
  message: 'AEAD operation failed (wrong key, AAD mismatch, or malformed ciphertext). ... the ciphertext is damaged or was altered.' }

That is wrong on an encrypt. A caller switching on kind would treat it as tampering. I reproduced this from vitest and from Rust: depths 126 and 127 seal, 128 fails as above, and 129 is refused by vitaminc.

Fix: check the depth here, at most 127 as the engine's parser reads, and refuse with recipher::not_json ("nested deeper than 127 levels"). You could also make encrypt_with map an engine Aead to Kind::Value, since no ciphertext exists yet. Add a test at 127 and 128.

* decrypting is what authenticates them.
*
* A JSON document is sealed as its JSON text, so one read back here
* opens as that text.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix: the untyped fromBytes gap is a trap for JSON.

The real path is store, then read back, so in practice every json(..) value goes through fromBytes and opens as a string. The natural next step loses data silently. I ran:

const sealed = (await k.encrypt(json({ id: 18446744073709551615n }))).unwrap()
const opened = (await c.decrypt(Ciphertext.fromBytes(sealed.toBytes()).unwrap())).unwrap()
// opened === '{"id":18446744073709551615}'
JSON.parse(opened) // { id: 18446744073709552000 }

This is the precision loss the bigint rule exists to prevent. The type is honest (OpenedScalar includes string), but nothing pushes the caller to the right reader, because none exists yet.

Fix: add a way to read stored bytes as a JSON document in this PR, for example Ciphertext.fromBytes(bytes, { json: true }), to become kinds.json in step 3. Or keep json(..) back until typed fromBytes lands. At the very least, say in this doc comment and the README not to JSON.parse the text.

| `new VcDate('2026-11-23')` | a calendar date | `VcDate` |
| `new VcDecimal('1.50')` | a decimal, with its scale | `VcDecimal` |
| `null` | null | `null` |
| `json(value)` | a JSON document, as its JSON text | the document |

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Decrypts as: the document" is true only for a Ciphertext that never left memory. Read back with Ciphertext.fromBytes, which is how stored data is read, it decrypts as the JSON text, and JSON.parse of that text loses bigint digits. See the comment on src/cipher.ts:48. Please make this row say so, or fix the gap.

return Ok(Value::Number(Number::from(value as i64)));
}
return Err(NotJson::Kind(
"an integer outside the safe range held as a number; use a bigint",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix: every large float is refused, and decrypt then encrypt fails.

Every f64 of magnitude 2^53 or more has no fraction. So this branch refuses every large float, not only integers that lost digits. json({ x: 1e21 }), json({ x: Number.MAX_VALUE }) and json(JSON.parse('{"x":6.02e23}')) are all recipher::not_json.

Worse, the read and write rules disagree. A document Rust or Go wrote as {"x": 1e20} opens in JS as { x: 1e20 }, a number (number_of returns F64). Encrypting that same value again is refused. I checked this in Rust: the engine sealed JsonPlaintext::from(json!({"x": 1e20})), the SDK opened it with Encoding::Json, and re-sealing it gave Err(Value, "recipher::not_json", "...an integer outside the safe range held as a number; use a bigint").

Fix: write an integer-valued float outside the safe range as a float. Number::from_f64(1e20) writes 1e20, and the engine's parser reads it back as the same float. Or narrow the refusal to the range where an integer was plausibly meant (for example, up to 2^64). Then add a test that decrypts a document and encrypts it again.


/// The value of an opened document's text, as a frame, by the rules in the
/// module docs.
pub(crate) fn opened(frame: &ValueFrame) -> Result<ValueFrame, Refusal> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix: JSON keys constructor, prototype and __proto__.

vitaminc refuses these three property names in both directions. For a record that is a fine rule. In a JSON document they are ordinary keys (JSON.parse('{"constructor":1}') gives an own property). What happens now:

  • keyset.encrypt(json(JSON.parse('{"constructor":1}'))) gives { kind: 'value', code: 'InvalidArg', message: 'the value could not be read for encryption' }. The code is a napi status, not a stable one, and the message does not say why.
  • A document another SDK wrote with such a key gives { kind: 'internal', code: 'recipher::build_value' } on decrypt. internal means "not the caller's to fix", but the data is authentic and simply cannot be built in JS.

I reproduced both. For the decrypt case I sealed the text as a string and opened it with the JSON encoding, which is the same leaf the engine seals.

Fix: decide with vitaminc how a JSON document carries these keys. Until then, report kind open on decrypt and value on encrypt, with a code that names the key rule, and list the three keys in the README.

value instanceof VcDate ||
value instanceof VcTimestamp ||
value instanceof VcDecimal ||
value instanceof VcUuid

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix: the UUID refusal does not say "UUID".

A VcUuid passes this check and is refused later, by the engine's value model. The result is:

{ kind: 'value', code: 'recipher::value',
  message: 'the value cannot be encrypted: expected a null, bool, integer, float, string, bytes, date, timestamp or decimal in range' }

A caller who reads the README will look for a UUID message and not find one. Since the SDK exports the class and knows it cannot be sealed, refuse it here with its own code, for example recipher::uuid and "a UUID cannot be encrypted yet: the engine's value model does not hold one". Assert that code in the values.test.ts UUID test, which checks only the kind today.

expect(result.err()?.kind).toBe('value')
})

it("an integer vitaminc cannot hold, with vitaminc's code", async () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test name promises vitaminc's code, but the test asserts only kind and the message. Today the code is ERR_INTEGER_RANGE (I checked), so add expect(result.err()?.code).toBe('ERR_INTEGER_RANGE'). Without it, a regression to a generic code would still pass.

const message = binding.error.message
const Missing = class {
constructor(_text: string) {
throw new TypeError(`${name} needs the native build: ${message}`)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question / design: a missing addon throws here.

The plan says nothing escapes as an exception, and that a build that does not load is an Err. With this stand-in, new VcDate('2026-11-23') throws a TypeError when the addon is missing. It is the only SDK call that does. An alternative: a frozen stand-in that keeps its text and constructs normally. Then the failure arrives at keyset.encrypt(..), which already returns recipher::load without a build. Is the throw deliberate?

Related: wrapperClass calls native() at module load (line 78), so the addon is now loaded when the package is imported. native.ts still says it is "loaded once, on first use". Either make it lazy, or update that comment.

fn entry(&mut self, key: &str) -> Result<ToJson<Member<'_>>, NotJson> {
Ok(ToJson(Member {
object: &mut self.members,
key: key.to_owned(),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: hygiene. This key copy is wiped only when it reaches the map. If the member's value is refused (bytes, a date, an unsafe float), ToJson<Member> is dropped with the key in it, and the key is freed without being wiped. The same happens when the member holds an array or object that is dropped unfinished: the Member sits in out and is dropped without a wipe. Holding the key in Zeroizing<String> until put would fix both.

/**
* A JSON value. An integer outside the safe range of a `number` is a
* `bigint`; on encrypt, a `number` that is an integer outside it is
* refused, and a `bigint` is written as its digits.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. "A bigint is written as its digits" does not mention the limit. A bigint outside the 64-bit range (below i64::MIN or above u64::MAX) is refused, because the engine's parser reads no wider. Please say so here and in the README.

@coderdan

Copy link
Copy Markdown
Contributor Author

Rewritten to fold in #1791, #1805, #1807, #1808. Previous head: a94a1a7.

The skeleton encrypts one string. An application needs every value
JavaScript has, arrays of them, and JSON documents.

keyset.encrypt now takes every value in the value bridge's mapping: a
string, a boolean, a number, a bigint at the narrowest width that holds
it, bytes, a Date, the wrapper classes for a date, a fine timestamp and a
decimal, and null. An array in gives an array out, in one key request each
way, and one refused element fails the whole array before any request.
json(..) is a native function that reads a document when it is called
and holds the engine's JsonPlaintext, so a document is encrypted as the
engine encrypts one.

A Ciphertext records the kind it decrypts as, and
Ciphertext.fromBytes(bytes, kind) reads stored bytes as a kind, so a JSON
document read back with kinds.json decrypts to the document, not to its
text. Each refusal is a variant of the SDK's error enum with a
recipher_js:: code of its own, and the bridge's refusals keep the
bridge's codes.

Every new signature is written on the Rust method, as the skeleton's are:
the array overloads of encrypt and decrypt, and the kind overload of
fromBytes, are ts_type strings, one overload per line, so the generated
native.d.ts stays the public type. The value types those signatures name
live in src/value-types.ts, which imports nothing: the declarations
import it, and a module that loaded the addon would make them import
themselves. A Json is the native class, marked in the header so no other
object type-checks as one. A ciphertext with no type named now allows any
scalar, since one read from stored bytes with no kind can decrypt to any.

Nothing is released, so the binding interface stays 1.

Closes #1812
@coderdan
coderdan force-pushed the feat/recipher-js-values branch from a5555b7 to fc5c851 Compare November 25, 2026 12:40
if value.get_type().ok() == Some(ValueType::Undefined) {
return Err(Error::Undefined.into());
}
let uuid = is_uuid(env, &value);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a special case for UUID?

.map_err(|error| refused(env, &error))?;
ValueFrame::from_bytes(frame.as_protected_ref()).map_err(|_| Error::Value.into())
ValueFrame::from_bytes(frame.as_protected_ref())
.map_err(|_| RecipherErrorFields::from(if uuid { Error::Uuid } else { Error::Value }))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a nasty hack.

.to_frame()
.map_err(|error| refused(env, &error))?;
ValueFrame::from_bytes(frame.as_protected_ref()).map_err(|_| Error::Value.into())
ValueFrame::from_bytes(frame.as_protected_ref())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in this method seems to be doing multiple conversions from a JS ref to a frame and then to a value frame. There are several layers of indirection here.

I would have thought that the napi crate did all of this already directly from the unknown type into our value types.

Comment on lines +120 to +130
/// Makes a JSON document to encrypt as one ciphertext. The document is a
/// plain object, an array, text, a number, a `bigint`, a boolean or `null`,
/// nested at most 127 levels.
///
/// Give an integer outside a `number`'s safe range as a `bigint`, within 64
/// bits. The safe range is at most 2^53 - 1 from zero. A whole `number`
/// between 2^53 and 2^64 from zero is refused, because the caller probably
/// meant an integer.
///
/// `json(..)` reads the document now. `json(..)` never throws: `encrypt`
/// returns an `Err` for a document that cannot be encrypted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included an example here. I can't reason about how this would be used.

@coderdan coderdan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many layers: most of this belongs in the value bridge or the engine

Three of this PR's four large pieces repeat something that the value bridge (value-napi) or the engine already owns. The bridge was created to own the JavaScript value mapping. The SDK should use it, not restate it.

1. The wrapper classes exist in five places

VcDate, VcTimestamp, VcDecimal and VcUuid are:

  1. defined by the bridge, in value-napi/src/wrappers.js, and recognised by wrappers.rs;
  2. re-exported from the addon by name, in crate/src/lib.rs;
  3. redeclared by hand as an interface each, in src/value-types.ts, because napi-rs does not declare them;
  4. wrapped again in src/values.ts: a type alias per class, WrapperConstructor<W>, and wrapperClass(name), which reads the class off the addon with Reflect.get;
  5. given a stand-in class each, for when the addon did not load.

The bridge has no TypeScript declarations of its own, so the SDK redeclares its classes.

2. The kinds table copies the engine and the bridge

src/kinds.ts copies the engine's 19 ValueKind names by hand, and pairs each with the TypeScript type it decrypts to (int32 to bigint, decimal to VcDecimal). crate/src/ciphertext.rs then parses { name } back into ValueKind. The names are the engine's. Which JavaScript type each kind becomes is the bridge's mapping: JsBuilder implements it. Nothing keeps the copies in step.

3. crate/src/json.rs is 581 lines of conversion in the addon

It converts a frame to serde_json and back, applying the JavaScript number rules. That is two jobs, and neither belongs in the addon:

  • Converting a frame to and from JsonPlaintext is language-neutral. Any binding needs it, so it belongs in the engine's dynamic module, as ScalarFrame does (#1825).
  • The JavaScript number rules (safe integers, a bigint for a large integer) are a value mapping, which is the bridge's job.

4. OneValue

Already dealt with: the engine's ScalarFrame replaces it (#1825, #1827).

The stand-ins

Because no call throws, even when the addon fails to load, every export has a stand-in: the three classes, the four wrappers, json and checkDeclarations. A good share of src/ is that. If a failed load only has to surface from Cipher.create(), most of this layer can go. That needs a decision.

What belongs in this PR

The array overloads on encrypt and decrypt, the kind argument on fromBytes, and the new error variants.

Proposed restructure

  1. The bridge ships its own TypeScript declarations beside wrappers.js: the Vc* classes and the mapping from kind to type. The header imports them, and the SDK's hand-written copies go. A prototype of this step is on its way as a separate draft PR.
  2. The JSON conversion moves out of the addon: the number rules into the bridge, and the frame conversion into the engine.
  3. Decide whether the stand-ins stay.

None of this is tested yet. Step 1 looks the most mechanical, and the JSON move is the largest.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant