Skip to content

isObject helper fails in jest #178

@maurolucc

Description

@maurolucc

Describe the bug

fromKeyLike does not return an object (JWK). If you use the output of this function in the latest version of node you get the following error:

TypeError: JWK must be an object

To Reproduce

Use Node v15.14.0.

  const key = crypto.generateKeyPairSync("ec", {
    namedCurve: "secp256k1",
  });
  const privateJwk = await fromKeyLike(key.privateKey);
     // ^^^^^^^^^^ this is not an object
  const privateKey = await parseJwk(privateJwk, "ES256K");                                  
  // TypeError: JWK must be an object

Expected behaviour
Get proper object so as to be able to use JWK.

Environment:

  • jose version: 3.11.4
  • Typescript v4.2.4
  • affected runtime is: Node.js v15.14.0

Additional context
If anyone faces the same issue, there are two tricks that can save you:

  • Do not use privateJwk in the next function as input but {...privateJwk }
    or
  • After getting privateJwk set jwk.constructor = Object;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions