Exemplo n.º 1
0
        /*
         * Constructs the message object and initiates its serialization
         *
         * @Param: Serializer, The serializer to use during serialization
         * @Param: Message, The message string. Note: if null, a zero value byte[4] is serialized instead
         * @Param: Encrypted, Whether the message should be encrypted or not
         */

        internal Message(Connectivity.Connection con, PrivateKey senderKey, string address, string message, bool encrypted)

        {
            Encrypted = encrypted;

            MessageString = message;

            if (MessageString != null)
            {
                if (Encrypted)
                {
                    var a = new AccountClient(con).BeginGetAccountInfoFromAddress(body =>
                    {
                        if (body.Content.Account.PublicKey == null)
                        {
                            throw new Exception("recipient public key cannot be null for encryption");
                        }

                        PublicKey = body.Content.Account.PublicKey;
                    }, address);

                    a.AsyncWaitHandle.WaitOne();

                    if (PublicKey == null)
                    {
                        throw new ArgumentNullException("could not find recipient public key");
                    }

                    Sender = new PrivateKeyAccountClient(con, senderKey);

                    MessageBytes = new Ed25519BlockCipher(Sender, PublicKey).Encrypt(Encoding.UTF8.GetBytes(MessageString));
                }
                else
                {
                    MessageBytes = Encoding.UTF8.GetBytes(MessageString);
                }

                PayloadLengthInBytes = MessageBytes.Length;
            }

            Serialize();

            CalculateMessageFee();
        }
        private static void SignTransaction(PrivateKeyAccountClient acc, Transactions.TransactionData t, string multisigAcc)
        {
            Console.WriteLine("signing transaction");
            try
            {
                acc.BeginSignatureTransactionAsync(ar => {
                    try {
                        if (ar.Content.Code == 1)
                        {
                            var sum = new TxSummary()
                            {
                                AccAddress = multisigAcc,
                                DateOfTx   = DateTime.Now,
                                Amount     = t.transaction.otherTrans.amount
                            };

                            TxSummaryController.AddSummaryForAccount(sum);
                        }
                        else
                        {
                            Console.WriteLine(ar.Content.Code);
                        }
                        Console.WriteLine(ar.Content.Message);
                        Console.WriteLine();
                        Console.WriteLine();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }, new MultisigSignatureTransactionData
                {
                    Deadline = int.Parse(ConfigurationManager.AppSettings["deadline"]) == 0
                      ? 82800 : int.Parse(ConfigurationManager.AppSettings["deadline"]),
                    TransactionHash = t.meta.data,
                    MultisigAddress = new Address(multisigAcc),
                }).AsyncWaitHandle.WaitOne();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                SignTransaction(acc, t, multisigAcc);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructs an instance of the <see cref="Ed25519BlockCipher"/> class.
 /// </summary>
 /// <param name="PrivateKeyAccountClient">The PrivateKeyAccountClient used to encrypt or decrypt data</param>
 /// <param name="publicKey">The public key of the recipient of the encrypted data.</param>
 public Ed25519BlockCipher(PrivateKeyAccountClient PrivateKeyAccountClient, string publicKey)
 {
     PublicKey         = publicKey;
     PrivateKeyAccount = PrivateKeyAccountClient;
     Random            = new SecureRandom();
 }