1
              <html>

                <body>
                    <script src="./lightwallet.min.js"></script>
                    <script type="text/javascript" src="web3.js"></script>

                <form id="signup" method="POST" action="upload.html" enctype="multipart/form-data">
                  <input type="file" id="myfile" name="myfile"  accept=".json" >
              </form>



          <h1>LightWallet</h1>
                        <h2>New Wallet</h2>
                        <div>
   <input type="text" id="userEntropy" placeholder="Type random text to generate entropy" size="80"></input>
                        <button onClick="newWallet()">Create New Wallet</button>
                    </div>
                    <h2>Restore Wallet</h2>
                    <div>
                        <input type="text" id="seed" value="" size="80"></input>
                        <button onClick="setSeed()">Restore wallet from Seed</button>
                    </div>
                    <div id="addr"></div>
                    <div>
                        <button onClick='getBalances()'>Refresh</button>
                    </div>


                     <script>
                    var web3 = new Web3();
                    var global_keystore;
                    if (!web3.currentProvider)
                        web3.setProvider(new web3.providers.HttpProvider('http://XXXXXXXX'));

                    function newAddresses(password) {
                        if (password == '') {
                            password = prompt('Enter password to retrieve addresses', 'Password');
                        }
                        global_keystore.keyFromPassword(password, function(err, pwDerivedKey){
                            if(err) throw err;
                            global_keystore.generateNewAddress(pwDerivedKey, 1);
                            var address = global_keystore.getAddresses()[0];
                            document.getElementById('functionCaller').innerHTML = ''
                            document.getElementById('functionCaller').innerHTML += '0x' + address 
                            getBalances();
                        });
                    }

                    function getBalances() {
                        var address = global_keystore.getAddresses()[0];
                        document.getElementById('addr').innerHTML = ''
                        web3.eth.getBalance(address, function(err, balance) {
                            web3.eth.getTransactionCount('0x' + address, function(err, nonce) {
                                document.getElementById('addr').innerHTML += '<div>0x' + address + ' (Bal: ' + (balance / 1.0e18) + ' ETH, Nonce: ' + nonce + ')' + '</div>'
                            });
                        });      
                    }

                    function setSeed() {
                        var password = prompt('Enter Password to encrypt your seed', 'Password');
                        lightwallet.keystore.createVault({ password: password , seedPhrase: document.getElementById('seed').value, hdPathString: "m/44'/60'/0'/0"} , function(err, keystore){

                            global_keystore = keystore;
                            document.getElementById('seed').value = ''
                            newAddresses(password);
                        });
                    }

                    function newWallet() {
                        var extraEntropy = document.getElementById('userEntropy').value;
                        document.getElementById('userEntropy').value = '';
                        var randomSeed = lightwallet.keystore.generateRandomSeed(extraEntropy);
                        console.log('GGGG: ', randomSeed);
                        var infoString = 'Your new wallet seed is: "' + randomSeed +
                            '". Please write it down on paper or in a password manager, you will need it to access your wallet. Do not let anyone see this seed or they can take your Ether. ' +
                            'Please enter a password to encrypt your seed while in the browser.'
                        var password = prompt(infoString, 'Password');
                        lightwallet.keystore.createVault({ password: password, seedPhrase: randomSeed , hdPathString: "m/44'/60'/0'/0"} , function(err, keystore){
                            global_keystore = keystore;
                            newAddresses(password);
                        });
                    }

                    function functionCall() {
                        var fromAddr = document.getElementById('functionCaller').innerHTML
                        var contractAddr = document.getElementById('contractAddr').value
                        var abi = JSON.parse(document.getElementById('contractAbi').value)
                        var contract = web3.eth.contract(abi).at(contractAddr)
                        var functionName = document.getElementById('functionName').value
                        var args = JSON.parse('[' + document.getElementById('functionArgs').value + ']')
                        var valueEth = document.getElementById('sendValueAmount').value
                        var value = parseFloat(valueEth) * 1.0e18
                        var gasPrice = 50000000000
                        var gas = 3141592

                        web3.eth.getTransactionCount(fromAddr, function(err, nonce){
                            var funcTx = lightwallet.txutils.functionTx(abi, functionName, [], {to: contractAddr, gasLimit: 300000, gasPrice: gasPrice , nonce: nonce, value: value });
                            var password = prompt('Enter Password to sign Transaction', 'Password');
                            global_keystore.keyFromPassword(password, function(err, pwDerivedKey){
                                //sign tx NIC LIN
                                var signedTx = lightwallet.signing.signTx(global_keystore, pwDerivedKey, funcTx, global_keystore.getAddresses()[0]);
                                console.log("signedTx: " + signedTx.toString('hex'));

                                //send tx NIC LIN
                                web3.eth.sendRawTransaction(signedTx.toString('hex'), function(err, tx_id){
                                    console.log(tx_id);
                                });
                            });

                        });
                    }
                    </script>

                </body>

                </html>

Thanks for helping me.

1

On their github repo it says you get the pwDerivedKey from password like this:

const pwDerivedKey = keystore.keyFromPassword(password, callback)

Using that you can get the seed:

const seed = keystore.getSeed(pwDerivedKey)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.