Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fc5c851
feat(recipher-js): every value type, arrays and JSON documents
coderdan Nov 25, 2026
85c1fc8
Merge branch 'next' into feat/recipher-js-values
coderdan Nov 27, 2026
f99259a
refactor(recipher-js): name the wrapper classes RcDate, RcTimestamp, …
coderdan Nov 28, 2026
27b7ac1
docs(recipher-js): the value bridge defines the value mapping, not vi…
coderdan Nov 28, 2026
1e200d6
refactor(recipher-js): declare each wrapper class beside its type, wi…
coderdan Nov 28, 2026
dab69c5
fix(recipher-js): a stand-in wrapper class constructs as the addon's …
coderdan Nov 28, 2026
cceea6a
docs(recipher-js): a plain object is json(..) today, and opaque(..) w…
coderdan Nov 28, 2026
c001978
feat(recipher-js): the value bridge reads and builds JSON documents
coderdan Nov 28, 2026
e0cc1c6
refactor(recipher-js): the addon passes a JSON document between the b…
coderdan Nov 28, 2026
7602062
fix(recipher-js): refuse a hole in the array given to encrypt or decrypt
coderdan Nov 28, 2026
bb51af7
fix(recipher-js): Ciphertext.fromBytes takes only a kind the package …
coderdan Nov 28, 2026
629362b
test(recipher-js): pin the help of every error the addon defines
coderdan Nov 28, 2026
b1a38b0
docs(recipher-js): only Rust's keyset.encrypt writes the single-value…
coderdan Nov 28, 2026
4f8179a
docs(recipher-js): the JSON rules as the bridge implements them
coderdan Nov 28, 2026
e69aba2
test(recipher-js): pin the depth limit of a JSON document the bridge …
coderdan Nov 28, 2026
c378520
docs(recipher-js): "An RcUuid", in the doc of the addon's uuid error
coderdan Nov 28, 2026
e9ad2aa
docs(recipher-js): plain language for the values and JSON prose
coderdan Nov 28, 2026
1cf2f55
fix(recipher-js): error messages for values in the SDK's own words
coderdan Nov 28, 2026
78c2c78
fix(recipher-js): bump the binding interface, and say why a UUID is r…
coderdan Nov 28, 2026
89a3b27
docs(recipher-js): give the bigint range in the json() docs
coderdan Nov 28, 2026
5c78ecf
fix(recipher-js): refuse a number below -2^63 without asking for a bi…
coderdan Nov 29, 2026
f489f4a
Merge next into feat/recipher-js-values
coderdan Nov 29, 2026
2dbc9fd
feat(recipher-js)!: encrypt one value through dynamic::value, with a …
coderdan Nov 29, 2026
6b52b68
fix(recipher-js): give a refused null value the code recipher_js::nul…
coderdan Nov 29, 2026
988ae6a
fix(recipher-js): refuse an unsafe number for an integer kind, and fi…
coderdan Nov 29, 2026
0b88351
feat(recipher-js)!: make null opt-in with nullable(kind), as Rust's O…
coderdan Nov 29, 2026
b284a8e
feat(recipher-js)!: make a wrapper with from(text) and get a Result
coderdan Nov 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions conformance/vitaminc-aead/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ than skipping the row:

- `js_reencode`: Node has two projections. A Float32 becomes a Number and
re-encodes as Float64. A timestamp that is a whole number of milliseconds
is read as a `Date` and re-encodes as the `Timestamp(Millis)` envelope; a
finer one is read as a `VcTimestamp` and re-encodes in the nanosecond
shorthand. As for Go, this is safe because `LeafTypeAad` binds the kind and
the logical id but not the unit, and the equality terms put every unit in
one timestamp domain.
is read as a `Date`, and re-encodes as the `Timestamp(Millis)` envelope. A
finer timestamp is read as an `RcTimestamp`, and re-encodes in the
nanosecond shorthand. As for Go, the timestamp projection is safe for two
reasons. `LeafTypeAad` binds the kind and the logical id, but not the
unit. The equality terms put every unit in one timestamp domain.
- `go_reencode`: Go has two projections. `undefined` becomes nil and
re-encodes as null. A timestamp in the envelope (seconds, milliseconds or
microseconds) is read as a `time.Time` and re-encodes in the nanosecond
Expand Down
6 changes: 6 additions & 0 deletions languages/typescript/packages/recipher-js/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

251 changes: 238 additions & 13 deletions languages/typescript/packages/recipher-js/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
/**
* The ESM and the CommonJS builds in one process: an application that
* imports the package and a dependency that requires it. Both load the one
* addon, so they share its classes, and a ciphertext from either opens in
* the other. Runs the built `dist/`, in a Node process of its own;
* `test:addon` builds it first.
* Two cases:
*
* - The ECMAScript module (ESM) build and the CommonJS build in one process.
* An application imports the package, and a dependency requires it. Both
* builds load the same addon, so they share its classes. A ciphertext from
* either build decrypts in the other.
* - The package with no native build at all.
*
* Each case runs the built `dist/` in a Node process of its own.
* `test:addon` builds `dist/` first.
*/
import { execFileSync } from 'node:child_process'
import { existsSync } from 'node:fs'
import { cpSync, existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'

Expand Down Expand Up @@ -48,6 +55,59 @@ const out = {
console.log(JSON.stringify(out))
`

const MISSING = `
const recipher = await import(process.argv[1])
const testing = await import(process.argv[2])
const out = {}
out.date = recipher.RcDate.from('2026-11-23').err().code
out.dateFrozen = Object.isFrozen(recipher.RcDate)
out.json = String(recipher.json({ a: 1 }))
out.create = (await recipher.Cipher.create()).err().code
out.testing = (await testing.testCipher()).err().code
out.fromBytes = recipher.Ciphertext.fromBytes(new Uint8Array(4)).err().code
out.notACipher = {} instanceof recipher.Cipher
console.log(JSON.stringify(out))
`

describe('the package without its native build', () => {
it('imports, constructs the wrapper classes, and resolves every call to the load error', () => {
const dir = mkdtempSync(join(tmpdir(), 'recipher-missing-'))
try {
cpSync(
fileURLToPath(new URL('../../dist', import.meta.url)),
join(dir, 'dist'),
{
recursive: true,
},
)
writeFileSync(join(dir, 'package.json'), '{"type":"module"}')
const output = execFileSync(
process.execPath,
[
'--input-type=module',
'--eval',
MISSING,
'--',
join(dir, 'dist', 'index.js'),
join(dir, 'dist', 'testing.js'),
],
{ encoding: 'utf8' },
)
expect(JSON.parse(output)).toEqual({
date: 'recipher_js::load',
dateFrozen: true,
json: 'Json(***)',
create: 'recipher_js::load',
testing: 'recipher_js::load',
fromBytes: 'recipher_js::load',
notACipher: false,
})
} finally {
rmSync(dir, { recursive: true, force: true })
}
})
})

describe('the ESM and CommonJS builds in one process', () => {
it('share the native classes, so each opens what the other sealed', () => {
const files = ['index.js', 'testing.js', 'index.cjs', 'testing.cjs'].map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,12 @@ describe('failures are values', () => {
expect(opened.isErr()).toBe(true)
})

it('refuses a value that is not a string', async () => {
const keyset = (await cipher()).defaultKeyset()
// @ts-expect-error: this build encrypts a string.
const result = await keyset.encrypt(5)
expect(result.err()?.code).toBe('recipher_js::not_a_string')
})

it('refuses a string with an unpaired surrogate, with a code of its own', async () => {
const result = await (await cipher()).defaultKeyset().encrypt('\uD800')
expect(result.err()?.code).toBe('recipher_js::unpaired_surrogate')
})

it('names the rule vitaminc refused a value by', async () => {
it('names the rule a refused value broke', async () => {
const keyset = (await cipher()).defaultKeyset()
const cases: [unknown, string][] = [
[new Map(), 'recipher_js::not_plain'],
Expand All @@ -143,7 +136,7 @@ describe('failures are values', () => {

it('refuses a decrypt of something that is not a ciphertext', async () => {
const c = await cipher()
// @ts-expect-error: decrypt takes a Ciphertext.
// @ts-expect-error: decrypt accepts a Ciphertext.
const result = await c.decrypt(new Uint8Array(8))
expect(result.err()?.code).toBe('recipher_js::not_a_ciphertext')
})
Expand Down Expand Up @@ -211,13 +204,16 @@ describe('every other call returns or resolves to a Result', () => {
encrypt(...args: unknown[]): ReturnType<Keyset['encrypt']>
decrypt(...args: unknown[]): ReturnType<Keyset['decrypt']>
}
expect((await loose.encrypt()).err()?.code).toBe(
'recipher_js::not_a_string',
)
expect((await loose.encrypt()).err()?.code).toBe('recipher_js::undefined')
expect((await loose.decrypt()).err()?.code).toBe(
'recipher_js::not_a_ciphertext',
)
const sealed = (await loose.encrypt('a', 'extra')).unwrap()
// The second argument of `encrypt` is its options, so a stray one is
// refused. An argument after the options is ignored.
expect((await loose.encrypt('a', 'extra')).err()?.code).toBe(
'recipher_js::options',
)
const sealed = (await loose.encrypt('a', undefined, 'extra')).unwrap()
expect((await loose.decrypt(sealed, 'extra')).unwrap()).toBe('a')
const fromBytes = Ciphertext.fromBytes as (...args: unknown[]) => unknown
expect((fromBytes() as { isErr(): boolean }).isErr()).toBe(true)
Expand All @@ -226,19 +222,19 @@ describe('every other call returns or resolves to a Result', () => {
it('arguments of every wrong type resolve to an Err', async () => {
const c = await cipher()
const keyset = c.defaultKeyset()
const wrong: unknown[] = [
const notValues: unknown[] = [
undefined,
null,
0,
{},
[],
Symbol('s'),
() => 1,
new Map(),
]
for (const value of wrong) {
for (const value of notValues) {
expect((await keyset.encrypt(value as never)).isErr()).toBe(true)
}
const notCiphertexts: unknown[] = [...notValues, null, 0, 'text', [1]]
for (const value of notCiphertexts) {
const anyValue = value as never
expect((await keyset.encrypt(anyValue)).isErr()).toBe(true)
expect((await keyset.decrypt(anyValue)).isErr()).toBe(true)
expect((await c.decrypt(anyValue)).isErr()).toBe(true)
expect(Ciphertext.fromBytes(anyValue).isErr()).toBe(true)
Expand Down
Loading
Loading