/// <summary>
        /// Build a challenge transaction you can use for Stellar Web Authentication.
        /// </summary>
        /// <param name="serverKeypair">Server signing keypair</param>
        /// <param name="clientAccountId">The client account id that needs authentication</param>
        /// <param name="homeDomain">The server home domain</param>
        /// <param name="nonce">48 bytes long cryptographic-quality random data</param>
        /// <param name="now">The datetime from which the transaction is valid</param>
        /// <param name="timeout">The transaction lifespan</param>
        /// <param name="network">The network the transaction will be submitted to</param>
        /// <returns>The challenge transaction</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        public static Transaction BuildChallengeTransaction(KeyPair serverKeypair, string clientAccountId,
                                                            string homeDomain, byte[] nonce = null, DateTimeOffset?now = null, TimeSpan?timeout = null,
                                                            Network network = null)
        {
            if (string.IsNullOrEmpty(clientAccountId))
            {
                throw new ArgumentNullException(nameof(clientAccountId));
            }

            if (StrKey.DecodeVersionByte(clientAccountId) != StrKey.VersionByte.ACCOUNT_ID)
            {
                throw new InvalidWebAuthenticationException($"{nameof(clientAccountId)} is not a valid account id");
            }
            var clientAccountKeypair = KeyPair.FromAccountId(clientAccountId);

            return(BuildChallengeTransaction(serverKeypair, clientAccountKeypair, homeDomain, nonce, now, timeout,
                                             network));
        }
예제 #2
0
 /// <summary>
 ///     Creates a new Stellar KeyPair from a strkey encoded Stellar account ID.
 /// </summary>
 /// <param name="accountId">accountId The strkey encoded Stellar account ID.</param>
 /// <returns>
 ///     <see cref="KeyPair" />
 /// </returns>
 public static KeyPair FromAccountId(string accountId)
 {
     byte[] decoded = StrKey.DecodeStellarAccountId(accountId);
     return(FromPublicKey(decoded));
 }
예제 #3
0
 /// <summary>
 ///     Creates a new Stellar KeyPair from a strkey encoded Stellar secret seed.
 /// </summary>
 /// <param name="seed">eed Char array containing strkey encoded Stellar secret seed.</param>
 /// <returns>
 ///     <see cref="KeyPair" />
 /// </returns>
 public static KeyPair FromSecretSeed(string seed)
 {
     byte[] bytes = StrKey.DecodeStellarSecretSeed(seed);
     return(FromSecretSeed(bytes));
 }