digitalbazaar / forge

A native implementation of TLS in Javascript and tools to write crypto-based and network-heavy webapps
https://digitalbazaar.com/
Other
5.01k stars 767 forks source link

forge/prime.worker.js 404 (Not Found) #1069

Closed badasukerubin closed 6 months ago

badasukerubin commented 6 months ago

I faced this issue in my dev environment when I tried to generate a key pair asynchronously, the stack is Laravel + React (Vite). I was able to solve this by doing the following:

// declare a variable to point to a public resource of the minified version of prime worker
const worker = `${window.location.origin}/workers/prime/prime.worker.min.js`;

pki.rsa.generateKeyPair(
      {
        bits: 2048,
        workers: 2,
        workerScript: worker,
      },
      ...
// package.json
// Automate the cp process; ensure to install copyfiles and also add to build.

  "scripts": {
    "copy-worker": "copyfiles -u 1 node_modules/node-forge/dist/prime.worker.min.js public/workers/prime/",
    "dev": "npm run copy-worker && vite",
    ...