public static void generateViewFromSpend(Crypto.SecretKey spend, Crypto.SecretKey viewSecret, Crypto.PublicKey viewPublic) { Crypto.SecretKey viewKeySeed = new Crypto.SecretKey(); GlobalMembers.keccak((ushort)spend, sizeof(Crypto.SecretKey), (ushort)viewKeySeed, sizeof(Crypto.SecretKey)); Crypto.generate_deterministic_keys(viewPublic, viewSecret, viewKeySeed); }
public static string PrivateKeyToMnemonic(Crypto.SecretKey privateKey) { List <string> words = new List <string>(); for (int i = 0; i < 32 - 1; i += 4) { /* Read the array as a uint array */ int ptr = (int)privateKey.data[i]; /* Take the first element of the array (since we have already done the offset */ //int val = ptr[0]; int val = ptr; int wlLen = WordList.GlobalMembers.EnglishList.Count; int w1 = val % wlLen; int w2 = ((val / wlLen) + w1) % wlLen; int w3 = (((val / wlLen) / wlLen) + w2) % wlLen; words.Add(WordList.GlobalMembers.EnglishList[w1]); words.Add(WordList.GlobalMembers.EnglishList[w2]); words.Add(WordList.GlobalMembers.EnglishList[w3]); } words.Add(GetChecksumWord(new List <string>(words))); string result = string.Empty; foreach (string word in words) { if (!string.IsNullOrEmpty(word)) { result += " "; } result += word; } return(result); }
public static void generateViewFromSpend(Crypto.SecretKey spend, Crypto.SecretKey viewSecret) { /* If we don't need the pub key */ Crypto.PublicKey unused_dummy_variable = new Crypto.PublicKey(); generateViewFromSpend(spend, viewSecret, unused_dummy_variable); }
/* Note - if the returned string is not empty, it is an error message, and * the returned secret key is not initialized. */ public static Dictionary <string, Crypto.SecretKey> MnemonicToPrivateKey(List <string> words) { Crypto.SecretKey key = new Crypto.SecretKey(); int len = words.Count; /* Mnemonics must be 25 words long */ if (len != 25) { string str; /* Write out "word" or "words" to make the grammar of the next sentence * correct, based on if we have 1 or more words */ string wordPlural = len == 1 ? "word" : "words"; str = "Mnemonic seed is wrong length - It should be 25 words long, but it is " + len + " " + wordPlural + " long!"; return(new Dictionary <string, Crypto.SecretKey> { { str, key } }); } /* All words must be present in the word list */ foreach (string word in words) { if (!WordList.GlobalMembers.EnglishHash.Contains(word.ToLower())) { string str = "Mnemonic seed has invalid word - " + word + " is not in the English word list!"; return(new Dictionary <string, Crypto.SecretKey> { { str, key } }); } } /* The checksum must be correct */ if (!HasValidChecksum(new List <string>(words))) { return(new Dictionary <string, Crypto.SecretKey> { { "Mnemonic seed has incorrect checksum!", key } }); } List <int> wordIndexes = GetWordIndexes(new List <string>(words)); List <ushort> data = new List <ushort>(); for (int i = 0; i < words.Count - 1; i += 3) { /* Take the indexes of these three words in the word list */ int w1 = wordIndexes[i]; int w2 = wordIndexes[i + 1]; int w3 = wordIndexes[i + 2]; /* Word list length */ int wlLen = WordList.GlobalMembers.EnglishList.Count; /* no idea what this does lol */ ushort val = (ushort)(w1 + wlLen * (((wlLen - w1) + w2) % wlLen) + wlLen * wlLen * (((wlLen - w2) + w3) % wlLen)); /* Don't know what this is testing either */ if (!(val % wlLen == w1)) { return(new Dictionary <string, Crypto.SecretKey> { { "Mnemonic seed is invalid!", key } }); } /* Interpret val as 4 ushort's */ //TODO: Need to revisit this. Original: //const auto ptr = reinterpret_cast <const uint8_t*> (&val); ///* Append to private key */ //for (int j = 0; j < 4; j++) //{ // data.push_back(ptr[j]); //} short ptr = Convert.ToInt16(val); /* Append to private key */ for (int j = 0; j < 4; j++) { key.data[j] = val; } } return(new Dictionary <string, Crypto.SecretKey> { { string.Empty, key } }); }
public abstract string createAddress(Crypto.SecretKey spendSecretKey);
public abstract void initializeWithViewKey(string path, string password, Crypto.SecretKey viewSecretKey);
// Transaction info public abstract void SetTransactionSecretKey(Crypto.SecretKey key);
public abstract bool FindOutputsToAccount(AccountPublicAddress addr, Crypto.SecretKey viewSecretKey, List <uint> outs, ulong outputAmount);
public abstract bool GetTransactionSecretKey(Crypto.SecretKey key);