|
4 | 4 | """ |
5 | 5 |
|
6 | 6 | from __future__ import absolute_import, division, print_function, \ |
7 | | - unicode_literals |
| 7 | + unicode_literals |
8 | 8 |
|
9 | 9 | from argparse import ArgumentParser |
10 | 10 | from getpass import getpass as secure_input |
11 | 11 | from sys import argv |
12 | 12 | from typing import Optional, Text |
13 | 13 |
|
14 | | -from iota import __version__, Iota |
| 14 | +from six import binary_type, moves as compat, text_type |
| 15 | + |
| 16 | +from iota import Iota, __version__ |
15 | 17 | from iota.crypto.addresses import AddressGenerator |
16 | 18 | from iota.crypto.types import Seed |
17 | | -from six import binary_type, moves as compat, text_type |
18 | 19 |
|
19 | 20 |
|
20 | 21 | def main(uri, index, count, security, checksum): |
21 | | - # type: (Text, int, Optional[int], Optional[int], bool) -> None |
22 | | - seed = get_seed() |
| 22 | + # type: (Text, int, Optional[int], Optional[int], bool) -> None |
| 23 | + seed = get_seed() |
23 | 24 |
|
24 | | - # Create the API instance. |
25 | | - # Note: If ``seed`` is null, a random seed will be generated. |
26 | | - api = Iota(uri, seed) |
| 25 | + # Create the API instance. |
| 26 | + # Note: If ``seed`` is null, a random seed will be generated. |
| 27 | + api = Iota(uri, seed) |
27 | 28 |
|
28 | | - # If we generated a random seed, then we need to display it to the |
29 | | - # user, or else they won't be able to use their new addresses! |
30 | | - if not seed: |
31 | | - print('A random seed has been generated. Press return to see it.') |
32 | | - output_seed(api.seed) |
| 29 | + # If we generated a random seed, then we need to display it to the |
| 30 | + # user, or else they won't be able to use their new addresses! |
| 31 | + if not seed: |
| 32 | + print('A random seed has been generated. Press return to see it.') |
| 33 | + output_seed(api.seed) |
33 | 34 |
|
34 | | - print('Generating addresses. This may take a few minutes...') |
35 | | - print('') |
| 35 | + print('Generating addresses. This may take a few minutes...') |
| 36 | + print('') |
36 | 37 |
|
37 | | - # Here's where all the magic happens! |
38 | | - api_response = api.get_new_addresses(index, count, security, checksum) |
39 | | - for addy in api_response['addresses']: |
40 | | - print(binary_type(addy).decode('ascii')) |
| 38 | + # Here's where all the magic happens! |
| 39 | + api_response = api.get_new_addresses(index, count, security, checksum) |
| 40 | + for addy in api_response['addresses']: |
| 41 | + print(binary_type(addy).decode('ascii')) |
41 | 42 |
|
42 | | - print('') |
| 43 | + print('') |
43 | 44 |
|
44 | 45 |
|
45 | 46 | def get_seed(): |
46 | | - # type: () -> binary_type |
47 | | - """ |
48 | | - Prompts the user securely for their seed. |
49 | | - """ |
50 | | - print( |
51 | | - 'Enter seed and press return (typing will not be shown). ' |
52 | | - 'If empty, a random seed will be generated and displayed on the screen.' |
53 | | - ) |
54 | | - seed = secure_input('') # type: Text |
55 | | - return seed.encode('ascii') |
| 47 | + # type: () -> binary_type |
| 48 | + """ |
| 49 | + Prompts the user securely for their seed. |
| 50 | + """ |
| 51 | + print( |
| 52 | + 'Enter seed and press return (typing will not be shown). ' |
| 53 | + 'If empty, a random seed will be generated and displayed on the screen.' |
| 54 | + ) |
| 55 | + seed = secure_input('') # type: Text |
| 56 | + return seed.encode('ascii') |
56 | 57 |
|
57 | 58 |
|
58 | 59 | def output_seed(seed): |
59 | | - # type: (Seed) -> None |
60 | | - """ |
61 | | - Outputs the user's seed to stdout, along with lots of warnings |
62 | | - about security. |
63 | | - """ |
64 | | - print( |
65 | | - 'WARNING: Anyone who has your seed can spend your IOTAs! ' |
66 | | - 'Clear the screen after recording your seed!' |
67 | | - ) |
68 | | - compat.input('') |
69 | | - print('Your seed is:') |
70 | | - print('') |
71 | | - print(binary_type(seed).decode('ascii')) |
72 | | - print('') |
73 | | - |
74 | | - print( |
75 | | - 'Clear the screen to prevent shoulder surfing, ' |
76 | | - 'and press return to continue.' |
77 | | - ) |
78 | | - print('https://en.wikipedia.org/wiki/Shoulder_surfing_(computer_security)') |
79 | | - compat.input('') |
| 60 | + # type: (Seed) -> None |
| 61 | + """ |
| 62 | + Outputs the user's seed to stdout, along with lots of warnings |
| 63 | + about security. |
| 64 | + """ |
| 65 | + print( |
| 66 | + 'WARNING: Anyone who has your seed can spend your IOTAs! ' |
| 67 | + 'Clear the screen after recording your seed!' |
| 68 | + ) |
| 69 | + compat.input('') |
| 70 | + print('Your seed is:') |
| 71 | + print('') |
| 72 | + print(binary_type(seed).decode('ascii')) |
| 73 | + print('') |
| 74 | + |
| 75 | + print( |
| 76 | + 'Clear the screen to prevent shoulder surfing, ' |
| 77 | + 'and press return to continue.' |
| 78 | + ) |
| 79 | + print('https://en.wikipedia.org/wiki/Shoulder_surfing_(computer_security)') |
| 80 | + compat.input('') |
80 | 81 |
|
81 | 82 |
|
82 | 83 | if __name__ == '__main__': |
83 | | - parser = ArgumentParser( |
84 | | - description = __doc__, |
85 | | - epilog = 'PyOTA v{version}'.format(version=__version__), |
86 | | - ) |
87 | | - |
88 | | - parser.add_argument( |
89 | | - '--uri', |
90 | | - type = text_type, |
91 | | - default = 'http://localhost:14265/', |
92 | | - |
93 | | - help = |
94 | | - 'URI of the node to connect to ' |
95 | | - '(defaults to http://localhost:14265/).', |
96 | | - ) |
97 | | - |
98 | | - parser.add_argument( |
99 | | - '--index', |
100 | | - type = int, |
101 | | - default = 0, |
102 | | - help = 'Index of the key to generate.', |
103 | | - ) |
104 | | - |
105 | | - parser.add_argument( |
106 | | - '--count', |
107 | | - type = int, |
108 | | - default = None, |
109 | | - |
110 | | - help = |
111 | | - 'Number of addresses to generate. ' |
112 | | - 'If not specified, the first unused address will be returned.' |
113 | | - ) |
114 | | - |
115 | | - parser.add_argument( |
116 | | - '--security', |
117 | | - type = int, |
118 | | - default = AddressGenerator.DEFAULT_SECURITY_LEVEL, |
119 | | - help = 'Security level to be used for the private key / address. ' |
120 | | - 'Can be 1, 2 or 3', |
121 | | - ) |
122 | | - |
123 | | - parser.add_argument( |
124 | | - '--with-checksum', |
125 | | - action = 'store_true', |
126 | | - default = False, |
127 | | - dest = 'checksum', |
128 | | - help = 'List the address with the checksum.', |
129 | | - ) |
130 | | - |
131 | | - main(**vars(parser.parse_args(argv[1:]))) |
| 84 | + parser = ArgumentParser( |
| 85 | + description=__doc__, |
| 86 | + epilog='PyOTA v{version}'.format(version=__version__), |
| 87 | + ) |
| 88 | + |
| 89 | + parser.add_argument( |
| 90 | + '--uri', |
| 91 | + type=text_type, |
| 92 | + default='http://localhost:14265/', |
| 93 | + |
| 94 | + help=( |
| 95 | + 'URI of the node to connect to ' |
| 96 | + '(defaults to http://localhost:14265/).' |
| 97 | + ), |
| 98 | + ) |
| 99 | + |
| 100 | + parser.add_argument( |
| 101 | + '--index', |
| 102 | + type=int, |
| 103 | + default=0, |
| 104 | + help='Index of the key to generate.', |
| 105 | + ) |
| 106 | + |
| 107 | + parser.add_argument( |
| 108 | + '--count', |
| 109 | + type=int, |
| 110 | + default=None, |
| 111 | + |
| 112 | + help=( |
| 113 | + 'Number of addresses to generate. ' |
| 114 | + 'If not specified, the first unused address will be returned.' |
| 115 | + ), |
| 116 | + ) |
| 117 | + |
| 118 | + parser.add_argument( |
| 119 | + '--security', |
| 120 | + type=int, |
| 121 | + default=AddressGenerator.DEFAULT_SECURITY_LEVEL, |
| 122 | + help=( |
| 123 | + 'Security level to be used for the private key / address. ' |
| 124 | + 'Can be 1, 2 or 3' |
| 125 | + ), |
| 126 | + ) |
| 127 | + |
| 128 | + parser.add_argument( |
| 129 | + '--with-checksum', |
| 130 | + action='store_true', |
| 131 | + default=False, |
| 132 | + dest='checksum', |
| 133 | + help='List the address with the checksum.', |
| 134 | + ) |
| 135 | + |
| 136 | + main(**vars(parser.parse_args(argv[1:]))) |
0 commit comments