3

I am using eth-lightwallet on a NodeJS server. I am getting a stack trace when I try and get the private key from the keystore. It is flagging this line "keystore.generateNewAddress(pwDerivedKey);" I cannot see how it is related. When I comment out the line "account.prv_key = keystore.exportPrivateKey(sendingAddr, pwDerivedKey);" it appears to work flawlessly. Am I doing something wrong? The error is throwing "No seed set" however when I look in debug mode the seed is most certainly set. I am new to Node and suspect it has something to do with the asynchronous nature of Node. I have included the code and the stacktrace below. Thank you.

lightwallet.keystore.deriveKeyFromPassword('mypassword',
    function (err, pwDerivedKey) {
      var seed = lightwallet.keystore.generateRandomSeed();
      var keystore = new lightwallet.keystore(seed, pwDerivedKey);

      keystore.generateNewAddress(pwDerivedKey);
      account.address = keystore.getAddresses()[0];
      account.prv_key = keystore.exportPrivateKey(sendingAddr, pwDerivedKey);
    })



/Users/username/WebstormProjects/eth-project/nodejs-server/node_modules/eth-lightwallet/lib/keystore.js:389
    throw new Error('KeyStore.generateNewAddress: No seed set');
    ^

Error: KeyStore.generateNewAddress: No seed set
    at KeyStore.generateNewAddress (/Users/username/WebstormProjects/eth-project/nodejs-server/node_modules/eth-lightwallet/lib/keystore.js:389:11)
    at /Users/username/WebstormProjects/eth-project/nodejs-server/controllers/ActorService.js:39:20
    at cb (/Users/username/WebstormProjects/eth-project/nodejs-server/node_modules/eth-lightwallet/lib/keystore.js:459:7)
    at /Users/username/WebstormProjects/eth-project/nodejs-server/node_modules/eth-lightwallet/node_modules/scrypt-async/scrypt-async.js:474:9
    at Immediate._onImmediate (/Users/username/WebstormProjects/eth-project/nodejs-server/node_modules/eth-lightwallet/node_modules/scrypt-async/scrypt-async.js:433:11)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

1 Answer 1

7

Your handler function may have some error preventing the handler to execute correctly. You can check if "err" got set in your handler and print it to see exactly what error it is. For me if I run your exact code, I had to remove the reference to "account" and change "sendingAddr" to the first address of the keystore before the code runs. Make sure these 2 variables are defined in your code context. This is the code that works for me:

lightwallet.keystore.deriveKeyFromPassword('mypassword',
function (err, pwDerivedKey) {
  var seed = lightwallet.keystore.generateRandomSeed();
  var keystore = new lightwallet.keystore(seed, pwDerivedKey);

  keystore.generateNewAddress(pwDerivedKey);
  var address = keystore.getAddresses()[0];
  var prv_key = keystore.exportPrivateKey(address, pwDerivedKey);
  console.log('address and key: ', address, prv_key);
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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