I'm currently using the Hedera JS SDK to generate a single ECDSA key-pair using a private key directly as an input, like so:
const privateKey = PrivateKey.fromStringECDSA(process.env.TARGET_HEX_PRIVATE_KEY);
Instead I would like to do something like this instead, where I am using a BIP-39 seed phrase and a derivation path as inputs:
const mnemonic = Mnemonic.fromString(process.env.TARGET_SEED_PHRASE);
const privateKey = await mnemonic.toEcdsaPrivateKey('', "m/44'/60'/0'/0/0");
However, Mnemonic
's toEcdsaPrivateKey
function seems to accept an array of numbers as the input for the derivation path, based on its JsDoc @param
comment, copied below:
/**
* Recover an ECDSA private key from this mnemonic phrase, with an
* optional passphrase.
*
* @param {string} [passphrase]
* @param {number[]} [path]
* @returns {Promise<PrivateKey>}
*/
async toEcdsaPrivateKey(passphrase = "", path) {
return CACHE.privateKeyConstructor(
await this._mnemonic.toEcdsaPrivateKey(passphrase, path)
);
}
In my use case, I would like to work with MetaMask, which unfortunately does not yet support custom derivation paths per network configuration, and hardcodes the Ethereum derivation path of m/44'/60'/0'/0/0
instead. Note that the first 3 segments are "hardened", while the remaining 2 are not.
How can I specify this derivation path?