Repository navigation
Conversation
Add @cipherstash/recipher, the TypeScript SDK on the Stack Encrypt engine, with the first call through it: one string encrypted and decrypted on Node, with no context. The Rust is a detached Cargo workspace. `recipher-js` holds the logic, names the engine's types and has no JavaScript types, so its tests run without Node. `recipher-js-node` is the napi-rs 3 addon: it reads and builds JavaScript values through vitaminc-aead-napi 0.10 and calls the core crate. The engine's futures are Send and 'static, and run on napi's tokio runtime. Every call resolves to the package's own Result, with Rust's methods; none throws and no promise rejects. A test cipher over the engine's deterministic key source (@cipherstash/recipher/testing) runs every test offline. The ciphertext is the engine's: a Rust test opens what the core seals with the engine's typed keyset.decrypt::<String>, and the core opens what the engine sealed. Tests fail if the core crate names Label or IntoLabel, or if either crate links eql-bindings. The package is private and takes no changeset. Its build and test scripts never run cargo; tests-recipher-js.yml runs the cargo checks and the suites that load the addon, on Linux.
|
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 |
Contributor
Mutation testing (cargo-mutants,
|
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
This is step 1 of phase 1 of the TypeScript SDK plan (#1747): a walking skeleton of
@cipherstash/recipher. A TypeScript program can build a cipher, encrypt onestringand decrypt it again on Node, through the Stack Encrypt engine (the Rust cratepackages/stack-encrypt). Every call resolves to aResult; none throws.The package is private and is not published. It takes no changeset.
Changes
Rust: a detached Cargo workspace at
languages/typescript/packages/recipher-js, with its ownCargo.lock. The rootCargo.tomlexcludes it.crates/core(craterecipher-js): the logic. It is the only crate that names an engine type, and it has no JavaScript types, so its tests run without Node. It hasCipher::detect(ZeroKMS, with the credentials the engine finds),Cipher::testing(the engine's deterministic test key source, behind atestingfeature),encryptanddecrypt, andRefusal: every error with akind,code,message,reasonandfield.crates/node(craterecipher-js-node): the napi-rs 3 addon. It reads a JavaScript value into a frame with vitaminc'sJsRef::to_frame, and builds the opened value withJsBuilder::build. It holds no value conversion of its own. It also exports vitaminc's four wrapper classes, ready for step 2.TypeScript:
@cipherstash/recipher.Cipher.create(),cipher.defaultKeyset(),keyset.encrypt(string),cipher.decrypt(ct),keyset.decrypt(ct),Ciphertext.toBytes()andCiphertext.fromBytes(bytes).Result: the package's own type, with Rust's methods in camelCase. Onlyunwrap()andexpect()throw.RecipherErrorand the closedErrorKindset.@cipherstash/recipher/testing:testCipher(), a cipher with no credentials and no network.Err(not an exception) when the addon is missing or has another number.Tests and CI.
test(run by rootpnpm test): theResultand error suites, a test thattestandbuildnever reach cargo, andtscover the type tests. It loads no addon.test:addon: the suites that load the addon.test:cargo:cargo test --locked,cargo fmt --checkand clippy..github/workflows/tests-recipher-js.yml: one Linux job that runstest:cargo,build:debugandtest:addon, then checks the build left the tree clean.AGENTS.md(repository layout, Cargo workspaces) andSECURITY.md(package list) name the package.What the tests prove
keyset.decrypt::<String>. Another seals with the engine'skeyset.encrypt(String)and opens it through the core crate. So Rust (and Go, which runs the same engine) read what this SDK writes.Sendand'static. The plan could not check this. The core crate's futures say so in their types, a test asserts it, and napi'sspawn_future_with_callback(which requires it) compiles over them.LabelorIntoLabel(a test reads its source), and neither crate linkseql-bindings(a test runscargo tree --lockedon each).Cipher.create()with no credentials each resolve to anErrof the right kind. None quotes the plaintext or the bytes.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: 16 passed (6 unit, 3 boundary, 7 round-trip).pnpm --filter @cipherstash/recipher build(tsup, ESM and CJS): passed. Bothdist/index.jsanddist/index.cjsload the addon and round-trip a value, and a cipher from./testingis aninstanceofthe root entry'sCipher.pnpm --filter @cipherstash/recipher build:debug: builtrecipher.node.pnpm --filter @cipherstash/recipher test:addon: 13 passed.pnpm --filter @cipherstash/recipher test(unit suites andtscwith the type tests): 16 passed, typecheck clean.pnpm run code:check: no errors (the warnings are the repository's existing ones; none is in this package).pnpm run test:scripts: 96 files passed.lint:typecheck-scope,lint:package-paths,lint:workflow-cache,lint:eql-pins: passed.Not run: anything against a live ZeroKMS (no credentials were used). The new workflow has not run on Linux yet; this PR's checks are its first run.
Deviations from the plan
scripts/build-native.mjs) that runscargo buildand copies the cdylib torecipher.node.@napi-rs/cli3 brings a large dependency tree (including native cross-toolchain packages) into the lockfile, and step 1 needs none of what it does. So there is no generatednative.d.ts; the addon's interface is typed by hand insrc/native.ts, and the loader checks that each function it calls exists. Step 10 (the platform packages) is the place to decide on the CLI.kind,code,reasonandfield. The error also hasmessage, because the engine's message is what a person reads. The plan's eight kinds have no home for "the native build did not load" or "the engine returned something the SDK does not read", so there is a ninth kind,internal.Promise, not yet a builder. The plan's builder exists to carry.audit,.withCredentialand.signal, which are step 5. A builder that is awaited the same way can replace thePromisethen without changing any call site.build:debugturns on thetestingcargo feature;build:native(release) does not. How a published package offers@cipherstash/recipher/testing(a second build, as Go'sencrypttesthas, or a feature in the one build) is left to step 5 or step 10.wasmnowhere. The plan lists three crates; the wasm crate is step 6, and no placeholder is created.Needs from the engine
Nothing for this step.
Related
Refs #1747 (the plan). The next step's PR is based on this branch.