/// <summary> /// Removes the checksum from the specified address with checksum /// </summary> /// <param name="address">The address with checksum or without checksum.</param> /// <returns>the specified address without checksum</returns> public static string RemoveChecksum(this string address) { if (InputValidator.IsAddress(address)) { return(RemoveChecksumFromAddress(address)); } if (InputValidator.IsAddressWithoutChecksum(address)) { return(address); } throw new ArgumentException(Constants.INVALID_ADDRESSES_INPUT_ERROR); }
/// <summary> /// /// </summary> /// <param name="seed"></param> /// <param name="security"></param> /// <param name="index"></param> /// <param name="checksum"></param> /// <param name="curl"></param> /// <returns></returns> public static string NewAddress(string seed, int security, int index, bool checksum, ICurl curl) { if (!InputValidator.IsValidSecurityLevel(security)) { throw new ArgumentException(Constants.INVALID_SECURITY_LEVEL_INPUT_ERROR); } Signing signing = new Signing(curl); sbyte[] key = signing.Key(Converter.ToTrits(seed), index, security); sbyte[] digests = signing.Digests(key); sbyte[] addressTrits = signing.Address(digests); string address = Converter.ToTrytes(addressTrits); if (checksum) { address = address.AddChecksum(); } return(address); }
/// <summary> /// </summary> /// <param name="bundleToSign"></param> /// <param name="inputAddress"></param> /// <param name="keyTrytes"></param> /// <returns></returns> public Bundle AddSignature(Bundle bundleToSign, string inputAddress, string keyTrytes) { // Get the security used for the private key // 1 security level = 2187 trytes var security = keyTrytes.Length / Constants.MESSAGE_LENGTH; // convert private key trytes into trits var key = Converter.ToTrits(keyTrytes); // First get the total number of already signed transactions // use that for the bundle hash calculation as well as knowing // where to add the signature var numSignedTxs = 0; for (var i = 0; i < bundleToSign.Transactions.Count; i++) { if (bundleToSign.Transactions[i].Address.Equals(inputAddress, StringComparison.Ordinal)) { if (!InputValidator.IsNinesTrytes(bundleToSign.Transactions[i].SignatureMessageFragment, bundleToSign.Transactions[i].SignatureMessageFragment.Length)) { numSignedTxs++; } // Else sign the transactions else { var bundleHash = bundleToSign.Transactions[i].Bundle; // First 6561 trits for the firstFragment var firstFragment = new sbyte[6561]; Array.Copy(key, firstFragment, 6561); // Get the normalized bundle hash var normalizedBundleFragments = new sbyte[3][]; for (var n = 0; n < 3; n++) { normalizedBundleFragments[n] = new sbyte[27]; } var normalizedBundleHash = bundleToSign.NormalizedBundle(bundleHash); // Split hash into 3 fragments for (var k = 0; k < 3; k++) { Array.Copy(normalizedBundleHash, k * 27, normalizedBundleFragments[k], 0, 27); } // First bundle fragment uses 27 trytes var firstBundleFragment = normalizedBundleFragments[numSignedTxs % 3]; // Calculate the new signatureFragment with the first bundle fragment var firstSignedFragment = _signing.SignatureFragment(firstBundleFragment, firstFragment); // Convert signature to trytes and assign the new signatureFragment bundleToSign.Transactions[i].SignatureMessageFragment = Converter.ToTrytes(firstSignedFragment); for (var j = 1; j < security; j++) { // Next 6561 trits for the firstFragment var nextFragment = new sbyte[6561]; Array.Copy(key, 6561 * j, nextFragment, 0, 6561); // Use the next 27 trytes var nextBundleFragment = normalizedBundleFragments[(numSignedTxs + j) % 3]; // Calculate the new signatureFragment with the first bundle fragment var nextSignedFragment = _signing.SignatureFragment(nextBundleFragment, nextFragment); // Convert signature to trytes and add new bundle entry at i + j position // Assign the signature fragment bundleToSign.Transactions[i + j].SignatureMessageFragment = Converter.ToTrytes(nextSignedFragment); } break; } } } return(bundleToSign); }