/// <summary> /// Decodes user input as either the hexadecimal or PGP word list encoding /// of a seed and validates the seed length. /// </summary> public static byte[] DecodeAndValidateUserInput(string userInput, PgpWordList pgpWordList) { if (userInput == null) throw new ArgumentNullException(nameof(userInput)); if (pgpWordList == null) throw new ArgumentNullException(nameof(pgpWordList)); var decodedInput = DecodeUserInput(userInput, pgpWordList); if (decodedInput.Length != SeedLength) { throw new Exception($"Decoded seed must have byte length {SeedLength}"); } return decodedInput; }
private static byte[] DecodeUserInput(string userInput, PgpWordList pgpWordList) { byte[] seed; if (Hexadecimal.TryDecode(userInput, out seed)) return seed; var splitInput = userInput.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); if (splitInput.Length == 1) { // Hex decoding failed, but it's not a multi-word mneumonic either. // Assume the user intended hex. throw new HexadecimalEncodingException(); } return pgpWordList.Decode(splitInput); }
private static byte[] DecodeUserInput(string userInput, PgpWordList pgpWordList) { byte[] seed; if (Hexadecimal.TryDecode(userInput, out seed)) { return(seed); } var splitInput = userInput.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); if (splitInput.Length == 1) { // Hex decoding failed, but it's not a multi-word mneumonic either. // Assume the user intended hex. throw new HexadecimalEncodingException(); } return(pgpWordList.Decode(splitInput)); }
/// <summary> /// Decodes user input as either the hexadecimal or PGP word list encoding /// of a seed and validates the seed length. /// </summary> public static byte[] DecodeAndValidateUserInput(string userInput, PgpWordList pgpWordList) { if (userInput == null) { throw new ArgumentNullException(nameof(userInput)); } if (pgpWordList == null) { throw new ArgumentNullException(nameof(pgpWordList)); } var decodedInput = DecodeUserInput(userInput, pgpWordList); if (decodedInput.Length != SeedLength) { throw new Exception($"Decoded seed must have byte length {SeedLength}"); } return(decodedInput); }
public static string[] EncodeWordList(PgpWordList pgpWordList, byte[] seed) => pgpWordList.Encode(seed);
public ConfirmSeedBackupDialog(StartupWizard wizard, CreateOrImportSeedDialog previousDialog, byte[] seed, PgpWordList pgpWordlist) : base(wizard) { _previousDialog = previousDialog; _seed = seed; _pgpWordList = pgpWordlist; ConfirmSeedCommand = new DelegateCommand(ConfirmSeed); BackCommand = new DelegateCommand(Back); }