getPrivateKeyFromMnemonic static method

String getPrivateKeyFromMnemonic(
  1. String mnemonic
)

Derives a private key from a mnemonic directly, use this if you want a quick way to get a private key from a mnemonic.

final privateKey = Nostr.instance.keysService.getPrivateKeyFromMnemonic('your mnemonic');
print(privateKey); // ...

Implementation

static String getPrivateKeyFromMnemonic(String mnemonic) {
  final seed = bip39.mnemonicToSeedHex(mnemonic);
  final chain = bip32_bip44.Chain.seed(seed);

  final key =
      chain.forPath("m/44'/1237'/0'/0") as bip32_bip44.ExtendedPrivateKey;

  final childKey = bip32_bip44.deriveExtendedPrivateChildKey(key, 0);

  var hexChildKey = '';

  if (childKey.key != null) {
    hexChildKey = childKey.key!.toRadixString(16);
  }

  return hexChildKey;
}