File tree 1 file changed +36
-1
lines changed 1 file changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -5,13 +5,48 @@ const fs = require('fs');
5
5
6
6
// TODO : lightwallet 모듈을 사용하여 랜덤한 니모닉 코드를 얻습니다.
7
7
router . post ( '/newMnemonic' , async ( req , res ) => {
8
-
8
+ let mnemonic ;
9
+ try {
10
+ mnemonic = lightwallet . keystore . generateRandomSeed ( ) ;
11
+ res . json ( { mnemonic} ) ;
12
+ } catch ( err ) {
13
+ console . log ( err ) ;
14
+ }
9
15
} ) ;
10
16
11
17
12
18
// TODO : 니모닉 코드와 패스워드를 이용해 keystore와 address를 생성합니다.
13
19
router . post ( '/newWallet' , async ( req , res ) => {
20
+ let password = req . body . password
21
+ let mnemonic = req . body . mnemonic ;
22
+
23
+ try {
24
+ lightwallet . keystore . createVault (
25
+ {
26
+ password : password ,
27
+ seedPhrase : mnemonic ,
28
+ hdPathString : "m/0'/0'/0'"
29
+ } ,
30
+ function ( err , ks ) {
31
+ ks . keyFromPassword ( password , function ( err , pwDerivedKey ) {
32
+ ks . generateNewAddress ( pwDerivedKey , 1 ) ;
33
+
34
+ let address = ( ks . getAddresses ( ) ) . toString ( ) ;
35
+ let keystore = ks . serialize ( ) ;
14
36
37
+ fs . writeFile ( 'wallet.json' , keystore , function ( err , data ) {
38
+ if ( err ) {
39
+ res . json ( { code :999 , message :"실패" } ) ;
40
+ } else {
41
+ res . json ( { code :1 , message :"성공" } ) ;
42
+ }
43
+ } ) ;
44
+ } ) ;
45
+ }
46
+ ) ;
47
+ } catch ( exception ) {
48
+ console . log ( "NewWallet ==>>>> " + exception ) ;
49
+ }
15
50
} ) ;
16
51
17
52
module . exports = router ;
You can’t perform that action at this time.
0 commit comments