Skip to content

feat(core,web): members-only (v0x03) and specific-people (v0x04) envelopes with conformance vectors - #392

Merged
PastaPastaPasta merged 9 commits into
masterfrom
feat/mv1-crypto
Oct 5, 2026
Merged

PastaPastaPasta merged 9 commits into
masterfrom
feat/mv1-crypto

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

What

The shared crypto core for members-only content in public repositories (mixed-visibility phase 1, streams 1J, the crypto half of 1A and the crypto half of 1C). No UI, no write or read wiring: the lane, web-lane, dg and env streams build on this.

Members-only content, enc v0x03 (crates/forge-core/src/private/doc.rs, forge-web/lib/private/doc.ts)

enc        = 0x03 ‖ nonce ‖ COMMIT_obj ‖ AES-256-GCM(K_doc,obj, nonce, TLV, AD') ‖ tag      (61 B)
K_obj      = HKDF-Expand(PRK_e, "dash-forge/v2/obj" ‖ 0x00 ‖ u32(e) ‖ nonce ‖ SHA-256(AD), 32)
PRK_obj    = HKDF-Extract(repoId, K_obj);  K_doc,obj / COMMIT_obj = Expand(PRK_obj, "dash-forge/v2/obj-doc|obj-commit" ‖ 0x00)
AD'        = AD(enc[0] = 0x03) ‖ COMMIT_obj
  • The per-object key is bound to the AD (spike S6): a revealed key cannot mint content members accept.
  • The commitment is compared before GCM runs. A mismatch is Unreadable(CommitMismatch), never BadTag and never a silent drop.
  • The nonce is hedged as private-repos.md §3.6.
  • Issues, PRs, comments and reviews pad their TLV to 64 bytes with one tag-64 record (D28). Ref updates, events and configs are not padded.
  • Which version where. DocHeader.vis / PrivateDoc.vis is the document's own vis, which consensus holds equal to the repository's visibility. It is absent, and so private, by default. The open path admits v0x01 only in private repositories and v0x03 only in public ones; v0x04 is admitted in both. A writer refuses the other pairings too.
  • A public repository's members lane is a distinct type, private::Lane, not a Private. It implements none of the git-plane seams (ref hashes, codec, packs), so one object never answers for both planes. Lane::seal_doc writes v0x03 (its anchor config v0x02). Lane::seal_artifact seals members artifacts (a kind-70 long body, a Members environment) under the lane key, never as plaintext. Lane::epoch_keys gives keyed ref-name hashes for later phases.

Specific-people letters, enc v0x04 (private/named.rs, lib/private/named.ts)

  • The layout follows design §4.2: no recipientKeyId, a COMMIT_obj, slot version 0x02, the sender in slot 0, n ≤ 16, AD' = AD(0x04, epoch 0) ‖ SHA-256(H), and TLV tag 25 listing the recipients in slot order.
  • The reader rule is implemented exactly as specified:
    • the sender key is only the owner's senderKeyId, an ECDSA_SECP256K1 ENCRYPTION key;
    • every slot is tried;
    • padding, version, KCV and the full commitment must all match;
    • then GCM;
    • then count(tag 25) = n, the owner at slot 0, no identity twice, and the reader's own id at its slot.
  • Sender keys must be 33-byte compressed points. owner_keys / ownerKeys must be the keys of this document's (or this manifest's) $ownerId.
  • open_content returns a distinct Unreadable::Letter ('letter') for a well-framed v0x04 document.
  • The doc comments say how to wire these: callers check the owner-signed manifest's packHash before open_artifact.
  • Rust goes through forge_core::envelope (platform_encryption). A new envelope::SharedKey gives one ECDH per key pair.
  • TS uses @noble/secp256k1 and hashes the full compressed point (not the x-only slice) with WebCrypto AES.
  • lib/auth/encryption-key.ts gains only sealLetterAs / openLetterAs. They open the vault key for the call and then wipe it.
  • DocHeader::ad_without_keys / docAdWithoutKeys give the repoId-only, epoch-0 AD.

Sealed artifacts under a specific-people header (DFPK version 0x02), for the Maintainers environments of stream 1I: the letter's slot block stands where version 0x01 has its epoch, K_pack = HKDF-Expand(PRK_obj, "dash-forge/v2/obj-pack" ‖ 0x00 ‖ 0x02 ‖ fileId), and the whole header is every segment's AD. Whole-file open only.

TLV. Tag 25 is legal only in v0x04. Tag 64 is the padding record. Tags 22–24 and 27 are defined in the spec but stay reserved, so no reader opens them.

Spec. docs/security/private-repos.md §3.7, §4.1, §4.3, §4.4, §10 and §11. The new §11 values are asserted by the generator. §8.1/§17 rule text and docs/errors.md are left to the lane stream.

Vectors

