{{ message }}
feat: split kyc controller responsibility - #10094
Open
Akaryatrh wants to merge 15 commits into
Open
Conversation
Signed-off-by: Sébastien Van Eyck <sebastien.vaneyck@consensys.net>
Signed-off-by: Sébastien Van Eyck <sebastien.vaneyck@consensys.net>
Signed-off-by: Sébastien Van Eyck <sebastien.vaneyck@consensys.net>
Signed-off-by: Sébastien Van Eyck <sebastien.vaneyck@consensys.net>
Signed-off-by: Sébastien Van Eyck <sebastien.vaneyck@consensys.net>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 997ef28. Configure here.
Signed-off-by: Sébastien Van Eyck <sebastien.vaneyck@consensys.net>
Signed-off-by: Sébastien Van Eyck <sebastien.vaneyck@consensys.net>
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.


Explanation
KycController.tshad grown to ~2,400 lines because it carried several unrelated concerns in one file: the phase machine and flow orchestration, the full state type plus its persistence metadata and defaults, pure consent-record helpers, and the UKYC attestation / capability-token wrapping glue. That made the actual orchestration logic hard to find and hard to test in isolation — the consent helpers, for instance, were module-private and could only be exercised through the controller.This PR extracts the cohesive pieces into dedicated modules so the controller is left as the orchestrator it's meant to be. Each extracted module is domain-named rather than a generic
utils.ts, so ownership stays obvious:src/KycControllerState.ts— theKycControllerStatetype,kycControllerMetadata, and thegetDefaultKycControllerState/getDefaultKycVendorDisclaimersAccepted/getDefaultKycProviderDisclaimersAcceptedfactories.src/consents.ts— the pure consent-record and error-shape predicates:consentRecordKey,isSessionAlreadyCompletedError,isConsentConflictError,isValidConsentRecordList,consentRecordsFromAcceptedList,isAcceptedCategoryEmpty,acceptedCategoryStillMissing, andusesConsentsFlow.src/ukyc/sessionAuthorizations.ts— the attestation and capability-token wrapping glue:UKYC_CAPABILITY_TOKEN_TTL_MS,assertAttestedServerPublicKey, andwrapUkycSessionAuthorizations.Two repeated blocks inside the controller were also folded into private helpers:
#markAlreadyCompleted(the "session already completed" error branch, which appeared identically in two flows) and#refreshUserStatusSoft(the best-effort user-status refresh). Both keep the existing#generationguard so areset()landing mid-flight still can't write onto an idle controller.Net effect:
KycController.tsgoes from 2,424 to 1,954 lines.This is a pure restructuring — no behavior change and no API change.
Documentation
ARCHITECTURE.mdgains the new modules in its key-source-files appendix, along withvendorDisclaimerAcceptance.tsandsrc/ukyc/, which were already missing from that table. I also corrected some drift left over from #10082: the doc still describedKycControlleras owning the frame protocol and an X25519 keypair named#keypaircreated at construction, when that material now lives inMoonPayFrameHandleras#frameKeypairand is minted when a MoonPay flow starts. The component diagram now routes the frame protocol anddecryptCredentials()through the handler rather than the controller.Checklist
Note
Low Risk
Internal module layout and docs only; behavior and package exports are intended to be unchanged, with added unit tests on extracted pure logic.
Overview
Refactors
KycControllerinto focused modules so the main file stays the phase machine and flow orchestration only. State shape, persistence metadata, and default factories move toKycControllerState.ts; consent catalog mapping and HTTP/error predicates move toconsents.ts(with new unit tests); JWT attestation and wrapping forsetAuthorizationsmove toukyc/sessionAuthorizations.ts(also tested). Package root exports are rewired so public API names stay the same.Inside the controller, duplicated “already completed KYC” handling is consolidated into
#markAlreadyCompleted, and best-effortrefreshKycStatuscalls use#tryRefreshKycStatusso toast refresh failures still cannot rewind the flow.ARCHITECTURE.mdand the changelog document the split and correct earlier drift: MoonPay frame crypto/protocol is attributed toMoonPayFrameHandler, notKycController.Reviewed by Cursor Bugbot for commit 2ab43a7. Bugbot is set up for automated code reviews on this repo. Configure here.