Javascript newbie can't keystore.generate("EC", "P-256")

254 views Asked by At

I'm pretty new to Javascript and Node. Using Jupyter Notebook I ran a subsection of this [SMART HEALTH CARD][1] to generate a key. I just took the "Creating the Signed Health Card" section and ran it in notebook. I get "{ keys: [] }" . When I run it from Node, I get nothing (no error and no JSON output). I am using MacOS Big Sur 11.6.2 & node 16.9.0 & node-jose 2.0.0

The actual subsection I ran is:

var jose = require('node-jose');

const keystore = jose.JWK.createKeyStore()

let signingKey;

keystore.generate("EC", "P-256").
then(function(result) {
  // {result} is a jose.JWK.Key
  signingKey = result;
});

keystore.toJSON(true);

When I added console.log(signingKey)to the generate function in Jupyter Notebook, I get the key so somehow the signingKey is not getting exported out of the generate function.

I've looked thru all the questions and at Node-Jose docs but can't figure it out. What is this clueless person missing?

1

There are 1 answers

0
ccsrequest On

The signingKey is a local variable within the generate function. All I need to do is add a return (signingkey) to the function and I have my key.

I'm sure there is a better answer but least I've learned a little about .then().