-
Notifications
You must be signed in to change notification settings - Fork 5
/
1Ring-cli
executable file
·251 lines (218 loc) · 12.1 KB
/
1Ring-cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/usr/bin/env python
#
# Copyright 2015 Alternative Systems All Rights Reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the Alternative Systems LLC nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE ALTSYSTEM OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF YOUR
# JURISDICTION. It is licensee's responsibility to comply with any export
# regulations applicable in licensee's jurisdiction. Under CURRENT (Dec 2015)
# U.S. export regulations this software is eligible for export from the U.S.
# and can be downloaded by or otherwise exported or reexported worldwide EXCEPT
# to U.S. embargoed destinations which include Cuba, Iraq, Libya, North Korea,
# Iran, Syria, Sudan, Afghanistan and any other country to which the U.S. has
# embargoed goods and services.
# The DHT contains the processed transactions
# The tuple space operates as a messaging stack
import argparse, sys
from Keyring import Keyring
from common.identity import *
from common.wallet import *
from common.utils import *
from common.gpg import *
from common.web import *
import binascii
from key.coins import COINS
def list_identities():
print "1Ring Identities"
print "--------------------------------------------------------------------"
print "ID\tFingerprint\tCreated\t\t\tLabel"
for id in ListIdentities():
print str(id['id']) + "\t" + "0x" + binascii.hexlify(id['fingerprint']).upper() + "\t" + str(unpackTime(id['created'])) + "\t" + str(id['label'])
sys.exit(0)
def export_identity(args):
print ExportIdentity(args.select_identity,args.password)
def import_identity(args):
print ImportIdentity(args.import_identity,args.password)
def list_addresses(args):
data = ListAddresses(args.password,args.select_identity,args.use_wallet)
print "1Ring Addresses for Wallet ID #%s, %s" % (args.use_wallet, data[0][1].capitalize())
print "--------------------------------------------------------------------"
print "ID\tAddress\t\t\t\t\tBalance"
for addr in data:
print str(addr[3]) + "\t" + addr[0] + "\t" + str(addr[2])
def list_wallets(args):
print "1Ring Wallets for Identity #%s" % args.select_identity
print "--------------------------------------------------------------------"
print "ID\tBlockchain\t\tTestnet\t\tBalance"
for id in ListWallets(args.password,args.select_identity):
if id['balance'] is False:
balance = "No addresses."
else:
balance = id['balance']
print str(id['id']) + "\t" + id['currency'].ljust(15).capitalize() + "\t\t" + str(id['testnet']==1) + "\t\t" + str(balance)
sys.exit(0)
def list_websites(args):
print "1Ring Website Passwords for ID #%s" % (args.select_identity)
print "--------------------------------------------------------------------"
print "ID\tDomain\t\t\t\t\tCreated\t\t\tUsername"
for item in ListWebsites(args.select_identity):
print '%s\t%s\t\t\t\t%s\t%s' % (item['id'], item['domain'], item['created'], item['username'],)
def show_password(args):
password, username, email = ShowPassword(args.password,args.select_identity,args.show_password)
print "%s %s %s" % (password, username, email)
def sign_message(args):
print binascii.hexlify(SignMessage(args.password,args.sign,args.select_identity))
def verify_message(args):
print VerifyMessage(args.password,args.select_identity,binascii.unhexlify(args.verify),args.message,args.use_address)
def generate_address(args):
GenerateAddress(args.password, args.select_identity, args.use_wallet)
def create_website_password(args):
CreateWebsitePassword(args.password, args.select_identity, args.create_website_password, args.website_login)
def create_wallet(args):
CreateWallet(args.password,args.select_cryptocurrency,args.use_testnet,args.select_identity)
def create_identity(args):
id = CreateIdentity(args.password,args.select_cryptocurrency,args.use_testnet,args.select_identity)
print ExportIdentity(id,args.password)
def create_GPG_key(args):
CreateGPGKey(args.select_identity, args.password, args.create_GPG_key)
def GetArgs():
"Parse command line and validate inputs"
parser = argparse.ArgumentParser(description='Manage 1Ring Identities')
parser.add_argument('-i','--select-identity', action='store', type=int, default=1,
help="Select an identity for further operations")
parser.add_argument('-p','--password', required=False, action='store', default=None,
help="Password for the specified identity. Should be enclosed in single (\') or double (\") quotes.")
parser.add_argument('-l','--list-identities', action='store_true',
help="List all identites")
parser.add_argument('-e','--create-identity', action='store',
help="Create an identity with the specified label. Should be enclosed in single (\') or double (\") quotes.")
parser.add_argument('-x','--export-identity', action='store_true',
help="Export the identity specified with -i into a 16 word mnemonic.")
parser.add_argument('-I','--import-identity', action='store',
help="Import the 16 word mnemonic into an identity.")
parser.add_argument('-y','--select-cryptocurrency', action='store', default='bitcoin', choices=['bitcoin','ethereum','expanse','litecoin','unobtanium'],
help="Select the cryptocurrency to use")
parser.add_argument('-t','--use-testnet', action='store', default=False,
help="Use testnet encoding.")
parser.add_argument('-c','--create-wallet', action='store_true',
help="Create a HD wallet and display the WIF and BIP32 private key")
parser.add_argument('-b','--list-wallets', action='store_true',
help="List all wallets")
parser.add_argument('-g','--use-wallet', action='store', type=int, default=1,
help="Select wallet for further operations")
parser.add_argument('-a','--generate-address', action='store_true',
help="Generates an address from a wallet")
parser.add_argument('-d','--list-addresses', action='store_true',
help="Lists addresses in a wallet")
parser.add_argument('-u','--use-address', action='store', type=int, default=1,
help="Select address for further operations")
parser.add_argument('-s','--sign', action='store',
help="Sign a string with the specified identity. Should be enclosed in double (\") quotes.")
parser.add_argument('-v','--verify', action='store',
help="Supply a signature to be verified. Should be enclosed in double (\") quotes. Use -m to specify the message, -k to specify origin address.")
parser.add_argument('-m','--message', action='store',
help="Supply a message (with a signature) to be verified. Should be enclosed in double (\") quotes. Use -v to specify the signature.")
parser.add_argument('-w','--list-websites', action='store_true',
help="List non-1Ring websites")
parser.add_argument('-r','--create-website-password', action='store',
help="Create a password for the specified non-1Ring website ID. If a password exists, replace it.")
parser.add_argument('-o','--show-password', action='store',
help="Display the password for the non-1Ring website ID provided")
parser.add_argument('-n','--website-login', action='store',
help="Use the specified login name for the non-1Ring website indicated with -r")
"""
parser.add_argument('-C','--create-GPG-key', action='store',
help="Create a GPG key for the given identity with the provided label.")
parser.add_argument('-L','--list-GPG-keys', action='store_true',
help="List GPG keys for the given identity")
parser.add_argument('-U','--use-GPG-key', action='store',
help="Select GPG key for further operation")
parser.add_argument('-E','--encrypt-using-GPG-key', action='store',
help="Encrypt text with selected GPG key")
parser.add_argument('-D','--decrypt-using-GPG-key', action='store',
help="Encrypt text with selected GPG key")
parser.add_argument('-X','--export-GPG-key-pair', action='store',
help="Export the selected GPG key pair to specified file")
"""
args = parser.parse_args()
if args.select_identity is None:
ErrorExit("Use -i to specify an identity!")
elif args.create_website_password is not None and args.website_login is None:
ErrorExit ("The -r command requires -n. Use --help for more information.")
elif args.website_login is not None and args.create_website_password is None:
ErrorExit ("The -n command requires -r. Use --help for more information.")
elif args.use_address is None and args.verify is not None:
ErrorExit ("The -v command requires -u. Use --help for more information.")
elif args.message is None and args.verify is not None:
ErrorExit ("The -v command requires -m. Use --help for more information.")
return args
def ErrorExit(e):
"Ab-end, printing exception"
try:
sys.stderr.write(sys.argv[0]+": "+e.message+'\n')
except:
sys.stderr.write(sys.argv[0]+": "+e+'\n')
sys.exit(1)
if __name__ == '__main__':
try:
args = GetArgs()
except Exception as e:
ErrorExit(e)
InitializeKeyStore(args)
# Load the identity with the password specicied at the command line
if args.password is None:
if args.list_identities:
list_identities()
else:
ErrorExit("Nothing to do. Use --help for a list of commands")
elif args.import_identity is not None:
import_identity(args)
elif not Keyring(args.password, args.select_identity).isValid():
ErrorExit("Password invalid or identity does not exist. Use -l for a list of valid identities.")
else:
if args.create_wallet:
create_wallet(args)
if args.list_identities:
list_identities()
elif args.list_wallets:
list_wallets(args)
elif args.list_addresses:
list_addresses(args)
elif args.sign:
sign_message(args)
elif args.verify:
verify_message(args)
#elif args.create_GPG_key:
# create_GPG_key(args)
elif args.list_websites:
list_websites(args)
elif args.create_website_password is not None:
create_website_password(args)
elif args.show_password is not None:
show_password(args)
elif args.generate_address:
generate_address(args)
elif args.export_identity:
export_identity(args)