SHARE
TWEET

Untitled

a guest Oct 9th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top