public void TestPrivateKeyToMnemonic() { PrivateKey p1 = new PrivateKey("4318e9ea979c6a478b224b233fa1c19fe19508a93caf95899ba90c1e32db1e02"); string m1 = Mnemonics.PrivateKeyToMnemonic(p1); /* The corresponding mnemonic to this private key */ Assert.AreEqual <string>(m1, "dexterity tolerant sixteen jubilee pamphlet useful looking king odometer rounded listen border inundate aphid reruns lumber noodles bogeys bawled situated union tequila flippant foxes border"); PrivateKey p2 = new PrivateKey("7abd03833990b87b7787ee1eac16b6b1823cc85690ae686d5a794b2171107e05"); string m2 = Mnemonics.PrivateKeyToMnemonic(p2); /* A completely unrelated mnemonic */ Assert.AreNotEqual <string>(m2, "point wolf alchemy laboratory duplex tsunami rarest lids rugged factual pepper stunning folding fibula daily textbook timber jailed intended five etched reinvest aloof beer duplex"); }
public void TestMnemonicBothWays() { for (int i = 0; i < 1000; i++) { /* Generate a random private key */ PrivateKey p = KeyOps.GenerateKeys().privateKey; /* Convert to mnemonic */ string m = Mnemonics.PrivateKeyToMnemonic(p); /* Convert back to a private key */ Mnemonics.MnemonicToPrivateKey(m).Do( err => Assert.Fail($"Failed to parse mnemonic seed: {err}"), /* Should be the same as the original private key */ key => Assert.AreEqual <PrivateKey>(p, key) ); } }
private static void ExportKeys(WalletBackend wallet) { Utilities.ConfirmPassword(wallet); RedMsg.WriteLine("The below data is PRIVATE and should not be " + "given to anyone!"); RedMsg.WriteLine("If someone else gains access to these, they " + "can steal all your funds!"); Console.WriteLine(); if (wallet.isViewWallet) { GreenMsg.WriteLine("Private view key:"); GreenMsg.WriteLine(wallet.keys.privateViewKey.ToString()); return; } GreenMsg.WriteLine("Private spend key:"); GreenMsg.WriteLine(wallet.keys.privateSpendKey.ToString()); Console.WriteLine(); GreenMsg.WriteLine("Private view key:"); GreenMsg.WriteLine(wallet.keys.privateViewKey.ToString()); if (KeyOps.AreKeysDeterministic(wallet.keys.privateSpendKey, wallet.keys.privateViewKey)) { string mnemonic = Mnemonics.PrivateKeyToMnemonic( wallet.keys.privateSpendKey ); GreenMsg.WriteLine("\nMnemonic seed:"); GreenMsg.WriteLine(mnemonic); } }