Example #1
0
        public bool ValidateSignatures(string expectedAddress, string[] signatureFragments, string bundleHash)
        {
            var normalizedBundleFragments = new int[3, NUMBER_OF_ROUNDS];

            int[] normalizedBundleHash = TransactionExtensions.NormalizedBundle(bundleHash);

            // Split hash into 3 fragments
            for (int i = 0; i < 3; i++)
            {
                Array.Copy(normalizedBundleHash, i * NUMBER_OF_ROUNDS, normalizedBundleFragments, i * NUMBER_OF_ROUNDS, (i + 1) * NUMBER_OF_ROUNDS);
            }

            // Get digests
            int[] digests = new int[signatureFragments.Length * Curl.HashLength];

            for (int i = 0; i < signatureFragments.Length; i++)
            {
                int[] digestBuffer = this.Digest(ArrayUtils.SliceRow(normalizedBundleFragments, i % 3).ToArray(),
                                                 Converter.ToTrits(signatureFragments[i]));

                Array.Copy(digestBuffer, 0, digests, i * Curl.HashLength, Curl.HashLength);
            }
            string address = Converter.ToTrytes(this.Address(digests));

            return(expectedAddress.Equals(address));
        }
Example #2
0
        public bool ValidateSignatures(string expectedAddress, sbyte[] signatureFragments, string bundleHash)
        {
            if (string.IsNullOrWhiteSpace(bundleHash))
            {
                throw new ArgumentNullException(nameof(bundleHash));
            }

            var bundle = new Bundle();

            var normalizedBundleFragments = new List <int[]>(3);
            var normalizedBundleHash      = TransactionExtensions.NormalizedBundle(bundleHash);

            // Split hash into 3 fragments
            for (var i = 0; i < 3; i++)
            {
                normalizedBundleFragments[i] = normalizedBundleHash.Slice(i * 27, (i + 1) * 27);
            }

            // Get digests
            var digests = new sbyte[signatureFragments.Length * 243];

            for (var i = 0; i < signatureFragments.Length; i++)
            {
                var digestBuffer = Digest(normalizedBundleFragments[i % 3], Converter.GetTrits(signatureFragments[i]));

                for (var j = 0; j < 243; j++)
                {
                    digests[i * 243 + j] = digestBuffer[j];
                }
            }

            var address = Converter.GetTrytes(Address(digests));

            return(expectedAddress == address);
        }
Example #3
0
        public bool ValidateSignatures(string expectedAddress, string[] signatureFragments, string bundleHash)
        {
            //Bundle bundle = new Bundle();

            var normalizedBundleFragments = new int[3, 27];

            int[] normalizedBundleHash = TransactionExtensions.NormalizedBundle(bundleHash); //bundle.NormalizedBundle(bundleHash);

            // Split hash into 3 fragments
            for (int i = 0; i < 3; i++)
            {
                // normalizedBundleFragments[i] = Arrays.copyOfRange(normalizedBundleHash, i*27, (i + 1)*27);
                Array.Copy(normalizedBundleHash, i * 27, normalizedBundleFragments, 0, 27);
            }

            // Get digests
            int[] digests = new int[signatureFragments.Length * 243];

            for (int i = 0; i < signatureFragments.Length; i++)
            {
                int[] digestBuffer = Digest(ArrayUtils.SliceRow(normalizedBundleFragments, i % 3).ToArray(),
                                            Converter.ToTrits(signatureFragments[i]));

                for (int j = 0; j < 243; j++)
                {
                    Array.Copy(digestBuffer, j, digests, i * 243 + j, 1);
                }
            }
            string address = Converter.ToTrytes(Address(digests));

            return(expectedAddress.Equals(address));
        }
        public static void SignSignature(this TransactionItem transactionItem, int[] addressPrivateKey, ICurl curl)
        {
            var value = Int64.Parse(transactionItem.Value);

            if (value > 0)
            {
                return;
            }
            //throw new IotaException($"Cannot sign transaction with value greater than 0. Current value '{value}'");

            int index = value < 0 ? 0 : 1;

            var normalizedBundleHash = TransactionExtensions.NormalizedBundle(transactionItem.Bundle);

            //  First 6561 trits for the firstFragment
            int[] firstFragment = ArrayUtils.SubArray2(addressPrivateKey, 6561 * index, 6561);
            //  First bundle fragment uses 27 trytes
            int[] firstBundleFragment = ArrayUtils.SubArray2(normalizedBundleHash, 27 * index, 27);
            //  Calculate the new signatureFragment with the first bundle fragment
            int[] firstSignedFragment = new Signing(curl).SignatureFragment(firstBundleFragment, firstFragment);

            //  Convert signature to trytes and assign the new signatureFragment
            transactionItem.SignatureFragment = Converter.ToTrytes(firstSignedFragment);
        }