public static string GenerateAddress(int[] privateKey, bool checksum, CancellationToken cancellationToken) { var signing = new Signing(new Kerl()); var digests = signing.Digests(privateKey); cancellationToken.ThrowIfCancellationRequested(); var addressTrits = signing.Address(digests); cancellationToken.ThrowIfCancellationRequested(); string address = Converter.ToTrytes(addressTrits); if (checksum) { address = Checksum.AddChecksum(address); } return(address); }
public static void SignSignature(this TransactionItem transactionItem, int[] addressPrivateKey, ICurl curl) { var value = 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); }