question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught TypeError: cb is not a function

See original GitHub issue

I’m having some trouble implementing both signing and encryption at the same time (probably due to tiredness). The below code gives the above error but I’m not really sure why, if anyone could help me out that would be great, I’m super rusty with Javascript.

  var signencryptionButton = $("#signencryption-button");

  signencryptionButton.click(function(){
      var signencryptionPlainText = $("#signencryption-plain-text");
      var signencryptionEncryptedText = $("#signencryption-encrypted-text");
      var signencryptionReceiversPublicKey = $("#signencryption-receivers-public-key");
      var sign2PrivateKey = $("#sign2private-Key");
      var sign2Passphrase = $("#sign2-passphrase");

      // import receiver's public key
      var receiver = kbpgp.KeyManager.import_from_armored_pgp({
        armored: signencryptionReceiversPublicKey.val()});

          var currUser = kbpgp.KeyManager.import_from_armored_pgp({
            armored: sign2PrivateKey.val()});
            currUser.unlock_pgp({
              passphrase: sign2Passphrase.val()});
          // encrypt the message
          var params = {
            msg: signencryptionPlainText.val(),
            encrypt_for: receiver,
            sign_with: currUser
          };

          kbpgp.box(params, function(err, result_string, result_buffer) {
            console.log(err, result_string, result_buffer);
            signencryptionEncryptedText.val(result_string);
          });
      });

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
TheChiefMeatcommented, Mar 1, 2018

I feel a little bit proud saying that despite not knowing any Javascript before a few days ago, I figured it out alone, yay.

It’s now live on the site! https://thechiefmeat.github.io/pgp/

  // SIGN+Encrypt
  var signencryptButton = $("#signencrypt-button");

  signencryptButton.click(function() {
      var signencryptPlainText = $("#signencrypt-plain-text");
      var signencryptText = $("#signencrypt-text");
      var signencryptPrivateKey = $("#signencrypt-private-key");
      var signencryptPassphrase = $("#signencrypt-passphrase");
      var signencryptReceiversPublicKey = $("#signencrypt-receivers-public-key");

      var currUser = kbpgp.KeyManager.import_from_armored_pgp({
          armored: signencryptPrivateKey.val()
      }, function(err, currUser) {
          if (!err) {
              if (currUser.is_pgp_locked()) {
                  currUser.unlock_pgp({
                      passphrase: signencryptPassphrase.val()
                  }, function(err) {
                      if (!err) {
                          console.log("Loaded private key with passphrase");
                      }
                  });
              }
          }
          // import receiver's public key
          var receiver = kbpgp.KeyManager.import_from_armored_pgp({
              armored: signencryptReceiversPublicKey.val()
          }, function(err, receiver) {
              if (!err) {
                  console.log("receiver's public key is loaded");
                  console.log(receiver);

                  var params = {
                      msg: signencryptPlainText.val(),
                      sign_with: currUser,
                      encrypt_for: receiver
                  };

                  kbpgp.box(params, function(err, result_string, result_buffer) {
                      console.log(err, result_string, result_buffer);
                      signencryptText.val(result_string);
                  });
              } else {
                  console.log("Error!");
              }
          });
      });
  });
0reactions
TheChiefMeatcommented, Feb 26, 2018

Whoops, didn’t mean to close the issue :S

Closest I have so far is:

// Sign+ENCRYPTION
  var signencryptionButton = $("#signencryption-button");

  signencryptionButton.click(function(){
    var signencryptionPlainText = $("#signencryption-plain-text");
    var signencryptionEncryptedText = $("#signencryption-encrypted-text");
    var signencryptionReceiversPublicKey = $("#signencryption-receivers-public-key");
    var sign2PrivateKey = $("#sign2private-Key");
    var sign2Passphrase = $("#sign2-passphrase");

    var receiver = kbpgp.KeyManager.import_from_armored_pgp({
      armored: signencryptionReceiversPublicKey.val()
    }, function(err, receiver) {
      if (!err) {
        console.log("Public Key Loaded!")

    var currUser = kbpgp.KeyManager.import_from_armored_pgp({
      armored: sign2PrivateKey.val()
    }, function(err, currUser) {
      if (!err) {
        if (sign2PrivateKey.is_pgp_locked()) {
          sign2PrivateKey.unlock_pgp({
            passphrase: sign2Passphrase.val()
          }, function(err) {
            if (!err) {
              console.log("Loaded private key with passphrase");
            }
          });

          var params = {
            msg: signencryptionPlainText.val(),
            encrypt_for: receiver,
            sign_with: currUser
            };

        kbpgp.box(params, function(err, result_string, result_buffer) {
          console.log(err, result_string, result_buffer);
          signencryptionEncryptedText.val(result_string);
        });
        } else {
          console.log("Loaded private key w/o passphrase");
        }
      }
    });
        } else {
        console.log("Error!");
      }
    });
  });

With this it no longer complains about any errors, and the keys appear to be loaded, but it doesn’t do anything after that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: cb is not a function - javascript - Stack Overflow
1. You aren't passing any cb s to any of the three functions that require a callback as a second parameter. – CertainPerformance...
Read more >
TypeError: cb is not a function #917 - tediousjs/tedious - GitHub
Hi @Steexyz, for the 'cb' function issue, there is a change under PR #845 that has been recently merged into master which introduce...
Read more >
Uncaught TypeError: cb is not a function - Espruino Forum
Hi, i am working on a little project which involves controlling the puck from a web browser. i have came across this error...
Read more >
How I fixed a "cb.apply is not a function" error while using ...
I regularly use Gitbook, a little Node.js software used to generate an ebook from a set of markdown files. I use it for...
Read more >
TypeError: callback is not a function in JavaScript | bobbyhadz
The "callback is not a function" error occurs when we define a callback parameter to a function, but invoke the function without passing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found