Skip to content

Commit 62eb3a4

Browse files
committed
test: 💍 case use import like aelf-sdk/wallet,keyStore
1 parent 3e9b7c1 commit 62eb3a4

File tree

8 files changed

+568
-27
lines changed

8 files changed

+568
-27
lines changed

examples/reactDemo/README.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ A comprehensive React demo application showcasing the complete functionality of
1818
- **Encryption/Decryption**: AES encrypt and decrypt sensitive data
1919
- **Address Operations**: Get addresses from public keys
2020

21+
### 🔐 KeyStore Management
22+
- **KeyStore Generation**: Create encrypted keyStore files from wallet data
23+
- **KeyStore Import/Export**: Import and export keyStore JSON files
24+
- **Password Protection**: Secure wallet data with password-based encryption
25+
- **Multiple Cipher Support**: Support for various AES encryption modes
26+
- **KeyStore Unlocking**: Decrypt and unlock keyStore files with passwords
27+
- **Password Validation**: Check if passwords are correct for keyStore files
28+
2129
### 📋 Contract Operations
2230
- **Contract Initialization**: Initialize and interact with smart contracts
2331
- **Token Operations**: Get token information, balances, and perform transfers
@@ -50,6 +58,7 @@ src/
5058
├── components/
5159
│ ├── Chain.jsx # Chain operations component
5260
│ ├── Wallet.jsx # Wallet management component
61+
│ ├── KeyStore.jsx # KeyStore management component
5362
│ ├── contract.jsx # Contract operations component
5463
│ ├── Transaction.jsx # Transaction management component
5564
│ └── Utils.jsx # Utils operations component
@@ -94,19 +103,26 @@ Navigate to `http://localhost:5173`
94103
- Encrypt/decrypt sensitive data
95104
- View wallet information and addresses
96105

97-
### 3. Contract Operations Tab
106+
### 3. KeyStore Management Tab
107+
- Generate encrypted keyStore files from wallet data
108+
- Import and export keyStore JSON files
109+
- Test password protection and validation
110+
- Unlock keyStore files with passwords
111+
- Support for multiple AES encryption modes
112+
113+
### 4. Contract Operations Tab
98114
- Initialize token contracts
99115
- Get token information and balances
100116
- Perform transfers and approvals
101117
- Query contract methods and parameters
102118

103-
### 4. Transaction Management Tab
119+
### 5. Transaction Management Tab
104120
- Create custom transactions
105121
- Sign and broadcast transactions
106122
- Track transaction status and results
107123
- Query blocks and merkle paths
108124

109-
### 5. Utils Operations Tab
125+
### 6. Utils Operations Tab
110126
- Test hash functions and encoding
111127
- Perform string operations and conversions
112128
- Handle BigNumber operations
@@ -205,6 +221,28 @@ const result = await tokenContract.Transfer.sendTransaction({
205221
console.log('Transaction ID:', result.TransactionId);
206222
```
207223

224+
### KeyStore Generation and Unlocking
225+
```javascript
226+
// Generate keyStore
227+
const walletData = {
228+
mnemonic: wallet.mnemonic,
229+
privateKey: wallet.privateKey,
230+
nickName: 'My Wallet',
231+
address: wallet.address
232+
};
233+
const keyStore = AElf.utils.keyStore.getKeystore(walletData, 'password123', {
234+
cipher: 'aes-256-cbc'
235+
});
236+
237+
// Unlock keyStore
238+
const unlocked = AElf.utils.keyStore.unlockKeystore(keyStore, 'password123');
239+
console.log('Unlocked private key:', unlocked.privateKey);
240+
241+
// Check password
242+
const isValid = AElf.utils.keyStore.checkPassword(keyStore, 'password123');
243+
console.log('Password valid:', isValid);
244+
```
245+
208246
## 🚨 Important Notes
209247

210248
- **Test Environment**: This demo uses test networks and test private keys

examples/reactDemo/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
"dependencies": {
1212
"aelf-sdk": "^3.5.0-beta.8",
1313
"react": "^18.2.0",
14-
"react-dom": "^18.2.0"
14+
"react-dom": "^18.2.0",
15+
"buffer": "^5.2.1",
16+
"minimalistic-assert": "^1.0.1",
17+
"stream-browserify": "^3.0.0"
1518
},
1619
"devDependencies": {
1720
"@types/react": "^18.2.66",

examples/reactDemo/src/App.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,47 @@
318318
font-weight: 500;
319319
}
320320

321+
.keystore-info {
322+
background: #f8f9fa;
323+
border-radius: 6px;
324+
padding: 15px;
325+
margin: 15px 0;
326+
}
327+
328+
.keystore-info p {
329+
margin: 8px 0;
330+
color: #495057;
331+
word-break: break-all;
332+
font-size: 14px;
333+
}
334+
335+
.info-content {
336+
background: #f8f9fa;
337+
border-radius: 6px;
338+
padding: 15px;
339+
margin: 15px 0;
340+
}
341+
342+
.info-content h4 {
343+
margin-top: 0;
344+
color: #495057;
345+
font-size: 14px;
346+
font-weight: 600;
347+
margin-bottom: 10px;
348+
}
349+
350+
.info-content ul {
351+
margin: 10px 0;
352+
padding-left: 20px;
353+
}
354+
355+
.info-content li {
356+
margin: 5px 0;
357+
color: #495057;
358+
font-size: 14px;
359+
line-height: 1.4;
360+
}
361+
321362
.chain-info,
322363
.pool-info,
323364
.peers-info,

examples/reactDemo/src/App.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ChainComponent from './components/Chain';
77
import Contract from './components/contract';
88
import TransactionComponent from './components/Transaction';
99
import UtilsComponent from './components/Utils';
10+
import KeyStoreComponent from './components/KeyStore';
1011

1112
window.AElf = AElf;
1213

@@ -53,6 +54,7 @@ function App() {
5354
const tabs = [
5455
{ id: 'chain', label: 'Chain Operations', component: ChainComponent },
5556
{ id: 'wallet', label: 'Wallet Management', component: WalletComponent },
57+
{ id: 'keystore', label: 'KeyStore Management', component: KeyStoreComponent },
5658
{ id: 'contract', label: 'Contract Operations', component: Contract },
5759
{ id: 'transaction', label: 'Transaction Management', component: TransactionComponent },
5860
{ id: 'utils', label: 'Utils Operations', component: UtilsComponent }

0 commit comments

Comments
 (0)