feat(documents): contract parties, roles, optional parties and dual roles - #387
Merged
Conversation
…oles Replaces the closed #385 after both open questions came back maximal: one human MAY hold two roles, and optional / non-signing parties ARE a launch requirement. They turn out to be the same change — both need the capacity in the signed bytes — so doing them together costs far less than either alone. NO SIGNOFF_DOMAIN BUMP, CONTRARY TO WHAT I EXPECTED `partyId` is an OPTIONAL payload field. `canonicalize` filters undefined keys, so a threshold signature produces bytes byte-identical to before this field existed and every proof already issued keeps verifying. A domain bump is only needed to RENAME or re-mean a field, not to add one. Proven by a test that asserts threshold bytes contain no partyId and that partyId: null canonicalizes identically to omitting it. It has to be in the SIGNED bytes rather than beside them: a contract's claim is "the Buyer signed as Buyer", and once one human can hold two roles, two signatures from one address are otherwise indistinguishable. The verifier binds it, so a relabelled capacity fails verification instead of quietly re-attributing a signature. A PARTY-AWARE OUTCOME RULE `evaluateThreshold` counts approvals anonymously, which cannot decide a contract: an optional Witness in the snapshot lets one be Approved over a REQUIRED party's explicit rejection, and leaving the Witness out denies them at submission instead. `evaluateContractOutcome` decides on WHICH parties acted — every required party approved, any required party rejected, optional parties recorded and never counted. A test asserts the two rules genuinely diverge on the same facts. It also refuses to decide a party set with nothing required: "every required party approved" is vacuously true over an empty set, and approving a contract nobody had to sign is the worst possible default. THE COST OF DUAL ROLES, PAID EXPLICITLY Allowing one address two capacities means dropping DocumentReview_versionId_signerAddress_key. That would silently weaken THRESHOLD mode, where one signer acting twice on a version is still wrong and the in-transaction check reads rows fetched before the write. A partial unique index restores exactly the old guarantee exactly where it still applies (WHERE partyId IS NULL). Prisma cannot express a WHERE on @@unique, so it is raw SQL with a note on how migrations are generated here and why that keeps it safe. VERIFIED AGAINST A THROWAWAY POSTGRES - one human on two parties with one address: allowed - that human signs the same version twice, once per capacity: allowed - twice as the SAME party: refused - threshold mode, one signer twice: still refused - RLS on both new tables, in this migration rather than a follow-up 1174 unit tests, 85 integration tests, tsc clean, next build exit 0. Still required before parties mode works, unchanged from #385: the access layer (a named party cannot reach any document procedure today), the startReview parties branch, the ordering gate and row lock in submitSignerAction, and rendering ContractField values into the body before hashing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Replaces the closed #385, after both open questions came back maximal: one human may hold two roles, and optional / non-signing parties are a launch requirement.
They turn out to be the same change — both need the capacity in the signed bytes — so doing them together costs far less than either alone.
No
SIGNOFF_DOMAINbump, contrary to what I told youpartyIdis an optional payload field, andcanonicalizefiltersundefinedkeys. So a threshold signature produces bytes byte-identical to before this field existed, and every proof already issued keeps verifying. A domain bump is only needed to rename or re-mean a field, not to add one.Proven by a test: threshold bytes contain no
partyId, andpartyId: nullcanonicalizes identically to omitting it.It has to be in the signed bytes rather than beside them. A contract's claim is "the Buyer signed as Buyer", and once one human can hold two roles, two signatures from one address are otherwise indistinguishable. The verifier binds it, so a relabelled capacity fails verification instead of quietly re-attributing a signature.
A party-aware outcome rule
evaluateThresholdcounts approvals anonymously, which cannot decide a contract: an optional Witness in the snapshot lets one be Approved over a required party's explicit rejection, and leaving the Witness out denies them at submission instead.evaluateContractOutcomedecides on which parties acted — every required party approved, any required party rejected, optional parties recorded and never counted. A test asserts the two rules genuinely diverge on identical facts.It also refuses to decide a party set with nothing required: "every required party approved" is vacuously true over an empty set, and approving a contract nobody had to sign is the worst possible default.
The cost of dual roles, paid explicitly
Allowing one address two capacities means dropping
DocumentReview_versionId_signerAddress_key. That would silently weaken threshold mode, where one signer acting twice is still wrong and the in-transaction check reads rows fetched before the write.A partial unique index restores exactly the old guarantee exactly where it still applies (
WHERE "partyId" IS NULL). Prisma can't express aWHEREon@@unique, so it's raw SQL, with a note on how migrations are generated here and why that keeps it safe.Verified against a throwaway Postgres
1174 unit tests, 85 integration tests,
tscclean,next buildexit 0.Still required before parties mode works
Unchanged from #385, and none of it is here: the access layer (a named party cannot reach any document procedure today), the
startReviewparties branch, the ordering gate and row lock insubmitSignerAction, and renderingContractFieldvalues into the body before hashing.🤖 Generated with Claude Code