src/components/entry/CreateWallet.js
//here we create the wallet file in the default location after prompting for a password and creating the encrypted file.
here we create the wallet file in the default location after prompting for a password and creating the encrypted file.
here we create the wallet file in the default location after prompting for a password and creating the encrypted file .
handleSubmit(e) {
        e.preventDefault();
        if (e.target.create_password.value.length > 0 && e.target.create_password.value === e.target.repeat_password.value) {
            const key_pair = genkey();
            const { address } = bitcoin.payments.p2pkh({ pubkey: key_pair.publicKey });
            const key_json = {};
            key_json['public_key'] = address;
            key_json['private_key'] = key_pair.toWIF();
            key_json['safex_bal'] = 0;
            key_json['btc_bal'] = 0;
            key_json['pending_safex_bal'] = 0;
            key_json['pending_btc_bal'] = 0;
            key_json['label'] = 'Enter your label here';
            const key_array = [];
            key_array.push(key_json);
            const json = {};
            json['version'] = '1';
            json['keys'] = key_array;
            console.log(json);
            const algorithm = 'aes-256-ctr';
            const password = e.target.create_password.value;
            const cipher_text = encrypt(JSON.stringify(json), algorithm, password);
            const walletPath = DEFAULT_WALLET_PATH;
            fs.writeFile(walletPath, cipher_text, (err) => {
                if (err) {
                    console.error(err);
                    this.openWalletImportAlert(`Failed to write wallet to ${walletPath}: ${err.message}`, 5000);
                } else {
                    localStorage.setItem('password', password);
                    localStorage.setItem('wallet', JSON.stringify(json));
                    localStorage.setItem('wallet_path', walletPath);
                    this.context.router.push('/wallet');
                }
            });
        } else if (e.target.create_password.value.length === 0) {
            this.wrongPassword();
            this.openWalletImportAlert(`Wrong password`, 5000);
        }
        if ((e.target.create_password.value.length > 0 && e.target.repeat_password.value.length === 0) || (e.target.repeat_password.value.length > 0 && e.target.repeat_password.value !== e.target.create_password.value)) {
            this.wrongRepeatPassword();
            this.openWalletImportAlert(`Wrong repeated password`, 5000);
        }
    }
handleSubmit ( e ) { e . preventDefault ( ) ; if ( e . target . create_password . value . length > 0 && e . target . create_password . value === e . target . repeat_password . value ) { const key_pair = genkey ( ) ; const { address } = bitcoin . payments . p2pkh ( { pubkey : key_pair . publicKey } ) ; const key_json = { } ; key_json [ 'public_key' ] = address ; key_json [ 'private_key' ] = key_pair . toWIF ( ) ; key_json [ 'safex_bal' ] = 0 ; key_json [ 'btc_bal' ] = 0 ; key_json [ 'pending_safex_bal' ] = 0 ; key_json [ 'pending_btc_bal' ] = 0 ; key_json [ 'label' ] = 'Enter your label here' ; const key_array = [ ] ; key_array . push ( key_json ) ; const json = { } ; json [ 'version' ] = '1' ; json [ 'keys' ] = key_array ; console . log ( json ) ; const algorithm = 'aes-256-ctr' ; const password = e . target . create_password . value ; const cipher_text = encrypt ( JSON . stringify ( json ) , algorithm , password ) ; const walletPath = DEFAULT_WALLET_PATH ; fs . writeFile ( walletPath , cipher_text , ( err ) => { if ( err ) { console . error ( err ) ; this . openWalletImportAlert ( ` ${ walletPath } ${ err . message } ` , 5000 ) ; } else { localStorage . setItem ( 'password' , password ) ; localStorage . setItem ( 'wallet' , JSON . stringify ( json ) ) ; localStorage . setItem ( 'wallet_path' , walletPath ) ; this . context . router . push ( '/wallet' ) ; } } ) ; } else if ( e . target . create_password . value . length === 0 ) { this . wrongPassword ( ) ; this . openWalletImportAlert ( ` ` , 5000 ) ; } if ( ( e . target . create_password . value . length > 0 && e . target . repeat_password . value . length === 0 ) || ( e . target . repeat_password . value . length > 0 && e . target . repeat_password . value !== e . target . create_password . value ) ) { this . wrongRepeatPassword ( ) ; this . openWalletImportAlert ( ` ` , 5000 ) ; } }
here we create the wallet file in the default location after prompting for a password and creating the encrypted file.
here we create the wallet file in the default location after prompting for a password and creating the encrypted file .