/// <summary> /// Gets the reader. /// </summary> /// <returns>A ChannelDataReader with indices</returns> public ChannelDataReader GetReader() { var records = new List <List <List <object> > >(_records); return(new ChannelDataReader(records, Mnemonics.ToArray(), Units.ToArray(), DataTypes.ToArray(), NullValues.ToArray(), Uri) .WithIndices(Indices, true)); }
private static PrivateKeys GetPrivateKeysFromSeed() { while (true) { ConsoleMessage.Write(ConsoleColor.Yellow, "Mnemonic seed (25 words): "); string input = Console.ReadLine(); switch (Mnemonics.MnemonicToPrivateKey(input)) { case ILeft <Error> error: { ConsoleMessage.WriteLine(ConsoleColor.Red, error.Value.errorMessage); ConsoleMessage.WriteLine("Try again.\n"); continue; } case IRight <PrivateKey> key: { var privateSpendKey = key.Value; var privateViewKey = KeyOps.GenerateDeterministicKeys(privateSpendKey) .privateKey; return(new PrivateKeys(privateSpendKey, privateViewKey)); } } } }
public RecoverWalletViewModel( string walletName, Network network, WalletManager walletManager) { Suggestions = new Mnemonic(Wordlist.English, WordCount.Twelve).WordList.GetWords(); Mnemonics.ToObservableChangeSet().ToCollection() .Select(x => x.Count == 12 ? new Mnemonic(GetTagsAsConcatString()) : default)
public RecoverWalletViewModel( string walletName, WalletManagerViewModel walletManagerViewModel) { Suggestions = new Mnemonic(Wordlist.English, WordCount.Twelve).WordList.GetWords(); var walletManager = walletManagerViewModel.WalletManager; var network = walletManager.Network; Mnemonics.ToObservableChangeSet().ToCollection() .Select(x => x.Count is 12 or 15 or 18 or 21 or 24 ? new Mnemonic(GetTagsAsConcatString().ToLowerInvariant()) : default)
public VerifyRecoveryWordsViewModel(Wallet wallet) { _suggestions = new Mnemonic(Wordlist.English, WordCount.Twelve).WordList.GetWords(); _wallet = wallet; Mnemonics.ToObservableChangeSet().ToCollection() .Select(x => x.Count is 12 or 15 or 18 or 21 or 24 ? new Mnemonic(GetTagsAsConcatString().ToLowerInvariant()) : default)
public Instruction(Mnemonics Mnemonic, Registers?Register, byte?Value = null, bool Is64Bit = false) { this._mnemonic = Mnemonic; // If a register hasn't been supplied, this means it's a special instruction. this._register = Register; // If a value hasn't been supplied, this means it's a unary mnemonic. this._value = Value; this._is64Bit = Is64Bit; this.GenerateByteCode(); }
/// <summary> /// Adds the channel. /// </summary> /// <param name="channelId">The channel identifier.</param> /// <param name="mnemonic">The mnemonic.</param> /// <param name="unit">The unit.</param> /// <param name="dataType">The data type.</param> /// <param name="nullValue">The null value.</param> public void AddChannel(long channelId, string mnemonic, string unit, string dataType, string nullValue = null) { if (Mnemonics.Any(x => x.EqualsIgnoreCase(mnemonic))) { return; } ChannelIds.Add(channelId); Mnemonics.Add(mnemonic); Units.Add(unit); DataTypes.Add(dataType); NullValues.Add(nullValue); }
NewWallet(string filename, string password, string mnemonicSeed) { /* Derive the mnemonic into a private spend key if possible */ return(Mnemonics.MnemonicToPrivateKey(mnemonicSeed) .Fmap(privateSpendKey => { /* Derive the private view key from the private spend key */ var privateKeys = new PrivateKeys( privateSpendKey, KeyOps.GenerateDeterministicKeys(privateSpendKey).privateKey ); /* Try and create the new wallet from the private keys */ return NewWallet(filename, password, privateKeys); })); }
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 ShowNextInstruction() { var opcode = memoryController.GetPosition(PC); var instruction = Mnemonics.Mnemonic(opcode); var instructionText = instruction.Text; if (instruction.ExtraOpcodes == 1) { instructionText = instructionText.Replace("n", string.Format("0x{0:X2}", memoryController.GetPosition((ushort)(PC + 1)))); } else if (instruction.ExtraOpcodes == 2) { var first = memoryController.GetPosition((ushort)(PC + 1)); var second = memoryController.GetPosition((ushort)(PC + 2)); instructionText = instructionText.Replace("nn", string.Format("0x{0:X2}{1:X2}", second, first)); } Console.WriteLine("Next instruction: {0}", instructionText); }
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) ); } }
public void TestMnemonicToPrivateKey() { string m1 = "optical rumble bamboo worry auctions width essential request oxygen acoustic wounded gawk ginger ornament sixteen pawnshop pairing soapy rift alley enraged orbit axle binocular bamboo"; Mnemonics.MnemonicToPrivateKey(m1).Do( err => Assert.Fail($"Failed to parse mnemonic seed: {err}"), /* The corresponding private key to this mnemonic */ key => Assert.AreEqual <PrivateKey>(key, new PrivateKey("f41d515ac6e84de566f3a9eb559f3e58db6d8b28906857288f9f9f3809846006")) ); string m2 = "psychic frown wetsuit orders rover rays ruffled initiate adhesive acumen among lectures drunk itches tanks highway evolved amended asked thorn nanny juggled vaults velvet adhesive"; Mnemonics.MnemonicToPrivateKey(m2).Do( err => Assert.Fail($"Failed to parse mnemonic seed: {err}"), /* A completely unrelated private key */ key => Assert.AreNotEqual <PrivateKey>(key, new PrivateKey("17a27c50a43b99505d7934c1f05e748deee52bb813d7b1d0654ac980d1a93304")) ); /* Mnemonic with invalid checksum */ string m3 = "double hatchet solved bifocals dozen ulcers sickness sneeze unrest deftly molten oven deity spud upgrade shipped vogue razor gopher sailor drowning epoxy nephew oust spud"; Mnemonics.MnemonicToPrivateKey(m3).Do( err => { /* Expected */ }, key => Assert.Fail($"Mnemonic has invalid checksum but was still successfully parsed!") ); /* Not 25 words */ string m4 = "lol, i'm not valid"; Mnemonics.MnemonicToPrivateKey(m4).Do( err => { /* Expected */ }, key => Assert.Fail($"Mnemonic is invalid length but was still successfully parsed!") ); /* Final word is not in mnemonic dictionary */ string m5 = "daily utopia pistons null giddy pirate return espionage fossil rustled biweekly fictional sedan jubilee asked ugly mystery paper awning titans point luxury eccentric ecstatic word_not_in_dictionary"; Mnemonics.MnemonicToPrivateKey(m5).Do( err => { /* Expected */ }, key => Assert.Fail($"Mnemonic has invalid word but was still successfully parsed!") ); }
public static bool VerifyArgTypes(Mnemonics mnemonic, object[] args) { OpcodeDef?defRef = OpcodeTable[(uint)mnemonic]; if (defRef == null) { return(false); } OpcodeDef def = defRef.Value; if (def.Args == null) { return(args.Length == 0); } if (def.Args.Length != args.Length) { return(false); } for (int i = 0; i < args.Length; i++) { Type expected = Opcode.InternalTypes[(int)def.Args[i]]; Type passed = args[i].GetType(); if (expected != passed) { return(false); } if (def.Args[i] == ArgType.ByteS8) { if ((int)args[i] > 127 || (int)args[i] < -128) { return(false); } } } return(true); }
/// <summary> /// Gets the correct register opcode depending on the operation /// </summary> /// <param name="Mnemonic">The mnemonic of the operation</param> /// <returns>The correct register opcode for a mnemonic</returns> private byte GetRegisterOpcode(Mnemonics Mnemonic) { if (Mnemonic == Mnemonics.ADD) { return((byte)(0xc0 + (int)this._register)); } if (Mnemonic == Mnemonics.SUB) { return((byte)(0xe8 + (int)this._register)); } if (Mnemonic == Mnemonics.XOR) { return((byte)(0xf0 + (int)this._register)); } if (Mnemonic == Mnemonics.NOT) { return((byte)(0xd0 + (int)this._register)); } return(0); }
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); } }
public override string ToString() { return(string.Join("/", Mnemonics.Select(x => x.ToString().Replace('_', ' ').ToLowerInvariant()))); }
public Instruction(byte address, Mnemonics opcode, byte operand) { this.Address = address; this.OpCode = opcode; this.Operand = operand; }
public void Add(Mnemonic expression) { Mnemonics.Add(expression); }
public OpCodeInfo(int opcode, Mnemonics mnemonic, String name, int flags) { OpCode = opcode; Id = mnemonic; Name = name; Flags = flags; CEquivalent = null; }
public Instruction(Mnemonics mnemonic, Operand[] operands) { this.mnemonic = mnemonic; this.operands = operands; }
public OpCodeInfo(int opcode, Mnemonics mnemonic, String name, int flags, CTranslator translator) { OpCode = opcode; Id = mnemonic; Name = name; Flags = flags; CEquivalent = translator; }
public static bool VerifyArgTypes(Mnemonics mnemonic, object[] args) { OpcodeDef? defRef = OpcodeTable[(uint)mnemonic]; if (defRef == null) { return false; } OpcodeDef def = defRef.Value; if (def.Args == null) { return (args.Length == 0); } if (def.Args.Length != args.Length) { return false; } for (int i = 0; i < args.Length; i++) { Type expected = Opcode.InternalTypes[(int)def.Args[i]]; Type passed = args[i].GetType(); if (expected != passed) { return false; } if (def.Args[i] == ArgType.ByteS8) { if ((int)args[i] > 127 || (int)args[i] < -128) { return false; } } } return true; }
public RecoveryPageViewModel(IScreen screen) : base(screen) { Suggestions = new Mnemonic(Wordlist.English, WordCount.Twelve).WordList.GetWords(); _currentMnemonic = Mnemonics.ToObservableChangeSet().ToCollection() .Select(x => x.Count == 12 ? new Mnemonic(GetTagsAsConcatString()) : default)
private bool FirstPass(FileInfo source) { using (StreamReader sr = new StreamReader(source.FullName)) { int lineCounter = 0; // debug source file string line; string[] split; while (!sr.EndOfStream) { line = sr.ReadLine().ToUpper(); split = line.Split((char[])null, StringSplitOptions.RemoveEmptyEntries); // ignore whitespace // Instruction lines must begin with whitespace. if (!char.IsWhiteSpace(line[0])) { // Must be a symbol/label string newLabel = split[0]; if (PseudoInstructions.ContainsKey(newLabel) || Mnemonics.ContainsKey(newLabel)) { Console.WriteLine($"Line #{lineCounter}: {line} is not valid!\nCannot declare a symbol with the same name as an instruction or pseudo-instruction."); return(false); } if (split.Length > 1) { // Declaring a new symbol. if (split[1] == PseudoInstruction.Constant.Mnemonic) { Labels.Add(newLabel, InstructionCounter); InstructionCounter += 1; ByteCounter += 1; } else { Console.WriteLine($"Line #{lineCounter}: {line} is not valid!\nInvalid pseudo-intruction."); return(false); } } else { // Declaring a new label. Labels.Add(newLabel, InstructionCounter); } } else { string instruction = split[0]; string operand = split[1]; if (instruction == PseudoInstruction.Origin.Mnemonic) { InstructionCounter = Utilities.StringToAddress(operand); } else if (instruction == PseudoInstruction.End.Mnemonic) { // should be eof } else if (Mnemonics.ContainsKey(instruction)) { InstructionCounter += Mnemonics[instruction].Size; ByteCounter += Mnemonics[instruction].Size; } else { Console.WriteLine($"Line #{lineCounter}: {line} is not valid!\nInvalid instruction."); return(false); } } lineCounter++; } } return(true); }