Skip to content

Query KYC Status from Soroban Contract [wallet -service]Β #153

Description

@salazarsebas

πŸ”‘ Query KYC Status from Soroban Contract πŸ› οΈ

πŸ“ Description

Implement an API endpoint to query the KYC/KYB status from the Soroban smart contract for the Stellar wallet service. This endpoint will allow clients to retrieve the verification status (e.g., approved or rejected) of a KYC record by its ID, enabling verification of user identity data stored on the blockchain.

🎯 Objective

Create a GET /kyc/status/:id endpoint in services/stellar-wallet/src/routes/kyc-status.js to retrieve the KYC status from the Soroban contract, with a unit test to verify functionality.

πŸ—‚ Structure

  • Directory: services/stellar-wallet
  • Files:
    • src/routes/kyc-status.js
    • tests/routes/kyc-status.test.js
  • Expected structure:
    services/stellar-wallet
    β”œβ”€β”€ src
    β”‚   β”œβ”€β”€ index.js
    β”‚   β”œβ”€β”€ stellar
    β”‚   β”‚   β”œβ”€β”€ client.js
    β”‚   β”‚   β”œβ”€β”€ keys.js
    β”‚   β”‚   └── fund.js
    β”‚   β”œβ”€β”€ db
    β”‚   β”‚   └── kyc.js
    β”‚   β”œβ”€β”€ routes
    β”‚   β”‚   β”œβ”€β”€ kyc.js
    β”‚   β”‚   β”œβ”€β”€ kyc-verify.js
    β”‚   β”‚   └── kyc-status.js
    β”‚   β”œβ”€β”€ kyc
    β”‚   β”‚   └── validate.js
    β”‚   └── soroban
    β”‚       β”œβ”€β”€ client.js
    β”‚       β”œβ”€β”€ kyc-contract.rs
    β”‚       └── deploy.js
    β”œβ”€β”€ config
    β”‚   └── db.sqlite
    β”œβ”€β”€ tests
    β”‚   β”œβ”€β”€ stellar
    β”‚   β”‚   β”œβ”€β”€ client.test.js
    β”‚   β”‚   β”œβ”€β”€ keys.test.js
    β”‚   β”‚   └── fund.test.js
    β”‚   β”œβ”€β”€ db
    β”‚   β”‚   └── kyc.test.js
    β”‚   β”œβ”€β”€ routes
    β”‚   β”‚   β”œβ”€β”€ kyc.test.js
    β”‚   β”‚   β”œβ”€β”€ kyc-verify.test.js
    β”‚   β”‚   └── kyc-status.test.js
    β”‚   β”œβ”€β”€ kyc
    β”‚   β”‚   └── validate.test.js
    β”‚   └── soroban
    β”‚       β”œβ”€β”€ client.test.js
    β”‚       └── deploy.test.js
    β”œβ”€β”€ package.json
    β”œβ”€β”€ .env.example
    β”œβ”€β”€ .eslintrc.json
    β”œβ”€β”€ .eslintignore
    β”œβ”€β”€ .prettierrc.json
    β”œβ”€β”€ .prettierignore
    β”œβ”€β”€ .gitignore
    

βœ… Requirements

  • Create a branch named feat/kyc-status-endpoint for this task.
  • Create src/routes/kyc-status.js to define a GET /kyc/status/:id endpoint using Express.
  • Configure the endpoint to accept a URL parameter id (the kyc_id from the SQLite database and Soroban contract).
  • Validate that id is a non-empty string; return HTTP 400 with a JSON error message (e.g., { error: "Invalid KYC ID" }) if invalid.
  • Use the Soroban client (from Issue 11) and contract ID (from Issue 13) to call the get_kyc_status function of the KYC contract (from Issue 12) with the provided kyc_id.
  • Return a JSON response with HTTP status 200 and the status (e.g., { kyc_id, status }).
  • Handle errors (e.g., non-existent kyc_id, contract call failure) with HTTP 404 or 500 and a JSON error message (e.g., { error: "KYC record not found" }).
  • Create a unit test in tests/routes/kyc-status.test.js to verify:
    • Successful queries return HTTP 200 with the correct status.
    • Invalid or non-existent kyc_id returns HTTP 400 or 404.
  • Mock the Soroban client in the unit test to avoid network dependencies.
  • Update src/index.js to mount the KYC status routes at /kyc/status.
  • Ensure the code adheres to ESLint and Prettier rules (from Issue 3).
  • Commit changes to the feat/kyc-status-endpoint branch with a message like feat: query kyc status.
  • Verify that the CI pipeline (from Issue 1) passes, with linting and test jobs succeeding.

πŸ† Expected Outcomes

  • src/routes/kyc-status.js defines a GET /kyc/status/:id endpoint that retrieves the KYC status from the Soroban contract.
  • Valid kyc_id queries return HTTP 200 with a JSON response containing kyc_id and status.
  • Invalid or non-existent kyc_id queries return appropriate HTTP status codes and JSON error messages.
  • Unit test in tests/routes/kyc-status.test.js confirms correct behavior for valid and invalid inputs.
  • Express server mounts KYC status routes correctly.
  • Code passes ESLint and Prettier checks.
  • Changes are committed to the feat/kyc-status-endpoint branch with a descriptive lowercase commit message.
  • CI pipeline runs successfully, with linting passing for src/routes/kyc-status.js and tests/routes/kyc-status.test.js, and the unit test passing.

πŸ”— References

πŸ“‹ Notes

  • The kyc_id should match the ID used in the SQLite database and Soroban contract.
  • Mocking the Soroban client in tests ensures reliable CI execution without network dependencies.
  • Error handling should differentiate between invalid input (HTTP 400) and non-existent records (HTTP 404).
  • Commit messages must be in lowercase and start with feat, change, fix, chore, or refactor.
  • The CI pipeline should validate the new code, ensuring ESLint passes and the unit test executes successfully.

Metadata

Metadata

Assignees

Labels

onlydust-waveContribute to awesome OSS repos during OnlyDust's open source week

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions