/// <summary> /// Use the wallet_propose method to generate a key pair and XRP Ledger address. /// This command only generates key and address values, and does not affect the XRP Ledger itself in any way. /// To become a funded address stored in the ledger, the address must receive a Payment transaction that provides enough XRP to meet the reserve requirement. /// </summary> public async Task <WalletProposeResponse> WalletPropose(WalletProposeRequest request, CancellationToken cancellationToken = default) { jsonBuffer.Clear(); jsonWriter.Reset(); jsonWriter.WriteStartObject(); var requestId = WriteHeader(jsonWriter, "wallet_propose"); if (request.KeyType.HasValue) { var type = request.KeyType.Value == KeyType.Secp256k1 ? "secp256k1" : "ed25519"; jsonWriter.WriteString("key_type", type); } if (request.Passphrase != null) { jsonWriter.WriteString("passphrase", request.Passphrase); } if (request.Seed != null) { jsonWriter.WriteString("seed", request.Seed); } if (request.SeedHex != null) { jsonWriter.WriteString("seed_hex", request.SeedHex); } WriteFooter(jsonWriter); jsonWriter.WriteEndObject(); jsonWriter.Flush(); var response = await SendReceiveAsync(requestId, jsonBuffer.WrittenMemory, cancellationToken); return(new WalletProposeResponse(response)); }
public Task <WalletPropose> WalletPropose(WalletProposeRequest request) { var command = JsonConvert.SerializeObject(request, serializerSettings); TaskCompletionSource <WalletPropose> task = new TaskCompletionSource <WalletPropose>(); TaskInfo taskInfo = new TaskInfo(); taskInfo.TaskId = request.Id; taskInfo.TaskCompletionResult = task; taskInfo.Type = typeof(WalletPropose); tasks.TryAdd(request.Id, taskInfo); this.SendMessage(command); return(task.Task); }
public void WalletProposeWithoutKeyType() { // Arrange var request = new WalletProposeRequest(); request.Params.Add(new WalletProposeRequestParams() { PassPhrase = "snoPBrXtMeMyMHUVTgbuqAfg1SUTb" }); // Act var response = _client.AccountInformation.WalletProposeAsync(request).Result; // Assert Assert.AreEqual(Status.Success, response.Result.Status); }
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); }
public async Task <RpcJsonResponse <WalletProposeResult> > WalletProposeAsync(WalletProposeRequest request) { return(await PostAsync <RpcJsonResponse <WalletProposeResult>, WalletProposeResult>(request)); }