コード例 #1
0
        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);
        }
コード例 #2
0
 private static string GetUniqueFulfillment(TxTemplate transaction, string serializedTransaction, int index)
 {
     return(transaction.Inputs[index].Fulfills == null ?
            serializedTransaction +
            transaction.Inputs[index].Fulfills?.TransactionId +
            transaction.Inputs[index].Fulfills?.OutputIndex : serializedTransaction);
 }
コード例 #3
0
        public (byte[], byte[], byte[]) GetSignature(TxTemplate transaction, string serializedTransaction, int index, string privKey)
        {
            var pubKeyBuffer = Encoders.Base58.DecodeData(transaction.Outputs[index].PublicKeys[0]);

            string transactionUniqueFulfillment = GetUniqueFulfillment(transaction, serializedTransaction, index);

            var transactionHash = HashingUtils.ComputeSha3Hash(Encoding.UTF8.GetBytes(transactionUniqueFulfillment));

            var signature = CryptographyUtility.Ed25519Sign(transactionHash, Encoders.Base58.DecodeData(privKey));

            return(transactionHash, pubKeyBuffer, signature);
        }