/// <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 + 1)) { // deal with "checksum" byte[] d = new byte[SeedLength]; Array.Copy(decodedInput, 0, d, 0, SeedLength); var digest = DoubleSha256(d); if (decodedInput[SeedLength] != digest[0]) { throw new ChecksumException("Invalid checksum"); } } else if (decodedInput.Length != SeedLength) { throw new Exception($"Decoded seed must have byte length {SeedLength}"); } return(decodedInput); }
/// <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); switch (decodedInput.Length) { // No checksum case SeedLength: return decodedInput; // Extra byte of checksum appended to end case SeedLength + 1: var seed = new byte[SeedLength]; Array.Copy(decodedInput, seed, SeedLength); var digest = DoubleSha256(seed); if (decodedInput[SeedLength] != digest[0]) { throw new ChecksumException("Invalid checksum"); } return seed; // Wrong size or seed is using a newer format not understood yet default: throw new Exception($"Decoded seed must have byte length {SeedLength}"); } }
/// <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); switch (decodedInput.Length) { // No checksum case SeedLength: return(decodedInput); // Extra byte of checksum appended to end case SeedLength + 1: var seed = new byte[SeedLength]; Array.Copy(decodedInput, seed, SeedLength); var digest = DoubleSha256(seed); if (decodedInput[SeedLength] != digest[0]) { throw new ChecksumException("Invalid checksum"); } return(seed); // Wrong size or seed is using a newer format not understood yet default: throw new Exception($"Decoded seed must have byte length {SeedLength}"); } }
/// <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 + 1)) { // deal with "checksum" byte[] d = new byte[SeedLength]; Array.Copy(decodedInput, 0, d, 0, SeedLength); var digest = DoubleSha256(d); if (decodedInput[SeedLength] != digest[0]) { throw new ChecksumException("Invalid checksum"); } } else if (decodedInput.Length != SeedLength) { throw new Exception($"Decoded seed must have byte length {SeedLength}"); } return decodedInput; }
public static string[] EncodeWordList(PgpWordList pgpWordList, byte[] seed) { var seedHash = DoubleSha256(seed); var seedWithChecksum = new byte[seed.Length + 1]; Array.Copy(seed, seedWithChecksum, seed.Length); seedWithChecksum[seedWithChecksum.Length - 1] = seedHash[0]; return pgpWordList.Encode(seedWithChecksum); }
public static string[] EncodeWordList(PgpWordList pgpWordList, byte[] seed) { var seedHash = DoubleSha256(seed); var seedWithChecksum = new byte[seed.Length + 1]; Array.Copy(seed, seedWithChecksum, seed.Length); seedWithChecksum[seedWithChecksum.Length - 1] = seedHash[0]; return(pgpWordList.Encode(seedWithChecksum)); }
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, CreateSeedDialog previousDialog, byte[] seed, PgpWordList pgpWordlist) : base(wizard) { _previousDialog = previousDialog; _seed = seed; _pgpWordList = pgpWordlist; ConfirmSeedCommand = new DelegateCommand(ConfirmSeed); BackCommand = new DelegateCommand(Back); }
public CreateSeedDialog(StartupWizard wizard, PgpWordList pgpWordlist, ConnectionWizardDialog previousDialog) : base(wizard) { _previousDialog = previousDialog; _pgpWordList = pgpWordlist; BackCommand = new DelegateCommand(Back); ContinueCommand = new DelegateCommand(Continue); // false below and remove raise to require a selection. ContinueCommand.Executable = true; }
public ImportSeedDialog(StartupWizard wizard, PgpWordList pgpWordlist, ConnectionWizardDialog previousDialog) : base(wizard) { _previousDialog = previousDialog; _pgpWordList = pgpWordlist; BackCommand = new DelegateCommand(Back); ContinueCommand = new DelegateCommand(Continue); }