Exemple #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));
        }
Exemple #2
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));
        }