///<param name="account">Stellar AccountResponse instance</param> ///<param name="keypair">Account keypair</param> public Account(StellarResponses.AccountResponse account, Stellar.KeyPair keypair) { this.InnerAccount = account; this.InnerKeyPair = keypair; this.AssetIssuers = new Dictionary <string, string>(); this.ClientInstance = new Client().HorizonClient; }
///<summary>Private: Returns user keypair or keypair from a public key</summary> ///<returns>keypair object of user being authorized</returns> private Stellar.KeyPair GetTheirKeypair() { this.TheirKeypair = this.TheirKeypair != null ? this.TheirKeypair : Stellar.KeyPair.FromAccountId(this.InnerAddress); return(this.TheirKeypair); }
public void TransactionIsCorrectlySigned() { Stellar.KeyPair keypair = Stellar.KeyPair.Random(); Stellar.Transaction tx = this.GenerateSignedTransaction(keypair).Result; Assert.True(Library.Utils.Keypair.Verify(tx, keypair)); }
private Stellar.Transaction GenerateSignedChallenge(Stellar.KeyPair UserKeypair, Stellar.KeyPair DevKeypair) { string challengeXdr = new Library.Auth.Challenge().Call(DevKeypair.SecretSeed); string signedXdr = new Library.Auth.Sign().Call(UserKeypair.SeedBytes, challengeXdr, DevKeypair.PublicKey); return(Stellar.Transaction.FromEnvelopeXdr(signedXdr)); }
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)); }
///<summary>Get account information from Stellar network and returns an instance of Account</summary> ///<returns>Promise returns Blockchain.Accont instance</returns> async public static Task <Account> Build(Stellar.KeyPair keypair) { Client client = new Client(); var account = await client.HorizonClient.Accounts.Account(keypair); return(new Account(account, keypair)); }
///<summary>Private: App payment operation</summary> ///<param name="amount">Payment amount</param> ///<param name="destination">Receiver keypair</param> ///<returns>Promise returns payment operation</returns> async private Task <Stellar.Operation> AppPaymentOp(decimal amount, Stellar.KeyPair destination) { var asset = await new Client().StellarAsset(); return(new Stellar.PaymentOperation .Builder(destination, asset.Asset, amount.ToString()) .SetSourceAccount(AppKeypair()) .Build()); }
///<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); }
///<summary>Add a cosigner to a given account.</summary> ///<param name="keypair">Account keypair</param> ///<param name="cosignerKeypair">Cosigner keypair</param> ///<param name="weight">Cosigner weight = 1 (default)</param> ///<returns>Returns submitted transaction response</returns> public StellarResponses.SubmitTransactionResponse Call( Stellar.KeyPair keypair, Stellar.xdr.SignerKey cosignerKeypair, int weight = 1 ) { var client = new Client().HorizonClient; var account = new Stellar.Account(keypair, null); // null sequnece number for now var tx = this.Tx(account, cosignerKeypair, weight); tx.Sign(account.KeyPair); return(client.SubmitTransaction(tx).Result); }
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())); }
///<summary>Creates unlimited trustline for given asset.</summary> ///<param name="keypair">Account keypair</para> ///<param name="asset">(optional) - default to Client.StellarAsset()</param> ///<returns>Promise returns submitted transaction response.</returns> async public Task <StellarResponses.SubmitTransactionResponse> Call(Stellar.KeyPair keypair, StellarResponses.AssetResponse asset = null) { Client client = new Client(); if (asset == null) { asset = await client.StellarAsset(); } var account = await AccountBuilder.Build(keypair); var _account = client.GetStellarAccount(account); var tx = this.Tx(_account, asset.Asset); tx.Sign(account.KeyPair().PrivateKey); return(await client.HorizonClient.SubmitTransaction(tx)); }
public static LedgerKey Trustline(KeyPair account, Asset asset) => new LedgerKeyTrustline(account, asset);
///<summary>Private: Returns keypair or keypair from a secret seed</summary> ///<returns>keypair object for given Developer private key</returns> private Stellar.KeyPair GetKeypair() { this.Keypair = this.Keypair != null ? this.Keypair : Stellar.KeyPair.FromSecretSeed(this.DeveloperSecret); return(this.Keypair); }
public static LedgerKey Account(KeyPair account) => new LedgerKeyAccount(account);
/// <summary> /// Sets the source account for this operation. /// </summary> /// <param name="account">The operation's source account.</param> /// <returns>Builder object so you can chain methods.</returns> public Builder SetSourceAccount(KeyPair account) { _sourceAccount = account; return(this); }
///<summary> /// Class constructor. /// </summary> /// <param name="keypair">KeyPair associated with this Account</param> /// <param name="sequenceNumber">Current sequence number of the account (can be obtained using dotnet-stellar-sdk or horizon server)</param> public Account(KeyPair keypair, long?sequenceNumber) { KeyPair = keypair ?? throw new ArgumentNullException(nameof(keypair), "keypair cannot be null"); SequenceNumber = sequenceNumber ?? throw new ArgumentNullException(nameof(sequenceNumber), "sequenceNumber cannot be null"); }
/// <summary> /// Sets the source account for this operation. /// </summary> /// <param name="sourceAccount">The operation's source account.</param> /// <returns>Builder object so you can chain methods.</returns> public Builder SetSourceAccount(KeyPair sourceAccount) { this.sourceAccount = sourceAccount; return(this); }
public static LedgerKey Data(KeyPair account, string dataName) => new LedgerKeyData(account, dataName);
///<param name="toKeypair">Keypair to check</param> ///<returns>Returns true if given keypair is added as cosigner to current account.</returns> public Boolean Authorized(Stellar.KeyPair toKeypair) { var signer = this.FindSigner(toKeypair.AccountId); return(signer != null ? true : false); }
private PaymentOperation(KeyPair destination, Asset asset, string amount) { Destination = destination ?? throw new ArgumentNullException(nameof(destination), "destination cannot be null"); Asset = asset ?? throw new ArgumentNullException(nameof(asset), "asset cannot be null"); Amount = amount ?? throw new ArgumentNullException(nameof(amount), "amount cannot be null"); }
///<summary> /// Construct a new PaymentOperation builder from a PaymentOp XDR. ///</summary> ///<param name="op"><see cref="PaymentOp"/></param> public Builder(PaymentOp op) { destination = KeyPair.FromXdrPublicKey(op.Destination.InnerValue); asset = Asset.FromXdr(op.Asset); amount = FromXdrAmount(op.Amount.InnerValue); }
///<summary> /// Creates a new PaymentOperation builder. ///</summary> ///<param name="destination">The destination keypair (uses only the public key).</param> ///<param name="asset">The asset to send.</param> ///<param name="amount">The amount to send in lumens.</param> public Builder(KeyPair destination, Asset asset, string amount) { this.destination = destination; this.asset = asset; this.amount = amount; }
///<summary>Fund keypair and get response</summary> ///<param name="keypair">Keypair of account to fund</param> ///<returns>Promise returns response of funded account</returns> public static StellarRequests.FriendBotRequestBuilder Call(Stellar.KeyPair keypair) { return(new Client().HorizonClient.TestNetFriendBot.FundAccount(keypair)); }
public static LedgerKey Offer(KeyPair seller, long offerId) => new LedgerKeyOffer(seller, offerId);
private BeginSponsoringFutureReservesOperation(KeyPair sponsoredId) { SponsoredId = sponsoredId ?? throw new ArgumentNullException(nameof(sponsoredId)); }
/// <summary> /// Construct a new BeginSponsoringFutureReserves builder from a BeginSponsoringFutureReservesOp XDR. /// </summary> /// <param name="beginSponsoringFutureReservesOp"></param> public Builder(BeginSponsoringFutureReservesOp beginSponsoringFutureReservesOp) { _sponsoredId = KeyPair.FromXdrPublicKey(beginSponsoringFutureReservesOp.SponsoredID.InnerValue); }
/// <summary> /// Create a new BeginSponsoringFutureReserves builder with the given sponsoredId. /// </summary> /// <param name="sponsoredId"></param> public Builder(KeyPair sponsoredId) { _sponsoredId = sponsoredId ?? throw new ArgumentNullException(nameof(sponsoredId)); }
/// <summary> /// Sets the inflation destination for the account. /// </summary> /// <param name="inflationDestination">The inflation destination account.</param> /// <returns>Builder object so you can chain methods.</returns> public Builder SetInflationDestination(KeyPair inflationDestination) { this.inflationDestination = inflationDestination; return(this); }
/// <summary> /// Set source account of this operation /// </summary> /// <returns>Builder object so you can chain methods.</returns> public Builder SetSourceAccount(KeyPair sourceAccount) { _SourceAccount = sourceAccount ?? throw new ArgumentNullException(nameof(sourceAccount), "sourceAccount cannot be null"); return(this); }