internal static void Sign(IInvoice invoice, ECPrivateKeyParameters privateKey) { var digest = new KeccakDigest(256); digest.BlockUpdate(invoice.TxBytes.ToArray(), 0, invoice.TxBytes.Length); var hash = new byte[digest.GetByteLength()]; digest.DoFinal(hash, 0); var signer = new ECDsaSigner(new HMacDsaKCalculator(new Sha256Digest())); signer.Init(true, privateKey); var components = signer.GenerateSignature(hash); var encoded = new byte[64]; insert256Int(components[0], 0, encoded); insert256Int(components[1], 32, encoded); var publicKey = domain.G.Multiply(privateKey.D).GetEncoded(true); var prefix = new ReadOnlyMemory <byte>(publicKey, 0, Math.Min(Math.Max(6, invoice.MinimumDesiredPrefixSize), publicKey.Length)); invoice.AddSignature(KeyType.ECDSASecp256K1, prefix, encoded); }