Skip to content

SEP-12 KYC Field Submission Handler #585

Description

@Kingsman-99

Description

Cross-border payment flows mediated by SEP-31 anchors require counterparties to complete KYC via the SEP-12 PUT /customer endpoint before a transfer can proceed. The SDK currently leaves callers to construct and submit these requests manually with no field validation or structured error handling. A SEP-12 handler would abstract the upload of KYC text fields and binary documents, poll for approval status, and surface a typed KycNeedsInfoError when the anchor rejects or requests additional fields.

Technical Context

New module src/sep/sep12.ts with a Sep12Client class. Derives the KYC_SERVER URL from the anchor's TOML file using existing TOML utilities in src/utils/toml.ts. Interfaces KycFields, KycDocument, KycStatus, and KycNeedsInfoError added to src/types.ts. Uses FormData and fetch for multipart document upload. The existing SEP-10 auth interceptor in src/auth/sep10.ts is reused to attach the bearer token automatically.

Acceptance Criteria

  • Sep12Client.putCustomer(fields: KycFields, docs?: KycDocument[]) submits text fields and optional binary attachments in a single multipart/form-data PUT request
  • Sep12Client.getCustomer(id: string): Promise<KycStatus> returns a typed status object with discriminated union ACCEPTED | PROCESSING | NEEDS_INFO | REJECTED
  • When status is NEEDS_INFO, the resolved value includes a missingFields: string[] list derived from the anchor's response body
  • The SEP-10 JWT is automatically attached as Authorization: Bearer <token> without callers having to pass it manually
  • Tests use a mock anchor HTTP server and cover the full status lifecycle plus the NEEDS_INFO and REJECTED error paths
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions