You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The way eth-lightwallet seems to be working is by using ks.generateNewAddress(pwDerivedKey, 1); you'd get the next address but I couldn't find a way to get either the path for that address or input the custom path to generate the address in the path I want.
There's a way to iterate through the addresses which is a bit hacky, something like the following:
functiongenerateNewAddress(seed,password,HdPathString,newAddressIdentifier,done){// newAddressIdentifier is the incremental value for new address// the final path is basically HdPathString/newAddressIdentifierconstfinalHdPath=HdPathString+'/'+newAddressIdentifier.toString()+"'";console.log('finalHdPath',finalHdPath);lightwallet.keystore.deriveKeyFromPassword(password,function(err,pwDerivedKey){varks=newlightwallet.keystore(secretSeed,pwDerivedKey,finalHdPath);ks.generateNewAddress(pwDerivedKey,1);varaddr=ks.getAddresses()[0];console.log('addr',addr);varprivKey=ks.exportPrivateKey(addr,pwDerivedKey,finalHdPath);constretObj={address: addr,privateKey: privKey};done(null,retObj);});}
The ^ solution is using the deprecated function which will be removed on next updates.
However using the new method KeyStore.createVault() even this hack is not possible as it would throw exception.
this works fine when the finalHdPath is m/0'/0'/0'. but fails as soon as we try to run it using any other default path:
functiongenerateNewAddress(seed,password,HdPathString,newAddressIdentifier,done){// newAddressIdentifier is the incremental value for new address// the final path is basically HdPathString/newAddressIdentifierconstfinalHdPath=HdPathString+'/'+newAddressIdentifier.toString()+"'";console.log('finalHdPath',finalHdPath);lightwallet.keystore.createVault({password: password,seedPhrase: secretSeed,HdPathString: finalHdPath},function(err,ks){if(err)done(err);ks.keyFromPassword(password,function(err,pwDerivedKey){if(err)done(err);ks.generateNewAddress(pwDerivedKey,1,finalHdPath);// generateNewAddress(pwDerivedKey, [num,] [hdPathString])console.log(ks.getAddresses());varaddr=ks.getAddresses()[0];varprivKey=ks.exportPrivateKey(addr,pwDerivedKey,finalHdPath);console.log(ks.defaultHdPathString);console.log('addr',addr);constretObj={address: addr,privateKey: privKey};done(null,retObj);});});}
hdPathString m/0'/0'/1'
this.ksData[hdPathString] undefined
/token_eth_sweeper/testFlow.js:43
if (err) throw err;
^
TypeError: Cannot read property 'info' of undefined
at KeyStore.generateNewAddress (/token_eth_sweeper/node_modules/eth-lightwallet/lib/keystore.js:443:32)
at /token_eth_sweeper/testFlow.js:29:10
at cb (/token_eth_sweeper/node_modules/eth-lightwallet/lib/keystore.js:524:7)
at /token_eth_sweeper/node_modules/scrypt-async/scrypt-async.js:518:13
at Immediate._onImmediate (/token_eth_sweeper/node_modules/scrypt-async/scrypt-async.js:481:11)
at runCallback (timers.js:800:20)
at tryOnImmediate (timers.js:762:5)
at processImmediate [as _immediateCallback] (timers.js:733:5)
The text was updated successfully, but these errors were encountered:
@christianlundkvist Thanks, the way ks.generateNewAddress(pwDerivedKey, 4) works is that if you generate 4 for now and later on you want to continue on the path using another instance of the app, you have to generate let's say 10 and don't use the first 4 that you've already used. This solution would not be really scalable.
I made a pull request to add this feature so you can derive any path you need: #156
I'm trying to use eth-lightwallet to generate BIP32/44 style addresses using custom paths, let's say:
The way eth-lightwallet seems to be working is by using
ks.generateNewAddress(pwDerivedKey, 1);
you'd get the next address but I couldn't find a way to get either the path for that address or input the custom path to generate the address in the path I want.There's a way to iterate through the addresses which is a bit hacky, something like the following:
Here is the source code for such iteration:
The ^ solution is using the deprecated function which will be removed on next updates.
However using the new method
KeyStore.createVault()
even this hack is not possible as it would throw exception.this works fine when the finalHdPath is
m/0'/0'/0'
. but fails as soon as we try to run it using any other default path:for input
m/0'/0'/0'
:for input
m/0'/0'/1'
:The text was updated successfully, but these errors were encountered: