get_passphrase.py 1.7 KB

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