mmgen-walletchk 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. import mmgen.Opts as Opts
  24. from mmgen.utils import *
  25. help_data = {
  26. 'desc': """Check integrity of a %s deterministic wallet, display
  27. its information and export seed and mnemonic data."""\
  28. % proj_name,
  29. 'usage': "[opts] [filename]",
  30. 'options': """
  31. -h, --help Print this help message
  32. -e, --echo-passphrase Print passphrase to screen when typing it
  33. -m, --export-mnemonic Export the wallet's mnemonic to file
  34. -s, --export-seed Export the wallet's seed to file
  35. -v, --verbose Produce more verbose output
  36. """
  37. }
  38. short_opts = "hemsv"
  39. long_opts = "help","echo_passphrase","export_mnemonic","export_seed","verbose"
  40. opts,cmd_args = Opts.process_opts(sys.argv,help_data,short_opts,long_opts)
  41. if len(cmd_args) != 1:
  42. msg("One input file must be specified")
  43. sys.exit(2)
  44. if 'export_mnemonic' in opts:
  45. msg("Exporting mnemonic data to file by user request")
  46. if 'export_seed' in opts:
  47. msg("Exporting seed data to file by user request")
  48. seed = get_seed_from_wallet(cmd_args[0], opts)
  49. msg("Wallet is OK")
  50. if 'export_mnemonic' in opts:
  51. wl = get_default_wordlist()
  52. from mmgen.mnemonic import get_mnemonic_from_seed
  53. p = True if debug else False
  54. mn = get_mnemonic_from_seed(seed, wl, default_wl, print_info=p)
  55. write_mnemonic_to_file(mn, seed, opts)
  56. if debug: print "Mnemonic:\n%s" % " ".join(mn)
  57. if 'export_seed' in opts:
  58. write_seed_to_file(seed, opts)
  59. if debug:
  60. from mmgen.bitcoin import b58encode_pad
  61. print "Seed: %s" % col4(b58encode_pad(seed))