keep-starknet-strange / vault

Empower Your Assets, Redefine Control.
https://vlt.finance
MIT License
23 stars 18 forks source link

Implement /register Endpoint #30

Closed 0xLucqs closed 5 months ago

0xLucqs commented 6 months ago

Issue: Implement /register Endpoint

Description

We need to implement the /register endpoint in the Vault backend. This endpoint is responsible for temporarily registering a new user. It will then wait for the user to confirm the phone number and deploy their account contract.

Details

Request Body:

{
    "phone_number": "+1234567890",
    "address": "0x0123456789abcdefABCDEF0123456789abcdefABCDEF0123456789abcdefABCD",
    "first_name": "John",
    "last_name": "Doe"
}

Response:

{
    "success": true
}

Validation:

Notes:

Upon successful registration, a contract will be deployed based on the provided information.

Example

// Import necessary modules
import fastify from 'fastify';

// Create Fastify instance
const app = fastify({ logger: true });

// Define the register endpoint
app.post('/register', async (request, reply) => {
    try {
        const { phone_number, address, first_name, last_name } = request.body;

        // Perform validation checks
        if (!phone_number.match(/^\+[1-9]\d{1,14}$/)) {
            return reply.status(400).send({ error: 'Invalid phone number format' });
        }

        if (!address.match(/^0x0[0-9a-fA-F]{63}$/)) {
            return reply.status(400).send({ error: 'Invalid StarkNet address format' });
        }

        if (!/^[A-Za-z]{1,20}$/.test(first_name)) {
            return reply.status(400).send({ error: 'Invalid first name format' });
        }

        if (!/^[A-Za-z]{1,20}$/.test(last_name)) {
            return reply.status(400).send({ error: 'Invalid last name format' });
        }

        // If validation passes, proceed with registration
        // Registration logic goes here

        // Return success response
        return { success: true };
    } catch (error) {
        // Handle errors
        console.error('Error during registration:', error);
        return reply.status(500).send({ error: 'Internal Server Error' });
    }
});

// Start the server
app.listen(3000, '0.0.0.0', (err, address) => {
    if (err) throw err;
    console.log(`Server listening on ${address}`);
});

Tasks:

ocdbytes commented 6 months ago

hey @LucasLvy can you assign this issue to me ?

Dprof-in-tech commented 5 months ago

hey @LucasLvy Please i would love to work on this

mubarak23 commented 5 months ago

@LucasLvy if @ocdbytes is occupied, i will like to tackle this issue

0xLucqs commented 5 months ago

Hey this endpoint is done