tools/private-repos-vectors/gen.py (independent Python, cryptography, secp256k1 by hand, points validated) writes 73 new files. Both harnesses run them byte for byte:

  • mixed_doc_seal__* (11): v03_{comment,issue,review,inline,long_body} plus review_empty, event_not_padded and four refusals.
  • mixed_doc_open__* (24):
    • member, outsider_placeholder, commit_mismatch, forged_after_reveal_refused, v01_relabelled_refused, pad_roundtrip;
    • also no_lane, body_tampered, moved_to_other_target, v01_byte_relabelled_as_v03, v03_in_private_refused, v03_too_short;
    • padding strictness, tag 25 and reserved tags 22, 23, 24 and 27, late, v04_public and v04_private (Letter), config_anchor_public.
  • named_envelope__n{1,3,16}, each with every recipient's open, plus six writer refusals (refused_*), checked independently in the generator.
  • named_envelope_open__* (22):
    • swapped_slots, not_a_recipient, other_slot_flipped, equivocating_slot, wrong_sender_key_type;
    • also …_purpose, sender_key_missing, sender_key_not_a_point, sender_key_uncompressed, other_owner, second_key_opens, recipient_list_short, sender_not_slot0, duplicate_recipient, reader_not_at_its_slot, epoch_not_zero, n_zero, n_seventeen, truncated, ref_update_refused, config_refused, slot_version_1_refused.
  • named_artifact__n3 and named_artifact_open__* (6).
  • SDK drift check. Each harness opens every letter slot through the SDK's own decrypt (rs-sdk decrypt_property, the evo-sdk encryptedFor facade) with the repoKey.wrapped declaration as a carrier. This is test-only.
  • Existing private_* vectors are byte-identical. Six of them were committed by hand on master (efbb9f1, d0e6607), and the master generator deletes them on every run. A HAND_WRITTEN keep-list now preserves them; porting them into the generator is a follow-up.
  • The rules harnesses in both stacks skip the new cases, as they skip private_*.

How tested

  • Rust: cargo fmt --all -- --check, cargo clippy -p forge-core --all-targets -- -D warnings, cargo test -p forge-core. Locally after the review fixes: fmt and forge-core clippy pass, built from this branch's sources under the shared-target staleness rule. The forge-core tests passed on an earlier run (823 lib tests), but the shared build directory may have served another branch's forge-core to that run, and the rule-compliant re-run was stopped by the disk watchdog. CI is the authoritative Rust gate for this head. Only forge-core changed, and no other crate uses the changed types.
  • New unit tests cover production (random) seals:
    • v0x03 round trip, padding, the vis gate, commitment and tag failures;
    • letters to every recipient and only them, and the sender-first, unique-id, ≤ 16 and epoch-0 refusals;
    • a multi-segment artifact.
  • Web: tsc --noEmit, next lint, copy lint, vitest run (365 files, 6,019 tests passed, 33 skipped).
  • python3 tools/private-repos-vectors/gen.py --write-vectors adds files only and leaves every existing file unchanged. python3 forge-contracts/schema/vectors.py --check passes.
  • Live QA on sakura: not done in this PR. Consensus for v0x03 and v0x04 documents was proven by spikes S1, S3 and S6. A live seal needs the lane-0 anchor writer and the dg/web write paths, so it lands with the lane and dg streams.

Limits

  • open_content / openContent hold no ECDH keys. A well-framed v0x04 document returns Unreadable(NoKey) there and opens through named::open / openLetter.
  • Letters keep no session cache of S yet. That is a performance follow-up for the phase-2 documents.
  • A DFPK 0x02 artifact carries no recipient list (it has no TLV). A format that needs one puts it in its own plaintext.
  • Handoff notes for the lane stream:
    • keyring::header_of must set vis;
    • Keyring::open turns a v0x03 CommitMismatch into EarlierUse under earlier_use(), and hidden_bucket files it under "wrong or missing key". It should be counted as not encrypted for this repo.
    • long_body room under v0x03 is 32 bytes less.

🤖 Generated with Claude Code

PastaPastaPasta and others added 6 commits October 5, 2026 02:14
enc v0x03 seals members-only content of a public repository under a
per-object key bound to the nonce and the AD, with a key commitment and
64-byte padding for discussion types; v0x04 (private::named) seals a
letter to up to 16 identities by ECDH slots. The open path admits v0x01
only in private repositories and v0x03 only in public ones (DocHeader.vis).
Private::from_resolution_mixed gives a public repository's members-lane
keys whose git-plane seams stay public.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
gen.py writes mixed_doc_seal/open (v0x03: AD-bound key, commitment,
padding, version-by-visibility) and named_envelope/_open (v0x04: n = 1, 3,
16 and the reader-rule negatives); the Rust harness runs them and opens
every letter slot through the SDK's decrypt_property as a drift check.
Six hand-written private vectors the generator does not produce are kept
instead of deleted on each run.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
lib/private mirrors forge-core: sealMembersDoc and the openContent
dispatch on enc[0] and doc.vis, tag 25 and the 64-byte padding in the TLV,
and lib/private/named (noble ECDH over the full compressed point, WebCrypto
AES) for letters. The conformance harness runs every mixed_doc and
named_envelope vector and opens each slot through the evo-sdk facade as a
drift check; encryption-key gains sealLetterAs/openLetterAs.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… 0x02)

