Esempio n. 1
0
        public async Task Open_NotExist_Account()
        {
            var address   = Address.FromString("test account");
            var addString = address.GetFormatted();
            var keyPair   = _keyStore.GetAccountKeyPair(addString);

            keyPair.ShouldBe(null);

            var errResult = await _keyStore.OpenAsync(addString, "123");

            errResult.ShouldBe(AElfKeyStore.Errors.AccountFileNotFound);
        }
        public Transaction SignTransaction(Transaction tx)
        {
            string addr = tx.From.Value.ToHex();

            ECKeyPair kp = _keyStore.GetAccountKeyPair(addr);

            if (kp == null)
            {
                Console.WriteLine("The following account is locked:" + addr);
                return(null);
            }

            MemoryStream ms = new MemoryStream();

            Serializer.Serialize(ms, tx);

            byte[] b     = ms.ToArray();
            byte[] toSig = SHA256.Create().ComputeHash(b);

            // Sign the hash
            ECSigner    signer    = new ECSigner();
            ECSignature signature = signer.Sign(kp, toSig);

            // Update the signature
            tx.R = signature.R;
            tx.S = signature.S;

            tx.P = kp.PublicKey.Q.GetEncoded();

            return(tx);
        }
Esempio n. 3
0
        private void UnlockAccount(string address, bool timeout = true)
        {
            var accounts = _keyStore.ListAccounts();

            if (accounts == null || accounts.Count <= 0)
            {
                _screenManager.PrintError("error: the account '" + address + "' does not exist.");
                return;
            }

            if (!accounts.Contains(address))
            {
                _screenManager.PrintError("account does not exist!");
                return;
            }

            var password = _screenManager.AskInvisible("password: "******"incorrect password!");
                return;
            }
            if (tryOpen == AElfKeyStore.Errors.AccountAlreadyUnlocked)
            {
                _screenManager.PrintError("account already unlocked!");
                return;
            }

            if (tryOpen == AElfKeyStore.Errors.None)
            {
                _screenManager.PrintLine("account successfully unlocked!");
                return;
            }

            var kp = _keyStore.GetAccountKeyPair(address);

            _screenManager.PrintLine($"Pub : {kp.GetEncodedPublicKey().ToHex()}");
        }
Esempio n. 4
0
        public void Init(ContainerBuilder builder)
        {
            ECKeyPair nodeKey = null;

            if (!string.IsNullOrWhiteSpace(NodeConfig.Instance.NodeAccount))
            {
                try
                {
                    var ks = new AElfKeyStore(ApplicationHelpers.GetDefaultConfigPath());

                    var pass = string.IsNullOrWhiteSpace(NodeConfig.Instance.NodeAccountPassword)
                        ? AskInvisible(NodeConfig.Instance.NodeAccount)
                        : NodeConfig.Instance.NodeAccountPassword;

                    ks.OpenAsync(NodeConfig.Instance.NodeAccount, pass, false);

                    NodeConfig.Instance.NodeAccountPassword = pass;

                    nodeKey = ks.GetAccountKeyPair(NodeConfig.Instance.NodeAccount);

                    if (nodeKey == null)
                    {
                        Console.WriteLine("Load keystore failed");
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("Load keystore failed");
                }
            }

            TransactionPoolConfig.Instance.EcKeyPair = nodeKey;
            NetworkConfig.Instance.EcKeyPair         = nodeKey;

            builder.RegisterModule(new NodeAutofacModule());
        }
Esempio n. 5
0
        public ECKeyPair GetKeyPair(string addr)
        {
            ECKeyPair kp = _keyStore.GetAccountKeyPair(addr);

            return(kp);
        }