Private Decentralized Communication Network
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB

  1. '''
  2. Onionr - Private P2P Communication
  3. convert a base32 string (intended for ed25519 user ids) to pgp word list
  4. '''
  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. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. '''
  17. import base64
  18. import niceware
  19. import unpaddedbase32
  20. import onionrcrypto
  21. from etc import onionrvalues
  22. DELIMITER = '-'
  23. def get_human_readable_ID(pub=''):
  24. '''gets a human readable ID from a public key'''
  25. if pub == '':
  26. pub = onionrcrypto.pub_key
  27. if not len(pub) == onionrvalues.MAIN_PUBLIC_KEY_SIZE:
  28. pub = base64.b32decode(pub)
  29. return DELIMITER.join(niceware.bytes_to_passphrase(pub))
  30. #return niceware.bytes_to_passphrase(pub).replace(' ', DELIMITER)
  31. def get_base32(words):
  32. '''converts mnemonic to base32'''
  33. return unpaddedbase32.b32encode(niceware.passphrase_to_bytes(words.replace(DELIMITER, ' ')))