A sealed artifact whose header carries a letter's slot block instead of an
epoch: the file key is HKDF-Expand(PRK_obj, obj-pack ‖ 0x00 ‖ 0x02 ‖ fileId)
and the whole header is every segment's AD. For the Maintainers
environments of stream 1I. named_artifact vectors in gen.py, both
harnesses.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… and 64

private-repos.md §3.7 (artifacts sealed to specific people), §4.1 (members
v0x03: AD-bound per-object key, commitment, padding; specific-people v0x04
with its writer and reader rules; which version where), §4.3 (tag 25 for
letters, 22-24 and 27 defined but reserved, the tag-64 padding record),
§4.4, §10 and §11, whose new summary values gen.py asserts.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9d9efe6e-bbae-4902-bc4a-f180c6439243
📥 Commits

Reviewing files that changed from the base of the PR and between fe376f7 and d309e8a.

📒 Files selected for processing (94)
  • crates/forge-core/src/envelope.rs
  • crates/forge-core/src/platform/wrap.rs
  • crates/forge-core/src/private/conformance.rs
  • crates/forge-core/src/private/doc.rs
  • crates/forge-core/src/private/keys.rs
  • crates/forge-core/src/private/mod.rs
  • crates/forge-core/src/private/named.rs
  • crates/forge-core/src/private/tlv.rs
  • crates/forge-core/src/rules.rs
  • docs/security/private-repos.md
  • forge-contracts/vectors/mixed_doc_open__blind_tags_reserved.json
  • forge-contracts/vectors/mixed_doc_open__body_tampered.json
  • forge-contracts/vectors/mixed_doc_open__commit_mismatch.json
  • forge-contracts/vectors/mixed_doc_open__config_anchor_public.json
  • forge-contracts/vectors/mixed_doc_open__forged_after_reveal_refused.json
  • forge-contracts/vectors/mixed_doc_open__late.json
  • forge-contracts/vectors/mixed_doc_open__member.json
  • forge-contracts/vectors/mixed_doc_open__moved_to_other_target.json
  • forge-contracts/vectors/mixed_doc_open__no_lane.json
  • forge-contracts/vectors/mixed_doc_open__outsider_placeholder.json
  • forge-contracts/vectors/mixed_doc_open__pad_before_content_refused.json
  • forge-contracts/vectors/mixed_doc_open__pad_mid_bucket.json
  • forge-contracts/vectors/mixed_doc_open__pad_roundtrip.json
  • forge-contracts/vectors/mixed_doc_open__pad_twice_refused.json
  • forge-contracts/vectors/mixed_doc_open__recipient_tag_refused.json
  • forge-contracts/vectors/mixed_doc_open__reserved_tag_23.json
  • forge-contracts/vectors/mixed_doc_open__reserved_tag_24.json
  • forge-contracts/vectors/mixed_doc_open__reserved_tag_27.json
  • forge-contracts/vectors/mixed_doc_open__v01_byte_relabelled_as_v03.json
  • forge-contracts/vectors/mixed_doc_open__v01_relabelled_refused.json
  • forge-contracts/vectors/mixed_doc_open__v03_in_private_refused.json
  • forge-contracts/vectors/mixed_doc_open__v03_too_short.json
  • forge-contracts/vectors/mixed_doc_open__v04_private.json
  • forge-contracts/vectors/mixed_doc_open__v04_public.json
  • forge-contracts/vectors/mixed_doc_seal__v03_body_over_cap.json
  • forge-contracts/vectors/mixed_doc_seal__v03_comment.json
  • forge-contracts/vectors/mixed_doc_seal__v03_config_refused.json
  • forge-contracts/vectors/mixed_doc_seal__v03_event_not_padded.json
  • forge-contracts/vectors/mixed_doc_seal__v03_inline.json
  • forge-contracts/vectors/mixed_doc_seal__v03_issue.json
  • forge-contracts/vectors/mixed_doc_seal__v03_long_body.json
  • forge-contracts/vectors/mixed_doc_seal__v03_private_header_refused.json
  • forge-contracts/vectors/mixed_doc_seal__v03_review.json
  • forge-contracts/vectors/mixed_doc_seal__v03_review_empty.json
  • forge-contracts/vectors/mixed_doc_seal__v03_tag_not_for_kind.json
  • forge-contracts/vectors/named_artifact__n3.json
  • forge-contracts/vectors/named_artifact_open__recipients.json
  • forge-contracts/vectors/named_artifact_open__size_mismatch.json
  • forge-contracts/vectors/named_artifact_open__slot_flipped.json
  • forge-contracts/vectors/named_artifact_open__truncated.json
  • forge-contracts/vectors/named_artifact_open__version_1_refused.json
  • forge-contracts/vectors/named_artifact_open__wrong_sender_key_type.json
  • forge-contracts/vectors/named_envelope__n1.json
  • forge-contracts/vectors/named_envelope__n16.json
  • forge-contracts/vectors/named_envelope__n3.json
  • forge-contracts/vectors/named_envelope__refused_duplicate_recipient.json
  • forge-contracts/vectors/named_envelope__refused_epoch_1.json
  • forge-contracts/vectors/named_envelope__refused_over_cap.json
  • forge-contracts/vectors/named_envelope__refused_ref_update.json
  • forge-contracts/vectors/named_envelope__refused_sender_not_first.json
  • forge-contracts/vectors/named_envelope__refused_seventeen.json
  • forge-contracts/vectors/named_envelope_open__config_refused.json
  • forge-contracts/vectors/named_envelope_open__duplicate_recipient.json
  • forge-contracts/vectors/named_envelope_open__epoch_not_zero.json
  • forge-contracts/vectors/named_envelope_open__equivocating_slot.json
  • forge-contracts/vectors/named_envelope_open__n_seventeen.json
  • forge-contracts/vectors/named_envelope_open__n_zero.json
  • forge-contracts/vectors/named_envelope_open__not_a_recipient.json
  • forge-contracts/vectors/named_envelope_open__other_owner.json
  • forge-contracts/vectors/named_envelope_open__other_slot_flipped.json
  • forge-contracts/vectors/named_envelope_open__reader_not_at_its_slot.json
  • forge-contracts/vectors/named_envelope_open__recipient_list_short.json
  • forge-contracts/vectors/named_envelope_open__ref_update_refused.json
  • forge-contracts/vectors/named_envelope_open__second_key_opens.json
  • forge-contracts/vectors/named_envelope_open__sender_key_missing.json
  • forge-contracts/vectors/named_envelope_open__sender_key_not_a_point.json
  • forge-contracts/vectors/named_envelope_open__sender_key_uncompressed.json
  • forge-contracts/vectors/named_envelope_open__sender_not_slot0.json
  • forge-contracts/vectors/named_envelope_open__slot_version_1_refused.json
  • forge-contracts/vectors/named_envelope_open__swapped_slots.json
  • forge-contracts/vectors/named_envelope_open__truncated.json
  • forge-contracts/vectors/named_envelope_open__wrong_sender_key_purpose.json
  • forge-contracts/vectors/named_envelope_open__wrong_sender_key_type.json
  • forge-web/lib/auth/encryption-key.ts
  • forge-web/lib/private/conformance.test.ts
  • forge-web/lib/private/doc.ts
  • forge-web/lib/private/index.ts
  • forge-web/lib/private/keys.ts
  • forge-web/lib/private/named.test.ts
  • forge-web/lib/private/named.ts
  • forge-web/lib/private/testing.ts
  • forge-web/lib/private/tlv.ts
  • forge-web/lib/rules/conformance.test.ts
  • tools/private-repos-vectors/gen.py
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

