Skip to content

fix(credentials): wire verifyCredential to StellarService - #17

Merged
merlik787-droi merged 1 commit into
Kqirox:mainfrom
ameeribro4-sudo:fix/issue-7-credential-verify-stellar
Aug 19, 2026
Merged

fix(credentials): wire verifyCredential to StellarService#17
merlik787-droi merged 1 commit into
Kqirox:mainfrom
ameeribro4-sudo:fix/issue-7-credential-verify-stellar

Conversation

@ameeribro4-sudo

Copy link
Copy Markdown

Summary

Closes #7

Wires verifyCredential to actually call stellarService.verifyCredential and maps the on-chain result into the response. The critical design decision: the endpoint fails closed — if onChainId is null or the Soroban contract is not configured, it returns valid: false rather than forging a positive result.

Why

The handler previously hardcoded:

res.json({ data: { valid: true, verification: { status: 'verified', message: 'This credential is valid and has been verified on-chain' } } })

stellarService was not imported anywhere in src/. The flagship "public, on-chain verification" feature reported verified for any database row, including rows where onChainId was null. An integrator trusting this endpoint was verifying nothing.

What was built

File What it contains
src/controllers/credential.controller.ts stellarService and StellarServiceError imported; verifyCredential calls stellarService.verifyCredential; three distinct result paths (verified, unverified, error)
tests/unit/credential.controller.test.ts Added vi.mock for stellar.service; 7 updated/new tests for the verify suite

Integration changes outside module

  • src/controllers/credential.controller.tsstellarService singleton import added; no other file changed.

Acceptance criteria coverage

  • verifyCredential invokes stellarService.verifyCredential when onChainId is present and maps isValid into the response (credential.controller.test.ts — "should call stellarService.verifyCredential when onChainId is present")
  • A credential row with onChainId: null returns valid: false and a non-verified status (credential.controller.test.ts — "should return valid:false and status:unverified when onChainId is null"; asserts stellarService is NOT called)
  • A StellarServiceError from 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"; returns valid:false, status:'error')
  • Unit tests mock stellarService.verifyCredential and assert both isValid: true and isValid: false responses (credential.controller.test.ts — "should call stellarService" and "should return valid:false when stellarService returns isValid:false")
  • A test asserts the endpoint no longer returns valid: true without the on-chain call (credential.controller.test.ts — "should never return valid:true without calling stellarService")

Test plan

  • pnpm test:ci281/281 passing (7 updated/new verify tests)
  • pnpm build (tsc) — no type errors
  • pnpm lint — no errors or warnings

Env vars / Notes

SOROBAN_CONTRACT_ID must be set in production for on-chain verification to return valid: true. Without it, the endpoint returns valid: false, status: 'error' with an explanatory message — intentional fail-closed behavior.

…-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

@merlik787-droi merlik787-droi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@merlik787-droi
merlik787-droi merged commit efed828 into Kqirox:main Aug 19, 2026
1 check passed
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.

Credential verify endpoint authenticates nothing: reports verified-on-chain without contacting Stellar

2 participants