Seed Phrases (Bip39)

Note that in the following example we derive our “master private key” from a Seed Phrase. This derivation is “deterministic”, therefore we do not need to backup or store actual private key, only the Seed Phrase is needed for future recovery of the key hierarchy.

class description
Mnemonic The Mnemonic class is used to generate and validate seed values and lists of words as per the BIP39 specification

Generate a random seed phrase

New seedphrases can be generated quite easily. Default entropy for seed generation is 128 bits.

String seedPhrase = await Mnemonic().generateMnemonic();

Derive a private key from seed phrase

var MNEMONIC = 'edge eagle blue panda zone tiger emerge trial limit royal average basket';

var hdMaster = HDPrivateKey.fromSeed(MNEMONIC, NetworkType.TEST);

//derive a new hardened keypair from our Master Key
HDPrivateKey xprivateKey = HDPrivateKey.fromXpriv(hdMaster.xprivkey).deriveChildKey("m/44'/1'/1'/0'");
xprivateKey.networkType = NetworkType.TEST;
HDPublicKey xpublicKey = xprivateKey.hdPublicKey;