-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Labels
onlydust-waveContribute to awesome OSS repos during OnlyDust's open source weekContribute to awesome OSS repos during OnlyDust's open source week
Description
π Register Biometric Credentials with WebAuthn π οΈ
π Description
Implement an API endpoint to register biometric credentials (e.g., fingerprint or Face ID) using WebAuthn for the Stellar wallet service. This endpoint will allow users to create and store public key credentials securely, associating them with a user ID for authentication in subsequent requests. The registration process will leverage the WebAuthn configuration set up previously to ensure secure and seamless biometric authentication.
π― Objective
Create a POST /auth/register endpoint in services/stellar-wallet/src/routes/auth-register.js to handle WebAuthn credential registration and store credentials in the SQLite database, with a unit test to verify functionality.
π Structure
- Directory:
services/stellar-wallet - Files:
src/routes/auth-register.jstests/routes/auth-register.test.jssrc/db/kyc.js(updated)
- 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 β βββ 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 β βββ 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-registerfor this task. - Update
src/db/kyc.jsto add a tablecredentialswith columnsid(primary key, auto-increment),user_id(string, linked tokyc_id),credential_id(string), andpublic_key(string) for storing WebAuthn credentials. - Create
src/routes/auth-register.jsto define aPOST /auth/registerendpoint using Express. - Configure the endpoint to accept JSON input with
user_id(string, matching akyc_idfrom the SQLite database). - Validate that
user_idexists in thekyctable; return HTTP 400 with a JSON error message (e.g.,{ error: "Invalid user ID" }) if not found. - Use
generateRegistrationOptionsfromsrc/auth/webauthn.js(Issue 16) to create WebAuthn registration options for the client. - Accept the clientβs WebAuthn response, verify it using
@simplewebauthn/server, and store thecredential_idandpublic_keyin thecredentialstable, associated withuser_id. - Return a JSON response with HTTP status 201 and details (e.g.,
{ user_id, credential_id }). - Handle errors (e.g., invalid WebAuthn response) with HTTP 400 or 500 and a JSON error message (e.g.,
{ error: "Failed to register credentials" }). - Create a unit test in
tests/routes/auth-register.test.jsto verify:- Successful registration stores credentials and returns HTTP 201.
- Invalid
user_idor WebAuthn response returns HTTP 400.
- Mock the WebAuthn server and SQLite database in the unit test to avoid external dependencies.
- Update
src/index.jsto mount the authentication routes at/auth/register. - Ensure the code adheres to ESLint and Prettier rules (from Issue 3).
- Commit changes to the
feat/webauthn-registerbranch with a message likefeat: register webauthn credentials. - Verify that the CI pipeline (from Issue 1) passes, with linting and test jobs succeeding.
π Expected Outcomes
src/db/kyc.jsincludes acredentialstable for storing WebAuthn credentials.src/routes/auth-register.jsdefines aPOST /auth/registerendpoint that handles WebAuthn credential registration.- Valid registrations store
credential_idandpublic_keyin thecredentialstable, linked touser_id. - Successful registrations return HTTP 201 with a JSON response containing
user_idandcredential_id. - Invalid inputs or errors return appropriate HTTP status codes and JSON error messages.
- Unit test in
tests/routes/auth-register.test.jsconfirms correct behavior for valid and invalid inputs. - Express server mounts authentication routes correctly.
- Code passes ESLint and Prettier checks.
- Changes are committed to the
feat/webauthn-registerbranch with a descriptive lowercase commit message. - CI pipeline runs successfully, with linting passing for
src/routes/auth-register.js,tests/routes/auth-register.test.js, and updatedsrc/db/kyc.js, and the unit test passing.
π References
- SimpleWebAuthn Server
- WebAuthn Registration
- SQLite3 Node.js Package
- Jest Mocking
- ESLint Node.js Rules
π Notes
- The
user_idshould correspond to akyc_idin thekyctable. - Mocking the WebAuthn server and SQLite database in tests ensures reliable CI execution.
- Ensure credentials are stored securely, avoiding exposure of sensitive data.
- The
credentialstable should be created withIF NOT EXISTSto ensure idempotency. - Commit messages must be in lowercase and start with
feat,change,fix,chore, orrefactor. - The CI pipeline should validate the new code, ensuring ESLint passes and the unit test executes successfully.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
onlydust-waveContribute to awesome OSS repos during OnlyDust's open source weekContribute to awesome OSS repos during OnlyDust's open source week