public TxTemplate SignTransaction(TxTemplate transaction, List <string> privateKeys)
        {
            var signedTx = (TxTemplate)transaction.Clone();

            var serializedTransaction = JsonUtility.SerializeTransactionIntoCanonicalString(JsonConvert.SerializeObject(transaction));

            var index = 0;

            foreach (var privKey in privateKeys)
            {
                SignatureMetadata signatures = GetSignature(transaction, serializedTransaction, index, privKey);

                bool verifyFullfill = signatures.Signature.VerifySignature(signatures.TransactionHash, signatures.PubKeyBuffer);
                if (!verifyFullfill)
                {
                    continue;
                }


                signedTx.Inputs[index].Fulfillment = GenerateFulfillmentUri(signatures.PubKeyBuffer, signatures.Signature);
                index++;
            }

            var serializedSignedTransaction = JsonUtility.SerializeTransactionIntoCanonicalString(JsonConvert.SerializeObject(signedTx));

            signedTx.Id = HashingUtils.ComputeSha3Hash(Encoding.UTF8.GetBytes(serializedSignedTransaction)).ToHex(false);
            return(signedTx);
        }
Esempio n. 2
0
        protected override void ReadSpecific(BinaryReader reader)
        {
            var count = reader.ReadVarUint32();

            for (var i = 0; i < count; i++)
            {
                Signatures.Add(SignatureMetadata.Read(reader));
            }
        }
Esempio n. 3
0
        public void ProvidedTx_ShouldReturnValidSignedTxHash()
        {
            var expectedSerializedTransactionHash = "7c93d8e95c6e2d1b6ba6d77020a9e7d09d30c498fcb0485801fc7507fda43fca";

            var keyPair = new GeneratedKeyPair()
            {
                ExpandedPrivateKey = "2SmR42zKeTExHeXa5gFCJzfVLzPb843bkv9L9EGNxfABo9roeGWuNvTg5KFCcNoA6xd4VnWnX1yzALSvszBFncGu",
                PrivateKey         = "5ryt9DgJWu2G5Ptzd5CwUXsvw5DKygd4serdMoJ67KCm",
                PublicKey          = "6up1UDJC2EnReHcdYVZkJdR8hbSym48P5XWiyD1oW2Qm"
            };

            var tx = GetMockResponseTx(keyPair.PublicKey);

            var serializedTransaction = JsonUtility.SerializeTransactionIntoCanonicalString(JsonConvert.SerializeObject(tx));

            var signTx = new Bigchain_SignTransaction();

            SignatureMetadata signatures = signTx.GetSignature(tx, serializedTransaction, 0, keyPair.ExpandedPrivateKey);

            Assert.AreEqual(expectedSerializedTransactionHash, signatures.TransactionHash.ToHex());
        }