예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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}");
            }
        }
예제 #3
0
        /// <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}");
            }
        }
예제 #4
0
        /// <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;
        }
예제 #5
0
 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);
 }
예제 #6
0
        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));
        }
예제 #7
0
        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);
        }
예제 #8
0
        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));
        }
예제 #9
0
        /// <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);
        }
예제 #10
0
 public static string[] EncodeWordList(PgpWordList pgpWordList, byte[] seed) => pgpWordList.Encode(seed);
예제 #11
0
        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);
        }
예제 #12
0
        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;
        }
예제 #13
0
        public ImportSeedDialog(StartupWizard wizard, PgpWordList pgpWordlist, ConnectionWizardDialog previousDialog) : base(wizard)
        {
            _previousDialog = previousDialog;
            _pgpWordList = pgpWordlist;

            BackCommand = new DelegateCommand(Back);
            ContinueCommand = new DelegateCommand(Continue);
        }