help.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2022 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. help.py: help notes for MMGen suite commands
  20. """
  21. def help_notes_func(proto,po,k):
  22. from .globalvars import g
  23. def fee_spec_letters(use_quotes=False):
  24. cu = proto.coin_amt.units
  25. sep,conj = ((',',' or '),("','","' or '"))[use_quotes]
  26. return sep.join(u[0] for u in cu[:-1]) + ('',conj)[len(cu)>1] + cu[-1][0]
  27. def fee_spec_names():
  28. cu = proto.coin_amt.units
  29. return ', '.join(cu[:-1]) + ('',' and ')[len(cu)>1] + cu[-1] + ('',',\nrespectively')[len(cu)>1]
  30. def coind_exec():
  31. from .daemon import CoinDaemon
  32. return (
  33. CoinDaemon(proto.coin).exec_fn if proto.coin in CoinDaemon.coins else 'bitcoind' )
  34. class help_notes:
  35. def MasterShareIdx():
  36. from .seedsplit import MasterShareIdx
  37. return MasterShareIdx
  38. def test_py_log_file():
  39. from test.test_py_d.common import log_file
  40. return log_file
  41. def tool_help():
  42. from .tool.help import main_help
  43. return main_help()
  44. def dfl_subseeds():
  45. from .subseed import SubSeedList
  46. return str(SubSeedList.dfl_len)
  47. def dfl_seed_len():
  48. from .seed import Seed
  49. return str(Seed.dfl_len)
  50. def password_formats():
  51. from .passwdlist import PasswordList
  52. pwi_fs = '{:8} {:1} {:26} {:<7} {:<7} {}'
  53. return '\n '.join(
  54. [pwi_fs.format('Code','','Description','Min Len','Max Len','Default Len')] +
  55. [pwi_fs.format(k,'-',v.desc,v.min_len,v.max_len,v.dfl_len) for k,v in PasswordList.pw_info.items()]
  56. )
  57. def dfl_mmtype():
  58. from .addr import MMGenAddrType
  59. return "'{}' or '{}'".format(
  60. proto.dfl_mmtype,
  61. MMGenAddrType.mmtypes[proto.dfl_mmtype].name )
  62. def address_types():
  63. from .addr import MMGenAddrType
  64. return '\n '.join([
  65. "'{}','{:<12} - {}".format( k, v.name+"'", v.desc )
  66. for k,v in MMGenAddrType.mmtypes.items()
  67. ])
  68. def fmt_codes():
  69. from .wallet import format_fmt_codes
  70. return '\n '.join( format_fmt_codes().splitlines() )
  71. def coin_id():
  72. return proto.coin_id
  73. def keygen_backends():
  74. from .keygen import get_backends
  75. from .addr import MMGenAddrType
  76. backends = get_backends(
  77. MMGenAddrType(proto,po.user_opts.get('type') or proto.dfl_mmtype).pubkey_type
  78. )
  79. return ' '.join( f'{n}:{k}{" [default]" if n==1 else ""}' for n,k in enumerate(backends,1) )
  80. def coind_exec():
  81. return coind_exec()
  82. def coin_daemon_network_ids():
  83. from .daemon import CoinDaemon
  84. from .util import fmt_list
  85. return fmt_list(CoinDaemon.get_network_ids(),fmt='bare')
  86. def rel_fee_desc():
  87. from .tx import BaseTX
  88. return BaseTX(proto=proto).rel_fee_desc
  89. def fee_spec_letters():
  90. return fee_spec_letters()
  91. def fee():
  92. from .tx import BaseTX
  93. return """
  94. FEE SPECIFICATION: Transaction fees, both on the command line and at the
  95. interactive prompt, may be specified as either absolute {c} amounts, using
  96. a plain decimal number, or as {r}, using an integer followed by
  97. '{l}', for {u}.
  98. """.format(
  99. c = proto.coin,
  100. r = BaseTX(proto=proto).rel_fee_desc,
  101. l = fee_spec_letters(use_quotes=True),
  102. u = fee_spec_names() )
  103. def passwd():
  104. return """
  105. PASSPHRASE NOTE:
  106. For passphrases all combinations of whitespace are equal, and leading and
  107. trailing space are ignored. This permits reading passphrase or brainwallet
  108. data from a multi-line file with free spacing and indentation.
  109. """.strip()
  110. def brainwallet():
  111. return """
  112. BRAINWALLET NOTE:
  113. To thwart dictionary attacks, it's recommended to use a strong hash preset
  114. with brainwallets. For a brainwallet passphrase to generate the correct
  115. seed, the same seed length and hash preset parameters must always be used.
  116. """.strip()
  117. def txcreate():
  118. return f"""
  119. The transaction's outputs are specified on the command line, while its inputs
  120. are chosen from a list of the user's unspent outputs via an interactive menu.
  121. If the transaction fee is not specified on the command line (see FEE
  122. SPECIFICATION below), it will be calculated dynamically using network fee
  123. estimation for the default (or user-specified) number of confirmations.
  124. If network fee estimation fails, the user will be prompted for a fee.
  125. Network-estimated fees will be multiplied by the value of '--tx-fee-adj',
  126. if specified.
  127. All addresses on the command line can be either {proto.name} addresses or {g.proj_name}
  128. addresses of the form <seed ID>:<index>.
  129. To send the value of all inputs (minus TX fee) to a single output, specify
  130. one address with no amount on the command line.
  131. """
  132. def txsign():
  133. from .proto.btc import mainnet
  134. return """
  135. Transactions may contain both {pnm} or non-{pnm} input addresses.
  136. To sign non-{pnm} inputs, a {wd}flat key list is used
  137. as the key source ('--keys-from-file' option).
  138. To sign {pnm} inputs, key data is generated from a seed as with the
  139. {pnl}-addrgen and {pnl}-keygen commands. Alternatively, a key-address file
  140. may be used (--mmgen-keys-from-file option).
  141. Multiple wallets or other seed files can be listed on the command line in
  142. any order. If the seeds required to sign the transaction's inputs are not
  143. found in these files (or in the default wallet), the user will be prompted
  144. for seed data interactively.
  145. To prevent an attacker from crafting transactions with bogus {pnm}-to-{pnu}
  146. address mappings, all outputs to {pnm} addresses are verified with a seed
  147. source. Therefore, seed files or a key-address file for all {pnm} outputs
  148. must also be supplied on the command line if the data can't be found in the
  149. default wallet.
  150. """.format(
  151. wd = (f'{coind_exec()} wallet dump or ' if isinstance(proto,mainnet) else ''),
  152. pnm = g.proj_name,
  153. pnu = proto.name,
  154. pnl = g.proj_name.lower() )
  155. def seedsplit():
  156. from .seedsplit import SeedShareIdx,SeedShareCount,MasterShareIdx
  157. return """
  158. COMMAND NOTES:
  159. This command generates shares one at a time. Shares may be output to any
  160. MMGen wallet format, with one limitation: only one share in a given split may
  161. be in hidden incognito format, and it must be the master share in the case of
  162. a master-share split.
  163. If the command's optional first argument is omitted, the default wallet is
  164. used for the split.
  165. The last argument is a seed split specifier consisting of an optional split
  166. ID, a share index, and a share count, all separated by colons. The split ID
  167. must be a valid UTF-8 string. If omitted, the ID 'default' is used. The
  168. share index (the index of the share being generated) must be in the range
  169. {si.min_val}-{si.max_val} and the share count (the total number of shares in the split)
  170. in the range {sc.min_val}-{sc.max_val}.
  171. Master Shares
  172. Each seed has a total of {mi.max_val} master shares, which can be used as the first
  173. shares in multiple splits if desired. To generate a master share, use the
  174. --master-share (-M) option with an index in the range {mi.min_val}-{mi.max_val} and omit
  175. the last argument.
  176. When creating and joining a split using a master share, ensure that the same
  177. master share index is used in all split and join commands.
  178. EXAMPLES:
  179. Split a BIP39 seed phrase into two BIP39 shares. Rejoin the split:
  180. $ echo 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong' > sample.bip39
  181. $ mmgen-seedsplit -o bip39 sample.bip39 1:2
  182. BIP39 mnemonic data written to file '03BAE887-default-1of2[D51CB683][128].bip39'
  183. $ mmgen-seedsplit -o bip39 sample.bip39 2:2
  184. BIP39 mnemonic data written to file '03BAE887-default-2of2[67BFD36E][128].bip39'
  185. $ mmgen-seedjoin -o bip39 \\
  186. '03BAE887-default-2of2[67BFD36E][128].bip39' \\
  187. '03BAE887-default-1of2[D51CB683][128].bip39'
  188. BIP39 mnemonic data written to file '03BAE887[128].bip39'
  189. $ cat '03BAE887[128].bip39'
  190. zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong
  191. Create a 3-way default split of your default wallet, outputting all shares
  192. to default wallet format. Rejoin the split:
  193. $ mmgen-seedsplit 1:3 # Step A
  194. $ mmgen-seedsplit 2:3 # Step B
  195. $ mmgen-seedsplit 3:3 # Step C
  196. $ mmgen-seedjoin <output_of_step_A> <output_of_step_B> <output_of_step_C>
  197. Create a 2-way split of your default wallet with ID string 'alice',
  198. outputting shares to MMGen native mnemonic format. Rejoin the split:
  199. $ mmgen-seedsplit -o words alice:1:2 # Step D
  200. $ mmgen-seedsplit -o words alice:2:2 # Step E
  201. $ mmgen-seedjoin <output_of_step_D> <output_of_step_E>
  202. Create a 2-way split of your default wallet with ID string 'bob' using
  203. master share #7, outputting share #1 (the master share) to default wallet
  204. format and share #2 to BIP39 format. Rejoin the split:
  205. $ mmgen-seedsplit -M7 # Step X
  206. $ mmgen-seedsplit -M7 -o bip39 bob:2:2 # Step Y
  207. $ mmgen-seedjoin -M7 --id-str=bob <output_of_step_X> <output_of_step_Y>
  208. Create a 2-way split of your default wallet with ID string 'alice' using
  209. master share #7. Rejoin the split using master share #7 generated in the
  210. previous example:
  211. $ mmgen-seedsplit -M7 -o bip39 alice:2:2 # Step Z
  212. $ mmgen-seedjoin -M7 --id-str=alice <output_of_step_X> <output_of_step_Z>
  213. Create a 2-way default split of your default wallet with an incognito-format
  214. master share hidden in file 'my.hincog' at offset 1325. Rejoin the split:
  215. $ mmgen-seedsplit -M4 -o hincog -J my.hincog,1325 1:2 # Step M (share A)
  216. $ mmgen-seedsplit -M4 -o bip39 2:2 # Step N (share B)
  217. $ mmgen-seedjoin -M4 -H my.hincog,1325 <output_of_step_N>
  218. """.strip().format(
  219. si = SeedShareIdx,
  220. sc = SeedShareCount,
  221. mi = MasterShareIdx )
  222. def subwallet():
  223. from .subseed import SubSeedIdxRange
  224. return f"""
  225. SUBWALLETS:
  226. Subwallets (subseeds) are specified by a "Subseed Index" consisting of:
  227. a) an integer in the range 1-{SubSeedIdxRange.max_idx}, plus
  228. b) an optional single letter, 'L' or 'S'
  229. The letter designates the length of the subseed. If omitted, 'L' is assumed.
  230. Long ('L') subseeds are the same length as their parent wallet's seed
  231. (typically 256 bits), while short ('S') subseeds are always 128-bit.
  232. The long and short subseeds for a given index are derived independently,
  233. so both may be used.
  234. MMGen has no notion of "depth", and to an outside observer subwallets are
  235. identical to ordinary wallets. This is a feature rather than a bug, as it
  236. denies an attacker any way of knowing whether a given wallet has a parent.
  237. Since subwallets are just wallets, they may be used to generate other
  238. subwallets, leading to hierarchies of arbitrary depth. However, this is
  239. inadvisable in practice for two reasons: Firstly, it creates accounting
  240. complexity, requiring the user to independently keep track of a derivation
  241. tree. More importantly, however, it leads to the danger of Seed ID
  242. collisions between subseeds at different levels of the hierarchy, as
  243. MMGen checks and avoids ID collisions only among sibling subseeds.
  244. An exception to this caveat would be a multi-user setup where sibling
  245. subwallets are distributed to different users as their default wallets.
  246. Since the subseeds derived from these subwallets are private to each user,
  247. Seed ID collisions among them doesn't present a problem.
  248. A safe rule of thumb, therefore, is for *each user* to derive all of his/her
  249. subwallets from a single parent. This leaves each user with a total of two
  250. million subwallets, which should be enough for most practical purposes.
  251. """.strip()
  252. return getattr(help_notes,k)()