public void testExportKeys() { var algorithm = SignatureAlgorithm.Ed25519; BlockchainAccount account = AccountApi.createAccount(true); account.PublicKey.ShouldNotBe(null); account.Key.ShouldNotBe(null); var data = Encoding.UTF8.GetBytes("Hello world!"); // sign the data with the private key var signature = algorithm.Sign(account.Key, data); var key = account.Export(); key.ShouldNotBe(null); var privateStr = Utils.ByteArrayToString(key); var pub = account.ExportPublic(); pub.ShouldNotBe(null); var publicStr = Utils.ByteArrayToString(pub); using (var newKey = Key.Import(algorithm, Utils.StringToByteArray(privateStr), KeyBlobFormat.PkixPrivateKey)) { var publicKey = PublicKey.Import(algorithm, Utils.StringToByteArray(publicStr), KeyBlobFormat.PkixPublicKey); // sign the data with the private key var signature2 = algorithm.Sign(newKey, data); signature2.ShouldBe(signature); // verify the data with the signature and the public key var done = algorithm.Verify(publicKey, data, signature2); done.ShouldBe(true); } // now user }
public async Task testBurnTransaction() { var publicKeyObj = BlockchainAccount.publicKeyFromHex(publicKey); var privateKeyObj = BlockchainAccount.privateKeyFromHex(privateKey); Vehicle car = new Vehicle(); car.id = "92832938203903-" + DateTime.Now.Ticks.ToString(); car.consumption = "20.9"; // Set up, sign, and send your transaction var transaction = BigchainDbTransactionBuilder <Vehicle, object> .init() .addAssets(car) .operation(Operations.CREATE) .buildAndSignOnly(publicKeyObj, privateKeyObj); //.buildAndSign(account.PublicKey, account.PrivateKey); //var info = transaction.toHashInput(); var createTransaction = await TransactionsApi <Vehicle, object> .sendTransactionAsync(transaction); createTransaction.Data.ShouldNotBe(null); // the asset's ID is equal to the ID of the transaction that created it if (createTransaction != null) { string testId2 = createTransaction.Data.Id; var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(testId2); testTran2.ShouldNotBe(null); } // Describe the output you are fulfilling on the previous transaction FulFill spendFrom = new FulFill(); // the asset's ID is equal to the ID of the transaction that created it spendFrom.TransactionId = createTransaction.Data.Id; spendFrom.OutputIndex = 0; // By default, the 'amount' of a created digital asset == "1". So we spend "1" in our TRANSFER. string amount = "1"; var burnKey = new BlockchainAccount(); var burnKeyStr = Utils.ByteArrayToString(burnKey.ExportPublic()); var s = new Status(); s.Value = "BURNED"; Details details = null; // Use the previous transaction's asset and TRANSFER it var build2 = BigchainDbTransactionBuilder <Vehicle, Status> . init(). addInput(details, spendFrom, publicKeyObj). addOutput(amount, burnKey.PublicKey). addAssets(createTransaction.Data.Id). addMetaData(s). operation(Operations.TRANSFER). buildAndSignOnly(publicKeyObj, privateKeyObj); var transferTransaction = await TransactionsApi <Vehicle, Status> .sendTransactionAsync(build2); transferTransaction.Data.ShouldNotBe(null); if (transferTransaction != null) { string tran2 = transferTransaction.Data.Id; var testTran2 = await TransactionsApi <object, object> .getTransactionByIdAsync(tran2); testTran2.ShouldNotBe(null); string tran3 = transferTransaction.Data.Asset.Id; var testTran3 = await TransactionsApi <object, object> .getTransactionByIdAsync(tran3); testTran3.ShouldNotBe(null); } }