1use anyhow::{Context, Result};
2use colored::Colorize;
3use ed25519_dalek::{SigningKey, VerifyingKey};
4use serde::{Deserialize, Serialize};
5use sha2::{Digest, Sha256};
6use std::fs;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Wallet {
10 pub address: String,
11 pub private_key: String,
12 pub network: String,
13 pub seed_phrase: String,
14}
15
16impl Wallet {
17 pub async fn create(network: &str) -> Result<Self> {
18 println!("{}", "Creating wallet...".cyan());
19
20 let seed_phrase = Self::generate_seed_phrase();
21 let (private_key, address) = Self::derive_keys(&seed_phrase);
22
23 let wallet = Wallet {
24 address,
25 private_key,
26 network: network.to_string(),
27 seed_phrase,
28 };
29
30 println!("{}", "✓ Wallet created successfully".green().bold());
31
32 Ok(wallet)
33 }
34
35 pub fn save_to_file(&self) -> Result<()> {
36 let mut wallets_dir = dirs::home_dir().context("Failed to determine home directory")?;
37
38 wallets_dir.push(".x402");
39 wallets_dir.push("wallets");
40
41 fs::create_dir_all(&wallets_dir)
42 .with_context(|| format!("Failed to create wallets directory"))?;
43
44 let wallet_file = wallets_dir.join(format!("{}.json", self.address));
45
46 let wallet_data =
47 serde_json::to_string_pretty(self).context("Failed to serialize wallet data")?;
48
49 fs::write(&wallet_file, wallet_data)
50 .with_context(|| format!("Failed to save wallet file: {}", wallet_file.display()))?;
51
52 let display = wallet_file.display();
53 println!(
54 "{}",
55 format!(" ✓ Wallet saved to {}", display).cyan().dimmed()
56 );
57
58 Ok(())
59 }
60
61 pub async fn fund_from_faucet(&self) -> Result<()> {
62 if self.network != "testnet" {
63 println!(
64 "{}",
65 " ℹ Skipping faucet funding (not on testnet)"
66 .yellow()
67 .dimmed()
68 );
69 return Ok(());
70 }
71
72 let faucet_url = "https://faucet.testnet.aptoslabs.com";
73
74 let client = reqwest::Client::new();
75 let request_body = serde_json::json!({
76 "address": self.address,
77 "amount": 100_000_000
78 });
79
80 let response = client
81 .post(faucet_url)
82 .header("Content-Type", "application/json")
83 .json(&request_body)
84 .send()
85 .await
86 .context("Failed to contact faucet")?;
87
88 if response.status().is_success() {
89 let _output = response.text().await.unwrap_or_default();
90 println!(
91 "{}",
92 format!(" ✓ Funded with 1 APT from faucet")
93 .green()
94 .dimmed()
95 );
96 } else {
97 let status = response.status();
98 let error = response.text().await.unwrap_or_default();
99 println!(
100 "{}",
101 format!(" ⚠ Faucet request failed: {} - {}", status, error)
102 .yellow()
103 .dimmed()
104 );
105 }
106
107 Ok(())
108 }
109
110 fn generate_seed_phrase() -> String {
111 const WORDS: &[&str] = &[
112 "abandon",
113 "ability",
114 "able",
115 "about",
116 "above",
117 "absent",
118 "absorb",
119 "abstract",
120 "absurd",
121 "abuse",
122 "access",
123 "accident",
124 "account",
125 "accuse",
126 "achieve",
127 "acid",
128 "acoustic",
129 "acquire",
130 "across",
131 "act",
132 "action",
133 "actor",
134 "actress",
135 "actual",
136 "adapt",
137 "add",
138 "addict",
139 "address",
140 "adjust",
141 "admit",
142 "adult",
143 "advance",
144 "advice",
145 "aerobic",
146 "affair",
147 "afford",
148 "afraid",
149 "again",
150 "age",
151 "agent",
152 "agree",
153 "ahead",
154 "aim",
155 "air",
156 "airport",
157 "aisle",
158 "alarm",
159 "album",
160 "alcohol",
161 "alert",
162 "alien",
163 "all",
164 "alley",
165 "allow",
166 "almost",
167 "alone",
168 "alpha",
169 "already",
170 "also",
171 "alter",
172 "always",
173 "amateur",
174 "amazing",
175 "among",
176 "amount",
177 "amused",
178 "analyst",
179 "anchor",
180 "ancient",
181 "anger",
182 "angle",
183 "angry",
184 "animal",
185 "ankle",
186 "announce",
187 "annual",
188 "another",
189 "answer",
190 "antenna",
191 "antique",
192 "anxiety",
193 "any",
194 "apart",
195 "apology",
196 "appear",
197 "apple",
198 "approve",
199 "april",
200 "arch",
201 "arctic",
202 "area",
203 "arena",
204 "argue",
205 "arm",
206 "armed",
207 "armor",
208 "army",
209 "around",
210 "arrange",
211 "arrest",
212 "arrive",
213 "arrow",
214 "art",
215 "artist",
216 "artwork",
217 "ask",
218 "aspect",
219 "assault",
220 "asset",
221 "assist",
222 "assume",
223 "asthma",
224 "athlete",
225 "atom",
226 "attack",
227 "attend",
228 "attract",
229 "auction",
230 "audit",
231 "august",
232 "aunt",
233 "author",
234 "auto",
235 "autumn",
236 "average",
237 "avocado",
238 "avoid",
239 "awake",
240 "aware",
241 "away",
242 "awesome",
243 "awful",
244 "awkward",
245 "axis",
246 "baby",
247 "bachelor",
248 "bacon",
249 "badge",
250 "bag",
251 "balance",
252 "balcony",
253 "ball",
254 "bamboo",
255 "banana",
256 "banner",
257 "bar",
258 "barely",
259 "bargain",
260 "barrel",
261 "base",
262 "basic",
263 "basket",
264 "battle",
265 "beach",
266 "bean",
267 "beauty",
268 "become",
269 "beef",
270 "before",
271 "begin",
272 "behave",
273 "behind",
274 "believe",
275 "below",
276 "belt",
277 "bench",
278 "benefit",
279 "best",
280 "betray",
281 "better",
282 "between",
283 "beyond",
284 "bicycle",
285 "bid",
286 "bike",
287 "bind",
288 "biology",
289 "bird",
290 "birth",
291 "bitter",
292 "black",
293 "blade",
294 "blame",
295 "blanket",
296 "blast",
297 "bleak",
298 "bless",
299 "blind",
300 "blood",
301 "blossom",
302 "blouse",
303 "blue",
304 "blur",
305 "blush",
306 "board",
307 "boat",
308 "body",
309 "boil",
310 "bomb",
311 "bone",
312 "bonus",
313 "book",
314 "boost",
315 "border",
316 "bored",
317 "borrow",
318 "boss",
319 "bottom",
320 "bounce",
321 "box",
322 "boy",
323 "bracket",
324 "brain",
325 "brand",
326 "brass",
327 "brave",
328 "bread",
329 "breeze",
330 "brick",
331 "bridge",
332 "brief",
333 "bright",
334 "bring",
335 "brisk",
336 "broken",
337 "bronze",
338 "broom",
339 "brother",
340 "brown",
341 "brush",
342 "bubble",
343 "buddy",
344 "budget",
345 "buffalo",
346 "build",
347 "bulb",
348 "bulk",
349 "bullet",
350 "bundle",
351 "bunker",
352 "burden",
353 "burger",
354 "burst",
355 "bus",
356 "business",
357 "busy",
358 "butter",
359 "buyer",
360 "buzz",
361 "cabbage",
362 "cabin",
363 "cable",
364 "cactus",
365 "cage",
366 "cake",
367 "call",
368 "calm",
369 "camera",
370 "camp",
371 "can",
372 "canal",
373 "cancel",
374 "candy",
375 "cannon",
376 "canoe",
377 "canvas",
378 "canyon",
379 "capable",
380 "capital",
381 "captain",
382 "car",
383 "carbon",
384 "card",
385 "cargo",
386 "carpet",
387 "carry",
388 "cart",
389 "case",
390 "cash",
391 "casino",
392 "castle",
393 "casual",
394 "cat",
395 "catalog",
396 "catch",
397 "category",
398 "cattle",
399 "caught",
400 "cause",
401 "caution",
402 "cave",
403 "ceiling",
404 "celery",
405 "cement",
406 "census",
407 "century",
408 "cereal",
409 "certain",
410 "chair",
411 "chalk",
412 "champion",
413 "change",
414 "chaos",
415 "chapter",
416 "charge",
417 "chase",
418 "chat",
419 "cheap",
420 "check",
421 "cheese",
422 "chef",
423 "cherry",
424 "chest",
425 "chicken",
426 "chief",
427 "child",
428 "chimney",
429 "choice",
430 "choose",
431 "chronic",
432 "chuckle",
433 "chunk",
434 "churn",
435 "cigar",
436 "cinnamon",
437 "circle",
438 "citizen",
439 "city",
440 "civil",
441 "claim",
442 "clap",
443 "clarify",
444 "claw",
445 "clay",
446 "clean",
447 "clerk",
448 "clever",
449 "click",
450 "client",
451 "cliff",
452 "climb",
453 "clinic",
454 "clip",
455 "clock",
456 "clog",
457 "close",
458 "cloth",
459 "cloud",
460 "clown",
461 "club",
462 "clump",
463 "cluster",
464 "clutch",
465 "coach",
466 "coast",
467 "coconut",
468 "code",
469 "coffee",
470 "coil",
471 "coin",
472 "collect",
473 "color",
474 "column",
475 "combine",
476 "come",
477 "comfort",
478 "comic",
479 "common",
480 "company",
481 "concert",
482 "conduct",
483 "confirm",
484 "congress",
485 "connect",
486 "consider",
487 "control",
488 "convince",
489 "cook",
490 "cool",
491 "copper",
492 "copy",
493 "coral",
494 "core",
495 "corn",
496 "corner",
497 "correct",
498 "cost",
499 "cotton",
500 "couch",
501 "country",
502 "couple",
503 "course",
504 "cousin",
505 "cover",
506 "coyote",
507 "crack",
508 "cradle",
509 "craft",
510 "cram",
511 "crane",
512 "crash",
513 "crater",
514 "crawl",
515 "crazy",
516 "cream",
517 "credit",
518 "creek",
519 "crew",
520 "cricket",
521 "crime",
522 "crisp",
523 "critic",
524 "crop",
525 "cross",
526 "crouch",
527 "crowd",
528 "crucial",
529 "cruel",
530 "cruise",
531 "crumble",
532 "crunch",
533 "crush",
534 "cry",
535 "crystal",
536 "cube",
537 "culture",
538 "cup",
539 "cupboard",
540 "curious",
541 "current",
542 "curtain",
543 "curve",
544 "cushion",
545 "custom",
546 "cute",
547 "cycle",
548 "dad",
549 "damage",
550 "damp",
551 "dance",
552 "danger",
553 "daring",
554 "dash",
555 "daughter",
556 "dawn",
557 "day",
558 "deal",
559 "debate",
560 "debris",
561 "decade",
562 "december",
563 "decide",
564 "decline",
565 "decorate",
566 "decrease",
567 "deer",
568 "defense",
569 "define",
570 "defy",
571 "degree",
572 "delay",
573 "deliver",
574 "demand",
575 "demise",
576 "denial",
577 "dentist",
578 "deny",
579 "depart",
580 "depend",
581 "deposit",
582 "depth",
583 "deputy",
584 "derive",
585 "describe",
586 "desert",
587 "design",
588 "desk",
589 "despair",
590 "destroy",
591 "detail",
592 "detect",
593 "develop",
594 "device",
595 "devote",
596 "diagram",
597 "dial",
598 "diamond",
599 "diary",
600 "dice",
601 "diesel",
602 "diet",
603 "differ",
604 "digital",
605 "dignity",
606 "dilemma",
607 "dinner",
608 "dinosaur",
609 "direct",
610 "dirt",
611 "disagree",
612 "discover",
613 "disease",
614 "dish",
615 "dismiss",
616 "disorder",
617 "display",
618 "distance",
619 "divert",
620 "divide",
621 "divorce",
622 "dizzy",
623 "doctor",
624 "document",
625 "dog",
626 "doll",
627 "dolphin",
628 "domain",
629 "donate",
630 "donkey",
631 "donor",
632 "door",
633 "dose",
634 "double",
635 "dove",
636 "draft",
637 "dragon",
638 "drama",
639 "draw",
640 "dream",
641 "dress",
642 "drift",
643 "drill",
644 "drink",
645 "drip",
646 "drive",
647 "drop",
648 "drum",
649 "dry",
650 "duck",
651 "dumb",
652 "dune",
653 "during",
654 "dust",
655 "dutch",
656 "duty",
657 "dwarf",
658 "dynamic",
659 "eager",
660 "eagle",
661 "early",
662 "earn",
663 "earth",
664 "easily",
665 "east",
666 "easy",
667 "echo",
668 "ecology",
669 "economy",
670 "edge",
671 "edit",
672 "educate",
673 "effort",
674 "egg",
675 "eight",
676 "elbow",
677 "elder",
678 "electric",
679 "elegant",
680 "element",
681 "elephant",
682 "elevator",
683 "elite",
684 "else",
685 "embark",
686 "embody",
687 "embrace",
688 "emerge",
689 "emotion",
690 "employ",
691 "empower",
692 "empty",
693 "enable",
694 "enact",
695 "end",
696 "endless",
697 "endorse",
698 "enemy",
699 "energy",
700 "enforce",
701 "engage",
702 "engine",
703 "enhance",
704 "enjoy",
705 "enlist",
706 "enough",
707 "enrich",
708 "enroll",
709 "ensure",
710 "enter",
711 "entire",
712 "entry",
713 "envelope",
714 "episode",
715 "equal",
716 "equip",
717 "era",
718 "erase",
719 "erode",
720 "erosion",
721 "error",
722 "erupt",
723 "escape",
724 "essay",
725 "essence",
726 "estate",
727 "eternal",
728 "ethics",
729 "evidence",
730 "evil",
731 "evoke",
732 "evolve",
733 "exact",
734 "example",
735 "excess",
736 "exchange",
737 "excite",
738 "exclude",
739 "excuse",
740 "execute",
741 "exercise",
742 "exhaust",
743 "exhibit",
744 "exile",
745 "exist",
746 "exit",
747 "exotic",
748 "expand",
749 "expect",
750 "expire",
751 "explain",
752 "expose",
753 "express",
754 "extend",
755 "extra",
756 "eye",
757 "eyebrow",
758 "fabric",
759 "face",
760 "faculty",
761 "fade",
762 "faint",
763 "faith",
764 "fall",
765 "false",
766 "fame",
767 "family",
768 "famous",
769 "fan",
770 "fancy",
771 "fantasy",
772 "farm",
773 "fashion",
774 "fat",
775 "fatal",
776 "father",
777 "fatigue",
778 "fault",
779 "favorite",
780 "feature",
781 "february",
782 "federal",
783 "fee",
784 "feed",
785 "feel",
786 "female",
787 "fence",
788 "festival",
789 "fetch",
790 "fever",
791 "few",
792 "fiber",
793 "fiction",
794 "field",
795 "figure",
796 "file",
797 "film",
798 "filter",
799 "final",
800 "find",
801 "fine",
802 "finger",
803 "finish",
804 "fire",
805 "firm",
806 "first",
807 "fiscal",
808 "fish",
809 "fit",
810 "fitness",
811 "fix",
812 "flag",
813 "flame",
814 "flash",
815 "flat",
816 "flavor",
817 "flee",
818 "flight",
819 "flip",
820 "float",
821 "flock",
822 "floor",
823 "flower",
824 "fluid",
825 "flush",
826 "fly",
827 "foam",
828 "focus",
829 "fog",
830 "foil",
831 "fold",
832 "follow",
833 "food",
834 "foot",
835 "force",
836 "forest",
837 "forget",
838 "fork",
839 "fortune",
840 "forum",
841 "forward",
842 "fossil",
843 "foster",
844 "found",
845 "fox",
846 "fragile",
847 "frame",
848 "frequent",
849 "fresh",
850 "friend",
851 "fringe",
852 "frog",
853 "front",
854 "frost",
855 "frown",
856 "frozen",
857 "fruit",
858 "fuel",
859 "fun",
860 "funny",
861 "furnace",
862 "fury",
863 "future",
864 "gadget",
865 "gain",
866 "galaxy",
867 "gallery",
868 "game",
869 "gap",
870 "garage",
871 "garbage",
872 "garden",
873 "garlic",
874 "garment",
875 "gas",
876 "gasp",
877 "gate",
878 "gather",
879 "gauge",
880 "gaze",
881 "general",
882 "genius",
883 "genre",
884 "gentle",
885 "genuine",
886 "gesture",
887 "ghost",
888 "giant",
889 "gift",
890 "giggle",
891 "ginger",
892 "giraffe",
893 "girl",
894 "give",
895 "glad",
896 "glance",
897 "glare",
898 "glass",
899 "glide",
900 "glimpse",
901 "globe",
902 "gloom",
903 "glory",
904 "glove",
905 "glow",
906 "glue",
907 "goat",
908 "goddess",
909 "gold",
910 "good",
911 "goose",
912 "gorilla",
913 "gospel",
914 "gossip",
915 "govern",
916 "gown",
917 "grab",
918 "grace",
919 "grain",
920 "grant",
921 "grape",
922 "grass",
923 "gravity",
924 "great",
925 "green",
926 "grid",
927 "grief",
928 "grit",
929 "grocery",
930 "group",
931 "grow",
932 "grunt",
933 "guard",
934 "guess",
935 "guide",
936 "guilt",
937 "guitar",
938 "gun",
939 "gym",
940 "habit",
941 "hair",
942 "half",
943 "hammer",
944 "hamster",
945 "hand",
946 "handle",
947 "harbor",
948 "hard",
949 "harsh",
950 "harvest",
951 "hat",
952 "have",
953 "hawk",
954 "hazard",
955 "head",
956 "health",
957 "heart",
958 "heavy",
959 "hedgehog",
960 "height",
961 "hello",
962 "helmet",
963 "help",
964 "hen",
965 "hero",
966 "hidden",
967 "high",
968 "hill",
969 "hint",
970 "hip",
971 "hire",
972 "history",
973 "hobby",
974 "hockey",
975 "hold",
976 "hole",
977 "holiday",
978 "hollow",
979 "home",
980 "honey",
981 "hood",
982 "hope",
983 "horn",
984 "horror",
985 "horse",
986 "hospital",
987 "host",
988 "hotel",
989 "hour",
990 "hover",
991 "hub",
992 "huge",
993 "human",
994 "humble",
995 "humor",
996 "hundred",
997 "hungry",
998 "hunt",
999 "hurdle",
1000 "hurry",
1001 "hurt",
1002 "husband",
1003 "hybrid",
1004 "ice",
1005 "icon",
1006 "idea",
1007 "identify",
1008 "idle",
1009 "ignore",
1010 "ill",
1011 "illegal",
1012 "illness",
1013 "image",
1014 "imitate",
1015 "immense",
1016 "immune",
1017 "impact",
1018 "impose",
1019 "improve",
1020 "impulse",
1021 "inch",
1022 "include",
1023 "income",
1024 "increase",
1025 "index",
1026 "indicate",
1027 "indoor",
1028 "industry",
1029 "infant",
1030 "inflict",
1031 "inform",
1032 "inhale",
1033 "inherit",
1034 "initial",
1035 "inject",
1036 "injury",
1037 "inmate",
1038 "inner",
1039 "innocent",
1040 "input",
1041 "inquiry",
1042 "insane",
1043 "insect",
1044 "inside",
1045 "inspire",
1046 "install",
1047 "intact",
1048 "interest",
1049 "into",
1050 "invest",
1051 "invite",
1052 "involve",
1053 "iron",
1054 "island",
1055 "isolate",
1056 "issue",
1057 "item",
1058 "ivory",
1059 "jacket",
1060 "jaguar",
1061 "jar",
1062 "jazz",
1063 "jealous",
1064 "jeans",
1065 "jelly",
1066 "jewel",
1067 "job",
1068 "join",
1069 "joke",
1070 "journey",
1071 "joy",
1072 "judge",
1073 "juggle",
1074 "juice",
1075 "jump",
1076 "jungle",
1077 "junior",
1078 "junk",
1079 "just",
1080 "kangaroo",
1081 "keen",
1082 "keep",
1083 "ketchup",
1084 "key",
1085 "kick",
1086 "kid",
1087 "kidney",
1088 "kind",
1089 "kingdom",
1090 "kiss",
1091 "kit",
1092 "kitchen",
1093 "kite",
1094 "kitten",
1095 "kiwi",
1096 "knee",
1097 "knife",
1098 "knock",
1099 "know",
1100 "lab",
1101 "label",
1102 "labor",
1103 "ladder",
1104 "lady",
1105 "lake",
1106 "lamp",
1107 "language",
1108 "laptop",
1109 "large",
1110 "later",
1111 "latin",
1112 "laugh",
1113 "laundry",
1114 "lava",
1115 "law",
1116 "lawn",
1117 "lawsuit",
1118 "layer",
1119 "lazy",
1120 "leader",
1121 "leaf",
1122 "learn",
1123 "leave",
1124 "lecture",
1125 "left",
1126 "leg",
1127 "legal",
1128 "legend",
1129 "leisure",
1130 "lemon",
1131 "lend",
1132 "length",
1133 "lens",
1134 "leopard",
1135 "lesson",
1136 "letter",
1137 "level",
1138 "liar",
1139 "liberty",
1140 "library",
1141 "license",
1142 "life",
1143 "lift",
1144 "light",
1145 "like",
1146 "limb",
1147 "limit",
1148 "link",
1149 "lion",
1150 "liquid",
1151 "list",
1152 "little",
1153 "live",
1154 "lizard",
1155 "load",
1156 "loan",
1157 "lobster",
1158 "local",
1159 "lock",
1160 "logic",
1161 "lonely",
1162 "long",
1163 "loop",
1164 "lottery",
1165 "loud",
1166 "lounge",
1167 "love",
1168 "loyal",
1169 "lucky",
1170 "luggage",
1171 "lumber",
1172 "lunar",
1173 "lunch",
1174 "luxury",
1175 "lyrics",
1176 "machine",
1177 "mad",
1178 "magic",
1179 "magnet",
1180 "maid",
1181 "mail",
1182 "main",
1183 "major",
1184 "make",
1185 "mammal",
1186 "man",
1187 "manage",
1188 "mandate",
1189 "mango",
1190 "mansion",
1191 "manual",
1192 "maple",
1193 "marble",
1194 "march",
1195 "margin",
1196 "marine",
1197 "market",
1198 "marriage",
1199 "mask",
1200 "mass",
1201 "master",
1202 "match",
1203 "material",
1204 "math",
1205 "matrix",
1206 "matter",
1207 "maximum",
1208 "maze",
1209 "meadow",
1210 "mean",
1211 "measure",
1212 "meat",
1213 "mechanic",
1214 "medal",
1215 "media",
1216 "melody",
1217 "melt",
1218 "member",
1219 "memory",
1220 "mention",
1221 "menu",
1222 "mercy",
1223 "merge",
1224 "merit",
1225 "merry",
1226 "mesh",
1227 "message",
1228 "metal",
1229 "method",
1230 "middle",
1231 "midnight",
1232 "milk",
1233 "million",
1234 "mimic",
1235 "mind",
1236 "minimum",
1237 "minor",
1238 "minute",
1239 "miracle",
1240 "mirror",
1241 "misery",
1242 "miss",
1243 "mistake",
1244 "mix",
1245 "mixed",
1246 "mixture",
1247 "mobile",
1248 "model",
1249 "modify",
1250 "mom",
1251 "moment",
1252 "monitor",
1253 "monkey",
1254 "monster",
1255 "month",
1256 "moon",
1257 "moral",
1258 "more",
1259 "morning",
1260 "mosquito",
1261 "mother",
1262 "motion",
1263 "motor",
1264 "mountain",
1265 "mouse",
1266 "move",
1267 "movie",
1268 "much",
1269 "muffin",
1270 "mule",
1271 "multiply",
1272 "muscle",
1273 "museum",
1274 "mushroom",
1275 "music",
1276 "must",
1277 "mutual",
1278 "myself",
1279 "mystery",
1280 "myth",
1281 "naive",
1282 "name",
1283 "napkin",
1284 "narrow",
1285 "nasty",
1286 "nation",
1287 "nature",
1288 "near",
1289 "neck",
1290 "need",
1291 "negative",
1292 "neglect",
1293 "neither",
1294 "nephew",
1295 "nerve",
1296 "nest",
1297 "net",
1298 "network",
1299 "neutral",
1300 "never",
1301 "news",
1302 "next",
1303 "nice",
1304 "night",
1305 "noble",
1306 "noise",
1307 "nominee",
1308 "noodle",
1309 "normal",
1310 "north",
1311 "nose",
1312 "notable",
1313 "note",
1314 "nothing",
1315 "notice",
1316 "novel",
1317 "now",
1318 "nuclear",
1319 "number",
1320 "nurse",
1321 "nut",
1322 "oak",
1323 "obey",
1324 "object",
1325 "oblige",
1326 "obscure",
1327 "observe",
1328 "obtain",
1329 "obvious",
1330 "occur",
1331 "ocean",
1332 "october",
1333 "odor",
1334 "off",
1335 "offer",
1336 "office",
1337 "often",
1338 "oil",
1339 "okay",
1340 "old",
1341 "olive",
1342 "olympic",
1343 "omit",
1344 "once",
1345 "one",
1346 "onion",
1347 "online",
1348 "only",
1349 "open",
1350 "opera",
1351 "opinion",
1352 "oppose",
1353 "option",
1354 "orange",
1355 "orbit",
1356 "orchard",
1357 "order",
1358 "ordinary",
1359 "organ",
1360 "orient",
1361 "original",
1362 "orphan",
1363 "ostrich",
1364 "other",
1365 "outdoor",
1366 "outer",
1367 "output",
1368 "outside",
1369 "oval",
1370 "oven",
1371 "over",
1372 "own",
1373 "owner",
1374 "oxygen",
1375 "oyster",
1376 "ozone",
1377 "pact",
1378 "paddle",
1379 "page",
1380 "pair",
1381 "palace",
1382 "palm",
1383 "panda",
1384 "panel",
1385 "panic",
1386 "panther",
1387 "paper",
1388 "parade",
1389 "parent",
1390 "park",
1391 "parrot",
1392 "party",
1393 "pass",
1394 "patch",
1395 "path",
1396 "patient",
1397 "patrol",
1398 "pattern",
1399 "pause",
1400 "pave",
1401 "payment",
1402 "peace",
1403 "peanut",
1404 "pear",
1405 "peasant",
1406 "pelican",
1407 "pen",
1408 "penalty",
1409 "pencil",
1410 "people",
1411 "pepper",
1412 "perfect",
1413 "permit",
1414 "person",
1415 "pet",
1416 "phone",
1417 "photo",
1418 "phrase",
1419 "physical",
1420 "piano",
1421 "picnic",
1422 "picture",
1423 "piece",
1424 "pig",
1425 "pigeon",
1426 "pill",
1427 "pilot",
1428 "pink",
1429 "pioneer",
1430 "pipe",
1431 "pistol",
1432 "pitch",
1433 "pizza",
1434 "place",
1435 "planet",
1436 "plastic",
1437 "plate",
1438 "play",
1439 "please",
1440 "pledge",
1441 "pluck",
1442 "plug",
1443 "plunge",
1444 "poem",
1445 "poet",
1446 "point",
1447 "polar",
1448 "pole",
1449 "police",
1450 "pond",
1451 "pony",
1452 "pool",
1453 "popular",
1454 "portion",
1455 "position",
1456 "possible",
1457 "post",
1458 "potato",
1459 "pottery",
1460 "poverty",
1461 "powder",
1462 "power",
1463 "practice",
1464 "praise",
1465 "predict",
1466 "prefer",
1467 "prepare",
1468 "present",
1469 "pretty",
1470 "prevent",
1471 "price",
1472 "pride",
1473 "primary",
1474 "print",
1475 "priority",
1476 "prison",
1477 "private",
1478 "prize",
1479 "problem",
1480 "process",
1481 "produce",
1482 "profit",
1483 "program",
1484 "project",
1485 "promote",
1486 "proof",
1487 "property",
1488 "prosper",
1489 "protect",
1490 "proud",
1491 "provide",
1492 "public",
1493 "pudding",
1494 "pull",
1495 "pulp",
1496 "pulse",
1497 "pumpkin",
1498 "punch",
1499 "pupil",
1500 "puppy",
1501 "purchase",
1502 "purity",
1503 "purpose",
1504 "purse",
1505 "push",
1506 "put",
1507 "puzzle",
1508 "pyramid",
1509 "quality",
1510 "quantum",
1511 "quarter",
1512 "question",
1513 "quick",
1514 "quit",
1515 "quiz",
1516 "quote",
1517 "rabbit",
1518 "raccoon",
1519 "race",
1520 "rack",
1521 "radar",
1522 "radio",
1523 "rail",
1524 "rain",
1525 "raise",
1526 "rally",
1527 "ramp",
1528 "ranch",
1529 "random",
1530 "range",
1531 "rapid",
1532 "rare",
1533 "rate",
1534 "rather",
1535 "raven",
1536 "raw",
1537 "reach",
1538 "react",
1539 "read",
1540 "real",
1541 "realm",
1542 "reason",
1543 "rebel",
1544 "rebuild",
1545 "receipt",
1546 "receive",
1547 "recipe",
1548 "record",
1549 "recycle",
1550 "red",
1551 "reduce",
1552 "reflect",
1553 "reform",
1554 "refuge",
1555 "refuse",
1556 "region",
1557 "regret",
1558 "regular",
1559 "reject",
1560 "relax",
1561 "release",
1562 "relief",
1563 "rely",
1564 "remain",
1565 "remember",
1566 "remind",
1567 "remote",
1568 "remove",
1569 "render",
1570 "renew",
1571 "rent",
1572 "reopen",
1573 "repair",
1574 "repeat",
1575 "replace",
1576 "reply",
1577 "report",
1578 "represent",
1579 "reptile",
1580 "require",
1581 "rescue",
1582 "resemble",
1583 "resist",
1584 "resource",
1585 "response",
1586 "result",
1587 "retire",
1588 "retreat",
1589 "return",
1590 "reunion",
1591 "reveal",
1592 "review",
1593 "reward",
1594 "rhythm",
1595 "rib",
1596 "ribbon",
1597 "rice",
1598 "rich",
1599 "ride",
1600 "ridge",
1601 "rifle",
1602 "right",
1603 "rigid",
1604 "ring",
1605 "riot",
1606 "ripple",
1607 "risk",
1608 "ritual",
1609 "rival",
1610 "river",
1611 "road",
1612 "roast",
1613 "robot",
1614 "robust",
1615 "rocket",
1616 "romance",
1617 "roof",
1618 "rookie",
1619 "room",
1620 "rose",
1621 "rotate",
1622 "rough",
1623 "round",
1624 "route",
1625 "royal",
1626 "rubber",
1627 "rude",
1628 "rug",
1629 "rule",
1630 "run",
1631 "runway",
1632 "rural",
1633 "sad",
1634 "saddle",
1635 "sadness",
1636 "safe",
1637 "sail",
1638 "salad",
1639 "salmon",
1640 "salon",
1641 "salt",
1642 "salute",
1643 "same",
1644 "sample",
1645 "sand",
1646 "satisfy",
1647 "satoshi",
1648 "sauce",
1649 "sausage",
1650 "save",
1651 "say",
1652 "scale",
1653 "scan",
1654 "scare",
1655 "scatter",
1656 "scene",
1657 "scheme",
1658 "school",
1659 "science",
1660 "scissors",
1661 "scorpion",
1662 "scout",
1663 "scrap",
1664 "screen",
1665 "script",
1666 "scrub",
1667 "sea",
1668 "search",
1669 "season",
1670 "seat",
1671 "second",
1672 "secret",
1673 "section",
1674 "security",
1675 "seed",
1676 "seek",
1677 "segment",
1678 "select",
1679 "sell",
1680 "seminar",
1681 "senior",
1682 "sense",
1683 "sentence",
1684 "series",
1685 "service",
1686 "session",
1687 "settle",
1688 "setup",
1689 "seven",
1690 "shadow",
1691 "shaft",
1692 "shallow",
1693 "share",
1694 "shed",
1695 "shell",
1696 "sheriff",
1697 "shield",
1698 "shift",
1699 "shine",
1700 "ship",
1701 "shiver",
1702 "shock",
1703 "shoe",
1704 "shoot",
1705 "shop",
1706 "short",
1707 "shoulder",
1708 "shove",
1709 "shrimp",
1710 "shrug",
1711 "shuffle",
1712 "shy",
1713 "sibling",
1714 "sick",
1715 "side",
1716 "siege",
1717 "sight",
1718 "sign",
1719 "silent",
1720 "silk",
1721 "silly",
1722 "silver",
1723 "similar",
1724 "simple",
1725 "since",
1726 "sing",
1727 "siren",
1728 "sister",
1729 "sit",
1730 "situation",
1731 "six",
1732 "size",
1733 "skate",
1734 " sketch",
1735 "ski",
1736 "skill",
1737 "skin",
1738 "skirt",
1739 "skull",
1740 "slab",
1741 "slam",
1742 "sleep",
1743 "slender",
1744 "slice",
1745 "slide",
1746 "slight",
1747 "slim",
1748 "slogan",
1749 "slot",
1750 "slow",
1751 "slush",
1752 "small",
1753 "smart",
1754 "smile",
1755 "smoke",
1756 "smooth",
1757 "snack",
1758 "snake",
1759 "snap",
1760 "sniff",
1761 "snow",
1762 "soap",
1763 "soccer",
1764 "social",
1765 "sock",
1766 "soda",
1767 "soft",
1768 "solar",
1769 "soldier",
1770 "solid",
1771 "solution",
1772 "solve",
1773 "someone",
1774 "song",
1775 "soon",
1776 "sorry",
1777 "sort",
1778 "soul",
1779 "sound",
1780 "soup",
1781 "source",
1782 "south",
1783 "space",
1784 "spare",
1785 "spatial",
1786 "spawn",
1787 "speak",
1788 "special",
1789 "speed",
1790 "spell",
1791 "spend",
1792 "sphere",
1793 "spice",
1794 "spider",
1795 "spike",
1796 "spin",
1797 "spirit",
1798 "split",
1799 "spoil",
1800 "sponsor",
1801 "spoon",
1802 "sport",
1803 "spot",
1804 "spray",
1805 "spread",
1806 "spring",
1807 "spy",
1808 "square",
1809 "squeeze",
1810 "squirrel",
1811 "stable",
1812 "stadium",
1813 "staff",
1814 "stage",
1815 "stairs",
1816 "stamp",
1817 "stand",
1818 "start",
1819 "state",
1820 "stay",
1821 "steak",
1822 "steel",
1823 "stem",
1824 "step",
1825 "stereo",
1826 "stick",
1827 "still",
1828 "sting",
1829 "stock",
1830 "stomach",
1831 "stone",
1832 "stool",
1833 "story",
1834 "stove",
1835 "strategy",
1836 "street",
1837 "strike",
1838 "strong",
1839 "struggle",
1840 "student",
1841 "stuff",
1842 "stumble",
1843 "style",
1844 "subject",
1845 "submit",
1846 "subway",
1847 "success",
1848 "such",
1849 "sudden",
1850 "suffer",
1851 "sugar",
1852 "suggest",
1853 "suit",
1854 "summer",
1855 "sun",
1856 "sunny",
1857 "sunset",
1858 "super",
1859 "supply",
1860 "supreme",
1861 "sure",
1862 "surface",
1863 "surge",
1864 "surprise",
1865 "surround",
1866 "survey",
1867 "suspect",
1868 "sustain",
1869 "swallow",
1870 "swamp",
1871 "swap",
1872 "swarm",
1873 "swear",
1874 "sweet",
1875 "swift",
1876 "swim",
1877 "swing",
1878 "switch",
1879 "sword",
1880 "symbol",
1881 "symptom",
1882 "syrup",
1883 "system",
1884 "table",
1885 "tackle",
1886 "tag",
1887 "tail",
1888 "talent",
1889 "talk",
1890 "tank",
1891 "tape",
1892 "target",
1893 "task",
1894 "taste",
1895 "tattoo",
1896 "taxi",
1897 "teach",
1898 "team",
1899 "tell",
1900 "ten",
1901 "tenant",
1902 "tennis",
1903 "tent",
1904 "term",
1905 "test",
1906 "text",
1907 "thank",
1908 "that",
1909 "theme",
1910 "then",
1911 "theory",
1912 "there",
1913 "they",
1914 "thing",
1915 "this",
1916 "thought",
1917 "three",
1918 "thrive",
1919 "throw",
1920 "thumb",
1921 "thunder",
1922 "ticket",
1923 "tide",
1924 "tiger",
1925 "tilt",
1926 "timber",
1927 "time",
1928 "tiny",
1929 "tip",
1930 "tired",
1931 "tissue",
1932 "title",
1933 "toast",
1934 "tobacco",
1935 "today",
1936 "toddler",
1937 "toe",
1938 "together",
1939 "toilet",
1940 "token",
1941 "tomato",
1942 "tomorrow",
1943 "tone",
1944 "tongue",
1945 "tonight",
1946 "tool",
1947 "tooth",
1948 "top",
1949 "topic",
1950 "topple",
1951 "torch",
1952 "tornado",
1953 "tortoise",
1954 "toss",
1955 "total",
1956 "tourist",
1957 "toward",
1958 "tower",
1959 "town",
1960 "toy",
1961 "track",
1962 "trade",
1963 "traffic",
1964 "tragic",
1965 "train",
1966 "transfer",
1967 "trap",
1968 "trash",
1969 "travel",
1970 "tray",
1971 "treat",
1972 "tree",
1973 "trend",
1974 "trial",
1975 "tribe",
1976 "trick",
1977 "trigger",
1978 "trim",
1979 "trip",
1980 "trophy",
1981 "trouble",
1982 "truck",
1983 "true",
1984 "truly",
1985 "trumpet",
1986 "trust",
1987 "truth",
1988 "try",
1989 "tube",
1990 "tuition",
1991 "tumble",
1992 "tuna",
1993 "tunnel",
1994 "turkey",
1995 "turn",
1996 "turtle",
1997 "twelve",
1998 "twenty",
1999 "twice",
2000 "twin",
2001 "twist",
2002 "two",
2003 "type",
2004 "typical",
2005 "ugly",
2006 "umbrella",
2007 "unable",
2008 "unaware",
2009 "uncle",
2010 "uncover",
2011 "under",
2012 "undo",
2013 "unfair",
2014 "unfold",
2015 "unhappy",
2016 "uniform",
2017 "unique",
2018 "unit",
2019 "universe",
2020 "unknown",
2021 "unlock",
2022 "until",
2023 "unusual",
2024 "unveil",
2025 "update",
2026 "upgrade",
2027 "uphold",
2028 "upon",
2029 "upper",
2030 "upset",
2031 "urban",
2032 "urge",
2033 "usage",
2034 "use",
2035 "used",
2036 "useful",
2037 "useless",
2038 "user",
2039 "utility",
2040 "vacant",
2041 "vacuum",
2042 "vague",
2043 "valid",
2044 "valley",
2045 "valve",
2046 "van",
2047 "vanish",
2048 "vapor",
2049 "various",
2050 "vegan",
2051 "velvet",
2052 "vendor",
2053 "venture",
2054 "venue",
2055 "verb",
2056 "verify",
2057 "version",
2058 "very",
2059 "vessel",
2060 "veteran",
2061 "viable",
2062 "vibrant",
2063 "vicious",
2064 "victory",
2065 "video",
2066 "view",
2067 "village",
2068 "vintage",
2069 "violin",
2070 "virtual",
2071 "virus",
2072 "visa",
2073 "visit",
2074 "visual",
2075 "vital",
2076 "vivid",
2077 "vocal",
2078 "voice",
2079 "void",
2080 "volcano",
2081 "volume",
2082 "vote",
2083 "voyage",
2084 "wage",
2085 "wagon",
2086 "wait",
2087 "walk",
2088 "wall",
2089 "walnut",
2090 "want",
2091 "warfare",
2092 "warm",
2093 "warrior",
2094 "wash",
2095 "wasp",
2096 "waste",
2097 "water",
2098 "wave",
2099 "way",
2100 "wealth",
2101 "weapon",
2102 "wear",
2103 "weasel",
2104 "weather",
2105 "web",
2106 "wedding",
2107 "weekend",
2108 "weird",
2109 "welcome",
2110 "west",
2111 "wet",
2112 "whale",
2113 "what",
2114 "wheat",
2115 "wheel",
2116 "when",
2117 "where",
2118 "whip",
2119 "whisper",
2120 "wide",
2121 "width",
2122 "wife",
2123 "wild",
2124 "will",
2125 "win",
2126 "window",
2127 "wine",
2128 "wing",
2129 "wink",
2130 "winner",
2131 "winter",
2132 "wire",
2133 "wisdom",
2134 "wise",
2135 "wish",
2136 "witness",
2137 "wolf",
2138 "woman",
2139 "wonder",
2140 "wood",
2141 "wool",
2142 "word",
2143 "work",
2144 "world",
2145 "worry",
2146 "worth",
2147 "wrap",
2148 "wreck",
2149 "wrestle",
2150 "wrist",
2151 "write",
2152 "wrong",
2153 "yard",
2154 "year",
2155 "yellow",
2156 "you",
2157 "young",
2158 "youth",
2159 "zebra",
2160 "zero",
2161 "zone",
2162 "zoo",
2163 ];
2164
2165 use rand::Rng;
2166 let mut rng = rand::thread_rng();
2167 let mut phrase = Vec::new();
2168 for _ in 0..12 {
2169 phrase.push(WORDS[rng.gen_range(0..WORDS.len())]);
2170 }
2171 phrase.join(" ")
2172 }
2173
2174 fn derive_keys(seed: &str) -> (String, String) {
2175 let mut hasher = Sha256::new();
2176 hasher.update(seed.as_bytes());
2177 let hash_result = hasher.finalize();
2178
2179 let mut key_bytes = [0u8; 32];
2180 key_bytes.copy_from_slice(&hash_result[..32]);
2181
2182 let signing_key = SigningKey::from_bytes(&key_bytes);
2183 let verifying_key: VerifyingKey = signing_key.verifying_key();
2184
2185 let private_key_hex = hex::encode(signing_key.to_bytes());
2186 let address = hex::encode(&verifying_key.as_bytes()[1..]);
2187
2188 let formatted_address = format!("0x{}", address);
2189 let formatted_private_key = format!("0x{}", private_key_hex);
2190
2191 (formatted_private_key, formatted_address)
2192 }
2193}
2194
2195impl Default for Wallet {
2196 fn default() -> Self {
2197 Wallet {
2198 address: "0x0000000000000000000000000000000000000000000000000000000000000000"
2199 .to_string(),
2200 private_key: "0x0000000000000000000000000000000000000000000000000000000000000000"
2201 .to_string(),
2202 network: "testnet".to_string(),
2203 seed_phrase: String::new(),
2204 }
2205 }
2206}