public void TestFromPublicKey(string publicKey, string expected) { var bytes = new byte[33]; Base16.DecodeFromUtf8(System.Text.Encoding.UTF8.GetBytes(publicKey), bytes, out var _, out var _); var account = AccountId.FromPublicKey(bytes); Assert.Equal(expected, account.ToString()); }
public void TestSeedToAccountId(string seed, string account) { var secret = new Seed(seed); var address = new AccountId(account); secret.GetKeyPairs(out var _, out var keyPair); var publicKey = keyPair.PublicKey.GetCanoncialBytes(); Assert.Equal(address, AccountId.FromPublicKey(publicKey)); }
public async Task TestGenerate() { var api = CreateApi(); var client = new FaucetClient(); var seed = await client.Generate(); seed.GetKeyPairs(out var _, out var keyPair); var publicKey = keyPair.PublicKey; var account = AccountId.FromPublicKey(publicKey.GetCanoncialBytes()); var info = await Utils.WaitForAccount(api, account); Assert.Equal(info.AccountData.Account, account); Assert.True(info.AccountData.Balance.Drops > 0, "Balance is positive"); }
static async Task Main(string[] args) { // Create the network client var address = new Uri("https://s.altnet.rippletest.net:51234"); var httpClient = new HttpClient(); httpClient.BaseAddress = address; var xrplClient = new JsonRpcApi(httpClient); // Create a wallet using the testnet faucet var faucetClient = new FaucetClient(); var testSeed = await faucetClient.Generate(); Console.WriteLine(testSeed); // Create an account string from the wallet // N.B rootKeyPair will be null for ED25519 keys testSeed.GetKeyPairs(out var rootKeyPair, out var keyPair); var accountId = AccountId.FromPublicKey(keyPair.PublicKey.GetCanoncialBytes()); Console.WriteLine(accountId); // Look up info about your account, need to do this in a loop because it will take some time for the account to actually be present in a validated ledger while (true) { var infoRequest = new AccountInfoRequest() { Account = accountId, Ledger = LedgerSpecification.Validated }; try { var infoResponse = await xrplClient.AccountInfo(infoRequest); Console.WriteLine("Balance: {0}", infoResponse.AccountData.Balance); break; } catch (RippleRequestException exc) { if (exc.Error == "actNotFound") { continue; } throw; } } }
public async void TestWalletPropose_NoEntropy(KeyType?keyType) { var request = new WalletProposeRequest { KeyType = keyType, }; var response = await Api.WalletPropose(request); Assert.Equal(keyType == KeyType.Ed25519 ? "ed25519" : "secp256k1", response.KeyType); Assert.NotNull(response.AccountId); Assert.NotNull(response.PublicKey); Assert.NotNull(response.MasterSeed); var masterEntropy = Base16.Decode(response.MasterSeedHex); var masterSeed = new Seed(masterEntropy, keyType ?? KeyType.Secp256k1); masterSeed.GetKeyPairs(out _, out var keyPair); var publicKey = keyPair.PublicKey.GetCanoncialBytes(); Assert.Equal(response.PublicKeyHex, Base16.Encode(publicKey)); var accountId = AccountId.FromPublicKey(publicKey); Assert.Equal(response.AccountId, accountId.ToString()); var buffer = new byte[publicKey.Length + 1]; buffer[0] = 35; publicKey.CopyTo(buffer, 1); var base58PublicKey = Base58Check.ConvertTo(buffer); Assert.Equal(base58PublicKey, response.PublicKey); // The hex is a 256 bit little endian number, so reverse the bits for RFC1751 encoding Array.Reverse(masterEntropy); var masterKey = Rfc1751.Encode(masterEntropy); Assert.Equal(masterKey, response.MasterKey); }