-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from backpacker69/master
using gpg to encrypt and decrypt keystore
- Loading branch information
Showing
5 changed files
with
133 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import gnupg | ||
import getpass | ||
import sys | ||
from pypeerassets.kutil import Kutil | ||
|
||
mypg = None | ||
|
||
def read_keystore(Settings,keyfile) -> str: | ||
mykeys = "" | ||
|
||
if Settings.keystore == "gnupg" and Settings.provider != "rpcnode": | ||
mypg = gnupg.GPG(binary='/usr/bin/gpg',homedir=Settings.gnupgdir,use_agent=bool(Settings.gnupgagent=="True"),keyring='pubring.gpg',secring='secring.gpg') | ||
password = getpass.getpass("Input gpg key password:") | ||
fd = open(keyfile) | ||
data = fd.read() | ||
|
||
if len(data)>0: | ||
mykeys = str(mypg.decrypt(data,passphrase=password)) | ||
fd.close() | ||
else: | ||
print("using rpcnode") | ||
|
||
return mykeys | ||
|
||
def write_keystore(Settings,keyfile,keys): | ||
|
||
if mypg: | ||
data = str(mypg.encrypt(str(keys),Settings.gnupgkey)) | ||
fd = open(keyfile,"w") | ||
fd.write(data) | ||
fd.close() | ||
|
||
class KeyedProvider: | ||
|
||
""" | ||
Keystore class | ||
""" | ||
|
||
@classmethod | ||
def __init__(self, provider, keysJson: str=""): | ||
""" | ||
: | ||
""" | ||
self.provider = provider | ||
|
||
if keysJson != "": | ||
self.privkeys = eval(keysJson) | ||
else: | ||
self.privkeys = {} | ||
|
||
@classmethod | ||
def __getattr__(self, name): | ||
return getattr(self.provider, name) | ||
|
||
@classmethod | ||
def importprivkey(self, privkey: str, label: str) -> int: | ||
"""import <privkey> with <label>""" | ||
mykey = Kutil(wif=privkey) | ||
|
||
if label not in self.privkeys.keys(): | ||
self.privkeys[label] = [] | ||
|
||
if mykey._privkey not in [key['privkey'] for key in self.privkeys[label]]: | ||
self.privkeys[label].append({"privkey":mykey._privkey,"address":mykey.address}) | ||
|
||
@classmethod | ||
def getaddressesbyaccount(self, label: str) -> list: | ||
if label in self.privkeys.keys(): | ||
return [key["address"] for key in self.privkeys[label]] | ||
|
||
@classmethod | ||
def listaccounts(self) -> dict: | ||
return {key:0 for key in self.privkeys.keys()} | ||
|
||
@classmethod | ||
def dumpprivkeys(self) -> dict: | ||
return self.privkeys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pypeerassets>=0.1.1 | ||
terminaltables>=3.1.0 | ||
gnupg>=2.1 | ||
appdirs |