backend: SEP-12 KYC — signature verification, query optimization, error recovery, audit#833
Merged
emdevelopa merged 1 commit intoMay 27, 2026
Conversation
…mized queries, error recovery Introduce the SEP-12 KYC module (it did not previously exist; the repo only had SEP-10 and SEP-0001) and the four enhancements requested against it: - SEP-12 KYC module: PUT/GET/DELETE /sep12/customer routes backed by a sep12-kyc service and a sep12_kyc_customers table (migration). - Cryptographic signature verification (emdevelopa#590): every KYC write must carry an Ed25519 signature from the account's own Stellar key over a canonical payload (account|memo|timestamp|sha256(fields)), with a 5-minute replay window. - SQL query optimization (emdevelopa#591): single-round-trip parameterized upsert via INSERT ... ON CONFLICT, indexed (stellar_account, memo) lookups, status index; only required columns selected. - Error recovery (emdevelopa#592): a withRecovery wrapper builds on queryWithRetry, surfacing exhausted transient failures as a retryable 503 and everything else as a non-leaky 500 with structured KycError codes. - Security audit (emdevelopa#593): SEP12_KYC_SECURITY_AUDIT.md documents the threat model (auth, replay, SQLi, mass-assignment, PII logging) plus residual risks; the code enforces strict zod field validation and never logs field values. 15 unit tests pass (vitest), covering signature verification, the upsert shape, validation, get/delete, and both error-recovery branches. Closes emdevelopa#590 Closes emdevelopa#591 Closes emdevelopa#592 Closes emdevelopa#593
|
@davidmaronio is attempting to deploy a commit to the Emmanuel's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@davidmaronio Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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
These four issues target the SEP-12 KYC Integration, which did not yet exist in the backend (only SEP-10 auth and SEP-0001 were present). This PR adds the SEP-12 KYC module and implements all four enhancements on it.
PUT/GET/DELETE /sep12/customerroutes (src/routes/sep12.js, mounted inapp.js) backed bysrc/lib/sep12-kyc.jsand asep12_kyc_customerstable (knex migration).account|memo|timestamp|sha256(fields)), verified withKeypair.verify, with a 5-minute replay window.INSERT ... ON CONFLICT (stellar_account, memo)), a unique composite index for the hot upsert/lookup path, astatusindex for dashboards, and column-scoped selects.withRecoverywrapper over the existingqueryWithRetry, surfacing exhausted transient failures as a retryable 503 and everything else as a non-leaky 500 with structuredKycErrorcodes.backend/SEP12_KYC_SECURITY_AUDIT.mddocuments the threat model (auth, replay, SQLi, mass-assignment, PII-in-logs) and residual risks; the code enforces strictzodvalidation (.strict()rejects unknown keys) and never logs field values.Test plan
npx vitest run src/lib/sep12-kyc.test.js— 15 tests pass (valid/forged/stale/wrong-key/missing signatures, parameterised upsert shape, field validation, invalid account, status derivation, get/delete hit & miss, retryable-503 vs non-leaky-500 recovery)node --checkon all new/modified filesNotes
Closes #590
Closes #591
Closes #592
Closes #593