rippled
Loading...
Searching...
No Matches
KeyGeneration_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2015 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <test/jtx/TestSuite.h>
21
22#include <xrpld/rpc/detail/RPCHelpers.h>
23#include <xrpld/rpc/handlers/WalletPropose.h>
24
25#include <xrpl/json/json_value.h>
26#include <xrpl/json/json_writer.h>
27#include <xrpl/protocol/ErrorCodes.h>
28#include <xrpl/protocol/jss.h>
29
30namespace ripple {
31
32namespace RPC {
33
35{
36 char const* account_id;
37 char const* master_key;
38 char const* master_seed;
39 char const* master_seed_hex;
40 char const* public_key;
41 char const* public_key_hex;
42 char const* secret_key_hex;
43 char const* passphrase;
44 char const* passphrase_warning;
45};
46
47namespace common {
48static char const* passphrase = "REINDEER FLOTILLA";
49static char const* master_key =
50 "SCAT BERN ISLE FOR ROIL BUS SOAK AQUA FREE FOR DRAM BRIG";
51static char const* master_seed = "snMwVWs2hZzfDUF3p2tHZ3EgmyhFs";
52static char const* master_seed_hex = "BE6A670A19B209E112146D0A7ED2AAD7";
53} // namespace common
54
56 "r4Vtj2jrfmTVZGfSP3gH9hQPMqFPQFin8f",
60 "aBQxK2YFNqzmAaXNczYcjqDjfiKkLsJUizsr1UBf44RCF8FHdrmX",
61 "038AAE247B2344B1837FBED8F57389C8C11774510A3F7D784F2A09F0CB6843236C",
62 "1949ECD889EA71324BC7A30C8E81F4E93CB73EE19D59E9082111E78CC3DDABC2",
64 "This wallet was generated using a user-supplied "
65 "passphrase that has low entropy and is vulnerable "
66 "to brute-force attacks.",
67};
68
70 "r4qV6xTXerqaZav3MJfSY79ynmc1BSBev1",
74 "aKEQmgLMyZPMruJFejUuedp169LgW6DbJt1rej1DJ5hWUMH4pHJ7",
75 "ED54C3F5BEDA8BD588B203D23A27398FAD9D20F88A974007D6994659CD7273FE1D",
76 "77AAED2698D56D6676323629160F4EEF21CFD9EE3D0745CC78FA291461F98278",
78 "This wallet was generated using a user-supplied "
79 "passphrase that has low entropy and is vulnerable "
80 "to brute-force attacks.",
81};
82
84 "rBcvXmNb7KPkNdMkpckdWPpbvkWgcV3nir",
85 "TED AVON CAVE HOUR BRAG JEFF RIFT NEAL TOLD FAT SEW SAN",
86 "shKdhWka8hS7Es3bpctCZXBiAwfUN",
87 "74BA8389B44F98CF41E795CD91F9C93F",
88 "aBRL2sqVuzrsM6zikPB4v8UBHGn1aKkrsxhYEffhcQxB2LKyywE5",
89 "03BD334FB9E06C58D69603E9922686528B18A754BC2F2E1ADA095FFE67DE952C64",
90 "84262FB16AA25BE407174C7EDAB531220C30FA4D8A28AA9D564673FB3D34502C",
91 "A4yKIRGdzrw0YQ$2%TFKYG9HP*&ok^!sy7E@RwICs",
92 "This wallet was generated using a user-supplied "
93 "passphrase. It may be vulnerable to brute-force "
94 "attacks.",
95};
96
98{
99public:
100 void
102 {
103 Json::Value params;
104 if (keyType)
105 params[jss::key_type] = *keyType;
106 Json::Value result = walletPropose(params);
107
108 BEAST_EXPECT(!contains_error(result));
109 BEAST_EXPECT(result.isMember(jss::account_id));
110 BEAST_EXPECT(result.isMember(jss::master_seed));
111 BEAST_EXPECT(result.isMember(jss::master_seed_hex));
112 BEAST_EXPECT(result.isMember(jss::public_key));
113 BEAST_EXPECT(result.isMember(jss::public_key_hex));
114 BEAST_EXPECT(result.isMember(jss::key_type));
115
117 result[jss::key_type],
118 params.isMember(jss::key_type) ? params[jss::key_type]
119 : "secp256k1");
120 BEAST_EXPECT(!result.isMember(jss::warning));
121
122 std::string seed = result[jss::master_seed].asString();
123
124 result = walletPropose(params);
125
126 // We asked for two random seeds, so they shouldn't match.
127 BEAST_EXPECT(result[jss::master_seed].asString() != seed);
128 }
129
131 testSecretWallet(Json::Value const& params, key_strings const& s)
132 {
133 Json::Value result = walletPropose(params);
134
135 BEAST_EXPECT(!contains_error(result));
136 expectEquals(result[jss::account_id], s.account_id);
137 expectEquals(result[jss::master_seed], s.master_seed);
138 expectEquals(result[jss::master_seed_hex], s.master_seed_hex);
139 expectEquals(result[jss::public_key], s.public_key);
140 expectEquals(result[jss::public_key_hex], s.public_key_hex);
142 result[jss::key_type],
143 params.isMember(jss::key_type) ? params[jss::key_type]
144 : "secp256k1");
145 return result;
146 }
147
148 void
150 std::optional<std::string> const& keyType,
151 key_strings const& strings)
152 {
153 testcase("seed");
154
155 Json::Value params;
156 if (keyType)
157 params[jss::key_type] = *keyType;
158 params[jss::seed] = strings.master_seed;
159
160 auto const wallet = testSecretWallet(params, strings);
161 BEAST_EXPECT(!wallet.isMember(jss::warning));
162 }
163
164 void
166 std::optional<std::string> const& keyType,
167 key_strings const& strings)
168 {
169 testcase("seed_hex");
170
171 Json::Value params;
172 if (keyType)
173 params[jss::key_type] = *keyType;
174 params[jss::seed_hex] = strings.master_seed_hex;
175
176 auto const wallet = testSecretWallet(params, strings);
177 BEAST_EXPECT(!wallet.isMember(jss::warning));
178 }
179
180 void
182 char const* value,
183 std::optional<std::string> const& keyType,
184 key_strings const& strings)
185 {
186 Json::Value params;
187 if (keyType)
188 params[jss::key_type] = *keyType;
189 params[jss::passphrase] = value;
190
191 auto const wallet = testSecretWallet(params, strings);
192 if (value == strings.passphrase)
193 BEAST_EXPECT(wallet[jss::warning] == strings.passphrase_warning);
194 else
195 BEAST_EXPECT(!wallet.isMember(jss::warning));
196 }
197
198 void
200 std::optional<std::string> const& keyType,
201 key_strings const& strings)
202 {
203 testcase("passphrase");
204
205 testLegacyPassphrase(strings.passphrase, keyType, strings);
206 testLegacyPassphrase(strings.master_key, keyType, strings);
207 testLegacyPassphrase(strings.master_seed, keyType, strings);
208 testLegacyPassphrase(strings.master_seed_hex, keyType, strings);
209 }
210
211 void
213 std::optional<std::string> const& keyType,
214 key_strings const& strings)
215 {
216 testcase(keyType ? *keyType : "no key_type");
217
218 testRandomWallet(keyType);
219 testSeed(keyType, strings);
220 testSeedHex(keyType, strings);
221 testLegacyPassphrase(keyType, strings);
222
223 Json::Value params;
224 if (keyType)
225 params[jss::key_type] = *keyType;
226 params[jss::seed] = strings.master_seed;
227 params[jss::seed_hex] = strings.master_seed_hex;
228
229 // Secret fields are mutually exclusive.
230 BEAST_EXPECT(contains_error(walletPropose(params)));
231 }
232
233 void
235 {
236 testcase("Bad inputs");
237
238 // Passing non-strings where strings are required
239 {
240 Json::Value params;
241 params[jss::key_type] = "secp256k1";
242 params[jss::passphrase] = 20160506;
243 auto result = walletPropose(params);
244 BEAST_EXPECT(contains_error(result));
245 BEAST_EXPECT(
246 result[jss::error_message] ==
247 "Invalid field 'passphrase', not string.");
248 }
249
250 {
251 Json::Value params;
252 params[jss::key_type] = "secp256k1";
253 params[jss::seed] = Json::objectValue;
254 auto result = walletPropose(params);
255 BEAST_EXPECT(contains_error(result));
256 BEAST_EXPECT(
257 result[jss::error_message] ==
258 "Invalid field 'seed', not string.");
259 }
260
261 {
262 Json::Value params;
263 params[jss::key_type] = "ed25519";
264 params[jss::seed_hex] = Json::arrayValue;
265 auto result = walletPropose(params);
266 BEAST_EXPECT(contains_error(result));
267 BEAST_EXPECT(
268 result[jss::error_message] ==
269 "Invalid field 'seed_hex', not string.");
270 }
271
272 // Specifying multiple items at once
273 {
274 Json::Value params;
275 params[jss::key_type] = "secp256k1";
276 params[jss::passphrase] = common::master_key;
277 params[jss::seed_hex] = common::master_seed_hex;
278 params[jss::seed] = common::master_seed;
279 auto result = walletPropose(params);
280 BEAST_EXPECT(contains_error(result));
281 BEAST_EXPECT(
282 result[jss::error_message] ==
283 "Exactly one of the following must be specified: passphrase, "
284 "seed or seed_hex");
285 }
286
287 // Specifying bad key types:
288 {
289 Json::Value params;
290 params[jss::key_type] = "prime256v1";
291 params[jss::passphrase] = common::master_key;
292 auto result = walletPropose(params);
293 BEAST_EXPECT(contains_error(result));
294 BEAST_EXPECT(result[jss::error_message] == "Invalid parameters.");
295 }
296
297 {
298 Json::Value params;
299 params[jss::key_type] = Json::objectValue;
300 params[jss::seed_hex] = common::master_seed_hex;
301 auto result = walletPropose(params);
302 BEAST_EXPECT(contains_error(result));
303 BEAST_EXPECT(
304 result[jss::error_message] ==
305 "Invalid field 'key_type', not string.");
306 }
307
308 {
309 Json::Value params;
310 params[jss::key_type] = Json::arrayValue;
311 params[jss::seed] = common::master_seed;
312 auto result = walletPropose(params);
313 BEAST_EXPECT(contains_error(result));
314 BEAST_EXPECT(
315 result[jss::error_message] ==
316 "Invalid field 'key_type', not string.");
317 }
318 }
319
320 void
323 key_strings const& strings)
324 {
325 testcase(
326 "keypairForSignature - " + (keyType ? *keyType : "no key_type"));
327
328 auto const publicKey = parseBase58<PublicKey>(
330 BEAST_EXPECT(publicKey);
331
332 if (!keyType)
333 {
334 {
335 Json::Value params;
336 Json::Value error;
337 params[jss::secret] = strings.master_seed;
338
339 auto ret = keypairForSignature(params, error);
340 BEAST_EXPECT(!contains_error(error));
341 if (BEAST_EXPECT(ret))
342 {
343 BEAST_EXPECT(ret->first.size() != 0);
344 BEAST_EXPECT(ret->first == publicKey);
345 }
346 }
347
348 {
349 Json::Value params;
350 Json::Value error;
351 params[jss::secret] = strings.master_seed_hex;
352
353 auto ret = keypairForSignature(params, error);
354 BEAST_EXPECT(!contains_error(error));
355 if (BEAST_EXPECT(ret))
356 {
357 BEAST_EXPECT(ret->first.size() != 0);
358 BEAST_EXPECT(ret->first == publicKey);
359 }
360 }
361
362 {
363 Json::Value params;
364 Json::Value error;
365 params[jss::secret] = strings.master_key;
366
367 auto ret = keypairForSignature(params, error);
368 BEAST_EXPECT(!contains_error(error));
369 if (BEAST_EXPECT(ret))
370 {
371 BEAST_EXPECT(ret->first.size() != 0);
372 BEAST_EXPECT(ret->first == publicKey);
373 }
374 }
375
376 keyType.emplace("secp256k1");
377 }
378
379 {
380 Json::Value params;
381 Json::Value error;
382
383 params[jss::key_type] = *keyType;
384 params[jss::seed] = strings.master_seed;
385
386 auto ret = keypairForSignature(params, error);
387 BEAST_EXPECT(!contains_error(error));
388 if (BEAST_EXPECT(ret))
389 {
390 BEAST_EXPECT(ret->first.size() != 0);
391 BEAST_EXPECT(ret->first == publicKey);
392 }
393 }
394
395 {
396 Json::Value params;
397 Json::Value error;
398
399 params[jss::key_type] = *keyType;
400 params[jss::seed_hex] = strings.master_seed_hex;
401
402 auto ret = keypairForSignature(params, error);
403 BEAST_EXPECT(!contains_error(error));
404 if (BEAST_EXPECT(ret))
405 {
406 BEAST_EXPECT(ret->first.size() != 0);
407 BEAST_EXPECT(ret->first == publicKey);
408 }
409 }
410
411 {
412 Json::Value params;
413 Json::Value error;
414
415 params[jss::key_type] = *keyType;
416 params[jss::passphrase] = strings.master_key;
417
418 auto ret = keypairForSignature(params, error);
419 BEAST_EXPECT(!contains_error(error));
420 if (BEAST_EXPECT(ret))
421 {
422 BEAST_EXPECT(ret->first.size() != 0);
423 BEAST_EXPECT(ret->first == publicKey);
424 }
425 }
426 }
427
428 void
430 {
431 // Specify invalid "secret"
432 {
433 Json::Value params;
434 Json::Value error;
435 params[jss::secret] = 314159265;
436 auto ret = keypairForSignature(params, error);
437 BEAST_EXPECT(contains_error(error));
438 BEAST_EXPECT(!ret);
439 BEAST_EXPECT(
440 error[jss::error_message] ==
441 "Invalid field 'secret', not string.");
442 }
443
444 {
445 Json::Value params;
446 Json::Value error;
447 params[jss::secret] = Json::arrayValue;
448 params[jss::secret].append("array:0");
449
450 auto ret = keypairForSignature(params, error);
451 BEAST_EXPECT(contains_error(error));
452 BEAST_EXPECT(!ret);
453 BEAST_EXPECT(
454 error[jss::error_message] ==
455 "Invalid field 'secret', not string.");
456 }
457
458 {
459 Json::Value params;
460 Json::Value error;
461 params[jss::secret] = Json::objectValue;
462 params[jss::secret]["string"] = "string";
463 params[jss::secret]["number"] = 702;
464
465 auto ret = keypairForSignature(params, error);
466 BEAST_EXPECT(contains_error(error));
467 BEAST_EXPECT(!ret);
468 BEAST_EXPECT(
469 error[jss::error_message] ==
470 "Invalid field 'secret', not string.");
471 }
472
473 // Specify "secret" and "key_type"
474 {
475 Json::Value params;
476 Json::Value error;
477 params[jss::key_type] = "ed25519";
478 params[jss::secret] = common::master_seed;
479
480 auto ret = keypairForSignature(params, error);
481 BEAST_EXPECT(contains_error(error));
482 BEAST_EXPECT(!ret);
483 BEAST_EXPECT(
484 error[jss::error_message] ==
485 "The secret field is not allowed if key_type is used.");
486 }
487
488 // Specify unknown or bad "key_type"
489 {
490 Json::Value params;
491 Json::Value error;
492 params[jss::key_type] = "prime256v1";
493 params[jss::passphrase] = common::master_key;
494
495 auto ret = keypairForSignature(params, error);
496 BEAST_EXPECT(contains_error(error));
497 BEAST_EXPECT(!ret);
498 BEAST_EXPECT(
499 error[jss::error_message] == "Invalid field 'key_type'.");
500 }
501
502 {
503 Json::Value params;
504 Json::Value error;
505 params[jss::key_type] = Json::objectValue;
506 params[jss::seed_hex] = common::master_seed_hex;
507
508 auto ret = keypairForSignature(params, error);
509 BEAST_EXPECT(contains_error(error));
510 BEAST_EXPECT(!ret);
511 BEAST_EXPECT(
512 error[jss::error_message] ==
513 "Invalid field 'key_type', not string.");
514 }
515
516 {
517 Json::Value params;
518 Json::Value error;
519 params[jss::key_type] = Json::arrayValue;
520 params[jss::seed] = common::master_seed;
521
522 auto ret = keypairForSignature(params, error);
523 BEAST_EXPECT(contains_error(error));
524 BEAST_EXPECT(!ret);
525 BEAST_EXPECT(
526 error[jss::error_message] ==
527 "Invalid field 'key_type', not string.");
528 }
529
530 // Specify non-string passphrase
531 { // not a passphrase: number
532 Json::Value params;
533 Json::Value error;
534 params[jss::key_type] = "secp256k1";
535 params[jss::passphrase] = 1234567890;
536
537 auto ret = keypairForSignature(params, error);
538 BEAST_EXPECT(contains_error(error));
539 BEAST_EXPECT(!ret);
540 BEAST_EXPECT(
541 error[jss::error_message] ==
542 "Invalid field 'passphrase', not string.");
543 }
544
545 { // not a passphrase: object
546 Json::Value params;
547 Json::Value error;
548 params[jss::key_type] = "secp256k1";
549 params[jss::passphrase] = Json::objectValue;
550
551 auto ret = keypairForSignature(params, error);
552 BEAST_EXPECT(contains_error(error));
553 BEAST_EXPECT(!ret);
554 BEAST_EXPECT(
555 error[jss::error_message] ==
556 "Invalid field 'passphrase', not string.");
557 }
558
559 { // not a passphrase: array
560 Json::Value params;
561 Json::Value error;
562 params[jss::key_type] = "secp256k1";
563 params[jss::passphrase] = Json::arrayValue;
564
565 auto ret = keypairForSignature(params, error);
566 BEAST_EXPECT(contains_error(error));
567 BEAST_EXPECT(!ret);
568 BEAST_EXPECT(
569 error[jss::error_message] ==
570 "Invalid field 'passphrase', not string.");
571 }
572
573 { // not a passphrase: empty string
574 Json::Value params;
575 Json::Value error;
576 params[jss::key_type] = "secp256k1";
577 params[jss::passphrase] = "";
578
579 auto ret = keypairForSignature(params, error);
580 BEAST_EXPECT(contains_error(error));
581 BEAST_EXPECT(!ret);
582 BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
583 }
584
585 // Specify non-string or invalid seed
586 { // not a seed: number
587 Json::Value params;
588 Json::Value error;
589 params[jss::key_type] = "secp256k1";
590 params[jss::seed] = 443556;
591
592 auto ret = keypairForSignature(params, error);
593 BEAST_EXPECT(contains_error(error));
594 BEAST_EXPECT(!ret);
595 BEAST_EXPECT(
596 error[jss::error_message] ==
597 "Invalid field 'seed', not string.");
598 }
599
600 { // not a string: object
601 Json::Value params;
602 Json::Value error;
603 params[jss::key_type] = "secp256k1";
604 params[jss::seed] = Json::objectValue;
605
606 auto ret = keypairForSignature(params, error);
607 BEAST_EXPECT(contains_error(error));
608 BEAST_EXPECT(!ret);
609 BEAST_EXPECT(
610 error[jss::error_message] ==
611 "Invalid field 'seed', not string.");
612 }
613
614 { // not a string: array
615 Json::Value params;
616 Json::Value error;
617 params[jss::key_type] = "secp256k1";
618 params[jss::seed] = Json::arrayValue;
619
620 auto ret = keypairForSignature(params, error);
621 BEAST_EXPECT(contains_error(error));
622 BEAST_EXPECT(!ret);
623 BEAST_EXPECT(
624 error[jss::error_message] ==
625 "Invalid field 'seed', not string.");
626 }
627
628 { // not a seed: empty
629 Json::Value params;
630 Json::Value error;
631 params[jss::key_type] = "secp256k1";
632 params[jss::seed] = "";
633
634 auto ret = keypairForSignature(params, error);
635 BEAST_EXPECT(contains_error(error));
636 BEAST_EXPECT(!ret);
637 BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
638 }
639
640 { // not a seed: invalid characters
641 Json::Value params;
642 Json::Value error;
643 params[jss::key_type] = "secp256k1";
644 params[jss::seed] = "s M V s h z D F p t Z E m h s";
645
646 auto ret = keypairForSignature(params, error);
647 BEAST_EXPECT(contains_error(error));
648 BEAST_EXPECT(!ret);
649 BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
650 }
651
652 { // not a seed: random string
653 Json::Value params;
654 Json::Value error;
655 params[jss::key_type] = "secp256k1";
656 params[jss::seed] = "pnnjkbnobnml43679nbvjdsklnbjs";
657
658 auto ret = keypairForSignature(params, error);
659 BEAST_EXPECT(contains_error(error));
660 BEAST_EXPECT(!ret);
661 BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
662 }
663
664 // Specify non-string or invalid seed_hex
665 { // not a string: number
666 Json::Value params;
667 Json::Value error;
668 params[jss::key_type] = "secp256k1";
669 params[jss::seed_hex] = 443556;
670
671 auto ret = keypairForSignature(params, error);
672 BEAST_EXPECT(contains_error(error));
673 BEAST_EXPECT(!ret);
674 BEAST_EXPECT(
675 error[jss::error_message] ==
676 "Invalid field 'seed_hex', not string.");
677 }
678
679 { // not a string: object
680 Json::Value params;
681 Json::Value error;
682 params[jss::key_type] = "secp256k1";
683 params[jss::seed_hex] = Json::objectValue;
684
685 auto ret = keypairForSignature(params, error);
686 BEAST_EXPECT(contains_error(error));
687 BEAST_EXPECT(!ret);
688 BEAST_EXPECT(
689 error[jss::error_message] ==
690 "Invalid field 'seed_hex', not string.");
691 }
692
693 { // not a string: array
694 Json::Value params;
695 Json::Value error;
696 params[jss::key_type] = "secp256k1";
697 params[jss::seed_hex] = Json::arrayValue;
698
699 auto ret = keypairForSignature(params, error);
700 BEAST_EXPECT(contains_error(error));
701 BEAST_EXPECT(!ret);
702 BEAST_EXPECT(
703 error[jss::error_message] ==
704 "Invalid field 'seed_hex', not string.");
705 }
706
707 { // empty
708 Json::Value params;
709 Json::Value error;
710 params[jss::key_type] = "secp256k1";
711 params[jss::seed_hex] = "";
712
713 auto ret = keypairForSignature(params, error);
714 BEAST_EXPECT(contains_error(error));
715 BEAST_EXPECT(!ret);
716 BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
717 }
718
719 { // short
720 Json::Value params;
721 Json::Value error;
722 params[jss::key_type] = "secp256k1";
723 params[jss::seed_hex] = "A670A19B";
724
725 auto ret = keypairForSignature(params, error);
726 BEAST_EXPECT(contains_error(error));
727 BEAST_EXPECT(!ret);
728 BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
729 }
730
731 { // not hex
732 Json::Value params;
733 Json::Value error;
734 params[jss::key_type] = "secp256k1";
735 params[jss::seed_hex] = common::passphrase;
736
737 auto ret = keypairForSignature(params, error);
738 BEAST_EXPECT(contains_error(error));
739 BEAST_EXPECT(!ret);
740 BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
741 }
742
743 { // overlong
744 Json::Value params;
745 Json::Value error;
746 params[jss::key_type] = "secp256k1";
747 params[jss::seed_hex] =
748 "BE6A670A19B209E112146D0A7ED2AAD72567D0FC913";
749
750 auto ret = keypairForSignature(params, error);
751 BEAST_EXPECT(contains_error(error));
752 BEAST_EXPECT(!ret);
753 BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
754 }
755 }
756
757 void
759 {
760 testcase("ripple-lib encoded Ed25519 keys");
761
762 auto test = [this](char const* seed, char const* addr) {
763 {
764 Json::Value params;
765 Json::Value error;
766
767 params[jss::passphrase] = seed;
768
769 auto ret = keypairForSignature(params, error);
770
771 BEAST_EXPECT(!contains_error(error));
772 if (BEAST_EXPECT(ret))
773 {
774 BEAST_EXPECT(ret->first.size() != 0);
775 BEAST_EXPECT(toBase58(calcAccountID(ret->first)) == addr);
776 }
777 }
778
779 {
780 Json::Value params;
781 Json::Value error;
782
783 params[jss::key_type] = "secp256k1";
784 params[jss::passphrase] = seed;
785
786 auto ret = keypairForSignature(params, error);
787
788 BEAST_EXPECT(contains_error(error));
789 BEAST_EXPECT(
790 error[jss::error_message] ==
791 "Specified seed is for an Ed25519 wallet.");
792 }
793
794 {
795 Json::Value params;
796 Json::Value error;
797
798 params[jss::key_type] = "ed25519";
799 params[jss::seed] = seed;
800
801 auto ret = keypairForSignature(params, error);
802
803 BEAST_EXPECT(!contains_error(error));
804 if (BEAST_EXPECT(ret))
805 {
806 BEAST_EXPECT(ret->first.size() != 0);
807 BEAST_EXPECT(toBase58(calcAccountID(ret->first)) == addr);
808 }
809 }
810
811 {
812 Json::Value params;
813 Json::Value error;
814
815 params[jss::key_type] = "secp256k1";
816 params[jss::seed] = seed;
817
818 auto ret = keypairForSignature(params, error);
819
820 BEAST_EXPECT(contains_error(error));
821 BEAST_EXPECT(
822 error[jss::error_message] ==
823 "Specified seed is for an Ed25519 wallet.");
824 }
825 };
826
827 test(
828 "sEdVWZmeUDgQdMEFKTK9kYVX71FKB7o",
829 "r34XnDB2zS11NZ1wKJzpU1mjWExGVugTaQ");
830 test(
831 "sEd7zJoVnqg1FxB9EuaHC1AB5UPfHWz",
832 "rDw51qRrBEeMw7Na1Nh79LN7HYZDo7nZFE");
833 test(
834 "sEdSxVntbihdLyabbfttMCqsaaucVR9",
835 "rwiyBDfAYegXZyaQcN2L1vAbKRYn2wNFMq");
836 test(
837 "sEdSVwJjEXTYCztqDK4JD9WByH3otDX",
838 "rQJ4hZzNGkLQhLtKPCmu1ywEw1ai2vgUJN");
839 test(
840 "sEdV3jXjKuUoQTSr1Rb4yw8Kyn9r46U",
841 "rERRw2Pxbau4tevE61V5vZUwD7Rus5Y6vW");
842 test(
843 "sEdVeUZjuYT47Uy51FQCnzivsuWyiwB",
844 "rszewT5gRjUgWNEmnfMjvVYzJCkhvWY32i");
845 test(
846 "sEd7MHTewdw4tFYeS7rk7XT4qHiA9jH",
847 "rBB2rvnf4ztwjgNhinFXQJ91nAZjkFgR3p");
848 test(
849 "sEd7A5jFBSdWbNeKGriQvLr1thBScJh",
850 "rLAXz8Nz7aDivz7PwThsLFqaKrizepNCdA");
851 test(
852 "sEdVPU9M2uyzVNT4Yb5Dn4tUtYjbFAw",
853 "rHbHRFPCxD5fnn98TBzsQHJ7SsRq7eHkRj");
854 test(
855 "sEdVfF2zhAmS8gfMYzJ4yWBMeR4BZKc",
856 "r9PsneKHcAE7kUfiTixomM5Mnwi28tCc7h");
857 test(
858 "sEdTjRtcsQkwthDXUSLi9DHNyJcR8GW",
859 "rM4soF4XS3wZrmLurvE6ZmudG16Lk5Dur5");
860 test(
861 "sEdVNKeu1Lhpfh7Nf6tRDbxnmMyZ4Dv",
862 "r4ZwJxq6FDtWjapDtCGhjG6mtNm1nWdJcD");
863 test(
864 "sEd7bK4gf5BHJ1WbaEWx8pKMA9MLHpC",
865 "rD6tnn51m4o1uXeEK9CFrZ3HR7DcFhiYnp");
866 test(
867 "sEd7jCh3ppnQMsLdGcZ6TZayZaHhBLg",
868 "rTcBkiRQ1EfFQ4FCCwqXNHpn1yUTAACkj");
869 test(
870 "sEdTFJezurQwSJAbkLygj2gQXBut2wh",
871 "rnXaMacNbRwcJddbbPbqdcpSUQcfzFmrR8");
872 test(
873 "sEdSWajfQAAWFuDvVZF3AiGucReByLt",
874 "rBJtow6V3GTdsWMamrxetRDwWs6wwTxcKa");
875 }
876
877 void
895};
896
897BEAST_DEFINE_TESTSUITE(WalletPropose, rpc, ripple);
898
899} // namespace RPC
900} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
Value & append(Value const &value)
Append value to array at the end.
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:155
void testLegacyPassphrase(std::optional< std::string > const &keyType, key_strings const &strings)
void run() override
Runs the suite.
void testKeypairForSignature(std::optional< std::string > keyType, key_strings const &strings)
void testLegacyPassphrase(char const *value, std::optional< std::string > const &keyType, key_strings const &strings)
void testSeedHex(std::optional< std::string > const &keyType, key_strings const &strings)
void testKeyType(std::optional< std::string > const &keyType, key_strings const &strings)
void testRandomWallet(std::optional< std::string > const &keyType)
Json::Value testSecretWallet(Json::Value const &params, key_strings const &s)
void testSeed(std::optional< std::string > const &keyType, key_strings const &strings)
bool expectEquals(S actual, T expected, std::string const &message="")
Definition TestSuite.h:34
T emplace(T... args)
T is_same_v
@ arrayValue
array value (ordered list)
Definition json_value.h:44
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:45
static char const * master_key
static char const * master_seed_hex
static char const * master_seed
static char const * passphrase
static key_strings const ed25519_strings
bool contains_error(Json::Value const &json)
Returns true if the json contains an rpc error specification.
static key_strings const strong_brain_strings
static key_strings const secp256k1_strings
std::optional< std::pair< PublicKey, SecretKey > > keypairForSignature(Json::Value const &params, Json::Value &error, unsigned int apiVersion)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
AccountID calcAccountID(PublicKey const &pk)
Json::Value walletPropose(Json::Value const &params)