|
| 1 | +# Quasar Private Key Access Feature |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The Quasar wallet now supports requesting private key access during connection. This is a **high-security feature** that should only be used when absolutely necessary and with trusted applications. |
| 6 | + |
| 7 | +## API Changes |
| 8 | + |
| 9 | +### Updated `connect()` Method |
| 10 | + |
| 11 | +The `connect()` method now accepts a `QuasarConnectionParams` object: |
| 12 | + |
| 13 | +```typescript |
| 14 | +interface QuasarConnectionParams { |
| 15 | + address?: string; // Connect to specific wallet address |
| 16 | + return_private_key?: boolean; // Request private key access |
| 17 | +} |
| 18 | + |
| 19 | +// New signature |
| 20 | +async connect(params?: QuasarConnectionParams | string): Promise<WalletAccount[]> |
| 21 | +``` |
| 22 | + |
| 23 | +### Backward Compatibility |
| 24 | + |
| 25 | +The method maintains backward compatibility. You can still pass a string as the address: |
| 26 | + |
| 27 | +```javascript |
| 28 | +// Old way (still works) |
| 29 | +await quasar.connect("0x1234567890abcdef..."); |
| 30 | + |
| 31 | +// New way |
| 32 | +await quasar.connect({ |
| 33 | + address: "0x1234567890abcdef...", |
| 34 | + return_private_key: false |
| 35 | +}); |
| 36 | +``` |
| 37 | + |
| 38 | +## Usage Examples |
| 39 | + |
| 40 | +### Basic Connection |
| 41 | +```javascript |
| 42 | +// Connect normally (no changes needed) |
| 43 | +const accounts = await quasar.connect(); |
| 44 | +``` |
| 45 | + |
| 46 | +### Connect with Private Key Access |
| 47 | +```javascript |
| 48 | +// Request private key access |
| 49 | +const result = await quasar.connect({ |
| 50 | + return_private_key: true |
| 51 | +}); |
| 52 | + |
| 53 | +// Private key will be included in the response |
| 54 | +console.log('Private key:', result.privateKey); |
| 55 | +``` |
| 56 | + |
| 57 | +### Connect to Specific Address with Private Key |
| 58 | +```javascript |
| 59 | +// Connect to specific wallet and request private key |
| 60 | +const result = await quasar.connect({ |
| 61 | + address: "0x1234567890abcdef...", |
| 62 | + return_private_key: true |
| 63 | +}); |
| 64 | +``` |
| 65 | + |
| 66 | +## Security Features |
| 67 | + |
| 68 | +When `return_private_key: true` is requested: |
| 69 | + |
| 70 | +### 1. Security Warning Dialog |
| 71 | +- A prominent warning is displayed to the user |
| 72 | +- Clear indication of the security implications |
| 73 | +- Visual emphasis on the risks |
| 74 | + |
| 75 | +### 2. Confirmation Phrase Requirement |
| 76 | +- User must type the exact phrase: **"I understand the security risks"** |
| 77 | +- Prevents accidental approval |
| 78 | +- Ensures user awareness of the implications |
| 79 | + |
| 80 | +### 3. Visual Indicators |
| 81 | +- Red color scheme for private key requests |
| 82 | +- Warning icons and messages |
| 83 | +- Disabled approve button until phrase is correctly entered |
| 84 | + |
| 85 | +## Security Best Practices |
| 86 | + |
| 87 | +### For Developers |
| 88 | +1. **Only request private key access when absolutely necessary** |
| 89 | +2. **Never store private keys in logs or persistent storage** |
| 90 | +3. **Use private key access only for legitimate cryptographic operations** |
| 91 | +4. **Implement proper key handling and memory cleanup** |
| 92 | +5. **Test only with development/test wallets** |
| 93 | + |
| 94 | +### For Users |
| 95 | +1. **Only approve private key requests from trusted applications** |
| 96 | +2. **Verify the website URL before entering the confirmation phrase** |
| 97 | +3. **Never approve private key requests from unknown websites** |
| 98 | +4. **Use separate test wallets for development** |
| 99 | + |
| 100 | +## Response Format |
| 101 | + |
| 102 | +When private key access is granted, the response includes additional fields: |
| 103 | + |
| 104 | +```javascript |
| 105 | +{ |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +## Error Handling |
| 110 | + |
| 111 | +```javascript |
| 112 | + |
| 113 | +``` |
| 114 | + |
| 115 | +## Testing |
| 116 | + |
| 117 | +Use the provided test page: `tests/private-key-test.html` |
| 118 | + |
| 119 | +This page includes: |
| 120 | +- Normal connection test |
| 121 | +- Private key access test |
| 122 | +- Multi-parameter connection test |
| 123 | +- Security warning demonstrations |
| 124 | + |
| 125 | +## Implementation Details |
| 126 | + |
| 127 | +### Files Modified |
| 128 | +- `src/lib/browser/wallet-injection.ts` - Updated connect method signature |
| 129 | +- `src/pages/Background/index.js` - Enhanced connection parameter handling |
| 130 | +- `src/pages/Popup/RequestDialog.tsx` - Added security warning UI and validation |
| 131 | +- `src/pages/Popup/RequestDialog.css` - Styled security warning components |
| 132 | +- `src/pages/Panel/Panel.tsx` - Updated dev tools to support new parameters |
| 133 | + |
| 134 | +### Security Measures Implemented |
| 135 | +1. **Phrase verification** - Exact match required for confirmation |
| 136 | +2. **Visual warnings** - Red color scheme and warning icons |
| 137 | +3. **Disabled controls** - Approval disabled until phrase is entered |
| 138 | +4. **Clear messaging** - Explicit security warnings and implications |
| 139 | +5. **Parameter validation** - Proper handling of connection parameters |
| 140 | + |
| 141 | +## Migration Guide |
| 142 | + |
| 143 | +### From v5.4.30 and earlier |
| 144 | +```javascript |
| 145 | +// Old code |
| 146 | +const accounts = await quasar.connect(); |
| 147 | +const accountsWithAddress = await quasar.connect("0x123..."); |
| 148 | + |
| 149 | +// New code (backward compatible) |
| 150 | +const accounts = await quasar.connect(); |
| 151 | +const accountsWithAddress = await quasar.connect("0x123..."); |
| 152 | + |
| 153 | +// Or use new parameter object |
| 154 | +const accounts = await quasar.connect({}); |
| 155 | +const accountsWithAddress = await quasar.connect({ |
| 156 | + address: "0x123..." |
| 157 | +}); |
| 158 | + |
| 159 | +// New private key access |
| 160 | +const result = await quasar.connect({ |
| 161 | + return_private_key: true |
| 162 | +}); |
| 163 | +``` |
| 164 | + |
| 165 | +No breaking changes - all existing code continues to work unchanged. |
0 commit comments