whitespace: various

This commit is contained in:
The MMGen Project 2024-10-18 10:32:08 +00:00
commit b7de7b9701
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
6 changed files with 27 additions and 27 deletions

View file

@ -17,7 +17,7 @@ altcoin.py - Constants for Bitcoin-derived altcoins
# pc: https://github.com/richardkiss/pycoin/blob/master/pycoin/networks/legacy_networks.py
# vg: https://github.com/exploitagency/vanitygen-plus/blob/master/keyconv.c
# wn: https://walletgenerator.net
# cc: https://www.cryptocompare.com/api/data/coinlist/ (names,symbols only)
# cc: https://www.cryptocompare.com/api/data/coinlist/ (names, symbols only)
# BIP44
# https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
@ -34,7 +34,7 @@ from ..protocol import CoinProtocol
from ..proto.btc.params import mainnet
ce = namedtuple('CoinInfoEntry',
['name','symbol','wif_ver_num','p2pkh_info','p2sh_info','has_segwit','trust_level'])
['name', 'symbol', 'wif_ver_num', 'p2pkh_info', 'p2sh_info', 'has_segwit', 'trust_level'])
class CoinInfo:
coin_constants = {}
@ -256,26 +256,26 @@ class CoinInfo:
)
@classmethod
def get_supported_coins(cls,network):
def get_supported_coins(cls, network):
return [e for e in cls.coin_constants[network] if e.trust_level != -1]
@classmethod
def get_entry(cls,coin,network):
def get_entry(cls, coin, network):
try:
idx = [e.symbol for e in cls.coin_constants[network]].index(coin.upper())
except:
return None
return cls.coin_constants[network][idx]
def make_proto(e,testnet=False):
def make_proto(e, testnet=False):
proto = ('X_' if e.name[0] in '0123456789' else '') + e.name + ('Testnet' if testnet else '')
if hasattr(CoinProtocol,proto):
if hasattr(CoinProtocol, proto):
return
def num2hexstr(n):
return '{:0{}x}'.format(n,(4,2)[n < 256])
return '{:0{}x}'.format(n, (4, 2)[n < 256])
setattr(
CoinProtocol,
@ -286,18 +286,18 @@ def make_proto(e,testnet=False):
{
'base_coin': e.symbol,
'addr_ver_info': dict(
[( num2hexstr(e.p2pkh_info[0]), 'p2pkh' )] +
([( num2hexstr(e.p2sh_info[0]), 'p2sh' )] if e.p2sh_info else [])
[(num2hexstr(e.p2pkh_info[0]), 'p2pkh')] +
([(num2hexstr(e.p2sh_info[0]), 'p2sh')] if e.p2sh_info else [])
),
'wif_ver_num': { 'std': num2hexstr(e.wif_ver_num) },
'mmtypes': ('L','C','S') if e.has_segwit else ('L','C'),
'wif_ver_num': {'std': num2hexstr(e.wif_ver_num)},
'mmtypes': ('L', 'C', 'S') if e.has_segwit else ('L', 'C'),
'dfl_mmtype': 'L',
'mmcaps': (),
},
)
)
def init_genonly_altcoins(usr_coin=None,testnet=False):
def init_genonly_altcoins(usr_coin=None, testnet=False):
"""
Initialize altcoin protocol class or classes for current network.
If usr_coin is a core coin, initialization is skipped.
@ -306,7 +306,7 @@ def init_genonly_altcoins(usr_coin=None,testnet=False):
Returns trust_level of usr_coin, or 0 (untrusted) if usr_coin is None.
"""
data = { 'mainnet': (), 'testnet': () }
data = {'mainnet': (), 'testnet': ()}
networks = ['mainnet'] + (['testnet'] if testnet else [])
network = 'testnet' if testnet else 'mainnet'
@ -317,7 +317,7 @@ def init_genonly_altcoins(usr_coin=None,testnet=False):
if usr_coin.lower() in gc.core_coins: # core coin, so return immediately
return CoinProtocol.coins[usr_coin.lower()].trust_level
for network in networks:
data[network] = (CoinInfo.get_entry(usr_coin,network),)
data[network] = (CoinInfo.get_entry(usr_coin, network),)
cinfo = data[network][0]
if not cinfo:
@ -329,11 +329,11 @@ def init_genonly_altcoins(usr_coin=None,testnet=False):
make_proto(e)
for e in data['testnet']:
make_proto(e,testnet=True)
make_proto(e, testnet=True)
for e in data['mainnet']:
if e.symbol.lower() in CoinProtocol.coins:
continue
CoinProtocol.coins[e.symbol.lower()] = CoinProtocol.proto_info(
name = 'X_'+e.name if e.name[0] in '0123456789' else e.name,
trust_level = e.trust_level )
trust_level = e.trust_level)

View file

@ -14,7 +14,7 @@ altcoin.util: various altcoin-related utilities
from ..util import die
def decrypt_keystore(data,passwd,mac_algo=None,mac_params={}):
def decrypt_keystore(data, passwd, mac_algo=None, mac_params={}):
"""
Decrypt the encrypted data in a cross-chain keystore
Returns the decrypted data as a bytestring
@ -23,14 +23,14 @@ def decrypt_keystore(data,passwd,mac_algo=None,mac_params={}):
cdata = data['crypto']
parms = cdata['kdfparams']
valid_kdfs = ['scrypt','pbkdf2']
valid_ciphers = ['aes-128-ctr','aes-256-ctr']
valid_kdfs = ['scrypt', 'pbkdf2']
valid_ciphers = ['aes-128-ctr', 'aes-256-ctr']
if (kdf := cdata['kdf']) not in valid_kdfs:
die(1, f'unsupported key derivation function {kdf!r} (must be one of {valid_kdfs})')
if (cipher := cdata['cipher']) not in valid_ciphers:
die(1,f'unsupported cipher {cipher!r} (must be one of {valid_ciphers})')
die(1, f'unsupported cipher {cipher!r} (must be one of {valid_ciphers})')
# Derive encryption key from password:
if kdf == 'scrypt':
@ -72,7 +72,7 @@ def decrypt_keystore(data,passwd,mac_algo=None,mac_params={}):
die(1, 'incorrect password')
# Decrypt data:
from cryptography.hazmat.primitives.ciphers import Cipher,algorithms,modes
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
cipher_len = int(cipher.split('-')[1]) // 8
c = Cipher(

View file

@ -55,7 +55,7 @@ def parse_version_bytes(vb_hex):
def compress_pubkey(pubkey_bytes):
# see: proto.secp256k1.keygen.pubkey_format()
return (b'\x02',b'\x03')[pubkey_bytes[-1] & 1] + pubkey_bytes[1:33]
return (b'\x02', b'\x03')[pubkey_bytes[-1] & 1] + pubkey_bytes[1:33]
def decompress_pubkey(pubkey_bytes):
import ecdsa

View file

@ -58,7 +58,7 @@ class help_notes:
from ..passwdlist import PasswordList
pwi_fs = '{:8} {:1} {:26} {:<7} {:<7} {}'
return '\n '.join(
[pwi_fs.format('Code', '','Description', 'Min Len', 'Max Len', 'Default Len')] +
[pwi_fs.format('Code', '', 'Description', 'Min Len', 'Max Len', 'Default Len')] +
[pwi_fs.format(k, '-', v.desc, v.min_len, v.max_len, v.dfl_len)
for k, v in PasswordList.pw_info.items()]
)

View file

@ -12,8 +12,8 @@
help.seedsplit: seedsplit help notes for MMGen suite
"""
def help(proto,cfg):
from ..seedsplit import SeedShareIdx,SeedShareCount,MasterShareIdx
def help(proto, cfg):
from ..seedsplit import SeedShareIdx, SeedShareCount, MasterShareIdx
return """
COMMAND NOTES:
@ -102,4 +102,4 @@ EXAMPLES:
""".strip().format(
si = SeedShareIdx,
sc = SeedShareCount,
mi = MasterShareIdx )
mi = MasterShareIdx)

View file

@ -105,7 +105,7 @@ def print_shares_info():
id_str.hl2(encl='‘’'),
len(shares))
si = 1
for n, s in enumerate(shares[si:],si+1):
for n, s in enumerate(shares[si:], si+1):
out += f'{n:3}: {s.sid}\n'
cfg._util.qmsg(out)