public static byte[] ToArray(this stellar_dotnet_sdk.Transaction tx) { var outputStream = new XdrDataOutputStream(); stellar_dotnet_sdk.xdr.Transaction.Encode(outputStream, tx.ToXdrV1()); return(outputStream.ToArray()); }
public void TestBuilderFee() { // GBPMKIRA2OQW2XZZQUCQILI5TMVZ6JNRKM423BSAISDM7ZFWQ6KWEBC4 var source = KeyPair.FromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS"); var destination = KeyPair.FromAccountId("GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR"); var account = new Account(source.AccountId, 2908908335136768L); var transaction = new TransactionBuilder(account) .AddOperation(new CreateAccountOperation.Builder(destination, "2000").Build()) .AddOperation(new CreateAccountOperation.Builder(destination, "2000").Build()) .SetFee(173) .Build(); // Convert transaction to binary XDR and back again to make sure fee is correctly de/serialized. var decodedTransaction = transaction.ToUnsignedEnvelopeXdr().V1.Tx; Assert.AreEqual(decodedTransaction.Fee.InnerValue, 173 * 2U); var transaction2 = Transaction.FromEnvelopeXdr(transaction.ToUnsignedEnvelopeXdr()); Assert.AreEqual(transaction.SourceAccount.AccountId, transaction2.SourceAccount.AccountId); Assert.AreEqual(transaction.SequenceNumber, transaction2.SequenceNumber); Assert.AreEqual(transaction.Memo, transaction2.Memo); Assert.AreEqual(transaction.TimeBounds, transaction2.TimeBounds); Assert.AreEqual(transaction.Fee, transaction2.Fee); Assert.AreEqual( ((CreateAccountOperation)transaction.Operations[0]).StartingBalance, ((CreateAccountOperation)transaction2.Operations[0]).StartingBalance ); Assert.AreEqual( ((CreateAccountOperation)transaction.Operations[1]).StartingBalance, ((CreateAccountOperation)transaction2.Operations[1]).StartingBalance ); }
public void ReturnsTransactionHash() { Stellar.Transaction tx = this.GenerateSignedChallenge(_fixture.UserKeypair, _fixture.DevKeypair); Library.Auth.Token token = new Library.Auth.Token(_fixture.DevKeypair.SecretSeed, tx.ToEnvelopeXdrBase64(), _fixture.UserKeypair.AccountId); Assert.NotNull(token.Hash()); }
public void TestBuilderMemoText() { // GBPMKIRA2OQW2XZZQUCQILI5TMVZ6JNRKM423BSAISDM7ZFWQ6KWEBC4 var source = KeyPair.FromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS"); var destination = KeyPair.FromAccountId("GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR"); var account = new Account(source, 2908908335136768); var transaction = new Transaction.Builder(account) .AddOperation(new CreateAccountOperation.Builder(destination, "2000").Build()) .AddMemo(Memo.Text("Hello world!")) .Build(); transaction.Sign(source); Assert.AreEqual( "AAAAAF7FIiDToW1fOYUFBC0dmyufJbFTOa2GQESGz+S2h5ViAAAAZAAKVaMAAAABAAAAAAAAAAEAAAAMSGVsbG8gd29ybGQhAAAAAQAAAAAAAAAAAAAAAO3gUmG83C+VCqO6FztuMtXJF/l7grZA7MjRzqdZ9W8QAAAABKgXyAAAAAAAAAAAAbaHlWIAAABAxzofBhoayuUnz8t0T1UNWrTgmJ+lCh9KaeOGu2ppNOz9UGw0abGLhv+9oWQsstaHx6YjwWxL+8GBvwBUVWRlBQ==", transaction.ToEnvelopeXdrBase64()); var transaction2 = Transaction.FromEnvelopeXdr(transaction.ToEnvelopeXdr()); Assert.AreEqual(transaction.SourceAccount.AccountId, transaction2.SourceAccount.AccountId); Assert.AreEqual(transaction.SequenceNumber, transaction2.SequenceNumber); Assert.AreEqual(transaction.Memo, transaction2.Memo); Assert.AreEqual(transaction.Fee, transaction2.Fee); Assert.AreEqual( ((CreateAccountOperation)transaction.Operations[0]).StartingBalance, ((CreateAccountOperation)transaction2.Operations[0]).StartingBalance ); }
public void TestBuilderMemoText() { // GBPMKIRA2OQW2XZZQUCQILI5TMVZ6JNRKM423BSAISDM7ZFWQ6KWEBC4 var source = KeyPair.FromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS"); var destination = KeyPair.FromAccountId("GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR"); var account = new Account(source.AccountId, 2908908335136768); var transaction = new TransactionBuilder(account) .AddOperation(new CreateAccountOperation.Builder(destination, "2000").Build()) .AddMemo(Memo.Text("Hello world!")) .Build(); transaction.Sign(source); Assert.AreEqual( "AAAAAF7FIiDToW1fOYUFBC0dmyufJbFTOa2GQESGz+S2h5ViAAAAZAAKVaMAAAABAAAAAAAAAAEAAAAMSGVsbG8gd29ybGQhAAAAAQAAAAAAAAAAAAAAAO3gUmG83C+VCqO6FztuMtXJF/l7grZA7MjRzqdZ9W8QAAAABKgXyAAAAAAAAAAAAbaHlWIAAABAxzofBhoayuUnz8t0T1UNWrTgmJ+lCh9KaeOGu2ppNOz9UGw0abGLhv+9oWQsstaHx6YjwWxL+8GBvwBUVWRlBQ==", transaction.ToEnvelopeXdrBase64(TransactionBase.TransactionXdrVersion.V0)); Assert.AreEqual( "AAAAAgAAAABexSIg06FtXzmFBQQtHZsrnyWxUzmthkBEhs/ktoeVYgAAAGQAClWjAAAAAQAAAAAAAAABAAAADEhlbGxvIHdvcmxkIQAAAAEAAAAAAAAAAAAAAADt4FJhvNwvlQqjuhc7bjLVyRf5e4K2QOzI0c6nWfVvEAAAAASoF8gAAAAAAAAAAAG2h5ViAAAAQMc6HwYaGsrlJ8/LdE9VDVq04JifpQofSmnjhrtqaTTs/VBsNGmxi4b/vaFkLLLWh8emI8FsS/vBgb8AVFVkZQU=", transaction.ToEnvelopeXdrBase64()); var transaction2 = Transaction.FromEnvelopeXdr(transaction.ToEnvelopeXdr()); Assert.AreEqual(transaction.SourceAccount.AccountId, transaction2.SourceAccount.AccountId); Assert.AreEqual(transaction.SequenceNumber, transaction2.SequenceNumber); Assert.AreEqual(transaction.Memo, transaction2.Memo); Assert.AreEqual(transaction.Fee, transaction2.Fee); Assert.AreEqual( ((CreateAccountOperation)transaction.Operations[0]).StartingBalance, ((CreateAccountOperation)transaction2.Operations[0]).StartingBalance ); }
public void ContainsCorrectCustomTimeBounds() { Stellar.Transaction tx = Stellar.Transaction.FromEnvelopeXdr(new Library.Auth.Challenge().Call(_fixture.Keypair.SecretSeed, 100)); long timeNow = DateTimeOffset.Now.ToUnixTimeSeconds() + 100; Assert.Equal(tx.TimeBounds.MaxTime.ToString(), timeNow.ToString()); }
public void CurrentTimeIsWithinTimeBounds() { Stellar.Transaction tx = this.GenerateSignedChallenge(_fixture.UserKeypair, _fixture.DevKeypair); Library.Auth.Token token = new Library.Auth.Token(_fixture.DevKeypair.SecretSeed, tx.ToEnvelopeXdrBase64(), _fixture.UserKeypair.AccountId); Assert.True(token.Validate()); }
public void TransactionIsCorrectlySigned() { Stellar.KeyPair keypair = Stellar.KeyPair.Random(); Stellar.Transaction tx = this.GenerateSignedTransaction(keypair).Result; Assert.True(Library.Utils.Keypair.Verify(tx, keypair)); }
public void TestFromXdrWithMemoId() { // https://github.com/elucidsoft/dotnet-stellar-sdk/issues/208 var tx = Transaction.FromEnvelopeXdr( "AAAAAEdL24Ttos6RnqXCsn8duaV035/QZSC9RXw29IknigHpAAAD6AFb56cAAukDAAAAAQAAAAAAAAAAAAAAAF20fKAAAAACjCiEBz2CpG0AAAABAAAAAAAAAAEAAAAADq+QhtWseqhtnwRIFyZRdLMOVtIqzkujfzUQ22rwZuEAAAAAAAAAAGZeJLcAAAAAAAAAASeKAekAAABAE+X7cGoBhuJ5SDB8WH2B1ZA2RrWIXxGtx+n6wE5d/EggDTpZhRm92b33QqjPUFOfcZ+zbcM+Ny0WR2vcYHEXDA=="); Assert.AreEqual("GBDUXW4E5WRM5EM6UXBLE7Y5XGSXJX472BSSBPKFPQ3PJCJHRIA6SH4C", tx.SourceAccount.AccountId); }
public void TransactionFailsIfIncorrectlySigned() { Stellar.KeyPair keypair = Stellar.KeyPair.Random(); Stellar.KeyPair anotherKeypair = Stellar.KeyPair.Random(); Stellar.Transaction tx = this.GenerateSignedTransaction(keypair).Result; Assert.False(Library.Utils.Keypair.Verify(tx, anotherKeypair)); }
public void ThrowsErrorIfCurrentTimeIsOutsideTimeBounds() { Stellar.Transaction tx = this.GenerateSignedChallenge(_fixture.UserKeypair, _fixture.DevKeypair); Library.Auth.Token token = new Library.Auth.Token(_fixture.DevKeypair.SecretSeed, tx.ToEnvelopeXdrBase64(), _fixture.UserKeypair.AccountId); System.Threading.Thread.Sleep(11000); Assert.ThrowsAny <Exception>(() => token.Validate()); }
///<summary>Private: Validates transaction is signed by developer.</summary> ///<param name="keypair">keypair object for given developer public key</param> ///<param name="tx">Transaction to verify</param> ///<returns>Returns true is transaction is valid, throws error otherwise</returns> private Boolean Validate(Stellar.KeyPair keypair, Stellar.Transaction tx) { Boolean isValid = Utils.Keypair.Verify(tx, keypair); if (!isValid) { throw new Exception("Wrong challenge transaction signature"); } return(true); }
///<summary>Verify given keypair is a signer on a given transaction.</summary> ///<param name="tx">Transaction to verify</param> ///<param name="keypair">Keypair object</param> ///<returns>Returns true if given transaction is signed using specified keypair</returns> public static Boolean Verify(Stellar.Transaction tx, Stellar.KeyPair keypair) { var signatures = tx.Signatures; var hash = tx.Hash(); if (signatures == null || signatures.Count == 0) { return(false); } return(signatures.Where(s => keypair.Verify(hash, s.Signature.InnerValue)).ToArray().Length >= 1); }
public static async Task <SubmitTransactionResponse> Submit(this stellar_dotnet_sdk.Transaction tx, ConstellationInfo constellation) { using (var server = constellation.StellarNetwork.GetServer()) { var res = await server.SubmitTransaction(tx); if (!res.IsSuccess()) { throw new Exception($"Tx submit error. Result xdr: {res.ResultXdr}"); } return(res); } }
public void TestTransactionWithMuxedAccount() { var originalXdr = "AAAAAgAAAQAAAAAAAAAAAHN2/eiOTNYcwPspSheGs/HQYfXy8cpXRl+qkyIRuUbWAAAAZAAAAAAAAAAIAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAABAAAAD0hhcHB5IGJpcnRoZGF5IQAAAAABAAAAAAAAAAEAAAAA4EiRthjlDMvx/ZR8o2GTsMrssrR/MtMFmqHOfei/mxIAAAAAAAAABKgXyAAAAAAAAAAAAA=="; var tx = Transaction.FromEnvelopeXdr(originalXdr); var xdr = tx.ToUnsignedEnvelopeXdrBase64(TransactionBase.TransactionXdrVersion.V1); Assert.AreEqual(originalXdr, xdr); var back = TransactionBuilder.FromEnvelopeXdr(xdr) as Transaction; Assert.IsNotNull(back); Assert.AreEqual(tx.SourceAccount.Address, back.SourceAccount.Address); CollectionAssert.AreEqual(tx.SourceAccount.PublicKey, back.SourceAccount.PublicKey); }
public void TestFromXdr() { var transaction = Transaction.FromEnvelopeXdr("AAAAAF7FIiDToW1fOYUFBC0dmyufJbFTOa2GQESGz+S2h5ViAAAAZAAKVaMAAAABAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAAEqBfIAAAAAAAAAAABtoeVYgAAAEDLki9Oi700N60Lo8gUmEFHbKvYG4QSqXiLIt9T0ru2O5BphVl/jR9tYtHAD+UeDYhgXNgwUxqTEu1WukvEyYcD"); var transaction2 = Transaction.FromEnvelopeXdr(transaction.ToEnvelopeXdr()); Assert.AreEqual(transaction.SourceAccount.AccountId, transaction2.SourceAccount.AccountId); Assert.AreEqual(transaction.SequenceNumber, transaction2.SequenceNumber); Assert.AreEqual(transaction.Fee, transaction2.Fee); Assert.AreEqual( ((CreateAccountOperation)transaction.Operations[0]).StartingBalance, ((CreateAccountOperation)transaction2.Operations[0]).StartingBalance ); CollectionAssert.AreEqual(transaction.Signatures, transaction2.Signatures); }
async private Task <Stellar.Transaction> GenerateSignedTransaction(Stellar.KeyPair keypair) { long randomSequence = (long)(99999999 - Math.Floor((decimal) new Random().Next() * 65536)); Stellar.Account account = new Stellar.Account(keypair, randomSequence); Stellar.Transaction.Builder txBuilder = new Stellar.Transaction.Builder(account); StellarResponses.AssetResponse asset = await new Library.Client().StellarAsset(); Stellar.Operation op = new Stellar.PaymentOperation.Builder(keypair, asset.Asset, "0.000001").Build(); Stellar.Transaction tx = txBuilder.AddOperation(op).Build(); tx.Sign(keypair); return(Stellar.Transaction.FromEnvelopeXdr(tx.ToEnvelopeXdr())); }
public void TestFromXdrWithMemo() { var transaction = Transaction.FromEnvelopeXdr( "AAAAACq1Ixcw1fchtF5aLTSw1zaYAYjb3WbBRd4jqYJKThB9AAAAZAA8tDoAAAALAAAAAAAAAAEAAAAZR29sZCBwYXltZW50IGZvciBzZXJ2aWNlcwAAAAAAAAEAAAAAAAAAAQAAAAARREGslec48mbJJygIwZoLvRtL6/gGL4ss2TOpnOUOhgAAAAFHT0xEAAAAACq1Ixcw1fchtF5aLTSw1zaYAYjb3WbBRd4jqYJKThB9AAAAADuaygAAAAAAAAAAAA=="); Assert.AreEqual(1, transaction.Operations.Length); Assert.IsInstanceOfType(transaction.Memo, typeof(MemoText)); var op = transaction.Operations[0]; Assert.IsNull(op.SourceAccount); Assert.IsInstanceOfType(op, typeof(PaymentOperation)); var payment = op as PaymentOperation; Assert.IsNotNull(payment); Assert.AreEqual("100", payment.Amount); var asset = payment.Asset as AssetTypeCreditAlphaNum; Assert.IsNotNull(asset); Assert.AreEqual("GOLD", asset.Code); }
public void TestBuilderTimeBounds() { // GBPMKIRA2OQW2XZZQUCQILI5TMVZ6JNRKM423BSAISDM7ZFWQ6KWEBC4 var source = KeyPair.FromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS"); var destination = KeyPair.FromAccountId("GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR"); var account = new Account(source, 2908908335136768L); var transaction = new Transaction.Builder(account) .AddOperation(new CreateAccountOperation.Builder(destination, "2000").Build()) .AddTimeBounds(new TimeBounds(42, 1337)) .AddMemo(Memo.Hash("abcdef")) .Build(); transaction.Sign(source); // Convert transaction to binary XDR and back again to make sure timebounds are correctly de/serialized. var bytes = transaction.ToEnvelopeXdrBase64().ToCharArray(); var xdrDataInputStream = new XdrDataInputStream(Convert.FromBase64CharArray(bytes, 0, bytes.Length)); var decodedTransaction = XdrTransaction.Decode(xdrDataInputStream); Assert.AreEqual(decodedTransaction.TimeBounds.MinTime.InnerValue, 42); Assert.AreEqual(decodedTransaction.TimeBounds.MaxTime.InnerValue, 1337); var transaction2 = Transaction.FromEnvelopeXdr(transaction.ToEnvelopeXdr()); Assert.AreEqual(transaction.SourceAccount.AccountId, transaction2.SourceAccount.AccountId); Assert.AreEqual(transaction.SequenceNumber, transaction2.SequenceNumber); Assert.AreEqual(transaction.Memo, transaction2.Memo); Assert.AreEqual(transaction.TimeBounds, transaction2.TimeBounds); Assert.AreEqual(transaction.Fee, transaction2.Fee); Assert.AreEqual( ((CreateAccountOperation)transaction.Operations[0]).StartingBalance, ((CreateAccountOperation)transaction2.Operations[0]).StartingBalance ); }
public abstract Task <TxSubmitModel> SubmitTransaction(stellar_dotnet_sdk.Transaction transaction);
public void SignsChallengeCorrectlyByUser() { Stellar.Transaction tx = this.GenerateSignedChallenge(_fixture.UserKeypair, _fixture.DevKeypair); Assert.True(Library.Utils.Keypair.Verify(tx, _fixture.UserKeypair)); }
public ChallengeFixture() { Stellar.Network.UseTestNetwork(); Tx = Stellar.Transaction.FromEnvelopeXdr(new Library.Auth.Challenge().Call(Keypair.SecretSeed)); }
///<summary>Checks challenge transaction signed by user on developer's side.</summary> ///<param name="developerSecret">Developer secret seed</param> ///<param name="xdr">Challenge transaction xdr</param> ///<param name="address">User public key</param> public Token(string developerSecret, string xdr, string address) { this.DeveloperSecret = developerSecret; this.Tx = Stellar.Transaction.FromEnvelopeXdr(xdr); this.InnerAddress = address; }
/// <summary> /// Submit a transaction to the network. /// /// This method will check if any of the destination accounts require a memo. Change the SkipMemoRequiredCheck /// options to change this behaviour. /// </summary> /// <param name="transaction"></param> /// <param name="options"></param> /// <returns></returns> public Task <SubmitTransactionResponse> SubmitTransaction(Transaction transaction, SubmitTransactionOptions options) { return(SubmitTransaction(transaction.ToEnvelopeXdrBase64(), options)); }