コード例 #1
0
        /// <summary>
        /// Signs the aggregate transaction with cosigners.
        /// </summary>
        /// <param name="initiatorAccount">The initiator account.</param>
        /// <param name="cosignatories">The cosignatories.</param>
        /// <returns>SignedTransaction.</returns>
        /// <exception cref="ArgumentNullException">
        /// initiatorAccount
        /// or
        /// cosignatories
        /// </exception>
        public SignedTransaction SignWithAggregateCosigners(KeyPair initiatorAccount, List <Account> cosignatories)
        {
            if (initiatorAccount == null)
            {
                throw new ArgumentNullException(nameof(initiatorAccount));
            }
            if (cosignatories == null)
            {
                throw new ArgumentNullException(nameof(cosignatories));
            }

            var signedTransaction = SignWith(initiatorAccount);
            var payload           = signedTransaction.Payload.FromHex();

            foreach (var cosignatory in cosignatories)
            {
                var bytes = signedTransaction.Hash.FromHex();

                var signatureBytes = TransactionExtensions.SignHash(cosignatory.KeyPair, bytes);

                payload = payload.Concat(cosignatory.KeyPair.PublicKey.Concat(signatureBytes)).ToArray();

                Cosignatures.Add(new AggregateTransactionCosignature(signatureBytes.ToHexLower(), new PublicAccount(cosignatory.KeyPair.PublicKey.ToHexLower(), Blockchain.NetworkType.Types.MIJIN_TEST)));
            }

            payload = BitConverter.GetBytes(payload.Length).Concat(payload.Take(4, payload.Length - 4).ToArray()).ToArray();

            return(SignedTransaction.Create(payload, signedTransaction.Hash.FromHex(), initiatorAccount.PublicKey, TransactionType));
        }
コード例 #2
0
        /// <summary>
        /// Generates the hash for a serialized transaction payload.
        /// </summary>
        /// <param name="transactionPayload">The transaction payload in hex format.</param>
        /// <returns>The hash in hex format.</returns>
        public static string CreateTransactionHash(string transactionPayload)
        {
            if (transactionPayload == null)
            {
                throw new ArgumentNullException(nameof(transactionPayload));
            }

            return(TransactionExtensions.Hasher(transactionPayload.FromHex()).ToHexUpper());
        }
コード例 #3
0
        /// <summary>
        /// Sign the transaction with a given account.
        /// </summary>
        /// <param name="account">The account.</param>
        /// <returns>CosignatureSignedTransactionDTO.</returns>
        /// <exception cref="ArgumentNullException">account</exception>
        public CosignatureSignedTransactionDTO SignWith(KeyPair account)
        {
            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }
            var bytes          = Hash.FromHex();
            var signatureBytes = TransactionExtensions.SignHash(account, bytes);

            return(new CosignatureSignedTransactionDTO {
                ParentHash = Hash, Signature = signatureBytes.ToHexLower(), Signer = account.PublicKeyString
            });
        }
コード例 #4
0
        /// <summary>
        /// Signs the transaction with the given <see cref="KeyPair"/>.
        /// </summary>
        /// <param name="keyPair">The <see cref="KeyPair"/>.</param>
        /// <returns><see cref="SignedTransaction"/>.</returns>
        /// <exception cref="ArgumentNullException">keyPair</exception>
        public SignedTransaction SignWith(KeyPair keyPair)
        {
            if (keyPair == null)
            {
                throw new ArgumentNullException(nameof(keyPair));
            }

            Signer = PublicAccount.CreateFromPublicKey(keyPair.PublicKeyString, NetworkType);

            Bytes = GenerateBytes();

            var sig = TransactionExtensions.SignTransaction(keyPair, Bytes);

            var signedBuffer = Bytes.Take(4)
                               .Concat(sig)
                               .Concat(keyPair.PublicKey)
                               .Concat(
                Bytes.Take(4 + 64 + 32, Bytes.Length - (4 + 64 + 32))
                ).ToArray();

            return(SignedTransaction.Create(signedBuffer, TransactionExtensions.Hasher(signedBuffer), keyPair.PublicKey, TransactionType));
        }