Added convenience method for HD path derivation.

This commit is contained in:
Richard Moore 2021-05-13 23:02:00 -04:00
parent 6e088099ad
commit aadc5cd3d6
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
2 changed files with 9 additions and 1 deletions

@ -6,7 +6,7 @@ import * as base64 from "@ethersproject/base64";
import { Base58 as base58 } from "@ethersproject/basex";
import { arrayify, concat, hexConcat, hexDataSlice, hexDataLength, hexlify, hexStripZeros, hexValue, hexZeroPad, isBytes, isBytesLike, isHexString, joinSignature, zeroPad, splitSignature, stripZeros } from "@ethersproject/bytes";
import { _TypedDataEncoder, hashMessage, id, isValidName, namehash } from "@ethersproject/hash";
import { defaultPath, entropyToMnemonic, HDNode, isValidMnemonic, mnemonicToEntropy, mnemonicToSeed } from "@ethersproject/hdnode";
import { defaultPath, entropyToMnemonic, getAccountPath, HDNode, isValidMnemonic, mnemonicToEntropy, mnemonicToSeed } from "@ethersproject/hdnode";
import { getJsonWalletAddress } from "@ethersproject/json-wallets";
import { keccak256 } from "@ethersproject/keccak256";
import { Logger } from "@ethersproject/logger";
@ -165,6 +165,7 @@ export {
verifyMessage,
verifyTypedData,
getAccountPath,
mnemonicToEntropy,
entropyToMnemonic,
isValidMnemonic,

@ -403,3 +403,10 @@ export function isValidMnemonic(mnemonic: string, wordlist?: Wordlist): boolean
} catch (error) { }
return false;
}
export function getAccountPath(index: number): string {
if (typeof(index) !== "number" || index < 0 || index >= HardenedBit || index % 1) {
logger.throwArgumentError("invalid account index", "index", index);
}
return `m/44'/60'/${ index }'/0/0`;
}