mmgen-walletchk 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
  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. mmgen-walletchk: Check integrity of a mmgen deterministic wallet, display
  20. information about it and export seed and mnemonic data
  21. """
  22. import sys
  23. from mmgen.Opts import *
  24. from mmgen.util import *
  25. help_data = {
  26. 'prog_name': sys.argv[0].split("/")[-1],
  27. 'desc': """Check integrity of a %s deterministic wallet, display
  28. its information and export seed and mnemonic data."""\
  29. % g.proj_name,
  30. 'usage': "[opts] [filename]",
  31. 'options': """
  32. -h, --help Print this help message
  33. -d, --outdir d Specify an alternate directory 'd' for output
  34. -e, --echo-passphrase Print passphrase to screen when typing it
  35. -m, --export-mnemonic Export the wallet's mnemonic to file
  36. -P, --passwd-file f Get passphrase from file 'f'
  37. -q, --quiet Suppress warnings; overwrite files without prompting
  38. -s, --export-seed Export the wallet's seed to file
  39. -S, --stdout Print seed or mnemonic data to standard output
  40. -v, --verbose Produce more verbose output
  41. """
  42. }
  43. short_opts = "hd:emP:qsSv"
  44. long_opts = "help","outdir=","echo_passphrase","export_mnemonic",\
  45. "passwd_file=","quiet","export_seed","stdout","verbose"
  46. opts,cmd_args = process_opts(sys.argv,help_data,short_opts,long_opts)
  47. if 'quiet' in opts: g.quiet = True
  48. if 'verbose' in opts: g.verbose = True
  49. # Argument sanity checks and processing:
  50. check_opts(opts,long_opts)
  51. if len(cmd_args) != 1: usage(help_data)
  52. check_infile(cmd_args[0])
  53. if 'export_mnemonic' in opts:
  54. qmsg("Exporting mnemonic data to file by user request")
  55. if 'export_seed' in opts:
  56. qmsg("Exporting seed data to file by user request")
  57. seed = get_seed_from_wallet(cmd_args[0], opts)
  58. if seed: qmsg("Wallet is OK")
  59. if 'export_mnemonic' in opts:
  60. wl = get_default_wordlist()
  61. from mmgen.mnemonic import get_mnemonic_from_seed
  62. p = True if g.debug else False
  63. mn = get_mnemonic_from_seed(seed, wl, g.default_wl, print_info=p)
  64. write_mnemonic(mn, seed, opts)
  65. if 'export_seed' in opts:
  66. write_seed(seed, opts)