fix(credentials): wire verifyCredential to StellarService - #17
Merged
merlik787-droi merged 1 commit intoAug 19, 2026
Merged
Conversation
…-chain check
The public verify endpoint previously hardcoded valid:true for any
credential row found in the database. stellarService.verifyCredential
was imported nowhere; no on-chain query was ever performed.
Changes:
- Import stellarService and StellarServiceError in credential.controller.ts
- verifyCredential now:
- Calls stellarService.verifyCredential(credential.onChainId) when
onChainId is present; maps isValid → valid and verified/unverified status
- Returns valid:false + status:'unverified' for credentials with onChainId
null — they have never been issued on-chain
- Catches StellarServiceError with code CONTRACT_NOT_CONFIGURED and fails
closed (valid:false, status:'error') rather than forging a positive result
- Propagates other StellarServiceErrors to the asyncHandler error pipeline
- Updated credential.controller.test.ts:
- Added vi.mock for '../../src/services/stellar.service'
- New tests: stellarService called with onChainId; isValid:false path;
null onChainId → no stellar call; CONTRACT_NOT_CONFIGURED → status:error;
endpoint never returns valid:true without an on-chain call
Closes Kqirox#7
6 tasks
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.
Summary
Closes #7
Wires
verifyCredentialto actually callstellarService.verifyCredentialand maps the on-chain result into the response. The critical design decision: the endpoint fails closed — ifonChainIdis null or the Soroban contract is not configured, it returnsvalid: falserather than forging a positive result.Why
The handler previously hardcoded:
stellarServicewas not imported anywhere insrc/. The flagship "public, on-chain verification" feature reported verified for any database row, including rows whereonChainIdwasnull. An integrator trusting this endpoint was verifying nothing.What was built
src/controllers/credential.controller.tsstellarServiceandStellarServiceErrorimported;verifyCredentialcallsstellarService.verifyCredential; three distinct result paths (verified, unverified, error)tests/unit/credential.controller.test.tsvi.mockfor stellar.service; 7 updated/new tests for the verify suiteIntegration changes outside module
src/controllers/credential.controller.ts—stellarServicesingleton import added; no other file changed.Acceptance criteria coverage
verifyCredentialinvokesstellarService.verifyCredentialwhenonChainIdis present and mapsisValidinto the response (credential.controller.test.ts— "should call stellarService.verifyCredential when onChainId is present")onChainId: nullreturnsvalid: falseand a non-verifiedstatus (credential.controller.test.ts— "should return valid:false and status:unverified when onChainId is null"; assertsstellarServiceis NOT called)StellarServiceErrorfrom a missing contract configuration surfaces as a controlled error rather than a forged success (credential.controller.test.ts— "should fail closed when Soroban contract is not configured"; returnsvalid:false, status:'error')stellarService.verifyCredentialand assert bothisValid: trueandisValid: falseresponses (credential.controller.test.ts— "should call stellarService" and "should return valid:false when stellarService returns isValid:false")valid: truewithout the on-chain call (credential.controller.test.ts— "should never return valid:true without calling stellarService")Test plan
pnpm test:ci— 281/281 passing (7 updated/new verify tests)pnpm build(tsc) — no type errorspnpm lint— no errors or warningsEnv vars / Notes
SOROBAN_CONTRACT_IDmust be set in production for on-chain verification to returnvalid: true. Without it, the endpoint returnsvalid: false, status: 'error'with an explanatory message — intentional fail-closed behavior.