#!/usr/bin/env node
/**
* Hyperident + SOCKS Proxy Integration Demo
* Demonstrates the complete workflow from Step 11
*/
import { IdentityManager } from './lib/identity-manager.js'
import { SocksProxy } from './socks-server.js'
console.log('🚀 Hyperident + SOCKS Proxy Integration Demo')
console.log('=' .repeat(50))
async function demo() {
try {
// Step 1: Initialize identity
console.log('\n📋 Step 1: Initialize Identity')
console.log('Running: hyperident init')
if (!IdentityManager.identityExists()) {
await IdentityManager.generateIdentity()
console.log('✅ Identity created successfully')
} else {
console.log('✅ Identity already exists')
}
// Step 2: Create profiles
console.log('\n📋 Step 2: Create Profiles')
console.log('Running: hyperident create-profile work')
console.log('Running: hyperident create-profile personal')
try {
await IdentityManager.createProfile('work', 'Work projects and development')
console.log('✅ Work profile created')
} catch (error) {
if (error.message.includes('already exists')) {
console.log('✅ Work profile already exists')
} else {
throw error
}
}
try {
await IdentityManager.createProfile('personal', 'Personal projects')
console.log('✅ Personal profile created')
} catch (error) {
if (error.message.includes('already exists')) {
console.log('✅ Personal profile already exists')
} else {
throw error
}
}
// Step 3: List profiles
console.log('\n📋 Step 3: List Profiles')
console.log('Running: hyperident list-profiles')
const profilesData = await IdentityManager.listProfiles()
const profiles = Object.values(profilesData.profiles)
console.log(`✅ Found ${profiles.length} profiles:`)
profiles.forEach((profile, index) => {
console.log(` ${index + 1}. ${profile.name} - ${profile.description || 'No description'}`)
})
// Step 4: Get profile addresses
console.log('\n📋 Step 4: Generate Profile Addresses')
for (const profile of profiles) {
const address = await IdentityManager.getProfileAddress(profile.name)
console.log(`✅ ${profile.name}: ${address}`)
}
// Step 5: Demonstrate SOCKS proxy with profile
console.log('\n📋 Step 5: Start SOCKS Proxy with Profile')
console.log('Running: node socks-server.js server --profile work')
const workAddress = await IdentityManager.getProfileAddress('work')
const proxy = new SocksProxy({
port: 0, // Use random port for demo
topic: Buffer.from(workAddress, 'hex'),
profileName: 'work'
})
await proxy.start()
const port = proxy.server.address().port
console.log('✅ SOCKS proxy started successfully!')
console.log(` Profile: work`)
console.log(` Address: ${workAddress}`)
console.log(` SOCKS proxy: 127.0.0.1:${port}`)
// Step 6: Demonstrate deterministic addressing
console.log('\n📋 Step 6: Verify Deterministic Addressing')
const address1 = await IdentityManager.getProfileAddress('work')
const address2 = await IdentityManager.getProfileAddress('work')
const address3 = await IdentityManager.getProfileAddress('work')
if (address1 === address2 && address2 === address3) {
console.log('✅ Deterministic addressing verified!')
console.log(` Same profile always generates: ${address1}`)
} else {
console.log('❌ Deterministic addressing failed!')
}
// Step 7: Compare different profiles
console.log('\n📋 Step 7: Compare Profile Addresses')
const workAddr = await IdentityManager.getProfileAddress('work')
const personalAddr = await IdentityManager.getProfileAddress('personal')
console.log(` work: ${workAddr}`)
console.log(` personal: ${personalAddr}`)
if (workAddr !== personalAddr) {
console.log('✅ Different profiles generate different addresses')
} else {
console.log('❌ Different profiles should generate different addresses!')
}
// Step 8: Stop proxy
console.log('\n📋 Step 8: Stop SOCKS Proxy')
await proxy.stop()
console.log('✅ SOCKS proxy stopped')
// Step 9: Integration summary
console.log('\n📋 Step 9: Integration Summary')
console.log('✅ Complete workflow demonstrated:')
console.log(' 1. Identity initialization')
console.log(' 2. Profile creation')
console.log(' 3. Profile listing')
console.log(' 4. Address generation')
console.log(' 5. SOCKS proxy with profile')
console.log(' 6. Deterministic addressing')
console.log(' 7. Profile differentiation')
console.log(' 8. Graceful shutdown')
console.log('\n🎉 Step 11: SOCKS Proxy --profile Flag Implementation COMPLETE!')
console.log('\n💡 Usage Examples:')
console.log(' # Start SOCKS proxy with random address')
console.log(' node socks-server.js server')
console.log('')
console.log(' # Start SOCKS proxy with deterministic profile address')
console.log(' node socks-server.js server --profile work')
console.log('')
console.log(' # Use custom port')
console.log(' node socks-server.js server --profile work --port 8080')
console.log('')
console.log(' # Get help')
console.log(' node socks-server.js --help')
} catch (error) {
console.error('\n❌ Demo failed:', error.message)
if (process.env.DEBUG) {
console.error(error.stack)
}
process.exit(1)
}
}
// Run demo if this file is executed directly
if (import.meta.url === `file://${process.argv[1]}`) {
demo()
}
export { demo }