get_passphrase.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. import sys, os
  3. pn = os.path.abspath(os.path.dirname(sys.argv[0]))
  4. os.chdir(os.path.dirname(os.path.dirname(pn)))
  5. sys.path[0] = os.curdir
  6. from mmgen.cfg import Config, gc
  7. from mmgen.util import msg
  8. opts_data = {
  9. 'text': {
  10. 'desc': '',
  11. 'usage': 'crypto | seed',
  12. 'options': """
  13. -h, --help Print this help message
  14. -P, --passwd-file=f a
  15. -p, --hash-preset=p b
  16. -r, --usr-randchars=n c
  17. -L, --label=l d
  18. -m, --keep-label e
  19. """
  20. }
  21. }
  22. cfg = Config(opts_data=opts_data, init_opts={'color': True})
  23. def crypto():
  24. desc = 'test data'
  25. from mmgen.crypto import Crypto
  26. crypto = Crypto(cfg)
  27. pw = crypto.get_new_passphrase(data_desc=desc, hash_preset=gc.dfl_hash_preset, passwd_file=None)
  28. msg(f'==> got new passphrase: [{pw}]\n')
  29. pw = crypto.get_passphrase(data_desc=desc, passwd_file=None)
  30. msg(f'==> got passphrase: [{pw}]\n')
  31. hp = crypto.get_hash_preset_from_user(data_desc=desc)
  32. msg(f'==> got hash preset: [{hp}]')
  33. hp = crypto.get_hash_preset_from_user(data_desc=desc)
  34. msg(f'==> got hash preset: [{hp}]')
  35. def seed():
  36. from mmgen.wallet import Wallet
  37. for n in range(1, 3):
  38. msg(f'------- NEW WALLET {n} -------\n')
  39. w1 = Wallet(cfg)
  40. msg(f'\n==> got pw, preset, lbl: [{w1.ssdata.passwd}][{w1.ssdata.hash_preset}][{w1.ssdata.label}]\n')
  41. for n in range(1, 3):
  42. msg(f'------- PASSCHG {n} -------\n')
  43. w2 = Wallet(cfg, ss=w1, passchg=True)
  44. msg(f'\n==> got pw, preset, lbl: [{w2.ssdata.passwd}][{w2.ssdata.hash_preset}][{w2.ssdata.label}]\n')
  45. msg('------- WALLET FROM FILE -------\n')
  46. w3 = Wallet(cfg, fn='test/ref/FE3C6545-D782B529[128,1].mmdat') # passphrase: 'reference password'
  47. msg(f'\n==> got pw, preset, lbl: [{w3.ssdata.passwd}][{w3.ssdata.hash_preset}][{w3.ssdata.label}]\n')
  48. globals()[cfg._args[0]]()