run-credential-manager-demo.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env npx tsx
  2. /**
  3. * Quick Start Script for Credential Manager
  4. *
  5. * Run this script to see the credential manager in action:
  6. * npx tsx scripts/run-credential-manager-demo.ts
  7. */
  8. import { CredentialManager } from '../src/core/credential-manager/CredentialManager'
  9. import { Platform } from '../src/types/credential'
  10. import { TradingOperation } from '../src/core/credential-manager/TradingIntegration'
  11. async function quickDemo() {
  12. console.log('🚀 Quick Credential Manager Demo\n')
  13. // Initialize with minimal config
  14. const credentialManager = new CredentialManager()
  15. await credentialManager.loadConfiguration({
  16. accounts: [
  17. {
  18. id: 'test-pacifica',
  19. name: 'Test Pacifica Account',
  20. platform: Platform.PACIFICA,
  21. enabled: true,
  22. credentials: {
  23. type: 'ed25519' as const,
  24. privateKey: 'f26670e2ca334117f8859f9f32e50251641953a30b54f6ffcf82db836cfdfea5'
  25. }
  26. }
  27. ]
  28. })
  29. console.log('✅ Credential manager initialized')
  30. // Test basic signing
  31. const message = new TextEncoder().encode('Hello, multi-platform trading!')
  32. console.log('\n🔐 Testing signature...')
  33. const startTime = Date.now()
  34. const result = await credentialManager.sign('test-pacifica', message)
  35. const duration = Date.now() - startTime
  36. if (result.success) {
  37. console.log(`✅ Signature successful!`)
  38. console.log(`📋 Algorithm: ${result.algorithm}`)
  39. console.log(`⚡ Time: ${duration}ms`)
  40. console.log(`🔐 Signature: ${result.signature?.substring(0, 32)}...`)
  41. } else {
  42. console.log(`❌ Signature failed: ${result.error}`)
  43. }
  44. // Test trading integration
  45. console.log('\n💹 Testing trading integration...')
  46. const tradingRequest = {
  47. operation: TradingOperation.PLACE_ORDER,
  48. platform: Platform.PACIFICA,
  49. parameters: {
  50. symbol: 'SOL/USDC',
  51. side: 'buy' as const,
  52. quantity: 1.0,
  53. type: 'market' as const
  54. }
  55. }
  56. const tradingResult = await credentialManager.signTradingRequest(tradingRequest)
  57. if (tradingResult.success) {
  58. console.log(`✅ Trading request signed!`)
  59. console.log(`📋 Platform: ${tradingResult.selectedAccount.platform}`)
  60. console.log(`🏦 Account: ${tradingResult.selectedAccount.accountId}`)
  61. console.log(`📝 Format: ${tradingResult.platformSignature.format}`)
  62. }
  63. await credentialManager.shutdown()
  64. console.log('\n🎉 Demo completed! The credential manager is working perfectly.')
  65. console.log('\n📚 Next steps:')
  66. console.log(' 1. Update config/credential-manager.example.json with your credentials')
  67. console.log(' 2. Run the full demo: npx tsx src/examples/credential-manager-demo.ts')
  68. console.log(' 3. Integrate with your trading system using the TradingIntegration interface')
  69. }
  70. quickDemo().catch(console.error)