The StarkRemit platform includes a comprehensive user onboarding and registration system that allows new users to create accounts, manage their profiles, and undergo KYC verification. This document provides detailed information about the registration functionality, API usage, and integration guidelines.
- User Registration: Create new user accounts with validated personal information
- Duplicate Prevention: Prevent multiple registrations with the same email or phone number
- Data Validation: Comprehensive validation of all user input data
- Event Logging: Complete audit trail of all registration activities
- Profile Management: Update and maintain user profile information
- KYC System: Multi-level KYC verification system
- Admin Controls: Administrative functions for user management
#[derive(Copy, Drop, Serde)]
pub struct RegistrationRequest {
pub email_hash: felt252, // Hashed email for privacy
pub phone_hash: felt252, // Hashed phone number for privacy
pub full_name: felt252, // User's full name
pub preferred_currency: felt252, // User's preferred currency
pub country_code: felt252, // User's country code
}
#[derive(Copy, Drop, Serde, starknet::Store)]
pub struct UserProfile {
pub address: ContractAddress, // User's wallet address
pub email_hash: felt252, // Email hash for uniqueness
pub phone_hash: felt252, // Phone hash for uniqueness
pub full_name: felt252, // Full name
pub preferred_currency: felt252, // Preferred currency
pub kyc_level: KYCLevel, // KYC verification level
pub registration_timestamp: u64, // Registration time
pub is_active: bool, // Account status
pub country_code: felt252, // Country code
}pub enum KYCLevel {
None, // No verification completed
Basic, // Email and phone verified
Advanced, // ID documents verified
Full, // Complete verification including address proof
}pub enum RegistrationStatus {
NotStarted, // User hasn't begun registration
InProgress, // Registration in progress
Completed, // Registration successfully completed
Failed, // Registration failed validation
Suspended, // Account suspended by admin
}Register a new user with the platform.
Parameters:
registration_data: Complete registration information
Returns: true if registration successful
Validation Rules:
- All fields must be non-empty (not 0)
- Email hash must be unique across the platform
- Phone hash must be unique across the platform
- Preferred currency must be supported by the platform
- Caller address cannot be zero address
- User cannot already be registered
Events Emitted:
UserRegisteredwith user details
Example Usage:
let registration_data = RegistrationRequest {
email_hash: 'hashed_email_value',
phone_hash: 'hashed_phone_value',
full_name: 'John Doe',
preferred_currency: 'USD',
country_code: 'US',
};
let success = contract.register_user(registration_data);Retrieve a user's complete profile information.
Parameters:
user_address: The wallet address of the user
Returns: Complete UserProfile struct
Requirements:
- User must be registered and have status
Completed
Update user profile information (user can only update their own profile).
Parameters:
updated_profile: Updated profile information
Returns: true if update successful
Restrictions:
- Only the profile owner can update their profile
- Address and registration timestamp cannot be changed
- Email and phone changes must maintain uniqueness
- New preferred currency must be supported
Events Emitted:
UserProfileUpdated
Check if a user is registered and active.
Parameters:
user_address: User's wallet address
Returns: true if user is registered with Completed status
Get the current registration status of a user.
Parameters:
user_address: User's wallet address
Returns: Current RegistrationStatus
Validate registration data without creating an account.
Parameters:
registration_data: Data to validate
Returns: true if all validation rules pass
Update a user's KYC verification level (admin only).
Parameters:
user_address: Target user's addresskyc_level: New KYC level
Returns: true if update successful
Requirements:
- Caller must be contract admin
- User must be registered
Events Emitted:
KYCLevelUpdatedwith old and new levels
Deactivate a user account (admin only).
Parameters:
user_address: User to deactivate
Returns: true if deactivation successful
Effects:
- Sets user status to
Suspended - Sets
is_activetofalse
Events Emitted:
UserDeactivated
Reactivate a suspended user account (admin only).
Parameters:
user_address: User to reactivate
Returns: true if reactivation successful
Events Emitted:
UserReactivated
Get the total number of registered users.
Returns: Total user count
Before calling the registration function, prepare user data:
// Hash sensitive data on frontend before sending
const emailHash = hashFunction(userEmail);
const phoneHash = hashFunction(userPhoneNumber);
const registrationData = {
email_hash: emailHash,
phone_hash: phoneHash,
full_name: convertToFelt252(userName),
preferred_currency: convertToFelt252('USD'),
country_code: convertToFelt252(userCountry)
};// Step 1: Validate data locally
const isValid = await contract.validate_registration_data(registrationData);
if (!isValid) {
throw new Error('Invalid registration data');
}
// Step 2: Check if user is already registered
const isRegistered = await contract.is_user_registered(userAddress);
if (isRegistered) {
throw new Error('User already registered');
}
// Step 3: Register user
try {
const result = await contract.register_user(registrationData);
if (result) {
console.log('Registration successful');
// Redirect to dashboard or next step
}
} catch (error) {
// Handle specific errors
if (error.message.includes('Email already exists')) {
showError('Email already registered');
} else if (error.message.includes('Phone already exists')) {
showError('Phone number already registered');
}
// ... handle other errors
}// Get user profile
const profile = await contract.get_user_profile(userAddress);
// Update profile
const updatedProfile = {
...profile,
full_name: convertToFelt252(newFullName),
preferred_currency: convertToFelt252(newCurrency)
};
await contract.update_user_profile(updatedProfile);Monitor registration events for analytics and compliance:
// Events to monitor
event UserRegistered {
user_address: ContractAddress,
email_hash: felt252,
preferred_currency: felt252,
registration_timestamp: u64,
}
event UserProfileUpdated {
user_address: ContractAddress,
updated_fields: felt252,
}
event KYCLevelUpdated {
user_address: ContractAddress,
old_level: KYCLevel,
new_level: KYCLevel,
admin: ContractAddress,
}- Email and Phone Hashing: Always hash email and phone data before storing
- Off-chain Storage: Consider storing detailed personal information off-chain
- Access Control: Implement proper access controls for sensitive operations
- Input Sanitization: Validate all inputs on both frontend and smart contract
- Duplicate Prevention: The system prevents duplicate registrations
- Admin Controls: Admin functions are properly protected
- KYC Integration: Implement proper KYC verification workflows
- Data Protection: Ensure compliance with data protection regulations
- Audit Trail: All operations are logged via events
| Error | Cause | Solution |
|---|---|---|
User already registered |
Attempting to register an existing user | Check registration status first |
Email already exists |
Email hash collision | Use different email address |
Phone already exists |
Phone hash collision | Use different phone number |
Incomplete registration data |
Missing required fields | Validate all fields are populated |
Unsupported currency |
Invalid preferred currency | Use supported currency codes |
Zero address not allowed |
Invalid wallet address | Ensure valid wallet connection |
ERC20: not admin |
Non-admin calling admin function | Use admin account for admin operations |
- Pre-validation: Always validate data before blockchain calls
- Error Feedback: Provide clear error messages to users
- Progressive Registration: Consider multi-step registration for better UX
- State Management: Track registration progress on frontend
- Retry Logic: Implement retry mechanisms for network issues
The system includes comprehensive tests covering:
- Successful registration flow
- Duplicate prevention (address, email, phone)
- Data validation
- KYC level management
- User activation/deactivation
- Admin function authorization
- Event emission verification
Test the complete flow:
- User data collection
- Data validation
- Registration submission
- Profile retrieval
- Profile updates
- KYC progression
- Deploy contract with proper admin configuration
- Set up supported currencies
- Configure oracle for exchange rates
- Test registration flow end-to-end
- Verify event monitoring setup
- Implement error handling in frontend
- Set up compliance monitoring
- Configure admin access controls
- Check prerequisites: Ensure user has valid wallet connection
- Validate data: Verify all required fields are properly formatted
- Check duplicates: Ensure email/phone haven't been used before
- Verify currency: Confirm preferred currency is supported
- Admin verification: For admin functions, ensure proper permissions
- Batch operations where possible
- Cache user profiles for frequent access
- Use events for real-time updates
- Implement pagination for user lists
For additional support, refer to the contract documentation or contact the development team.