Advertisement
Guest User

Untitled

a guest
Oct 9th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. **
  2. * Decodes the incoming message
  3. * @param {any} msg encoded message
  4. * @param {string} senderPublicKey sender public key
  5. * @param {string} privateKey our private key
  6. * @param {any} nonce nonce
  7. * @returns {string}
  8. */
  9. adamant.decodeMessage = function (msg, senderPublicKey, privateKey, nonce) {
  10. if (typeof msg === 'string') {
  11. msg = hexToBytes(msg)
  12. }
  13.  
  14. if (typeof nonce === 'string') {
  15. nonce = hexToBytes(nonce)
  16. }
  17.  
  18. if (typeof senderPublicKey === 'string') {
  19. senderPublicKey = hexToBytes(senderPublicKey)
  20. }
  21.  
  22. if (typeof privateKey === 'string') {
  23. privateKey = hexToBytes(privateKey)
  24. }
  25.  
  26. const DHPublicKey = ed2curve.convertPublicKey(senderPublicKey)
  27. const DHSecretKey = ed2curve.convertSecretKey(privateKey)
  28. const decrypted = nacl.box.open(msg, nonce, DHPublicKey, DHSecretKey)
  29.  
  30. return decrypted ? decode(decrypted) : ''
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement