fix(auth): correct entity type T→P for context ChittyIDs#49
fix(auth): correct entity type T→P for context ChittyIDs#49chitcommit wants to merge 1 commit intomainfrom
Conversation
ChittyMint ignores the entity_type=P parameter and always returns T (Thing). Contexts are Person (P) per canonical governance (chittycanon://gov/governance#core-types). This client-side correction: - Detects entity type mismatch after minting - Replaces T with P in the ChittyID segment - Recalculates mod-97 checksum for the corrected ID - Persists the minted ChittyID even when ChittyCanon DB is unavailable (previously fell back to "UNBOUND" losing the minted ID) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughThe pull request modifies ChittyID minting and context binding logic to validate and correct entity type segments to "P" during authentication, recalculate checksums when corrections are made, and propagate the corrected ChittyID through both database and local context creation paths, including fallback scenarios. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/commands/hook-handlers.ts`:
- Around line 564-573: The checksum recompute can throw when numericStr contains
unexpected chars; update the correction path that manipulates chittyId/segments
(the block using variables chittyId, segments, numericStr, checksum) to: strip
known prefixes like "did:chitty:" and any colons, convert to upper case, then
build numericStr by removing any non-alphanumeric characters and mapping A–Z to
10–35 (use /[A-Z]/g and /[0-9]/), e.g. replace letters with (charCodeAt-55) and
keep digits as-is; validate numericStr is non-empty and wrap the BigInt(...)
conversion and mod-97 logic in a try/catch to handle failures (log an error and
skip correction or mark as invalid) so the code never throws on malformed IDs.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e0ef5fc6-d191-4f0c-81be-5d6575ac9423
📒 Files selected for processing (1)
src/commands/hook-handlers.ts
| const segments = chittyId.split("-"); | ||
| let correctedId = chittyId; | ||
| if (segments[4] && segments[4] !== "P") { | ||
| console.log(` \x1b[33m⚠ Entity type mismatch: got '${segments[4]}', expected 'P' (Person) — correcting\x1b[0m`); | ||
| segments[4] = "P"; | ||
| // Recalculate checksum (mod-97 of all segments except last) | ||
| const baseSegments = segments.slice(0, -1); | ||
| const numericStr = baseSegments.join("").replace(/[A-Z]/g, (c) => String(c.charCodeAt(0) - 55)); | ||
| const checksum = String(98n - (BigInt(numericStr) % 97n)).padStart(2, "0"); | ||
| segments[segments.length - 1] = checksum; |
There was a problem hiding this comment.
Potential runtime failure in checksum recompute path.
At Line 571–572, BigInt(numericStr) can throw when the minted ID includes non-numeric chars (e.g., did:chitty: prefix/lowercase/:), because only [A-Z] is normalized. This can break context auth even after a successful mint.
Suggested hardening
- const baseSegments = segments.slice(0, -1);
- const numericStr = baseSegments.join("").replace(/[A-Z]/g, (c) => String(c.charCodeAt(0) - 55));
- const checksum = String(98n - (BigInt(numericStr) % 97n)).padStart(2, "0");
+ const baseSegments = segments.slice(0, -1);
+ // Normalize DID prefix + separators before numeric conversion
+ const normalized = baseSegments
+ .join("")
+ .replace(/^did:chitty:/i, "")
+ .replace(/[^a-zA-Z0-9]/g, "")
+ .toUpperCase();
+ const numericStr = normalized.replace(/[A-Z]/g, (c) => String(c.charCodeAt(0) - 55));
+ const checksum = String(98n - (BigInt(numericStr) % 97n)).padStart(2, "0");🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/commands/hook-handlers.ts` around lines 564 - 573, The checksum recompute
can throw when numericStr contains unexpected chars; update the correction path
that manipulates chittyId/segments (the block using variables chittyId,
segments, numericStr, checksum) to: strip known prefixes like "did:chitty:" and
any colons, convert to upper case, then build numericStr by removing any
non-alphanumeric characters and mapping A–Z to 10–35 (use /[A-Z]/g and /[0-9]/),
e.g. replace letters with (charCodeAt-55) and keep digits as-is; validate
numericStr is non-empty and wrap the BigInt(...) conversion and mod-97 logic in
a try/catch to handle failures (log an error and skip correction or mark as
invalid) so the code never throws on malformed IDs.
Summary
entity_type=Pparam, always returnsT(Thing) for context mintscreateLocalContextto persist minted ChittyID when DB is unavailable (was hardcoded to "UNBOUND")Test plan
can chitty authenticate-contextproduces ChittyID withPentity typesession_binding.jsonpersists corrected ChittyID (not "UNBOUND")🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes