globalvars.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2019 The MMGen Project <mmgen@tuta.io>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. globalvars.py: Constants and configuration options for the MMGen suite
  20. """
  21. import sys,os
  22. from decimal import Decimal
  23. from mmgen.devtools import *
  24. # Global vars are set to dfl values in class g.
  25. # They're overridden in this order:
  26. # 1 - config file
  27. # 2 - environmental vars
  28. # 3 - command line
  29. class g(object):
  30. def die(ev=0,s=''):
  31. if s: sys.stderr.write(s+'\n')
  32. sys.exit(ev)
  33. # Constants:
  34. version = '0.11.099'
  35. release_date = 'May 2019'
  36. proj_name = 'MMGen'
  37. proj_url = 'https://github.com/mmgen/mmgen'
  38. prog_name = os.path.basename(sys.argv[0])
  39. author = 'The MMGen Project'
  40. email = '<mmgen@tuta.io>'
  41. Cdates = '2013-2019'
  42. keywords = 'Bitcoin, BTC, Ethereum, ETH, Monero, XMR, ERC20, cryptocurrency, wallet, BIP32, cold storage, offline, online, spending, open-source, command-line, Python, Linux, Bitcoin Core, bitcoind, hd, deterministic, hierarchical, secure, anonymous, Electrum, seed, mnemonic, brainwallet, Scrypt, utility, script, scriptable, blockchain, raw, transaction, permissionless, console, terminal, curses, ansi, color, tmux, remote, client, daemon, RPC, json, entropy, xterm, rxvt, PowerShell, MSYS, MSYS2, MinGW, MinGW64, MSWin, Armbian, Raspbian, Raspberry Pi, Orange Pi, BCash, BCH, Litecoin, LTC, altcoin, ZEC, Zcash, DASH, Dashpay, SHA256Compress, monerod, EMC, Emercoin, token, deploy, contract, gas, fee, smart contract, solidity, Parity, testnet, devmode, Kovan'
  43. max_int = 0xffffffff
  44. stdin_tty = bool(sys.stdin.isatty() or os.getenv('MMGEN_TEST_SUITE_POPEN_SPAWN'))
  45. stdout = sys.stdout
  46. stderr = sys.stderr
  47. http_timeout = 60
  48. # Variables - these might be altered at runtime:
  49. user_entropy = ''
  50. hash_preset = '3'
  51. usr_randchars = 30
  52. tx_fee_adj = Decimal('1.0')
  53. tx_confs = 3
  54. seed_len = 256
  55. # Constant vars - some of these might be overridden in opts.py, but they don't change thereafter
  56. coin = 'BTC'
  57. dcoin = None # the display coin unit
  58. token = ''
  59. debug = False
  60. debug_opts = False
  61. debug_rpc = False
  62. debug_addrlist = False
  63. debug_subseed = False
  64. quiet = False
  65. no_license = False
  66. force_256_color = False
  67. testnet = False
  68. regtest = False
  69. accept_defaults = False
  70. use_internal_keccak_module = False
  71. chain = None # set by first call to rpc_init()
  72. chains = 'mainnet','testnet','regtest'
  73. # rpc:
  74. rpc_host = ''
  75. rpc_port = 0
  76. rpc_user = ''
  77. rpc_password = ''
  78. rpc_fail_on_command = ''
  79. rpch = None # global RPC handle
  80. use_cached_balances = False
  81. # regtest:
  82. bob = False
  83. alice = False
  84. # test suite:
  85. bogus_wallet_data = ''
  86. bogus_send = False
  87. debug_utf8 = False
  88. traceback = False
  89. test_suite = False
  90. test_suite_popen_spawn = False
  91. terminal_width = 0
  92. # warnings
  93. mswin_pw_warning = True
  94. for k in ('linux','win','msys'):
  95. if sys.platform[:len(k)] == k:
  96. platform = { 'linux':'linux', 'win':'win', 'msys':'win' }[k]
  97. break
  98. else:
  99. die(1,"'{}': platform not supported by {}\n".format(sys.platform,proj_name))
  100. color = sys.stdout.isatty()
  101. if os.getenv('HOME'): # Linux or MSYS
  102. home_dir = os.getenv('HOME')
  103. elif platform == 'win': # Windows native:
  104. die(1,'$HOME not set! {} for Windows must be run in MSYS environment'.format(proj_name))
  105. else:
  106. die(2,'$HOME is not set! Unable to determine home directory')
  107. data_dir_root,data_dir,cfg_file = None,None,None
  108. daemon_data_dir = '' # set by user or protocol
  109. # global var sets user opt:
  110. global_sets_opt = ( 'minconf','seed_len','hash_preset','usr_randchars','debug',
  111. 'quiet','tx_confs','tx_fee_adj','key_generator' )
  112. # user opt sets global var:
  113. opt_sets_global = ( 'use_internal_keccak_module','subseeds' )
  114. # 'long' opts - opt sets global var
  115. common_opts = (
  116. 'color','no_license','rpc_host','rpc_port','testnet','rpc_user','rpc_password',
  117. 'daemon_data_dir','force_256_color','regtest','coin','bob','alice',
  118. 'accept_defaults','token'
  119. )
  120. # opts initialized to None by opts.init() if not set by user
  121. required_opts = (
  122. 'quiet','verbose','debug','outdir','echo_passphrase','passwd_file','stdout',
  123. 'show_hash_presets','label','keep_passphrase','keep_hash_preset','yes',
  124. 'brain_params','b16','usr_randchars','coin','bob','alice','key_generator',
  125. 'hidden_incog_input_params','in_fmt'
  126. )
  127. incompatible_opts = (
  128. ('base32','hex'), # mmgen-passgen
  129. ('bob','alice'),
  130. ('quiet','verbose'),
  131. ('label','keep_label'),
  132. ('tx_id','info'),
  133. ('tx_id','terse_info'),
  134. ('batch','rescan') # still incompatible as of Core 0.15.0
  135. )
  136. cfg_file_opts = (
  137. 'color','debug','hash_preset','http_timeout','no_license','rpc_host','rpc_port',
  138. 'quiet','tx_fee_adj','usr_randchars','testnet','rpc_user','rpc_password',
  139. 'daemon_data_dir','force_256_color','regtest','subseeds',
  140. 'btc_max_tx_fee','ltc_max_tx_fee','bch_max_tx_fee','eth_max_tx_fee',
  141. 'eth_mainnet_chain_name','eth_testnet_chain_name',
  142. 'max_tx_file_size','max_input_size','mswin_pw_warning'
  143. )
  144. # Supported environmental vars
  145. # The corresponding vars (lowercase, minus 'mmgen_') must be initialized in g
  146. # 'DISABLE_' env vars disable the corresponding var in g
  147. env_opts = (
  148. 'MMGEN_DEBUG_ALL', # special: there is no g.debug_all var
  149. 'MMGEN_TEST_SUITE',
  150. 'MMGEN_TEST_SUITE_POPEN_SPAWN',
  151. 'MMGEN_TERMINAL_WIDTH',
  152. 'MMGEN_BOGUS_WALLET_DATA',
  153. 'MMGEN_BOGUS_SEND',
  154. 'MMGEN_DEBUG',
  155. 'MMGEN_DEBUG_OPTS',
  156. 'MMGEN_DEBUG_RPC',
  157. 'MMGEN_DEBUG_ADDRLIST',
  158. 'MMGEN_DEBUG_UTF8',
  159. 'MMGEN_DEBUG_SUBSEED',
  160. 'MMGEN_QUIET',
  161. 'MMGEN_FORCE_256_COLOR',
  162. 'MMGEN_MIN_URANDCHARS',
  163. 'MMGEN_NO_LICENSE',
  164. 'MMGEN_RPC_HOST',
  165. 'MMGEN_RPC_FAIL_ON_COMMAND',
  166. 'MMGEN_TESTNET',
  167. 'MMGEN_REGTEST',
  168. 'MMGEN_TRACEBACK',
  169. 'MMGEN_USE_STANDALONE_SCRYPT_MODULE',
  170. 'MMGEN_DISABLE_COLOR',
  171. 'MMGEN_DISABLE_MSWIN_PW_WARNING',
  172. )
  173. min_screen_width = 80
  174. minconf = 1
  175. max_tx_file_size = 100000
  176. max_input_size = 1024 * 1024
  177. passwd_max_tries = 5
  178. max_urandchars = 80
  179. min_urandchars = 10
  180. seed_lens = 128,192,256
  181. scramble_hash_rounds = 10
  182. subseeds = 100
  183. mmenc_ext = 'mmenc'
  184. salt_len = 16
  185. aesctr_iv_len = 16
  186. aesctr_dfl_iv = b'\x00' * (aesctr_iv_len-1) + b'\x01'
  187. hincog_chk_len = 8
  188. key_generators = 'python-ecdsa','secp256k1' # '1','2'
  189. key_generator = 2 # secp256k1 is default
  190. force_standalone_scrypt_module = False
  191. # Scrypt params: 'id_num': [N, p, r] (N is an exponent of two)
  192. # NB: hashlib.scrypt in Python (>=v3.6) supports max N value of 14. This means that
  193. # for hash presets > 3 the standalone scrypt library must be used!
  194. hash_presets = {
  195. '1': [12, 8, 1],
  196. '2': [13, 8, 4],
  197. '3': [14, 8, 8],
  198. '4': [15, 8, 12],
  199. '5': [16, 8, 16],
  200. '6': [17, 8, 20],
  201. '7': [18, 8, 24],
  202. }