I am using
ethereumjs-wallet npm package to generate a unique wallet address for each user. However instead of using the mnemonic/seed, a public extended key
xpub will be used instead to keep the private keys secure.
However the following code which I used is throwing the error
AssertionError [ERR_ASSERTION]: Could not derive hardened child key
The code works fine if we were to replace
const hdWallet = hdkey.fromExtendedKey("xpub...")
const hdWallet = hdkey.fromSeed("seed or mnemonic ...")
It appears to be a problem with the
hdPath, but which exactly is the problem? And how can we solve it?
var hdkey = require('ethereumjs-wallet/hdkey') const hdWallet = hdkey.fromExtendedKey("xpub...") const hdPath = "m/44'/60'/0'/1/0" const node = hdWallet.derivePath(hdPath) const nodeWallet = node.getWallet() const address = nodeWallet.getAddressString() return address