- a distinct private::Lane for a public repository's members lane: no
  git-plane seams (ref hashes, codec, packs), artifacts sealed under the
  lane key; Private is private-repo only again
- Unreadable::Letter ('letter') for a v0x04 document on the epoch-key path,
  with the V4 guard in Rust doc::decrypt
- letter reader rule: the owner at slot 0, no identity twice, 33-byte sender
  keys that are points; one checkRecipients helper in TS with length checks
- manifest/owner wiring documented on open_artifact and the letter openers
- zeroization of K_obj copies, members TLV on failure, artifact segments
- vectors: v04 on the content path, reserved tags 23/24/27, n 0/17,
  truncated, refUpdate/config letters, non-point and uncompressed sender
  keys, sender_not_slot0, duplicate_recipient, writer refusals; the
  generator validates points and checks the writer rule independently
- spec: why the full commitment, not only the KCV, is checked

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@PastaPastaPasta
PastaPastaPasta merged commit c3d38f3 into master Oct 5, 2026
32 checks passed
@PastaPastaPasta
PastaPastaPasta deleted the feat/mv1-crypto branch October 5, 2026 12:41
PastaPastaPasta added a commit that referenced this pull request Oct 5, 2026
Resolves the encryption-key.ts imports with #392's letters, and makes
sealLetterAs send from the held key its sender slot names and
openLetterAs try every held key (a letter does not say which of the
reader's keys it went to).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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