HdWallet.fromMnemonic constructor

HdWallet.fromMnemonic(
  1. String mnemonic, {
  2. String passphrase = "",
  3. String key = bitcoinKey,
})

Implementation

factory HdWallet.fromMnemonic(String mnemonic,
    {String passphrase = "", String key = bitcoinKey}) {
  final seed = BIP39.toSeed(mnemonic, passphrase: passphrase);
  if (seed.length < 16) {
    throw ArgumentError("Seed should be at least 128 bits");
  }
  if (seed.length > 64) {
    throw ArgumentError("Seed should be at most 512 bits");
  }

  final hash = hmacSHA512(utf8.encode(key) as Uint8List, seed);
  final private = hash.sublist(0, 32);
  final chainCode = hash.sublist(32);
  final compressedPub = ec.pointFromScalar(private, true);
  final wallet = HdWallet._base(private, compressedPub!, chainCode);
  return wallet;
}