BLGV Authentication Integration Plan
Bridge Treasury Email/Password โ Mobile Wallet Authentication
๐ฏ GOALโ
Enable seamless user experience where users can:
- Login to Treasury platform with email/password
- Link their mobile wallet address to their Treasury account
- Access same user data across all platforms
๐ CURRENT STATEโ
โ
Treasury Platform: Email/password auth with roles (admin, treasury, user, insider)
โ
Mobile App: Wallet creation + QR code auth to DEX/Pool platforms
โ
Profile Sync API: Backend infrastructure for linking wallets to accounts
โ Missing: UI flow to connect Treasury email accounts with mobile wallets
๐ง IMPLEMENTATION STEPSโ
Step 1: Treasury Platform - Add Mobile Wallet Linkingโ
1.1 Update Settings Page (platforms/treasury/client/src/pages/UserProfile.tsx)โ
// Add wallet linking section
const [showWalletLink, setShowWalletLink] = useState(false);
const [qrCodeData, setQrCodeData] = useState(null);
const generateWalletLinkQR = async () => {
const linkData = {
action: 'link_wallet',
platform: 'treasury',
userEmail: user.email,
challenge: `BLGV-TREASURY-LINK-${Date.now()}`,
endpoint: 'https://blgvbtc.com/api/profile/link-wallet'
};
setQrCodeData(JSON.stringify(linkData));
};
// UI Component
<Card>
<CardHeader>
<CardTitle>Mobile Wallet Integration</CardTitle>
</CardHeader>
<CardContent>
{!user.walletAddress ? (
<>
<p>Link your mobile wallet to access the full BLGV ecosystem</p>
<Button onClick={() => setShowWalletLink(true)}>
Link Mobile Wallet
</Button>
{showWalletLink && (
<QRCode value={qrCodeData} />
)}
</>
) : (
<div>
<p>โ
Wallet Linked: {user.walletAddress}</p>
<Button variant="outline">Manage Wallet</Button>
</div>
)}
</CardContent>
</Card>
1.2 Add Wallet Linking API Endpoint (platforms/treasury/server/routes.ts)โ
app.post('/api/profile/link-wallet', isAuthenticated, async (req, res) => {
try {
const { walletAddress, signature, challenge } = req.body;
const userId = req.session.userId;
// Verify signature (implement Bitcoin message verification)
const isValidSignature = await verifyBitcoinSignature(
walletAddress,
challenge,
signature
);
if (!isValidSignature) {
return res.status(400).json({ error: 'Invalid signature' });
}
// Link wallet to user account
await storage.updateUser(userId, {
walletAddress: walletAddress
});
// Sync to mobile profile system
await syncToMobileProfile(userId, walletAddress);
res.json({
success: true,
message: 'Wallet linked successfully',
walletAddress
});
} catch (error) {
res.status(500).json({ error: 'Failed to link wallet' });
}
});
Step 2: Mobile App - Add Treasury Account Linkingโ
2.1 Update Onboarding Flow (platforms/blgv-wallet-app/src/screens/onboarding/OnboardingScreen.tsx)โ
const [hasExistingAccount, setHasExistingAccount] = useState(null);
const [treasuryCredentials, setTreasuryCredentials] = useState({ email: '', password: '' });
// Add screen after wallet creation
<View style={styles.screen}>
<Text style={styles.title}>Connect Your Account</Text>
<Text style={styles.subtitle}>
Do you have an existing BLGV Treasury account?
</Text>
<Button
title="Yes - Link Existing Account"
onPress={() => setHasExistingAccount(true)}
/>
<Button
title="No - Create New Profile"
onPress={() => setHasExistingAccount(false)}
/>
</View>
{hasExistingAccount && (
<View style={styles.screen}>
<Text style={styles.title}>Link Treasury Account</Text>
<TextInput
placeholder="Email"
value={treasuryCredentials.email}
onChangeText={(email) => setTreasuryCredentials(prev => ({...prev, email}))}
/>
<TextInput
placeholder="Password"
secureTextEntry
value={treasuryCredentials.password}
onChangeText={(password) => setTreasuryCredentials(prev => ({...prev, password}))}
/>
<Button title="Link Account" onPress={linkToTreasuryAccount} />
</View>
)}
2.2 Implement Treasury Account Linkingโ
const linkToTreasuryAccount = async () => {
try {
// 1. Authenticate with Treasury platform
const authResponse = await fetch('https://blgvbtc.com/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(treasuryCredentials)
});
if (!authResponse.ok) {
throw new Error('Invalid Treasury credentials');
}
const authData = await authResponse.json();
// 2. Link wallet to Treasury account
const linkResponse = await fetch('https://blgvbtc.com/api/profile/link-wallet', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authData.token}`
},
body: JSON.stringify({
walletAddress: userWallet.address,
signature: await signMessage('LINK_TREASURY_ACCOUNT'),
challenge: 'LINK_TREASURY_ACCOUNT'
})
});
if (linkResponse.ok) {
// 3. Sync profile data
await profileSync.syncProfile(userWallet.address, authData.user);
Alert.alert(
'Account Linked!',
'Your Treasury account is now connected to your mobile wallet.'
);
}
} catch (error) {
Alert.alert('Linking Failed', error.message);
}
};
Step 3: Enhanced Profile Syncโ
3.1 Update Profile Sync to Handle Treasury Integrationโ
// platforms/treasury/server/mobile-profile-routes.ts
const syncToMobileProfile = async (treasuryUserId: number, walletAddress: string) => {
// Get Treasury user data
const treasuryUser = await storage.getUser(treasuryUserId);
// Create/update mobile profile with Treasury data
await db.insert(userProfiles).values({
primaryWallet: walletAddress,
walletAddresses: [walletAddress],
preferences: {
currency: 'USD',
theme: 'dark',
notifications: {
treasury: true,
mining: treasuryUser.role === 'treasury',
dex: treasuryUser.role === 'treasury',
price: true
}
},
verificationStatus: {
equityVerified: treasuryUser.role === 'admin' || treasuryUser.role === 'treasury',
kycCompleted: treasuryUser.status === 'approved',
accreditedInvestor: ['insider', 'treasury', 'admin'].includes(treasuryUser.role)
},
crossPlatformData: {
treasuryAccount: {
email: treasuryUser.email,
role: treasuryUser.role,
linkedAt: new Date().toISOString()
}
}
}).onConflictDoUpdate({
target: userProfiles.primaryWallet,
set: {
// Merge Treasury data with existing profile
lastSyncAt: new Date()
}
});
};
๐ฏ TESTING STRATEGYโ
Test Scenario 1: New Userโ
- โ User creates wallet in mobile app
- โ User chooses "Create New Profile"
- โ Profile syncs to unified database
- โ User can access DEX/Pool via mobile wallet auth
Test Scenario 2: Existing Treasury Userโ
- โ User has Treasury account ([email protected])
- โ User creates wallet in mobile app
- โ User chooses "Link Existing Account"
- โ User enters Treasury email/password
- โ Wallet gets linked to Treasury account
- โ User gets Treasury role permissions in mobile app
Test Scenario 3: Treasury User Adds Mobileโ
- โ User logs into Treasury platform
- โ User goes to Settings โ Mobile Wallet
- โ User scans QR code with mobile app
- โ Mobile wallet gets linked to Treasury account
- โ Cross-platform sync works seamlessly
๐ DEPLOYMENT TIMELINEโ
โ COMPLETED: Treasury platform wallet linking UI + API โ COMPLETED: Mobile app Treasury account linking flow โณ NEXT: Testing and refinement โณ NEXT: Deploy to production
โ PHASE 1 IMPLEMENTATION COMPLETEDโ
Treasury Platform Changesโ
- โ Added Mobile Wallet Integration section to UserProfile.tsx
- โ Added QR code generation for wallet linking
- โ Added wallet status display and management UI
- โ
Added
/api/profile/link-walletAPI endpoint with validation - โ Updated User interface to include walletAddress field
- โ Updated database schema with walletAddress column
Mobile App Changesโ
- โ Added new "Account Integration" onboarding step
- โ Added choice between linking existing account vs creating new
- โ Added Treasury login form with email/password inputs
- โ Added Treasury authentication function
- โ Added complete UI styling for all account linking components
- โ Added state management for account linking flow
Database Schema Updatesโ
- โ
Added
walletAddress varcharfield to users table - โ Updated storage.ts to handle wallet address updates
- โ Updated TypeScript types for User interface
๐งช TESTING INSTRUCTIONSโ
Test Scenario 1: Treasury User Links Mobile Walletโ
- Login to Treasury platform ([email protected])
- Go to Profile โ Mobile Wallet Integration section
- Click "Generate QR Code to Link Wallet"
- QR code should display with wallet linking challenge
- Mobile app can scan this QR to link (when mobile auth is complete)
Test Scenario 2: Mobile User Links Treasury Accountโ
- Open mobile app and go through onboarding
- Reach "Account Integration" step
- Choose "Yes - Link Existing Account"
- Enter Treasury credentials ([email protected])
- Account should authenticate and proceed to completion
Test Scenario 3: Mobile User Creates New Profileโ
- Open mobile app and go through onboarding
- Reach "Account Integration" step
- Choose "No - Create New Profile"
- Should proceed to final onboarding step
- Profile will be created with wallet as primary identifier
โ SUCCESS CRITERIAโ
- Unified User Experience: Users can access same data from Treasury web and mobile app
- Role Preservation: Treasury role permissions carry over to mobile app
- Seamless Sync: Wallet activities sync to Treasury platform analytics
- Security: Bitcoin signature verification for all wallet linking
- Backwards Compatible: Existing Treasury users and mobile wallets continue working
This bridges your authentication gap and creates the unified ecosystem experience you're aiming for!