forked from piperwallet/Piper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genkeys.py
63 lines (53 loc) · 1.74 KB
/
genkeys.py
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
# This file is part of Piper.
#
# Piper is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Piper is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Piper. If not, see <http://www.gnu.org/licenses/>.
#
# Piper Copyright (C) 2013 Christopher Cassano
import os
from subprocess import Popen, PIPE
import sqlite3
pubkey = ""
privkey = ""
keysAreValid = False
def genKeys():
global pubkey, privkey, keysAreValid
keysAreValid = False
con = None
try:
con = sqlite3.connect('/home/pi/Printer/keys.db3')
cur = con.cursor()
cur.execute("SELECT coinType, addrPrefix FROM piper_settings LIMIT 1;")
row = cur.fetchone()
coinType = row[0]
addrPrefix = row[1]
except sqlite3.Error, e:
print("Error %s:" % e.args[0])
sys.exit(1)
finally:
if con:
con.commit()
con.close()
if(coinType == "litecoin"):
process = Popen(["./vanitygen-litecoin", "-q", "-L", "-t","1","-s", "/dev/random", addrPrefix], stdout=PIPE)
else:
process = Popen(["./vanitygen", "-q", "-t","1","-s", "/dev/random", addrPrefix], stdout=PIPE)
results = process.stdout.read()
addrs = results.split()
pubkey = addrs[3]
privkey = addrs[5]
#we do a basic length sanity check on the public and private keys
if len(privkey) == 51 and len(pubkey) >= 27:
keysAreValid = True
else:
keysAreValid = False