Ejemplo n.º 1
0
        public static Transaction CreateDummy()
        {
            var transaction = new TransferTransaction();

            transaction.Inputs = new[] { new TransactionInput { Transaction = addressGenerator.NextULong(), Index = 0 } };
            transaction.Outputs = new[] { new TransactionOutput { Address = RandomHashedAddress(), Value = Math.Abs(addressGenerator.Next()) % 100 } };

            foreach(var input in transaction.Inputs)
            {
                using (var cngKey = CngKey.Create(CngAlgorithm.ECDsaP256, null, new CngKeyCreationParameters { ExportPolicy = CngExportPolicies.AllowPlaintextExport }))
                {
                    var publicKey = cngKey.Export(CngKeyBlobFormat.EccPublicBlob);
                    var privateKey = cngKey.Export(CngKeyBlobFormat.EccPrivateBlob);
                    var priorOutput = new TransactionOutput { Address = RandomHashedAddress(), Value = Math.Abs(addressGenerator.Next()) % 100 };

                    input.PublicKey = publicKey;
                    input.Sign(priorOutput, privateKey);
                }
            }

            return transaction;
        }
Ejemplo n.º 2
0
        public void Sign(TransactionOutput output, byte[] privateKey)
        {
            var signature = new InputSignature
            {
                Address = output.Address,
                Value = output.Value,
                Transaction = this.Transaction,
                Index = this.Index
            };

            using (var key = CngKey.Import(privateKey, CngKeyBlobFormat.EccPrivateBlob))
            using (var encryption = new ECDsaCng(key))
            {
                this.Signature = encryption.SignData(signature.Bytes);
            }
        }