π Verify Biometric Credentials with WebAuthn π οΈ
π Description
Implement an API endpoint to verify biometric credentials (e.g., fingerprint or Face ID) using WebAuthn for the Stellar wallet service. This endpoint will allow users to authenticate by validating their WebAuthn credentials against stored public keys, ensuring secure access to protected routes and operations in the wallet service.
π― Objective
Create a POST /auth/verify endpoint in services/stellar-wallet/src/routes/auth-verify.js to verify WebAuthn credentials against the SQLite database, with a unit test to confirm functionality.
π Structure
- Directory:
services/stellar-wallet
- Files:
src/routes/auth-verify.js
tests/routes/auth-verify.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
β β βββ auth-register.js
β β βββ auth-verify.js
β βββ kyc
β β βββ validate.js
β βββ soroban
β β βββ client.js
β β βββ kyc-contract.rs
β β βββ deploy.js
β βββ auth
β βββ webauthn.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
β β βββ auth-register.test.js
β β βββ auth-verify.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/webauthn-verify for this task.
- Create
src/routes/auth-verify.js to define a POST /auth/verify endpoint using Express.
- Configure the endpoint to accept JSON input with
user_id (string, matching a kyc_id from the SQLite database) and the WebAuthn authentication response.
- Validate that
user_id exists in the credentials table (from Issue 17); return HTTP 400 with a JSON error message (e.g., { error: "Invalid user ID" }) if not found.
- Use
generateAuthenticationOptions from src/auth/webauthn.js (Issue 16) to create WebAuthn authentication options for the client.
- Verify the clientβs WebAuthn response using
@simplewebauthn/server against the stored credential_id and public_key in the credentials table.
- Return a JSON response with HTTP status 200 and details (e.g.,
{ user_id, verified: true }) if verification succeeds.
- Handle errors (e.g., invalid WebAuthn response, non-existent credentials) with HTTP 401 or 500 and a JSON error message (e.g.,
{ error: "Authentication failed" }).
- Create a unit test in
tests/routes/auth-verify.test.js to verify:
- Successful verification returns HTTP 200 with
verified: true.
- Invalid
user_id or WebAuthn response returns HTTP 401 or 400.
- Mock the WebAuthn server and SQLite database in the unit test to avoid external dependencies.
- Update
src/index.js to mount the authentication verification routes at /auth/verify.
- Ensure the code adheres to ESLint and Prettier rules (from Issue 3).
- Commit changes to the
feat/webauthn-verify branch with a message like feat: verify webauthn credentials.
- Verify that the CI pipeline (from Issue 1) passes, with linting and test jobs succeeding.
π Expected Outcomes
src/routes/auth-verify.js defines a POST /auth/verify endpoint that verifies WebAuthn credentials.
- Valid credentials are verified against the
credentials table, returning HTTP 200 with a JSON response.
- Invalid inputs or failed verifications return appropriate HTTP status codes and JSON error messages.
- Unit test in
tests/routes/auth-verify.test.js confirms correct behavior for valid and invalid inputs.
- Express server mounts authentication verification routes correctly.
- Code passes ESLint and Prettier checks.
- Changes are committed to the
feat/webauthn-verify branch with a descriptive lowercase commit message.
- CI pipeline runs successfully, with linting passing for
src/routes/auth-verify.js and tests/routes/auth-verify.test.js, and the unit test passing.
π References
π Notes
- The
user_id should match a kyc_id in the credentials table.
- Mocking the WebAuthn server and SQLite database in tests ensures reliable CI execution.
- Ensure secure handling of credentials, avoiding exposure of sensitive data like
public_key.
- Verification failures should return HTTP 401 to indicate unauthorized access.
- 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.
π Verify Biometric Credentials with WebAuthn π οΈ
π Description
Implement an API endpoint to verify biometric credentials (e.g., fingerprint or Face ID) using WebAuthn for the Stellar wallet service. This endpoint will allow users to authenticate by validating their WebAuthn credentials against stored public keys, ensuring secure access to protected routes and operations in the wallet service.
π― Objective
Create a
POST /auth/verifyendpoint inservices/stellar-wallet/src/routes/auth-verify.jsto verify WebAuthn credentials against the SQLite database, with a unit test to confirm functionality.π Structure
services/stellar-walletsrc/routes/auth-verify.jstests/routes/auth-verify.test.jsβ Requirements
feat/webauthn-verifyfor this task.src/routes/auth-verify.jsto define aPOST /auth/verifyendpoint using Express.user_id(string, matching akyc_idfrom the SQLite database) and the WebAuthn authentication response.user_idexists in thecredentialstable (from Issue 17); return HTTP 400 with a JSON error message (e.g.,{ error: "Invalid user ID" }) if not found.generateAuthenticationOptionsfromsrc/auth/webauthn.js(Issue 16) to create WebAuthn authentication options for the client.@simplewebauthn/serveragainst the storedcredential_idandpublic_keyin thecredentialstable.{ user_id, verified: true }) if verification succeeds.{ error: "Authentication failed" }).tests/routes/auth-verify.test.jsto verify:verified: true.user_idor WebAuthn response returns HTTP 401 or 400.src/index.jsto mount the authentication verification routes at/auth/verify.feat/webauthn-verifybranch with a message likefeat: verify webauthn credentials.π Expected Outcomes
src/routes/auth-verify.jsdefines aPOST /auth/verifyendpoint that verifies WebAuthn credentials.credentialstable, returning HTTP 200 with a JSON response.tests/routes/auth-verify.test.jsconfirms correct behavior for valid and invalid inputs.feat/webauthn-verifybranch with a descriptive lowercase commit message.src/routes/auth-verify.jsandtests/routes/auth-verify.test.js, and the unit test passing.π References
π Notes
user_idshould match akyc_idin thecredentialstable.public_key.feat,change,fix,chore, orrefactor.