Example #1
0
        /// <summary>
        ///     Decrypts and add the account to the Wallet Account List, using NEP2.
        /// </summary>
        /// <param name="label"></param>
        /// <param name="encryptedPrivateKey"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <Account> ImportAccount(string encryptedPrivateKey, string password, string label)
        {
            var privateKey = await Nep2.Decrypt(encryptedPrivateKey, password, _wallet.Scrypt);

            var key = new KeyPair(privateKey);

            Array.Clear(privateKey, 0, privateKey.Length);

            var contract = new Contract
            {
                Script     = Helper.CreateSignatureRedeemScript(key.PublicKey),
                Parameters = new List <Parameter>
                {
                    new Parameter("signature", ParameterType.Signature)
                },
                Deployed = false
            };

            var account = new Account(contract.ScriptHash, key)
            {
                Nep2Key   = encryptedPrivateKey,
                Label     = label,
                Contract  = contract,
                IsDefault = false
            };

            AddAccount(account);
            return(account);
        }
Example #2
0
        /// <summary>
        ///     Gets the KeyPair object using the encrypted key and password pair.
        /// </summary>
        /// <param name="nep2Key"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <KeyPair> GetKey(string nep2Key, string password)
        {
            if (nep2Key == null)
            {
                return(null);
            }
            var decryptedKey = await Nep2.Decrypt(nep2Key, password, _wallet.Scrypt);

            var privKey = new KeyPair(decryptedKey);

            return(privKey);
        }
Example #3
0
        /// <summary>
        ///     Verifies if the provided encrypted key and password are correct.
        /// </summary>
        /// <param name="nep2Key"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <bool> VerifyPassword(string nep2Key, string password)
        {
            try
            {
                await Nep2.Decrypt(nep2Key, password, _wallet.Scrypt);

                return(true);
            }
            catch (FormatException)
            {
                return(false);
            }
        }