privateKeyFromMnemonic static method

String privateKeyFromMnemonic(
  1. String mnemonic, {
  2. String derivationPath = "m/44'/60'/0'/0/",
  3. int childIndex = 0,
  4. String passphrase = "",
})

Derives a private key from a BIP-39 mnemonic using a given derivation path and passphrase.

mnemonic - The BIP-39 mnemonic to derive the private key from. derivationPath - The derivation path to use (default "m/44'/60'/0'/0/"). childIndex - The index of the child key to derive (default 0). passphrase - The optional passphrase to use when deriving the key (default "").

Returns a string representing the derived private key.

Implementation

static String privateKeyFromMnemonic(
  String mnemonic, {
  String derivationPath = "m/44'/60'/0'/0/",
  int childIndex = 0,
  String passphrase = "",
}) {
  final String seed = bip39.mnemonicToSeedHex(
    mnemonic,
    passphrase: passphrase,
  );
  final bip32.BIP32 rootNode = bip32.BIP32.fromSeed(
    HEX.decode(seed) as Uint8List,
  );
  final bip32.BIP32 childNode = rootNode.derivePath(
    "$derivationPath$childIndex",
  );
  final String privateKey = HEX.encode(childNode.privateKey!);
  return privateKey;
}