title: JavaScript, eccrypto.encrypt() giving an [object object] after hexing the value
body: <p><strong>Intro</strong>:</p>
  <p>Hello Community. I have been trying to encrypt a message with the <a href="https://www.npmjs.com/package/eccrypto" rel="nofollow noreferrer">https://www.npmjs.com/package/eccrypto</a> ~ eccrypto.encrypt() function then .toString('hex') the value after encrypting but when I return the hexed value, it gives me [object object]. Why does this happen? I am new to javascript and eccrypto and any insight will be appreciated.</p>
  <p><strong>Relevant Code</strong>:</p>
  <pre><code>window.encryptMes = async function(data)
  {
      //for this you need to get the sender's public key to encrypt the message
      console.log(&quot;encryptmes: began&quot;);
      var pkey = genPKey();
  
      if (pkey === null || undefined) 
      {
        
        console.log('You do not have a key pair');
  
      }
  
      var encryptedMes = await eccrypto.encrypt(pkey, Buffer.from(data));
  
      var enMes = encryptedMes.toString('hex');
  
  //question now becomes, WHY IS THIS RETURNING OBJECT OBJECT
  
      console.log(`encryptedMes returned: ${encryptedMes}`); //could be this since it is not stringified when it goes into celox network
      console.log(`enMes returned: ${enMes}`);
      console.log(`enMes completed successfully`);
  
      return enMes;
  }
  </code></pre>
  <pre><code>window.genPKey = function()
  {
      console.log(&quot;getSKey flag: 0&quot;);
  
      const skey = localStorage.getItem('skey');
  
      const SKey = Buffer.from(skey, 'hex');
  
      console.log(&quot;getSKey flag: 1&quot;);
  
      if(SKey != null || undefined)
      {
          console.log(SKey);
  
          console.log(&quot;getSKey flag: 2&quot;);
  
          const publicKey = eccrypto.getPublic(SKey);
          //encrypt(SKey.publicKey.toHex(), &quot;fuck this is shitty&quot;);
  
          console.log(&quot;getSKey flag: 3&quot;);
  
          //localStorage.setItem(&quot;pkey&quot;, window.btoa(JSON.stringify(publicKey)));
  
          return publicKey;
  
      }
  
      console.log(&quot;getSKey flag: alt&quot;);
  
      //genSKey();
      //genPKey();
  
      return;
  }
  </code></pre>
  <p><strong>Focus</strong>:
  Why is this returning an [object object] and not something I can store successfully?</p>