dajiaji / hpke-js

A Hybrid Public Key Encryption (HPKE) module built on top of Web Cryptography API.
https://dajiaji.github.io/hpke-js/docs
MIT License
63 stars 9 forks source link

NotSupportedError: Web Cryptograph API not supported #95

Closed OR13 closed 1 year ago

OR13 commented 2 years ago

This happens when you try to run the examples in the readme directly with jest.

I tried creating jest.config.js, but it did not resolve the issue.

with:

module.exports = {
  testEnvironment: 'node',
};

This is likely not a problem with your library, but rather with how jest handles node modules / es modules by default.

  "dependencies": {
    "hpke-js": "^0.13.0"
  },
  "devDependencies": {
    "jest": "^29.1.2"
  }

Work around... don't use jest.

dajiaji commented 2 years ago

I used to support jest but stopped supporting it when we started supporting Deno.

Could you try testEnvironment: 'jsdom' ?

OR13 commented 2 years ago

I will give it a shot, thanks for the reply.

Zhiyi-Zhang commented 1 year ago

@OR13

import crypto from 'crypto'
// ...
(self: any).crypto = (crypto: any).webcrypto;

solve the problem for me